#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 O = 3LL; static constexpr i64 M = 1224736769LL; static constexpr i64 N = M - 1; 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) { const int n = 1 << logn; for(int H=1, W=n>>1; H>=1) { vector y = a; i64 r = mod_pow(O, N/(H*2), M); if(inv) { r = mod_inv(r, M); } i64 w = 1; for(int k=0; k &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