Under construction

Still being built. Things may change

Another Filling the Grid

Time limit1sMemory limit1024 MB

Summary
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 n×nn \times n square grid and an integer kk. Write an integer in each cell so that all of the following conditions hold.

  • Every number in the grid is between 1 and kk, inclusive.
  • The minimum of the ii-th row is 1 (1≤i≤n1 \le i \le n).
  • The minimum of the jj-th column is 1 (1≤j≤n1 \le j \le n).

Count the ways to fill the grid. The answer can be very large, so print it modulo (109+7)(10^{9} + 7).

The figure shows valid and invalid grids when n=k=2n=k=2.

Input

The only line contains two integers nn and kk (1≤n≤2501 \le n \le 250, 1≤k≤1091 \le k \le 10^{9}).

Output

Print the answer modulo (109+7)(10^{9} + 7).

Hint

When n=k=2n=k=2, there are 7 valid grids.

Examples2

  1. Example 1

    Input
    2 2
    
    Expected output
    7
    
  2. Example 2

    Input
    123 456789
    
    Expected output
    689974806