import sys

input = sys.stdin.readline



MAX = 5*10**5+100

MOD = 10**9+7

fact = [0]*MAX #fact[i]: i!

inv = [0]*MAX #inv[i]: iの逆元

finv = [0]*MAX #finv[i]: i!の逆元

fact[0] = 1

fact[1] = 1

finv[0] = 1

finv[1] = 1

inv[1] = 1

    

for i in range(2, MAX):

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

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

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



def C(n, r):

    if n<r:

        return 0

    if n<0 or r<0:

        return 0

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



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

ans = (C(M, N)*fact[N])**2%MOD



for i in range(1, N+1):

    if i%2==0:

        ans += C(N, i)*C(M, i)*fact[i]*(C(M-i, N-i)*fact[N-i])**2

    else:

        ans -= C(N, i)*C(M, i)*fact[i]*(C(M-i, N-i)*fact[N-i])**2

    

    ans %= MOD



print(ans)
MAX = 5*10**5+100

MOD = 10**9+7

fact = [0]*MAX #fact[i]: i!

inv = [0]*MAX #inv[i]: iの逆元

finv = [0]*MAX #finv[i]: i!の逆元

fact[0] = 1

fact[1] = 1

finv[0] = 1

finv[1] = 1

inv[1] = 1

    

for i in range(2, MAX):

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

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

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



def C(n, r):

    if n<r:

        return 0

    if n<0 or r<0:

        return 0

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



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

ans = C(M, N)*fact[N]



for i in range(1, N+1):

    if i%2==0:

        ans += C(N, i)*C(M-i, N-i)*fact[N-i]

    else:

        ans -= C(N, i)*C(M-i, N-i)*fact[N-i]

    

    ans %= MOD

    

ans = (ans*C(M, N))%MOD

ans = (ans*fact[N])%MOD

print(ans)
import sys

input = sys.stdin.readline
MAX = 5 * 10**5 + 100
MOD = 10**9 + 7
fact = [0] * MAX  # fact[i]: i!
inv = [0] * MAX  # inv[i]: iの逆元
finv = [0] * MAX  # finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
    fact[i] = fact[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


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


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

MAX = 5 * 10**5 + 100
MOD = 10**9 + 7
fact = [0] * MAX  # fact[i]: i!
inv = [0] * MAX  # inv[i]: iの逆元
finv = [0] * MAX  # finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
    fact[i] = fact[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


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


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

-import sys - -input = sys.stdin.readline -ans = (C(M, N) * fact[N]) ** 2 % MOD +ans = C(M, N) * fact[N] -        ans += C(N, i) * C(M, i) * fact[i] * (C(M - i, N - i) * fact[N - i]) ** 2 +        ans += C(N, i) * C(M - i, N - i) * fact[N - i] -        ans -= C(N, i) * C(M, i) * fact[i] * (C(M - i, N - i) * fact[N - i]) ** 2 +        ans -= C(N, i) * C(M - i, N - i) * fact[N - i] +ans = (ans * C(M, N)) % MOD +ans = (ans * fact[N]) % MOD