QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#690031#1139. Stationssnpmrnhlol100 ✓48ms4076kbC++171.5kb2024-10-30 19:54:322024-10-30 19:54:32

Judging History

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

  • [2024-10-30 19:54:32]
  • 评测
  • 测评结果:100
  • 用时:48ms
  • 内存:4076kb
  • [2024-10-30 19:54:32]
  • 提交

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) {
    vector <vector<int>> e;
    vector<int> labels;
    e.resize(n);
    int cnt = 0;
    auto dfs = [&](auto self, int node, int p, int d) -> void{
        if(d == 0)labels[node] = cnt++;
        for(auto i:e[node]){
            if(i == p)continue;
            self(self, i, node, d^1);
        }
        if(d == 1)labels[node] = cnt++;
    };
	labels.resize(n);
	for(int i = 0;i < n - 1;i++){
        e[u[i]].push_back(v[i]);
        e[v[i]].push_back(u[i]);
	}
	for(int i = 0;i < n;i++){
        if(e[i].size() == 1){
            dfs(dfs, i, -1, 0);
            break;
        }
	}
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    if(c.size() == 1)return c[0];
    sort(c.begin(),c.end());
    if(s < c[0]){
        if(s <= t && t <= c[(int)c.size() - 2]){
            int nr = 1000000;
            for(auto i:c){
                if(t <= i){
                    nr = min(nr, i);
                }
            }
            return nr;
        }else{
            return c[(int)c.size() - 1];
        }
    }else{
        if(c[1] <= t && t <= s){
            int nr = -1;
            for(auto i:c){
                if(i <= t){
                    nr = max(nr, i);
                }
            }
            return nr;
        }else{
            return c[0];
        }
    }
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

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

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
4
8
3
9
2
7
6
0
1
5
3
0
2
1
998
109
886
915
992
254
408
815
813
66
57
833
733
40
604
304
33
774
135
340
738
566
708
217
654
201
643
359
481
409
160
894
578
597
647
488
828
227
944
423
544
870
3
844
986
157
516
120
945
811
239
704
928
543
286
292
546
2
68
865
234
99
439
937
876
79
20
38
916
279
49...

input:

1
59784
0 1 1
1
365 409 2
633
634
0 1 1
1
848 310 2
151
152
2 1 1
1
1 0 1
0
0 1 1
1
533 56 2
465
466
1 0 2
2
3
0 3 1
3
474 416 2
525
526
6 3 2
3
4
985 679 2
13
14
934 400 2
65
66
808 125 2
188
189
285 437 2
714
715
0 1 1
1
96 79 2
3
4
2 1 2
0
1
0 1 1
1
538 46 2
459
460
1 0 1
0
233 941 2
766
767
0 1 ...

output:

1
633
1
152
1
0
1
465
3
3
526
3
14
66
188
714
1
4
1
1
459
0
767
1
2
503
1
0
0
239
49
861
1
6
20
0
803
46
7
3
6
244
775
805
55
658
908
551
276
7
2
239
150
1
2
2
1
405
2
3
0
0
802
270
467
67
966
0
0
857
646
125
207
0
292
468
2
1
926
1
1
666
2
283
2
62
81
361
6
6
6
2
72
3
1
366
293
669
2
579
394
312
0
...

result:

ok 

Test #2:

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

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
62
507
358
210
484
711
585
165
697
10
337
943
564
703
285
68
426
817
178
938
874
91
61
94
509
483
326
868
696
717
928
260
667
767
799
633
675
658
753
199
917
445
726
935
557
209
259
590
472
241
411
850
797
508
180
227
71
612
421
103
540
802
869
275
828
831
469
539
211
284
461
315
457
213
463
372...

input:

1
50048
333 28 2
659
660
557 273 2
433
434
377 946 2
619
620
546 365 2
446
447
324 99 2
673
674
415 111 2
580
581
529 142 2
466
467
378 176 2
618
619
598 386 2
401
402
593 885 2
402
403
437 725 2
557
558
472 455 2
524
525
118 19 2
881
882
720 47 2
270
271
874 70 2
116
117
21 831 2
969
970
74 979 2
9...

output:

660
433
620
446
674
581
466
619
401
402
558
525
882
270
116
969
919
510
252
940
180
911
623
114
197
850
759
273
750
317
64
793
263
640
981
728
690
740
823
401
694
884
792
839
546
706
275
116
47
478
831
489
145
223
200
693
488
803
741
298
225
971
797
208
985
959
344
130
116
126
126
373
467
468
122
95...

result:

ok 

Test #3:

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

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: 40ms
memory: 3768kb

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

input:

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

output:

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

result:

ok 

Test #5:

score: 5
Accepted
time: 28ms
memory: 4056kb

input:

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

output:

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

input:

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

result:

ok 

Test #6:

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

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
362
158
720
777
399
219
714
942
756
310
33
250
662
865
391
910
262
964
358
370
221
455
464
275
372
965
265
828
864
335
27
357
146
555
725
990
93
922
968
148
947
439
727
423
16
133
616
257
366
919
334
169
180
489
35
706
350
0
32
216
101
764
993
71
984
322
426
201
100
236
701
553
669
554
962
704
...

input:

1
50055
562 731 2
437
438
528 474 2
471
472
861 172 2
138
139
979 214 2
20
21
319 884 2
680
681
222 411 2
777
778
563 528 2
436
437
15 365 2
984
985
2 844 2
997
998
476 265 2
523
524
200 772 2
799
800
890 797 2
109
110
419 440 2
580
581
317 260 2
682
683
293 640 2
706
707
750 241 2
249
250
281 772 2...

output:

437
472
139
21
681
777
437
984
997
524
799
110
580
683
706
249
719
366
227
465
128
59
967
820
925
499
43
335
361
846
464
268
912
845
938
878
945
952
269
852
608
467
694
175
474
774
686
768
833
195
431
330
254
196
211
697
884
799
532
65
968
982
471
120
601
271
310
902
42
993
293
521
469
763
980
368
4...

result:

ok 

Test #7:

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

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
374
805
951
89
49
139
516
916
363
540
67
823
975
389
72
309
21
740
222
73
263
779
319
381
347
923
225
271
234
452
502
122
578
795
594
87
887
183
629
295
470
826
379
866
241
820
507
753
621
63
743
88
879
487
336
548
296
651
645
29
22
841
947
5
767
526
836
380
716
56
48
871
683
688
32
530
782
4
7...

input:

1
50046
890 719 2
109
110
434 241 2
565
566
975 750 2
24
25
432 409 2
567
568
614 787 2
385
386
692 373 2
307
308
302 129 2
697
698
439 996 2
560
561
314 398 2
685
686
409 456 2
590
591
496 945 2
503
504
536 521 2
463
464
375 518 2
624
625
751 744 2
248
249
17 285 2
982
983
528 616 2
471
472
11 428 ...

output:

110
566
25
568
385
308
698
561
685
590
504
464
624
249
982
471
988
464
849
312
585
675
26
186
948
729
955
482
216
766
987
195
192
336
486
882
671
937
391
336
249
834
329
980
332
162
166
893
737
882
452
240
86
533
627
215
367
958
600
58
287
783
241
447
462
842
993
849
221
248
417
19
155
65
613
834
66...

result:

ok 

Test #8:

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

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

input:

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

output:

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

result:

ok 

Test #9:

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

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: 3728kb

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

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

output:

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

result:

ok 

Subtask #2:

score: 8
Accepted

Test #11:

score: 8
Accepted
time: 24ms
memory: 4056kb

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
4
515
771
5
260
516
3
132
259
387
514
643
770
898
962
6
69
133
196
261
324
388
451
517
580
644
707
772
835
899
2
37
68
100
131
164
195
227
258
292
323
355
386
419
450
482
513
548
579
611
642
675
706
738
769
803
834
866
897
930
961
985
977
7
22
38
53
70
85
101
116
134
149
165
180
197
212
228
243
...

input:

1
50252
733 385 1
731
856 134 1
855
972 527 1
973
413 389 1
412
861 226 1
859
425 928 1
424
711 717 1
709
438 782 1
436
716 757 3
717
718
722
874 467 3
867
868
871
972 19 1
973
600 147 3
601
602
603
786 520 1
784
407 926 1
405
295 4 1
294
75 151 1
74
868 935 3
869
870
874
323 314 3
261
293
308
365 6...

output:

731
855
973
412
859
424
709
436
722
867
973
603
784
405
294
74
874
308
364
986
939
868
716
164
379
919
213
762
687
930
899
889
777
364
293
509
613
773
304
463
858
412
970
907
418
52
172
691
844
141
172
372
926
57
843
985
336
942
634
235
690
904
191
446
868
653
451
105
270
216
755
691
604
99
962
898
...

result:

ok 

Test #12:

score: 8
Accepted
time: 36ms
memory: 3776kb

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
2
25
17
1
18
3
10
30
28
21
24
6
9
13
16
0
29
26
27
19
20
22
23
4
5
7
8
11
12
14
15
128
3
98
66
2
67
4
35
121
113
82
97
19
34
50
65
1
114
99
106
68
75
83
90
5
12
20
27
36
43
51
58
127
124
117
120
102
105
109
112
71
74
78
81
86
89
93
96
8
11
15
18
23
26
30
33
39
42
46
49
54
57
61
64
125
0
122
123
1...

input:

1
59568
21 10 3
18
19
20
439 279 3
440
441
442
490 99 3
493
496
497
85 146 3
88
91
99
23 10 3
20
21
22
2 1 2
0
1
107 119 1
109
56 164 3
53
54
55
369 76 3
363
367
368
3 1 2
0
1
353 10 3
347
351
352
0 1 1
3
139 130 1
140
0 2 1
3
1 0 1
0
36 83 3
39
42
50
104 86 1
105
55 114 1
57
189 755 1
188
277 284 3...

output:

18
442
497
99
20
1
109
53
363
1
347
3
140
3
0
50
105
57
188
291
1
18
649
63
68
12
109
0
423
3
0
448
1
1
1
2
98
28
89
231
0
0
627
795
1
2
350
226
2
1
772
121
311
2
1
125
1
24
0
355
2
2
487
23
3
111
104
1
5
388
1
0
24
7
0
1
46
183
280
256
3
17
851
954
2
6
499
1
20
69
21
2
395
9
18
1
979
106
26
34
22
1...

result:

ok 

Test #13:

score: 8
Accepted
time: 48ms
memory: 4052kb

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: 40ms
memory: 3764kb

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

input:

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

output:

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

result:

ok 

Test #15:

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

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

input:

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

output:

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

result:

ok 

Test #16:

score: 8
Accepted
time: 32ms
memory: 3852kb

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
4
515
771
5
260
516
3
132
259
387
514
643
770
898
962
6
69
133
196
261
324
388
451
517
580
644
707
772
835
899
2
37
68
100
131
164
195
227
258
292
323
355
386
419
450
482
513
548
579
611
642
675
706
738
769
803
834
866
897
930
961
993
977
7
22
38
53
70
85
101
116
134
149
165
180
197
212
228
243...

input:

1
50108
323 96 3
261
293
308
132 796 3
5
6
69
340 206 3
347
354
355
219 248 3
212
213
216
728 507 1
727
290 685 1
288
525 221 3
518
519
522
910 339 1
908
186 868 1
184
973 625 3
970
971
972
285 618 3
286
287
291
471 886 3
472
473
474
476 739 1
475
371 22 3
378
385
386
176 846 3
177
178
179
280 888 1...

output:

261
5
355
212
727
288
518
908
184
970
291
474
475
386
179
278
712
649
371
451
172
393
412
634
219
953
708
612
96
808
890
260
116
160
765
85
923
258
747
631
74
70
754
92
288
641
397
294
914
739
823
213
563
434
823
46
962
963
635
213
220
855
211
610
156
687
580
498
36
347
799
966
676
795
683
308
336
3...

result:

ok 

Subtask #3:

score: 16
Accepted

Test #17:

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

input:

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

output:

2
0
1
997
565
306
218
854
396
715
169
286
755
583
102
622
443
880
807
793
468
440
409
523
351
189
656
213
651
485
900
959
875
232
551
576
394
735
129
244
763
678
606
918
475
353
867
314
362
859
28
47
179
643
701
621
714
930
716
932
473
964
127
74
858
849
871
0
425
532
256
505
965
114
566
851
586
996...

input:

1
59859
7 5 2
2
3
1 0 1
0
1 0 1
0
984 957 2
15
16
852 801 2
146
147
366 67 2
631
632
0 1 1
1
1 2 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
548 652 2
448
449
814 893 2
185
186
744 748 2
255
256
6 8 2
3
4
1 2 1
2
285 180 2
711
712
34 59 2
65
66
221 208 2
776
777
192 617 2
806
807
509 52...

output:

3
0
0
16
147
632
1
8
938
1
1
0
1
448
185
255
3
2
712
65
777
806
487
508
1
86
819
904
2
1
877
2
228
3
0
1
813
163
103
1
752
906
505
321
4
3
459
204
488
1
885
3
770
662
90
22
1
33
0
0
2
7
7
20
302
415
30
3
160
1
134
170
16
3
714
1
432
377
1
358
2
33
740
1
1
644
1
187
1
653
80
1
2
2
865
6
2
1
197
1
452...

result:

ok 

Test #18:

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

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
99
993
585
538
372
212
729
801
525
96
692
89
23
726
59
202
741
775
98
539
404
227
467
515
362
403
370
555
286
357
989
879
48
471
354
669
975
757
646
568
495
645
126
182
721
812
664
977
793
21
187
524
107
486
455
616
7
43
782
348
876
784
504
922
367
893
118
19
933
848
50
398
130
974
966
564
57
62...

input:

1
50048
600 806 2
390
391
795 128 2
200
201
406 428 2
589
590
820 610 2
170
171
337 964 2
661
662
237 608 2
761
762
507 617 2
483
484
958 853 2
32
33
899 510 2
96
97
974 763 2
20
21
364 807 2
634
635
385 461 2
611
612
988 770 2
4
5
441 248 2
553
554
121 107 2
874
875
449 40 2
543
544
861 374 2
134
1...

output:

390
200
589
171
662
761
483
33
97
21
635
611
5
554
875
544
135
533
823
343
670
115
307
341
431
335
742
253
769
749
574
589
642
327
483
207
932
371
718
661
470
668
576
95
614
788
178
775
748
730
518
732
941
32
383
887
584
578
667
428
725
66
895
678
190
46
911
930
980
966
541
976
724
592
929
529
175
5...

result:

ok 

Test #19:

score: 16
Accepted
time: 48ms
memory: 3776kb

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: 40ms
memory: 3860kb

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

output:

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

result:

ok 

Test #21:

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

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

input:

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

output:

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

result:

ok 

Test #22:

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

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
638
816
188
306
993
224
981
387
680
536
696
900
748
254
517
444
305
165
781
410
341
238
823
311
27
959
548
454
403
471
588
437
503
683
376
298
462
706
234
857
286
6
652
830
870
672
455
161
822
924
661
331
26
543
515
369
80
138
226
303
527
314
519
511
258
839
262
383
310
709
431
718
914
278
249
...

input:

1
50050
608 509 2
391
392
384 385 2
615
616
588 145 2
411
412
545 887 2
454
455
501 853 2
498
499
681 287 2
318
319
418 848 2
581
582
156 976 2
843
844
191 731 2
808
809
132 502 2
867
868
653 310 2
346
347
75 276 2
924
925
132 644 2
867
868
914 969 2
85
86
199 124 2
800
801
728 214 2
271
272
663 66 ...

output:

392
615
411
454
498
318
582
844
808
867
346
924
867
85
801
271
336
843
370
441
772
850
923
866
283
296
698
881
251
668
462
37
518
968
691
155
339
697
445
629
707
827
26
639
291
94
875
711
399
436
71
17
298
747
768
245
624
709
206
229
865
926
697
166
922
573
497
914
131
627
1
702
507
178
561
215
113
...

result:

ok 

Test #23:

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

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
617
978
685
548
584
782
37
912
615
438
120
388
97
62
966
998
522
828
244
427
571
898
375
950
105
233
306
663
414
861
656
817
529
386
79
941
856
10
370
525
523
402
929
333
147
837
561
524
327
305
863
41
308
682
175
322
158
841
238
474
185
196
156
355
417
574
539
371
630
266
33
751
681
299
696
94...

input:

1
50053
277 673 2
722
723
190 906 2
809
810
591 484 2
408
409
61 761 2
938
939
784 166 2
215
216
948 892 2
51
52
480 916 2
519
520
745 238 2
254
255
153 694 2
846
847
705 212 2
294
295
490 482 2
509
510
897 126 2
102
103
920 604 2
79
80
405 109 2
594
595
879 891 2
120
121
437 960 2
562
563
386 417 2...

output:

722
810
409
938
215
52
520
254
846
294
510
103
80
595
120
563
613
958
960
280
303
823
124
808
806
759
550
165
457
646
630
100
979
850
57
298
873
258
879
476
145
412
922
7
196
847
598
276
618
689
159
754
230
841
675
35
393
803
833
933
343
280
513
442
637
596
209
828
926
488
377
717
917
110
134
112
10...

result:

ok 

Test #24:

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

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

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

output:

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

result:

ok 

Test #25:

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

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: 3728kb

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

input:

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

output:

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

result:

ok 

Test #27:

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

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

input:

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

output:

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

result:

ok 

Test #28:

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

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
228
277
452
588
935
819
618
333
0
956
204
671
320
471
392
676
15
811
678
64
498
623
119
385
702
495
416
474
44
388
826
345
626
383
287
924
182
300
184
907
77
235
647
572
927
640
506
855
513
28
21
502
701
34
233
527
164
328
290
573
57
240
239
688
948
463
735
785
734
837
229
916
428
5
361
418
606...

input:

1
51340
774 606 2
228
229
367 474 2
632
633
308 431 2
691
692
278 923 2
312
313
51 251 2
948
949
581 260 2
561
562
683 218 2
665
666
119 878 2
111
112
570 720 1
571
700 682 1
1
695 737 2
307
308
994 780 2
8
9
653 83 2
666
667
705 942 1
999
958 881 2
952
953
638 573 2
641
642
175 650 2
239
240
627 31...

output:

229
632
691
313
948
561
665
111
571
1
307
9
667
999
952
642
240
999
1
830
575
815
354
918
775
999
949
215
172
76
943
379
137
214
648
39
543
130
664
749
430
576
710
1
388
237
497
0
927
263
178
216
887
603
294
999
914
889
416
412
963
1
934
176
999
18
108
666
259
143
24
830
335
765
622
18
253
224
284
7...

result:

ok 

Test #29:

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

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
21
598
511
0
292
460
385
713
54
397
860
590
173
717
869
575
774
958
398
835
254
602
871
324
969
586
513
967
661
115
492
800
433
998
772
522
224
698
839
854
441
616
357
863
673
756
877
103
85
367
505
897
176
483
142
664
915
945
294
662
726
822
136
758
244
766
62
543
165
237
73
53
306
387
36
442
...

input:

1
51513
389 540 2
621
622
251 373 2
211
212
415 617 1
999
485 744 1
999
691 474 2
685
686
482 154 2
485
486
649 111 2
348
349
40 226 2
959
960
570 66 2
551
552
490 386 1
999
937 354 2
61
62
892 281 2
896
897
576 671 2
591
999
540 907 2
527
528
832 975 2
567
568
744 911 2
576
577
49 179 1
998
180 628...

output:

621
211
999
999
685
486
348
959
551
999
62
897
999
527
567
576
998
459
678
264
107
286
999
207
816
662
999
932
69
548
834
785
285
396
742
866
500
247
153
999
286
821
12
618
351
999
27
999
426
67
999
999
8
701
999
317
999
625
34
772
225
122
447
187
182
752
360
714
911
328
416
995
282
422
777
240
956
...

result:

ok 

Test #30:

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

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
658
314
0
203
69
353
901
626
206
320
42
661
34
130
117
356
382
566
194
225
650
554
272
147
190
289
519
944
611
252
31
119
831
288
711
530
714
767
56
665
846
872
108
843
150
983
209
305
432
89
293
111
960
926
498
683
32
154
24
522
627
263
372
384
233
235
217
379
848
299
880
772
409
286
685
487
6...

input:

1
49931
640 784 2
642
643
331 771 2
360
361
17 430 30
49
89
118
138
167
192
229
261
288
324
367
392
426
454
480
516
556
583
624
658
690
723
753
786
824
853
898
938
982
983
288 783 2
17
262
445 984 2
435
436
598 603 2
609
610
757 511 2
782
783
959 489 2
961
962
293 883 2
319
320
895 191 2
856
857
94 ...

output:

643
361
454
17
435
609
783
962
320
856
114
491
42
329
17
65
420
632
900
336
578
149
853
488
800
152
535
501
947
418
17
625
791
767
587
658
831
731
538
238
67
312
650
524
852
688
558
789
476
771
683
841
559
288
399
584
612
406
29
692
152
106
760
456
278
666
872
37
893
215
956
17
515
454
97
367
745
70...

result:

ok 

Test #31:

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

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

input:

1
4026
65 93 1
95
16 77 1
95
34 83 1
95
49 43 1
95
69 76 1
95
95 17 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...

output:

95
95
95
95
95
17
95
95
95
95
95
95
95
95
24
95
0
95
81
95
95
95
95
95
66
95
95
60
95
95
95
95
26
95
95
95
95
95
95
95
95
95
95
95
25
95
95
95
95
95
74
45
18
95
20
95
95
95
95
95
95
95
95
95
95
10
95
95
45
95
8
95
95
95
95
95
95
55
95
95
95
95
95
95
95
93
95
95
95
95
95
95
25
84
95
9
52
39
93
95
95
...

result:

ok 

Test #32:

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

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
540
201 375 1
540
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...

output:

540
540
540
540
402
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
...

result:

ok 

Test #33:

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

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
999
0
877
520
905
468
452
440
100
609
423
160
347
343
604
98
843
18
244
211
972
688
22
596
16
700
770
58
870
573
567
320
460
229
54
28
205
430
424
260
571
714
432
140
600
226
749
327
235
633
417
955
850
261
810
392
707
589
208
45
210
214
172
811
462
826
971
496
158
569
236
522
37
70
952
762
384...

input:

1
10180
71 387 1
999
46 334 1
999
56 339 1
999
122 914 1
999
196 717 1
999
970 767 1
999
736 589 1
999
402 607 1
999
613 255 1
999
105 319 1
999
275 804 1
999
774 189 1
999
28 666 1
999
238 327 1
999
107 172 1
999
75 237 1
999
281 564 1
999
182 710 1
999
191 982 1
999
392 830 1
999
513 606 1
999
119...

output:

999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
839
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
240
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
...

result:

ok 

Subtask #4:

score: 10
Accepted

Test #34:

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

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: 32ms
memory: 3788kb

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

input:

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

output:

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

result:

ok 

Test #36:

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

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

input:

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

output:

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

result:

ok 

Test #37:

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

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

input:

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

output:

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

result:

ok 

Test #38:

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

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: 3792kb

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

input:

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

output:

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

result:

ok 

Test #40:

score: 10
Accepted
time: 30ms
memory: 4072kb

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

input:

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

output:

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

result:

ok 

Test #41:

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

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: 40ms
memory: 3772kb

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

input:

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

output:

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

result:

ok 

Test #43:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #44:

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

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

input:

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

output:

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

result:

ok 

Test #45:

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

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

input:

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

output:

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

result:

ok 

Test #46:

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

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

input:

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

output:

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

result:

ok 

Test #47:

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

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

output:

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

result:

ok 

Test #48:

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

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

input:

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

output:

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

result:

ok 

Test #49:

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

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

input:

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

output:

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

result:

ok 

Test #50:

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

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

input:

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

output:

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

result:

ok 

Test #51:

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

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

input:

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

output:

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

result:

ok 

Test #52:

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

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

input:

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

output:

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

result:

ok 

Test #53:

score: 10
Accepted
time: 32ms
memory: 3792kb

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

input:

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

output:

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

result:

ok 

Subtask #5:

score: 61
Accepted

Test #54:

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

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
896
830
158
357
460
966
315
531
108
734
987
655
118
640
682
440
983
960
537
922
805
57
374
280
287
927
9
474
182
317
129
473
310
408
729
869
778
638
398
141
902
748
517
430
271
720
528
606
870
56
859
934
784
923
894
850
611
267
77
97
188
670
771
651
823
933
313
593
718
405
904
88
478
442...

input:

1
59797
1 2 2
2
3
886 933 2
113
114
1 0 1
0
42 74 2
57
58
862 460 2
136
137
3 0 2
0
1
3 2 2
0
1
837 689 2
160
161
472 271 2
526
527
786 861 2
210
211
0 1 1
1
128 124 2
871
872
181 817 2
818
819
125 222 2
872
873
2 0 2
0
1
663 964 2
333
334
742 541 2
257
258
87 80 2
12
13
4 5 2
5
6
912 677 2
87
88
47...

output:

2
113
0
58
137
0
1
161
527
210
1
872
818
872
0
333
258
13
5
88
529
0
3
718
7
547
416
474
326
1
0
107
383
2
371
84
943
506
34
0
2
1
628
636
0
56
652
933
727
4
1
478
110
0
7
622
157
1
490
3
1
761
2
8
300
809
3
943
871
95
98
659
99
177
912
424
1
461
508
304
2
962
2
3
6
313
227
794
1
3
57
2
4
280
1
1
24...

result:

ok 

Test #55:

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

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
864
987
10
833
568
203
459
835
893
177
486
920
985
412
281
298
867
200
378
438
344
102
957
655
669
590
453
166
463
179
733
694
428
827
713
377
520
436
183
917
439
194
757
358
928
80
531
775
567
753
791
940
763
228
488
6
661
556
324
234
78
364
848
820
582
224
943
142
640
581
441
432
99
341
861
16...

input:

1
50045
324 892 2
666
667
60 42 2
932
933
783 35 2
214
215
724 862 2
267
268
388 174 2
608
609
805 79 2
187
188
853 36 2
139
140
788 746 2
211
212
376 133 2
622
623
669 63 2
325
326
849 889 2
148
149
205 202 2
787
788
574 843 2
417
418
133 950 2
866
867
613 423 2
378
379
888 518 2
110
111
937 661 2
...

output:

667
933
214
267
609
187
139
212
623
325
148
788
417
867
379
111
62
188
724
508
901
637
398
991
573
19
101
257
234
207
32
639
990
534
248
924
482
747
438
400
743
864
878
375
401
906
588
131
777
113
663
316
851
456
95
625
190
686
658
654
533
293
439
665
355
295
419
900
51
136
481
527
955
358
212
297
8...

result:

ok 

Test #56:

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

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: 40ms
memory: 3800kb

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

output:

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

result:

ok 

Test #58:

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

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

input:

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

output:

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

result:

ok 

Test #59:

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

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
748
640
942
658
723
745
555
972
809
941
477
317
776
980
179
593
747
341
520
46
339
12
497
116
733
895
884
448
313
419
937
800
539
466
864
698
931
743
16
646
273
148
140
248
280
826
205
762
620
422
424
186
629
835
60
521
916
608
995
482
613
473
673
250
878
335
369
971
674
703
54
77
43
925
883
0
...

input:

1
50038
309 684 2
690
691
339 645 2
660
661
435 781 2
564
565
459 600 2
540
541
690 511 2
309
310
117 916 2
882
883
476 345 2
523
524
735 121 2
264
265
804 827 2
195
196
305 778 2
694
695
730 954 2
269
270
694 890 2
305
306
516 352 2
483
484
843 550 2
156
157
112 399 2
887
888
326 466 2
673
674
341 ...

output:

690
660
565
541
310
883
524
264
195
695
269
305
483
157
887
673
658
536
414
657
334
741
988
900
171
424
80
311
23
540
864
642
434
843
986
795
905
95
858
670
283
974
470
406
815
744
583
672
355
310
847
609
707
38
952
460
486
121
383
550
43
861
551
338
937
790
117
435
446
338
298
86
475
784
623
649
91...

result:

ok 

Test #60:

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

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
221
752
699
250
9
409
420
770
59
790
6
652
657
396
321
799
125
175
745
570
674
929
346
726
447
698
888
406
82
386
378
226
14
366
532
38
354
379
352
49
841
515
446
915
713
771
873
555
750
654
150
999
826
106
285
587
228
325
868
215
615
843
879
94
631
703
892
452
260
128
178
706
425
565
481
596
1...

input:

1
50048
771 256 2
228
229
890 525 2
109
110
611 798 2
388
389
580 766 2
419
420
217 459 2
782
783
567 536 2
432
433
130 749 2
869
870
241 926 2
758
759
223 507 2
776
777
166 79 2
833
834
686 996 2
313
314
579 180 2
420
421
145 655 2
854
855
678 17 2
321
322
515 457 2
484
485
405 342 2
594
595
302 63...

output:

229
110
388
419
782
433
869
759
776
834
313
420
854
321
484
595
697
419
843
940
443
335
963
157
222
467
259
572
11
522
441
844
855
721
70
495
667
683
22
881
978
808
69
90
608
513
48
137
134
868
593
716
319
960
612
179
475
347
907
246
335
100
306
275
119
128
792
351
100
71
704
467
612
239
465
163
99
...

result:

ok 

Test #61:

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

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

input:

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

output:

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

result:

ok 

Test #62:

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

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: 3856kb

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

input:

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

output:

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

result:

ok 

Test #64:

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

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
4
515
771
5
260
516
3
132
259
387
514
643
770
898
962
6
69
133
196
261
324
388
451
517
580
644
707
772
835
899
2
37
68
100
131
164
195
227
258
292
323
355
386
419
450
482
513
548
579
611
642
675
706
738
769
803
834
866
897
930
961
985
977
7
22
38
53
70
85
101
116
134
149
165
180
197
212
228
243
...

input:

1
49888
708 394 3
715
722
738
183 375 1
181
775 207 1
774
751 403 1
750
475 693 3
476
477
481
482 800 3
451
452
467
224 821 1
223
1 571 3
985
992
996
949 286 1
947
544 935 3
545
546
547
494 146 3
495
496
497
585 88 3
586
587
588
894 398 1
893
835 336 3
866
897
898
648 241 1
646
864 28 1
862
486 552 ...

output:

738
181
774
750
481
451
223
985
947
547
497
588
893
898
646
862
484
37
459
23
506
419
969
942
308
750
707
915
572
899
172
999
276
68
957
242
453
896
516
242
463
788
194
684
187
517
773
71
195
173
671
582
247
878
378
300
434
564
690
596
575
179
450
978
367
649
858
347
787
815
37
707
418
585
799
213
1...

result:

ok 

Test #65:

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

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
4
387
259
3
260
5
132
482
450
323
386
68
131
195
258
2
451
388
419
261
292
324
355
6
37
69
100
133
164
196
227
505
497
466
481
403
418
434
449
276
291
307
322
339
354
370
385
21
36
52
67
84
99
115
130
148
163
179
194
211
226
242
257
1
498
483
490
452
459
467
474
389
396
404
411
420
427
435
442
2...

input:

1
59652
27 9 1
28
375 156 1
377
2 0 1
1
0 1 1
1
29 99 1
30
1 2 2
2
3
0 1 1
1
1 0 1
0
0 1 1
1
242 356 3
227
228
235
48 217 3
45
46
47
2 16 3
98
113
121
1 2 1
2
642 502 3
580
612
627
412 410 1
414
26 12 1
28
0 1 1
1
69 65 1
71
35 27 3
50
65
66
128 481 1
127
421 468 1
423
3 1 2
0
1
1 2 1
2
137 251 3
13...

output:

28
377
1
1
30
2
1
0
1
227
45
98
2
580
414
28
1
71
66
127
423
1
2
134
1
133
3
16
24
1
38
2
1
2
385
3
1
18
148
2
448
96
6
667
155
1
3
474
0
1
1
11
21
2
493
0
3
25
0
1
363
1
1
3
0
3
3
115
105
99
193
2
39
435
307
9
3
57
1
8
1
1
1
21
93
1
1
18
234
287
28
11
0
417
1
3
498
21
2
1
25
50
20
3
3
0
556
2
77
0
...

result:

ok 

Test #66:

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

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: 40ms
memory: 3772kb

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

input:

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

output:

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

result:

ok 

Test #68:

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

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

input:

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

output:

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

result:

ok 

Test #69:

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

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
4
515
771
5
260
516
3
132
259
387
514
643
770
898
962
6
69
133
196
261
324
388
451
517
580
644
707
772
835
899
2
37
68
100
131
164
195
227
258
292
323
355
386
419
450
482
513
548
579
611
642
675
706
738
769
803
834
866
897
930
961
993
977
7
22
38
53
70
85
101
116
134
149
165
180
197
212
228
243...

input:

1
50098
723 428 3
730
737
738
545 839 1
544
756 280 1
755
192 764 1
191
171 741 1
169
989 713 3
990
991
992
570 912 1
568
806 361 1
805
76 268 1
74
6 605 3
37
68
132
576 369 1
575
430 466 1
428
246 509 1
244
643 761 3
516
517
580
858 659 3
851
852
855
137 558 1
135
459 899 3
452
453
456
61 740 3
62
...

output:

738
544
755
191
169
992
568
805
74
132
575
428
244
516
851
135
452
67
512
23
244
475
836
109
731
743
976
947
626
563
716
333
516
723
627
45
211
277
436
292
134
652
273
580
962
71
403
755
970
307
868
664
914
804
324
858
973
734
149
117
560
428
580
347
875
145
771
661
626
53
216
628
85
886
420
645
705...

result:

ok 

Test #70:

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

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

input:

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

output:

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

result:

ok 

Test #71:

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

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
335
287
776
573
228
268
720
492
339
727
207
612
542
267
876
375
827
716
760
771
654
51
505
904
435
19
312
59
915
590
473
2
745
225
257
290
707
713
980
879
85
81
917
911
123
589
397
575
33
338
189
377
478
49
842
592
577
793
465
222
734
132
559
943
766
120
794
990
918
584
64
163
924
330
197
88
48...

input:

1
50431
84 449 2
914
915
333 453 2
312
313
949 574 1
999
599 14 2
399
400
549 965 1
999
557 573 2
442
443
812 754 2
801
802
212 459 2
787
788
607 153 2
614
615
987 149 2
997
998
821 622 2
178
179
493 335 2
506
507
906 846 2
92
93
709 584 2
290
291
802 762 1
999
539 183 1
999
589 897 2
592
593
492 58...

output:

914
312
999
399
999
442
801
787
615
998
179
507
93
291
999
999
593
507
479
918
159
999
273
999
908
313
303
761
309
665
842
739
350
49
966
278
1
279
744
387
628
606
698
135
21
158
716
194
190
161
967
426
645
646
498
370
462
94
617
653
1
235
999
485
381
383
336
321
387
391
404
999
900
512
220
352
263
...

result:

ok 

Test #72:

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

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
226
179
250
922
858
984
401
237
102
960
525
320
94
656
997
594
346
194
108
744
166
288
136
163
477
498
537
168
70
21
592
759
731
141
713
966
486
610
339
971
899
860
900
33
941
260
880
195
951
18
667
923
745
251
671
392
887
156
719
904
889
308
893
732
174
390
937
80
321
238
599
5
97
77
512
785
7...

input:

1
51725
527 82 2
458
459
202 25 2
798
799
333 357 2
343
344
767 316 1
768
14 295 1
999
838 704 2
147
148
298 877 2
300
301
557 548 2
429
430
558 279 2
541
542
751 2 2
771
772
11 791 1
999
554 342 2
446
447
934 255 2
51
52
980 488 1
999
628 473 2
372
373
751 864 2
702
703
837 21 2
148
149
993 555 1
9...

output:

458
799
344
768
999
148
301
430
541
772
999
446
52
999
373
702
148
994
149
702
552
972
144
999
999
720
486
296
999
618
21
558
767
919
356
926
85
429
563
952
289
61
957
76
83
999
412
849
961
999
998
804
756
274
226
292
997
443
88
205
131
605
502
763
916
658
999
6
115
60
997
997
416
999
113
172
706
44...

result:

ok 

Test #73:

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

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
408
165
636
6
3
282
204
328
501
488
278
211
337
0
125
858
923
96
726
106
684
954
659
30
506
532
525
388
994
372
137
240
706
516
284
860
325
371
418
333
754
683
334
425
87
983
402
238
273
360
859
288
395
196
129
349
544
594
980
460
213
677
47
692
338
821
252
653
293
584
493
984
642
185
648
545
1...

input:

1
49651
889 652 2
894
895
861 423 1
862
252 418 2
263
264
433 665 1
432
798 305 1
799
638 567 2
639
640
428 914 2
437
438
247 959 2
268
269
101 295 2
87
88
463 59 2
472
473
349 7 2
382
383
25 39 2
27
28
540 924 2
520
521
310 508 2
279
280
130 157 2
132
133
634 390 2
643
644
969 270 2
973
974
821 442...

output:

895
862
264
432
799
640
438
269
87
473
383
28
520
279
133
644
974
845
716
985
879
663
119
505
985
913
897
250
334
470
180
342
165
49
285
382
820
946
686
652
815
985
359
380
132
113
828
834
999
985
666
864
909
143
918
868
105
554
410
705
770
194
41
678
584
797
746
870
552
958
791
840
778
439
153
943
...

result:

ok 

Test #74:

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

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
95
95
37
95
95
95
95
95
95
95
95
95
28
95
95
0
95
95
95
95
95
95
95
95
95
95
95
95
95
95
95
95
95
95
95
95
95
89
95
95
95
50
95
95
95
95
95
82
95
38
82
52
95
68
50
95
95
95
95
95
95
95
95
95
95
95
95
95
42
51
17
60
95
95
95
57
95
95
95
95
95
95
95
95
95
95
95
95
95
64
86
95
95
95
95
95
74
9...

result:

ok 

Test #75:

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

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
540
0
250
54
62
312
321
369
63
57
237
387
251
498
422
366
381
41
466
272
98
484
83
142
203
75
476
169
124
508
249
535
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
524
232
489
475
310
336
2
174
7
400
343
96
195
159...

input:

1
6214
484 470 1
540
434 217 1
540
58 503 1
540
308 332 1
540
485 301 1
540
310 482 1
540
45 65 1
540
353 93 1
540
160 30 1
540
420 139 1
540
112 211 1
540
172 400 1
540
383 352 1
540
359 253 1
540
401 238 1
540
438 298 1
540
162 426 1
540
266 314 1
540
237 131 1
540
366 221 1
540
499 540 1
540
435 ...

output:

540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
353
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
540
154
540
540
540
540
540
540
540
540
...

result:

ok 

Test #76:

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

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
999
4 424 1
999
617 21 1
999
203 286 1
999
470 861 1
999
531 782 1
999
133 908 1
999
213 609 1
999
967 870 1
999
551 572 1
999
978 747 1
999
859 355 1
999
668 689 1
999
782 396 1
999
150 322 1
999
677 512 1
999
287 913 1
999
287 790 1
999
50 101 1
999
397 26 1
999
290 875 1
999
762 ...

output:

999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
...

result:

ok 

Test #77:

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

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

input:

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

output:

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

result:

ok 

Test #78:

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

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

output:

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

result:

ok 

Test #79:

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

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

input:

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

output:

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

result:

ok 

Test #80:

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

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

input:

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

output:

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

result:

ok 

Test #81:

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

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

input:

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

output:

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

result:

ok 

Test #82:

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

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

input:

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

output:

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

result:

ok 

Test #83:

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

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

output:

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

result:

ok 

Test #84:

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

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

output:

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

result:

ok 

Test #85:

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

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

output:

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

result:

ok 

Test #86:

score: 61
Accepted
time: 32ms
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
6
7
1
2
0
5
3
4
8
3
4
0
5
2
6
7
1
8
6
0
2
3
1
5
7
4
8
3
0
6
1
5
2
7
4
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
7 0 4
0
1
4
6
0 5 1
7
6 2 1
7
1 0 1
7
0 5 1
7
0 1 1
7
4 7 2
5
7
0 7 1
7
6 2 1
7
4 6 1
7
2 5 1
1
1 4 1
7
2 1 1
7
4 1 1
5
7 6 2
0
1
0 4 1
7
6 2 1
7
3 1 1
2
3 4 2
4
5
1 0 1
7
5 7 1
1
7 4 2
0
1
0 2 1
7
6 5 2
1
2
1 7 2
6
7
4 7 1
3
6 1 2
1
3
4 5 1
5
7 4 2
0
1
7 4 2
0
1
0 6 1
7
1 5 ...

output:

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

result:

ok 

Test #87:

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

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
804
649
610
680
246
657
220
508
366
144
349
96
290
63
237
524
421
161
716
188
503
517
43
444
160
705
259
475
238
966
203
528
944
359
461
210
886
781
61
353
737
867
915
783
56
49
244
650
462
947
973
645
193
793
460
553
414
571
457
339
29
32
638
684
959
190
82
437
365
774
525
219
169
252
95
784
47...

input:

1
35090
325 274 2
541
542
345 52 2
520
521
519 387 2
522
523
855 913 2
133
134
551 137 2
429
430
470 440 2
673
674
329 760 2
213
214
980 879 2
14
15
559 329 2
454
455
700 837 2
443
444
955 887 2
22
23
314 577 2
111
112
379 644 2
881
882
170 763 2
372
373
522 819 2
344
345
604 330 2
330
331
750 108 2...

output:

542
521
523
133
429
674
213
15
454
443
23
111
881
373
344
330
825
518
784
204
944
147
83
541
904
974
838
329
855
160
198
355
479
826
858
441
307
631
222
909
829
566
477
245
414
95
379
809
39
564
310
158
2
477
702
410
464
496
142
716
689
400
595
872
855
76
598
330
142
49
721
655
950
601
354
604
375
1...

result:

ok 

Test #88:

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

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
818 715 2
816
817
826 268 3
819
820
823
773 38 1
770
46 262 3
47
48
52
41 907 1
40
4 15 1
5
694 858 2
304
305
573 98 2
574
575
81 723 2
918
919
681 851 6
682
683
685
690
691
697
508 491 1
498
219 502 2
779
780
357 374 1
999
705 948 2
707
711
71 809 3
72
73
77
0 272 1
999
876 675 2
123
124
29...

output:

816
819
770
52
40
5
304
575
918
697
498
779
999
711
77
999
124
300
999
837
574
225
999
3
715
952
193
188
874
753
64
450
364
791
818
966
681
61
896
997
970
869
999
140
504
921
431
276
869
848
3
953
244
999
946
780
650
511
440
316
4
999
999
747
474
917
43
411
484
792
873
961
276
8
450
400
543
54
724
1...

result:

ok 

Test #89:

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

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
80
979
349
367
632
330
466
20
863
875
474
618
792
645
540
862
867
555
773
148
312
373
941
831
841
969
470
739
887
461
824
188
940
451
874
686
730
35
919
945
218
776
14
179
666
986
830
229
230
631
596
641
414
818
884
736
242
925
467
609
983
954
599
236
836
683
372
272
535
805
735
827
168
750
846
...

input:

1
49922
846 399 2
847
848
702 63 1
710
328 790 2
337
338
623 149 2
366
367
238 962 2
427
428
732 847 2
767
768
775 460 2
482
483
194 597 3
195
197
198
948 564 2
41
42
283 672 2
295
296
716 494 2
723
724
137 561 2
112
113
509 942 2
748
749
780 577 1
779
54 515 1
63
290 310 2
700
701
75 176 2
914
915
...

output:

848
710
338
366
428
768
482
198
42
296
724
112
749
779
63
700
914
74
382
519
371
295
189
763
790
150
12
716
815
362
565
671
108
228
162
464
406
495
781
832
228
37
638
311
117
56
579
26
874
881
223
995
647
237
201
543
232
630
244
837
736
972
358
193
789
960
926
760
494
622
300
201
729
629
673
446
842...

result:

ok 

Test #90:

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

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
808 820 3
803
805
806
332 945 1
327
958 65 1
999
321 473 3
65
66
73
207 54 2
209
210
763 130 1
764
614 607 1
615
427 235 1
3
648 839 3
620
621
647
335 940 2
8
10
917 717 1
999
703 106 2
699
702
614 449 1
615
160 551 2
141
158
990 879 2
991
993
912 758 1
905
687 846 1
686
18 776 2
16
17
773 9...

output:

803
327
999
65
210
764
615
3
620
8
999
699
615
141
993
905
686
16
762
801
90
47
968
264
115
974
222
591
158
211
77
415
267
947
901
694
47
821
355
189
54
901
611
47
763
211
477
47
608
364
143
856
965
449
47
841
450
897
673
769
418
655
270
213
220
961
554
751
97
982
269
606
428
781
872
800
853
250
434...

result:

ok 

Test #91:

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

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
808 820 3
803
805
806
332 945 1
327
958 65 1
999
321 473 3
65
66
73
207 54 2
209
210
763 130 1
764
614 607 1
615
427 235 1
3
648 839 3
620
621
647
335 940 2
8
10
917 717 1
999
703 106 2
699
702
614 449 1
615
160 551 2
141
158
990 879 2
991
993
912 758 1
905
687 846 1
686
18 776 2
16
17
773 9...

output:

803
327
999
65
210
764
615
3
620
8
999
699
615
141
993
905
686
16
762
801
90
47
968
264
115
974
222
591
158
211
77
415
267
947
901
694
47
821
355
189
54
901
611
47
763
211
477
47
608
364
143
856
965
449
47
841
450
897
673
769
418
655
270
213
220
961
554
751
97
982
269
606
428
781
872
800
853
250
434...

result:

ok 

Test #92:

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

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
757 47 2
753
756
142 315 1
141
50 1 2
48
49
70 112 3
712
713
714
970 352 1
984
907 263 4
871
904
905
906
459 13 1
458
585 20 3
524
525
584
98 24 1
99
925 488 1
920
812 617 1
813
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
928 6...

output:

776
753
141
48
712
984
871
458
524
99
920
813
494
350
10
224
902
50
927
445
907
887
895
325
635
374
989
147
23
451
846
829
680
239
374
255
145
775
175
39
637
399
680
336
640
901
567
249
111
916
350
503
577
989
422
606
443
201
10
350
201
194
635
989
249
674
376
1
702
990
696
990
838
248
989
841
155
8...

result:

ok 

Test #93:

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

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
757 47 2
753
756
142 315 1
141
50 1 2
48
49
70 112 3
712
713
714
970 352 1
984
907 263 4
871
904
905
906
459 13 1
458
585 20 3
524
525
584
98 24 1
99
925 488 1
920
812 617 1
813
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
928 6...

output:

776
753
141
48
712
984
871
458
524
99
920
813
494
350
10
224
902
50
927
445
907
887
895
325
635
374
989
147
23
451
846
829
680
239
374
255
145
775
175
39
637
399
680
336
640
901
567
249
111
916
350
503
577
989
422
606
443
201
10
350
201
194
635
989
249
674
376
1
702
990
696
990
838
248
989
841
155
8...

result:

ok 

Test #94:

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

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
206 719 1
188
160 875 1
159
734 163 2
666
720
600 73 1
597
209 475 1
208
538 58 1
545
127 612 1
126
964 75 3
965
967
977
215 936 2
216
270
685 549 1
647
651 583 2
648
650
70 33 10
33
55
56
57
58
59
60
61
63
69
688 322 2
689
690
364 531 3
73
346
362
857 159 1
875
983 201 1
999
583 721 1
999
3...

output:

188
159
666
597
208
545
126
977
270
647
648
33
690
73
875
999
999
327
531
856
72
827
943
640
602
20
415
144
980
776
910
24
794
282
449
637
999
307
570
25
574
95
621
147
876
752
929
18
669
895
957
363
559
105
945
422
735
154
18
257
742
301
826
955
74
18
987
701
588
313
90
763
661
290
428
943
719
735
...

result:

ok 

Test #95:

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

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
210 200 1
730
250 341 1
730
269 537 1
730
258 602 1
730
48 608 1
730
558 235 1
730
672 603 1
730
247 9 1
730
578 615 1
730
297 687 1
730
576 654 1
730
94 405 1
730
576 379 1
730
621 429 1
730
326 534 1
730
93 273 1
730
527 449 1
730
726 691 1
730
483 172 1
730
495 444 1
730
102 602 1
730
509 ...

output:

730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
65
730
730
730
730
730
730
730
730
730
730
730
718
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
730
7...

result:

ok 

Test #96:

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

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
699 389 1
999
0 277 1
999
716 178 1
999
719 135 1
999
124 242 1
999
633 120 1
999
640 258 1
999
591 343 1
999
645 291 1
999
759 824 1
999
565 29 1
999
424 253 1
999
734 77 1
999
925 318 1
999
956 663 1
999
270 781 1
999
895 332 1
999
137 99 1
999
661 88 1
999
465 489 1
999
124 511 1
999
97 7...

output:

999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
563
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
...

result:

ok 

Test #97:

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

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
194 680 10
195
196
197
198
199
200
201
202
203
214
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
678 461 2
...

output:

6
493
1
214
4
93
670
70
196
322
469
816
89
726
560
52
765
45
783
46
669
198
549
669
382
361
2
322
425
669
886
551
781
553
781
305
617
369
1
412
511
361
2
553
376
196
457
326
426
840
269
69
837
166
57
6
457
578
186
382
296
64
155
765
269
69
726
886
645
487
493
548
369
771
728
462
297
669
156
702
237
...

result:

ok 

Test #98:

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

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
364 816 9
365
366
367
368
369
370
371
372
382
221 797 8
222
223
224
225
226
227
228
245
874 118 8
882
890
898
906
914
922
930
988
354 287 9
427
500
573
622
695
768
841
914
988
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
189 192 9
135
181
...

output:

382
245
988
988
531
427
735
135
17
307
884
149
460
610
498
573
505
119
9
172
892
820
360
62
17
986
188
617
312
178
484
714
908
802
245
702
500
24
412
676
103
668
236
997
103
347
454
536
622
113
455
464
701
826
506
109
9
810
565
170
565
236
529
297
578
146
988
748
48
682
817
369
171
500
267
671
781
7...

result:

ok 

Test #99:

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

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
164
182
290
205
307
109
0
665
79
503
53
498
50
344
709
655
432
427
632
55
510
172
615
12
117
215
477
356
154
631
337
233
13
693
199
20
553
170
388
695
286
134
316
604
613
336
186
625
476
320
536
300
42
398
607
10
706
253
689
611
531
365
277
416
244
433
14
291
251
549
386
650
123
319
422
323
497
...

input:

1
33400
536 419 3
168
169
170
482 315 3
483
681
682
45 212 3
329
330
331
109 355 3
33
34
35
581 545 3
78
80
580
453 311 3
265
266
452
39 30 3
391
392
394
3 685 3
443
444
446
339 182 3
505
506
508
411 413 3
261
262
263
440 666 3
417
419
420
527 366 3
438
440
526
508 451 3
238
239
507
61 475 3
179
180...

output:

170
682
329
33
80
266
394
446
508
261
417
438
239
181
293
434
148
381
296
492
465
592
68
703
72
462
502
441
319
659
652
537
213
463
310
533
44
533
344
300
313
540
245
342
489
175
181
511
220
635
263
99
177
259
119
259
706
508
233
676
366
142
42
443
431
334
470
543
122
355
247
256
365
338
4
40
394
94...

result:

ok 

Test #100:

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

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
263 252 3
264
772
773
590 910 3
321
323
324
788 297 3
243
245
787
16 83 3
264
265
267
705 794 3
427
428
429
845 298 3
259
260
261
897 546 3
451
452
896
324 799 3
806
807
808
950 415 3
71
73
74
464 692 3
582
583
584
878 82 3
50
51
52
808 673 3
462
463
464
452 220 3
484
4...

output:

832
773
321
245
264
427
261
452
806
74
584
52
464
486
289
756
141
361
222
937
241
210
894
567
130
212
296
620
141
491
387
583
299
714
703
823
886
486
235
153
675
831
763
578
806
76
887
18
817
537
707
6
814
697
801
914
212
506
987
116
342
644
962
853
791
438
144
332
388
777
100
463
97
49
295
76
752
5...

result:

ok 

Test #101:

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

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: 12ms
memory: 3828kb

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