QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506225#4895. Lovely Dogslefy20 830ms53052kbC++143.6kb2024-08-05 16:04:212024-08-05 16:04:21

Judging History

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

  • [2024-08-05 16:04:21]
  • 评测
  • 测评结果:20
  • 用时:830ms
  • 内存:53052kb
  • [2024-08-05 16:04:21]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=2e5+10;
vector<int>e[N],hav[N];
int a[N];
ll f[N],g[N],h[N];
int sz[N],son[N],mu[N],d,n;
void dfs(int x,int fa){
    for(int v:e[x])if(v^fa){
        dfs(v,x);
        sz[x]+=sz[v];
        if(sz[v]>sz[son[x]])son[x]=v;
    }
    sz[x]++;
}
ll ans;

int ok[N];
ll pw(ll x,int cnt){
    ll ans=1;
    while(cnt){
        if(cnt&1)ans=ans*x;
        cnt>>=1;
        x*=x;
    }
    return ans;
}
ll gcd(ll x,ll y){
    if(!y)return x;
    return gcd(y,x%y);
}
int get(int t,int b){
    if(t==1)return 1;
    ll c=pw(t,d+1);
    c/=gcd(c,b);
    if(c<=n)return c;
    return 0;
}
void dfs(int x,int fa,int op){
    if(op==1){
        for(int v:e[x])if(v^fa)dfs(v,x,op);
        if(ok[a[x]]){
            // if(a[x]==13)cout<<ans<<"\n";
            for(int v:hav[a[x]])h[v]+=g[a[x]];
            for(int t:hav[a[x]]){
                ans+=mu[t]*h[get(t,a[x])]*g[a[x]];
                // if(a[x]==10)cout<<get(t,a[x])<<" "<<t<<"\n";
            }
        }
        
        return;
    }
    if(op==-1){
        if(ok[a[x]]){
            for(int t:hav[a[x]])ans-=mu[t]*h[get(t,a[x])]*g[a[x]];
            for(int v:hav[a[x]])h[v]-=g[a[x]];
        }
        for(int v:e[x])if(v^fa)dfs(v,x,op);
        return;
    }
    for(int v:e[x])if(v!=fa&&v!=son[x]){
        dfs(v,x,0);
        dfs(v,x,-1);
        // cout<<v<<" "<<ans<<"*\n";
    }
    
    // cout<<x<<" ";cout<<ans<<" ";
    if(son[x])dfs(son[x],x,0);
    // if(x==8)cout<<ans<<"\n";
    for(int v:e[x])if(v!=fa&&v!=son[x]){
        dfs(v,x,1);
        // if(x==8)cout<<a[v]<<" "<<ans<<" "<<h[5]<<"\n";
    }
    // if(x==8)cout<<ans<<"*\n";

    if(ok[a[x]]){
        for(int v:hav[a[x]])h[v]+=g[a[x]];
        for(int t:hav[a[x]]){
                ans+=mu[t]*h[get(t,a[x])]*g[a[x]];
            // if(a[x]==18)cout<<get(t,a[x])<<" "<<t<<" "<<h[get(t,a[x])]<<"\n";
        }
        
    }
    
    f[x]=ans;
}
int p[N],cnt,vis[N];
void init(){
    mu[1]=1;
    for(int i=2;i<=2e5;i++){
        if(!vis[i])p[++cnt]=i,mu[i]=-1;
        for(int j=1;j<=cnt&&(ll)p[j]*i<=2e5;j++){
            vis[p[j]*i]=1;
            mu[p[j]*i]=-mu[i];
            if(i%p[j]==0){
                mu[p[j]*i]=0;
                break;
            }
        }
    }
}
int get(int x){
    int ans=1;
     for(int j=1;p[j]*p[j]<=x;j++)if(x%p[j]==0){
        int cnt=0;
        while(x%p[j]==0)x/=p[j],cnt++;
        if(cnt&1)ans*=-1;
        if(cnt>d)ans=0;
    }
    if(x!=1)ans*=-1;
    return ans;
}
int main() {
    scanf("%d%d",&n,&d);
    init();
    for(int i=1;i<n;i++){
        int x,y;scanf("%d%d",&x,&y);
        e[x].push_back(y);
        e[y].push_back(x);
    }
    for(int i=1;i<=n;i++){
        g[i]=1;int x=i;ok[i]=1;
        for(int j=1;p[j]*p[j]<=x;j++)if(x%p[j]==0){
            int cnt=0;
            while(x%p[j]==0)x/=p[j],cnt++;
            if(cnt&1)g[i]*=-1;
            if(cnt>d)ok[i]=0;
        }
        if(x!=1)g[i]*=-1;
        // cout<<g[i]<<" "<<mu[i]<<"\n";
    }
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j+=i)hav[j].push_back(i);
    }
    // int t=0;
    // for(int i=1;i<=n;i++)if(i>3&&a[i]!=8&&a[i]!=16){
    //     for(int j=1;j<=a[i]*18;j++)if(a[i]*18%pw(j,d+1)==0){
    //         t+=mu[j]*g[a[i]]*g[18],cout<<j<<" "<<a[i]<<"\n";
    //     }

    //     // t+=g[a[i]];
    // }
    // cout<<t<<"\n";
    dfs(1,0);dfs(1,0,0);
    for(int i=1;i<=n;i++)printf("%lld\n",f[i]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 10
Accepted
time: 0ms
memory: 22352kb

input:

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

output:

16
1
1
1
0
1
0
12
3
1
6
1
3
1
2
1
1
7
1
0

result:

ok 20 tokens

Test #2:

score: 10
Accepted
time: 3ms
memory: 23276kb

input:

500 1
287 459
335 297
303 82
427 202
500 158
257 45
410 274
208 19
172 113
274 379
380 65
234 46
161 441
73 488
473 327
474 481
152 67
78 414
260 20
142 385
494 343
446 72
498 296
111 9
349 372
448 217
282 442
412 144
342 44
282 92
337 128
426 201
104 493
278 298
278 145
363 121
92 305
278 379
166 1...

output:

158
-3
0
0
-1
0
0
0
-1
-1
-2
0
0
1
0
0
0
0
-1
-3
0
0
1
0
1
0
0
0
0
0
1
6
5
0
0
0
0
0
1
0
0
0
-1
2
0
0
0
98
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
-11
0
0
1
0
0
0
-5
0
0
11
0
0
0
0
-1
0
0
1
0
7
-2
0
31
0
2
14
-3
0
1
0
0
0
0
1
0
0
-2
-3
0
0
-3
0
0
0
0
0
0
0
0
0
-1
0
0
-1
0
1
0
0
0
2
1
0
-3
0
0
0
-1
0
0
0
-...

result:

ok 500 tokens

Test #3:

score: 10
Accepted
time: 3ms
memory: 22144kb

input:

500 1
420 282
9 357
176 82
390 58
280 145
303 106
342 485
300 241
149 18
233 286
499 473
288 22
472 103
271 244
490 273
419 93
26 5
408 243
132 423
75 53
112 390
26 227
413 312
401 320
96 71
479 129
459 373
322 425
465 85
244 117
155 7
44 407
225 351
67 480
370 24
408 60
463 245
270 264
271 82
109 3...

output:

158
0
-1
0
6
0
0
0
0
1
0
0
-1
18
0
0
0
0
0
0
0
1
0
0
0
4
0
0
0
1
1
2
0
0
0
0
0
-3
0
0
0
0
0
0
-1
0
3
-1
0
-3
0
0
0
0
0
-1
-1
0
1
0
0
0
1
0
0
0
0
1
0
0
-1
0
7
0
1
230
2
0
0
-6
0
6
0
-2
-2
0
0
-8
0
0
-1
3
1
0
1
0
0
1
0
-3
1
0
0
0
0
-1
0
0
0
0
0
-2
0
-1
0
1
0
7
0
0
-1
0
0
0
0
0
1
0
0
-3
0
-1
0
0
0
0
0
...

result:

ok 500 tokens

Test #4:

score: 10
Accepted
time: 6ms
memory: 22320kb

input:

500 1
407 7
167 9
444 291
345 93
446 169
305 310
231 378
93 158
93 128
233 75
499 106
93 430
403 132
26 186
305 452
15 238
82 93
146 93
272 11
62 319
301 91
136 28
93 60
478 324
101 248
180 445
253 155
61 456
348 130
137 308
93 63
376 93
202 446
93 401
458 9
226 93
164 93
432 484
265 93
396 218
473 ...

output:

158
-207
0
-12
20
0
0
0
49
0
-34
0
56
-59
-38
-119
0
0
0
103
-48
-46
-64
-11
0
-54
0
65
0
0
0
0
0
0
-41
-7
0
0
0
-54
0
39
0
-155
0
0
-49
0
0
-67
0
0
0
-54
-120
0
0
-55
0
0
-21
115
0
0
0
-206
0
0
-21
0
-48
-27
0
0
-71
0
151
0
2
-41
-58
0
0
0
0
0
-11
0
0
-49
-54
-38
49
-32
0
37
0
0
0
0
-42
0
0
-56
54
...

result:

ok 500 tokens

Test #5:

score: 10
Accepted
time: 0ms
memory: 22648kb

input:

500 1
27 412
370 80
199 200
189 311
29 174
242 428
302 491
64 278
390 342
334 86
145 468
329 308
466 462
85 371
198 182
18 435
338 85
473 105
50 131
312 62
58 417
233 53
38 278
377 365
162 397
293 228
12 211
432 499
218 134
390 130
272 381
336 133
137 356
95 449
290 327
151 232
179 272
201 269
304 3...

output:

158
1
2
0
0
0
0
0
1
0
0
0
0
1
1
0
0
3
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
2
0
-8
0
0
0
0
0
0
0
-1
0
0
0
0
0
1
0
0
0
-1
0
0
0
0
-2
0
-2
-1
-3
0
0
0
2
0
-1
0
0
1
1
0
-1
-4
0
1
0
0
0
0
0
1
0
-3
0
0
0
0
0
0
-2
0
0
0
0
0
0
1
1
1
-1
0
0
0
0
0
-1
0
9
0
-67
0
0
0
0
0
0
-4
-2
0
0
0
0
-2
-1
-1
0
-2
0
0
-...

result:

ok 500 tokens

Test #6:

score: 10
Accepted
time: 0ms
memory: 22716kb

input:

500 2
428 7
101 379
176 90
188 28
455 459
196 332
481 438
294 234
222 285
2 448
58 491
132 449
111 413
254 163
9 201
269 393
79 11
182 331
277 265
88 370
233 188
329 294
446 445
136 131
317 453
311 219
437 486
496 310
85 349
421 326
316 490
499 367
404 361
446 411
249 494
462 58
433 60
57 278
45 456...

output:

629
8
20
1
0
1
1
1
2
0
2
0
1
0
3
0
4
0
0
0
1
0
0
1
0
1
1
169
1
0
2
1
1
0
2
1
1
1
1
568
2
2
0
0
0
1
1
0
0
48
1
0
1
1
0
2
0
8
0
0
1
0
0
2
2
2
2
1
1
0
1
0
1
1
0
7
0
0
1
1
1
0
0
2
7
0
0
0
0
1
13
1
0
6
-1
1
0
1
2
0
4
1
1
4
1
1
1
1
0
0
1
-1
3
2
1
1
0
0
0
1
1
2
3
1
9
1
1
1
3
0
5
8
-1
1
2
0
5
1
1
0
0
2
0
1
...

result:

ok 500 tokens

Test #7:

score: 10
Accepted
time: 0ms
memory: 22788kb

input:

500 3
102 64
271 215
377 453
237 410
39 280
210 109
7 139
446 304
9 484
189 335
60 398
269 65
429 487
186 279
451 44
245 144
288 396
498 433
225 335
254 482
392 335
477 139
275 193
58 274
312 334
427 201
141 4
389 330
184 133
436 18
239 302
188 38
45 348
173 433
285 54
33 296
150 189
320 278
182 316...

output:

104
0
4
75
1
21
1
1
7
0
2
2
4
4
4
-3
0
1
0
1
2
1
0
2
1
2
0
6
0
1
0
8
3
5
2
1
1
1
2
2
6
1
0
0
0
3
-2
1
3
1
0
5
0
0
0
1
1
1
1
33
1
1
0
1
6
1
2
3
0
-1
1
1
1
1
1
1
7
1
1
0
1
0
1
1
120
3
1
2
10
0
3
0
0
1
3
1
3
1
0
0
1
0
2
1
0
1
0
26
2
6
1
0
0
1
4
1
0
0
1
1
2
1
0
3
1
1
0
0
1
0
14
1
0
3
0
1
1
0
11
0
8
0
1
...

result:

ok 500 tokens

Test #8:

score: 10
Accepted
time: 0ms
memory: 23312kb

input:

500 4
89 102
92 484
360 314
414 280
439 165
331 311
349 110
484 252
422 473
401 137
183 34
175 91
306 42
285 186
296 22
62 441
389 238
240 268
165 44
117 34
110 255
465 58
53 82
478 350
195 306
362 422
239 35
36 33
484 284
153 181
285 478
201 148
5 196
331 350
235 291
497 270
140 292
317 439
222 252...

output:

525
6
6
1
4
0
1
1
1
1
3
1
1
1
1
3
1
1
1
3
12
3
1
5
1
1
2
3
1
11
1
3
6
1
2
1
1
1
1
1
1
0
0
1
1
0
1
1
1
1
2
0
1
3
1
4
0
1
1
1
1
1
2
1
1
0
547
1
6
5
62
0
1
1
6
0
1
0
4
6
1
0
1
3
3
1
3
0
4
6
3
7
0
2
1
1
1
0
1
1
1
6
1
1
1
1
1
0
307
5
2
1
1
0
0
1
5
1
1
1
5
1
2
1
1
1
1
0
2
0
1
1
3
2
7
2
405
1
1
3
1
1
0
4
2...

result:

ok 500 tokens

Test #9:

score: 10
Accepted
time: 6ms
memory: 22056kb

input:

500 5
487 484
346 261
290 56
40 334
16 3
171 224
311 151
425 371
460 469
248 256
117 217
309 79
165 482
259 374
131 408
117 24
18 234
448 197
253 205
421 211
437 408
218 298
159 35
463 169
247 310
289 365
389 275
64 411
117 431
472 279
259 236
351 106
447 39
75 54
18 336
82 89
259 41
331 356
385 77
...

output:

308
1
24
1
0
0
1
1
0
1
1
6
12
1
3
2
1
11
1
1
0
1
6
4
1
1
1
1
1
1
1
1
1
1
10
1
6
2
38
1
3
5
0
1
1
0
0
1
5
0
61
3
1
2
5
1
5
32
4
8
1
0
0
4
1
1
1
9
1
2
4
1
4
1
1
1
8
0
1
0
4
1
0
1
4
1
38
2
2
1
1
1
3
6
0
119
10
1
1
13
1
3
1
1
1
7
1
3
1
1
1
1
1
1
3
1
6
3
1
1
3
1
5
1
3
1
1
1
3
0
10
3
8
2
1
2
4
2
1
1
0
1
0...

result:

ok 500 tokens

Test #10:

score: 10
Accepted
time: 0ms
memory: 23084kb

input:

500 6
387 133
199 269
328 469
142 241
334 323
266 453
479 411
141 56
287 158
493 267
306 387
257 483
310 381
398 14
110 457
462 170
11 262
321 316
413 299
364 488
132 166
304 131
208 245
423 21
360 427
369 188
72 10
219 93
181 279
118 129
20 499
462 122
261 254
180 495
199 300
241 90
491 274
382 127...

output:

506
1
4
1
1
1
1
1
1
1
15
1
2
1
0
1
1
5
1
2
2
3
1
12
1
6
7
1
3
5
1
1
4
1
2
1
70
1
1
12
32
4
3
1
1
3
11
1
3
3
1
9
4
10
1
0
4
1
63
1
1
1
26
4
1
1
3
1
3
3
1
1
1
1
1
1
7
1
1
2
1
1
8
1
1
1
5
7
5
3
2
1
4
3
1
1
6
1
1
2
0
2
1
3
1
1
6
1
4
1
3
3
1
1
2
1
2
0
5
3
1
1
2
3
1
7
1
1
343
1
1
2
4
2
1
1
2
1
1
1
12
1
1
...

result:

ok 500 tokens

Test #11:

score: 0
Runtime Error

input:

500 7
366 320
150 327
384 317
144 293
399 290
438 76
27 305
210 43
472 144
310 490
347 234
457 268
319 142
268 407
295 371
82 111
282 244
324 203
438 60
493 170
162 157
96 104
489 323
274 236
170 307
252 84
144 404
483 264
370 272
124 282
353 250
499 406
492 306
361 54
233 361
366 155
72 17
114 103
...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #24:

score: 10
Accepted
time: 0ms
memory: 23332kb

input:

2000 1
134 1468
867 1750
351 1220
1690 1888
1685 134
585 282
1142 643
206 271
260 1833
1987 770
1029 1667
322 1371
341 518
601 915
119 893
1933 1502
951 1785
1056 1630
1957 1208
96 55
1508 1212
331 427
505 151
1378 1486
1545 697
1459 629
202 997
180 1917
1638 1177
1244 1896
302 658
1433 1605
1318 19...

output:

581
-3
0
0
0
0
0
0
0
-2
0
0
0
0
0
-1
0
0
0
1
0
-1
0
0
-1
0
0
0
17
-2
0
-1
-2
0
0
0
0
0
0
0
-5
0
0
0
0
-14
0
-1
0
-1
0
0
1
1
-1
-4
0
0
1
0
0
0
3
0
0
0
-1
-2
0
0
4
0
0
0
0
-1
0
1
0
0
0
-5
0
0
0
0
-1
0
0
0
0
0
0
0
1
-1
0
18
0
0
13
-2
0
-2
0
0
0
0
2
-2
2
0
0
3
0
-1
0
0
0
0
-3
0
0
0
0
0
0
1
-1
0
0
0
0
0
...

result:

ok 2000 tokens

Test #25:

score: 10
Accepted
time: 7ms
memory: 23528kb

input:

2000 1
1754 1650
906 642
596 1542
1656 1549
716 1578
1799 1182
53 244
1032 41
1290 1758
485 1496
1438 948
1683 684
400 653
1756 1459
1965 1322
1540 1263
1365 1564
108 1801
741 717
1113 13
1787 1124
411 732
64 1817
907 259
1308 29
1518 752
375 422
663 1631
528 799
863 310
790 793
587 579
1828 874
502...

output:

581
0
-1
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
-12
0
0
0
0
0
0
2
-1
0
0
0
0
0
0
0
0
0
-1
-1
1
0
0
-2
0
20
-1
0
-3
1
0
5
-1
0
0
1
1
0
0
0
0
-1
0
-2
0
0
0
-15
1
1
0
0
0
0
0
1
0
30
0
1
0
0
1
-1
0
0
0
0
-1
0
0
0
0
0
1
0
0
0
0
0
0
0
-1
0
1
0
1
-1
0
-1
0
0
0
0
-3
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
1
0
0
0...

result:

ok 2000 tokens

Test #26:

score: 10
Accepted
time: 3ms
memory: 22528kb

input:

2000 1
146 1160
146 388
146 1033
382 1917
162 1342
1 1425
1841 764
1674 780
1109 1649
1282 1786
488 1386
1753 1698
17 192
1692 944
693 146
1933 146
976 463
1603 392
1709 248
18 678
146 1157
1517 1416
31 1153
973 39
1359 1046
625 1840
745 146
1316 146
124 146
627 1410
146 540
772 1461
1041 1537
1374 ...

output:

581
0
-36
-192
435
473
506
0
0
358
0
0
0
0
0
0
-180
35
438
0
0
0
607
0
0
0
-17
0
0
26
2
499
0
-180
-85
0
-104
-120
-63
-60
0
0
0
0
598
0
0
0
0
356
592
0
0
0
45
-73
-116
343
0
0
0
0
0
0
31
-108
-5
0
0
0
637
270
494
0
0
487
0
-197
0
401
520
0
0
52
0
128
0
0
82
0
0
0
-22
0
0
0
0
0
0
30
0
0
0
0
0
0
0
0
...

result:

ok 2000 tokens

Test #27:

score: 10
Accepted
time: 8ms
memory: 23248kb

input:

2000 1
681 278
1551 1142
424 928
738 174
1393 1727
456 944
1713 468
359 1597
1265 1737
246 500
1095 695
654 904
1465 27
1172 1385
1455 40
1391 1384
1979 970
1123 800
1618 1892
1444 1506
79 806
313 1350
1872 85
1467 1031
741 1139
739 1681
263 1454
169 885
1222 153
864 799
192 1339
935 1843
1633 1358
...

output:

581
0
-1
0
0
0
1
25
0
0
0
0
1
0
-8
0
0
-3
0
0
0
-2
0
0
-3
0
0
0
0
0
0
0
-3
-1
-1
0
0
-1
1
-2
3
0
0
0
0
0
2
3
0
0
-1
-7
0
0
0
0
0
-7
0
0
-1
1
9
0
0
-1
0
0
0
0
0
-1
-3
-1
1
-3
0
-1
-1
0
-1
-1
-1
-1
0
0
-2
-1
12
-7
-10
0
0
0
-6
0
0
0
0
41
0
0
-15
0
0
0
0
0
1
1
0
0
0
0
0
-7
0
-3
-26
0
0
0
0
0
0
0
0
0
2
...

result:

ok 2000 tokens

Test #28:

score: 10
Accepted
time: 8ms
memory: 22116kb

input:

2000 2
1608 842
1808 1921
1404 549
594 1521
1755 855
1047 1256
340 1877
407 670
1100 1239
1511 1142
790 1103
1212 944
515 167
180 415
399 1563
1458 136
728 1480
1074 819
555 1594
1693 1301
1802 1879
1936 501
306 87
1125 796
720 1298
1999 1529
767 1396
1258 1940
1651 1564
1059 281
704 848
1861 473
13...

output:

2854
3
3
12
1
1
1
1
55
1
1
1
2
0
4
3
7
1
0
1
0
1
1
1
1
0
3
5
0
0
1
126
0
2
15
45
0
0
0
0
1
1
1
1
1
1
1
7
2
0
-2
1
1
3
0
0
0
0
2
0
1
0
3
1
1
5
1
-2
1
1
2
1
1
0
0
6
0
1
1
1
6
1
1
1
0
0
3
1
0
1
1
1
4
1
1
0
1
4
0
-1
1
1
0
1
1
1
3
0
0
0
2
1
0
1
1
1
0
0
1
1
23
1
0
1
1
0
1
1
2
0
1
4
1
3
0
2
1
1
0
3
3
2
1
0...

result:

ok 2000 tokens

Test #29:

score: 10
Accepted
time: 6ms
memory: 23312kb

input:

2000 3
1424 1720
1698 425
1429 965
955 45
629 466
537 1175
656 1047
1333 1754
1060 818
688 1990
1859 292
1588 1664
1134 1683
1378 1828
1353 1173
1906 1710
106 1208
1938 746
368 1557
1899 1866
433 1933
614 1604
999 278
418 1609
458 1347
1688 1325
1089 434
208 1987
519 1275
1227 870
305 1164
425 1930
...

output:

-26
3
0
1
10
1
1
0
4
6
1
2
0
50
15
1
0
1
1
0
0
0
1
1
1
4
4
3
1
0
1
1
3
0
1
5
1
1
3
3
1
11
0
1
0
1
2
1
157
0
1
3
0
1
1
2
1
3
1
0
3
4
1
0
0
0
1
0
7
1
0
0
1
1
1
0
0
1
1
1
2
1
0
1
0
1
1
1
1
0
0
0
1
4
1
1
0
12
0
1
17
2
1
1
1
6
0
3
0
2
2
5
0
0
0
1
1
1
2
1
0
0
1
0
0
0
2
1
1
1
3
-1
0
0
3
1
1
1
5
0
0
2
1
1
1...

result:

ok 2000 tokens

Test #30:

score: 10
Accepted
time: 4ms
memory: 22552kb

input:

2000 4
836 736
1179 1789
800 1646
768 914
1814 370
3 1531
1357 1646
1092 1016
1361 1295
1087 1220
210 574
885 1057
21 649
567 1568
1205 1889
869 1810
618 1075
1566 1575
1704 1349
1275 1029
190 1862
1661 1962
140 85
1764 19
226 1945
600 1727
849 724
383 1311
891 1457
183 643
1510 959
1701 346
1151 11...

output:

1802
1
1
6
1
0
1
3
2
25
3
4
1
0
1
5
6
1
1
3
11
1
5
1
0
2
1
1
1
31
3
1
23
1
1
25
1
0
1
1
54
9
3
5
3
1
1
1
0
1
0
0
21
1
3
1
1
2
34
1
5
4
3
0
4
0
1
2
1
41
1
1
1
1
1
1
3
6
0
1
22
11
2
0
3
2
4
15
0
1
1
74
2
1
11
0
1
1
3
1
1
3
1
25
3
0
1
1
1
1
1
1
0
1
1
1
1
5
15
1
80
1
3
3
2
5
1
10
3
3
1817
16
1
0
3
2
4
1...

result:

ok 2000 tokens

Test #31:

score: 0
Runtime Error

input:

2000 5
1800 301
502 481
173 833
98 1487
1118 1092
1418 1661
47 1275
1575 688
814 79
1428 1543
537 1252
1550 1326
1614 1397
551 1299
1918 1840
1682 1751
997 1168
240 1433
651 758
1881 1142
1845 1627
406 1097
1828 964
1387 1266
1764 1063
1852 1402
1021 1050
723 465
956 1865
1192 1255
387 1917
948 1695...

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #45:

score: 0
Runtime Error

input:

200000 20
117994 12616
53490 106425
103660 50033
132640 78252
58384 19939
69183 10015
39098 165030
179856 130356
65245 57831
18234 83378
4240 154896
177149 102260
4634 180087
132390 19627
98506 60775
1890 120740
87908 21917
41323 192721
181885 96684
69412 139951
9800 38301
59025 29879
186185 81402
1...

output:


result:


Subtask #4:

score: 20
Accepted

Test #50:

score: 20
Accepted
time: 226ms
memory: 46512kb

input:

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

output:

-44916
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200000 tokens

Test #51:

score: 20
Accepted
time: 212ms
memory: 46100kb

input:

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

output:

-44916
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200000 tokens

Test #52:

score: 20
Accepted
time: 216ms
memory: 45544kb

input:

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

output:

-44916
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200000 tokens

Test #53:

score: 20
Accepted
time: 219ms
memory: 46296kb

input:

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

output:

-44916
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200000 tokens

Test #54:

score: 20
Accepted
time: 221ms
memory: 45964kb

input:

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

output:

-44916
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200000 tokens

Subtask #5:

score: 0
Runtime Error

Test #55:

score: 15
Accepted
time: 216ms
memory: 45716kb

input:

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

output:

-44916
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200000 tokens

Test #56:

score: 15
Accepted
time: 214ms
memory: 45624kb

input:

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

output:

-44916
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200000 tokens

Test #57:

score: 15
Accepted
time: 224ms
memory: 45732kb

input:

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

output:

-44916
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200000 tokens

Test #58:

score: 15
Accepted
time: 323ms
memory: 46432kb

input:

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

output:

685522
1
1
1
0
1
1
1
1
0
1
0
1
1
1
1
1
0
1
0
0
1
1
0
1
1
0
1
1
1
1
1
1
1
0
1
1
0
0
1
0
1
1
1
0
1
1
0
1
1
0
1
1
0
1
0
0
1
0
0
1
0
1
1
1
1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
0
1
0
0
1
1
1
1
0
1
1
0
0
1
1
0
1
1
0
1
1
1
1
0
1
1
1
1
0
1
0
0
0
1
0
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
1
1
0...

result:

ok 200000 tokens

Test #59:

score: 15
Accepted
time: 316ms
memory: 46396kb

input:

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

output:

685522
1
0
0
1
0
1
1
1
1
0
1
0
1
1
0
0
1
0
0
1
1
1
1
0
1
0
0
1
0
1
0
1
1
0
0
1
0
1
1
1
1
1
0
1
1
1
1
1
0
1
1
1
0
1
1
0
1
1
1
1
1
1
0
0
1
0
0
1
0
1
1
1
1
1
1
0
0
0
1
1
1
1
1
1
1
0
0
0
1
1
0
0
1
1
0
0
0
1
0
0
1
0
1
0
1
0
0
0
1
0
0
0
1
1
1
0
1
1
1
0
1
1
0
1
1
1
1
1
1
1
0
1
1
1
1
1
0
0
0
0
1
1
1
1
1
1
1...

result:

ok 200000 tokens

Test #60:

score: 0
Runtime Error

input:

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

output:


result:


Subtask #6:

score: 0
Runtime Error

Test #78:

score: 10
Accepted
time: 84ms
memory: 28604kb

input:

50000 1
8097 41839
17674 41774
40520 8024
5786 38261
20664 43471
1217 49276
11185 40807
14186 25584
31704 14814
42333 41475
13053 39565
45938 30104
5826 39463
5031 10814
43784 6042
58 33849
42978 18978
36307 33276
34769 4351
27884 37532
27528 29431
29451 39345
10946 9667
19016 47269
7911 30103
10308...

output:

-9152
0
0
0
0
0
0
-1
0
-1
0
0
1
0
0
0
0
0
0
0
0
-2
-1
-2
0
-2
0
2
-3
3
0
0
-1
0
0
0
0
0
0
0
0
-2
-1
0
-1
0
2
0
1
0
0
0
0
1
0
0
31
0
0
0
0
0
0
-3
0
-1
26
-2
9
-1
-1
5
0
0
2
0
-1
0
0
0
4
-1
-1
0
-1
0
0
0
0
0
-1
0
0
-2
-1
-1
0
0
4
0
0
0
0
0
0
8
-12
0
0
0
0
0
0
0
9
0
1
0
0
0
0
0
0
0
0
0
0
0
-1
1
0
0
0
-...

result:

ok 50000 tokens

Test #79:

score: 10
Accepted
time: 83ms
memory: 28880kb

input:

50000 1
32034 47865
25944 188
8598 48750
2708 28815
30476 36844
46054 9168
4967 34970
41763 39703
15403 23747
17970 29303
36579 18070
19316 40824
40459 44029
3823 38050
3084 19147
18056 49063
25399 16977
39334 9283
41398 29161
20384 27913
30470 31528
640 5773
1605 32691
48417 23633
27454 6779
19548 ...

output:

-9152
11
14
0
0
7
0
-1
0
0
0
-14
0
0
0
1
0
0
-1
0
0
0
0
3
0
0
0
0
0
0
0
0
0
-2
0
-1
0
0
1
0
0
-50
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
6
5
-1
0
0
1
0
0
0
0
0
-8
0
-16
0
5
0
0
0
0
0
0
-1
0
0
0
-1
0
0
-1
0
0
0
2
0
0
0
0
-2
1
0
0
-5
0
0
0
-13
0
0
0
0
-3
-3
0
0
0
0
0
-1
0
0
0
-1
-1
-1
0
-1
0
-3
0
2
1
0
0
...

result:

ok 50000 tokens

Test #80:

score: 10
Accepted
time: 48ms
memory: 30076kb

input:

50000 1
39371 11897
18057 28366
41597 38680
18057 27889
11426 20379
41380 30688
28903 40347
18057 25169
37754 8154
23412 45346
18057 45516
18057 33624
18057 30696
26612 23615
18718 44663
27320 18057
20424 36013
19003 29291
6016 18057
1718 5947
41466 23544
38799 26926
18057 30495
18057 14852
16829 27...

output:

-9152
0
0
-1472
-7389
-6321
0
-4854
-2735
0
0
0
0
-3769
-2558
0
0
-1531
-2588
-2908
0
-6720
0
0
0
-9803
0
0
0
0
-5494
-2885
-1898
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-3164
0
0
0
0
0
-3224
-4062
-1307
-1030
0
-4877
0
0
-6232
0
0
0
0
-3739
-1918
-4896
0
0
0
-5332
-8995
-1790
0
0
-6320
0
0
-5089
0
-6664
-9...

result:

ok 50000 tokens

Test #81:

score: 10
Accepted
time: 115ms
memory: 28752kb

input:

50000 1
33407 5182
3870 21606
16080 48453
2777 4478
49747 843
42539 32472
2195 15316
9184 16559
39787 27989
15822 46476
3462 8502
15130 37017
31019 7086
13437 19984
3 20139
21162 27689
1067 27927
37709 11407
38509 34963
36180 28194
10151 38894
21219 29603
18000 26175
48974 14856
22675 18606
44861 24...

output:

-9152
0
0
0
-2
-1
0
0
0
0
0
0
0
0
0
0
0
0
-2
0
0
2
0
0
-4
0
0
0
1
0
0
0
0
0
0
0
0
0
11
-2
0
0
0
0
-2
0
31
0
-2
0
0
0
0
-1
0
0
-1
0
-4
-1
-1
0
-1
0
0
0
-5
-1
0
0
0
0
-3
0
-1
-2
-1
0
1
-1
0
0
-2
0
-4
0
0
0
0
0
-1
-5
0
-1
0
0
7
-1
-11
0
2
-1
0
-5
0
0
0
-1
4
0
0
0
0
0
0
0
-3
0
-33
0
0
2
-1
-5
0
0
0
-1
0...

result:

ok 50000 tokens

Test #82:

score: 10
Accepted
time: 139ms
memory: 28900kb

input:

50000 2
33498 4348
23123 14835
39691 37408
16639 34690
11658 6884
18384 37709
34876 362
31285 46209
46969 43774
42016 8213
20575 17772
6850 7416
22841 15580
29655 11944
39386 14476
43195 12555
17750 39637
38370 1807
23684 7842
15935 30198
37729 13374
37344 19025
18023 42781
2091 42469
20928 26586
34...

output:

132856
19
0
0
1
0
1
1
0
1
1
1
1
0
1
0
1
1
1
1
1
0
0
1
1
30
1
1
1
3
0
1
4
1
1
1
44
0
1
1
14
6
3
0
1
3
0
0
1
0
0
1
8
0
1
1
1
119
1
1
1
1
2
3
5
-1
1
-2
1
1
0
1
2
1
2
1
1
1
1
1
2
0
9
0
1
1
0
0
1
2
3
7
2
1
56
8
1
1
0
22
1
1
1
0
2
7
10
1
23
0
1
1
1
0
1
1
1
1
1
0
0
1
0
2
1
1
1
5
1
1
0
1
0
0
0
1
0
1
1
1
6
4...

result:

ok 50000 tokens

Test #83:

score: 10
Accepted
time: 168ms
memory: 28820kb

input:

50000 3
2197 38217
46761 30089
46038 49892
40751 49695
12716 11374
46387 35267
44578 48391
31915 4177
27631 44787
5472 47601
2696 24412
34415 854
31686 8645
32438 47873
15844 8092
20099 37483
31858 40715
49343 18475
15451 32156
19723 20620
3387 44439
4994 10604
19669 42347
39388 6540
31228 12393
117...

output:

7883
10
4
0
3
0
0
0
2
0
1
1
7
2
5
2
2
1
2
1
1
1
1
3
7
1
1
0
3
5
0
1
7
1
0
3
8
1
1
0
0
1
0
1
0
1
0
0
1
1
1
0
0
1
7
1
2
0
1
21
1
1
2
2
50
2
0
8
2
1
1
1
1
4
1
0
1
1
3
1
3
2
1
1
1
1
1
1
0
3
0
1
3
0
1
1
3
1
2
3
2
1
1
0
1
0
3
3
3
0
1
0
1
1
21
17
1
2
0
3
25
1
5
1
-1
0
1
0
8
1
1
1
1
2
1
-1
2
0
1
1
1
3
2
0
0...

result:

ok 50000 tokens

Test #84:

score: 0
Runtime Error

input:

50000 4
19179 18268
14798 46951
25900 20679
30994 36099
12554 48166
27677 31985
44627 25537
43523 21523
42118 48501
40332 49984
7319 34492
3601 25176
47666 39140
43378 38712
34585 32082
880 824
45859 46998
43250 30136
28243 15080
27583 15609
40535 27408
8327 11651
4436 16972
44961 17114
2692 9085
26...

output:


result:


Subtask #7:

score: 0
Runtime Error

Test #103:

score: 25
Accepted
time: 479ms
memory: 46056kb

input:

200000 1
118863 188865
188022 168616
118976 119404
178852 33449
81624 40431
151228 160976
68943 136313
57200 117631
147789 139875
100240 55537
164811 145415
103548 186750
15010 168029
155731 107005
69836 1502
86171 122700
83448 131948
189162 94464
128210 2509
49724 183329
174782 192641
27687 71315
1...

output:

-44916
0
0
0
0
0
0
0
0
0
-1
-1
0
0
-1
0
0
0
-2
-1
0
0
1
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
5
0
0
-1
0
0
0
0
0
0
17
0
0
0
0
0
0
-1
0
1
6
41
0
0
0
0
0
0
0
0
0
0
0
3
0
0
-1
-38
0
0
0
0
0
0
-3
0
0
0
0
0
0
0
0
-1
0
0
0
-25
0
0
0
-6
-1
0
0
0
0
-1
-1
0
-1
0
-8
0
0
0
0
0
0
-1
0
0
0
3
0
0
0
0
0
0
0
0
-2
0
0
1
...

result:

ok 200000 tokens

Test #104:

score: 25
Accepted
time: 508ms
memory: 46180kb

input:

200000 1
103058 36806
98944 9225
170214 92545
96750 194462
199969 147292
67357 143473
167591 8145
25143 108831
176035 146998
191872 102153
157796 195518
189602 112527
139590 8953
91004 39370
139847 165500
121776 127200
49688 174930
100747 89328
53647 122360
70871 38221
164904 6986
89568 54074
92205 ...

output:

-44916
0
1
0
0
0
1
0
3
0
3
0
0
2
0
1
0
0
0
-1
0
0
0
-1
0
-1
0
0
0
0
-1
0
0
0
0
0
0
0
1
0
0
0
0
0
9
1
0
0
0
0
0
0
0
0
0
1
0
0
0
-2
-1
-1
0
0
0
-3
-3
0
1
0
0
0
0
0
0
0
0
0
-1
0
0
0
1
0
0
0
0
2
1
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
38
0
0
0
0
0
0
0
6
0
0
0
1
0
0
0
0
1
0
2
0
0
0
0
0
0
0
0
0
0
5
0
0
-1
-1
0...

result:

ok 200000 tokens

Test #105:

score: 25
Accepted
time: 265ms
memory: 53052kb

input:

200000 1
28250 161590
136522 143045
181858 25068
161590 155647
161590 197485
43365 24019
123719 161590
128919 161590
58859 80176
85441 66983
116620 163645
177760 161590
193780 161590
170319 136949
168425 147380
127765 98730
16031 33995
111500 161590
160891 80562
151520 168155
161590 88595
161590 183...

output:

-44916
0
0
-16363
0
0
-3356
0
7550
0
0
0
0
0
0
0
-17835
0
0
0
0
-8035
0
26446
0
2129
0
21700
-16680
0
5343
0
-19636
21957
0
0
4737
0
-17516
-12886
0
-3256
0
-20314
0
0
-10408
6465
0
-14092
7776
0
13921
-19336
-17481
-17769
0
-19842
0
-16465
-42172
24284
0
0
0
0
0
0
0
0
0
16892
-1034
8628
-22066
0
-8...

result:

ok 200000 tokens

Test #106:

score: 25
Accepted
time: 749ms
memory: 46304kb

input:

200000 1
29151 12047
166630 189622
159302 185388
56306 138684
167377 1062
99113 5207
100849 22306
79189 122160
10736 142854
76648 36503
137066 37553
66832 3721
179882 88103
182415 185761
53496 103576
129285 59686
66332 195352
2368 21433
39255 187827
174971 31698
183694 19447
22168 29852
88859 49687
...

output:

-44916
-2
-1
1
0
-1
-3
0
0
-1
0
-4
0
0
0
0
0
0
0
0
0
8
2
0
0
0
0
3
0
0
1
1
0
-1
0
-1
0
-1
0
0
4
0
0
1
9
0
-1
0
0
0
0
0
0
0
0
1
1
-10
0
-4
0
0
0
0
0
0
0
0
-7
-5
-1
3
16
-1
-5
0
0
0
0
6
0
0
-2
0
1
-1
0
0
1
6
-1
-1
0
1
-1
1
0
1
0
-1
0
0
0
0
0
0
-1
0
0
1
0
1
0
0
-1
0
3
0
-9
5
-2
0
0
0
0
0
0
0
-1
0
-1
0
...

result:

ok 200000 tokens

Test #107:

score: 25
Accepted
time: 830ms
memory: 46288kb

input:

200000 2
73273 103776
194559 42388
82298 138574
177827 37744
5197 123582
70941 85195
121397 35370
91418 159544
11718 125482
58762 190078
48171 119294
161791 145423
16897 57707
74723 170139
169164 188570
88835 181650
189900 70704
71127 85502
135720 150086
130652 191440
132832 61498
84639 17713
190705...

output:

685522
0
1
0
0
1
0
0
1
1
7
1
1
0
1
1
1
1
1
1
6
1
3
11
1
0
0
1
1
0
3
1
1
0
1
3
3
23
1
1
0
2
1
1
1
1
1
0
1
0
1
1
0
1
0
0
1
2
5
1
0
1
2
2
1
1
6
10
2
0
3
1
1
46
1
2
1
1
0
3
4
1
2
1
1
4
0
0
1
0
0
2
1
1
1
0
0
1
1
1
0
0
1
1
3
1
0
0
1
4
1
4
1
0
6
3
1
5
0
37
1
0
1
3
23
0
0
0
0
5
3
1
0
1
0
1
1
1
1
1
4
1
1
1
1...

result:

ok 200000 tokens

Test #108:

score: 0
Runtime Error

input:

200000 3
159438 4449
49255 165300
137160 24101
159610 33317
36201 48725
90269 77986
174649 141170
109722 168376
154824 123889
24498 30647
90371 164967
195568 160292
24457 69055
146070 118561
8721 42537
133890 131233
187926 30640
122172 198090
52913 111462
49494 9123
22482 151966
80978 2154
47643 148...

output:


result: