QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625231#8759. 小班课ucup-team3475#AC ✓33ms10356kbC++204.7kb2024-10-09 18:03:332024-10-09 18:03:33

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5 5
1 1 1 1 1
4 1 3 2 4
1 5
4 3 4 2 1
2 3 5
1 1
5 3
1 2 2
2 1 2
2 1 2
2 1 3
2 1 3
2 1 3
5 5
1 1 1 1 1
2 1 2
2 5 4
2 3 2
2 4 3
2 5 1

output:

5
2 4 5 1 3 
5
3 1 2 4 5 
5
1 5 2 4 3 

result:

ok Correct!

Test #2:

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

input:

250
2 1
2
1 1
1 1
1 1
1
0
2 2
1 1
1 1
2 2 1
2 2
0 2
2 1 2
1 2
1 1
1
1 1
1 2
1 0
0
1 2
1 0
0
2 1
2
1 1
0
1 2
1 0
0
2 1
2
1 1
1 1
1 1
1
1 1
1 2
1 0
1 2
2 2
2 0
1 1
1 2
1 1
1
0
1 1
1
0
1 2
0 1
1 1
2 2
1 1
1 1
2 1 2
2 2
1 1
2 2 1
2 2 1
1 2
0 1
1 2
2 1
2
1 1
0
2 2
2 0
1 1
1 2
1 1
1
1 1
2 1
2
0
1 1
1 1
1
...

output:

2
1 2 
0
1 
2
1 2 
2
2 1 
1
1 
0
1 
0
1 
1
1 2 
0
1 
2
1 2 
1
1 
0
1 
1
1 2 
0
1 
0
1 
0
1 
2
1 2 
2
1 2 
1
1 
1
1 2 
1
1 2 
1
1 
1
2 1 
1
1 
1
2 1 
0
1 2 
1
1 
1
1 
0
1 
1
1 
2
1 2 
0
1 
0
1 
1
1 2 
2
2 1 
0
1 
0
1 
0
1 
0
1 2 
2
1 2 
1
1 
1
1 
0
1 
0
1 
0
1 
1
1 
1
1 
0
1 
2
1 2 
2
1 2 
1
2 1 
1
1...

result:

ok Correct!

Test #3:

score: 0
Accepted
time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0 0 0 1 2 4 1 2 1 2 3
7 1 37 21 3 13 43 22
0
10 23 46 22 40 12 19 47 27 16 42
4 29 19 45 35
10 6 26 2 43 41 7 9 16 42 44
5 39 40 34 46 14
3 34 3 38
8 10 5 38 23 19 37 9 34
0
5 31 29 15 13 35
3 40 4 28
1 7
6 29 12 9 35 2...

output:

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

result:

ok Correct!

Test #7:

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

input:

1
499 497
1 2 0 2 0 1 0 0 0 2 1 2 0 3 1 2 0 0 0 1 0 1 0 2 1 0 1 0 1 1 1 2 0 1 0 1 0 2 2 3 1 1 2 1 0 0 1 0 2 3 0 1 0 0 2 0 1 2 1 0 0 1 2 0 0 2 0 2 0 1 0 1 0 0 1 0 0 1 1 1 1 1 0 0 0 1 2 3 0 0 0 4 2 2 1 2 2 0 1 0 1 0 2 0 1 0 2 0 0 1 1 1 3 2 0 2 2 2 0 1 1 1 1 1 0 1 0 1 1 1 1 1 2 0 0 1 0 2 1 2 1 2 1 0 1 ...

output:

482
234 31 95 124 126 142 153 167 190 268 347 346 318 401 359 412 410 273 344 27 496 125 353 291 159 324 433 372 67 247 75 329 294 377 287 116 155 53 312 393 222 367 244 38 17 290 10 321 342 52 136 37 485 482 307 492 171 189 143 115 197 491 32 446 345 250 480 383 409 79 462 471 308 46 5 8 92 449 150...

result:

ok Correct!

Test #8:

score: 0
Accepted
time: 33ms
memory: 10356kb

input:

1
498 499
0 1 1 0 1 0 1 0 0 0 0 2 0 3 1 2 4 0 1 0 1 1 0 0 0 1 1 0 0 2 2 0 1 1 1 0 4 1 1 2 1 0 0 1 2 0 1 2 1 0 1 2 0 2 1 2 2 0 2 2 0 1 0 2 0 0 3 0 1 1 1 1 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 2 1 1 0 1 0 1 0 0 0 1 1 2 0 1 0 2 1 1 2 2 0 0 0 0 2 0 2 1 0 1 0 2 0 1 3 1 1 1 0 1 3 0 1 0 1 0 0 1 3 2 3 2 1 1 0 2 ...

output:

498
67 128 167 232 334 427 206 184 183 388 268 94 162 491 156 496 12 320 145 394 140 406 359 299 336 249 430 192 294 428 440 341 266 382 127 1 22 240 91 393 357 410 455 63 271 204 195 80 118 202 381 87 178 473 416 33 360 220 302 42 437 470 55 21 252 2 148 226 14 45 397 431 99 433 258 136 60 39 43 47...

result:

ok Correct!

Test #9:

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

input:

5
99 96
2 0 0 1 1 2 1 0 1 1 1 0 0 0 1 0 1 1 2 1 1 1 1 1 0 1 2 4 0 0 0 2 2 1 1 1 1 1 0 2 0 0 0 1 1 3 0 1 0 0 1 2 1 4 1 2 1 0 1 0 0 2 0 0 0 2 3 2 1 0 1 2 2 0 1 1 0 0 1 0 0 1 2 1 3 1 3 1 3 0 3 0 0 2 2 2
2 14 58
1 55
2 53 69
0
0
1 76
2 23 38
1 41
2 74 54
0
0
2 83 91
0
0
0
1 48
0
0
1 96
2 76 52
1 17
2 51...

output:

48
71 30 34 35 38 39 40 45 46 57 60 62 65 69 2 72 73 74 77 82 87 88 93 94 95 97 99 19 3 26 6 7 22 16 42 56 9 53 59 78 20 44 23 24 92 66 67 12 75 86 76 10 79 80 11 13 81 83 84 85 64 8 89 90 91 5 4 96 98 1 50 29 27 31 32 33 25 36 37 41 43 21 47 48 49 14 51 52 54 55 58 18 61 17 63 28 68 15 70 
44
73 91...

result:

ok Correct!

Test #10:

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

input:

5
99 97
0 2 4 0 0 2 0 1 1 1 0 1 0 3 0 1 1 1 1 0 0 1 0 0 1 2 0 0 1 3 1 2 0 2 1 1 1 3 3 1 2 1 0 1 0 1 0 2 0 0 0 0 1 2 3 1 1 1 0 1 0 1 0 0 1 2 1 2 1 1 1 2 2 3 1 1 0 0 1 1 0 0 1 1 2 1 2 2 0 1 1 1 2 0 1 3 1
2 56 63
2 52 45
4 26 56 80 10
2 27 19
1 81
2 38 64
1 83
1 8
3 14 81 60
3 63 28 15
5 59 33 80 88 56...

output:

72
63 1 49 48 46 87 40 39 58 33 91 30 29 25 23 22 14 83 9 12 8 7 70 6 97 77 53 34 85 42 41 47 81 60 68 16 94 65 71 27 73 24 79 82 64 37 54 18 62 55 57 78 35 3 72 17 95 59 32 99 96 98 66 45 44 28 11 13 90 20 52 76 84 93 92 86 89 88 50 36 2 4 5 10 15 19 21 26 31 80 38 43 51 56 61 67 69 74 75 
67
72 33...

result:

ok Correct!

Test #11:

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

input:

5
99 98
4 0 1 1 3 2 0 1 4 0 1 1 2 2 1 2 0 0 1 2 1 2 0 1 1 1 2 0 2 0 0 3 0 2 0 0 1 1 1 0 1 1 1 2 0 1 1 0 1 1 1 0 0 1 0 0 2 1 2 3 3 0 0 0 0 0 1 2 1 1 0 3 0 0 0 1 2 0 0 0 0 1 0 2 2 1 2 1 0 1 0 0 1 1 2 3 3 0
5 72 78 90 7 60
6 69 37 10 41 4 59
10 61 85 79 5 7 58 3 55 1 50
6 59 24 30 26 77 21
2 29 21
10 7...

output:

85
71 63 24 29 30 89 70 83 8 79 5 55 72 59 84 20 42 40 53 90 51 74 68 58 97 98 47 41 94 95 69 6 14 62 33 28 44 11 46 16 10 85 80 82 75 2 86 26 32 4 96 31 34 35 73 78 54 77 93 76 21 91 87 38 67 12 37 60 27 25 66 65 64 23 19 15 1 49 99 57 81 50 43 3 39 45 36 48 88 52 22 92 18 17 56 13 9 7 61 
87
24 46...

result:

ok Correct!

Test #12:

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

input:

5
97 100
1 1 1 0 0 1 0 1 1 2 0 1 2 0 1 0 2 3 0 1 0 1 0 1 0 0 1 0 1 2 0 3 2 2 1 0 1 1 2 3 3 1 0 2 1 1 1 2 2 2 0 2 0 3 1 2 2 2 0 1 0 1 1 0 2 0 0 0 0 3 1 0 0 1 0 1 1 0 0 1 1 2 1 2 0 0 1 2 0 1 1 0 2 0 0 1 0 0 2 2
48 80 1 66 89 71 73 40 2 50 99 68 91 31 76 25 67 94 37 6 88 86 28 22 43 62 21 16 17 39 70 1...

output:

94
25 19 16 23 79 9 4 24 48 64 2 3 86 15 78 39 72 37 85 40 8 73 30 13 27 5 70 22 47 59 77 17 33 82 7 62 11 38 28 1 88 96 42 18 89 21 53 52 44 51 36 74 45 75 6 84 50 71 57 10 97 54 29 90 65 83 67 43 34 20 63 55 49 31 80 93 56 61 87 12 60 94 32 14 26 58 35 69 91 81 92 76 41 66 68 46 95 
94
15 90 72 25...

result:

ok Correct!

Test #13:

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

input:

5
96 96
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 72 44
0
0
1 75
0
2 48 35
1 29
1 55
2 75 32
1 95
0
2 87 85
1 69
1 6
2 48 6
1 77
1 67
0
0
1 75
2 59 ...

output:

59
65 31 32 35 36 39 41 48 51 56 58 59 60 61 64 49 67 70 71 73 74 75 80 81 82 83 86 88 89 96 29 8 12 13 15 16 17 20 23 24 25 90 27 62 6 9 85 91 21 79 78 87 55 68 34 47 46 45 44 10 77 76 69 30 7 84 5 4 3 92 93 94 95 2 57 42 43 40 1 50 26 52 53 54 22 11 38 19 18 63 37 66 28 14 72 33 
54
32 21 23 49 25...

result:

ok Correct!

Test #14:

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

input:

1
499 497
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

287
261 286 280 278 277 272 270 264 263 287 260 258 254 252 246 244 243 238 317 341 339 335 330 328 327 323 321 235 312 311 309 305 300 294 292 288 167 187 186 183 178 176 174 170 169 191 162 159 154 152 150 147 146 145 216 234 233 229 228 227 225 223 222 343 211 210 209 207 201 198 197 192 442 453 ...

result:

ok Correct!

Test #15:

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

input:

10
50 49
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 43
0
0
2 25 28
0
0
2 28 14
0
2 8 38
1 1
0
1 6
1 41
0
2 40 47
2 8 34
2 26 41
2 31 28
1 5
0
2 33 45
0
2 14 43
0
2 39 34
1 32
1 6
1 15
1 17
0
0
2 9 6
2 37 1
0
2 13 20
0
2 4 41
2 31 5
0
2 44 14
1...

output:

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

result:

ok Correct!

Test #16:

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

input:

10
50 49
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 32
0
0
2 47 41
1 10
3 33 18 13
1 43
1 49
1 39
0
0
3 16 27 31
0
0
2 30 25
3 23 16 37
3 18 1 46
2 8 9
3 32 33 10
3 24 14 31
3 31 11 2
2 8 36
1 44
1 9
0
2 39 27
1 14
1 6
3 47 12 10
1 14
1 10
0
1...

output:

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

result:

ok Correct!

Test #17:

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

input:

1
495 495
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

344
379 384 171 173 174 383 382 178 179 180 181 182 381 184 168 187 190 191 192 377 198 372 204 205 371 369 368 210 136 113 114 116 406 120 404 122 123 403 127 129 132 133 212 394 392 391 144 145 146 148 387 156 158 386 161 385 330 260 261 340 263 266 268 270 271 272 338 274 277 331 342 283 288 289 ...

result:

ok Correct!

Test #18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2 1 2
0
3 1 2 3
0
5 5
0 0 1 2 2
3 1 2 3
3 1 2 3
3 1 2 3
0
3 2 3 4
5 5
0 2 1 2 0
1 1
2 1 2
3 1 2 3
1 1
2 1 2
5 5
0 0 0 0 5
0
0
0
0
3 1 2 3
5 5
1 0 0 2 2
1 1
3 1 2 3
2 1 2
3 1 2 3
3 1 2 3
5 5
0 0 1 2 2
3 1 2 3
0
0
2 1 2
1 1
5 5
0 2 0 ...

output:

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

result:

ok Correct!

Test #22:

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

input:

10
49 49
0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 0 0 1 2 0 2 2 1 1 0 0 2 3 1 2 1 1 1 2 2 0 1 0 1 0 2 2 0 0 4 1 3 3 3
5 3 10 12 16 18
5 2 16 36 21 39
9 19 23 5 31 32 12 15 34 40
0
5 5 19 21 24 30
3 6 8 16
6 15 17 26 2 14 7
1 3
2 14 15
3 16 21 23
6 3 4 17 19 21 22
1 7
7 2 11 28 10 13 31 6
0
6 13 33 43 47 14 1
4...

output:

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

result:

ok Correct!

Test #23:

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

input:

1
498 500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 2 1 0 1 0 0 2 0 1 0 0 1 1 0 0 0 0 0 2 0 0 1 0 1 0 0 0 0 0 2 1 2 0 1 0 0 1 1 0 1 ...

output:

464
162 342 60 400 296 78 483 112 325 27 372 465 218 378 189 19 33 46 42 310 429 67 54 118 190 298 191 362 267 271 129 149 171 109 235 197 179 496 230 330 299 421 43 338 153 288 24 136 107 233 412 316 100 198 304 14 254 473 431 486 275 353 433 188 409 119 185 459 461 398 144 488 408 439 145 62 135 4...

result:

ok Correct!

Test #24:

score: 0
Accepted
time: 17ms
memory: 7188kb

input:

1
497 496
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 0 1 0 1 0 2 1 0 0 0 0 0 0 0 1 1 0 1 0 1 2 1 2 0 1 0 0 1 2 0 1 1 1 0 0 0 0 2 1 1 1 0 0 1 ...

output:

496
39 199 318 480 236 340 168 400 493 105 442 391 479 468 7 322 91 45 262 320 76 336 239 395 448 154 420 290 141 148 266 319 494 213 352 483 15 349 166 111 482 371 421 309 463 194 331 380 369 381 430 384 30 156 263 343 62 466 473 485 159 272 42 144 382 115 339 23 109 470 460 346 282 238 375 364 347...

result:

ok Correct!

Test #25:

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

input:

5
100 100
0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 1 1 2 0 1 0 0 1 1 1 1 0 2 1 0 0 1 2 1 0 1 1 1 1 0 1 1 2 5 1 0 1 2 0 2 0 3 1 1 1 2 3 2 1 1 1 2 4 2 1 4 1 2 1 0 3 3 1 3 0 0 3 1 0 0 0 3 4 2
1 35
0
1 8
1 35
0
0
1 10
2 15 19
2 1 3
2 6 61
0
0
0
0
2 14 20
2 4 80
0
0
0
1 6
0
1 13
1 4
...

output:

19
83 84 98 57 66 7 59 92 48 39 43 79 27 16 37 76 10 54 73 69 70 71 64 68 67 65 78 63 62 61 60 58 56 88 100 99 97 96 95 94 93 91 90 89 72 87 86 85 82 81 80 51 77 75 74 14 26 25 24 23 22 21 20 19 18 17 15 28 13 12 11 9 8 6 5 4 3 2 41 53 52 1 50 49 47 46 45 44 42 55 40 38 36 35 34 33 32 31 30 29 
26
7...

result:

ok Correct!

Test #26:

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

input:

5
95 99
0 0 1 0 0 0 0 0 1 1 0 0 0 2 1 0 0 0 1 0 1 0 0 0 1 2 0 0 1 1 2 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 1 1 2 2 0 0 0 1 0 1 1 1 4 3 0 3 1 2 1 0 1 0 1 5 0 1 1 0 3 0 3 1 2 2 4 0 0 0 1 1 1 2 3 1 0 2 4 0 1 1 4 3
0
1 5
3 31 50 70
1 21
5 14 26 31 2 6
5 7 41 19 45 30
3 1 6 40
0
2 16 19
4 5 6 9 25
0
0
5 17 47...

output:

41
59 78 83 17 44 88 92 54 15 38 70 19 75 93 42 63 3 84 72 5 45 47 30 28 36 79 41 66 65 57 90 62 51 89 87 81 85 82 43 73 13 91 86 61 94 60 95 48 64 67 68 80 69 77 76 71 74 12 25 24 23 22 21 20 18 16 14 26 11 10 9 8 7 6 4 2 39 56 55 53 52 50 49 1 46 40 58 37 35 34 33 32 31 29 27 
37
95 93 5 66 91 19 ...

result:

ok Correct!

Test #27:

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

input:

5
97 97
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 1 0 0 1 1 2 0 0 1 2 1 0 0 1 2 2 1 0 2 0 1 0 0 3 0 2 3 0 2 1 1 1 1 0 1 1 2 4 1 0 2 1 0 1 2 1 2 2 2 1 2 5 2 0 1 0 3 1 3 1 0 1 2 0 0 2 4 2 2 1 2 1 3 0
0
5 14 16 33 41 9
7 12 28 16 32 45 46 71
10 15 63 65 17 66 18 81 45 8 68
6 8 35 12 54 21 63
0
0
0
...

output:

67
86 14 66 73 80 82 63 59 49 85 41 72 77 70 83 57 2 16 29 26 5 38 94 65 92 25 21 95 91 89 54 42 87 48 78 75 67 10 81 51 4 71 22 56 97 96 58 69 55 31 93 47 24 53 23 45 3 36 64 62 19 20 34 60 27 50 84 17 9 79 30 18 28 1 90 88 61 43 44 46 15 52 40 39 37 13 12 6 11 35 68 33 8 7 74 32 76 
62
97 71 84 35...

result:

ok Correct!

Test #28:

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

input:

5
95 95
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 0 0 1 1 0 1 0 1 1 1 0 0 2 1 0 0 1 1 0 0 1 0 1 0 0 3 0 2 1 1 5 0 0 0 4 3 0 2 1 0 3 2 2 1 2 1 6 1 3 4 2 1 2 2 3 0 2 0 2 1 1 2 2 1 0 2 1 0 0 1 2 3
16 2 9 23 36 52 58 31 65 66 71 72 17 75 24 44 27
28 4 2 32 38 45 21 52 61 94 55 46 79 92 1 11 65 73 95...

output:

89
3 71 35 93 9 7 72 54 67 1 31 59 18 45 15 74 88 79 77 80 28 33 57 29 22 25 40 26 89 82 48 42 27 94 73 75 55 53 23 85 30 39 11 46 47 68 49 83 65 36 95 32 91 78 58 34 86 84 50 61 10 66 4 76 14 63 41 20 2 16 17 44 19 92 51 37 56 13 87 60 81 52 38 21 64 69 6 70 43 8 62 90 12 24 5 
89
56 7 5 71 42 58 9...

result:

ok Correct!

Test #29:

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

input:

1
498 500
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 2 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 1 1 2 0 0 1 0 0 0 0 0 1 0 0 2 0 1 1 1 0 0 1 0 2 0 0 1 1 0 0 2 0 0 0 0 0 3 1 0 2 0 1 3 0 0 0 ...

output:

108
462 255 86 369 471 149 469 231 298 432 464 438 29 440 459 288 457 365 243 60 54 187 58 401 128 497 125 137 407 99 374 307 443 294 144 192 384 448 470 445 323 133 237 392 319 394 395 330 317 199 437 416 250 14 210 405 429 409 329 228 427 450 348 493 260 12 481 251 479 360 472 468 361 461 291 186 ...

result:

ok Correct!

Test #30:

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

input:

1
500 498
2 0 0 1 1 1 0 0 0 0 1 1 2 2 2 0 1 0 0 0 1 1 1 0 1 1 2 2 2 1 1 0 4 3 1 1 1 1 0 3 0 3 3 1 2 1 0 2 3 2 0 2 0 0 0 1 1 1 0 2 4 1 0 1 1 1 1 3 1 0 0 1 1 2 2 4 1 1 1 0 0 2 2 1 2 1 1 1 0 0 2 0 0 1 0 0 1 1 1 1 0 1 0 0 1 2 1 1 1 2 2 4 2 0 0 0 0 1 1 0 1 4 1 3 0 2 0 3 0 1 1 1 0 4 0 1 1 3 2 0 0 1 0 1 1 ...

output:

258
500 467 375 252 304 259 301 477 331 295 348 489 286 323 490 354 389 333 346 361 430 334 433 459 353 378 422 387 209 442 306 288 403 230 246 242 191 479 435 270 289 263 235 466 481 269 285 474 256 291 294 281 411 426 445 352 408 241 313 311 347 260 391 473 273 296 383 441 468 326 211 395 240 491 ...

result:

ok Correct!

Test #31:

score: 0
Accepted
time: 16ms
memory: 7216kb

input:

1
496 498
0 0 0 0 2 0 0 1 0 1 1 0 2 3 1 1 2 0 3 2 2 0 2 1 2 0 1 1 1 0 1 2 0 0 0 0 5 1 1 0 2 1 0 0 1 0 0 2 0 3 0 0 3 1 0 3 0 1 1 2 1 2 0 2 0 2 1 0 3 0 1 0 1 1 2 0 1 0 0 1 2 1 2 0 1 0 1 1 1 0 3 3 3 2 0 1 2 1 1 3 1 1 0 0 3 0 1 0 0 0 0 1 3 1 0 1 1 2 1 0 1 2 0 2 0 1 1 1 2 2 0 0 1 2 1 1 1 2 1 3 1 1 1 0 0 ...

output:

248
335 320 450 304 466 331 468 460 467 411 368 323 263 253 420 275 309 379 394 293 434 414 252 251 406 372 405 490 312 365 489 419 249 492 313 396 339 384 393 496 389 398 410 260 326 300 380 431 493 397 282 311 473 354 476 310 440 426 375 390 386 288 417 443 425 401 355 328 271 319 407 429 303 424 ...

result:

ok Correct!

Test #32:

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

input:

10
49 50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
0
0
1 4
0
1 7
2 8 7
2 9 8
0
1 10
1 12
2 13 12
0
0
1 16
2 16 17
0
1 19
0
1 20
1 21
1 23
2 24 23
2 25 24
1 26
1 27
1 27
1 28
0
2 31 30
1 32
0
1 33
1 34
2 35 36
1 37
2 38 37
1 38
1 40
2 41 4...

output:

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

result:

ok Correct!

Test #33:

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

input:

5
99 99
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 2
0
0
2 5 4
1 5
1 7
0
1 9
1 10
0
2 12 11
1 12
1 14
1 14
2 15 16
1 17
0
1 19
1 19
1 21
2 21 2...

output:

60
70 33 34 38 40 43 44 45 1 51 55 56 58 60 62 67 50 71 73 75 76 77 81 84 87 91 93 94 95 96 97 99 26 22 23 21 19 25 16 27 14 12 9 8 6 5 11 85 32 31 15 69 68 88 66 57 4 53 41 36 80 2 82 83 10 29 86 39 30 89 90 37 92 7 35 3 98 54 48 59 20 61 52 63 64 65 24 18 49 79 17 47 72 46 74 28 13 42 78 
63
42 28...

result:

ok Correct!

Test #34:

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

input:

1
496 500
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

325
268 286 283 282 280 276 274 273 270 269 289 267 264 256 247 246 245 243 242 241 305 322 321 319 318 317 312 310 309 307 233 303 299 297 296 295 293 292 291 179 195 192 191 190 188 186 183 181 180 197 176 173 171 170 168 165 159 155 218 232 231 230 227 226 225 224 222 220 324 215 209 207 206 202 ...

result:

ok Correct!

Test #35:

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

input:

10
46 47
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
2 3 4
1 5
2 5 6
2 6 5
3 8 6 7
0
1 8
1 10
0
2 11 13
2 14 13
2 14 13
3 15 14 16
2 16 15
1 18
1 18
0
1 20
1 21
1 21
0
2 23 24
1 26
2 27 26
1 27
1 29
1 29
1 31
1 30
1 32
1 32
1 33
2 35 36
2 35 37
1...

output:

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

result:

ok Correct!

Test #36:

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

input:

5
99 99
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 1 3 2
2 4 3
2 4 3
0
2 6 7
1 6
3 8 7 9
2 10 9
1 11
3 12 11 10
3 13 12 11
1 12
2 13 14
0
1 15
...

output:

75
66 32 34 42 44 45 46 47 48 50 54 55 56 59 60 64 2 67 70 72 73 74 80 82 84 86 88 89 90 92 96 12 23 24 9 11 22 7 6 20 15 18 16 81 13 68 75 76 63 77 98 99 83 10 8 85 87 5 91 3 93 95 97 27 19 62 40 39 38 36 53 41 30 58 1 43 25 29 4 37 94 35 33 31 28 26 79 78 49 51 52 21 57 71 14 69 61 65 17 
75
52 27...

result:

ok Correct!

Test #37:

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

input:

1
495 497
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

383
264 278 275 274 273 271 270 268 267 265 282 262 252 251 248 246 244 243 240 239 301 319 317 315 314 312 310 308 307 306 237 300 297 292 290 289 287 284 283 174 195 192 190 187 184 179 178 177 175 198 173 171 170 168 166 165 160 159 158 219 232 231 229 228 226 225 224 222 221 320 218 216 215 210 ...

result:

ok Correct!

Test #38:

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

input:

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

output:

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

result:

ok Correct!

Test #39:

score: 0
Accepted
time: 0ms
memory: 3920kb

input:

5
95 98
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 5 1 3
1 6
3 5 4 7
2 7 8
1 7
3 7 10 6
3 9 11 8
4 10 8 9 11
3 9 10 12
1 12
3 12 14 15
1 16
4 14 ...

output:

90
84 87 27 29 32 33 35 36 38 40 42 95 52 53 56 78 60 63 64 67 68 72 17 88 12 10 91 15 90 7 5 71 70 61 51 50 49 3 81 82 11 4 66 75 74 80 9 48 47 92 93 59 44 45 46 28 25 26 16 21 23 22 19 20 31 30 18 34 37 39 85 43 83 79 94 89 86 69 6 13 1 54 55 58 62 41 65 14 73 8 57 77 76 24 2 
90
82 28 29 89 87 35...

result:

ok Correct!

Test #40:

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

input:

1
498 496
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

462
163 141 142 332 144 146 330 328 151 325 323 156 318 162 334 164 489 166 313 169 171 311 173 174 175 176 309 357 363 107 108 473 361 360 112 359 114 115 116 358 181 354 351 121 123 348 345 128 132 133 338 138 139 269 216 279 218 220 223 274 225 226 227 229 231 232 280 236 240 241 265 243 245 261 ...

result:

ok Correct!

Test #41:

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

input:

10
49 47
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
7 3 1 7 4 9 8 10
6 11 2 6 3 4 5
3 3 12 10
5 5 9 6 12 7
5 13 7 10 9 11
3 10 6 12
6 12 16 7 8 10 9
7 11 9 16 12 17 10 15
5 15 14 11 13 9
3 12 18 16
5 13 20 17 15 19
4 15 19 17 12
7 13 15 22 18 19 17 ...

output:

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

result:

ok Correct!

Test #42:

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

input:

5
99 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 9 7
5 2 9 8 11 7
6 5 8 4 9 3 11
6 9 8 13 10 12 4
6 5 6 12 14 9 11
2 10 14
8 12 15 8 9 14 ...

output:

99
2 70 59 77 45 37 81 33 27 23 19 18 13 5 3 96 93 97 95 94 38 41 34 35 39 42 31 36 29 28 30 20 22 12 21 14 11 8 7 1 99 90 17 16 15 9 10 6 40 86 89 88 87 85 82 83 84 80 78 51 48 46 57 53 71 67 72 92 55 61 52 65 68 63 58 60 50 47 62 56 64 74 73 75 66 69 54 49 32 44 91 4 98 76 79 25 24 43 26 
95
22 28...

result:

ok Correct!

Test #43:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

1
498 499
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

497
341 239 453 423 73 339 120 122 455 246 458 459 451 124 214 410 344 345 56 468 347 350 136 298 89 227 430 104 99 333 107 229 95 93 335 330 52 336 326 441 325 113 114 324 447 236 338 274 395 155 379 30 272 357 48 26 11 180 159 161 485 19 276 162 385 291 264 5 44 140 42 141 476 47 185 204 8 399 396...

result:

ok Correct!