#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++) #define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--) #define rirep(i, n) for (int64_t i = n; i >= 0; i--) #define chmax(a, b) (a) = max(a, b) #define chmin(a, b) (a) = min(a, b) template class Modint { using Self = Modint; int64_t m_value; public: Modint() : m_value(0) {} Modint(int64_t value) : m_value((value % MOD + MOD) % MOD) {} Self pow(int64_t e) const { if (e == 0) { return (Self)1; } else if (e % 2 == 0) { return ((*this) * (*this)).pow(e / 2); } else { return (*this).pow(e - 1) * (*this); } } Self inv() const { return pow(MOD - 2); } Self& operator=(const Self& rh) { m_value = rh.m_value; return *this; } Self operator-() const { return Self(-m_value); } Self operator+(const Self& other) const { return Self(m_value + other.m_value); } Self operator-(const Self& other) const { return Self(m_value - other.m_value); } Self operator*(const Self& other) const { return Self(m_value * other.m_value); } Self operator/(const Self& other) const { return (*this) * other.inv(); } Self& operator+=(const Self& rh) { return (*this) = (*this) + rh; } Self& operator-=(const Self& rh) { return (*this) = (*this) - rh; } Self& operator*=(const Self& rh) { return (*this) = (*this) * rh; } Self& operator/=(const Self& rh) { return (*this) = (*this) / rh; } int64_t value() const { return m_value; } }; int main() { int64_t N, M; cin >> N >> M; if (N < M) { cout << 0 << endl; return 0; } using Mint = Modint<1'000'000'007>; vector fact(M + 1); fact[0] = 1; rep(i, M) { fact[i + 1] = fact[i] * (i + 1); } Mint result = 0; irep(i, M) { Mint term = Mint(-1).pow(i) * fact[M] / (fact[i] * fact[M - i]) * Mint(M - i).pow(N); result += term; } cout << result.value() << endl; return 0; }