atcoder#ABC172E. [ABC172E] NEQ

[ABC172E] NEQ

Score : 500500 points

Problem Statement

Count the pairs of length-NN sequences consisting of integers between 11 and MM (inclusive), A1,A2,,ANA_1, A_2, \cdots, A_{N} and B1,B2,,BNB_1, B_2, \cdots, B_{N}, that satisfy all of the following conditions:

  • AiBiA_i \neq B_i, for every ii such that 1iN1\leq i\leq N.
  • AiAjA_i \neq A_j and BiBjB_i \neq B_j, for every (i,j)(i, j) such that 1i<jN1\leq i < j\leq N.

Since the count can be enormous, print it modulo (109+7)(10^9+7).

Constraints

  • 1NM5×1051\leq N \leq M \leq 5\times10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

Output

Print the count modulo (109+7)(10^9+7).

2 2
2

A1=1,A2=2,B1=2,B2=1A_1=1,A_2=2,B_1=2,B_2=1 and A1=2,A2=1,B1=1,B2=2A_1=2,A_2=1,B_1=1,B_2=2 satisfy the conditions.

2 3
18
141421 356237
881613484