QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#108838 | #5741. Triterminant | maspy | AC ✓ | 13ms | 4796kb | C++23 | 38.3kb | 2023-05-26 19:02:05 | 2023-05-26 19:02:08 |
Judging History
answer
#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
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); }
// (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, typename U>
T ceil(T x, U y) {
return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sum = 0;
for (auto &&a: A) sum += a;
return sum;
}
#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) {
assert(!que.empty());
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
assert(!que.empty());
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;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, 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;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, 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;
}
#endif
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>
namespace fastio {
#define FASTIO
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
template <class T>
static auto check(T &&x) -> decltype(x.write(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};
struct has_read_impl {
template <class T>
static auto check(T &&x) -> decltype(x.read(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};
struct Scanner {
FILE *fp;
char line[(1 << 15) + 1];
size_t st = 0, ed = 0;
void reread() {
memmove(line, line + st, ed - st);
ed -= st;
st = 0;
ed += fread(line + ed, 1, (1 << 15) - ed, fp);
line[ed] = '\0';
}
bool succ() {
while (true) {
if (st == ed) {
reread();
if (st == ed) return false;
}
while (st != ed && isspace(line[st])) st++;
if (st != ed) break;
}
if (ed - st <= 50) {
bool sep = false;
for (size_t i = st; i < ed; i++) {
if (isspace(line[i])) {
sep = true;
break;
}
}
if (!sep) reread();
}
return true;
}
template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
while (true) {
size_t sz = 0;
while (st + sz < ed && !isspace(line[st + sz])) sz++;
ref.append(line + st, sz);
st += sz;
if (!sz || st != ed) break;
reread();
}
return true;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
bool neg = false;
if (line[st] == '-') {
neg = true;
st++;
}
ref = T(0);
while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
if (neg) ref = -ref;
return true;
}
template <typename T,
typename enable_if<has_read<T>::value>::type * = nullptr>
inline bool read_single(T &x) {
x.read();
return true;
}
bool read_single(double &ref) {
string s;
if (!read_single(s)) return false;
ref = std::stod(s);
return true;
}
bool read_single(char &ref) {
string s;
if (!read_single(s) || s.size() != 1) return false;
ref = s[0];
return true;
}
template <class T>
bool read_single(vector<T> &ref) {
for (auto &d: ref) {
if (!read_single(d)) return false;
}
return true;
}
template <class T, class U>
bool read_single(pair<T, U> &p) {
return (read_single(p.first) && read_single(p.second));
}
template <size_t N = 0, typename T>
void read_single_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
read_single(x);
read_single_tuple<N + 1>(t);
}
}
template <class... T>
bool read_single(tuple<T...> &tpl) {
read_single_tuple(tpl);
return true;
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
bool f = read_single(h);
assert(f);
read(t...);
}
Scanner(FILE *fp) : fp(fp) {}
};
struct Printer {
Printer(FILE *_fp) : fp(_fp) {}
~Printer() { flush(); }
static constexpr size_t SIZE = 1 << 15;
FILE *fp;
char line[SIZE], small[50];
size_t pos = 0;
void flush() {
fwrite(line, 1, pos, fp);
pos = 0;
}
void write(const char val) {
if (pos == SIZE) flush();
line[pos++] = val;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
void write(T val) {
if (pos > (1 << 15) - 50) flush();
if (val == 0) {
write('0');
return;
}
if (val < 0) {
write('-');
val = -val; // todo min
}
size_t len = 0;
while (val) {
small[len++] = char(0x30 | (val % 10));
val /= 10;
}
for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
pos += len;
}
void write(const string s) {
for (char c: s) write(c);
}
void write(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) write(s[i]);
}
void write(const double x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
void write(const long double x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
template <typename T,
typename enable_if<has_write<T>::value>::type * = nullptr>
inline void write(T x) {
x.write();
}
template <class T>
void write(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
template <class T, class U>
void write(const pair<T, U> val) {
write(val.first);
write(' ');
write(val.second);
}
template <size_t N = 0, typename T>
void write_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { write(' '); }
const auto x = std::get<N>(t);
write(x);
write_tuple<N + 1>(t);
}
}
template <class... T>
bool write(tuple<T...> tpl) {
write_tuple(tpl);
return true;
}
template <class T, size_t S>
void write(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
void write(i128 val) {
string s;
bool negative = 0;
if (val < 0) {
negative = 1;
val = -val;
}
while (val) {
s += '0' + int(val % 10);
val /= 10;
}
if (negative) s += "-";
reverse(all(s));
if (len(s) == 0) s = "0";
write(s);
}
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
printer.write(head);
if (sizeof...(Tail)) printer.write(' ');
print(forward<Tail>(tail)...);
}
void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
scanner.read(head);
read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __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/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/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(q));
}
return dat[n];
}
template <typename mint>
mint fact(int n) {
static const int mod = mint::get_mod();
assert(0 <= n);
if (n >= mod) return 0;
static vector<mint> dat = {1, 1};
while (len(dat) <= n) dat.eb(dat[len(dat) - 1] * mint(len(dat)));
return dat[n];
}
template <typename mint>
mint fact_inv(int n) {
static const int mod = mint::get_mod();
assert(-1 <= n && n < mod);
static vector<mint> dat = {1, 1};
if (n == -1) 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 (dense) return C_dense<mint>(n, k);
if (!large) return multinomial<mint>(n, k, n - k);
k = min(k, n - k);
mint x(1);
FOR(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_assert(mod < (1 << 30));
int val;
constexpr modint(const ll val = 0) noexcept
: val(val >= 0 ? val % mod : (mod - (-val) % mod) % mod) {}
bool operator<(const modint &other) const {
return val < other.val;
} // To use std::map
modint &operator+=(const modint &p) {
if ((val += p.val) >= mod) val -= mod;
return *this;
}
modint &operator-=(const modint &p) {
if ((val += mod - p.val) >= mod) val -= mod;
return *this;
}
modint &operator*=(const modint &p) {
val = (int)(1LL * val * p.val % mod);
return *this;
}
modint &operator/=(const modint &p) {
*this *= p.inverse();
return *this;
}
modint operator-() const { return modint(-val); }
modint operator+(const modint &p) const { return modint(*this) += p; }
modint operator-(const modint &p) const { return modint(*this) -= p; }
modint operator*(const modint &p) const { return modint(*this) *= p; }
modint operator/(const modint &p) const { return modint(*this) /= p; }
bool operator==(const modint &p) const { return val == p.val; }
bool operator!=(const modint &p) const { return val != p.val; }
modint inverse() const {
int a = val, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b), swap(u -= t * v, v);
}
return modint(u);
}
modint pow(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;
}
#ifdef FASTIO
void write() { fastio::printer.write(val); }
void read() { fastio::scanner.read(val); }
#endif
static constexpr int get_mod() { return mod; }
// (n, r), r は 1 の 2^n 乗根
static constexpr pair<int, int> ntt_info() {
if (mod == 167772161) return {25, 17};
if (mod == 469762049) return {26, 30};
if (mod == 754974721) return {24, 362};
if (mod == 880803841) return {23, 211};
if (mod == 998244353) return {23, 31};
if (mod == 1045430273) return {20, 363};
if (mod == 1051721729) return {20, 330};
if (mod == 1053818881) return {20, 2789};
return {-1, -1};
}
static constexpr bool can_ntt() { return ntt_info().fi != -1; }
};
using modint107 = modint<1000000007>;
using modint998 = modint<998244353>;
#line 3 "library/linalg/mat_mul.hpp"
template <class T, typename enable_if<has_mod<T>::value>::type* = nullptr>
vc<vc<T>> mat_mul(const vc<vc<T>>& A, const vc<vc<T>>& B) {
constexpr int mod = T::get_mod();
auto N = len(A), M = len(B), K = len(B[0]);
vv(int, b, K, M);
FOR(i, M) FOR(j, K) b[j][i] = B[i][j].val;
vv(T, C, N, K);
if (M <= 16) {
FOR(i, N) FOR(j, K) {
u64 sm = 0;
FOR(m, M) sm += u64(A[i][m].val) * b[j][m];
C[i][j] = sm % mod;
}
} else {
FOR(i, N) FOR(j, K) {
i128 sm = 0;
FOR(m, M) sm += ll(A[i][m].val) * b[j][m];
C[i][j] = sm % mod;
}
}
return C;
}
template <class T, typename enable_if<!has_mod<T>::value>::type* = nullptr>
vc<vc<T>> mat_mul(const vc<vc<T>>& A, const vc<vc<T>>& B) {
assert(!A.empty() && !B.empty());
auto N = len(A), M = len(B), K = len(B[0]);
vv(T, b, K, M);
FOR(i, M) FOR(j, K) b[j][i] = B[i][j];
vv(T, C, N, K);
FOR(n, N) FOR(m, M) FOR(k, K) C[n][k] += A[n][m] * b[k][m];
return C;
}
#line 1 "library/linalg/mat_inv.hpp"
// (det, invA) をかえす
template <typename T>
pair<T, vc<vc<T>>> mat_inv(vc<vc<T>> A) {
T det = 1;
int N = len(A);
vv(T, B, N, N);
FOR(n, N) B[n][n] = 1;
FOR(i, N) {
FOR(k, i, N) if (A[k][i] != 0) {
if (k != i) {
swap(A[i], A[k]), swap(B[i], B[k]);
det = -det;
}
break;
}
if (A[i][i] == 0) return {T(0), {}};
T c = T(1) / A[i][i];
det *= A[i][i];
FOR(j, i, N) A[i][j] *= c;
FOR(j, N) B[i][j] *= c;
FOR(k, N) if (i != k) {
T c = A[k][i];
FOR(j, i, N) A[k][j] -= A[i][j] * c;
FOR(j, N) B[k][j] -= B[i][j] * c;
}
}
return {det, B};
}
#line 1 "library/linalg/characteristic_poly.hpp"
template <typename T>
void to_Hessenberg_matrix(vc<vc<T>>& A) {
/*
P^{-1}AP の形の変換で、Hessenberg 行列に変形する。
特定多項式の計算に用いることができる。
*/
int n = len(A);
FOR(k, n - 2) {
FOR3(i, k + 1, n) if (A[i][k] != 0) {
if (i != k + 1) {
swap(A[i], A[k + 1]);
FOR(j, n) swap(A[j][i], A[j][k + 1]);
}
break;
}
if (A[k + 1][k] == 0) continue;
FOR3(i, k + 2, n) {
T c = A[i][k] / A[k + 1][k];
// i 行目 -= k+1 行目 * c
FOR(j, n) A[i][j] -= A[k + 1][j] * c;
// k+1 列目 += i 列目 * c
FOR(j, n) A[j][k + 1] += A[j][i] * c;
}
}
}
// det(xI-A)
template <typename T>
vc<T> characteristic_poly(vc<vc<T>> A) {
/*
・Hessenberg 行列に変形
・Hessenberg 行列の行列式は、最後の列で場合分けすれば dp できる
*/
int n = len(A);
to_Hessenberg_matrix(A);
vc<vc<T>> DP(n + 1);
DP[0] = {1};
FOR(k, n) {
DP[k + 1].resize(k + 2);
auto& dp = DP[k + 1];
// (k, k) 成分を使う場合
FOR(i, len(DP[k])) dp[i + 1] += DP[k][i];
FOR(i, len(DP[k])) dp[i] -= DP[k][i] * A[k][k];
// 下側対角の総積を管理
T prod = 1;
FOR_R(i, k) {
// (i, k) 成分を使う場合
prod *= A[i + 1][i];
T c = prod * A[i][k];
// DP[i] の c 倍を加算
FOR(j, len(DP[i])) dp[j] -= DP[i][j] * c;
}
}
return DP[n];
}
#line 2 "library/nt/primetable.hpp"
template <typename T = long long>
vc<T> primetable(int LIM) {
++LIM;
const int S = 32768;
static int done = 2;
static vc<T> primes = {2}, sieve(S + 1);
if (done < LIM) {
done = LIM;
primes = {2}, sieve.assign(S + 1, 0);
const int R = LIM / 2;
primes.reserve(int(LIM / log(LIM) * 1.1));
vc<pair<int, int>> cp;
for (int i = 3; i <= S; i += 2) {
if (!sieve[i]) {
cp.eb(i, i * i / 2);
for (int j = i * i; j <= S; j += 2 * i) sieve[j] = 1;
}
}
for (int L = 1; L <= R; L += S) {
array<bool, S> block{};
for (auto& [p, idx]: cp)
for (int i = idx; i < S + L; idx = (i += p)) block[i - L] = 1;
FOR(i, min(S, R - L)) if (!block[i]) primes.eb((L + i) * 2 + 1);
}
}
int k = LB(primes, LIM + 1);
return {primes.begin(), primes.begin() + k};
}
#line 3 "library/mod/powertable.hpp"
// a^0, ..., a^N
template <typename mint>
vc<mint> powertable_1(mint a, ll N) {
// table of a^i
vc<mint> f(N + 1, 1);
FOR(i, N) f[i + 1] = a * f[i];
return f;
}
// 0^e, ..., N^e
template <typename mint>
vc<mint> powertable_2(ll e, ll N) {
auto primes = primetable(N);
vc<mint> f(N + 1, 1);
f[0] = mint(0).pow(e);
for (auto&& p: primes) {
if (p > N) break;
mint xp = mint(p).pow(e);
ll pp = p;
while (pp <= N) {
ll i = pp;
while (i <= N) {
f[i] *= xp;
i += pp;
}
pp *= p;
}
}
return f;
}
#line 2 "library/mod/mod_inv.hpp"
// long でも大丈夫
ll mod_inv(ll val, ll 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 1 "library/poly/convolution_naive.hpp"
template <class T>
vector<T> convolution_naive(const vector<T>& a, const vector<T>& b) {
int n = int(a.size()), m = int(b.size());
vector<T> ans(n + m - 1);
if (n < m) {
FOR(j, m) FOR(i, n) ans[i + j] += a[i] * b[j];
} else {
FOR(i, n) FOR(j, m) ans[i + j] += a[i] * b[j];
}
return ans;
}
#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;
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 7 "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 const long long nttprimes[] = {754974721, 167772161, 469762049};
using mint0 = modint<754974721>;
using mint1 = modint<167772161>;
using mint2 = modint<469762049>;
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);
static const long long m01 = 1LL * nttprimes[0] * nttprimes[1];
static const long long m0_inv_m1 = mint1(nttprimes[0]).inverse().val;
static const long long m01_inv_m2 = mint2(m01).inverse().val;
const int mod = mint::get_mod();
auto garner = [&](mint0 x0, mint1 x1, mint2 x2) -> mint {
int r0 = x0.val, r1 = x1.val, r2 = x2.val;
int v1 = (m0_inv_m1 * (r1 + nttprimes[1] - r0)) % nttprimes[1];
auto v2 = (mint2(r2) - r0 - mint2(nttprimes[0]) * v1) * mint2(m01_inv_m2);
return mint(r0 + 1LL * nttprimes[0] * v1 + m01 % mod * v2.val);
};
vc<mint> c(len(c0));
FOR(i, len(c)) c[i] = garner(c0[i], c1[i], c2[i]);
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++) {
int x = (i < (int)a.size() ? a[i] : 0);
int y = (i < (int)b.size() ? b[i] : 0);
fa[i] = C(x, y);
}
CFFT::fft(fa, sz);
C r(0, -0.25 / (sz >> 1)), s(0, 1), t(0.5, 0);
for (int i = 0; i <= (sz >> 1); i++) {
int j = (sz - i) & (sz - 1);
C z = (fa[j] * fa[j] - (fa[i] * fa[i]).conj()) * r;
fa[j] = (fa[i] * fa[i] - (fa[j] * fa[j]).conj()) * r;
fa[i] = z;
}
for (int i = 0; i < (sz >> 1); i++) {
C A0 = (fa[i] + fa[i + (sz >> 1)]) * t;
C A1 = (fa[i] - fa[i + (sz >> 1)]) * t * CFFT::rts[(sz >> 1) + i];
fa[i] = A0 + A1 * s;
}
CFFT::fft(fa, sz >> 1);
vector<double> ret(need);
for (int i = 0; i < need; i++) {
ret[i] = (i & 1 ? fa[i >> 1].y : fa[i >> 1].x);
}
return ret;
}
vector<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) <= 60) 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, n) 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_naive(a, b);
return convolution_ntt(a, b);
}
if (min(n, m) <= 200) return convolution_naive(a, b);
return convolution_garner(a, b);
}
#line 3 "library/poly/poly_taylor_shift.hpp"
// f(x) -> f(x+c)
template <typename mint>
vc<mint> poly_taylor_shift(vc<mint> f, mint c) {
ll N = len(f);
FOR(i, N) f[i] *= fact<mint>(i);
auto b = powertable_1<mint>(c, N);
FOR(i, N) b[i] *= fact_inv<mint>(i);
reverse(all(f));
f = convolution(f, b);
f.resize(N);
reverse(all(f));
FOR(i, N) f[i] *= fact_inv<mint>(i);
return f;
}
#line 6 "library/linalg/det_A_plus_xB.hpp"
// det(A + xB) = f(x) となる N 次多項式 f を返す
// 確率 N / mod で正しく解ける(乱数に依存しない方法もあるようだ)
template <typename mint>
vc<mint> det_A_plus_xB(vvc<mint> A, vvc<mint> B) {
int N = len(A);
vc<mint> f(N + 1);
mint a = RNG(mint::get_mod());
FOR(i, N) FOR(j, N) A[i][j] += a * B[i][j];
auto [det_A, inv_A] = mat_inv(A);
if (det_A == 0) { return f; }
B = mat_mul(B, inv_A);
FOR(i, N) FOR(j, N) B[i][j] = -B[i][j];
f = characteristic_poly(B);
reverse(all(f));
for (auto&& x: f) x *= det_A;
f = poly_taylor_shift(f, -a);
return f;
}
#line 6 "main.cpp"
using mint = modint998;
void test() {
ll LIM = 18;
auto check = [&](vc<int> B) -> bool {
int K = len(B);
vv(mint, X, K + 1, K + 1);
vv(mint, Y, K + 1, K + 1);
FOR(i, K) X[i + 1][i] = mint(1), X[i][i + 1] = B[i];
FOR(i, K + 1) Y[i][i] = mint(1);
vc<mint> f = det_A_plus_xB<mint>(X, Y);
for (auto&& v: f) {
if (v == mint(1) || v == mint(0) || v == mint(-1)) continue;
return 0;
}
return 1;
};
vvvc<int> dp(LIM);
dp[0].eb(vc<int>());
FOR(K, 1, LIM) {
for (auto B: dp[K - 1]) {
B.eb(-1);
if (check(B)) dp[K].eb(B);
B.back() = 1;
if (check(B)) dp[K].eb(B);
}
}
FOR(K, 1, LIM) {
print("cnt", K, len(dp[K]));
for (auto&& x: dp[K]) {
string S;
for (auto&& v: x) { S += (v > 0 ? '+' : '-'); }
print(S);
}
print();
}
}
void solve() {
LL(N);
VEC(int, A, N);
vc<int> B = {0, 1};
int nxt = 2;
while (len(B) < N) {
vc<int> C;
C.insert(C.end(), all(B));
C.eb(nxt++);
C.eb(nxt++);
reverse(all(B));
C.insert(C.end(), all(B));
swap(B, C);
}
int n = nxt;
B.resize(N);
vc<int> X(n), Y(n);
FOR(i, N) {
if (A[i] == 1) X[B[i]]++;
if (A[i] == -1) Y[B[i]]++;
}
ll ANS = 0;
FOR(i, n / 2) {
int a = X[2 * i + 0] + Y[2 * i + 1];
int b = X[2 * i + 1] + Y[2 * i + 0];
ANS += min(a, b);
}
print(ANS);
}
signed main() {
INT(T);
FOR(T) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3648kb
input:
3 4 1 1 1 1 2 1 -1 5 -1 1 1 1 -1
output:
2 0 2
result:
ok 3 number(s): "2 0 2"
Test #2:
score: 0
Accepted
time: 5ms
memory: 4424kb
input:
3 27354 -1 -1 1 -1 1 1 1 1 -1 -1 1 1 -1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 -1 -1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 -1 1 -1 1 -1 1 1 -1 1 1 1 -1 1 1 1 1 -1 -1 -1 -1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 1 1 -1 1 1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 1 1 1 -1 -1 -1 1 1 1 -1 1 -1 -1 -1 ...
output:
13567 27879 7121
result:
ok 3 number(s): "13567 27879 7121"
Test #3:
score: 0
Accepted
time: 4ms
memory: 4336kb
input:
3 27970 1 -1 1 -1 -1 -1 1 1 1 -1 -1 1 -1 -1 1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 1 1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 1 -1 1 1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 -1...
output:
2767 80 6378
result:
ok 3 number(s): "2767 80 6378"
Test #4:
score: 0
Accepted
time: 4ms
memory: 4036kb
input:
3 36019 -1 1 -1 1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 1 -1 1 -1 1 1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 1 1 1 1 1 -1 -1 1 -1 1 1 1 -1 1 -1 1 1 -1 1 1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 1 -1 1 -1 1 -1 1 -1 -1 1 1 -1 -1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 -1 -1 1 -1 -1 1 1 1 ...
output:
7231 6152 5290
result:
ok 3 number(s): "7231 6152 5290"
Test #5:
score: 0
Accepted
time: 0ms
memory: 4064kb
input:
9 20499 -1 -1 1 1 -1 1 1 1 1 -1 1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 1 1 1 1 -1 1 -1 1 -1 -1 1 1 -1 -1 1 -1 -1 -1 -1 1 -1 1 -1 1 1 -1 -1 1 -1 -1 1 1 1 1 1 -1 1 -1 -1 -1 1 1 -1 -1 -1 -1 1 1 -1 1 1 1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 -1 1 -1 -1 1 1 -1 1 1 1 1 -1 -1 1 -1 -1 -1 1 1 1 1 -1 1 1 -1 -1 -1 1 1 1 1 1 -1 -...
output:
6093 6901 2328 11469 915 87 6 1331 86
result:
ok 9 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 4656kb
input:
2 94689 1 1 -1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 1 1 -1 -1 1 -1 1 -1 1 1 1 -1 1 -1 1 -1 -1 -1 -1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 -1 1 -1 -1 1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 -1 -1 -1 1 1 -1 -1 -1 1 -1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 -1 1 1 -1 1 1 -1 -1 -1 -1 1 -1 1 1 -1 -1 1 -1 ...
output:
37779 587
result:
ok 2 number(s): "37779 587"
Test #7:
score: 0
Accepted
time: 5ms
memory: 4612kb
input:
4 90533 -1 -1 1 -1 1 1 1 -1 1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 -1 1 1 -1 1 1 -1 1 1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 1 1 1 -1 -1 -1 -1 1 1 1 -1 1 1 -1 -1 1 -1 -1 1 -1 1 1 -1 1 1 -1 -1 -1 1 1 1 -1 1 -1 1 -1 -1 -1 1 -1 1 -1 1 -1 -1 -1 1 -1 1 -1 -1 1 1 1 1 1 -1 1 -1 1 -1 1...
output:
36192 516 2233 928
result:
ok 4 number(s): "36192 516 2233 928"
Test #8:
score: 0
Accepted
time: 3ms
memory: 4572kb
input:
2 74465 1 -1 1 1 -1 1 -1 -1 -1 -1 -1 1 1 1 1 -1 1 -1 1 -1 1 1 1 1 1 -1 -1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 1 1 1 1 -1 1 1 1 1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 -1 -1 1 -1 -1 -1 -1 -1 -1 1 1 1 -1 1 -1 -1 1 -1 1 -1 1 -1 -1 -1 1 -1 -1 1 -1 -1 -1 1 1 -1 1 -1 -1 -1 1 1 1 1 1 1 1 1 -1 1 1 1 1 -1 1 -1 -1 1...
output:
22551 7372
result:
ok 2 number(s): "22551 7372"
Test #9:
score: 0
Accepted
time: 3ms
memory: 4112kb
input:
5 41709 -1 1 1 -1 1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 -1 -1 1 1 -1 1 -1 1 1 1 -1 1 1 -1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 1 1 -1 1 1 1 1 1 1 -1 1 1 -1 -1 -1 -1 -1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 -1 -1 1...
output:
8311 8174 2118 148 552
result:
ok 5 number(s): "8311 8174 2118 148 552"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
5 47359 -1 1 1 -1 1 -1 -1 -1 1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 -1 -1 1 -1 -1 1 1 1 1 -1 1 -1 1 1 1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 -1 -1 1 1 -1 1 1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 1 1 1 -1 1 -1 1 1 -1 -1 1 -1 1 1 1 1 -1 1 -1 -1 1 -1 1 1 1 1 -1 -1 1 1 -1 1 -1 -1 ...
output:
4819 2783 44 287 1764
result:
ok 5 number(s): "4819 2783 44 287 1764"
Test #11:
score: 0
Accepted
time: 6ms
memory: 4620kb
input:
1 100000 -1 -1 -1 1 -1 -1 1 1 1 -1 1 1 -1 1 -1 -1 -1 1 -1 1 -1 -1 1 1 1 1 1 1 1 -1 -1 1 1 1 -1 1 1 1 -1 1 1 1 -1 1 -1 -1 -1 1 -1 -1 -1 -1 1 1 -1 -1 -1 1 1 1 1 -1 -1 1 1 -1 1 1 1 1 1 -1 -1 -1 1 1 -1 1 1 -1 1 1 -1 -1 -1 -1 -1 1 -1 1 1 -1 -1 1 1 1 1 -1 -1 -1 -1 1 -1 1 -1 1 1 1 -1 -1 -1 1 -1 1 -1 1 1 -1...
output:
49773
result:
ok 1 number(s): "49773"
Test #12:
score: 0
Accepted
time: 1ms
memory: 4676kb
input:
1 100000 1 1 -1 -1 1 -1 -1 -1 1 1 1 -1 1 -1 1 1 -1 1 -1 1 1 1 -1 -1 -1 1 -1 1 1 1 -1 -1 -1 -1 1 1 1 -1 -1 1 1 1 1 -1 -1 -1 1 1 -1 1 -1 1 1 1 1 -1 1 1 -1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 1 1 -1 1 1 -1 -1 -1 1 1 -1 1 1 1 1 -1 1 -1 -1 1 1 1 1 -1 -1 -1 -1 1 1 -1 1 -1 1 1 1 1 1 -1 1 -1 -1 -1 -1 -1 -1 1 1 1 -1...
output:
30144
result:
ok 1 number(s): "30144"
Test #13:
score: 0
Accepted
time: 0ms
memory: 4788kb
input:
1 100000 -1 1 1 -1 -1 1 1 1 1 1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 1 1 -1 1 1 -1 1 1 -1 1 1 -1 1 1 -1 1 1 1 -1 1 1 -1 -1 -1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 -1 1 1 -1 1 1 1 -1 -1 -1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 -1 -1 -1 1 -1 -1 -1 1 -1 1 -1 -1 1 -1 -1 1 ...
output:
40103
result:
ok 1 number(s): "40103"
Test #14:
score: 0
Accepted
time: 5ms
memory: 4796kb
input:
1 100000 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 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 1 1 -1 -1 1 -1 1 1 -1 7 1 -1 -1 1 -1 1 1 8 -1 1 -1 1 1 -1 1 -1 7 -1 1 1 -1 1 -1 1 9 -1 1 -1 1 1 -1 1 -1 -1 7 1 -1 -1 1 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 9595 numbers
Test #28:
score: 0
Accepted
time: 2ms
memory: 3628kb
input:
100 42 1 -1 1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 1 -1 -1 -1 -1 1 1 1 -1 -1 -1 1 1 1 -1 -1 -1 -1 1 1 1 -1 -1 1 -1 1 1 1 1 31 -1 1 1 1 -1 -1 -1 1 -1 1 1 1 1 1 1 -1 -1 1 1 -1 1 1 -1 -1 1 -1 -1 -1 -1 -1 -1 35 1 1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 1 1 1 1 1 1 -1 -1 -1 -1 1 1 1 1 1 1 -1 -1 1 1 1 1 1 45 -1 -1 -1 -1 1 ...
output:
20 10 16 18 32 28 32 9 8 20 22 25 22 20 15 10 36 20 21 32 34 20 2 16 33 2 18 4 11 11 24 19 23 4 10 6 12 37 41 4 22 29 19 32 33 18 26 16 33 11 38 6 26 1 34 24 2 18 36 41 33 35 20 36 3 20 30 11 40 20 11 14 5 10 6 2 0 6 16 4 13 28 22 16 28 15 44 5 30 21 29 17 31 4 10 14 10 4 29 1
result:
ok 100 numbers
Test #29:
score: 0
Accepted
time: 2ms
memory: 3488kb
input:
100 34 -1 1 -1 1 -1 -1 1 1 -1 1 1 1 1 -1 1 1 -1 1 -1 1 1 -1 -1 -1 1 1 1 1 -1 -1 1 -1 -1 1 74 1 1 1 -1 1 1 1 -1 1 1 -1 1 1 -1 1 -1 -1 1 1 1 1 -1 -1 1 -1 1 -1 -1 -1 1 -1 1 -1 -1 1 -1 -1 -1 1 1 1 1 -1 1 -1 1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 54 1 1 -1 -1 -1 1 1 ...
output:
8 20 14 13 13 20 26 21 1 8 6 31 24 8 18 39 1 5 9 29 6 15 7 25 7 0 17 29 3 25 36 29 14 10 16 23 9 31 31 27 28 5 17 13 7 25 11 4 1 34 15 20 23 12 11 3 4 9 20 2 20 9 14 31 10 10 1 30 20 30 11 2 17 21 1 12 2 16 6 13 22 23 7 29 39 8 19 1 13 29 24 10 4 19 20 26 12 12 12 2
result:
ok 100 numbers
Test #30:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
100 46 1 1 -1 -1 1 1 1 1 -1 -1 -1 -1 1 -1 1 -1 1 1 -1 -1 1 -1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 -1 1 1 1 -1 1 -1 -1 -1 -1 1 60 -1 1 1 1 1 1 -1 -1 1 1 -1 -1 1 -1 -1 1 -1 1 1 1 1 -1 1 1 -1 1 1 -1 1 -1 -1 -1 -1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 1 -1 -1 1 1 1 1 1 -1 1 -1 -1 1 1 40 1 1 -1 -1 -1 1 -1 1 1 -1...
output:
15 13 11 15 19 7 1 20 4 9 18 22 5 5 11 21 35 21 21 20 8 40 15 27 2 19 18 11 2 5 23 10 0 7 26 3 3 24 19 8 2 3 11 24 11 33 23 10 0 20 12 8 8 34 26 1 17 8 11 8 17 14 21 18 28 22 6 7 14 17 26 5 22 23 16 14 23 12 19 8 22 14 3 30 25 3 9 25 16 16 0 33 15 5 21 14 14 6 9 5
result:
ok 100 numbers
Test #31:
score: 0
Accepted
time: 2ms
memory: 3476kb
input:
100 55 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 -1 94 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 100 numbers
Test #32:
score: 0
Accepted
time: 2ms
memory: 3644kb
input:
413 254 -1 1 -1 -1 1 1 1 1 1 -1 1 -1 1 1 -1 1 -1 1 1 1 1 1 1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 -1 1 -1 1 1 1 1 1 1 1 -1 -1 -1 1 -1 1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 1 1 -1 -1 1 1 1 -1 1 1 -1 -1 -1 -1 1 -1 -1 1 1 -1 1 -1 -1 -1 1 -1 1 -1 -1 1 1 1 -1 1 1 -1 -1 -1 -1 1 1 1 -1 -1 -1 1 -1 -1 -...
output:
120 174 202 184 52 70 186 44 191 164 4 140 53 180 199 91 118 41 157 176 193 185 209 116 59 83 201 67 38 32 133 133 220 165 30 47 84 146 219 97 228 145 19 86 115 47 54 26 62 54 1 219 144 2 18 56 88 90 110 129 112 64 72 7 120 19 17 119 0 209 86 1 89 106 150 41 17 80 34 72 81 178 20 30 41 17 154 10 107...
result:
ok 413 numbers
Test #33:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
400 43 1 1 -1 -1 -1 -1 -1 1 1 1 1 1 1 -1 1 -1 -1 -1 1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 -1 -1 1 -1 1 -1 -1 -1 1 -1 1 1 241 1 -1 1 1 -1 1 1 1 -1 1 1 1 -1 -1 1 1 1 -1 -1 1 1 -1 -1 -1 1 1 1 1 -1 1 1 -1 1 -1 -1 1 1 -1 -1 1 1 -1 -1 -1 -1 1 -1 1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 -1 -1 -1 -1 1 ...
output:
11 79 118 118 122 120 33 127 133 66 114 46 125 111 130 26 27 94 112 64 97 113 13 41 81 13 30 25 151 112 15 86 74 156 18 32 54 118 7 95 80 91 129 9 43 133 125 44 21 69 139 100 50 21 79 95 79 39 78 51 7 16 70 97 20 9 57 129 94 30 15 109 48 80 65 6 37 77 59 136 79 87 37 110 90 41 117 42 116 101 79 100 ...
result:
ok 400 numbers
Test #34:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
395 2 1 -1 123 1 -1 -1 1 -1 1 1 1 1 -1 1 1 1 -1 -1 1 1 1 -1 -1 1 1 1 1 1 1 1 -1 -1 1 1 1 -1 -1 1 1 -1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 1 1 1 -1 1 -1 1 -1 -1 -1 1 -1 -1 1 1 1 1 1 1 -1 1 -1 1 -1 -1 1 -1 1 -1 1 -1 1 -1 1 1 1 1 1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 -1 1 -1 1 1 -1 -1 1 1 -1 1 -1 -1 1 -...
output:
0 34 111 126 136 33 80 127 111 52 136 83 105 156 74 39 72 0 82 101 21 133 31 123 143 30 133 115 2 104 9 104 17 119 25 139 21 98 55 2 97 86 130 51 40 76 89 17 29 90 37 78 89 131 102 20 57 87 55 93 80 9 103 133 91 77 77 14 10 9 132 72 151 6 104 96 26 35 107 80 57 153 157 37 67 11 130 70 97 45 100 56 1...
result:
ok 395 numbers
Test #35:
score: 0
Accepted
time: 4ms
memory: 3728kb
input:
415 156 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 415 numbers
Test #36:
score: 0
Accepted
time: 2ms
memory: 3516kb
input:
10 180 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 ...
output:
0 0 0 0 0 0 0 0 0 0
result:
ok 10 numbers
Test #37:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
207 941 -1 1 1 1 1 1 1 -1 1 1 -1 -1 1 1 1 -1 1 -1 1 1 1 1 1 1 1 -1 1 1 1 1 1 -1 -1 -1 1 1 1 -1 1 1 1 -1 -1 -1 -1 -1 1 -1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 -1 1 -1 1 -1 1 -1 -1 -1 1 -1 -1 -1 1 1 -1 -1 1 1 1 1 1 -1 1 1 -1 -1 1 -1 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 -1 -1 1 ...
output:
441 409 147 227 67 208 47 76 176 376 150 296 51 359 206 47 5 2 18 397 86 290 329 342 223 291 0 96 221 180 169 97 6 155 385 135 356 77 100 108 89 141 297 60 149 439 117 426 346 74 258 167 272 201 222 264 364 114 387 313 187 17 438 33 221 112 451 80 377 456 369 26 81 357 208 264 157 142 214 13 28 393 ...
result:
ok 207 numbers
Test #38:
score: 0
Accepted
time: 4ms
memory: 3556kb
input:
208 214 1 -1 -1 1 -1 1 1 1 1 1 -1 -1 -1 -1 1 1 1 -1 -1 -1 1 -1 1 -1 1 1 1 -1 -1 1 -1 1 1 1 -1 1 1 1 1 -1 1 -1 1 1 1 -1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 1 -1 1 1 -1 1 -1 -1 -1 1 1 1 1 -1 -1 -1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 1 1 -1 1 1 -1 -1 -1 -1 1 -1 1 1 1 1 1 -1 1 -1 1 -1 -1 1 -1 1 -1 1 1 1 -1 1 1 -1 1 -1 ...
output:
78 100 208 39 318 42 107 65 46 285 134 96 146 217 49 297 163 268 59 226 114 219 281 122 206 232 3 104 136 155 0 109 145 262 241 120 240 220 11 48 292 126 280 216 42 24 76 278 290 88 238 264 301 38 184 12 23 137 31 74 260 34 112 283 146 184 109 83 130 227 5 265 170 119 300 70 200 107 143 56 23 30 217...
result:
ok 208 numbers
Test #39:
score: 0
Accepted
time: 5ms
memory: 3568kb
input:
200 101 -1 1 -1 1 1 -1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 -1 -1 1 1 -1 1 1 -1 1 -1 -1 1 1 1 -1 -1 1 -1 -1 -1 -1 1 -1 1 1 -1 -1 1 -1 -1 1 1 -1 -1 1 -1 1 1 -1 -1 -1 -1 1 -1 -1 -1 1 1 1 1 1 -1 1 1 -1 -1 -1 1 -1 1 -1 1 -1 1 -1 -1 -1 -1 1 -1 296 1 -1 1 1 1 -1 -1 -1 -1 1 1 1 1 ...
output:
29 100 59 269 244 171 158 108 72 313 251 103 95 304 108 150 125 142 203 201 234 246 172 48 122 117 43 45 89 171 128 222 128 73 19 35 110 57 218 25 271 25 188 295 304 84 247 164 1 35 98 84 251 111 11 98 205 162 213 113 177 159 120 40 299 80 160 45 226 224 275 165 274 61 174 14 207 198 280 5 175 93 99...
result:
ok 200 numbers
Test #40:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
196 12 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 893 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 1 -1...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 196 numbers