QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647812#5407. 基础图论练习题TrueFalse100 ✓180ms7252kbC++142.1kb2024-10-17 15:48:002024-10-17 15:48:01

Judging History

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

  • [2024-10-17 15:48:01]
  • 评测
  • 测评结果:100
  • 用时:180ms
  • 内存:7252kb
  • [2024-10-17 15:48:00]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>

using namespace std;

using ci = const int;

using u32 = uint32_t;
using i64 =  int64_t;
using u64 = uint64_t;

#define il inline
#define TT template<class T>

TT il void Max(T &x, const T &y) { if (x < y) x = y; }
TT il void Min(T &x, const T &y) { if (y < x) x = y; }

struct TimeCalc {
	~TimeCalc() { cerr << clock() * 1.0 / CLOCKS_PER_SEC; }
} TimeCalc;

const int N = 5005;
const int mod = 1e9 + 7;

int T, n;
char str[N];
bitset<N> e[N];
int d[N], s[N], s0[N], s1[N], sz[N];

il int C2(int x) { return x * (x - 1) / 2; }

void work() {
	scanf("%d", &n);
	for (int i = 2; i <= n; ++i) {
		scanf("%s", str + 1);
		for (int j = 1, x, p = 1; j <= (i + 3) / 4; ++j) {
			x = str[j] >= 'A' ? str[j] - 'A' + 10 : str[j] - '0';
			for (int k = 0; k < 4; ++k, ++p) {
				if (p >= i) break;
				if (x >> k & 1) e[i]._Unchecked_set(p), ++d[i];
				else e[p]._Unchecked_set(i), ++d[p];
			}
		}
	}

	memcpy(s, d, sizeof(int) * (n + 1));
	sort(s + 1, s + 1 + n);

	for (int i = 1; i <= n; ++i) {
		s[i] += s[i - 1];
		s0[i] = s0[i - 1] + (s[i] == C2(i));
		s1[i] = s1[i - 1] + (s[i] == C2(i) + 1);
	}

	for (int i = 1; i <= n; ++i) ++sz[d[i]];
	for (int i = 1; i <= n; ++i) sz[i] += sz[i - 1];

	int ans = 0;
	for (int i = n; i >= 1; --i) {
		for (int j = i - 1; j; --j) {
			int x = i, y = j, z = s0[n];
			if (e[x][y]) swap(x, y);

			/**
			 * for d[x] >= d[y]
			 * 交换前在同一个强连通分量中,只需贡献新增的量
			 * 
			 * for d[x] + 1 < d[y]
			 * 交换后在同一个强连通分量中,与上述相反
			 */
			if (d[x] >= d[y]) z += s1[sz[d[x]] - 1] - s1[sz[d[y] - 1]];
			if (d[x] + 1 < d[y]) z -= s0[sz[d[y] - 1]] - s0[sz[d[x]] - 1];
			ans = (ans * 2 + z) % mod;
		}
	}

	printf("%d\n", ans);

	for (int i = 1; i <= n; ++i) e[i].reset();
	memset(d, 0, sizeof(int) * (n + 1));
	memset(sz, 0, sizeof(int) * (n + 1));
}

int main() {
#ifndef ONLINE_JUDGE
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif

	scanf("%d", &T);
	while (T--) {
		work();
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 8ms
memory: 4008kb

input:

10000
100
1
2
2
8
C0
F0
27
78
AE1
C01
511
D87
EF20
3873
2742
73D0
DC9B0
FB2A3
9C011
9B4E0
95DC00
A7B980
F43531
6A6245
5347BE0
1A6C8A1
88E46D6
64CF3AE
D25F63C1
C894E4C3
1C0AFD73
EC1C3F9A
087CE17C0
22149A380
B28038AF1
B9CA21C7F
D78F5307C1
49045489A2
72C4DE6FD1
7713F40D05
EEE8878EEC1
310E62812B1
DA9D5B...

output:

281603732
13
285212672
371842543
84
0
1983
2
268505087
268435455
719476515
32785
2
719476771
123
2621567
2523
0
719476275
371842543
2097159
41087
34815
3113984
719478307
502774846
719476267
719476259
719476259
65224
268697613
719477283
36863
2171007
719476259
371842543
120
84
219
5769215
268435455
1...

result:

ok 10000 numbers

Test #2:

score: 20
Accepted
time: 8ms
memory: 4128kb

input:

10000
100
0
2
1
8
41
F2
30
30
F60
7D2
605
024
E910
45F3
3CB0
3B88
0FE21
A7DF3
3B162
70D7A
70B9C1
DFB731
883B33
930FC6
4F8BEC1
CC73551
1A344F3
88966C9
3879FE20
93839630
B6C3FF85
F6D5F7B1
F757DCB20
63C3512A3
9BFD99935
ED1E4F248
ECAB4DA041
EA5CE54511
EA07C72263
F8ADE1FD8C
B220226E1F0
34F274277A0
4A1A14...

output:

281603732
2097151
0
144
268443647
32767
2097151
2
19
903009902
0
268435455
1103
1099
268501119
719476259
17
574715508
0
268435455
321515202
1023
745417303
84
2097151
371842543
301989887
272629791
268435455
153406
0
719476531
2
3368
132695
0
402653183
268435455
371842543
0
0
17
719476259
371842543
23...

result:

ok 10000 numbers

Test #3:

score: 20
Accepted
time: 4ms
memory: 4136kb

input:

10000
100
1
0
3
7
11
C1
71
1A
C01
E43
237
9B5
33C1
0DE3
7C74
B042
38E60
65480
1D103
862A7
B2DA80
C63273
CF8AD3
AFBDC2
2816D11
1B12351
1869CC5
6BC6DB3
50E5FAB1
4E291CB2
4DF82716
0D410C3E
FD4B31250
8BF2C54A0
1266235D1
757755C58
724DFD1960
F6D1285122
281CDE0BB1
5EF924A6A9
786A08B90C1
BE8C674EE52
B9EFA2...

output:

281603732
371842549
371842543
268435459
1281
371842543
719476259
371842543
84
60934
108
2
268435455
108
1159
108
2097663
2
371842543
719476259
2
371842543
1536
7288681
269746175
371842543
268435463
2
371842543
0
899345324
84
1183
0
19
93
371842543
21
21
21
1152
371842543
780828798
268435455
71947625...

result:

ok 10000 numbers

Test #4:

score: 20
Accepted
time: 8ms
memory: 6120kb

input:

10000
100
0
0
1
3
D1
D0
B4
DD
940
C13
2C3
62A
E900
2FC1
2470
E6EE
80151
912A3
CADA5
7F6D3
0CB410
E17771
686F85
68DFEE
FABD991
150D7A2
90C8247
5B06F87
46894CE0
42575142
BC2873D5
8F1E0A9C
D26EDC921
30F8DCAA2
6ECD63697
C739CFD42
631139F800
A57ED99C72
20B0B17882
347727E7CA
E619F1E8A91
1DC6F46E610
01C38C...

output:

281603732
21
371842543
2
102
102
0
268435455
1536
17
719476259
2
2
371842543
2621443
32767
2
21
371842543
189
719476259
1035
1087
2097151
0
719476259
2
2
268435455
0
21
144
719476259
2
1023
32767
2097151
32775
719476259
371842543
0
36863
21
2097151
2
32767
268435455
2
32768
180
21
123
371842543
93
3...

result:

ok 10000 numbers

Test #5:

score: 20
Accepted
time: 8ms
memory: 4156kb

input:

10000
100
1
3
3
C
A1
A2
96
AA
9D1
A01
C16
EDD
2560
D652
0990
0630
1CCF0
6FCD0
FF216
A1AE4
733020
7287D3
E64A46
ADA8C2
AD3E2A0
02BC872
6D92D01
05C5759
33F30180
D42829D1
42734D77
01C7FE14
047CF2770
AE654B450
8C50339E5
AABDF020C
92316BB5E0
4E2EA0A9E2
3C962A0C27
9956ED19E9
458EFDCCCC0
0B1BC934520
5B83A4...

output:

281603732
21
2359295
719476259
105
0
268435455
2113543
33023
21
2
0
0
32847
2097151
405396975
21
371842543
2162687
268435455
84
371842543
105
32767
3343
268435455
371842543
719476259
0
32895
2
719476259
21
2
21
21
21
21
21
21
21
171
2621439
268959743
2113791
108
2
32767
268435487
268435463
32840
78
...

result:

ok 10000 numbers

Test #6:

score: 20
Accepted
time: 3ms
memory: 4192kb

input:

10000
100
1
3
0
7
D1
82
10
3D
E60
EE2
0B1
5A5
10C0
B543
0AD3
1390
45750
C6830
0EAB5
B2D55
FF2090
503CC2
0BB701
EB004B
3FDD210
17A52F1
44B5255
7418726
75843761
150CEF50
F20F26E6
8FBBA768
D24A5D161
AA31E8A90
373E9FE24
D32AA0A0A
F4C90F3500
6C36C6F8C3
726D14EF35
CFC549657E
10803BE30D1
4DF734243E0
FF192B...

output:

281603732
0
2375679
21
21
2097151
2098207
21
2
2097151
0
0
2
84
0
32767
268435455
2
21
2097279
1040
2
268435455
93
2097151
2097151
105
719476259
2170879
36863
268435455
371842543
268435455
719476259
719476259
102
0
371842543
2
21
1535
1025
21
371842543
2
371842543
0
371842543
21
1033
21
371842543
17...

result:

ok 10000 numbers

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #7:

score: 20
Accepted
time: 8ms
memory: 4280kb

input:

10000
300
1
0
5
7
B1
C2
26
32
DA0
243
682
E2E
D4B1
DFD3
60C3
4D66
826E1
D8511
AFC36
254F4
EC8F70
F5B480
7DEA20
06DF55
3EA08A1
C6B5463
C9B2C45
544D18E
2693C7C0
31E27182
D31059D1
BE767720
AC55C6D80
A21839A80
AE17E0DD6
772EF61A9
66EE846D51
B19BE410D0
03A8D64927
3297B9C9DC
05E209071C0
0A327E1EBE2
7C4427...

output:

713679823
719476259
189
2236927
2097151
380231151
1280
33407
21
2
404226047
268435455
2
177
13
371842543
180
268435455
418322861
120
32879
138
19
0
2098175
21
91318796
268435455
219
371842544
719476262
666809811
32775
2255
36967
21
21
32769
32783
2164735
719476259
371842543
13
2105343
462361576
2627...

result:

ok 10000 numbers

Test #8:

score: 20
Accepted
time: 8ms
memory: 4260kb

input:

10000
300
1
3
7
D
70
A0
97
D2
581
D73
FE3
ADE
BE90
2C00
0FD0
1ADD
9D7E1
85380
8D154
1C3E1
4091C1
835721
16A5A0
A579FF
3338C21
4C5BC41
B3267C0
481D2E5
C045A400
D2330C70
AA7E1366
ED783C80
5D9C8EB61
A20944E71
2F2CCB6F4
AB4C91E62
FABB51BF80
41ED063E43
C54DCF1D52
4B12739A29
9F98B9E4760
927BF482451
E8BFD2...

output:

713679823
268435459
62321207
128701157
120
123
3145743
2
371842543
33926
2
2
61146
2
268435455
1287
371842543
2
140217
719541795
1043
36863
61689
719476515
2097279
192
2143
0
780828798
0
219
162
1223
0
2603
12411540
33886
91318796
0
32767
171
0
268435455
21
2097151
21
373939695
256347164
371842547
7...

result:

ok 10000 numbers

Test #9:

score: 20
Accepted
time: 4ms
memory: 6040kb

input:

10000
300
1
3
3
A
D0
D0
76
31
710
D91
4F7
A42
F3B1
6AA2
71F0
F751
CB4B0
30362
8EB94
C1913
532281
59FF53
9C2B57
3DCF3B
BA00450
6E6FE40
76F7C50
4EE1E71
0FBA9391
D3C71DA3
2E925076
A44C773E
F02E9DFB1
DC7535EE3
90DAF35E7
784F6A354
409869FC20
9C10BEAFB1
0EE9879CC0
EE8886BEEA
CE586A8E371
08003AF5E92
FAB058...

output:

713679823
0
2655231
177
719476259
2130942
2097151
84
371842543
13
719476259
2
1107
17
21
2
786585123
268435455
93
13
69121
268435455
108
2
719476259
21
2363391
719476259
2621439
719476259
17
2
371842543
719492643
719476259
2
371842543
32767
0
49407
2
268435455
719476259
49155
339738623
40970
19
2
0
...

result:

ok 10000 numbers

Test #10:

score: 20
Accepted
time: 5ms
memory: 6116kb

input:

10000
300
1
2
0
B
A0
42
A7
C3
3B0
310
4B0
E7D
4421
9AB2
BBB2
5C0B
932B1
96EF3
12742
15A3C
CDCC71
729330
1B7FD3
5C8E8B
F431B00
C2E9C11
86FE105
2A2516D
376B4CA0
432EA5A1
A5EB6871
39A6E061
D93C4F551
C75FF9432
80CC17881
62FF560ED
DB75889331
6D4C06F682
ABDA809031
AA8BE151AF
FDA74DF05B1
9BBFF121F21
37DD84...

output:

713679823
371842543
219
123
13
268435455
1159
2047
0
2097151
2097151
78
719476259
19
719476259
78
719476259
0
32767
0
2097663
1023
2
19
21
1071
0
268435455
268435455
81
0
1151
0
719476259
268435455
268435459
0
2047
719476259
2
371842543
1055
719476259
21
49167
719476259
719476259
21
268435455
102
0
...

result:

ok 10000 numbers

Test #11:

score: 20
Accepted
time: 8ms
memory: 4256kb

input:

10000
300
0
1
2
5
21
E3
E7
86
C31
AE2
604
3AD
BD21
7532
7D50
4062
FC4C0
14321
D2F02
04FC5
930270
D2F1C3
C4B331
3E6C9D
14B2D91
D4DB863
972E643
704C878
44068510
30CC1B10
60027D91
ECF452A6
3DC3A8021
208B1B201
BE704CBC0
D7B215102
4B2067BFC0
93203D7A02
D6859EAB12
9A1DA02E88
C1256A2BBE1
7959F7570A2
03AD40...

output:

713679823
2
0
1055
21
371842543
34847
2
1039
21
21
36863
723670563
268435455
21
81
0
371842543
719476259
719476323
719476259
21
371842543
2097151
2
0
38419
21
2097153
84
371842543
268435455
2097151
1287
2099199
0
2097151
371842543
371842671
853693987
268435463
2621439
268435455
33279
21
371842543
21...

result:

ok 10000 numbers

Test #12:

score: 20
Accepted
time: 8ms
memory: 4260kb

input:

10000
300
1
3
1
D
C1
C0
81
CE
6D1
8F0
E03
DF8
9811
1062
6977
A4A8
35BD0
A8A22
896E7
AC529
E6A321
DFB152
BA0EF1
201971
22B6670
D9B2A33
5456C01
624F7BC
5D70CF31
2DF2CEE2
A281DE17
4259303C
FC2738E01
FE7D9DE22
5D66F93C4
48F91AB50
DC6EE7EC10
FF7C2E2AB0
CCE40C2874
C463A3A01F
79687341061
E63184689B1
CE3739...

output:

713679823
32768
171
1041
2
371842543
371842543
2
2097151
1047
268435455
1159
177
21
2
2097151
0
270532607
171
2105343
268435455
2
0
0
2
123
35071
719476259
120
2
1023
2097151
21
93
2097151
2097159
719476259
1023
2
719476259
1023
1537
0
2097151
268435455
268435455
0
2097151
21
371842543
2
49159
0
78
...

result:

ok 10000 numbers

Subtask #3:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #13:

score: 20
Accepted
time: 9ms
memory: 4408kb

input:

10000
500
1
0
1
D
00
52
64
DC
651
C83
3D5
81F
C280
5D02
A006
69BA
F9170
ED933
600D4
F1224
8A7760
6692B3
C724E5
A84AEE
DE9D551
BA075F0
004A075
0CB2132
200D6780
BC8227B2
E253F4C6
DE92ECBB
324EB89A0
394E85723
AD1B83763
AC28DAAE3
42480D89C1
9E82EECD13
EDCB865053
F8505D00E7
5966982D421
1369B1238A2
0C7886...

output:

731931765
464803179
0
0
167068
371842543
213
2
3657
268959875
64723
19
105
2
2170879
2
1167
49231
371843567
2
0
21
268435455
225
2
19
2528
371842543
720524835
268470271
268435455
13
793218204
371842543
276824063
2162687
1287
532608873
123
4058978
19
2
102
14443520
84
371842543
719476259
2146567
123
...

result:

ok 10000 numbers

Test #14:

score: 20
Accepted
time: 9ms
memory: 4388kb

input:

10000
500
1
1
7
E
C0
83
01
F2
430
7B1
4C2
F69
79B0
BAB0
8501
ED04
623C1
44270
28EA1
6951B
D800E1
6AAE23
3E4700
2951CF
FC6A2E1
88EC680
CB91BD0
3C1B2D7
E0506900
5E9881F1
EFCEF6B1
F43AD3AD
AFB842AD0
854FD0EF1
0605F2662
8159FD734
4A0462E631
7C8D1C73C3
25E9002DD3
F6A1C7872A
C318B9CF590
AC0AB582702
683C03...

output:

731931765
32791
371842543
961777079
0
2097151
2
0
2
2
405396975
371850735
0
17
132
0
0
13
719476771
371842543
268697599
371842543
2097151
144
2099455
84
1183
108
0
1791
2
0
719476259
168451700
1143
0
222
180
84
485458942
180
371842543
93
268505087
721606179
371842543
2
3114046
371842543
719476263
71...

result:

ok 10000 numbers

Test #15:

score: 20
Accepted
time: 10ms
memory: 6408kb

input:

10000
500
0
0
4
C
61
91
F5
72
850
1F0
1C7
198
0C50
8EC1
5703
41D7
96610
65C50
E1353
BC830
BE9C61
B56811
7DD2B7
CAA09D
32F3451
768A221
3E9FB81
87BC19E
6A1A9371
E754F460
229B4E01
BA918ED6
22F435311
9A9055D01
7BE24D815
688E46D63
2EF15F69A1
BD076C4272
8F060DFEB1
7E0E9F450C
36F83622141
4D146501601
DFC62B...

output:

731931765
719476259
2
719476259
21
32767
2
1056
268435455
102
0
21
719476259
32775
32767
0
2097215
2
0
371842543
0
1599
102
21
534739891
17
2
3718206
1671
719476259
371842543
2162687
1023
21
19
1536
2
1295
2
0
0
3685438
2
105
371842543
2361343
2098179
719476259
2
36927
268435455
32771
719476259
7194...

result:

ok 10000 numbers

Test #16:

score: 20
Accepted
time: 9ms
memory: 6028kb

input:

10000
500
1
1
6
C
70
91
43
C8
751
DB0
475
B65
02D1
11C0
DFD0
735A
BAEB1
89142
BCB77
ACE59
C2FF20
B6CAD0
39DED4
DB1867
9507A20
DB3B4D2
CCC9E84
E32626F
1230A770
44DBE282
0A852D36
D0BDC9D9
766834570
C7DB0AAE1
EE8F99502
F142EE706
90B1FEC591
8B2FF38D82
B2FC398E97
E4BBD7874F
35A957E9AC0
8E65891D891
2BD857...

output:

731931765
719476259
32831
2097151
34815
0
32767
2
2113535
276824063
268435455
2097407
719476259
268435455
0
177
0
2
2
719476259
268435455
21
2
2
2097151
0
21
33279
1025
0
2
371842543
0
21
225
268435455
1539
81
371842543
2097151
33283
0
78
1539
2101247
371842543
1543
2
1159
2
2
21
719476259
719476259...

result:

ok 10000 numbers

Test #17:

score: 20
Accepted
time: 9ms
memory: 4396kb

input:

10000
500
0
1
4
1
D1
C1
C3
8F
110
971
2F3
E54
38F0
0331
6C44
7C86
E6090
B2DF2
C4576
18921
68C3E1
29C5F0
62B6A4
396B00
96D71A0
14A9872
A1D75D2
2BBD5BA
162F2F50
2A3806A0
25E4C1D2
653257DD
0FF494901
A9C278C32
FB5AAF7E6
E9CE9172B
D332B7FBD1
936CF94A90
85ECF6BC16
9E128C7838
8CF618E4420
59778EA0A01
E68623...

output:

731931765
0
2113567
2
0
371842543
268435459
1669
371842543
719476259
33823
719476259
32771
371846639
1063
371842543
21
1280
719476259
21
0
171
719476259
2
2098183
0
2097151
32771
2
0
33151
42176
2
2097153
2097183
719476259
268435455
0
123
786585131
21
268437503
371842543
2
2
1023
0
2
2
1608
2424895
...

result:

ok 10000 numbers

Test #18:

score: 20
Accepted
time: 9ms
memory: 4352kb

input:

10000
500
1
3
7
7
C0
23
F3
C1
B71
A63
713
AE0
CC11
ADA1
D524
D9D4
8CC31
0F420
69C50
99AE4
9E3BB0
0F4703
A500E5
E9E696
FDD5900
08F3913
FF7EEA6
9A94F58
D6D968D1
E9908093
8E0616A4
B6630A50
4B55F67A1
38DF7BC12
22F514233
DEB02DCC7
794208B8F0
AD3469EB32
F3A8349666
E43B434544
16FBC8DF851
62F0A44AE53
C83474...

output:

731931765
40959
371842543
1056
21
93
2097155
1159
0
2097151
0
2
2097151
108
2097151
32767
1287
1279
0
81
32767
2
719476259
0
32767
719476259
32783
2097151
177
1155
268435455
1071
2
2097151
371842543
0
268435455
21
0
2
2
120
21
2
32767
32767
2097155
2051
719476259
32767
371842543
144
371842543
2
2097...

result:

ok 10000 numbers

Subtask #4:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #19:

score: 20
Accepted
time: 24ms
memory: 5032kb

input:

10000
1500
0
2
7
2
C1
A1
62
45
601
472
201
5D0
5800
1861
4171
2EC4
A14C0
553B3
8E644
8268A
D29BB1
961990
10ECB1
16F48F
F152360
55711D3
B9B4643
50FAFC0
A7D5EA10
7BE77013
C1907CC7
FD610245
690ACF6F0
963E3E152
7DDADE887
4037FD164
3FFB819E11
6A08950852
3968246D26
19A75C9E9D
401FBCA3380
88072D9D331
9B877...

output:

549008470
2658
2
2101247
17
372891119
87243
63584
34935
2
2535
371842543
3407875
719476259
114083515
371842543
2
719476259
1040
0
1296
40960
2
21
372366831
13
138
33279
268435455
0
34818
270540799
13
285736959
2097663
371842543
268435455
719476259
2
987911715
371842543
19
2
2
1536
78
4127601
3019898...

result:

ok 10000 numbers

Test #20:

score: 20
Accepted
time: 24ms
memory: 5028kb

input:

10000
1500
0
1
4
A
10
21
47
EB
0D0
261
855
A7E
DE61
9892
CCF2
3C4B
7EA30
C4981
E05B0
4DEEA
1E2431
F11551
31C513
5C53F4
6A6E530
49369F1
80465C7
94F3E7B
B29E07A1
7EEB6D63
886F6744
63C9BE03
4F823BBA1
C7B85FB51
97DBFE796
57477CC69
FE45562E20
9BBBECB292
D8885AB9D6
F368CE90B7
00EADC95511
EE2091D6E21
D7828...

output:

549008470
719476259
2523
3145727
719476259
2
1057
2
1031
2
268697599
2
268435455
32775
0
0
1131
3167
2097151
213
371842543
0
40960
2174975
2
0
371842543
32831
120
2051
2099201
2097151
268435455
189
719476259
3638526
2
2
13
32767
17
2
219
719476259
987911730
719739427
1567
19
371842543
2
302055423
26...

result:

ok 10000 numbers

Test #21:

score: 20
Accepted
time: 24ms
memory: 4988kb

input:

10000
1500
0
1
4
0
90
81
22
51
5D1
151
8F7
F6D
3AE1
34D2
3777
F794
CB431
BE642
A8656
0B319
0BE810
117F60
476595
D6C926
352E470
6C46D43
72551C3
B7FE5EC
685C5740
64C90912
E25F5907
4F55EF30
5D23DEA50
BDC93D8C3
6EBAE70F6
5645B7BB8
8440CCB451
CAE50BA323
2071F3FA45
4261AD9359
39F45EB09E0
C6C50DD7631
5A30C...

output:

549008470
21
2
276824063
32767
41099
719476259
21
108
268435455
79214382
33087
3276799
32895
345505791
371842543
1023
0
719476259
2
2
49943
2
41087
899345324
2097167
719476291
2
0
0
719476259
1296
2097151
719476259
2113535
21
4227071
33024
268435455
36927
721573411
2
719476259
719476259
268566527
17...

result:

ok 10000 numbers

Test #22:

score: 20
Accepted
time: 21ms
memory: 5032kb

input:

10000
1500
1
3
2
7
21
A2
E2
83
DE0
793
350
18C
03A1
D4A3
C3F6
CA22
525B1
54462
9A023
78BD1
1E9121
18E0E3
B363F5
B393D1
049C071
0F65A43
6C7B164
6E8847E
667698E0
53D5E331
5B9BCF45
1C76E5E1
477D648B0
D0F83C632
42F6E86C3
95A66E961
13354D0EB1
7868C56F01
BBBFD1B7B6
FA1EC7B244
6A06B08A850
15B66062650
B092C...

output:

549008470
719476259
268435455
1791
32767
32767
268435455
268435455
21
21
21
2
371842543
2097151
177
1056
371842543
719476259
0
1023
371842543
268468223
1023
2
34815
123
105
2097151
13
268435455
371842543
719476259
32768
21
371842543
32895
108
21
13
102
49663
371842543
371842543
268435455
13
2097151
...

result:

ok 10000 numbers

Test #23:

score: 20
Accepted
time: 25ms
memory: 6900kb

input:

10000
1500
0
1
3
9
10
12
B4
F6
4C0
DC0
525
2F4
00A1
8873
F857
C66E
ACCF0
CD283
95305
A5D30
3A74D1
9F9E62
4C3AB3
AC746F
CB67380
F16EAF2
C69E9A2
1813EF8
51490E61
832FAAF2
8298BEB4
3AAA8572
F754C4950
BD5F5E0F1
15AF2DC11
242BF7AC2
2938614071
AF6FD578D2
F03F3319A4
82A98BCB3B
20E3EF127B0
DA508FAD662
B02D2...

output:

549008470
0
268435455
276856831
1535
21
21
35071
21
719476259
268435455
371842559
2097151
268435455
2
33791
21
102
1535
268566527
371842543
2097151
719476259
0
2111487
21
1280
2
1103
2
0
2
35071
36863
2
2097151
1536
32771
32911
719476259
1280
719476323
371842543
2097151
371842543
309410788
108
2
102...

result:

ok 10000 numbers

Test #24:

score: 20
Accepted
time: 21ms
memory: 5052kb

input:

10000
1500
0
1
7
E
10
E2
F4
99
2C0
D71
B92
149
0BB1
6162
10E2
4C1D
47961
39A01
4FFD4
09D69
61A861
61B6B0
505947
DBFD93
53B7620
6C30FA0
DCFB9E5
9B86A39
41D0D7C0
6C020F13
7E59E182
8A7A3494
20BDFF681
9A228F3D0
FE6B41125
A33D8F4F6
97C90B1010
6612603071
C664B7CA92
97015D285E
456A12761F1
8B8A62147A2
6C72D...

output:

549008470
32767
2097151
1039
2
268435455
719476259
2097151
2
268435455
0
1163
32767
0
21
32771
1041
371842543
32767
120
81
1675
50687
371842543
2
2
123
33279
268435455
719476259
719476259
21
108
1159
268435455
21
34815
0
0
2
268435455
2
0
2097151
21
268435455
33288
0
2
371842543
2
2
21
0
268435455
0...

result:

ok 10000 numbers

Subtask #5:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #25:

score: 20
Accepted
time: 180ms
memory: 7252kb

input:

10000
5000
1
3
5
C
D1
80
C7
E6
E81
400
AA7
FCC
9510
FCE2
D072
E615
84031
12D30
878C0
23743
8B99A0
FB6DA1
193577
8D1931
0243E30
771F392
55D4052
3B02514
426923C0
4287A023
0668BB35
16EFDA36
CE23DEC41
0340A12D2
F80B66D30
CEA7DEBC9
F3E5720CE1
C1F56C5721
55502C6CB2
1CC0E410F1
4A5DE99D560
307DF19CA10
545E8...

output:

415719582
1035
17
2
371842543
108
105
32847
1667
268509183
373939695
189
721573411
1891
371842543
435100077
0
0
445584360
64905
371842543
2
2098175
0
371842543
371842543
32775
0
81
1120
371842543
32767
3244031
4129496
56383
0
138
40959
0
123
105
1865
371842543
3145759
64578
21
268582915
33279
1031
1...

result:

ok 10000 numbers

Test #26:

score: 20
Accepted
time: 175ms
memory: 7188kb

input:

10000
5000
0
1
2
1
41
21
A7
ED
FE0
E41
2B7
C48
1F00
E592
9F73
A737
1D470
941D0
4F133
C020F
1F9750
970582
F9E052
218DEF
73C9A20
1CF96E1
5B5A801
59994C7
A7BC3E40
CE0403B0
4C060E26
664B7CA9
AC388A610
693599680
761F17155
940DDA6C7
2D9F2B2E01
42D79C8212
637C451AF5
102E783580
41670617D30
E64C9A477A2
4BD1E...

output:

415719582
0
285218047
84
2193
268435455
21
1551
371842543
301990271
17
21
268435455
268435583
17
4609
1535
0
2
268435455
268443647
371842543
2
958278690
71384
371842543
2
36879
734986162
2
21
504170258
2359295
4255576
268435519
2
502807618
1088
371842543
3670047
719476259
0
2
0
2
21
219
812876148
71...

result:

ok 10000 numbers

Test #27:

score: 20
Accepted
time: 171ms
memory: 7252kb

input:

10000
5000
1
1
2
9
30
52
A1
26
871
433
515
BAD
CCA1
3CF1
D735
58AB
974E0
AA071
678E7
C5117
22B1A1
5E7C01
22A147
9655E0
3EC2F90
4EDDB43
29FECF2
D77EE3B
BB8D7FC0
91D2CE82
08D47493
BFD33310
6190258B0
1820DEAD1
8A757B946
188AFC15C
6554FA5220
D06DBFDC33
546B8168C4
AE6D652ABB
995D731F840
EE16EDCF2E3
08839...

output:

415719582
719476259
2097155
2097155
0
0
2
719476259
1407
1023
2097151
1599
2339
17
0
93
32771
21
2113535
371842543
0
1029
2
2097215
0
2097153
2097291
2098687
0
177
268435967
32767
81
0
102
2359313
0
21
719476259
21
438951407
19
41223
719476259
2097151
2
268435455
268435519
371842543
2
0
36931
33791
...

result:

ok 10000 numbers

Test #28:

score: 20
Accepted
time: 174ms
memory: 7244kb

input:

10000
5000
1
0
6
D
E1
A3
22
F5
891
DE3
BD5
C44
12E1
B461
BBD2
301B
A6941
3A9F0
FC265
0B409
F61441
C31A53
465AA6
710812
9F82B91
7A25F01
FDBEA72
51B00FA
5D8E4E31
C7B3E1C0
E6B664D0
67C0174D
F5F85CA31
798223E30
B9E5C2BF3
216858762
AF900B9310
974D8D1122
A912A336F6
EDACF80F2D
0F89BBC2DE1
8D5CE77D3D1
B7375...

output:

415719582
719476259
189
40959
371842543
2
268435455
0
2
120
371842543
268435455
268435455
2
2097151
0
719476259
371842543
32775
371842543
2
17
0
21
1425
105
0
1029
371842543
32767
371842543
34815
2113535
1169
719476259
371842543
1087
21
2097151
268435455
21
371842543
371842543
719476259
0
719476259
...

result:

ok 10000 numbers

Test #29:

score: 20
Accepted
time: 177ms
memory: 7252kb

input:

10000
5000
0
3
4
7
A1
22
81
35
4D0
0F1
F12
14E
2B70
4BB3
E774
DB5F
B6831
F6580
23503
B28A8
52A6D0
606261
1B0924
17D2F6
59FA491
D18B522
3AE8381
EF00C38
CFA5AA81
3AD15322
D469F4C4
60F78B9E
BC29ADCE1
06D9F3E71
490E49F02
298A80F8B
E3C5DC55A0
AAE9191D61
27D2A9D691
5EC6542352
8EF6C7C0E00
278175422A2
3FC6D...

output:

415719582
105
268435487
1311
32779
2
371842543
21
21
899345324
2097167
171
0
371842543
719476259
21
0
81
268697599
21
21
371842543
719476259
719476259
177
81
2
371842543
268435455
32835
2
371842543
1615
102
0
371842543
2048
719476259
719476259
81
32771
2097151
720524835
32768
3145727
268468239
171
2...

result:

ok 10000 numbers

Test #30:

score: 20
Accepted
time: 175ms
memory: 7228kb

input:

10000
5000
0
1
4
2
61
32
D6
F0
3C1
573
9E2
C51
C1E0
4881
25C0
810A
63C80
0E642
0FB86
FDB2F
EB74F1
555B53
6B3171
F8B4F5
05DFF51
055F433
0863290
33F22A5
657ABF01
8A76A9F0
0F5AC000
0EF0A9FC
B48EA13A0
3ADD86982
796952C56
7326DC494
5E920432E1
E7CA3B99B2
CCF8B50FC0
305DAE181D
3AE9F9E6211
7477AC746F0
FADD0...

output:

415719582
371842543
2097155
719476259
2097151
268435455
0
1023
21
21
268435455
1539
120
2097151
0
2047
32767
2
49151
0
1536
2047
21
1035
0
0
0
2
371842543
21
719476259
268435455
268435455
32767
371842543
268435455
719476259
177
32783
268435455
2097151
2571
719476259
2
719476259
371842543
0
268435455...

result:

ok 10000 numbers