#line 2 "library/template/template.hpp" #include #line 3 "library/template/alias.hpp" using ll = long long; using ull = unsigned long long; using ld = long double; using i128 = __int128_t; using u128 = __uint128_t; using pi = std::pair; using pl = std::pair; using vi = std::vector; using vl = std::vector; using vs = std::vector; using vc = std::vector; using vvl = std::vector; using vd = std::vector; using vp = std::vector; using vb = std::vector; template struct infinity { static constexpr T max = std::numeric_limits::max(); static constexpr T min = std::numeric_limits::min(); static constexpr T value = std::numeric_limits::max() / 2; static constexpr T mvalue = std::numeric_limits::min() / 2; }; template constexpr T INF = infinity::value; constexpr ll inf = INF; constexpr ld EPS = 1e-8; constexpr ld PI = 3.1415926535897932384626; constexpr int dx[8] = {-1, 0, 1, 0, 1, -1, -1, 1}; constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; #line 3 "library/template/macro.hpp" #ifndef __COUNTER__ #define __COUNTER__ __LINE__ #endif #define SELECT4(a, b, c, d, e, ...) e #define SELECT3(a, b, c, d, ...) d #define REP_1(a, c) for (ll REP_##c = 0; REP_##c < (ll)(a); ++REP_##c) #define REP1(a) REP_1(a, __COUNTER__) #define REP2(i, a) for (ll i = 0; i < (ll)(a); ++i) #define REP3(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i) #define REP4(i, a, b, c) for (ll i = (ll)(a); i < (ll)(b); i += (ll)(c)) #define rep(...) SELECT4(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__) #define RREP_1(a, c) for (ll RREP_##c = (ll)(a) - 1; RREP_##c >= 0; --RREP_##c) #define RREP1(a) RREP_1(a, __COUNTER__) #define RREP2(i, a) for (ll i = (ll)(a) - 1; i >= 0; --i) #define RREP3(i, a, b) for (ll i = (ll)(b) - 1; i >= (ll)(a); --i) #define rrep(...) SELECT3(__VA_ARGS__, RREP3, RREP2, RREP1)(__VA_ARGS__) #define all(v) std::begin(v), std::end(v) #define rall(v) std::rbegin(v), std::rend(v) #define INT(...) \ int __VA_ARGS__; \ scan(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ scan(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ scan(__VA_ARGS__) #define CHR(...) \ char __VA_ARGS__; \ scan(__VA_ARGS__) #define DBL(...) \ double __VA_ARGS__; \ scan(__VA_ARGS__) #define LD(...) \ ld __VA_ARGS__; \ scan(__VA_ARGS__) #define pb push_back #define eb emplace_back #line 3 "library/template/type-traits.hpp" #line 5 "library/template/type-traits.hpp" template struct function_traits_impl { using return_type = T; static constexpr std::size_t arg_size = sizeof...(Args); template using argument_type = typename std::tuple_element>::type; using argument_types = std::tuple; }; template struct function_traits_helper; template struct function_traits_helper : function_traits_impl {}; template struct function_traits_helper : function_traits_impl {}; template struct function_traits_helper : function_traits_impl {}; template struct function_traits_helper : function_traits_impl {}; template using function_traits = function_traits_helper::type::operator())>; template using function_return_type = typename function_traits::return_type; template using function_argument_type = typename function_traits::template argument_type; template using function_argument_types = typename function_traits::argument_types; template using is_signed_int = std::integral_constant::value && std::is_signed::value) || std::is_same::value>; template using is_unsigned_int = std::integral_constant::value && std::is_unsigned::value) || std::is_same::value>; template using is_int = std::integral_constant::value || is_unsigned_int::value>; template struct is_range : std::false_type {}; template struct is_range< T, decltype(all(std::declval::type>()), (void)0)> : std::true_type {}; template struct int_least { static_assert(size <= 128, "size must be less than or equal to 128"); using type = typename std::conditional< size <= 8, std::int_least8_t, typename std::conditional< size <= 16, std::int_least16_t, typename std::conditional< size <= 32, std::int_least32_t, typename std::conditional::type>::type>::type>::type; }; template using int_least_t = typename int_least::type; template struct uint_least { static_assert(size <= 128, "size must be less than or equal to 128"); using type = typename std::conditional< size <= 8, std::uint_least8_t, typename std::conditional< size <= 16, std::uint_least16_t, typename std::conditional< size <= 32, std::uint_least32_t, typename std::conditional::type>::type>::type>::type; }; template using uint_least_t = typename uint_least::type; template using double_size_int = int_least::digits * 2 + 1>; template using double_size_int_t = typename double_size_int::type; template using double_size_uint = uint_least::digits * 2>; template using double_size_uint_t = typename double_size_uint::type; template using double_size = typename std::conditional::value, double_size_int, double_size_uint>::type; template using double_size_t = typename double_size::type; #line 2 "library/template/in.hpp" #include #line 5 "library/template/in.hpp" namespace fastio { template struct Scanner { private: template struct has_scan : std::false_type {}; template struct has_scan().scan(std::declval()), (void)0)> : std::true_type {}; int fd; char buffer[BUFF_SIZE + 1]; int idx, sz; bool state; inline void load() { int len = sz - idx; if (idx < len) return; std::memcpy(buffer, buffer + idx, len); sz = len + read(fd, buffer + len, BUFF_SIZE - len); idx = 0; buffer[sz] = 0; } inline char cur() { if (idx == sz) load(); if (idx == sz) { state = false; return '\0'; } return buffer[idx]; } inline void next() { if (idx == sz) load(); if (idx == sz) return; idx++; } public: Scanner() : Scanner(0) {} explicit Scanner(int fd) : fd(fd), idx(0), sz(0), state(true) {} explicit Scanner(FILE* file) : fd(fileno(file)), idx(0), sz(0), state(true) {} inline char scan_char() { if (idx == sz) load(); return (idx == sz ? '\0' : buffer[idx++]); } Scanner ignore(int n = 1) { if (idx + n > sz) load(); idx += n; return (*this); } inline void skip_space() { if (idx == sz) load(); while (('\t' <= cur() && cur() <= '\r') || cur() == ' ') { if (++idx == sz) load(); } } void scan(char& a) { skip_space(); a = scan_char(); } void scan(std::string& a) { skip_space(); a.clear(); while (cur() != '\0' && (buffer[idx] < '\t' || '\r' < buffer[idx]) && buffer[idx] != ' ') { a += scan_char(); } } template void scan(std::bitset& a) { skip_space(); if (idx + len > sz) load(); rrep(i, len) a[i] = (buffer[idx++] != '0'); } template ::value && !has_scan::value>::type* = nullptr> void scan(T& a) { skip_space(); bool neg = false; if constexpr (std::is_signed::value || std::is_same_v) { if (cur() == '-') { neg = true; next(); } } if (idx + 40 > sz && (idx == sz || ('0' <= buffer[sz - 1] && buffer[sz - 1] <= '9'))) load(); a = 0; while ('0' <= buffer[idx] && buffer[idx] <= '9') { a = a * 10 + (buffer[idx++] & 15); } if constexpr (std::is_signed::value || std::is_same::value) { if (neg) a = -a; } } template ::value && !has_scan::value>::type* = nullptr> void scan(T& a) { skip_space(); bool neg = false; if (cur() == '-') { neg = true; next(); } a = 0; while ('0' <= cur() && cur() <= '9') { a = a * 10 + (scan_char() & 15); } if (cur() == '.') { next(); T n = 0, d = 1; for (int i = 0; '0' <= cur() && cur() <= '9' && i < decimal_precision; ++i) { n = n * 10 + (scan_char() & 15); d *= 10; } while ('0' <= cur() && cur() <= '9') next(); a += n / d; } if (neg) a = -a; } private: template void scan(std::tuple& a) { if constexpr (i < sizeof...(Args)) { scan(std::get(a)); scan(a); } } public: template void scan(std::tuple& a) { scan<0, Args...>(a); } template void scan(std::pair& a) { scan(a.first); scan(a.second); } template ::value && !has_scan::value>::type* = nullptr> void scan(T& a) { for (auto& i : a) scan(i); } template ::value>::type* = nullptr> void scan(T& a) { a.scan(*this); } void operator()() {} template void operator()(Head& head, Tail&... tail) { scan(head); operator()(std::forward(tail)...); } template Scanner& operator>>(T& a) { scan(a); return *this; } explicit operator bool() const { return state; } friend Scanner& getline(Scanner& sc, std::string& a) { a.clear(); char c; if ((c = sc.scan_char()) == '\0' || c == '\n') return sc; a += c; while ((c = sc.scan_char()) != '\0' && c != '\n') a += c; return sc; } }; Scanner<> sc; } // namespace fastio using fastio::sc; #line 6 "library/template/out.hpp" namespace fastio { struct Pre { char buffer[10000][4]; constexpr Pre() : buffer() { for (int i = 0; i < 10000; ++i) { int n = i; for (int j = 3; j >= 0; --j) { buffer[i][j] = n % 10 | '0'; n /= 10; } } } } constexpr pre; template struct Printer { private: template struct has_print : std::false_type {}; template struct has_print().print(std::declval()), (void)0)> : std::true_type {}; template struct has_print().debug(std::declval()), (void)0)> : std::true_type {}; int fd; char buffer[BUFF_SIZE]; int idx; std::size_t decimal_precision; public: Printer() : Printer((debug ? 2 : 1)) {} explicit Printer(int fd) : fd(fd), idx(0), decimal_precision(16) {} explicit Printer(FILE* file) : fd(fileno(file)), idx(0), decimal_precision(16) {} ~Printer() { flush(); } void set_decimal_precision(std::size_t n) { decimal_precision = n; } inline void print_char(char c) { buffer[idx++] = c; if (idx == BUFF_SIZE) flush(); } inline void flush() { idx = write(fd, buffer, idx); idx = 0; } void print(char a) { if constexpr (debug) print_char('\''); print_char(a); if constexpr (debug) print_char('\''); } void print(bool a) { if constexpr (debug) print_char('\''); print_char('0' + a); if constexpr (debug) print_char('\''); } void print(const char* a) { if constexpr (debug) print_char('\"'); for (; *a != '\0'; ++a) print_char(*a); if constexpr (debug) print_char('\"'); } template void print(const char (&a)[N]) { if constexpr (debug) print_char('\"'); for (auto i : a) print_char(i); if constexpr (debug) print_char('\"'); } void print(const std::string& a) { if constexpr (debug) print_char('\"'); for (auto i : a) print_char(i); if constexpr (debug) print_char('\"'); } template void print(const std::bitset& a) { for (int i = len - 1; i >= 0; --i) print_char('0' + a[i]); } template ::value && !has_print::value>::type* = nullptr> void print(T a) { if (!a) { print_char('0'); return; } if constexpr (is_signed_int::value) { if (a < 0) { print_char('-'); a = -a; } } if (static_cast(idx + 40) >= BUFF_SIZE) flush(); static char stk[40]; int top = 40; while (a >= 10000) { int i = a % 10000; a /= 10000; top -= 4; std::memcpy(stk + top, pre.buffer[i], 4); } if (a >= 1000) { std::memcpy(buffer + idx, pre.buffer[a], 4); idx += 4; } else if (a >= 100) { std::memcpy(buffer + idx, pre.buffer[a] + 1, 3); idx += 3; } else if (a >= 10) { std::memcpy(buffer + idx, pre.buffer[a] + 2, 2); idx += 2; } else { buffer[idx++] = '0' | a; } std::memcpy(buffer + idx, stk + top, 40 - top); idx += 40 - top; } template ::value && !has_print::value>::type* = nullptr> void print(T a) { if (a == infinity::max || a == infinity::value) { print("inf"); return; } if (a == infinity::min || a == infinity::mvalue) { print("-inf"); return; } if (std::isnan(a)) { print("nan"); return; } if (a < 0) { print_char('-'); a = -a; } T b = a; if (b < 1) { print_char('0'); } else { std::string s; while (b >= 1) { s += (char)('0' | (int)std::fmod(b, 10.0)); b /= 10; } for (auto i = s.rbegin(); i != s.rend(); ++i) { print_char(*i); } } print_char('.'); for (std::size_t _ = 0; _ < decimal_precision; ++_) { a *= 10; print_char('0' | (int)std::fmod(a, 10.0)); } } private: template void print(const std::tuple& a) { if constexpr (i < sizeof...(Args)) { if constexpr (debug) print_char(','); print_char(' '); print(std::get(a)); print(a); } } public: template void print(const std::tuple& a) { if constexpr (debug) print_char('('); if constexpr (sizeof...(Args) != 0) { print(std::get<0>(a)); } print<1, Args...>(a); if constexpr (debug) print_char(')'); } template void print(const std::pair& a) { if constexpr (debug) print_char('('); print(a.first); if constexpr (debug) print_char(','); print_char(' '); print(a.second); if constexpr (debug) print_char(')'); } template ::value>::type* = nullptr> void print(const T& a) { if constexpr (debug) print_char('{'); auto it = std::begin(a); if (it != std::end(a)) { print(*it); while (++it != std::end(a)) { if constexpr (debug) print_char(','); print_char(' '); print(*it); } } if constexpr (debug) print_char('}'); } template ::value && !debug>::type* = nullptr> void print(const T& a) { a.print(*this); } template ::value && debug>::type* = nullptr> void print(const T& a) { a.debug(*this); } void operator()() {} template void operator()(const Head& head, const Tail&... tail) { print(head); operator()(std::forward(tail)...); } template Printer& operator<<(const T& a) { print(a); return *this; } Printer& operator<<(Printer& (*f)(Printer&)) { return f(*this); } }; template Printer& endl(Printer& out) { out.print_char('\n'); out.flush(); return out; } template Printer& flush(Printer& out) { out.flush(); return out; } Printer<> pr; Printer<1 << 17, true> prd; } // namespace fastio using fastio::endl; using fastio::flush; using fastio::pr; using fastio::prd; #line 3 "library/template/func.hpp" #line 8 "library/template/func.hpp" inline constexpr int msb(ull x) { int res = x ? 0 : -1; if (x & 0xffffffff00000000) x &= 0xffffffff00000000, res += 32; if (x & 0xffff0000ffff0000) x &= 0xffff0000ffff0000, res += 16; if (x & 0xff00ff00ff00ff00) x &= 0xff00ff00ff00ff00, res += 8; if (x & 0xf0f0f0f0f0f0f0f0) x &= 0xf0f0f0f0f0f0f0f0, res += 4; if (x & 0xcccccccccccccccc) x &= 0xcccccccccccccccc, res += 2; return res + (x & 0xaaaaaaaaaaaaaaaa ? 1 : 0); } inline constexpr int ceil_log2(ull x) { return x ? msb(x - 1) + 1 : 0; } inline constexpr ull reverse(ull x) { x = ((x & 0x5555555555555555) << 1) | ((x & 0xaaaaaaaaaaaaaaaa) >> 1); x = ((x & 0x3333333333333333) << 2) | ((x & 0xcccccccccccccccc) >> 2); x = ((x & 0x0f0f0f0f0f0f0f0f) << 4) | ((x & 0xf0f0f0f0f0f0f0f0) >> 4); x = ((x & 0x00ff00ff00ff00ff) << 8) | ((x & 0xff00ff00ff00ff00) >> 8); x = ((x & 0x0000ffff0000ffff) << 16) | ((x & 0xffff0000ffff0000) >> 16); return (x << 32) | (x >> 32); } inline constexpr ull reverse(ull x, int len) { return reverse(x) >> (64 - len); } inline constexpr int popcnt(ull x) { #if __cplusplus >= 202002L return std::popcount(x); #endif x = (x & 0x5555555555555555) + ((x >> 1) & 0x5555555555555555); x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); x = (x & 0x0f0f0f0f0f0f0f0f) + ((x >> 4) & 0x0f0f0f0f0f0f0f0f); x = (x & 0x00ff00ff00ff00ff) + ((x >> 8) & 0x00ff00ff00ff00ff); x = (x & 0x0000ffff0000ffff) + ((x >> 16) & 0x0000ffff0000ffff); return (x & 0x00000000ffffffff) + ((x >> 32) & 0x00000000ffffffff); } template inline constexpr bool chmin(T& a, U b) { return a > b && (a = b, true); } template inline constexpr bool chmax(T& a, U b) { return a < b && (a = b, true); } inline constexpr ll gcd(ll a, ll b) { if (a < 0) a = -a; if (b < 0) b = -b; while (b) { const ll c = b; b = a % b; a = c; } return a; } inline constexpr ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline constexpr bool is_prime(ll n) { if (n <= 1) return false; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } inline constexpr ll my_pow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } inline constexpr ll mod_pow(ll a, ll b, const ll& mod) { if (mod == 1) return 0; a %= mod; ll res = 1; while (b) { if (b & 1) (res *= a) %= mod; (a *= a) %= mod; b >>= 1; } return res; } inline ll mod_inv(ll a, const ll& mod) { ll b = mod, x = 1, u = 0, t; while (b) { t = a / b; std::swap(a -= t * b, b); std::swap(x -= t * u, u); } if (x < 0) x += mod; return x; } template T binary_gcd(T x_, T y_) { T x = x_ < 0 ? -x_ : x_, y = y_ < 0 ? -y_ : y_; if (!x || !y) return x + y; int n = __builtin_ctzll(x), m = __builtin_ctzll(y); x >>= n, y >>= m; while (x != y) { if (x > y) { x = (x - y) >> __builtin_ctzll(x - y); } else { y = (y - x) >> __builtin_ctzll(y - x); } } return x << std::min(n, m); } template std::ostream& operator<<(std::ostream& os, const std::pair& p) { os << p.first << " " << p.second; return os; } template std::istream& operator>>(std::istream& is, std::pair& p) { is >> p.first >> p.second; return is; } template std::ostream& operator<<(std::ostream& os, const std::vector& v) { for (auto it = std::begin(v); it != std::end(v);) { os << *it << ((++it) != std::end(v) ? " " : ""); } return os; } template std::istream& operator>>(std::istream& is, std::vector& v) { for (T& in : v) { is >> in; } return is; } inline void scan() {} template inline void scan(Head& head, Tail&... tail) { sc >> head; scan(tail...); } template inline void print(const T& t) { pr << t << '\n'; } template inline void print(const Head& head, const Tail&... tail) { pr << head << ' '; print(tail...); } template inline void fin(const T&... a) { print(a...); exit(0); } template inline void dump(const T& a) { prd << a; } inline void trace() { prd << endl; } template inline void trace(const Head& head, const Tail&... tail) { dump(head); if (sizeof...(tail)) prd.print_char(','), prd.print_char(' '); trace(tail...); } #ifdef ONLINE_JUDGE #define dbg(...) (void(0)) #else #define dbg(...) \ do { \ prd << #__VA_ARGS__; \ prd.print_char(' '), prd.print_char('='), prd.print_char(' '); \ trace(__VA_ARGS__); \ } while (0) #endif #line 3 "library/template/util.hpp" #line 6 "library/template/util.hpp" template struct REC { private: F f; public: explicit constexpr REC(F&& f_) : f(std::forward(f_)) {} template constexpr auto operator()(Args&&... args) const { return f(*this, std::forward(args)...); } }; template > struct compressor { private: std::vector data; Comp cmp; bool sorted = false; public: compressor() : compressor(Comp()) {} compressor(const Comp& cmp) : cmp(cmp) {} compressor(const std::vector& dat, const Comp& cmp = Comp()) : data(dat), cmp(cmp) {} compressor(std::vector&& dat, const Comp& cmp = Comp()) : data(std::move(dat)), cmp(cmp) {} compressor(std::initializer_list li, const Comp& cmp = Comp()) : data(li.begin(), li.end()), cmp(cmp) {} void push_back(const T& v) { assert(!sorted); data.push_back(v); } void push_back(T&& v) { assert(!sorted); data.push_back(std::move(v)); } template void emplace_back(Args&&... args) { assert(!sorted); data.emplace_back(std::forward(args)...); } void push(const std::vector& v) { assert(!sorted); const int n = data.size(); data.resize(v.size() + n); for (int i = 0; i < (int)v.size(); i++) data[i + n] = v[i]; } void build() { assert(!sorted); sorted = 1; std::sort(data.begin(), data.end(), cmp); data.erase(unique(data.begin(), data.end(), [&](const T& l, const T& r) -> bool { return !cmp(l, r) && !cmp(r, l); }), data.end()); } const T& operator[](int k) const& { assert(sorted); return data[k]; } int get_index(const T& v) const { assert(sorted); return int(lower_bound(data.begin(), data.end(), v, cmp) - data.begin()); } void press(std::vector& v) const { assert(sorted); for (auto&& i : v) i = get_index(i); } std::vector pressed(const std::vector& v) const { assert(sorted); std::vector ret(v.size()); for (int i = 0; i < (int)v.size(); i++) ret[i] = get_index(v[i]); return ret; } int size() const { assert(sorted); return data.size(); } }; #line 11 "library/template/template.hpp" using namespace std; #line 3 "library/math/modular/modint.hpp" namespace internal { struct modint_base {}; } // namespace internal template using is_modint = is_base_of; template struct StaticModInt : internal::modint_base { static_assert(is_integral::value, "T must be integral"); static_assert(is_unsigned::value, "T must be unsgined"); static_assert(mod > 0, "mod must be positive"); static_assert(mod <= INF, "mod*2 must be less than or equal to T::max()"); private: using large_t = typename double_size_uint::type; using signed_t = typename make_signed::type; T val; public: constexpr StaticModInt() : val(0) {} template ::value && is_unsigned::value>::type* = nullptr> constexpr StaticModInt(U x) : val(x % mod) {} template ::value && is_signed::value>::type* = nullptr> constexpr StaticModInt(U x) : val{} { x %= static_cast(mod); if (x < 0) x += static_cast(mod); val = static_cast(x); } constexpr T get() const { return val; } static constexpr T get_mod() { return mod; } static constexpr StaticModInt raw(T v) { StaticModInt res; res.val = v; return res; } constexpr StaticModInt inv() const { return mod_inv(val, mod); } constexpr StaticModInt& operator++() { ++val; if (val == mod) val = 0; return *this; } constexpr StaticModInt operator++(int) { StaticModInt res = *this; ++*this; return res; } constexpr StaticModInt& operator--() { if (val == 0) val = mod; --val; return *this; } constexpr StaticModInt operator--(int) { StaticModInt res = *this; --*this; return res; } constexpr StaticModInt& operator+=(const StaticModInt& x) { val += x.val; if (val >= mod) val -= mod; return *this; } constexpr StaticModInt& operator-=(const StaticModInt& x) { if (val < x.val) val += mod; val -= x.val; return *this; } constexpr StaticModInt& operator*=(const StaticModInt& x) { val = static_cast((static_cast(val) * x.val) % mod); return *this; } constexpr StaticModInt& operator/=(const StaticModInt& x) { return *this *= x.inv(); } friend constexpr StaticModInt operator+(const StaticModInt& l, const StaticModInt& r) { return StaticModInt(l) += r; } friend constexpr StaticModInt operator-(const StaticModInt& l, const StaticModInt& r) { return StaticModInt(l) -= r; } friend constexpr StaticModInt operator*(const StaticModInt& l, const StaticModInt& r) { return StaticModInt(l) *= r; } friend constexpr StaticModInt operator/(const StaticModInt& l, const StaticModInt& r) { return StaticModInt(l) /= r; } constexpr StaticModInt operator+() const { return StaticModInt(*this); } constexpr StaticModInt operator-() const { return StaticModInt() - *this; } friend constexpr bool operator==(const StaticModInt& l, const StaticModInt& r) { return l.val == r.val; } friend constexpr bool operator!=(const StaticModInt& l, const StaticModInt& r) { return l.val != r.val; } constexpr StaticModInt pow(ll a) const { StaticModInt v = *this, res = 1; if (a < 0) { a = -a; v = v.inv(); } while (a) { if (a & 1) res *= v; v *= v; a >>= 1; } return res; } template void scan(Sc& a) { ll x; a.scan(x); *this = x; } template void print(Pr& a) const { a.print(val); } template void debug(Pr& a) const { a.print(val); } }; template using ModInt = StaticModInt; template struct DynamicModInt { static_assert(is_integral::value, "T must be integral"); static_assert(is_unsigned::value, "T must be unsigned"); private: using large_t = typename double_size_uint::type; using signed_t = typename make_signed::type; T val; static T mod; public: constexpr DynamicModInt() : val(0) {} template ::value && is_unsigned::value>::type* = nullptr> constexpr DynamicModInt(U x) : val(x % mod) {} template ::value && is_signed::value>::type* = nullptr> constexpr DynamicModInt(U x) : val{} { x %= static_cast(mod); if (x < 0) x += static_cast(mod); val = static_cast(x); } T get() const { return val; } static T get_mod() { return mod; } static void set_mod(T x) { mod = x; assert(mod > 0); assert(mod <= INF); } static DynamicModInt raw(T v) { DynamicModInt res; res.val = v; return res; } DynamicModInt inv() const { return mod_inv(val, mod); } DynamicModInt& operator++() { ++val; if (val == mod) val = 0; return *this; } DynamicModInt operator++(int) { DynamicModInt res = *this; ++*this; return res; } DynamicModInt& operator--() { if (val == 0) val = mod; --val; return *this; } DynamicModInt operator--(int) { DynamicModInt res = *this; --*this; return res; } DynamicModInt& operator+=(const DynamicModInt& x) { val += x.val; if (val >= mod) val -= mod; return *this; } DynamicModInt& operator-=(const DynamicModInt& x) { if (val < x.val) val += mod; val -= x.val; return *this; } DynamicModInt& operator*=(const DynamicModInt& x) { val = static_cast((static_cast(val) * x.val) % mod); return *this; } DynamicModInt& operator/=(const DynamicModInt& x) { return *this *= x.inv(); } friend DynamicModInt operator+(const DynamicModInt& l, const DynamicModInt& r) { return DynamicModInt(l) += r; } friend DynamicModInt operator-(const DynamicModInt& l, const DynamicModInt& r) { return DynamicModInt(l) -= r; } friend DynamicModInt operator*(const DynamicModInt& l, const DynamicModInt& r) { return DynamicModInt(l) *= r; } friend DynamicModInt operator/(const DynamicModInt& l, const DynamicModInt& r) { return DynamicModInt(l) /= r; } DynamicModInt operator+() const { return DynamicModInt(*this); } DynamicModInt operator-() const { return DynamicModInt() - *this; } friend bool operator==(const DynamicModInt& l, const DynamicModInt& r) { return l.val == r.val; } friend bool operator!=(const DynamicModInt& l, const DynamicModInt& r) { return l.val != r.val; } DynamicModInt pow(ll a) const { DynamicModInt v = *this, res = 1; if (a < 0) { a = -a; v = v.inv(); } while (a) { if (a & 1) res *= v; v *= v; a >>= 1; } return res; } template void scan(Sc& a) { ll x; a.scan(x); *this = x; } template void print(Pr& a) const { a.print(val); } template void debug(Pr& a) const { a.print(val); } }; template T DynamicModInt::mod = 998244353; template using dynamic_modint = DynamicModInt; using modint = dynamic_modint<-1>; /** * @brief ModInt */ #line 4 "library/math/others/combinatorics.hpp" template struct Combinatorics { private: static vector dat, idat; public: static void extend(int sz) { const int pre_sz = dat.size(); if (sz < pre_sz) return; dat.resize(sz + 1, 1); idat.resize(sz + 1, 1); for (int i = pre_sz; i <= sz; i++) dat[i] = dat[i - 1] * i; idat[sz] = T(1) / dat[sz]; for (int i = sz - 1; i >= pre_sz; i--) idat[i] = idat[i + 1] * (i + 1); } static T fac(ll n) { if (n < 0) return T(); extend(n); return dat[n]; } static T finv(ll n) { if (n < 0) return T(); extend(n); return idat[n]; } static T inv(ll n) { if (n <= 0) return T(); extend(n); return dat[n - 1] * idat[n]; } static T com(ll n, ll k) { if (k < 0 || n < k || n < 0) return T(); extend(n); return dat[n] * idat[k] * idat[n - k]; } static T hom(ll n, ll k) { if (n < 0 || k < 0) return T(); return k == 0 ? 1 : com(n + k - 1, k); } static inline T per(ll n, ll k) { if (k < 0 || n < k) return T(); extend(n); return dat[n] * idat[n - k]; } }; template vector Combinatorics::dat = vector(2, 1); template vector Combinatorics::idat = vector(2, 1); template struct COMB { private: static vector>> comb; static void init() { if (!comb.empty()) return; comb.assign(p, vector>(p)); comb[0][0] = 1; for (int i = 1; i < p; i++) { comb[i][0] = 1; for (int j = i; j > 0; j--) comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; } } public: COMB() { init(); } ModInt

com(int n, int k) { init(); ModInt

ret = 1; while (n > 0 || k > 0) { int ni = n % p, ki = k % p; ret *= comb[ni][ki]; n /= p; k /= p; } return ret; } }; template vector>> COMB

::comb = vector>>(); /** * @brief Combinatorics(組み合わせ) */ #line 4 "code.cpp" using mint = ModInt<998244353>; Combinatorics comb; int main() { LL(n); if (n & 1) fin(0); n /= 2; n--; print(mint(2).pow(2 * n + 1) - comb.com(2 * n + 3, n + 1) + comb.com(2 * n + 1, n)); return 0; /* rep(n, 1, 11) { ll sum = 0; rep(bit, 1 << (2 * n)) { stack st; ll ans = 0; bool f = true; rep(i, 2 * n) { if ((bit >> i) & 1) { st.emplace(i); } else { if (st.empty()) { f = false; break; } st.pop(); ans += st.size(); } } f &= st.empty(); if (f) sum += ans; } print(sum); }*/ }