fac=[1]*505050

inv=[1]*505050

finv=[1]*505050

mod=1000000007

for i in range(2,500010):

  fac[i]=fac[i-1]*i%mod

  inv[i]=-inv[mod%i]*(mod//i)%mod

  finv[i]=finv[i-1]*inv[i]%mod



def C(n,r):

  if n<0 or r<0 or n<r: return 0

  return fac[n]*finv[n-r]%mod*finv[r]%mod



N,M=list(map(int,input().split()))

ans=0

for i in range(N+1):

  ans+=C(N,i)*fac[M]%mod*finv[M-i]%mod*((fac[M-i]*finv[M-N])**2%mod)*(1 if i%2==0 else -1)%mod

  ans%=mod

print((ans%mod))

fac=[1]*505050

inv=[1]*505050

finv=[1]*505050

mod=1000000007

for i in range(2,500010):

  fac[i]=fac[i-1]*i%mod

  inv[i]=-inv[mod%i]*(mod//i)%mod

  finv[i]=finv[i-1]*inv[i]%mod



def C(n,r):

  if n<0 or r<0 or n<r: return 0

  return fac[n]*finv[n-r]%mod*finv[r]%mod



N,M=list(map(int,input().split()))

ans=0

for i in range(N+1):

  ans+=C(N,i)*fac[M]%mod*finv[M-i]%mod*((fac[M-i]*finv[M-N]%mod)**2%mod)*(1 if i%2==0 else -1)%mod

  ans%=mod

print((ans%mod))

fac = [1] * 505050
inv = [1] * 505050
finv = [1] * 505050
mod = 1000000007
for i in range(2, 500010):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = -inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def C(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fac[n] * finv[n - r] % mod * finv[r] % mod


N, M = list(map(int, input().split()))
ans = 0
for i in range(N + 1):
    ans += (
        C(N, i)
        * fac[M]
        % mod
        * finv[M - i]
        % mod
        * ((fac[M - i] * finv[M - N]) ** 2 % mod)
        * (1 if i % 2 == 0 else -1)
        % mod
    )
    ans %= mod
print((ans % mod))

fac = [1] * 505050
inv = [1] * 505050
finv = [1] * 505050
mod = 1000000007
for i in range(2, 500010):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = -inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def C(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fac[n] * finv[n - r] % mod * finv[r] % mod


N, M = list(map(int, input().split()))
ans = 0
for i in range(N + 1):
    ans += (
        C(N, i)
        * fac[M]
        % mod
        * finv[M - i]
        % mod
        * ((fac[M - i] * finv[M - N] % mod) ** 2 % mod)
        * (1 if i % 2 == 0 else -1)
        % mod
    )
    ans %= mod
print((ans % mod))

-        * ((fac[M - i] * finv[M - N]) ** 2 % mod) +        * ((fac[M - i] * finv[M - N] % mod) ** 2 % mod)