p222.ans1
======================
24

=================
p222.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n, k;

void read() { cin >> n >> k; }

void solve() {
    // Placing k non-attacking rooks means choosing k of the n rows, k of the n
    // columns, and a bijection between them: C(n, k) * C(n, k) * k! ways. We
    // compute this as (n!)^2 / (k! * ((n-k)!)^2), accumulating n! squared in
    // the numerator and dividing out the k! and (n-k)!^2 factors. If k > n no
    // placement is possible, so the answer is 0.

    if(n < k) {
        cout << 0 << '\n';
        return;
    }

    int64_t answer = 1;
    for(int i = 1; i <= n; i++) {
        answer *= i * i;
    }

    for(int i = 1; i <= k; i++) {
        answer /= i;
    }

    for(int i = 1; i <= n - k; i++) {
        answer /= i * i;
    }

    cout << answer << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}

=================
p222.in1
======================
4 4

=================
statement.txt
======================
222. Little Rooks
time limit per test: 0.25 sec.
memory limit per test: 65536 KB
input: standard
output: standard



Inspired by a "Little Bishops" problem, Petya now wants to solve problem for rooks.

A rook is a piece used in the game of chess which is played on a board of square grids. A rook can only move horizontally and vertically from its current position and two rooks attack each other if one is on the path of the other.

Given two numbers n and k, your job is to determine the number of ways one can put k rooks on an n × n chessboard so that no two of them are in attacking positions.

Input

The input file contains two integers n (1 ≤ n ≤ 10) and k (0 ≤ k ≤ n2).

Output

Print a line containing the total number of ways one can put the given number of rooks on a chessboard of the given size so that no two of them are in attacking positions.

Sample test(s)

Input
4 4

Output
24
Author:	Andrew Stankevich
Resource:	Little Chess Pieces Series, SPb IFMO 2003-2004 Authumn Training Sessions
Date:	2003-10-01






=================
