//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll INF = 1e9;
const ll LINF = ll(1e18);
const ll MOD = 1000000007;
const ll dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const ll Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll M = pow(10, 9) + 7;

vector<ll> fac(1000001);  //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)
ll mpow(ll x, ll n)
{ //x^n(mod M)
    ll ans = 1;
    while (n != 0)
    {
        if (n & 1)
            ans = ans * x % M;
        x = x * x % M;
        n = n >> 1;
    }
    return ans;
}
//conbination
ll comb(ll a, ll b)
{ //aCb(mod M)
    if (a == 0 && b == 0)
        return 1;
    if (a < b || a < 0)
        return 0;
    ll tmp = ifac[a - b] * ifac[b] % M;
    return tmp * fac[a] % M;
}
//素因数分解o√n
map<int, int> prime_factor(int n)
{
    map<int, int> res;
    for (int i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1)
        res[n] = 1;
    // for (int i = 2; i <= n; i++)
    //cout << res[i] << "\n";
    return res;
}
//n!
ll fact_mod(ll n)
{
    ll ret = 1;
    for (ll i = 2; i <= n; i++)
        ret = ret * (i % MOD) % MOD;
    return ret;
}
vector<ll> fact_mod_v(ll n)
{
    ll ret = 1;
    vector<ll> res(n + 1, 1);
    for (ll i = 2; i <= n; i++)
    {
        ret = ret * (i % MOD) % MOD;
        res[i] = ret;
    }
    return res;
}
// 繰り返し二乗法
ll pow_mod(ll x, ll n)
{
    if (n == 0)
        return 1;
    ll ret = pow_mod((x * x) % MOD, n / 2);
    if (n & 1)
        ret = (ret * x) % MOD;
    return ret;
}

//nCr O(r) nがでかくても安心
ll combination_mod(ll n, ll r)
{
    if (r > n - r)
        r = n - r;
    if (r == 0)
        return 1;
    ll a = 1;
    //a=n!/(n-r)!=n~n-r+1までの総積->O(r)
    for (ll i = 0; i < r; i++)
        a = a * ((n - i) % MOD) % MOD;
    //b=inv(r!)
    ll b = pow_mod(fact_mod(r), MOD - 2);
    return (a % MOD) * (b % MOD) % MOD;
}

ll inv_mod(ll n)
{
    // フェルマーの小定理
    return pow_mod(n, MOD - 2);
}
const int N_MAX = 1001;
double pascal[N_MAX][N_MAX] = {};

// パスカルの三角形
// 確率Ver
// n段目は 2^n で割った値が入る (横の和 = 1)

void calc_pascal()
{
    FOR(i, 0, N_MAX)
    {
        pascal[i][0] = 1.0 / pow(2.0f, i);
    }
    pascal[1][1] = 1.0 / 2.0;

    FOR(i, 2, N_MAX)
    {
        for (int j = 1; j <= i; j++)
        {
            pascal[i][j] = pascal[i - 1][j] + pascal[i - 1][j - 1];
            pascal[i][j] /= 2.0;
        }
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    fac[0] = 1;
    ifac[0] = 1;
    for (ll i = 0; i < 1000000; i++)
    {
        fac[i + 1] = fac[i] * (i + 1) % M;              // n!(mod M)
        ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M)
    }
    ll a_comb = comb(m, n) * fact_mod(n);
    a_comb %= MOD;
    ll b_comb = comb(m, n) * fact_mod(n);
    b_comb %= MOD;
    vector<ll> fv = fact_mod_v(n);
    for (ll i = 1; i <= n; i++)
    {
        ll temp = comb(n, i) * comb(m - i, n - i);
        temp %= MOD;
        temp *= fv[n - i];
        temp %= MOD;
        if (i % 2)
            b_comb -= temp;
        else
            b_comb += temp;
        b_comb = (b_comb + MOD) % MOD;
    }
    //cout << a_comb << " " << b_comb << "\n";
    a_comb *= b_comb;
    cout << a_comb % MOD << "\n";
}

Measured memory_bytes: 22628