struct mint {
int x;
mint() {x = 0; }
mint(int _x) {x = _x; }
friend mint operator + (const mint a, const mint b) {return (a.x + b.x) % P; }
friend mint operator - (const mint a, const mint b) {return (a.x - b.x + P) % P; }
friend mint operator * (const mint a, const mint b) {return 1ll * a.x * b.x % P; }
friend mint operator ^ (mint a, int b) {
mint c(1);
for(; b; b >>= 1, a = a * a) if(b & 1) c = c * a;
return c;
}
friend mint operator / (mint a, mint b) {return a * (b ^ (P - 2)); }
friend void operator += (mint &a, const mint b) {a = a + b; }
friend void operator -= (mint &a, const mint b) {a = a - b; }
friend void operator *= (mint &a, const mint b) {a = a * b; }
friend void operator /= (mint &a, const mint b) {a = a / b; }
} fac[N], ifac[N], inv[N];
void initmath(int n) {
inv[1] = fac[0] = ifac[0] = 1;
for(int i = 2; i <= n; i++) inv[i] = inv[P % i] * (P - P / i);
for(int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i, ifac[i] = ifac[i - 1] * inv[i];
return;
}
mint binom(int n, int m) {return n < m || m < 0 ? 0 : fac[n] * ifac[m] * ifac[n - m]; }