output_description: Print the count modulo (10^9+7).
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
attempt: class Mod:
      def __init__(self, mod, n_max):
          """
          イニシャライザ
          予め 1~nの階乗と階乗の逆元を計算しておく
          :param mod: 法
          :param n_max: nの最大値(100,000で約1秒)
          """
          self.mod = mod
          self.n_max = n_max
          self.facts = [1, 1]
          self.inverses = [None, 1]
          self.fact_inverses = [1, 1]
  
          for i in range(2, self.n_max + 1):
              self.facts.append(self.facts[i - 1] * i % self.mod)
              # self.inverses.append(mod_inverse(i, self.mod))
              self.inverses.append(
                  self.mod - self.inverses[self.mod % i] * (self.mod // i) % self.mod
              )
              self.fact_inverses.append(
                  self.fact_inverses[i - 1] * self.inverses[i] % self.mod
              )
  
      def combination(self, n, k):
          if k > n:
              raise ValueError
          elif k == n:
              return 1
          elif k == 0:
              return 1
  
          denominator = self.fact_inverses[k] * self.fact_inverses[n - k] % self.mod
          return self.facts[n] * denominator % self.mod
  
      def permutation(self, n, r):
          return self.facts[n] * self.fact_inverses[n - r] % self.mod
  
  
  N, M = map(int, input().split(" "))
  MOD = 10**9 + 7
  
  m = Mod(MOD, M)
  mPn = m.permutation(M, N)
  
  b = mPn
  x = mPn
  
  for k in range(1, N + 1):
      dup = m.permutation(M - k, N - k) * m.combination(N, k) % MOD
      if k % 2 == 1:
          b -= dup
      else:
          b += dup
      b %= MOD
  
  print(mPn * b % MOD)
  
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"}]