QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#667837#9465. 基础 01 练习题cmk666100 ✓1734ms1006364kbC++2318.1kb2024-10-23 08:39:272024-10-23 08:39:27

Judging History

你现在查看的是最新测评结果

  • [2024-10-23 08:39:27]
  • 评测
  • 测评结果:100
  • 用时:1734ms
  • 内存:1006364kb
  • [2024-10-23 08:39:27]
  • 提交

answer

/*  _              _     _                                             _       __      __      __   
   / \     _   _  | |_  | |__     ___    _ __   _    ___   _ __ ___   | | __  / /_    / /_    / /_  
  / _ \   | | | | | __| | '_ \   / _ \  | '__| (_)  / __| | '_ ` _ \  | |/ / | '_ \  | '_ \  | '_ \ 
 / ___ \  | |_| | | |_  | | | | | (_) | | |     _  | (__  | | | | | | |   <  | (_) | | (_) | | (_) |
/_/   \_\  \__,_|  \__| |_| |_|  \___/  |_|    (_)  \___| |_| |_| |_| |_|\_\  \___/   \___/   \___/ 
[Created Time:       2024-10-22 20:30:21]
[Last Modified Time: 2024-10-23 08:39:04] */
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#ifdef LOCAL
#include"debug.h"
#else
#define D(...) ((void)0)
#endif
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
namespace FastIO
{
#define USE_FastIO
// ------------------------------
// #define DISABLE_MMAP
// ------------------------------
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifdef LOCAL
	inline void _chk_i() {}
	inline char _gc_nochk() { return getchar(); }
	inline char _gc() { return getchar(); }
	inline void _chk_o() {}
	inline void _pc_nochk(char c) { putchar(c); }
	inline void _pc(char c) { putchar(c); }
	template < int n > inline void _pnc_nochk(const char *c) { for ( int i = 0 ; i < n ; i++ ) putchar(c[i]); }
#else
#ifdef DISABLE_MMAP
	inline constexpr int _READ_SIZE = 1 << 18; inline static char _read_buffer[_READ_SIZE + 40], *_read_ptr = nullptr, *_read_ptr_end = nullptr; static inline bool _eof = false;
	inline void _chk_i() { if ( __builtin_expect(!_eof, true) && __builtin_expect(_read_ptr_end - _read_ptr < 40, false) ) { int sz = _read_ptr_end - _read_ptr; if ( sz ) memcpy(_read_buffer, _read_ptr, sz); char *beg = _read_buffer + sz; _read_ptr = _read_buffer, _read_ptr_end = beg + fread(beg, 1, _READ_SIZE, stdin); if ( __builtin_expect(_read_ptr_end != beg + _READ_SIZE, false) ) _eof = true, *_read_ptr_end = EOF; } }
	inline char _gc_nochk() { return __builtin_expect(_eof && _read_ptr == _read_ptr_end, false) ? EOF : *_read_ptr++; }
	inline char _gc() { _chk_i(); return _gc_nochk(); }
#else
#include<sys/mman.h>
#include<sys/stat.h>
	inline static char *_read_ptr = (char *)mmap(nullptr, [] { struct stat s; return fstat(0, &s), s.st_size; } (), 1, 2, 0, 0);
	inline void _chk_i() {}
	inline char _gc_nochk() { return *_read_ptr++; }
	inline char _gc() { return *_read_ptr++; }
#endif
	inline constexpr int _WRITE_SIZE = 1 << 18; inline static char _write_buffer[_WRITE_SIZE + 40], *_write_ptr = _write_buffer;
	inline void _chk_o() { if ( __builtin_expect(_write_ptr - _write_buffer > _WRITE_SIZE, false) ) fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout), _write_ptr = _write_buffer; }
	inline void _pc_nochk(char c) { *_write_ptr++ = c; }
	inline void _pc(char c) { *_write_ptr++ = c, _chk_o(); }
	template < int n > inline void _pnc_nochk(const char *c) { memcpy(_write_ptr, c, n), _write_ptr += n; }
	inline struct _auto_flush { inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); } } _auto_flush;
#endif
#define println println_ // don't use C++23 std::println
	template < class T > inline constexpr bool _is_signed = numeric_limits < T >::is_signed;
	template < class T > inline constexpr bool _is_unsigned = numeric_limits < T >::is_integer && !_is_signed < T >;
#if __SIZEOF_LONG__ == 64
	template <> inline constexpr bool _is_signed < __int128 > = true;
	template <> inline constexpr bool _is_unsigned < __uint128_t > = true;
#endif
	inline bool _isgraph(char c) { return c >= 33; }
	inline bool _isdigit(char c) { return 48 <= c && c <= 57; } // or faster, remove c <= 57
	constexpr struct _table {
#ifndef LOCAL
	int i[65536];
#endif
	char o[40000]; constexpr _table() :
#ifndef LOCAL
	i{},
#endif
	o{} {
#ifndef LOCAL
	for ( int x = 0 ; x < 65536 ; x++ ) i[x] = -1; for ( int x = 0 ; x <= 9 ; x++ ) for ( int y = 0 ; y <= 9 ; y++ ) i[x + y * 256 + 12336] = x * 10 + y;
#endif
	for ( int x = 0 ; x < 10000 ; x++ ) for ( int y = 3, z = x ; ~y ; y-- ) o[x * 4 + y] = z % 10 + 48, z /= 10; } } _table;
	template < class T, int digit > inline constexpr T _pw10 = 10 * _pw10 < T, digit - 1 >;
	template < class T > inline constexpr T _pw10 < T, 0 > = 1;
	inline void read(char &c) { do c = _gc(); while ( !_isgraph(c) ); }
	inline void read_cstr(char *s) { char c = _gc(); while ( !_isgraph(c) ) c = _gc(); while ( _isgraph(c) ) *s++ = c, c = _gc(); *s = 0; }
	inline void read(string &s) { char c = _gc(); s.clear(); while ( !_isgraph(c) ) c = _gc(); while ( _isgraph(c) ) s.push_back(c), c = _gc(); }
	template < class T, bool neg >
#ifndef LOCAL
	__attribute__((no_sanitize("undefined")))
#endif
	inline void _read_int_suf(T &x) { _chk_i(); char c; while
#ifndef LOCAL
	( ~_table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)] ) if constexpr ( neg ) x = x * 100 - _table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)++]; else x = x * 100 + _table.i[*reinterpret_cast < unsigned short *& >(_read_ptr)++]; if
#endif
	( _isdigit(c = _gc_nochk()) ) if constexpr ( neg ) x = x * 10 - ( c & 15 ); else x = x * 10 + ( c & 15 ); }
	template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void read(T &x) { char c; while ( !_isdigit(c = _gc()) ) if ( c == 45 ) { _read_int_suf < T, true >(x = -( _gc_nochk() & 15 )); return; } _read_int_suf < T, false >(x = c & 15); }
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > inline void read(T &x) { char c; while ( !_isdigit(c = _gc()) ); _read_int_suf < T, false >(x = c & 15); }
	inline void write(bool x) { _pc(x | 48); }
	inline void write(char c) { _pc(c); }
	inline void write_cstr(const char *s) { while ( *s ) _pc(*s++); }
	inline void write(const string &s) { for ( char c : s ) _pc(c); }
	template < class T, bool neg, int digit > inline void _write_int_suf(T x) { if constexpr ( digit == 4 ) _pnc_nochk < 4 >(_table.o + ( neg ? -x : x ) * 4); else _write_int_suf < T, neg, digit / 2 >(x / _pw10 < T, digit / 2 >), _write_int_suf < T, neg, digit / 2 >(x % _pw10 < T, digit / 2 >); }
	template < class T, bool neg, int digit > inline void _write_int_pre(T x) { if constexpr ( digit <= 4 ) if ( digit >= 3 && ( neg ? x <= -100 : x >= 100 ) ) if ( digit >= 4 && ( neg ? x <= -1000 : x >= 1000 ) ) _pnc_nochk < 4 >(_table.o + ( neg ? -x : x ) * 4); else _pnc_nochk < 3 >(_table.o + ( neg ? -x : x ) * 4 + 1); else if ( digit >= 2 && ( neg ? x <= -10 : x >= 10 ) ) _pnc_nochk < 2 >(_table.o + ( neg ? -x : x ) * 4 + 2); else _pc_nochk(( neg ? -x : x ) | 48); else { constexpr int cur = 1 << __lg(digit - 1); if ( neg ? x <= -_pw10 < T, cur > : x >= _pw10 < T, cur > ) _write_int_pre < T, neg, digit - cur >(x / _pw10 < T, cur >), _write_int_suf < T, neg, cur >(x % _pw10 < T, cur >); else _write_int_pre < T, neg, cur >(x); } }
	template < class T, enable_if_t < _is_signed < T >, int > = 0 > inline void write(T x) { if ( x >= 0 ) _write_int_pre < T, false, numeric_limits < T >::digits10 + 1 >(x); else _pc_nochk(45), _write_int_pre < T, true, numeric_limits < T >::digits10 + 1 >(x); _chk_o(); }
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 > inline void write(T x) { _write_int_pre < T, false, numeric_limits < T >::digits10 + 1 >(x), _chk_o(); }
	template < size_t N, class ...T > inline void _read_tuple(tuple < T... > &x) { read(get < N >(x)); if constexpr ( N + 1 != sizeof...(T) ) _read_tuple < N + 1, T... >(x); }
	template < size_t N, class ...T > inline void _write_tuple(const tuple < T... > &x) { write(get < N >(x)); if constexpr ( N + 1 != sizeof...(T) ) _pc(32), _write_tuple < N + 1, T... >(x); }
	template < class ...T > inline void read(tuple < T... > &x) { _read_tuple < 0, T... >(x); }
	template < class ...T > inline void write(const tuple < T... > &x) { _write_tuple < 0, T... >(x); }
	template < class T1, class T2 > inline void read(pair < T1, T2 > &x) { read(x.first), read(x.second); }
	template < class T1, class T2 > inline void write(const pair < T1, T2 > &x) { write(x.first), _pc(32), write(x.second); }
	template < class T > inline auto read(T &x) -> decltype(x.read(), void()) { x.read(); }
	template < class T > inline auto write(const T &x) -> decltype(x.write(), void()) { x.write(); }
	template < class T1, class ...T2 > inline void read(T1 &x, T2 &...y) { read(x), read(y...); }
	template < class ...T > inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); }
	template < class T1, class ...T2 > inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); }
	template < class ...T > inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); }
	template < class T > inline void print(const T &x) { write(x); }
	inline void print_cstr(const char *x) { write_cstr(x); }
	template < class T1, class ...T2 > inline void print(const T1 &x, const T2 &...y) { write(x), _pc(32), print(y...); }
	template < class ...T > inline void print_cstr(const char *x, const T *...y) { write_cstr(x), _pc(32), print_cstr(y...); }
	inline void println() { _pc(10); }
	inline void println_cstr() { _pc(10); }
	template < class ...T > inline void println(const T &...x) { print(x...), _pc(10); }
	template < class ...T > inline void println_cstr(const T *...x) { print_cstr(x...), _pc(10); }
}	using FastIO::read, FastIO::read_cstr, FastIO::write, FastIO::write_cstr, FastIO::println, FastIO::println_cstr;
template < auto P_ > class MontgomeryModInt
{
	using S = decltype(P_); static_assert(is_same_v < S, int > || is_same_v < S, long long >);
	static_assert(P_ & 1 && 0 < P_ && P_ < ( (S)1 << ( sizeof(S) * 8 - 2 ) ));
	using U = conditional_t < is_same_v < S, int >, unsigned, unsigned long long >; using D = conditional_t < is_same_v < S, int >, unsigned long long, __uint128_t >;
	inline constexpr static U uinv(U x) { U y = x; for ( int i = is_same_v < S, int > ? 4 : 5 ; i-- ; ) y *= 2 - x * y; return y; }
	constexpr static U P = P_, P2 = P << 1, R = -uinv(P), R2 = -(D)P % P; static_assert(P * R == -1);
	inline constexpr static U reduce(D x) { return ( x + (U)x * R * (D)P ) >> ( sizeof(U) * 8 ); }
	inline constexpr MontgomeryModInt(U x, int) : v(x) {} U v;
public:
	inline constexpr static S mod() { return P; }
	inline constexpr MontgomeryModInt() : v(0) {}
	inline constexpr MontgomeryModInt(const MontgomeryModInt &x) : v(x.v) {}
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 > inline constexpr MontgomeryModInt(T x) : v(reduce((D)R2 * ( numeric_limits < T >::is_signed && x < 0 ? ( ( x + P < 0 ) && ( x %= P ), x + P ) : ( ( sizeof(T) > sizeof(U) && x >= (T)1 << sizeof(U) ) && ( x %= P ), x ) ))) {}
	inline constexpr S val()const { U x = reduce(v); return ( x - P ) >> ( sizeof(U) * 8 - 1 ) ? x : x - P; }
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 > explicit inline constexpr operator T()const { return val(); }
	inline constexpr friend bool operator==(const MontgomeryModInt &x, const MontgomeryModInt &y) { return x.val() == y.val(); }
	inline constexpr friend bool operator!=(const MontgomeryModInt &x, const MontgomeryModInt &y) { return x.val() != y.val(); }
	inline constexpr MontgomeryModInt &operator=(const MontgomeryModInt &x) & { v = x.v; return *this; }
	inline constexpr MontgomeryModInt &operator++() & { return *this += 1; }
	inline constexpr MontgomeryModInt operator++(int) & { MontgomeryModInt x = *this; *this += 1; return x; }
	inline constexpr MontgomeryModInt &operator--() & { return *this -= 1; }
	inline constexpr MontgomeryModInt operator--(int) & { MontgomeryModInt x = *this; *this -= 1; return x; }
	inline constexpr MontgomeryModInt operator-()const { return MontgomeryModInt(v ? P2 - v : 0, 0); }
	inline constexpr MontgomeryModInt &operator+=(const MontgomeryModInt &x) & { v += x.v, ( v - P2 ) >> ( sizeof(U) * 8 - 1 ) || ( v -= P2 ); return *this; }
	inline constexpr MontgomeryModInt &operator-=(const MontgomeryModInt &x) & { v -= x.v, v >> ( sizeof(U) * 8 - 1 ) && ( v += P2 ); return *this; }
	inline constexpr MontgomeryModInt &operator*=(const MontgomeryModInt &x) & { v = reduce((D)v * x.v); return *this; }
	inline constexpr MontgomeryModInt &operator/=(const MontgomeryModInt &x) & { return *this *= x.inv(); }
	inline constexpr friend MontgomeryModInt operator+(MontgomeryModInt x, const MontgomeryModInt &y) { return x += y; }
	inline constexpr friend MontgomeryModInt operator-(MontgomeryModInt x, const MontgomeryModInt &y) { return x -= y; }
	inline constexpr friend MontgomeryModInt operator*(MontgomeryModInt x, const MontgomeryModInt &y) { return x *= y; }
	inline constexpr friend MontgomeryModInt operator/(MontgomeryModInt x, const MontgomeryModInt &y) { return x /= y; }
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 > inline constexpr MontgomeryModInt qpow(T y)const { MontgomeryModInt x = *this, z = 1; while ( y ) { if ( y & 1 ) z *= x; if ( y >>= 1 ) x *= x; } return z; }
	template < class T, enable_if_t < numeric_limits < T >::is_integer, int > = 0 > inline constexpr friend MontgomeryModInt qpow(const MontgomeryModInt &x, T y) { return x.qpow(y); }
	inline constexpr MontgomeryModInt inv()const { return qpow(P - 2); }
	inline constexpr friend MontgomeryModInt inv(const MontgomeryModInt &x) { return x.inv(); }
	inline friend istream &operator>>(istream &is, MontgomeryModInt &x) { S y; is >> y, x = y; return is; }
	inline friend ostream &operator<<(ostream &os, const MontgomeryModInt &x) { return os << x.val(); }
#ifdef USE_FastIO
	inline void read() & { S x; ::read(x), *this = x; }
	inline void write()const { ::write(val()); }
#endif
};	using MI = MontgomeryModInt < 1145141919810000037ll >; // 1000000007 1145141919810000037ll
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
template < class T > inline T R(T l, T r) { return uniform_int_distribution < T >(l, r)(rnd); }
const MI B = MI::mod() / 2 + R(-2333333333ll, 2333333333ll); MI pw[200009], w[200009];
int n, q, _, o, l, r, lp, rp, rt[200009], id[200009], mn[200009], mx[200009];
int ww[200009], pp[200009], qq[200009], cnt[400009], sz[400009];
vector < pair < int, int > > mdf[200009], mdf2[200009]; vector < int > vec[200009]; ll ans;
inline ll calc(int x) { return max(0ll, (ll)cnt[x] * sz[x] - 1); }
namespace DSU
{
	int fa[400009];
	inline void init(int n) { iota(fa + 1, fa + n + 2, 1); }
	inline int fat(int x) { return x == fa[x] ? x : fa[x] = fat(fa[x]); }
	inline void mrg(int l, int r)
	{
		for ( l = fat(l) ; l < r ; )
		{
			int p = fat(l + 1); ans -= calc(l) + calc(p);
			cnt[p] += cnt[l], sz[p] += sz[l], ans += calc(p), l = fa[l] = p;
		}
	}
}
namespace ST
{
	struct node
	{
		int lc, rc; MI h; bool lz;
		inline void apply(int len) { h = w[len] - h, lz = !lz; }
	}	t[40000009]; int cnt;
	inline int &cpy(int &p) { return t[++cnt] = t[p], p = cnt; }
	inline int &lc(int p) { return t[p].lc; }
	inline int &rc(int p) { return t[p].rc; }
	inline int md(int l, int r) { return ( l + r ) >> 1; }
	inline void pu(int p, int l, int r) { t[p].h = t[lc(p)].h * pw[r - md(l, r)] + t[rc(p)].h; }
	inline void pd(int p, int l, int r)
	{
		if ( !t[p].lz ) return;
		t[cpy(lc(p))].apply(md(l, r) - l + 1), t[cpy(rc(p))].apply(r - md(l, r)), t[p].lz = false;
	}
	inline void flip(int &p, int l, int r, int lp, int rp)
	{
		if ( l > rp || r < lp ) return;
		cpy(p);
		if ( lp <= l && r <= rp ) { t[p].apply(r - l + 1); return; }
		pd(p, l, r), flip(lc(p), l, md(l, r), lp, rp),
					 flip(rc(p), md(l, r) + 1, r, lp, rp), pu(p, l, r);
	}
	inline int cmp(int p, int q, int l, int r)
	{
		if ( t[p].h == t[q].h ) return 0;
		if ( !t[q].h || t[p].h == w[r - l + 1] ) return  1;
		if ( !t[p].h || t[q].h == w[r - l + 1] ) return -1;
		pd(p, l, r), pd(q, l, r); int res = cmp(lc(p), lc(q), l, md(l, r));
		return res ? res : cmp(rc(p), rc(q), md(l, r) + 1, r);
	}
}
namespace ST_
{
	struct node
	{
		int mn0, mx0, mn1, mx1, s; bool lz;
		inline void apply(int len) { swap(mn0, mn1), swap(mx0, mx1), s = len - s, lz = !lz; }
	}	t[200009 << 2];
	inline int lc(int p) { return p << 1; }
	inline int rc(int p) { return p << 1 | 1; }
	inline int md(int l, int r) { return ( l + r ) >> 1; }
	inline void pu(int p)
	{
		t[p].mn0 = min(t[lc(p)].mn0, t[rc(p)].mn0), t[p].mx0 = max(t[lc(p)].mx0, t[rc(p)].mx0),
		t[p].mn1 = min(t[lc(p)].mn1, t[rc(p)].mn1), t[p].mx1 = max(t[lc(p)].mx1, t[rc(p)].mx1),
		t[p].s = t[lc(p)].s + t[rc(p)].s;
	}
	inline void pd(int p, int l, int r) 
	{
		if ( t[p].lz ) t[lc(p)].apply(md(l, r) - l + 1),
					   t[rc(p)].apply(r - md(l, r)), t[p].lz = false;
	}
	inline void build(int p, int l, int r)
	{
		if ( l == r ) { t[p].mn0 = t[p].mx0 = ww[l], t[p].mn1 = n + 1; return; }
		build(lc(p), l, md(l, r)), build(rc(p), md(l, r) + 1, r), pu(p);
	}
	inline void flip(int p, int l, int r, int lp, int rp)
	{
		if ( l > rp || r < lp ) return;
		if ( lp <= l && r <= rp ) { t[p].apply(r - l + 1); return; }
		pd(p, l, r), flip(lc(p), l, md(l, r), lp, rp), flip(rc(p), md(l, r) + 1, r, lp, rp), pu(p);
	}
}
int main()
{
	read(n, q, _), *pw = 1;
	For(i, 1, n) pw[i] = pw[i - 1] * B, w[i] = w[i - 1] + pw[i - 1];
	while ( q-- ) read(l, r, lp, rp), mdf[l].emplace_back(lp, rp), mdf[r + 1].emplace_back(lp, rp),
									  mdf2[lp].emplace_back(l, r), mdf2[rp + 1].emplace_back(l, r);
	For(i, 1, n)
	{
		id[i] = i, rt[i] = rt[i - 1];
		for ( auto [l, r] : mdf[i] ) ST::flip(rt[i], 1, n, l, r);
	}
	stable_sort(id + 1, id + n + 1, [&](int x, int y) { return ST::cmp(rt[x], rt[y], 1, n) < 0; });
	For(i, 1, n) ww[id[i]] = i;
	ST_::build(1, 1, n);
	For(i, 1, n)
	{
		for ( auto [l, r] : mdf2[i] ) ST_::flip(1, 1, n, l, r);
		mn[i] = ST_::t[1].mn1, mx[i] = ST_::t[1].mx0, vec[n - ST_::t[1].s].push_back(i);
	}
	For(i, 0, n)
	{
		if ( i ) pp[i] = ++o, sz[o] = 1;
		for ( int j : vec[i] ) qq[j] = ++o;
	}
	DSU::init(n + n);
	For(i, 1, n)
	{
		if ( mn[i] <= mx[i] ) DSU::mrg(pp[mn[i]], pp[mx[i]]);
		o = DSU::fat(qq[i]), ans -= calc(o), cnt[o]++, ans += calc(o);
		if ( _ || i == n ) write((ll)i * n - ans, i == n ? '\n' : ' ');
	}
	return 0;
}
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 72ms
memory: 942744kb

input:

4 1000 0
2 3 1 2
1 3 1 3
1 2 1 2
1 2 3 4
1 4 2 4
1 3 1 2
1 4 1 2
1 3 1 4
3 3 2 3
1 2 2 4
4 4 1 3
3 3 3 4
3 4 3 4
2 3 1 1
1 2 2 4
1 4 3 4
3 4 1 2
1 2 2 3
3 4 3 3
1 2 4 4
4 4 2 4
1 4 1 1
1 1 1 3
2 3 2 3
1 1 2 4
2 3 2 4
3 3 1 4
3 3 3 3
1 3 3 3
2 3 2 4
3 3 2 2
1 3 2 4
1 3 1 2
3 4 1 2
2 3 1 3
1 1 1 2
1 2...

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 5
Accepted
time: 79ms
memory: 954192kb

input:

4 1000 0
1 4 3 3
2 3 4 4
3 4 3 4
3 4 1 2
1 4 2 4
2 3 1 3
3 4 2 4
2 3 3 3
3 4 1 3
1 3 1 4
2 3 1 3
1 1 2 2
1 4 3 4
1 4 1 3
1 2 3 4
1 2 1 2
2 3 1 4
2 2 2 2
1 3 1 3
2 2 2 4
1 2 1 4
1 1 1 1
1 2 3 4
4 4 1 3
2 4 1 3
1 1 1 3
1 4 2 2
2 3 1 2
2 2 1 2
1 2 1 4
1 4 2 4
1 2 1 3
1 2 1 3
2 4 2 2
1 2 1 1
1 2 1 3
2 4...

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 5
Accepted
time: 104ms
memory: 941908kb

input:

4 1000 0
1 4 1 2
1 4 2 2
1 4 3 4
2 4 4 4
2 3 3 4
2 4 2 4
1 2 2 2
4 4 2 4
1 3 1 3
1 4 1 4
3 3 3 4
4 4 2 3
2 3 1 4
2 2 1 3
2 3 2 4
2 2 1 4
1 2 2 3
1 4 1 3
4 4 1 4
3 4 1 4
1 2 1 2
1 2 1 3
2 2 3 3
1 2 1 4
1 1 1 4
2 2 1 4
1 4 3 4
2 4 2 4
2 2 1 4
3 4 1 3
2 3 2 4
1 3 1 4
1 3 1 4
3 3 1 3
1 2 1 3
3 3 1 4
1 4...

output:

5

result:

ok 1 number(s): "5"

Subtask #2:

score: 10
Accepted

Test #4:

score: 10
Accepted
time: 136ms
memory: 950768kb

input:

50 200000 0
1 45 2 6
29 44 2 6
31 37 2 50
2 37 1 19
7 13 8 38
38 46 19 38
10 30 30 46
22 42 1 45
5 35 24 27
10 36 19 31
20 47 17 35
7 9 23 42
15 26 31 42
7 8 7 42
1 26 33 48
2 5 30 36
17 44 21 44
5 44 24 36
19 47 15 17
29 36 2 42
31 34 11 41
9 24 12 30
30 43 8 20
2 12 13 20
11 12 10 15
14 22 3 29
2 ...

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 10
Accepted
time: 67ms
memory: 941896kb

input:

50 70 0
1 50 1 50
24 50 1 1
50 50 2 2
34 50 3 3
36 50 4 4
32 50 5 5
18 50 6 6
12 50 7 7
6 50 8 8
28 50 9 9
38 50 10 10
4 50 11 11
26 50 12 12
14 50 13 13
46 50 14 14
2 50 15 15
8 50 16 16
44 50 17 17
10 50 18 18
30 50 19 19
22 50 20 20
48 50 21 21
20 50 22 22
42 50 23 23
40 50 24 24
16 50 25 25
16 5...

output:

2280

result:

ok 1 number(s): "2280"

Test #6:

score: 10
Accepted
time: 71ms
memory: 941984kb

input:

50 100 0
2 49 1 1
23 28 2 2
19 32 3 3
21 30 4 4
20 31 5 5
22 29 6 6
12 39 7 7
15 36 8 8
7 44 9 9
3 48 10 10
10 41 11 11
5 46 12 12
14 37 13 13
13 38 14 14
4 47 15 15
6 45 16 16
17 34 17 17
25 26 18 18
1 50 19 19
9 42 20 20
11 40 21 21
16 35 22 22
24 27 23 23
8 43 24 24
18 33 25 25
11 40 26 26
14 37 ...

output:

339

result:

ok 1 number(s): "339"

Test #7:

score: 10
Accepted
time: 84ms
memory: 942004kb

input:

50 500 0
1 2 1 14
3 4 1 3
5 6 1 12
7 8 1 9
9 10 1 15
11 12 1 11
13 14 1 13
15 16 1 17
17 18 1 16
19 20 1 20
21 22 1 2
23 24 1 10
25 26 1 4
27 28 1 8
29 30 1 19
31 32 1 21
33 34 1 24
35 36 1 23
37 38 1 6
39 40 1 18
41 42 1 25
43 44 1 5
45 46 1 22
47 48 1 1
49 50 1 7
35 36 26 26
41 42 26 26
27 28 27 2...

output:

51

result:

ok 1 number(s): "51"

Subtask #3:

score: 10
Accepted

Test #8:

score: 10
Accepted
time: 395ms
memory: 961532kb

input:

5000 200000 0
1438 2561 3478 4930
1740 4634 87 3003
590 3275 1376 1681
2035 2793 2004 4945
567 3159 550 4470
61 3039 3431 3519
2654 3834 3460 4960
591 3560 409 443
345 2599 746 2891
1288 4570 1577 4402
249 377 1951 4534
2411 2455 294 1192
1679 3153 1645 4259
1735 1856 601 668
477 4881 411 2094
424 1...

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: 10
Accepted
time: 128ms
memory: 954564kb

input:

5000 200000 0
4336 5000 1 1
686 5000 2 2
3130 5000 3 3
672 5000 4 4
1664 5000 5 5
1480 5000 6 6
1326 5000 7 7
3726 5000 8 8
4170 5000 9 9
4794 5000 10 10
3374 5000 11 11
1836 5000 12 12
310 5000 13 13
2146 5000 14 14
3266 5000 15 15
820 5000 16 16
1152 5000 17 17
2876 5000 18 18
134 5000 19 19
828 5...

output:

24995

result:

ok 1 number(s): "24995"

Test #10:

score: 10
Accepted
time: 154ms
memory: 955216kb

input:

5000 200000 0
1410 5000 1 1
3340 5000 2 2
4202 5000 3 3
4450 5000 4 4
914 5000 5 5
4514 5000 6 6
4 5000 7 7
238 5000 8 8
3182 5000 9 9
3302 5000 10 10
2136 5000 11 11
1504 5000 12 12
3204 5000 13 13
2078 5000 14 14
4026 5000 15 15
3690 5000 16 16
4430 5000 17 17
1304 5000 18 18
2156 5000 19 19
4154 ...

output:

10000

result:

ok 1 number(s): "10000"

Test #11:

score: 10
Accepted
time: 194ms
memory: 956684kb

input:

5000 200000 0
1556 3445 1 1
1803 3198 2 2
790 4211 3 3
564 4437 4 4
1128 3873 5 5
129 4872 6 6
2062 2939 7 7
1480 3521 8 8
1252 3749 9 9
942 4059 10 10
111 4890 11 11
915 4086 12 12
1575 3426 13 13
2186 2815 14 14
392 4609 15 15
1689 3312 16 16
492 4509 17 17
866 4135 18 18
381 4620 19 19
92 4909 20...

output:

34989

result:

ok 1 number(s): "34989"

Test #12:

score: 10
Accepted
time: 235ms
memory: 954904kb

input:

5000 200000 0
1 1 2330 2671
2 2 789 4212
3 3 1593 3408
4 4 438 4563
5 5 2048 2953
6 6 491 4510
7 7 578 4423
8 8 770 4231
9 9 482 4519
10 10 395 4606
11 11 1960 3041
12 12 1289 3712
13 13 621 4380
14 14 2235 2766
15 15 916 4085
16 16 781 4220
17 17 1440 3561
18 18 902 4099
19 19 1998 3003
20 20 641 4...

output:

49977

result:

ok 1 number(s): "49977"

Test #13:

score: 10
Accepted
time: 321ms
memory: 955632kb

input:

5000 200000 0
1 661 1 2
1 1385 3 4
1 225 5 6
1 1833 7 8
1 58 9 10
1 2064 11 12
1 235 13 14
1 1918 15 16
1 2137 17 18
1 538 19 20
1 513 21 22
1 1405 23 24
1 1376 25 26
1 1711 27 28
1 165 29 30
1 209 31 32
1 68 33 34
1 1864 35 36
1 1455 37 38
1 425 39 40
1 669 41 42
1 2326 43 44
1 133 45 46
1 2257 47 ...

output:

5001

result:

ok 1 number(s): "5001"

Subtask #4:

score: 10
Accepted

Test #14:

score: 10
Accepted
time: 420ms
memory: 964208kb

input:

5000 200000 1
565 4401 1659 1826
429 1640 2999 3495
572 3994 9 3863
3844 4284 2307 3144
1054 1943 358 2592
727 4248 29 1171
1685 2392 4559 4929
1149 2787 1204 1947
2349 2619 405 998
1910 2786 25 1275
912 3475 4384 4387
3822 4895 1849 4548
3082 4749 3457 4220
3174 4885 117 1085
2517 3919 4325 4869
17...

output:

5000 5653 3715 1781 1031 823 540 185 190 71 56 61 66 71 76 81 86 91 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

result:

ok 5000 numbers

Test #15:

score: 10
Accepted
time: 150ms
memory: 955120kb

input:

5000 200000 1
1 1 4840 5000
2 2 1690 5000
3 3 908 5000
4 4 1212 5000
5 5 2712 5000
6 6 3950 5000
7 7 4724 5000
8 8 3706 5000
9 9 1888 5000
10 10 4056 5000
11 11 1074 5000
12 12 3806 5000
13 13 3756 5000
14 14 2822 5000
15 15 1264 5000
16 16 4088 5000
17 17 796 5000
18 18 4888 5000
19 19 4610 5000
20...

output:

5000 9997 14997 19997 24997 29994 34974 39958 44944 49928 54902 59872 64858 69833 74833 79777 84760 89728 94710 99675 104675 109599 114578 119536 124492 129423 134374 139298 144270 149188 154130 159041 163948 168851 173814 178678 183638 188563 193522 198522 203288 208204 213158 218030 222898 227719 ...

result:

ok 5000 numbers

Test #16:

score: 10
Accepted
time: 131ms
memory: 954556kb

input:

5000 200000 1
4090 5000 1 1
3772 5000 2 2
3880 5000 3 3
1888 5000 4 4
2602 5000 5 5
4934 5000 6 6
4224 5000 7 7
226 5000 8 8
176 5000 9 9
2862 5000 10 10
224 5000 11 11
1204 5000 12 12
3202 5000 13 13
2726 5000 14 14
3468 5000 15 15
2134 5000 16 16
4392 5000 17 17
4814 5000 18 18
3748 5000 19 19
390...

output:

5000 10000 15000 20000 25000 30000 35000 40000 45000 50000 55000 60000 65000 70000 75000 80000 85000 90000 95000 100000 105000 110000 115000 120000 125000 130000 135000 140000 145000 150000 155000 160000 165000 170000 175000 180000 185000 190000 195000 200000 205000 210000 215000 220000 225000 23000...

result:

ok 5000 numbers

Test #17:

score: 10
Accepted
time: 176ms
memory: 955896kb

input:

5000 200000 1
1443 3558 1 1
2025 2976 2 2
837 4164 3 3
2197 2804 4 4
1545 3456 5 5
2471 2530 6 6
764 4237 7 7
2462 2539 8 8
44 4957 9 9
2283 2718 10 10
742 4259 11 11
959 4042 12 12
1558 3443 13 13
1111 3890 14 14
2090 2911 15 15
687 4314 16 16
509 4492 17 17
1461 3540 18 18
2060 2941 19 19
2218 278...

output:

5000 10000 15000 20000 25000 30000 35000 40000 45000 50000 55000 60000 65000 70000 75000 80000 85000 90000 95000 100000 105000 110000 115000 120000 125000 130000 135000 140000 145000 150000 155000 160000 165000 170000 175000 180000 185000 190000 195000 200000 205000 210000 215000 220000 225000 23000...

result:

ok 5000 numbers

Test #18:

score: 10
Accepted
time: 251ms
memory: 956484kb

input:

5000 200000 1
1 1 1194 3807
2 2 721 4280
3 3 471 4530
4 4 142 4859
5 5 1727 3274
6 6 1549 3452
7 7 551 4450
8 8 981 4020
9 9 1649 3352
10 10 2233 2768
11 11 980 4021
12 12 1498 3503
13 13 196 4805
14 14 381 4620
15 15 2085 2916
16 16 1559 3442
17 17 890 4111
18 18 1853 3148
19 19 527 4474
20 20 881 ...

output:

5000 10000 14973 19950 24950 29950 34950 39833 44833 49758 54691 59605 64557 69557 74557 79557 84557 89151 94065 98975 103975 108975 113975 118975 123975 128251 133251 138030 143030 147768 152768 157768 162768 167163 172009 177009 181653 186486 191486 196140 200961 205778 210591 215591 220205 225205...

result:

ok 5000 numbers

Test #19:

score: 10
Accepted
time: 363ms
memory: 956380kb

input:

5000 200000 1
1 2402 1 2
1 85 3 4
1 610 5 6
1 531 7 8
1 1258 9 10
1 2389 11 12
1 885 13 14
1 1658 15 16
1 2210 17 18
1 643 19 20
1 1079 21 22
1 499 23 24
1 1768 25 26
1 224 27 28
1 237 29 30
1 124 31 32
1 359 33 34
1 248 35 36
1 1896 37 38
1 1867 39 40
1 625 41 42
1 2407 43 44
1 2370 45 46
1 2177 47...

output:

5000 7635 2635 2261 1936 1645 1611 1705 1873 2021 2223 2401 2601 2801 3001 3201 3401 3601 3801 4001 4201 4401 4601 4801 5001 5201 5401 5601 5801 6001 6201 6401 6601 6801 7001 7201 7401 7601 7801 8001 8201 8401 8386 8581 8776 8971 9166 9361 9556 9751 9946 10141 10336 10531 10726 10921 11116 11311 115...

result:

ok 5000 numbers

Test #20:

score: 10
Accepted
time: 332ms
memory: 957088kb

input:

5000 200000 1
1 2 1 1040
3 4 1 742
5 6 1 187
7 8 1 378
9 10 1 595
11 12 1 1296
13 14 1 1104
15 16 1 2266
17 18 1 1137
19 20 1 1383
21 22 1 2167
23 24 1 1540
25 26 1 118
27 28 1 1783
29 30 1 2023
31 32 1 2185
33 34 1 1951
35 36 1 2292
37 38 1 2268
39 40 1 458
41 42 1 88
43 44 1 120
45 46 1 1782
47 48...

output:

5000 10000 15000 20000 25000 30000 35000 40000 45000 50000 55000 60000 65000 70000 75000 80000 85000 90000 95000 100000 105000 110000 115000 120000 125000 130000 135000 140000 145000 150000 155000 160000 165000 170000 175000 180000 185000 190000 195000 200000 205000 210000 215000 220000 225000 23000...

result:

ok 5000 numbers

Subtask #5:

score: 15
Accepted

Test #21:

score: 15
Accepted
time: 835ms
memory: 995040kb

input:

200000 200000 1
1 2 1 6
3 4 1 1
5 6 1 5
7 8 1 3
9 10 1 3
11 12 1 6
13 14 1 5
15 16 1 6
17 18 1 6
19 20 1 1
21 22 1 4
23 24 1 5
25 26 1 2
27 28 1 4
29 30 1 3
31 32 1 2
33 34 1 6
35 36 1 3
37 38 1 2
39 40 1 2
41 42 1 3
43 44 1 1
45 46 1 2
47 48 1 3
49 50 1 4
51 52 1 5
53 54 1 1
55 56 1 5
57 58 1 5
59 ...

output:

200000 400000 532619 597930 598645 533081 733081 933081 631687 831687 1031687 1064777 1264777 1464777 1664777 1864777 1897874 2097874 2297874 2330961 2530961 2730961 2764057 2964057 3164057 3364057 3564057 3764057 3964057 3997153 4197153 4397153 4597153 4797153 4997153 5197153 5230249 5430249 563024...

result:

ok 200000 numbers

Test #22:

score: 15
Accepted
time: 756ms
memory: 994284kb

input:

200000 200000 1
1 4 1 2
1 3 3 4
1 6 5 6
1 2 7 8
1 2 9 10
1 6 11 12
1 2 13 14
1 3 15 16
1 3 17 18
1 6 19 20
1 1 21 22
1 5 23 24
1 1 25 26
1 6 27 28
1 1 29 30
1 1 31 32
1 1 33 34
1 5 35 36
1 3 37 38
1 1 39 40
1 2 41 42
1 6 43 44
1 3 45 46
1 4 47 48
1 3 49 50
1 4 51 52
1 4 53 54
1 1 55 56
1 4 57 58
1 3...

output:

200000 400000 599992 799992 999981 1199971 1399971 1599938 1799938 1999921 2199911 2399901 2599901 2799901 2999891 3199869 3399858 3599847 3799806 3999793 4199686 4399686 4599671 4799656 4999593 5199551 5399533 5599515 5799469 5999421 6199421 6399371 6599371 6799319 6999137 7199044 7399015 7598986 7...

result:

ok 200000 numbers

Test #23:

score: 15
Accepted
time: 723ms
memory: 995496kb

input:

200000 200000 1
1 2 1 2
1 6 3 4
1 1 5 6
1 2 7 8
1 5 9 10
1 2 11 12
1 6 13 14
1 1 15 16
1 3 17 18
1 5 19 20
1 3 21 22
1 6 23 24
1 5 25 26
1 2 27 28
1 1 29 30
1 3 31 32
1 2 33 34
1 2 35 36
1 3 37 38
1 5 39 40
1 6 41 42
1 2 43 44
1 5 45 46
1 5 47 48
1 3 49 50
1 5 51 52
1 2 53 54
1 5 55 56
1 6 57 58
1 1...

output:

200000 400000 600000 800000 1000000 1199971 1399965 1599952 1799945 1999929 2199901 2399869 2599833 2799819 2999819 3199819 3399777 3599746 3799729 3999712 4199695 4399659 4599641 4799602 4999539 5199518 5399497 5599476 5799476 5999476 6199429 6399353 6599301 6799276 6999221 7199195 7399137 7599110 ...

result:

ok 200000 numbers

Test #24:

score: 15
Accepted
time: 842ms
memory: 996332kb

input:

200000 200000 1
1 2 3 6
3 4 3 6
5 6 3 5
7 8 3 6
9 10 3 4
11 12 2 5
13 14 2 5
15 16 2 2
17 18 1 1
19 20 2 3
21 22 3 5
23 24 2 5
25 26 1 5
27 28 2 5
29 30 1 4
31 32 1 1
33 34 1 6
35 36 3 7
37 38 3 7
39 40 1 6
41 42 2 5
43 44 3 7
45 46 1 5
47 48 2 3
49 50 2 7
51 52 1 2
53 54 3 8
55 56 3 5
57 58 3 5
59 ...

output:

200000 244003 133246 133117 111726 66913 1 1 200001 200001 400001 400001 600001 800001 1000001 1200001 1400001 1400001 1400001 1600001 1800001 1800001 2000001 2200001 2400001 2600001 2600001 2600001 2800001 3000001 3000001 3000001 3200001 3200001 3400001 3600001 3600001 3800001 4000001 4000001 40000...

result:

ok 200000 numbers

Test #25:

score: 15
Accepted
time: 1136ms
memory: 999140kb

input:

200000 200000 1
62179 62180 166600 166600
168902 168904 109106 109107
71739 71741 40856 40856
68155 68155 50355 50355
82427 82427 131433 131435
134495 134497 97523 97524
100523 100523 163640 163642
103078 103078 39321 39321
75997 75997 52778 52780
141945 141946 67489 67489
20781 20782 198096 198098
...

output:

200000 399993 599993 799980 999965 1199946 1399935 1599889 1799873 1999848 2199848 2399848 2599801 2799801 2999801 3199759 3399759 3599725 3799611 3999581 4199551 4399457 4599372 4799263 4999165 5199061 5399014 5598923 5798828 5998828 6198633 6398501 6598311 6798165 6998013 7197942 7397721 7597645 7...

result:

ok 200000 numbers

Test #26:

score: 15
Accepted
time: 1118ms
memory: 997452kb

input:

200000 200000 1
172635 172635 165118 165120
182060 182062 140709 140711
79621 79622 120595 120597
22131 22132 38357 38357
15637 15637 73583 73583
163025 163027 90579 90579
98127 98129 186936 186938
15578 15580 67768 67769
170985 170986 105541 105542
166284 166285 199715 199715
179347 179347 86139 86...

output:

200000 400000 600000 799989 999965 1199941 1399911 1599889 1799849 1999794 2199771 2399771 2599715 2799677 2999611 3199611 3399511 3599416 3799345 3999270 4199227 4399070 4598981 4798867 4998813 5198713 5398585 5598451 5798207 5998057 6197985 6397826 6597826 6797691 6997521 7197377 7397377 7597163 7...

result:

ok 200000 numbers

Test #27:

score: 15
Accepted
time: 1140ms
memory: 998120kb

input:

200000 200000 1
192777 192779 177750 177752
143767 143769 170842 170843
26652 26654 75434 75435
43426 43427 188344 188345
139929 139929 172505 172506
176663 176665 58244 58246
32815 32815 193800 193801
148127 148127 103366 103368
136791 136793 152591 152591
33978 33979 63334 63334
108117 108117 1561...

output:

200000 400000 599993 799965 999946 1199929 1399917 1599881 1799821 1999801 2199737 2399653 2599533 2799469 2999356 3199281 3399236 3599137 3799089 3999041 4199041 4399041 4599041 4799041 4998972 5198879 5398713 5598657 5798551 5998389 6198327 6398181 6598087 6798087 6997991 7197800 7397729 7597394 7...

result:

ok 200000 numbers

Subtask #6:

score: 15
Accepted

Test #28:

score: 15
Accepted
time: 1734ms
memory: 1001068kb

input:

200000 200000 0
91264 123676 6826 154505
121351 188051 108158 131448
65413 163961 26771 116304
93852 110556 34929 187363
31794 142162 33578 38712
26574 67763 178013 197235
46436 146042 95 122860
11683 50463 60177 195245
60862 194711 37817 97212
144366 176271 113551 171098
120095 170517 73555 167299
...

output:

400001

result:

ok 1 number(s): "400001"

Test #29:

score: 15
Accepted
time: 1037ms
memory: 998800kb

input:

200000 200000 0
1 1 56536 200000
2 2 132706 200000
3 3 82540 200000
4 4 109520 200000
5 5 142654 200000
6 6 101918 200000
7 7 106538 200000
8 8 159544 200000
9 9 26906 200000
10 10 188164 200000
11 11 191128 200000
12 12 67484 200000
13 13 85262 200000
14 14 60094 200000
15 15 97210 200000
16 16 732...

output:

39999163316

result:

ok 1 number(s): "39999163316"

Test #30:

score: 15
Accepted
time: 707ms
memory: 1001404kb

input:

200000 200000 0
25800 200000 1 1
62940 200000 2 2
187740 200000 3 3
165776 200000 4 4
134702 200000 5 5
147858 200000 6 6
45252 200000 7 7
41426 200000 8 8
180134 200000 9 9
33128 200000 10 10
144100 200000 11 11
117322 200000 12 12
90626 200000 13 13
6478 200000 14 14
32082 200000 15 15
45174 20000...

output:

39999157648

result:

ok 1 number(s): "39999157648"

Test #31:

score: 15
Accepted
time: 1049ms
memory: 1005608kb

input:

200000 200000 0
52913 147088 1 1
89311 110690 2 2
33159 166842 3 3
22992 177009 4 4
79143 120858 5 5
12119 187882 6 6
72531 127470 7 7
88417 111584 8 8
50515 149486 9 9
6184 193817 10 10
51198 148803 11 11
94324 105677 12 12
9992 190009 13 13
99826 100175 14 14
72778 127223 15 15
78368 121633 16 16
...

output:

39997454775

result:

ok 1 number(s): "39997454775"

Test #32:

score: 15
Accepted
time: 1564ms
memory: 1005984kb

input:

200000 200000 0
1 1 66398 133603
2 2 95273 104728
3 3 87806 112195
4 4 43273 156728
5 5 83765 116236
6 6 24507 175494
7 7 16554 183447
8 8 38133 161868
9 9 93169 106832
10 10 18756 181245
11 11 23818 176183
12 12 23676 176325
13 13 69663 130338
14 14 4767 195234
15 15 89615 110386
16 16 62918 137083...

output:

39997455184

result:

ok 1 number(s): "39997455184"

Test #33:

score: 15
Accepted
time: 1060ms
memory: 1000688kb

input:

200000 200000 0
1 99109 1 2
1 41562 3 4
1 87395 5 6
1 75085 7 8
1 67893 9 10
1 61887 11 12
1 99675 13 14
1 56276 15 16
1 86066 17 18
1 16995 19 20
1 51396 21 22
1 59800 23 24
1 73886 25 26
1 98979 27 28
1 24742 29 30
1 64034 31 32
1 75999 33 34
1 65101 35 36
1 53859 37 38
1 84304 39 40
1 67647 41 42...

output:

400001

result:

ok 1 number(s): "400001"

Test #34:

score: 15
Accepted
time: 1318ms
memory: 1006364kb

input:

200000 200000 0
1 2 1 76333
3 4 1 90974
5 6 1 20814
7 8 1 72888
9 10 1 52071
11 12 1 18540
13 14 1 13489
15 16 1 17941
17 18 1 45362
19 20 1 16284
21 22 1 24187
23 24 1 41194
25 26 1 1558
27 28 1 10915
29 30 1 68928
31 32 1 6479
33 34 1 68983
35 36 1 7711
37 38 1 23648
39 40 1 68711
41 42 1 57310
43...

output:

2400001

result:

ok 1 number(s): "2400001"

Test #35:

score: 15
Accepted
time: 890ms
memory: 980068kb

input:

100000 200000 0
1 2 1 19771
3 4 1 39595
5 6 1 27581
7 8 1 41937
9 10 1 39232
11 12 1 39905
13 14 1 8441
15 16 1 48733
17 18 1 34518
19 20 1 6835
21 22 1 43762
23 24 1 37043
25 26 1 36455
27 28 1 19964
29 30 1 13725
31 32 1 35707
33 34 1 31784
35 36 1 27771
37 38 1 11420
39 40 1 27486
41 42 1 45341
4...

output:

100001

result:

ok 1 number(s): "100001"

Test #36:

score: 15
Accepted
time: 830ms
memory: 978212kb

input:

100000 200000 0
1 11465 1 2
1 25633 3 4
1 27381 5 6
1 16379 7 8
1 9499 9 10
1 35924 11 12
1 43463 13 14
1 41338 15 16
1 16887 17 18
1 12063 19 20
1 10427 21 22
1 16858 23 24
1 42462 25 26
1 45296 27 28
1 32959 29 30
1 45287 31 32
1 22414 33 34
1 802 35 36
1 21530 37 38
1 42845 39 40
1 4605 41 42
1 4...

output:

100001

result:

ok 1 number(s): "100001"

Subtask #7:

score: 35
Accepted

Test #37:

score: 35
Accepted
time: 879ms
memory: 978020kb

input:

100000 200000 1
1 22878 1 2
1 7957 3 4
1 21779 5 6
1 34321 7 8
1 41692 9 10
1 49473 11 12
1 10254 13 14
1 43995 15 16
1 46975 17 18
1 668 19 20
1 25996 21 22
1 24975 23 24
1 43259 25 26
1 4174 27 28
1 39330 29 30
1 35462 31 32
1 27523 33 34
1 5574 35 36
1 47955 37 38
1 47013 39 40
1 3846 41 42
1 276...

output:

100000 200000 195499 260665 271141 281125 247871 244233 167815 186461 119505 130369 136332 146819 139966 149297 158628 167959 38799 40841 42883 44925 46967 49009 51051 53093 55135 57177 59219 61261 63303 65345 67387 69429 71471 73513 75555 77597 79639 81681 83723 85765 87807 89849 82711 75257 69937 ...

result:

ok 100000 numbers

Test #38:

score: 35
Accepted
time: 899ms
memory: 980664kb

input:

100000 200000 1
1 2 1 49478
3 4 1 14485
5 6 1 31201
7 8 1 26895
9 10 1 40944
11 12 1 35847
13 14 1 19021
15 16 1 43774
17 18 1 20305
19 20 1 39980
21 22 1 13770
23 24 1 16404
25 26 1 45734
27 28 1 48842
29 30 1 16814
31 32 1 1987
33 34 1 29392
35 36 1 12267
37 38 1 17547
39 40 1 28676
41 42 1 9513
4...

output:

100000 200000 300000 400000 500000 600000 700000 800000 900000 1000000 1100000 1200000 1300000 1400000 1500000 1600000 1700000 1800000 1900000 2000000 2100000 2200000 2300000 2400000 2500000 2600000 2700000 2800000 2900000 3000000 3100000 3200000 3300000 3400000 3500000 3600000 3700000 3800000 39000...

result:

ok 100000 numbers

Test #39:

score: 35
Accepted
time: 954ms
memory: 981920kb

input:

100000 200000 1
1 2 1 35162
3 4 1 31702
5 6 1 1660
7 8 1 10240
9 10 1 8763
11 12 1 31436
13 14 1 18048
15 16 1 33735
17 18 1 36181
19 20 1 282
21 22 1 9633
23 24 1 5237
25 26 1 9143
27 28 1 42670
29 30 1 46242
31 32 1 2303
33 34 1 2467
35 36 1 38417
37 38 1 3307
39 40 1 19414
41 42 1 33762
43 44 1 3...

output:

100000 200000 300000 400000 500000 600000 700000 800000 900000 1000000 1100000 1200000 1300000 1400000 1500000 1600000 1700000 1800000 1900000 2000000 2100000 2200000 2300000 2400000 2500000 2600000 2700000 2800000 2900000 3000000 3100000 3200000 3300000 3400000 3500000 3600000 3700000 3800000 39000...

result:

ok 100000 numbers

Test #40:

score: 35
Accepted
time: 681ms
memory: 979704kb

input:

100000 200000 1
43178 56823 1 1
675 99326 2 2
15099 84902 3 3
4203 95798 4 4
23354 76647 5 5
41222 58779 6 6
15927 84074 7 7
39572 60429 8 8
40253 59748 9 9
32007 67994 10 10
15324 84677 11 11
29454 70547 12 12
31223 68778 13 13
7737 92264 14 14
33351 66650 15 15
45210 54791 16 16
28837 71164 17 17
...

output:

100000 200000 300000 400000 500000 600000 700000 800000 900000 1000000 1100000 1200000 1300000 1400000 1500000 1600000 1700000 1800000 1900000 2000000 2100000 2200000 2300000 2400000 2500000 2600000 2700000 2800000 2900000 3000000 3100000 3200000 3300000 3400000 3500000 3600000 3700000 3800000 39000...

result:

ok 100000 numbers

Test #41:

score: 35
Accepted
time: 1263ms
memory: 983740kb

input:

100000 200000 1
24 82240 56597 91255
26810 82165 18477 22393
9362 24598 53820 92593
68653 83682 16581 31580
17086 81545 70066 71299
26891 53343 4122 35933
27137 61932 16905 52055
9728 69119 26769 80202
7404 34071 3636 52818
59726 95606 6460 97518
7723 22242 61797 94241
25097 71751 56647 65839
45036 ...

output:

100000 130029 41890 25005 21841 23671 27616 31561 35506 30751 33826 35041 37961 40881 19756 21073 22390 23707 25024 26341 27658 20087 21000 21913 22826 23739 24652 25565 26478 27391 28304 29217 16006 16491 16976 17461 17946 18431 18916 19401 19886 20371 20856 21341 21826 22311 22796 23281 23766 2425...

result:

ok 100000 numbers

Test #42:

score: 35
Accepted
time: 1262ms
memory: 979056kb

input:

100000 200000 1
10442 70043 2175 22031
4751 86216 49718 75813
11230 75716 34714 50209
16942 65616 33095 95840
33191 72240 14261 31402
9935 34540 12217 30676
58193 92643 17134 90866
23201 90801 51849 97032
21201 27012 54197 54348
82079 92697 60976 72155
53763 74827 13276 64080
55841 57573 19848 58819...

output:

100000 200000 151606 78017 75741 85945 44430 32873 36982 41091 45200 13405 10544 11355 12166 12977 13788 14473 15277 16081 16885 17689 15618 16297 16976 17655 18334 19013 19692 20371 21050 21729 22408 23087 23766 24445 25124 25803 26482 27161 27840 28519 29198 29877 30556 31235 31914 32593 33272 339...

result:

ok 100000 numbers

Test #43:

score: 35
Accepted
time: 691ms
memory: 1002540kb

input:

200000 200000 1
191770 200000 1 1
49834 200000 2 2
137006 200000 3 3
16604 200000 4 4
174746 200000 5 5
164448 200000 6 6
60062 200000 7 7
186290 200000 8 8
96212 200000 9 9
14358 200000 10 10
37358 200000 11 11
75496 200000 12 12
97964 200000 13 13
110230 200000 14 14
9604 200000 15 15
188424 20000...

output:

200000 400000 600000 800000 1000000 1200000 1400000 1600000 1800000 2000000 2200000 2400000 2600000 2800000 3000000 3200000 3400000 3600000 3800000 4000000 4200000 4400000 4600000 4800000 5000000 5200000 5400000 5600000 5800000 6000000 6200000 6400000 6600000 6800000 7000000 7200000 7400000 7600000 ...

result:

ok 200000 numbers

Test #44:

score: 35
Accepted
time: 1041ms
memory: 1001160kb

input:

200000 200000 1
1 1 47436 200000
2 2 145508 200000
3 3 86384 200000
4 4 89596 200000
5 5 54700 200000
6 6 109498 200000
7 7 93690 200000
8 8 112142 200000
9 9 128928 200000
10 10 186574 200000
11 11 120000 200000
12 12 113798 200000
13 13 141426 200000
14 14 128510 200000
15 15 21714 200000
16 16 75...

output:

200000 400000 600000 800000 1000000 1200000 1399993 1599986 1799973 1999961 2199953 2399938 2599938 2799938 2999938 3199933 3399927 3599919 3799914 3999903 4199903 4399903 4599903 4799892 4999883 5199872 5399864 5599850 5799834 5999808 6199796 6399796 6599796 6799796 6999796 7199796 7399796 7599796 ...

result:

ok 200000 numbers

Test #45:

score: 35
Accepted
time: 996ms
memory: 1000444kb

input:

200000 200000 1
1 1 123918 200000
2 2 77032 200000
3 3 136820 200000
4 4 162384 200000
5 5 4904 200000
6 6 22228 200000
7 7 142570 200000
8 8 115024 200000
9 9 192398 200000
10 10 122324 200000
11 11 178300 200000
12 12 196486 200000
13 13 39810 200000
14 14 134430 200000
15 15 184864 200000
16 16 7...

output:

200000 400000 600000 800000 1000000 1199997 1399992 1599985 1799981 1999971 2199966 2399966 2599966 2799963 2999961 3199955 3399952 3599937 3799932 3999903 4199895 4399877 4599877 4799877 4999877 5199872 5399869 5599869 5799869 5999864 6199858 6399846 6599840 6799828 6999814 7199790 7399780 7599760 ...

result:

ok 200000 numbers

Test #46:

score: 35
Accepted
time: 1608ms
memory: 1004748kb

input:

200000 200000 1
1 1 82579 117422
2 2 63022 136979
3 3 8144 191857
4 4 64744 135257
5 5 1783 198218
6 6 41837 158164
7 7 71106 128895
8 8 31078 168923
9 9 3943 196058
10 10 56362 143639
11 11 67719 132282
12 12 8975 191026
13 13 31283 168718
14 14 19388 180613
15 15 76274 123727
16 16 61568 138433
17...

output:

200000 400000 600000 800000 1000000 1200000 1400000 1600000 1800000 2000000 2200000 2400000 2600000 2800000 3000000 3200000 3400000 3600000 3800000 4000000 4200000 4400000 4600000 4800000 5000000 5200000 5400000 5600000 5800000 6000000 6200000 6400000 6600000 6800000 7000000 7200000 7400000 7600000 ...

result:

ok 200000 numbers

Test #47:

score: 35
Accepted
time: 1610ms
memory: 1005492kb

input:

200000 200000 1
1 1 53027 146974
2 2 47299 152702
3 3 94867 105134
4 4 64012 135989
5 5 55552 144449
6 6 35166 164835
7 7 36618 163383
8 8 22902 177099
9 9 6101 193900
10 10 74168 125833
11 11 86934 113067
12 12 90059 109942
13 13 55109 144892
14 14 67424 132577
15 15 79712 120289
16 16 75707 124294...

output:

200000 400000 600000 800000 1000000 1200000 1400000 1600000 1800000 2000000 2200000 2400000 2600000 2800000 3000000 3200000 3400000 3600000 3800000 4000000 4200000 4400000 4600000 4800000 5000000 5200000 5400000 5600000 5800000 6000000 6200000 6400000 6600000 6800000 7000000 7200000 7400000 7600000 ...

result:

ok 200000 numbers

Test #48:

score: 35
Accepted
time: 1086ms
memory: 1006036kb

input:

200000 200000 1
67288 132713 1 1
49773 150228 2 2
41713 158288 3 3
83513 116488 4 4
98696 101305 5 5
18310 181691 6 6
68386 131615 7 7
71251 128750 8 8
39058 160943 9 9
84043 115958 10 10
61872 138129 11 11
95740 104261 12 12
15793 184208 13 13
53398 146603 14 14
75066 124935 15 15
13068 186933 16 1...

output:

200000 400000 600000 800000 1000000 1200000 1400000 1600000 1800000 2000000 2200000 2400000 2600000 2800000 3000000 3200000 3400000 3600000 3800000 4000000 4200000 4400000 4600000 4800000 5000000 5200000 5400000 5600000 5800000 6000000 6200000 6400000 6600000 6800000 7000000 7200000 7400000 7600000 ...

result:

ok 200000 numbers

Test #49:

score: 35
Accepted
time: 1110ms
memory: 1004804kb

input:

200000 200000 1
62126 137875 1 1
76402 123599 2 2
70364 129637 3 3
28999 171002 4 4
6601 193400 5 5
46650 153351 6 6
22854 177147 7 7
21102 178899 8 8
60671 139330 9 9
12158 187843 10 10
69159 130842 11 11
79623 120378 12 12
85415 114586 13 13
14428 185573 14 14
36043 163958 15 15
67689 132312 16 16...

output:

200000 400000 600000 800000 1000000 1200000 1400000 1600000 1800000 2000000 2200000 2400000 2600000 2800000 3000000 3200000 3400000 3600000 3800000 4000000 4200000 4400000 4600000 4800000 5000000 5200000 5400000 5600000 5800000 6000000 6200000 6400000 6600000 6800000 7000000 7200000 7400000 7600000 ...

result:

ok 200000 numbers

Test #50:

score: 35
Accepted
time: 1633ms
memory: 1006252kb

input:

200000 200000 1
1 1 80000 120001
2 2 39479 160522
3 3 88314 111687
4 4 4715 195286
5 5 47511 152490
6 6 87159 112842
7 7 48784 151217
8 8 67603 132398
9 9 59415 140586
10 10 9894 190107
11 11 35357 164644
12 12 26658 173343
13 13 4891 195110
14 14 45616 154385
15 15 80953 119048
16 16 88368 111633
1...

output:

200000 400000 600000 800000 1000000 1200000 1400000 1600000 1800000 2000000 2200000 2400000 2600000 2800000 3000000 3200000 3400000 3600000 3800000 4000000 4200000 4400000 4600000 4800000 5000000 5200000 5400000 5600000 5800000 6000000 6200000 6400000 6600000 6800000 7000000 7200000 7400000 7600000 ...

result:

ok 200000 numbers