#include <bits/stdc++.h>

using namespace std;

template<class Modint>
class Binomial{
    vector<Modint> fact(uint64_t n){
        vector<Modint> f(n + 1);
        f[0] = 1;
        for (uint64_t i = 0; i < n; i++)
            f[i + 1] = Modint(i + 1) * f[i];
        return f;
    }

    vector<Modint> invfact(uint64_t n){
        vector<Modint> inv(n + 1);
        inv[n] = Modint(1) / f[n];
        for (uint64_t i = n; i > 0; i--)
            inv[i - 1] = inv[i] * i;
        return inv;
    }

public:
    vector<Modint> f, invf;

    Binomial(uint64_t n){
        f = fact(n);
        invf = invfact(n);
    }

    Modint binomial(int64_t a, int64_t b){
        if (a < b)
            return 0;
        if (a < 0 or b < 0)
            return 0;
        return f[a] * invf[b] * invf[a - b];
    }
};

static constexpr uint32_t mul_inv(uint32_t n, int e = 5, uint32_t x = 1) {
  return e == 0 ? x : mul_inv(n, e - 1, x * (2 - x * n));
}

template< uint32_t mod, bool fast = false >
struct ModInt {
  using u32 = uint32_t;
  using u64 = uint64_t;

  static constexpr u32 inv = mul_inv(mod);
  static constexpr u32 r2 = -uint64_t(mod) % mod;

  uint32_t x;

  ModInt() : x(0) {}

  ModInt(const int64_t &y)
      : x(reduce(u64(fast ? y : (y >= 0 ? y % mod : (mod - (-y) % mod) % mod)) * r2)) {}

  u32 reduce(const u64 &w) const {
    return u32(w >> 32) + mod - u32((u64(u32(w) * inv) * mod) >> 32);
  }

  ModInt &operator+=(const ModInt &p) {
    if(int(x += p.x - 2 * mod) < 0) x += 2 * mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if(int(x -= p.x) < 0) x += 2 * mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = reduce(uint64_t(x) * p.x);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt() - *this; }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return get() == p.get(); }

  bool operator!=(const ModInt &p) const { return get() != p.get(); }

  int get() const { return reduce(x) % mod; }

   template <class Int>
  ModInt pow(Int n) const {
    ModInt ret(1), mul(*this);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  ModInt inverse() const {
    return pow(mod - 2);
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.get();
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod, fast >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

// using modint = ModInt< mod, true >;

template< typename Mint >
struct NumberTheoreticTransformFriendlyModInt {

  vector< Mint > dw, idw;
  int max_base;
  Mint root;

  NumberTheoreticTransformFriendlyModInt() {
    const unsigned mod = Mint::get_mod();
    assert(mod >= 3 && mod % 2 == 1);
    auto tmp = mod - 1;
    max_base = 0;
    while(tmp % 2 == 0) tmp >>= 1, max_base++;
    root = 2;
    while(root.pow((mod - 1) >> 1) == 1) root += 1;
    assert(root.pow(mod - 1) == 1);
    dw.resize(max_base);
    idw.resize(max_base);
    for(int i = 0; i < max_base; i++) {
      dw[i] = -root.pow((mod - 1) >> (i + 2));
      idw[i] = Mint(1) / dw[i];
    }
  }

  void ntt(vector< Mint > &a) {
    const int n = (int) a.size();
    assert((n & (n - 1)) == 0);
    assert(__builtin_ctz(n) <= max_base);
    for(int m = n; m >>= 1;) {
      Mint w = 1;
      for(int s = 0, k = 0; s < n; s += 2 * m) {
        for(int i = s, j = s + m; i < s + m; ++i, ++j) {
          auto x = a[i], y = a[j] * w;
          a[i] = x + y, a[j] = x - y;
        }
        w *= dw[__builtin_ctz(++k)];
      }
    }
  }

  void intt(vector< Mint > &a, bool f = true) {
    const int n = (int) a.size();
    assert((n & (n - 1)) == 0);
    assert(__builtin_ctz(n) <= max_base);
    for(int m = 1; m < n; m *= 2) {
      Mint w = 1;
      for(int s = 0, k = 0; s < n; s += 2 * m) {
        for(int i = s, j = s + m; i < s + m; ++i, ++j) {
          auto x = a[i], y = a[j];
          a[i] = x + y, a[j] = (x - y) * w;
        }
        w *= idw[__builtin_ctz(++k)];
      }
    }
    if(f) {
      Mint inv_sz = Mint(1) / n;
      for(int i = 0; i < n; i++) a[i] *= inv_sz;
    }
  }

  vector< Mint > multiply(vector< Mint > a, vector< Mint > b) {
    int need = a.size() + b.size() - 1;
    int nbase = 1;
    while((1 << nbase) < need) nbase++;
    int sz = 1 << nbase;
    a.resize(sz, 0);
    b.resize(sz, 0);
    ntt(a);
    ntt(b);
    Mint inv_sz = Mint(1) / sz;
    for(int i = 0; i < sz; i++) a[i] *= b[i] * inv_sz;
    intt(a, false);
    a.resize(need);
    return a;
  }
};


template< int mod >
vector< int > AnyModNTTMultiply(vector< int > &a, vector< int > &b) {
  using mint = ModInt< mod >;
  using mint1 = ModInt< 1045430273 >;
  using mint2 = ModInt< 1051721729 >;
  using mint3 = ModInt< 1053818881 >;
  NumberTheoreticTransformFriendlyModInt< mint1 > ntt1;
  NumberTheoreticTransformFriendlyModInt< mint2 > ntt2;
  NumberTheoreticTransformFriendlyModInt< mint3 > ntt3;
  vector< mint1 > a1(begin(a), end(a)), b1(begin(b), end(b));
  vector< mint2 > a2(begin(a), end(a)), b2(begin(b), end(b));
  vector< mint3 > a3(begin(a), end(a)), b3(begin(b), end(b));
  auto x = ntt1.multiply(a1, b1);
  auto y = ntt2.multiply(a2, b2);
  auto z = ntt3.multiply(a3, b3);
  const int m1 = 1045430273, m2 = 1051721729, m3 = 1053818881;
  const auto m1_inv_m2 = mint2(m1).inverse().get();
  const auto m12_inv_m3 = (mint3(m1) * m2).inverse().get();
  const auto m12_mod = (mint(m1) * m2).get();
  vector< int > ret(x.size());
  for(int i = 0; i < x.size(); i++) {
    auto v1 = ((mint2(y[i]) + m2 - x[i].get()) * m1_inv_m2).get();
    auto v2 = ((z[i] + m3 - x[i].get() - mint3(m1) * v1) * m12_inv_m3).get();
    ret[i] = (mint(x[i].get()) + mint(m1) * v1 + mint(m12_mod) * v2).get();
  }
  return ret;
}

int main(){
    const constexpr int64_t p = 1e9 + 7;
    using mint = ModInt<p>;
    int n, m;
    cin >> n >> m;
    Binomial<mint> binom(m);

    vector<int> A(n + 1), B(n + 1);
    mint ans = 0;
    for (int k = 0; k <= n; k++){
        A[k] = (mint(k & 1 ? -1 : 1) * binom.f[n - k] * binom.invf[k]).get();
        B[k] = binom.invf[k].get();
    }

    auto C = AnyModNTTMultiply<p>(A, B);

    for (int l = 0; l <= n; l++)
        ans += mint(C[l]) * binom.invf[n - l].pow(2) * (m - 2 * n + l < 0 ? mint(0) : binom.invf[m - 2 * n + l]);

    cout << ans * binom.f[n] * binom.f[m] << endl;
}

Measured memory_bytes: 42916