output_description: Print the count modulo (10^9+7).
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
attempt: def main():
      N, M = map(int, input().split())
      P = 10**9 + 7
  
      # 全部：mPn ** 2通り
      # A:mPn通り
      mPn = M
      for i in range(M - N + 1, M):
          mPn = mPn * i % P
  
      """
      #Bのダメなパターン:固定したAに対して、∑(k=1...N)(-1)**(k)*nCk*(m-k)P(n-k)
      #   少なくとも1つがAと同じ
      #       Aと同じ箇所の取り方：nC1
      #       N-1個の数の組み合わせ：(m-1)(m-2)...(m-n+1) = (m-1)P(n-1)
      #   少なくとも2つがAと同じ
      #       Aと同じ箇所の取り方：nC2
      #       N-2個の数の組み合わせ：(m-2)(m-3)...(m-n+1) = (m-2)P(n-2)
  
      """
      num_b = 0
      nCk = 1
      m_kPn_k = mPn
  
      for k in range(1, N + 1):
          nCk = nCk * (N - k + 1) * pow(k, P - 2, P) % P
          m_kPn_k = m_kPn_k * pow(M - k + 1, P - 2, P) % P
          num_b = (num_b + ((-1) ** (k - 1)) * nCk * m_kPn_k) % P
      print((mPn**2 - mPn * num_b) % P)
  
  
  main()
  
problem_description: Statement
  
  Count the pairs of length-N sequences consisting of integers between 1 and M
  (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N}, that satisfy
  all of the following conditions:
  
    * A_i \neq B_i, for every i such that 1\leq i\leq N.
    * A_i \neq A_j and B_i \neq B_j, for every (i, j) such that 1\leq i < j\leq N.
  
  Since the count can be enormous, print it modulo (10^9+7).
samples: [{"input": "2 2", "output": "2\n    \n\nA_1=1,A_2=2,B_1=2,B_2=1 and A_1=2,A_2=1,B_1=1,B_2=2 satisfy the conditions.\n\n* * *"}, {"input": "2 3", "output": "18\n    \n\n* * *"}, {"input": "141421 356237", "output": "881613484"}]