SIZE=5*10**5; MOD=10**9+7 #998244353 #ここを変更する



SIZE += 1

inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD

fac = [0]*SIZE  # fac[j] = j! mod MOD

finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD

fac[0] = fac[1] = 1

finv[0] = finv[1] = 1

for i in range(2,SIZE):

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

finv[-1] = pow(fac[-1],MOD-2,MOD)

for i in range(SIZE-1,0,-1):

    finv[i-1] = finv[i]*i%MOD

    inv[i] = finv[i]*fac[i-1]%MOD



def choose(n,r): # nCk mod MOD の計算

    if 0 <= r <= n:

        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD

    else:

        return 0



def f(x,y):

    return fac[x]*finv[x-y]%MOD

    

    

# coding: utf-8

# Your code here!

import sys

read = sys.stdin.read

readline = sys.stdin.readline



n,m = list(map(int,readline().split()))



ans = 0

r = 1

for u in range(n+1):

    ans += r*f(m-u,n-u)*choose(n,u)%MOD

    ans %= MOD

    r *= -1







print((ans*f(m,n)%MOD))



# coding: utf-8

# Your code here!

import sys

read = sys.stdin.read

readline = sys.stdin.readline



n,m = list(map(int,readline().split()))

"""

漸化式は f(m,n) = (m-1)f(m-1,n-1) + (n-1)f(m-2,n-2)

初期条件 f(m-n,0)=1, f(m-n+1,1)=m-n

"""

MOD = 10**9+7

res = [0]*(n+1)

res[0] = 1

res[1] = m-n

for i in range(2,n+1):

    res[i] = (m-n+i-1)*res[i-1] + (i-1)*res[i-2]

    res[i] %= MOD



#print(res)

ans = res[n] 

for i in range(m,m-n,-1):

    ans *= i

    ans %= MOD



print(ans)
SIZE = 5 * 10**5
MOD = 10**9 + 7  # 998244353 #ここを変更する
SIZE += 1
inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
fac = [0] * SIZE  # fac[j] = j! mod MOD
finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2, SIZE):
    fac[i] = fac[i - 1] * i % MOD
finv[-1] = pow(fac[-1], MOD - 2, MOD)
for i in range(SIZE - 1, 0, -1):
    finv[i - 1] = finv[i] * i % MOD
    inv[i] = finv[i] * fac[i - 1] % MOD


def choose(n, r):  # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n] * finv[r] % MOD) * finv[n - r] % MOD
    else:
        return 0


def f(x, y):
    return fac[x] * finv[x - y] % MOD


# coding: utf-8
# Your code here!
import sys

read = sys.stdin.read
readline = sys.stdin.readline
n, m = list(map(int, readline().split()))
ans = 0
r = 1
for u in range(n + 1):
    ans += r * f(m - u, n - u) * choose(n, u) % MOD
    ans %= MOD
    r *= -1
print((ans * f(m, n) % MOD))

# coding: utf-8
# Your code here!
import sys

read = sys.stdin.read
readline = sys.stdin.readline
n, m = list(map(int, readline().split()))
"""
漸化式は f(m,n) = (m-1)f(m-1,n-1) + (n-1)f(m-2,n-2)
初期条件 f(m-n,0)=1, f(m-n+1,1)=m-n
"""
MOD = 10**9 + 7
res = [0] * (n + 1)
res[0] = 1
res[1] = m - n
for i in range(2, n + 1):
    res[i] = (m - n + i - 1) * res[i - 1] + (i - 1) * res[i - 2]
    res[i] %= MOD
# print(res)
ans = res[n]
for i in range(m, m - n, -1):
    ans *= i
    ans %= MOD
print(ans)

-SIZE = 5 * 10**5 -MOD = 10**9 + 7  # 998244353 #ここを変更する -SIZE += 1 -inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD -fac = [0] * SIZE  # fac[j] = j! mod MOD -finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD -fac[0] = fac[1] = 1 -finv[0] = finv[1] = 1 -for i in range(2, SIZE): -    fac[i] = fac[i - 1] * i % MOD -finv[-1] = pow(fac[-1], MOD - 2, MOD) -for i in range(SIZE - 1, 0, -1): -    finv[i - 1] = finv[i] * i % MOD -    inv[i] = finv[i] * fac[i - 1] % MOD - - -def choose(n, r):  # nCk mod MOD の計算 -    if 0 <= r <= n: -        return (fac[n] * finv[r] % MOD) * finv[n - r] % MOD -    else: -        return 0 - - -def f(x, y): -    return fac[x] * finv[x - y] % MOD - - -ans = 0 -r = 1 -for u in range(n + 1): -    ans += r * f(m - u, n - u) * choose(n, u) % MOD +""" +漸化式は f(m,n) = (m-1)f(m-1,n-1) + (n-1)f(m-2,n-2) +初期条件 f(m-n,0)=1, f(m-n+1,1)=m-n +""" +MOD = 10**9 + 7 +res = [0] * (n + 1) +res[0] = 1 +res[1] = m - n +for i in range(2, n + 1): +    res[i] = (m - n + i - 1) * res[i - 1] + (i - 1) * res[i - 2] +    res[i] %= MOD +# print(res) +ans = res[n] +for i in range(m, m - n, -1): +    ans *= i -    r *= -1 -print((ans * f(m, n) % MOD)) +print(ans)