QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#879458 | #9700. Ying’s Cup | ucup-team987# | TL | 1990ms | 4480kb | C++23 | 42.1kb | 2025-02-02 02:57:33 | 2025-02-02 02:57:34 |
Judging History
answer
/**
* date : 2025-02-02 03:57:22
* author : Nyaan
*/
#define NDEBUG
using namespace std;
// intrinstic
#include <immintrin.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tr2/dynamic_bitset>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// utility
namespace Nyaan {
using ll = long long;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<vector<T>>;
using vi = vector<int>;
using vl = vector<long long>;
using vd = V<double>;
using vs = V<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename U>
struct P : pair<T, U> {
template <typename... Args>
constexpr P(Args... args) : pair<T, U>(args...) {}
using pair<T, U>::first;
using pair<T, U>::second;
P &operator+=(const P &r) {
first += r.first;
second += r.second;
return *this;
}
P &operator-=(const P &r) {
first -= r.first;
second -= r.second;
return *this;
}
P &operator*=(const P &r) {
first *= r.first;
second *= r.second;
return *this;
}
template <typename S>
P &operator*=(const S &r) {
first *= r, second *= r;
return *this;
}
P operator+(const P &r) const { return P(*this) += r; }
P operator-(const P &r) const { return P(*this) -= r; }
P operator*(const P &r) const { return P(*this) *= r; }
template <typename S>
P operator*(const S &r) const {
return P(*this) *= r;
}
P operator-() const { return P{-first, -second}; }
};
using pl = P<ll, ll>;
using pi = P<int, int>;
using vp = V<pl>;
constexpr int inf = 1001001001;
constexpr long long infLL = 4004004004004004004LL;
template <typename T>
int sz(const T &t) {
return t.size();
}
template <typename T, typename U>
inline bool amin(T &x, U y) {
return (y < x) ? (x = y, true) : false;
}
template <typename T, typename U>
inline bool amax(T &x, U y) {
return (x < y) ? (x = y, true) : false;
}
template <typename T>
inline T Max(const vector<T> &v) {
return *max_element(begin(v), end(v));
}
template <typename T>
inline T Min(const vector<T> &v) {
return *min_element(begin(v), end(v));
}
template <typename T>
inline long long Sum(const vector<T> &v) {
return accumulate(begin(v), end(v), 0LL);
}
template <typename T>
int lb(const vector<T> &v, const T &a) {
return lower_bound(begin(v), end(v), a) - begin(v);
}
template <typename T>
int ub(const vector<T> &v, const T &a) {
return upper_bound(begin(v), end(v), a) - begin(v);
}
constexpr long long TEN(int n) {
long long ret = 1, x = 10;
for (; n; x *= x, n >>= 1) ret *= (n & 1 ? x : 1);
return ret;
}
template <typename T, typename U>
pair<T, U> mkp(const T &t, const U &u) {
return make_pair(t, u);
}
template <typename T>
vector<T> mkrui(const vector<T> &v, bool rev = false) {
vector<T> ret(v.size() + 1);
if (rev) {
for (int i = int(v.size()) - 1; i >= 0; i--) ret[i] = v[i] + ret[i + 1];
} else {
for (int i = 0; i < int(v.size()); i++) ret[i + 1] = ret[i] + v[i];
}
return ret;
};
template <typename T>
vector<T> mkuni(const vector<T> &v) {
vector<T> ret(v);
sort(ret.begin(), ret.end());
ret.erase(unique(ret.begin(), ret.end()), ret.end());
return ret;
}
template <typename F>
vector<int> mkord(int N, F f) {
vector<int> ord(N);
iota(begin(ord), end(ord), 0);
sort(begin(ord), end(ord), f);
return ord;
}
template <typename T>
vector<int> mkinv(vector<T> &v) {
int max_val = *max_element(begin(v), end(v));
vector<int> inv(max_val + 1, -1);
for (int i = 0; i < (int)v.size(); i++) inv[v[i]] = i;
return inv;
}
vector<int> mkiota(int n) {
vector<int> ret(n);
iota(begin(ret), end(ret), 0);
return ret;
}
template <typename T>
T mkrev(const T &v) {
T w{v};
reverse(begin(w), end(w));
return w;
}
template <typename T>
bool nxp(T &v) {
return next_permutation(begin(v), end(v));
}
// 返り値の型は入力の T に依存
// i 要素目 : [0, a[i])
template <typename T>
vector<vector<T>> product(const vector<T> &a) {
vector<vector<T>> ret;
vector<T> v;
auto dfs = [&](auto rc, int i) -> void {
if (i == (int)a.size()) {
ret.push_back(v);
return;
}
for (int j = 0; j < a[i]; j++) v.push_back(j), rc(rc, i + 1), v.pop_back();
};
dfs(dfs, 0);
return ret;
}
// F : function(void(T&)), mod を取る操作
// T : 整数型のときはオーバーフローに注意する
template <typename T>
T Power(T a, long long n, const T &I, const function<void(T &)> &f) {
T res = I;
for (; n; f(a = a * a), n >>= 1) {
if (n & 1) f(res = res * a);
}
return res;
}
// T : 整数型のときはオーバーフローに注意する
template <typename T>
T Power(T a, long long n, const T &I = T{1}) {
return Power(a, n, I, function<void(T &)>{[](T &) -> void {}});
}
template <typename T>
T Rev(const T &v) {
T res = v;
reverse(begin(res), end(res));
return res;
}
template <typename T>
vector<T> Transpose(const vector<T> &v) {
using U = typename T::value_type;
if(v.empty()) return {};
int H = v.size(), W = v[0].size();
vector res(W, T(H, U{}));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
res[j][i] = v[i][j];
}
}
return res;
}
template <typename T>
vector<T> Rotate(const vector<T> &v, int clockwise = true) {
using U = typename T::value_type;
int H = v.size(), W = v[0].size();
vector res(W, T(H, U{}));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (clockwise) {
res[W - 1 - j][i] = v[i][j];
} else {
res[j][H - 1 - i] = v[i][j];
}
}
}
return res;
}
} // namespace Nyaan
// bit operation
namespace Nyaan {
__attribute__((target("popcnt"))) inline int popcnt(const u64 &a) {
return __builtin_popcountll(a);
}
inline int lsb(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int ctz(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int msb(const u64 &a) { return a ? 63 - __builtin_clzll(a) : -1; }
template <typename T>
inline int gbit(const T &a, int i) {
return (a >> i) & 1;
}
template <typename T>
inline void sbit(T &a, int i, bool b) {
if (gbit(a, i) != b) a ^= T(1) << i;
}
constexpr long long PW(int n) { return 1LL << n; }
constexpr long long MSK(int n) { return (1LL << n) - 1; }
} // namespace Nyaan
// inout
namespace Nyaan {
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
int s = (int)v.size();
for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v) is >> x;
return is;
}
istream &operator>>(istream &is, __int128_t &x) {
string S;
is >> S;
x = 0;
int flag = 0;
for (auto &c : S) {
if (c == '-') {
flag = true;
continue;
}
x *= 10;
x += c - '0';
}
if (flag) x = -x;
return is;
}
istream &operator>>(istream &is, __uint128_t &x) {
string S;
is >> S;
x = 0;
for (auto &c : S) {
x *= 10;
x += c - '0';
}
return is;
}
ostream &operator<<(ostream &os, __int128_t x) {
if (x == 0) return os << 0;
if (x < 0) os << '-', x = -x;
string S;
while (x) S.push_back('0' + x % 10), x /= 10;
reverse(begin(S), end(S));
return os << S;
}
ostream &operator<<(ostream &os, __uint128_t x) {
if (x == 0) return os << 0;
string S;
while (x) S.push_back('0' + x % 10), x /= 10;
reverse(begin(S), end(S));
return os << S;
}
void in() {}
template <typename T, class... U>
void in(T &t, U &...u) {
cin >> t;
in(u...);
}
void out() { cout << "\n"; }
template <typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
cout << t;
if (sizeof...(u)) cout << sep;
out(u...);
}
struct IoSetupNya {
IoSetupNya() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
cerr << fixed << setprecision(7);
}
} iosetupnya;
} // namespace Nyaan
// debug
#ifdef NyaanDebug
#define trc(...) (void(0))
#else
#define trc(...) (void(0))
#endif
#ifdef NyaanLocal
#define trc2(...) (void(0))
#else
#define trc2(...) (void(0))
#endif
// macro
#define each(x, v) for (auto&& x : v)
#define each2(x, y, v) for (auto&& [x, y] : v)
#define all(v) (v).begin(), (v).end()
#define rep(i, N) for (long long i = 0; i < (long long)(N); i++)
#define repr(i, N) for (long long i = (long long)(N)-1; i >= 0; i--)
#define rep1(i, N) for (long long i = 1; i <= (long long)(N); i++)
#define repr1(i, N) for (long long i = (N); (long long)(i) > 0; i--)
#define reg(i, a, b) for (long long i = (a); i < (b); i++)
#define regr(i, a, b) for (long long i = (b)-1; i >= (a); i--)
#define fi first
#define se second
#define ini(...) \
int __VA_ARGS__; \
in(__VA_ARGS__)
#define inl(...) \
long long __VA_ARGS__; \
in(__VA_ARGS__)
#define ins(...) \
string __VA_ARGS__; \
in(__VA_ARGS__)
#define in2(s, t) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i]); \
}
#define in3(s, t, u) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i], u[i]); \
}
#define in4(s, t, u, v) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i], u[i], v[i]); \
}
#define die(...) \
do { \
Nyaan::out(__VA_ARGS__); \
return; \
} while (0)
namespace Nyaan {
void solve();
}
int main() { Nyaan::solve(); }
//
using namespace std;
namespace internal {
unsigned long long non_deterministic_seed() {
unsigned long long m =
chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count();
m ^= 9845834732710364265uLL;
m ^= m << 24, m ^= m >> 31, m ^= m << 35;
return m;
}
unsigned long long deterministic_seed() { return 88172645463325252UL; }
// 64 bit の seed 値を生成 (手元では seed 固定)
// 連続で呼び出すと同じ値が何度も返ってくるので注意
// #define RANDOMIZED_SEED するとシードがランダムになる
unsigned long long seed() {
#if defined(DETERMINISTIC_SEED)
return deterministic_seed();
#elif defined(NyaanLocal) && !defined(RANDOMIZED_SEED)
return deterministic_seed();
#else
return non_deterministic_seed();
#endif
}
} // namespace internal
namespace my_rand {
using i64 = long long;
using u64 = unsigned long long;
// [0, 2^64 - 1)
u64 rng() {
static u64 _x = internal::seed();
return _x ^= _x << 7, _x ^= _x >> 9;
}
// [l, r]
i64 rng(i64 l, i64 r) {
assert(l <= r);
return l + rng() % u64(r - l + 1);
}
// [l, r)
i64 randint(i64 l, i64 r) {
assert(l < r);
return l + rng() % u64(r - l);
}
// choose n numbers from [l, r) without overlapping
vector<i64> randset(i64 l, i64 r, i64 n) {
assert(l <= r && n <= r - l);
unordered_set<i64> s;
for (i64 i = n; i; --i) {
i64 m = randint(l, r + 1 - i);
if (s.find(m) != s.end()) m = r - i;
s.insert(m);
}
vector<i64> ret;
for (auto& x : s) ret.push_back(x);
sort(begin(ret), end(ret));
return ret;
}
// [0.0, 1.0)
double rnd() { return rng() * 5.42101086242752217004e-20; }
// [l, r)
double rnd(double l, double r) {
assert(l < r);
return l + rnd() * (r - l);
}
template <typename T>
void randshf(vector<T>& v) {
int n = v.size();
for (int i = 1; i < n; i++) swap(v[i], v[randint(0, i + 1)]);
}
} // namespace my_rand
using my_rand::randint;
using my_rand::randset;
using my_rand::randshf;
using my_rand::rnd;
using my_rand::rng;
//
template <typename mint>
struct FormalPowerSeries : vector<mint> {
using vector<mint>::vector;
using FPS = FormalPowerSeries;
FPS &operator+=(const FPS &r) {
if (r.size() > this->size()) this->resize(r.size());
for (int i = 0; i < (int)r.size(); i++) (*this)[i] += r[i];
return *this;
}
FPS &operator+=(const mint &r) {
if (this->empty()) this->resize(1);
(*this)[0] += r;
return *this;
}
FPS &operator-=(const FPS &r) {
if (r.size() > this->size()) this->resize(r.size());
for (int i = 0; i < (int)r.size(); i++) (*this)[i] -= r[i];
return *this;
}
FPS &operator-=(const mint &r) {
if (this->empty()) this->resize(1);
(*this)[0] -= r;
return *this;
}
FPS &operator*=(const mint &v) {
for (int k = 0; k < (int)this->size(); k++) (*this)[k] *= v;
return *this;
}
FPS &operator/=(const FPS &r) {
if (this->size() < r.size()) {
this->clear();
return *this;
}
int n = this->size() - r.size() + 1;
if ((int)r.size() <= 64) {
FPS f(*this), g(r);
g.shrink();
mint coeff = g.back().inverse();
for (auto &x : g) x *= coeff;
int deg = (int)f.size() - (int)g.size() + 1;
int gs = g.size();
FPS quo(deg);
for (int i = deg - 1; i >= 0; i--) {
quo[i] = f[i + gs - 1];
for (int j = 0; j < gs; j++) f[i + j] -= quo[i] * g[j];
}
*this = quo * coeff;
this->resize(n, mint(0));
return *this;
}
return *this = ((*this).rev().pre(n) * r.rev().inv(n)).pre(n).rev();
}
FPS &operator%=(const FPS &r) {
*this -= *this / r * r;
shrink();
return *this;
}
FPS operator+(const FPS &r) const { return FPS(*this) += r; }
FPS operator+(const mint &v) const { return FPS(*this) += v; }
FPS operator-(const FPS &r) const { return FPS(*this) -= r; }
FPS operator-(const mint &v) const { return FPS(*this) -= v; }
FPS operator*(const FPS &r) const { return FPS(*this) *= r; }
FPS operator*(const mint &v) const { return FPS(*this) *= v; }
FPS operator/(const FPS &r) const { return FPS(*this) /= r; }
FPS operator%(const FPS &r) const { return FPS(*this) %= r; }
FPS operator-() const {
FPS ret(this->size());
for (int i = 0; i < (int)this->size(); i++) ret[i] = -(*this)[i];
return ret;
}
void shrink() {
while (this->size() && this->back() == mint(0)) this->pop_back();
}
FPS rev() const {
FPS ret(*this);
reverse(begin(ret), end(ret));
return ret;
}
FPS dot(FPS r) const {
FPS ret(min(this->size(), r.size()));
for (int i = 0; i < (int)ret.size(); i++) ret[i] = (*this)[i] * r[i];
return ret;
}
// 前 sz 項を取ってくる。sz に足りない項は 0 埋めする
FPS pre(int sz) const {
FPS ret(begin(*this), begin(*this) + min((int)this->size(), sz));
if ((int)ret.size() < sz) ret.resize(sz);
return ret;
}
FPS operator>>(int sz) const {
if ((int)this->size() <= sz) return {};
FPS ret(*this);
ret.erase(ret.begin(), ret.begin() + sz);
return ret;
}
FPS operator<<(int sz) const {
FPS ret(*this);
ret.insert(ret.begin(), sz, mint(0));
return ret;
}
FPS diff() const {
const int n = (int)this->size();
FPS ret(max(0, n - 1));
mint one(1), coeff(1);
for (int i = 1; i < n; i++) {
ret[i - 1] = (*this)[i] * coeff;
coeff += one;
}
return ret;
}
FPS integral() const {
const int n = (int)this->size();
FPS ret(n + 1);
ret[0] = mint(0);
if (n > 0) ret[1] = mint(1);
auto mod = mint::get_mod();
for (int i = 2; i <= n; i++) ret[i] = (-ret[mod % i]) * (mod / i);
for (int i = 0; i < n; i++) ret[i + 1] *= (*this)[i];
return ret;
}
mint eval(mint x) const {
mint r = 0, w = 1;
for (auto &v : *this) r += w * v, w *= x;
return r;
}
FPS log(int deg = -1) const {
assert(!(*this).empty() && (*this)[0] == mint(1));
if (deg == -1) deg = (int)this->size();
return (this->diff() * this->inv(deg)).pre(deg - 1).integral();
}
FPS pow(int64_t k, int deg = -1) const {
const int n = (int)this->size();
if (deg == -1) deg = n;
if (k == 0) {
FPS ret(deg);
if (deg) ret[0] = 1;
return ret;
}
for (int i = 0; i < n; i++) {
if ((*this)[i] != mint(0)) {
mint rev = mint(1) / (*this)[i];
FPS ret = (((*this * rev) >> i).log(deg) * k).exp(deg);
ret *= (*this)[i].pow(k);
ret = (ret << (i * k)).pre(deg);
if ((int)ret.size() < deg) ret.resize(deg, mint(0));
return ret;
}
if (__int128_t(i + 1) * k >= deg) return FPS(deg, mint(0));
}
return FPS(deg, mint(0));
}
static void *ntt_ptr;
static void set_fft();
FPS &operator*=(const FPS &r);
void ntt();
void intt();
void ntt_doubling();
static int ntt_pr();
FPS inv(int deg = -1) const;
FPS exp(int deg = -1) const;
};
template <typename mint>
void *FormalPowerSeries<mint>::ntt_ptr = nullptr;
/**
* @brief 多項式/形式的冪級数ライブラリ
* @docs docs/fps/formal-power-series.md
*/
template <typename mint>
struct ProductTree {
using fps = FormalPowerSeries<mint>;
const vector<mint> &xs;
vector<fps> buf;
int N, xsz;
vector<int> l, r;
ProductTree(const vector<mint> &xs_) : xs(xs_), xsz(xs.size()) {
N = 1;
while (N < (int)xs.size()) N *= 2;
buf.resize(2 * N);
l.resize(2 * N, xs.size());
r.resize(2 * N, xs.size());
fps::set_fft();
if (fps::ntt_ptr == nullptr)
build();
else
build_ntt();
}
void build() {
for (int i = 0; i < xsz; i++) {
l[i + N] = i;
r[i + N] = i + 1;
buf[i + N] = {-xs[i], 1};
}
for (int i = N - 1; i > 0; i--) {
l[i] = l[(i << 1) | 0];
r[i] = r[(i << 1) | 1];
if (buf[(i << 1) | 0].empty())
continue;
else if (buf[(i << 1) | 1].empty())
buf[i] = buf[(i << 1) | 0];
else
buf[i] = buf[(i << 1) | 0] * buf[(i << 1) | 1];
}
}
void build_ntt() {
fps f;
f.reserve(N * 2);
for (int i = 0; i < xsz; i++) {
l[i + N] = i;
r[i + N] = i + 1;
buf[i + N] = {-xs[i] + 1, -xs[i] - 1};
}
for (int i = N - 1; i > 0; i--) {
l[i] = l[(i << 1) | 0];
r[i] = r[(i << 1) | 1];
if (buf[(i << 1) | 0].empty())
continue;
else if (buf[(i << 1) | 1].empty())
buf[i] = buf[(i << 1) | 0];
else if (buf[(i << 1) | 0].size() == buf[(i << 1) | 1].size()) {
buf[i] = buf[(i << 1) | 0];
f.clear();
copy(begin(buf[(i << 1) | 1]), end(buf[(i << 1) | 1]),
back_inserter(f));
buf[i].ntt_doubling();
f.ntt_doubling();
for (int j = 0; j < (int)buf[i].size(); j++) buf[i][j] *= f[j];
} else {
buf[i] = buf[(i << 1) | 0];
f.clear();
copy(begin(buf[(i << 1) | 1]), end(buf[(i << 1) | 1]),
back_inserter(f));
buf[i].ntt_doubling();
f.intt();
f.resize(buf[i].size(), mint(0));
f.ntt();
for (int j = 0; j < (int)buf[i].size(); j++) buf[i][j] *= f[j];
}
}
for (int i = 0; i < 2 * N; i++) {
buf[i].intt();
buf[i].shrink();
}
}
};
template <typename mint>
vector<mint> InnerMultipointEvaluation(const FormalPowerSeries<mint> &f,
const vector<mint> &xs,
const ProductTree<mint> &ptree) {
using fps = FormalPowerSeries<mint>;
vector<mint> ret;
ret.reserve(xs.size());
auto rec = [&](auto self, fps a, int idx) {
if (ptree.l[idx] == ptree.r[idx]) return;
a %= ptree.buf[idx];
if ((int)a.size() <= 64) {
for (int i = ptree.l[idx]; i < ptree.r[idx]; i++)
ret.push_back(a.eval(xs[i]));
return;
}
self(self, a, (idx << 1) | 0);
self(self, a, (idx << 1) | 1);
};
rec(rec, f, 1);
return ret;
}
template <typename mint>
vector<mint> MultipointEvaluation(const FormalPowerSeries<mint> &f,
const vector<mint> &xs) {
if(f.empty() || xs.empty()) return vector<mint>(xs.size(), mint(0));
return InnerMultipointEvaluation(f, xs, ProductTree<mint>(xs));
}
/**
* @brief Multipoint Evaluation
*/
template <class mint>
FormalPowerSeries<mint> PolynomialInterpolation(const vector<mint> &xs,
const vector<mint> &ys) {
using fps = FormalPowerSeries<mint>;
assert(xs.size() == ys.size());
ProductTree<mint> ptree(xs);
fps w = ptree.buf[1].diff();
vector<mint> vs = InnerMultipointEvaluation<mint>(w, xs, ptree);
auto rec = [&](auto self, int idx) -> fps {
if (idx >= ptree.N) {
if (idx - ptree.N < (int)xs.size())
return {ys[idx - ptree.N] / vs[idx - ptree.N]};
else
return {mint(1)};
}
if (ptree.buf[idx << 1 | 0].empty())
return {};
else if (ptree.buf[idx << 1 | 1].empty())
return self(self, idx << 1 | 0);
return self(self, idx << 1 | 0) * ptree.buf[idx << 1 | 1] +
self(self, idx << 1 | 1) * ptree.buf[idx << 1 | 0];
};
return rec(rec, 1);
}
template <typename T>
struct edge {
int src, to;
T cost;
edge(int _to, T _cost) : src(-1), to(_to), cost(_cost) {}
edge(int _src, int _to, T _cost) : src(_src), to(_to), cost(_cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
using UnweightedGraph = vector<vector<int>>;
// Input of (Unweighted) Graph
UnweightedGraph graph(int N, int M = -1, bool is_directed = false,
bool is_1origin = true) {
UnweightedGraph g(N);
if (M == -1) M = N - 1;
for (int _ = 0; _ < M; _++) {
int x, y;
cin >> x >> y;
if (is_1origin) x--, y--;
g[x].push_back(y);
if (!is_directed) g[y].push_back(x);
}
return g;
}
// Input of Weighted Graph
template <typename T>
WeightedGraph<T> wgraph(int N, int M = -1, bool is_directed = false,
bool is_1origin = true) {
WeightedGraph<T> g(N);
if (M == -1) M = N - 1;
for (int _ = 0; _ < M; _++) {
int x, y;
cin >> x >> y;
T c;
cin >> c;
if (is_1origin) x--, y--;
g[x].emplace_back(x, y, c);
if (!is_directed) g[y].emplace_back(y, x, c);
}
return g;
}
// Input of Edges
template <typename T>
Edges<T> esgraph([[maybe_unused]] int N, int M, int is_weighted = true,
bool is_1origin = true) {
Edges<T> es;
for (int _ = 0; _ < M; _++) {
int x, y;
cin >> x >> y;
T c;
if (is_weighted)
cin >> c;
else
c = 1;
if (is_1origin) x--, y--;
es.emplace_back(x, y, c);
}
return es;
}
// Input of Adjacency Matrix
template <typename T>
vector<vector<T>> adjgraph(int N, int M, T INF, int is_weighted = true,
bool is_directed = false, bool is_1origin = true) {
vector<vector<T>> d(N, vector<T>(N, INF));
for (int _ = 0; _ < M; _++) {
int x, y;
cin >> x >> y;
T c;
if (is_weighted)
cin >> c;
else
c = 1;
if (is_1origin) x--, y--;
d[x][y] = c;
if (!is_directed) d[y][x] = c;
}
return d;
}
/**
* @brief グラフテンプレート
* @docs docs/graph/graph-template.md
*/
//
template <typename mint>
struct NTT {
static constexpr uint32_t get_pr() {
uint32_t _mod = mint::get_mod();
using u64 = uint64_t;
u64 ds[32] = {};
int idx = 0;
u64 m = _mod - 1;
for (u64 i = 2; i * i <= m; ++i) {
if (m % i == 0) {
ds[idx++] = i;
while (m % i == 0) m /= i;
}
}
if (m != 1) ds[idx++] = m;
uint32_t _pr = 2;
while (1) {
int flg = 1;
for (int i = 0; i < idx; ++i) {
u64 a = _pr, b = (_mod - 1) / ds[i], r = 1;
while (b) {
if (b & 1) r = r * a % _mod;
a = a * a % _mod;
b >>= 1;
}
if (r == 1) {
flg = 0;
break;
}
}
if (flg == 1) break;
++_pr;
}
return _pr;
};
static constexpr uint32_t mod = mint::get_mod();
static constexpr uint32_t pr = get_pr();
static constexpr int level = __builtin_ctzll(mod - 1);
mint dw[level], dy[level];
void setwy(int k) {
mint w[level], y[level];
w[k - 1] = mint(pr).pow((mod - 1) / (1 << k));
y[k - 1] = w[k - 1].inverse();
for (int i = k - 2; i > 0; --i)
w[i] = w[i + 1] * w[i + 1], y[i] = y[i + 1] * y[i + 1];
dw[1] = w[1], dy[1] = y[1], dw[2] = w[2], dy[2] = y[2];
for (int i = 3; i < k; ++i) {
dw[i] = dw[i - 1] * y[i - 2] * w[i];
dy[i] = dy[i - 1] * w[i - 2] * y[i];
}
}
NTT() { setwy(level); }
void fft4(vector<mint> &a, int k) {
if ((int)a.size() <= 1) return;
if (k == 1) {
mint a1 = a[1];
a[1] = a[0] - a[1];
a[0] = a[0] + a1;
return;
}
if (k & 1) {
int v = 1 << (k - 1);
for (int j = 0; j < v; ++j) {
mint ajv = a[j + v];
a[j + v] = a[j] - ajv;
a[j] += ajv;
}
}
int u = 1 << (2 + (k & 1));
int v = 1 << (k - 2 - (k & 1));
mint one = mint(1);
mint imag = dw[1];
while (v) {
// jh = 0
{
int j0 = 0;
int j1 = v;
int j2 = j1 + v;
int j3 = j2 + v;
for (; j0 < v; ++j0, ++j1, ++j2, ++j3) {
mint t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3];
mint t0p2 = t0 + t2, t1p3 = t1 + t3;
mint t0m2 = t0 - t2, t1m3 = (t1 - t3) * imag;
a[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3;
a[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3;
}
}
// jh >= 1
mint ww = one, xx = one * dw[2], wx = one;
for (int jh = 4; jh < u;) {
ww = xx * xx, wx = ww * xx;
int j0 = jh * v;
int je = j0 + v;
int j2 = je + v;
for (; j0 < je; ++j0, ++j2) {
mint t0 = a[j0], t1 = a[j0 + v] * xx, t2 = a[j2] * ww,
t3 = a[j2 + v] * wx;
mint t0p2 = t0 + t2, t1p3 = t1 + t3;
mint t0m2 = t0 - t2, t1m3 = (t1 - t3) * imag;
a[j0] = t0p2 + t1p3, a[j0 + v] = t0p2 - t1p3;
a[j2] = t0m2 + t1m3, a[j2 + v] = t0m2 - t1m3;
}
xx *= dw[__builtin_ctzll((jh += 4))];
}
u <<= 2;
v >>= 2;
}
}
void ifft4(vector<mint> &a, int k) {
if ((int)a.size() <= 1) return;
if (k == 1) {
mint a1 = a[1];
a[1] = a[0] - a[1];
a[0] = a[0] + a1;
return;
}
int u = 1 << (k - 2);
int v = 1;
mint one = mint(1);
mint imag = dy[1];
while (u) {
// jh = 0
{
int j0 = 0;
int j1 = v;
int j2 = v + v;
int j3 = j2 + v;
for (; j0 < v; ++j0, ++j1, ++j2, ++j3) {
mint t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3];
mint t0p1 = t0 + t1, t2p3 = t2 + t3;
mint t0m1 = t0 - t1, t2m3 = (t2 - t3) * imag;
a[j0] = t0p1 + t2p3, a[j2] = t0p1 - t2p3;
a[j1] = t0m1 + t2m3, a[j3] = t0m1 - t2m3;
}
}
// jh >= 1
mint ww = one, xx = one * dy[2], yy = one;
u <<= 2;
for (int jh = 4; jh < u;) {
ww = xx * xx, yy = xx * imag;
int j0 = jh * v;
int je = j0 + v;
int j2 = je + v;
for (; j0 < je; ++j0, ++j2) {
mint t0 = a[j0], t1 = a[j0 + v], t2 = a[j2], t3 = a[j2 + v];
mint t0p1 = t0 + t1, t2p3 = t2 + t3;
mint t0m1 = (t0 - t1) * xx, t2m3 = (t2 - t3) * yy;
a[j0] = t0p1 + t2p3, a[j2] = (t0p1 - t2p3) * ww;
a[j0 + v] = t0m1 + t2m3, a[j2 + v] = (t0m1 - t2m3) * ww;
}
xx *= dy[__builtin_ctzll(jh += 4)];
}
u >>= 4;
v <<= 2;
}
if (k & 1) {
u = 1 << (k - 1);
for (int j = 0; j < u; ++j) {
mint ajv = a[j] - a[j + u];
a[j] += a[j + u];
a[j + u] = ajv;
}
}
}
void ntt(vector<mint> &a) {
if ((int)a.size() <= 1) return;
fft4(a, __builtin_ctz(a.size()));
}
void intt(vector<mint> &a) {
if ((int)a.size() <= 1) return;
ifft4(a, __builtin_ctz(a.size()));
mint iv = mint(a.size()).inverse();
for (auto &x : a) x *= iv;
}
vector<mint> multiply(const vector<mint> &a, const vector<mint> &b) {
int l = a.size() + b.size() - 1;
if (min<int>(a.size(), b.size()) <= 40) {
vector<mint> s(l);
for (int i = 0; i < (int)a.size(); ++i)
for (int j = 0; j < (int)b.size(); ++j) s[i + j] += a[i] * b[j];
return s;
}
int k = 2, M = 4;
while (M < l) M <<= 1, ++k;
setwy(k);
vector<mint> s(M);
for (int i = 0; i < (int)a.size(); ++i) s[i] = a[i];
fft4(s, k);
if (a.size() == b.size() && a == b) {
for (int i = 0; i < M; ++i) s[i] *= s[i];
} else {
vector<mint> t(M);
for (int i = 0; i < (int)b.size(); ++i) t[i] = b[i];
fft4(t, k);
for (int i = 0; i < M; ++i) s[i] *= t[i];
}
ifft4(s, k);
s.resize(l);
mint invm = mint(M).inverse();
for (int i = 0; i < l; ++i) s[i] *= invm;
return s;
}
void ntt_doubling(vector<mint> &a) {
int M = (int)a.size();
auto b = a;
intt(b);
mint r = 1, zeta = mint(pr).pow((mint::get_mod() - 1) / (M << 1));
for (int i = 0; i < M; i++) b[i] *= r, r *= zeta;
ntt(b);
copy(begin(b), end(b), back_inserter(a));
}
};
template <typename mint>
void FormalPowerSeries<mint>::set_fft() {
if (!ntt_ptr) ntt_ptr = new NTT<mint>;
}
template <typename mint>
FormalPowerSeries<mint>& FormalPowerSeries<mint>::operator*=(
const FormalPowerSeries<mint>& r) {
if (this->empty() || r.empty()) {
this->clear();
return *this;
}
set_fft();
auto ret = static_cast<NTT<mint>*>(ntt_ptr)->multiply(*this, r);
return *this = FormalPowerSeries<mint>(ret.begin(), ret.end());
}
template <typename mint>
void FormalPowerSeries<mint>::ntt() {
set_fft();
static_cast<NTT<mint>*>(ntt_ptr)->ntt(*this);
}
template <typename mint>
void FormalPowerSeries<mint>::intt() {
set_fft();
static_cast<NTT<mint>*>(ntt_ptr)->intt(*this);
}
template <typename mint>
void FormalPowerSeries<mint>::ntt_doubling() {
set_fft();
static_cast<NTT<mint>*>(ntt_ptr)->ntt_doubling(*this);
}
template <typename mint>
int FormalPowerSeries<mint>::ntt_pr() {
set_fft();
return static_cast<NTT<mint>*>(ntt_ptr)->pr;
}
template <typename mint>
FormalPowerSeries<mint> FormalPowerSeries<mint>::inv(int deg) const {
assert((*this)[0] != mint(0));
if (deg == -1) deg = (int)this->size();
FormalPowerSeries<mint> res(deg);
res[0] = {mint(1) / (*this)[0]};
for (int d = 1; d < deg; d <<= 1) {
FormalPowerSeries<mint> f(2 * d), g(2 * d);
for (int j = 0; j < min((int)this->size(), 2 * d); j++) f[j] = (*this)[j];
for (int j = 0; j < d; j++) g[j] = res[j];
f.ntt();
g.ntt();
for (int j = 0; j < 2 * d; j++) f[j] *= g[j];
f.intt();
for (int j = 0; j < d; j++) f[j] = 0;
f.ntt();
for (int j = 0; j < 2 * d; j++) f[j] *= g[j];
f.intt();
for (int j = d; j < min(2 * d, deg); j++) res[j] = -f[j];
}
return res.pre(deg);
}
template <typename mint>
FormalPowerSeries<mint> FormalPowerSeries<mint>::exp(int deg) const {
using fps = FormalPowerSeries<mint>;
assert((*this).size() == 0 || (*this)[0] == mint(0));
if (deg == -1) deg = this->size();
fps inv;
inv.reserve(deg + 1);
inv.push_back(mint(0));
inv.push_back(mint(1));
auto inplace_integral = [&](fps& F) -> void {
const int n = (int)F.size();
auto mod = mint::get_mod();
while ((int)inv.size() <= n) {
int i = inv.size();
inv.push_back((-inv[mod % i]) * (mod / i));
}
F.insert(begin(F), mint(0));
for (int i = 1; i <= n; i++) F[i] *= inv[i];
};
auto inplace_diff = [](fps& F) -> void {
if (F.empty()) return;
F.erase(begin(F));
mint coeff = 1, one = 1;
for (int i = 0; i < (int)F.size(); i++) {
F[i] *= coeff;
coeff += one;
}
};
fps b{1, 1 < (int)this->size() ? (*this)[1] : 0}, c{1}, z1, z2{1, 1};
for (int m = 2; m < deg; m *= 2) {
auto y = b;
y.resize(2 * m);
y.ntt();
z1 = z2;
fps z(m);
for (int i = 0; i < m; ++i) z[i] = y[i] * z1[i];
z.intt();
fill(begin(z), begin(z) + m / 2, mint(0));
z.ntt();
for (int i = 0; i < m; ++i) z[i] *= -z1[i];
z.intt();
c.insert(end(c), begin(z) + m / 2, end(z));
z2 = c;
z2.resize(2 * m);
z2.ntt();
fps x(begin(*this), begin(*this) + min<int>(this->size(), m));
x.resize(m);
inplace_diff(x);
x.push_back(mint(0));
x.ntt();
for (int i = 0; i < m; ++i) x[i] *= y[i];
x.intt();
x -= b.diff();
x.resize(2 * m);
for (int i = 0; i < m - 1; ++i) x[m + i] = x[i], x[i] = mint(0);
x.ntt();
for (int i = 0; i < 2 * m; ++i) x[i] *= z2[i];
x.intt();
x.pop_back();
inplace_integral(x);
for (int i = m; i < min<int>(this->size(), 2 * m); ++i) x[i] += (*this)[i];
fill(begin(x), begin(x) + m, mint(0));
x.ntt();
for (int i = 0; i < 2 * m; ++i) x[i] *= y[i];
x.intt();
b.insert(end(b), begin(x) + m, end(x));
}
return fps{begin(b), begin(b) + deg};
}
/**
* @brief NTT mod用FPSライブラリ
* @docs docs/fps/ntt-friendly-fps.md
*/
template <uint32_t mod>
struct LazyMontgomeryModInt {
using mint = LazyMontgomeryModInt;
using i32 = int32_t;
using u32 = uint32_t;
using u64 = uint64_t;
static constexpr u32 get_r() {
u32 ret = mod;
for (i32 i = 0; i < 4; ++i) ret *= 2 - mod * ret;
return ret;
}
static constexpr u32 r = get_r();
static constexpr u32 n2 = -u64(mod) % mod;
static_assert(mod < (1 << 30), "invalid, mod >= 2 ^ 30");
static_assert((mod & 1) == 1, "invalid, mod % 2 == 0");
static_assert(r * mod == 1, "this code has bugs.");
u32 a;
constexpr LazyMontgomeryModInt() : a(0) {}
constexpr LazyMontgomeryModInt(const int64_t &b)
: a(reduce(u64(b % mod + mod) * n2)){};
static constexpr u32 reduce(const u64 &b) {
return (b + u64(u32(b) * u32(-r)) * mod) >> 32;
}
constexpr mint &operator+=(const mint &b) {
if (i32(a += b.a - 2 * mod) < 0) a += 2 * mod;
return *this;
}
constexpr mint &operator-=(const mint &b) {
if (i32(a -= b.a) < 0) a += 2 * mod;
return *this;
}
constexpr mint &operator*=(const mint &b) {
a = reduce(u64(a) * b.a);
return *this;
}
constexpr mint &operator/=(const mint &b) {
*this *= b.inverse();
return *this;
}
constexpr mint operator+(const mint &b) const { return mint(*this) += b; }
constexpr mint operator-(const mint &b) const { return mint(*this) -= b; }
constexpr mint operator*(const mint &b) const { return mint(*this) *= b; }
constexpr mint operator/(const mint &b) const { return mint(*this) /= b; }
constexpr bool operator==(const mint &b) const {
return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);
}
constexpr bool operator!=(const mint &b) const {
return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);
}
constexpr mint operator-() const { return mint() - mint(*this); }
constexpr mint operator+() const { return mint(*this); }
constexpr mint pow(u64 n) const {
mint ret(1), mul(*this);
while (n > 0) {
if (n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
constexpr mint inverse() const {
int x = get(), y = mod, u = 1, v = 0, t = 0, tmp = 0;
while (y > 0) {
t = x / y;
x -= t * y, u -= t * v;
tmp = x, x = y, y = tmp;
tmp = u, u = v, v = tmp;
}
return mint{u};
}
friend ostream &operator<<(ostream &os, const mint &b) {
return os << b.get();
}
friend istream &operator>>(istream &is, mint &b) {
int64_t t;
is >> t;
b = LazyMontgomeryModInt<mod>(t);
return (is);
}
constexpr u32 get() const {
u32 ret = reduce(a);
return ret >= mod ? ret - mod : ret;
}
static constexpr u32 get_mod() { return mod; }
};
using namespace std;
// コンストラクタの MAX に 「C(n, r) や fac(n) でクエリを投げる最大の n 」
// を入れると倍速くらいになる
// mod を超えて前計算して 0 割りを踏むバグは対策済み
template <typename T>
struct Binomial {
vector<T> f, g, h;
Binomial(int MAX = 0) {
assert(T::get_mod() != 0 && "Binomial<mint>()");
f.resize(1, T{1});
g.resize(1, T{1});
h.resize(1, T{1});
if (MAX > 0) extend(MAX + 1);
}
void extend(int m = -1) {
int n = f.size();
if (m == -1) m = n * 2;
m = min<int>(m, T::get_mod());
if (n >= m) return;
f.resize(m);
g.resize(m);
h.resize(m);
for (int i = n; i < m; i++) f[i] = f[i - 1] * T(i);
g[m - 1] = f[m - 1].inverse();
h[m - 1] = g[m - 1] * f[m - 2];
for (int i = m - 2; i >= n; i--) {
g[i] = g[i + 1] * T(i + 1);
h[i] = g[i] * f[i - 1];
}
}
T fac(int i) {
if (i < 0) return T(0);
while (i >= (int)f.size()) extend();
return f[i];
}
T finv(int i) {
if (i < 0) return T(0);
while (i >= (int)g.size()) extend();
return g[i];
}
T inv(int i) {
if (i < 0) return -inv(-i);
while (i >= (int)h.size()) extend();
return h[i];
}
T C(int n, int r) {
if (n < 0 || n < r || r < 0) return T(0);
return fac(n) * finv(n - r) * finv(r);
}
inline T operator()(int n, int r) { return C(n, r); }
template <typename I>
T multinomial(const vector<I>& r) {
static_assert(is_integral<I>::value == true);
int n = 0;
for (auto& x : r) {
if (x < 0) return T(0);
n += x;
}
T res = fac(n);
for (auto& x : r) res *= finv(x);
return res;
}
template <typename I>
T operator()(const vector<I>& r) {
return multinomial(r);
}
T C_naive(int n, int r) {
if (n < 0 || n < r || r < 0) return T(0);
T ret = T(1);
r = min(r, n - r);
for (int i = 1; i <= r; ++i) ret *= inv(i) * (n--);
return ret;
}
T P(int n, int r) {
if (n < 0 || n < r || r < 0) return T(0);
return fac(n) * finv(n - r);
}
// [x^r] 1 / (1-x)^n
T H(long long n, long long r) {
if (n < 0 || r < 0) return T(0);
return r == 0 ? 1 : C(n + r - 1, r);
}
};
// #include "fps/arbitrary-fps.hpp"
//
using namespace Nyaan;
using mint = LazyMontgomeryModInt<998244353>;
// using mint = LazyMontgomeryModInt<1000000007>;
using vm = vector<mint>;
using vvm = vector<vm>;
Binomial<mint> C;
using fps = FormalPowerSeries<mint>;
using namespace Nyaan;
fps naive(int N, vvi g) {
vi p = mkiota(N);
fps res(N + 1);
do {
int num = 0;
rep(i, N) {
int ok = 1;
each(j, g[i]) ok &= p[i] > p[j];
num += ok;
}
res[num] += 1;
} while (nxp(p));
return res;
}
mint calc_sub(vvi g, mint a) {
trc(a);
a -= 1;
// (最大値候補の場合, 最大値候補でない場合の各値, サイズ)
auto dfs = [&](auto rc, int c, int par) -> tuple<fps, fps, int> {
// 最大値候補たちのうちの最小値に注目する
// f[i] : 最大値候補たちの値のうちの最小値が i 超過である場合
fps f;
// 最大値が存在しない場合 : 子の頂点の値の最大値に注目する
// g[i] : 子の頂点の値の最大値が i 以下である場合
fps f2;
each(d, g[c]) {
if (d == par) continue;
auto [x, z, s] = rc(rc, d, c);
assert(sz(z) == s);
if (f.empty()) {
repr(i, s - 1) x[i] += x[i + 1];
rep(i, s - 1) z[i + 1] += z[i];
f = x;
f2 = z;
continue;
}
trc(f, f2, x, z, s);
mint y = accumulate(begin(z), end(z), mint{0});
fps p(sz(f) + s), q(sz(f) + s);
// d が最大値候補でない場合, かつ f からの遷移
// i 番目の前に少なくとも j 個来る
rep(i, sz(f)) rep(j, s + 1) {
p[i + j] += f[i] * y * C(i + j, j) * C(sz(f) - i + s - j, s - j);
}
trc(p, q);
// d が最大値候補でない場合, かつ f2 からの遷移
rep(i, s - 1) z[i + 1] += z[i];
f2 = f2.rev(), z = z.rev();
rep(i, sz(f)) rep(j, s) {
q[i + j] += f2[i] * z[j] * C(i + j, j) * C(sz(f) - i + s - j, s - j);
}
f2 = f2.rev(), z = z.rev(), q = q.rev();
trc(p, q);
// d が最大値候補である場合
// i 超過かつ j 超過
repr(i, s - 1) x[i] += x[i + 1];
rep(i, sz(f)) rep(j, s) {
p[i + j] += f[i] * x[j] * C(i + j, j) * C(sz(f) - i + s - j, s - j);
}
trc(p, q);
mint w = f2.back();
// j 番目前にちょうど i 個来る
rep(i, sz(f) + 1) rep(j, s) {
p[i + j] += w * x[j] * C(i + j, j) * C(sz(f) - i + s - j, s - j);
}
trc(p, q);
f = p, f2 = q;
}
trc(c, f, f2);
if (f.empty()) return make_tuple(fps{a}, fps{1}, 1);
int s = sz(f);
// c が最大値候補の場合
fps x(s + 1);
// i の場合 : j<i
rep(i, s) x[i + 1] = f2[i];
x *= a;
// c が最大値候補でない場合
// 子が f2 の場合 : 自由
fps y(s + 1, f2.back());
// 子が f の場合
// i の場合 : (i<j) f[j] たちの和になる
rep(i, s) y[i] += f[i];
trc(c, x, y);
return make_tuple(x, y, s + 1);
};
auto [f, f2, s] = dfs(dfs, 0, -1);
trc(f, f2, s);
return accumulate(begin(f), end(f), mint{}) +
accumulate(begin(f2), end(f2), mint{});
}
fps calc(int N, vvi g) {
vm xs, ys;
rep1(a, N + 1) {
xs.push_back(a);
ys.push_back(calc_sub(g, a));
}
auto ans = PolynomialInterpolation(xs, ys);
return ans;
}
void test() {
rep(t, TEN(3)) {
int N = rng(1, 8);
vvi g(N);
rep1(i, N - 1) {
int p = rng(0, i - 1);
g[p].push_back(i);
g[i].push_back(p);
}
auto an = naive(N, g);
auto ac = calc(N, g);
if (an != ac) {
trc(N, g);
trc(an);
trc(ac);
exit(1);
}
}
trc2("OK");
}
void q() {
ini(N);
auto g = graph(N);
auto ans = calc(N, g);
ans.erase(begin(ans));
each(x, ans) out(x);
}
void Nyaan::solve() {
// test();
int t = 1;
// in(t);
while (t--) q();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
5 1 2 1 3 2 4 2 5
output:
28 54 38 0 0
result:
ok 5 number(s): "28 54 38 0 0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
10 6 10 5 9 10 3 9 10 7 4 4 1 3 2 3 7 8 4
output:
11540 253870 957220 1439080 737000 230090 0 0 0 0
result:
ok 10 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
10 8 4 4 7 3 1 6 10 6 4 9 10 2 5 5 6 9 1
output:
7140 204390 1027380 1597560 731880 60450 0 0 0 0
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 2 4 2 5 8 9 7 10 10 9 2 8 3 9 1 3 6 10
output:
14200 210620 1137900 1210580 811660 243840 0 0 0 0
result:
ok 10 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
9 9 8 4 1 9 1 2 7 8 5 8 7 6 5 1 3
output:
2472 34356 162036 107292 56724 0 0 0 0
result:
ok 9 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 3 8 4 7 8 6 4 6 6 10 9 1 3 2 4 5 9 10
output:
8800 148400 1210800 1396880 798640 65280 0 0 0 0
result:
ok 10 numbers
Test #7:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
15 14 9 7 13 7 8 3 6 1 15 4 15 7 11 8 1 2 7 14 8 15 5 10 6 2 10 12 1
output:
56289600 967779134 923981730 96060068 10686262 235209478 265673053 195831107 217488197 0 0 0 0 0 0
result:
ok 15 numbers
Test #8:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
15 6 9 10 12 6 10 7 15 9 7 8 15 4 12 11 1 13 6 2 9 3 12 1 3 9 14 7 5
output:
31011120 397655661 546345792 817109204 257395717 479471757 323343241 216283820 898626670 0 0 0 0 0 0
result:
ok 15 numbers
Test #9:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
15 9 3 9 5 9 6 11 15 5 11 4 14 1 15 2 1 13 14 8 1 9 7 7 14 10 2 12 2
output:
7023120 201832948 304836830 97923512 115869813 704294252 680848885 806741309 252218772 795653541 0 0 0 0 0
result:
ok 15 numbers
Test #10:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
14 5 4 3 7 9 4 3 8 10 9 1 2 10 7 4 11 14 2 5 1 2 12 4 13 6 11
output:
1277136 187034232 817102492 231238823 482826933 368166096 908219189 329900647 0 0 0 0 0 0
result:
ok 14 numbers
Test #11:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
15 9 12 1 9 13 10 7 4 11 6 7 3 14 1 11 3 15 14 11 10 2 10 5 12 1 13 12 8
output:
9790200 299361307 878733115 457013044 633916410 202070873 627253395 427436036 431668602 0 0 0 0 0 0
result:
ok 15 numbers
Test #12:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
30 21 17 4 6 30 28 12 19 3 6 18 11 5 17 13 30 3 27 5 28 7 30 3 25 3 7 27 24 4 16 20 26 30 1 5 9 9 2 23 12 13 20 17 19 22 14 18 20 17 14 11 29 10 27 15 23 11 8
output:
476665504 833146853 594913132 343840733 858440316 821830796 654815681 964050488 845418488 904523186 295267527 167669554 262061667 391216026 785126836 458297537 593077098 789556990 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 30 numbers
Test #13:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
30 13 21 15 29 9 3 22 8 3 15 15 25 14 8 19 8 24 27 28 4 12 27 8 18 28 25 24 25 8 9 21 5 7 17 11 23 11 16 3 11 26 10 10 16 8 7 11 20 27 21 26 30 15 6 1 6 2 28
output:
249311566 811045480 794072210 750170140 651800148 196077467 477989528 572918836 242191488 523238077 544740575 334825331 251208738 982415005 179148017 25972277 259519791 198540679 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 30 numbers
Test #14:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
30 10 11 7 29 9 30 4 12 20 18 30 15 3 30 18 16 23 1 22 6 29 25 29 5 16 14 25 27 15 13 24 5 14 22 23 5 1 19 2 11 7 15 26 29 12 21 26 14 12 20 15 28 27 10 17 26 8 26
output:
951802166 75337913 968695388 666501385 268553896 268591487 700091004 819234540 144322774 215302608 21960660 240875748 383482009 549084481 792698573 853681515 56586856 68382350 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 30 numbers
Test #15:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
29 5 13 18 19 7 2 10 16 2 3 28 22 17 14 25 29 14 8 27 17 9 6 15 11 7 20 8 1 15 12 13 18 9 26 10 23 10 5 17 7 9 24 10 17 21 29 22 1 16 24 4 28 20 21 20 11
output:
183093936 736732472 832827292 220921133 411064273 11608335 442961727 541248342 443664563 614435954 805482321 716726563 537008113 6091735 691949655 359540208 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 29 numbers
Test #16:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
30 1 17 27 23 2 19 28 7 17 22 20 23 9 27 9 5 11 13 7 24 9 11 13 28 16 9 8 3 22 16 29 16 8 24 22 18 22 14 10 11 13 6 4 18 21 9 25 28 17 12 16 30 27 15 24 2 26 24
output:
808671184 292518367 616199530 559639988 739602615 50200053 943966753 160098660 786551596 68220094 4828146 85859498 850152734 502065476 849914909 707591022 19104728 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 30 numbers
Test #17:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
30 2 1 3 1 1 4 4 5 6 5 4 7 8 6 9 8 9 10 9 11 9 12 11 13 14 11 12 15 13 16 15 17 18 17 19 16 19 20 20 21 19 22 22 23 22 24 22 25 26 24 24 27 28 26 29 26 27 30
output:
797780008 686571598 512601217 172589162 229077536 547622293 778878933 995407067 370565763 781815547 856193170 12039270 113119304 865952842 482288625 709423510 10626583 120877278 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 30 numbers
Test #18:
score: 0
Accepted
time: 5ms
memory: 3584kb
input:
70 48 32 5 25 9 43 42 18 13 35 32 28 17 66 53 36 21 52 47 17 20 34 67 13 34 40 52 36 49 50 11 66 30 32 44 43 20 51 47 56 6 66 11 24 69 50 39 19 11 30 9 62 18 21 68 34 69 39 28 10 14 24 4 30 67 47 44 6 66 22 65 1 42 16 59 8 12 50 32 45 24 60 46 17 69 8 43 41 33 61 27 2 22 2 8 67 60 52 55 15 13 61 37 ...
output:
943526961 320961617 166604850 701811460 389268693 738553375 215044618 451762417 891005935 810701751 125288699 585534137 985892828 931011067 707058487 7650954 536390154 943272279 709112563 723959681 929197521 402121766 553250601 260050045 712455754 1522617 370081754 452796510 644890353 36138167 57584...
result:
ok 70 numbers
Test #19:
score: 0
Accepted
time: 7ms
memory: 3840kb
input:
70 55 32 44 27 40 6 52 42 39 67 56 64 21 43 7 48 62 59 1 26 31 13 44 1 18 39 15 64 46 48 28 5 12 47 39 19 30 66 43 56 37 22 4 26 2 40 9 2 34 12 18 15 18 6 28 68 30 40 37 31 30 57 24 52 43 47 22 15 20 29 47 62 18 10 2 70 61 12 47 28 1 52 23 38 58 16 4 49 49 28 57 3 23 24 15 17 70 16 51 8 31 69 60 29 ...
output:
25910015 163992214 232378033 119711775 187475131 195677641 426749502 361226824 176083776 463491958 727433469 889576680 332436759 809785997 718639576 39870971 540913995 428104678 799845288 976730249 521491333 365953390 479106938 328510082 604649102 755282530 253636597 836671759 332287833 682395480 50...
result:
ok 70 numbers
Test #20:
score: 0
Accepted
time: 6ms
memory: 3712kb
input:
69 63 5 59 5 4 15 52 14 57 60 7 34 9 68 33 62 62 31 59 27 29 60 64 58 63 39 27 30 1 39 55 62 69 47 68 17 6 46 26 1 50 25 35 56 37 46 59 12 30 2 35 24 19 16 64 21 51 43 55 41 37 58 55 16 41 67 7 11 35 66 28 58 13 17 54 32 3 44 67 21 54 68 42 1 35 4 23 69 39 8 53 61 23 10 27 52 54 35 59 46 43 53 34 46...
output:
433178845 749347039 483550824 961302408 490763456 38943809 258235571 249129284 529624467 919699700 478839438 51132901 227139138 693529588 232856595 372323915 931822866 275207593 647509343 892538620 833150204 409551669 583012730 465413566 580934706 626121538 241910322 407826554 329925651 11988244 568...
result:
ok 69 numbers
Test #21:
score: 0
Accepted
time: 7ms
memory: 3840kb
input:
70 16 59 15 31 4 36 1 16 68 9 64 23 52 25 51 25 27 9 7 44 49 65 35 37 21 26 32 4 33 37 69 7 58 62 41 44 54 30 19 21 45 12 13 44 51 33 64 33 10 16 69 64 24 16 5 61 58 69 38 11 69 30 45 18 9 24 56 35 1 51 40 13 6 69 3 40 20 46 50 64 61 68 49 29 22 58 15 63 68 55 70 23 29 22 70 42 35 14 21 17 66 1 22 1...
output:
913892556 512515359 307932596 208166439 923812488 787814883 926522725 861402576 943667618 243713276 714542402 21996395 555468493 726536623 346707943 782684467 820344669 880144284 606053876 228354729 25060139 991208882 163764214 614834489 971165918 436603249 472900353 884414168 364542656 330974777 32...
result:
ok 70 numbers
Test #22:
score: 0
Accepted
time: 6ms
memory: 3840kb
input:
70 2 1 3 1 3 4 3 5 6 3 7 6 8 6 9 7 10 7 10 11 12 11 10 13 13 14 15 13 13 16 17 15 18 17 17 19 17 20 21 18 21 22 23 22 21 24 25 22 26 25 27 24 28 26 27 29 30 28 28 31 32 31 30 33 34 33 35 32 36 33 34 37 35 38 39 38 38 40 39 41 41 42 43 40 41 44 42 45 45 46 45 47 45 48 49 46 50 48 48 51 52 50 53 50 54...
output:
770169934 954555437 202257555 347334878 830323432 768480462 270384736 663728843 213556185 822256151 64172800 679424659 434554033 132510570 315113252 187753192 669137644 184968401 682886109 217514370 981985189 19129665 347549366 96071198 773619812 940957399 146067192 241287331 513595468 194094689 270...
result:
ok 70 numbers
Test #23:
score: 0
Accepted
time: 7ms
memory: 3840kb
input:
70 63 48 17 68 8 15 31 51 23 9 19 27 10 2 51 53 56 5 59 7 42 14 36 45 58 41 24 52 70 21 29 42 16 40 35 38 51 57 50 24 54 29 47 20 36 41 51 70 51 12 32 23 68 51 28 11 19 43 58 55 61 35 6 69 65 10 38 32 5 25 42 67 45 10 43 68 64 54 36 9 13 11 3 56 43 58 45 64 69 42 46 69 70 25 49 53 3 59 25 34 9 44 62...
output:
264422203 259298436 524867369 934958379 512456582 915748464 236380955 958526478 624343335 46856122 857595835 988798351 913132871 742485039 771978513 861720636 383944358 713516744 979650053 426134061 462415499 160845205 625982509 264284599 857319056 336185780 669646687 739448821 735484325 401233653 2...
result:
ok 70 numbers
Test #24:
score: 0
Accepted
time: 323ms
memory: 4480kb
input:
499 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 5...
output:
154029661 845001665 588557122 331004513 87119293 243589628 266481846 147445671 723892377 953399570 23874206 699082355 636337437 324612961 626615378 446859683 694059168 787587513 149004470 635734612 621444756 210884890 779365620 551506117 15704724 403748771 906444429 246784225 846106948 640128219 739...
result:
ok 499 numbers
Test #25:
score: 0
Accepted
time: 320ms
memory: 4480kb
input:
498 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 5...
output:
576137007 698536 705959869 459350169 613887621 376422552 900328015 918425372 851033096 643279868 515045927 107782280 474198026 593065562 958399880 98812746 600959826 162247473 259978802 763053996 89480037 867722997 92715192 529872829 910853989 935119642 95654181 955573778 151180755 97383478 30815805...
result:
ok 498 numbers
Test #26:
score: 0
Accepted
time: 240ms
memory: 4352kb
input:
449 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 5...
output:
751815647 426017185 189946231 837605210 831032354 558518285 609712385 770376473 693334904 134936351 532982601 250533254 139517032 523182123 20943426 27206945 383519608 556767776 27517590 500413486 826823026 418022166 434103911 995245814 561462243 103918631 698821468 459687218 593594456 251057760 800...
result:
ok 449 numbers
Test #27:
score: 0
Accepted
time: 169ms
memory: 4224kb
input:
398 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 5...
output:
816865800 985467713 971327665 632395692 196446727 434030679 627560633 627485844 690518955 454995971 243792985 450549538 100043661 886174999 104714586 987473276 24532275 653353159 139211535 243040095 979920292 162798353 813215115 604552457 213219564 149285135 67591743 54703787 644578633 662367371 938...
result:
ok 398 numbers
Test #28:
score: 0
Accepted
time: 26ms
memory: 4096kb
input:
205 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 5...
output:
753130417 109881001 685399927 861559523 151807032 22067972 614582330 316790429 378783717 575992167 91660065 720021539 865352199 971813962 435797246 865719812 619611866 937412322 908785703 927403083 612136223 897290670 901657475 401254407 359043429 459501291 47347742 420861174 906213402 353842071 581...
result:
ok 205 numbers
Test #29:
score: 0
Accepted
time: 88ms
memory: 4224kb
input:
317 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 5...
output:
537692343 70332772 131269515 673005701 470271276 733808699 437387223 925852785 517665139 598305587 815114704 735338355 630639875 169905755 142417305 877665425 232910454 933440866 86065313 658117379 740478559 66328597 653130205 664013451 540141148 375663590 811732978 974656532 822687271 842318519 648...
result:
ok 317 numbers
Test #30:
score: 0
Accepted
time: 23ms
memory: 3840kb
input:
195 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 5...
output:
77748471 398477838 589876897 629903989 552184816 787052062 874959254 688197019 964544174 66654714 385501062 703342362 923033837 26511983 988277234 187746498 191143482 840098727 119964152 811499910 309252543 763245158 468083088 423007512 670157523 205395175 724354927 254415808 210586892 252761012 319...
result:
ok 195 numbers
Test #31:
score: 0
Accepted
time: 57ms
memory: 3840kb
input:
150 116 71 34 7 65 101 5 46 111 13 137 101 1 55 44 21 38 41 106 137 78 59 100 46 35 28 124 1 89 91 19 68 18 99 138 3 69 84 121 51 86 148 96 8 136 114 78 10 45 59 62 111 17 121 76 133 128 57 10 82 45 22 82 14 62 54 9 12 147 75 93 118 66 100 77 36 48 84 13 108 115 89 29 98 150 99 54 39 2 16 24 104 62 ...
output:
221296425 233619510 597093928 590289712 520646361 398787779 484565637 451952423 966808834 186744490 419775993 552896963 156815267 588385113 462237525 747539400 791215426 62461466 329133131 749412389 946770150 966106474 801575459 480097895 759451763 96057697 309781826 691936385 16597521 943612018 664...
result:
ok 150 numbers
Test #32:
score: 0
Accepted
time: 59ms
memory: 3712kb
input:
150 61 85 45 79 111 108 96 19 76 12 127 104 82 1 117 31 109 57 23 101 51 36 74 137 144 123 34 15 144 53 60 124 98 106 114 45 39 66 54 4 8 37 108 56 58 96 118 43 62 135 127 134 67 123 31 42 10 32 12 105 135 8 16 75 103 119 68 146 18 14 84 117 35 109 54 136 135 50 28 9 148 6 94 42 74 113 79 148 56 13 ...
output:
713725525 805562334 96433020 546123807 550691934 597527928 6533268 108784302 346228487 668175131 725745656 308268308 531991783 504805897 823191919 88577010 559908403 373437029 643168298 582685816 738472610 829730996 92704611 527426356 551119256 512680311 249734977 802231938 430120193 835729579 72788...
result:
ok 150 numbers
Test #33:
score: 0
Accepted
time: 56ms
memory: 3840kb
input:
149 97 65 112 85 97 21 38 85 32 58 4 94 46 87 24 97 96 149 79 95 40 132 112 82 149 34 65 86 114 16 149 68 116 118 61 4 114 38 139 21 55 87 116 79 84 105 107 94 97 142 28 121 112 134 144 41 60 109 114 20 140 7 15 95 136 105 120 31 95 57 36 67 98 131 69 98 95 102 109 7 90 1 82 124 95 30 81 47 7 84 75 ...
output:
98042867 96892318 375476331 826808672 387356478 182904951 224552511 300909834 67785767 440277040 630023108 621935275 500093521 693308446 637811355 460126499 782411882 191034277 114291640 20098658 552825174 692896813 21273264 935546769 696524278 370374643 992604036 460222526 768855555 296709495 79758...
result:
ok 149 numbers
Test #34:
score: 0
Accepted
time: 54ms
memory: 3840kb
input:
150 67 64 16 91 106 96 83 97 6 66 53 64 70 17 97 76 6 112 14 1 37 52 42 78 118 139 97 125 5 62 50 33 81 107 42 116 129 42 63 32 103 124 143 34 23 85 133 35 132 15 117 82 70 27 29 66 142 57 33 49 79 31 146 12 136 126 65 97 64 131 88 145 102 30 150 9 41 8 69 92 66 126 143 128 144 93 40 27 12 65 131 97...
output:
862895765 456420712 402639020 89112608 995034647 608820005 960561754 120569939 231419101 990088535 848221961 910262651 930666128 527873138 347606922 469727448 814427204 644774591 489780107 639337324 629765393 695760351 536267340 159127690 102994880 377510967 123705146 521753217 395619906 902275239 2...
result:
ok 150 numbers
Test #35:
score: 0
Accepted
time: 41ms
memory: 3968kb
input:
150 2 1 1 3 3 4 5 2 6 4 6 7 6 8 8 9 7 10 11 10 9 12 10 13 14 12 13 15 13 16 16 17 18 15 16 19 20 18 21 18 19 22 23 20 22 24 25 24 26 25 27 25 27 28 27 29 30 28 31 28 29 32 33 30 33 34 34 35 36 33 37 34 38 36 39 37 38 40 40 41 42 39 40 43 44 42 44 45 46 43 47 46 48 46 49 46 49 50 51 48 52 50 52 53 52...
output:
920670062 463733942 472140513 386651320 175691980 779851065 972743419 650713153 164206870 690737598 81968990 395149724 99382252 586595508 489378741 783502764 517111220 246324086 47612930 773952049 323656923 176968903 301570017 467644419 59081691 49338463 448048355 90082381 753381881 189847025 747786...
result:
ok 150 numbers
Test #36:
score: 0
Accepted
time: 59ms
memory: 3840kb
input:
150 36 119 42 147 121 60 72 65 69 11 91 4 46 55 39 129 19 136 112 110 147 86 73 84 126 65 98 33 95 111 13 123 101 59 5 42 51 141 64 35 129 101 136 122 119 140 115 27 1 149 77 93 85 143 16 21 107 114 115 18 56 135 133 25 38 51 52 69 102 12 34 56 74 25 36 11 8 105 82 94 32 92 51 144 62 106 51 57 103 2...
output:
850082776 26004871 338267392 751281655 138411800 883677482 879611326 79151046 600215417 244678741 534465903 12453393 959482755 578220125 493219092 852056214 140518474 465654507 482847096 252282939 128985349 205480431 318675845 692762577 866275797 136996062 175465110 512401807 673518901 890548146 384...
result:
ok 150 numbers
Test #37:
score: 0
Accepted
time: 11ms
memory: 3840kb
input:
150 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 5...
output:
863397297 563570776 698316583 440383599 991396522 763829634 23113903 491282516 312338255 649052955 767053627 955088494 935433077 235695296 840027517 835088017 95680139 128426743 911697339 58888643 136149623 665701675 849916677 743050511 301268970 866071625 497117417 770475232 505934278 730317443 895...
result:
ok 150 numbers
Test #38:
score: 0
Accepted
time: 58ms
memory: 3840kb
input:
150 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 11 6 12 6 13 7 14 7 15 8 16 8 17 9 18 9 19 10 20 10 21 11 22 11 23 12 24 12 25 13 26 13 27 14 28 14 29 15 30 15 31 16 32 16 33 17 34 17 35 18 36 18 37 19 38 19 39 20 40 20 41 21 42 21 43 22 44 22 45 23 46 23 47 24 48 24 49 25 50 25 51 26 52 26 53 27 54 27 5...
output:
795549660 575116415 34771012 784418026 567016119 962178455 356109035 805358863 230506273 15689356 285843982 826705870 997188588 568990161 688127903 930740453 788088247 197589842 390445164 105719055 190866841 472055214 129652900 500774519 153294491 277517303 9666229 791923011 721258429 727084906 6832...
result:
ok 150 numbers
Test #39:
score: 0
Accepted
time: 62ms
memory: 3840kb
input:
150 1 2 3 2 4 1 1 5 6 5 7 5 8 6 9 7 10 7 3 11 12 6 13 3 14 2 15 2 16 10 6 17 18 7 19 15 20 1 5 21 10 22 10 23 24 1 3 25 1 26 27 3 28 24 8 29 30 1 19 31 32 5 33 16 34 23 21 35 24 36 37 31 38 15 12 39 29 40 2 41 42 18 26 43 29 44 4 45 18 46 47 45 35 48 49 35 50 11 34 51 17 52 34 53 54 14 55 15 37 56 5...
output:
477892339 861107133 91499080 18411298 828050894 925278484 138752131 923950221 694917313 62650040 13353244 783106978 159036537 611695535 525448272 927188500 758881145 332461574 906090868 263018229 824205178 740612904 97994176 425045475 460658948 881189832 902324169 743475670 1454614 491700138 9382768...
result:
ok 150 numbers
Test #40:
score: 0
Accepted
time: 43ms
memory: 3840kb
input:
150 2 1 3 1 2 4 5 3 3 6 4 7 8 7 9 7 10 7 10 11 9 12 10 13 14 13 15 13 16 14 17 16 15 18 16 19 20 17 20 21 22 19 21 23 23 24 25 22 25 26 26 27 28 27 28 29 27 30 31 30 30 32 33 30 32 34 32 35 33 36 37 34 37 38 39 36 39 40 38 41 40 42 40 43 43 44 45 43 45 46 46 47 45 48 49 48 47 50 51 49 51 52 53 50 54...
output:
392650722 592029195 112331471 474015453 836899789 119059153 643097913 968773580 203367894 260515872 362187408 180805394 320775982 233905889 334788497 544076554 446302051 858931094 165682096 313555562 755816689 829847569 896736777 545716931 968232429 380436982 85523190 910186860 638752557 984428996 9...
result:
ok 150 numbers
Test #41:
score: 0
Accepted
time: 1972ms
memory: 3968kb
input:
500 223 142 220 10 470 426 370 270 80 297 332 12 420 84 452 154 33 84 500 189 454 67 483 192 218 366 83 337 496 101 393 196 380 236 1 453 442 114 220 245 363 248 26 72 217 263 91 243 65 315 122 455 120 210 263 31 47 327 407 170 253 195 189 471 349 239 393 107 159 217 274 288 261 141 351 381 425 394 ...
output:
217468707 22882298 552814381 336641701 280982427 4518558 286600491 327908926 71236802 607480516 341144934 145652523 357795122 880648080 593855033 155591372 115979568 572282817 201023943 910037699 38519375 783989147 687331830 145029114 553765411 214029311 211398637 151704968 11990592 772349877 445702...
result:
ok 500 numbers
Test #42:
score: 0
Accepted
time: 1978ms
memory: 3840kb
input:
500 49 314 6 110 398 255 250 143 80 120 61 292 417 235 191 290 380 326 206 145 400 166 71 34 80 323 293 137 374 336 433 119 457 463 492 403 275 361 249 347 275 384 90 403 172 490 407 188 5 407 344 158 206 49 22 26 243 13 218 279 433 419 109 421 318 170 427 444 229 363 380 455 265 267 320 300 162 483...
output:
17917287 959921372 757861805 763547231 789925395 832660373 706850355 850297107 471930799 635626657 585991391 145308342 445793537 654485112 210465545 926834850 940662817 694429408 531996987 383765155 455430586 112385468 26168862 697668300 849419501 662404053 711156391 896540974 520045392 414621739 53...
result:
ok 500 numbers
Test #43:
score: 0
Accepted
time: 1976ms
memory: 3840kb
input:
499 13 465 190 132 384 96 199 193 261 10 379 62 61 365 280 331 186 314 406 117 475 232 497 458 2 446 150 87 211 51 216 174 97 292 425 454 374 478 273 439 359 188 357 111 166 477 332 185 187 313 195 200 260 86 89 144 319 303 400 355 138 106 402 455 267 30 33 437 389 153 331 13 149 45 307 44 11 306 20...
output:
895081361 103555181 578866162 490597126 665816135 309192356 60263574 444439210 638493658 785464101 192641111 321491623 169363877 361407501 475788144 66102833 242889663 503706375 938588358 927055504 282861522 260355268 753910201 725284774 200220281 773496080 422470654 963799110 460009349 420706288 13...
result:
ok 499 numbers
Test #44:
score: 0
Accepted
time: 1990ms
memory: 3968kb
input:
500 141 365 363 324 356 85 389 336 6 238 287 80 18 383 332 260 77 216 44 256 216 164 411 306 13 252 439 341 478 432 337 95 120 78 238 320 201 144 184 292 2 228 129 197 455 115 314 163 425 250 492 417 436 314 127 120 308 337 148 112 407 15 77 58 397 84 319 87 86 291 228 154 48 126 473 469 268 468 95 ...
output:
145232419 459607844 882409319 453400253 886017870 679552878 302881182 901761962 374895433 911415295 471870649 939637572 762322883 289001565 449776769 923787798 100003097 647930805 716275914 670127560 513881741 193828867 529043666 358701046 136492841 605728655 696243956 449115719 962661510 794022549 ...
result:
ok 500 numbers
Test #45:
score: 0
Accepted
time: 1321ms
memory: 4224kb
input:
500 2 1 1 3 2 4 5 3 3 6 4 7 5 8 6 9 10 7 9 11 9 12 12 13 14 12 15 14 15 16 16 17 16 18 18 19 18 20 20 21 19 22 21 23 24 23 25 23 26 23 24 27 28 26 29 28 27 30 30 31 32 29 33 32 33 34 35 34 36 35 37 36 38 36 36 39 40 37 41 40 42 40 43 42 44 41 42 45 46 43 46 47 48 46 47 49 50 49 50 51 52 49 52 53 52 ...
output:
876027314 791187132 110224056 814416850 531135568 159208865 303931590 71739249 544912755 305431690 485489903 976186361 44537910 564902229 873939344 404043704 986777826 355382783 122787087 182101691 882765307 485345622 360241953 417874086 672561454 400183801 510098036 725729495 200897606 897527447 85...
result:
ok 500 numbers
Test #46:
score: 0
Accepted
time: 1984ms
memory: 3840kb
input:
500 181 10 284 460 393 104 23 484 116 224 412 208 256 416 341 291 43 140 104 169 132 469 51 344 74 29 484 472 219 91 20 304 212 413 321 125 99 113 316 104 23 304 321 98 78 46 95 53 91 83 2 85 427 311 186 136 27 361 219 417 122 384 123 471 470 381 431 252 12 27 77 393 87 134 379 307 309 383 145 205 3...
output:
442132840 381735235 564742071 197584134 774494395 692387618 628894613 323167552 642633794 277146534 633096180 777103809 421672236 340066918 446533332 174322775 954514168 627796810 369172460 559242495 218649588 652690914 211164304 184240408 533221594 696704846 67890756 514651069 849685816 499126293 6...
result:
ok 500 numbers
Test #47:
score: 0
Accepted
time: 324ms
memory: 4352kb
input:
500 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 5...
output:
308059322 227229598 394807253 909658943 13339434 690533221 816673242 101053296 541241898 630195210 961112458 239005104 920695145 259114263 317750216 351232439 137409107 402710500 754120929 434480438 98652665 416793626 246073764 971430956 504912834 111220008 231247384 827992380 923791110 112046367 61...
result:
ok 500 numbers
Test #48:
score: -100
Time Limit Exceeded
input:
500 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 5 10 5 11 6 12 6 13 7 14 7 15 8 16 8 17 9 18 9 19 10 20 10 21 11 22 11 23 12 24 12 25 13 26 13 27 14 28 14 29 15 30 15 31 16 32 16 33 17 34 17 35 18 36 18 37 19 38 19 39 20 40 20 41 21 42 21 43 22 44 22 45 23 46 23 47 24 48 24 49 25 50 25 51 26 52 26 53 27 54 27 5...