QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#327106#1139. Stationshotboy2703100 ✓70ms8796kbC++201.7kb2024-02-14 19:02:372024-02-14 19:02:37

Judging History

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

  • [2024-02-14 19:02:37]
  • 评测
  • 测评结果:100
  • 用时:70ms
  • 内存:8796kb
  • [2024-02-14 19:02:37]
  • 提交

stations

#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
using ull = unsigned long long;
using ld = long double;
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1LL)
#define MASK(i) (1LL << (i))
#define MP make_pair
#define ms(a) memset(a,0,sizeof (a))
namespace {
    vector <ll> g[200100];
    ll sus[200100];
    ll depth[200100];
    ll timeDFS;
    void dfs(ll u,ll p){
        depth[u] = depth[p]+1;
        if (depth[u]&1)sus[u]=timeDFS++;
        for (auto v:g[u]){
            if (v!=p)dfs(v,u);
        }
        if ((depth[u]&1)==0)sus[u]=timeDFS++;
    }
}
std::vector<ll> label(ll n, ll k, std::vector<ll> u, std::vector<ll> v) {
	std::vector<ll> labels(n);
	for (ll i = 0;i < n;i ++)g[i].clear();
	timeDFS = 0;
	for (ll i = 0;i <= n - 2;i ++){
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
	}
	dfs(0,0);
	for (ll i = 0;i < n;i ++){
        labels[i] = sus[i];
	}
	return labels;
}

ll find_next_station(ll s, ll t, std::vector<ll> c) {
    if (s>c[0]){
        ll p = *c.begin();
        c.erase(c.begin());
        c.push_back(s+1);
        for (ll i = 0;i + 1 < sz(c);i ++){
            ll l=c[i],r=c[i+1]-1;
            if (l <= t && t <= r){
                return l;
            }
        }
        return p;
    }
    else{
        ll p = c.back();
        if (s>0)c.pop_back();
        c.insert(c.begin(),s-1);
        for (ll i = 0;i + 1 < sz(c);i ++){
            ll l=c[i]+1,r=c[i+1];
            if (l <= t && t <= r){
                return c[i+1];
            }
        }
        return p;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

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

input:

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

output:

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

input:

1
59784
0 1 1
1
574 618 2
842
843
0 1 1
1
848 310 2
151
152
1 2 1
2
1 0 1
0
0 1 1
1
742 153 2
674
675
2 3 2
0
1
3 0 1
0
474 416 2
525
526
9 2 2
0
2
223 888 2
195
196
934 400 2
65
66
112 795 2
731
732
285 437 2
714
715
0 1 1
1
76 93 2
68
69
0 1 2
1
2
0 1 1
1
647 63 2
568
569
1 0 1
0
570 744 2
36
37
0...

output:

1
842
1
152
2
0
1
674
0
0
526
2
195
66
732
714
1
68
1
1
568
0
36
1
0
300
2
0
2
348
22
861
2
9
52
0
405
19
8
0
9
676
28
608
28
767
711
369
527
65
0
564
150
2
0
0
2
614
0
2
2
0
118
650
467
40
242
3
0
351
157
234
713
0
628
335
0
2
849
1
2
137
0
520
0
35
81
570
9
9
9
0
45
2
2
437
627
134
0
224
394
312
0...

result:

ok 

Test #2:

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

input:

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

output:

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

input:

1
50048
628 989 2
301
302
473 189 2
349
350
148 818 2
390
391
415 596 2
514
515
595 172 2
944
945
595 69 2
760
761
709 38 2
646
647
149 591 2
389
390
601 389 2
404
405
773 291 2
582
583
198 365 2
77
78
243 226 2
295
296
121 22 2
884
885
636 859 2
186
187
790 836 2
32
33
885 747 2
927
928
887 947 2
4...

output:

301
349
391
515
945
761
646
390
404
582
77
296
885
186
32
928
42
448
168
236
587
358
338
653
645
490
939
44
666
497
906
709
740
911
195
731
870
380
138
581
334
292
477
430
317
622
213
119
682
416
345
146
83
544
380
333
404
443
220
69
228
821
967
753
625
809
498
133
845
835
64
469
405
648
757
2
992
4...

result:

ok 

Test #3:

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

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

input:

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

result:

ok 

Test #6:

score: 5
Accepted
time: 30ms
memory: 8536kb

input:

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

output:

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

input:

1
50055
420 589 2
295
296
585 531 2
528
529
565 254 2
287
288
383 148 2
341
342
738 173 2
376
377
429 618 2
984
985
400 365 2
273
274
740 121 2
770
771
753 911 2
757
758
313 102 2
360
361
226 654 2
626
627
865 958 2
645
646
256 277 2
417
418
725 668 2
90
91
69 722 2
655
656
506 514 2
5
6
689 180 2
1...

output:

295
529
287
341
376
984
274
771
758
361
627
645
417
91
656
5
127
423
635
942
185
367
459
606
333
706
319
172
568
516
671
158
514
581
119
958
353
255
326
984
364
325
363
602
230
283
676
546
890
231
289
738
112
861
846
453
871
408
390
122
809
390
528
657
459
328
517
460
384
784
764
886
247
600
856
575...

result:

ok 

Test #7:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #8:

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

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

input:

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

output:

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

result:

ok 

Test #10:

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

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

input:

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

output:

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

result:

ok 

Subtask #2:

score: 8
Accepted

Test #11:

score: 8
Accepted
time: 30ms
memory: 8484kb

input:

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

output:

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

input:

1
50252
728 374 1
729
852 130 1
851
986 522 1
984
408 399 1
410
857 222 1
855
420 923 1
422
707 713 1
705
433 777 1
434
714 752 3
711
712
713
870 463 3
863
864
867
992 14 1
990
596 143 3
597
598
599
781 515 1
782
402 924 1
403
291 0 1
290
70 146 1
72
864 931 3
865
866
870
288 309 3
303
318
319
360 6...

output:

729
851
984
410
855
422
705
434
711
863
990
599
782
403
290
72
870
318
362
960
937
866
712
129
375
917
211
760
683
926
957
878
773
362
303
507
609
783
302
461
854
410
981
896
407
48
168
687
840
137
161
368
924
53
839
958
332
940
630
224
686
900
189
442
866
651
447
103
268
214
751
687
600
95
996
767
...

result:

ok 

Test #12:

score: 8
Accepted
time: 42ms
memory: 8484kb

input:

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

output:

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

input:

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

output:

8
438
33
350
87
1
25
304
232
0
215
3
391
3
1
95
20
114
184
160
0
8
645
315
40
79
25
1
101
17
1
125
0
0
0
2
350
7
52
482
1
2
623
791
0
0
219
222
1
0
768
1
180
2
0
4
0
15
1
223
2
2
483
81
3
363
356
1
72
66
0
1
15
258
1
0
103
434
149
508
3
31
847
950
2
20
495
0
10
321
12
2
73
22
8
0
960
31
84
80
274
9
...

result:

ok 

Test #13:

score: 8
Accepted
time: 70ms
memory: 8484kb

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

input:

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

output:

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

result:

ok 

Test #14:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #15:

score: 8
Accepted
time: 46ms
memory: 8484kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #16:

score: 8
Accepted
time: 30ms
memory: 8524kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Subtask #3:

score: 16
Accepted

Test #17:

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

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
996
125
213
574
35
713
262
145
673
845
329
806
874
548
621
635
899
871
22
954
80
242
772
218
777
916
528
469
553
199
982
852
37
693
302
187
665
750
822
510
906
78
561
117
69
569
403
384
252
785
727
807
714
498
712
496
904
464
304
357
570
579
557
431
6
963
175
936
463
317
862
577
842
432
85...

input:

1
59859
5 3 2
0
1
1 0 1
0
1 0 1
0
15 42 2
983
984
194 245 2
899
900
867 568 2
134
135
0 1 1
1
6 0 2
8
9
938 835 2
60
61
0 1 1
1
0 1 1
1
1 0 1
0
0 1 2
1
2
979 776 2
879
880
185 106 2
813
814
255 251 2
743
744
4 9 2
1
2
1 0 1
0
146 251 2
716
717
23 98 2
91
92
722 709 2
279
280
854 429 2
239
240
940 95...

output:

1
0
0
983
899
135
1
9
61
1
1
0
1
879
814
744
1
0
716
92
280
240
918
939
1
530
263
348
0
2
321
0
729
0
0
2
316
836
604
1
676
350
938
678
2
0
587
227
558
1
161
0
276
384
67
70
1
24
2
0
0
5
5
37
746
584
27
0
839
6
865
614
41
0
217
2
614
622
1
73
0
534
259
1
1
784
1
859
1
346
77
6
0
0
181
4
0
1
849
1
54...

result:

ok 

Test #18:

score: 16
Accepted
time: 30ms
memory: 8464kb

input:

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

output:

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

input:

1
50048
856 650 2
74
75
572 243 2
170
171
777 799 2
960
961
636 846 2
294
295
238 934 2
562
563
138 509 2
662
663
972 839 2
948
949
498 603 2
432
433
468 881 2
274
275
4 215 2
957
958
265 708 2
535
536
222 72 2
992
993
793 28 2
802
803
537 730 2
424
425
250 264 2
492
493
349 838 2
254
255
506 745 2
...

output:

75
171
960
294
563
662
948
432
274
957
536
993
803
424
492
254
236
375
628
892
308
863
346
266
980
177
625
545
670
49
404
146
156
471
854
756
909
427
649
137
79
979
402
893
170
689
79
872
590
248
360
66
498
809
595
717
200
135
980
37
567
833
796
579
463
561
987
717
918
12
915
671
254
192
718
189
973...

result:

ok 

Test #19:

score: 16
Accepted
time: 56ms
memory: 8512kb

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

input:

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

output:

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

result:

ok 

Test #20:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #21:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #22:

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

input:

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

output:

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

input:

1
50050
255 156 2
38
39
285 284 2
53
54
773 507 2
949
950
563 905 2
472
473
662 308 2
659
660
939 333 2
301
302
943 210 2
779
780
958 91 2
270
271
429 889 2
811
812
494 859 2
229
230
720 377 2
413
414
643 844 2
492
493
488 976 2
752
753
583 638 2
754
755
868 793 2
469
470
397 883 2
940
941
730 1 2
4...

output:

39
54
950
472
659
302
779
270
812
229
413
492
753
754
470
940
403
861
991
88
790
917
723
754
350
658
60
243
412
735
207
605
165
637
53
173
500
265
92
732
939
496
594
30
859
373
286
756
417
83
186
629
866
899
835
222
737
776
440
591
296
235
715
184
239
220
118
247
30
734
670
918
61
339
208
282
533
16...

result:

ok 

Test #23:

score: 16
Accepted
time: 30ms
memory: 8744kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #24:

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

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

input:

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

output:

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

result:

ok 

Test #25:

score: 16
Accepted
time: 6ms
memory: 8700kb

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

input:

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

output:

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

result:

ok 

Test #26:

score: 16
Accepted
time: 6ms
memory: 8468kb

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

input:

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

output:

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

result:

ok 

Test #27:

score: 16
Accepted
time: 44ms
memory: 8744kb

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

input:

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

output:

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

result:

ok 

Test #28:

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

input:

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

output:

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

input:

1
51340
149 771 2
603
604
877 984 2
142
143
131 254 2
514
515
278 923 2
312
313
561 761 2
458
459
532 231 2
551
552
636 10 2
653
654
124 900 2
131
132
585 694 1
586
700 682 1
1
70 112 2
682
683
369 155 2
383
384
679 85 2
665
666
676 913 1
42
958 897 2
963
964
654 579 2
650
651
327 659 2
262
263
598 ...

output:

604
142
514
313
458
552
654
132
586
1
682
384
665
42
964
650
262
42
1
781
734
815
369
293
751
42
959
287
682
746
862
889
157
229
540
852
570
152
556
760
947
801
24
1
280
22
419
1
927
155
1
12
262
495
186
42
937
399
416
235
928
0
917
191
42
33
618
653
289
151
399
722
367
940
445
33
763
239
107
546
21...

result:

ok 

Test #29:

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

input:

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

output:

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

input:

1
51513
478 629 2
710
711
318 31 2
357
358
415 617 1
0
485 744 1
0
726 509 2
720
721
481 150 2
484
485
5 767 2
305
306
305 677 2
224
225
605 77 2
586
587
490 386 1
0
13 596 2
888
889
895 316 2
899
900
584 662 2
5
569
575 910 2
562
563
567 424 2
831
832
9 176 2
841
842
45 175 1
997
723 957 2
444
445
...

output:

710
358
0
0
720
485
306
224
586
0
888
900
5
562
832
841
997
444
272
249
172
375
5
863
815
318
0
935
46
106
992
781
665
507
777
84
899
32
797
0
282
910
23
595
347
0
38
0
515
111
0
0
664
884
0
406
0
588
144
807
881
118
456
276
768
787
375
803
910
324
424
102
284
51
433
663
443
954
379
371
168
813
411
...

result:

ok 

Test #30:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #31:

score: 16
Accepted
time: 16ms
memory: 8472kb

input:

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

output:

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

input:

1
4026
66 94 1
0
16 77 1
0
34 84 1
0
50 44 1
0
69 76 1
95
95 16 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
...

output:

0
0
0
0
95
16
95
0
95
0
0
95
95
0
24
95
95
0
81
95
0
95
95
95
66
95
0
61
0
0
95
0
27
0
0
95
95
95
0
95
0
0
0
95
26
95
0
0
0
95
75
46
19
0
20
0
0
0
0
0
95
95
0
0
95
10
0
0
45
95
7
0
95
95
95
95
0
55
95
0
95
0
0
0
0
93
0
0
0
0
0
0
25
84
0
8
52
39
93
0
95
0
0
0
95
95
18
95
0
0
84
0
0
0
0
76
95
95
61
87...

result:

ok 

Test #32:

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

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
234 167 1
540
200 375 1
540
191 467 1
0
206 58 1
0
0 402 540
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
8...

output:

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

result:

ok 

Test #33:

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

input:

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

output:

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

input:

1
10180
71 387 1
0
46 334 1
0
56 339 1
999
122 914 1
0
196 718 1
0
970 767 1
0
737 590 1
0
402 607 1
0
613 255 1
999
105 319 1
0
274 804 1
999
774 189 1
0
28 667 1
0
238 327 1
0
106 171 1
999
75 237 1
999
281 564 1
999
182 711 1
0
191 982 1
999
392 830 1
0
513 606 1
999
119 109 1
0
74 128 1
0
77 102...

output:

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

result:

ok 

Subtask #4:

score: 10
Accepted

Test #34:

score: 10
Accepted
time: 56ms
memory: 8376kb

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

input:

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

output:

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

result:

ok 

Test #35:

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

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

input:

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

output:

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

result:

ok 

Test #36:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #37:

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

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

input:

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

output:

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

result:

ok 

Test #38:

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

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

input:

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

output:

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

result:

ok 

Test #39:

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

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

input:

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

output:

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

result:

ok 

Test #40:

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

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

input:

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

output:

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

result:

ok 

Test #41:

score: 10
Accepted
time: 56ms
memory: 8504kb

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

input:

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

output:

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

result:

ok 

Test #42:

score: 10
Accepted
time: 46ms
memory: 8760kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #43:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #44:

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

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

input:

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

output:

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

result:

ok 

Test #45:

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

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

input:

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

output:

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

result:

ok 

Test #46:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #47:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #48:

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

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

input:

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

result:

ok 

Test #49:

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

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

input:

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

output:

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

result:

ok 

Test #51:

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

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

result:

ok 

Subtask #5:

score: 61
Accepted

Test #54:

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

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
997
931
259
458
561
133
416
632
209
835
112
756
219
741
783
541
116
139
638
177
906
44
475
381
388
172
92
575
283
418
230
574
411
509
830
970
879
739
499
242
197
849
618
531
372
821
629
707
971
45
960
165
885
176
995
951
712
368
24
4
289
771
872
752
924
166
414
694
819
506
195
13
579
543...

input:

1
59797
2 1 2
0
1
493 446 2
265
266
0 1 1
1
64 32 2
48
49
380 703 2
106
107
0 3 2
2
3
0 1 2
2
3
938 790 2
261
262
715 514 2
769
770
782 707 2
360
361
1 0 1
0
251 255 2
507
508
198 562 2
560
561
226 323 2
973
974
2 0 2
0
1
905 604 2
237
238
742 541 2
257
258
19 26 2
93
94
5 6 2
6
7
912 677 2
87
88
47...

output:

1
266
1
48
106
3
2
262
770
361
0
507
561
973
0
238
258
93
6
88
529
1
0
961
94
547
659
853
427
0
0
107
188
2
8
22
156
885
72
1
2
0
871
932
1
323
652
446
970
5
0
53
269
0
8
622
222
0
869
0
1
862
3
9
300
433
0
625
371
2
5
909
99
66
912
525
1
461
609
75
2
137
2
0
7
66
152
895
0
0
44
2
5
280
1
0
492
114
...

result:

ok 

Test #55:

score: 61
Accepted
time: 30ms
memory: 8484kb

input:

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

output:

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

input:

1
50045
217 982 2
559
560
317 335 2
437
438
772 522 2
342
343
383 245 2
839
840
741 955 2
520
521
565 298 2
189
190
517 341 2
237
238
382 340 2
805
806
172 661 2
418
419
473 735 2
129
130
706 666 2
408
409
172 175 2
582
583
533 264 2
689
690
727 544 2
460
461
494 684 2
728
729
905 314 2
683
684
856 ...

output:

560
437
343
840
520
190
238
806
419
129
409
582
690
461
728
683
732
369
318
401
654
918
687
802
556
135
276
150
143
801
257
233
126
319
33
60
42
551
242
185
542
0
915
182
205
968
373
725
593
681
892
61
445
349
699
429
917
490
443
453
910
186
668
890
140
834
204
893
645
642
285
816
91
143
566
832
908...

result:

ok 

Test #56:

score: 61
Accepted
time: 56ms
memory: 8460kb

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

input:

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

output:

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

result:

ok 

Test #57:

score: 61
Accepted
time: 52ms
memory: 8472kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #58:

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

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

input:

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

output:

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

result:

ok 

Test #59:

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

input:

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

output:

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

input:

1
50038
782 407 2
400
401
465 771 2
786
787
41 695 2
911
912
540 399 2
458
459
786 987 2
166
167
359 560 2
593
594
676 545 2
723
724
311 925 2
781
782
242 219 2
850
851
946 30 2
556
557
521 206 2
981
982
397 201 2
785
786
673 837 2
705
706
156 449 2
842
843
14 525 2
238
239
359 219 2
11
12
135 118 2...

output:

401
786
911
458
166
593
724
782
851
556
982
786
706
842
239
12
818
510
614
434
855
258
178
152
305
261
919
996
976
666
116
609
251
156
671
204
590
780
188
796
409
226
670
532
231
302
893
804
121
995
353
580
833
134
94
16
513
806
616
449
157
185
751
851
189
42
307
611
646
757
424
913
210
984
749
540
...

result:

ok 

Test #60:

score: 61
Accepted
time: 30ms
memory: 8416kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #61:

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

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

input:

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

output:

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

result:

ok 

Test #62:

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

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

input:

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

output:

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

result:

ok 

Test #63:

score: 61
Accepted
time: 4ms
memory: 8500kb

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

input:

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

output:

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

result:

ok 

Test #64:

score: 61
Accepted
time: 30ms
memory: 8736kb

input:

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

output:

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

input:

1
49888
704 390 3
711
718
734
178 373 1
179
771 203 1
770
747 399 1
746
471 689 3
472
473
477
478 796 3
447
448
463
219 816 1
221
959 567 3
966
971
979
944 281 1
945
542 933 3
536
540
541
490 142 3
491
492
493
581 84 3
582
583
584
889 393 1
891
893 334 3
767
831
862
643 236 1
644
860 24 1
858
482 54...

output:

734
179
770
746
477
447
221
979
945
536
493
584
891
767
644
858
480
33
448
19
504
415
977
940
304
748
765
925
570
895
161
978
272
33
955
231
449
885
766
238
461
784
183
682
183
575
783
69
160
171
667
580
245
874
374
296
430
560
679
592
573
175
415
959
363
647
847
343
776
811
33
765
414
581
795
211
1...

result:

ok 

Test #65:

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

input:

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

output:

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

input:

1
59652
7 20 1
5
244 408 1
246
1 3 1
2
1 0 1
0
90 24 1
88
2 1 2
0
1
1 0 1
0
0 1 1
1
1 0 1
0
478 230 3
485
492
508
300 469 3
297
298
299
32 77 3
0
1
17
2 0 1
0
638 498 3
576
608
623
90 88 1
92
5 25 1
7
1 0 1
0
34 110 1
33
126 94 3
64
96
111
124 477 1
123
98 50 1
97
0 2 2
2
3
2 0 1
0
389 503 3
386
387...

output:

5
246
2
0
88
1
0
1
0
508
297
0
0
576
92
7
0
33
64
123
97
2
0
386
1
129
23
29
12
0
295
0
0
1
238
0
0
15
144
0
122
59
17
663
403
2
0
57
1
2
2
68
11
0
25
1
0
15
1
0
232
0
0
0
1
0
23
11
21
24
441
0
97
118
160
20
0
114
0
66
2
2
2
9
56
8
0
8
482
152
5
24
1
95
1
0
494
9
0
0
0
95
87
0
0
1
552
0
334
1
253
0
...

result:

ok 

Test #66:

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

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

input:

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

output:

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

result:

ok 

Test #67:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #68:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #69:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #70:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #71:

score: 61
Accepted
time: 30ms
memory: 8744kb

input:

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

output:

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

input:

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

output:

749
334
21
64
937
655
806
426
600
936
382
720
570
911
937
937
582
694
783
181
181
937
272
937
755
350
287
644
353
597
841
924
400
614
697
924
0
383
957
875
634
600
32
338
642
55
689
469
212
52
945
448
696
636
163
892
127
115
830
549
0
226
21
462
821
819
326
881
409
811
426
21
888
750
241
311
939
525...

result:

ok 

Test #72:

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

input:

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

output:

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

input:

1
51725
885 262 2
816
817
834 61 2
237
238
386 362 2
375
376
811 403 1
810
14 295 1
999
506 640 2
196
197
300 876 2
297
298
357 366 2
484
485
578 270 2
594
595
768 22 2
747
748
11 791 1
999
482 694 2
589
590
410 89 2
292
293
980 488 1
999
408 563 2
663
664
746 955 2
794
795
507 323 2
195
196
993 553...

output:

816
237
375
810
999
196
297
484
595
747
999
590
292
999
663
795
196
992
195
680
556
973
624
999
999
715
282
740
999
150
40
561
752
861
353
495
634
290
573
814
747
283
809
966
953
999
416
852
819
999
20
853
759
275
542
281
2
471
948
209
135
114
505
273
903
110
43
341
927
62
2
2
190
999
308
864
62
589...

result:

ok 

Test #73:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #74:

score: 61
Accepted
time: 8ms
memory: 8740kb

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
95
64
46
14
9
12...

input:

1
4308
3 53 1
95
47 89 1
0
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
9...

output:

95
0
48
0
0
37
0
95
95
0
95
0
95
0
95
28
95
95
95
0
95
95
0
0
0
0
95
0
0
95
95
0
0
0
95
95
0
0
95
0
89
95
0
95
50
0
0
95
95
95
82
0
38
82
52
95
69
50
0
0
95
95
95
0
95
95
95
95
0
95
0
42
50
17
60
95
95
0
56
95
95
95
0
95
0
95
0
0
95
95
95
0
64
87
0
0
95
0
0
74
95
95
26
81
3
19
0
0
6
0
7
95
0
95
41
0...

result:

ok 

Test #75:

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

input:

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

output:

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

input:

1
6214
484 470 1
540
434 217 1
0
58 503 1
540
308 332 1
0
485 301 1
540
311 483 1
0
44 64 1
540
353 92 1
540
159 29 1
540
420 139 1
540
112 212 1
0
172 400 1
0
383 352 1
540
359 253 1
540
402 238 1
0
438 298 1
540
162 426 1
0
265 313 1
540
237 131 1
0
366 221 1
0
499 540 1
540
435 34 1
0
264 100 1
0...

output:

540
0
540
0
540
0
540
540
540
540
0
0
540
540
0
540
0
540
0
0
540
0
0
0
540
0
0
353
540
540
0
540
540
0
540
0
0
0
540
540
0
0
0
0
0
0
0
540
540
0
0
0
0
0
0
540
0
0
540
0
0
540
540
0
0
0
153
0
0
0
540
0
0
540
0
0
0
540
0
0
0
540
540
0
0
0
0
540
540
540
0
0
540
0
540
0
540
540
0
0
0
540
540
0
540
540
...

result:

ok 

Test #76:

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

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
17 800 1
999
3 424 1
999
618 21 1
0
203 286 1
0
471 862 1
0
531 782 1
999
133 908 1
999
212 608 1
999
968 871 1
0
552 573 1
0
978 747 1
0
859 355 1
0
668 689 1
999
783 397 1
0
150 322 1
0
678 513 1
0
288 914 1
0
287 790 1
999
50 101 1
0
396 25 1
999
290 876 1
0
762 395 1
999
170 767 1
999
22...

output:

999
999
0
0
0
999
999
999
0
0
0
0
999
0
0
0
0
999
0
999
0
999
999
999
0
999
0
999
999
0
999
0
0
999
999
0
999
0
999
0
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
0
999
999
0
0
999
999
999
999
999
0
999
999
0
999
999
999
0
999
999
0
999
0
999
999
0
0
999
999
0
999
999
0
999
0
999
...

result:

ok 

Test #77:

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

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

result:

ok 

Test #78:

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

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

input:

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

output:

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

result:

ok 

Test #79:

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

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

input:

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

output:

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

result:

ok 

Test #80:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #81:

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

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

input:

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

output:

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

result:

ok 

Test #82:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #85:

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

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

input:

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

output:

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

input:

1
35090
368 419 2
151
152
710 313 2
885
886
765 897 2
761
762
202 144 2
923
924
30 444 2
151
152
472 442 2
675
676
136 567 2
20
21
416 837 2
386
387
424 194 2
319
320
702 839 2
445
446
781 713 2
826
827
267 4 2
469
470
381 646 2
883
884
179 570 2
934
935
171 645 2
348
349
0 678 2
678
951
532 560 2
4...

output:

151
886
761
924
152
676
20
386
319
445
827
470
883
934
349
678
457
175
932
69
778
12
887
743
906
800
231
297
857
561
428
220
286
828
684
306
319
600
36
511
453
15
244
247
416
676
381
907
481
820
675
610
444
807
529
275
829
861
946
718
539
321
960
844
248
78
600
296
300
715
128
978
683
966
928
969
74...

result:

ok 

Test #88:

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

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
771 668 2
769
770
822 264 3
815
816
819
697 921 1
694
42 258 3
43
44
48
8 874 1
7
397 408 1
398
977 424 2
587
588
526 339 2
527
528
47 851 2
209
210
605 775 6
606
607
609
614
615
621
508 491 1
498
63 785 2
502
503
357 374 1
0
629 969 2
631
635
67 805 3
68
69
73
0 272 1
999
252 803 2
4
5
178 ...

output:

769
815
694
48
7
398
587
528
210
621
498
503
0
635
73
999
4
179
0
790
702
353
0
3
843
952
806
184
254
677
218
446
647
791
818
986
318
938
386
131
990
130
999
64
632
921
714
404
793
151
3
920
211
0
913
502
349
511
723
683
4
0
0
700
470
17
375
411
480
490
409
167
276
274
47
396
543
842
720
80
418
535
...

result:

ok 

Test #89:

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

input:

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

output:

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

input:

1
49922
712 158 2
710
711
702 63 1
710
489 27 2
479
480
696 479 2
952
953
579 787 2
389
390
632 711 2
596
597
936 258 2
235
236
357 921 3
358
360
361
288 755 2
371
372
736 133 2
748
749
689 467 2
696
697
110 534 2
85
86
209 769 2
962
963
659 901 1
658
54 515 1
63
210 230 2
620
621
405 506 2
254
255
...

output:

710
710
479
953
389
596
236
361
372
749
697
85
962
658
63
620
254
836
435
199
948
522
368
641
710
123
342
177
815
335
485
146
925
228
96
940
913
495
930
532
228
367
638
322
447
446
940
843
874
677
613
57
845
580
201
543
325
630
244
567
668
460
199
523
129
300
626
604
494
542
273
201
982
629
593
419
...

result:

ok 

Test #90:

score: 61
Accepted
time: 30ms
memory: 8436kb

input:

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

output:

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

input:

1
50698
398 409 3
399
401
402
24 787 1
19
958 65 1
999
636 67 3
643
891
892
207 54 2
209
210
763 130 1
762
614 607 1
615
561 357 1
945
214 432 3
240
241
246
353 469 2
26
28
917 717 1
999
701 106 2
702
707
614 449 1
615
160 551 2
141
158
991 878 2
3
990
754 600 1
747
686 846 1
688
704 974 2
702
703
7...

output:

402
19
999
892
210
762
615
945
246
26
999
707
615
141
3
747
688
702
762
21
96
47
968
973
209
888
759
433
165
211
77
420
265
476
486
787
47
821
598
236
54
902
611
47
961
211
477
47
608
354
143
442
779
291
47
912
292
895
673
611
10
497
703
253
215
754
554
325
961
572
274
448
436
774
821
811
853
297
43...

result:

ok 

Test #91:

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

input:

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

output:

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

input:

1
50698
398 409 3
399
401
402
24 787 1
19
958 65 1
999
636 67 3
643
891
892
207 54 2
209
210
763 130 1
762
614 607 1
615
561 357 1
945
214 432 3
240
241
246
353 469 2
26
28
917 717 1
999
701 106 2
702
707
614 449 1
615
160 551 2
141
158
991 878 2
3
990
754 600 1
747
686 846 1
688
704 974 2
702
703
7...

output:

402
19
999
892
210
762
615
945
246
26
999
707
615
141
3
747
688
702
762
21
96
47
968
973
209
888
759
433
165
211
77
420
265
476
486
787
47
821
598
236
54
902
611
47
961
211
477
47
608
354
143
442
779
291
47
912
292
895
673
611
10
497
703
253
215
754
554
325
961
572
274
448
436
774
821
811
853
297
43...

result:

ok 

Test #92:

score: 61
Accepted
time: 30ms
memory: 8476kb

input:

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

output:

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

input:

1
49569
775 641 1
776
537 545 2
538
540
141 305 1
142
48 992 2
49
50
582 196 3
225
226
581
970 352 1
984
903 266 4
904
905
906
907
857 284 1
858
585 20 3
524
525
584
98 24 1
99
925 488 1
920
302 116 1
301
495 976 1
494
434 714 1
446
30 132 1
140
209 933 2
210
224
899 996 4
885
886
887
896
453 635 1
...

output:

776
540
142
50
225
984
907
858
524
99
920
301
494
446
140
224
885
950
928
449
696
881
895
330
635
350
0
659
23
451
867
459
645
239
355
255
200
38
173
39
124
402
695
337
625
901
741
249
111
916
446
519
577
0
422
714
394
164
140
446
164
127
635
0
876
674
383
15
717
0
602
0
838
251
0
841
158
842
973
72...

result:

ok 

Test #93:

score: 61
Accepted
time: 30ms
memory: 8556kb

input:

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

output:

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

input:

1
49569
775 641 1
776
537 545 2
538
540
141 305 1
142
48 992 2
49
50
582 196 3
225
226
581
970 352 1
984
903 266 4
904
905
906
907
857 284 1
858
585 20 3
524
525
584
98 24 1
99
925 488 1
920
302 116 1
301
495 976 1
494
434 714 1
446
30 132 1
140
209 933 2
210
224
899 996 4
885
886
887
896
453 635 1
...

output:

776
540
142
50
225
984
907
858
524
99
920
301
494
446
140
224
885
950
928
449
696
881
895
330
635
350
0
659
23
451
867
459
645
239
355
255
200
38
173
39
124
402
695
337
625
901
741
249
111
916
446
519
577
0
422
714
394
164
140
446
164
127
635
0
876
674
383
15
717
0
602
0
838
251
0
841
158
842
973
72...

result:

ok 

Test #94:

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

input:

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

output:

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

input:

1
50684
407 965 1
389
159 875 1
160
16 774 2
1
2
600 74 1
603
683 276 1
966
538 58 1
537
754 151 1
758
909 867 3
905
906
907
215 936 2
216
270
685 549 1
705
395 338 2
396
418
69 32 10
32
54
55
56
57
58
59
60
62
68
435 508 2
108
434
873 306 3
889
891
892
857 159 1
875
982 201 1
1
584 721 1
1
120 979 ...

output:

389
160
1
603
966
537
758
905
270
705
418
32
108
892
875
1
1
64
268
485
871
456
935
638
607
671
415
144
878
776
650
24
561
468
306
634
1
283
348
366
120
95
914
26
689
817
929
18
83
524
957
424
566
306
971
670
737
765
18
318
762
304
826
743
74
18
980
115
324
985
795
943
659
290
997
734
491
737
83
884...

result:

ok 

Test #95:

score: 61
Accepted
time: 8ms
memory: 8768kb

input:

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

output:

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

input:

1
5230
211 201 1
0
250 341 1
0
269 537 1
0
258 602 1
730
48 608 1
0
559 235 1
0
672 603 1
0
247 9 1
0
579 616 1
0
297 687 1
730
576 654 1
0
95 406 1
0
576 379 1
730
621 429 1
730
326 534 1
0
94 274 1
0
527 449 1
0
727 692 1
0
483 172 1
730
495 444 1
0
102 602 1
730
509 360 1
0
225 599 1
0
532 678 1
...

output:

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

result:

ok 

Test #96:

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

input:

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

output:

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

input:

1
10180
700 389 1
0
999 277 1
0
717 178 1
0
719 135 1
999
124 242 1
0
632 119 1
999
640 258 1
0
590 342 1
999
644 290 1
999
759 824 1
999
565 29 1
999
423 252 1
999
734 76 1
999
926 318 1
0
956 663 1
999
269 781 1
999
895 332 1
0
137 99 1
999
661 88 1
999
466 490 1
0
123 510 1
999
97 756 1
0
607 841...

output:

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

result:

ok 

Test #97:

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

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
548 51 11
549
550
551
552
553
554
555
556
557
558
603
882 309 10
1
873
874
875
876
877
878
879
880
881
81 223 10
82
83
84
85
86
87
88
89
90
101
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
221 602 2
213
220
32...

output:

6
603
1
101
4
93
213
410
196
111
480
836
89
726
580
63
810
214
783
46
810
218
549
810
393
150
2
111
4
810
886
551
781
598
781
446
662
369
881
432
556
150
300
598
376
196
457
326
3
840
269
879
56
177
167
6
457
719
186
492
307
64
70
810
269
879
726
886
665
628
603
548
369
782
739
462
297
810
176
747
2...

result:

ok 

Test #98:

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

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

output:

356
245
988
835
531
483
735
470
17
542
940
149
460
610
540
274
505
354
9
407
892
298
360
397
17
986
188
852
312
178
540
748
908
802
245
702
201
853
454
676
103
668
210
893
103
582
454
771
323
56
497
464
670
795
506
139
9
810
565
113
565
236
721
297
578
381
835
940
48
682
817
411
201
201
267
713
259
...

result:

ok 

Test #99:

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

input:

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

output:

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

input:

1
33400
247 378 3
248
614
616
109 669 3
110
308
309
124 2 3
550
551
553
109 355 3
33
34
35
47 91 3
547
548
549
344 483 3
530
531
533
31 41 3
389
390
391
74 312 3
344
345
347
339 182 3
505
506
508
229 227 3
230
378
380
440 666 3
417
419
420
439 365 3
525
526
527
238 451 3
506
507
509
180 496 3
59
61
...

output:

614
309
553
33
547
530
389
344
508
380
417
527
506
59
647
361
595
271
500
150
28
150
675
560
71
255
295
303
232
571
652
537
602
347
664
160
473
211
63
447
225
540
570
304
52
69
564
423
132
628
535
146
657
490
693
259
499
460
408
588
366
142
42
236
357
688
470
455
513
267
601
610
418
542
37
470
394
3...

result:

ok 

Test #100:

score: 61
Accepted
time: 30ms
memory: 8752kb

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
830 140 3
506
507
829
216 205 3
217
725
726
590 910 3
321
323
324
741 250 3
196
198
740
49 872 3
50
800
802
414 503 3
136
137
138
259 297 3
260
844
846
451 781 3
895
896
898
33 508 3
515
516
517
548 207 3
670
671
672
159 270 3
38
40
158
878 82 3
50
51
52
593 458 3
247
248
249
485 733 3
450
4...

output:

506
726
321
198
802
136
844
895
515
672
38
52
249
450
553
541
94
70
731
407
864
210
952
352
973
165
81
6
964
614
340
536
84
240
412
776
839
195
99
106
289
616
472
363
515
857
959
18
817
322
405
949
140
253
151
184
853
506
252
119
921
429
747
99
576
438
963
285
719
365
820
506
817
769
666
875
705
77
...

result:

ok 

Test #101:

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

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
331 893 42
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
403
694 498 1
420
661 359 1
571
130 336 69
131
132
133
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695...

output:

403
420
571
680
475
158
103
412
91
111
904
773
123
637
365
420
904
672
904
201
52
120
130
309
830
852
103
680
904
530
700
123
283
531
904
629
412
882
103
108
692
420
904
547
547
670
571
547
370
728
17
904
796
680
130
904
27
245
871
130
663
120
427
0
803
91
410
760
904
530
91
365
904
680
284
111
0
85...

result:

ok 

Test #102:

score: 61
Accepted
time: 8ms
memory: 8796kb

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
544 424 1
955
776 793 1
965
358 2 1
390
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
772
169 245 1
348
846 273 1
810
351 386 1
...

output:

214
955
965
390
382
772
348
810
387
882
890
420
772
302
547
518
0
999
882
778
999
955
890
711
518
420
435
58
848
633
890
387
333
890
564
17
316
302
367
695
440
865
955
390
243
999
0
902
882
218
890
754
841
101
892
523
0
89
58
841
218
999
742
955
435
518
390
12
85
662
842
0
367
955
86
545
956
771
882...

result:

ok 

Extra Test:

score: 0
Extra Test Passed