結果
問題 | No.287 場合の数 |
ユーザー | Shaik Mulla Abeed Basha |
提出日時 | 2023-07-07 15:54:51 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 28,089 bytes |
コンパイル時間 | 6,991 ms |
コンパイル使用メモリ | 412,828 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-21 11:13:44 |
合計ジャッジ時間 | 7,438 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 4 ms
5,376 KB |
testcase_10 | AC | 4 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 4 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | AC | 4 ms
5,376 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | AC | 4 ms
5,376 KB |
testcase_18 | AC | 4 ms
5,376 KB |
testcase_19 | AC | 3 ms
5,376 KB |
testcase_20 | AC | 3 ms
5,376 KB |
testcase_21 | AC | 4 ms
5,376 KB |
testcase_22 | AC | 4 ms
5,376 KB |
testcase_23 | AC | 5 ms
5,376 KB |
testcase_24 | AC | 3 ms
5,376 KB |
ソースコード
#include <x86intrin.h> #include <bits/stdc++.h> using namespace std; using str = string; using ll = long long; using ld = long double; using u64 = unsigned long long; template<class T> using pr = pair<T, T>; template<class T> using vt = vector<T>; template<class T> using vvt = vector<vt<T>>; #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) #define r_each(x,a) for(auto& x:a | views::reverse) template<class T> constexpr T inf = 0; template<> constexpr int inf<int> = 1'000'000'005; template<> constexpr long long inf<long long> = (long long) (inf<int>) * inf<int> * 2; template<> constexpr unsigned int inf<unsigned int> = inf<int>; template<> constexpr unsigned long long inf<unsigned long long> = inf<long long>; template<> constexpr __int128 inf<__int128> = __int128(inf<long long>) * inf<long long>; template<> constexpr double inf<double> = inf<long long>; template<> constexpr long double inf<long double> = inf<long long>; template<class T, class S> inline bool ctmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); } template<class T, class S> inline bool ctmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); } template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << p.first << " " << p.second;return os;} template<typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) {is >> p.first >> p.second;return is;} template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) {int s = (int) v.size();for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];return os;} template<typename T> istream &operator>>(istream &is, vector<T> &v) {for (auto &x: v) is >> x;return is;} void read() {} template<typename T, class... U> void read(T &t, U &...u) {cin >> t;read(u...);} void print() { cout << "\n"; } template<typename T, class... U, char sep = ' '> void print(const T &t, const U &...u) {cout << t;if (sizeof...(u)) cout << sep;print(u...);} void write() { cout << " "; } template<typename T, class... U, char sep = ' '> 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<type> 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<typename T> inline int gbit(const T &a, int i) { return (a >> i) & 1; } template<typename T> 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; } template<typename T> vector<int> argsort(const vector<T> &A) { vector<int> ids((int) A.size()); iota(ids.begin(), ids.end(), 0); sort(ids.begin(), ids.end(), [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); }); return ids; } #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define LB(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define UB(c, x) distance((c).begin(), upper_bound(all(c), (x))) #define UNIQUE(x) \ sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit() namespace dbg{ // DEBUG BEGIN #ifndef ONLINE_JUDGE template<class L, class R> ostream &operator<<(ostream &out, const pair<L, R> &p){ return out << "{" << p.first << ", " << p.second << "}"; } template<class Tuple, size_t N> struct _tuple_printer{ static ostream &_print(ostream &out, const Tuple &t){ return _tuple_printer<Tuple, N-1>::_print(out, t) << ", " << get<N-1>(t); } }; template<class Tuple> struct _tuple_printer<Tuple, 1>{ static ostream &_print(ostream &out, const Tuple& t){ return out << get<0>(t); } }; template<class... Args> ostream &_print_tuple(ostream &out, const tuple<Args...> &t){ return _tuple_printer<decltype(t), sizeof...(Args)>::_print(out << "{", t) << "}"; } template<class ...Args> ostream &operator<<(ostream &out, const tuple<Args...> &t){ return _print_tuple(out, t); } template<class T> ostream &operator<<(class enable_if<!is_same<T, string>::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<class T, class A, class C> ostream &operator<<(ostream &out, priority_queue<T, A, C> pq){ vector<T> a; while(!pq.empty()) a.push_back(pq.top()), pq.pop(); return out << a; } template<class Head> void debug_out(Head H){ cerr << H << endl; } template<class Head, class... Tail> void debug_out(Head H, Tail... T){ cerr << H << ", ", debug_out(T...); } void debug2_out(){ } template<class Head, class... Tail> void debug2_out(Head H, Tail... T){ cerr << "\n"; for(auto x: H) cerr << x << ",\n"; debug2_out(T...); } template<class Width, class Head> void debugbin_out(Width w, Head H){ for(auto rep = w; rep; -- rep, H >>= 1) cerr << (H & 1); cerr << endl; } template<class Width, class Head, class... Tail> 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; // 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; } struct has_mod_impl { template <class T> static auto check(T &&x) -> decltype(x.get_mod(), std::true_type{}); template <class T> static auto check(...) -> std::false_type; }; template <class T> class has_mod : public decltype(has_mod_impl::check<T>(std::declval<T>())) {}; template <typename mint> mint inv(int n) { static const int mod = mint::get_mod(); static vector<mint> 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 <typename mint> mint fact(int n) { static const int mod = mint::get_mod(); assert(0 <= n); if (n >= mod) return 0; static vector<mint> dat = {1, 1}; while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * mint(len(dat))); return dat[n]; } template <typename mint> mint fact_inv(int n) { static vector<mint> dat = {1, 1}; if (n < 0) return mint(0); while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * inv<mint>(len(dat))); return dat[n]; } template <class mint, class... Ts> mint fact_invs(Ts... xs) { return (mint(1) * ... * fact_inv<mint>(xs)); } template <typename mint, class Head, class... Tail> mint multinomial(Head &&head, Tail &&... tail) { return fact<mint>(head) * fact_invs<mint>(std::forward<Tail>(tail)...); } template <typename mint> mint C_dense(int n, int k) { static vector<vector<mint>> 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 <typename mint, bool large = false, bool dense = false> mint C(long long n, long long k) { assert(n >= 0); if (k < 0 || n < k) return 0; if (dense) return C_dense<mint>(n, k); if (!large) return multinomial<mint>(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<mint>(k); } template <typename mint, bool large = false> mint C_inv(long long n, long long k) { assert(n >= 0); assert(0 <= k && k <= n); if (!large) return fact_inv<mint>(n) * fact<mint>(k) * fact<mint>(n - k); return mint(1) / C<mint, 1>(n, k); } // [x^d] (1-x) ^ {-n} の計算 template <typename mint, bool large = false, bool dense = false> 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<mint, large, dense>(n + d - 1, d); } // Requires modint_common.cpp template <int mod> 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<int, int> 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>; 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<C> rts = {{0, 0}, {1, 0}}; vector<int> 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<C>& 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 <class T> vector<T> convolution_naive(const vector<T>& a, const vector<T>& b) { int n = int(a.size()), m = int(b.size()); vector<T> 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 <class mint> void ntt(vector<mint>& a, bool inverse) { assert(mint::can_ntt()); const int rank2 = mint::ntt_info().first; const int mod = mint::get_mod(); static array<mint, 30> root, iroot; static array<mint, 30> rate2, irate2; static array<mint, 30> 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; } } } } template <class mint> vector<mint> convolution_ntt(vector<mint> a, vector<mint> 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 <typename mint> vector<mint> convolution_garner(const vector<mint>& a, const vector<mint>& 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<mint0> a0(n), b0(m); vector<mint1> a1(n), b1(m); vector<mint2> 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<mint0>(a0, b0); auto c1 = convolution_ntt<mint1>(a1, b1); auto c2 = convolution_ntt<mint2>(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<mint> 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 <typename R> vector<double> convolution_fft(const vector<R>& a, const vector<R>& 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<C> 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<double> ret(need); for (int i = 0; i < need; i++) { ret[i] = (i & 1 ? fa[i >> 1].y : fa[i >> 1].x); } return ret; } vector<long long> convolution(const vector<long long>& a, const vector<long long>& 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<double> c = convolution_fft<long long>(a, b); vector<long long> 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<MOD1>; using mint2 = modint<MOD2>; using mint3 = modint<MOD3>; vector<mint1> a1(n), b1(m); vector<mint2> a2(n), b2(m); vector<mint3> 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<mint1>(a1, b1); auto c2 = convolution_ntt<mint2>(a2, b2); auto c3 = convolution_ntt<mint3>(a3, b3); vector<long long> 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 <typename mint> vector<mint> convolution(const vector<mint>& a, const vector<mint>& 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); } signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); auto __solve_tc = [&](auto __tc_num) -> int { Int(n); vt<ll> poly(n+1,1); rep(3) poly= convolution(poly,poly); print(poly[6*n]); return 0; }; int __tc_cnt = 1; // cin >> __tc_cnt; for (auto __tc_num = 0; __tc_num < __tc_cnt; ++__tc_num) { __solve_tc(__tc_num); } }