namespace GMS { template ll pow(ll a, ll b) { static_assert(mod <= (ll)2e9, "mod should be less than 2e9"); a %= mod; ll ret = 1; while(b != 0) { if(b&1) ret = ret*a%mod; a = a*a%mod; b>>=1; } return ret; } template void ntt(vector &a, bool inv = false) { static_assert(mod <= (ll)2e9, "mod should be less than 2e9"); int n = a.size(), j = 0; assert((n & -n) == n); assert((mod-1)%n == 0); for(int i=1; i> 1); while(j >= bit){ j -= bit; bit >>= 1; } j += bit; if(i < j) swap(a[i], a[j]); } static vector root[30], iroot[30]; for(int st=1; (1<(w, (mod-1)/(1<(w, (mod-1)/(1<(t, mod-2); iroot[st].pb(1); for(int i=1; i<(1<<(st-1)); i++) iroot[st].pb(iroot[st].back()*t%mod); } } vector* r = (inv?root:iroot); for(int st = 1; (1<(n, mod-2); for(int i=0; i vl conv(vl A, vl B) { int n = A.size(), m = B.size(); int t = 1; while(t < n+m-1) t*=2; A.resize(t); B.resize(t); ntt(A); ntt(B); fors(i, 0, t-1) A[i] = A[i]*B[i]%mod; ntt(A, true); A.resize(n+m-1); return A; } } // namespace GMS