// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/27/20 20:37:14
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename T, T MOD>
class modular {
 private:
  T val_;

 public:
  constexpr modular() : val_(0) {}
  constexpr modular(T v) : val_(v%MOD) {}
  constexpr modular& operator=(T v) { val_ = v%MOD; return *this; }

  constexpr T val() const { return val_; }
  constexpr modular operator+(modular x) const { return (val() + x.val())%MOD; }
  constexpr modular operator+=(modular x) { return *this = *this + x; }
  constexpr modular operator++() { return *this += 1; }
  constexpr modular operator++(int) { modular c = *this; ++(*this); return c; }
  constexpr modular operator-(modular x) const { return (val() + MOD - x.val())%MOD; }
  constexpr modular operator-=(modular x) { return *this = *this - x; }
  constexpr modular operator--() { return *this -= 1; }
  constexpr modular operator--(int) { modular c = *this; --(*this); return c; }
  constexpr modular operator*(modular x) const { return (val() * x.val())%MOD; }
  constexpr modular operator*=(modular x) { return *this = *this * x; }
  friend constexpr modular pow(modular x, T p) {
    modular t = 1;
    modular u = x;
    while (p) {
      if (p & 1)
        t *= u;
      u *= u;
      p >>= 1;
    }
    return t;
  }
  constexpr modular operator/(modular x) const { return *this * pow(modular{x}, MOD-2); }
  constexpr modular operator/=(modular x) { return *this = *this / x; }

  constexpr bool operator==(modular x) const { return val() == x.val(); }
  constexpr bool operator!=(modular x) const { return val() != x.val(); }
  constexpr bool operator<(modular x) const { return val() < x.val(); };
  constexpr bool operator<=(modular x) const { return val() <= x.val(); };
  constexpr bool operator>(modular x) const { return val() > x.val(); };
  constexpr bool operator>=(modular x) const { return val() >= x.val(); };

  friend std::ostream& operator<<(std::ostream& os, const modular& x) {
    return os << x.val();
  }
  friend std::istream& operator>>(std::istream& is, modular& x) {
    return is >> x.val_;
  }

};

#line 4 "include/combination.hpp"

template <typename T, T MOD, unsigned int MAX>
class combination {
 public:
  using mint = modular<T, MOD>;
 private:
  mint fact_[MAX+1];
  mint ifact_[MAX+1];

 public:
  constexpr combination() {
    fact_[0] = 1;
    for (size_t i = 1; i <= MAX; ++i) {
      fact_[i] = fact_[i-1] * i;
    }
    ifact_[MAX] = mint(1)/fact_[MAX];
    for (int i = MAX-1; i >= 0; i--) {
      ifact_[i] = ifact_[i+1] * (i+1);
    }
  }

  mint operator()(T p, T q) const {
    if (p < q) return 0;
    return fact_[p] * ifact_[q] * ifact_[p-q];
  }

  mint fact(int p) const {
    return fact_[p];
  }
  mint ifact(int p) const {
    return ifact_[p];
  }

};

using Cmb = combination<ll, (ll)1e9+7, (ll)55e4>;
Cmb cmb;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  int n,m; cin>>n>>m;
  auto all = cmb(m,n) * cmb.fact(n);
  Cmb::mint igs = 0;
  for (int i = 1; i <= n; i++) {
    Cmb::mint dir = i%2 ? 1 : -1;
    auto p = cmb(n, i) * cmb(m-i, n-i) * cmb.fact(n-i);
    igs += p * dir;
//    cerr<<p<<endl;
  }
//  cerr<<all<<" "<<igs<<endl;
  auto ans = all * (all-igs);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12196