QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#103940 | #6399. Classic: Classical Problem | pachicobue | AC ✓ | 3441ms | 25536kb | C++23 | 40.6kb | 2023-05-07 22:22:48 | 2023-05-07 22:22:50 |
Judging History
answer
#include <bits/stdc++.h>
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
using f64 = double;
using f80 = long double;
using f128 = __float128;
constexpr i32 operator"" _i32(u64 v) { return v; }
constexpr u32 operator"" _u32(u64 v) { return v; }
constexpr i64 operator"" _i64(u64 v) { return v; }
constexpr u64 operator"" _u64(u64 v) { return v; }
constexpr f64 operator"" _f64(f80 v) { return v; }
constexpr f80 operator"" _f80(f80 v) { return v; }
using Istream = std::istream;
using Ostream = std::ostream;
using Str = std::string;
template<typename T>
using Lt = std::less<T>;
template<typename T>
using Gt = std::greater<T>;
template<int n>
using BSet = std::bitset<n>;
template<typename T1, typename T2>
using Pair = std::pair<T1, T2>;
template<typename... Ts>
using Tup = std::tuple<Ts...>;
template<typename T, int N>
using Arr = std::array<T, N>;
template<typename... Ts>
using Deq = std::deque<Ts...>;
template<typename... Ts>
using Set = std::set<Ts...>;
template<typename... Ts>
using MSet = std::multiset<Ts...>;
template<typename... Ts>
using USet = std::unordered_set<Ts...>;
template<typename... Ts>
using UMSet = std::unordered_multiset<Ts...>;
template<typename... Ts>
using Map = std::map<Ts...>;
template<typename... Ts>
using MMap = std::multimap<Ts...>;
template<typename... Ts>
using UMap = std::unordered_map<Ts...>;
template<typename... Ts>
using UMMap = std::unordered_multimap<Ts...>;
template<typename... Ts>
using Vec = std::vector<Ts...>;
template<typename... Ts>
using Stack = std::stack<Ts...>;
template<typename... Ts>
using Queue = std::queue<Ts...>;
template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, Vec<T>, Gt<T>>;
constexpr bool LOCAL = false;
constexpr bool OJ = not LOCAL;
template<typename T>
static constexpr T OjLocal(T oj, T local)
{
return LOCAL ? local : oj;
}
template<typename T>
constexpr T LIMMIN = std::numeric_limits<T>::min();
template<typename T>
constexpr T LIMMAX = std::numeric_limits<T>::max();
template<typename T = i64>
constexpr T INF = (LIMMAX<T> - 1) / 2;
template<typename T = f80>
constexpr T PI = T{3.141592653589793238462643383279502884};
template<typename T = u64>
constexpr T TEN(int n)
{
return n == 0 ? T{1} : TEN<T>(n - 1) * T{10};
}
template<typename T>
constexpr bool chmin(T& a, const T& b)
{
return (a > b ? (a = b, true) : false);
}
template<typename T>
constexpr bool chmax(T& a, const T& b)
{
return (a < b ? (a = b, true) : false);
}
template<typename T>
constexpr T floorDiv(T x, T y)
{
assert(y != 0);
if (y < 0) { x = -x, y = -y; }
return x >= 0 ? x / y : (x - y + 1) / y;
}
template<typename T>
constexpr T ceilDiv(T x, T y)
{
assert(y != 0);
if (y < 0) { x = -x, y = -y; }
return x >= 0 ? (x + y - 1) / y : x / y;
}
template<typename T, typename I>
constexpr T powerMonoid(T v, I n, const T& e)
{
assert(n >= 0);
if (n == 0) { return e; }
return (n % 2 == 1 ? v * powerMonoid(v, n - 1, e) : powerMonoid(v * v, n / 2, e));
}
template<typename T, typename I>
constexpr T powerInt(T v, I n)
{
return powerMonoid(v, n, T{1});
}
template<typename Vs, typename... Args>
constexpr auto accumAll(const Vs& vs, Args... args)
{
return std::accumulate(std::begin(vs), std::end(vs), args...);
}
template<typename Vs>
constexpr auto sumAll(const Vs& vs)
{
return accumAll(vs, decltype(vs[0]){});
}
template<typename Vs>
constexpr auto gcdAll(const Vs& vs)
{
return accumAll(vs, decltype(vs[0]){}, [&](auto v1, auto v2) { return std::gcd(v1, v2); });
}
template<typename Vs, typename V>
constexpr int lbInd(const Vs& vs, const V& v)
{
return std::lower_bound(std::begin(vs), std::end(vs), v) - std::begin(vs);
}
template<typename Vs, typename V>
constexpr int ubInd(const Vs& vs, const V& v)
{
return std::upper_bound(std::begin(vs), std::end(vs), v) - std::begin(vs);
}
template<typename Vs>
constexpr void concat(Vs& vs1, const Vs vs2)
{
std::copy(std::begin(vs2), std::end(vs2), std::back_inserter(vs1));
}
template<typename Vs>
constexpr Vs concatted(Vs vs1, const Vs& vs2)
{
concat(vs1, vs2);
return vs1;
}
template<typename Vs, typename V>
constexpr void fillAll(Vs& arr, const V& v)
{
if constexpr (std::is_convertible<V, Vs>::value) {
arr = v;
} else {
for (auto& subarr : arr) { fillAll(subarr, v); }
}
}
template<typename T, typename F>
constexpr Vec<T> genVec(int n, F gen)
{
Vec<T> ans;
std::generate_n(std::back_inserter(ans), n, gen);
return ans;
}
template<typename Vs>
constexpr auto minAll(const Vs& vs)
{
return *std::min_element(std::begin(vs), std::end(vs));
}
template<typename Vs>
constexpr auto maxInd(const Vs& vs)
{
return *std::max_element(std::begin(vs), std::end(vs));
}
template<typename Vs>
constexpr int minInd(const Vs& vs)
{
return std::min_element(std::begin(vs), std::end(vs)) - std::begin(vs);
}
template<typename Vs>
constexpr int maxInd(const Vs& vs)
{
return std::max_element(std::begin(vs), std::end(vs)) - std::begin(vs);
}
template<typename T = int>
constexpr Vec<T> iotaVec(int n, T offset = 0)
{
Vec<T> ans(n);
std::iota(std::begin(ans), std::end(ans), offset);
return ans;
}
template<typename Vs, typename... Args>
constexpr Vec<int> iotaSort(const Vs& vs, Args... args)
{
auto is = iotaVec(vs.size());
std::sort(std::begin(is), std::end(is), args...);
return is;
}
inline Vec<int> permInv(const Vec<int>& is)
{
auto ris = is;
for (int i = 0; i < (int)is.size(); i++) { ris[is[i]] = i; }
return ris;
}
template<typename Vs, typename V>
constexpr void plusAll(Vs& vs, const V& v)
{
for (auto& v_ : vs) { v_ += v; }
}
template<typename Vs>
constexpr void reverseAll(Vs& vs)
{
std::reverse(std::begin(vs), std::end(vs));
}
template<typename Vs>
constexpr Vs reversed(Vs vs)
{
reverseAll(vs);
return vs;
}
template<typename Vs, typename... Args>
constexpr void sortAll(Vs& vs, Args... args)
{
std::sort(std::begin(vs), std::end(vs), args...);
}
template<typename Vs, typename... Args>
constexpr Vs sorted(Vs vs, Args... args)
{
sortAll(vs, args...);
return vs;
}
inline Ostream& operator<<(Ostream& os, i128 v)
{
bool minus = false;
if (v < 0) { minus = true, v = -v; }
Str ans;
if (v == 0) { ans = "0"; }
while (v) { ans.push_back('0' + v % 10), v /= 10; }
std::reverse(ans.begin(), ans.end());
return os << (minus ? "-" : "") << ans;
}
inline Ostream& operator<<(Ostream& os, u128 v)
{
Str ans;
if (v == 0) { ans = "0"; }
while (v) { ans.push_back('0' + v % 10), v /= 10; }
std::reverse(ans.begin(), ans.end());
return os << ans;
}
constexpr bool isBitOn(u64 mask, int ind) { return (mask >> ind) & 1_u64; }
constexpr bool isBitOff(u64 mask, int ind) { return not isBitOn(mask, ind); }
constexpr int topBit(u64 v) { return v == 0 ? -1 : 63 - __builtin_clzll(v); }
constexpr int lowBit(u64 v) { return v == 0 ? 64 : __builtin_ctzll(v); }
constexpr int bitWidth(u64 v) { return topBit(v) + 1; }
constexpr u64 bitCeil(u64 v) { return v ? (1_u64 << bitWidth(v - 1)) : 1_u64; }
constexpr u64 bitFloor(u64 v) { return v ? (1_u64 << topBit(v)) : 0_u64; }
constexpr bool hasSingleBit(u64 v) { return (v > 0) and ((v & (v - 1)) == 0); }
constexpr u64 bitMask(int bitWidth) { return (bitWidth == 64 ? ~0_u64 : (1_u64 << bitWidth) - 1); }
constexpr u64 bitMask(int start, int end) { return bitMask(end - start) << start; }
constexpr int popCount(u64 v) { return v ? __builtin_popcountll(v) : 0; }
constexpr bool popParity(u64 v) { return v > 0 and __builtin_parity(v) == 1; }
template<typename F>
struct Fix : F
{
constexpr Fix(F&& f) : F{std::forward<F>(f)} {}
template<typename... Args>
constexpr auto operator()(Args&&... args) const
{
return F::operator()(*this, std::forward<Args>(args)...);
}
};
class irange
{
private:
struct itr
{
constexpr itr(i64 start = 0, i64 step = 1) : m_cnt{start}, m_step{step} {}
constexpr bool operator!=(const itr& it) const { return m_cnt != it.m_cnt; }
constexpr i64 operator*() { return m_cnt; }
constexpr itr& operator++() { return m_cnt += m_step, *this; }
i64 m_cnt, m_step;
};
i64 m_start, m_end, m_step;
public:
static constexpr i64 cnt(i64 start, i64 end, i64 step)
{
if (step == 0) { return -1; }
const i64 d = (step > 0 ? step : -step);
const i64 l = (step > 0 ? start : end);
const i64 r = (step > 0 ? end : start);
i64 n = (r - l) / d + ((r - l) % d ? 1 : 0);
if (l >= r) { n = 0; }
return n;
}
constexpr irange(i64 start, i64 end, i64 step = 1)
: m_start{start}, m_end{m_start + step * cnt(start, end, step)}, m_step{step}
{
assert(step != 0);
}
constexpr itr begin() const { return itr{m_start, m_step}; }
constexpr itr end() const { return itr{m_end, m_step}; }
};
constexpr irange rep(i64 end) { return irange(0, end, 1); }
constexpr irange per(i64 rend) { return irange(rend - 1, -1, -1); }
class Scanner
{
public:
Scanner(Istream& is = std::cin) : m_is{is} { m_is.tie(nullptr)->sync_with_stdio(false); }
template<typename T>
T val()
{
T v;
return m_is >> v, v;
}
template<typename T>
T val(T offset)
{
return val<T>() - offset;
}
template<typename T>
Vec<T> vec(int n)
{
return genVec<T>(n, [&]() { return val<T>(); });
}
template<typename T>
Vec<T> vec(int n, T offset)
{
return genVec<T>(n, [&]() { return val<T>(offset); });
}
template<typename T>
Vec<Vec<T>> vvec(int n, int m)
{
return genVec<Vec<T>>(n, [&]() { return vec<T>(m); });
}
template<typename T>
Vec<Vec<T>> vvec(int n, int m, const T offset)
{
return genVec<Vec<T>>(n, [&]() { return vec<T>(m, offset); });
}
template<typename... Args>
auto tup()
{
return Tup<Args...>{val<Args>()...};
}
template<typename... Args>
auto tup(Args... offsets)
{
return Tup<Args...>{val<Args>(offsets)...};
}
private:
Istream& m_is;
};
inline Scanner in;
class Printer
{
public:
Printer(Ostream& os = std::cout) : m_os{os} { m_os << std::fixed << std::setprecision(15); }
template<typename... Args>
int operator()(const Args&... args)
{
return dump(args...), 0;
}
template<typename... Args>
int ln(const Args&... args)
{
return dump(args...), m_os << '\n', 0;
}
template<typename... Args>
int el(const Args&... args)
{
return dump(args...), m_os << std::endl, 0;
}
int YES(bool b = true) { return ln(b ? "YES" : "NO"); }
int NO(bool b = true) { return YES(not b); }
int Yes(bool b = true) { return ln(b ? "Yes" : "No"); }
int No(bool b = true) { return Yes(not b); }
private:
template<typename T>
void dump(const T& v)
{
m_os << v;
}
template<typename T>
void dump(const Vec<T>& vs)
{
for (int i : rep(vs.size())) { m_os << (i ? " " : ""), dump(vs[i]); }
}
template<typename T>
void dump(const Vec<Vec<T>>& vss)
{
for (int i : rep(vss.size())) { m_os << (i ? "\n" : ""), dump(vss[i]); }
}
template<typename T, typename... Ts>
int dump(const T& v, const Ts&... args)
{
return dump(v), m_os << ' ', dump(args...), 0;
}
Ostream& m_os;
};
inline Printer out;
template<typename T, int n, int i = 0>
auto ndVec(int const (&szs)[n], const T x = T{})
{
if constexpr (i == n) {
return x;
} else {
return std::vector(szs[i], ndVec<T, n, i + 1>(szs, x));
}
}
template<typename T, typename F>
inline T binSearch(T ng, T ok, F check)
{
while (std::abs(ok - ng) > 1) {
const T mid = (ok + ng) / 2;
(check(mid) ? ok : ng) = mid;
}
return ok;
}
template<typename T, typename F>
inline T fbinSearch(T ng, T ok, F check, int times)
{
for (auto _temp_name_0 [[maybe_unused]] : rep(times)) {
const T mid = (ok + ng) / 2;
(check(mid) ? ok : ng) = mid;
}
return ok;
}
template<typename T>
constexpr T clampAdd(T x, T y, T min, T max)
{
return std::clamp(x + y, min, max);
}
template<typename T>
constexpr T clampSub(T x, T y, T min, T max)
{
return std::clamp(x - y, min, max);
}
template<typename T>
constexpr T clampMul(T x, T y, T min, T max)
{
if (y < 0) { x = -x, y = -y; }
const T xmin = ceilDiv(min, y);
const T xmax = floorDiv(max, y);
if (x < xmin) {
return min;
} else if (x > xmax) {
return max;
} else {
return x * y;
}
}
template<typename T>
constexpr T clampDiv(T x, T y, T min, T max)
{
return std::clamp(floorDiv(x, y), min, max);
}
template<typename T>
constexpr Pair<T, T> extgcd(const T a, const T b) // [x,y] -> ax+by=gcd(a,b)
{
static_assert(std::is_signed_v<T>, "Signed integer is allowed.");
assert(a != 0 or b != 0);
if (a >= 0 and b >= 0) {
if (a < b) {
const auto [y, x] = extgcd(b, a);
return {x, y};
}
if (b == 0) { return {1, 0}; }
const auto [x, y] = extgcd(b, a % b);
return {y, x - (a / b) * y};
} else {
auto [x, y] = extgcd(std::abs(a), std::abs(b));
if (a < 0) { x = -x; }
if (b < 0) { y = -y; }
return {x, y};
}
}
template<typename T>
constexpr T inverse(const T a, const T mod) // ax=gcd(a,M) (mod M)
{
assert(a > 0 and mod > 0);
auto [x, y] = extgcd(a, mod);
if (x <= 0) { x += mod; }
return x;
}
template<u32 mod_, u32 root_, u32 max2p_>
class modint
{
template<typename U = u32&>
static U modRef()
{
static u32 s_mod = 0;
return s_mod;
}
template<typename U = u32&>
static U rootRef()
{
static u32 s_root = 0;
return s_root;
}
template<typename U = u32&>
static U max2pRef()
{
static u32 s_max2p = 0;
return s_max2p;
}
public:
static_assert(mod_ <= LIMMAX<i32>, "mod(signed int size) only supported!");
static constexpr bool isDynamic() { return (mod_ == 0); }
template<typename U = const u32>
static constexpr std::enable_if_t<mod_ != 0, U> mod()
{
return mod_;
}
template<typename U = const u32>
static std::enable_if_t<mod_ == 0, U> mod()
{
return modRef();
}
template<typename U = const u32>
static constexpr std::enable_if_t<mod_ != 0, U> root()
{
return root_;
}
template<typename U = const u32>
static std::enable_if_t<mod_ == 0, U> root()
{
return rootRef();
}
template<typename U = const u32>
static constexpr std::enable_if_t<mod_ != 0, U> max2p()
{
return max2p_;
}
template<typename U = const u32>
static std::enable_if_t<mod_ == 0, U> max2p()
{
return max2pRef();
}
template<typename U = u32>
static void setMod(std::enable_if_t<mod_ == 0, U> m)
{
assert(1 <= m and m <= LIMMAX<i32>);
modRef() = m;
sinvRef() = {1, 1};
factRef() = {1, 1};
ifactRef() = {1, 1};
}
template<typename U = u32>
static void setRoot(std::enable_if_t<mod_ == 0, U> r)
{
rootRef() = r;
}
template<typename U = u32>
static void setMax2p(std::enable_if_t<mod_ == 0, U> m)
{
max2pRef() = m;
}
constexpr modint() : m_val{0} {}
constexpr modint(i64 v) : m_val{normll(v)} {}
constexpr void setRaw(u32 v) { m_val = v; }
constexpr modint operator-() const { return modint{0} - (*this); }
constexpr modint& operator+=(const modint& m)
{
m_val = norm(m_val + m.val());
return *this;
}
constexpr modint& operator-=(const modint& m)
{
m_val = norm(m_val + mod() - m.val());
return *this;
}
constexpr modint& operator*=(const modint& m)
{
m_val = normll((i64)m_val * (i64)m.val() % (i64)mod());
return *this;
}
constexpr modint& operator/=(const modint& m) { return *this *= m.inv(); }
constexpr modint operator+(const modint& m) const
{
auto v = *this;
return v += m;
}
constexpr modint operator-(const modint& m) const
{
auto v = *this;
return v -= m;
}
constexpr modint operator*(const modint& m) const
{
auto v = *this;
return v *= m;
}
constexpr modint operator/(const modint& m) const
{
auto v = *this;
return v /= m;
}
constexpr bool operator==(const modint& m) const { return m_val == m.val(); }
constexpr bool operator!=(const modint& m) const { return not(*this == m); }
friend Istream& operator>>(Istream& is, modint& m)
{
i64 v;
return is >> v, m = v, is;
}
friend Ostream& operator<<(Ostream& os, const modint& m) { return os << m.val(); }
constexpr u32 val() const { return m_val; }
template<typename I>
constexpr modint pow(I n) const
{
return powerInt(*this, n);
}
constexpr modint inv() const { return inverse<i32>(m_val, mod()); }
static modint sinv(u32 n)
{
auto& is = sinvRef();
for (u32 i = (u32)is.size(); i <= n; i++) { is.push_back(-is[mod() % i] * (mod() / i)); }
return is[n];
}
static modint fact(u32 n)
{
auto& fs = factRef();
for (u32 i = (u32)fs.size(); i <= n; i++) { fs.push_back(fs.back() * i); }
return fs[n];
}
static modint ifact(u32 n)
{
auto& ifs = ifactRef();
for (u32 i = (u32)ifs.size(); i <= n; i++) { ifs.push_back(ifs.back() * sinv(i)); }
return ifs[n];
}
static modint perm(int n, int k) { return k > n or k < 0 ? modint{0} : fact(n) * ifact(n - k); }
static modint comb(int n, int k)
{
return k > n or k < 0 ? modint{0} : fact(n) * ifact(n - k) * ifact(k);
}
private:
static Vec<modint>& sinvRef()
{
static Vec<modint> is{1, 1};
return is;
}
static Vec<modint>& factRef()
{
static Vec<modint> fs{1, 1};
return fs;
}
static Vec<modint>& ifactRef()
{
static Vec<modint> ifs{1, 1};
return ifs;
}
static constexpr u32 norm(u32 x) { return x < mod() ? x : x - mod(); }
static constexpr u32 normll(i64 x) { return norm(u32(x % (i64)mod() + (i64)mod())); }
u32 m_val;
};
using modint_1000000007 = modint<1000000007, 5, 1>;
using modint_998244353 = modint<998244353, 3, 23>;
template<int id>
using modint_dynamic = modint<0, 0, id>;
template<typename T = int>
class Graph
{
struct Edge
{
Edge() = default;
Edge(int i, int t, T c) : id{i}, to{t}, cost{c} {}
int id;
int to;
T cost;
operator int() const { return to; }
};
public:
Graph(int n) : m_v{n}, m_edges(n) {}
void addEdge(int u, int v, bool bi = false)
{
assert(0 <= u and u < m_v);
assert(0 <= v and v < m_v);
m_edges[u].emplace_back(m_e, v, 1);
if (bi) { m_edges[v].emplace_back(m_e, u, 1); }
m_e++;
}
void addEdge(int u, int v, const T& c, bool bi = false)
{
assert(0 <= u and u < m_v);
assert(0 <= v and v < m_v);
m_edges[u].emplace_back(m_e, v, c);
if (bi) { m_edges[v].emplace_back(m_e, u, c); }
m_e++;
}
const Vec<Edge>& operator[](const int u) const
{
assert(0 <= u and u < m_v);
return m_edges[u];
}
Vec<Edge>& operator[](const int u)
{
assert(0 <= u and u < m_v);
return m_edges[u];
}
int v() const { return m_v; }
int e() const { return m_e; }
friend Ostream& operator<<(Ostream& os, const Graph& g)
{
for (int u : rep(g.v())) {
for (const auto& [id, v, c] : g[u]) {
os << "[" << id << "]: ";
os << u << "->" << v << "(" << c << ")\n";
}
}
return os;
}
Vec<T> sizes(int root = 0) const
{
const int N = v();
assert(0 <= root and root < N);
Vec<T> ss(N, 1);
Fix([&](auto dfs, int u, int p) -> void {
for ([[maybe_unused]] const auto& [_temp_name_1, v, c] : m_edges[u]) {
if (v == p) { continue; }
dfs(v, u);
ss[u] += ss[v];
}
})(root, -1);
return ss;
}
Vec<T> depths(int root = 0) const
{
const int N = v();
assert(0 <= root and root < N);
Vec<T> ds(N, 0);
Fix([&](auto dfs, int u, int p) -> void {
for ([[maybe_unused]] const auto& [_temp_name_2, v, c] : m_edges[u]) {
if (v == p) { continue; }
ds[v] = ds[u] + c;
dfs(v, u);
}
})(root, -1);
return ds;
}
Vec<int> parents(int root = 0) const
{
const int N = v();
assert(0 <= root and root < N);
Vec<int> ps(N, -1);
Fix([&](auto dfs, int u, int p) -> void {
for ([[maybe_unused]] const auto& [_temp_name_3, v, c] : m_edges[u]) {
if (v == p) { continue; }
ps[v] = u;
dfs(v, u);
}
})(root, -1);
return ps;
}
private:
int m_v;
int m_e = 0;
Vec<Vec<Edge>> m_edges;
};
template<typename Engine>
class RNG
{
public:
using result_type = typename Engine::result_type;
using T = result_type;
static constexpr T min() { return Engine::min(); }
static constexpr T max() { return Engine::max(); }
RNG() : RNG(std::random_device{}()) {}
RNG(T seed) : m_rng(seed) {}
T operator()() { return m_rng(); }
template<typename T>
T val(T min, T max)
{
return std::uniform_int_distribution<T>(min, max)(m_rng);
}
template<typename T, typename... Args>
auto tup(T min, T max, const Args&... offsets)
{
return Tup<T, Args...>{val<T>(min, max), val<Args>(offsets)...};
}
template<typename T>
Vec<T> vec(int n, T min, T max)
{
return genVec<T>(n, [&]() { return val<T>(min, max); });
}
template<typename T>
Vec<Vec<T>> vvec(int n, int m, T min, T max)
{
return genVec<Vec<T>>(n, [&]() { return vec(m, min, max); });
}
private:
Engine m_rng;
};
inline RNG<std::mt19937> rng;
inline RNG<std::mt19937_64> rng64;
template<u64 mod_, u64 root_, u64 max2p_>
class modint64
{
template<typename U = u64&>
static U modRef()
{
static u64 s_mod = 0;
return s_mod;
}
template<typename U = u64&>
static U rootRef()
{
static u64 s_root = 0;
return s_root;
}
template<typename U = u64&>
static U max2pRef()
{
static u64 s_max2p = 0;
return s_max2p;
}
public:
static_assert(mod_ <= LIMMAX<i64>, "mod(signed int size) only supported!");
static constexpr bool isDynamic() { return (mod_ == 0); }
template<typename U = const u64>
static constexpr std::enable_if_t<mod_ != 0, U> mod()
{
return mod_;
}
template<typename U = const u64>
static std::enable_if_t<mod_ == 0, U> mod()
{
return modRef();
}
template<typename U = const u64>
static constexpr std::enable_if_t<mod_ != 0, U> root()
{
return root_;
}
template<typename U = const u64>
static std::enable_if_t<mod_ == 0, U> root()
{
return rootRef();
}
template<typename U = const u64>
static constexpr std::enable_if_t<mod_ != 0, U> max2p()
{
return max2p_;
}
template<typename U = const u64>
static std::enable_if_t<mod_ == 0, U> max2p()
{
return max2pRef();
}
template<typename U = u64>
static void setMod(std::enable_if_t<mod_ == 0, U> m)
{
assert(1 <= m and m <= LIMMAX<i64>);
modRef() = m;
sinvRef() = {1, 1};
factRef() = {1, 1};
ifactRef() = {1, 1};
}
template<typename U = u64>
static void setRoot(std::enable_if_t<mod_ == 0, U> r)
{
rootRef() = r;
}
template<typename U = u64>
static void setMax2p(std::enable_if_t<mod_ == 0, U> m)
{
max2pRef() = m;
}
constexpr modint64() : m_val{0} {}
constexpr modint64(const i64 v) : m_val{normLL(v)} {}
constexpr void setRaw(const u64 v) { m_val = v; }
constexpr modint64 operator+() const { return *this; }
constexpr modint64 operator-() const { return modint64{0} - (*this); }
constexpr modint64& operator+=(const modint64& m)
{
m_val = norm(m_val + m.val());
return *this;
}
constexpr modint64& operator-=(const modint64& m)
{
m_val = norm(m_val + mod() - m.val());
return *this;
}
constexpr modint64& operator*=(const modint64& m)
{
m_val = normLL((i128)m_val * (i128)m.val() % (i128)mod());
return *this;
}
constexpr modint64& operator/=(const modint64& m) { return *this *= m.inv(); }
constexpr modint64 operator+(const modint64& m) const
{
auto v = *this;
return v += m;
}
constexpr modint64 operator-(const modint64& m) const
{
auto v = *this;
return v -= m;
}
constexpr modint64 operator*(const modint64& m) const
{
auto v = *this;
return v *= m;
}
constexpr modint64 operator/(const modint64& m) const
{
auto v = *this;
return v /= m;
}
constexpr bool operator==(const modint64& m) const { return m_val == m.val(); }
constexpr bool operator!=(const modint64& m) const { return not(*this == m); }
friend Istream& operator>>(Istream& is, modint64& m)
{
i64 v;
return is >> v, m = v, is;
}
friend Ostream& operator<<(Ostream& os, const modint64& m) { return os << m.val(); }
constexpr u64 val() const { return m_val; }
template<typename I>
constexpr modint64 pow(I n) const
{
return powerInt(*this, n);
}
constexpr modint64 inv() const { return inverse<i64>(m_val, mod()); }
modint64 sinv() const { return sinv(m_val); }
static modint64 sinv(u32 n)
{
auto& is = sinvRef();
for (u32 i = (u32)is.size(); i <= n; i++) { is.push_back(-is[mod() % i] * (mod() / i)); }
return is[n];
}
static modint64 fact(u32 n)
{
auto& fs = factRef();
for (u32 i = (u32)fs.size(); i <= n; i++) { fs.push_back(fs.back() * i); }
return fs[n];
}
static modint64 ifact(u32 n)
{
auto& ifs = ifactRef();
for (u32 i = (u32)ifs.size(); i <= n; i++) { ifs.push_back(ifs.back() * sinv(i)); }
return ifs[n];
}
static modint64 perm(int n, int k)
{
return k > n or k < 0 ? modint64{0} : fact(n) * ifact(n - k);
}
static modint64 comb(int n, int k)
{
return k > n or k < 0 ? modint64{0} : fact(n) * ifact(n - k) * ifact(k);
}
private:
static Vec<modint64>& sinvRef()
{
static Vec<modint64> is{1, 1};
return is;
}
static Vec<modint64>& factRef()
{
static Vec<modint64> fs{1, 1};
return fs;
}
static Vec<modint64>& ifactRef()
{
static Vec<modint64> ifs{1, 1};
return ifs;
}
static constexpr u64 norm(const u64 x) { return x < mod() ? x : x - mod(); }
static constexpr u64 normLL(const i64 x)
{
return norm(u64((i128)x % (i128)mod() + (i128)mod()));
}
u64 m_val;
};
template<int id>
using modint64_dynamic = modint64<0, 0, id>;
template<typename mint>
bool millerRabin(u64 n, const Vec<u64>& as)
{
auto d = n - 1;
for (; (d & 1) == 0; d >>= 1) {}
for (const u64 a : as) {
if (n <= a) { break; }
auto s = d;
mint x = mint(a).pow(s);
while (x.val() != 1 and x.val() != n - 1 and s != n - 1) { x *= x, s <<= 1; }
if (x.val() != n - 1 and s % 2 == 0) { return false; }
}
return true;
}
inline bool isPrime(u64 n)
{
using mint = modint_dynamic<873293817>;
using mint64 = modint64_dynamic<828271328>;
if (n == 1) { return false; }
if ((n & 1) == 0) { return n == 2; }
if (n < (1ULL << 30)) {
mint::setMod(n);
return millerRabin<mint>(n, {2, 7, 61});
} else {
mint64::setMod(n);
return millerRabin<mint64>(n, {2, 325, 9375, 28178, 450775, 9780504});
}
}
template<typename mint>
u64 pollardRho(u64 n)
{
if (n % 2 == 0) { return 2; }
if (isPrime(n)) { return n; }
mint c;
auto f = [&](const mint& x) { return x * x + c; };
while (true) {
mint x, y, ys, q = 1;
y = rng64.val<u64>(0, n - 2) + 2;
c = rng64.val<u64>(0, n - 2) + 2;
u64 d = 1;
constexpr u32 dk = 128;
for (u32 r = 1; d == 1; r <<= 1) {
x = y;
for (u32 i = 0; i < r; i++) { y = f(y); }
for (u32 k = 0; k < r and d == 1; k += dk) {
ys = y;
for (u32 i = 0; i < dk and i < r - k; i++) { q *= x - (y = f(y)); }
d = std::gcd((u64)q.val(), n);
}
}
if (d == n) {
do {
d = std::gcd(u64((x - (ys = f(ys))).val()), n);
} while (d == 1);
}
if (d != n) { return d; }
}
return n;
}
Map<u64, int> primeFactors(u64 n)
{
using mint = modint_dynamic<287687412>;
using mint64 = modint64_dynamic<4832432>;
Map<u64, int> ans;
Fix([&](auto dfs, u64 x) -> void {
while ((x & 1) == 0) { x >>= 1, ans[2]++; }
if (x == 1) { return; }
u64 p;
if (x < (1ULL << 30)) {
mint::setMod(x);
p = pollardRho<mint>(x);
} else {
mint64::setMod(x);
p = pollardRho<mint64>(x);
}
if (p == x) {
ans[p]++;
return;
}
dfs(p), dfs(x / p);
})(n);
return ans;
}
Vec<u64> divisors(const u64 n)
{
const auto fs = primeFactors(n);
Vec<u64> ds{1};
for (const auto& [p, e] : fs) {
u64 pe = p;
const u32 dn = ds.size();
for (i32 i = 0; i < e; i++, pe *= p) {
for (u32 j = 0; j < dn; j++) { ds.push_back(ds[j] * pe); }
}
}
return ds;
}
template<typename mint>
class NumberTheoriticTransform
{
// DynamicModint 非対応
static_assert(not mint::isDynamic(), "class NTT: Not support dynamic modint.");
private:
static constexpr u32 MOD = mint::mod();
static constexpr u32 ROOT = mint::root();
static constexpr u32 L_MAX = mint::max2p();
static constexpr int N_MAX = (1 << L_MAX);
public:
static Vec<mint> convolute(Vec<mint> as, Vec<mint> bs)
{
const int AN = as.size();
const int BN = bs.size();
const int CN = AN + BN - 1;
const int N = bitCeil(CN);
as.resize(N, 0), bs.resize(N, 0);
transform(as, false), transform(bs, false);
for (int i : rep(N)) { as[i] *= bs[i]; }
transform(as, true);
as.resize(CN);
return as;
}
static void transform(Vec<mint>& as, bool rev)
{
const int N = as.size();
assert(hasSingleBit(N));
if (N == 1) { return; }
const int L = topBit(N);
const auto l_range = (rev ? irange(1, L + 1, 1) : irange(L, 0, -1));
for (int l : l_range) {
const int H = 1 << l;
const int B = N / H;
for (int b : rep(B)) {
const mint W = zeta(l, rev);
mint W_h = 1;
for (int h : rep(H / 2)) {
const int y1 = H * b + h;
const int y2 = y1 + H / 2;
const mint a1 = as[y1];
const mint a2 = as[y2];
const mint na1 = (rev ? a1 + a2 * W_h : a1 + a2);
const mint na2 = (rev ? a1 - a2 * W_h : (a1 - a2) * W_h);
as[y1] = na1;
as[y2] = na2;
W_h *= W;
}
}
}
if (rev) {
const mint iN = mint::sinv(N);
for (auto& a : as) { a *= iN; }
}
}
private:
static mint zeta(int i, bool rev)
{
static Vec<mint> zs; // zs[i] = 1の2^i乗根
static Vec<mint> izs; // izs[i] = zs[i]の逆元
if (zs.empty()) {
zs.resize(L_MAX + 1, 1);
izs.resize(L_MAX + 1, 1);
zs[L_MAX] = mint(ROOT).pow((MOD - 1) / (1 << L_MAX));
izs[L_MAX] = zs[L_MAX].inv();
for (int l : per(L_MAX)) {
zs[l] = zs[l + 1] * zs[l + 1];
izs[l] = izs[l + 1] * izs[l + 1];
}
}
return (rev ? izs[i] : zs[i]);
}
};
class Garner
{
public:
template<typename mint, typename mint1, typename mint2>
static mint restore_mod(const mint1& x1, const mint2& x2)
{
constexpr auto m1 = mint1::mod();
const auto [y0, y1] = coeff(x1, x2);
return mint(y0.val()) + mint(y1.val()) * m1;
}
template<typename mint, typename mint1, typename mint2, typename mint3>
static mint restore_mod(const mint1& x1, const mint2& x2, const mint3& x3)
{
constexpr auto m1 = mint1::mod();
constexpr auto m2 = mint2::mod();
const auto [y0, y1, y2] = coeff(x1, x2, x3);
return mint(y0.val()) + mint(y1.val()) * m1 + mint(y2.val()) * m1 * m2;
}
template<typename mint1, typename mint2>
static i64 restore_i64(const mint1& x1, const mint2& x2)
{
constexpr u32 m1 = mint1::mod();
constexpr u32 m2 = mint2::mod();
const auto [y0, y1] = coeff(x1, x2);
constexpr u64 MAX = 1_u64 << 63;
const i128 M = (i128)m1 * m2;
i128 S = i128(y0.val()) + i128(y1.val()) * m1;
if (S >= MAX) { S -= M; }
return (i64)S;
}
template<typename mint1, typename mint2, typename mint3>
static i64 restore_i64(const mint1& x1, const mint2& x2, const mint3& x3)
{
constexpr u32 m1 = mint1::mod();
constexpr u32 m2 = mint2::mod();
constexpr u32 m3 = mint3::mod();
const auto [y0, y1, y2] = coeff(x1, x2, x3);
constexpr u64 MAX = 1_u64 << 63;
const i128 M = (i128)m1 * m2 * m3;
i128 S = i128(y0.val()) + i128(y1.val()) * m1 + i128(y2.val()) * m1 * m2;
if (S >= MAX) { S -= M; }
return (i64)S;
}
private:
template<typename mint1, typename mint2>
static Pair<mint1, mint2> coeff(const mint1& x1, const mint2& x2)
{
constexpr auto m1 = mint1::mod();
constexpr mint2 m1_inv = mint2(m1).inv();
const mint1 y0 = x1;
const mint2 y1 = (x2 - mint2(y0.val())) * m1_inv;
return {y0, y1};
}
template<typename mint1, typename mint2, typename mint3>
static Tup<mint1, mint2, mint3> coeff(const mint1& x1, const mint2& x2, const mint3& x3)
{
constexpr auto m1 = mint1::mod();
constexpr auto m2 = mint2::mod();
constexpr mint2 m1_inv = mint2(m1).inv();
constexpr mint3 m1m2_inv = (mint3(m1) * mint3(m2)).inv();
const mint1 y0 = x1;
const mint2 y1 = (x2 - mint2(y0.val())) * m1_inv;
const mint3 y2 = (x3 - mint3(y0.val()) - mint3(y1.val()) * m1) * m1m2_inv;
return {y0, y1, y2};
}
};
template<typename mint>
Vec<mint> convolute_mod(const Vec<mint>& as, const Vec<mint>& bs)
{
constexpr u32 L_MAX = mint::max2p();
constexpr int N_MAX = (1 << L_MAX);
const int AN = as.size();
const int BN = bs.size();
if (AN == 0 or BN == 0) { return {}; }
if (AN > BN) { return convolute_mod(bs, as); }
const int N = AN + BN - 1;
if (AN * 10 <= BN) {
Vec<mint> cs(N, 0);
for (int sj : irange(0, BN, AN)) {
const int tj = std::min(BN, sj + AN);
const auto bbs = Vec<mint>(std::begin(bs) + sj, std::begin(bs) + tj);
const auto bcs = convolute_mod(as, bbs);
for (int dj : rep(bcs.size())) { cs[sj + dj] += bcs[dj]; }
}
return cs;
}
if (N <= N_MAX) {
// mintはNTT Friendlyなのでそのまま畳み込み
return NumberTheoriticTransform<mint>::convolute(as, bs);
} else {
assert(N <= (1 << 24));
using submint1 = modint<469762049, 3, 26>;
using submint2 = modint<167772161, 3, 25>;
using submint3 = modint<754974721, 11, 24>;
// mod 3つでGarner復元
Vec<submint1> as1(AN), bs1(BN);
Vec<submint2> as2(AN), bs2(BN);
Vec<submint3> as3(AN), bs3(BN);
for (int i : rep(AN)) { as1[i] = as[i].val(), as2[i] = as[i].val(), as3[i] = as[i].val(); }
for (int i : rep(BN)) { bs1[i] = bs[i].val(), bs2[i] = bs[i].val(), bs3[i] = bs[i].val(); }
const auto cs1 = NumberTheoriticTransform<submint1>::convolute(as1, bs1);
const auto cs2 = NumberTheoriticTransform<submint2>::convolute(as2, bs2);
const auto cs3 = NumberTheoriticTransform<submint3>::convolute(as3, bs3);
Vec<mint> cs(N);
for (int i : rep(N)) { cs[i] = Garner::restore_mod<mint>(cs1[i], cs2[i], cs3[i]); }
return cs;
}
}
template<typename I>
Vec<i64> convolute_i64(const Vec<I>& as, const Vec<I>& bs)
{
const int AN = as.size();
const int BN = bs.size();
if (AN == 0 or BN == 0) { return {}; }
if (AN > BN) { return convolute_i64<I>(bs, as); }
const int N = AN + BN - 1;
assert(N <= (1 << 24));
if (AN * 2 <= BN) {
Vec<i64> cs(N, 0);
for (int sj : irange(0, BN, AN)) {
const int tj = std::min(BN, sj + AN);
const auto bbs = Vec<I>(std::begin(bs) + sj, std::begin(bs) + tj);
const auto bcs = convolute_i64<I>(as, bbs);
for (int dj : rep(bcs.size())) { cs[sj + dj] += bcs[dj]; }
}
return cs;
}
using submint1 = modint<469762049, 3, 26>;
using submint2 = modint<167772161, 3, 25>;
using submint3 = modint<754974721, 11, 24>;
// mod 3つでGarner復元
Vec<submint1> as1(AN), bs1(BN);
Vec<submint2> as2(AN), bs2(BN);
Vec<submint3> as3(AN), bs3(BN);
for (int i : rep(AN)) { as1[i] = as[i], as2[i] = as[i], as3[i] = as[i]; }
for (int i : rep(BN)) { bs1[i] = bs[i], bs2[i] = bs[i], bs3[i] = bs[i]; }
const auto cs1 = NumberTheoriticTransform<submint1>::convolute(as1, bs1);
const auto cs2 = NumberTheoriticTransform<submint2>::convolute(as2, bs2);
const auto cs3 = NumberTheoriticTransform<submint3>::convolute(as3, bs3);
Vec<i64> cs(N);
for (int i : rep(N)) { cs[i] = Garner::restore_i64(cs1[i], cs2[i], cs3[i]); }
return cs;
}
int main()
{
auto solve = [&]() {
const auto [N, P] = in.tup<int, int>();
using mintP = modint_dynamic<0>;
mintP::setMod(P);
using mint998244353 = modint_998244353;
const auto As = in.vec<int>(N);
int ZN = 0;
for (int A : As) {
if (A == 0) {
ZN++;
}
}
if (ZN == 0) {
out.ln(1, 1);
out.ln(0);
return 0;
}
if (ZN == N) {
out.ln(P, 1);
out.ln(iotaVec(P));
return 0;
}
if (P == 2) {
out.ln(1, 2);
out.ln(1);
return 0;
}
int g = 1; // 原始根
{
Vec<int> ps;
for (const auto& [p, e] : primeFactors(P - 1)) {
ps.push_back(p);
}
for (g = 1; g < P; g++) {
bool ok = true;
for (int p : ps) {
if (mintP(g).pow((P - 1) / p) == 1) {
ok = false;
}
}
if (ok) {
break;
}
}
}
Vec<int> logs(P, -1); // 対数
{
mintP p = 1;
for (int i : rep(P - 1)) {
logs[p.val()] = i;
p *= g;
}
}
Vec<mint998244353> as((P - 1) * 2, 0);
for (int A : As) {
if (A == 0) {
continue;
}
const int l = logs[A];
as[l] = 1, as[l + (P - 1)] = 1;
}
reverseAll(as);
auto check = [&](int M) { // 1 ~ M-1 が含まれるか?
Vec<mint998244353> bs(P - 1, 0);
for (int m : irange(1, M)) {
bs[logs[m]] = 1;
}
int B = 0;
for (int i : rep(P - 1)) {
if (bs[i] != 0) {
B++;
}
}
const auto cs = convolute_mod(as, bs);
Vec<int> ks;
for (int k : rep(P - 1)) {
const auto c = cs[P * 2 - 3 - k];
if (c == B) {
ks.push_back(k);
}
}
return ks;
};
const int M
= binSearch(P + 1, 1, [&](int M) { return not check(M).empty(); });
const auto ks = check(M);
out.ln(ks.size(), M);
Vec<int> cs;
for (int k : ks) {
cs.push_back(mintP(g).pow(P - 1 - k).val());
}
sortAll(cs);
out.ln(cs);
return 0;
};
const auto T = in.val<int>();
for (auto _temp_name_4 [[maybe_unused]] : rep(T)) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3420kb
input:
3 2 3 0 2 3 5 2 3 4 3 5 0 2 3
output:
1 2 2 1 1 0 2 2 2 3
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3416kb
input:
3 1 2 0 1 2 1 2 2 1 0
output:
2 1 0 1 1 1 0 1 2 1
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 2ms
memory: 3520kb
input:
7 1 3 0 1 3 1 2 3 1 0 1 3 2 2 3 2 0 2 3 1 2 3 3 0 1 2
output:
3 1 0 1 2 1 1 0 1 2 1 1 1 0 1 2 2 1 1 0 2 3 1 2
result:
ok 14 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3460kb
input:
31 1 5 0 1 5 1 2 5 1 0 1 5 2 2 5 0 2 2 5 2 1 3 5 1 0 2 1 5 3 2 5 0 3 2 5 1 3 3 5 0 1 3 2 5 3 2 3 5 0 2 3 3 5 2 1 3 4 5 2 0 1 3 1 5 4 2 5 4 0 2 5 1 4 3 5 1 4 0 2 5 2 4 3 5 2 4 0 3 5 4 2 1 4 5 1 0 4 2 2 5 4 3 3 5 0 4 3 3 5 3 1 4 4 5 1 4 3 0 3 5 4 3 2 4 5 2 4 0 3 4 5 2 1 4 3 5 5 1 3 0 2 4
output:
5 1 0 1 2 3 4 1 1 0 1 2 1 1 1 0 1 2 3 1 1 0 1 3 1 1 1 0 1 2 2 1 1 0 1 3 2 1 1 0 2 2 2 3 1 1 0 1 4 1 1 1 0 1 2 4 1 1 0 2 2 1 4 1 1 0 1 3 3 1 1 0 1 4 3 1 1 0 1 3 4 1 1 0 1 4 2 1 1 0 1 4 4 1 1 0 4 5 1 2 3 4
result:
ok 62 lines
Test #5:
score: 0
Accepted
time: 2ms
memory: 3428kb
input:
127 1 7 0 1 7 1 2 7 1 0 1 7 2 2 7 2 0 2 7 2 1 3 7 2 1 0 1 7 3 2 7 3 0 2 7 3 1 3 7 3 1 0 2 7 2 3 3 7 2 0 3 3 7 2 1 3 4 7 2 0 3 1 1 7 4 2 7 0 4 2 7 1 4 3 7 0 1 4 2 7 4 2 3 7 0 4 2 3 7 1 2 4 4 7 2 4 1 0 2 7 4 3 3 7 3 0 4 3 7 3 1 4 4 7 1 0 4 3 3 7 3 2 4 4 7 3 0 2 4 4 7 4 1 3 2 5 7 4 3 0 1 2 1 7 5 2 7 0 ...
output:
7 1 0 1 2 3 4 5 6 1 1 0 1 2 1 1 1 0 1 2 4 1 1 0 1 3 1 1 1 0 1 2 5 1 1 0 2 2 1 5 1 1 0 2 2 4 5 1 1 0 1 4 1 1 1 0 1 2 2 1 1 0 1 3 2 1 1 0 1 3 4 1 1 0 3 3 1 2 4 1 1 0 2 2 2 5 1 1 0 1 3 2 1 1 0 1 3 4 1 1 0 1 5 1 1 1 0 1 2 3 1 1 0 2 2 1 3 1 1 0 2 2 3 4 1 1 0 1 3 1 1 1 0 1 3 3 1 1 0 1 4 3 1 1 0 1 3 3 1 1 ...
result:
ok 254 lines
Test #6:
score: 0
Accepted
time: 12ms
memory: 3464kb
input:
2047 1 11 0 1 11 1 2 11 0 1 1 11 2 2 11 0 2 2 11 2 1 3 11 1 0 2 1 11 3 2 11 3 0 2 11 3 1 3 11 0 3 1 2 11 2 3 3 11 0 2 3 3 11 2 1 3 4 11 1 0 3 2 1 11 4 2 11 0 4 2 11 4 1 3 11 1 4 0 2 11 2 4 3 11 2 0 4 3 11 2 1 4 4 11 0 2 1 4 2 11 3 4 3 11 3 4 0 3 11 3 1 4 4 11 4 1 3 0 3 11 4 3 2 4 11 3 4 0 2 4 11 3 1...
output:
11 1 0 1 2 3 4 5 6 7 8 9 10 1 1 0 1 2 1 1 1 0 1 2 6 1 1 0 1 3 1 1 1 0 1 2 4 1 1 0 2 2 1 4 1 1 0 2 2 4 6 1 1 0 1 4 1 1 1 0 1 2 3 1 1 0 2 2 1 3 1 1 0 1 3 6 1 1 0 2 3 1 6 1 1 0 2 2 3 4 1 1 0 3 2 1 3 4 1 1 0 1 3 6 1 1 0 1 5 1 1 1 0 1 2 9 1 1 0 2 2 1 9 1 1 0 2 2 6 9 1 1 0 1 3 1 1 1 0 2 2 4 9 1 1 0 3 2 1 ...
result:
ok 4094 lines
Test #7:
score: 0
Accepted
time: 82ms
memory: 3492kb
input:
8191 1 13 0 1 13 1 2 13 0 1 1 13 2 2 13 2 0 2 13 2 1 3 13 2 1 0 1 13 3 2 13 0 3 2 13 1 3 3 13 1 0 3 2 13 2 3 3 13 2 0 3 3 13 3 1 2 4 13 1 3 2 0 1 13 4 2 13 4 0 2 13 4 1 3 13 0 1 4 2 13 2 4 3 13 0 2 4 3 13 2 4 1 4 13 0 1 4 2 2 13 3 4 3 13 3 0 4 3 13 4 1 3 4 13 4 1 0 3 3 13 4 2 3 4 13 3 2 0 4 4 13 3 4...
output:
13 1 0 1 2 3 4 5 6 7 8 9 10 11 12 1 1 0 1 2 1 1 1 0 1 2 7 1 1 0 1 3 1 1 1 0 1 2 9 1 1 0 2 2 1 9 1 1 0 2 2 7 9 1 1 0 1 4 1 1 1 0 1 2 10 1 1 0 2 2 1 10 1 1 0 1 3 7 1 1 0 2 3 1 7 1 1 0 2 2 9 10 1 1 0 3 2 1 9 10 1 1 0 1 3 7 1 1 0 1 5 1 1 1 0 1 2 8 1 1 0 2 2 1 8 1 1 0 2 2 7 8 1 1 0 1 3 1 1 1 0 2 2 8 9 1 ...
result:
ok 16382 lines
Test #8:
score: 0
Accepted
time: 131ms
memory: 3432kb
input:
11764 1 17 0 1 17 1 2 17 0 1 1 17 2 2 17 0 2 2 17 2 1 3 17 2 1 0 1 17 3 2 17 3 0 2 17 1 3 3 17 3 0 1 2 17 2 3 3 17 0 3 2 3 17 3 2 1 4 17 3 2 0 1 1 17 4 2 17 0 4 2 17 4 1 3 17 1 4 0 2 17 4 2 3 17 0 2 4 3 17 2 1 4 4 17 2 4 1 0 2 17 3 4 3 17 3 4 0 3 17 4 1 3 4 17 4 1 0 3 3 17 2 4 3 4 17 2 0 3 4 4 17 2 ...
output:
17 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 1 0 1 2 1 1 1 0 1 2 9 1 1 0 1 3 1 1 1 0 1 2 6 1 1 0 2 2 1 6 1 1 0 2 2 6 9 1 1 0 1 4 1 1 1 0 1 2 13 1 1 0 2 2 1 13 1 1 0 1 3 9 1 1 0 2 3 1 9 1 1 0 2 2 6 13 1 1 0 3 2 1 6 13 1 1 0 1 3 9 1 1 0 1 5 1 1 1 0 1 2 7 1 1 0 2 2 1 7 1 1 0 2 2 7 9 1 1 0 1 3 1 1 1 ...
result:
ok 23528 lines
Test #9:
score: 0
Accepted
time: 112ms
memory: 3532kb
input:
10526 1 19 0 1 19 1 2 19 0 1 1 19 2 2 19 2 0 2 19 2 1 3 19 0 2 1 1 19 3 2 19 0 3 2 19 3 1 3 19 1 0 3 2 19 3 2 3 19 2 0 3 3 19 1 3 2 4 19 1 2 0 3 1 19 4 2 19 0 4 2 19 4 1 3 19 0 1 4 2 19 4 2 3 19 4 0 2 3 19 2 4 1 4 19 4 2 0 1 2 19 4 3 3 19 0 3 4 3 19 1 3 4 4 19 3 4 0 1 3 19 4 3 2 4 19 0 4 3 2 4 19 1 ...
output:
19 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 1 0 1 2 1 1 1 0 1 2 10 1 1 0 1 3 1 1 1 0 1 2 13 1 1 0 2 2 1 13 1 1 0 2 2 10 13 1 1 0 1 4 1 1 1 0 1 2 5 1 1 0 2 2 1 5 1 1 0 1 3 10 1 1 0 2 3 1 10 1 1 0 2 2 5 13 1 1 0 3 2 1 5 13 1 1 0 1 3 10 1 1 0 1 5 1 1 1 0 1 2 4 1 1 0 2 2 1 4 1 1 0 2 2 4 10 1 1...
result:
ok 21052 lines
Test #10:
score: 0
Accepted
time: 279ms
memory: 3504kb
input:
10000 9 83 60 35 63 59 58 81 0 13 71 1 5 0 1 7 0 2 61 39 0 2 7 0 4 1 7 0 2 19 0 14 1 2 0 3 23 14 10 0 3 11 0 5 2 1 5 0 2 7 0 4 2 3 0 2 2 3 0 1 1 13 0 5 47 10 2 34 15 0 1 2 0 1 17 0 1 11 0 2 7 1 0 1 7 0 2 23 0 17 2 13 10 0 2 7 1 0 6 31 19 13 6 29 0 24 4 23 0 5 18 17 2 19 0 5 1 7 0 2 13 7 0 3 17 0 6 1...
output:
2 3 38 76 5 1 0 1 2 3 4 7 1 0 1 2 3 4 5 6 1 2 36 1 2 2 7 1 0 1 2 3 4 5 6 1 2 15 2 1 0 1 2 2 5 7 2 2 6 9 5 1 0 1 2 3 4 1 2 2 1 2 2 1 2 1 13 1 0 1 2 3 4 5 6 7 8 9 10 11 12 4 2 18 22 24 33 2 1 0 1 17 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 11 1 0 1 2 3 4 5 6 7 8 9 10 1 2 1 7 1 0 1 2 3 4 5 6 1 2 19 1...
result:
ok 20000 lines
Test #11:
score: 0
Accepted
time: 343ms
memory: 3600kb
input:
10000 10 11 6 8 0 1 7 3 2 9 4 5 21 23 21 19 10 17 11 20 6 3 2 18 9 16 13 14 4 12 8 7 1 0 15 7 7 6 2 4 0 1 5 3 17 19 4 6 5 11 17 15 0 10 3 8 12 18 13 7 9 2 14 15 17 11 15 8 2 12 3 1 13 16 6 7 0 9 10 5 2 2 0 1 2 2 0 1 33 37 11 20 9 16 19 32 33 31 3 29 36 10 8 25 22 17 5 6 15 28 14 0 4 27 18 12 34 21 3...
output:
1 10 1 1 19 4 6 7 1 2 3 4 5 6 1 14 14 1 14 12 1 2 1 1 2 1 2 21 21 24 1 8 8 6 7 1 2 3 4 5 6 10 11 1 2 3 4 5 6 7 8 9 10 1 22 22 1 6 1 1 10 11 1 26 22 2 3 1 2 1 14 16 22 23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2 4 2 6 1 18 3 6 7 1 2 3 4 5 6 1 2 1 1 8 7 1 28 15 1 42 22 1 18 8 12 13 1...
result:
ok 20000 lines
Test #12:
score: 0
Accepted
time: 320ms
memory: 3500kb
input:
10000 4 13 4 5 0 6 12 31 0 16 11 13 3 24 26 21 20 6 5 19 12 43 29 21 40 23 31 24 27 17 30 10 0 42 3 3 0 2 1 15 47 41 46 0 44 17 39 30 4 12 14 36 28 27 31 10 1 5 0 5 11 6 2 0 5 1 6 13 11 0 7 5 10 6 5 17 15 0 9 12 11 6 13 0 5 2 12 11 7 15 43 14 28 13 24 40 29 37 9 27 0 34 39 15 12 2 1 3 0 8 17 15 6 0 ...
output:
3 2 8 10 11 1 6 6 2 3 33 41 2 3 1 2 3 3 31 37 41 5 1 0 1 2 3 4 2 3 1 2 2 3 4 8 4 2 2 8 10 14 1 3 12 1 4 14 3 1 0 1 2 1 4 8 2 1 0 1 3 2 4 9 10 4 2 1 3 5 12 1 2 3 5 2 3 12 15 16 18 7 1 0 1 2 3 4 5 6 5 2 2 5 15 16 18 10 2 2 6 8 11 19 25 27 29 34 35 3 2 2 7 9 1 2 2 3 3 7 14 15 2 5 36 42 1 2 4 2 3 13 14 ...
result:
ok 20000 lines
Test #13:
score: 0
Accepted
time: 333ms
memory: 3484kb
input:
10000 13 19 13 6 0 9 15 2 4 10 3 5 11 12 14 5 11 5 8 10 0 6 2 3 0 1 1 2 0 10 19 6 16 2 1 17 0 4 10 5 7 4 7 0 1 4 2 41 73 55 47 13 35 18 68 3 25 67 36 70 69 62 37 56 64 49 72 12 0 4 17 31 8 66 63 2 16 65 60 24 26 7 21 33 52 54 39 29 53 71 1 3 0 26 61 43 0 37 54 47 49 17 38 19 28 35 18 39 36 33 34 8 2...
output:
1 6 13 2 3 7 9 1 2 1 2 1 0 1 1 4 10 3 3 1 2 4 1 12 72 3 1 0 1 2 2 5 10 17 1 7 11 1 7 27 1 4 8 2 3 1 2 2 3 1 2 1 2 1 1 2 2 1 6 6 1 8 31 1 4 13 1 3 3 1 4 12 3 5 1 2 7 1 7 5 1 2 4 3 1 0 1 2 2 1 0 1 2 4 4 6 1 2 4 2 2 1 10 2 4 10 12 2 4 4 6 1 2 2 2 6 3 5 7 1 0 1 2 3 4 5 6 2 4 2 6 2 3 1 11 1 2 1 1 3 2 1 4...
result:
ok 20000 lines
Test #14:
score: 0
Accepted
time: 336ms
memory: 3588kb
input:
10000 2 3 0 2 38 61 50 55 35 52 17 40 15 51 39 11 5 41 2 33 49 25 0 24 53 13 30 59 9 34 57 37 38 27 29 1 19 31 46 8 45 58 6 42 11 17 5 13 1 11 2 0 6 7 4 12 10 6 11 3 0 4 7 10 6 21 29 17 14 7 18 20 28 23 25 16 3 22 5 21 2 0 9 13 1 12 11 19 5 5 0 3 2 1 4 20 23 19 16 0 1 15 18 14 12 21 6 22 8 11 13 20 ...
output:
1 2 2 2 10 15 45 1 7 3 1 5 8 2 8 7 24 4 5 1 2 3 4 1 14 20 1 9 16 1 6 7 1 7 29 1 6 6 2 2 1 4 1 6 8 1 3 4 2 4 2 3 1 8 5 1 7 8 2 4 1 3 1 6 3 1 9 14 1 6 5 1 2 1 2 7 11 22 1 8 12 2 5 2 8 2 6 3 10 1 7 2 1 4 2 1 2 1 1 4 1 1 5 11 1 14 28 2 3 1 2 1 2 1 1 10 8 1 8 6 1 6 5 1 16 2 1 8 22 2 3 1 2 2 10 11 19 1 11...
result:
ok 20000 lines
Test #15:
score: 0
Accepted
time: 379ms
memory: 3504kb
input:
10000 17 17 1 5 10 2 16 6 12 13 15 3 8 9 11 4 14 7 0 67 67 34 11 54 25 8 40 33 24 2 44 22 5 28 46 23 59 30 1 38 18 55 15 35 6 39 64 27 51 65 12 52 53 58 20 14 19 29 43 0 9 62 45 41 42 47 49 31 32 26 57 37 48 7 36 17 13 10 50 63 3 16 21 4 61 66 56 60 3 3 1 0 2 3 3 2 0 1 5 5 4 0 2 1 3 13 13 8 1 5 10 4...
output:
16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 66 67 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 2 3 1 2 2 3 1 2 4 5 1 2 3 4 12 13 1 2 3 4 5 6 7 8 9 10 11 12...
result:
ok 20000 lines
Test #16:
score: 0
Accepted
time: 711ms
memory: 3624kb
input:
1000 2 11 0 1 23 173 145 124 4 130 41 45 115 53 102 156 68 85 49 100 114 75 0 90 81 96 93 61 91 37 293 0 206 166 68 220 15 58 256 125 182 239 67 116 32 114 261 8 106 137 89 130 120 128 202 75 2 110 5 233 133 145 74 259 164 264 10 56 19 181 18 165 71 52 170 177 81 114 124 46 103 20 43 94 144 96 0 125...
output:
1 2 1 2 3 50 60 1 4 176 18 2 27 38 42 44 45 51 52 58 66 80 94 100 122 127 147 148 171 172 5 2 3 9 13 23 33 1 3 126 3 3 101 318 624 1 3 16 1 3 60 8 2 8 10 24 31 32 38 39 44 1 3 35 8 2 17 19 24 44 51 59 61 69 5 3 44 95 108 126 216 6 3 82 100 284 471 479 501 2 3 276 298 5 3 72 181 186 199 293 1 3 52 3 ...
result:
ok 2000 lines
Test #17:
score: 0
Accepted
time: 746ms
memory: 3672kb
input:
1000 451 503 279 78 450 47 182 318 120 215 45 315 292 384 143 122 251 427 230 276 128 314 130 203 146 85 157 312 24 190 316 126 370 271 322 207 465 63 372 99 466 469 211 167 407 180 307 326 458 213 144 217 106 33 414 495 66 421 189 62 417 346 111 232 260 89 366 502 429 86 282 353 161 138 491 183 240...
output:
1 54 73 1 45 97 1 60 71 1 41 53 1 54 48 1 50 15 1 66 362 1 27 22 3 34 327 413 476 1 22 20 1 72 123 1 62 137 1 41 107 1 40 34 1 30 104 1 49 151 1 33 152 1 40 6 1 61 52 2 3 1 2 1 60 119 1 48 288 1 51 62 1 12 7 1 31 23 1 37 38 1 39 31 1 70 79 1 35 42 1 43 55 1 69 3 1 59 255 1 34 42 3 42 224 350 496 1 4...
result:
ok 2000 lines
Test #18:
score: 0
Accepted
time: 741ms
memory: 3640kb
input:
1000 205 647 447 128 382 69 202 453 358 585 306 177 471 296 318 183 345 324 457 241 36 558 605 612 148 104 577 84 580 339 5 288 362 409 320 4 131 405 95 165 287 629 448 63 533 377 134 553 611 138 407 463 450 560 581 8 576 178 591 441 142 123 641 504 360 515 567 347 329 172 478 305 483 432 267 311 3 ...
output:
2 7 225 290 3 7 7 27 54 1 6 54 1 4 17 1 6 202 1 5 71 1 3 8 1 7 98 2 2 4 14 4 4 12 36 57 102 2 5 12 81 2 4 1 117 1 7 57 2 5 30 47 1 6 86 9 3 13 19 21 28 34 66 72 87 96 2 1 0 1 1 9 114 3 4 2 13 46 2 4 16 108 2 4 55 137 2 4 12 13 2 3 5 10 1 5 3 1 5 135 1 6 157 3 5 278 451 468 1 4 11 1 8 99 2 4 38 92 1 ...
result:
ok 2000 lines
Test #19:
score: 0
Accepted
time: 742ms
memory: 3708kb
input:
1000 94 193 184 174 163 185 118 147 125 21 155 93 188 36 112 10 95 101 64 128 179 35 48 43 42 150 108 23 31 104 3 120 2 78 84 53 25 69 116 97 71 0 59 98 83 160 85 90 117 121 61 102 30 191 19 135 56 29 55 173 24 15 47 89 16 161 154 114 124 146 109 144 111 182 14 183 60 74 140 148 157 138 170 115 86 6...
output:
1 12 131 1 8 38 1 6 14 1 9 35 5 3 5 8 10 25 31 1 4 3 1 10 247 1 10 39 1 11 495 2 12 77 252 1 12 662 2 3 4 9 1 10 528 1 8 76 1 10 177 1 10 31 2 11 159 185 1 6 1 1 13 162 1 7 118 2 7 98 147 1 8 59 1 8 56 1 12 387 1 7 3 1 11 47 1 8 64 1 6 18 4 6 23 38 100 131 1 9 2 1 8 21 2 6 38 67 1 5 9 2 3 1 2 3 6 10...
result:
ok 2000 lines
Test #20:
score: 0
Accepted
time: 702ms
memory: 3696kb
input:
1000 131 199 51 45 85 104 37 139 44 158 116 53 185 29 32 43 173 72 142 149 195 152 112 180 41 64 110 188 182 102 60 87 140 132 70 109 8 76 171 133 198 96 130 46 86 19 192 2 63 124 100 143 159 164 6 161 146 194 127 155 82 184 88 34 118 7 35 99 111 168 186 154 151 147 59 157 160 131 172 163 81 36 119 ...
output:
1 10 53 1 17 11 1 17 142 1 19 40 1 13 44 2 8 32 36 2 15 71 301 2 17 295 327 2 10 3 21 1 19 30 1 3 2 1 18 767 1 19 159 1 8 7 1 21 89 1 14 223 1 17 219 1 26 176 1 12 149 1 13 24 1 17 77 4 4 8 12 13 17 1 6 2 1 15 263 2 3 1 2 3 13 30 36 45 1 13 125 4 15 282 474 554 557 1 19 95 1 10 4 1 12 3 1 13 10 1 4 ...
result:
ok 2000 lines
Test #21:
score: 0
Accepted
time: 802ms
memory: 3744kb
input:
1000 139 139 44 102 101 91 113 62 65 127 137 18 103 42 53 10 52 87 4 89 78 70 55 132 123 121 83 5 8 29 58 100 71 34 33 106 138 3 110 43 59 117 107 32 82 22 14 30 47 77 73 133 72 97 21 86 6 49 9 90 126 23 19 80 41 85 26 61 75 125 122 105 15 60 88 135 56 46 79 94 63 129 17 98 74 13 16 108 112 96 39 7 ...
output:
138 139 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
result:
ok 2000 lines
Test #22:
score: 0
Accepted
time: 1182ms
memory: 3956kb
input:
100 2 491 245 0 25 3413 0 1988 1276 1798 1323 708 3299 287 960 2934 3141 3327 1417 3275 1929 3347 3352 672 506 1711 1249 1874 449 3036 971 8 1019 599 691 470 85 451 976 0 471 1 109 0 12 757 739 335 553 468 348 105 257 477 213 0 151 42 61 5333 1044 5282 971 2923 80 154 4976 326 3659 0 1378 2457 2663 ...
output:
1 2 489 24 2 57 344 1014 1029 1075 1119 1125 1195 1389 1431 1695 1803 1946 1970 2197 2216 2286 2340 2667 2942 2973 3034 3051 3189 7 2 12 233 479 761 782 794 871 109 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47...
result:
ok 200 lines
Test #23:
score: 0
Accepted
time: 1344ms
memory: 4612kb
input:
100 278 2833 79 302 1453 2747 2818 2216 1785 1563 2081 1580 958 1791 1307 483 12 921 2781 1634 783 1046 1878 859 1736 1612 2801 1208 2575 2824 1629 585 762 2230 194 2125 2180 2179 2405 1821 1585 453 1383 447 235 2692 1278 506 1948 1571 1666 720 1667 1475 2509 2647 1309 1151 898 977 1313 308 1683 641...
output:
1 4 1682 3 4 676 1143 1951 1 6 754 1 5 1733 3 4 114 1044 1296 3 4 412 417 432 1 4 34 1 5 964 10 3 96 267 468 501 543 598 609 666 749 769 2 4 748 1333 1 3 114 2 4 56 477 1 4 2188 1 5 919 13 2 5 19 20 46 47 56 67 83 87 90 95 97 136 1 5 4775 4 3 11 22 134 191 1 5 2161 4 4 379 3009 4734 5096 1 5 809 2 4...
result:
ok 200 lines
Test #24:
score: 0
Accepted
time: 1245ms
memory: 4004kb
input:
100 2060 2273 767 1795 435 985 57 1932 247 89 939 41 664 2242 2040 814 2013 2271 958 2222 1494 1456 2143 582 184 667 506 2238 1142 2031 1727 1091 493 1429 1145 728 1985 1964 792 992 410 452 545 1187 2052 2117 234 2004 1421 2132 2070 313 1157 748 240 758 1578 1024 2173 1789 1898 1074 1169 1049 765 41...
output:
1 92 1466 2 58 21 135 1 70 1178 1 80 858 1 57 383 1 80 1407 1 69 273 1 38 53 1 51 170 1 91 542 1 1 0 1 110 815 1 87 641 1 80 915 1 133 1190 1 38 80 1 53 51 1 75 594 1 61 150 1 93 4662 1 95 471 1 86 286 1 74 2157 1 76 1051 1 63 1096 1 77 525 1 99 356 1 76 1065 1 59 943 1 123 822 2 54 1832 1998 1 98 7...
result:
ok 200 lines
Test #25:
score: 0
Accepted
time: 1190ms
memory: 3944kb
input:
100 325 1129 292 583 603 223 698 338 1122 10 867 705 652 602 51 140 584 782 1118 487 534 628 819 81 554 40 200 162 955 927 333 456 992 201 1064 310 124 557 94 985 675 515 189 1024 516 884 398 91 407 663 837 556 968 1073 90 281 561 160 259 888 308 102 482 330 855 141 288 787 372 279 480 690 600 179 1...
output:
2 6 770 1017 1 8 58 1 7 474 3 8 917 1661 2053 2 5 355 557 1 7 99 1 7 695 2 4 14 16 1 7 1884 1 7 4505 7 4 22 108 161 211 357 458 497 1 8 1660 1 4 3 1 5 281 1 6 391 1 9 4391 4 6 347 417 444 702 1 7 1112 1 9 377 2 6 229 337 1 8 518 1 9 973 3 4 22 33 53 2 7 100 1396 1 8 1930 1 5 42 1 7 343 1 6 193 12 5 ...
result:
ok 200 lines
Test #26:
score: 0
Accepted
time: 1287ms
memory: 3960kb
input:
100 458 929 631 686 117 194 405 237 831 288 35 447 400 865 229 909 679 162 630 520 812 324 576 496 535 43 0 244 56 305 750 396 645 927 606 823 258 758 767 386 203 918 910 233 659 884 746 85 212 365 617 329 209 900 678 915 97 885 817 836 802 335 733 572 755 742 563 410 167 289 7 453 388 443 281 190 6...
output:
1 10 86 1 11 273 1 9 65 1 10 759 1 13 509 1 13 658 1 6 20 1 10 38 1 3 6 2 10 102 222 1 13 2369 1 16 1772 3 8 77 111 356 1 11 1306 2 12 173 231 1 10 520 2 9 156 502 1 16 4193 1 9 64 2 10 158 165 1 12 233 4 5 43 48 49 52 1 10 112 1 11 672 1 15 772 1 10 818 1 15 515 1 14 3648 2 13 248 562 3 10 29 797 8...
result:
ok 200 lines
Test #27:
score: 0
Accepted
time: 1306ms
memory: 4644kb
input:
100 541 761 343 550 71 112 606 707 375 414 248 50 342 198 338 590 571 759 280 387 196 561 55 533 143 210 725 315 539 351 440 673 286 177 160 359 404 139 335 254 205 575 36 543 169 760 641 723 567 433 127 403 629 537 321 584 199 110 408 468 532 452 273 372 682 134 184 492 121 490 451 51 354 300 190 4...
output:
3 20 269 460 655 2 20 185 723 1 18 197 1 20 263 2 9 41 47 1 13 43 1 28 3345 1 28 3724 1 24 2034 1 15 120 1 18 574 1 29 4920 1 20 623 1 17 723 3 16 315 545 548 1 22 115 2 20 1032 1270 2 14 130 590 1 17 314 1 17 281 1 22 22 1 13 210 1 23 1031 1 18 365 1 10 103 1 25 4825 1 25 434 1 22 563 1 22 208 1 36...
result:
ok 200 lines
Test #28:
score: 0
Accepted
time: 1365ms
memory: 4668kb
input:
100 1423 1423 232 525 930 123 280 654 145 484 778 386 628 1039 804 45 1370 592 705 934 947 597 1278 645 696 115 1307 308 578 993 1287 193 1010 885 582 136 738 32 1250 1377 183 177 1416 11 370 1053 1418 65 48 448 175 792 529 797 14 179 631 847 38 1063 1390 656 1043 873 1027 690 634 604 9 1160 557 727...
output:
1422 1423 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...
result:
ok 200 lines
Test #29:
score: 0
Accepted
time: 2305ms
memory: 8876kb
input:
10 7993 7993 7925 7104 7311 3183 1053 6564 7074 4967 769 2958 7364 7232 4315 5949 3871 6024 6222 7981 3702 4434 2732 7588 7526 212 6127 1219 3637 393 7229 7493 207 4957 2577 7659 7389 3444 4444 5811 7916 2555 6587 6486 2659 263 1027 7547 5206 4467 1291 6851 6590 4262 3549 6092 4015 1054 4635 2112 78...
output:
7992 7993 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...
result:
ok 20 lines
Test #30:
score: 0
Accepted
time: 1865ms
memory: 8556kb
input:
10 6 29573 4370 20998 3600 28860 19784 0 5 32749 0 12773 8683 10478 4415 2 13901 10071 0 3 44701 44237 0 26317 1 8609 0 2 11503 965 0 1 1297 0 4 23801 16480 0 129 2134 2 15749 0 13316 3 18061 8349 14239 0
output:
5 2 1339 8959 9353 11054 11457 4 2 8649 10136 18315 23183 1 2 5339 2 2 8610 12813 8609 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73...
result:
ok 20 lines
Test #31:
score: 0
Accepted
time: 2137ms
memory: 8568kb
input:
10 2423 24659 5046 2123 2304 6184 2778 20409 6089 3720 4310 18664 13348 12437 13958 4335 4413 1884 1087 5028 6866 22156 4105 4092 13443 8532 5846 7747 3505 5005 21019 676 13790 17528 10848 15377 21546 14315 15756 15218 10311 1446 23146 8594 10674 12156 8953 140 8060 24490 3029 16358 463 15940 13432 ...
output:
5 5 4381 6907 14172 17902 18142 3 4 1522 3926 5351 2 5 6532 7303 1 6 10366 4 4 1770 4101 4676 5374 1 5 1176 1 6 1981 2 4 1390 1699 33 4 81 1736 2127 2638 3146 4289 4583 4839 5476 6074 7007 10401 11309 11483 12768 12931 13986 14543 16784 19765 20142 20295 20383 21183 22360 22732 23601 23871 23970 249...
result:
ok 20 lines
Test #32:
score: 0
Accepted
time: 1664ms
memory: 6336kb
input:
10 27791 30983 15484 22415 13855 15495 17417 9408 5123 8201 24203 13154 25137 9681 27394 10408 20395 18547 25950 24567 25061 24920 773 9609 10480 11830 6858 9233 6136 20982 30875 26573 3305 21872 2955 12610 29955 14537 26504 1477 6883 4210 19950 30204 15488 22180 7751 3877 12936 1954 23082 3067 2211...
output:
1 96 29718 1 117 14014 1 121 676 1 77 2150 1 92 3657 1 106 34715 1 87 7860 1 105 25966 1 57 787 1 94 177
result:
ok 20 lines
Test #33:
score: 0
Accepted
time: 1961ms
memory: 9204kb
input:
10 2197 7253 4947 2552 2524 6057 6284 1032 3475 3699 1434 3626 525 1132 2657 5390 3530 5146 1810 4053 2581 4971 2580 3675 5961 1518 1570 4229 1835 2569 6481 3963 7165 6106 1250 243 6800 3308 6364 3610 4199 4440 6502 5411 4256 2543 3480 248 199 502 4770 855 6444 834 4068 1979 828 6381 3289 5777 550 2...
output:
1 9 3045 5 8 4970 13431 20984 33828 36158 1 11 59537 1 8 1253 1 8 3478 2 9 17710 17780 2 6 106 848 1 9 2195 1 10 15194 3 8 11931 13343 14440
result:
ok 20 lines
Test #34:
score: 0
Accepted
time: 1860ms
memory: 6272kb
input:
10 10732 21503 5683 15374 12701 19032 10507 12795 1334 1404 21391 1027 3552 8963 13872 14945 15569 15572 10912 1822 20461 13019 8576 17448 4672 6110 4209 707 3927 7451 8667 4007 7615 710 6310 21201 7136 13435 16735 154 16694 18189 7684 21274 12268 4130 5491 7811 6140 11633 8446 2624 17019 7920 10474...
output:
1 17 20702 1 16 21888 2 12 3680 5170 1 16 5625 1 20 2761 1 21 24305 1 14 6683 7 12 944 2237 10032 10812 11205 12166 12888 4 11 1052 2640 3792 3831 4 13 3808 7602 20524 21531
result:
ok 20 lines
Test #35:
score: 0
Accepted
time: 1952ms
memory: 8900kb
input:
10 524 773 667 450 19 239 437 182 579 564 254 689 674 568 236 642 529 352 706 599 107 460 534 279 609 93 742 268 372 327 519 464 301 1 650 63 586 110 726 293 756 167 643 765 478 355 595 416 153 241 342 501 413 592 377 234 358 755 444 224 67 440 20 491 490 258 64 71 607 271 219 533 576 278 614 461 21...
output:
3 15 178 184 718 1 28 2829 1 32 27180 1 28 22059 1 28 1438 1 17 336 1 29 22502 1 27 32920 1 29 2798 1 24 1701
result:
ok 20 lines
Test #36:
score: 0
Accepted
time: 1999ms
memory: 8676kb
input:
10 55139 55147 43591 14674 26899 25678 7528 27223 50766 26393 8233 38072 48273 11188 3478 22018 43098 49708 3270 10438 34716 13303 367 37148 18286 6347 16390 54154 26514 14544 15497 64 10056 54185 35896 15281 50172 41743 25645 51612 9194 16557 52163 28025 53759 13376 40211 18493 40247 28008 17856 28...
output:
1 42928 45416 2062 2063 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 ...
result:
ok 20 lines
Test #37:
score: 0
Accepted
time: 3202ms
memory: 24676kb
input:
3 10 6229 936 0 3568 131 2226 5474 5841 4624 811 3690 3 5003 2742 3138 0 194 188753 9780 132848 63101 60942 103103 57318 94142 146741 92155 152668 99413 0 2458 52221 186156 3674 63659 107568 83495 165348 52178 4895 61439 129362 103436 18413 104367 11745 8846 75016 92768 36276 95958 28532 88715 18473...
output:
9 2 33 594 951 1765 2381 3587 3607 4207 6045 2 2 1293 1633 193 2 388 947 1570 1634 3791 4724 7893 9854 10285 11708 12222 12356 16371 16837 17146 18507 19318 20024 20207 21969 23566 23818 24025 24582 25145 25736 27899 28322 32039 32592 33216 33228 33582 34539 35400 36181 37008 38377 39650 39725 39984...
result:
ok 6 lines
Test #38:
score: 0
Accepted
time: 2088ms
memory: 9484kb
input:
3 7324 72883 69476 35362 1897 35280 11920 57530 19677 42324 59798 46378 18674 18684 66354 25975 56319 31885 71554 35609 34553 49645 51808 67557 37781 30289 10237 37438 7659 863 50230 30149 55431 27452 50140 61315 33663 19352 60530 71359 32459 58060 4946 60040 22885 64125 20139 29402 61391 54765 1104...
output:
8 5 3128 9288 30119 31145 35211 44216 48739 50132 9 5 8194 16753 24817 25891 44727 51564 54840 62685 67247 4 5 3398 4236 10648 32107
result:
ok 6 lines
Test #39:
score: 0
Accepted
time: 1891ms
memory: 16932kb
input:
3 3336 3691 150 3577 837 3252 3215 688 3065 847 684 2297 2299 664 3367 813 3525 3689 89 1184 465 3384 1682 1873 1589 3450 1901 485 1841 1071 2509 1139 2222 818 1073 756 2916 850 18 2924 2191 3208 2433 3059 1492 2700 3653 411 218 1302 2358 1192 1054 1168 1378 1819 694 742 3078 2611 3490 2492 3406 179...
output:
1 69 3476 1 120 158632 1 98 25197
result:
ok 6 lines
Test #40:
score: 0
Accepted
time: 2887ms
memory: 15988kb
input:
3 29482 98327 2401 5690 97393 52140 27527 73599 49060 17544 70399 62248 43291 9316 34579 21595 57560 45335 31698 1248 55882 66221 61324 69877 57188 70014 72762 58031 59459 30185 35956 25834 50853 56778 12866 84131 18707 21922 41692 69640 92830 36719 5543 66512 88069 82962 75684 1391 78806 48654 3571...
output:
1 12 27533 3 10 12754 49569 51467 1 10 7458
result:
ok 6 lines
Test #41:
score: 0
Accepted
time: 1941ms
memory: 16424kb
input:
3 56 127 50 111 93 22 59 67 39 120 47 62 116 23 0 53 90 5 71 64 55 85 51 52 92 117 1 82 119 14 105 70 69 114 95 68 75 86 61 35 107 80 2 4 103 81 33 36 87 113 49 29 54 77 60 102 104 3 82927 165799 76622 139290 127619 21990 36319 54588 152606 69597 61378 43351 150153 33583 113121 72865 48173 137687 39...
output:
2 6 1 111 1 20 161037 1 20 24239
result:
ok 6 lines
Test #42:
score: 0
Accepted
time: 3023ms
memory: 15952kb
input:
3 68212 97883 41613 93058 19573 73851 62282 69643 56409 53457 21509 20653 65680 28307 59422 80222 52524 8346 39305 13162 49862 5652 43520 75167 24860 75787 83685 65826 47125 53162 64324 63362 70391 67587 31449 62709 60273 96664 45275 9765 37794 74517 15712 88046 94537 4923 16183 6941 69631 47063 150...
output:
2 32 18760 33126 1 25 2740 1 33 57992
result:
ok 6 lines
Test #43:
score: 0
Accepted
time: 2029ms
memory: 15184kb
input:
3 25714 25717 15088 22526 5758 21483 8453 17743 25319 15764 21083 7328 18066 17235 9642 4563 20770 23121 3247 8699 2930 5810 9370 5455 4297 17750 16788 22657 18184 24486 1002 2131 1606 4224 10753 9830 12768 20196 3624 1237 13294 25604 8730 16226 8719 16905 11799 24790 22773 21000 18347 15261 25372 2...
output:
1 25174 17276 1 79689 137881 1 20458 12495
result:
ok 6 lines
Test #44:
score: 0
Accepted
time: 1719ms
memory: 17572kb
input:
2 23 171541 98697 0 29405 42501 163488 157726 133732 25890 122616 57073 21492 23035 12755 67217 41752 74461 118686 95750 166311 107560 75121 155941 6256 4 28447 25748 9026 23554 0
output:
22 2 16912 18702 28235 29943 33710 37835 39126 62555 63798 67207 85064 93039 94239 97883 99979 100970 105619 115440 119144 133448 150647 160094 3 2 14819 19610 24208
result:
ok 4 lines
Test #45:
score: 0
Accepted
time: 2252ms
memory: 13988kb
input:
2 13360 132763 44094 90038 92716 21633 128682 48634 35213 52001 78298 55346 50750 105358 7247 100946 16108 89436 30067 65470 120398 57992 100642 15292 69686 22150 19520 48604 37241 57277 66225 12587 26019 55500 12921 4531 76693 3444 83872 115362 74786 73252 63308 89630 114130 73895 89350 53605 71703...
output:
6 5 17490 25547 64188 70628 100411 106476 6 5 5315 19197 41182 62408 65948 66459
result:
ok 4 lines
Test #46:
score: 0
Accepted
time: 3270ms
memory: 25132kb
input:
2 4832 5381 3222 3538 3112 894 2207 4871 70 3764 3813 4077 5186 5114 5352 4195 4735 4614 4867 4943 3961 3812 2094 4884 1789 795 5275 49 1533 1780 1633 1928 2571 2709 4792 3790 340 871 3849 2857 4874 1607 5228 2789 1719 2598 399 234 3793 4712 3373 322 2000 4146 721 974 145 2662 2290 257 3230 2046 369...
output:
1 84 2483 1 104 75606
result:
ok 4 lines
Test #47:
score: 0
Accepted
time: 2242ms
memory: 14988kb
input:
2 40468 135077 96058 55445 48756 124324 91900 29558 69141 13005 29903 87721 7007 65434 73900 81742 20490 102816 107242 50183 34860 66546 60554 65460 76913 38994 72285 127621 31440 12267 44092 23991 67148 66085 58179 116578 121321 119026 35317 6010 34991 118853 96041 29634 47215 102444 35416 50622 72...
output:
1 13 87961 3 10 36090 40503 58715
result:
ok 4 lines
Test #48:
score: 0
Accepted
time: 1928ms
memory: 17732kb
input:
2 84290 169079 127059 66657 61651 121872 113239 8356 90886 52591 14448 25784 131919 143302 157036 20944 25976 78335 153750 57871 21487 4544 36840 19505 86646 9845 165708 24714 24148 47413 139326 863 150147 40140 418 136306 117573 101002 96845 63487 61672 164792 118371 66508 64427 90913 89558 96855 7...
output:
1 19 137370 1 17 7773
result:
ok 4 lines
Test #49:
score: 0
Accepted
time: 1948ms
memory: 16772kb
input:
2 120129 171341 110398 119483 31452 124116 83391 105206 113782 96001 135178 134709 31824 140049 8788 125086 76006 117379 85079 167990 152723 62019 10574 42418 64223 161029 167223 39307 137918 122615 106129 49848 140930 84081 57264 162048 87503 124024 96773 149613 117733 79629 86937 141330 50894 2724...
output:
1 34 2652 1 31 8013
result:
ok 4 lines
Test #50:
score: 0
Accepted
time: 2239ms
memory: 15104kb
input:
2 137578 137587 135274 71032 97433 68393 25725 3828 27807 135730 115783 91789 120452 95395 37439 120525 95008 90395 70143 99423 51625 6261 9972 22238 129504 57393 41768 114228 38428 85848 62986 97568 15730 94502 11353 92481 127114 80058 10057 101730 78945 113223 39790 76879 47640 30662 9727 27891 13...
output:
1 102149 108737 1 44754 43384
result:
ok 4 lines
Test #51:
score: 0
Accepted
time: 3037ms
memory: 24640kb
input:
1 3 199999 193667 0 15502
output:
2 2 47413 73752
result:
ok 2 lines
Test #52:
score: 0
Accepted
time: 3416ms
memory: 24892kb
input:
1 20105 199999 46654 146536 169399 40421 167047 42907 24666 79012 178470 63683 85423 58281 67519 152203 80111 98862 194589 188763 122932 117174 174098 174461 194088 22430 56866 159708 98517 156295 30340 157425 54753 160836 19633 96833 121268 178649 191017 150796 167076 96756 198225 4669 107399 17464...
output:
16 5 5032 6625 16233 28910 38444 42401 48500 56926 70377 71050 73480 76869 81019 88761 95925 171099
result:
ok 2 lines
Test #53:
score: 0
Accepted
time: 3426ms
memory: 25504kb
input:
1 180250 199999 189078 195476 172553 133293 37093 72698 197912 159314 119078 198806 147543 20836 167364 23860 113289 138683 178548 170845 37393 111747 178054 64889 105017 55556 144681 11204 72679 7319 159195 125646 60137 79694 82520 84012 60404 104992 22906 38355 37357 168557 56915 85924 177365 1486...
output:
1 114 65179
result:
ok 2 lines
Test #54:
score: 0
Accepted
time: 3250ms
memory: 24916kb
input:
1 60061 199999 157215 33938 158407 93886 136932 84450 38475 114415 86660 18575 3325 141315 99424 144311 34744 49582 197663 170581 80654 179350 161103 104039 94671 50120 186944 160865 42447 96877 109964 24894 3290 111072 58306 50848 82017 118051 43726 78326 161496 146731 195226 59925 186911 19439 401...
output:
1 10 131695
result:
ok 2 lines
Test #55:
score: 0
Accepted
time: 3418ms
memory: 25152kb
input:
1 99729 199999 30086 30555 10118 181847 2997 122174 153358 196665 196594 31730 189807 164679 125944 21116 173012 144636 162773 137290 111887 46993 94084 89988 48596 83518 17189 72082 33756 147411 147319 134250 50604 34855 66458 103332 151057 197405 195001 159110 196068 118658 42291 121524 184263 924...
output:
2 18 154208 164274
result:
ok 2 lines
Test #56:
score: 0
Accepted
time: 3441ms
memory: 25192kb
input:
1 140028 199999 5335 157624 58044 59830 77586 78007 195292 149961 107515 116630 150568 46507 109695 116531 192970 155131 30135 65209 84585 52812 142977 55746 176356 175247 173543 136091 100186 135056 93593 107308 29017 108533 63087 152948 67333 162347 134578 105974 101828 73371 67997 165278 88599 10...
output:
3 33 111102 155807 178457
result:
ok 2 lines
Test #57:
score: 0
Accepted
time: 3410ms
memory: 25536kb
input:
1 199976 199999 133008 191728 136938 125252 9027 103691 113322 162671 41110 71424 28728 90939 126416 63364 23262 45041 7917 159597 148962 109919 45615 188801 132889 176694 66892 192412 69157 16547 75814 158618 161752 80376 32766 34578 17578 69633 67660 127232 129029 57710 92300 26805 29741 142045 16...
output:
1 82725 192407
result:
ok 2 lines