結果
| 問題 | No.303 割れません |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-11 18:17:41 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 959 ms / 10,000 ms |
| コード長 | 43,391 bytes |
| 記録 | |
| コンパイル時間 | 4,412 ms |
| コンパイル使用メモリ | 338,900 KB |
| 実行使用メモリ | 13,496 KB |
| 最終ジャッジ日時 | 2026-04-11 18:17:56 |
| 合計ジャッジ時間 | 13,239 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
#define YRSD
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <bit>
#include <chrono>
#include <functional>
#include <iomanip>
#include <utility>
#include <type_traits>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
#include <limits>
#include <ranges>
#include <concepts>
#define TE template <typename T>
#define TES template <typename T, typename ...S>
#define Z auto
#define var const Z &
#define ep emplace_back
#define eb emplace
#define fi first
#define se second
#define bg begin
#define ed end
#define all(x) bg(x), ed(x)
#define OV(a, b, c, d, e, ...) e
#define FO1(a) for (int _ = 0; _ < (a); ++_)
#define FO2(i, a) for (int i = 0; i < (a); ++i)
#define FO3(i, a, b) for (int i = (a); i < (b); ++i)
#define FO4(i, a, b, c) for (int i = (a); i < (b); i += (c))
#define FOR(...) OV(__VA_ARGS__, FO4, FO3, FO2, FO1)(__VA_ARGS__)
#define FF1(a) for (int _ = (a) - 1; _ >= 0; --_)
#define FF2(i, a) for (int i = (a) - 1; i >= 0; --i)
#define FF3(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define FF4(i, a, b, c) for (int i = (b) - 1; i >= (a); i -= (c))
#define FOR_R(...) OV(__VA_ARGS__, FF4, FF3, FF2, FF1)(__VA_ARGS__)
#define FOR_subset(t, s) for (int t = (s); t > -1; t = (t == 0 ? -1 : (t - 1) & s))
#define sort ranges::sort
using namespace std;
TE using vc = vector<T>;
TE using vvc = vc<vc<T>>;
TE using T1 = tuple<T>;
TE using T2 = tuple<T, T>;
TE using T3 = tuple<T, T, T>;
TE using T4 = tuple<T, T, T, T>;
TE using max_heap = priority_queue<T>;
TE using min_heap = priority_queue<T, vc<T>, greater<T>>;
using u8 = unsigned char; using uint = unsigned int; using ll = long long; using ull = unsigned long long;
using ld = long double; using i128 = __int128; using u128 = __uint128_t; using f128 = __float128;
using u16 = uint16_t;
using PII = pair<int, int>; using PLL = pair<ll, ll>;
#ifdef YRSD
constexpr bool dbg = 1;
#else
constexpr bool dbg = 0;
#endif
TES concept nof = (not same_as<T, S> and ...);
istream &operator>>(istream &I, i128 &x) {
static string s;
I >> s;
int f = s[0] == '-';
x = 0;
const int N = (int)s.size();
FOR(i, f, N) x = x * 10 + s[i] - '0';
if (f) x = -x;
return I;
}
ostream &operator<<(ostream &O, i128 x) {
static string s;
s.clear();
bool f = x < 0;
if (f) x = -x;
while (x) s += '0' + x % 10, x /= 10;
if (s.empty()) s += '0';
if (f) s += '-';
reverse(all(s));
return O << s;
}
istream &operator>>(istream &I, f128 &x) {
static string s;
I >> s, x = stold(s);
return I;
}
ostream &operator<<(ostream &O, const f128 x) { return O << ld(x); }
template <typename... S>
istream &operator>>(istream &I, tuple<S...> &t) {
return apply([&I](Z &...s) { ((I >> s), ...); }, t), I;
}
template <typename T, typename U>
istream &operator>>(istream &I, pair<T, U> &x) {
return I >> x.fi >> x.se;
}
template <typename T, typename U>
ostream &operator<<(ostream &O, const pair<T, U> &x) {
return O << x.fi << ' ' << x.se;
}
TE requires requires(T &c) { begin(c); end(c); } and
(not is_same_v<decay_t<T>, string>)
istream &operator>>(istream &I, T &c) {
for (Z &e : c) I >> e;
return I;
}
TE ostream &operator<<(ostream &cout, const vc<T> &a) {
if (a.empty()) return cout;
Z i = bg(a);
cout << *i++;
for (; i != ed(a); ++i) cout << ' ' << *i;
return cout;
}
template <typename T, int N> requires(N > 0)
ostream &operator<<(ostream &cout, const array<T, N> &a) {
cout << a[0];
FOR(i, 1, N) cout << ' ' << a[i];
return cout;
}
void IN() {}
TE void IN(T &x, Z &...s) { cin >> x, IN(s...); }
void print() { cout << '\n'; }
TES void print(T &&x, S &&...y) {
cout << x;
if constexpr (sizeof...(S)) cout << ' ';
print(forward<S>(y)...);
}
void put() {}
TES void put(T &&x, S &&...y) {
cout << x;
put(forward<S>(y)...);
}
#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__)
#define UINT(...) uint __VA_ARGS__; IN(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; IN(__VA_ARGS__)
#define I128(...) i128 __VA_ARGS__; IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)
#define CH(...) char __VA_ARGS__; IN(__VA_ARGS__)
#define REAL(...) re __VA_ARGS__; IN(__VA_ARGS__)
#define VEC(T, a, n) vc<T> a(n); IN(a)
void YES(bool o = 1) { print(o ? "YES" : "NO"); }
void Yes(bool o = 1) { print(o ? "Yes" : "No"); }
void yes(bool o = 1) { print(o ? "yes" : "no"); }
void NO(bool o = 1) { YES(not o); }
void No(bool o = 1) { Yes(not o); }
void no(bool o = 1) { yes(not o); }
void ALICE(bool o = 1) { print(o ? "ALICE" : "BOB"); }
void Alice(bool o = 1) { print(o ? "Alice" : "Bob"); }
void alice(bool o = 1) { print(o ? "alice" : "bob"); }
void BOB(bool o = 1) { ALICE(not o); }
void Bob(bool o = 1) { Alice(not o); }
void bob(bool o = 1) { alice(not o); }
void POSSIBLE(bool o = 1) { print(o ? "POSSIBLE" : "IMPOSSIBLE"); }
void Possible(bool o = 1) { print(o ? "Possible" : "Impossible"); }
void possible(bool o = 1) { print(o ? "possible" : "impossible"); }
void IMPOSSIBLE(bool o = 1) { POSSIBLE(not o); }
void Impossible(bool o = 1) { Possible(not o); }
void impossible(bool o = 1) { possible(not o); }
void TAK(bool o = 1) { print(o ? "TAK" : "NIE"); }
void NIE(bool o = 1) { TAK(not o); }
#if (__cplusplus >= 202002L)
#include <numbers>
constexpr ld pi = numbers::pi_v<ld>;
#endif
TE constexpr T inf = numeric_limits<T>::max();
template <> constexpr i128 inf<i128> = i128(inf<ll>) * 2'000'000'000'000'000'000;
template <typename T, typename U>
constexpr pair<T, U> inf<pair<T, U>> = {inf<T>, inf<U>};
TE constexpr static inline int pc(T x) { return popcount(make_unsigned_t<T>(x)); }
constexpr static inline ll si(var a) { return a.size(); }
void reverse(Z &a) { reverse(all(a)); }
void unique(Z &a) {
sort(a);
a.erase(unique(all(a)), ed(a));
}
TE vc<int> inverse(const vc<T> &a) {
int N = si(a);
vc<int> b(N, -1);
FOR(i, N) if (a[i] != -1) b[a[i]] = i;
return b;
}
Z QMAX(var a) { return *max_element(all(a)); }
Z QMIN(var a) { return *min_element(all(a)); }
TE Z QMAX(T l, T r) { return *max_element(l, r); }
TE Z QMIN(T l, T r) { return *min_element(l, r); }
constexpr bool chmax(Z &a, var b) { return (a < b ? a = b, 1 : 0); }
constexpr bool chmin(Z &a, var b) { return (a > b ? a = b, 1 : 0); }
vc<int> argsort(var a) {
vc<int> I(si(a));
iota(all(I), 0);
sort(I, [&](int i, int k) { return a[i] < a[k] or (a[i] == a[k] and i < k); });
return I;
}
TE vc<T> rearrange(const vc<T> &a, const vc<int> &I) {
int N = si(I);
vc<T> b(N);
FOR(i, N) b[i] = a[I[i]];
return b;
}
template <int of = 1, typename T>
vc<T> pre_sum(const vc<T> &a) {
int N = si(a);
vc<T> c(N + 1);
FOR(i, N) c[i + 1] = c[i] + a[i];
if (of == 0) c.erase(bg(c));
return c;
}
TE constexpr static int topbit(T x) {
if (x == 0) return -1;
if constexpr (sizeof(T) <= 4) return 31 - __builtin_clz(x);
else return 63 - __builtin_clzll(x);
}
TE constexpr static int lowbit(T x) {
if (x == 0) return -1;
if constexpr (sizeof(T) <= 4) return __builtin_ctz(x);
else return __builtin_ctzll(x);
}
TE constexpr inline T floor(T x, T y) { return x / y - (x % y and (x ^ y) < 0); }
TE constexpr inline T ceil(T x, T y) { return floor(x + y - 1, y); }
TE constexpr inline T bmod(T x, T y) { return x - floor(x, y) * y; }
TE constexpr inline pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return pair{q, x - q * y};
}
TE T SUM(var v) { return accumulate(all(v), T()); }
TE T SUM(Z l, Z r) { return accumulate(l, r, T()); }
int lb(var a, Z x) { return lower_bound(all(a), x) - a.begin(); }
TE int lb(T l, T r, Z x) { return lower_bound(l, r, x) - l; }
int ub(var a, Z x) { return upper_bound(all(a), x) - a.begin(); }
TE int ub(T l, T r, Z x) { return upper_bound(l, r, x) - l; }
template <bool ck = 1>
ll bina(Z f, ll l, ll r) {
if (ck) assert(f(l));
while (abs(l - r) > 1) {
ll x = (r + l) >> 1;
(f(x) ? l : r) = x;
}
return l;
}
TE T bina_real(Z f, T l, T r, int c = 100) {
while (c--) {
T x = (l + r) / 2;
(f(x) ? l : r) = x;
}
return (l + r) / 2;
}
TE T pop(vc<T> &a) {
T x = a.back();
a.pop_back();
return x;
}
TE T pop(max_heap<T> &q) {
T x = q.top();
q.pop();
return x;
}
TE T pop(min_heap<T> &q) {
T x = q.top();
q.pop();
return x;
}
char pop(string &s) {
char x = s.back();
s.pop_back();
return x;
}
void setp(int x) { cout << fixed << setprecision(x); }
TE inline void sh(vc<T> &a, int N, T b = {}) { a.resize(N, b); }
#ifdef YRSD
void DBG() { cerr << "]" << endl; }
TES void DBG(T &&x, S &&...y) {
cerr << x;
if constexpr (sizeof...(S)) cerr << ", ";
DBG(forward<S>(y)...);
}
#define debug(...) cerr << "[" << __LINE__ << "]: [" #__VA_ARGS__ "] = [", DBG(__VA_ARGS__)
void ERR() { cerr << endl; }
TES void ERR(T &&x, S &&...y) {
cerr << x;
if constexpr (sizeof...(S)) cerr << ", ";
ERR(forward<S>(y)...);
}
#define err(...) cerr << "[" << __LINE__ << "]: ", ERR(__VA_ARGS__)
#else
#define debug(...) void(0721)
#define err(...) void(0721)
#endif
#define FIO
static constexpr uint SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
uint pil = 0, pir = 0, por = 0;
struct Pre {
char num[10000][4];
constexpr Pre() : num() {
for (int i = 0; i < 10000; i++) {
int n = i;
for (int j = 3; j >= 0; j--) {
num[i][j] = n % 10 | '0';
n /= 10;
}
}
}
} constexpr pre;
inline void load() {
memcpy(ibuf, ibuf + pil, pir - pil);
pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
pil = 0;
if (pir < SZ) ibuf[pir++] = '\n';
}
inline void flush() {
fwrite(obuf, 1, por, stdout);
por = 0;
}
inline void rd(char &c) {
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
}
inline void rd(string &x) {
x.clear();
char c;
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
do {
x += c;
if (pil == pir) load();
c = ibuf[pil++];
} while (!isspace(c));
}
TE inline void rd_real(T &x) {
string s;
rd(s);
x = stod(s);
}
TE inline void rd_integer(T &x) {
if (pil + 100 > pir) load();
char c;
do c = ibuf[pil++];
while (c < '-');
bool minus = 0;
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (c == '-') {
minus = 1, c = ibuf[pil++];
}
}
x = 0;
while ('0' <= c) {
x = x * 10 + (c & 15), c = ibuf[pil++];
}
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (minus) x = -x;
}
}
inline void rd(int16_t &x) { rd_integer(x); }
inline void rd(uint16_t &x) { rd_integer(x); }
inline void rd(int &x) { rd_integer(x); }
inline void rd(long &x) { rd_integer(x); }
inline void rd(ll &x) { rd_integer(x); }
inline void rd(i128 &x) { rd_integer(x); }
inline void rd(uint &x) { rd_integer(x); }
inline void rd(ull &x) { rd_integer(x); }
inline void rd(u128 &x) { rd_integer(x); }
inline void rd(double &x) { rd_real(x); }
inline void rd(long double &x) { rd_real(x); }
inline void rd(f128 &x) { rd_real(x); }
template <typename T, typename U>
inline void rd(pair<T, U> &p) {
return rd(p.fi), rd(p.se);
}
template <size_t N = 0, typename T>
inline void rd_tuple(T &t) {
if constexpr (N < tuple_size<T>::value) {
Z &x = get<N>(t);
rd(x);
rd_tuple<N + 1>(t);
}
}
template <typename... T>
inline void rd(tuple<T...> &tpl) {
rd_tuple(tpl);
}
template <size_t N = 0, typename T>
inline void rd(array<T, N> &x) {
for (Z &e : x) rd(e);
}
TE inline void rd(vc<T> &x) {
for (Z &e : x) rd(e);
}
inline void read() {}
template <typename H, typename... T>
inline void read(H &h, T &...t) {
rd(h), read(t...);
}
inline void wt(const char c) {
if (por == SZ) flush();
obuf[por++] = c;
}
inline void wt(const string s) {
for (char c : s) wt(c);
}
inline void wt(const char *s) {
size_t si = strlen(s);
for (size_t i = 0; i < si; i++) wt(s[i]);
}
TE inline void wt_integer(T x) {
if (por > SZ - 100) flush();
if (x < 0) {
obuf[por++] = '-', x = -x;
}
int outi;
for (outi = 96; x >= 10000; outi -= 4) {
memcpy(out + outi, pre.num[x % 10000], 4);
x /= 10000;
}
if (x >= 1000) {
memcpy(obuf + por, pre.num[x], 4);
por += 4;
} else if (x >= 100) {
memcpy(obuf + por, pre.num[x] + 1, 3);
por += 3;
} else if (x >= 10) {
int q = (x * 103) >> 10;
obuf[por] = q | '0';
obuf[por + 1] = (x - q * 10) | '0';
por += 2;
} else
obuf[por++] = x | '0';
memcpy(obuf + por, out + outi + 4, 96 - outi);
por += 96 - outi;
}
#ifndef SETP
#define SETP 10
#endif
TE inline void wt_real(T x) {
ostringstream oss;
oss << fixed << setprecision(SETP) << double(x);
string s = oss.str();
wt(s);
}
inline void wt(int x) { wt_integer(x); }
inline void wt(long x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(uint x) { wt_integer(x); }
inline void wt(ull x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }
template <typename T, typename U>
inline void wt(const pair<T, U> &val) {
wt(val.fi);
wt(' ');
wt(val.se);
}
template <size_t N = 0, typename T>
inline void wt_tuple(const T &t) {
if constexpr (N < tuple_size<T>::value) {
if constexpr (N > 0) {
wt(' ');
}
const Z x = get<N>(t);
wt(x);
wt_tuple<N + 1>(t);
}
}
template <typename... T>
inline void wt(tuple<T...> &tpl) {
wt_tuple(tpl);
}
template <typename T, size_t S>
inline void wt(const array<T, S> &val) {
Z n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
TE inline void wt(const vc<T> &a) {
int N = si(a);
FOR(i, N) {
if (i) wt(' ');
wt(a[i]);
}
}
TE inline void wt(const vc<vc<T>> &v) {
int N = si(v);
FOR(i, N) {
wt(v[i]);
if (i + 1 != N) wt('\n');
}
}
template <typename T, const size_t s>
inline void wt(const vc<array<T, s>> &v) {
int N = si(v);
FOR(i, N) {
wt(v[i]);
if (i + 1 != N) wt('\n');
}
}
inline void __attribute__((destructor)) _d() { flush(); }
inline void println() { wt('\n'); }
template <typename Head, typename... Tail>
inline void println(Head &&head, Tail &&...tail) {
wt(head);
if (sizeof...(Tail)) wt(' ');
println(forward<Tail>(tail)...);
}
#define IN(...) read(__VA_ARGS__)
#define print(...) println(__VA_ARGS__)
#define FLUSH() flush()
TE struct retsu {
int N, M;
vc<T> a;
retsu(int N, int M, T bs = T()) : N(N), M(M), a(N * M, bs) {}
T* operator[](int i) { return a.data() + i * M; }
const T* operator[](int i) const { return a.data() + i * M; }
void fill(T x) { std::fill(all(a), x); }
void build(int n, int m, T bs = T()) {
N = n, M = m;
a.assign(N * M, bs);
}
inline int id(int x, int y) const { return x * M + y; }
retsu rol() const {
retsu<T> c(M, N);
FOR(i, N) FOR(k, M) c[k][i] = a[id(i, k)];
return c;
}
retsu rol90() const {
retsu<T> c(M, N);
FOR(i, N) FOR(k, M) c[k][i] = a[id(i, M - k - 1)];
return c;
}
void pres() {
FOR(i, 1, N) FOR(k, M) a[id(i, k)] += a[id(i - 1, k)];
FOR(i, N) FOR(k, 1, M) a[id(i, k)] += a[id(i, k - 1)];
}
inline T prod(int x, int y) const { return a[id(x, y)]; }
inline T prod(int l, int r, int a, int b) const {
return prod(r, b) + prod(l, a) - prod(l, b) - prod(r, a);
}
T max() const { return QMAX(a); }
T min() const { return QMIN(a); }
void reverse() {
FOR(i, N) FOR(k, M >> 1) swap(a[i * M + k], a[i * M + M - k - 1]);
}
vc<vc<T>> to_v() const {
vector c(N, vc<T>(M));
FOR(i, N) FOR(k, M) c[i][k] = a[id(i, k)];
return c;
}
};
TE istream &operator>>(istream &cin, retsu<T> &a) {
for (Z &e : a.a) cin >> e;
return cin;
}
TE ostream &operator<<(ostream &cout, const retsu<T> &a) {
FOR(i, a.N) {
FOR(k, a.M) {
if (k) cout << ' ';
cout << a[i][k];
}
if (i + 1 != a.N) cout << '\n';
}
return cout;
}
#ifdef FIO
TE inline void rd(retsu<T> &a) {
for (T &x : a.a) rd(x);
}
TE inline void wt(retsu<T> &a) {
FOR(i, a.N) {
FOR(k, a.M) {
if (k) wt(' ');
wt(a[i][k]);
}
if (i != a.M) wt('\n');
}
}
#endif
#define c constexpr
template <int mod>
struct mint_t {
using T = mint_t;
static c uint m = mod;
uint x;
c inline uint val() const { return x; }
c mint_t() : x(0) {}
TE requires(is_unsigned_v<T>) mint_t(T x) : x(x % m) {}
mint_t(u128 x) : x(x % m) {}
TE requires(is_signed_v<T>) mint_t(T x) : x((x %= mod) < 0 ? x + mod : x) {}
mint_t(i128 x) : x((x %= mod) < 0 ? x + mod : x) {}
c T &operator+=(T p) {
if ((x += p.x) >= m) x -= m;
return *this;
}
c T &operator-=(T p) {
if ((x += m - p.x) >= m) x -= m;
return *this;
}
c T operator+(T p) const { return T(*this) += p; }
c T operator-(T p) const { return T(*this) -= p; }
c T &operator*=(T p) {
x = ull(x) * p.x % m;
return *this;
}
c T operator*(T p) const { return T(*this) *= p; }
c T &operator/=(T p) { return *this *= p.inv(); }
c T operator/(T p) const { return T(*this) /= p; }
c T operator-() const { return T::gen(x ? mod - x : 0); }
c T inv() const {
int a = x, b = mod, x = 1, y = 0;
while (b > 0) {
int t = a / b;
swap(a -= t * b, b);
swap(x -= t * y, y);
}
return T(x);
}
c T pow(ll k) const {
if (k < 0) return inv().pow(-k);
T s(1), a(x);
for (; k; k >>= 1, a *= a) {
if (k & 1) s *= a;
}
return s;
}
c bool operator<(T p) const { return x < p.x; }
c bool operator==(T p) const { return x == p.x; }
c bool operator!=(T p) const { return x != p.x; }
static c T gen(uint x) {
T s;
s.x = x;
return s;
}
friend istream &operator>>(istream &cin, T &p) {
ll t;
cin >> t;
p = t;
return cin;
}
friend ostream &operator<<(ostream &cout, T p) { return cout << p.x; }
static c int get_mod() { return mod; }
static c PII ntt_info() {
if (mod == 167772161) return {25, 17};
if (mod == 469762049) return {26, 30};
if (mod == 754974721) return {24, 362};
if (mod == 998244353) return {23, 31};
if (mod == 120586241) return {20, 74066978};
if (mod == 880803841) return {23, 211};
if (mod == 943718401) return {22, 663003469};
if (mod == 1004535809) return {21, 582313106};
if (mod == 1012924417) return {21, 368093570};
return {-1, -1};
}
static c bool can_ntt() { return ntt_info().fi != -1; }
};
#undef c
using M99 = mint_t<998244353>;
using M17 = mint_t<1000000007>;
using M11 = M17;
#ifdef FIO
template <int mod>
void rd(mint_t<mod> &x) {
LL(y);
x = y;
}
template <int mod>
void wt(mint_t<mod> x) {
wt(x.x);
}
#endif
TE struct fps_t {
using fps = vc<T>;
using cf = const fps &;
static inline const uint p = T::get_mod(), t = T::ntt_info().fi,
r = T::ntt_info().se;
static inline const ull M = ull(p) * p;
fps fa{1, 1}, ifa{1, 1}, in{0, 1};
T inv(int);
T fac(int);
T ifac(int);
T C(int, int);
static constexpr int p0 = 167'772'161, p1 = 469'762'049, p2 = 754'974'721;
using f0 = fps_t<mint_t<p0>>;
using f1 = fps_t<mint_t<p1>>;
using f2 = fps_t<mint_t<p2>>;
static void sh(fps &, int);
static int count_terms(cf);
static T eval(cf, T);
T crt(ull, ull, ull);
u128 crt_128(ull, ull, ull);
T crt(ull, ull, ull, ull, ull);
static void ntr(T *, T *, T *, T *, T *, T *);
static void ntt(fps &, bool);
static void trans_ntt(fps &, bool);
static void ntt_db(fps &f, bool = 0);
fps conv_naive(cf, cf);
fps conv_kara(cf, cf);
static fps conv_ntt(fps, fps);
fps conv_mtt(cf, cf);
fps conv(cf, cf);
vc<T> conv_ull(const vc<ull> &, const vc<ull> &);
vc<int> conv_int(const vc<int> &, const vc<int> &);
static fps sq_ntt(fps);
fps sq_mtt(cf);
fps sq(cf);
fps diff(cf);
fps inte(cf);
T inte(cf, T, T);
fps mid_prod(cf, cf);
fps inv_sp(cf);
fps inv_ntt(cf);
fps inv_mtt(cf);
fps inv(cf);
fps div_sp(fps, fps);
fps div_ntt(cf, cf);
fps div_mtt(fps, fps);
fps div_dense(cf, cf);
fps div(cf, cf);
fps log_sp(cf);
fps log_dense(cf);
fps log(cf);
fps exp_sp(cf);
fps exp_ntt(cf);
fps exp_mtt(cf);
fps exp_dense(cf);
fps exp(cf);
fps pw_sp(cf, T);
fps pw_dense(cf, T);
fps pw(cf, T);
fps pow(cf, ll);
fps sqr_sp(cf);
fps sqr_ntt(cf);
fps sqr_dense(cf);
fps sqr(cf);
fps sqrt(cf);
fps conv_all(const vc<fps> &);
fps conv_all(fps);
fps eval_geo(fps, T, T, int);
fps inte_geo(fps, T, T);
struct subprod_t;
subprod_t subprod(cf);
fps eval_ntt(fps, fps);
fps eval(fps, fps);
fps inte(fps, fps);
fps shift(fps, T);
T lag(cf, T);
fps lag(cf, T, int);
T lag(cf, cf, T);
fps pow_proj_ntt(fps, fps, int);
fps pow_proj_mtt(fps, fps, int);
fps pow_proj(fps, fps, int);
fps comp_slow(cf, cf);
fps comp_ntt(fps, fps);
fps comp_mtt(fps, fps);
fps comp(fps, fps);
fps comp_inv(fps);
pair<fps, fps> divmod(fps, cf);
fps modpow(cf, ll, cf);
fps prod_of_f_rk_x(fps, T, int);
fps prod_of_one_minus_xn(const vc<int> &, int);
fps prod_of_inv_one_minus_xn(const vc<int> &, int);
fps prod_of_one_plus_xn(const vc<int> &a, int);
fps prod_of_inv_one_plus_xn(const vc<int> &a, int);
pair<fps, fps> sum_of_rationals(vc<pair<fps, fps>>);
pair<fps, fps> sum_of_rationals_sp(cf, cf);
fps sum_of_exp_bx(cf, cf, int);
fps sum_of_pow(cf, int);
fps sum_of_pow(ll, ll, int);
fps sum_of_pow(cf, cf, int);
fps sum_of_binomail(fps, T, T);
fps subset_sum(const vc<int> &, int k);
fps subset_sum_lm(const vc<int> &, int k);
T coef_of_rationals_ntt(fps, fps, ll);
T coef_of_rationals_mtt(fps, fps, ll);
T coef_of_rationals(fps, fps, ll);
fps coef_of_rationals(fps, ll, ll);
tuple<fps, fps, fps> poly_exgcd(cf, cf);
fps poly_gcd(cf, cf);
fps find_root(fps);
pair<bool, vc<T>> poly_inv(cf, cf);
fps find_line(cf);
T line_inte(cf a, ll N);
template <int>
struct fac_t;
template <int lg = 10>
fac_t<lg> fac_large();
fps p_to_ffp(cf);
fps ffp_to_p(cf);
fps ffp_conv_ntt(fps, fps);
fps ffp_conv_mtt(fps, fps);
fps ffp_conv(cf, cf);
fps sin(cf);
fps cos(cf);
fps asin(cf);
fps atan(cf);
fps comp_f_ex(cf);
fps comp_f_1_minus_ex(cf);
fps comp_f_ex_minus_1(cf);
fps comp_f_a_plus_bx(cf, T, T);
fps comp_f_aplusbx_div_cplusdx_fake(cf, T, T, T, T);
fps comp_f_aplusbx_div_cplusdx(cf, T, T, T, T);
fps comp_f_x_plus_1_divx(cf);
struct conv_t;
conv_t online_conv();
struct exp_t;
exp_t online_exp();
struct log_t;
log_t online_log();
struct inv_t;
inv_t online_inv();
struct div_t;
div_t online_div();
struct pow_t;
pow_t online_pow(T);
fps presum(cf, T);
fps sinh(int);
fps exp_x(int);
fps exp_invx(int);
fps E_S(int);
fps E(int);
fps E_n(int, int);
fps E_odd(int);
fps E_noempty(int);
fps C_R(int);
fps bell(int);
fps derange(int);
fps bernoulli(int);
fps partition(int);
retsu<T> stiling_1_mat(int, int, bool = 0);
fps stiling_1_dit(int);
fps stiling_1_n(int, bool = 0);
fps stiling_1_k(int, int, bool = 0);
fps stiling_1_suf(ll, ll);
retsu<T> stiling_2_mat(int, int);
fps stiling_2_n(int, int);
fps stiling_2_k(int, int);
fps count_label_dag(int);
fps count_label_dag_con(int);
fps count_label_undir(int);
fps count_label_undir_con(int);
fps count_label_unicycle(int);
fps count_label_unicycle2(int);
fps count_label_bipartite(int, bool);
fps count_label_bcc_v(int);
T count_label_bcc_v_N(int);
fps count_label_bcc_e(int);
T count_label_bcc_e_N(int);
T count_label_tournament(int);
fps count_label_scc(int);
fps count_label_euler_undir(int);
fps count_label_tree(int);
fps count_unlabel_tree(int);
fps conv_multi_p(cf, cf);
fps conv_multi_2n(cf, cf);
};
TE Z fps_t<T>::inv(int n) -> T {
assert(0 <= n);
while (si(in) <= n) {
int k = si(in), q = (p + k - 1) / k, r = k * q - p;
in.ep(in[r] * T(q));
}
return in[n];
}
TE Z fps_t<T>::fac(int n) -> T {
if (n >= p) return 0;
while (si(fa) <= n) {
int k = si(fa);
fa.ep(fa[k - 1] * T(k));
}
return fa[n];
}
TE Z fps_t<T>::ifac(int n) -> T {
if (n < 0) return T(0);
while (si(ifa) <= n) ifa.ep(ifa.back() * inv(si(ifa)));
return ifa[n];
}
TE Z fps_t<T>::C(int n, int k) -> T {
assert(n >= 0);
if (k < 0 or n < k) return 0;
return fac(n) * ifac(k) * ifac(n - k);
}
TE Z fps_t<T>::sh(fps &a, int N) -> void { a.resize(N); }
TE Z fps_t<T>::count_terms(cf f) -> int {
int s = 0, N = si(f);
FOR(i, N) s += f[i].val() != 0;
return s;
}
TE Z fps_t<T>::eval(cf f, T x) -> T {
T s = 0, c = 1;
int N = si(f);
FOR(i, N) s += f[i] * c, c *= x;
return s;
}
TE Z fps_t<T>::crt(ull a, ull b, ull c) -> T {
constexpr ull x = 104'391'568, xx = 190'329'765;
ull t = (b - a + p1) * x % p1, s = a + t * p0;
t = (c - s % p2 + p2) * xx % p2;
return T(s) + T(t) * T(ull(p0) * p1);
}
TE Z fps_t<T>::ntr(T *w, T *iw, T *r, T *ir, T *b, T *ib) -> void {
w[t] = fps_t<T>::r, iw[t] = w[t].inv();
FOR_R(i, t) w[i] = w[i + 1] * w[i + 1], iw[i] = iw[i + 1] * iw[i + 1];
T s = 1, c = 1;
#define f(a, g) FOR(i, t - g + 1) a[i] = w[i + g] * s, s *= iw[i + g], i##a[i] = iw[i + g] * c, c *= w[i + g]
f(r, 2);
s = c = 1;
f(b, 3);
#undef f
}
TE Z fps_t<T>::ntt(fps &a, bool in) -> void {
assert(T::can_ntt());
const uint m = p;
static T w[30], iw[30], r[30], ir[30], b[30], ib[30];
static bool ok = 0;
if (ok == 0) ok = 1, ntr(w, iw, r, ir, b, ib);
#define f(k) a[i + of + k * p]
#define g(k) ull(f(k).val())
#define tp topbit(~s & -~s)
int N = si(a), n = topbit(N);
if (not in) {
int sz = 0;
while (sz < n) {
if (n - sz == 1) {
int p = 1 << (n - sz - 1);
T c = 1;
FOR(s, 1 << sz) {
int of = s << (n - sz);
FOR(i, p) {
T l = f(0), w = f(1) * c;
f(0) = l + w, f(1) = l - w;
}
c *= r[tp];
}
++sz;
} else {
int p = 1 << (n - sz - 2);
T c = 1, in = w[2];
FOR(s, 1 << sz) {
T rr = c * c, R = rr * c;
int of = s << (n - sz);
FOR(i, p) {
ull x = g(0), y = g(1) * c.val(), e = g(2) * rr.val(),
r = g(3) * R.val(), t = (y + M - r) % m * in.val();
f(0) = x + y + e + r;
f(1) = x + e + M + M - y - r;
f(2) = x + M - e + t;
f(3) = x + M + M - e - t;
}
c *= b[tp];
}
sz += 2;
}
}
} else {
T c = T(N).inv();
FOR(i, N) a[i] *= c;
int sz = n;
while (sz) {
if (sz == 1) {
int p = 1 << (n - sz);
T c = 1;
FOR(s, 1 << (sz - 1)) {
int of = s << (n - sz + 1);
FOR(i, p) {
ull l = g(0), r = g(1);
f(0) = l + r, f(1) = (m + l - r) * c.val();
}
c *= ir[tp];
}
--sz;
} else {
int p = 1 << (n - sz);
T c = 1, in = iw[2];
FOR(s, 1 << (sz - 2)) {
T rr = c * c, R = rr * c;
int of = s << (n - sz + 2);
FOR(i, p) {
ull x = g(0), y = g(1), e = g(2), r = g(3),
t = (m + e - r) * in.val() % m;
f(0) = x + y + e + r;
f(1) = (x + m - y + t) * c.val();
f(2) = (x + y + m + m - e - r) * rr.val();
f(3) = (x + m + m - y - t) * R.val();
}
c *= ib[tp];
}
sz -= 2;
}
}
}
}
#undef f
#undef g
#undef tp
TE Z fps_t<T>::conv_naive(cf a, cf b) -> fps {
int N = si(a), M = si(b), sz = N + M - 1;
if (not N or not M) return {};
if (N > M) return conv_naive(b, a);
fps c(sz);
FOR(i, N) FOR(k, M) c[i + k] += a[i] * b[k];
return c;
}
TE Z fps_t<T>::conv_kara(cf f, cf g) -> fps {
constexpr int lm = 30;
if (min(si(f), si(g)) <= lm) return conv_naive(f, g);
int N = max(si(f), si(g)), M = ceil(N, 2);
fps f1, f2, g1, g2;
if (si(f) < M) f1 = f;
if (si(f) >= M) f1 = {bg(f), bg(f) + M};
if (si(f) >= M) f2 = {bg(f) + M, ed(f)};
if (si(g) < M) g1 = g;
if (si(g) >= M) g1 = {bg(g), bg(g) + M};
if (si(g) >= M) g2 = {bg(g) + M, ed(g)};
fps a = conv_kara(f1, g1);
fps b = conv_kara(f2, g2);
FOR(i, si(f2)) f1[i] += f2[i];
FOR(i, si(g2)) g1[i] += g2[i];
fps c = conv_kara(f1, g1), F(si(f) + si(g) - 1);
FOR(i, si(a)) F[i] += a[i], c[i] -= a[i];
FOR(i, si(b)) F[2 * M + i] += b[i], c[i] -= b[i];
if (c.back() == T(0)) pop(c);
FOR(i, si(c)) if (c[i] != T(0)) F[M + i] += c[i];
return F;
}
TE Z fps_t<T>::conv_ntt(fps a, fps b) -> fps {
assert(T::can_ntt());
int N = si(a), M = si(b), sz = 1;
if (min(N, M) == 0) return {};
while (sz < N + M - 1) sz <<= 1;
sh(a, sz), sh(b, sz);
ntt(a, 0);
ntt(b, 0);
FOR(i, sz) a[i] *= b[i];
ntt(a, 1);
sh(a, N + M - 1);
return a;
}
TE Z fps_t<T>::conv_mtt(cf a, cf b) -> fps {
int N = si(a), M = si(b);
if (not N or not M) return {};
f0::fps a0(N), b0(M);
f1::fps a1(N), b1(M);
f2::fps a2(N), b2(M);
FOR(i, N) a0[i] = a[i].val(), a1[i] = a[i].val(), a2[i] = a[i].val();
FOR(i, M) b0[i] = b[i].val(), b1[i] = b[i].val(), b2[i] = b[i].val();
Z c0 = f0::conv_ntt(a0, b0);
Z c1 = f1::conv_ntt(a1, b1);
Z c2 = f2::conv_ntt(a2, b2);
fps c(si(c0));
FOR(i, N + M - 1) c[i] = crt(c0[i].val(), c1[i].val(), c2[i].val());
return c;
}
TE Z fps_t<T>::conv(cf a, cf b) -> fps {
int N = si(a), M = si(b);
if (min(N, M) == 0) return {};
if (T::can_ntt()) {
if (min(N, M) <= 50) return conv_kara(a, b);
return conv_ntt(a, b);
}
if (min(N, M) <= 200) return conv_kara(a, b);
return conv_mtt(a, b);
}
TE Z fps_t<T>::sq_ntt(fps a) -> fps {
assert(T::can_ntt());
int N = si(a), sz = 1;
if (N == 0) return {};
while (sz < N + N - 1) sz <<= 1;
sh(a, sz);
ntt(a, 0);
FOR(i, sz) a[i] *= a[i];
ntt(a, 1);
sh(a, N + N - 1);
return a;
}
TE Z fps_t<T>::sq_mtt(cf a) -> fps {
int N = si(a);
if (N == 0) return {};
f0::fps a0(N);
f1::fps a1(N);
f2::fps a2(N);
FOR(i, N) a0[i] = a[i].val(), a1[i] = a[i].val(), a2[i] = a[i].val();
Z c0 = f0::sq_ntt(a0);
Z c1 = f1::sq_ntt(a1);
Z c2 = f2::sq_ntt(a2);
fps c(si(c0));
FOR(i, N + N - 1) c[i] = crt(c0[i].val(), c1[i].val(), c2[i].val());
return c;
}
TE Z fps_t<T>::sq(cf a) -> fps {
int N = si(a);
if (T::can_ntt()) {
if (N <= 50) return conv_naive(a, a);
return sq_ntt(a);
}
if (N <= 150) return conv_kara(a, a);
return sq_mtt(a);
}
TE Z fps_t<T>::diff(cf f) -> fps {
int N = si(f);
if (N <= 1) return {};
fps g(N - 1);
FOR(i, N - 1) g[i] = f[i + 1] * T(i + 1);
return g;
}
TE Z fps_t<T>::inte(cf f) -> fps {
int N = si(f);
fps g(N + 1);
FOR(i, 1, N + 1) g[i] = f[i - 1] * inv(i);
return g;
}
TE Z fps_t<T>::inte(cf f, T l, T r) -> T {
T s = 0, L = 1, R = 1;
int N = si(f);
FOR(i, N) {
L *= l, R *= r;
s += inv(i + 1) * f[i] * (L - R);
}
return s;
}
TE Z fps_t<T>::crt_128(ull a, ull b, ull c) -> u128 {
constexpr ull x = 104'391'568, xx = 190'329'765;
ull t = (b - a + p1) * x % p1, s = a + t * p0;
t = (c - s % p2 + p2) * xx % p2;
return s + u128(t) * p0 * p1;
}
TE Z fps_t<T>::conv_int(const vc<int> &a, const vc<int> &b) -> vc<int> {
f0::fps a0(all(a)), b0(all(b));
f1::fps a1(all(a)), b1(all(b));
f2::fps a2(all(a)), b2(all(b));
Z c0 = f0::conv_ntt(a0, b0);
Z c1 = f1::conv_ntt(a1, b1);
Z c2 = f2::conv_ntt(a2, b2);
vc<int> c(si(c0));
u128 x = 0;
static constexpr int M = 1000000000;
int N = si(a) + si(b) - 1;
FOR(i, N) {
x += crt_128(c0[i].val(), c1[i].val(), c2[i].val());
c[i] = x % M, x /= M;
}
while (x) c.ep(x % M), x /= M;
return c;
}
struct bigint {
static constexpr int TEN[]
{1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000};
static constexpr int n = 9, M = TEN[n];
using T = bigint;
int op;
vc<int> a;
bigint() : op(0), a() {}
bigint(int op, const vc<int> &a) : op(op), a(a) {}
bigint(ll x) {
if (x == 0) { op = 0; return; }
op = 1;
if (x < 0) op = -1, x = -x;
while (x) a.ep(x % M), x /= M;
}
bigint(string s) {
if (s[0] == '0') { op = 0; return; }
op = 1;
if (s[0] == '-') op = -1, s.erase(bg(s));
reverse(s);
int N = si(s), m = ceil(N, n);
a.assign(m, 0);
FOR(i, N) a[i / n] += TEN[i % n] * (s[i] - '0');
}
void from_str(string s) {
a.clear();
if (s[0] == '0') { op = 0; return; }
op = 1;
if (s[0] == '-') op = -1, s.erase(bg(s));
reverse(s);
int N = si(s), m = ceil(N, n);
a.assign(m, 0);
FOR(i, N) a[i / n] += TEN[i % n] * (s[i] - '0');
}
bool operator<(const T &p) const {
if (op != p.op) return op < p.op;
if (op == 0) return 0;
if (op == 1) return less(a, p.a);
else return less(p.a, a);
}
bool operator>(const T &p) const { return p < *this; }
bool operator<=(const T &p) const { return not(*this > p); }
bool operator>=(const T &p) const { return not(*this < p); }
bool operator==(const T &p) const { return op == p.op and a == p.a; }
bool operator!=(const T &p) const { return op != p.op or a != p.a; }
T operator-() const {
T p = *this;
return p.op = -op, p;
}
T operator+() const { return *this; }
T &operator+=(const T &p) {
if (op == 0) return *this = p;
if (p.op == 0) return *this;
if (op == p.op) return a = sm(a, p.a), *this;
if (less(a, p.a)) return a = sb(p.a, a), op = -op, *this;
a = sb(a, p.a);
if (is_zero(a)) op = 0;
return *this;
}
T &operator-=(const T &p) {
if (p.op == 0) return *this;
if (op == 0) return *this = -p;
if (op != p.op) return a = sm(a, p.a), *this;
if (less(a, p.a)) return a = sb(p.a, a), op = -op, *this;
a = sb(a, p.a);
if (is_zero(a)) op = 0;
return *this;
}
T &operator*=(const T &p) {
op *= p.op;
if (not op) a.clear();
else a = ml(a, p.a);
return *this;
}
T &operator/=(const T &p) { return *this = divmod(p).fi; }
T &operator%=(const T &p) { return *this = divmod(p).se; }
T operator+(const T &p) const { return T(*this) += p; }
T operator-(const T &p) const { return T(*this) -= p; }
T operator*(const T &p) const { return T(*this) *= p; }
T operator/(const T &p) const { return T(*this) /= p; }
T operator%(const T &p) const { return T(*this) %= p; }
pair<T, T> divmod(const T &p) const {
assert(p.op != 0);
if (op == 0) return {T(), T()};
Z res = divmod_newton(a, p.a);
int op1 = op * p.op, op2 = op;
if (is_zero(res.fi)) op1 = 0;
if (is_zero(res.se)) op2 = 0;
return {{op1, res.fi}, {op2, res.se}};
}
T pow(ll k) const { return pow(*this, k); }
static T pow(T a, ll k) {
if (k == 0) return 1;
T p = pow(a, k >> 1), s = p * p;
return (k & 1) ? s * a : s;
}
string to_string() const {
if (not op) return "0";
string s = to_string(a);
if (op == -1) s += '-';
return reverse(s), s;
}
string to_binary_string() const {
assert(op != -1);
vc<uint> A(all(a));
string s;
while (1) {
while (not A.empty() and A.back() == uint(0)) pop(A);
if (A.empty()) break;
ull r = 0;
int N = si(A);
FOR_R(i, N) {
r = r * M + A[i];
A[i] = r >> 32;
r &= uint(-1);
}
FOR(i, 32) s += '0' + (r >> i & 1);
}
while (not s.empty() and s.back() == '0') pop(s);
if (s.empty()) s += '0';
return reverse(s), s;
}
ll to_ll() const {
if (op == 0) return 0;
ll x = to_ll(a);
return op == -1 ? -x : x;
}
i128 to_i128() const {
if (op == 0) return 0;
i128 x = to_i128(a);
return op == -1 ? -x : x;
}
friend ostream &operator<<(ostream &cout, const T &b) {
return cout << b.to_string();
}
friend istream &operator>>(istream &cin, T &b) {
static string s;
cin >> s;
b.from_str(s);
return cin;
}
bool is_zero() const { return op == 0; }
bool is_one() const { return op == 1 and si(a) == 1 and a[0] == 1; }
bool is_odd() const { return op != 0 and (a[0] & 1); }
bool is_even() const { return not is_odd(); }
T div2() const {
T r = *this;
int N = si(a);
for (int i = N; i--; r.a[i] >>= 1)
if ((r.a[i] & 1) and i) r.a[i - 1] += M;
sh(r.a);
if (r.a.empty()) r.op = 0;
return r;
}
T gcd(const T &x) const {
T a = this->abs(), b = x.abs();
if (a < b) swap(a, b);
if (b.is_zero()) return a;
int t = 0;
while (a.is_even() and b.is_even()) a = a.div2(), b = b.div2(), ++t;
while (b > 0) {
if (a.is_even()) a = a.div2();
else if (b.is_even()) b = b.div2();
else a -= b;
if (a < b) swap(a, b);
}
while (t--) a += a;
return a;
}
T lcm(const T &x) const { return *this / gcd(x) * x; }
T abs() const {
if (op == 0) return 0;
if (op < 0) return -(*this);
return *this;
}
using f = vc<int>;
using cf = const f &;
using PVV = pair<f, f>;
static vc<int> ml(cf a, cf b) {
int N = si(a), m = si(b), t = min(N, m);
if (t == 0) return {};
if (t <= 500) {
f c(N + m - 1);
u128 x = 0;
FOR(k, N + m - 1) {
int s = max(0, k + 1 - m), t = min(k, N - 1);
FOR(i, s, t + 1) x += ull(a[i]) * b[k - i];
c[k] = x % M;
x /= M;
}
while (x > 0) c.ep(x % M), x /= M;
return c;
}
static fps_t<mint_t<M>> X;
return X.conv_int(a, b);
}
static bool is_zero(cf a) { return a.empty(); }
static bool is_one(cf a) { return si(a) == 1 and a[0] == 1; }
static bool eq(cf a, cf b) { return a == b; }
static bool less(cf a, cf b) {
if (si(a) != si(b)) return si(a) < si(b);
int N = si(a);
FOR_R(i, N) if (a[i] != b[i]) return a[i] < b[i];
return 0;
}
static bool greater(cf a, cf b) { return less(b, a); }
static bool less_eq(cf a, cf b) { return not greater(a, b); }
static bool greater_eq(cf a, cf b) { return not less(a, b); }
static void sh(f &a) {
while (not a.empty() and a.back() == 0) pop(a);
}
static f to_vec(ll x) {
f s;
while (x) s.ep(x % M), x /= M;
return s;
}
static ll to_ll(cf a) {
ll s = 0;
int N = si(a);
FOR_R(i, N) s = s * M + a[i];
return s;
}
static i128 to_i128(cf a) {
i128 s = 0;
int N = si(a);
FOR_R(i, N) s = s * M + a[i];
return s;
}
static string to_string(cf a) {
string s;
for (int x : a) FOR(n) s += '0' + x % 10, x /= 10;
while (s.back() == '0') pop(s);
return s;
}
static f sm(cf a, cf b) {
f c(a);
c.resize(max(si(a), si(b)) + 1);
int N = si(b);
FOR(i, N) c[i] += b[i];
N = si(c) - 1;
FOR(i, N) if (c[i] >= M) c[i] -= M, ++c[i + 1];
return sh(c), c;
}
static f sb(cf a, cf b) {
f c(a);
int N = si(b);
FOR(i, N) c[i] -= b[i];
N = si(a) - 1;
FOR(i, N) if (c[i] < 0) c[i] += M, --c[i + 1];
return sh(c), c;
}
static PVV divmod_ll_int(cf a, cf b) {
assert(0 <= si(a) and si(a) <= 2);
assert(si(b) == 1);
ll x = to_ll(a);
int y = b[0];
return {to_vec(x / y), to_vec(x % y)};
}
static PVV divmod_ll_ll(cf a, cf b) {
assert(0 <= si(a) and si(a) <= 2);
assert(1 <= si(b) and si(b) <= 2);
ll x = to_ll(a), y = to_ll(b);
return {to_vec(x / y), to_vec(x % y)};
}
static PVV divmod_1e9(cf a, cf b) {
assert(si(b) == 1);
if (si(a) <= 2) return divmod_ll_int(a, b);
int N = si(a);
f s(N);
ll d = 0;
int bb = b[0];
FOR_R(i, N) {
d = d * M + a[i];
assert(d <= 1ll * M * bb);
int q = d / bb, r = d % bb;
s[i] = q, d = r;
}
return sh(s), pair{s, d ? f{int(d)} : f{}};
}
static PVV divmod_naive(cf a, cf b) {
assert(not is_zero(b));
if (si(b) == 1) return divmod_1e9(a, b);
if (max(si(a), si(b)) <= 2) return divmod_ll_ll(a, b);
if (less(a, b)) return {{}, a};
int norm = M / (b.back() + 1);
f x = ml(a, {norm}), y = ml(b, {norm});
int yb = y.back();
f s(si(x) - si(y) + 1);
f r(ed(x) - si(y), ed(x));
int N = si(s);
FOR_R(i, N) {
if (si(r) < si(y));
else if (si(r) == si(y)) {
if (less_eq(y, r)) s[i] = 1, r = sb(r, y);
} else {
assert(si(y) + 1 == si(r));
ll rb = 1ll * r.back() * M + ed(r)[-2];
int q = rb / yb;
f yq = ml(y, {q});
while (less(r, yq)) --q, yq = sb(yq, y);
r = sb(r, yq);
while (less_eq(y, r)) ++q, r = sb(r, y);
s[i] = q;
}
if (i) r.insert(r.begin(), x[i - 1]);
}
sh(s), sh(r);
Z [ss, rr] = divmod_1e9(r, {norm});
assert(is_zero(rr));
return {s, ss};
};
static f kinv(cf a, int deg) {
assert(not a.empty() and M / 2 <= a.back() and a.back() < M);
int k = deg, N = si(a);
while (k > 64) k = (k + 1) >> 1;
f b(N + k + 1);
b.back() = 1;
b = divmod_naive(b, a).fi;
while (k < deg) {
f s = ml(b, b);
s.insert(bg(s), 0);
int d = min(N, k * 2 + 1);
f t{ed(a) - d, ed(a)}, v = ml(s, t);
v.erase(bg(v), bg(v) + d);
f w(k + 1), ww = sm(b, b);
copy(all(ww), back_inserter(w));
b = sb(w, v);
b.erase(b.begin());
k <<= 1;
}
return b.erase(b.begin(), b.begin() + k - deg), b;
}
static PVV divmod_newton(cf a, cf b) {
assert(not is_zero(b));
if (si(b) <= 64) return divmod_naive(a, b);
if (si(a) - si(b) <= 64) return divmod_naive(a, b);
int norm = M / (b.back() + 1);
f x = ml(a, {norm}), y = ml(b, {norm});
int N = si(x), m = si(y);
int deg = N - m + 2;
f z = kinv(y, deg), q = ml(x, z);
q.erase(bg(q), bg(q) + m + deg);
f yq = ml(y, q);
while (less(x, yq)) q = sb(q, {1}), yq = sb(yq, y);
f r = sb(x, yq);
while (less_eq(y, r)) q = sm(q, {1}), r = sb(r, y);
sh(q);
sh(r);
Z [qq, rr] = divmod_1e9(r, {norm});
assert(is_zero(rr));
return {std::move(q), std::move(qq)};
}
};
bigint abs(const bigint &x) { return x.abs(); }
bigint gcd(const bigint &a, const bigint &b) { return a.gcd(b); }
bigint lcm(const bigint &a, const bigint &b) { return a.lcm(b); }
#ifdef FIO
void rd(bigint &x) {
static string s;
rd(s);
x.from_str(s);
}
void wt(const bigint &x) {
wt(x.to_string());
}
#endif
TE struct fibonacci {
T operator()(ll K, T T0 = 0, T T1 = 1, T P = 1, T Q = 1) {
mat R = pow(mat{0, 1, Q, P}, K);
return R.a * T0 + R.b * T1;
}
T f(ll K, T T0 = 0, T T1 = 1, T P = 1, T Q = 1) {
mat R = pow(mat{0, 1, Q, P}, K);
return R.a * T0 + R.b * T1;
}
struct mat {
T a, b, c, d;
};
constexpr static mat mul(const mat &x, const mat &y) {
return {x.a * y.a + x.b * y.c, x.a * y.b + x.b * y.d,
x.c * y.a + x.d * y.c, x.c * y.b + x.d * y.d};
}
constexpr static mat pow(mat a, ll k) {
mat r = {1, 0, 0, 1};
for (; k; k >>= 1, a = mul(a, a)) {
if (k & 1) r = mul(r, a);
}
return r;
}
};
void Yorisou() {
LL(N);
if (N == 2) return print(3), print("INF");
using ll = bigint;
ll x = fibonacci<ll>{}(N);
if ((N & 1) == 0) {
ll d = fibonacci<ll>{}(N >> 1);
x -= d * d;
}
print(N);
print(x);
}
int main() {
Yorisou();
return 0;
}