QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768617#2766. Unique Cities_8_8_36 392ms216396kbC++174.4kb2024-11-21 12:55:532024-11-21 12:55:54

Judging History

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

  • [2024-11-21 12:55:54]
  • 评测
  • 测评结果:36
  • 用时:392ms
  • 内存:216396kb
  • [2024-11-21 12:55:53]
  • 提交

answer

#include <bits/stdc++.h>
    
using namespace std;
    
typedef long long ll;

const int  N = 2e5 + 12, MOD = (int)1e9 + 7;

int n, m, a[N], vis[N], timer;
vector<int> g[N], gt[N];
bool is[N];
vector<vector<int>> dist;
int f(int d) {
    vector<int> D(n + 1, 0);
    timer++;
    vis[d] = timer;
    int lst = d;
    queue<int> q;
    q.push(d);
    while(!q.empty()) {
        int v = q.front();
        lst = v;
        q.pop();
        for(int to : g[v]) {
            if(vis[to] != timer) {
                D[to] = D[v] + 1;
                q.push(to);
                vis[to] = timer;
            }
        }
    }
    dist.push_back(D);
    return lst;
}
int dep[N], mxd[N], res[N], d, d1, o, cr;
int zap = 0;
bool ok[N];
void dfs(int v, int pr = -1) {
    mxd[v] = dep[v];
    for(int to:g[v]) if(to != pr) {
        gt[v].push_back(to);
        dep[to] = dep[v] + 1;
        dfs(to, v);
        if(ok[to]) ok[v] = 1;
        mxd[v] = max(mxd[v], mxd[to]);
    }
    for(int i = 0; i < (int)gt[v].size(); i++) {
        if(mxd[gt[v][i]] == mxd[v]) {
            swap(gt[v][0], gt[v][i]);
        }
    }
    if(v == d) ok[v] = 1;
}
int b = 17, it = 0, cur = 0, ver[N];
int up[N][18];
struct node{
    node *l = 0, *r = 0;
    int sum = 0;
    node(){};
    node(int v) {
        sum = v;
    }
    node (node *L, node *R) {
        l = L;
        r = R;
        sum = l->sum + r->sum;
    }
};
using pnode = node *;
pnode tr[N];    
pnode build(int tl = 1, int tr = m) {
    if(tl == tr) {
        return new node();
    }
    int tm = (tl + tr) >> 1;
    return new node(build(tl, tm), build(tm + 1, tr));
}
pnode upd(int pos, pnode v, int tl = 1, int tr = m) {
    if(tl == tr) {
        return new node(1);
    }
    int tm = (tl + tr) >> 1;
    if(pos <= tm) 
        return new node(upd(pos, v->l, tl, tm), v->r);
    return new node(v->l, upd(pos, v->r, tm + 1, tr));
}
void go(int v) {
    if(dist[cr][v] > dist[o][v] || (dist[cr][v] == dist[o][v] && zap)) {
        int f = cur, val = -mxd[v] + dep[v] * 2;
        set<int> r;
        if(dep[ver[f]] >= val) {
            for(int i = b - 1; i >= 0; i--) {
                int nv = ver[up[f][i]];
                if(dep[nv] >= val) {
                    f = up[f][i];
                }
            }
            f = up[f][0];
        }
        res[v] += tr[f]->sum;
    }
    if(gt[v].empty()) return;
    int sz = (int)gt[v].size();
    vector<int> p(sz), s(sz);
    p[0] = mxd[gt[v][0]];
    s[sz - 1] = mxd[gt[v][sz - 1]];
    for(int i = 1; i < sz; i++) {
        p[i] = max(p[i - 1], mxd[gt[v][i]]);
    }
    for(int i = sz - 2; i >= 0; i--) {
        s[i] = max(s[i + 1], mxd[gt[v][i]]);
    }
    vector<int> del;
    int bf = cur;
    for(int i = 0; i < sz; i++) {
        int to = gt[v][i];
        int mx = dep[v];
        if(i) mx = max(mx, p[i - 1]);
        if(i < sz - 1) mx = max(mx, s[i + 1]);
        mx -= dep[v];
        if(i == 1) {
            cur = up[cur][0];
        }
        if(i <= 1 && dep[v] - dep[ver[cur]] <= mx) {
            for(int i = b - 1; i >= 0; i--) {
                int nv = up[cur][i];
                if(dep[v] - dep[ver[nv]] <= mx) {
                    cur = nv;
                }
            }
            cur = up[cur][0];
        }
        if(i <= 1) {
            it++;
            ver[it] = v;
            up[it][0] = cur;
            tr[it] = upd(a[v], tr[cur]);
            for(int i = 1; i < b; i++) {
                up[it][i] = up[up[it][i - 1]][i - 1];
            }
            cur = it;
        }
        go(to);
    }
    cur = bf;
}
void solve(int root) {
    it = cur = 0;
    for(int i = 1; i <= n; i++) {
        gt[i].clear();
    }
    ver[0] = 0;
    dep[0] = -(int)1e9;
    tr[0] = build();
    dep[root] = 1;
    dfs(root);

    go(root);

}
void test() {
    cin >> n >> m;
    for(int i = 1; i <= n - 1; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    d = f(1), d1 = f(d);
    f(d1);
    o = 2;cr = 1;
    solve(d);
    zap = 1;
    o = 1;cr = 2;
    solve(d1);
    for(int i = 1; i <= n; i++) {
        cout << res[i] << '\n';
    }

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t = 1; 
    // cin >> t;

    while(t--) 
        test();
}

詳細信息

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 0ms
memory: 19988kb

input:

2 1
1 2
1 1

output:

1
1

result:

ok 2 lines

Test #2:

score: 4
Accepted
time: 3ms
memory: 21528kb

input:

1842 848
740 1093
1299 922
801 1560
265 1664
1043 65
1430 427
80 233
4 1238
1623 1473
1569 274
953 1485
1259 649
1671 1409
246 542
742 1517
720 1120
1527 1328
1167 1531
1056 1130
673 1222
192 980
1393 913
446 688
135 23
1065 1787
978 1481
1765 1720
310 202
1406 1451
475 523
104 774
1531 829
169 396
...

output:

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

result:

ok 1842 lines

Test #3:

score: 4
Accepted
time: 0ms
memory: 21320kb

input:

951 908
777 679
676 510
34 425
424 889
78 4
924 408
151 905
399 942
606 776
275 332
616 900
513 372
911 130
465 430
126 303
380 603
506 505
592 38
917 270
435 815
591 773
63 66
417 642
301 693
814 454
735 671
899 674
925 846
254 898
845 569
703 659
707 241
482 715
646 282
274 925
861 374
699 488
903...

output:

302
286
491
486
478
563
380
32
497
563
115
30
581
428
510
491
374
565
242
418
469
550
410
229
499
386
274
588
487
276
279
536
445
203
483
56
565
361
129
140
533
437
229
68
442
559
570
502
493
212
588
96
330
405
262
526
464
516
258
541
554
264
475
441
544
476
406
222
468
397
531
591
406
39
320
198
60...

result:

ok 951 lines

Test #4:

score: 4
Accepted
time: 0ms
memory: 21456kb

input:

1817 365
1516 74
1811 1805
1036 311
1769 1663
1029 473
1596 310
337 888
324 426
385 315
1780 1684
1750 794
895 1029
1108 1194
566 613
489 1230
1727 1520
170 302
731 1171
591 295
1165 1233
304 835
1607 404
1035 1675
158 735
1553 1764
1390 1078
197 980
1176 1626
16 1218
1530 1146
1692 1477
1513 574
32...

output:

0
129
0
0
0
224
1
203
0
0
0
0
229
0
239
0
1
0
0
0
162
0
0
0
0
113
1
0
0
0
0
200
208
0
218
0
2
0
72
0
161
0
0
195
0
0
0
33
0
132
0
0
1
0
146
118
147
0
66
0
0
70
240
177
0
165
0
4
0
1
3
68
243
2
1
2
0
1
0
0
230
208
0
250
12
3
195
0
69
0
0
6
1
114
218
0
0
199
0
0
0
0
1
27
157
1
0
0
0
1
0
163
1
0
1
168
...

result:

ok 1817 lines

Test #5:

score: 4
Accepted
time: 0ms
memory: 20532kb

input:

2000 5
1695 1417
623 8
1319 1473
329 1662
879 1654
108 555
1765 1258
1808 962
893 532
779 664
1507 1612
435 250
1645 349
666 992
921 24
1343 1974
50 1258
1497 2000
1156 1076
227 1921
413 543
737 294
218 554
1735 32
234 1718
1615 1126
1620 1915
1722 10
1031 871
871 674
626 1527
1792 148
101 1837
893 ...

output:

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

result:

ok 2000 lines

Test #6:

score: 4
Accepted
time: 6ms
memory: 21420kb

input:

2000 6
462 1865
693 166
1818 5
444 1736
1133 1670
1356 760
1732 919
1485 126
1655 1476
957 1185
343 1431
968 52
1595 764
1541 1498
1729 1457
558 387
1458 480
1199 1759
979 1230
512 700
278 1058
1894 496
191 1524
411 103
415 1628
1524 715
41 1128
291 1115
1599 1613
114 1990
564 1439
805 1273
504 1051...

output:

6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
...

result:

ok 2000 lines

Test #7:

score: 4
Accepted
time: 0ms
memory: 18796kb

input:

2000 3
246 351
568 1925
1167 1934
847 1223
1203 894
1076 1886
1394 1834
704 1777
1483 1744
40 963
619 509
1738 212
1498 77
286 144
1946 456
626 647
1653 658
1216 1418
29 1320
754 1874
667 1585
457 589
1784 1793
1788 1104
488 818
1452 224
1259 1855
653 1931
1253 1413
1352 227
1919 122
1675 563
767 19...

output:

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

result:

ok 2000 lines

Test #8:

score: 4
Accepted
time: 0ms
memory: 20808kb

input:

2000 8
1053 321
1821 1638
946 445
1686 570
532 192
1306 987
70 1362
1564 1337
737 1540
1686 1533
1776 1864
1212 1891
476 1618
1031 815
883 939
1487 177
1659 1116
794 434
473 1040
1867 1424
108 1095
1788 1612
791 937
958 1545
161 1053
1594 1053
668 1900
918 1270
889 1119
635 1747
1126 271
420 551
572...

output:

1
1
2
2
2
1
4
1
3
2
2
3
1
1
1
1
1
3
2
3
1
2
1
1
3
2
1
1
1
2
2
3
1
1
2
2
2
3
3
2
2
3
3
1
1
1
1
2
1
3
1
4
1
1
1
2
2
4
2
2
3
4
3
1
1
2
3
1
2
1
1
2
1
2
1
3
2
3
3
2
1
4
1
2
2
1
3
1
1
2
1
3
2
3
2
2
2
1
3
2
1
2
2
3
4
1
4
2
2
2
1
2
2
3
1
3
1
2
1
3
1
2
2
2
3
1
1
1
1
2
3
1
2
1
3
2
1
2
1
1
2
1
1
1
2
3
2
3
2
1
...

result:

ok 2000 lines

Test #9:

score: 4
Accepted
time: 3ms
memory: 20664kb

input:

2000 10
1446 902
516 588
381 360
1588 766
1162 1333
951 1610
567 1665
329 998
527 1126
1770 1847
156 925
305 384
704 831
171 888
387 1139
450 904
341 1897
999 617
1643 1611
894 1636
57 1221
993 459
660 826
1336 1639
37 652
734 871
950 1234
254 1561
151 675
1585 230
1255 595
92 321
1711 913
1986 231
...

output:

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

result:

ok 2000 lines

Test #10:

score: 4
Accepted
time: 6ms
memory: 20860kb

input:

2000 4
1037 1229
171 1052
87 746
329 1413
1527 1925
1120 349
208 1815
535 1430
432 102
634 707
490 334
1139 933
1492 1110
907 1412
1480 197
324 926
1324 565
1638 937
1122 1238
823 87
387 1159
1261 1829
715 295
1822 1058
1595 1596
1525 1416
288 364
110 1536
137 68
807 85
376 165
33 76
1495 1172
780 6...

output:

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

result:

ok 2000 lines

Test #11:

score: 4
Accepted
time: 6ms
memory: 20804kb

input:

2000 9
203 1192
632 234
1825 844
1559 1036
596 742
33 1345
1254 1183
1592 1737
886 760
836 50
793 1955
115 1040
1067 1943
153 456
1819 1456
1563 1366
664 209
583 1574
1120 1737
1385 1354
852 284
945 1668
225 1963
341 928
1351 979
479 1652
1353 1333
1907 1933
1487 21
1737 600
1913 395
1336 888
338 32...

output:

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

result:

ok 2000 lines

Test #12:

score: 4
Accepted
time: 5ms
memory: 20124kb

input:

2000 6
1425 1140
781 2
1556 1112
1953 1556
475 1556
1019 251
1556 543
1556 1186
1556 983
273 1556
1556 1783
1963 1340
1645 1556
1556 300
1556 1551
1556 346
525 1556
1556 1289
1556 1257
1556 1729
1556 974
1556 888
1556 1738
1556 716
315 1556
1220 1556
1556 353
1001 1469
1556 1335
1556 374
1556 1263
1...

output:

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

result:

ok 2000 lines

Test #13:

score: 4
Accepted
time: 3ms
memory: 20992kb

input:

2000 5
1443 1122
821 1362
1348 1904
268 600
502 241
1837 820
622 355
413 684
527 314
1648 822
1702 1812
299 194
1553 1040
265 863
892 1789
1979 329
341 11
169 207
845 960
1592 323
1408 350
982 1569
1704 1561
1091 1759
471 1354
1782 1730
1992 779
1171 782
752 955
80 1938
770 304
333 1094
1329 1655
98...

output:

5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
1
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
4
5
5
5
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
...

result:

ok 2000 lines

Test #14:

score: 4
Accepted
time: 3ms
memory: 18476kb

input:

2000 1
1230 354
1787 355
1656 683
905 469
1820 1452
101 369
1502 355
754 356
659 355
511 1462
705 471
251 442
1711 355
1973 925
650 822
1934 1160
1358 995
1571 818
355 115
1076 1336
487 355
108 570
774 731
355 1849
1349 1398
490 1168
31 1670
1874 29
699 347
355 1684
272 355
22 1960
643 874
355 1722
...

output:

1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
0
0
1
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
1
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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
0
1
1
...

result:

ok 2000 lines

Test #15:

score: 4
Accepted
time: 6ms
memory: 20716kb

input:

2000 10
1292 134
1644 1008
144 364
765 709
1671 1188
1624 1836
390 900
913 1540
719 1691
295 259
534 1316
1360 296
1228 387
386 1355
1546 1095
1412 1102
141 1266
1267 1198
1292 1300
1030 424
1146 1848
596 886
542 1522
951 1952
671 628
763 1220
1222 231
1944 963
1431 1769
792 959
1046 1292
1292 383
1...

output:

1
10
0
1
10
10
1
10
1
0
0
10
10
0
0
10
2
10
0
6
1
1
1
10
10
0
0
1
10
0
0
0
10
10
0
8
1
1
0
10
10
1
10
10
1
0
1
10
10
1
0
0
0
1
0
10
10
10
1
0
9
0
10
9
10
0
0
0
10
10
1
10
10
1
0
1
10
1
0
10
1
10
0
10
10
0
2
2
0
1
1
10
9
10
10
10
10
10
1
10
10
10
0
10
10
10
1
1
0
1
0
0
10
0
1
10
0
10
1
10
10
1
10
0
0...

result:

ok 2000 lines

Test #16:

score: 4
Accepted
time: 0ms
memory: 18380kb

input:

2000 5
305 900
106 900
577 900
900 1017
900 631
134 900
900 1402
900 1652
1324 900
164 900
559 900
900 1342
900 1734
1125 900
824 900
1246 900
291 900
1190 900
900 1782
900 1195
900 1043
584 900
900 1741
900 1965
1188 900
900 1844
900 1264
900 581
900 845
900 1931
900 1326
1877 900
900 1255
900 894
...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 2000 lines

Test #17:

score: 4
Accepted
time: 0ms
memory: 20700kb

input:

2000 4
1890 1838
1103 1956
1614 260
1512 571
85 1838
1838 148
233 169
1838 58
1838 1946
1838 445
1494 1263
1407 301
100 1912
1418 1975
1627 270
1128 1838
674 1867
1752 1668
1268 1651
82 215
999 146
1838 548
250 1543
1274 1838
305 1838
1838 844
1751 1498
1906 10
543 163
122 1838
660 1655
1838 1576
85...

output:

4
4
1
1
1
4
1
4
4
4
4
4
4
4
1
4
1
1
4
4
4
1
4
4
1
4
4
4
4
4
1
4
1
4
4
4
4
4
4
4
1
4
4
4
4
1
4
4
4
4
1
1
4
1
1
1
4
1
4
4
4
4
4
1
4
1
4
4
1
1
4
4
4
4
4
4
1
4
4
1
4
4
4
1
1
1
4
4
1
4
4
4
4
4
4
4
1
1
4
4
4
1
1
4
4
1
4
1
1
4
4
1
4
4
1
1
1
1
4
4
4
1
4
1
4
4
1
4
1
4
4
1
4
4
1
4
4
4
1
1
4
4
4
4
4
4
4
1
4
4
...

result:

ok 2000 lines

Test #18:

score: 4
Accepted
time: 0ms
memory: 19116kb

input:

2000 2
1032 289
236 1488
1762 128
1926 580
349 922
835 1988
835 1377
1112 1586
341 998
635 387
1835 1723
1029 835
1303 1914
314 1481
1662 430
1314 1152
1212 926
554 523
361 949
1924 1477
154 1799
835 1283
324 23
835 1482
321 540
1320 1820
835 1485
835 200
1927 504
1725 1006
220 656
835 1007
364 1717...

output:

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

result:

ok 2000 lines

Test #19:

score: 4
Accepted
time: 3ms
memory: 21356kb

input:

2000 619
1215 1416
174 1576
1559 1503
514 651
1484 1539
1217 1121
752 485
512 719
1010 1903
926 1242
882 309
844 485
1295 460
115 1504
38 1130
1000 1990
1389 57
219 1493
579 1797
281 1347
224 782
1295 1793
224 278
221 1227
300 1686
990 1266
1643 181
1028 1861
803 1762
304 1976
1554 1042
420 1742
180...

output:

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

result:

ok 2000 lines

Test #20:

score: 4
Accepted
time: 3ms
memory: 20512kb

input:

2000 1589
398 1883
874 1438
1025 159
759 1551
206 670
1074 1873
1807 1108
242 1785
719 1380
15 1405
24 804
668 1287
362 181
1471 1396
1813 101
987 1259
1499 471
1283 221
1641 416
1128 1595
497 1235
170 1034
1579 1430
1522 1085
58 419
1517 1503
638 808
760 946
1773 1014
1441 305
1390 1925
1077 37
142...

output:

719
690
800
868
923
972
712
690
587
433
236
105
331
467
293
866
845
284
908
842
437
668
555
38
416
937
554
93
1002
432
935
859
298
650
998
812
871
562
990
895
1029
598
758
117
1075
781
895
962
1124
731
334
709
106
1081
242
634
1032
936
574
1018
708
163
1092
508
913
1076
1065
797
1005
1048
1040
995
4...

result:

ok 2000 lines

Test #21:

score: 4
Accepted
time: 3ms
memory: 22300kb

input:

2000 1174
1718 1701
1663 1817
990 1332
1638 1283
870 674
249 719
430 853
490 287
621 378
501 1386
66 1713
1794 1811
1455 873
998 910
1998 1968
1103 619
726 42
1184 577
1348 204
1567 1700
632 990
1661 1845
1967 1125
728 1178
1361 560
681 1867
130 139
1983 1380
1484 620
1159 1412
989 1065
109 1354
101...

output:

1
0
0
6
139
0
1
252
0
321
8
144
0
0
0
1
1
2
0
0
67
368
374
274
3
115
0
343
1
0
0
0
30
0
315
0
134
205
213
170
0
250
168
0
398
0
327
0
0
0
0
0
0
1
263
0
378
247
1
0
1
0
3
0
288
236
0
0
0
0
310
0
328
79
0
0
0
391
0
0
0
301
228
0
269
0
391
0
0
0
332
4
0
206
0
317
111
313
71
236
0
0
281
0
193
1
1
0
0
19...

result:

ok 2000 lines

Test #22:

score: 4
Accepted
time: 3ms
memory: 22932kb

input:

2000 144
1589 315
1662 685
726 522
959 721
1420 1935
1591 1075
687 1198
538 3
1410 428
363 1984
621 928
1494 773
325 1051
500 538
669 853
1960 839
318 160
1358 62
637 1323
88 624
1850 538
538 1616
1719 1701
700 1350
117 538
2000 1821
314 1828
1832 1889
1120 1243
1631 1849
939 1758
531 95
390 538
825...

output:

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

result:

ok 2000 lines

Test #23:

score: 4
Accepted
time: 3ms
memory: 21792kb

input:

2000 1539
610 682
1567 1833
455 673
1603 1799
211 138
1579 1009
1441 335
1472 116
1802 1558
256 1034
1176 930
1607 1868
937 1762
1866 1088
54 352
201 411
244 1374
253 324
1048 1554
1197 1284
935 1300
374 1562
1609 1792
1576 1240
805 1997
925 1563
1951 1035
1431 401
1846 1342
809 1304
335 1113
1229 1...

output:

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

result:

ok 2000 lines

Test #24:

score: 4
Accepted
time: 3ms
memory: 23256kb

input:

2000 519
1773 1636
553 814
1028 682
317 1210
1168 13
206 173
1498 1425
1663 1246
1165 1262
1618 134
375 9
1998 546
1415 670
432 1363
1435 1017
400 1395
323 1614
169 906
284 146
776 549
24 58
1001 1552
563 1898
1638 1180
1135 1449
15 1074
1649 1557
1094 1643
527 241
24 1545
1274 1200
1968 1187
1004 9...

output:

4
4
12
3
4
16
3
4
12
4
12
3
3
6
2
10
5
4
3
13
2
4
3
3
3
3
12
3
10
2
3
4
2
3
8
5
10
10
11
2
3
4
10
14
3
3
11
5
3
7
3
13
2
4
3
6
6
3
11
2
13
4
2
5
3
6
12
13
6
3
14
10
4
8
3
3
5
2
13
14
9
3
6
4
3
6
11
2
6
6
4
3
5
2
4
14
4
12
5
2
5
11
5
4
5
2
2
12
4
3
10
11
3
3
10
13
3
6
7
12
6
3
6
4
12
4
3
4
6
4
3
3
13...

result:

ok 2000 lines

Test #25:

score: 4
Accepted
time: 0ms
memory: 21252kb

input:

2000 568
1955 1424
1169 799
1607 1094
1731 805
1542 349
38 1167
1030 463
1127 222
1326 328
1183 1140
1914 1363
1945 347
1333 1127
1007 625
1086 869
62 153
140 541
1533 693
1442 996
984 1362
1245 785
1771 140
749 940
1535 1351
1279 1372
1148 1570
162 1579
386 416
1324 1641
252 93
45 1823
1467 1190
17...

output:

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

result:

ok 2000 lines

Test #26:

score: 4
Accepted
time: 0ms
memory: 20324kb

input:

2000 460
1762 905
1762 593
903 1762
1038 1762
1026 1762
1762 1974
16 851
1762 214
751 1271
1762 1868
1762 1011
1762 815
1762 1983
1345 1762
1762 1955
1134 625
1762 1723
1762 740
419 1956
1762 434
1148 1762
1762 233
39 1762
1189 1762
444 1762
541 1762
1762 1918
1762 1010
1762 601
1591 1762
1913 1762
...

output:

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

result:

ok 2000 lines

Test #27:

score: 4
Accepted
time: 3ms
memory: 20196kb

input:

2000 1870
195 1081
1072 11
706 155
1893 180
236 761
1895 1174
1239 1526
547 1716
1944 304
153 719
620 1064
739 1506
491 1514
679 1415
384 1562
1826 36
550 446
560 505
1993 359
984 1761
327 4
96 461
513 809
732 991
240 53
7 1707
54 330
1768 602
1493 134
496 1577
610 187
1545 1976
1223 221
1447 1916
5...

output:

535
753
351
85
815
175
371
516
101
464
154
13
528
277
244
321
283
768
449
313
219
666
797
388
1
93
776
155
302
771
272
683
634
93
645
484
365
728
368
779
759
634
86
599
582
713
700
47
534
296
9
25
96
10
368
345
133
315
372
661
397
783
636
696
736
660
231
62
462
162
174
102
356
797
302
771
728
760
14...

result:

ok 2000 lines

Test #28:

score: 4
Accepted
time: 3ms
memory: 21552kb

input:

2000 1091
1068 386
1827 1070
1001 1488
808 125
397 1056
1838 1342
1163 1626
839 567
672 1780
740 1626
1718 897
288 101
1086 1049
1626 1839
1946 372
1530 227
1030 1592
1626 1780
1828 1709
1626 55
1351 390
260 666
1626 1046
621 680
1047 1626
176 1626
1538 1287
1004 272
1187 292
273 1440
1857 310
1973 ...

output:

428
194
2
449
574
314
187
451
441
374
703
2
379
75
400
89
179
3
601
1
2
383
141
288
289
192
2
455
252
162
59
507
402
2
696
2
81
97
2
153
95
2
2
93
277
2
2
673
427
115
700
84
517
2
1
2
589
153
2
583
2
373
19
2
187
505
629
262
384
15
561
125
351
659
2
579
2
459
694
378
673
29
2
2
577
28
2
334
403
241
...

result:

ok 2000 lines

Test #29:

score: 4
Accepted
time: 7ms
memory: 21740kb

input:

2000 1959
377 463
1434 1542
343 638
567 1086
1626 1251
342 28
841 785
835 557
638 1562
541 1291
1224 638
1973 422
1602 341
1643 1875
638 1034
15 1128
1729 638
654 1491
384 1876
370 638
70 1986
1315 1467
675 1894
1980 1549
1822 1451
1230 638
1138 496
900 217
1947 470
1548 727
211 1141
136 1193
1322 1...

output:

2
45
0
1
278
0
0
222
0
78
2
0
0
0
1
0
0
235
0
0
0
281
1
116
0
0
2
234
1
228
3
0
0
0
0
0
1
0
232
225
194
0
263
1
1
0
0
68
209
0
1
0
1
0
206
1
98
112
236
57
0
44
0
28
2
62
0
123
0
0
202
0
91
0
43
1
0
211
165
0
195
0
4
1
0
0
1
0
11
0
1
163
1
148
2
136
1
250
302
126
1
2
168
98
1
143
200
65
45
1
0
0
1
1
...

result:

ok 2000 lines

Test #30:

score: 4
Accepted
time: 0ms
memory: 20128kb

input:

2000 492
235 1628
1289 1628
468 1628
1628 667
1628 220
1628 973
1628 92
172 1628
1628 882
1628 1260
1628 316
1628 1055
1628 1213
1987 1628
1628 136
1156 1628
1628 282
1276 1628
974 1628
1628 1772
1628 1214
229 1628
419 1628
1628 1031
873 1628
636 1628
165 1628
182 1628
567 1628
1403 1628
779 1628
75...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 2000 lines

Test #31:

score: 4
Accepted
time: 3ms
memory: 19252kb

input:

2000 266
115 1606
1219 795
108 49
1606 965
1114 166
1005 1645
744 1671
538 1354
1606 267
230 1465
1872 599
1784 172
431 1601
1737 474
1606 334
821 1172
86 520
1606 1235
1709 1044
72 838
1015 914
649 1606
627 1030
1051 1606
1528 1340
1606 1185
1695 1774
1187 1606
13 691
1329 1366
1606 500
1606 567
16...

output:

1
263
258
1
259
120
158
1
1
1
1
245
79
264
263
1
1
26
1
244
162
239
1
231
202
1
133
1
1
254
1
1
1
212
218
1
1
245
231
257
81
245
1
261
1
254
4
258
248
1
1
165
1
249
135
185
262
258
188
231
202
255
1
1
1
1
263
10
1
188
130
264
1
123
1
1
1
240
1
1
195
261
256
1
1
123
254
1
1
1
182
1
1
258
1
249
1
1
1
...

result:

ok 2000 lines

Test #32:

score: 4
Accepted
time: 0ms
memory: 21628kb

input:

2000 1192
34 1120
699 1974
440 726
1440 1321
1709 1305
946 1419
1927 915
1023 1686
226 1037
1607 646
448 613
189 1233
448 496
657 1092
1911 777
1977 1012
714 1637
1604 306
820 1992
1047 1803
1805 448
344 1164
448 535
448 1558
629 185
7 448
52 859
1161 1575
1556 1787
902 524
643 1673
94 438
1236 459
...

output:

1
142
0
397
0
224
1
0
250
0
264
0
0
0
0
1
301
0
94
3
0
181
307
0
1
1
40
1
0
0
120
1
248
26
66
0
98
116
1
0
1
212
1
0
0
0
1
0
381
1
284
134
1
372
0
0
1
251
0
276
157
1
349
118
1
1
0
1
0
319
1
0
0
172
1
0
0
383
1
1
0
358
126
305
1
105
0
1
0
0
0
0
9
188
282
292
125
48
1
0
324
1
0
1
0
362
1
314
0
370
33...

result:

ok 2000 lines

Subtask #2:

score: 32
Accepted

Test #33:

score: 32
Accepted
time: 99ms
memory: 40052kb

input:

115391 1
32067 50006
1710 5850
21016 66364
72998 34367
24783 10670
49950 93666
81835 81234
53480 68963
87357 43320
93905 30509
72528 92224
520 100511
54804 2917
58490 23858
93643 87530
90737 65205
60740 110812
9553 90266
70028 67222
108045 88982
35584 110286
53518 21733
108735 26404
108228 109796
92...

output:

1
1
0
1
0
1
1
0
1
1
1
1
1
1
1
1
1
0
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
0
0
1
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
0
1
1
0
1
1
1
1
1
1
1
1
0
1
0
1
1
0
1
1
1
1
1
0
1
1
1
1
0
1
1
0
1
0
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 115391 lines

Test #34:

score: 32
Accepted
time: 196ms
memory: 75896kb

input:

114976 1
74053 36053
62978 89255
32367 21913
113882 44280
60815 35782
107811 95272
109039 78845
22484 41688
1781 111596
111506 59375
19869 45586
84990 81214
38638 90205
14928 14370
10758 5465
87745 5949
66720 6357
76134 26466
91805 105936
31792 68220
74216 108462
60158 67410
69489 50297
74956 63776
...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 114976 lines

Test #35:

score: 32
Accepted
time: 24ms
memory: 29972kb

input:

28388 1
10509 15648
25863 14495
26973 2553
22819 7801
5054 15080
6091 12384
4727 3538
14600 14672
4481 9533
26520 23761
6729 3525
15678 8426
7628 26890
25846 26267
10186 5633
21692 25057
17882 26693
25518 13361
6875 371
27786 23632
24474 21637
1387 8015
22050 3422
8420 25752
26814 7209
11499 21112
5...

output:

1
1
1
0
1
0
0
0
0
0
0
1
0
0
0
0
1
0
1
1
1
1
0
1
1
0
0
1
1
1
0
1
0
1
0
1
1
1
0
1
0
1
1
1
0
1
1
0
1
0
1
1
0
0
0
1
0
1
0
0
1
0
0
1
1
0
1
1
1
1
0
1
1
0
1
1
1
0
0
1
1
0
1
0
0
1
1
0
1
0
0
0
0
1
0
1
1
0
0
0
1
0
1
0
0
1
1
0
1
1
0
0
0
0
1
1
0
1
1
0
0
0
0
1
1
0
0
1
1
1
1
0
1
0
0
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
...

result:

ok 28388 lines

Test #36:

score: 32
Accepted
time: 184ms
memory: 56488kb

input:

200000 1
17564 189544
118109 130056
39153 56739
138814 48828
103560 16598
174399 8469
146229 189678
173046 95721
168793 168656
21067 78280
169301 178753
63496 153947
22754 181712
34926 22205
41248 16310
81136 35768
87905 3442
89999 119217
108408 136055
153855 175444
177272 157293
174568 5857
71023 5...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #37:

score: 32
Accepted
time: 392ms
memory: 116932kb

input:

200000 1
35713 32997
199904 59024
24108 108224
75623 8060
169202 44171
166898 189166
52691 184504
91052 94474
3355 161889
76684 4006
13328 59307
83889 5391
139095 198059
194946 197068
147175 102095
68329 10784
45563 111710
123071 177610
156268 186570
149699 52604
191299 78685
68117 130476
132359 860...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #38:

score: 32
Accepted
time: 274ms
memory: 87520kb

input:

200000 1
15065 142612
651 173717
153862 68423
150849 147717
192561 152722
165359 180378
34627 59508
140908 24495
180671 177962
183330 27822
155654 53394
20596 1741
76236 52151
167441 5306
73654 149981
97720 142937
10793 84081
124721 123748
185212 150311
170407 158310
125015 73861
36456 121189
39975 ...

output:

1
0
1
1
0
0
1
0
0
0
0
0
0
0
1
0
0
1
1
0
1
1
1
1
0
0
1
0
0
0
0
1
0
1
1
1
0
1
0
1
1
0
1
1
0
1
0
1
1
1
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
1
1
1
1
1
1
1
0
1
0
1
1
1
1
0
1
1
0
1
1
0
0
1
0
0
1
1
0
0
0
0
0
0
0
0
1
0
1
0
0
1
1
0
1
1
0
1
0
0
0
1
1
1
1
0
0
0
1
0
0
0
1
0
0
0
1
1
1
1
0
1
0
0
1
1
0
0
0
1
...

result:

ok 200000 lines

Test #39:

score: 32
Accepted
time: 175ms
memory: 52864kb

input:

200000 1
86027 61282
69968 35175
136022 154753
52733 39599
97774 24158
25263 138562
112124 6412
183205 101112
112094 38819
113526 47859
137031 122132
165018 84375
76900 182974
29302 174006
34918 73123
23660 37001
141115 33742
61282 24152
150734 61282
22552 49677
106054 193519
84741 62724
6470 178907...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #40:

score: 32
Accepted
time: 195ms
memory: 60680kb

input:

200000 1
28426 75100
141794 24004
167055 168353
178427 10860
34348 190354
192106 81422
75263 134731
54229 108154
90586 122196
172392 58237
84932 15421
79435 77253
185144 24679
63387 23340
68674 72825
137398 109447
33249 46900
99738 44920
92707 125920
163133 64180
83887 123053
152655 83838
133345 953...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #41:

score: 32
Accepted
time: 201ms
memory: 59260kb

input:

200000 1
69183 39245
163717 95756
76286 79561
100403 156730
144012 28043
198819 127959
64878 40226
57715 170431
64896 172859
44376 76276
154716 52042
193460 121983
98422 173076
114307 113862
51895 51986
193923 26201
116458 6275
6786 5649
175035 64551
148902 26238
129547 45157
151907 50571
76031 8614...

output:

1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
0
0
0
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
1
1
1
1
1
0
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
0
0
1
1
0
1
1
0
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
0
1
0
1
0
1
1
1
0
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #42:

score: 32
Accepted
time: 211ms
memory: 59084kb

input:

200000 1
196045 146636
176533 42271
166724 196028
139244 76615
148314 148067
178418 115890
192238 183829
32675 57585
185089 143473
101515 59837
190250 186401
150802 188721
50798 191609
47863 142815
183786 28970
184954 58810
13430 196707
133210 193546
49302 49747
109810 162864
98935 133593
169908 210...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #43:

score: 32
Accepted
time: 83ms
memory: 33276kb

input:

200000 1
58527 148510
90024 104304
46291 148510
148510 193006
51631 148510
148510 117266
148510 53357
166103 148510
148510 127112
148510 105363
148510 171703
56809 148510
148510 60920
164837 148510
148510 181377
67076 148510
148510 94358
8910 148510
43101 148510
148510 64867
148510 46788
148510 4249...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
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
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #44:

score: 32
Accepted
time: 346ms
memory: 91220kb

input:

200000 1
66730 123320
47115 79350
85283 171708
156551 17983
140238 171549
93983 190883
146694 145897
48194 48325
186569 69965
165293 107104
105458 137156
117295 132479
49962 144513
135589 103731
120064 134791
163864 155625
175728 67758
190171 179156
102382 51967
50807 154114
8247 142134
101115 87765...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #45:

score: 32
Accepted
time: 283ms
memory: 78992kb

input:

200000 1
119243 17471
67473 185473
190254 145264
53666 71426
9704 176027
198823 89774
71677 118558
159294 5996
185413 50972
191335 108317
37995 17944
145264 181582
159163 179684
129331 153479
109731 88138
42760 145264
145264 60498
145264 128517
142009 99861
97187 193109
58740 36290
25804 155500
1772...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #46:

score: 32
Accepted
time: 260ms
memory: 79652kb

input:

200000 1
180791 170350
48720 135071
182635 17624
64784 50175
87186 159402
159402 66047
160362 52459
124401 33646
32003 80049
87225 130074
159402 154274
25488 50341
70872 198001
159175 3485
95007 34608
179653 31222
41151 186981
62308 59184
161512 53729
198034 28649
95823 130252
159402 123739
16422 11...

output:

1
1
1
1
1
1
0
0
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
1
0
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #47:

score: 32
Accepted
time: 73ms
memory: 30852kb

input:

200000 1
78129 101331
31692 78129
78129 108968
173678 78129
78129 193716
78129 108185
78129 153059
19448 78129
78129 159448
78129 56603
103258 78129
51678 78129
151290 78129
78129 195380
174479 78129
12931 78129
150607 78129
113935 78129
157004 78129
78129 22638
78129 140760
137800 78129
78129 16451...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #48:

score: 32
Accepted
time: 288ms
memory: 90736kb

input:

200000 1
166243 176626
72675 120076
174047 145754
74966 144274
16524 38961
169628 41061
107629 128678
52336 144274
128129 144274
78204 144274
144274 64980
108790 32439
27043 51977
106796 109356
164139 144274
85737 17025
174536 152580
4863 50617
144274 16825
144274 144369
144274 124976
181247 51097
1...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 200000 lines

Test #49:

score: 32
Accepted
time: 244ms
memory: 84428kb

input:

200000 1
120958 155316
149423 10108
115797 62195
102476 192436
162724 195049
138522 47257
60272 15129
74064 169985
15504 93511
172244 101053
40670 60272
60272 125017
51824 61439
136524 7174
168447 66399
170627 141660
67971 173187
111804 29595
163654 33473
153084 1690
60451 11738
133054 181387
14573 ...

output:

0
0
0
1
1
0
1
0
0
1
1
1
1
1
0
1
0
1
0
1
0
1
1
1
0
0
1
0
1
1
1
0
0
1
1
1
0
1
1
1
0
0
1
1
1
1
1
1
1
1
0
0
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
0
1
1
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
1
1
1
0
1
1
1
1
0
1
1
0
1
1
1
0
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
0
0
1
1
1
1
1
1
1
1
0
1
...

result:

ok 200000 lines

Subtask #3:

score: 0
Memory Limit Exceeded

Test #50:

score: 32
Accepted
time: 302ms
memory: 216396kb

input:

157976 157976
20171 157173
44732 54119
107845 121149
109200 110309
82678 108206
89140 64200
36916 128759
3966 123760
92978 105716
43700 146126
14924 3429
107721 36095
94906 78173
97162 29552
119574 39605
25145 138492
16622 99431
60281 7949
76176 136644
75716 91518
127987 110605
77999 110960
101187 5...

output:

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

result:

ok 157976 lines

Test #51:

score: 0
Memory Limit Exceeded

input:

191205 191205
92326 99995
188142 63029
71973 50899
68069 72878
159479 103397
143191 93854
27574 146981
63427 186167
104978 177629
22355 188155
184293 15184
101908 143833
111535 144687
112209 61685
59401 128258
97717 87496
168079 130237
49319 190230
119632 98368
76193 184597
22790 136093
1080 80811
1...

output:

33816
135610
162660
131426
190598
61940
182394
60206
64348
110918
188484
7222
137922
180624
16470
93248
10468
114842
68032
166390
123722
186038
67156
83116
49318
25192
173746
73986
142500
173072
102348
118504
80854
27648
134168
50044
59926
32322
46458
177450
48524
8924
13134
77972
122644
120576
1412...

result:


Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%