QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#624920#9426. Relearn through ReviewDung1604AC ✓1212ms106404kbC++173.9kb2024-10-09 16:54:542024-10-09 16:54:54

Judging History

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

  • [2024-10-09 16:54:54]
  • 评测
  • 测评结果:AC
  • 用时:1212ms
  • 内存:106404kb
  • [2024-10-09 16:54:54]
  • 提交

answer

#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <tuple>
#include <iomanip>
#include <map>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <unordered_map>
#define ll long long
#define inf 10000000000007
#define mod 1000000007

using namespace std;

const int BLOCK = 450;


ll fastpow(ll n, ll x) {

	if (x == 0) {
		return 1;
	}
	else {
		ll ret = fastpow(n, x / 2);
		ret = ((ret % mod) * (ret % mod)) % mod;
		if (x % 2 == 0) {
			return ret;
		}
		else {
			return ((ret) * (n)) % mod;
		}
	}
}


ll gcd(ll a, ll b) {
	if (a == 0) {
		return b;
	}
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	ll val = (a % mod * b % mod) % mod;
	val = (val * fastpow(gcd(a, b), mod - 2)) % mod;
	return val;
}
int Logk(ll n, ll k) {
	if (k == 1) {
		return 1;
	}
	if (n == 0) {
		return 0;
	}
	int count = -1;
	while (n > 0) {
		count++;
		n /= k;
	}
	return count;
}
struct Dsu {
	vector<int> par;

	void init(int n) {
		par.resize(n + 5, 0);
		for (int i = 1; i <= n; i++) par[i] = i;
	}

	int find(int u) {
		if (par[u] == u) return u;
		return par[u] = find(par[u]);
	}

	bool join(int u, int v) {
		u = find(u); v = find(v);
		if (u == v) return false;
		par[v] = u;
		return true;
	}
} dsu;

ll dp[300005][35];
void solve() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n + 1);
	vector<ll> b(n + 1);
	vector<ll> prefix(n + 1);
	set<ll> sufix;
	map<ll, set<int>> second;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		b[i] = abs(a[i] - a[i - 1]);
	}
	prefix[1] = a[1];
	for (int i = 2; i <= n; i++) {
		prefix[i] = gcd(prefix[i - 1], a[i]);
	}
	for (int i = 1; i <= n; i++) {
		dp[i][0] = b[i];
	}
	if (k == 0) {
		cout << prefix[n] << endl;
		
		
		return;
	}
	else {
		bool equal = true;
		for (int i = 2; i <= n; i++) {
			if (a[i] != a[1]) {
				equal = false;
				break;
			}
		}
		if (equal) {
			cout << a[1] + k << endl;
			return;
		}
	}
	for (int j = 1; j < 30; j++) {
		for (int i = 1; i <= n; i++) {
			if (i + (1 << j) - 1 <= n) {
				dp[i][j] = gcd(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
			}
		}
	}
	ll kkk = a[1] + k;
	for (int i = 2; i <= n; i++) {
		kkk = gcd(kkk, a[i] + k);
	}

	ll ans = kkk;

	ll cur = a[n];
	sufix.insert(cur);
	second[cur].insert(n);
	for (int i = n - 1; i >= 1; i--) {
		if (i >= 1) {
			ll r = i;
			ll p = gcd(cur, a[1] + k);
			ll l = 1;
			if (i > 1) {
				ll log = Logk(r - l, 2);
				ll h = gcd(dp[l + 1][log], dp[r - (1LL << log) + 1][log]);
				p = gcd(p, h);

			}
			ans = max(ans, p);
		}

		cur = gcd(cur, a[i]);
		second[cur].insert(i);
		sufix.insert(cur);
		
	}
	
	for (int i = 1; i <= n; i++) {
		ll x = prefix[i];
		
		if (x == 1) {
			break;
		}
		
		for (auto it = sufix.begin(); it != sufix.end(); it++) {
			ll y = *it;
			
			ll p = gcd(x, y);
			if (p == 1)continue;
			int posL = i + 1;
			p = gcd(p, a[posL] + k);
			auto find = second[y].lower_bound(i + 2);
			if (find == second[y].end())continue;

			int posR = *find-1;
			
			if (posR == posL) {
				ans = max(ans, p);
			}
			else {
				ll log = Logk(posR - posL, 2);
				ll mid = gcd(dp[posL + 1][log], dp[posR - (1 << log) + 1][log]);
				p = gcd(mid, p);
				
				ans = max(ans, gcd(mid, p));
				
				
			}
		}
		if (i + 1 <= n) {
			ll l = i + 1;
			ll p = gcd(x, a[l] + k);
			ll r = n;
			if (l < r) {
				ll log = Logk(r - l, 2);
				ll h = gcd(dp[l + 1][log], dp[r - (1LL << log) + 1][log]);
				p = gcd(p, h);

			}
			ans = max(ans, p);
		}
		else {
			ans = max(ans, x);
		}
		
		

	}
	cout << ans << endl;

}



int main() {




	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int t;
	cin >> t;
	while (t--) {
		solve();
	}






























}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

input:

2
6 2
5 3 13 8 10 555
3 0
3 6 9

output:

5
3

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 227ms
memory: 3580kb

input:

100000
1 608611451460421713
33155506392034032
1 743116173559300609
6138108577573005
7 364454564010802125
657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115
4 316648374341335221
365788422120542814 182894211060271407 731...

output:

641766957852455745
749254282136873614
657035115675878115
182894211060271407
880411769063535667
560553564512176618
183698346865682381
962990836390050009
616597869896951268
878097339332572161
188820994675344528
997057718507559252
949074379610491450
37337367838628559
632093288650732211
3771217139073309...

result:

ok 100000 lines

Test #3:

score: 0
Accepted
time: 149ms
memory: 6572kb

input:

1000
71 451750502977198411
701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 7015137...

output:

701513700102652904
628264251002959880
866034990978685601
718723820869997225
525309136656747615
453291245761058554
420366973911241294
500173849665919725
16701821680586640
794711320668492112
799961738480944637
963500289005941882
190368877908873112
973069943210898565
629019279628092667
1921616220783983...

result:

ok 1000 lines

Test #4:

score: 0
Accepted
time: 149ms
memory: 9204kb

input:

100
5516 16561406822518327
121909691713696369 226403713182578971 940446193219943418 505054437099599243 505054437099599243 383144745385902874 470223096609971709 714042480037364447 417976085875530408 783705161016619515 888199182485502117 208988042937765204 330897734651461573 818536501506247049 7488738...

output:

17415670244813767
678667366385241526
375190657607916623
343566816881610443
293858497297593293
545063989451911922
101584687520632945
923261939978554511
245471164671296626
996567332718295422
871411820593738277
999473841903341933
575286590792404442
298698210937205101
265822932252018295
4113318308187297...

result:

ok 100 lines

Test #5:

score: 0
Accepted
time: 229ms
memory: 38560kb

input:

10
2651 1901143105096273
954803577560210292 636535718373473528 159133929593368382 159133929593368382 954803577560210292 477401788780105146 636535718373473528 636535718373473528 954803577560210292 636535718373473528 318267859186736764 636535718373473528 636535718373473528 318267859186736764 795669647...

output:

159133929593368382
793024501989621764
454059328664071477
113729984568648330
507863600649451091
779491329333959710
821665805532903623
384579792180981183
356029896436006899
340683633028457433

result:

ok 10 lines

Test #6:

score: 0
Accepted
time: 187ms
memory: 62644kb

input:

3
31056 13873801082583029
316385357210519324 316385357210519324 316385357210519324 949156071631557972 632770714421038648 949156071631557972 316385357210519324 316385357210519324 316385357210519324 316385357210519324 632770714421038648 949156071631557972 316385357210519324 316385357210519324 31638535...

output:

316385357210519324
399693130963531970
229449205713014908

result:

ok 3 lines

Test #7:

score: 0
Accepted
time: 297ms
memory: 106308kb

input:

1
300000 309955051600565498
497784205512766609 995568411025533218 995568411025533218 995568411025533218 995568411025533218 497784205512766609 497784205512766609 995568411025533218 995568411025533218 995568411025533218 497784205512766609 995568411025533218 497784205512766609 497784205512766609 497784...

output:

497784205512766609

result:

ok single line: '497784205512766609'

Test #8:

score: 0
Accepted
time: 119ms
memory: 106244kb

input:

1
300000 1
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7...

output:

7

result:

ok single line: '7'

Test #9:

score: 0
Accepted
time: 175ms
memory: 106180kb

input:

1
300000 60
66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 ...

output:

66

result:

ok single line: '66'

Test #10:

score: 0
Accepted
time: 1212ms
memory: 106260kb

input:

1
300000 522555291
775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355...

output:

721916083

result:

ok single line: '721916083'

Test #11:

score: 0
Accepted
time: 7ms
memory: 92352kb

input:

1
300000 0
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6...

output:

1

result:

ok single line: '1'

Test #12:

score: 0
Accepted
time: 139ms
memory: 106404kb

input:

1
300000 3
64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 6...

output:

4

result:

ok single line: '4'

Test #13:

score: 0
Accepted
time: 339ms
memory: 106248kb

input:

1
300000 634838941
826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341...

output:

720994598

result:

ok single line: '720994598'

Test #14:

score: 0
Accepted
time: 823ms
memory: 106284kb

input:

1
300000 236226483
980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362...

output:

721363081

result:

ok single line: '721363081'

Test #15:

score: 0
Accepted
time: 68ms
memory: 3648kb

input:

75000
4 0
1 1 1 1
4 1
1 1 1 1
4 2
1 1 1 1
4 3
1 1 1 1
4 4
1 1 1 1
4 0
2 1 1 1
4 1
2 1 1 1
4 2
2 1 1 1
4 3
2 1 1 1
4 4
2 1 1 1
4 0
3 1 1 1
4 1
3 1 1 1
4 2
3 1 1 1
4 3
3 1 1 1
4 4
3 1 1 1
4 0
4 1 1 1
4 1
4 1 1 1
4 2
4 1 1 1
4 3
4 1 1 1
4 4
4 1 1 1
4 0
5 1 1 1
4 1
5 1 1 1
4 2
5 1 1 1
4 3
5 1 1 1
4 4
5 ...

output:

1
2
3
4
5
1
2
1
2
1
1
2
3
2
1
1
2
3
4
1
1
2
1
4
5
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
1
2
1
2
1
1
2
3
2
1
1
2
1
2
1
1
2
1
2
1
1
1
3
1
1
1
2
1
2
1
1
1
3
1
1
1
2
3
4
1
1
1
1
1
1
1
2
1
4
1
1
2
1
2
1
1
2
1
2
1
1
2
1
4
1
1
2
1
4
5
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 75000 lines

Test #16:

score: 0
Accepted
time: 76ms
memory: 3660kb

input:

75000
4 0
2 2 2 2
4 1
2 2 2 2
4 2
2 2 2 2
4 3
2 2 2 2
4 4
2 2 2 2
4 0
3 2 2 2
4 1
3 2 2 2
4 2
3 2 2 2
4 3
3 2 2 2
4 4
3 2 2 2
4 0
4 2 2 2
4 1
4 2 2 2
4 2
4 2 2 2
4 3
4 2 2 2
4 4
4 2 2 2
4 0
5 2 2 2
4 1
5 2 2 2
4 2
5 2 2 2
4 3
5 2 2 2
4 4
5 2 2 2
4 0
6 2 2 2
4 1
6 2 2 2
4 2
6 2 2 2
4 3
6 2 2 2
4 4
6 ...

output:

2
3
4
5
6
1
3
1
2
3
2
2
4
2
2
1
3
1
5
3
2
3
4
2
6
1
2
1
2
1
1
3
1
2
3
1
2
1
2
1
1
2
1
2
1
1
3
1
2
3
2
2
2
2
2
1
2
1
2
1
2
2
4
2
2
1
2
1
2
1
2
2
2
2
2
1
3
1
2
3
1
3
1
2
3
1
2
1
2
1
1
3
1
5
3
1
3
1
2
3
2
2
4
2
2
1
3
1
2
3
2
2
4
2
2
1
2
1
2
1
2
3
4
2
6
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
...

result:

ok 75000 lines

Test #17:

score: 0
Accepted
time: 75ms
memory: 3856kb

input:

75000
4 0
3 3 3 3
4 1
3 3 3 3
4 2
3 3 3 3
4 3
3 3 3 3
4 4
3 3 3 3
4 0
4 3 3 3
4 1
4 3 3 3
4 2
4 3 3 3
4 3
4 3 3 3
4 4
4 3 3 3
4 0
5 3 3 3
4 1
5 3 3 3
4 2
5 3 3 3
4 3
5 3 3 3
4 4
5 3 3 3
4 0
6 3 3 3
4 1
6 3 3 3
4 2
6 3 3 3
4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
2
1
4
1
2
...

result:

ok 75000 lines

Test #19:

score: 0
Accepted
time: 52ms
memory: 3664kb

input:

75000
4 0
2 2 2 2
4 1
2 2 2 2
4 2
2 2 2 2
4 3
2 2 2 2
4 4
2 2 2 2
4 5
2 2 2 2
4 0
3 2 2 2
4 1
3 2 2 2
4 2
3 2 2 2
4 3
3 2 2 2
4 4
3 2 2 2
4 5
3 2 2 2
4 0
4 2 2 2
4 1
4 2 2 2
4 2
4 2 2 2
4 3
4 2 2 2
4 4
4 2 2 2
4 5
4 2 2 2
4 0
5 2 2 2
4 1
5 2 2 2
4 2
5 2 2 2
4 3
5 2 2 2
4 4
5 2 2 2
4 5
5 2 2 2
4 0
6 ...

output:

2
3
4
5
6
7
1
3
1
2
3
2
2
2
4
2
2
2
1
3
1
5
3
2
2
3
4
2
6
2
1
2
1
5
1
7
1
2
1
2
1
2
1
3
1
2
3
2
1
2
1
2
1
2
1
2
1
2
1
2
1
3
1
2
3
2
1
2
1
2
1
2
2
2
2
2
2
2
1
2
1
2
1
2
2
2
4
2
2
2
1
2
1
2
1
2
2
2
2
2
2
2
1
2
1
2
1
2
1
3
1
2
3
2
1
3
1
2
3
2
1
2
1
2
1
2
1
3
1
5
3
2
1
3
1
2
3
2
1
2
1
2
1
2
2
2
4
2
2
2
...

result:

ok 75000 lines

Test #20:

score: 0
Accepted
time: 91ms
memory: 3572kb

input:

75000
4 0
3 3 3 3
4 1
3 3 3 3
4 2
3 3 3 3
4 3
3 3 3 3
4 4
3 3 3 3
4 5
3 3 3 3
4 0
4 3 3 3
4 1
4 3 3 3
4 2
4 3 3 3
4 3
4 3 3 3
4 4
4 3 3 3
4 5
4 3 3 3
4 0
5 3 3 3
4 1
5 3 3 3
4 2
5 3 3 3
4 3
5 3 3 3
4 4
5 3 3 3
4 5
5 3 3 3
4 0
6 3 3 3
4 1
6 3 3 3
4 2
6 3 3 3
4 3
6 3 3 3
4 4
6 3 3 3
4 5
6 3 3 3
4 0
7 ...

output:

3
4
5
6
7
8
1
4
3
2
1
4
1
3
5
2
3
2
3
3
3
6
3
3
1
4
3
2
7
4
1
4
5
2
3
8
1
1
3
1
1
3
1
4
3
2
1
4
1
1
1
1
1
1
1
2
3
2
1
3
1
1
3
1
1
3
1
4
1
2
1
4
1
3
1
2
3
2
1
2
1
2
1
2
1
3
5
2
3
2
1
3
1
2
3
2
1
2
1
2
1
2
1
3
1
2
3
2
3
3
3
3
3
3
1
2
3
2
1
3
1
3
1
1
3
1
3
3
3
6
3
3
1
1
3
1
1
3
1
3
1
2
3
2
1
4
3
2
1
4
...

result:

ok 75000 lines

Test #21:

score: 0
Accepted
time: 63ms
memory: 3780kb

input:

60000
5 0
1 1 1 1 1
5 1
1 1 1 1 1
5 2
1 1 1 1 1
5 3
1 1 1 1 1
5 4
1 1 1 1 1
5 0
2 1 1 1 1
5 1
2 1 1 1 1
5 2
2 1 1 1 1
5 3
2 1 1 1 1
5 4
2 1 1 1 1
5 0
3 1 1 1 1
5 1
3 1 1 1 1
5 2
3 1 1 1 1
5 3
3 1 1 1 1
5 4
3 1 1 1 1
5 0
4 1 1 1 1
5 1
4 1 1 1 1
5 2
4 1 1 1 1
5 3
4 1 1 1 1
5 4
4 1 1 1 1
5 0
5 1 1 1 1
...

output:

1
2
3
4
5
1
2
1
2
1
1
2
3
2
1
1
2
3
4
1
1
2
1
4
5
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
1
2
1
2
1
1
2
3
2
1
1
2
1
2
1
1
2
1
2
1
1
1
3
1
1
1
2
1
2
1
1
1
3
1
1
1
2
3
4
1
1
1
1
1
1
1
2
1
4
1
1
2
1
2
1
1
2
1
2
1
1
2
1
4
1
1
2
1
4
5
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 60000 lines

Test #22:

score: 0
Accepted
time: 40ms
memory: 3660kb

input:

60000
5 0
2 2 2 2 2
5 1
2 2 2 2 2
5 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1
2
3
1
2
1
2
1
1
3
5
2
3
1
3
1
2
3
1
2
1
2
1
3
3
3
3
3
1
2
3
2
1
1
3
1
1
3
3
3
3
6
3
1
1
3
1
1
1
4
3
2
1
1
4
3
2
1
1
2
1
2
1
1
2
3
2
1
1
4
3
2
7
1
1
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
3
1
1
1
1
1
1
1
...

result:

ok 60000 lines

Test #24:

score: 0
Accepted
time: 55ms
memory: 3624kb

input:

60000
5 0
1 1 1 1 1
5 1
1 1 1 1 1
5 2
1 1 1 1 1
5 3
1 1 1 1 1
5 4
1 1 1 1 1
5 5
1 1 1 1 1
5 0
2 1 1 1 1
5 1
2 1 1 1 1
5 2
2 1 1 1 1
5 3
2 1 1 1 1
5 4
2 1 1 1 1
5 5
2 1 1 1 1
5 0
3 1 1 1 1
5 1
3 1 1 1 1
5 2
3 1 1 1 1
5 3
3 1 1 1 1
5 4
3 1 1 1 1
5 5
3 1 1 1 1
5 0
4 1 1 1 1
5 1
4 1 1 1 1
5 2
4 1 1 1 1
...

output:

1
2
3
4
5
6
1
2
1
2
1
2
1
2
3
2
1
3
1
2
3
4
1
3
1
2
1
4
5
2
1
2
3
2
5
6
1
1
1
1
1
1
1
2
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
3
2
1
3
1
2
1
2
1
2
1
2
1
2
1
2
1
2
3
2
1
3
1
1
3
1
1
3
1
2
1
2
1
2
1
1
3
1
1
3
1
2
3
4
1
3
1
1
1
1
1
1
1
2
3
2
1
3
1
2
1
4
1
2
...

result:

ok 60000 lines

Test #25:

score: 0
Accepted
time: 61ms
memory: 3600kb

input:

60000
5 0
2 2 2 2 2
5 1
2 2 2 2 2
5 2
2 2 2 2 2
5 3
2 2 2 2 2
5 4
2 2 2 2 2
5 5
2 2 2 2 2
5 0
3 2 2 2 2
5 1
3 2 2 2 2
5 2
3 2 2 2 2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
1
2
1
3
1
2
3
2
3
3
3
3
3
3
1
2
3
2
1
3
1
3
1
1
3
1
3
3
3
6
3
3
1
1
3
1
1
3
1
3
1
2
3
2
1
4
3
2
1
4
...

result:

ok 60000 lines

Test #27:

score: 0
Accepted
time: 63ms
memory: 3556kb

input:

50000
6 0
1 1 1 1 1 1
6 1
1 1 1 1 1 1
6 2
1 1 1 1 1 1
6 3
1 1 1 1 1 1
6 4
1 1 1 1 1 1
6 0
2 1 1 1 1 1
6 1
2 1 1 1 1 1
6 2
2 1 1 1 1 1
6 3
2 1 1 1 1 1
6 4
2 1 1 1 1 1
6 0
3 1 1 1 1 1
6 1
3 1 1 1 1 1
6 2
3 1 1 1 1 1
6 3
3 1 1 1 1 1
6 4
3 1 1 1 1 1
6 0
4 1 1 1 1 1
6 1
4 1 1 1 1 1
6 2
4 1 1 1 1 1
6 3
4 ...

output:

1
2
3
4
5
1
2
1
2
1
1
2
3
2
1
1
2
3
4
1
1
2
1
4
5
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
1
2
1
2
1
1
2
3
2
1
1
2
1
2
1
1
2
1
2
1
1
1
3
1
1
1
2
1
2
1
1
1
3
1
1
1
2
3
4
1
1
1
1
1
1
1
2
1
4
1
1
2
1
2
1
1
2
1
2
1
1
2
1
4
1
1
2
1
4
5
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 50000 lines

Test #28:

score: 0
Accepted
time: 67ms
memory: 3564kb

input:

50000
6 0
2 2 2 2 2 2
6 1
2 2 2 2 2 2
6 2
2 2 2 2 2 2
6 3
2 2 2 2 2 2
6 4
2 2 2 2 2 2
6 0
3 2 2 2 2 2
6 1
3 2 2 2 2 2
6 2
3 2 2 2 2 2
6 3
3 2 2 2 2 2
6 4
3 2 2 2 2 2
6 0
4 2 2 2 2 2
6 1
4 2 2 2 2 2
6 2
4 2 2 2 2 2
6 3
4 2 2 2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
1
1
1
1
...

result:

ok 50000 lines

Test #30:

score: 0
Accepted
time: 62ms
memory: 3556kb

input:

50000
6 0
1 1 1 1 1 1
6 1
1 1 1 1 1 1
6 2
1 1 1 1 1 1
6 3
1 1 1 1 1 1
6 4
1 1 1 1 1 1
6 5
1 1 1 1 1 1
6 0
2 1 1 1 1 1
6 1
2 1 1 1 1 1
6 2
2 1 1 1 1 1
6 3
2 1 1 1 1 1
6 4
2 1 1 1 1 1
6 5
2 1 1 1 1 1
6 0
3 1 1 1 1 1
6 1
3 1 1 1 1 1
6 2
3 1 1 1 1 1
6 3
3 1 1 1 1 1
6 4
3 1 1 1 1 1
6 5
3 1 1 1 1 1
6 0
4 ...

output:

1
2
3
4
5
6
1
2
1
2
1
2
1
2
3
2
1
3
1
2
3
4
1
3
1
2
1
4
5
2
1
2
3
2
5
6
1
1
1
1
1
1
1
2
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
3
2
1
3
1
2
1
2
1
2
1
2
1
2
1
2
1
2
3
2
1
3
1
1
3
1
1
3
1
2
1
2
1
2
1
1
3
1
1
3
1
2
3
4
1
3
1
1
1
1
1
1
1
2
3
2
1
3
1
2
1
4
1
2
...

result:

ok 50000 lines

Test #31:

score: 0
Accepted
time: 61ms
memory: 3636kb

input:

50000
6 0
2 2 2 2 2 2
6 1
2 2 2 2 2 2
6 2
2 2 2 2 2 2
6 3
2 2 2 2 2 2
6 4
2 2 2 2 2 2
6 5
2 2 2 2 2 2
6 0
3 2 2 2 2 2
6 1
3 2 2 2 2 2
6 2
3 2 2 2 2 2
6 3
3 2 2 2 2 2
6 4
3 2 2 2 2 2
6 5
3 2 2 2 2 2
6 0
4 2 2 2 2 2
6 1
4 2 2 2 2 2
6 2
4 2 2 2 2 2
6 3
4 2 2 2 2 2
6 4
4 2 2 2 2 2
6 5
4 2 2 2 2 2
6 0
5 ...

output:

2
3
4
5
6
7
1
3
1
2
3
2
2
2
4
2
2
2
1
3
1
5
3
2
2
3
4
2
6
2
1
2
1
5
1
7
1
2
1
2
1
2
1
3
1
2
3
2
1
2
1
2
1
2
1
2
1
2
1
2
1
3
1
2
3
2
1
2
1
2
1
2
2
2
2
2
2
2
1
2
1
2
1
2
2
2
4
2
2
2
1
2
1
2
1
2
2
2
2
2
2
2
1
2
1
2
1
2
1
3
1
2
3
2
1
3
1
2
3
2
1
2
1
2
1
2
1
3
1
5
3
2
1
3
1
2
3
2
1
2
1
2
1
2
2
2
4
2
2
2
...

result:

ok 50000 lines

Test #32:

score: 0
Accepted
time: 68ms
memory: 3820kb

input:

50000
6 0
3 3 3 3 3 3
6 1
3 3 3 3 3 3
6 2
3 3 3 3 3 3
6 3
3 3 3 3 3 3
6 4
3 3 3 3 3 3
6 5
3 3 3 3 3 3
6 0
4 3 3 3 3 3
6 1
4 3 3 3 3 3
6 2
4 3 3 3 3 3
6 3
4 3 3 3 3 3
6 4
4 3 3 3 3 3
6 5
4 3 3 3 3 3
6 0
5 3 3 3 3 3
6 1
5 3 3 3 3 3
6 2
5 3 3 3 3 3
6 3
5 3 3 3 3 3
6 4
5 3 3 3 3 3
6 5
5 3 3 3 3 3
6 0
6 ...

output:

3
4
5
6
7
8
1
4
3
2
1
4
1
3
5
2
3
2
3
3
3
6
3
3
1
4
3
2
7
4
1
4
5
2
3
8
1
1
3
1
1
3
1
4
3
2
1
4
1
1
1
1
1
1
1
2
3
2
1
3
1
1
3
1
1
3
1
4
1
2
1
4
1
3
1
2
3
2
1
2
1
2
1
2
1
3
5
2
3
2
1
3
1
2
3
2
1
2
1
2
1
2
1
3
1
2
3
2
3
3
3
3
3
3
1
2
3
2
1
3
1
3
1
1
3
1
3
3
3
6
3
3
1
1
3
1
1
3
1
3
1
2
3
2
1
4
3
2
1
4
...

result:

ok 50000 lines

Test #33:

score: 0
Accepted
time: 47ms
memory: 3628kb

input:

42857
7 0
1 1 1 1 1 1 1
7 1
1 1 1 1 1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
2
2
2
1
2
1
2
1
2
2
4
2
2
1
2
1
2
1
2
2
2
2
2
1
3
1
2
3
1
3
1
2
3
1
2
1
2
1
1
3
1
5
3
1
3
1
2
3
2
2
4
2
2
1
3
1
2
3
2
2
4
2
2
1
2
1
2
1
2
3
4
2
6
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
...

result:

ok 42857 lines

Test #35:

score: 0
Accepted
time: 53ms
memory: 3560kb

input:

42857
7 0
3 3 3 3 3 3 3
7 1
3 3 3 3 3 3 3
7 2
3 3 3 3 3 3 3
7 3
3 3 3 3 3 3 3
7 4
3 3 3 3 3 3 3
7 0
4 3 3 3 3 3 3
7 1
4 3 3 3 3 3 3
7 2
4 3 3 3 3 3 3
7 3
4 3 3 3 3 3 3
7 4
4 3 3 3 3 3 3
7 0
5 3 3 3 3 3 3
7 1
5 3 3 3 3 3 3
7 2
5 3 3 3 3 3 3
7 3
5 3 3 3 3 3 3
7 4
5 3 3 3 3 3 3
7 0
6 3 3 3 3 3 3
7 1
6 ...

output:

3
4
5
6
7
1
4
3
2
1
1
3
5
2
3
3
3
3
6
3
1
4
3
2
7
1
1
3
1
1
1
4
3
2
1
1
1
1
1
1
1
2
3
2
1
1
1
3
1
1
1
3
1
2
3
1
2
1
2
1
1
3
5
2
3
1
3
1
2
3
1
2
1
2
1
3
3
3
3
3
1
2
3
2
1
1
3
1
1
3
3
3
3
6
3
1
1
3
1
1
1
4
3
2
1
1
4
3
2
1
1
2
1
2
1
1
2
3
2
1
1
4
3
2
7
1
1
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
3
1
1
1
1
1
1
1
...

result:

ok 42857 lines

Test #36:

score: 0
Accepted
time: 52ms
memory: 3820kb

input:

42857
7 0
1 1 1 1 1 1 1
7 1
1 1 1 1 1 1 1
7 2
1 1 1 1 1 1 1
7 3
1 1 1 1 1 1 1
7 4
1 1 1 1 1 1 1
7 5
1 1 1 1 1 1 1
7 0
2 1 1 1 1 1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