<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

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

<|response|>
1. Abridged Problem Statement  
Given integers n and k, determine the number of ways to place k rooks on an n×n chessboard so that no two rooks attack each other (i.e., no two share the same row or column). If k>n, the answer is 0.

2. Key Observations  
- Two rooks attack each other if and only if they share a row or a column.  
- To avoid attacks, each rook must occupy a unique row and a unique column.  
- We need to choose k distinct rows out of n, choose k distinct columns out of n, then assign one rook per chosen row–column pair in a one-to-one fashion.  
- The number of ways to choose k rows is C(n,k). Similarly for columns. The number of ways to match k chosen rows to k chosen columns is k! (a permutation of k elements).  
- Therefore the total number of valid placements is  
  C(n,k) × C(n,k) × k! = [C(n,k)]² × k!  
- If k>n, it is impossible to place k non-attacking rooks, so the answer is 0.

3. Full Solution Approach  
Step 1. Read n and k.  
Step 2. If k>n, print 0 and terminate.  
Step 3. Precompute factorials f[i] = i! for i=0…n.  
Step 4. Compute the binomial coefficient C(n,k) = f[n] / (f[k] * f[n−k]).  
Step 5. Compute the final answer as C(n,k) × C(n,k) × f[k].  
Step 6. Print the answer.  

Since n≤10, all intermediate values (factorials, binomial coefficients) fit comfortably into 64-bit integers.

4. C++ Solution

```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;
}
```

5. Python Implementation with Detailed Comments
```python
import sys
import math

def main():
    data = sys.stdin.read().split()
    n, k = map(int, data)

    # If k > n, impossible to place k non-attacking rooks
    if k > n:
        print(0)
        return

    # Compute binomial coefficient C(n, k)
    cnk = math.comb(n, k)

    # Compute the total ways: C(n,k) * C(n,k) * k!
    result = cnk * cnk * math.factorial(k)

    print(result)

if __name__ == "__main__":
    main()
```