QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#360093#6299. Binary StringningagoAC ✓434ms340892kbC++145.9kb2024-03-21 11:34:012024-03-21 11:34:01

Judging History

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

  • [2024-03-21 11:34:01]
  • 评测
  • 测评结果:AC
  • 用时:434ms
  • 内存:340892kb
  • [2024-03-21 11:34:01]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <cctype>
#include <set>
#include <random>

namespace uvu
{
#define LOCAL ____________DONT_DEFINE_ME____________
#define ll long long
#define inf 0x3f3f3f3f
// #define int long long
// #define inf 0x3f3f3f3f3f3f3f3fll
#define intll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
	return getchar();
#else
	if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
	return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}

void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher { ~Flusher(){ Flush(); } }iamflusher;

void putc(char c)
{
#ifdef LOCAL
	putchar(c);
#else
	*oS++ = c;
	if(oS == oT) Flush();
#endif
#define putchar ERR
}

template <typename T = int> T read()
{
	T x = 0, f = 1; char c = getc();
	for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
	for(;  isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x * f;
}

template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
	top = 0;
	if(x < 0) putc('-'), x = -x;
	if(!x) sta[top = 1] = 0;
	for(; x; x /= 10) sta[++top] = x % 10;
	for(; top; ) putc(sta[top--] ^ 48);
	if(c) putc(c);
}

int readstr(char *s, int base)
{
	int idx = base - 1; char c = getc();
	for(; !(isdigit(c) || isalpha(c) || c == '#' || c == '.'); c = getc());
	for(;   isdigit(c) || isalpha(c) || c == '#' || c == '.' ; c = getc()) s[++idx] = c;
	return idx - base + 1;
}

void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
	for(; *s; s++)
	{
		if(*s != '%') { putc(*s); continue; }
		s++; if(*s == 'd') print(x, 0);
		else if(*s == 'c') putc(x);
		printf(s + 1, rest ...);
		return;
	}
}

template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
#define mod 998244353
// #define mod 1000000007
int sm(int x) { return x >= mod ? x - mod : x; }
void plus_(int &x, int y) { x = sm(x + y); }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b) { int res = 1; for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a); return res; }

#define N 10000010
int n, m; char str[N];
int a[N], suf[N], pre[N], sum[N];
int L[N], R[N];
pii b[N], sta[N]; int top;
int c[N], fail[N];

void solve()
{
	// memset(h, idx = -1, sizeof(h));
	n = readstr(str, 1);
	for(int i = 1; i <= n; i++) a[i] = (str[i] == '1'), R[i] = c[i] = fail[i] = 0;
	if(std::count(a + 1, a + 1 + n, 0) >= std::count(a + 1, a + 1 + n, 1))
	{
		for(int i = 1; i <= n; i++) a[i] ^= 1;
		std::reverse(a + 1, a + 1 + n);
	}
	if(std::count(a + 1, a + 1 + n, 1) == n) { print(1, '\n'); return; }
	for(int i = 1; i <= n; i++) if(!a[i]) a[i]--;
	// for(int i = 1; i <= n; i++) print(std::max(a[i], 0), 0);
	// putc('\n');
	m = 0;
	a[0] = a[n], a[n + 1] = a[1];
	bool flag = 1;
	for(int i = 1; i <= n; i++) flag &= (a[i] != a[i - 1]);
	if(flag) 
	{
		print(2, '\n');
		return;
	}
	for(int i = 1; i <= n; i++) if((a[i] == 1 && a[i - 1] == 1) || (a[i] == -1 && a[i + 1] == -1)) 
		b[++m] = mkp(a[i], i);
	pre[0] = suf[m + 1] = sum[m + 1] = 0;
	for(int i = 1; i <= m; i++) pre[i] = pre[i - 1] + b[i].fi;
	for(int i = 1; i <= m; i++) ckmin(pre[i], pre[i - 1]);
	for(int i = m; i >= 1; i--) suf[i] = std::min(suf[i + 1] + b[i].fi, b[i].fi);
	for(int i = m; i >= 1; i--) sum[i] = sum[i + 1] + b[i].fi;
	int S = 0, SS = b[S].se;
	// for(int i = 1; i <= m; i++) print(std::max(b[i].fi, 0), 0);
	// putc('\n');
	for(int i = 1; i <= m; i++) if(suf[i] >= 0 && sum[i] + pre[i - 1] >= 0) S = i;
	SS = b[S].se;
	if(!S) { debug("???\n"); return; }
	// printf("SS = %d, S = %d\n", SS, S);
	std::rotate(a + 1, a + SS, a + 1 + n);
	std::rotate(b + 1, b + S, b + 1 + m);
	// for(int i = 1; i <= n; i++) print(std::max(a[i], 0), 0);
	// putc('\n');
	top = 0;
	for(int i = 1; i <= m; i++)
	{
		if(b[i].se >= SS) b[i].se = b[i].se - SS + 1;
		else b[i].se = b[i].se - SS + 1 + n;
		if(b[i].fi > 0) sta[++top] = b[i];
		else R[sta[top].se] = b[i].se, L[b[i].se] = sta[top--].se;
	}
	// for(int i = 1; i <= n; i++) print(std::max(a[i], 0), 0);
	// putc('\n');
	int tim = 0;
	for(int i = 1; i <= n; i++)
		if(R[i]) ckmax(tim, (R[i] - i + 1) / 2);
	// for(int i = 1; i <= n; i++) printf("R[%d] = %d\n", i, R[i]);
	// printf("tim = %d\n", tim);
	a[0] = a[n]; a[n + 1] = a[1]; R[n + 1] = R[1];
	for(int i = 1; i <= n; i++)
		if(a[i] > 0 && (a[i - 1] > 0 || (a[i + 1] > 0 && !R[i + 1])) && !R[i]) 
			c[(i - 1 + tim) % n + 1] = a[i];//, printf("c[%d] = a[%d] = %d\n", (i - 1 + tim) % n + 1, i, a[i]);
	if(std::count(c + 1, c + 1 + n, 0) == n)
	{
		if(tim & 1) c[1] = -1;
		else c[1] = 1;
	}
	// for(int i = 1; i <= n; i++) print(c[i], 0);
	// putc('\n');
	for(int i = 1; i < n; i++) if(c[i] && !c[i + 1]) c[i + 1] = -c[i];
	for(int i = n; i > 1; i--) if(c[i] && !c[i - 1]) c[i - 1] = -c[i];
	// for(int i = 1; i <= n; i++) print(std::max(c[i], 0), 0);
	// putc('\n');
	int ans = tim, t = n;
	for(int i = 2, p = 0; i <= n; i++)
	{
		for(; p && c[p + 1] != c[i]; p = fail[p]);
		if(c[p + 1] == c[i]) p++;
		fail[i] = p;
	}
	// printf("fail[%d] = %d\n", n, fail[n]);
	if(fail[n] && n % (n - fail[n]) == 0) t = n - fail[n];
	ans += t;
	print(ans, '\n');
}
void init()
{

}
char _ED_;
void mian()
{
	debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
	init();
	for(int T = read(); T; solve(), T--);
}

#ifdef int
	#undef int
#endif
}

int main()
{
	uvu::mian(); return 0;
}

詳細信息

Test #1:

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

input:

3
1
001001
0001111

output:

1
3
9

result:

ok 3 number(s): "1 3 9"

Test #2:

score: 0
Accepted
time: 120ms
memory: 3908kb

input:

262144
000000000000000000
100000000000000000
010000000000000000
110000000000000000
001000000000000000
101000000000000000
011000000000000000
111000000000000000
000100000000000000
100100000000000000
010100000000000000
110100000000000000
001100000000000000
101100000000000000
011100000000000000
11110000...

output:

1
18
18
19
18
18
19
20
18
18
18
20
19
19
20
21
18
18
18
19
18
18
20
21
19
19
19
21
20
20
21
22
18
18
18
19
18
18
19
21
18
18
18
21
20
20
21
22
19
19
19
19
19
19
21
22
20
20
20
22
21
21
22
23
18
18
18
19
18
18
19
20
18
18
18
20
19
19
21
22
18
18
18
19
18
18
21
22
20
20
20
22
21
21
22
23
19
19
19
19
1...

result:

ok 262144 numbers

Test #3:

score: 0
Accepted
time: 241ms
memory: 3932kb

input:

524288
0000000000000000000
1000000000000000000
0100000000000000000
1100000000000000000
0010000000000000000
1010000000000000000
0110000000000000000
1110000000000000000
0001000000000000000
1001000000000000000
0101000000000000000
1101000000000000000
0011000000000000000
1011000000000000000
0111000000000...

output:

1
19
19
20
19
19
20
21
19
19
19
21
20
20
21
22
19
19
19
20
19
19
21
22
20
20
20
22
21
21
22
23
19
19
19
20
19
19
20
22
19
19
19
22
21
21
22
23
20
20
20
20
20
20
22
23
21
21
21
23
22
22
23
24
19
19
19
20
19
19
20
21
19
19
19
21
20
20
22
23
19
19
19
20
19
19
22
23
21
21
21
23
22
22
23
24
20
20
20
20
2...

result:

ok 524288 numbers

Test #4:

score: 0
Accepted
time: 434ms
memory: 3892kb

input:

952358
0011101111
101010101101
101111111010100
0101011000110001100
0101111101110
010
100100000111011
011010110110011
1010111
1
1111101010
11111011001111110
0101101101011
001
1100111100
100011
10
10
0001
011100
1100010
111111101010010
01001111110011011
01100
1010
10101111
01000111100011111110
10101
0...

output:

11
12
18
20
14
3
21
16
7
1
10
18
13
3
11
4
2
2
4
4
8
18
19
6
2
8
24
5
1
1
5
25
1
14
1
15
20
3
7
24
12
10
20
21
23
1
22
18
22
5
1
6
18
12
1
4
5
12
13
12
21
1
5
12
21
8
1
8
18
4
1
12
13
6
3
3
16
6
8
1
1
17
1
1
1
6
6
4
4
10
7
5
4
5
24
6
11
4
8
15
3
9
9
19
5
16
11
5
6
9
17
1
25
14
6
1
4
20
1
4
20
14
14
...

result:

ok 952358 numbers

Test #5:

score: 0
Accepted
time: 419ms
memory: 3816kb

input:

645561
001000111110000
01001111000
01011010
110000110111111111
0110100010000100
0
010011
010011111
00000111100001101110101100001
10111111000
100
1101100000001010110110101
1001111101
000100
101
1110101100011111101001111
000111100111100
1111001101011000000
100101001001001010111011011111
10111001100111...

output:

19
14
4
21
18
1
4
11
37
13
3
34
11
6
3
29
21
27
38
24
13
22
26
39
26
31
10
22
1
17
34
40
18
9
29
31
11
3
28
15
20
27
29
16
2
23
18
31
5
14
33
18
1
1
18
7
36
17
34
1
18
6
16
20
19
3
18
36
21
23
21
4
30
12
4
35
16
18
35
2
25
20
31
17
26
24
3
24
6
26
25
17
13
7
24
27
25
18
22
10
20
4
6
23
17
30
16
22
3...

result:

ok 645561 numbers

Test #6:

score: 0
Accepted
time: 409ms
memory: 3944kb

input:

488486
01101101
011000000100011010101011010
0100101110001011
00111110011110011010001101010000
11010010000010011111011010000010001
01001111001000010110
10110010011010100101010101111
10100000000001
1000010010
0
1111
10001010011011001111100101010
01010111100001011111011110101110101
11100
10101010001101...

output:

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

result:

ok 488486 numbers

Test #7:

score: 0
Accepted
time: 399ms
memory: 3900kb

input:

392510
01
00110011011000101011100
0100001010100011111011100011101011111100001110
1011001
00100110000011010
1101110
000100011000001111111100101011110111010111110
0111110000001010111110100011
0100111110000000111101110011011100100
100110000111101101101011011110001101111
111
0000001101011
11101100
10000...

output:

2
26
62
8
19
7
59
34
54
44
1
17
9
43
37
5
1
17
10
30
52
32
11
36
16
37
45
31
12
44
31
45
43
16
11
10
51
41
48
31
22
1
13
1
33
27
25
35
2
5
15
27
6
49
33
3
33
38
52
60
48
28
35
31
25
5
1
44
67
31
36
6
24
31
1
35
56
44
38
36
15
14
49
61
57
61
44
22
38
27
11
51
53
13
30
34
4
56
51
18
2
29
42
51
2
15
9
...

result:

ok 392510 numbers

Test #8:

score: 0
Accepted
time: 354ms
memory: 3816kb

input:

197451
00010111010000100100110001010100100100101001111001000101101001010111100010110101001000001
0000011
11010001011010010010001000011111001110110100111110000010101100110000001100111
0110101110000001001010100
10100010
0110100111
010101000100011001110000000110000000011101010011101
0000110110101011001...

output:

98
8
112
30
8
12
63
96
73
123
10
106
5
106
28
24
101
44
85
109
69
29
104
76
106
111
126
8
106
89
44
36
9
56
9
111
28
37
94
6
102
2
116
19
5
50
32
17
97
114
127
12
26
9
90
133
109
9
66
27
95
1
59
59
93
40
139
84
51
33
101
127
27
1
86
12
95
41
90
134
87
24
109
57
11
85
60
50
4
52
133
66
58
15
41
45
11...

result:

ok 197451 numbers

Test #9:

score: 0
Accepted
time: 299ms
memory: 3932kb

input:

99606
110011011001101010010101101110011100110101
111110001011000010010110011001110111010101100110100001111
1111111111110101101011000101101101101110011110100001100010
00110110000101111000010011100010011110101000111110010011111110011011100001001111101001010000101010000100101111001001110010100001000100...

output:

45
66
67
227
261
108
39
44
204
26
72
249
44
130
44
80
39
180
23
148
157
66
201
157
150
151
184
137
252
102
139
36
51
216
9
17
141
216
253
241
92
220
52
139
125
75
98
162
202
2
50
117
170
46
154
95
132
202
23
154
222
210
17
91
39
163
145
184
98
225
35
12
163
197
247
78
28
85
207
177
145
65
1
101
231
...

result:

ok 99606 numbers

Test #10:

score: 0
Accepted
time: 266ms
memory: 3912kb

input:

39961
0010111101010101011101101111110000010000000011100101001100100001101101110110110111000100111010001110101000001011011011101110000111001011001000101000000110100111100110011010011
0011110111000100101111001001010100001011111111011001000110011001100000110110001101001110011100001010100100001010110100...

output:

218
247
101
564
482
45
274
1
342
161
263
364
76
233
581
28
229
134
514
690
722
234
109
555
553
696
481
383
88
78
510
226
603
498
175
10
307
542
333
731
447
608
153
304
193
427
372
242
383
640
664
93
126
434
176
69
361
547
418
518
372
63
439
359
15
249
394
311
194
341
423
202
90
594
595
206
141
154
3...

result:

ok 39961 numbers

Test #11:

score: 0
Accepted
time: 245ms
memory: 3972kb

input:

19900
00101000110101110100101101101000100001110011010110001000111000101000101100110110110010101010110011001
000100001101000100000000011001111100001010011100001010110010100111100000110100100010011110100011000001101100101010010110001100001000011100010001001111111011000111100011100001111111101100000010...

output:

117
1202
935
320
31
349
631
371
30
181
1132
764
708
1262
436
1222
960
1076
1310
1168
715
320
946
959
101
528
746
183
1347
641
765
1101
801
858
742
54
555
782
369
1085
175
496
566
793
804
197
540
25
727
1043
601
1197
1230
136
129
528
1442
962
1081
926
655
465
176
402
576
1089
117
1075
927
11
1350
185...

result:

ok 19900 numbers

Test #12:

score: 0
Accepted
time: 220ms
memory: 4052kb

input:

4031
0101001000010110001001000101110011010010110101001111001011010100001011000000011110000101010100111010110111001000101010101101011110001011000010101100111001110101000101001101001111011001100100101000010100110000010001110101101000110011001000001100000110000001101000100111100101001010111010000010001...

output:

6202
584
6509
657
1743
5982
1148
748
1575
6011
6040
5974
2214
5948
4292
4605
2487
2731
4044
1993
5214
6627
4551
1840
2417
244
6770
2494
1059
3867
4419
2657
4977
4832
5701
1563
1289
5763
1109
2331
2856
1656
1779
6475
5204
600
2179
1248
5753
3579
3725
977
2984
4648
5155
5718
4911
655
1706
930
3573
544...

result:

ok 4031 numbers

Test #13:

score: 0
Accepted
time: 226ms
memory: 4228kb

input:

1986
0010100001101000101100001101010011101001110001011101000101010011011000011000000011100110111111010011011010000001000100100001111010101000110000011001110011111100100011100000000101011010101001001011100001111010110011101001000101001110111011001001011111000101000111111101000111110100110100101110011...

output:

3575
158
10791
2517
10092
379
2714
4211
10875
864
7134
3087
9276
5867
4399
6739
7310
8962
1786
1864
6083
9574
2381
887
9533
6409
7472
101
9389
4962
8088
1381
4558
6064
11626
13564
9725
8062
9960
7461
4006
8686
7926
992
10332
5300
4297
1258
3574
8521
9338
4518
1454
9619
6148
1728
1693
8778
4767
9005
...

result:

ok 1986 numbers

Test #14:

score: 0
Accepted
time: 220ms
memory: 6932kb

input:

200
11110101000100010101100111001011001100011010111101111001010110111100011000110100000101001011100110000001101101010111001001111000011000110101100001101111000010010001110011011011100100000110001101010000111111011010001010000111111010100110001110111011010001001010010111100000000101000000110110100101...

output:

99387
101499
105048
107208
147040
123233
104316
147653
129648
112911
123645
68175
86293
59301
9216
20367
135688
57251
140800
103068
15284
5563
54435
56802
115931
5470
10007
102744
17459
94573
120878
36051
60255
25462
37271
89381
25412
60168
121131
103391
6313
72623
18730
112666
126652
20613
126380
1...

result:

ok 200 numbers

Test #15:

score: 0
Accepted
time: 224ms
memory: 29180kb

input:

32
001000110111000110001001011111010111101110100100100001101101110100111101110100011001010110101100011010111100110110001100101000100011011101100111111101100101110110011010011011110100101111000001111110101110010010100111000101000000001000100000010001111011011000110011011100111100010000110010101100011...

output:

789128
429343
538544
596982
409959
372382
359690
572322
247119
172312
601326
439990
866424
598385
696599
12351
835984
854751
639495
121099
381828
201978
2258
217
2648
1957
880
85
3
3
6
2

result:

ok 32 numbers

Test #16:

score: 0
Accepted
time: 240ms
memory: 144504kb

input:

17
001011111100001100101011100000000011110111100110100110111010110100001111000010011111111110010001101000100011110101111011001011111011000010011001100000110101001101100101010000101110010010101101110110000101001101011100011001101010101010011000101000001000001001010111100001000010011100101100011001111...

output:

4673925
490734
133816
1140925
276336
3107252
202768
110731
148861
35367
14100
4549
1219
1698
15
2
1

result:

ok 17 numbers

Test #17:

score: 0
Accepted
time: 144ms
memory: 340892kb

input:

1
0010000000010010001000000001001000100000000100100010000000010010001000000001001000100000000100100010000000010010001000000001001000100000000100100010000000010010001000000001001000100000000100100010000000010010001000000001001000100000000100100010000000010010001000000001001000100000000100100010000000...

output:

16

result:

ok 1 number(s): "16"

Test #18:

score: 0
Accepted
time: 137ms
memory: 268412kb

input:

1
0010100000010000010100010001001000010010010000101010010010101010101010101010100010010010010010010101000100101010100000000001010000100001001010101001001010000000010001000010100000100100101001001010101010010010001010010100000010101010101010000101000100001010000001000001010001000100100001001001000010...

output:

250

result:

ok 1 number(s): "250"

Test #19:

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

input:

1
0010101010100101000010001001010101010101001001010001001010100010100000100101001010100100010000100101000010101010010000101010000001010100001010101001010100100000010101010000010101010010001001001001010010100100100100001001010100100010010101010101010001001001010100010101001010010100010001010010000101...

output:

8000

result:

ok 1 number(s): "8000"

Test #20:

score: 0
Accepted
time: 208ms
memory: 261132kb

input:

1
0100101000001010100010101001001010100000101000001001010101000010010001010001010010101001001001010001010101010010100100001010010010101010101001010010010010001010101001001010101001010101010010101010101001000100101010010010101000010010101001010100001010001010010100100010101010100101010001001001001001...

output:

250000

result:

ok 1 number(s): "250000"

Test #21:

score: 0
Accepted
time: 172ms
memory: 333948kb

input:

1
0100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010000100001000010...

output:

5

result:

ok 1 number(s): "5"

Test #22:

score: 0
Accepted
time: 379ms
memory: 3900kb

input:

952716
000000001111110000
011110000
11001111000001010
1
0000000000
00
0000000
000000000000000
1111111111
0000
1000000011
0000111
00000000000111
101110111111000101
1111111111111001111
000010000000
00011010010010000
11111111111000000000
1
000100001111001
11001
000000000
00000000000000000000
1100111110...

output:

23
12
20
1
1
1
1
1
1
1
12
9
16
20
20
12
19
28
1
19
6
1
1
15
25
11
1
12
14
1
16
5
10
1
24
1
5
6
25
3
4
10
14
11
20
18
17
15
5
25
18
13
22
1
23
21
1
1
19
1
11
27
6
1
1
21
1
10
23
1
9
5
6
1
24
24
5
3
3
12
23
15
5
1
11
3
19
10
12
1
22
22
9
15
3
8
1
9
13
22
11
16
1
16
7
1
1
11
1
15
1
17
14
5
21
1
1
9
5
9...

result:

ok 952716 numbers

Test #23:

score: 0
Accepted
time: 373ms
memory: 3924kb

input:

952556
0001011
1000110010000
0100000010100
0
0
1110
0000000000000000
1100
01100001100000
11000100000000111101
110
0011110
0000000
011001111
1111100001
100110001
000000000000
00000000111110110111
011100
00100010011101
00000000000111111111
0000000
0
1000000010000001
01111
110000001110010001
00
1111000...

output:

8
14
13
1
1
4
1
3
15
27
3
9
1
10
13
10
1
11
4
18
28
1
1
17
5
21
1
21
1
16
15
1
18
17
1
11
22
15
20
17
20
1
21
1
17
1
6
1
1
1
9
3
15
9
8
12
16
20
3
24
7
12
10
12
17
1
3
1
10
15
1
1
3
15
16
25
1
5
23
1
6
18
1
16
1
15
14
27
17
2
15
7
1
8
4
19
11
21
3
8
5
4
12
7
11
18
18
1
13
12
24
17
9
4
16
22
1
11
2
1...

result:

ok 952556 numbers

Test #24:

score: 0
Accepted
time: 390ms
memory: 3936kb

input:

644975
001
0000111111111111110111111
000011111101000
0
11111111111111111111000
011100111111111111110
0000
0100
0
00000000000000
1101111100010
00000
01011011111010000111111101100
110
00011111111000
0000000000001111100000
0111111111111000000
10111011000
0000
00111000000
0000000000001111111111111
00000...

output:

3
28
21
1
25
22
1
4
1
1
15
1
33
3
19
26
25
14
1
13
36
27
4
22
35
32
3
5
7
13
32
1
17
15
5
1
1
1
24
21
33
22
15
3
17
10
1
31
12
23
22
18
20
28
11
8
20
1
1
25
30
15
1
19
31
36
1
15
17
1
10
13
32
25
21
36
8
1
13
23
16
15
34
25
34
24
10
1
33
14
8
1
9
1
27
1
6
20
27
14
22
18
4
37
14
5
26
27
6
9
36
37
28
...

result:

ok 644975 numbers

Test #25:

score: 0
Accepted
time: 381ms
memory: 3940kb

input:

645112
000000111100001
0000000100111111
00001100010001110001001110010
111111100000111
0000011
11110001111111100011001011
100000001100010101
010000100011001111
000000
00000000000000000000
00001100000000000000000
0000000110111111111111100000
001100111011100110011011
00
000010001111111000000000011
1000...

output:

18
21
32
19
8
28
19
22
1
1
24
39
25
1
33
8
3
25
1
27
5
29
1
30
39
6
1
14
27
30
12
20
6
15
34
26
20
31
1
27
12
37
1
1
1
17
28
5
34
24
3
1
1
26
9
8
18
39
1
15
14
4
7
16
6
21
1
22
4
10
38
26
27
1
1
28
1
21
21
1
1
1
9
5
17
3
39
11
1
17
32
23
12
14
23
13
11
24
11
1
23
5
4
29
15
13
5
25
10
18
3
21
20
10
2...

result:

ok 645112 numbers

Test #26:

score: 0
Accepted
time: 375ms
memory: 4000kb

input:

392147
0000000000000000001111111111111110000000000
00011011110010000111111
000000000000000000000000
1110110011
0101111001101101100110001111011001111111
001111000000000000001111110000000000
010000100011101111101110111111111
000000000100000000000111111111111
00000000000001111111
0111111011100111001111...

output:

57
29
1
11
45
41
40
45
26
27
11
4
62
10
50
36
18
47
17
18
30
48
39
42
28
59
4
21
46
1
1
10
15
37
20
53
19
23
1
26
29
42
23
50
1
51
19
51
19
20
14
11
50
44
23
49
65
43
7
1
9
6
12
8
42
39
27
47
37
41
14
27
42
70
40
1
30
55
39
42
11
7
7
53
1
9
32
18
61
6
28
20
3
16
34
47
5
1
55
9
36
33
31
8
28
15
20
17...

result:

ok 392147 numbers

Test #27:

score: 0
Accepted
time: 363ms
memory: 3812kb

input:

392221
111110110001111101
0100001000
000000000001000001111100000000011110000000000111
11111111111100111110000000000000011111111111111111
000001111110000000000001011111111111110
00000000100011100111101000000010000011
000000000001000000000000
000111001111111110000000011
1
10001100001111101011111100001...

output:

21
5
52
65
56
45
24
37
1
45
13
7
38
60
28
53
1
16
4
7
48
13
1
1
44
1
27
37
1
17
1
60
51
34
1
31
42
30
48
57
13
8
66
34
5
60
1
38
18
3
40
28
73
45
33
32
1
60
1
35
37
1
1
22
9
49
60
57
14
52
32
9
1
38
52
24
48
49
39
57
25
20
38
1
57
11
8
38
3
47
38
18
41
4
30
37
53
57
6
28
46
8
1
22
44
11
32
6
66
23
3...

result:

ok 392221 numbers

Test #28:

score: 0
Accepted
time: 309ms
memory: 3908kb

input:

197924
0011111110010001101111110011001001110111111000001101110000111000011000000111000
111100110011010101100011101111
011110000111111111110000000100010000010001000
00000000011000
1
0111010011111111111100011011000100111011011111110001111010111100000001000
111110011110100100000110010010011110110001111...

output:

111
35
57
15
1
88
103
19
110
110
98
101
1
1
45
124
33
46
85
102
18
51
109
123
121
69
144
21
36
1
75
47
91
67
60
25
64
118
40
19
78
103
98
3
100
5
61
104
19
6
45
90
90
79
103
25
34
129
78
121
96
107
1
23
42
97
15
28
16
9
97
12
6
95
58
94
119
20
22
60
13
129
2
113
89
90
47
14
109
71
123
99
57
74
20
12...

result:

ok 197924 numbers

Test #29:

score: 0
Accepted
time: 320ms
memory: 3992kb

input:

197520
001001110011111111111111111100111111110000000111100111
0000000000000000100000001111100001111111111111111100000001
01001100000110000110111000111110010010110100000110101
001101
00000000000000000000011111111111111111111111111111111
0000000000000000000000111111111101111111111111000000000000000001...

output:

60
80
67
4
73
111
101
24
66
69
27
79
144
39
24
84
33
55
56
29
1
100
75
48
13
84
115
5
10
1
85
18
13
52
95
2
103
39
17
105
59
27
76
81
70
64
1
86
37
53
97
63
91
134
116
94
59
43
115
35
79
118
25
130
38
74
2
1
108
37
52
107
28
32
55
99
13
98
20
20
64
93
54
58
29
41
27
75
59
84
103
37
1
48
82
73
109
42...

result:

ok 197520 numbers

Test #30:

score: 0
Accepted
time: 283ms
memory: 3892kb

input:

99357
010000101111110001110000101100011011111110011011110100111000111100111101011101100001110010001111101101001111001110100110011
001111111000111111111111111111000001100000111000000000000000000000000000111
000000000000000000000001100
000011110000000110000000111111111111010000111001111000011111101111...

output:

134
107
28
92
210
230
197
91
200
45
19
191
46
1
168
130
250
1
151
23
1
172
104
73
18
237
61
71
112
85
190
164
1
210
195
202
30
19
34
10
96
231
32
97
91
15
219
216
1
25
213
96
260
235
152
112
55
178
63
113
249
43
223
165
279
188
1
36
187
192
178
30
13
70
116
170
101
252
166
264
65
24
27
38
197
218
11...

result:

ok 99357 numbers

Test #31:

score: 0
Accepted
time: 231ms
memory: 4020kb

input:

40003
000000000000000000000000011110000000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111001111111110000000001111111111111111110001111111111111111111111000000000000000000000111111111111111111000000000000000000000000000000000000000000000000000000000...

output:

451
152
562
43
456
342
654
452
239
1
179
70
324
201
517
106
491
488
197
388
367
92
354
14
186
200
169
244
52
173
673
382
17
409
230
424
387
37
77
146
467
339
107
336
135
364
138
450
559
371
595
16
72
181
57
392
373
384
318
463
160
53
25
583
189
234
298
142
71
558
346
116
523
396
407
516
365
463
510
...

result:

ok 40003 numbers

Test #32:

score: 0
Accepted
time: 209ms
memory: 3904kb

input:

19920
110001111101111111101111100011111110001011111000010011000000000011110001100001110111111111000000111111110000011111111111110100001010011111100000000111100110111110001010000010110010000010010000100111111000111101100001111111111111100100110110010011111111111111100001100100111000000001000000011110...

output:

950
231
1010
645
267
542
600
556
401
1246
1136
100
1018
1186
112
556
1024
1140
775
664
187
1213
901
736
1073
317
1052
48
465
1192
124
467
1277
598
309
1077
825
945
715
212
705
1091
1063
518
977
450
129
301
605
1
921
994
52
264
194
14
11
161
438
739
671
252
245
890
523
497
891
1063
435
906
1064
507
7...

result:

ok 19920 numbers

Test #33:

score: 0
Accepted
time: 199ms
memory: 4156kb

input:

4035
0110100011100000000111111101111111111111111000000001111110000000011111111100000111100001111111111111111011100000111000000000111111111100110000011111110000111111111111100000111000110111000000011111111100000010000111000011111111111000111111000111111111000001111000001111100000011111100000001111110...

output:

5336
3684
2346
5649
243
822
94
6014
2260
2406
3863
1785
5205
3266
1408
1514
5302
3991
2172
408
4607
1863
3470
5147
4310
3183
6964
2145
7315
4164
4031
826
5751
4257
2207
4953
3781
1463
1361
1237
3990
978
5268
657
4705
2698
3087
1806
2689
6293
4760
573
1066
699
1278
1531
5744
2520
3401
3844
2572
2190
...

result:

ok 4035 numbers

Test #34:

score: 0
Accepted
time: 200ms
memory: 4244kb

input:

2017
1110010001100001100011100000000001110111100001111110011000000001111111011111110111110111111111100000000000000110000001111111110000000000000011110001100000111100000000111111110001110000001100000001110100000000001010000100000000011111011000000111000000001001100100001111111100000000000111110001000...

output:

7466
4208
6136
3523
275
8357
1
8628
7158
9990
3457
10117
9795
8693
7931
7807
3899
2155
9119
9060
4531
2085
6772
9385
8447
7751
8386
3587
1921
4877
13054
8249
7957
13599
8275
8372
1999
4046
4944
9125
198
2091
8050
2465
8665
2702
3615
4371
6288
10388
2461
12866
11853
7626
6265
5536
1912
11573
379
1013...

result:

ok 2017 numbers

Test #35:

score: 0
Accepted
time: 189ms
memory: 5916kb

input:

430
00110010000000000011111111111111111111111101111111111111111110000000000000000001111111111111111111111111111110111111110000111111000011111000110011111111111101111111100000000001100000000011111111100000110111111111111111000000000001111111100000000000010111000000000000111111110000111100000011111111...

output:

2542
59622
37281
23095
46116
66952
15402
5302
34928
12217
16728
53183
14185
14975
43500
23805
28456
71262
47266
18186
7995
54080
40497
24859
13045
14372
27865
57464
22376
24709
59470
57967
30481
59326
44160
9039
40950
27547
19219
21913
42711
23105
59495
61070
6496
1190
18235
21091
31207
50091
8334
4...

result:

ok 430 numbers

Test #36:

score: 0
Accepted
time: 195ms
memory: 7748kb

input:

223
00000000001000011000000000001111111000000000000000011111111000011100111111110000000111111111111111111000111111010011111111111111100000011111100001111110000000000011100011111111111110011111111100000000000001111111111110001000000000000011111111111111111111111110000000000000000000000000000010011111...

output:

41794
130077
22990
64587
99490
29611
109186
84053
69464
93823
67780
58456
46549
38391
97287
14478
43299
8300
96079
96909
129668
73919
69467
43296
5657
26741
7839
120956
68357
107361
32884
69336
22442
114282
65657
58426
15697
120320
6114
77537
106268
20163
9596
37297
21576
95775
19316
23985
35072
923...

result:

ok 223 numbers

Test #37:

score: 0
Accepted
time: 200ms
memory: 40568kb

input:

31
111100001111111110011111000011100001111000000011110000000100011111000001111010001001001000010000100000000001110011110000001110000000000000001100010000000001111000011000000111110001100011110000111110000000000001111111110110001100111111100011101111100100000000111100001100011001111110111110001000000...

output:

181127
1439434
1169403
640491
758786
694113
37226
603893
684221
322742
769105
900993
775850
134608
1223228
429314
946968
735745
1279
159503
1034408
28998
30688
686
977
452
173
6
1
1
1

result:

ok 31 numbers

Test #38:

score: 0
Accepted
time: 262ms
memory: 287668kb

input:

19
000010110101101110100110111100001100010000110000111010100000101101110010010001100100110000001111111010010111100111100001101111111110101110011001010001001101001000111100001010001010011100000100011110001111011111110010011100110000010001011011100100101011111001111111100111011101101000100100000010100...

output:

10549871
842547
637254
13208
4092
1806
1299
1006
9499
1922
128
1608
726
410
9
50
136
1
5

result:

ok 19 numbers

Test #39:

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

input:

909007
00000000
0000000
0000
000101000101
0010000100
0000000000000
010100101001010
0101010101
0000000
0000000000
000000
0000
00
00010100001010
0101010101010101
000010100000010100
0000100001
000010000010000010
000010000100001
00000
0000000000000
000
00000
000
00000000000
00000000
010010010
0101
00000...

output:

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

result:

ok 909007 numbers

Test #40:

score: 0
Accepted
time: 125ms
memory: 3988kb

input:

624263
001000001000001000001000
0000000
000000000000000000
0000000000000000000000000000
0000000000000000000
0100000001000000
0101010101010101
0010100101001010010100101
00
0000000000000000000
000000000000000000000000000
000000000
00000000000000000000000000000
0000000000000
000000000
0101010001010100
...

output:

6
1
1
1
1
8
2
5
1
1
1
1
1
1
1
8
1
7
1
1
6
1
1
1
15
1
1
3
7
1
1
1
3
8
1
1
6
1
1
1
5
1
1
2
1
2
1
2
1
13
2
3
3
1
1
14
1
1
1
1
8
1
1
1
10
1
1
7
1
1
5
1
1
1
1
1
3
1
5
3
1
1
1
1
1
1
1
1
1
1
11
5
5
2
1
1
1
15
1
1
1
3
1
1
1
1
1
3
6
1
1
1
2
1
2
1
1
3
12
1
7
3
13
1
2
3
1
1
1
8
2
1
1
1
1
1
1
1
3
1
5
1
1
2
1
2
...

result:

ok 624263 numbers

Test #41:

score: 0
Accepted
time: 129ms
memory: 3884kb

input:

475754
0000000000000000000
01010101010101010101
0000
0000000000000000000000000000
01001010010100100101001010
00
00010000100001000010000100001000010
00000000
00000000000000000
010010010010010010010
00000000000000000000000000000000000000
00010001000100010001
00000000
010101
01010101010101010101010101
...

output:

1
2
1
1
13
1
5
1
1
3
1
4
1
2
2
1
1
1
2
10
4
1
1
3
1
1
1
1
2
1
3
2
1
6
1
15
2
1
1
1
1
1
13
1
15
1
1
4
1
4
1
13
8
1
1
3
1
1
3
1
1
8
2
16
3
2
1
2
8
5
1
1
2
1
1
3
1
1
3
14
1
5
1
2
1
5
1
19
1
1
1
1
1
1
1
1
3
1
5
1
1
1
7
1
1
2
1
1
1
3
6
1
1
7
7
1
13
7
1
5
1
1
1
1
1
4
1
5
1
4
7
1
10
1
4
12
4
1
17
1
1
5
3
1...

result:

ok 475754 numbers

Test #42:

score: 0
Accepted
time: 125ms
memory: 3808kb

input:

384460
001010001010001010001010001010001010
000001000100001000001000100001
010101010101010101010101010101
01010101010101010101010101
0000000000000000000000000000
000000000000000000000000000000000000000000
0000000000000000000000
00000000000000000
00001000000100
00000000000000000000000000
001010000101...

output:

6
15
2
2
1
1
1
1
7
1
7
1
2
6
1
3
1
1
1
8
2
7
5
1
7
1
1
16
19
1
1
1
3
1
1
19
9
1
1
1
13
11
5
1
6
1
1
7
1
1
1
1
4
18
1
11
8
5
7
2
1
7
2
7
1
1
15
1
1
1
1
1
7
3
2
1
1
7
1
1
1
1
3
7
1
1
1
1
1
1
1
1
5
1
2
3
11
3
3
1
3
1
1
1
13
17
1
1
1
1
11
1
1
11
1
19
1
5
1
1
1
1
1
1
5
1
4
17
1
1
15
11
1
1
3
1
1
6
1
1
11...

result:

ok 384460 numbers

Test #43:

score: 0
Accepted
time: 127ms
memory: 3916kb

input:

196114
0000000000000000000000000000000000000000000
00000000000000000000000000
000100000100000100000100000100000100000100000100000100000100000100000100000100
0000000000000000000000000000000000000000000
00010000100001000010000100001000010000100001000010000100001000010
000101010100000101010010001010101...

output:

1
1
6
1
5
23
1
1
1
1
6
1
1
1
5
4
1
1
2
5
32
1
15
5
1
1
4
1
2
1
1
13
1
3
2
1
3
4
3
7
1
1
7
3
4
1
1
1
4
4
1
2
1
2
3
5
2
11
1
1
2
1
1
1
3
1
1
7
7
15
1
11
1
12
4
10
37
1
3
11
5
1
1
1
1
1
1
1
13
8
1
1
6
1
1
1
1
1
6
10
1
1
9
1
1
1
2
1
2
18
1
1
1
33
15
1
10
11
27
1
23
1
1
1
1
1
1
1
1
3
4
5
22
18
13
2
14
1
...

result:

ok 196114 numbers

Test #44:

score: 0
Accepted
time: 121ms
memory: 3940kb

input:

99121
010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010010101010
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

9
1
10
10
95
2
1
1
7
4
1
67
25
91
1
1
1
15
1
23
4
1
1
1
10
65
1
3
13
13
95
1
43
11
2
1
59
1
1
1
31
36
10
1
47
1
24
12
4
44
5
3
12
19
1
1
1
1
1
1
3
1
34
1
1
46
1
13
3
9
5
44
1
1
5
77
59
4
1
3
19
1
1
7
7
11
5
98
3
1
1
1
34
5
6
19
4
7
1
1
13
1
23
11
7
1
19
40
1
1
1
21
4
10
5
1
100
1
1
1
21
1
5
3
16
30
...

result:

ok 99121 numbers

Test #45:

score: 0
Accepted
time: 108ms
memory: 3956kb

input:

39897
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0100010100010000101010000100100000001010001000101000100001010100001001000000010100010001010001000010101000010010000000101000100010100010...

output:

1
41
1
12
1
3
1
1
1
1
28
54
1
1
5
2
43
5
56
134
3
34
123
8
35
1
1
1
3
5
1
1
13
1
1
14
2
69
13
139
1
1
1
1
124
7
1
1
3
31
166
2
241
1
1
19
1
23
1
1
14
1
1
18
9
9
5
11
43
6
1
2
1
97
71
1
47
1
5
14
1
3
163
8
1
1
3
13
1
7
2
19
85
1
18
1
1
1
31
23
1
1
11
25
7
1
7
43
1
25
14
1
1
149
23
2
31
1
1
1
43
4
3
7...

result:

ok 39897 numbers

Test #46:

score: 0
Accepted
time: 104ms
memory: 3844kb

input:

19823
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1
1
2
1
1
1
1
17
1
124
1
27
29
1
33
202
1
1
7
38
119
1
1
13
28
253
1
1
58
1
1
17
23
423
1
1
15
1
63
271
2
1
4
1
1
239
1
421
3
87
124
1
1
3
1
47
23
7
2
5
2
194
43
158
11
5
269
7
329
77
7
1
233
1
3
20
7
1
1
3
9
103
2
1
3
42
5
442
1
1
266
451
1
2
24
1
24
4
2
7
284
1
227
3
151
1
1
1
5
3
1
1
49
254
9
89
...

result:

ok 19823 numbers

Test #47:

score: 0
Accepted
time: 94ms
memory: 4096kb

input:

4068
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1
2
15
16
210
3
347
247
104
1
7
126
218
1
57
1
1
1
503
13
674
1
117
89
1
1363
8
121
1
4
1
1
773
1611
35
1
3
1
1
1237
196
61
1
13
1
83
1
1
1
163
1
1466
4
2
1
246
3
21
83
1
193
1
407
1
14
1
1
172
4
26
33
79
106
1
24
115
1323
101
78
1
29
5
771
1
9
2
1
1194
2459
2
2
1459
1
1
1
1
34
7
1
1
13
4
1
178
1
3
...

result:

ok 4068 numbers

Test #48:

score: 0
Accepted
time: 97ms
memory: 4300kb

input:

2014
0101010100101000010000100101010000010100001010100001000101001010000010100001001001010100010100101010101010010000001010001010000101010100100000010010100010001010010101001010100010100010101000001000000101010100100101001001001010010010000100001000100001010001001000010010000101001001000010100101001...

output:

523
1
9
14
5
83
1
283
157
3
1
692
7
16
954
1
491
515
9
15
23
6
1
49
55
38
1031
4
2003
34
434
137
129
31
3323
163
1
29
1
7
1
365
417
33
356
9
1
53
111
5
1
1
1
1
127
1951
1
262
22
4
1210
1
22
1
1
2
559
3
1
5
1299
1
3
1
4
1
1
1
3
1
1
1
657
1
361
253
233
5
5
1
5
2141
139
14
53
13
2
568
1219
201
42
105
5...

result:

ok 2014 numbers

Test #49:

score: 0
Accepted
time: 101ms
memory: 7340kb

input:

206
00001010000101000010100001010000101000010100001010000101000010100001010000101000010100001010000101000010100001010000101000010100001010000101000010100001010000101000010100001010000101000010100001010000101000010100001010000101000010100001010000101000010100001010000101000010100001010000101000010100...

output:

7
2153
4
6603
241
3
1
7
21
1
16
4
20197
36023
37958
1
4456
1
1
785
1029
1
1
1
1
502
14
1
29
1
37
26
81
1
107
1137
1
6
2411
62
699
109
1898
83
211
116
11614
11
9
1
11
1
1
1
44
71
1027
24862
82
1
25
22
9095
19553
1426
33270
4
46
7949
3664
363
3
85
10
446
1
44758
1
5103
6
1259
1
20337
1
239
1383
1069
4...

result:

ok 206 numbers

Test #50:

score: 0
Accepted
time: 97ms
memory: 29540kb

input:

28
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1
1
3
1
382
454
23
142559
241663
22
2
1
904
2578
1
1
35365
1
1
23213
924
388
16
1
1
1
1
1

result:

ok 28 numbers

Test #51:

score: 0
Accepted
time: 122ms
memory: 206864kb

input:

17
010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010010...

output:

3
19
1
847
1
2
205
717
1
1
1
1
1
11
5
1
1

result:

ok 17 numbers