/* ---------- STL Libraries ---------- */ // IO library #include #include #include #include #include // algorithm library #include #include #include #include #include #include // container library #include #include #include #include #include #include #include #include #include #include #include // type #include #include /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll template using MaxHeap = priority_queue; template using MinHeap = priority_queue, greater>; #define P pair /* ---------- Constants */ const double PI = 3.141592653589793238462643383279; const ll MOD = 1e9 + 7; const int INF = 1LL << 55; /* ---------- Functions */ template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } /* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */ class Combination { int powmod(int a, int p) { int ans = 1; int mul = a; for (; p > 0; p >>= 1, mul = (mul * mul) % mod) { if ((p & 1) == 1) ans = (ans * mul) % mod; } return ans; } public: int N; int mod; vector fact; vector revFact; Combination(int n, int m) : N(n), mod(m), fact(n+1), revFact(n+1) { fact[0] = 1; for (int i = 1; i <= N; i++) { fact[i] = fact[i-1] * i; fact[i] %= mod; } // Fermat's little theorem revFact[N] = powmod(fact[N], mod - 2); for (int i = N-1; i >= 0; i--) { revFact[i] = revFact[i+1] * (i+1); revFact[i] %= mod; } } int get(int a, int b) { if (a < 0 || b < 0) return 0; if (b > a) return 0; return (((fact[a] * revFact[b]) % mod) * revFact[a-b]) % mod; } }; int powmod(int a, int p, int mod) { int ans = 1; int mul = a; for (; p > 0; p >>= 1, mul = (mul * mul) % mod) { if ((p & 1) == 1) ans = (ans * mul) % mod; } return ans; } signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int N, M; cin >> N >> M; auto comb = new Combination(2 * N, MOD); int ret= 0; for (int k = 0; k < M; k++) { int tmp = comb->get(M, k) * powmod(M-k, N, MOD) % MOD; if (k % 2 != 0) tmp *= -1; ret += MOD + tmp; ret %= MOD; } cout << ret << endl; return 0; }