#include #include using namespace std; using i64 = long long; struct FMT { static void fmt(const int, vector&); static void ifmt(const int, vector&); static void convol(const int, vector&, vector&); private: static constexpr i64 W = 3LL; static constexpr i64 M = 1224736769LL; static void myfmt(const int, vector&, const bool); }; tuple extgcd(const i64 x, const i64 y) { if(y == 0) { return make_tuple(1LL, 0LL, x); } i64 a, b, d; tie(a, b, d) = extgcd(y, x%y); return make_tuple(b, a-x/y*b, d); } i64 mod_inv(const i64 a, const i64 m) { i64 x, _, d; tie(x, _, d) = extgcd(a, m); return (x % m + m) % m; } i64 mod_pow(const i64 a, const i64 r, const i64 n, const i64 m) { if(n == 0) { return r; } if(n & 1) { return mod_pow(a, a*r%m, n-1, m); } return mod_pow(a*a%m, r, n>>1, m); } i64 mod_pow(const i64 a, const i64 n, const i64 m) { return mod_pow(a, 1, n, m); } void FMT::myfmt(const int logn, vector &a, const bool inv) { int n = 1 << logn; i64 base = mod_pow(W, (M-1) / n, M); if(inv) { base = mod_inv(base, M); } for(int m=n; m>=2; m>>=1, base=base*base%M) { i64 w = 1; for(int i=0, mh=m>>1; i>1; k>(i^=k); k>>=1) /* nop */ ; if(j > i) { swap(a[i], a[j]); } } } void FMT::fmt(const int logn, vector &a) { myfmt(logn, a, false); } void FMT::ifmt(const int logn, vector &a) { myfmt(logn, a, true); int n = 1 << logn; i64 inv = mod_inv(n, M); for(int i=0; i &a, vector &b) { fmt(logn, a); fmt(logn, b); for(int i=0; i<1<> L >> M >> N; int size = (N + 1) * 2; int m; for(m=0; 1< p(1<> x; p[x] = true; } for(int i=0; i> x; q[N-x] = true; } FMT::convol(m, p, q); cin >> Q; for(int v=0; v