QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187750 | #4910. Numbers | hos_lyric | 100 ✓ | 1345ms | 40484kb | C++14 | 18.6kb | 2023-09-24 21:40:27 | 2023-09-24 21:40:28 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// M: prime, G: primitive root, 2^K | M - 1
template <unsigned M_, unsigned G_, int K_> struct Fft {
static_assert(2U <= M_, "Fft: 2 <= M must hold.");
static_assert(M_ < 1U << 30, "Fft: M < 2^30 must hold.");
static_assert(1 <= K_, "Fft: 1 <= K must hold.");
static_assert(K_ < 30, "Fft: K < 30 must hold.");
static_assert(!((M_ - 1U) & ((1U << K_) - 1U)), "Fft: 2^K | M - 1 must hold.");
static constexpr unsigned M = M_;
static constexpr unsigned M2 = 2U * M_;
static constexpr unsigned G = G_;
static constexpr int K = K_;
ModInt<M> FFT_ROOTS[K + 1], INV_FFT_ROOTS[K + 1];
ModInt<M> FFT_RATIOS[K], INV_FFT_RATIOS[K];
Fft() {
const ModInt<M> g(G);
for (int k = 0; k <= K; ++k) {
FFT_ROOTS[k] = g.pow((M - 1U) >> k);
INV_FFT_ROOTS[k] = FFT_ROOTS[k].inv();
}
for (int k = 0; k <= K - 2; ++k) {
FFT_RATIOS[k] = -g.pow(3U * ((M - 1U) >> (k + 2)));
INV_FFT_RATIOS[k] = FFT_RATIOS[k].inv();
}
assert(FFT_ROOTS[1] == M - 1U);
}
// as[rev(i)] <- \sum_j \zeta^(ij) as[j]
void fft(ModInt<M> *as, int n) const {
assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << K);
int m = n;
if (m >>= 1) {
for (int i = 0; i < m; ++i) {
const unsigned x = as[i + m].x; // < M
as[i + m].x = as[i].x + M - x; // < 2 M
as[i].x += x; // < 2 M
}
}
if (m >>= 1) {
ModInt<M> prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < M
as[i + m].x = as[i].x + M - x; // < 3 M
as[i].x += x; // < 3 M
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
for (; m; ) {
if (m >>= 1) {
ModInt<M> prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < M
as[i + m].x = as[i].x + M - x; // < 4 M
as[i].x += x; // < 4 M
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
if (m >>= 1) {
ModInt<M> prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < M
as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x; // < 2 M
as[i + m].x = as[i].x + M - x; // < 3 M
as[i].x += x; // < 3 M
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
}
for (int i = 0; i < n; ++i) {
as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x; // < 2 M
as[i].x = (as[i].x >= M) ? (as[i].x - M) : as[i].x; // < M
}
}
// as[i] <- (1/n) \sum_j \zeta^(-ij) as[rev(j)]
void invFft(ModInt<M> *as, int n) const {
assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << K);
int m = 1;
if (m < n >> 1) {
ModInt<M> prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned long long y = as[i].x + M - as[i + m].x; // < 2 M
as[i].x += as[i + m].x; // < 2 M
as[i + m].x = (prod.x * y) % M; // < M
}
prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
}
m <<= 1;
}
for (; m < n >> 1; m <<= 1) {
ModInt<M> prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + (m >> 1); ++i) {
const unsigned long long y = as[i].x + M2 - as[i + m].x; // < 4 M
as[i].x += as[i + m].x; // < 4 M
as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x; // < 2 M
as[i + m].x = (prod.x * y) % M; // < M
}
for (int i = i0 + (m >> 1); i < i0 + m; ++i) {
const unsigned long long y = as[i].x + M - as[i + m].x; // < 2 M
as[i].x += as[i + m].x; // < 2 M
as[i + m].x = (prod.x * y) % M; // < M
}
prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
}
}
if (m < n) {
for (int i = 0; i < m; ++i) {
const unsigned y = as[i].x + M2 - as[i + m].x; // < 4 M
as[i].x += as[i + m].x; // < 4 M
as[i + m].x = y; // < 4 M
}
}
const ModInt<M> invN = ModInt<M>(n).inv();
for (int i = 0; i < n; ++i) {
as[i] *= invN;
}
}
void fft(vector<ModInt<M>> &as) const {
fft(as.data(), as.size());
}
void invFft(vector<ModInt<M>> &as) const {
invFft(as.data(), as.size());
}
vector<ModInt<M>> convolve(vector<ModInt<M>> as, vector<ModInt<M>> bs) const {
if (as.empty() || bs.empty()) return {};
const int len = as.size() + bs.size() - 1;
int n = 1;
for (; n < len; n <<= 1) {}
as.resize(n); fft(as);
bs.resize(n); fft(bs);
for (int i = 0; i < n; ++i) as[i] *= bs[i];
invFft(as);
as.resize(len);
return as;
}
vector<ModInt<M>> square(vector<ModInt<M>> as) const {
if (as.empty()) return {};
const int len = as.size() + as.size() - 1;
int n = 1;
for (; n < len; n <<= 1) {}
as.resize(n); fft(as);
for (int i = 0; i < n; ++i) as[i] *= as[i];
invFft(as);
as.resize(len);
return as;
}
};
// M0 M1 M2 = 789204840662082423367925761 (> 7.892 * 10^26, > 2^89)
// M0 M3 M4 M5 M6 = 797766583174034668024539679147517452591562753 (> 7.977 * 10^44, > 2^149)
const Fft<998244353U, 3U, 23> FFT0;
const Fft<897581057U, 3U, 23> FFT1;
const Fft<880803841U, 26U, 23> FFT2;
const Fft<985661441U, 3U, 22> FFT3;
const Fft<943718401U, 7U, 22> FFT4;
const Fft<935329793U, 3U, 22> FFT5;
const Fft<918552577U, 5U, 22> FFT6;
// T = unsigned, unsigned long long, ModInt<M>
template <class T, unsigned M0, unsigned M1, unsigned M2>
T garner(ModInt<M0> a0, ModInt<M1> a1, ModInt<M2> a2) {
static const ModInt<M1> INV_M0_M1 = ModInt<M1>(M0).inv();
static const ModInt<M2> INV_M0M1_M2 = (ModInt<M2>(M0) * M1).inv();
const ModInt<M1> b1 = INV_M0_M1 * (a1 - a0.x);
const ModInt<M2> b2 = INV_M0M1_M2 * (a2 - (ModInt<M2>(b1.x) * M0 + a0.x));
return (T(b2.x) * M1 + b1.x) * M0 + a0.x;
}
template <class T, unsigned M0, unsigned M1, unsigned M2, unsigned M3, unsigned M4>
T garner(ModInt<M0> a0, ModInt<M1> a1, ModInt<M2> a2, ModInt<M3> a3, ModInt<M4> a4) {
static const ModInt<M1> INV_M0_M1 = ModInt<M1>(M0).inv();
static const ModInt<M2> INV_M0M1_M2 = (ModInt<M2>(M0) * M1).inv();
static const ModInt<M3> INV_M0M1M2_M3 = (ModInt<M3>(M0) * M1 * M2).inv();
static const ModInt<M4> INV_M0M1M2M3_M4 = (ModInt<M4>(M0) * M1 * M2 * M3).inv();
const ModInt<M1> b1 = INV_M0_M1 * (a1 - a0.x);
const ModInt<M2> b2 = INV_M0M1_M2 * (a2 - (ModInt<M2>(b1.x) * M0 + a0.x));
const ModInt<M3> b3 = INV_M0M1M2_M3 * (a3 - ((ModInt<M3>(b2.x) * M1 + b1.x) * M0 + a0.x));
const ModInt<M4> b4 = INV_M0M1M2M3_M4 * (a4 - (((ModInt<M4>(b3.x) * M2 + b2.x) * M1 + b1.x) * M0 + a0.x));
return (((T(b4.x) * M3 + b3.x) * M2 + b2.x) * M1 + b1.x) * M0 + a0.x;
}
#define ModInt ModIntR
////////////////////////////////////////////////////////////////////////////////
// Barrett
struct ModInt {
static unsigned M;
static unsigned long long NEG_INV_M;
static void setM(unsigned long long m) { M = m; NEG_INV_M = -1ULL / M; }
unsigned x;
ModInt() : x(0U) {}
ModInt(unsigned x_) : x(x_ % M) {}
ModInt(unsigned long long x_) : x(x_ % M) {}
ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) {
const unsigned long long y = static_cast<unsigned long long>(x) * a.x;
const unsigned long long q = static_cast<unsigned long long>((static_cast<unsigned __int128>(NEG_INV_M) * y) >> 64);
const unsigned long long r = y - M * q;
x = r - M * (r >= M);
return *this;
}
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
unsigned ModInt::M;
unsigned long long ModInt::NEG_INV_M;
// !!!Use ModInt::setM!!!
////////////////////////////////////////////////////////////////////////////////
using Mint = ModInt;
#undef ModInt
vector<Mint> convolve(const vector<Mint> &as, const vector<Mint> &bs) {
static constexpr unsigned M0 = decltype(FFT0)::M;
static constexpr unsigned M1 = decltype(FFT1)::M;
static constexpr unsigned M2 = decltype(FFT2)::M;
if (as.empty() || bs.empty()) return {};
const int asLen = as.size(), bsLen = bs.size();
vector<ModInt<M0>> as0(asLen), bs0(bsLen);
for (int i = 0; i < asLen; ++i) as0[i] = as[i].x;
for (int i = 0; i < bsLen; ++i) bs0[i] = bs[i].x;
const vector<ModInt<M0>> cs0 = FFT0.convolve(as0, bs0);
vector<ModInt<M1>> as1(asLen), bs1(bsLen);
for (int i = 0; i < asLen; ++i) as1[i] = as[i].x;
for (int i = 0; i < bsLen; ++i) bs1[i] = bs[i].x;
const vector<ModInt<M1>> cs1 = FFT1.convolve(as1, bs1);
vector<ModInt<M2>> as2(asLen), bs2(bsLen);
for (int i = 0; i < asLen; ++i) as2[i] = as[i].x;
for (int i = 0; i < bsLen; ++i) bs2[i] = bs[i].x;
const vector<ModInt<M2>> cs2 = FFT2.convolve(as2, bs2);
vector<Mint> cs(asLen + bsLen - 1);
for (int i = 0; i < asLen + bsLen - 1; ++i) {
cs[i] = garner<Mint>(cs0[i], cs1[i], cs2[i]);
}
return cs;
}
/*
fix t != 0
F[u] := Pr[u -> t]
F[0] = 0
F[t] = 1
F[u] = \sum[i] P[i] F[u+e[i]] (u != 0, t)
F(x) = \sum[u] F[u] x^u
= x^t + \sum[u!=0,t] F[u] x^u
= x^t + \sum[u!=0,t] \sum[i] P[i] F[u+e[i]] x^u
= x^t + \sum[v] \sum[i] P[i] F[v] x^(v-e[i]) - \sum[i] P[i] F[e[i]] - \sum[i] P[i] F[t+e[i]] x^t
=: G(x) F(x) + a + b x^t
G(x) = \sum[i] P[i] x^(-i)
Pr[start -> t] = -a
F(1) = G(1) F(1) + a + b
G(1) = 1
b = -a
(1 - G(x)) F(x) = a (x^0 - x^t)
w: vector of roots of unity
H(w) = 1 - w^t
F(w) = (1 - w^t) / (1 - G(w)) (w != 1)
F(1) = -\sum[w!=1] F(w)
F[t] = (1/M) (F(1) + \sum[w!=1] w^-t F(w))
= (1/M) \sum[w!=1] (w^(-t) - 2 + w^t) / (1 - G(w))
*/
int N, MO, I;
vector<int> L;
vector<Mint> P, D;
int M;
vector<int> LL;
// without 1/n
namespace dft1 {
constexpr int THR_N = 64;
int n;
Mint ww[THR_N][THR_N];
vector<Mint> w1s, w2s, invW1s, invW2s;
void build(int n_, Mint w, bool inv) {
n = n_;
if (inv) w = w.inv();
if (n < THR_N) {
Mint wi = 1;
for (int i = 0; i < n; ++i) {
ww[i][0] = 1;
for (int j = 1; j < n; ++j) {
ww[i][j] = ww[i][j - 1] * wi;
}
wi *= w;
}
} else {
const Mint invW = w.inv();
w1s.resize(2 * n - 1);
w2s.resize(2 * n - 1);
invW1s.resize(2 * n - 1);
invW2s.resize(2 * n - 1);
w1s[0] = w2s[0] = invW1s[0] = invW2s[0] = 1;
for (int i = 1; i < 2 * n - 1; ++i) {
w1s[i] = w1s[i - 1] * w;
w2s[i] = w2s[i - 1] * w1s[i - 1];
invW1s[i] = invW1s[i - 1] * invW;
invW2s[i] = invW2s[i - 1] * invW1s[i - 1];
}
}
}
void run(vector<Mint> &fs) {
if (n < THR_N) {
vector<Mint> gs(n, 0);
for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) gs[i] += ww[i][j] * fs[j];
fs = gs;
} else {
for (int i = 0; i < n; ++i) fs[i] *= invW2s[i];
reverse(fs.begin(), fs.end());
fs = convolve(w2s, fs);
fs.erase(fs.begin(), fs.begin() + (n - 1));
fs.resize(n);
for (int i = 0; i < n; ++i) fs[i] *= invW2s[i];
}
}
} // dft1
void dft2(vector<Mint> &fs, bool inv) {
for (int i = 0; i < N; ++i) {
dft1::build(L[i], D[i], inv);
for (int u = 0; u < M; u += LL[i + 1]) for (int v = u; v < u + LL[i]; ++v) {
vector<Mint> gs(L[i]);
for (int k = 0; k < L[i]; ++k) gs[k] = fs[v + k * LL[i]];
dft1::run(gs);
for (int k = 0; k < L[i]; ++k) fs[v + k * LL[i]] = gs[k];
}
}
if (inv) {
const Mint invM = Mint(M).inv();
for (int u = 0; u < M; ++u) {
fs[u] *= invM;
}
}
}
int main() {
for (; ~scanf("%d%d%d", &N, &MO, &I); ) {
Mint::setM(MO);
L.resize(N);
P.resize(N);
D.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%d%u%u", &L[i], &P[i].x, &D[i].x);
}
{
Mint sumP = 0;
for (int i = 0; i < N; ++i) {
sumP += P[i];
}
const Mint invSumP = sumP.inv();
for (int i = 0; i < N; ++i) {
P[i] *= invSumP;
}
}
LL.resize(N + 1);
LL[0] = 1;
for (int i = 0; i < N; ++i) {
LL[i + 1] = LL[i] * L[i];
}
M = LL[N];
cerr<<"N = "<<N<<", M = "<<M<<", I = "<<I<<", L = "<<L<<endl;
Mint ans = 0;
if (N == 1) {
ans = M;
} else {
vector<Mint> gs(M, 0);
gs[0] += 1;
for (int i = 0; i < N; ++i) {
gs[(L[i] - 1) * LL[i]] -= P[i];
}
dft2(gs, false);
assert(!gs[0]);
for (int u = 1; u < M; ++u) {
assert(gs[u]);
gs[u] = gs[u].inv();
}
dft2(gs, true);
ans = 1;
for (int t = 1; t < M; ++t) {
int tt = 0;
for (int i = 0; i < N; ++i) {
tt += ((L[i] - t / LL[i] % L[i]) % L[i]) * LL[i];
}
const Mint f = gs[t] - 2 * gs[0] + gs[tt];
assert(f);
ans -= f.inv();
}
}
printf("%u\n", ans.x);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 2
Accepted
Test #1:
score: 2
Accepted
time: 1ms
memory: 3884kb
input:
1 1040016149 1 114514 86782 975423317
output:
114514
result:
ok 1 number(s): "114514"
Subtask #2:
score: 8
Accepted
Test #2:
score: 8
Accepted
time: 0ms
memory: 3876kb
input:
1 917829557 2 7 409960 84299716
output:
7
result:
ok 1 number(s): "7"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
2 1021037011 2 3 673845 456586624 2 557323 1021037010
output:
325765596
result:
ok 1 number(s): "325765596"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
2 974672641 2 2 919159 974672640 4 945246 788001635
output:
206340059
result:
ok 1 number(s): "206340059"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
3 942949663 2 2 900268 942949662 2 314911 942949662 2 488210 942949662
output:
697012073
result:
ok 1 number(s): "697012073"
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #6:
score: 10
Accepted
time: 1ms
memory: 4164kb
input:
2 1040469361 3 3 607396 156553896 20 622587 835710357
output:
212836966
result:
ok 1 number(s): "212836966"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
6 932284961 3 2 976786 932284960 2 296977 932284960 2 640048 932284960 2 883210 932284960 2 178849 932284960 2 292747 932284960
output:
767388139
result:
ok 1 number(s): "767388139"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
3 972511489 3 4 270846 275326774 6 901035 3644392 3 450749 3644391
output:
386017324
result:
ok 1 number(s): "386017324"
Test #9:
score: 0
Accepted
time: 1ms
memory: 4000kb
input:
4 952654361 3 4 353315 567578568 2 265582 952654360 2 429959 952654360 5 62389 840524015
output:
942289666
result:
ok 1 number(s): "942289666"
Test #10:
score: 0
Accepted
time: 0ms
memory: 4172kb
input:
3 969859729 3 3 342202 745159492 9 270897 686337727 3 216159 745159492
output:
184152966
result:
ok 1 number(s): "184152966"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
3 953647801 3 7 943891 755724372 4 151642 109446108 3 775757 89434891
output:
811899700
result:
ok 1 number(s): "811899700"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3936kb
input:
3 1029304937 3 4 54303 379091496 2 193487 1029304936 11 607170 762447147
output:
626421900
result:
ok 1 number(s): "626421900"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
3 904885561 3 3 554090 196965144 2 945499 904885560 15 747460 217098071
output:
676301027
result:
ok 1 number(s): "676301027"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3948kb
input:
6 986788531 3 2 522554 986788530 2 316305 986788530 2 94022 986788530 2 249256 986788530 2 625960 986788530 3 405298 837112629
output:
441366932
result:
ok 1 number(s): "441366932"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3888kb
input:
2 1023351421 3 20 337665 403345072 5 40276 480359844
output:
1002751099
result:
ok 1 number(s): "1002751099"
Subtask #4:
score: 8
Accepted
Test #16:
score: 8
Accepted
time: 2ms
memory: 3916kb
input:
2 998244353 4 4 61786 911660635 238 287234 493901365
output:
223055892
result:
ok 1 number(s): "223055892"
Test #17:
score: 0
Accepted
time: 1ms
memory: 3868kb
input:
2 998244353 4 7 25813 683624219 112 96355 961521397
output:
97474170
result:
ok 1 number(s): "97474170"
Test #18:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
2 998244353 4 56 87114 727469702 14 24912 983690962
output:
592417090
result:
ok 1 number(s): "592417090"
Test #19:
score: 0
Accepted
time: 1ms
memory: 3892kb
input:
2 998244353 4 32 147776 617152567 28 775643 859007132
output:
566596649
result:
ok 1 number(s): "566596649"
Test #20:
score: 0
Accepted
time: 1ms
memory: 4136kb
input:
2 998244353 4 17 545281 464157011 56 816599 3898319
output:
469481867
result:
ok 1 number(s): "469481867"
Subtask #5:
score: 10
Accepted
Test #21:
score: 10
Accepted
time: 1ms
memory: 3872kb
input:
7 1023063703 5 2 265354 1023063702 2 526733 1023063702 2 685323 1023063702 2 856929 1023063702 2 116643 1023063702 2 909182 1023063702 2 533391 1023063702
output:
72258463
result:
ok 1 number(s): "72258463"
Test #22:
score: 0
Accepted
time: 1ms
memory: 4152kb
input:
8 909973201 5 2 803753 909973200 2 909951 909973200 2 686418 909973200 2 751586 909973200 2 596938 909973200 2 931460 909973200 2 613477 909973200 2 716815 909973200
output:
446664445
result:
ok 1 number(s): "446664445"
Test #23:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
9 1016555329 5 2 955958 1016555328 2 672234 1016555328 2 870436 1016555328 2 31291 1016555328 2 206731 1016555328 2 727640 1016555328 2 134125 1016555328 2 893866 1016555328 2 138706 1016555328
output:
808692189
result:
ok 1 number(s): "808692189"
Test #24:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
10 1007394217 5 2 961834 1007394216 2 209391 1007394216 2 715582 1007394216 2 553353 1007394216 2 213960 1007394216 2 589617 1007394216 2 666503 1007394216 2 407731 1007394216 2 152967 1007394216 2 848445 1007394216
output:
9280802
result:
ok 1 number(s): "9280802"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
10 968522221 5 2 21932 968522220 2 675564 968522220 2 378437 968522220 2 81037 968522220 2 963992 968522220 2 311430 968522220 2 699121 968522220 2 45417 968522220 2 275308 968522220 2 411066 968522220
output:
692011298
result:
ok 1 number(s): "692011298"
Subtask #6:
score: 12
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #26:
score: 12
Accepted
time: 1ms
memory: 3880kb
input:
4 972401761 6 2 972661 972401760 15 255992 126248662 12 878880 606133410 2 224371 972401760
output:
115576065
result:
ok 1 number(s): "115576065"
Test #27:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
4 904442113 6 4 455381 759185044 32 370753 618464921 3 500887 212337160 2 124789 904442112
output:
423186989
result:
ok 1 number(s): "423186989"
Test #28:
score: 0
Accepted
time: 0ms
memory: 4168kb
input:
2 1044288001 6 200 909466 831914154 4 635879 349141366
output:
992703804
result:
ok 1 number(s): "992703804"
Test #29:
score: 0
Accepted
time: 2ms
memory: 4200kb
input:
3 995557889 6 208 995170 150328412 2 962966 995557888 2 870197 995557888
output:
559608682
result:
ok 1 number(s): "559608682"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
3 926933113 6 4 600105 859154928 24 395570 903534782 9 869027 266882176
output:
586077830
result:
ok 1 number(s): "586077830"
Test #31:
score: 0
Accepted
time: 1ms
memory: 4164kb
input:
4 1018608697 6 28 136320 512857858 2 391617 1018608696 2 416876 1018608696 8 640950 421343802
output:
275871736
result:
ok 1 number(s): "275871736"
Test #32:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
5 909759601 6 10 839897 853552356 2 969093 909759600 4 795795 674156232 2 423545 909759600 6 600787 419741593
output:
241411297
result:
ok 1 number(s): "241411297"
Test #33:
score: 0
Accepted
time: 0ms
memory: 4136kb
input:
4 998016823 6 27 155873 262940187 2 158035 998016822 9 202421 553668428 2 21539 998016822
output:
118420215
result:
ok 1 number(s): "118420215"
Test #34:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
4 910702297 6 3 890425 906157449 24 469847 206340805 2 422607 910702296 7 67244 714860697
output:
836808927
result:
ok 1 number(s): "836808927"
Test #35:
score: 0
Accepted
time: 2ms
memory: 3852kb
input:
2 965490689 6 4 468310 246473372 256 256288 754419658
output:
20502222
result:
ok 1 number(s): "20502222"
Subtask #7:
score: 8
Accepted
Dependency #6:
100%
Accepted
Test #36:
score: 8
Accepted
time: 7ms
memory: 3896kb
input:
4 1040169409 7 2 835454 1040169408 3 772774 636723579 4 342482 586400067 192 334236 48598666
output:
836620519
result:
ok 1 number(s): "836620519"
Test #37:
score: 0
Accepted
time: 3ms
memory: 3892kb
input:
5 1001291201 7 2 380607 1001291200 8 447454 176535093 32 876312 112032651 5 769899 24926973 2 833606 1001291200
output:
773216067
result:
ok 1 number(s): "773216067"
Test #38:
score: 0
Accepted
time: 7ms
memory: 3920kb
input:
3 1027170721 7 108 162949 530583958 8 335705 915297592 6 762677 864984184
output:
944135384
result:
ok 1 number(s): "944135384"
Test #39:
score: 0
Accepted
time: 6ms
memory: 3988kb
input:
4 965986561 7 672 958339 534727307 2 543173 965986560 2 884696 965986560 2 78668 965986560
output:
731390335
result:
ok 1 number(s): "731390335"
Test #40:
score: 0
Accepted
time: 3ms
memory: 4148kb
input:
5 1033312897 7 2 847300 1033312896 22 496446 176836498 4 545327 842729668 4 825711 842729668 8 55521 221623844
output:
111025694
result:
ok 1 number(s): "111025694"
Test #41:
score: 0
Accepted
time: 6ms
memory: 3996kb
input:
4 974073601 7 80 688089 65481914 6 743381 676241902 2 457097 974073600 6 433647 676241902
output:
20654041
result:
ok 1 number(s): "20654041"
Test #42:
score: 0
Accepted
time: 9ms
memory: 3880kb
input:
4 988969921 7 192 682290 823722245 2 231872 988969920 4 644835 908425877 4 599428 80544044
output:
327364135
result:
ok 1 number(s): "327364135"
Test #43:
score: 0
Accepted
time: 4ms
memory: 3900kb
input:
4 905233921 7 10 797498 529875391 40 404554 190390703 8 51869 591750273 2 267795 905233920
output:
840539530
result:
ok 1 number(s): "840539530"
Test #44:
score: 0
Accepted
time: 4ms
memory: 3976kb
input:
4 995124209 7 8 15181 811988629 4 25011 700264330 4 29108 700264330 52 401060 745256833
output:
704350003
result:
ok 1 number(s): "704350003"
Test #45:
score: 0
Accepted
time: 7ms
memory: 3912kb
input:
3 942316129 7 12 857153 473633986 72 777888 329202798 8 483455 869896725
output:
388869095
result:
ok 1 number(s): "388869095"
Test #46:
score: 0
Accepted
time: 10ms
memory: 4332kb
input:
3 1035901441 7 896 435538 726832882 4 15200 453561200 2 924673 1035901440
output:
938917469
result:
ok 1 number(s): "938917469"
Test #47:
score: 0
Accepted
time: 10ms
memory: 4136kb
input:
2 1019232001 7 4 673885 248868967 1920 754816 341141141
output:
476117109
result:
ok 1 number(s): "476117109"
Test #48:
score: 0
Accepted
time: 11ms
memory: 4432kb
input:
2 957116737 7 3888 412700 63632954 2 333017 957116736
output:
21716613
result:
ok 1 number(s): "21716613"
Test #49:
score: 0
Accepted
time: 9ms
memory: 3932kb
input:
2 1018688833 7 168 928533 47528245 48 431265 446651888
output:
377651323
result:
ok 1 number(s): "377651323"
Test #50:
score: 0
Accepted
time: 11ms
memory: 4100kb
input:
2 930680833 7 2048 213064 343165841 4 619665 206937758
output:
710731553
result:
ok 1 number(s): "710731553"
Subtask #8:
score: 6
Accepted
Dependency #4:
100%
Accepted
Test #51:
score: 6
Accepted
time: 841ms
memory: 40484kb
input:
2 998244353 8 229376 553453 626702417 2 148397 998244352
output:
942359197
result:
ok 1 number(s): "942359197"
Test #52:
score: 0
Accepted
time: 1015ms
memory: 5464kb
input:
2 998244353 8 544 790355 550966489 896 187218 528905230
output:
821359943
result:
ok 1 number(s): "821359943"
Test #53:
score: 0
Accepted
time: 1008ms
memory: 5988kb
input:
2 998244353 8 3808 61621 800472218 128 340446 90326106
output:
313652514
result:
ok 1 number(s): "313652514"
Test #54:
score: 0
Accepted
time: 1022ms
memory: 6048kb
input:
2 998244353 8 3584 84070 488937671 136 502854 265129779
output:
311354359
result:
ok 1 number(s): "311354359"
Test #55:
score: 0
Accepted
time: 1028ms
memory: 5900kb
input:
2 998244353 8 128 745552 249745217 3808 24183 979437006
output:
800304170
result:
ok 1 number(s): "800304170"
Subtask #9:
score: 8
Accepted
Dependency #8:
100%
Accepted
Test #56:
score: 8
Accepted
time: 512ms
memory: 4696kb
input:
2 998244353 9 1024 890631 674816215 256 505634 280778420
output:
252098958
result:
ok 1 number(s): "252098958"
Test #57:
score: 0
Accepted
time: 1018ms
memory: 5600kb
input:
3 998244353 9 256 272030 680107844 952 390160 81552934 2 248471 998244352
output:
659256944
result:
ok 1 number(s): "659256944"
Test #58:
score: 0
Accepted
time: 712ms
memory: 7404kb
input:
3 998244353 9 14336 680183 785721917 8 733319 509520358 4 727219 86583718
output:
685697293
result:
ok 1 number(s): "685697293"
Test #59:
score: 0
Accepted
time: 763ms
memory: 14340kb
input:
2 998244353 9 60928 148823 499088267 8 950907 372528824
output:
777164685
result:
ok 1 number(s): "777164685"
Test #60:
score: 0
Accepted
time: 337ms
memory: 4668kb
input:
3 998244353 9 4 486207 86583718 1904 558847 739086177 32 759123 910687289
output:
57611731
result:
ok 1 number(s): "57611731"
Test #61:
score: 0
Accepted
time: 547ms
memory: 4772kb
input:
4 998244353 9 2 17862 998244352 2 536183 998244352 136 576612 607112440 512 287212 914464108
output:
714839257
result:
ok 1 number(s): "714839257"
Test #62:
score: 0
Accepted
time: 609ms
memory: 5420kb
input:
5 998244353 9 4 931852 86583718 4 915233 86583718 7 355297 14553391 34 970627 511225650 128 974908 381262342
output:
711640581
result:
ok 1 number(s): "711640581"
Test #63:
score: 0
Accepted
time: 642ms
memory: 5436kb
input:
6 998244353 9 238 953000 458625863 4 188309 911660635 2 335975 998244352 8 787731 509520358 4 209142 86583718 8 365300 509520358
output:
713841626
result:
ok 1 number(s): "713841626"
Test #64:
score: 0
Accepted
time: 136ms
memory: 4360kb
input:
5 998244353 9 4 101133 86583718 32 902625 666194801 34 58866 995719509 7 224335 779057549 8 994132 488723995
output:
365734961
result:
ok 1 number(s): "365734961"
Test #65:
score: 0
Accepted
time: 246ms
memory: 5112kb
input:
7 998244353 9 14 235694 983690962 8 744104 625715529 8 637536 625715529 8 100975 488723995 4 483443 911660635 2 863459 998244352 8 618213 509520358
output:
704893603
result:
ok 1 number(s): "704893603"
Test #66:
score: 0
Accepted
time: 327ms
memory: 4360kb
input:
6 998244353 9 8 237280 625715529 4 164854 911660635 4 222248 911660635 4 542353 86583718 4 863270 911660635 136 555788 418624303
output:
24164169
result:
ok 1 number(s): "24164169"
Test #67:
score: 0
Accepted
time: 328ms
memory: 4484kb
input:
7 998244353 9 112 335624 263656516 2 404823 998244352 2 612984 998244352 8 460719 509520358 4 759780 911660635 2 525332 998244352 8 561035 625715529
output:
831206565
result:
ok 1 number(s): "831206565"
Test #68:
score: 0
Accepted
time: 118ms
memory: 4364kb
input:
6 998244353 9 14 275099 314620134 8 772812 372528824 8 546908 625715529 2 662447 998244352 16 164487 661054123 8 993159 488723995
output:
50327783
result:
ok 1 number(s): "50327783"
Test #69:
score: 0
Accepted
time: 282ms
memory: 4544kb
input:
16 998244353 9 2 223902 998244352 2 356273 998244352 7 102151 530734902 2 124503 998244352 2 231032 998244352 2 764641 998244352 2 439592 998244352 2 626656 998244352 2 827889 998244352 2 683287 998244352 2 527533 998244352 2 96136 998244352 2 595457 998244352 2 630440 998244352 2 402492 998244352 2...
output:
662143805
result:
ok 1 number(s): "662143805"
Test #70:
score: 0
Accepted
time: 0ms
memory: 4136kb
input:
1 998244353 9 487424 494448 849013356
output:
487424
result:
ok 1 number(s): "487424"
Subtask #10:
score: 10
Accepted
Dependency #5:
100%
Accepted
Test #71:
score: 10
Accepted
time: 31ms
memory: 3872kb
input:
15 969740263 10 2 373621 969740262 2 946569 969740262 2 253224 969740262 2 664561 969740262 2 611912 969740262 2 204304 969740262 2 746434 969740262 2 336578 969740262 2 200784 969740262 2 557632 969740262 2 651211 969740262 2 559106 969740262 2 610198 969740262 2 799763 969740262 2 908557 969740262
output:
411647692
result:
ok 1 number(s): "411647692"
Test #72:
score: 0
Accepted
time: 82ms
memory: 3880kb
input:
16 991926851 10 2 712792 991926850 2 396612 991926850 2 850616 991926850 2 678097 991926850 2 939368 991926850 2 978032 991926850 2 226041 991926850 2 545440 991926850 2 261283 991926850 2 142065 991926850 2 350488 991926850 2 915911 991926850 2 355737 991926850 2 57300 991926850 2 584284 991926850 ...
output:
529574589
result:
ok 1 number(s): "529574589"
Test #73:
score: 0
Accepted
time: 183ms
memory: 4152kb
input:
17 1004734669 10 2 774339 1004734668 2 761099 1004734668 2 350815 1004734668 2 956243 1004734668 2 13259 1004734668 2 547506 1004734668 2 459082 1004734668 2 817986 1004734668 2 724570 1004734668 2 935942 1004734668 2 560680 1004734668 2 520194 1004734668 2 260207 1004734668 2 852274 1004734668 2 56...
output:
426830028
result:
ok 1 number(s): "426830028"
Test #74:
score: 0
Accepted
time: 361ms
memory: 4368kb
input:
18 934497901 10 2 116198 934497900 2 820160 934497900 2 77657 934497900 2 611949 934497900 2 498059 934497900 2 471331 934497900 2 90116 934497900 2 413650 934497900 2 938011 934497900 2 455321 934497900 2 808088 934497900 2 467664 934497900 2 1790 934497900 2 746901 934497900 2 649412 934497900 2 9...
output:
132988262
result:
ok 1 number(s): "132988262"
Test #75:
score: 0
Accepted
time: 359ms
memory: 4484kb
input:
18 997115969 10 2 677091 997115968 2 182601 997115968 2 859073 997115968 2 844740 997115968 2 486819 997115968 2 239614 997115968 2 605204 997115968 2 108805 997115968 2 547452 997115968 2 78461 997115968 2 662608 997115968 2 930644 997115968 2 950692 997115968 2 223335 997115968 2 405750 997115968 ...
output:
576918483
result:
ok 1 number(s): "576918483"
Subtask #11:
score: 12
Accepted
Dependency #10:
100%
Accepted
Test #76:
score: 12
Accepted
time: 111ms
memory: 4196kb
input:
4 1032431401 11 22 699510 258557651 35 925197 147665025 12 561090 444222341 22 908847 573733633
output:
99475181
result:
ok 1 number(s): "99475181"
Test #77:
score: 0
Accepted
time: 150ms
memory: 4364kb
input:
5 990258361 11 26 569351 462961367 6 80029 91923647 28 860702 695739176 13 338538 474254325 5 292764 939161661
output:
153420054
result:
ok 1 number(s): "153420054"
Test #78:
score: 0
Accepted
time: 167ms
memory: 4632kb
input:
5 942013381 11 11 779531 345150756 6 675857 348180154 5 505879 317895062 22 723269 596862625 42 880286 229109913
output:
402752746
result:
ok 1 number(s): "402752746"
Test #79:
score: 0
Accepted
time: 246ms
memory: 4872kb
input:
5 962729461 11 3 778362 370070893 10 605034 216793322 11 337490 739455560 28 33633 871490348 44 355775 427272628
output:
591659186
result:
ok 1 number(s): "591659186"
Test #80:
score: 0
Accepted
time: 212ms
memory: 5140kb
input:
6 980201041 11 6 509634 440462155 4 665806 169208619 13 174944 769308185 13 802268 979901095 7 735659 594468251 15 716016 587533173
output:
196440161
result:
ok 1 number(s): "196440161"
Test #81:
score: 0
Accepted
time: 276ms
memory: 5252kb
input:
5 1006335331 11 33 465476 412382195 26 62659 649367959 10 379814 435149835 26 32613 193899237 2 362546 1006335330
output:
767433541
result:
ok 1 number(s): "767433541"
Test #82:
score: 0
Accepted
time: 295ms
memory: 5156kb
input:
7 1025362801 11 2 103702 1025362800 3 230121 393065710 3 866490 393065710 5 996945 438528644 7 75346 889862126 22 727767 723881393 33 744345 331906350
output:
624948293
result:
ok 1 number(s): "624948293"
Test #83:
score: 0
Accepted
time: 319ms
memory: 5336kb
input:
6 927400321 11 34 690193 633272049 14 271947 158466609 5 29155 48767577 3 680991 558580854 34 504089 50083535 2 269784 927400320
output:
529445988
result:
ok 1 number(s): "529445988"
Test #84:
score: 0
Accepted
time: 135ms
memory: 4440kb
input:
6 1026720001 11 5 856582 192380835 4 275465 826256064 2 577506 1026720000 30 726584 514798836 8 226229 122245655 24 708136 70845584
output:
196483828
result:
ok 1 number(s): "196483828"
Test #85:
score: 0
Accepted
time: 216ms
memory: 4612kb
input:
7 1048614337 11 8 81957 714673501 28 132495 421563936 2 981004 1048614336 2 730100 1048614336 2 504455 1048614336 42 710077 567746601 4 890757 467835333
output:
717647484
result:
ok 1 number(s): "717647484"
Test #86:
score: 0
Accepted
time: 183ms
memory: 4612kb
input:
6 1048924801 11 10 89570 521413525 4 496152 501406936 2 700711 1048924800 8 812007 592618035 48 653132 179779517 10 998767 343279042
output:
956663514
result:
ok 1 number(s): "956663514"
Test #87:
score: 0
Accepted
time: 201ms
memory: 4628kb
input:
5 1010095921 11 6 530393 687121127 30 440107 843763139 12 684275 324267076 4 691228 475079850 40 649981 506902675
output:
525817982
result:
ok 1 number(s): "525817982"
Test #88:
score: 0
Accepted
time: 238ms
memory: 4876kb
input:
7 935718661 11 20 799816 725732576 4 922930 747355853 2 463829 935718660 2 766609 935718660 4 175830 747355853 15 238560 611128660 20 768805 48007705
output:
339402274
result:
ok 1 number(s): "339402274"
Test #89:
score: 0
Accepted
time: 286ms
memory: 5140kb
input:
7 904611457 11 3 896340 681718948 4 145563 9216110 8 315633 570585560 42 124915 772177444 2 790943 904611456 7 756555 392957847 8 680504 387697417
output:
513967674
result:
ok 1 number(s): "513967674"
Test #90:
score: 0
Accepted
time: 279ms
memory: 5140kb
input:
7 954670081 11 2 181551 954670080 6 601961 633710667 20 415802 518488008 16 36518 470515757 6 527605 633710667 2 772131 954670080 10 592493 212387045
output:
845226312
result:
ok 1 number(s): "845226312"
Subtask #12:
score: 6
Accepted
Dependency #7:
100%
Accepted
Dependency #9:
100%
Accepted
Dependency #11:
100%
Accepted
Test #91:
score: 6
Accepted
time: 487ms
memory: 6332kb
input:
2 940283521 12 10128 916891 881732406 40 319509 229502633
output:
819210562
result:
ok 1 number(s): "819210562"
Test #92:
score: 0
Accepted
time: 578ms
memory: 5820kb
input:
3 964109281 12 4460 529113 561201332 2 584568 964109280 48 959674 576980669
output:
185961710
result:
ok 1 number(s): "185961710"
Test #93:
score: 0
Accepted
time: 817ms
memory: 5304kb
input:
3 985543201 12 12 423534 630035952 80 534310 861430626 454 886448 982755151
output:
158666490
result:
ok 1 number(s): "158666490"
Test #94:
score: 0
Accepted
time: 623ms
memory: 5424kb
input:
4 974715601 12 10 822569 896595666 12 381386 199317125 2 592870 974715600 1832 873842 760178656
output:
512490541
result:
ok 1 number(s): "512490541"
Test #95:
score: 0
Accepted
time: 515ms
memory: 5584kb
input:
4 959195761 12 2330 338858 281585961 4 224822 442548969 8 161907 456904616 6 171896 132568499
output:
901449688
result:
ok 1 number(s): "901449688"
Test #96:
score: 0
Accepted
time: 613ms
memory: 5468kb
input:
5 906775561 12 5 108955 894444589 8 23657 502875925 12 69485 110286081 2 298454 906775560 478 562053 185780167
output:
117102764
result:
ok 1 number(s): "117102764"
Test #97:
score: 0
Accepted
time: 620ms
memory: 5124kb
input:
5 921044161 12 32 488663 76321973 5 345291 507072799 6 357954 895020767 241 381073 310674276 2 516952 921044160
output:
21557079
result:
ok 1 number(s): "21557079"
Test #98:
score: 0
Accepted
time: 605ms
memory: 5468kb
input:
4 960105121 12 20 61235 629292865 502 758953 338610188 6 31315 307440177 8 309913 475159507
output:
539745126
result:
ok 1 number(s): "539745126"
Test #99:
score: 0
Accepted
time: 618ms
memory: 5424kb
input:
5 1004489641 12 257 442823 397311768 8 616213 469865403 4 50596 408619556 20 322882 375967564 3 453830 583595012
output:
526555385
result:
ok 1 number(s): "526555385"
Test #100:
score: 0
Accepted
time: 711ms
memory: 6132kb
input:
4 1002845101 12 30 937948 43797392 4036 664622 563453039 2 76177 1002845100 2 992569 1002845100
output:
235148813
result:
ok 1 number(s): "235148813"
Test #101:
score: 0
Accepted
time: 687ms
memory: 5688kb
input:
4 936437461 12 30 958117 452004031 4 233553 578995550 2 800696 936437460 2026 445979 901166189
output:
842824070
result:
ok 1 number(s): "842824070"
Test #102:
score: 0
Accepted
time: 562ms
memory: 6100kb
input:
4 967479361 12 5095 693179 480545460 4 557405 24233647 8 145874 594769868 3 287627 802063289
output:
136118600
result:
ok 1 number(s): "136118600"
Test #103:
score: 0
Accepted
time: 864ms
memory: 6412kb
input:
4 925761121 12 6126 135605 711742328 4 428900 296402215 2 586889 925761120 10 492678 408666890
output:
573527672
result:
ok 1 number(s): "573527672"
Test #104:
score: 0
Accepted
time: 680ms
memory: 5596kb
input:
6 1041722401 12 5 164243 565473986 2 669751 1041722400 6 495765 971750216 2 771390 1041722400 4 270828 827058779 1031 895005 554360088
output:
721402587
result:
ok 1 number(s): "721402587"
Test #105:
score: 0
Accepted
time: 684ms
memory: 5688kb
input:
5 997939981 12 3 835560 887273591 10 538742 92659661 4 310465 448614931 2 123413 997939980 2066 103520 853352
output:
993763929
result:
ok 1 number(s): "993763929"
Test #106:
score: 0
Accepted
time: 707ms
memory: 5668kb
input:
5 949188841 12 2 141270 949188840 20 493997 317310843 2 853188 949188840 2078 838599 833342537 3 552003 403814483
output:
889441128
result:
ok 1 number(s): "889441128"
Test #107:
score: 0
Accepted
time: 127ms
memory: 4192kb
input:
8 1036067761 12 10 416938 177402038 4 559871 951496097 12 175026 919588307 4 595348 951496097 2 982924 1036067760 2 405420 1036067760 4 347313 951496097 7 946965 429684228
output:
553020182
result:
ok 1 number(s): "553020182"
Test #108:
score: 0
Accepted
time: 201ms
memory: 4592kb
input:
8 1004240161 12 6 296913 663971589 6 366581 663971589 8 147391 748751600 2 955732 1004240160 10 85111 577005150 2 931695 1004240160 2 79627 1004240160 14 934105 575837948
output:
440759412
result:
ok 1 number(s): "440759412"
Test #109:
score: 0
Accepted
time: 507ms
memory: 4720kb
input:
8 953156161 12 2 749780 953156160 2 666434 953156160 2 664135 953156160 8 578893 936686511 6 48776 789310653 4 980429 190825120 2 470040 953156160 110 859649 241053346
output:
774169072
result:
ok 1 number(s): "774169072"
Test #110:
score: 0
Accepted
time: 318ms
memory: 4988kb
input:
8 979767361 12 2 425831 979767360 16 178102 9165626 2 240448 979767360 2 797490 979767360 2 120283 979767360 30 335709 674074218 2 760289 979767360 26 320926 553345576
output:
166534822
result:
ok 1 number(s): "166534822"
Test #111:
score: 0
Accepted
time: 592ms
memory: 5064kb
input:
9 1040921701 12 2 342279 1040921700 2 575382 1040921700 12 338599 38878157 2 289503 1040921700 4 390795 195107884 2 210642 1040921700 70 512604 525671225 4 612237 845813817 2 953087 1040921700
output:
478615806
result:
ok 1 number(s): "478615806"
Test #112:
score: 0
Accepted
time: 307ms
memory: 5260kb
input:
8 902221321 12 2 727095 902221320 11 566951 570627224 2 207388 902221320 2 217661 902221320 21 171322 496957039 4 328618 364571187 8 67174 659903664 8 35381 349978672
output:
325234098
result:
ok 1 number(s): "325234098"
Test #113:
score: 0
Accepted
time: 356ms
memory: 5232kb
input:
9 1011754801 12 7 238495 134006536 4 768617 691946137 18 537125 233835973 2 584327 1011754800 2 460415 1011754800 2 701739 1011754800 2 321821 1011754800 3 168496 485383365 20 21593 396687980
output:
790558667
result:
ok 1 number(s): "790558667"
Test #114:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
1 952414649 12 493991 642637 798174221
output:
493991
result:
ok 1 number(s): "493991"
Test #115:
score: 0
Accepted
time: 1325ms
memory: 5324kb
input:
3 996787007 12 67 388369 991505886 83 593046 106506264 89 765490 171907274
output:
646679314
result:
ok 1 number(s): "646679314"
Test #116:
score: 0
Accepted
time: 1083ms
memory: 6420kb
input:
2 1039371559 12 79 92678 336932966 6283 314443 261579480
output:
989406346
result:
ok 1 number(s): "989406346"
Test #117:
score: 0
Accepted
time: 1345ms
memory: 5424kb
input:
3 918529841 12 79 65267 903684432 71 677401 582535550 89 398315 541715787
output:
573181569
result:
ok 1 number(s): "573181569"
Test #118:
score: 0
Accepted
time: 429ms
memory: 5372kb
input:
3 952251301 12 2310 73753 701445334 6 476123 663720703 26 61857 617439077
output:
287332583
result:
ok 1 number(s): "287332583"
Test #119:
score: 0
Accepted
time: 704ms
memory: 4904kb
input:
4 928675441 12 132 498937 723714791 10 155140 688217707 2 183844 928675440 147 172893 735125766
output:
578553575
result:
ok 1 number(s): "578553575"
Test #120:
score: 0
Accepted
time: 602ms
memory: 4968kb
input:
4 1035609121 12 6 768099 265932961 30 116268 505398613 182 612149 528298388 12 713349 392936811
output:
56807518
result:
ok 1 number(s): "56807518"
Test #121:
score: 0
Accepted
time: 598ms
memory: 5108kb
input:
4 941579101 12 21 528779 473778183 225 928653 422638104 44 458686 687559060 2 886515 941579100
output:
752918048
result:
ok 1 number(s): "752918048"
Test #122:
score: 0
Accepted
time: 255ms
memory: 5136kb
input:
5 923130601 12 2 45235 923130600 17 848848 239357641 30 973849 407373432 14 114480 423445517 30 324043 215683557
output:
484086499
result:
ok 1 number(s): "484086499"
Test #123:
score: 0
Accepted
time: 551ms
memory: 5124kb
input:
6 1017989281 12 2 172394 1017989280 7 616861 1017508889 8 147746 183941737 66 2325 40564271 3 663516 74086722 20 473402 886782526
output:
557292174
result:
ok 1 number(s): "557292174"
Test #124:
score: 0
Accepted
time: 726ms
memory: 5108kb
input:
5 997926931 12 42 90388 302627328 2 426939 997926930 10 118325 842908340 90 257428 556605406 6 975615 937490888
output:
777574268
result:
ok 1 number(s): "777574268"
Test #125:
score: 0
Accepted
time: 615ms
memory: 5156kb
input:
6 914700151 12 65 842507 424930724 49 62967 642752500 6 137236 603809437 2 635830 914700150 2 808357 914700150 6 832292 310890715
output:
166163595
result:
ok 1 number(s): "166163595"
Test #126:
score: 0
Accepted
time: 532ms
memory: 5528kb
input:
4 950019841 12 12 64558 109760691 15 667317 675243511 2 978550 950019840 1309 969513 640374249
output:
11564562
result:
ok 1 number(s): "11564562"
Test #127:
score: 0
Accepted
time: 315ms
memory: 5164kb
input:
6 1017992641 12 38 934427 757399582 12 521945 68515975 3 770385 377978918 35 726573 606684726 5 639006 825344673 2 768656 1017992640
output:
793025770
result:
ok 1 number(s): "793025770"
Test #128:
score: 0
Accepted
time: 621ms
memory: 5532kb
input:
4 1032431401 12 10 773519 634237118 2 473563 1032431400 546 391665 196833300 44 990054 519575415
output:
638516534
result:
ok 1 number(s): "638516534"
Test #129:
score: 0
Accepted
time: 308ms
memory: 5544kb
input:
7 1038557521 12 5 556284 591278962 39 904101 1028030401 3 532965 165612271 6 825185 872945250 5 301722 956190774 2 256370 1038557520 14 618680 158028144
output:
486790345
result:
ok 1 number(s): "486790345"
Test #130:
score: 0
Accepted
time: 329ms
memory: 5620kb
input:
7 907137001 12 6 380959 117708860 6 608834 789428142 3 633154 117708859 4 568352 850222375 55 970552 433791124 3 469231 789428141 7 953744 470478510
output:
627924542
result:
ok 1 number(s): "627924542"
Extra Test:
score: 0
Extra Test Passed