#include #include using namespace std; using str = string; using ll = long long; using ld = long double; using u64 = unsigned long long; template using pr = pair; template using vt = vector; template using vvt = vector>; #define ar array #define pb push_back #define fi first #define se second #define all(c) (c).begin(), (c).end() #define len(x) (int)(x).size() #define elif else if #define def function #define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define rep(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define each(x, a) for (auto& x: a) template constexpr T inf = 0; template <> constexpr int inf = 1'000'000'005; template <> constexpr long long inf = (long long)(inf) * inf * 2; template <> constexpr unsigned int inf = inf; template <> constexpr unsigned long long inf = inf; template <> constexpr __int128 inf<__int128> = __int128(inf) * inf; template <> constexpr double inf = inf; template <> constexpr long double inf = inf; template inline bool ctmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); } template inline bool ctmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } template ostream &operator<<(ostream &os, const pair &p) { os << p.first << " " << p.second; return os; } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const vector &v) { int s = (int)v.size(); for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i]; return os; } template istream &operator>>(istream &is, vector &v) { for (auto &x : v) is >> x; return is; } void read() {} template void read(T &t, U &...u) { cin >> t; read(u...); } void print() { cout << "\n"; } template void print(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; print(u...); } void write() { cout << " "; } template void write(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; write(u...); } #define Int(...) \ int __VA_ARGS__; \ read(__VA_ARGS__) #define Ll(...) \ long long __VA_ARGS__; \ read(__VA_ARGS__) #define Str(...) \ string __VA_ARGS__; \ read(__VA_ARGS__) #define Vt(type, name, size) \ vector name(size); \ read(name) #define Die(...) \ do { \ print(__VA_ARGS__); \ return 0; \ } while (0) __attribute__((target("popcnt"))) inline int popcnt(const u64 &a) { return _mm_popcnt_u64(a); } inline int lsb(const u64 &a) { return a ? __builtin_ctzll(a) : 64; } inline int ctz(const u64 &a) { return a ? __builtin_ctzll(a) : 64; } inline int msb(const u64 &a) { return a ? 63 - __builtin_clzll(a) : -1; } template inline int gbit(const T &a, int i) { return (a >> i) & 1; } template inline void sbit(T &a, int i, bool b) { if (gbit(a, i) != b) a ^= T(1) << i; } constexpr long long Pw(int n) { return 1LL << n; } constexpr long long Msk(int n) { return (1LL << n) - 1; } struct has_mod_impl { template static auto check(T &&x) -> decltype(x.get_mod(), std::true_type{}); template static auto check(...) -> std::false_type; }; template class has_mod : public decltype(has_mod_impl::check(std::declval())) {}; template mint inv(int n) { static const int mod = mint::get_mod(); static vector dat = {0, 1}; assert(0 <= n); if (n >= mod) n %= mod; while (len(dat) <= n) { int k = len(dat); int q = (mod + k - 1) / k; dat.eb(dat[k * q - mod] * mint(q)); } return dat[n]; } template mint fact(int n) { static const int mod = mint::get_mod(); assert(0 <= n); if (n >= mod) return 0; static vector dat = {1, 1}; while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * mint(len(dat))); return dat[n]; } template mint fact_inv(int n) { static vector dat = {1, 1}; if (n < 0) return mint(0); while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * inv(len(dat))); return dat[n]; } template mint fact_invs(Ts... xs) { return (mint(1) * ... * fact_inv(xs)); } template mint multinomial(Head &&head, Tail &&... tail) { return fact(head) * fact_invs(std::forward(tail)...); } template mint C_dense(int n, int k) { static vector> C; static int H = 0, W = 0; auto calc = [&](int i, int j) -> mint { if (i == 0) return (j == 0 ? mint(1) : mint(0)); return C[i - 1][j] + (j ? C[i - 1][j - 1] : 0); }; if (W <= k) { for(int i = 0; i < H; i++) { C[i].resize(k + 1); for(int j = W; j < k + 1; j++) { C[i][j] = calc(i, j); } } W = k + 1; } if (H <= n) { C.resize(n + 1); for(int i = H; i < n + 1; i++) { C[i].resize(W); for(int j = 0; j < W; j++) { C[i][j] = calc(i, j); } } H = n + 1; } return C[n][k]; } template mint C(long long n, long long k) { assert(n >= 0); if (k < 0 || n < k) return 0; if (dense) return C_dense(n, k); if (!large) return multinomial(n, k, n - k); k = min(k, n - k); mint x(1); for(int i = 0; i < k; i++) x *= mint(n - i); return x * fact_inv(k); } template mint C_inv(long long n, long long k) { assert(n >= 0); assert(0 <= k && k <= n); if (!large) return fact_inv(n) * fact(k) * fact(n - k); return mint(1) / C(n, k); } // [x^d] (1-x) ^ {-n} の計算 template mint C_negative(long long n, long long d) { assert(n >= 0); if (d < 0) return mint(0); if (n == 0) { return (d == 0 ? mint(1) : mint(0)); } return C(n + d - 1, d); } template struct modint { static_assert(mod < (1 << 30)); int val; constexpr modint(const long long val = 0) noexcept : val(val >= 0 ? val % mod : (mod - (-val) % mod) % mod) {} bool operator<(const modint &other) const { return val < other.val; } // To use std::map modint &operator+=(const modint &p) { if ((val += p.val) >= mod) val -= mod; return *this; } modint &operator-=(const modint &p) { if ((val += mod - p.val) >= mod) val -= mod; return *this; } modint &operator*=(const modint &p) { val = (int)(1LL * val * p.val % mod); return *this; } modint &operator/=(const modint &p) { *this *= p.inverse(); return *this; } modint operator-() const { return modint(-val); } modint operator+(const modint &p) const { return modint(*this) += p; } modint operator-(const modint &p) const { return modint(*this) -= p; } modint operator*(const modint &p) const { return modint(*this) *= p; } modint operator/(const modint &p) const { return modint(*this) /= p; } bool operator==(const modint &p) const { return val == p.val; } bool operator!=(const modint &p) const { return val != p.val; } modint inverse() const { int a = val, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b), swap(u -= t * v, v); } return modint(u); } modint pow(long long n) const { assert(n >= 0); modint ret(1), mul(val); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } void write() { write(val); } void read() { read(val); val = (val >= 0 ? val % mod : (mod - (-val) % mod) % mod); } static constexpr int get_mod() { return mod; } // (n, r), r は 1 の 2^n 乗根 static constexpr pair ntt_info() { if (mod == 167772161) return {25, 17}; if (mod == 469762049) return {26, 30}; if (mod == 754974721) return {24, 362}; if (mod == 880803841) return {23, 211}; if (mod == 998244353) return {23, 31}; if (mod == 1045430273) return {20, 363}; if (mod == 1051721729) return {20, 330}; if (mod == 1053818881) return {20, 2789}; return {-1, -1}; } static constexpr bool can_ntt() { return ntt_info().first != -1; } }; using modint107 = modint<1000000007>; using modint998 = modint<998244353>; // long でも大丈夫 // (val * x - 1) が mod の倍数になるようにする // 特に mod=0 なら x=0 が満たす long long mod_inv(long long val, long long mod) { if (mod == 0) return 0; mod = abs(mod); val %= mod; if (val < 0) val += mod; long long a = val, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b), swap(u -= t * v, v); } if (u < 0) u += mod; return u; } template vector convolution_naive(const vector& a, const vector& b) { int n = int(a.size()), m = int(b.size()); vector ans(n + m - 1); if (n < m) { for(int j = 0; j < m; j++) for(int i = 0; i < n; i++) ans[i + j] += a[i] * b[j]; } else { for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) ans[i + j] += a[i] * b[j]; } return ans; } template void ntt(vector& a, bool inverse) { assert(mint::can_ntt()); const int rank2 = mint::ntt_info().first; const int mod = mint::get_mod(); static array root, iroot; static array rate2, irate2; static array rate3, irate3; static bool prepared = 0; if (!prepared) { prepared = 1; root[rank2] = mint::ntt_info().second; iroot[rank2] = mint(1) / root[rank2]; for(int i = rank2 - 1; i >= 0; i--) { root[i] = root[i + 1] * root[i + 1]; iroot[i] = iroot[i + 1] * iroot[i + 1]; } mint prod = 1, iprod = 1; for (int i = 0; i <= rank2 - 2; i++) { rate2[i] = root[i + 2] * prod; irate2[i] = iroot[i + 2] * iprod; prod *= iroot[i + 2]; iprod *= root[i + 2]; } prod = 1, iprod = 1; for (int i = 0; i <= rank2 - 3; i++) { rate3[i] = root[i + 3] * prod; irate3[i] = iroot[i + 3] * iprod; prod *= iroot[i + 3]; iprod *= root[i + 3]; } } int n = int(a.size()); int h = (n == 0 ? -1 : 31 - __builtin_clz(n)); assert(n == 1 << h); if (!inverse) { int len = 0; while (len < h) { if (h - len == 1) { int p = 1 << (h - len - 1); mint rot = 1; for(int s = 0; s < 1 << len; s++) { int offset = s << (h - len); for(int i = 0; i < p; i++) { auto l = a[i + offset]; auto r = a[i + offset + p] * rot; a[i + offset] = l + r; a[i + offset + p] = l - r; } rot *= rate2[((~s & -~s) == 0 ? -1 : 31 - __builtin_clz(~s & -~s))]; } len++; } else { int p = 1 << (h - len - 2); mint rot = 1, imag = root[2]; for (int s = 0; s < (1 << len); s++) { mint rot2 = rot * rot; mint rot3 = rot2 * rot; int offset = s << (h - len); for (int i = 0; i < p; i++) { unsigned long long mod2 = (unsigned long long)(mod) * mod; unsigned long long a0 = a[i + offset].val; unsigned long long a1 = (unsigned long long)(a[i + offset + p].val) * rot.val; unsigned long long a2 = (unsigned long long)(a[i + offset + 2 * p].val) * rot2.val; unsigned long long a3 = (unsigned long long)(a[i + offset + 3 * p].val) * rot3.val; unsigned long long a1na3imag = (a1 + mod2 - a3) % mod * imag.val; unsigned long long na2 = mod2 - a2; a[i + offset] = a0 + a2 + a1 + a3; a[i + offset + 1 * p] = a0 + a2 + (2 * mod2 - (a1 + a3)); a[i + offset + 2 * p] = a0 + na2 + a1na3imag; a[i + offset + 3 * p] = a0 + na2 + (mod2 - a1na3imag); } rot *= rate3[((~s & -~s) == 0 ? -1 : 31 - __builtin_clz(~s & -~s))]; } len += 2; } } } else { mint coef = mint(1) / mint((int) a.size()); for(int i = 0; i < (int) a.size(); i++) a[i] *= coef; int len = h; while (len) { if (len == 1) { int p = 1 << (h - len); mint irot = 1; for(int s = 0; s < 1 << (len - 1); s++) { int offset = s << (h - len + 1); for(int i = 0; i < p; i++) { unsigned long long l = a[i + offset].val; unsigned long long r = a[i + offset + p].val; a[i + offset] = l + r; a[i + offset + p] = (mod + l - r) * irot.val; } irot *= irate2[((~s & -~s) == 0 ? -1 : 31 - __builtin_clz(~s & -~s))]; } len--; } else { int p = 1 << (h - len); mint irot = 1, iimag = iroot[2]; for(int s = 0; s < (1 << (len - 2)); s++) { mint irot2 = irot * irot; mint irot3 = irot2 * irot; int offset = s << (h - len + 2); for (int i = 0; i < p; i++) { unsigned long long a0 = a[i + offset + 0 * p].val; unsigned long long a1 = a[i + offset + 1 * p].val; unsigned long long a2 = a[i + offset + 2 * p].val; unsigned long long a3 = a[i + offset + 3 * p].val; unsigned long long x = (mod + a2 - a3) * iimag.val % mod; a[i + offset] = a0 + a1 + a2 + a3; a[i + offset + 1 * p] = (a0 + mod - a1 + x) * irot.val; a[i + offset + 2 * p] = (a0 + a1 + 2 * mod - a2 - a3) * irot2.val; a[i + offset + 3 * p] = (a0 + 2 * mod - a1 - x) * irot3.val; } irot *= irate3[((~s & -~s) == 0 ? -1 : 31 - __builtin_clz(~s & -~s))]; } len -= 2; } } } } namespace CFFT { using real = double; struct C { real x, y; C() : x(0), y(0) {} C(real x, real y) : x(x), y(y) {} inline C operator+(const C& c) const { return C(x + c.x, y + c.y); } inline C operator-(const C& c) const { return C(x - c.x, y - c.y); } inline C operator*(const C& c) const { return C(x * c.x - y * c.y, x * c.y + y * c.x); } inline C conj() const { return C(x, -y); } }; const real PI = acosl(-1); int base = 1; vector rts = {{0, 0}, {1, 0}}; vector rev = {0, 1}; void ensure_base(int nbase) { if (nbase <= base) return; rev.resize(1 << nbase); rts.resize(1 << nbase); for (int i = 0; i < (1 << nbase); i++) { rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1)); } while (base < nbase) { real angle = PI * 2.0 / (1 << (base + 1)); for (int i = 1 << (base - 1); i < (1 << base); i++) { rts[i << 1] = rts[i]; real angle_i = angle * (2 * i + 1 - (1 << base)); rts[(i << 1) + 1] = C(cos(angle_i), sin(angle_i)); } ++base; } } void fft(vector& a, int n) { assert((n & (n - 1)) == 0); int zeros = __builtin_ctz(n); ensure_base(zeros); int shift = base - zeros; for (int i = 0; i < n; i++) { if (i < (rev[i] >> shift)) { swap(a[i], a[rev[i] >> shift]); } } for (int k = 1; k < n; k <<= 1) { for (int i = 0; i < n; i += 2 * k) { for (int j = 0; j < k; j++) { C z = a[i + j + k] * rts[j + k]; a[i + j + k] = a[i + j] - z; a[i + j] = a[i + j] + z; } } } } } // namespace CFFT template vector convolution_ntt(vector a, vector b) { if (a.empty() || b.empty()) return {}; int n = int(a.size()), m = int(b.size()); int sz = 1; while (sz < n + m - 1) sz *= 2; // sz = 2^k のときの高速化。分割統治的なやつで損しまくるので。 if ((n + m - 3) <= sz / 2) { auto a_last = a.back(), b_last = b.back(); a.pop_back(), b.pop_back(); auto c = convolution(a, b); c.resize(n + m - 1); c[n + m - 2] = a_last * b_last; for(int i = 0; i < (int) a.size(); i++) c[i + (int) b.size()] += a[i] * b_last; for(int i = 0; i < (int) b.size(); i++) c[i + (int) a.size()] += b[i] * a_last; return c; } a.resize(sz), b.resize(sz); bool same = a == b; ntt(a, 0); if (same) { b = a; } else { ntt(b, 0); } for(int i = 0; i < sz; i++) a[i] *= b[i]; ntt(a, 1); a.resize(n + m - 1); return a; } template vector convolution_garner(const vector& a, const vector& b) { int n = (int) a.size(), m = (int) b.size(); if (!n || !m) return {}; static const long long nttprimes[] = {754974721, 167772161, 469762049}; using mint0 = modint<754974721>; using mint1 = modint<167772161>; using mint2 = modint<469762049>; vector a0(n), b0(m); vector a1(n), b1(m); vector a2(n), b2(m); for(int i = 0; i < n; i++) a0[i] = a[i].val, a1[i] = a[i].val, a2[i] = a[i].val; for(int i = 0; i < m; i++) b0[i] = b[i].val, b1[i] = b[i].val, b2[i] = b[i].val; auto c0 = convolution_ntt(a0, b0); auto c1 = convolution_ntt(a1, b1); auto c2 = convolution_ntt(a2, b2); static const long long m01 = 1LL * nttprimes[0] * nttprimes[1]; static const long long m0_inv_m1 = mint1(nttprimes[0]).inverse().val; static const long long m01_inv_m2 = mint2(m01).inverse().val; const int mod = mint::get_mod(); auto garner = [&](mint0 x0, mint1 x1, mint2 x2) -> mint { int r0 = x0.val, r1 = x1.val, r2 = x2.val; int v1 = (m0_inv_m1 * (r1 + nttprimes[1] - r0)) % nttprimes[1]; auto v2 = (mint2(r2) - r0 - mint2(nttprimes[0]) * v1) * mint2(m01_inv_m2); return mint(r0 + 1LL * nttprimes[0] * v1 + m01 % mod * v2.val); }; vector c((int) c0.size()); for(int i = 0; i < (int) c.size(); i++) c[i] = garner(c0[i], c1[i], c2[i]); return c; } template vector convolution_fft(const vector& a, const vector& b) { using C = CFFT::C; int need = (int)a.size() + (int)b.size() - 1; int nbase = 1; while ((1 << nbase) < need) nbase++; CFFT::ensure_base(nbase); int sz = 1 << nbase; vector fa(sz); for (int i = 0; i < sz; i++) { int x = (i < (int)a.size() ? a[i] : 0); int y = (i < (int)b.size() ? b[i] : 0); fa[i] = C(x, y); } CFFT::fft(fa, sz); C r(0, -0.25 / (sz >> 1)), s(0, 1), t(0.5, 0); for (int i = 0; i <= (sz >> 1); i++) { int j = (sz - i) & (sz - 1); C z = (fa[j] * fa[j] - (fa[i] * fa[i]).conj()) * r; fa[j] = (fa[i] * fa[i] - (fa[j] * fa[j]).conj()) * r; fa[i] = z; } for (int i = 0; i < (sz >> 1); i++) { C A0 = (fa[i] + fa[i + (sz >> 1)]) * t; C A1 = (fa[i] - fa[i + (sz >> 1)]) * t * CFFT::rts[(sz >> 1) + i]; fa[i] = A0 + A1 * s; } CFFT::fft(fa, sz >> 1); vector ret(need); for (int i = 0; i < need; i++) { ret[i] = (i & 1 ? fa[i >> 1].y : fa[i >> 1].x); } return ret; } vector convolution(const vector& a, const vector& b) { int n = (int) a.size(), m = (int) b.size(); if (!n || !m) return {}; if (min(n, m) <= 60) return convolution_naive(a, b); long long abs_sum_a = 0, abs_sum_b = 0; long long LIM = 1e15; for(int i = 0; i < n; i++) abs_sum_a = min(LIM, abs_sum_a + abs(a[i])); for(int i = 0; i < m; i++) abs_sum_b = min(LIM, abs_sum_b + abs(b[i])); if (__int128(abs_sum_a) * abs_sum_b < 1e15) { vector c = convolution_fft(a, b); vector res((int) c.size()); for(int i = 0; i < (int) c.size(); i++) res[i] = (long long)(floor(c[i] + .5)); return res; } static constexpr unsigned long long MOD1 = 754974721; // 2^24 static constexpr unsigned long long MOD2 = 167772161; // 2^25 static constexpr unsigned long long MOD3 = 469762049; // 2^26 static constexpr unsigned long long M2M3 = MOD2 * MOD3; static constexpr unsigned long long M1M3 = MOD1 * MOD3; static constexpr unsigned long long M1M2 = MOD1 * MOD2; static constexpr unsigned long long M1M2M3 = MOD1 * MOD2 * MOD3; static const unsigned long long i1 = mod_inv(MOD2 * MOD3, MOD1); static const unsigned long long i2 = mod_inv(MOD1 * MOD3, MOD2); static const unsigned long long i3 = mod_inv(MOD1 * MOD2, MOD3); using mint1 = modint; using mint2 = modint; using mint3 = modint; vector a1(n), b1(m); vector a2(n), b2(m); vector a3(n), b3(m); for(int i = 0; i < n; i++) a1[i] = a[i], a2[i] = a[i], a3[i] = a[i]; for(int i = 0; i < m; i++) b1[i] = b[i], b2[i] = b[i], b3[i] = b[i]; auto c1 = convolution_ntt(a1, b1); auto c2 = convolution_ntt(a2, b2); auto c3 = convolution_ntt(a3, b3); vector c(n + m - 1); for(int i = 0; i < n + m - 1; i++) { unsigned long long x = 0; x += (c1[i].val * i1) % MOD1 * M2M3; x += (c2[i].val * i2) % MOD2 * M1M3; x += (c3[i].val * i3) % MOD3 * M1M2; long long diff = c1[i].val - ((long long)(x) % (long long)(MOD1)); if (diff < 0) diff += MOD1; static constexpr unsigned long long offset[5] = {0, 0, M1M2M3, 2 * M1M2M3, 3 * M1M2M3}; x -= offset[diff % 5]; c[i] = x; } return c; } template vector convolution(const vector& a, const vector& b) { int n = (int) a.size(), m = (int) b.size(); if (!n || !m) return {}; if (mint::can_ntt()) { if (min(n, m) <= 50) return convolution_naive(a, b); return convolution_ntt(a, b); } if (min(n, m) <= 200) return convolution_naive(a, b); return convolution_garner(a, b); } namespace dbg{ // DEBUG BEGIN #ifndef ONLINE_JUDGE template ostream &operator<<(ostream &out, const pair &p){ return out << "{" << p.first << ", " << p.second << "}"; } template struct _tuple_printer{ static ostream &_print(ostream &out, const Tuple &t){ return _tuple_printer::_print(out, t) << ", " << get(t); } }; template struct _tuple_printer{ static ostream &_print(ostream &out, const Tuple& t){ return out << get<0>(t); } }; template ostream &_print_tuple(ostream &out, const tuple &t){ return _tuple_printer::_print(out << "{", t) << "}"; } template ostream &operator<<(ostream &out, const tuple &t){ return _print_tuple(out, t); } template ostream &operator<<(class enable_if::value, ostream>::type &out, const T &arr){ if(arr.empty()) return out << "{}"; out << "{"; for(auto it = arr.begin(); it != arr.end(); ++ it){ out << *it; next(it) != arr.end() ? out << ", " : out << "}"; } return out; } ostream &operator<<(ostream &out, const _Bit_reference &bit){ return out << bool(bit); } template ostream &operator<<(ostream &out, priority_queue pq){ vector a; while(!pq.empty()) a.push_back(pq.top()), pq.pop(); return out << a; } template void debug_out(Head H){ cerr << H << endl; } template void debug_out(Head H, Tail... T){ cerr << H << ", ", debug_out(T...); } void debug2_out(){ } template void debug2_out(Head H, Tail... T){ cerr << "\n"; for(auto x: H) cerr << x << ",\n"; debug2_out(T...); } template void debugbin_out(Width w, Head H){ for(auto rep = w; rep; -- rep, H >>= 1) cerr << (H & 1); cerr << endl; } template void debugbin_out(Width w, Head H, Tail... T){ for(auto rep = w; rep; -- rep, H >>= 1) cerr << (H & 1); cerr << ", "; debugbin_out(w, T...); } enum CODE{ CCRED = 31, CCGREEN = 32, CCYELLOW = 33, CCBLUE = 34, CCDEFAULT = 39 }; #define debug_endl() cerr << endl #define debug(...) cerr << "\033[" << (int)CODE(CCRED) << "m[" << #__VA_ARGS__ << "]: \033[" << (int)CODE(CCBLUE) << "m", debug_out(__VA_ARGS__), cerr << "\33[" << (int)CODE(CCDEFAULT) << "m" #define debug2(...) cerr << "\033[" << (int)CODE(CCRED) << "m[" << #__VA_ARGS__ << "] \033[" << (int)CODE(CCBLUE) << "m", debug2_out(__VA_ARGS__), cerr << "\33[" << (int)CODE(CCDEFAULT) << "m" #define debugbin(...) cerr << "\033[" << (int)CODE(CCRED) << "m[" << #__VA_ARGS__ << "] \033[" << (int)CODE(CCBLUE) << "m", debugbin_out(__VA_ARGS__), cerr << "\33[" << (int)CODE(CCDEFAULT) << "m" #else #define debug_endl() 42 #define debug(...) 42 #define debug2(...) 42 #define debugbin(...) 42 #endif // DEBUG END } using namespace dbg; signed main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); auto __solve_tc = [&](auto __tc_num)->int { Ll(n, m); Vt(ll, a, n); int mx = -1; each(x, a) ctmax(mx, x); int lim = mx + 1; vt poly(lim); each(x, a) poly[x] += 1; auto ret = convolution(poly, poly); if (m >= len(ret)) Die(0); print(ret[m]); return 0; }; int __tc_cnt = 1; for(auto __tc_num = 0; __tc_num < __tc_cnt; ++ __tc_num){ __solve_tc(__tc_num); } }