QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104874 | #5459. Goose, goose, DUCK? | maspy | AC ✓ | 2624ms | 188796kb | C++20 | 20.7kb | 2023-05-12 09:09:04 | 2023-05-12 09:09:06 |
Judging History
answer
#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
#define vv(type, name, h, ...) \
vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) \
vector<vector<vector<type>>> name( \
h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...) \
vector<vector<vector<vector<type>>>> name( \
a, vector<vector<vector<type>>>( \
b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)
#define FOR_subset(t, s) \
for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define stoi stoll
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
template <typename T, typename U>
T ceil(T x, U y) {
return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sum = 0;
for (auto &&a: A) sum += a;
return sum;
}
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
template <typename T>
T POP(deque<T> &que) {
T a = que.front();
que.pop_front();
return a;
}
template <typename T>
T POP(pq<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(pqg<T> &que) {
assert(!que.empty());
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
assert(!que.empty());
T a = que.back();
que.pop_back();
return a;
}
template <typename F>
ll binary_search(F check, ll ok, ll ng) {
assert(check(ok));
while (abs(ok - ng) > 1) {
auto x = (ng + ok) / 2;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
}
return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
FOR(iter) {
double x = (ok + ng) / 2;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
}
return (ok + ng) / 2;
}
template <class T, class S>
inline bool chmax(T &a, const S &b) {
return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
return (a > b ? a = b, 1 : 0);
}
// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
vc<int> A(S.size());
FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
return A;
}
template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
int N = A.size();
vector<T> B(N + 1);
FOR(i, N) { B[i + 1] = B[i] + A[i]; }
if (off == 0) B.erase(B.begin());
return B;
}
// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
vector<int> ids(len(A));
iota(all(ids), 0);
sort(all(ids),
[&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
return ids;
}
// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
vc<T> B(len(I));
FOR(i, len(I)) B[i] = A[I[i]];
return B;
}
#endif
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>
namespace fastio {
#define FASTIO
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
template <class T>
static auto check(T &&x) -> decltype(x.write(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};
struct has_read_impl {
template <class T>
static auto check(T &&x) -> decltype(x.read(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};
struct Scanner {
FILE *fp;
char line[(1 << 15) + 1];
size_t st = 0, ed = 0;
void reread() {
memmove(line, line + st, ed - st);
ed -= st;
st = 0;
ed += fread(line + ed, 1, (1 << 15) - ed, fp);
line[ed] = '\0';
}
bool succ() {
while (true) {
if (st == ed) {
reread();
if (st == ed) return false;
}
while (st != ed && isspace(line[st])) st++;
if (st != ed) break;
}
if (ed - st <= 50) {
bool sep = false;
for (size_t i = st; i < ed; i++) {
if (isspace(line[i])) {
sep = true;
break;
}
}
if (!sep) reread();
}
return true;
}
template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
while (true) {
size_t sz = 0;
while (st + sz < ed && !isspace(line[st + sz])) sz++;
ref.append(line + st, sz);
st += sz;
if (!sz || st != ed) break;
reread();
}
return true;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
bool neg = false;
if (line[st] == '-') {
neg = true;
st++;
}
ref = T(0);
while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
if (neg) ref = -ref;
return true;
}
template <typename T,
typename enable_if<has_read<T>::value>::type * = nullptr>
inline bool read_single(T &x) {
x.read();
return true;
}
bool read_single(double &ref) {
string s;
if (!read_single(s)) return false;
ref = std::stod(s);
return true;
}
bool read_single(char &ref) {
string s;
if (!read_single(s) || s.size() != 1) return false;
ref = s[0];
return true;
}
template <class T>
bool read_single(vector<T> &ref) {
for (auto &d: ref) {
if (!read_single(d)) return false;
}
return true;
}
template <class T, class U>
bool read_single(pair<T, U> &p) {
return (read_single(p.first) && read_single(p.second));
}
template <size_t N = 0, typename T>
void read_single_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
read_single(x);
read_single_tuple<N + 1>(t);
}
}
template <class... T>
bool read_single(tuple<T...> &tpl) {
read_single_tuple(tpl);
return true;
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
bool f = read_single(h);
assert(f);
read(t...);
}
Scanner(FILE *fp) : fp(fp) {}
};
struct Printer {
Printer(FILE *_fp) : fp(_fp) {}
~Printer() { flush(); }
static constexpr size_t SIZE = 1 << 15;
FILE *fp;
char line[SIZE], small[50];
size_t pos = 0;
void flush() {
fwrite(line, 1, pos, fp);
pos = 0;
}
void write(const char val) {
if (pos == SIZE) flush();
line[pos++] = val;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
void write(T val) {
if (pos > (1 << 15) - 50) flush();
if (val == 0) {
write('0');
return;
}
if (val < 0) {
write('-');
val = -val; // todo min
}
size_t len = 0;
while (val) {
small[len++] = char(0x30 | (val % 10));
val /= 10;
}
for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
pos += len;
}
void write(const string s) {
for (char c: s) write(c);
}
void write(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) write(s[i]);
}
void write(const double x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
void write(const long double x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
template <typename T,
typename enable_if<has_write<T>::value>::type * = nullptr>
inline void write(T x) {
x.write();
}
template <class T>
void write(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
template <class T, class U>
void write(const pair<T, U> val) {
write(val.first);
write(' ');
write(val.second);
}
template <size_t N = 0, typename T>
void write_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { write(' '); }
const auto x = std::get<N>(t);
write(x);
write_tuple<N + 1>(t);
}
}
template <class... T>
bool write(tuple<T...> tpl) {
write_tuple(tpl);
return true;
}
template <class T, size_t S>
void write(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
void write(i128 val) {
string s;
bool negative = 0;
if (val < 0) {
negative = 1;
val = -val;
}
while (val) {
s += '0' + int(val % 10);
val /= 10;
}
if (negative) s += "-";
reverse(all(s));
if (len(s) == 0) s = "0";
write(s);
}
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
printer.write(head);
if (sizeof...(Tail)) printer.write(' ');
print(forward<Tail>(tail)...);
}
void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
scanner.read(head);
read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
read(name)
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 2 "library/ds/segtree/lazy_segtree.hpp"
template <typename ActedMonoid>
struct Lazy_SegTree {
using AM = ActedMonoid;
using MX = typename AM::Monoid_X;
using MA = typename AM::Monoid_A;
using X = typename MX::value_type;
using A = typename MA::value_type;
int n, log, size;
vc<X> dat;
vc<A> laz;
Lazy_SegTree() {}
Lazy_SegTree(int n) { build(n); }
template <typename F>
Lazy_SegTree(int n, F f) {
build(n, f);
}
Lazy_SegTree(const vc<X>& v) { build(v); }
void build(int m) {
build(m, [](int i) -> X { return MX::unit(); });
}
void build(const vc<X>& v) {
build(len(v), [&](int i) -> X { return v[i]; });
}
template <typename F>
void build(int m, F f) {
n = m, log = 1;
while ((1 << log) < n) ++log;
size = 1 << log;
dat.assign(size << 1, MX::unit());
laz.assign(size, MA::unit());
FOR(i, n) dat[size + i] = f(i);
FOR_R(i, 1, size) update(i);
}
void update(int k) { dat[k] = MX::op(dat[2 * k], dat[2 * k + 1]); }
void set(int p, X x) {
assert(0 <= p && p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
dat[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
X get(int p) {
assert(0 <= p && p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return dat[p];
}
vc<X> get_all() {
FOR(k, 1, size) { push(k); }
return {dat.begin() + size, dat.begin() + size + n};
}
X prod(int l, int r) {
assert(0 <= l && l <= r && r <= n);
if (l == r) return MX::unit();
l += size, r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
X xl = MX::unit(), xr = MX::unit();
while (l < r) {
if (l & 1) xl = MX::op(xl, dat[l++]);
if (r & 1) xr = MX::op(dat[--r], xr);
l >>= 1, r >>= 1;
}
return MX::op(xl, xr);
}
X prod_all() { return dat[1]; }
void apply(int l, int r, A a) {
assert(0 <= l && l <= r && r <= n);
if (l == r) return;
l += size, r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
int l2 = l, r2 = r;
while (l < r) {
if (l & 1) apply_at(l++, a);
if (r & 1) apply_at(--r, a);
l >>= 1, r >>= 1;
}
l = l2, r = r2;
for (int i = 1; i <= log; i++) {
if (((l >> i) << i) != l) update(l >> i);
if (((r >> i) << i) != r) update((r - 1) >> i);
}
}
template <typename F>
int max_right(const F check, int l) {
assert(0 <= l && l <= n);
assert(check(MX::unit()));
if (l == n) return n;
l += size;
for (int i = log; i >= 1; i--) push(l >> i);
X sm = MX::unit();
do {
while (l % 2 == 0) l >>= 1;
if (!check(MX::op(sm, dat[l]))) {
while (l < size) {
push(l);
l = (2 * l);
if (check(MX::op(sm, dat[l]))) { sm = MX::op(sm, dat[l++]); }
}
return l - size;
}
sm = MX::op(sm, dat[l++]);
} while ((l & -l) != l);
return n;
}
template <typename F>
int min_left(const F check, int r) {
assert(0 <= r && r <= n);
assert(check(MX::unit()));
if (r == 0) return 0;
r += size;
for (int i = log; i >= 1; i--) push((r - 1) >> i);
X sm = MX::unit();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!check(MX::op(dat[r], sm))) {
while (r < size) {
push(r);
r = (2 * r + 1);
if (check(MX::op(dat[r], sm))) { sm = MX::op(dat[r--], sm); }
}
return r + 1 - size;
}
sm = MX::op(dat[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
void apply_at(int k, A a) {
ll sz = 1 << (log - topbit(k));
dat[k] = AM::act(dat[k], a, sz);
if (k < size) laz[k] = MA::op(laz[k], a);
}
void push(int k) {
if (laz[k] == MA::unit()) return;
apply_at(2 * k, laz[k]), apply_at(2 * k + 1, laz[k]);
laz[k] = MA::unit();
}
};
#line 2 "library/alg/monoid/minmincnt.hpp"
// 最小値、最小値の個数
template <typename E>
struct Monoid_MinMincnt {
using value_type = pair<E, E>;
using X = value_type;
static X op(X x, X y) {
auto [xmin, xmincnt] = x;
auto [ymin, ymincnt] = y;
if (xmin > ymin) return {ymin, ymincnt};
if (xmin == ymin) return {xmin, xmincnt + ymincnt};
return {xmin, xmincnt};
}
static constexpr X unit() { return {infty<E>, 0}; }
static constexpr bool commute = true;
};
#line 2 "library/alg/monoid/add.hpp"
template <typename X>
struct Monoid_Add {
using value_type = X;
static constexpr X op(const X &x, const X &y) noexcept { return x + y; }
static constexpr X inverse(const X &x) noexcept { return -x; }
static constexpr X power(const X &x, ll n) noexcept { return X(n) * x; }
static constexpr X unit() { return X(0); }
static constexpr bool commute = true;
};
#line 3 "library/alg/acted_monoid/minmincnt_add.hpp"
template <typename E>
struct ActedMonoid_MinMincnt_Add {
using Monoid_X = Monoid_MinMincnt<E>;
using Monoid_A = Monoid_Add<E>;
using X = typename Monoid_X::value_type;
using A = typename Monoid_A::value_type;
static constexpr X act(const X &x, const A &a, const ll &size) {
auto [xmin, xmincnt] = x;
if (xmin == infty<E>) return x;
return {xmin + a, xmincnt};
}
};
#line 3 "library/other/rectangle_union.hpp"
template <typename XY = int>
struct Rectangle_Union {
using RECT = tuple<XY, XY, XY, XY>;
vc<RECT> rectangles;
vc<XY> X, Y;
void add_rect(int xl, int xr, int yl, int yr) {
assert(xl < xr && yl < yr);
X.eb(xl), X.eb(xr), Y.eb(yl), Y.eb(yr);
rectangles.eb(xl, xr, yl, yr);
}
template <typename ANS_TYPE = ll>
ANS_TYPE calc() {
UNIQUE(X), UNIQUE(Y);
int N = len(X);
vc<vc<pair<int, int>>> add(N), rm(N);
for (auto &&[xl, xr, yl, yr]: rectangles) {
xl = LB(X, xl), xr = LB(X, xr);
yl = LB(Y, yl), yr = LB(Y, yr);
add[xl].eb(yl, yr);
rm[xr].eb(yl, yr);
}
using AM = ActedMonoid_MinMincnt_Add<XY>;
using T = typename AM::Monoid_X::value_type;
Lazy_SegTree<AM> seg(len(Y) - 1, [&](int i) -> T {
return {0, Y[i + 1] - Y[i]};
});
ANS_TYPE ANS = 0;
FOR(i, len(X) - 1) {
ANS_TYPE dx = X[i + 1] - X[i];
for (auto &&[yl, yr]: add[i]) seg.apply(yl, yr, 1);
for (auto &&[yl, yr]: rm[i]) seg.apply(yl, yr, -1);
auto [min, mincnt] = seg.prod_all();
ANS_TYPE n = Y.back() - Y[0];
if (min == 0) n -= mincnt;
ANS += n * dx;
}
return ANS;
}
};
#line 4 "main.cpp"
void solve() {
LL(N, K);
VEC(int, A, N);
int LIM = MAX(A);
vvc<int> pos(LIM + 1);
FOR(i, N) pos[A[i]].eb(i);
Rectangle_Union<int> X;
FOR(x, LIM + 1) {
auto& I = pos[x];
if (len(I) < K) continue;
FOR(i, len(I)) {
int j = i + K - 1;
if (j >= len(I)) continue;
int b = I[i], c = I[j];
int a = (i == 0 ? -1 : I[i - 1]);
int d = (j + 1 == len(I) ? N : I[j + 1]);
// (a, b] x [c, d)
X.add_rect(a, b, c, d);
}
}
ll ANS = N * (N + 1) / 2 - X.calc();
print(ANS);
}
signed main() {
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3432kb
input:
6 2 1 2 2 1 3 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3504kb
input:
6 1 1 2 3 4 5 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 10ms
memory: 26304kb
input:
100 10 142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...
output:
4309
result:
ok 1 number(s): "4309"
Test #4:
score: 0
Accepted
time: 11ms
memory: 18660kb
input:
1000 100 144044 144044 606320 144044 144044 653289 606320 606320 606320 144044 653289 606320 144044 606320 144044 653289 606320 653289 144044 144044 606320 606320 606320 144044 606320 653289 653289 144044 606320 606320 606320 606320 606320 606320 606320 606320 653289 606320 653289 606320 653289 6532...
output:
494331
result:
ok 1 number(s): "494331"
Test #5:
score: 0
Accepted
time: 4ms
memory: 26224kb
input:
1000 2 37158 712133 695735 352502 37158 111876 979836 322207 850 170255 712133 37158 68113 170255 269273 322207 644692 127744 575843 269273 352502 68113 166126 413274 111876 575843 704107 695735 37158 604776 127744 269273 166126 704107 850 111876 352502 979836 850 850 712133 850 979836 575843 704107...
output:
382010
result:
ok 1 number(s): "382010"
Test #6:
score: 0
Accepted
time: 4ms
memory: 25248kb
input:
1000 1 439144 11249 309118 842057 842057 938195 823723 842057 589439 914850 938195 455713 91595 938195 553566 761181 553566 70966 455713 439144 704849 11249 11249 236580 320993 933831 872377 589439 435476 558991 914850 690853 482410 690853 715546 155003 435476 155003 435476 435476 842057 236580 7096...
output:
341042
result:
ok 1 number(s): "341042"
Test #7:
score: 0
Accepted
time: 13ms
memory: 26836kb
input:
1000 1 675227 756097 647871 465683 473815 162625 396802 61313 758469 968915 283015 326083 86904 672294 145904 621859 346020 237440 669779 282692 626616 722910 999031 141389 440533 971280 807058 346648 405103 669779 463968 214284 50833 661085 826455 991362 984243 704592 426668 998421 949882 147122 72...
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 2557ms
memory: 188696kb
input:
1000000 1 420242 544222 171447 777913 987553 724009 569564 35971 931705 898245 672004 267555 967920 126950 627536 979230 592634 345070 437097 838283 124796 525563 988560 362647 502828 510728 538451 742569 327219 207978 943947 684879 278534 669721 356340 258535 85663 265714 956295 291196 419333 19692...
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 1762ms
memory: 188140kb
input:
1000000 1 559660 917135 718911 137428 227265 619698 582978 634509 968207 398589 647945 907790 647945 453872 267596 39233 647945 225421 404411 559660 401213 907790 765663 401213 339252 723380 907790 619698 896672 907790 58034 686103 455430 917135 686103 225421 619698 203386 893988 438096 75622 401213...
output:
499686064890
result:
ok 1 number(s): "499686064890"
Test #10:
score: 0
Accepted
time: 1744ms
memory: 188608kb
input:
1000000 20 861642 606482 953312 90817 363428 948603 487519 232986 519567 387790 428832 519567 307633 737110 521903 537123 787533 232986 5583 363428 162408 90817 179560 859355 774243 861642 776916 206258 801420 519567 801420 422101 206258 787533 390434 62305 994340 741875 801420 138248 519567 531603 ...
output:
499129896013
result:
ok 1 number(s): "499129896013"
Test #11:
score: 0
Accepted
time: 1669ms
memory: 187144kb
input:
1000000 200 485566 524102 778359 799174 823706 763480 616196 623850 594064 472722 778359 759395 336774 823706 814350 623850 662712 209130 702939 493199 974047 941295 623850 472722 947166 336774 493199 371798 974047 632804 702939 724695 509242 662712 776785 411318 280490 759395 336774 89517 493199 30...
output:
498381370313
result:
ok 1 number(s): "498381370313"
Test #12:
score: 0
Accepted
time: 1091ms
memory: 181132kb
input:
1000000 2000 278305 278305 348110 113854 832030 667125 113854 821689 667125 481645 305363 481645 348110 481645 278305 123360 821689 348110 481645 305363 305363 832030 123360 821689 832030 481645 113854 123360 832030 541509 278305 832030 541509 113854 481645 278305 113854 481645 305363 348110 278305 ...
output:
499905050517
result:
ok 1 number(s): "499905050517"
Test #13:
score: 0
Accepted
time: 1426ms
memory: 188796kb
input:
1000000 1 20506 24350 30587 37027 42391 66414 97104 110890 139464 147153 151865 154652 163381 181574 232570 237490 262035 270050 287512 300416 308447 310125 310983 312781 317123 318837 328920 330480 344807 346415 348094 350611 356439 366128 374463 383635 386897 408221 415742 416461 417999 419807 425...
output:
499801321042
result:
ok 1 number(s): "499801321042"
Test #14:
score: 0
Accepted
time: 1538ms
memory: 188376kb
input:
1000000 3 11023 31773 32161 38871 41021 44852 48136 50602 53388 101255 102564 106529 107369 122558 127492 129008 139504 168813 175401 197384 227294 235164 240779 260845 274861 280036 294860 328235 353725 355819 364809 368636 371245 380336 385635 387362 387463 397455 399364 401758 407996 424116 42811...
output:
499800994499
result:
ok 1 number(s): "499800994499"
Test #15:
score: 0
Accepted
time: 1526ms
memory: 188428kb
input:
1000000 20 3503 16481 16795 23406 31913 41872 51334 54530 54659 58868 61041 88488 93579 109541 110340 128839 131239 134456 158540 178156 181454 198922 200083 203463 220228 224053 260400 262942 280472 285105 287261 318193 338271 345198 355790 359916 372574 374790 380392 391766 416424 418976 424552 42...
output:
499797927548
result:
ok 1 number(s): "499797927548"
Test #16:
score: 0
Accepted
time: 1460ms
memory: 187648kb
input:
1000000 100 26705 33485 50901 54941 68943 81029 85286 113183 123732 125867 126194 135433 178979 180530 192244 193156 208961 212468 217679 227986 240063 252514 254933 257638 257813 261582 271371 292677 298888 319760 321433 327241 345967 347806 360472 369382 385741 390248 396342 405013 405299 411923 4...
output:
499785153218
result:
ok 1 number(s): "499785153218"
Test #17:
score: 0
Accepted
time: 1427ms
memory: 175280kb
input:
1000000 1000 54734 56859 60900 69121 73309 75054 98086 124241 128326 130579 133938 138638 170907 174090 209593 210626 227131 240148 285324 294171 294911 306676 310066 315911 316415 323391 325543 335382 338701 356893 357975 361369 375642 393131 412064 424646 429594 433991 441381 448701 450511 478719 ...
output:
499711049085
result:
ok 1 number(s): "499711049085"
Test #18:
score: 0
Accepted
time: 27ms
memory: 36016kb
input:
1000000 10000 15780 26236 27684 29851 30391 70638 74718 105424 106626 112856 121360 136256 143306 144423 160215 172628 178833 187008 187580 193012 204251 249462 268531 307132 312751 317920 334377 334794 338564 346157 346869 361652 385944 418212 419616 431221 452685 453777 457638 457725 499400 508745...
output:
500000494950
result:
ok 1 number(s): "500000494950"
Test #19:
score: 0
Accepted
time: 1639ms
memory: 188700kb
input:
1000000 3 13192 25254 37301 53898 55107 56589 60875 62479 90808 108918 112707 135312 138180 140042 144199 146700 148639 159639 161015 182707 203339 205293 217104 217993 221972 233487 256690 279730 303295 315509 323466 324495 343702 348772 362594 552837 376486 381055 388704 399808 401931 422683 43256...
output:
499724407843
result:
ok 1 number(s): "499724407843"
Test #20:
score: 0
Accepted
time: 1694ms
memory: 188580kb
input:
1000000 20 31594 44498 46841 50016 54025 62603 67202 69488 70166 115334 144272 148075 153366 157675 165752 175136 182730 201633 206707 212924 226032 245422 258994 270652 317043 338717 338753 339996 345085 346180 359946 367730 371425 376731 407733 409245 410195 416008 431461 439720 442584 444716 4468...
output:
499596476425
result:
ok 1 number(s): "499596476425"
Test #21:
score: 0
Accepted
time: 1760ms
memory: 187656kb
input:
1000000 100 57157 111627 122547 135685 140722 142818 153374 209026 223146 239026 252837 256776 281064 289700 290219 292233 294024 349159 355923 361093 362183 378753 381072 389411 391472 391617 396151 397557 398169 428876 432451 435010 449056 449146 451048 460835 462298 474684 482179 482770 488686 49...
output:
499391962641
result:
ok 1 number(s): "499391962641"
Test #22:
score: 0
Accepted
time: 1588ms
memory: 175496kb
input:
1000000 1000 31493 41881 47733 61011 71910 80336 95923 110457 110595 120368 127883 129274 173259 176814 195869 210362 221085 239440 255462 257568 259584 285984 290476 297671 313610 334878 338145 362300 365380 367825 380147 392530 394324 395227 406251 406263 418868 432138 437741 438162 486778 512830 ...
output:
498783493376
result:
ok 1 number(s): "498783493376"
Test #23:
score: 0
Accepted
time: 24ms
memory: 36404kb
input:
1000000 10000 42038 50384 66576 86923 87920 89011 112787 113849 124259 126873 129621 137006 139874 157994 325776 166583 186258 198164 209632 210915 211671 214969 216668 217801 237103 239515 249705 268737 281178 294292 319964 325776 340804 352085 354292 363407 388690 392733 393593 397954 405187 41300...
output:
500000487674
result:
ok 1 number(s): "500000487674"
Test #24:
score: 0
Accepted
time: 1896ms
memory: 188248kb
input:
1000000 20 8297 10253 11655 35181 469963 40980 44610 45480 45968 144412 349288 110821 793614 35181 141187 44610 144412 147994 162380 163126 8297 715077 223055 227282 239159 255415 256199 270255 793614 393755 286243 296085 307696 864863 322214 326864 328862 594408 673065 386853 393755 937498 412435 4...
output:
498372290400
result:
ok 1 number(s): "498372290400"
Test #25:
score: 0
Accepted
time: 1854ms
memory: 187456kb
input:
1000000 100 486435 23761 24235 33864 40684 53396 57584 295737 896419 77583 583583 548385 493160 791063 144501 486435 170285 174686 187914 77583 199976 209866 221143 222079 231963 975385 245272 246644 252021 295737 296906 313568 324144 334442 343938 349704 368668 421176 805941 919799 382762 812603 42...
output:
496980423237
result:
ok 1 number(s): "496980423237"
Test #26:
score: 0
Accepted
time: 1636ms
memory: 175296kb
input:
1000000 1000 2145 68136 16607 409458 22354 61633 68136 68812 69932 84624 202591 96813 99616 101201 123924 709687 140217 146803 149628 154171 173873 181288 202591 203691 433640 181288 260177 260255 262688 417949 285610 296625 316727 329114 332321 781226 790225 950078 409458 399598 272557 412138 41794...
output:
494633760441
result:
ok 1 number(s): "494633760441"
Test #27:
score: 0
Accepted
time: 28ms
memory: 36072kb
input:
1000000 10000 17351 65877 101842 108439 130529 131763 144871 835489 175925 184547 716087 237095 248755 263575 824662 274206 278167 371885 698029 971833 308720 315483 184547 441863 274206 354454 587577 366009 366344 315483 367916 371750 711360 371750 402253 403715 404490 412144 434109 441863 810118 4...
output:
500000435543
result:
ok 1 number(s): "500000435543"
Test #28:
score: 0
Accepted
time: 1884ms
memory: 188500kb
input:
1000000 20 126110 52385 464710 203919 305450 214423 566044 926946 477145 125830 602550 854825 699058 360960 662325 385240 252572 166915 585008 749718 385240 801236 385240 956433 101385 854825 626672 313521 755479 385240 227584 931898 214423 723758 610608 101385 124880 380048 699058 723758 876575 809...
output:
497932776583
result:
ok 1 number(s): "497932776583"
Test #29:
score: 0
Accepted
time: 1827ms
memory: 187820kb
input:
1000000 100 534859 762067 163543 126964 605251 944335 407972 651389 555665 447742 932806 101606 552259 784295 729406 460940 101606 295842 677547 330769 166607 585701 534859 605251 71349 740213 71349 709084 932806 967932 702200 476270 740213 236337 192428 884658 265499 884658 526560 27215 784295 5348...
output:
496316167265
result:
ok 1 number(s): "496316167265"
Test #30:
score: 0
Accepted
time: 1658ms
memory: 175940kb
input:
1000000 1000 762444 693573 2802 446818 560172 492832 383822 348558 527640 88414 640787 16618 719592 714819 645316 978131 878247 666414 692106 653890 403061 645316 16618 957721 640654 809285 240678 148559 315034 150418 383822 955234 595812 714819 333549 129451 958145 333549 422540 721509 139762 51676...
output:
494073094584
result:
ok 1 number(s): "494073094584"
Test #31:
score: 0
Accepted
time: 18ms
memory: 36532kb
input:
1000000 10000 698698 886860 655713 894253 100787 686560 716963 105439 783355 784550 8867 698748 541374 365425 49544 783355 112893 596451 515736 445994 515736 194834 596451 137179 894253 348902 515736 209077 698698 445994 230073 110676 235382 698748 87090 787660 596451 594676 938008 327825 483894 923...
output:
500000385825
result:
ok 1 number(s): "500000385825"
Test #32:
score: 0
Accepted
time: 2185ms
memory: 163496kb
input:
1000000 20 923555 989327 140006 149591 154990 770656 408196 595470 474964 537512 108725 16804 179424 723202 299438 427345 153899 332593 919096 234140 554147 754591 426981 640533 138648 838016 395769 701080 444832 776741 144383 602791 344245 178826 617846 276478 281857 670811 182691 876433 89178 1479...
output:
269690150257
result:
ok 1 number(s): "269690150257"
Test #33:
score: 0
Accepted
time: 87ms
memory: 37268kb
input:
1000000 100 894270 701908 348954 29652 46340 7063 218477 942940 128381 502610 965560 831423 440699 564774 550341 990435 852728 397056 625626 506722 608789 551661 828038 357426 842129 239594 347344 536072 940920 913148 87633 180898 670133 473898 500412 890328 196048 945189 695112 11699 368848 217761 ...
output:
495835073299
result:
ok 1 number(s): "495835073299"
Test #34:
score: 0
Accepted
time: 79ms
memory: 36320kb
input:
1000000 1000 146876 535949 746095 349132 639639 361106 286826 779672 175664 75072 511080 451425 511080 867604 802041 924874 223977 90568 525070 953756 85401 434559 380849 375687 483043 441018 90151 649468 624535 342124 886732 351402 99960 31304 403208 821589 808175 938946 827916 887938 802147 612931...
output:
500000500000
result:
ok 1 number(s): "500000500000"
Test #35:
score: 0
Accepted
time: 74ms
memory: 36248kb
input:
1000000 10000 841599 361404 145028 675800 199807 127899 37744 367759 570994 648968 893252 737006 913180 722495 537159 881248 984071 189205 436546 168541 726657 867566 515981 5265 248098 913968 512096 604631 5811 205062 672411 949351 590675 497055 415061 113883 333423 123673 709782 325626 377937 7754...
output:
500000500000
result:
ok 1 number(s): "500000500000"
Test #36:
score: 0
Accepted
time: 976ms
memory: 187260kb
input:
1000000 20 51324 985511 51324 51324 51324 985511 51324 985511 417669 985511 985511 985511 51324 417669 417669 51324 985511 417669 51324 985511 417669 51324 417669 417669 51324 51324 51324 985511 51324 985511 51324 51324 985511 985511 985511 417669 417669 985511 51324 417669 985511 51324 51324 985511...
output:
499992045370
result:
ok 1 number(s): "499992045370"
Test #37:
score: 0
Accepted
time: 907ms
memory: 181016kb
input:
1000000 100 107702 476057 476057 476057 718986 476057 476057 107702 476057 718986 718986 718986 476057 476057 107702 107702 718986 476057 718986 718986 107702 718986 718986 718986 476057 718986 718986 718986 718986 718986 476057 107702 107702 476057 476057 476057 718986 476057 718986 107702 718986 4...
output:
499991755386
result:
ok 1 number(s): "499991755386"
Test #38:
score: 0
Accepted
time: 921ms
memory: 186220kb
input:
1000000 1000 958601 116914 116914 589550 116914 116914 958601 116914 958601 958601 116914 958601 589550 589550 116914 116914 116914 958601 589550 589550 116914 589550 116914 958601 116914 958601 589550 116914 958601 958601 958601 116914 116914 589550 958601 589550 589550 958601 958601 958601 116914 ...
output:
499991601479
result:
ok 1 number(s): "499991601479"
Test #39:
score: 0
Accepted
time: 890ms
memory: 178196kb
input:
1000000 10000 644458 767484 108648 108648 767484 644458 644458 767484 644458 644458 644458 767484 644458 644458 644458 644458 767484 644458 644458 644458 767484 108648 644458 644458 767484 108648 644458 108648 767484 644458 767484 644458 767484 108648 108648 767484 767484 644458 767484 767484 108648...
output:
499991785725
result:
ok 1 number(s): "499991785725"
Test #40:
score: 0
Accepted
time: 1716ms
memory: 138156kb
input:
1000000 20 873002 450018 9888 248507 871070 300540 930269 465089 444632 9849 447875 386365 128305 895779 338602 769999 404169 998443 390426 989636 301758 481590 77748 753136 178402 73801 393865 332805 583013 546729 192898 596395 889967 743660 367511 365075 364656 822566 799880 28755 351614 389257 42...
output:
196659308951
result:
ok 1 number(s): "196659308951"
Test #41:
score: 0
Accepted
time: 2516ms
memory: 178244kb
input:
1000000 5 538693 776730 502024 413243 531707 11748 874778 720721 931056 235187 638366 463275 33691 233860 907251 290853 553006 504147 472583 168639 565616 356969 266190 821242 921105 89941 512363 992441 599518 768575 10656 322949 540275 104250 120821 484205 121784 73343 412438 171545 503940 643023 8...
output:
215757902963
result:
ok 1 number(s): "215757902963"
Test #42:
score: 0
Accepted
time: 2542ms
memory: 180760kb
input:
1000000 4 507660 309195 797944 138623 929921 297375 436242 16211 135484 958984 945634 885574 314555 210408 729866 57905 412659 328477 994684 593088 936867 249051 694497 221 18227 940327 428876 254887 838346 13651 468580 500022 226494 906990 132614 321987 653063 152458 474371 843963 616529 31024 5067...
output:
228016732045
result:
ok 1 number(s): "228016732045"
Test #43:
score: 0
Accepted
time: 2624ms
memory: 183400kb
input:
1000000 3 325831 521999 423880 205039 168231 863017 127350 673246 520684 782822 696799 16621 840222 383403 471580 594846 187613 894664 331157 33695 794732 579060 957571 281087 300714 879144 345990 123881 131366 123715 602567 615436 462256 861488 884404 64761 336231 412369 354792 219015 989201 739810...
output:
245821846717
result:
ok 1 number(s): "245821846717"