QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#535348 | #9225. Fibonacci Fusion | maspy | AC ✓ | 3148ms | 41276kb | C++20 | 54.3kb | 2024-08-27 23:42:56 | 2024-08-27 23:42:57 |
Judging History
answer
#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...) \
vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)
#define FOR_subset(t, s) for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define stoi stoll
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
template <typename T>
T floor(T a, T b) {
return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sm = 0;
for (auto &&a: A) sm += a;
return sm;
}
#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()
template <typename T>
T POP(deque<T> &que) {
T a = que.front();
que.pop_front();
return a;
}
template <typename T>
T POP(pq<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(pqg<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
T a = que.back();
que.pop_back();
return a;
}
template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
if (check_ok) assert(check(ok));
while (abs(ok - ng) > 1) {
auto x = (ng + ok) / 2;
(check(x) ? ok : ng) = x;
}
return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
FOR(iter) {
double x = (ok + ng) / 2;
(check(x) ? ok : ng) = x;
}
return (ok + ng) / 2;
}
template <class T, class S>
inline bool chmax(T &a, const S &b) {
return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
return (a > b ? a = b, 1 : 0);
}
// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
vc<int> A(S.size());
FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
return A;
}
template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
int N = A.size();
vector<T> B(N + 1);
FOR(i, N) { B[i + 1] = B[i] + A[i]; }
if (off == 0) B.erase(B.begin());
return B;
}
// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
vector<int> ids(len(A));
iota(all(ids), 0);
sort(all(ids), [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
return ids;
}
// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
vc<T> B(len(I));
FOR(i, len(I)) B[i] = A[I[i]];
return B;
}
template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
vc<T> &res = first;
(res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "library/other/io.hpp"
#define FASTIO
#include <unistd.h>
// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t 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;
}
void rd(char &c) {
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
}
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));
}
template <typename T>
void rd_real(T &x) {
string s;
rd(s);
x = stod(s);
}
template <typename T>
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;
}
}
void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }
template <class T, class U>
void rd(pair<T, U> &p) {
return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
rd(x);
rd_tuple<N + 1>(t);
}
}
template <class... T>
void rd(tuple<T...> &tpl) {
rd_tuple(tpl);
}
template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
for (auto &d: x) rd(d);
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
rd(h), read(t...);
}
void wt(const char c) {
if (por == SZ) flush();
obuf[por++] = c;
}
void wt(const string s) {
for (char c: s) wt(c);
}
void wt(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) wt(s[i]);
}
template <typename T>
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;
}
template <typename T>
void wt_real(T x) {
ostringstream oss;
oss << fixed << setprecision(15) << double(x);
string s = oss.str();
wt(s);
}
void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }
template <class T, class U>
void wt(const pair<T, U> val) {
wt(val.first);
wt(' ');
wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { wt(' '); }
const auto x = std::get<N>(t);
wt(x);
wt_tuple<N + 1>(t);
}
}
template <class... T>
void wt(tuple<T...> tpl) {
wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
template <class T>
void wt(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
wt(head);
if (sizeof...(Tail)) wt(' ');
print(forward<Tail>(tail)...);
}
// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;
#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define U32(...) \
u32 __VA_ARGS__; \
read(__VA_ARGS__)
#define U64(...) \
u64 __VA_ARGS__; \
read(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
read(name)
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"
#line 2 "library/mod/modint_common.hpp"
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::raw(q));
}
return dat[n];
}
template <typename mint>
mint fact(int n) {
static const int mod = mint::get_mod();
assert(0 <= n && n < mod);
static vector<mint> dat = {1, 1};
while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * mint::raw(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 vvc<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(i, H) {
C[i].resize(k + 1);
FOR(j, W, k + 1) { C[i][j] = calc(i, j); }
}
W = k + 1;
}
if (H <= n) {
C.resize(n + 1);
FOR(i, H, n + 1) {
C[i].resize(W);
FOR(j, W) { C[i][j] = calc(i, j); }
}
H = n + 1;
}
return C[n][k];
}
template <typename mint, bool large = false, bool dense = false>
mint C(ll n, ll k) {
assert(n >= 0);
if (k < 0 || n < k) return 0;
if constexpr (dense) return C_dense<mint>(n, k);
if constexpr (!large) return multinomial<mint>(n, k, n - k);
k = min(k, n - k);
mint x(1);
FOR(i, k) x *= mint(n - i);
return x * fact_inv<mint>(k);
}
template <typename mint, bool large = false>
mint C_inv(ll n, ll 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(ll n, ll 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);
}
#line 3 "library/mod/modint.hpp"
template <int mod>
struct modint {
static constexpr u32 umod = u32(mod);
static_assert(umod < u32(1) << 31);
u32 val;
static modint raw(u32 v) {
modint x;
x.val = v;
return x;
}
constexpr modint() : val(0) {}
constexpr modint(u32 x) : val(x % umod) {}
constexpr modint(u64 x) : val(x % umod) {}
constexpr modint(u128 x) : val(x % umod) {}
constexpr modint(int x) : val((x %= mod) < 0 ? x + mod : x){};
constexpr modint(ll x) : val((x %= mod) < 0 ? x + mod : x){};
constexpr modint(i128 x) : val((x %= mod) < 0 ? x + mod : x){};
bool operator<(const modint &other) const { return val < other.val; }
modint &operator+=(const modint &p) {
if ((val += p.val) >= umod) val -= umod;
return *this;
}
modint &operator-=(const modint &p) {
if ((val += umod - p.val) >= umod) val -= umod;
return *this;
}
modint &operator*=(const modint &p) {
val = u64(val) * p.val % umod;
return *this;
}
modint &operator/=(const modint &p) {
*this *= p.inverse();
return *this;
}
modint operator-() const { return modint::raw(val ? mod - val : u32(0)); }
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(ll n) const {
assert(n >= 0);
modint ret(1), mul(val);
while (n > 0) {
if (n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
static constexpr int get_mod() { return mod; }
// (n, r), r は 1 の 2^n 乗根
static constexpr pair<int, int> ntt_info() {
if (mod == 120586241) return {20, 74066978};
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 == 943718401) return {22, 663003469};
if (mod == 998244353) return {23, 31};
if (mod == 1004535809) return {21, 836905998};
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().fi != -1; }
};
#ifdef FASTIO
template <int mod>
void rd(modint<mod> &x) {
fastio::rd(x.val);
x.val %= mod;
// assert(0 <= x.val && x.val < mod);
}
template <int mod>
void wt(modint<mod> x) {
fastio::wt(x.val);
}
#endif
using modint107 = modint<1000000007>;
using modint998 = modint<998244353>;
#line 2 "library/mod/mod_inv.hpp"
// long でも大丈夫
// (val * x - 1) が mod の倍数になるようにする
// 特に mod=0 なら x=0 が満たす
ll mod_inv(ll val, ll mod) {
if (mod == 0) return 0;
mod = abs(mod);
val %= mod;
if (val < 0) val += mod;
ll 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;
}
#line 2 "library/mod/crt3.hpp"
constexpr u32 mod_pow_constexpr(u64 a, u64 n, u32 mod) {
a %= mod;
u64 res = 1;
FOR(32) {
if (n & 1) res = res * a % mod;
a = a * a % mod, n /= 2;
}
return res;
}
template <typename T, u32 p0, u32 p1>
T CRT2(u64 a0, u64 a1) {
static_assert(p0 < p1);
static constexpr u64 x0_1 = mod_pow_constexpr(p0, p1 - 2, p1);
u64 c = (a1 - a0 + p1) * x0_1 % p1;
return a0 + c * p0;
}
template <typename T, u32 p0, u32 p1, u32 p2>
T CRT3(u64 a0, u64 a1, u64 a2) {
static_assert(p0 < p1 && p1 < p2);
static constexpr u64 x1 = mod_pow_constexpr(p0, p1 - 2, p1);
static constexpr u64 x2 = mod_pow_constexpr(u64(p0) * p1 % p2, p2 - 2, p2);
static constexpr u64 p01 = u64(p0) * p1;
u64 c = (a1 - a0 + p1) * x1 % p1;
u64 ans_1 = a0 + c * p0;
c = (a2 - ans_1 % p2 + p2) * x2 % p2;
return T(ans_1) + T(c) * T(p01);
}
template <typename T, u32 p0, u32 p1, u32 p2, u32 p3, u32 p4>
T CRT5(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4) {
static_assert(p0 < p1 && p1 < p2 && p2 < p3 && p3 < p4);
static constexpr u64 x1 = mod_pow_constexpr(p0, p1 - 2, p1);
static constexpr u64 x2 = mod_pow_constexpr(u64(p0) * p1 % p2, p2 - 2, p2);
static constexpr u64 x3
= mod_pow_constexpr(u64(p0) * p1 % p3 * p2 % p3, p3 - 2, p3);
static constexpr u64 x4
= mod_pow_constexpr(u64(p0) * p1 % p4 * p2 % p4 * p3 % p4, p4 - 2, p4);
static constexpr u64 p01 = u64(p0) * p1;
static constexpr u64 p23 = u64(p2) * p3;
u64 c = (a1 - a0 + p1) * x1 % p1;
u64 ans_1 = a0 + c * p0;
c = (a2 - ans_1 % p2 + p2) * x2 % p2;
u128 ans_2 = ans_1 + c * static_cast<u128>(p01);
c = static_cast<u64>(a3 - ans_2 % p3 + p3) * x3 % p3;
u128 ans_3 = ans_2 + static_cast<u128>(c * p2) * p01;
c = static_cast<u64>(a4 - ans_3 % p4 + p4) * x4 % p4;
return T(ans_3) + T(c) * T(p01) * T(p23);
}
#line 2 "library/poly/convolution_naive.hpp"
template <class T, typename enable_if<!has_mod<T>::value>::type* = nullptr>
vc<T> convolution_naive(const vc<T>& a, const vc<T>& b) {
int n = int(a.size()), m = int(b.size());
if (n > m) return convolution_naive<T>(b, a);
if (n == 0) return {};
vector<T> ans(n + m - 1);
FOR(i, n) FOR(j, m) ans[i + j] += a[i] * b[j];
return ans;
}
template <class T, typename enable_if<has_mod<T>::value>::type* = nullptr>
vc<T> convolution_naive(const vc<T>& a, const vc<T>& b) {
int n = int(a.size()), m = int(b.size());
if (n > m) return convolution_naive<T>(b, a);
if (n == 0) return {};
vc<T> ans(n + m - 1);
if (n <= 16 && (T::get_mod() < (1 << 30))) {
for (int k = 0; k < n + m - 1; ++k) {
int s = max(0, k - m + 1);
int t = min(n, k + 1);
u64 sm = 0;
for (int i = s; i < t; ++i) { sm += u64(a[i].val) * (b[k - i].val); }
ans[k] = sm;
}
} else {
for (int k = 0; k < n + m - 1; ++k) {
int s = max(0, k - m + 1);
int t = min(n, k + 1);
u128 sm = 0;
for (int i = s; i < t; ++i) { sm += u64(a[i].val) * (b[k - i].val); }
ans[k] = T::raw(sm % T::get_mod());
}
}
return ans;
}
#line 2 "library/poly/convolution_karatsuba.hpp"
// 任意の環でできる
template <typename T>
vc<T> convolution_karatsuba(const vc<T>& f, const vc<T>& g) {
const int thresh = 30;
if (min(len(f), len(g)) <= thresh) return convolution_naive(f, g);
int n = max(len(f), len(g));
int m = ceil(n, 2);
vc<T> f1, f2, g1, g2;
if (len(f) < m) f1 = f;
if (len(f) >= m) f1 = {f.begin(), f.begin() + m};
if (len(f) >= m) f2 = {f.begin() + m, f.end()};
if (len(g) < m) g1 = g;
if (len(g) >= m) g1 = {g.begin(), g.begin() + m};
if (len(g) >= m) g2 = {g.begin() + m, g.end()};
vc<T> a = convolution_karatsuba(f1, g1);
vc<T> b = convolution_karatsuba(f2, g2);
FOR(i, len(f2)) f1[i] += f2[i];
FOR(i, len(g2)) g1[i] += g2[i];
vc<T> c = convolution_karatsuba(f1, g1);
vc<T> F(len(f) + len(g) - 1);
assert(2 * m + len(b) <= len(F));
FOR(i, len(a)) F[i] += a[i], c[i] -= a[i];
FOR(i, len(b)) F[2 * m + i] += b[i], c[i] -= b[i];
if (c.back() == T(0)) c.pop_back();
FOR(i, len(c)) if (c[i] != T(0)) F[m + i] += c[i];
return F;
}
#line 2 "library/poly/ntt.hpp"
template <class mint>
void ntt(vector<mint>& a, bool inverse) {
assert(mint::can_ntt());
const int rank2 = mint::ntt_info().fi;
const int mod = mint::get_mod();
static array<mint, 30> root, iroot;
static array<mint, 30> rate2, irate2;
static array<mint, 30> rate3, irate3;
assert(rank2 != -1 && len(a) <= (1 << max(0, rank2)));
static bool prepared = 0;
if (!prepared) {
prepared = 1;
root[rank2] = mint::ntt_info().se;
iroot[rank2] = mint(1) / root[rank2];
FOR_R(i, rank2) {
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 = topbit(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(s, 1 << len) {
int offset = s << (h - len);
FOR(i, p) {
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[topbit(~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++) {
u64 mod2 = u64(mod) * mod;
u64 a0 = a[i + offset].val;
u64 a1 = u64(a[i + offset + p].val) * rot.val;
u64 a2 = u64(a[i + offset + 2 * p].val) * rot2.val;
u64 a3 = u64(a[i + offset + 3 * p].val) * rot3.val;
u64 a1na3imag = (a1 + mod2 - a3) % mod * imag.val;
u64 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[topbit(~s & -~s)];
}
len += 2;
}
}
} else {
mint coef = mint(1) / mint(len(a));
FOR(i, len(a)) a[i] *= coef;
int len = h;
while (len) {
if (len == 1) {
int p = 1 << (h - len);
mint irot = 1;
FOR(s, 1 << (len - 1)) {
int offset = s << (h - len + 1);
FOR(i, p) {
u64 l = a[i + offset].val;
u64 r = a[i + offset + p].val;
a[i + offset] = l + r;
a[i + offset + p] = (mod + l - r) * irot.val;
}
irot *= irate2[topbit(~s & -~s)];
}
len--;
} else {
int p = 1 << (h - len);
mint irot = 1, iimag = iroot[2];
FOR(s, (1 << (len - 2))) {
mint irot2 = irot * irot;
mint irot3 = irot2 * irot;
int offset = s << (h - len + 2);
for (int i = 0; i < p; i++) {
u64 a0 = a[i + offset + 0 * p].val;
u64 a1 = a[i + offset + 1 * p].val;
u64 a2 = a[i + offset + 2 * p].val;
u64 a3 = a[i + offset + 3 * p].val;
u64 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[topbit(~s & -~s)];
}
len -= 2;
}
}
}
}
#line 1 "library/poly/fft.hpp"
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
#line 9 "library/poly/convolution.hpp"
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(i, len(a)) c[i + len(b)] += a[i] * b_last;
FOR(i, len(b)) c[i + len(a)] += 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(i, sz) 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 = len(a), m = len(b);
if (!n || !m) return {};
static constexpr int p0 = 167772161;
static constexpr int p1 = 469762049;
static constexpr int p2 = 754974721;
using mint0 = modint<p0>;
using mint1 = modint<p1>;
using mint2 = modint<p2>;
vc<mint0> a0(n), b0(m);
vc<mint1> a1(n), b1(m);
vc<mint2> 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;
auto c0 = convolution_ntt<mint0>(a0, b0);
auto c1 = convolution_ntt<mint1>(a1, b1);
auto c2 = convolution_ntt<mint2>(a2, b2);
vc<mint> c(len(c0));
FOR(i, n + m - 1) {
c[i] = CRT3<mint, p0, p1, p2>(c0[i].val, c1[i].val, c2[i].val);
}
return c;
}
template <typename R>
vc<double> convolution_fft(const vc<R>& a, const vc<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++) {
double x = (i < (int)a.size() ? a[i] : 0);
double 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<ll> convolution(const vector<ll>& a, const vector<ll>& b) {
int n = len(a), m = len(b);
if (!n || !m) return {};
if (min(n, m) <= 2500) return convolution_naive(a, b);
ll abs_sum_a = 0, abs_sum_b = 0;
ll LIM = 1e15;
FOR(i, n) abs_sum_a = min(LIM, abs_sum_a + abs(a[i]));
FOR(i, m) abs_sum_b = min(LIM, abs_sum_b + abs(b[i]));
if (i128(abs_sum_a) * abs_sum_b < 1e15) {
vc<double> c = convolution_fft<ll>(a, b);
vc<ll> res(len(c));
FOR(i, len(c)) res[i] = ll(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>;
vc<mint1> a1(n), b1(m);
vc<mint2> a2(n), b2(m);
vc<mint3> a3(n), b3(m);
FOR(i, n) a1[i] = a[i], a2[i] = a[i], a3[i] = a[i];
FOR(i, m) 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);
vc<ll> c(n + m - 1);
FOR(i, n + m - 1) {
u64 x = 0;
x += (c1[i].val * i1) % MOD1 * M2M3;
x += (c2[i].val * i2) % MOD2 * M1M3;
x += (c3[i].val * i3) % MOD3 * M1M2;
ll 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>
vc<mint> convolution(const vc<mint>& a, const vc<mint>& b) {
int n = len(a), m = len(b);
if (!n || !m) return {};
if (mint::can_ntt()) {
if (min(n, m) <= 50) return convolution_karatsuba<mint>(a, b);
return convolution_ntt(a, b);
}
if (min(n, m) <= 200) return convolution_karatsuba<mint>(a, b);
return convolution_garner(a, b);
}
#line 2 "library/nt/digit_sum.hpp"
int digit_sum(u64 x) {
const int K = 100'000;
static vc<int> dp(K);
if (dp[1] == 0) { FOR(x, 1, K) dp[x] = dp[x / 10] + (x % 10); }
int res = 0;
while (x) {
res += dp[x % K];
x /= K;
}
return res;
}
#line 3 "library/bigint/base.hpp"
// 10^9 ずつ区切って
struct BigInteger {
static constexpr int TEN[]
= {1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000};
static constexpr int LOG = 9;
static constexpr int MOD = TEN[LOG];
using bint = BigInteger;
int sgn;
vc<int> dat;
BigInteger() : sgn(0) {}
BigInteger(i128 val) {
if (val == 0) {
sgn = 0;
return;
}
sgn = 1;
if (val != 0) {
if (val < 0) sgn = -1, val = -val;
while (val > 0) { dat.eb(val % MOD), val /= MOD; }
}
}
BigInteger(string s) {
assert(!s.empty());
sgn = 1;
if (s[0] == '-') {
sgn = -1;
s.erase(s.begin());
assert(!s.empty());
}
if (s[0] == '0') {
sgn = 0;
return;
}
reverse(all(s));
int n = len(s);
int m = ceil(n, LOG);
dat.assign(m, 0);
FOR(i, n) { dat[i / LOG] += TEN[i % LOG] * (s[i] - '0'); }
}
bint &operator=(const bint &p) {
sgn = p.sgn, dat = p.dat;
return *this;
}
bool operator<(const bint &p) const {
if (sgn != p.sgn) { return sgn < p.sgn; }
if (sgn == 0) return false;
if (len(dat) != len(p.dat)) {
if (sgn == 1) return len(dat) < len(p.dat);
if (sgn == -1) return len(dat) > len(p.dat);
}
FOR_R(i, len(dat)) {
if (dat[i] == p.dat[i]) continue;
if (sgn == 1) return dat[i] < p.dat[i];
if (sgn == -1) return dat[i] > p.dat[i];
}
return false;
}
bool operator>(const bint &p) const { return p < *this; }
bool operator<=(const bint &p) const { return !(*this > p); }
bool operator>=(const bint &p) const { return !(*this < p); }
bint &operator+=(const bint p) {
if (sgn == 0) { return *this = p; }
if (p.sgn == 0) return *this;
if (sgn != p.sgn) {
*this -= (-p);
return *this;
}
int n = max(len(dat), len(p.dat));
dat.resize(n + 1);
FOR(i, n) {
if (i < len(p.dat)) dat[i] += p.dat[i];
if (dat[i] >= MOD) dat[i] -= MOD, dat[i + 1] += 1;
}
while (len(dat) && dat.back() == 0) dat.pop_back();
if (dat.empty()) sgn = 0;
return *this;
}
bint &operator-=(const bint p) {
if (p.sgn == 0) return *this;
if (sgn == 0) return *this = (-p);
if (sgn != p.sgn) {
*this += (-p);
return *this;
}
if ((sgn == 1 && *this < p) || (sgn == -1 && *this > p)) {
*this = p - *this;
sgn = -sgn;
return *this;
}
FOR(i, len(p.dat)) { dat[i] -= p.dat[i]; }
FOR(i, len(dat) - 1) {
if (dat[i] < 0) dat[i] += MOD, dat[i + 1] -= 1;
}
while (len(dat) && dat.back() == 0) { dat.pop_back(); }
if (dat.empty()) sgn = 0;
return *this;
}
bint &operator*=(const bint &p) {
sgn *= p.sgn;
if (sgn == 0) {
dat.clear();
} else {
dat = convolve(dat, p.dat);
}
return *this;
}
// bint &operator/=(const bint &p) { return *this; }
bint operator-() const {
bint p = *this;
p.sgn *= -1;
return p;
}
bint operator+(const bint &p) const { return bint(*this) += p; }
bint operator-(const bint &p) const { return bint(*this) -= p; }
bint operator*(const bint &p) const { return bint(*this) *= p; }
// bint operator/(const modint &p) const { return modint(*this) /= p; }
bool operator==(const bint &p) const {
return (sgn == p.sgn && dat == p.dat);
}
bool operator!=(const bint &p) const { return !((*this) == p); }
vc<int> convolve(const vc<int> &a, const vc<int> &b) {
int n = len(a), m = len(b);
if (!n || !m) return {};
if (min(n, m) <= 500) {
vc<int> c(n + m - 1);
u128 x = 0;
FOR(k, n + m - 1) {
int s = max<int>(0, k + 1 - m), t = min<int>(k, n - 1);
FOR(i, s, t + 1) { x += u64(a[i]) * b[k - i]; }
c[k] = x % MOD, x = x / MOD;
}
while (x > 0) { c.eb(x % MOD), x = x / MOD; }
return c;
}
static constexpr int p0 = 167772161;
static constexpr int p1 = 469762049;
static constexpr int p2 = 754974721;
using mint0 = modint<p0>;
using mint1 = modint<p1>;
using mint2 = modint<p2>;
vc<mint0> a0(all(a)), b0(all(b));
vc<mint1> a1(all(a)), b1(all(b));
vc<mint2> a2(all(a)), b2(all(b));
auto c0 = convolution_ntt<mint0>(a0, b0);
auto c1 = convolution_ntt<mint1>(a1, b1);
auto c2 = convolution_ntt<mint2>(a2, b2);
vc<int> c(len(c0));
u128 x = 0;
FOR(i, n + m - 1) {
x += CRT3<u128, p0, p1, p2>(c0[i].val, c1[i].val, c2[i].val);
c[i] = x % MOD, x = x / MOD;
}
while (x) { c.eb(x % MOD), x = x / MOD; }
return c;
}
string to_string() {
if (dat.empty()) return "0";
string s;
for (int x: dat) {
FOR(LOG) {
s += '0' + (x % 10);
x = x / 10;
}
}
while (s.back() == '0') s.pop_back();
if (sgn == -1) s += '-';
reverse(all(s));
return s;
}
// https://codeforces.com/contest/504/problem/D
string to_binary_string() {
assert(sgn >= 0);
vc<u32> A(all(dat));
string ANS;
while (1) {
while (len(A) && A.back() == u32(0)) POP(A);
if (A.empty()) break;
u64 rem = 0;
FOR_R(i, len(A)) {
rem = rem * MOD + A[i];
A[i] = rem >> 32;
rem &= u32(-1);
}
FOR(i, 32) { ANS += '0' + (rem >> i & 1); }
}
while (len(ANS) && ANS.back() == '0') ANS.pop_back();
reverse(all(ANS));
if (ANS.empty()) ANS += '0';
return ANS;
}
// https://codeforces.com/contest/759/problem/E
pair<bint, int> divmod(int p) {
vc<int> after;
ll rm = 0;
FOR_R(i, len(dat)) {
rm = rm * MOD + dat[i];
after.eb(rm / p);
rm = rm % p;
}
reverse(all(after));
while (len(after) && after.back() == 0) POP(after);
bint q;
q.sgn = sgn;
q.dat = after;
rm *= sgn;
if (rm < 0) {
rm += p;
q -= 1;
}
return {q, rm};
}
// https://codeforces.com/problemset/problem/582/D
vc<int> base_p_representation(int p) {
vc<u32> A(all(dat));
vc<int> res;
while (1) {
while (len(A) && A.back() == u32(0)) POP(A);
if (A.empty()) break;
u64 rm = 0;
FOR_R(i, len(A)) {
rm = rm * MOD + A[i];
A[i] = rm / p;
rm %= p;
}
res.eb(rm);
}
reverse(all(res));
return res;
}
// overflow 無視して計算
ll to_ll() {
ll x = 0;
FOR_R(i, len(dat)) x = MOD * x + dat[i];
return sgn * x;
}
// https://codeforces.com/contest/986/problem/D
bint pow(ll n) {
assert(n >= 0);
auto dfs = [&](auto &dfs, ll n) -> bint {
if (n == 1) return (*this);
bint x = dfs(dfs, n / 2);
x *= x;
if (n & 1) x *= (*this);
return x;
};
if (n == 0) return bint(1);
return dfs(dfs, n);
}
// https://codeforces.com/contest/986/problem/D
double log10() {
assert(!dat.empty() && sgn == 1);
if (len(dat) <= 3) {
double x = 0;
FOR_R(i, len(dat)) x = MOD * x + dat[i];
return std::log10(x);
}
double x = 0;
FOR(i, 4) x = MOD * x + dat[len(dat) - 1 - i];
x = std::log10(x);
x += double(LOG) * (len(dat) - 4);
return x;
}
int digit_sum() {
int ans = 0;
for (auto &x: dat) ans += ::digit_sum(x); // global にある digit_sum
return ans;
}
};
#ifdef FASTIO
void wt(BigInteger x) { fastio::wt(x.to_string()); }
void rd(BigInteger &x) {
string s;
fastio::rd(s);
x = BigInteger(s);
}
#endif
#line 1 "library/seq/famous/fibonacci.hpp"
// 0, 1, 1, 2, 3, 5, ...
template <typename mint>
mint fibonacci(ll N) {
using P = pair<mint, mint>;
P f = {0, 1}, res = {1, 0};
while (N) {
auto& [a, b] = f;
auto& [c, d] = res;
if (N & 1) { res = {a * c + b * d, b * c + (a + b) * d}; }
f = {a * a + b * b, b * (a + a + b)};
N >>= 1;
}
return res.se;
}
#line 6 "main.cpp"
#line 2 "library/random/base.hpp"
u64 RNG_64() {
static uint64_t x_
= uint64_t(chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count())
* 10150724397891781847ULL;
x_ ^= x_ << 7;
return x_ ^= x_ >> 9;
}
u64 RNG(u64 lim) { return RNG_64() % lim; }
ll RNG(ll l, ll r) { return l + RNG_64() % (r - l); }
#line 2 "library/mod/mongomery_modint.hpp"
// odd mod.
// x の代わりに rx を持つ
template <int id, typename U1, typename U2>
struct Mongomery_modint {
using mint = Mongomery_modint;
inline static U1 m, r, n2;
static constexpr int W = numeric_limits<U1>::digits;
static void set_mod(U1 mod) {
assert(mod & 1 && mod <= U1(1) << (W - 2));
m = mod, n2 = -U2(m) % m, r = m;
FOR(5) r *= 2 - m * r;
r = -r;
assert(r * m == U1(-1));
}
static U1 reduce(U2 b) { return (b + U2(U1(b) * r) * m) >> W; }
U1 x;
Mongomery_modint() : x(0) {}
Mongomery_modint(U1 x) : x(reduce(U2(x) * n2)){};
U1 val() const {
U1 y = reduce(x);
return y >= m ? y - m : y;
}
mint &operator+=(mint y) {
x = ((x += y.x) >= m ? x - m : x);
return *this;
}
mint &operator-=(mint y) {
x -= (x >= y.x ? y.x : y.x - m);
return *this;
}
mint &operator*=(mint y) {
x = reduce(U2(x) * y.x);
return *this;
}
mint operator+(mint y) const { return mint(*this) += y; }
mint operator-(mint y) const { return mint(*this) -= y; }
mint operator*(mint y) const { return mint(*this) *= y; }
bool operator==(mint y) const {
return (x >= m ? x - m : x) == (y.x >= m ? y.x - m : y.x);
}
bool operator!=(mint y) const { return not operator==(y); }
mint pow(ll n) const {
assert(n >= 0);
mint y = 1, z = *this;
for (; n; n >>= 1, z *= z)
if (n & 1) y *= z;
return y;
}
};
template <int id>
using Mongomery_modint_32 = Mongomery_modint<id, u32, u64>;
template <int id>
using Mongomery_modint_64 = Mongomery_modint<id, u64, u128>;
#line 3 "library/nt/primetest.hpp"
bool primetest(const u64 x) {
assert(x < u64(1) << 62);
if (x == 2 or x == 3 or x == 5 or x == 7) return true;
if (x % 2 == 0 or x % 3 == 0 or x % 5 == 0 or x % 7 == 0) return false;
if (x < 121) return x > 1;
const u64 d = (x - 1) >> lowbit(x - 1);
using mint = Mongomery_modint_64<202311020>;
mint::set_mod(x);
const mint one(u64(1)), minus_one(x - 1);
auto ok = [&](u64 a) -> bool {
auto y = mint(a).pow(d);
u64 t = d;
while (y != one && y != minus_one && t != x - 1) y *= y, t <<= 1;
if (y != minus_one && t % 2 == 0) return false;
return true;
};
if (x < (u64(1) << 32)) {
for (u64 a: {2, 7, 61})
if (!ok(a)) return false;
} else {
for (u64 a: {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) {
if (!ok(a)) return false;
}
}
return true;
}
#line 2 "library/mod/dynamic_modint.hpp"
#line 2 "library/mod/primitive_root.hpp"
#line 2 "library/nt/factor.hpp"
#line 5 "library/nt/factor.hpp"
template <typename mint>
ll rho(ll n, ll c) {
assert(n > 1);
const mint cc(c);
auto f = [&](mint x) { return x * x + cc; };
mint x = 1, y = 2, z = 1, q = 1;
ll g = 1;
const ll m = 1LL << (__lg(n) / 5);
for (ll r = 1; g == 1; r <<= 1) {
x = y;
FOR(r) y = f(y);
for (ll k = 0; k < r && g == 1; k += m) {
z = y;
FOR(min(m, r - k)) y = f(y), q *= x - y;
g = gcd(q.val(), n);
}
}
if (g == n) do {
z = f(z);
g = gcd((x - z).val(), n);
} while (g == 1);
return g;
}
ll find_prime_factor(ll n) {
assert(n > 1);
if (primetest(n)) return n;
FOR(100) {
ll m = 0;
if (n < (1 << 30)) {
using mint = Mongomery_modint_32<20231025>;
mint::set_mod(n);
m = rho<mint>(n, RNG(0, n));
} else {
using mint = Mongomery_modint_64<20231025>;
mint::set_mod(n);
m = rho<mint>(n, RNG(0, n));
}
if (primetest(m)) return m;
n = m;
}
assert(0);
return -1;
}
// ソートしてくれる
vc<pair<ll, int>> factor(ll n) {
assert(n >= 1);
vc<pair<ll, int>> pf;
FOR(p, 2, 100) {
if (p * p > n) break;
if (n % p == 0) {
ll e = 0;
do { n /= p, e += 1; } while (n % p == 0);
pf.eb(p, e);
}
}
while (n > 1) {
ll p = find_prime_factor(n);
ll e = 0;
do { n /= p, e += 1; } while (n % p == 0);
pf.eb(p, e);
}
sort(all(pf));
return pf;
}
vc<pair<ll, int>> factor_by_lpf(ll n, vc<int>& lpf) {
vc<pair<ll, int>> res;
while (n > 1) {
int p = lpf[n];
int e = 0;
while (n % p == 0) {
n /= p;
++e;
}
res.eb(p, e);
}
return res;
}
#line 2 "library/mod/mod_pow.hpp"
#line 2 "library/mod/barrett.hpp"
// https://github.com/atcoder/ac-library/blob/master/atcoder/internal_math.hpp
struct Barrett {
u32 m;
u64 im;
explicit Barrett(u32 m = 1) : m(m), im(u64(-1) / m + 1) {}
u32 umod() const { return m; }
u32 modulo(u64 z) {
if (m == 1) return 0;
u64 x = (u64)(((unsigned __int128)(z)*im) >> 64);
u64 y = x * m;
return (z - y + (z < y ? m : 0));
}
u64 floor(u64 z) {
if (m == 1) return z;
u64 x = (u64)(((unsigned __int128)(z)*im) >> 64);
u64 y = x * m;
return (z < y ? x - 1 : x);
}
pair<u64, u32> divmod(u64 z) {
if (m == 1) return {z, 0};
u64 x = (u64)(((unsigned __int128)(z)*im) >> 64);
u64 y = x * m;
if (z < y) return {x - 1, z - y + m};
return {x, z - y};
}
u32 mul(u32 a, u32 b) { return modulo(u64(a) * b); }
};
struct Barrett_64 {
u128 mod, mh, ml;
explicit Barrett_64(u64 mod = 1) : mod(mod) {
u128 m = u128(-1) / mod;
if (m * mod + mod == u128(0)) ++m;
mh = m >> 64;
ml = m & u64(-1);
}
u64 umod() const { return mod; }
u64 modulo(u128 x) {
u128 z = (x & u64(-1)) * ml;
z = (x & u64(-1)) * mh + (x >> 64) * ml + (z >> 64);
z = (x >> 64) * mh + (z >> 64);
x -= z * mod;
return x < mod ? x : x - mod;
}
u64 mul(u64 a, u64 b) { return modulo(u128(a) * b); }
};
#line 5 "library/mod/mod_pow.hpp"
u32 mod_pow(int a, ll n, int mod) {
assert(n >= 0);
a = ((a %= mod) < 0 ? a + mod : a);
if ((mod & 1) && (mod < (1 << 30))) {
using mint = Mongomery_modint_32<202311021>;
mint::set_mod(mod);
return mint(a).pow(n).val();
}
Barrett bt(mod);
int r = 1;
while (n) {
if (n & 1) r = bt.mul(r, a);
a = bt.mul(a, a), n >>= 1;
}
return r;
}
u64 mod_pow_64(ll a, ll n, u64 mod) {
assert(n >= 0);
a = ((a %= mod) < 0 ? a + mod : a);
if ((mod & 1) && (mod < (u64(1) << 62))) {
using mint = Mongomery_modint_64<202311021>;
mint::set_mod(mod);
return mint(a).pow(n).val();
}
Barrett_64 bt(mod);
ll r = 1;
while (n) {
if (n & 1) r = bt.mul(r, a);
a = bt.mul(a, a), n >>= 1;
}
return r;
}
#line 6 "library/mod/primitive_root.hpp"
// int
int primitive_root(int p) {
auto pf = factor(p - 1);
auto is_ok = [&](int g) -> bool {
for (auto&& [q, e]: pf)
if (mod_pow(g, (p - 1) / q, p) == 1) return false;
return true;
};
while (1) {
int x = RNG(1, p);
if (is_ok(x)) return x;
}
return -1;
}
ll primitive_root_64(ll p) {
auto pf = factor(p - 1);
auto is_ok = [&](ll g) -> bool {
for (auto&& [q, e]: pf)
if (mod_pow_64(g, (p - 1) / q, p) == 1) return false;
return true;
};
while (1) {
ll x = RNG(1, p);
if (is_ok(x)) return x;
}
return -1;
}
#line 6 "library/mod/dynamic_modint.hpp"
template <int id>
struct Dynamic_Modint {
static constexpr bool is_modint = true;
using mint = Dynamic_Modint;
u32 val;
static Barrett bt;
static u32 umod() { return bt.umod(); }
static int get_mod() { return (int)(bt.umod()); }
static void set_mod(int m) {
assert(1 <= m);
bt = Barrett(m);
}
static Dynamic_Modint raw(u32 v) {
Dynamic_Modint x;
x.val = v;
return x;
}
Dynamic_Modint() : val(0) {}
Dynamic_Modint(u32 x) : val(bt.modulo(x)) {}
Dynamic_Modint(u64 x) : val(bt.modulo(x)) {}
Dynamic_Modint(int x) : val((x %= get_mod()) < 0 ? x + get_mod() : x) {}
Dynamic_Modint(ll x) : val((x %= get_mod()) < 0 ? x + get_mod() : x) {}
Dynamic_Modint(i128 x) : val((x %= get_mod()) < 0 ? x + get_mod() : x){};
mint& operator+=(const mint& rhs) {
val = (val += rhs.val) < umod() ? val : val - umod();
return *this;
}
mint& operator-=(const mint& rhs) {
val = (val += umod() - rhs.val) < umod() ? val : val - umod();
return *this;
}
mint& operator*=(const mint& rhs) {
val = bt.mul(val, rhs.val);
return *this;
}
mint& operator/=(const mint& rhs) { return *this = *this * rhs.inverse(); }
mint operator-() const { return mint() - *this; }
mint pow(ll n) const {
assert(0 <= n);
mint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x, n >>= 1;
}
return r;
}
mint inverse() const {
int x = val, mod = get_mod();
int a = x, 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;
}
friend mint operator+(const mint& lhs, const mint& rhs) {
return mint(lhs) += rhs;
}
friend mint operator-(const mint& lhs, const mint& rhs) {
return mint(lhs) -= rhs;
}
friend mint operator*(const mint& lhs, const mint& rhs) {
return mint(lhs) *= rhs;
}
friend mint operator/(const mint& lhs, const mint& rhs) {
return mint(lhs) /= rhs;
}
friend bool operator==(const mint& lhs, const mint& rhs) {
return lhs.val == rhs.val;
}
friend bool operator!=(const mint& lhs, const mint& rhs) {
return lhs.val != rhs.val;
}
static pair<int, int>& get_ntt() {
static pair<int, int> p = {-1, -1};
return p;
}
static void set_ntt_info() {
int mod = get_mod();
int k = lowbit(mod - 1);
int r = primitive_root(mod);
r = mod_pow(r, (mod - 1) >> k, mod);
get_ntt() = {k, r};
}
static pair<int, int> ntt_info() { return get_ntt(); }
static bool can_ntt() { return ntt_info().fi != -1; }
};
#ifdef FASTIO
template <int id>
void rd(Dynamic_Modint<id>& x) {
fastio::rd(x.val);
x.val %= Dynamic_Modint<id>::umod();
}
template <int id>
void wt(Dynamic_Modint<id> x) {
fastio::wt(x.val);
}
#endif
using dmint = Dynamic_Modint<-1>;
template <int id>
Barrett Dynamic_Modint<id>::bt;
#line 10 "main.cpp"
using B = BigInteger;
int mod[20];
void init() {
FOR(i, 20) {
while (1) {
int p = RNG(500'000'000, 1'000'000'000);
if (primetest(p)) {
mod[i] = p;
break;
}
}
}
}
using ARR = array<int, 20>;
ARR from_bigint(B x) {
ARR A;
FOR(i, 20) A[i] = x.divmod(mod[i]).se;
return A;
}
using mint = dmint;
ARR fib(ll x) {
ARR A;
FOR(i, 20) {
mint::set_mod(mod[i]);
A[i] = fibonacci<mint>(x).val;
}
return A;
}
using Re = double;
void solve() {
LL(N);
vc<B> A(N);
FOR(i, N) read(A[i]);
sort(all(A));
ll ANS = 0;
map<ARR, int> MP;
Re phi = (sqrtl(5) + 1) / 2;
FOR(j, N) {
ll LG = 0;
if (A[j] != B(0)) LG = A[j].log10() / log10(phi);
ARR me = from_bigint(A[j]);
FOR(m, LG - 1, LG + 6) {
if (m < 0) continue;
if (m == 1) continue;
ARR F = fib(m);
FOR(k, 20) { F[k] = (ll(F[k]) - me[k] + mod[k]) % mod[k]; }
if (MP.count(F)) ANS += MP[F];
}
MP[me]++;
}
print(ANS);
}
signed main() {
init();
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4116kb
input:
6 50 8 8 5 72 354224848179261915070
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 99ms
memory: 6340kb
input:
28 200878223506436882933619847964496455022155117513398820563747455993172799881403389571477889821109288771413214004090719097929400406252135763028179112130390003528046316900603668569910008417315162907579003880220844686222148696041857432602133894827753998572080650383305777912447151917272483538029469449...
output:
27
result:
ok 1 number(s): "27"
Test #3:
score: 0
Accepted
time: 200ms
memory: 7228kb
input:
5187 2640352926124261912741724778991366987330659389621881876017670644497364093930668042530271338851702874394631009332660937266680740235862107353443518003194307853104942996827176097428402408674756368623972812842571069642405111849826172879369776309763468485788964245903781380419155348915131587410703749...
output:
6073
result:
ok 1 number(s): "6073"
Test #4:
score: 0
Accepted
time: 690ms
memory: 16192kb
input:
200000 2 2 2 2 1 2 1 1 2 2 1 1 1 2 2 1 1 2 1 1 2 2 1 2 2 2 1 1 1 1 2 2 1 2 1 2 1 1 2 2 1 1 1 2 1 1 2 1 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 1 2 1 2 2 1 1 1 2 2 2 1 1 2 1 1 2 1 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 2 2 1 1 2 1 1 2 1 2 2 1 2 1 2 2 1 1 2 1 1 1 2 2 2 1 2 2 1 1 2 2 2 2 1 2 1 1 2 1 2 2 1 1 1 1 2 2 2 2...
output:
15003749259
result:
ok 1 number(s): "15003749259"
Test #5:
score: 0
Accepted
time: 3148ms
memory: 41180kb
input:
200000 944176313232170622314 2590599414036674999101 753315073608896000424 9299685298577430049245 9361800333778142620806 8988699166328904060999 9606920674025578304023 4203331868598952026136 5183047027116137697788 3968714342776915029801 8130984095583566992354 3206443643596048048798 6248561214283254355...
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 992ms
memory: 27988kb
input:
200000 9 10 3 5 9 3 3 9 8 5 1 2 7 8 4 6 2 3 3 9 5 5 4 9 7 5 8 2 6 10 9 7 2 2 1 10 10 6 10 7 4 7 9 7 2 2 10 4 5 8 2 2 5 8 9 5 3 9 2 1 7 6 8 8 6 3 8 2 2 9 10 2 9 7 1 9 1 4 5 9 2 7 10 1 8 7 4 8 1 10 6 4 4 9 1 9 7 3 6 5 6 9 5 3 6 6 4 4 6 1 8 6 10 3 10 2 1 4 1 4 8 2 9 1 4 8 10 8 2 2 3 6 4 7 10 10 9 4 7 6...
output:
4388485679
result:
ok 1 number(s): "4388485679"
Test #7:
score: 0
Accepted
time: 2937ms
memory: 41112kb
input:
200000 6828421000391895 1989111434563275 5896525738540342 7580233289915833 7220157112714422 6690072177484914 6664449707566084 8245839001391019 3008772159581769 8148007474169818 9400853099859484 6346860654847919 7403109176990407 2581313740335401 1273038733901266 9824983373567665 7206452987542085 7181...
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 1968ms
memory: 41276kb
input:
200000 163414517 35065810 104946881 686842158 509604537 114869915 194658958 55736013 211143419 526188788 18298540 311113507 727676120 517103071 25044427 38567543 386683792 246028194 750300322 4412101 865997254 674545866 775054146 977862574 699213474 347544102 740489922 632436817 297903184 435135324 ...
output:
59
result:
ok 1 number(s): "59"
Test #9:
score: 0
Accepted
time: 87ms
memory: 11384kb
input:
2 2088564186870382794642016448725374479500907752342156600368614861600912666885211013490310624029649329209019866849808883315545780833167257516031795949145341911463438482795792374909577113387320732207052482556858037878075154734524317145645776084240387870219160545328462016106959746495953786767421892196...
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 976ms
memory: 19732kb
input:
200000 6 1 3 9 1 8 9 9 2 6 8 6 2 3 9 2 2 7 4 7 8 8 4 8 2 7 8 9 2 9 2 4 4 1 10 6 2 10 2 6 8 3 10 3 6 10 10 10 2 4 6 4 7 8 1 2 1 1 4 10 5 5 4 10 3 8 5 6 1 7 8 1 2 6 3 8 9 9 5 1 9 5 6 10 9 4 1 7 8 3 10 4 3 2 7 7 9 4 5 6 6 7 8 10 6 6 3 6 8 1 7 4 2 6 10 8 4 2 7 4 2 5 4 9 10 5 2 3 2 4 8 7 9 7 7 8 2 5 7 2 ...
output:
4400854684
result:
ok 1 number(s): "4400854684"
Test #11:
score: 0
Accepted
time: 2842ms
memory: 41160kb
input:
200000 3118333850638 35270102833223 62994441325054 21050207685515 79452732606523 43405025574846 14676822470608 40589739145551 72610266245240 95906978427970 59399311725881 80286412880911 98171197939601 15555757959003 68766133429050 11529744877477 36884730947747 93994258932707 21245575958503 287958909...
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 1814ms
memory: 40888kb
input:
200000 1218982 621720 5848120 1753415 5889366 1747270 7735728 8089704 4279399 7927020 9269797 1332511 6334797 8964092 9525679 7325470 1527918 893049 8483303 1134021 8872739 532622 8977450 4503590 6512507 4903981 4892296 6522908 9237430 2297267 8063244 1546378 5054973 8702942 4392067 7868582 2029729 ...
output:
5695
result:
ok 1 number(s): "5695"
Test #13:
score: 0
Accepted
time: 86ms
memory: 12892kb
input:
2 2088564186870382794642016448725374479500907752342156600368614861600912666885211013490310624029649329209019866849808883315545780833167257516031795949145341911463438482795792374909577113387320732207052482556858037878075154734524317145645776084240387870219160545328462016106959746495953786767421892196...
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 92ms
memory: 7844kb
input:
7 1337338011484742791299410909385691591046809197321138600848517667449672944525104556519885455609314839827342014896149347803816156838828377155724440687227582622225528496005639283622580269360626125544811511998701746678193286138664078007880894120371020695543061391758951301196457121332483784041873539166...
output:
3
result:
ok 1 number(s): "3"
Test #15:
score: 0
Accepted
time: 109ms
memory: 6936kb
input:
274 36199225654659696764078634911736913237817300779619275513532816361663892134832409526194170532894366762053993742963156407869241123825595148459428450874407641181641292360313933002704706339921470798414371554709977458935038423965022899542511184991008496997550268720067992926078576871685757638601127765...
output:
273
result:
ok 1 number(s): "273"
Test #16:
score: 0
Accepted
time: 1001ms
memory: 30996kb
input:
200000 4 3 8 5 8 9 4 10 1 3 7 1 3 10 1 10 10 7 8 2 8 9 6 6 1 2 2 6 6 7 10 7 1 3 6 2 8 4 3 3 8 9 4 3 9 6 4 1 6 3 3 5 4 2 3 9 3 3 6 7 6 1 5 5 2 10 2 1 5 9 6 7 3 2 9 1 3 8 8 3 10 7 5 5 6 9 10 8 1 5 6 2 1 8 5 4 1 7 9 9 2 8 9 8 5 7 4 9 3 3 4 7 9 1 8 1 5 9 8 8 7 10 1 4 2 3 7 8 6 1 10 10 8 9 4 10 4 5 5 6 9...
output:
4387062637
result:
ok 1 number(s): "4387062637"
Test #17:
score: 0
Accepted
time: 3119ms
memory: 41172kb
input:
200000 8244945625103564139 31587720380738895055 95764870267791202443 90342450187757930095 57990438361916446378 37041843791326956160 92044245094014254241 52147231507776742459 57440162490738372914 75951472709544205529 91095641579841704038 6354859395638708014 13171197741013485755 31875767906879519150 2...
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: 0
Accepted
time: 1ms
memory: 4188kb
input:
10 6 8 6 6 7 6 3 3 2 6
output:
12
result:
ok 1 number(s): "12"
Test #19:
score: 0
Accepted
time: 82ms
memory: 11180kb
input:
2 2088564186870382794642016448725374479500907752342156600368614861600912666885211013490310624029649329209019866849808883315545780833167257516031795949145341911463438482795792374909577113387320732207052482556858037878075154734524317145645776084240387870219160545328462016106959746495953786767421892196...
output:
0
result:
ok 1 number(s): "0"
Test #20:
score: 0
Accepted
time: 2657ms
memory: 41140kb
input:
200000 51732486464 15203118134 55665354475 37097810807 44823788729 92577384010 20189320156 62707564695 81665154265 89603063623 48003727587 14457078372 37230540002 65288477498 52282695470 76070393338 26054936545 14171092817 61770329497 85319218123 57730830347 20295186479 9036398880 63607160628 825711...
output:
1
result:
ok 1 number(s): "1"
Test #21:
score: 0
Accepted
time: 5ms
memory: 4108kb
input:
1000 7 2 6 10 8 6 1 4 5 4 8 6 9 4 1 5 1 5 2 10 6 8 10 10 1 3 4 2 10 1 9 2 7 6 7 9 10 6 9 8 3 2 10 7 6 5 4 3 1 10 5 3 5 1 8 6 5 10 5 7 10 4 9 1 10 9 4 8 8 7 8 5 9 1 5 6 2 10 1 10 9 10 10 10 1 5 3 10 10 3 3 9 10 3 9 1 5 7 6 5 2 9 7 9 10 4 9 1 7 7 5 8 10 8 8 5 5 6 1 5 5 6 10 2 1 1 2 5 9 5 3 5 6 8 5 3 8...
output:
108128
result:
ok 1 number(s): "108128"
Test #22:
score: 0
Accepted
time: 2424ms
memory: 26100kb
input:
170297 36618903089511909212027904 295898671290484359833820549055 855922209609024693421257591054 104046893712788281969810034913 294974348216094859258128389147 898675289823399842963411259541 849917444544425201790051381287 554091687601993279655091754543 100543835187751461953816001432 324625661878684349...
output:
669637
result:
ok 1 number(s): "669637"
Test #23:
score: 0
Accepted
time: 95ms
memory: 10268kb
input:
9 1554055664340235444670436446744662342403532554270354440324316254234564540613440405260344004460144314614345467104554712624142524427154124266304046362254623626323466324132625200314136012323044624260020307414632254233433163613166424734133322715601644464634614352434441422431546266431240655123113002704...
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 1ms
memory: 4032kb
input:
30 173224810532175 17167616931584 361 605 17167680176960 956658780060 4052737359577 497497353099204 1548072001901 190392490708530 789347852872433 5 804010804445736 139520616464 43988911432793 4052739537276 514224 2178304 25273161431631 53314112869 17114366064696 20097096794 26821231255228 4944012745...
output:
29
result:
ok 1 number(s): "29"
Test #25:
score: 0
Accepted
time: 104ms
memory: 6472kb
input:
100 11549310117176145486225764017375125851223984720694884717797775426631366931455266419214045399503089615971818090352858567015012529938870819767662704737995190471260542479965705803468920094883954929878415301662741322840828368641397254767329039284292920968364857914289821588505056486091849012400101879...
output:
36
result:
ok 1 number(s): "36"
Test #26:
score: 0
Accepted
time: 1673ms
memory: 22568kb
input:
100223 94009034043768394308211497706411911232935573312371 90700235808140495519523074128684120917303691406421 72874906060637684247409916135076680433361225881761 80161826274205256086415063126094978143520789283159 98145703778166390989463238108464755254200147417281 70995217131009339533392756476859088949...
output:
0
result:
ok 1 number(s): "0"
Test #27:
score: 0
Accepted
time: 1ms
memory: 4116kb
input:
6 50 8 8 5 72 354224848179261915070
output:
4
result:
ok 1 number(s): "4"
Test #28:
score: 0
Accepted
time: 167ms
memory: 7084kb
input:
3161 7 14 130 1467 16244 105149 1241120 13689232 151890909 1684420994 10901848031 128682014414 1419326741506 15748353436059 101920677024935 1203048867903722 13269285156772499 147231358659594589 1632748057345119600 10567412357776757138 124734439986929988911 1375786096219966094366 15265241654400597567...
output:
3160
result:
ok 1 number(s): "3160"
Test #29:
score: 0
Accepted
time: 2405ms
memory: 41144kb
input:
200000 7930099016 7136448262 4599143849 4725192685 4685680672 739140078 7214691825 5031750793 4820916507 6017675339 485443032 2327198454 8808146518 7746012012 713572475 4706110510 3560774990 7482541413 8975601524 3896030632 3018545943 7048325939 2370597692 7867568189 6902951191 333917381 112842576 9...
output:
7
result:
ok 1 number(s): "7"
Test #30:
score: 0
Accepted
time: 290ms
memory: 7284kb
input:
60123 4 3 4 7 5 7 5 1 2 6 9 10 7 4 2 1 8 6 4 6 4 2 8 6 2 8 5 4 5 7 1 10 7 5 1 9 7 4 8 8 8 5 2 6 8 4 6 4 9 7 3 9 5 6 2 8 10 2 10 2 1 4 9 5 10 9 7 2 1 9 3 9 10 1 8 7 6 5 7 1 4 10 5 9 8 10 4 10 4 9 3 7 4 4 10 4 1 7 4 10 4 9 10 2 2 8 3 7 1 1 6 4 10 9 9 4 8 3 4 7 5 7 6 10 10 2 8 1 8 10 6 9 4 7 3 8 2 5 6 ...
output:
399686351
result:
ok 1 number(s): "399686351"
Test #31:
score: 0
Accepted
time: 0ms
memory: 4064kb
input:
20 11142320330634256153203413422244004724022423010341634226101444226235404243251 1510233372263004374041444256322353356243032432623343544033530634305504714430614564334410564323262245 3315442551434205740422347432544540327016564444656542244600440525402604662333366 53153452623340724302644316423336472713...
output:
0
result:
ok 1 number(s): "0"
Test #32:
score: 0
Accepted
time: 1ms
memory: 4160kb
input:
15 9227465 832040 701408733 2178309 267914296 433494437 165580141 1346269 5702887 3524578 102334155 24157817 14930352 63245986 39088169
output:
14
result:
ok 1 number(s): "14"
Test #33:
score: 0
Accepted
time: 165ms
memory: 6088kb
input:
10011 5327909559109070794570420158512927656597532686406620479564191583982981578330651724849734045529811497 9659152635523321620063357842120653540264735554377366787893904211734024058449827205523008852363337860 74727969709789190305111991663528709940303307406256850364862896747520682645094217166643105732...
output:
0
result:
ok 1 number(s): "0"
Test #34:
score: 0
Accepted
time: 266ms
memory: 8208kb
input:
10051 63063334260332707210045601560460743222655443603043556526226343270234640534370464564114515210165526527443654044521634373434642424304154632545440427364312534131536671541443033313334224226302334143144172200431314323334240461563243422303322351122343066463334623434 625665325411647124616714317265541...
output:
14
result:
ok 1 number(s): "14"
Test #35:
score: 0
Accepted
time: 2773ms
memory: 41256kb
input:
200000 3231427058997 5671035772108 505876205893 9869979702346 336233080766 4805367039084 270125613380 929924360332 6390838551951 1896341268898 3923051450784 397979630166 6527843499305 1937207519921 9355189911971 953387547771 5307619807657 6689006266290 517624961010 1532034993156 1921439567851 331239...
output:
0
result:
ok 1 number(s): "0"
Test #36:
score: 0
Accepted
time: 97ms
memory: 7476kb
input:
30 167491015938836604073444715975948275020752570351918554475806772549228015468626967999929915531115950274814727218152384400389926950026165552262394643249255747252904223055992443689134599380405599101636105379410012227917206510976118633243994494607279010051579617303878166798657109212106136099974387457...
output:
29
result:
ok 1 number(s): "29"
Test #37:
score: 0
Accepted
time: 1679ms
memory: 26812kb
input:
200000 31520 9835 67679 91981 37157 27950 36846 70635 13880 18818 52443 46788 38014 56271 48270 28452 36146 82523 60850 55346 16869 95814 89245 98640 40746 68625 53391 63023 4402 36521 95532 52344 24072 70060 11619 12227 98964 78211 95010 83216 22122 46697 31271 85556 57237 82689 92115 88247 9186 85...
output:
555586
result:
ok 1 number(s): "555586"
Test #38:
score: 0
Accepted
time: 89ms
memory: 11992kb
input:
2 7471143542670631923583760838674866685142093708045228091216520373087113961892117195149240140968159205634006625906479367372855893882103887377565868731323681755476477285090435798416695243644387513257156317699123267511524797133211810893688279220755514610253525742595752854587254548452737426517576583616...
output:
1
result:
ok 1 number(s): "1"
Test #39:
score: 0
Accepted
time: 381ms
memory: 8548kb
input:
80000 6 4 5 5 4 5 9 8 5 6 2 2 1 10 6 9 4 10 6 5 3 4 3 3 4 5 10 2 6 4 6 2 6 2 4 7 9 6 6 8 1 1 7 10 10 2 7 2 2 9 8 5 4 9 1 5 7 4 7 7 6 7 7 9 8 9 9 4 10 7 2 9 9 9 4 2 8 4 9 1 3 9 1 4 2 1 2 4 3 2 1 10 5 7 10 5 9 3 6 3 4 4 1 8 1 8 10 8 6 6 2 5 1 3 6 8 2 2 10 6 6 3 2 6 3 8 4 10 8 10 3 9 9 2 8 8 10 4 5 5 7...
output:
706251650
result:
ok 1 number(s): "706251650"
Test #40:
score: 0
Accepted
time: 1008ms
memory: 31920kb
input:
200000 9 1 4 4 5 2 4 9 7 5 3 6 6 8 4 7 2 1 9 10 8 2 1 4 9 3 10 8 1 5 5 8 2 9 3 1 9 3 9 4 9 10 4 5 4 4 2 1 1 7 5 7 7 3 6 8 10 6 4 1 5 2 5 5 9 4 10 2 10 7 9 5 2 7 4 9 7 5 2 1 4 7 6 7 10 9 10 2 10 4 9 1 7 5 7 3 1 4 5 2 6 6 2 4 8 8 7 9 10 4 10 2 1 10 10 5 10 1 1 6 7 8 8 7 5 8 3 8 1 1 10 8 9 10 7 3 8 6 4...
output:
4417250451
result:
ok 1 number(s): "4417250451"
Test #41:
score: 0
Accepted
time: 1314ms
memory: 16856kb
input:
84752 86009844223237105273313186367406421847273312848013100091343 340516459610995530579473198046278412250343444815876655725270 62236463822700922600990709332929319814536375509143833251557 5611500219672931601067284378715174151735452175901717138530 64201778346042476353565735947990316834224189505881 609...
output:
420579
result:
ok 1 number(s): "420579"
Test #42:
score: 0
Accepted
time: 3077ms
memory: 41068kb
input:
200000 7127173784651987052 4249291679502906721 9703708230592019478 4404701921242244700 2344941043578422215 3091914365064271594 9867051863259427168 9880844309023770200 7211977710785226267 1694381065563438860 201683809955321192 4085536489000602058 7553409623903962290 4033981640350364868 54455660173955...
output:
0
result:
ok 1 number(s): "0"
Test #43:
score: 0
Accepted
time: 1012ms
memory: 28952kb
input:
200000 9 9 2 10 3 4 3 9 7 7 8 5 9 9 7 5 8 5 7 1 5 6 3 2 7 5 7 7 2 9 8 6 2 1 8 1 3 4 10 2 3 4 4 7 4 10 8 6 1 5 3 3 3 5 5 8 6 9 3 6 5 4 2 8 10 9 1 5 1 4 8 9 4 3 4 9 10 3 6 2 10 3 3 6 6 7 4 9 5 2 1 8 8 7 308061521170126 7 4 6 1 9 3 9 9 3 1 10 8 7 2 9 10 6 2 6 10 8 5 1 5 1 7 9 5 3 6 1 4 2 6 2 8 5 3 1 6 ...
output:
4397248166
result:
ok 1 number(s): "4397248166"
Test #44:
score: 0
Accepted
time: 31ms
memory: 5020kb
input:
156 18459619692692557705784877669569448552986613407875981372394172107449477143544507182981317111359110933094916231296859516709399078435198069511763391151449973008095601542066128297192521457018669738382503324519683244087838172215626103362576668917140635977557324975206273718561053735845026938082217687...
output:
155
result:
ok 1 number(s): "155"
Test #45:
score: 0
Accepted
time: 1000ms
memory: 39012kb
input:
200000 1 10 4 3 10 1 9 5 9 4 9 1 6 6 1 7 2 1 10 3 2 3 4 7 7 3 9 9 10 3 4 10 10 7 7 2 5 10 9 6 8 1 4 4 5 8 8 6 5 10 10 9 10 9 5 1 7 6 5 10 2 4 1 7 10 6 7 8 2 3 3 10 1 7 6 10 2 7 1 9 6 10 8 4 7 3 9 1 6 9 2 3 4 8 7 8 3 6 4 10 2 2 1 9 7 2 2 8 2 1 2 10 5 4 10 9 9 7 9 4 3 10 9 1 2 9 9 2 7 1 6 7 10 6 5 9 6...
output:
4407433502
result:
ok 1 number(s): "4407433502"
Test #46:
score: 0
Accepted
time: 881ms
memory: 13720kb
input:
51002 376123568879569384290612536925367837315702704676220875375604948366932308891841579226324979782110 28623980260058260408921525210046136035459718869538444006842678034295486291710095655185249062457587 21690449377523978494384257361181223226054780834691728496618681724478608654823982012150023238151530...
output:
81486
result:
ok 1 number(s): "81486"
Test #47:
score: 0
Accepted
time: 2819ms
memory: 41252kb
input:
200000 478606336755874083 603529542039676573 240066379679942455 20635508638460497 945472883349378253 395868479387568634 865948317871000880 136079313625171264 764680881358360622 195117422398549932 143437863196805305 907507515211279442 723479709912499971 671617918537158715 439287855279754360 202716825...
output:
0
result:
ok 1 number(s): "0"
Test #48:
score: 0
Accepted
time: 103ms
memory: 8224kb
input:
19 114661534643152246311744033174352334643324503262044605562234546544736534426056314403004340112331342520053464440541422433562206354434233744572233143044234304056542423441346156352252422334142225474302135741207345424432300443162054415443457163346015613444533444074633135446264371437171714063445404655...
output:
0
result:
ok 1 number(s): "0"
Test #49:
score: 0
Accepted
time: 2595ms
memory: 41136kb
input:
200000 497856383454 506720870857 899176487457 12145678485 541966940864 272264831455 178825186059 7038707436 481602633783 181735126537 559631305498 335603421321 761406732158 369431205173 615437274239 923671138603 543441698085 733638673698 858564208935 726626729204 880133143653 415511404815 9211110013...
output:
1
result:
ok 1 number(s): "1"
Test #50:
score: 0
Accepted
time: 94ms
memory: 10532kb
input:
5 2011068126132617886949194530211424837999019187297342375967282498616949073685995418305378991927261698758022155241855161670361072821581948280878066032787805987660111096801265330758292151243775781982581126595354464038574958455139626266660161003165949122588221798586300395825356961553839057885407409810...
output:
4
result:
ok 1 number(s): "4"
Test #51:
score: 0
Accepted
time: 1238ms
memory: 16196kb
input:
200000 91 67 28 7 87 97 87 80 71 5 67 1 98 85 60 62 99 46 9 81 10 7 15 91 74 69 11 34 85 47 56 48 29 16 25 5 46 9 73 24 84 10 97 22 78 18 29 70 92 98 61 43 54 66 55 15 77 20 25 16 84 11 93 65 61 91 18 59 31 93 53 33 34 59 90 41 21 27 82 49 33 64 96 18 46 71 94 95 30 62 47 9 62 79 29 28 65 67 32 48 9...
output:
591328867
result:
ok 1 number(s): "591328867"
Extra Test:
score: 0
Extra Test Passed