#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())

ll MOD(ll x, ll m) {
    ll r = x % m;
    if (r < 0) {
        r += m;
    }
    return r;
}

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 9e18
#define MINF -INF

const ll md = 1e9 + 7;

void add_self(ll& a, ll b) {
    a = MOD((a + b), md);
}

void sub_self(ll& a, ll b) {
    a = MOD((a - b), md);
}

void mul_self(ll& a, ll b) {
    a = MOD((a * b), md);
}

ll power(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) {
            mul_self(res, a);
        }
        mul_self(a, a);
        b >>= 1;
    }
    return res;
}

ll mod_inverse(ll a) {
    return power(a, md - 2);   // only when md is prime
}

vll factorial;
void computeFactorials(ll n) {
    factorial.resize(n + 1);
    factorial[0] = 1;
    for (ll i = 1; i <= n; i++) {
        factorial[i] = MOD(factorial[i - 1] * i, md);
    }
}

ll choose(ll n, ll k) {
    ll a = mod_inverse(factorial[k]);
    ll b = mod_inverse(factorial[n - k]);
    ll ab = MOD(a * b, md);
    return MOD(factorial[n] * ab, md);
}

void solve() {
    ll n, m;
    cin >> n >> m;

    computeFactorials(m);
    // vll dearg(m + 1);
    // dearg[0] = 1;
    // dearg[1] = 0;
    // FOR(i, 2, m + 1) {
    //     dearg[i] = (dearg[i - 1] + dearg[i - 2]) % md;
    //     mul_self(dearg[i], (i - 1));
    // }

    ll res = (factorial[m] * mod_inverse(factorial[m - n])) % md;
    mul_self(res, res);
    ll sgn = -1;
    ll test = 0;
    FOR(i, 1, n + 1) {
        ll delta = choose(n, i);
        mul_self(delta, (factorial[m] * mod_inverse(factorial[m - i])) % md);
        ll rest = (factorial[m - i] * mod_inverse(factorial[m - n])) % md;
        mul_self(delta, rest);
        mul_self(delta, rest);
        if (sgn == 1) {
            add_self(res, delta);
        } else {
            sub_self(res, delta);
        }
        sgn = sgn == 1 ? -1 : 1;
    }

    cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 7048