QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#533524#1139. StationsQwerty12325 48ms4072kbC++231.2kb2024-08-26 02:33:192024-08-26 02:33:20

Judging History

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

  • [2024-08-26 02:33:20]
  • 评测
  • 测评结果:5
  • 用时:48ms
  • 内存:4072kb
  • [2024-08-26 02:33:19]
  • 提交

stations

#include "stations.h"

#include <bits/stdc++.h>

#include <cassert>
#include <vector>

constexpr int N = 1e3;

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
    std::vector<std::vector<int>> gr(n);
    for (int i = 0; i < n - 1; i++) {
        gr[u[i]].push_back(v[i]);
        gr[v[i]].push_back(u[i]);
    }
    std::vector<int> res(n);
    auto dfs = [&](auto dfs, int v, int f, int d, int& e) -> void {
        for (int t : gr[v]) {
            if (t != f) {
                dfs(dfs, t, v, d + 1, e);
            }
        }
        res[v] = e++;
    };
    int e = 0;
    for (int i = 0; i < n; i++) {
        if (gr[i].size() == 1) {
            dfs(dfs, i, -1, 0, e);
            break;
        }
    }

    return res;
}

int find_next_station(int s, int dest, std::vector<int> c) {
    assert(s != dest);
    for (int to : c) {
        if (to == dest) {
            return to;
        }
    }
    if (c.size() == 1) {
        return c.front();
    }
    for (int t : c) {
        if (s <= t && t <= dest || dest <= t && t <= s) {
            return t;
        }
    }

    assert(false);
}


詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 36ms
memory: 3724kb

input:

0
10
10 1000
4 5
9 0
2 6
5 2
8 3
1 4
8 1
6 0
3 7
3 1000
0 1
1 2
998 1000
166 178
393 452
389 179
622 429
892 866
872 18
899 227
835 637
587 769
504 386
369 577
65 441
523 17
803 221
878 321
637 892
696 473
16 146
840 322
495 986
353 275
330 585
831 402
719 810
704 830
780 940
53 901
894 911
394 482
...

output:

10
1
6
3
8
5
4
2
9
7
0
3
2
1
0
998
779
774
832
986
489
181
632
628
865
883
668
468
917
210
389
931
550
727
317
478
134
418
563
310
595
288
279
35
179
677
790
158
196
296
21
658
543
890
151
90
742
991
690
974
683
34
757
892
624
519
410
858
88
425
413
94
993
861
732
529
799
119
876
754
839
957
921
834...

input:

1
59784
1 0 1
0
268 180 2
267
269
1 0 1
0
696 379 2
695
697
0 1 1
1
0 1 1
1
1 0 1
0
67 886 2
66
68
1 3 2
0
2
3 2 1
2
51 167 2
50
52
2 3 2
1
3
971 359 2
970
972
868 199 2
867
869
619 746 2
618
620
429 125 2
428
430
1 0 1
0
92 58 2
91
93
1 0 2
0
2
1 0 1
0
78 905 2
77
79
0 1 1
1
533 882 2
532
534
1 0 1...

output:

0
267
0
695
1
1
0
68
2
2
52
3
970
867
620
428
0
91
0
0
79
1
534
0
1
6
1
1
2
519
1
722
1
2
59
1
607
7
4
2
2
508
550
610
10
318
816
105
447
85
1
521
699
1
1
1
1
188
1
3
2
1
607
456
65
34
933
3
1
715
292
747
582
1
412
63
1
1
855
0
1
332
1
433
1
24
837
276
2
2
2
1
44
3
1
267
410
338
1
158
211
375
1
761
...

result:

ok 

Test #2:

score: 5
Accepted
time: 24ms
memory: 3856kb

input:

0
10
999 1000
235 825
647 906
541 62
613 565
578 619
248 881
769 526
994 607
456 840
66 498
55 390
563 846
932 717
568 140
443 49
369 210
721 37
431 796
632 398
861 25
724 153
403 851
688 315
803 191
213 469
339 674
166 517
236 859
67 199
867 510
804 372
820 443
628 483
835 200
692 488
295 42
5 140
...

output:

999
874
15
282
578
30
423
171
668
395
978
324
887
129
407
428
862
146
635
642
877
749
816
876
810
19
32
346
737
393
435
857
478
335
535
599
267
351
317
507
600
835
108
453
871
115
580
480
181
54
516
176
701
595
17
638
544
856
225
156
792
81
605
739
448
657
663
60
79
576
430
76
368
84
572
72
254
682
...

input:

1
50048
326 936 2
325
327
123 444 2
122
124
242 895 2
241
243
99 262 2
98
100
349 799 2
348
350
165 773 2
164
166
62 711 2
61
63
240 644 2
239
241
196 227 2
195
197
190 774 2
189
191
120 455 2
119
121
52 86 2
51
53
763 961 2
762
764
449 896 2
448
450
757 850 2
756
758
948 671 2
947
949
844 965 2
843...

output:

327
124
243
100
350
166
63
241
197
191
121
53
764
450
758
947
845
21
486
884
636
824
253
768
597
705
522
450
509
361
863
595
467
282
966
456
384
485
653
193
393
772
586
680
95
421
448
767
900
42
666
16
708
550
595
391
14
611
489
400
549
950
597
576
975
926
303
739
760
740
746
245
64
59
750
925
930
6...

result:

ok 

Test #3:

score: 5
Accepted
time: 48ms
memory: 3852kb

input:

0
10
2 1000
1 0
2 1000
0 1
2 1000
0 1
2 1000
0 1
2 1000
0 1
2 1000
0 1
2 1000
0 1
2 1000
1 0
2 1000
1 0
2 1000
0 1

output:

2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0

input:

1
100000
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
0 1...

output:

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

result:

ok 

Test #4:

score: 5
Accepted
time: 42ms
memory: 3792kb

input:

0
10
3 1000
2 1
0 1
3 1000
0 1
2 1
3 1000
2 1
0 1
3 1000
2 0
2 1
3 1000
2 0
1 0
3 1000
2 0
0 1
3 1000
1 0
2 1
3 1000
1 2
0 1
3 1000
0 1
1 2
3 1000
2 0
0 1

output:

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

input:

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

output:

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

result:

ok 

Test #5:

score: 5
Accepted
time: 36ms
memory: 4060kb

input:

0
10
4 1000
0 2
3 1
0 3
4 1000
3 1
3 0
2 1
4 1000
2 0
1 3
3 0
4 1000
0 3
1 2
2 3
4 1000
1 2
0 1
2 3
4 1000
1 3
2 0
2 3
4 1000
1 3
1 0
3 2
4 1000
3 0
1 0
2 1
4 1000
3 2
0 1
3 1
4 1000
1 2
1 0
2 3

output:

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

input:

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

output:

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

result:

ok 

Test #6:

score: 5
Accepted
time: 24ms
memory: 3848kb

input:

0
10
1000 1000
387 293
176 887
976 264
923 398
736 598
406 187
658 331
596 105
514 857
33 784
81 15
194 397
768 286
406 42
586 521
503 384
663 326
451 514
658 489
849 120
531 769
428 756
81 283
14 519
359 542
807 685
707 278
738 700
865 839
728 657
166 155
980 440
364 448
879 37
833 524
358 421
458 ...

output:

1000
275
683
440
554
201
561
428
884
512
379
933
499
324
730
217
820
475
928
283
259
557
89
71
449
255
930
469
656
728
329
945
285
707
110
450
980
813
844
936
703
894
121
454
153
967
733
232
485
267
838
331
661
639
21
929
412
299
999
935
567
797
528
986
857
968
355
147
597
799
527
402
106
338
108
92...

input:

1
50055
124 462 2
123
125
56 51 2
55
57
722 655 2
721
723
958 571 2
957
959
361 768 2
360
362
555 177 2
554
556
126 56 2
125
127
969 269 2
968
970
995 688 2
994
996
47 469 2
46
48
599 544 2
598
600
780 594 2
779
781
161 119 2
160
162
365 479 2
364
366
413 280 2
412
414
500 517 2
499
501
437 544 2
43...

output:

125
55
721
957
362
554
125
968
994
48
598
779
160
366
412
501
438
267
545
69
743
881
934
640
850
1
913
329
277
692
71
463
824
690
876
756
890
904
461
704
216
65
388
649
51
548
372
536
666
609
137
339
491
607
577
394
768
598
64
869
936
964
57
759
202
457
379
804
915
986
413
42
61
526
960
263
57
344
6...

result:

ok 

Test #7:

score: 5
Accepted
time: 32ms
memory: 3768kb

input:

0
1
1000 1000
502 584
460 198
192 539
565 266
519 363
448 97
907 459
427 458
694 915
546 555
23 843
177 257
733 258
98 274
983 648
708 132
685 763
616 357
880 61
772 108
967 710
238 549
117 105
737 775
495 935
586 688
808 121
970 747
798 332
958 750
58 830
829 120
34 964
168 357
886 646
241 920
100 ...

output:

1000
251
610
902
821
901
721
32
832
273
80
865
646
950
221
855
381
957
480
555
853
473
558
361
237
305
846
549
457
531
95
4
755
156
590
188
825
774
633
258
409
59
652
241
732
517
640
14
506
242
873
486
823
758
25
327
96
407
302
290
941
955
682
894
989
534
52
672
239
432
887
903
742
366
376
935
60
56...

input:

1
50046
780 438 2
779
781
131 517 2
130
132
950 500 2
949
951
135 181 2
134
136
228 574 2
227
229
384 253 2
383
385
395 741 2
394
396
121 992 2
120
122
371 203 2
370
372
181 87 2
180
182
7 890 2
6
8
72 42 2
71
73
249 36 2
248
250
502 488 2
501
503
965 429 2
964
966
56 232 2
55
57
977 143 2
976
978
7...

output:

779
132
949
136
229
383
396
122
370
180
8
71
248
501
964
57
976
71
698
375
170
350
947
627
896
458
910
35
567
532
974
609
615
327
27
764
342
874
217
327
501
668
341
960
335
675
667
786
474
764
95
519
827
66
254
569
265
916
200
883
425
566
517
105
75
684
986
698
557
503
165
961
689
869
226
668
338
85...

result:

ok 

Test #8:

score: 5
Accepted
time: 0ms
memory: 4072kb

input:

0
10
4 1000
0 1
1 2
2 3
4 1000
0 1
1 3
3 2
4 1000
0 2
2 1
1 3
4 1000
0 2
2 3
3 1
4 1000
0 3
3 1
1 2
4 1000
0 3
3 2
2 1
4 1000
1 0
0 2
2 3
4 1000
1 0
0 3
3 2
4 1000
1 2
2 0
0 3
4 1000
1 3
3 0
0 2

output:

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

input:

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

output:

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

result:

ok 

Test #9:

score: 5
Accepted
time: 2ms
memory: 4052kb

input:

0
10
6 1000
0 1
1 2
2 3
3 4
4 5
6 1000
0 1
1 2
2 3
3 5
5 4
6 1000
0 1
1 2
2 4
4 3
3 5
6 1000
0 1
1 2
2 4
4 5
5 3
6 1000
0 1
1 2
2 5
5 3
3 4
6 1000
0 1
1 2
2 5
5 4
4 3
6 1000
0 1
1 3
3 2
2 4
4 5
6 1000
0 1
1 3
3 2
2 5
5 4
6 1000
0 1
1 3
3 4
4 2
2 5
6 1000
0 1
1 3
3 4
4 5
5 2

output:

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

input:

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

output:

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

result:

ok 

Test #10:

score: 5
Accepted
time: 0ms
memory: 3788kb

input:

0
3
3 1000
0 1
1 2
3 1000
0 2
2 1
3 1000
1 0
0 2

output:

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

input:

1
18
1 2 2
0
2
1 0 2
0
2
0 1 1
1
0 2 1
1
1 0 2
0
2
1 2 2
0
2
0 2 1
1
0 2 1
1
2 1 1
1
1 0 2
0
2
2 0 1
1
2 0 1
1
0 1 1
1
2 1 1
1
2 1 1
1
2 0 1
1
1 2 2
0
2
0 1 1
1

output:

2
0
1
1
0
2
1
1
1
0
1
1
1
1
1
1
2
1

result:

ok 

Subtask #2:

score: 0
Stage 2: Program stations Runtime Error

Test #11:

score: 0
Stage 2: Program stations Runtime Error

input:

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

output:

996
511
510
767
254
509
766
895
126
253
381
508
638
765
894
959
62
125
189
252
317
380
444
507
574
637
701
764
830
893
958
975
30
61
93
124
157
188
220
251
285
316
348
379
412
443
475
506
542
573
605
636
669
700
732
763
798
829
861
892
926
957
983
974
14
29
45
60
77
92
108
123
141
156
172
187
204
21...

input:


output:


result:


Subtask #3:

score: 0
Stage 2: Program stations Runtime Error

Test #17:

score: 16
Accepted
time: 36ms
memory: 3768kb

input:

0
10
2 1000000
1 0
997 1000000
830 513
223 672
727 200
763 415
581 440
34 42
267 325
912 693
753 59
401 289
198 641
982 214
41 49
453 107
940 806
905 732
153 482
248 405
102 79
480 837
534 620
564 856
679 178
278 247
899 206
333 672
297 308
407 863
26 752
272 178
204 603
208 10
715 562
785 285
184 5...

output:

2
1
0
997
133
384
560
711
204
433
658
424
513
169
792
247
110
763
617
589
60
116
178
49
294
618
315
570
305
26
803
921
753
532
105
155
208
473
738
508
529
359
215
839
46
290
737
368
272
721
940
902
638
289
405
245
431
863
435
867
50
931
742
848
719
701
745
996
146
67
484
13
933
768
135
705
175
995
1...

input:

1
59859
4 0 2
3
5
0 1 1
1
0 1 1
1
968 914 2
967
969
705 603 2
704
706
265 863 2
264
266
1 0 1
0
7 5 2
6
8
877 671 2
876
878
1 0 1
0
1 0 1
0
0 1 1
1
1 0 2
0
2
99 307 2
98
100
628 786 2
627
629
488 496 2
487
489
2 6 2
1
3
0 1 1
1
426 636 2
425
427
31 18 2
30
32
555 581 2
554
556
614 235 2
613
615
21 4...

output:

3
1
1
967
704
266
0
6
876
0
0
1
0
100
629
489
3
1
427
30
556
613
22
19
0
827
638
808
1
1
754
5
541
2
1
1
628
673
791
0
507
812
10
357
1
2
80
588
22
0
771
2
541
325
80
954
0
33
2
1
1
4
4
59
395
169
39
2
679
7
731
659
67
2
430
1
134
245
0
280
1
931
480
0
0
291
0
624
0
306
60
7
1
1
731
2
1
0
604
0
95
1...

result:

ok 

Test #18:

score: 16
Accepted
time: 32ms
memory: 3772kb

input:

0
10
999 1000000
719 816
256 855
722 661
705 575
610 707
632 426
296 99
891 512
445 475
76 601
63 756
576 934
73 186
606 363
702 69
48 768
568 128
904 82
223 805
146 382
922 467
347 433
959 614
709 998
296 4
544 64
165 989
856 470
370 230
239 810
911 976
728 952
162 752
682 305
511 782
113 37
576 41...

output:

999
800
987
171
77
254
574
459
603
51
806
385
820
952
453
880
594
483
551
802
79
190
544
64
31
274
192
258
111
426
284
979
759
902
56
290
339
951
515
293
137
8
291
746
634
443
625
329
955
587
956
624
49
784
26
88
233
984
912
565
302
753
569
9
845
264
787
762
960
867
697
898
202
738
949
933
129
884
2...

input:

1
50048
209 621 2
208
210
594 739 2
593
595
183 139 2
182
184
649 229 2
648
650
324 929 2
323
325
524 217 2
523
525
23 243 2
22
24
925 715 2
924
926
802 24 2
801
803
953 531 2
952
954
270 615 2
269
271
226 74 2
225
227
983 547 2
982
984
112 498 2
111
113
753 781 2
752
754
94 912 2
93
95
726 247 2
72...

output:

210
595
182
648
325
523
24
924
801
952
271
225
982
113
754
95
725
66
653
305
345
764
379
314
129
329
488
486
539
505
153
186
291
338
29
577
864
250
440
329
51
342
157
802
230
577
642
556
496
465
36
471
890
935
228
777
170
164
340
134
450
866
791
357
613
904
823
866
961
937
91
958
453
186
864
64
642
...

result:

ok 

Test #19:

score: 16
Accepted
time: 40ms
memory: 4056kb

input:

0
10
2 1000000
0 1
2 1000000
0 1
2 1000000
1 0
2 1000000
0 1
2 1000000
1 0
2 1000000
0 1
2 1000000
1 0
2 1000000
1 0
2 1000000
1 0
2 1000000
1 0

output:

2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0

input:

1
100000
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
0 1 1
1
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
1 0 1
0
0 1...

output:

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

result:

ok 

Test #20:

score: 16
Accepted
time: 40ms
memory: 3768kb

input:

0
10
3 1000000
1 0
0 2
3 1000000
2 0
0 1
3 1000000
2 1
2 0
3 1000000
2 0
2 1
3 1000000
0 1
1 2
3 1000000
1 0
1 2
3 1000000
2 0
2 1
3 1000000
0 1
2 1
3 1000000
2 1
0 1
3 1000000
0 2
2 1

output:

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

input:

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

output:

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

result:

ok 

Test #21:

score: 16
Accepted
time: 36ms
memory: 3852kb

input:

0
10
4 1000000
0 1
2 3
0 2
4 1000000
2 1
3 1
0 2
4 1000000
3 1
3 0
1 2
4 1000000
1 3
2 1
0 2
4 1000000
1 2
1 3
0 3
4 1000000
1 0
1 2
0 3
4 1000000
3 0
0 2
2 1
4 1000000
0 1
2 0
1 3
4 1000000
2 0
0 1
2 3
4 1000000
2 1
3 0
3 1

output:

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

input:

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

output:

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

result:

ok 

Test #22:

score: 16
Accepted
time: 32ms
memory: 3768kb

input:

0
10
1000 1000000
526 757
286 227
877 883
484 370
847 13
425 107
166 745
276 357
746 21
304 131
462 834
317 58
942 423
375 631
977 908
229 838
549 167
518 60
51 772
419 970
909 386
362 829
470 46
218 986
82 787
919 307
947 691
348 900
233 650
253 762
90 850
144 627
954 103
602 268
187 746
568 992
31...

output:

1000
276
632
623
387
986
551
962
225
360
72
392
800
496
491
34
111
389
669
562
179
317
523
646
377
945
918
96
91
193
57
176
125
6
366
247
403
75
412
531
714
427
987
304
660
740
344
89
677
644
848
322
337
947
86
30
261
839
723
547
393
54
371
38
22
483
678
475
233
379
418
137
436
828
443
501
197
630
7...

input:

1
50050
216 18 2
215
217
231 229 2
230
232
176 709 2
175
177
90 774 2
89
91
2 706 2
1
3
362 425 2
361
363
163 696 2
162
164
687 952 2
686
688
617 462 2
616
618
735 4 2
734
736
306 379 2
305
307
849 447 2
848
850
735 288 2
734
736
828 938 2
827
829
601 751 2
600
602
456 571 2
455
457
326 867 2
325
32...

output:

215
230
177
91
3
363
164
688
616
734
307
848
734
829
602
457
327
686
259
117
544
700
846
732
433
407
396
762
497
336
75
925
36
936
382
689
321
394
109
258
414
654
947
278
417
811
750
422
201
127
857
965
403
494
536
509
248
418
587
541
730
852
394
667
844
146
5
828
737
254
997
404
14
643
122
569
773
...

result:

ok 

Test #23:

score: 16
Accepted
time: 32ms
memory: 4068kb

input:

0
1
1000 1000000
622 589
830 829
709 500
278 363
20 230
963 181
768 29
857 332
787 757
897 285
480 939
855 617
959 84
687 755
667 30
553 1
213 98
987 780
47 851
107 764
130 863
326 832
872 636
85 159
119 330
672 210
134 576
224 282
570 387
53 941
723 69
694 642
707 49
260 390
525 768
78 273
811 220
...

output:

1000
234
956
370
96
168
564
925
824
230
123
759
223
805
875
932
996
44
656
511
145
142
796
249
900
789
533
387
326
171
722
312
634
58
227
841
882
712
979
259
50
46
195
858
333
705
674
122
48
345
389
726
917
383
364
649
355
683
682
523
51
629
607
687
289
165
148
78
257
260
467
933
502
362
401
392
898...

input:

1
50053
445 346 2
444
446
619 812 2
618
620
182 31 2
181
183
877 522 2
876
878
568 667 2
567
569
896 784 2
895
897
39 832 2
38
40
490 523 2
489
491
693 388 2
692
694
410 575 2
409
411
19 35 2
18
20
794 747 2
793
795
840 208 2
839
841
189 781 2
188
190
758 782 2
757
759
125 920 2
124
126
227 165 2
22...

output:

444
620
181
876
569
895
40
491
692
411
20
793
839
190
759
126
226
916
920
439
393
646
751
616
612
518
100
669
85
292
260
799
958
700
885
403
746
483
758
47
709
175
844
985
607
694
196
447
236
378
681
508
539
682
350
929
213
606
666
866
313
439
26
115
274
192
581
656
852
23
245
434
834
779
731
775
78...

result:

ok 

Test #24:

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

input:

0
10
4 1000000
0 1
1 2
2 3
4 1000000
0 1
1 3
3 2
4 1000000
0 2
2 1
1 3
4 1000000
0 2
2 3
3 1
4 1000000
0 3
3 1
1 2
4 1000000
0 3
3 2
2 1
4 1000000
1 0
0 2
2 3
4 1000000
1 0
0 3
3 2
4 1000000
1 2
2 0
0 3
4 1000000
1 3
3 0
0 2

output:

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

input:

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

output:

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

result:

ok 

Test #25:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #26:

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

input:

0
3
3 1000000
0 1
1 2
3 1000000
0 2
2 1
3 1000000
1 0
0 2

output:

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

input:

1
18
2 0 1
1
2 1 1
1
1 0 2
0
2
2 0 1
1
0 2 1
1
1 0 2
0
2
0 2 1
1
0 2 1
1
2 1 1
1
1 2 2
0
2
2 1 1
1
1 2 2
0
2
2 0 1
1
0 1 1
1
0 1 1
1
1 2 2
0
2
0 1 1
1
1 0 2
0
2

output:

1
1
0
1
1
0
1
1
1
2
1
2
1
1
1
2
1
0

result:

ok 

Test #27:

score: 16
Accepted
time: 38ms
memory: 3772kb

input:

0
10
4 1000000
2 1
1 0
3 2
4 1000000
1 2
0 1
1 3
4 1000000
1 0
2 0
0 3
4 1000000
1 3
1 0
2 0
4 1000000
3 2
0 3
3 1
4 1000000
0 1
1 3
2 1
4 1000000
0 1
0 3
3 2
4 1000000
0 3
1 2
0 2
4 1000000
0 2
3 2
2 1
4 1000000
2 0
2 3
0 1

output:

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

input:

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

output:

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

result:

ok 

Test #28:

score: 0
Stage 2: Program stations Runtime Error

input:

10
1000 1000000
802 637
810 172
802 781
109 293
802 724
488 524
73 802
802 312
108 985
802 594
305 802
802 620
382 747
841 535
802 690
987 387
269 559
201 219
982 319
228 802
802 977
291 962
657 597
69 757
321 555
825 299
802 694
363 827
802 265
475 796
600 891
802 16
802 116
487 167
150 335
175 593...

output:

1000
198
273
473
549
933
803
609
333
999
955
219
653
319
435
391
650
14
819
654
54
482
619
118
384
701
476
415
434
43
387
812
344
625
382
288
923
181
299
183
906
76
212
646
517
932
639
498
854
512
18
32
490
700
27
208
604
163
327
289
519
53
222
220
674
947
451
734
769
733
834
200
915
427
4
360
417
5...

input:


output:


result:


Subtask #4:

score: 0
Stage 2: Program stations Runtime Error

Test #34:

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

input:

0
10
2 1000000000
0 1
2 1000000000
0 1
2 1000000000
1 0
2 1000000000
1 0
2 1000000000
0 1
2 1000000000
1 0
2 1000000000
1 0
2 1000000000
0 1
2 1000000000
0 1
2 1000000000
0 1

output:

2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0

input:

1
100000
0 1 1
1
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
0 1 1
1
0 1 1
1
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
0 1...

output:

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

result:

ok 

Test #35:

score: 10
Accepted
time: 26ms
memory: 4068kb

input:

0
10
3 1000000000
2 1
2 0
3 1000000000
1 0
2 0
3 1000000000
2 0
0 1
3 1000000000
0 2
1 2
3 1000000000
1 2
1 0
3 1000000000
1 0
2 1
3 1000000000
0 2
1 2
3 1000000000
1 2
1 0
3 1000000000
0 2
1 0
3 1000000000
2 0
1 2

output:

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

input:

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

output:

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

result:

ok 

Test #36:

score: 10
Accepted
time: 36ms
memory: 3856kb

input:

0
10
4 1000000000
3 1
2 0
1 0
4 1000000000
0 3
1 2
3 1
4 1000000000
3 1
0 2
0 1
4 1000000000
2 1
2 3
1 0
4 1000000000
3 1
0 1
2 3
4 1000000000
0 1
3 0
2 3
4 1000000000
2 0
3 0
1 2
4 1000000000
0 2
2 3
1 3
4 1000000000
3 2
2 1
3 0
4 1000000000
2 3
3 0
0 1

output:

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

input:

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

output:

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

result:

ok 

Test #37:

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

input:

0
10
4 1000000000
0 1
1 2
2 3
4 1000000000
0 1
1 3
3 2
4 1000000000
0 2
2 1
1 3
4 1000000000
0 2
2 3
3 1
4 1000000000
0 3
3 1
1 2
4 1000000000
0 3
3 2
2 1
4 1000000000
1 0
0 2
2 3
4 1000000000
1 0
0 3
3 2
4 1000000000
1 2
2 0
0 3
4 1000000000
1 3
3 0
0 2

output:

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

input:

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

output:

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

result:

ok 

Test #38:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #39:

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

input:

0
3
3 1000000000
0 1
1 2
3 1000000000
0 2
2 1
3 1000000000
1 0
0 2

output:

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

input:

1
18
1 0 2
0
2
1 2 2
0
2
1 2 2
0
2
0 2 1
1
0 1 1
1
2 1 1
1
0 1 1
1
0 2 1
1
1 0 2
0
2
1 2 2
0
2
2 0 1
1
2 0 1
1
2 0 1
1
2 1 1
1
0 1 1
1
0 2 1
1
2 1 1
1
1 0 2
0
2

output:

0
2
2
1
1
1
1
1
0
2
1
1
1
1
1
1
1
0

result:

ok 

Test #40:

score: 10
Accepted
time: 40ms
memory: 3768kb

input:

0
10
4 1000000000
1 3
1 2
0 1
4 1000000000
2 3
3 0
1 3
4 1000000000
2 0
1 3
0 1
4 1000000000
1 2
3 1
1 0
4 1000000000
3 1
0 2
3 2
4 1000000000
2 0
2 1
2 3
4 1000000000
1 2
1 3
2 0
4 1000000000
0 2
2 3
2 1
4 1000000000
2 1
2 0
3 0
4 1000000000
3 0
3 2
1 0

output:

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

input:

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

output:

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

result:

ok 

Test #41:

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

input:

0
10
2 1000000000
1 0
2 1000000000
0 1
2 1000000000
1 0
2 1000000000
1 0
2 1000000000
1 0
2 1000000000
0 1
2 1000000000
1 0
2 1000000000
1 0
2 1000000000
1 0
2 1000000000
0 1

output:

2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0

input:

1
100000
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
1 0 1
0
1 0 1
0
0 1 1
1
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
0 1 1
1
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
0 1 1
1
0 1...

output:

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

result:

ok 

Test #42:

score: 10
Accepted
time: 40ms
memory: 3764kb

input:

0
10
3 1000000000
0 1
0 2
3 1000000000
0 1
0 2
3 1000000000
1 0
2 0
3 1000000000
1 0
0 2
3 1000000000
1 0
2 0
3 1000000000
1 0
2 0
3 1000000000
1 0
0 2
3 1000000000
1 0
2 0
3 1000000000
1 0
0 2
3 1000000000
0 1
0 2

output:

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

input:

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

output:

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

result:

ok 

Test #43:

score: 10
Accepted
time: 36ms
memory: 4056kb

input:

0
10
4 1000000000
0 1
2 0
1 3
4 1000000000
0 1
0 2
3 1
4 1000000000
0 1
0 2
3 1
4 1000000000
0 1
0 2
1 3
4 1000000000
0 1
0 2
3 1
4 1000000000
0 1
0 2
1 3
4 1000000000
0 1
0 2
3 1
4 1000000000
0 1
0 2
3 1
4 1000000000
1 0
0 2
1 3
4 1000000000
0 1
2 0
3 1

output:

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

input:

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

output:

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

result:

ok 

Test #44:

score: 0
Stage 2: Program stations Runtime Error

input:

10
7 1000000000
5 3
6 3
0 3
4 3
1 3
2 3
42
3 5 5
3 6 6
3 0 0
3 4 4
3 1 1
3 2 2
5 3 3
5 6 3
5 0 3
5 4 3
5 1 3
5 2 3
6 3 3
6 5 3
6 0 3
6 4 3
6 1 3
6 2 3
0 3 3
0 5 3
0 6 3
0 4 3
0 1 3
0 2 3
4 3 3
4 5 3
4 6 3
4 0 3
4 1 3
4 2 3
1 3 3
1 5 3
1 6 3
1 0 3
1 4 3
1 2 3
2 3 3
2 5 3
2 6 3
2 0 3
2 4 3
2 1 3
7 100...

output:

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

input:


output:


result:


Subtask #5:

score: 0
Stage 2: Program stations Runtime Error

Test #54:

score: 61
Accepted
time: 34ms
memory: 3764kb

input:

0
10
3 1000000000
1 0
2 1
998 1000000000
928 443
90 795
55 379
957 417
759 300
960 136
309 858
833 370
228 827
876 955
619 365
15 108
243 388
54 925
141 894
272 634
0 989
600 346
380 277
350 113
326 613
975 946
660 98
34 538
220 864
9 585
185 860
458 424
509 14
22 275
109 872
153 233
76 834
972 736
...

output:

3
2
1
0
998
794
662
681
283
77
934
367
64
781
470
976
312
761
282
366
117
968
922
76
846
612
883
249
437
423
856
979
49
633
363
739
51
377
181
460
740
558
278
201
715
806
498
36
137
455
442
58
214
742
885
720
870
570
848
790
702
224
463
843
803
621
342
544
304
648
868
371
188
438
187
810
821
41
113
...

input:

1
59797
1 0 2
0
2
772 866 2
771
773
0 1 1
1
15 48 2
14
16
725 78 2
724
726
2 3 2
1
3
2 0 2
1
3
676 380 2
675
677
54 456 2
53
55
575 725 2
574
576
1 0 1
0
743 751 2
742
744
637 634 2
636
638
747 553 2
746
748
1 2 2
0
2
329 931 2
328
330
484 82 2
483
485
74 60 2
73
75
1 0 2
0
2
824 354 2
823
825
57 89...

output:

0
773
1
16
724
3
1
675
55
576
0
744
636
746
2
330
483
73
0
823
58
1
2
437
983
94
166
51
345
0
2
785
230
1
257
68
888
12
31
1
1
0
257
275
1
887
304
866
455
1
0
40
779
2
4
244
685
0
19
2
0
524
5
6
399
619
2
889
743
90
96
321
801
644
824
149
0
77
18
391
1
926
1
2
2
373
545
590
0
2
883
1
1
439
0
0
500
8...

result:

ok 

Test #55:

score: 61
Accepted
time: 32ms
memory: 3768kb

input:

0
10
997 1000000000
210 799
337 790
66 160
541 810
854 650
948 726
189 923
593 566
649 647
907 215
598 271
78 173
820 920
364 470
435 553
634 846
276 104
203 761
874 954
20 983
946 834
365 933
37 641
811 497
970 551
42 389
59 52
747 45
35 291
534 616
284 677
215 83
741 600
549 680
58 500
495 489
664...

output:

997
731
977
976
669
139
590
78
673
789
642
24
843
973
172
434
400
737
596
240
120
308
792
917
313
341
183
90
664
70
638
469
391
140
657
429
242
43
124
630
837
118
608
517
280
859
836
65
553
137
509
585
883
529
540
20
984
325
115
348
528
840
268
699
643
167
548
889
712
283
165
114
132
798
314
725
662...

input:

1
50045
342 793 2
341
343
872 908 2
871
873
568 927 2
567
569
456 732 2
455
457
220 648 2
219
221
617 834 2
616
618
713 920 2
712
714
576 492 2
575
577
246 732 2
245
247
343 868 2
342
344
700 780 2
699
701
582 588 2
581
583
156 694 2
155
157
733 900 2
732
734
234 145 2
233
235
777 37 2
776
778
875 3...

output:

343
873
569
457
221
618
714
575
247
344
701
583
157
734
233
776
874
621
448
25
804
276
199
987
149
953
790
476
524
585
931
278
983
74
497
851
33
499
118
193
490
731
757
247
192
821
182
737
561
772
328
360
702
78
808
255
611
377
322
316
73
404
113
332
283
406
155
805
897
721
32
58
913
277
569
402
734...

result:

ok 

Test #56:

score: 61
Accepted
time: 48ms
memory: 3724kb

input:

0
10
2 1000000000
0 1
2 1000000000
0 1
2 1000000000
0 1
2 1000000000
0 1
2 1000000000
1 0
2 1000000000
0 1
2 1000000000
0 1
2 1000000000
1 0
2 1000000000
1 0
2 1000000000
1 0

output:

2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0

input:

1
100000
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
0 1 1
1
1 0 1
0
0 1 1
1
0 1 1
1
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
0 1 1
1
1 0 1
0
1 0 1
0
0 1 1
1
1 0 1
0
1 0 1
0
1 0 1
0
1 0 1
0
0 1 1
1
1 0...

output:

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

result:

ok 

Test #57:

score: 61
Accepted
time: 40ms
memory: 3848kb

input:

0
10
3 1000000000
0 2
1 0
3 1000000000
1 0
2 1
3 1000000000
2 1
0 1
3 1000000000
2 0
0 1
3 1000000000
0 1
2 1
3 1000000000
1 2
0 2
3 1000000000
0 2
2 1
3 1000000000
1 0
2 1
3 1000000000
0 2
0 1
3 1000000000
2 0
1 0

output:

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

input:

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

output:

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

result:

ok 

Test #58:

score: 61
Accepted
time: 28ms
memory: 3768kb

input:

0
10
4 1000000000
1 2
0 2
1 3
4 1000000000
3 0
1 2
0 1
4 1000000000
2 3
3 0
0 1
4 1000000000
2 3
1 2
0 3
4 1000000000
1 3
0 3
2 0
4 1000000000
3 0
3 2
1 0
4 1000000000
3 1
0 1
2 3
4 1000000000
1 0
3 0
1 2
4 1000000000
3 1
2 3
1 0
4 1000000000
0 1
3 0
1 2

output:

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

input:

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

output:

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

result:

ok 

Test #59:

score: 61
Accepted
time: 20ms
memory: 3796kb

input:

0
10
1000 1000000000
313 401
316 54
721 11
679 942
681 467
84 472
977 306
285 19
891 45
654 702
294 627
927 124
583 515
700 300
401 460
521 643
911 738
818 7
895 746
370 781
405 64
904 359
22 187
609 408
363 713
768 965
345 943
512 10
149 608
438 998
642 108
680 783
648 653
592 351
79 477
759 16
430...

output:

1000
496
280
884
316
446
490
110
944
618
882
45
365
552
960
641
186
494
317
40
907
321
975
5
767
466
790
768
103
373
161
874
600
78
67
728
396
862
486
967
292
453
703
719
503
439
652
589
524
240
155
151
627
258
670
879
42
832
216
990
35
226
53
346
499
756
329
261
942
348
406
891
845
913
850
766
999
...

input:

1
50038
381 368 2
380
382
321 290 2
320
322
129 562 2
128
130
81 200 2
80
82
380 22 2
379
381
765 832 2
764
766
47 309 2
46
48
470 757 2
469
471
608 654 2
607
609
389 556 2
388
390
460 908 2
459
461
388 780 2
387
389
32 295 2
31
33
686 100 2
685
687
775 201 2
774
776
347 67 2
346
348
317 283 2
316
3...

output:

380
320
130
82
379
766
48
471
609
390
461
389
33
685
774
346
316
72
171
314
331
482
976
800
657
151
839
377
953
80
728
284
131
686
972
590
810
809
716
340
433
948
59
187
630
488
166
344
289
379
694
218
414
923
904
79
27
757
233
100
913
722
102
323
874
580
765
129
107
323
403
827
49
568
246
298
830
6...

result:

ok 

Test #60:

score: 61
Accepted
time: 32ms
memory: 3768kb

input:

0
1
1000 1000000000
165 608
217 371
579 924
67 365
865 568
258 7
999 657
669 881
268 354
140 308
76 139
428 750
616 661
178 737
179 1
705 411
437 759
119 472
353 50
549 581
327 276
319 864
662 404
619 776
651 890
153 938
580 396
501 193
560 607
786 871
291 760
898 722
511 542
743 74
742 918
431 774
...

output:

1000
557
504
398
499
981
181
159
540
881
580
987
304
314
207
357
598
749
649
490
140
348
858
307
452
105
396
776
187
835
227
243
547
971
267
64
923
291
241
295
901
682
30
107
830
426
542
746
110
500
308
699
998
652
787
429
174
543
349
736
569
230
686
758
811
262
406
784
95
479
743
643
412
149
130
37...

input:

1
50048
542 487 2
541
543
780 50 2
779
781
222 596 2
221
223
160 532 2
159
161
565 81 2
564
566
134 72 2
133
135
739 498 2
738
740
517 852 2
516
518
553 14 2
552
554
667 841 2
666
668
372 992 2
371
373
158 639 2
157
159
709 310 2
708
710
356 965 2
355
357
30 85 2
29
31
189 315 2
188
190
395 266 2
39...

output:

541
779
223
161
564
133
738
518
552
668
373
159
708
357
31
190
394
161
686
880
113
329
926
685
555
65
481
144
977
44
117
688
710
442
859
9
334
366
955
762
956
616
861
819
216
26
903
725
731
736
186
432
361
920
224
641
49
305
814
507
329
799
387
449
761
743
584
297
799
857
408
65
224
521
69
673
801
7...

result:

ok 

Test #61:

score: 61
Accepted
time: 0ms
memory: 3772kb

input:

0
10
4 1000000000
0 1
1 2
2 3
4 1000000000
0 1
1 3
3 2
4 1000000000
0 2
2 1
1 3
4 1000000000
0 2
2 3
3 1
4 1000000000
0 3
3 1
1 2
4 1000000000
0 3
3 2
2 1
4 1000000000
1 0
0 2
2 3
4 1000000000
1 0
0 3
3 2
4 1000000000
1 2
2 0
0 3
4 1000000000
1 3
3 0
0 2

output:

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

input:

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

output:

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

result:

ok 

Test #62:

score: 61
Accepted
time: 0ms
memory: 3764kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #63:

score: 61
Accepted
time: 0ms
memory: 3860kb

input:

0
3
3 1000000000
0 1
1 2
3 1000000000
0 2
2 1
3 1000000000
1 0
0 2

output:

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

input:

1
18
1 2 2
0
2
2 1 1
1
1 0 2
0
2
2 1 1
1
0 2 1
1
2 1 1
1
1 2 2
0
2
1 2 2
0
2
0 1 1
1
0 1 1
1
1 0 2
0
2
2 0 1
1
2 0 1
1
2 0 1
1
0 1 1
1
1 0 2
0
2
0 2 1
1
0 2 1
1

output:

2
1
0
1
1
1
2
2
1
1
0
1
1
1
1
0
1
1

result:

ok 

Test #64:

score: 0
Stage 2: Program stations Runtime Error

input:

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

output:

997
511
510
767
254
509
766
895
126
253
381
508
638
765
894
959
62
125
189
252
317
380
444
507
574
637
701
764
830
893
958
975
30
61
93
124
157
188
220
251
285
316
348
379
412
443
475
506
542
573
605
636
669
700
732
763
798
829
861
892
926
957
983
974
14
29
45
60
77
92
108
123
141
156
172
187
204
21...

input:


output:


result: