Another Filling the Grid
Time limit1sMemory limit1024 MB
Count the ways to fill an n by n grid with integers from 1 to k so that every row and every column has minimum 1, modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Combinatorics, Math
- Solved
- No attempts yet
Statement
You have an square grid and an integer . Write an integer in each cell so that all of the following conditions hold.
- Every number in the grid is between 1 and , inclusive.
- The minimum of the -th row is 1 ().
- The minimum of the -th column is 1 ().
Count the ways to fill the grid. The answer can be very large, so print it modulo .

The figure shows valid and invalid grids when .
Input
The only line contains two integers and (, ).
Output
Print the answer modulo .
Hint
When , there are 7 valid grids.
