QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#679440#9526. Subsequence Countingucup-team159#TL 1961ms58876kbC++2311.1kb2024-10-26 17:36:262024-10-26 17:36:29

Judging History

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

  • [2024-10-26 17:36:29]
  • 评测
  • 测评结果:TL
  • 用时:1961ms
  • 内存:58876kb
  • [2024-10-26 17:36:26]
  • 提交

answer

#line 1 "H.cpp"
// #pragma GCC target("avx2,avx512f,avx512vl,avx512bw,avx512dq,avx512cd,avx512vbmi,avx512vbmi2,avx512vpopcntdq,avx512bitalg,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("Ofast")

#line 2 "/home/sigma/comp/library/template.hpp"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> bool chmax(T& x, U y){
	if(x<y){ x=y; return true; }
	return false;
}
template<class T,class U> bool chmin(T& x, U y){
	if(y<x){ x=y; return true; }
	return false;
}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class T>
V<T> Vec(size_t a) {
    return V<T>(a);
}
template<class T, class... Ts>
auto Vec(size_t a, Ts... ts) {
  return V<decltype(Vec<T>(ts...))>(a, Vec<T>(ts...));
}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

template<class D> D divFloor(D a, D b){
	return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}
template<class D> D divCeil(D a, D b) {
	return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}
#line 1 "/home/sigma/comp/library/math/mint.cpp"
/*
	任意mod なら 
	template なくして costexpr の行消して global に unsigned int mod = 1;
	で cin>>mod してから使う
	任意 mod はかなり遅いので、できれば "atcoder/modint" を使う
*/

template<unsigned int mod_>
struct ModInt{	
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll _v):v(normS(_v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ModInt& operator++(int){ return *this=*this+1;}
	ModInt& operator--(int){ return *this=*this-1;}
	template<class T> friend ModInt operator+(T a, const ModInt& b){ return (ModInt(a) += b);}
	template<class T> friend ModInt operator-(T a, const ModInt& b){ return (ModInt(a) -= b);}
	template<class T> friend ModInt operator*(T a, const ModInt& b){ return (ModInt(a) *= b);}
	template<class T> friend ModInt operator/(T a, const ModInt& b){ return (ModInt(a) /= b);}
	ModInt pow(ll p) const {
		if(p<0) return inv().pow(-p);
		ModInt a = 1;
		ModInt x = *this;
		while(p){
			if(p&1) a *= x;
			x *= x;
			p >>= 1;
		}
		return a;
	}
	ModInt inv() const {		// should be prime
		return pow(mod-2);
	}
	// ll extgcd(ll a,ll b,ll &x,ll &y) const{
	// 	ll p[]={a,1,0},q[]={b,0,1};
	// 	while(*q){
	// 		ll t=*p/ *q;
	// 		rep(i,3) swap(p[i]-=t*q[i],q[i]);
	// 	}
	// 	if(p[0]<0) rep(i,3) p[i]=-p[i];
	// 	x=p[1],y=p[2];
	// 	return p[0];
	// }
	// ModInt inv() const {
	// 	ll x,y;
	// 	extgcd(v,mod,x,y);
	// 	return make(normS(x+mod));
	// }

	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	bool operator<(const ModInt& b) const { return v<b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
	// friend ostream& operator<<(ostream &o,const ModInt& x){
	// 	for(int b=1;b<=1000;b++){
	// 		ModInt ib = ModInt(b).inv();
	// 		for(int a=-1000;a<=1000;a++){
	// 			if(ModInt(a) * ib == x){
	// 				return o << a << "/" << b;
	// 			}
	// 		}
	// 	}
	// 	return o<<x.v;
	// }
};
using mint = ModInt<998244353>;
//using mint = ModInt<1000000007>;

V<mint> fact,ifact,invs;
// a,b >= 0 のみ
mint Choose(int a,int b){
	if(b<0 || a<b) return 0;
	return fact[a] * ifact[b] * ifact[a-b];
}

/*
// b >= 0 の範囲で、 Choose(a,b) = a(a-1)..(a-b+1) / b!
mint Choose(int a,int b){
	if(b<0 || a<b) return 0;
	return fact[a] * ifact[b] * ifact[a-b];
}
*/

void InitFact(int N){	//[0,N]
	N++;
	fact.resize(N);
	ifact.resize(N);
	invs.resize(N);
	fact[0] = 1;
	rep1(i,N-1) fact[i] = fact[i-1] * i;
	ifact[N-1] = fact[N-1].inv();
	for(int i=N-2;i>=0;i--) ifact[i] = ifact[i+1] * (i+1);
	rep1(i,N-1) invs[i] = fact[i-1] * ifact[i];
}
#line 6 "H.cpp"

template<class D>
struct Segtree{
	int N;
	vector<D> val;

	Segtree(){}
	Segtree(int n){
		N = 1; while(N < n) N *= 2;
		val.assign(N*2, D());
	}
	template<class Dlike>
	Segtree(const vector<Dlike>& vs){
		int n = vs.size();
		N = 1; while(N < n) N *= 2;
		val.assign(N*2, D());
		rep(i,n) val[i+N] = vs[i];
		for(int i=N-1;i>0;i--) val[i] = D::op(val[i*2],val[i*2+1]);
	}
	void set(int k, D v){
		k += N;
		val[k] = v;
		k /= 2;
		while(k){
			val[k] = D::op(val[k*2],val[k*2+1]);
			k /= 2;
		}
	}
	void add(int k, D v){
		k += N;
		val[k] = D::op(val[k],v);
		k /= 2;
		while(k){
			val[k] = D::op(val[k*2],val[k*2+1]);
			k /= 2;
		}
	}
	D query(int a, int b){		//non-commutative & unrecursive
		D L = D() , R = D();
		a += N, b += N;
		while(a<b){
			if(a&1) L = D::op(L,val[a++]);
			if(b&1) R = D::op(val[--b],R);
			a /= 2, b /= 2;
		}
		return D::op(L,R);
	}
};

struct EG { ll g, x, y; };
EG extGcdSub(ll a, ll b) {
	if(b == 0){
		if (a >= 0) return EG{a, 1, 0};
		else return EG{-a, -1, 0};
	}else{
		auto e = extGcdSub(b, a % b);
		return EG{e.g, e.y, e.x - a / b * e.y};
	}
}
EG extGcd(ll a,ll b){
	auto e = extGcdSub(a,b);
	if(e.x < 0){
		if(b > 0){
			e.x += b/e.g;
			e.y -= a/e.g;
		}else{
			e.x -= b/e.g;
			e.y += a/e.g;
		}
	}
	return e;
}
/*
	xz + md? = g
*/
ll inv_mod(ll x, ll md) {
	auto z = extGcd(x, md).x;
	return (z % md + md) % md;
}

// struct Monoid{
// 	string s;
// 	Monoid():s(""){}
// 	Monoid(string s_):s(s_){}

// 	static Monoid op(const Monoid &a, const Monoid &b){
// 		return Monoid{a.s+b.s};
// 	}
// 	Monoid pow(ll p) const {
// 		Monoid a = Monoid();
// 		Monoid x = *this;
// 		while(p){
// 			if(p&1) a = op(a, x);
// 			x = op(x, x);
// 			p >>= 1;
// 		}
// 		return a;
// 	}
// 	friend ostream& operator<<(ostream &o,const Monoid& x){ return o<<x.s;}
// };

// array<array<T,11>,11>
template<class T>
struct Matrix: public array<array<T,11>,11>{

	Matrix(int h,int w){
		rep(i,h) rep(j,w) (*this)[i][j] = 0;
	}
	Matrix(const array<array<T,11>,11>& m){(*this) = m;}

	static Matrix E(int n){
		Matrix a(n,n);
		rep(i,n) a[i][i] = 1;
		return a;
	}
	int h() const { return (*this).size(); }
	int w() const { return (*this)[0].size(); }

	Matrix operator*(const Matrix& r) const {
		assert(w() == r.h());
		int A = h(), B = w(), C = r.w();
		Matrix z(A,C);
		rep(i,A) rep(k,B) rep(j,C) z[i][j] += (*this)[i][k] * r[k][j];
		return z;
	}
	Matrix& operator+=(const Matrix& r){return (*this)=(*this)+r;}
	Matrix& operator-=(const Matrix& r){return (*this)=(*this)-r;}
	Matrix& operator*=(const Matrix& r){return (*this)=(*this)*r;}

	Matrix pow(ll p) const {
		assert(h() == w());
		Matrix res = E(h());
		Matrix x = *this;
		while(p){
			if(p&1) res *= x;
			x *= x;
			p >>= 1;
		}
		return res;
	}

	friend ostream& operator<<(ostream &o,const Matrix& A){
		rep(i,A.h()){
			rep(j,A.w()) o << A[i][j]<<" ";
			o << endl;
		}
		return o;
	}
};
using Mat = Matrix<mint>;

int M;

struct Monoid{
	Mat m;
	Monoid():m(Mat::E(M+1)){}
	Monoid(Mat m_):m(m_){}

	static Monoid op(const Monoid &a, const Monoid &b){
		return Monoid{a.m*b.m};
	}
	Monoid pow(ll p) const {
		return Monoid{m.pow(p)};
	}
	friend ostream& operator<<(ostream &o,const Monoid& x){ return o<<x.m;}
};


template<class T>
T f(V<ll> xs, V<T> vs, ll K){
	show("-------------");
	show(xs); show(vs); show(K);

	int N = si(vs);
	assert(si(xs) == N + 1);
	assert(xs[0] == 0);

	if(N == 1) return vs[0].pow(xs[1]);

	ll L = xs[N];

	if(K > L/2){
		V<ll> nxs = {0};
		rep1(i,si(xs)-1){
			nxs.pb(L - xs[i] + 1);
		}
		nxs.pb(L);
		sort(all(nxs));
		V<T> nvs; nvs.pb(vs[0]);
		per(i,si(vs)) nvs.pb(vs[i]);
		return f(nxs, nvs, L-K);
	}

	V<ll> cands;
	for(ll x: xs) cands.pb(x%K);
	mkuni(cands);
	V<ll> nxs;
	V<T> nvs;
	vector<ll> buf(N, -1);
	Segtree<T> seg(N);
	for(ll r: cands){
		nxs.pb(r);
		rep(i,N){
			// [xs[i], xs[i+1]) にある qK + r の個数
			ll num = divFloor(xs[i+1]-r-1, K) - divFloor(xs[i]-r-1, K);
			if(num != buf[i]){
				buf[i] = num;
				seg.set(i, vs[i].pow(num));
			}
		}
		auto nv = seg.query(0, N);
		nvs.pb(nv);
	}
	nxs.pb(K);
	ll nK = L/K*K+K - L;
	return f(nxs, nvs, nK);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	// {
	// 	string s = string(10,'a') + string(6,'b') + string(10,'a') + string(1,'b');
	// 	string t;
	// 	rep(i,27) t += s[i*17%27];
	// 	int res = 0;
	// 	rep(i,27) for(int j = i+1;j<27;j++) if(t[i] == 'a' && t[j] == 'b') res++;
	// 	cout << res << endl;
	// 	return 0;
	// }

	int N; ll K,L; cin >> N >> M >> K >> L;
	K = inv_mod(K, L);

	V<int> t(M); rep(i,M) cin >> t[i];

	V<ll> xs;
	V<Monoid> vs;
	int sm = 0;
	xs.pb(sm);
	rep(i,N){
		int len, val; cin >> len >> val;
		sm += len;
		xs.pb(sm);
		Mat m(M+1,M+1); rep(j,M+1) m[j][j] = 1;
		rep(j,M) if(t[j] == val) m[j][j+1] = 1;
		vs.pb(Monoid(m));
	}
	Monoid res = f(xs, vs, K);
	cout << res.m[0][M] << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3836kb

input:

4 2 17 27
3 1
10 3
6 1
10 3
1 1

output:

76

result:

ok single line: '76'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3788kb

input:

5 3 1789 15150
555 718 726
72 555
1029 718
5807 726
1002 718
7240 555

output:

390415327

result:

ok single line: '390415327'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3536kb

input:

1 1 1 1000000000
1000
1000000000 1000

output:

1755647

result:

ok single line: '1755647'

Test #4:

score: 0
Accepted
time: 161ms
memory: 8984kb

input:

1999 10 999999999 1000000000
944 901 986 915 979 988 947 999 969 946
198832 985
235662 982
367137 938
219700 949
166086 906
488084 905
891250 984
243743 971
253382 987
181971 935
2382 948
462701 981
4681 925
113363 916
119397 921
337742 982
427128 921
285959 986
197975 978
140753 907
167150 974
4576...

output:

211590728

result:

ok single line: '211590728'

Test #5:

score: 0
Accepted
time: 1303ms
memory: 39212kb

input:

2000 10 207560381 499173270
382 246 825 688 810 66 333 717 903 444
242322 825
303194 246
266460 66
133293 444
499376 688
175256 333
260041 717
202138 444
84931 688
353443 825
137750 382
333307 66
450617 810
27484 246
349436 717
45179 444
146073 810
107846 717
416816 246
255378 825
433826 688
273215 ...

output:

686508296

result:

ok single line: '686508296'

Test #6:

score: 0
Accepted
time: 1381ms
memory: 39760kb

input:

2000 10 261469558 497769147
990 38 906 66 751 758 913 137 187 724
253600 187
50741 758
58978 724
358384 751
258090 137
423638 990
121415 137
162742 758
93886 724
279287 913
392322 38
495784 758
195957 906
47122 913
87008 751
17599 66
22711 38
58373 724
116467 990
495160 724
471978 758
24585 724
3064...

output:

989869378

result:

ok single line: '989869378'

Test #7:

score: 0
Accepted
time: 1648ms
memory: 51456kb

input:

2000 10 321529781 512205698
105 216 706 872 564 639 983 85 153 396
319747 706
46163 639
134011 983
293977 153
176149 983
214154 216
45308 706
270691 396
491463 216
207041 639
118670 983
207549 639
430999 706
294263 872
137031 983
270440 85
480934 153
56566 85
462772 872
53771 639
455400 105
496369 8...

output:

43580469

result:

ok single line: '43580469'

Test #8:

score: 0
Accepted
time: 1481ms
memory: 45640kb

input:

2000 10 445061541 492744658
724 778 518 949 399 846 571 290 26 719
95511 399
430323 571
269833 399
378561 778
247054 719
449770 571
452091 719
31296 724
107940 26
330171 724
459597 719
454361 949
71045 724
332444 290
165408 518
123580 719
352964 518
187501 571
206988 778
95308 26
351267 846
22564 77...

output:

616245282

result:

ok single line: '616245282'

Test #9:

score: 0
Accepted
time: 1560ms
memory: 46156kb

input:

2000 10 82854895 499384144
533 699 969 632 566 827 967 951 475 208
67174 699
373746 475
43811 827
314087 566
487694 632
150698 475
411781 967
289698 475
202029 967
137762 208
21408 967
185906 632
322311 208
111984 967
219226 533
137525 632
194071 969
415968 951
495074 566
384006 699
75700 533
319248...

output:

325482724

result:

ok single line: '325482724'

Test #10:

score: 0
Accepted
time: 1572ms
memory: 48052kb

input:

2000 10 68884267 496908428
911 83 655 38 43 219 401 868 444 362
373884 868
301252 43
71730 83
152590 444
495048 43
220127 868
42667 83
152766 401
295425 911
156010 868
194248 655
258290 362
495166 868
359444 38
228210 83
236963 911
373081 401
219519 38
462869 444
132749 83
126049 362
233585 444
4346...

output:

618545771

result:

ok single line: '618545771'

Test #11:

score: 0
Accepted
time: 1396ms
memory: 42480kb

input:

2000 10 296584211 502951247
749 916 549 440 155 770 822 335 591 623
391756 916
403204 335
301242 591
162665 440
377091 623
24972 155
312374 916
171135 623
224221 822
408433 623
157158 822
55740 623
425392 591
37832 916
298703 440
119707 591
101034 749
125274 770
6109 440
78022 916
118181 591
325648 ...

output:

601538508

result:

ok single line: '601538508'

Test #12:

score: 0
Accepted
time: 1718ms
memory: 53716kb

input:

2000 10 166200743 502716830
533 628 821 905 330 77 520 46 735 156
96144 46
47146 735
295659 905
171260 156
458468 735
6371 77
76608 330
218288 533
67674 821
140084 520
397185 628
439197 520
466128 77
489650 628
280149 77
235961 821
314891 628
285703 821
456792 533
401436 520
415332 905
335720 735
46...

output:

714220375

result:

ok single line: '714220375'

Test #13:

score: 0
Accepted
time: 1564ms
memory: 46228kb

input:

2000 10 494777999 498279924
923 543 789 607 512 597 885 462 759 380
472583 543
70 885
281396 597
31713 885
294039 512
495370 607
338181 380
344775 597
457867 607
362253 543
457963 607
431365 597
489637 923
104753 380
49184 923
452889 543
46665 923
326714 462
332474 923
92685 543
293550 380
223152 51...

output:

867398339

result:

ok single line: '867398339'

Test #14:

score: 0
Accepted
time: 1016ms
memory: 31184kb

input:

2000 10 145282979 489563793
128 159 828 90 300 425 977 189 186 533
414271 425
461949 90
173115 300
188953 186
147473 90
361413 300
473121 828
418946 128
449971 828
114925 159
102198 828
420347 300
56815 533
334139 90
384997 977
84207 90
202111 977
318891 90
123614 189
42891 300
48668 128
354240 300
...

output:

642735856

result:

ok single line: '642735856'

Test #15:

score: 0
Accepted
time: 1230ms
memory: 34212kb

input:

2000 10 73726788 493104227
599 622 889 670 210 778 374 327 308 768
358274 622
227891 778
375954 768
466366 778
411108 374
347592 599
265078 622
174121 327
355147 374
167867 599
46552 374
10552 778
114210 622
331772 768
302246 599
24244 778
91362 622
130440 889
395599 599
394176 308
81768 374
83741 3...

output:

550082279

result:

ok single line: '550082279'

Test #16:

score: 0
Accepted
time: 1876ms
memory: 58876kb

input:

2000 10 152855876 496805251
413 309 740 266 721 715 21 857 206 62
209597 62
330590 857
51271 413
168907 721
473281 21
413081 266
196578 721
219198 21
396781 715
53173 206
200590 266
302416 740
15732 721
414567 740
163152 715
138244 413
158638 62
329207 857
16320 740
246121 21
187905 721
262236 62
90...

output:

937550461

result:

ok single line: '937550461'

Test #17:

score: 0
Accepted
time: 1671ms
memory: 45848kb

input:

2000 10 370831065 494204662
382 47 32 870 479 272 956 381 367 794
429604 382
154570 479
61831 382
492147 956
327498 272
427937 381
286339 479
468675 382
197165 479
83760 794
37841 32
283143 870
275120 272
76888 382
438285 381
281443 47
238356 32
353474 794
112098 870
380747 272
161610 479
393113 956...

output:

609619628

result:

ok single line: '609619628'

Test #18:

score: 0
Accepted
time: 999ms
memory: 32728kb

input:

2000 10 200672622 505250813
878 452 69 924 341 370 146 95 189 859
34803 95
36193 859
154299 146
211738 189
69700 859
436922 452
499998 341
338104 69
478735 452
489784 146
180937 189
488456 452
196359 95
126209 924
188052 452
321395 924
189009 859
87452 189
255497 878
43661 341
112027 146
33154 69
44...

output:

56885687

result:

ok single line: '56885687'

Test #19:

score: 0
Accepted
time: 1922ms
memory: 54604kb

input:

2000 10 72438867 486841996
394 384 548 742 861 766 155 863 283 525
347582 283
399712 861
451073 394
30203 155
477852 742
146217 861
256320 548
448082 384
104663 155
210939 742
351868 525
253138 548
271447 283
238297 525
464783 394
148139 861
354538 384
260219 155
243223 548
498139 525
291494 863
341...

output:

788937438

result:

ok single line: '788937438'

Test #20:

score: 0
Accepted
time: 1760ms
memory: 53024kb

input:

2000 10 12876147 507434473
669 614 751 903 152 518 761 303 63 275
385798 669
260649 275
314982 761
84162 614
324086 669
275099 903
22416 63
216034 669
395106 751
149779 63
474229 303
434728 518
313498 903
9711 152
365631 275
177888 669
496592 152
245728 614
394926 152
10600 63
471425 751
289977 761
...

output:

63922908

result:

ok single line: '63922908'

Test #21:

score: 0
Accepted
time: 1961ms
memory: 53384kb

input:

2000 10 240752091 504760936
128 816 447 424 211 177 102 675 680 898
270030 128
30581 177
239215 211
69720 102
285784 447
172262 675
362194 898
308818 177
257890 211
175781 102
352094 816
11391 211
19385 447
375117 177
201000 128
262442 675
237421 102
100994 211
102985 128
85249 177
496945 675
444348...

output:

227952735

result:

ok single line: '227952735'

Test #22:

score: -100
Time Limit Exceeded

input:

2000 10 237980579 505987937
892 269 84 481 972 522 978 105 450 479
252830 105
189317 450
56029 105
262872 522
279860 978
388378 269
84117 522
131970 105
422569 269
331506 479
96166 450
324575 84
144671 450
140397 978
453063 105
220994 84
150678 450
476768 105
330178 84
296397 105
421757 481
5724 269...

output:

468458072

result: