QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#323727#1139. Stationsbachbeo2007100 ✓54ms4132kbC++201.1kb2024-02-10 12:37:402024-02-10 12:37:40

Judging History

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

  • [2024-02-10 12:37:40]
  • 评测
  • 测评结果:100
  • 用时:54ms
  • 内存:4132kb
  • [2024-02-10 12:37:40]
  • 提交

stations

#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
 
std::vector<int> label(int n, int k, std::vector<int> U, std::vector<int> V) {
	std::vector<int> labels(n);
    vector<vector<int>> edge(n);
    for(int i=0;i<n-1;i++){
        edge[U[i]].push_back(V[i]);
        edge[V[i]].push_back(U[i]);
    }
    int num=0;
    function<void(int,int,int)> dfs;
    dfs = [&](int u,int p,int d){
        if(d==0) labels[u]=num++;
        for(int v:edge[u]){
            if(v==p) continue;
            dfs(v,u,d^1);
        }
        if(d==1) labels[u]=num++;
    };
    dfs(0,-1,0);
	return labels;
}
 
int find_next_station(int s, int t, std::vector<int> c){
    sort(c.begin(),c.end());
    if(c.back()<s){
        c.push_back(s);
        for(int i=1;i<(int)c.size()-1;i++){
            if(t>=c[i] && t<c[i+1]) return c[i];
        }
        return c.front();
    }
    else{
        if(t>s && t<=c[0]) return c[0];
        for(int i=1;i<(int)c.size();i++){
            if(t>c[i-1] && t<=c[i]) return c[i];
        }
        return c.back();
    }
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 38ms
memory: 3816kb

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
0
7
2
6
3
8
9
5
4
1
3
0
2
1
998
0
995
192
115
363
517
924
922
43
52
942
842
69
713
413
76
883
244
449
847
675
817
326
763
310
752
468
590
518
269
213
687
706
756
597
937
336
163
532
653
979
106
953
121
266
625
229
162
920
348
813
179
652
395
401
655
107
41
974
343
10
548
170
985
30
89
71
191
388
...

input:

1
59784
0 1 1
1
574 618 2
842
843
0 1 1
1
848 310 2
151
152
2 1 1
1
1 0 1
0
0 1 1
1
742 153 2
674
675
1 0 2
2
3
0 3 1
3
474 416 2
525
526
9 2 2
0
2
223 888 2
195
196
934 400 2
65
66
732 49 2
112
113
285 437 2
714
715
0 1 1
1
69 52 2
76
77
2 1 2
0
1
0 1 1
1
647 63 2
568
569
1 0 1
0
37 862 2
570
571
0...

output:

1
842
1
152
1
0
1
674
3
3
526
2
195
66
112
714
1
77
1
1
568
0
571
1
2
307
1
0
0
348
24
861
1
9
93
0
405
27
8
3
9
168
579
998
18
767
895
475
80
80
2
43
150
1
2
2
1
614
2
2
0
0
726
194
467
6
242
0
0
351
450
234
131
0
216
272
2
1
991
1
1
470
2
87
2
11
81
570
9
9
9
2
1
2
1
170
217
473
2
383
394
312
0
80...

result:

ok 

Test #2:

score: 5
Accepted
time: 34ms
memory: 3900kb

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
0
445
296
148
422
649
523
103
635
926
275
992
502
641
223
6
364
755
116
997
812
29
875
32
447
421
264
806
634
655
866
198
605
705
737
571
613
596
691
137
855
383
664
873
495
147
197
528
410
179
349
788
735
446
118
165
9
550
359
41
478
740
807
213
766
769
407
477
149
222
399
253
395
151
401
310
9...

input:

1
50048
628 989 2
301
302
350 634 2
473
474
148 818 2
390
391
415 596 2
514
515
595 172 2
944
945
761 292 2
595
596
647 323 2
709
710
149 591 2
389
390
405 617 2
601
602
583 70 2
773
774
198 365 2
77
78
243 226 2
295
296
885 984 2
121
122
187 954 2
636
637
33 977 2
790
791
928 76 2
885
886
887 947 2...

output:

301
474
391
515
945
595
710
390
602
774
77
296
121
637
791
885
42
448
655
125
587
358
338
653
48
490
417
44
157
859
778
114
214
911
166
275
486
380
138
775
334
69
477
430
317
201
213
887
682
416
16
146
83
544
976
333
419
443
220
69
778
863
967
753
625
875
195
873
845
835
64
224
405
708
757
2
992
434...

result:

ok 

Test #3:

score: 5
Accepted
time: 50ms
memory: 3824kb

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

input:

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

output:

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

result:

ok 

Test #4:

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

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
0
2
1
3
0
2
1
3
0
2
1
3
0
1
2
3
0
2
1
3
0
2
1
3
0
2
1
3
0
2
1
3
0
2
1
3
0
2
1

input:

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

output:

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

result:

ok 

Test #5:

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

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
0
2
1
3
4
0
1
2
3
4
0
2
1
3
4
0
2
1
3
4
0
3
1
2
4
0
2
3
1
4
0
3
2
1
4
0
3
2
1
4
0
3
2
1
4
0
3
1
2

input:

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

output:

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

result:

ok 

Test #6:

score: 5
Accepted
time: 34ms
memory: 3904kb

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
0
204
642
585
761
143
648
420
606
52
329
112
700
497
753
452
100
398
4
732
141
817
826
87
734
397
97
534
498
27
335
5
216
917
637
372
269
440
394
214
415
801
635
785
346
229
978
105
728
443
28
193
182
851
327
656
12
362
330
146
261
598
369
291
378
40
788
161
262
126
661
915
693
916
400
658
931
...

input:

1
50055
296 127 2
420
421
585 531 2
528
529
565 254 2
287
288
383 148 2
341
342
738 173 2
376
377
985 796 2
429
430
274 309 2
400
401
740 121 2
770
771
753 911 2
757
758
361 572 2
313
314
226 654 2
626
627
865 958 2
645
646
418 397 2
256
257
91 148 2
725
726
69 722 2
655
656
506 514 2
5
6
127 636 2
...

output:

421
529
287
341
376
430
400
771
758
313
627
645
257
725
656
5
689
423
181
873
185
367
459
606
483
708
319
502
846
516
743
158
514
581
119
715
463
160
326
689
364
391
363
953
230
283
676
10
890
231
427
78
604
861
846
453
871
7
326
122
746
426
528
898
257
328
897
460
384
771
764
929
309
74
817
839
833...

result:

ok 

Test #7:

score: 5
Accepted
time: 34ms
memory: 4084kb

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
0
820
674
536
576
486
142
709
262
166
558
802
650
15
553
316
604
885
403
552
362
846
306
7
278
702
400
354
391
78
128
503
204
830
220
538
738
442
996
330
96
799
5
759
384
805
133
872
247
562
882
537
746
113
289
174
329
974
980
596
603
784
678
620
858
152
789
6
909
569
577
754
942
937
593
156
84...

input:

1
50046
735 906 2
515
516
60 384 2
191
192
650 875 2
600
601
58 35 2
193
194
240 838 2
11
12
933 252 2
317
318
323 496 2
927
928
65 629 2
186
187
311 24 2
939
940
35 82 2
216
217
122 680 2
129
130
162 147 2
89
90
1 144 2
250
251
874 881 2
376
377
608 340 2
642
643
154 242 2
97
98
614 54 2
636
637
16...

output:

515
192
600
194
11
317
927
187
940
216
130
90
250
376
643
97
637
90
776
313
211
950
599
439
677
896
670
108
409
859
638
430
433
289
112
743
954
688
17
289
376
791
296
645
293
463
459
732
888
743
78
385
539
159
998
410
258
667
226
567
338
842
384
73
88
783
632
776
404
377
43
606
470
560
239
791
956
5...

result:

ok 

Test #8:

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

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
0
3
1
2
4
0
3
2
1
4
0
1
3
2
4
0
2
3
1
4
0
1
2
3
4
0
2
1
3
4
0
1
3
2
4
0
1
2
3
4
0
1
2
3
4
0
1
3
2

input:

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

output:

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

result:

ok 

Test #9:

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

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
0
5
1
4
2
3
6
0
5
1
4
3
2
6
0
5
1
2
4
3
6
0
5
1
3
4
2
6
0
5
1
2
3
4
6
0
5
1
3
2
4
6
0
5
4
1
2
3
6
0
5
4
1
3
2
6
0
5
2
1
4
3
6
0
5
3
1
4
2

input:

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

output:

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

result:

ok 

Test #10:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Subtask #2:

score: 8
Accepted

Test #11:

score: 8
Accepted
time: 34ms
memory: 3820kb

input:

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

output:

996
0
511
995
1
256
512
767
128
255
383
510
639
766
894
994
2
65
129
192
257
320
384
447
513
576
640
703
768
831
895
958
33
64
96
127
160
191
223
254
288
319
351
382
415
446
478
509
544
575
607
638
671
702
734
765
799
830
862
893
926
957
978
993
3
18
34
49
66
81
97
112
130
145
161
176
193
208
224
23...

input:

1
50252
729 381 1
727
852 130 1
851
986 523 1
987
409 385 1
408
857 222 1
855
421 924 1
420
707 713 1
705
434 778 1
432
712 753 3
713
714
718
870 463 3
863
864
867
992 15 1
993
596 143 3
597
598
599
782 516 1
780
403 922 1
401
291 0 1
290
71 147 1
70
864 931 3
865
866
870
319 310 3
257
289
304
361 6...

output:

727
851
987
408
855
420
705
432
718
863
993
599
780
401
290
70
870
304
360
960
935
864
712
160
375
915
209
758
683
926
895
885
773
360
289
505
609
769
300
459
854
408
981
903
414
48
168
687
840
137
168
368
922
53
839
976
332
938
630
231
686
900
187
442
864
649
447
101
266
212
751
687
600
95
996
894
...

result:

ok 

Test #12:

score: 8
Accepted
time: 38ms
memory: 3816kb

input:

0
10
31 1000
0 1
0 2
3 1
4 1
2 5
6 2
7 3
3 8
4 9
4 10
11 5
5 12
13 6
6 14
15 7
16 7
17 8
18 8
9 19
20 9
10 21
22 10
11 23
11 24
12 25
26 12
13 27
28 13
14 29
14 30
128 1000
0 1
2 0
3 1
4 1
5 2
6 2
3 7
8 3
9 4
10 4
11 5
12 5
6 13
6 14
7 15
16 7
17 8
18 8
19 9
20 9
10 21
22 10
11 23
11 24
12 25
26 12
...

output:

31
0
15
30
1
8
16
23
4
7
11
14
19
22
26
29
2
3
5
6
9
10
12
13
17
18
20
21
24
25
27
28
128
0
64
127
1
33
65
96
17
32
48
63
80
95
111
126
2
10
18
25
34
41
49
56
66
73
81
88
97
104
112
119
6
9
13
16
21
24
28
31
37
40
44
47
52
55
59
62
69
72
76
79
84
87
91
94
100
103
107
110
115
118
122
125
3
5
7
8
11
1...

input:

1
59568
11 23 3
8
9
10
435 275 3
436
437
438
26 351 3
29
32
33
336 397 3
339
342
350
84 71 3
81
82
83
0 2 2
1
2
26 15 1
28
307 415 3
304
305
306
238 328 3
232
236
237
0 2 2
2
3
221 261 3
215
219
220
3 2 1
0
390 381 1
391
3 1 1
0
1 0 1
0
96 48 3
99
102
110
22 51 1
23
115 9 1
117
185 751 1
184
146 153...

output:

8
438
33
350
81
2
28
304
232
2
215
0
391
0
0
110
23
117
184
160
1
8
645
315
34
73
28
0
101
17
0
125
1
1
1
0
350
7
55
482
0
3
623
791
1
0
219
222
1
1
768
17
180
0
1
3
1
15
0
223
0
0
483
84
0
363
356
1
66
66
2
0
15
258
0
1
106
434
149
508
0
31
847
950
0
20
495
1
10
321
12
0
73
22
8
1
960
25
87
95
274
...

result:

ok 

Test #13:

score: 8
Accepted
time: 44ms
memory: 3816kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #14:

score: 8
Accepted
time: 34ms
memory: 3792kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #15:

score: 8
Accepted
time: 38ms
memory: 4116kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #16:

score: 8
Accepted
time: 34ms
memory: 3836kb

input:

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

output:

1000
0
511
999
1
256
512
767
128
255
383
510
639
766
894
998
2
65
129
192
257
320
384
447
513
576
640
703
768
831
895
958
33
64
96
127
160
191
223
254
288
319
351
382
415
446
478
509
544
575
607
638
671
702
734
765
799
830
862
893
926
957
982
997
3
18
34
49
66
81
97
112
130
145
161
176
193
208
224
2...

input:

1
50108
319 92 3
257
289
304
128 792 3
1
2
65
336 202 3
343
350
351
215 244 3
208
209
212
724 503 1
723
286 681 1
284
521 217 3
514
515
518
906 335 1
904
182 864 1
180
993 621 3
990
991
992
281 614 3
282
283
287
467 882 3
468
469
470
472 735 1
471
367 18 3
374
381
382
172 842 3
173
174
175
276 884 1...

output:

257
1
351
208
723
284
514
904
180
990
287
470
471
382
175
274
708
645
367
447
168
389
408
630
215
949
704
608
92
804
886
256
112
156
761
81
919
254
743
627
70
66
750
88
284
637
393
290
910
735
819
209
559
430
819
42
998
983
631
209
216
851
207
606
152
683
576
494
32
343
795
986
672
791
679
304
332
3...

result:

ok 

Subtask #3:

score: 16
Accepted

Test #17:

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

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
0
1
997
0
738
650
289
828
150
601
718
190
18
534
57
985
315
242
228
960
988
841
905
783
621
91
645
86
943
335
394
310
664
877
11
826
170
561
676
198
113
41
353
953
785
302
746
794
294
460
479
611
78
136
56
149
365
151
367
955
399
559
506
293
284
306
432
857
896
688
923
400
546
1
286
21
431
5
646
5...

input:

1
59859
5 3 2
0
1
1 0 1
0
1 0 1
0
984 957 2
15
16
194 245 2
899
900
135 434 2
867
868
0 1 1
1
6 0 2
8
9
61 164 2
938
939
0 1 1
1
0 1 1
1
1 0 1
0
2 1 2
0
1
880 87 2
979
980
814 893 2
185
186
744 748 2
255
256
4 9 2
1
2
1 2 1
2
717 612 2
146
147
23 98 2
91
92
280 293 2
722
723
854 429 2
239
240
919 90...

output:

1
0
0
16
899
867
1
9
938
1
1
0
1
980
185
255
1
2
147
92
722
240
941
920
1
530
263
348
2
1
321
0
273
3
0
1
686
163
398
1
187
350
938
321
2
3
587
636
558
1
161
3
276
384
67
70
1
24
0
0
2
5
5
37
746
415
27
3
160
6
134
614
41
3
785
1
614
377
1
790
2
468
740
1
1
79
1
859
1
653
77
6
2
2
181
4
2
1
849
1
45...

result:

ok 

Test #18:

score: 16
Accepted
time: 34ms
memory: 3900kb

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
0
905
486
439
273
113
630
702
426
803
593
810
876
627
840
103
642
676
801
440
305
128
368
416
263
304
271
456
187
258
909
780
851
372
255
570
923
658
547
469
396
546
27
83
622
713
565
921
694
878
88
425
8
387
356
517
892
856
683
249
777
685
405
976
268
794
19
880
965
749
849
299
31
924
932
465
8...

input:

1
50048
856 650 2
74
75
171 500 2
572
573
961 939 2
777
778
636 846 2
294
295
238 934 2
562
563
138 509 2
662
663
972 839 2
948
949
498 603 2
432
433
275 857 2
468
469
4 215 2
957
958
265 708 2
535
536
222 72 2
992
993
803 576 2
793
794
537 730 2
424
425
493 479 2
250
251
255 758 2
349
350
237 993 2...

output:

75
572
778
294
563
662
948
432
469
957
536
993
793
424
251
350
507
309
968
892
308
863
961
266
980
507
118
59
670
555
404
146
448
133
884
756
774
177
94
467
79
328
402
703
401
689
79
435
94
248
324
538
498
874
595
717
371
135
327
37
117
833
796
579
844
561
987
590
918
12
915
636
254
379
589
125
623
...

result:

ok 

Test #19:

score: 16
Accepted
time: 50ms
memory: 3840kb

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

input:

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

output:

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

result:

ok 

Test #20:

score: 16
Accepted
time: 42ms
memory: 4116kb

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
0
1
2
3
0
2
1
3
0
1
2
3
0
1
2
3
0
2
1
3
0
2
1
3
0
1
2
3
0
2
1
3
0
2
1
3
0
1
2

input:

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

output:

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

result:

ok 

Test #21:

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

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
0
1
3
2
4
0
1
3
2
4
0
1
2
3
4
0
1
3
2
4
0
1
2
3
4
0
2
1
3
4
0
2
3
1
4
0
2
3
1
4
0
3
2
1
4
0
1
2
3

input:

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

output:

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

result:

ok 

Test #22:

score: 16
Accepted
time: 28ms
memory: 3716kb

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
0
178
550
668
355
586
343
974
42
825
58
262
110
616
844
917
667
527
143
951
703
600
185
673
389
321
813
907
958
890
773
924
858
45
985
660
899
68
596
219
648
368
14
192
232
34
906
523
184
286
23
693
388
818
846
992
442
500
588
665
834
676
842
850
620
201
624
978
672
71
930
80
276
640
611
960
17...

input:

1
50050
255 156 2
38
39
54 55 2
285
286
773 507 2
949
950
473 131 2
563
564
662 308 2
659
660
939 333 2
301
302
943 210 2
779
780
271 139 2
958
959
429 889 2
811
812
494 859 2
229
230
414 757 2
720
721
493 292 2
643
644
488 976 2
752
753
755 700 2
583
584
470 545 2
868
869
941 455 2
397
398
404 134 ...

output:

39
285
950
564
659
302
779
959
812
229
721
644
753
584
868
398
731
175
991
88
246
217
723
754
784
658
60
243
412
399
132
531
165
701
53
863
500
871
92
732
939
842
542
309
277
373
286
756
619
83
44
629
270
899
299
222
737
358
440
591
296
235
321
852
239
220
118
247
30
734
668
918
76
339
208
852
533
1...

result:

ok 

Test #23:

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

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
0
595
302
69
33
399
654
529
2
179
737
229
714
679
583
615
95
445
861
190
46
515
992
567
722
850
923
280
203
478
273
434
88
231
696
558
473
627
987
92
94
215
546
950
764
454
56
93
944
922
480
658
925
299
792
939
775
458
855
143
802
813
773
972
200
43
78
988
247
883
650
368
298
916
313
566
655
12...

input:

1
50053
894 290 2
339
340
807 523 2
426
427
26 133 2
208
209
678 378 2
555
556
401 783 2
832
833
565 509 2
668
669
137 533 2
97
98
362 855 2
871
872
770 311 2
463
464
322 829 2
911
912
127 135 2
107
108
514 743 2
719
720
537 13 2
696
697
212 726 2
22
23
496 508 2
737
738
180 577 2
54
55
231 200 2
3
...

output:

339
427
208
555
832
669
97
871
463
911
107
720
697
22
737
54
4
575
577
897
920
440
741
425
423
376
67
782
160
263
247
717
596
467
674
915
490
875
496
141
762
205
539
624
813
464
19
893
235
306
776
371
847
458
292
652
224
420
450
550
960
897
104
175
254
21
826
445
543
129
994
334
534
727
751
729
722
...

result:

ok 

Test #24:

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

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
0
3
1
2
4
0
3
2
1
4
0
1
3
2
4
0
2
3
1
4
0
1
2
3
4
0
2
1
3
4
0
1
3
2
4
0
1
2
3
4
0
1
2
3
4
0
1
3
2

input:

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

output:

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

result:

ok 

Test #25:

score: 16
Accepted
time: 2ms
memory: 3884kb

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
0
5
1
4
2
3
6
0
5
1
4
3
2
6
0
5
1
2
4
3
6
0
5
1
3
4
2
6
0
5
1
2
3
4
6
0
5
1
3
2
4
6
0
5
4
1
2
3
6
0
5
4
1
3
2
6
0
5
2
1
4
3
6
0
5
3
1
4
2

input:

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

output:

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

result:

ok 

Test #26:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #27:

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

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
0
3
1
2
4
0
3
1
2
4
0
1
2
3
4
0
2
3
1
4
0
2
1
3
4
0
3
2
1
4
0
1
2
3
4
0
2
3
1
4
0
2
3
1
4
0
3
2
1

input:

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

output:

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

result:

ok 

Test #28:

score: 16
Accepted
time: 34ms
memory: 3864kb

input:

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

output:

1000
0
239
464
525
898
792
495
307
886
928
989
648
291
445
363
643
57
800
641
98
418
490
161
356
673
421
387
442
86
359
785
316
597
354
260
896
224
271
226
878
119
20
618
541
906
611
410
826
484
71
78
414
672
65
18
586
206
299
261
540
105
25
24
631
920
453
706
741
705
774
14
888
399
47
332
389
507
5...

input:

1
51340
149 771 2
603
604
143 36 2
877
878
515 392 2
131
132
278 923 2
312
313
459 259 2
561
562
532 231 2
551
552
636 10 2
653
654
132 907 2
124
125
585 694 1
586
700 682 1
1
70 112 2
682
683
369 155 2
383
384
666 96 2
679
680
676 913 1
42
964 910 2
958
959
651 586 2
654
655
263 738 2
327
328
598 2...

output:

604
878
132
313
562
552
654
124
586
1
682
384
680
42
958
655
328
42
1
781
663
815
369
293
751
42
959
303
338
899
921
131
150
229
540
852
570
218
556
837
947
801
24
1
280
22
419
0
927
155
645
12
262
495
186
42
920
621
416
411
928
1
940
191
42
33
402
653
272
156
399
722
423
41
201
33
257
239
539
100
2...

result:

ok 

Test #29:

score: 16
Accepted
time: 34ms
memory: 3844kb

input:

0
10
1000 1000000
1 433
265 863
766 305
237 422
591 33
588 87
33 868
33 328
110 458
718 791
891 33
22 576
773 795
489 357
104 33
33 829
308 726
592 865
651 179
591 508
264 792
274 367
219 33
67 600
419 406
583 183
716 211
4 709
983 33
672 928
648 689
679 497
321 874
711 585
758 518
223 702
440 618
7...

output:

1000
0
597
510
426
288
459
381
712
50
393
859
589
169
716
868
574
773
957
394
834
250
601
870
320
968
585
512
966
660
111
491
799
432
997
771
521
220
697
838
853
440
615
353
862
672
755
876
99
81
363
504
896
172
482
138
663
914
944
290
661
725
821
132
757
240
765
58
542
161
233
69
49
302
383
32
441
...

input:

1
51513
711 560 2
478
479
318 31 2
357
358
415 617 1
999
485 744 1
999
726 509 2
720
721
481 150 2
484
485
306 543 2
5
6
305 677 2
224
225
605 77 2
586
587
490 386 1
999
889 306 2
13
14
895 316 2
899
900
584 662 2
5
569
575 910 2
562
563
832 975 2
567
568
9 176 2
841
842
45 175 1
997
723 957 2
444
4...

output:

479
358
999
999
720
485
5
224
586
999
14
900
5
562
567
841
997
444
630
249
107
814
5
447
815
992
999
935
46
205
992
781
237
507
777
818
500
247
105
999
282
279
23
595
347
999
38
999
674
111
999
999
648
884
999
783
999
588
144
807
429
118
456
913
134
787
375
386
910
324
424
106
284
51
877
663
956
954...

result:

ok 

Test #30:

score: 16
Accepted
time: 34ms
memory: 3820kb

input:

0
1
1000 1000000
394 768
598 218
369 360
414 385
909 666
948 524
272 868
110 348
723 672
225 409
312 213
865 469
207 711
779 480
303 958
946 880
22 137
265 787
595 9
193 865
661 869
680 238
708 770
389 82
828 35
881 49
138 749
220 975
452 201
641 269
734 497
155 159
324 778
105 650
882 621
519 319
4...

output:

1000
0
282
905
202
53
322
885
998
199
276
8
637
16
110
74
319
361
557
211
180
974
502
261
142
153
307
537
960
580
222
19
121
796
245
652
526
649
722
66
633
781
829
83
784
139
888
196
291
432
33
303
80
944
860
482
615
18
135
26
534
997
270
371
359
241
239
188
364
779
297
821
717
393
247
613
493
618
7...

input:

1
49931
984 705 2
981
982
344 718 2
314
315
966 434 30
0
1
33
73
102
122
151
176
213
245
272
308
351
376
410
438
464
500
540
567
608
640
673
703
736
774
803
848
888
922
245 706 2
271
966
419 889 2
428
429
593 588 2
581
582
732 469 2
706
707
945 491 2
942
943
303 818 2
276
277
806 152 2
844
845
97 88...

output:

981
314
410
966
429
582
706
942
276
845
77
489
8
346
966
57
382
992
886
339
545
140
774
492
760
137
521
479
957
384
966
999
769
722
604
0
796
695
518
236
55
284
974
532
775
610
565
771
442
718
615
786
564
245
403
607
579
396
21
671
137
85
729
462
255
632
829
13
808
190
948
966
465
410
94
308
681
663...

result:

ok 

Test #31:

score: 16
Accepted
time: 12ms
memory: 3880kb

input:

0
10
96 1000000
0 36
27 0
95 0
7 0
0 70
59 0
72 0
83 0
22 0
25 0
18 0
92 0
0 88
87 0
0 75
0 68
39 0
0 84
0 43
0 24
28 0
19 0
5 0
0 80
37 0
0 33
77 0
15 0
0 38
3 0
0 60
11 0
74 0
89 0
52 0
79 0
0 73
81 0
44 0
76 0
41 0
21 0
57 0
0 85
40 0
49 0
0 45
0 46
16 0
14 0
0 66
29 0
20 0
32 0
0 1
0 51
0 47
0 3...

output:

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

input:

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

output:

0
95
0
0
0
17
0
95
95
95
95
0
0
95
24
95
0
0
81
0
0
95
0
95
66
0
95
61
95
95
95
0
27
0
0
0
95
0
0
0
95
0
0
95
26
0
95
95
0
95
75
46
19
95
20
95
0
0
95
95
95
0
95
0
0
10
95
0
45
95
8
0
95
0
0
95
0
55
95
0
95
0
95
0
0
94
95
95
0
95
0
95
25
84
0
9
53
39
93
95
95
0
95
95
0
95
18
0
95
0
84
95
95
0
95
76
...

result:

ok 

Test #32:

score: 16
Accepted
time: 14ms
memory: 3840kb

input:

0
10
541 1000000
540 23
540 21
40 540
150 540
540 291
540 34
3 540
540 416
428 540
347 540
60 540
140 540
540 216
411 540
57 540
540 214
271 540
439 540
400 540
379 540
195 540
540 167
152 540
540 254
251 540
399 540
540 185
420 540
540 154
534 540
540 160
540 194
247 540
540 11
342 540
540 257
454 ...

output:

541
0
58
147
7
257
41
255
50
385
381
254
34
502
327
526
513
441
229
162
273
207
2
226
1
461
386
90
83
534
503
515
122
468
206
6
54
321
345
102
137
3
43
61
250
65
370
258
211
246
215
319
398
114
238
348
353
328
15
469
522
11
48
125
210
156
112
505
326
239
202
524
219
80
127
100
399
347
511
233
529
48...

input:

1
5675
235 168 1
0
201 376 1
0
191 467 1
540
206 58 1
540
540 402 540
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
...

output:

0
0
540
540
402
540
540
540
540
0
0
540
0
540
0
540
0
0
540
0
0
540
0
540
0
540
540
540
0
540
540
540
540
540
0
0
540
540
0
540
540
540
540
0
0
540
0
0
540
540
540
540
0
540
0
0
0
540
540
540
0
540
540
540
0
540
540
0
540
540
0
540
540
540
0
540
540
0
0
161
540
540
540
540
0
0
540
540
540
0
0
0
0
54...

result:

ok 

Test #33:

score: 16
Accepted
time: 10ms
memory: 3836kb

input:

0
10
1000 1000000
989 0
0 294
783 0
474 0
831 0
397 0
0 538
626 0
554 0
837 0
954 0
0 694
343 0
883 0
0 957
0 24
0 688
0 17
406 0
472 0
929 0
22 0
0 412
0 195
150 0
0 518
0 255
35 0
381 0
751 0
0 928
0 555
0 241
0 590
454 0
373 0
0 72
389 0
455 0
327 0
0 917
572 0
0 164
335 0
0 59
0 809
0 182
0 123
...

output:

1000
0
491
878
521
906
468
452
440
100
610
423
160
347
343
605
98
844
18
244
211
973
689
22
597
16
701
771
58
871
574
568
320
460
229
54
28
205
430
424
260
572
715
432
140
601
226
750
327
235
634
417
956
851
261
811
392
708
590
208
45
210
214
172
812
462
827
972
497
158
570
236
523
37
70
953
763
384...

input:

1
10180
71 387 1
999
46 334 1
999
56 339 1
999
122 914 1
999
196 718 1
0
970 767 1
999
737 590 1
0
402 607 1
999
613 255 1
999
105 319 1
0
275 805 1
0
774 189 1
999
28 667 1
0
238 327 1
0
107 172 1
0
75 237 1
999
281 564 1
999
182 711 1
0
191 982 1
999
392 830 1
999
513 606 1
999
119 109 1
999
74 12...

output:

999
999
999
999
0
999
0
999
999
0
0
999
0
0
0
999
999
0
999
999
999
999
999
0
840
0
0
999
999
0
999
0
999
0
999
999
999
999
999
999
999
999
0
999
0
0
999
999
999
999
999
999
999
240
999
999
999
999
999
999
0
999
0
999
0
999
999
999
999
0
0
999
999
999
999
999
999
999
999
999
999
999
999
999
999
0
99...

result:

ok 

Subtask #4:

score: 10
Accepted

Test #34:

score: 10
Accepted
time: 44ms
memory: 3824kb

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

input:

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

output:

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

result:

ok 

Test #35:

score: 10
Accepted
time: 42ms
memory: 4112kb

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
0
1
2
3
0
1
2
3
0
2
1
3
0
1
2
3
0
2
1
3
0
2
1
3
0
1
2
3
0
2
1
3
0
2
1
3
0
1
2

input:

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

output:

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

result:

ok 

Test #36:

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

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
0
3
1
2
4
0
1
2
3
4
0
3
1
2
4
0
3
1
2
4
0
3
2
1
4
0
1
2
3
4
0
1
2
3
4
0
2
3
1
4
0
2
1
3
4
0
3
1
2

input:

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

output:

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

result:

ok 

Test #37:

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

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
0
3
1
2
4
0
3
2
1
4
0
1
3
2
4
0
2
3
1
4
0
1
2
3
4
0
2
1
3
4
0
1
3
2
4
0
1
2
3
4
0
1
2
3
4
0
1
3
2

input:

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

output:

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

result:

ok 

Test #38:

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

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
0
5
1
4
2
3
6
0
5
1
4
3
2
6
0
5
1
2
4
3
6
0
5
1
3
4
2
6
0
5
1
2
3
4
6
0
5
1
3
2
4
6
0
5
4
1
2
3
6
0
5
4
1
3
2
6
0
5
2
1
4
3
6
0
5
3
1
4
2

input:

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

output:

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

result:

ok 

Test #39:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #40:

score: 10
Accepted
time: 38ms
memory: 3820kb

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
0
3
2
1
4
0
2
1
3
4
0
3
1
2
4
0
3
1
2
4
0
2
3
1
4
0
1
3
2
4
0
1
3
2
4
0
2
3
1
4
0
1
2
3
4
0
3
1
2

input:

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

output:

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

result:

ok 

Test #41:

score: 10
Accepted
time: 50ms
memory: 4116kb

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

input:

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

output:

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

result:

ok 

Test #42:

score: 10
Accepted
time: 42ms
memory: 3836kb

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
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2

input:

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

output:

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

result:

ok 

Test #43:

score: 10
Accepted
time: 38ms
memory: 3824kb

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
0
2
3
1
4
0
2
3
1
4
0
2
3
1
4
0
2
3
1
4
0
2
3
1
4
0
2
3
1
4
0
2
3
1
4
0
2
3
1
4
0
2
3
1
4
0
2
3
1

input:

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

output:

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

result:

ok 

Test #44:

score: 10
Accepted
time: 2ms
memory: 4116kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #45:

score: 10
Accepted
time: 2ms
memory: 4112kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #46:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #47:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #48:

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

input:

0
6
4 1000000000
3 2
1 2
0 2
4 1000000000
1 0
2 0
3 0
4 1000000000
2 3
1 3
0 2
3 1000000000
2 1
0 1
3 1000000000
1 0
2 0
2 1000000000
0 1

output:

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

input:

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

output:

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

result:

ok 

Test #49:

score: 10
Accepted
time: 34ms
memory: 3900kb

input:

0
10
8 1000000000
5 6
4 7
5 1
7 2
0 3
2 1
6 0
8 1000000000
7 6
4 7
7 2
3 7
7 5
1 3
7 0
8 1000000000
0 1
2 0
1 3
4 1
5 2
6 2
7 3
8 1000000000
4 2
6 0
0 1
4 7
1 4
4 3
4 5
8 1000000000
6 0
6 2
6 5
7 6
6 3
6 4
6 1
8 1000000000
7 2
5 7
7 6
1 7
4 7
7 3
7 0
8 1000000000
6 5
7 3
1 2
2 7
0 1
5 3
4 5
8 100000...

output:

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

input:

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

output:

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

result:

ok 

Test #50:

score: 10
Accepted
time: 34ms
memory: 3884kb

input:

0
10
8 1000000000
1 3
4 1
0 1
6 1
1 2
1 7
5 1
8 1000000000
4 0
2 0
5 4
3 5
7 2
1 6
0 1
8 1000000000
0 5
6 2
0 6
3 6
4 5
1 4
4 7
8 1000000000
5 1
5 7
3 0
2 3
3 1
7 4
3 6
8 1000000000
2 4
0 1
5 3
1 2
7 0
4 3
5 6
8 1000000000
6 5
1 2
0 3
6 1
2 4
3 4
7 0
8 1000000000
3 6
5 0
4 0
0 6
7 0
1 3
2 0
8 100000...

output:

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

input:

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

output:

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

result:

ok 

Test #51:

score: 10
Accepted
time: 34ms
memory: 4116kb

input:

0
10
8 1000000000
2 7
4 2
5 3
1 6
0 1
1 4
3 7
8 1000000000
4 2
0 4
4 5
4 1
4 6
4 7
4 3
8 1000000000
0 7
5 3
5 1
2 3
1 4
0 6
6 4
8 1000000000
6 4
5 4
4 0
4 1
2 0
7 4
4 3
8 1000000000
0 6
4 0
1 7
5 7
7 2
6 3
4 2
8 1000000000
3 1
3 6
5 0
4 7
2 4
2 5
1 0
8 1000000000
4 7
6 5
7 5
5 3
0 7
1 5
2 7
8 100000...

output:

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

input:

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

output:

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

result:

ok 

Test #52:

score: 10
Accepted
time: 34ms
memory: 3836kb

input:

0
10
8 1000000000
2 7
4 2
5 3
1 6
0 1
1 4
3 7
8 1000000000
4 2
0 4
4 5
4 1
4 6
4 7
4 3
8 1000000000
0 7
5 3
5 1
2 3
1 4
0 6
6 4
8 1000000000
6 4
5 4
4 0
4 1
2 0
7 4
4 3
8 1000000000
0 6
4 0
1 7
5 7
7 2
6 3
4 2
8 1000000000
3 1
3 6
5 0
4 7
2 4
2 5
1 0
8 1000000000
4 7
6 5
7 5
5 3
0 7
1 5
2 7
8 100000...

output:

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

input:

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

output:

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

result:

ok 

Test #53:

score: 10
Accepted
time: 34ms
memory: 3828kb

input:

0
10
8 1000000000
2 7
4 2
5 3
1 6
0 1
1 4
3 7
8 1000000000
4 2
0 4
4 5
4 1
4 6
4 7
4 3
8 1000000000
0 7
5 3
5 1
2 3
1 4
0 6
6 4
8 1000000000
6 4
5 4
4 0
4 1
2 0
7 4
4 3
8 1000000000
0 6
4 0
1 7
5 7
7 2
6 3
4 2
8 1000000000
3 1
3 6
5 0
4 7
2 4
2 5
1 0
8 1000000000
4 7
6 5
7 5
5 3
0 7
1 5
2 7
8 100000...

output:

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

input:

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

output:

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

result:

ok 

Subtask #5:

score: 61
Accepted

Test #54:

score: 61
Accepted
time: 38ms
memory: 3816kb

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
0
2
1
998
0
269
941
742
639
70
784
568
991
365
91
444
981
459
417
659
87
64
562
26
294
159
725
819
812
31
111
625
917
782
970
626
789
691
370
230
321
461
701
958
6
351
582
669
828
379
571
493
229
158
240
38
315
27
205
249
488
832
179
199
911
429
328
448
276
37
786
506
381
694
8
190
621
657
419
883...

input:

1
59797
1 2 2
2
3
266 313 2
493
494
1 0 1
0
64 32 2
48
49
107 782 2
380
381
3 0 2
0
1
3 2 2
0
1
262 410 2
938
939
770 971 2
715
716
782 707 2
360
361
0 1 1
1
508 504 2
251
252
561 197 2
198
199
974 877 2
226
227
2 0 2
0
1
905 604 2
237
238
742 541 2
257
258
19 26 2
93
94
5 6 2
6
7
912 677 2
87
88
47...

output:

2
493
0
48
381
0
1
938
715
361
1
252
198
227
0
238
258
93
6
88
529
0
3
524
109
547
826
905
773
1
0
107
188
2
751
22
47
873
72
0
2
1
614
932
0
436
652
313
515
5
1
53
490
0
8
622
537
1
889
3
1
338
3
9
300
54
3
625
116
2
5
909
99
421
912
675
1
461
591
684
2
66
2
3
7
693
607
305
1
3
159
2
5
280
1
1
993
...

result:

ok 

Test #55:

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

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
0
123
143
296
561
926
670
294
29
952
643
56
121
717
848
831
3
929
751
691
785
235
93
474
460
539
676
963
666
950
396
435
701
302
416
752
609
693
946
53
690
935
372
771
64
213
598
354
562
376
338
76
366
901
641
139
468
573
805
895
211
765
281
309
547
905
79
987
489
548
688
697
232
788
268
962
891...

input:

1
50045
560 785 2
217
218
317 335 2
437
438
343 593 2
772
773
383 245 2
839
840
741 955 2
520
521
565 298 2
189
190
517 341 2
237
238
382 340 2
805
806
419 928 2
172
173
130 862 2
473
474
409 449 2
706
707
172 175 2
582
583
533 264 2
689
690
727 544 2
460
461
494 684 2
728
729
684 277 2
905
906
733 ...

output:

217
437
772
840
520
190
238
806
172
474
706
582
690
461
728
906
857
746
318
376
461
197
687
795
556
135
276
627
143
801
257
233
126
245
531
60
76
52
361
379
542
0
674
933
398
799
191
725
593
908
223
61
445
428
890
174
917
113
121
453
910
591
668
225
424
834
360
704
645
915
318
816
91
421
991
832
649...

result:

ok 

Test #56:

score: 61
Accepted
time: 54ms
memory: 3788kb

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

input:

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

output:

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

result:

ok 

Test #57:

score: 61
Accepted
time: 42ms
memory: 4084kb

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
0
2
1
3
0
2
1
3
0
2
1
3
0
2
1
3
0
2
1
3
0
1
2
3
0
1
2
3
0
2
1
3
0
2
1
3
0
2
1

input:

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

output:

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

result:

ok 

Test #58:

score: 61
Accepted
time: 42ms
memory: 3824kb

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
0
1
3
2
4
0
3
2
1
4
0
3
1
2
4
0
2
1
3
4
0
1
3
2
4
0
3
1
2
4
0
3
2
1
4
0
2
1
3
4
0
3
2
1
4
0
2
1
3

input:

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

output:

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

result:

ok 

Test #59:

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

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
0
611
194
593
528
506
696
224
61
193
774
934
28
232
431
658
504
910
731
298
912
264
754
368
518
147
136
803
938
832
189
52
712
785
116
553
183
508
268
605
978
400
392
500
971
78
457
14
631
829
827
438
622
87
312
730
168
643
247
769
638
778
578
502
130
916
882
223
577
548
306
329
295
177
135
252...

input:

1
50038
401 776 2
782
783
465 771 2
786
787
912 258 2
41
42
459 600 2
540
541
167 965 2
786
787
594 393 2
359
360
724 855 2
676
677
311 925 2
781
782
242 219 2
850
851
946 30 2
556
557
521 206 2
981
982
786 982 2
397
398
673 837 2
705
706
843 550 2
156
157
14 525 2
238
239
359 219 2
11
12
818 835 2
...

output:

782
786
42
541
787
360
676
782
851
556
982
397
706
157
239
12
135
510
786
749
855
741
178
152
648
261
80
996
23
666
116
609
251
843
671
795
590
780
188
796
409
175
730
532
231
302
60
149
832
995
48
580
833
58
94
937
486
806
383
550
244
185
649
851
189
42
307
611
754
434
424
86
210
416
749
540
392
37...

result:

ok 

Test #60:

score: 61
Accepted
time: 26ms
memory: 3820kb

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
0
531
478
29
769
188
199
549
719
988
772
431
436
175
100
979
653
603
524
349
453
849
125
505
226
477
890
185
696
165
157
5
764
145
311
740
133
158
131
729
937
294
225
863
492
550
905
334
529
433
628
779
952
672
64
366
7
104
910
563
394
935
899
684
410
482
886
231
39
650
600
485
204
344
260
375
...

input:

1
50048
550 35 2
7
8
888 304 2
668
669
390 980 2
167
168
359 545 2
198
199
561 238 2
995
996
346 315 2
211
212
648 528 2
908
909
20 852 2
537
538
2 286 2
555
556
612 699 2
944
945
465 782 2
92
93
358 598 2
199
200
633 434 2
923
924
457 761 2
100
101
294 236 2
263
264
184 121 2
373
374
81 412 2
476
4...

output:

8
668
167
198
996
212
909
538
555
944
92
199
924
100
263
374
476
198
935
838
222
114
815
621
1
246
38
351
767
301
220
934
923
500
708
274
446
462
756
897
800
970
709
688
387
292
730
641
644
910
372
495
98
818
391
599
254
126
871
25
114
678
85
54
659
650
986
130
678
707
483
246
391
18
244
615
679
911...

result:

ok 

Test #61:

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

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
0
3
1
2
4
0
3
2
1
4
0
1
3
2
4
0
2
3
1
4
0
1
2
3
4
0
2
1
3
4
0
1
3
2
4
0
1
2
3
4
0
1
2
3
4
0
1
3
2

input:

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

output:

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

result:

ok 

Test #62:

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

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
0
5
1
4
2
3
6
0
5
1
4
3
2
6
0
5
1
2
4
3
6
0
5
1
3
4
2
6
0
5
1
2
3
4
6
0
5
1
3
2
4
6
0
5
4
1
2
3
6
0
5
4
1
3
2
6
0
5
2
1
4
3
6
0
5
3
1
4
2

input:

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

output:

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

result:

ok 

Test #63:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #64:

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

input:

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

output:

997
0
511
996
1
256
512
767
128
255
383
510
639
766
894
995
2
65
129
192
257
320
384
447
513
576
640
703
768
831
895
958
33
64
96
127
160
191
223
254
288
319
351
382
415
446
478
509
544
575
607
638
671
702
734
765
799
830
862
893
926
957
979
994
3
18
34
49
66
81
97
112
130
145
161
176
193
208
224
23...

input:

1
49888
704 390 3
711
718
734
179 371 1
177
771 203 1
770
747 399 1
746
471 689 3
472
473
477
478 796 3
447
448
463
220 817 1
219
959 567 3
966
971
979
945 282 1
943
540 931 3
541
542
543
490 142 3
491
492
493
581 84 3
582
583
584
890 394 1
889
831 332 3
862
893
894
644 237 1
642
860 24 1
858
482 54...

output:

734
177
770
746
477
447
219
979
943
543
493
584
889
894
642
858
480
33
455
19
502
415
980
938
304
746
703
911
568
895
168
978
272
64
953
238
449
892
512
238
459
784
190
680
183
513
769
67
191
169
667
578
243
874
374
296
430
560
686
592
571
175
446
959
363
645
854
343
783
811
33
703
414
581
795
209
1...

result:

ok 

Test #65:

score: 61
Accepted
time: 38ms
memory: 4112kb

input:

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

output:

512
0
256
511
1
129
257
384
65
128
192
255
320
383
447
510
2
34
66
97
130
161
193
224
258
289
321
352
385
416
448
479
18
33
49
64
81
96
112
127
145
160
176
191
208
223
239
254
273
288
304
319
336
351
367
382
400
415
431
446
463
478
494
509
3
11
19
26
35
42
50
57
67
74
82
89
98
105
113
120
131
138
14...

input:

1
59652
7 23 1
8
244 408 1
246
1 3 1
2
0 1 1
1
90 18 1
91
2 1 2
0
1
0 1 1
1
1 0 1
0
0 1 1
1
493 224 3
478
479
486
300 469 3
297
298
299
1 77 3
17
32
64
2 0 1
0
638 498 3
576
608
623
90 88 1
92
5 25 1
7
0 1 1
1
34 125 1
36
96 88 3
111
126
127
124 477 1
123
98 50 1
100
0 2 2
2
3
2 0 1
0
389 503 3
386
...

output:

8
246
2
1
91
1
1
0
1
478
297
64
0
576
92
7
1
36
127
123
100
2
0
386
1
129
17
29
15
1
289
0
1
1
253
0
1
9
144
0
125
62
20
663
406
2
0
57
1
2
2
71
11
0
28
1
0
15
1
1
232
1
1
0
0
0
17
11
24
18
444
0
100
112
175
23
0
117
1
69
2
2
2
12
59
1
1
8
485
155
8
24
0
95
1
0
494
12
0
1
16
110
81
0
0
0
552
0
328
0...

result:

ok 

Test #66:

score: 61
Accepted
time: 50ms
memory: 4116kb

input:

0
10
2 1000000000
0 1
2 1000000000
1 0
2 1000000000
0 1
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

output:

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

input:

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

output:

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

result:

ok 

Test #67:

score: 61
Accepted
time: 44ms
memory: 4132kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #68:

score: 61
Accepted
time: 38ms
memory: 3816kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #69:

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

input:

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

output:

1000
0
511
999
1
256
512
767
128
255
383
510
639
766
894
998
2
65
129
192
257
320
384
447
513
576
640
703
768
831
895
958
33
64
96
127
160
191
223
254
288
319
351
382
415
446
478
509
544
575
607
638
671
702
734
765
799
830
862
893
926
957
982
997
3
18
34
49
66
81
97
112
130
145
161
176
193
208
224
2...

input:

1
50098
719 424 3
726
733
734
541 835 1
540
752 276 1
751
188 760 1
187
167 737 1
165
970 709 3
971
972
973
566 908 1
564
802 357 1
801
72 264 1
70
2 601 3
33
64
128
572 365 1
571
426 462 1
424
242 505 1
240
639 757 3
512
513
576
854 655 3
847
848
851
133 554 1
131
455 895 3
448
449
452
57 736 3
58
...

output:

734
540
751
187
165
973
564
801
70
128
571
424
240
512
847
131
448
63
508
19
240
471
832
105
727
739
996
943
622
559
712
329
512
719
623
41
207
273
432
288
130
648
269
576
998
67
399
751
990
303
864
660
910
800
320
854
993
730
145
113
556
424
576
343
871
141
999
657
622
49
212
624
81
882
416
641
701...

result:

ok 

Test #70:

score: 61
Accepted
time: 38ms
memory: 4108kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #71:

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

input:

0
10
1000 1000000000
496 136
370 247
359 252
743 278
85 499
522 547
6 780
330 416
815 429
942 361
275 290
113 753
471 15
720 896
514 482
631 513
981 760
525 601
600 637
263 572
292 229
556 489
46 504
199 953
354 801
91 181
742 119
495 647
940 396
272 230
291 130
763 639
467 709
945 171
96 610
726 96...

output:

1000
0
376
887
238
435
395
943
157
4
936
456
277
207
396
787
40
836
947
903
892
319
612
170
759
100
644
351
604
748
255
138
661
918
438
406
373
956
950
683
784
578
582
746
752
540
254
62
240
630
3
474
42
143
614
821
257
242
870
130
441
929
531
224
720
897
543
869
673
745
249
599
500
739
333
466
575
...

input:

1
50431
579 114 2
748
749
335 463 2
355
356
934 559 1
21
264 649 2
64
65
600 903 1
937
770 786 2
655
656
806 748 2
795
796
1 672 2
425
426
601 169 2
608
609
925 199 2
935
936
24 580 2
381
382
706 548 2
719
720
757 817 2
570
571
493 618 2
911
912
740 968 1
937
590 233 1
937
583 891 2
586
587
709 614 ...

output:

749
356
21
64
937
655
795
426
609
936
382
720
570
911
937
937
587
694
742
345
133
937
267
937
755
350
297
644
389
928
836
924
400
614
697
924
1
359
957
650
622
600
32
338
642
55
689
469
189
52
961
438
696
656
163
633
127
128
830
549
1
315
21
479
821
819
416
881
389
811
460
21
894
775
300
311
939
525...

result:

ok 

Test #72:

score: 61
Accepted
time: 36ms
memory: 3844kb

input:

0
10
1000 1000000000
812 935
596 175
369 401
625 709
470 249
715 901
665 497
296 591
732 817
698 374
352 216
787 19
831 844
896 420
700 895
533 363
872 36
58 930
48 897
321 154
391 351
993 950
392 990
585 323
565 739
818 926
103 89
912 432
706 259
359 608
218 33
146 201
16 769
230 885
945 377
41 131...

output:

1000
0
242
24
499
563
437
175
11
319
461
619
94
327
750
424
688
120
227
313
838
255
62
285
258
944
592
631
253
351
400
686
853
825
280
807
455
935
704
113
450
522
561
521
388
480
34
541
226
470
403
761
498
839
25
765
166
534
265
813
517
532
82
528
826
247
164
484
341
95
12
693
416
324
344
606
879
82...

input:

1
51725
817 441 2
885
886
834 61 2
237
238
376 400 2
386
387
811 359 1
812
14 295 1
999
197 63 2
506
507
298 877 2
300
301
485 476 2
357
358
595 291 2
578
579
768 22 2
747
748
11 791 1
999
482 694 2
589
590
293 614 2
410
411
980 488 1
999
408 563 2
663
664
795 913 2
746
747
196 380 2
507
508
993 555...

output:

886
237
387
812
999
507
301
358
578
747
999
590
411
999
663
746
507
994
508
708
552
972
624
999
999
720
282
740
999
150
33
558
752
847
356
495
128
472
600
814
747
420
809
960
953
999
412
852
889
999
20
16
756
286
542
281
997
371
948
205
143
648
505
273
965
110
826
329
999
60
997
997
190
999
308
864
...

result:

ok 

Test #73:

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

input:

0
1
1000 1000000000
584 325
759 912
536 411
310 503
386 643
125 683
587 211
331 908
866 671
790 38
346 846
813 567
297 574
42 196
443 23
467 767
797 820
134 746
465 907
815 88
161 453
467 788
793 875
656 320
847 290
725 194
372 594
909 185
120 5
845 895
292 421
56 804
634 565
41 22
144 402
616 552
1...

output:

1000
0
150
634
361
358
302
228
326
486
499
306
221
317
355
132
857
938
87
745
77
650
907
675
17
481
521
528
980
349
383
120
270
699
537
300
855
329
384
440
321
772
651
320
433
96
952
992
194
237
395
856
296
999
166
128
406
509
606
955
468
219
657
62
713
316
837
258
617
291
546
494
951
628
177
622
50...

input:

1
49651
887 618 2
881
882
854 435 1
853
258 440 2
246
247
425 669 1
426
791 279 1
790
632 563 2
630
631
430 947 2
420
421
263 976 2
241
242
82 289 2
95
96
465 50 2
455
456
406 362 2
372
373
22 70 2
19
20
513 937 2
532
533
274 545 2
304
305
127 158 2
124
125
636 982 2
626
627
966 240 2
961
962
837 41...

output:

881
853
246
426
790
630
420
241
96
455
372
19
533
305
124
626
961
813
689
9
897
671
138
482
9
948
879
260
320
458
182
312
150
60
299
373
838
915
648
618
774
9
396
375
125
144
830
824
354
9
668
851
867
114
943
847
78
576
2
700
756
168
68
656
546
792
725
845
501
977
798
818
748
419
162
918
373
495
141...

result:

ok 

Test #74:

score: 61
Accepted
time: 6ms
memory: 3896kb

input:

0
10
96 1000000000
95 4
95 32
13 95
49 95
76 95
95 73
95 10
95 42
63 95
17 95
95 52
95 84
95 11
95 2
95 14
95 85
91 95
57 95
24 95
46 95
95 23
77 95
54 95
95 40
33 95
34 95
95 26
95 51
95 89
59 95
82 95
95 28
95 25
95 81
3 95
95 45
95 29
71 95
95 94
95 21
95 22
8 95
92 95
15 95
95 55
56 95
6 95
95 7...

output:

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

input:

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

output:

95
95
48
0
95
37
95
95
0
95
95
95
95
95
95
28
0
95
0
95
95
0
95
95
95
95
0
95
0
95
95
95
0
95
95
95
95
95
95
95
89
95
95
0
50
95
95
95
95
95
82
0
38
82
52
95
69
50
95
95
0
95
0
95
95
95
95
95
95
0
95
42
51
17
60
0
95
95
57
95
0
95
0
95
95
95
0
95
95
95
95
95
64
87
0
95
95
95
95
74
0
95
26
81
3
20
0
...

result:

ok 

Test #75:

score: 61
Accepted
time: 12ms
memory: 3832kb

input:

0
10
541 1000000000
0 527
0 72
0 176
0 246
0 323
190 0
74 0
0 110
518 0
259 0
0 293
0 51
0 59
149 0
0 232
327 0
0 136
0 503
0 142
0 248
64 0
0 398
379 0
0 156
0 265
406 0
84 0
0 49
522 0
0 413
0 513
429 0
170 0
163 0
319 0
233 0
490 0
0 187
0 270
273 0
0 17
471 0
437 0
0 154
276 0
63 0
378 0
0 38
42...

output:

541
0
490
250
54
62
312
321
369
63
57
237
387
251
499
422
366
381
41
466
272
98
484
83
142
203
75
476
169
124
509
249
536
161
329
435
235
385
212
48
182
361
78
285
183
170
355
438
426
286
28
178
12
217
448
423
147
267
344
146
13
50
113
449
46
21
394
525
232
489
475
310
336
2
174
7
400
343
96
195
159...

input:

1
6214
485 471 1
0
434 217 1
540
58 503 1
540
308 332 1
540
486 302 1
0
311 483 1
0
45 65 1
0
354 93 1
0
160 30 1
0
421 140 1
0
112 212 1
0
172 400 1
540
384 353 1
0
360 254 1
0
402 238 1
0
439 299 1
0
162 426 1
540
266 314 1
0
237 131 1
540
366 221 1
540
500 0 1
0
435 34 1
540
264 100 1
0
219 334 1...

output:

0
540
540
540
0
0
0
0
0
0
0
540
0
0
0
0
540
0
540
540
0
540
0
540
0
540
0
354
0
0
0
0
0
540
0
0
540
540
540
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
540
0
0
540
0
0
0
540
540
154
0
0
540
0
540
540
0
0
0
540
540
540
0
0
0
0
0
540
0
0
0
0
0
0
0
0
540
540
540
0
0
540
0
540
0
0
0
0
540
0
33
0
0
0
0
0
540
0
0...

result:

ok 

Test #76:

score: 61
Accepted
time: 14ms
memory: 3732kb

input:

0
10
1000 1000000000
999 444
999 412
999 312
999 906
999 990
999 616
999 554
718 999
999 228
494 999
999 726
999 728
55 999
370 999
190 999
999 230
999 64
944 999
358 999
999 189
65 999
500 999
457 999
480 999
414 999
999 820
999 29
331 999
999 693
239 999
132 999
999 918
527 999
999 534
145 999
999...

output:

1000
0
815
156
389
65
442
682
956
896
97
438
114
543
93
957
231
358
812
643
49
363
491
696
769
631
467
934
205
408
27
875
480
124
318
170
669
662
251
944
905
44
266
473
145
721
275
496
538
943
571
96
397
516
764
418
13
987
135
264
954
671
844
989
132
17
21
803
573
336
748
583
658
348
978
591
449
687...

input:

1
10180
18 801 1
0
4 425 1
0
618 21 1
0
203 286 1
999
471 862 1
0
532 783 1
0
133 908 1
999
213 609 1
0
968 871 1
0
552 573 1
0
978 747 1
999
859 355 1
999
668 689 1
999
783 397 1
0
150 322 1
999
678 513 1
0
288 914 1
0
287 790 1
999
50 101 1
0
397 26 1
0
290 876 1
0
763 396 1
0
171 768 1
0
22 938 1...

output:

0
0
0
999
0
0
999
0
0
0
999
999
999
0
999
0
0
999
0
0
0
0
0
999
0
999
0
999
0
999
0
999
0
999
0
999
999
0
999
999
999
999
999
0
999
999
999
0
0
0
999
0
999
999
0
0
0
999
999
0
0
0
999
999
999
0
0
0
0
0
999
0
0
0
0
0
999
999
999
999
0
0
999
0
0
0
999
999
999
0
999
0
999
999
0
0
999
0
0
0
999
0
999
99...

result:

ok 

Test #77:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #78:

score: 61
Accepted
time: 2ms
memory: 3820kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #79:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #80:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #81:

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

input:

0
6
4 1000000000
2 3
0 3
1 3
4 1000000000
0 3
2 3
1 3
4 1000000000
2 0
1 0
3 2
3 1000000000
0 2
1 2
3 1000000000
1 0
2 0
2 1000000000
1 0

output:

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

input:

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

output:

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

result:

ok 

Test #82:

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

input:

0
10
8 1000000000
2 1
4 7
6 0
7 3
1 5
6 5
4 0
8 1000000000
3 2
3 4
4 5
7 6
5 6
0 1
2 1
8 1000000000
0 6
4 7
3 6
3 1
2 5
5 1
4 0
8 1000000000
0 1
2 0
1 3
1 4
2 5
2 6
3 7
8 1000000000
5 1
5 0
6 5
5 7
3 5
5 2
4 5
8 1000000000
0 6
0 3
0 4
7 0
2 0
1 0
5 0
8 1000000000
7 0
1 2
1 5
6 0
4 3
6 3
5 7
8 100000...

output:

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

input:

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

output:

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

result:

ok 

Test #83:

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

input:

0
10
8 1000000000
4 0
3 4
4 6
6 2
1 4
4 5
7 4
8 1000000000
1 3
3 5
3 7
2 3
0 3
3 6
4 2
8 1000000000
0 4
3 2
2 5
7 2
0 2
2 6
3 1
8 1000000000
0 6
6 1
3 1
7 3
7 4
4 2
0 5
8 1000000000
0 4
3 4
6 5
0 2
7 0
5 1
6 2
8 1000000000
2 4
5 2
4 0
6 1
7 6
5 3
0 1
8 1000000000
5 3
0 1
0 5
2 0
7 6
6 5
4 2
8 100000...

output:

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

input:

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

output:

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

result:

ok 

Test #84:

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

input:

0
10
8 1000000000
3 7
0 3
3 6
3 2
4 3
3 5
3 1
8 1000000000
2 1
6 3
3 0
0 2
1 4
5 7
3 5
8 1000000000
6 2
6 7
1 6
0 7
0 4
5 6
1 3
8 1000000000
5 3
6 1
0 2
0 4
7 3
6 4
2 5
8 1000000000
2 0
4 0
4 7
3 6
3 5
1 6
3 2
8 1000000000
3 2
2 6
3 5
1 3
3 4
1 0
7 3
8 1000000000
4 1
2 1
0 6
7 4
3 7
6 3
2 5
8 100000...

output:

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

input:

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

output:

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

result:

ok 

Test #85:

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

input:

0
10
8 1000000000
3 7
0 3
3 6
3 2
4 3
3 5
3 1
8 1000000000
2 1
6 3
3 0
0 2
1 4
5 7
3 5
8 1000000000
6 2
6 7
1 6
0 7
0 4
5 6
1 3
8 1000000000
5 3
6 1
0 2
0 4
7 3
6 4
2 5
8 1000000000
2 0
4 0
4 7
3 6
3 5
1 6
3 2
8 1000000000
3 2
2 6
3 5
1 3
3 4
1 0
7 3
8 1000000000
4 1
2 1
0 6
7 4
3 7
6 3
2 5
8 100000...

output:

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

input:

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

output:

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

result:

ok 

Test #86:

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

input:

0
10
8 1000000000
3 7
0 3
3 6
3 2
4 3
3 5
3 1
8 1000000000
2 1
6 3
3 0
0 2
1 4
5 7
3 5
8 1000000000
6 2
6 7
1 6
0 7
0 4
5 6
1 3
8 1000000000
5 3
6 1
0 2
0 4
7 3
6 4
2 5
8 1000000000
2 0
4 0
4 7
3 6
3 5
1 6
3 2
8 1000000000
3 2
2 6
3 5
1 3
3 4
1 0
7 3
8 1000000000
4 1
2 1
0 6
7 4
3 7
6 3
2 5
8 100000...

output:

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

input:

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

output:

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

result:

ok 

Test #87:

score: 61
Accepted
time: 24ms
memory: 3828kb

input:

0
10
978 1000000000
201 44
44 320
320 907
907 278
278 477
477 755
755 461
461 235
235 83
83 919
919 38
38 443
443 629
629 42
42 13
13 208
208 898
898 205
205 924
924 887
887 170
170 326
326 255
255 684
684 301
301 909
909 161
161 621
621 130
130 587
587 530
530 334
334 700
700 771
771 722
722 712
71...

output:

978
0
579
83
548
447
571
584
185
327
948
344
900
403
867
456
169
272
965
512
616
190
176
847
249
964
523
434
218
455
792
601
165
770
334
232
594
712
23
865
340
491
693
741
21
860
853
449
578
231
773
799
48
611
11
233
140
279
122
236
354
833
836
55
544
785
614
886
256
328
30
168
585
973
441
899
20
22...

input:

1
35090
368 419 2
151
152
886 418 2
710
711
765 897 2
761
762
924 982 2
202
203
152 293 2
30
31
472 442 2
675
676
136 567 2
20
21
387 286 2
416
417
424 194 2
319
320
702 839 2
445
446
781 713 2
826
827
470 178 2
267
268
381 646 2
883
884
179 570 2
934
935
171 645 2
348
349
679 1 2
0
1
458 223 2
532
...

output:

151
710
761
202
30
676
20
417
319
445
827
267
883
934
349
1
533
175
191
69
778
12
887
743
906
800
183
398
857
668
267
220
286
828
684
306
376
24
588
651
537
167
879
247
416
486
381
216
481
912
921
173
444
807
95
275
767
735
946
718
539
802
636
279
166
78
600
399
300
715
1
978
683
630
702
627
856
258...

result:

ok 

Test #88:

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

input:

0
10
1000 1000000000
897 448
897 517
583 297
897 748
84 650
402 690
131 583
583 601
464 897
336 674
189 897
897 246
843 421
432 742
529 877
812 209
103 109
842 931
795 84
289 103
103 579
84 603
926 897
70 897
183 901
448 647
111 513
646 689
84 949
191 485
745 12
124 578
133 689
423 755
767 124
897 8...

output:

1000
0
841
875
541
554
862
825
405
39
700
396
163
125
612
607
472
895
898
340
817
333
183
798
145
830
670
63
350
478
247
716
900
418
537
238
996
496
653
795
271
94
536
913
35
636
869
637
104
175
265
679
753
698
385
137
218
30
191
739
899
198
594
932
595
886
926
486
692
186
23
24
441
704
412
785
781
...

input:

1
47617
770 643 2
771
772
822 264 3
815
816
819
697 921 1
694
42 258 3
43
44
48
8 836 1
927
398 408 1
397
588 142 2
977
978
528 339 2
526
527
47 851 2
209
210
605 775 6
606
607
609
614
615
621
508 491 1
498
503 780 2
63
64
357 374 1
999
629 969 2
631
635
67 805 3
68
69
73
0 272 1
999
252 803 2
4
5
1...

output:

772
815
694
48
927
397
978
526
210
621
498
63
999
635
73
999
4
178
999
801
702
353
999
3
843
952
193
184
254
677
348
446
918
791
818
986
681
61
180
131
990
869
999
64
632
921
851
404
793
848
3
790
164
999
797
64
650
511
842
316
4
999
999
702
470
17
430
411
480
76
157
167
276
292
54
396
543
842
720
7...

result:

ok 

Test #89:

score: 61
Accepted
time: 26ms
memory: 3900kb

input:

0
10
991 1000000000
454 800
702 960
660 644
108 499
445 776
921 520
184 252
730 588
97 163
465 448
361 58
227 250
577 112
191 405
394 157
830 296
589 428
814 830
531 947
161 797
490 127
145 911
858 49
935 552
600 543
138 501
850 916
602 242
114 606
516 650
573 988
121 41
617 723
680 173
619 709
620 ...

output:

991
0
922
269
287
552
250
386
890
783
795
394
538
712
565
460
782
787
475
693
68
232
293
960
751
761
932
390
659
807
381
744
108
961
371
794
606
650
875
982
956
138
696
896
99
586
915
750
149
150
551
516
561
334
738
804
656
162
976
387
529
918
947
519
156
756
603
292
192
455
725
655
747
88
670
766
9...

input:

1
49922
712 158 2
710
711
702 63 1
710
480 262 2
489
490
953 181 2
696
697
390 847 2
579
580
632 711 2
596
597
236 914 2
936
937
361 921 3
355
358
359
372 894 2
288
289
749 47 2
736
737
689 467 2
696
697
110 534 2
85
86
963 403 2
209
210
659 901 1
660
54 515 1
63
210 230 2
620
621
255 154 2
405
406
...

output:

710
710
490
696
580
596
936
355
288
736
697
85
210
660
63
620
406
836
534
973
701
447
368
756
710
123
318
3
815
335
485
143
709
228
175
457
736
495
242
534
228
293
638
303
213
640
940
791
874
677
473
57
124
389
201
543
325
630
244
830
729
475
199
137
531
360
522
604
494
542
273
201
190
629
593
419
8...

result:

ok 

Test #90:

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

input:

0
10
993 1000000000
659 162
695 292
133 492
301 424
380 243
646 631
297 394
653 704
220 522
825 939
861 883
602 802
939 903
875 50
576 279
343 778
734 393
665 687
340 125
189 579
672 873
201 476
715 325
846 119
682 482
362 218
694 968
463 785
402 585
985 957
207 215
887 618
859 317
871 214
655 459
3...

output:

993
0
522
83
231
237
633
959
785
627
782
566
116
872
354
261
946
637
306
543
75
726
529
821
932
615
320
670
471
346
7
96
718
488
588
941
733
629
277
990
887
274
193
109
702
265
526
436
486
650
154
855
552
819
636
341
741
758
55
535
973
255
484
459
337
293
612
48
978
926
40
35
970
87
59
465
253
88
33...

input:

1
50698
398 409 3
399
401
402
24 787 1
19
958 65 1
999
636 67 3
643
891
892
207 54 2
209
210
763 130 1
764
614 607 1
615
562 357 1
125
214 432 3
240
241
246
28 471 2
353
354
917 717 1
999
703 106 2
699
702
614 449 1
615
160 551 2
141
158
990 879 2
991
993
754 600 1
747
687 846 1
686
703 968 2
704
70...

output:

402
19
999
892
210
764
615
125
246
354
999
699
615
141
993
747
686
706
762
29
90
47
968
264
237
931
759
433
158
211
77
415
267
367
486
829
47
821
598
237
54
901
611
47
976
211
477
47
608
364
143
442
776
291
47
841
292
897
673
611
10
497
703
213
220
961
554
325
97
572
269
448
428
781
824
800
853
288
...

result:

ok 

Test #91:

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

input:

0
10
993 1000000000
659 162
695 292
133 492
301 424
380 243
646 631
297 394
653 704
220 522
825 939
861 883
602 802
939 903
875 50
576 279
343 778
734 393
665 687
340 125
189 579
672 873
201 476
715 325
846 119
682 482
362 218
694 968
463 785
402 585
985 957
207 215
887 618
859 317
871 214
655 459
3...

output:

993
0
522
83
231
237
633
959
785
627
782
566
116
872
354
261
946
637
306
543
75
726
529
821
932
615
320
670
471
346
7
96
718
488
588
941
733
629
277
990
887
274
193
109
702
265
526
436
486
650
154
855
552
819
636
341
741
758
55
535
973
255
484
459
337
293
612
48
978
926
40
35
970
87
59
465
253
88
33...

input:

1
50698
398 409 3
399
401
402
24 787 1
19
958 65 1
999
636 67 3
643
891
892
207 54 2
209
210
763 130 1
764
614 607 1
615
562 357 1
125
214 432 3
240
241
246
28 471 2
353
354
917 717 1
999
703 106 2
699
702
614 449 1
615
160 551 2
141
158
990 879 2
991
993
754 600 1
747
687 846 1
686
703 968 2
704
70...

output:

402
19
999
892
210
764
615
125
246
354
999
699
615
141
993
747
686
706
762
29
90
47
968
264
237
931
759
433
158
211
77
415
267
367
486
829
47
821
598
237
54
901
611
47
976
211
477
47
608
364
143
442
776
291
47
841
292
897
673
611
10
497
703
213
220
961
554
325
97
572
269
448
428
781
824
800
853
288
...

result:

ok 

Test #92:

score: 61
Accepted
time: 36ms
memory: 3780kb

input:

0
10
992 1000000000
274 302
761 266
243 116
753 556
69 885
191 771
127 476
904 335
735 660
798 382
116 771
973 331
753 437
318 813
250 127
64 904
929 494
127 885
318 538
135 116
822 415
894 258
187 322
874 759
574 890
379 812
988 653
332 331
572 244
215 346
825 401
510 519
517 777
958 897
911 176
40...

output:

992
0
3
16
761
988
699
421
717
720
113
555
663
875
736
391
153
621
863
783
949
581
682
564
450
950
341
332
182
175
667
282
60
360
61
753
385
987
71
710
24
148
501
585
293
524
378
429
202
573
318
377
108
767
376
218
56
359
731
173
51
536
657
695
551
451
215
474
188
363
858
729
309
35
543
544
387
472
...

input:

1
49569
775 641 1
776
537 545 2
538
540
142 315 1
141
50 1 2
48
49
582 196 3
225
226
581
970 352 1
984
907 263 4
871
904
905
906
857 284 1
858
585 20 3
524
525
584
98 24 1
99
925 488 1
920
302 116 1
301
495 976 1
494
435 715 1
350
31 133 1
10
209 933 2
210
224
886 0 4
887
896
899
902
454 636 1
50
92...

output:

776
540
141
48
225
984
871
858
524
99
920
301
494
350
10
224
902
50
927
445
907
887
895
325
635
374
989
659
23
451
846
459
680
239
374
255
145
775
175
39
124
399
680
336
640
901
741
249
111
916
350
503
577
989
422
606
443
201
10
350
201
127
635
989
876
674
376
1
702
990
602
990
838
248
989
841
155
8...

result:

ok 

Test #93:

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

input:

0
10
992 1000000000
274 302
761 266
243 116
753 556
69 885
191 771
127 476
904 335
735 660
798 382
116 771
973 331
753 437
318 813
250 127
64 904
929 494
127 885
318 538
135 116
822 415
894 258
187 322
874 759
574 890
379 812
988 653
332 331
572 244
215 346
825 401
510 519
517 777
958 897
911 176
40...

output:

992
0
3
16
761
988
699
421
717
720
113
555
663
875
736
391
153
621
863
783
949
581
682
564
450
950
341
332
182
175
667
282
60
360
61
753
385
987
71
710
24
148
501
585
293
524
378
429
202
573
318
377
108
767
376
218
56
359
731
173
51
536
657
695
551
451
215
474
188
363
858
729
309
35
543
544
387
472
...

input:

1
49569
775 641 1
776
537 545 2
538
540
142 315 1
141
50 1 2
48
49
582 196 3
225
226
581
970 352 1
984
907 263 4
871
904
905
906
857 284 1
858
585 20 3
524
525
584
98 24 1
99
925 488 1
920
302 116 1
301
495 976 1
494
435 715 1
350
31 133 1
10
209 933 2
210
224
886 0 4
887
896
899
902
454 636 1
50
92...

output:

776
540
141
48
225
984
871
858
524
99
920
301
494
350
10
224
902
50
927
445
907
887
895
325
635
374
989
659
23
451
846
459
680
239
374
255
145
775
175
39
124
399
680
336
640
901
741
249
111
916
350
503
577
989
422
606
443
201
10
350
201
127
635
989
876
674
376
1
702
990
602
990
838
248
989
841
155
8...

result:

ok 

Test #94:

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

input:

0
10
1000 1000000000
880 197
507 738
947 24
750 375
785 686
514 578
885 51
988 286
813 807
384 826
436 909
304 273
322 772
368 921
802 592
951 168
937 494
937 450
667 703
62 981
618 350
800 460
668 12
126 532
723 262
525 741
950 567
220 587
477 326
212 582
160 788
772 225
754 196
553 741
471 31
332 ...

output:

1000
0
236
449
131
759
722
253
711
848
833
755
957
254
675
316
977
756
839
577
558
269
405
815
673
639
778
262
637
536
480
605
445
888
683
881
951
101
213
195
301
203
48
808
102
81
91
973
464
987
350
417
99
144
932
252
767
667
219
741
426
286
12
849
656
771
805
354
696
781
280
632
877
990
906
801
68...

input:

1
50684
407 965 1
389
160 875 1
159
16 774 2
1
2
601 74 1
598
683 276 1
966
538 58 1
545
754 151 1
758
909 867 3
905
906
907
215 936 2
216
270
686 550 1
648
395 338 2
396
418
54 262 10
55
56
57
58
59
60
62
68
69
262
435 508 2
108
434
892 306 3
165
874
890
857 159 1
875
982 202 1
999
584 722 1
999
12...

output:

389
159
1
598
966
545
758
905
270
648
418
262
108
165
875
999
999
64
268
485
169
456
29
640
602
639
415
144
876
776
650
24
561
283
306
637
999
307
345
366
950
95
914
24
692
752
929
18
117
524
957
427
559
306
945
670
735
765
18
321
743
301
826
743
74
18
987
109
363
975
795
943
661
290
963
943
494
735...

result:

ok 

Test #95:

score: 61
Accepted
time: 12ms
memory: 3804kb

input:

0
10
731 1000000000
730 284
530 730
304 730
730 104
730 252
48 730
615 730
472 730
730 414
730 441
64 730
150 730
351 730
86 730
730 542
730 207
416 730
730 145
45 730
730 159
409 730
603 730
730 353
690 730
71 730
730 579
730 684
730 93
730 88
38 730
730 419
22 730
595 730
730 675
730 633
730 183
4...

output:

731
0
523
214
692
94
40
419
363
454
602
466
330
180
76
93
702
207
136
524
375
617
122
32
557
698
622
578
111
46
320
373
210
584
187
240
292
673
688
30
275
689
142
231
395
717
19
591
223
6
244
479
163
556
48
328
544
41
507
77
61
676
553
215
500
11
272
701
69
597
366
308
25
403
433
70
595
131
422
586
...

input:

1
5230
211 201 1
0
250 341 1
0
269 537 1
730
259 603 1
0
48 608 1
730
559 235 1
0
672 603 1
730
247 9 1
0
579 616 1
0
298 688 1
0
576 654 1
730
95 406 1
0
576 379 1
730
622 430 1
0
326 534 1
730
94 274 1
0
527 449 1
730
727 692 1
0
484 173 1
0
495 444 1
730
102 602 1
730
509 360 1
730
225 599 1
730
...

output:

0
0
730
0
730
0
730
0
0
0
730
0
730
0
730
0
730
0
0
730
730
730
730
0
0
0
730
730
0
0
65
0
0
0
0
730
0
730
0
730
0
0
719
0
0
0
730
730
0
0
730
0
0
730
0
0
0
0
730
0
0
0
730
0
0
730
730
730
0
0
0
730
730
0
0
730
0
730
0
730
0
730
0
730
0
0
730
730
0
730
0
0
730
730
730
508
730
0
730
0
730
0
0
0
730
0...

result:

ok 

Test #96:

score: 61
Accepted
time: 14ms
memory: 3836kb

input:

0
10
1000 1000000000
999 515
999 808
389 999
137 999
936 999
887 999
287 999
999 299
999 704
14 999
999 937
387 999
841 999
78 999
894 999
757 999
691 999
71 999
779 999
999 676
838 999
999 524
999 359
999 19
29 999
405 999
192 999
17 999
136 999
31 999
999 952
999 735
696 999
942 999
999 223
530 99...

output:

1000
0
793
262
168
277
453
587
887
429
336
997
491
611
722
10
650
518
28
667
24
448
719
283
905
60
939
90
312
173
25
586
30
964
190
884
528
59
912
149
383
483
795
554
955
302
593
889
553
497
427
461
311
590
468
186
665
916
504
285
839
489
82
249
531
203
751
160
263
281
388
447
18
247
942
456
368
184...

input:

1
10180
700 389 1
0
0 277 1
999
717 178 1
0
719 135 1
999
124 242 1
999
633 120 1
0
640 258 1
999
591 343 1
0
645 291 1
0
760 825 1
0
565 29 1
999
424 253 1
0
735 77 1
0
926 318 1
0
957 664 1
0
270 782 1
0
895 332 1
999
137 99 1
999
661 88 1
999
466 490 1
0
124 511 1
0
97 756 1
999
607 841 1
0
931 2...

output:

0
999
0
999
999
0
999
0
0
0
999
0
0
0
0
0
999
999
999
0
0
999
0
999
0
999
0
999
999
999
0
999
999
999
999
999
0
0
999
0
0
563
999
0
0
0
0
999
0
0
999
999
999
0
0
0
999
0
999
0
999
999
0
0
999
999
999
999
999
0
999
0
0
0
999
999
999
999
0
0
999
999
999
999
0
999
0
999
0
999
0
999
999
999
0
0
999
999
...

result:

ok 

Test #97:

score: 61
Accepted
time: 16ms
memory: 4084kb

input:

0
10
892 1000000000
606 640
172 727
509 98
109 640
296 474
23 332
782 57
427 887
57 179
720 206
766 218
884 395
110 412
188 813
801 345
131 824
359 689
686 789
274 346
167 842
429 845
249 550
273 798
588 61
631 364
120 266
296 213
819 110
10 420
401 438
286 261
813 61
454 67
824 59
174 859
252 271
3...

output:

892
0
792
373
783
547
275
500
460
801
211
398
539
155
183
38
612
284
627
461
172
273
562
663
741
244
394
452
581
223
830
645
360
871
197
191
166
563
144
843
192
739
277
161
643
415
108
51
376
662
757
852
403
89
762
686
239
868
641
48
19
517
320
870
322
266
3
593
105
288
559
396
205
83
769
154
595
41...

input:

1
13208
881 363 8
6
874
875
876
877
878
879
880
559 51 11
493
549
550
551
552
553
554
555
556
557
558
882 309 10
1
873
874
875
876
877
878
879
880
881
91 223 10
11
82
83
84
85
86
87
88
89
90
855 160 10
4
846
847
848
849
850
851
852
853
854
73 97 10
74
75
76
77
78
79
80
81
82
93
220 602 2
221
224
410...

output:

6
493
1
11
4
93
224
70
196
27
523
816
89
726
560
696
726
555
783
46
720
198
549
720
436
171
2
27
811
720
886
551
781
619
781
356
683
369
1
412
577
171
321
619
376
196
457
326
890
840
269
69
837
135
57
6
457
629
186
382
350
64
155
726
269
69
726
886
645
538
493
548
369
825
782
462
297
720
156
768
6
6...

result:

ok 

Test #98:

score: 61
Accepted
time: 12ms
memory: 4120kb

input:

0
10
1000 1000000000
180 624
132 59
664 556
950 732
810 7
7 911
627 313
332 648
703 375
220 710
922 375
812 676
664 387
725 759
223 711
329 138
536 671
316 235
182 116
65 893
948 116
521 965
728 495
502 950
521 460
103 682
574 331
89 865
490 979
530 125
980 65
176 190
308 702
308 597
309 107
523 566...

output:

1000
0
89
142
341
401
864
970
46
334
816
320
42
309
64
186
446
969
21
817
439
576
106
902
331
472
857
514
269
165
303
91
61
499
158
200
138
210
553
952
90
529
58
307
652
965
654
647
666
708
291
250
862
945
760
762
405
705
872
266
465
730
883
85
518
289
571
986
151
789
217
933
233
976
80
638
649
640
...

input:

1
16365
411 936 9
412
413
414
415
416
417
418
419
429
221 797 8
222
223
224
225
226
227
228
245
874 118 8
882
890
898
906
914
922
930
988
55 622 9
128
201
274
323
396
835
908
981
991
537 700 3
531
535
536
459 872 8
427
452
453
454
455
456
457
458
828 175 6
735
798
804
810
816
822
524 527 9
470
516
5...

output:

429
245
988
835
531
427
735
470
17
582
884
149
460
610
498
274
505
342
9
395
892
259
360
397
17
986
188
785
312
178
484
714
908
802
245
702
201
974
412
676
103
668
283
854
103
462
454
784
323
113
455
464
701
826
506
109
9
810
565
170
565
236
649
297
578
421
835
868
48
682
817
369
171
201
267
671
272...

result:

ok 

Test #99:

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

input:

0
10
712 1000000000
165 500
293 270
484 552
3 324
308 190
621 104
561 389
581 286
154 188
251 457
223 99
633 660
446 540
160 610
150 323
93 265
273 380
268 297
38 376
670 568
653 209
253 291
384 187
434 193
422 131
96 418
625 325
72 325
299 590
645 552
486 384
28 153
37 246
309 566
91 686
468 464
57...

output:

712
0
684
590
707
572
58
504
458
87
296
115
291
117
142
502
448
225
220
425
113
303
674
408
158
50
661
270
526
10
424
543
644
157
486
701
529
346
672
181
488
593
635
563
397
406
545
688
418
269
561
329
580
126
191
400
512
499
40
482
404
324
517
603
209
634
226
521
588
628
342
179
443
43
112
215
557
...

input:

1
33400
615 498 3
247
248
249
309 466 3
108
110
111
124 2 3
550
551
553
109 355 3
33
34
35
47 91 3
547
548
549
532 390 3
344
345
531
391 377 3
30
32
390
346 312 3
74
75
345
339 182 3
505
506
508
229 227 3
230
378
380
440 666 3
417
419
420
527 366 3
438
440
526
508 451 3
238
239
507
61 475 3
179
180
...

output:

249
108
553
33
547
345
32
75
508
380
417
438
239
181
488
513
148
271
375
150
28
592
68
560
72
255
295
441
232
571
652
537
652
182
473
264
52
533
467
300
225
540
684
304
52
175
181
423
132
628
342
99
657
259
558
259
499
508
408
588
366
142
42
236
64
445
470
455
513
267
542
531
5
542
4
57
394
371
218
...

result:

ok 

Test #100:

score: 61
Accepted
time: 26ms
memory: 3836kb

input:

0
10
1000 1000000000
339 519
436 552
9 671
650 693
652 769
640 509
384 65
726 126
261 226
444 449
419 177
123 140
813 825
4 483
859 484
506 423
273 852
939 263
891 108
985 3
299 95
490 816
846 130
963 551
714 667
771 311
856 316
515 601
647 905
2 877
612 372
163 540
642 602
717 169
699 632
854 124
5...

output:

1000
0
524
74
175
956
784
648
394
774
199
843
720
876
386
984
656
434
170
368
341
645
6
332
781
271
914
487
604
823
676
91
665
134
334
289
733
496
194
898
402
687
299
563
803
587
549
324
227
133
875
636
222
507
178
468
495
890
122
403
650
864
162
497
501
124
361
865
217
127
182
990
511
214
273
277
6...

input:

1
33377
507 140 3
829
830
832
216 205 3
217
725
726
590 910 3
321
323
324
741 250 3
196
198
740
801 986 3
49
50
51
414 503 3
136
137
138
845 298 3
259
260
261
897 546 3
451
452
896
33 508 3
515
516
517
548 207 3
670
671
672
159 270 3
38
40
158
878 82 3
50
51
52
248 365 3
249
593
595
452 220 3
484
48...

output:

832
726
321
198
49
136
261
452
515
672
38
52
593
486
553
292
94
70
222
937
241
210
952
472
130
165
765
6
141
491
340
536
764
714
412
776
839
195
235
106
675
219
472
459
515
76
959
18
817
506
707
6
814
697
801
914
4
506
252
119
921
392
98
853
267
438
144
285
388
365
820
463
817
769
295
76
705
77
540
...

result:

ok 

Test #101:

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

input:

0
10
905 1000000000
149 541
744 692
648 655
441 692
692 263
648 156
754 161
20 648
538 541
285 648
843 541
720 541
692 791
648 167
357 648
533 648
196 541
626 754
692 511
754 485
56 754
893 541
796 541
19 692
541 110
471 541
833 541
754 508
541 593
406 692
355 754
541 777
618 648
648 760
754 121
294...

output:

905
0
736
503
271
491
616
526
625
681
392
48
855
826
329
709
126
161
18
741
6
436
402
832
628
196
289
868
652
106
308
150
808
688
371
815
840
533
784
891
708
598
81
317
845
306
171
365
516
210
112
211
515
102
541
403
700
31
356
411
624
145
752
43
246
734
483
776
358
711
674
309
539
91
471
101
229
84...

input:

1
4502
373 894 42
315
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
694 498 1
420
661 359 1
665
130 336 69
131
132
133
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695...

output:

315
420
665
680
424
158
103
264
91
111
904
682
123
637
9
420
904
672
904
353
14
169
130
309
73
852
103
680
904
530
49
123
394
624
904
629
412
17
103
795
692
420
904
547
547
111
665
547
370
675
831
904
796
680
130
904
27
303
708
130
472
169
377
904
31
91
208
605
904
530
91
9
904
680
284
111
904
852
4...

result:

ok 

Test #102:

score: 61
Accepted
time: 14ms
memory: 3836kb

input:

0
10
1000 1000000000
864 948
95 883
976 573
252 601
415 95
95 514
601 388
573 857
666 136
535 95
751 666
605 541
666 971
289 541
69 501
601 321
370 573
438 601
681 515
541 795
948 668
948 827
515 14
515 94
478 601
319 95
69 342
461 186
573 704
69 706
573 301
573 16
772 601
788 666
948 537
666 530
51...

output:

1000
0
666
869
579
400
551
667
4
426
571
396
507
931
50
216
213
776
616
318
954
745
251
888
960
423
416
851
846
588
730
64
972
433
362
531
707
33
451
903
870
672
208
606
878
332
648
308
909
293
556
355
76
900
49
863
549
484
908
445
29
364
188
769
113
708
483
339
829
805
101
415
609
835
69
837
635
93...

input:

1
4293
242 230 1
214
545 424 1
510
776 793 1
965
359 2 1
99
197 164 44
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
382
801 866 1
856
169 245 1
348
846 273 1
810
351 386 1
3...

output:

214
510
965
99
382
856
348
810
387
128
11
771
856
811
771
518
999
999
128
778
999
510
11
711
518
771
435
58
443
633
11
387
415
11
564
17
398
811
367
695
288
60
510
99
243
999
999
902
128
218
11
628
793
101
892
523
999
624
58
793
218
999
667
510
435
518
99
12
85
727
842
999
367
510
293
545
48
511
128...

result:

ok 

Extra Test:

score: 0
Extra Test Passed