QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#522939#1139. Stationsgreen_gold_dog#100 ✓50ms4128kbC++201.1kb2024-08-17 17:07:552024-08-17 17:07:55

Judging History

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

  • [2024-08-17 17:07:55]
  • 评测
  • 测评结果:100
  • 用时:50ms
  • 内存:4128kb
  • [2024-08-17 17:07:55]
  • 提交

stations

#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

typedef int ll;

vector<ll> dfs(ll v, ll p, vector<vector<ll>>& arr) {
	vector<ll> ans(1, v);
	for (auto i : arr[v]) {
		if (i != p) {
			vector<ll> now = dfs(i, v, arr);
			reverse(now.begin(), now.end());
			for (auto j : now) {
				ans.push_back(j);
			}
		}
	}
	return ans;
}

vector<ll> label(ll n, ll k, vector<ll> u, vector<ll> v) {
	vector<vector<ll>> arr(n);
	for (ll i = 0; i < n - 1; i++) {
		arr[u[i]].push_back(v[i]);
		arr[v[i]].push_back(u[i]);
	}
	vector<ll> per = dfs(0, 0, arr);
	vector<ll> num(n);
	for (ll i = 0; i < n; i++) {
		num[per[i]] = i;
	}
	return num;
}

ll find_next_station(ll s, ll t, vector<ll> c) {
	if (c[0] > s) {
		sort(c.begin(), c.end());
		if (t < s) {
			return c.back();
		}
		for (ll i = 0; i < c.size(); i++) {
			if (t <= c[i]) {
				return c[i];
			}
		}
		return c.back();
	} else {
		sort(c.rbegin(), c.rend());
		if (t > s) {
			return c.back();
		}
		for (ll i = 0; i < c.size(); i++) {
			if (t >= c[i]) {
				return c[i];
			}
		}
		return c.back();
	}
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #2:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #3:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #4:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #5:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #6:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #7:

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

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #9:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #10:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Subtask #2:

score: 8
Accepted

Test #11:

score: 8
Accepted
time: 26ms
memory: 4120kb

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
256
1
740
512
383
510
128
255
867
994
639
739
320
257
447
384
65
2
192
129
804
741
931
868
576
513
676
640
351
382
288
319
478
509
415
446
96
127
33
64
223
254
160
191
835
866
772
803
962
993
899
930
607
638
544
575
707
738
660
675
336
321
367
352
273
258
304
289
463
448
494
479
400
38...

input:

1
50252
885 48 1
883
516 463 1
515
660 830 1
662
205 208 1
204
527 399 1
525
241 691 1
240
889 895 1
887
230 604 1
228
891 902 3
892
893
894
567 130 3
560
561
564
666 345 1
668
745 473 3
746
747
751
602 828 1
600
199 689 1
197
117 0 1
116
275 453 1
274
564 723 3
565
566
567
127 100 3
65
97
112
61 95...

output:

883
515
662
204
525
240
887
228
894
560
668
751
600
197
116
274
567
97
60
652
732
564
897
478
45
682
389
915
983
709
672
552
593
60
112
169
791
592
120
153
521
204
656
700
207
381
501
963
540
470
501
38
688
353
536
658
26
729
777
438
987
688
487
232
564
961
129
305
92
386
903
965
748
272
741
639
619...

result:

ok 

Test #12:

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

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

input:

1
59568
4 16 3
1
2
3
225 71 3
226
227
231
177 509 3
180
183
191
501 293 3
504
507
508
122 108 3
119
120
121
0 2 2
1
2
51 37 1
52
410 257 3
407
408
409
72 493 3
66
70
71
0 2 2
2
3
118 426 3
112
116
117
3 2 1
0
300 477 1
302
3 1 1
0
1 0 1
0
72 24 3
75
78
79
59 27 1
61
92 33 1
93
491 908 1
490
56 49 3
...

output:

1
231
191
508
119
2
52
407
66
2
112
0
302
0
0
79
61
93
490
63
1
1
952
404
9
97
52
0
204
24
0
214
1
1
1
0
501
14
30
331
0
3
777
584
1
0
115
399
1
1
576
48
28
0
1
42
1
7
0
65
0
0
177
122
0
452
459
8
104
224
2
0
7
423
0
1
68
283
59
343
0
31
514
723
0
27
165
1
2
479
4
0
238
29
1
1
653
49
125
126
439
1
6...

result:

ok 

Test #13:

score: 8
Accepted
time: 50ms
memory: 3832kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #14:

score: 8
Accepted
time: 40ms
memory: 3828kb

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #15:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #16:

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

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
256
1
744
512
383
510
128
255
871
998
639
743
320
257
447
384
65
2
192
129
808
745
935
872
576
513
680
640
351
382
288
319
478
509
415
446
96
127
33
64
223
254
160
191
839
870
776
807
966
997
903
934
607
638
544
575
711
742
664
679
336
321
367
352
273
258
304
289
463
448
494
479
400
3...

input:

1
50108
127 266 3
65
97
112
383 588 3
256
257
320
3 412 3
10
17
33
392 418 3
385
386
389
875 173 1
874
76 994 1
74
831 397 3
824
825
828
709 32 1
707
482 564 1
480
668 802 3
665
666
667
77 795 3
78
79
80
131 546 3
132
133
137
142 919 1
141
34 321 3
41
48
64
502 542 3
503
504
508
72 548 1
70
891 429 ...

output:

65
256
33
385
874
74
824
707
480
665
80
137
141
64
508
70
889
952
34
129
501
209
204
784
392
719
888
792
266
624
556
1
289
456
912
258
692
446
930
778
274
273
904
265
74
791
219
116
710
919
609
389
869
253
609
378
743
672
788
389
396
515
414
760
455
990
745
161
335
10
585
675
982
584
989
97
26
120
8...

result:

ok 

Subtask #3:

score: 16
Accepted

Test #17:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #18:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #19:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #20:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #21:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #22:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #23:

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

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #25:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #26:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #27:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #28:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #29:

score: 16
Accepted
time: 24ms
memory: 3916kb

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
399
491
572
716
533
622
287
951
606
141
408
832
283
127
423
221
35
607
161
742
403
129
681
34
415
484
32
338
889
508
199
568
997
232
477
783
301
159
149
560
378
647
132
325
242
124
904
919
630
496
103
821
515
864
329
89
50
702
339
269
176
868
244
755
240
939
463
845
760
929
950
691
614
968
56...

input:

1
51513
711 560 2
478
479
675 31 2
714
715
584 382 1
999
514 255 1
999
726 509 2
720
721
514 847 2
517
518
306 543 2
5
6
305 677 2
224
225
605 77 2
586
587
509 613 1
999
889 306 2
13
14
895 316 2
899
900
584 662 2
5
569
575 910 2
562
563
432 575 2
167
168
9 176 2
841
842
953 824 1
997
723 957 2
444
...

output:

479
715
999
999
720
518
5
224
586
999
14
900
5
562
167
841
997
444
630
249
827
814
5
447
815
992
999
935
46
205
992
781
237
507
777
818
100
967
105
999
710
279
23
446
650
999
38
999
674
901
999
999
648
884
999
783
999
439
934
807
429
883
456
913
134
787
375
386
910
677
424
106
284
51
877
663
556
954...

result:

ok 

Test #30:

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

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
669
62
780
914
630
116
998
777
663
941
356
949
853
866
627
601
417
789
758
974
429
711
836
793
694
464
39
372
731
952
864
186
695
306
453
303
250
927
352
171
145
875
174
833
45
774
678
551
894
690
872
23
91
485
334
951
829
959
461
997
720
611
599
750
748
766
604
169
684
137
245
574
697
332
49...

input:

1
49931
984 233 2
981
982
652 246 2
622
623
966 553 30
0
1
45
79
119
164
193
231
264
294
327
359
400
427
467
503
529
557
591
616
659
695
722
754
791
816
845
865
894
934
695 234 2
721
966
538 46 2
547
548
385 380 2
373
374
260 472 2
234
235
24 494 2
21
22
690 134 2
663
664
122 792 2
160
161
889 114 2...

output:

981
622
529
966
548
374
234
21
663
161
869
492
941
654
966
918
563
992
117
647
405
834
164
495
217
831
448
482
36
565
966
999
226
250
396
0
186
286
445
745
916
671
974
459
165
329
425
228
507
246
334
176
424
695
584
399
371
577
954
325
831
877
257
527
705
351
145
946
124
768
27
966
468
529
886
616
2...

result:

ok 

Test #31:

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

input:

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

output:

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

input:

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

output:

0
95
0
0
0
17
0
95
95
95
95
0
0
95
24
95
0
0
14
0
0
95
0
95
29
0
95
61
95
95
95
0
27
0
0
0
95
0
0
0
95
0
0
95
26
0
95
95
0
95
75
46
19
95
75
95
0
0
95
95
95
0
95
0
0
85
95
0
50
95
8
0
95
0
0
95
0
40
95
0
95
0
95
0
0
94
95
95
0
95
0
95
25
11
0
9
53
56
2
95
95
0
95
95
0
95
18
0
95
0
84
95
95
0
95
76
0...

result:

ok 

Test #32:

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

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
482
393
533
283
499
285
490
155
159
286
506
38
213
14
27
99
311
378
267
333
538
314
539
79
154
450
457
6
37
25
418
72
334
534
486
219
195
438
403
537
497
479
290
475
170
282
329
294
325
221
142
426
302
192
187
212
525
71
18
529
492
415
330
384
428
35
214
301
338
16
321
460
413
440
141
193
29
3...

input:

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

output:

0
0
540
540
138
540
540
540
540
0
0
540
0
540
0
540
0
0
540
0
0
540
0
540
0
540
540
540
0
540
540
540
540
540
0
0
540
540
0
540
540
540
540
0
0
540
0
0
540
540
540
540
0
540
0
0
0
540
540
540
0
540
540
540
0
540
540
0
540
540
0
540
540
540
0
540
540
0
0
161
540
540
540
540
0
0
540
540
540
0
0
0
0
54...

result:

ok 

Test #33:

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

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
928 612 1
999
953 665 1
999
943 660 1
999
877 85 1
999
196 718 1
0
29 232 1
999
737 590 1
0
597 392 1
999
386 744 1
999
105 319 1
0
275 805 1
0
225 810 1
999
28 667 1
0
238 327 1
0
107 172 1
0
924 762 1
999
718 435 1
999
182 711 1
0
808 17 1
999
607 169 1
999
486 393 1
999
880 890 1
999
925 ...

output:

999
999
999
999
0
999
0
999
999
0
0
999
0
0
0
999
999
0
999
999
999
999
999
0
840
0
0
999
999
0
999
0
999
0
999
999
999
999
999
999
999
999
0
999
0
0
999
999
999
999
999
999
999
759
999
999
999
999
999
999
0
999
0
999
0
999
999
999
999
0
0
999
999
999
999
999
999
999
999
999
999
999
999
999
999
0
99...

result:

ok 

Subtask #4:

score: 10
Accepted

Test #34:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #35:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #36:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #37:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #38:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #39:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #40:

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

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

input:

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

output:

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

result:

ok 

Test #41:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #42:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #43:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #44:

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

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

input:

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

output:

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

result:

ok 

Test #45:

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

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

input:

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

output:

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

result:

ok 

Test #46:

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

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

input:

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

output:

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

result:

ok 

Test #47:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #48:

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

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

input:

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

output:

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

result:

ok 

Test #49:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #50:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #51:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #52:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #53:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Subtask #5:

score: 61
Accepted

Test #54:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #55:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #56:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #57:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #58:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #59:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #60:

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

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #62:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #63:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #64:

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

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
256
1
741
512
383
510
128
255
868
995
639
740
320
257
447
384
65
2
192
129
805
742
932
869
576
513
677
640
351
382
288
319
478
509
415
446
96
127
33
64
223
254
160
191
836
867
773
804
963
994
900
931
607
638
544
575
708
739
661
676
336
321
367
352
273
258
304
289
463
448
494
479
400
38...

input:

1
49888
886 210 3
893
900
901
485 35 1
483
597 413 1
596
925 222 1
924
141 970 3
142
143
144
160 586 3
129
130
145
394 613 1
393
648 844 3
655
660
661
717 78 1
715
812 723 3
813
814
818
184 472 3
185
186
190
754 264 3
755
756
760
554 220 1
553
513 26 3
544
575
639
952 441 1
950
524 324 1
522
182 855...

output:

901
483
596
924
144
129
393
661
715
818
190
760
553
639
950
522
180
351
152
325
172
223
669
728
97
923
868
680
842
674
501
645
95
382
719
445
149
559
735
445
153
577
493
986
486
801
592
277
509
505
942
760
417
568
41
119
253
840
992
743
844
508
254
648
57
951
521
10
606
631
351
871
207
760
585
389
3...

result:

ok 

Test #65:

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

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
128
1
384
257
192
255
64
127
447
510
320
383
160
129
224
193
33
2
96
65
416
385
479
448
289
258
352
321
176
191
144
159
239
254
208
223
48
63
17
32
111
126
80
95
431
446
400
415
494
509
463
478
304
319
273
288
367
382
336
351
168
161
184
177
137
130
152
145
232
225
247
240
201
194
216
...

input:

1
59652
13 30 1
15
93 305 1
94
1 3 1
2
0 1 1
1
113 56 1
115
2 1 2
0
1
0 1 1
1
1 0 1
0
0 1 1
1
335 73 3
320
321
328
389 379 3
386
387
388
32 102 3
48
63
64
2 0 1
0
807 162 3
745
777
792
242 253 1
243
13 17 1
14
0 1 1
1
11 94 1
12
65 112 3
80
95
127
298 144 1
297
202 154 1
203
0 2 2
2
3
2 0 1
0
300 33...

output:

15
94
2
1
115
1
1
0
1
320
386
64
0
745
243
14
1
12
127
297
203
2
0
297
8
447
24
22
7
1
392
0
1
1
95
0
1
1
477
0
214
23
27
943
317
2
0
145
1
2
2
109
4
0
179
1
0
15
1
1
66
1
1
0
0
0
24
35
62
56
279
0
76
215
17
30
0
93
1
107
2
2
2
4
20
8
1
1
334
52
15
18
0
246
8
0
161
4
0
1
16
79
119
0
0
0
862
0
479
0
...

result:

ok 

Test #66:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #67:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #68:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #69:

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

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
256
1
744
512
383
510
128
255
871
998
639
743
320
257
447
384
65
2
192
129
808
745
935
872
576
513
680
640
351
382
288
319
478
509
415
446
96
127
33
64
223
254
160
191
839
870
776
807
966
997
903
934
607
638
544
575
711
742
664
679
336
321
367
352
273
258
304
289
463
448
494
479
400
3...

input:

1
50098
873 250 3
880
887
903
818 535 1
817
909 72 1
908
488 917 1
487
497 924 1
495
657 890 3
658
659
663
843 705 1
841
628 51 1
627
276 84 1
274
320 758 3
351
382
383
849 59 1
848
252 159 1
250
422 169 1
420
871 911 3
744
745
808
521 965 3
514
515
518
469 867 1
467
152 680 3
145
146
149
363 923 3
...

output:

903
817
908
487
495
663
841
627
274
383
848
250
420
744
514
467
145
366
175
325
420
141
529
315
884
920
671
716
806
869
899
29
744
873
777
374
414
66
228
96
463
958
89
745
743
277
222
908
665
126
564
937
710
623
2
521
668
881
448
293
863
250
745
10
571
471
999
940
806
352
386
781
258
546
239
951
981...

result:

ok 

Test #70:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #71:

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

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
662
918
438
406
373
956
950
683
784
578
582
746
752
540
254
62
240
630
3
474
42
143
614
821
257
242
870
130
441
929
531
224
720
897
543
869
673
745
249
599
500
739
333
466
575
...

input:

1
50431
579 114 2
748
749
335 463 2
355
356
934 559 1
21
264 649 2
64
65
387 114 1
937
770 786 2
655
656
806 748 2
795
796
1 672 2
425
426
601 169 2
608
609
52 802 2
62
63
24 580 2
381
382
706 548 2
719
720
757 817 2
570
571
493 618 2
911
912
247 968 1
937
397 754 1
937
583 891 2
586
587
709 614 2
6...

output:

749
356
21
64
937
655
795
426
609
63
382
720
570
911
937
937
587
694
742
345
133
937
267
937
755
350
297
644
610
928
836
924
577
614
697
924
1
580
957
650
622
600
32
338
642
55
689
469
189
52
961
438
307
656
163
633
127
128
830
549
1
737
21
479
821
819
637
881
389
811
460
21
894
775
722
311
939
517
...

result:

ok 

Test #72:

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

input:

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

output:

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

input:

1
51725
817 441 2
885
886
834 61 2
237
238
483 507 2
493
494
58 466 1
59
985 704 1
999
197 63 2
506
507
699 123 2
701
702
485 476 2
357
358
439 747 2
422
423
768 22 2
747
748
988 208 1
999
482 694 2
589
590
293 614 2
410
411
19 511 1
999
408 563 2
663
664
123 913 2
74
75
196 380 2
507
508
6 446 1
7
...

output:

886
237
494
59
999
507
702
358
422
747
999
590
411
999
663
74
507
7
508
337
443
26
624
999
999
284
282
740
999
150
977
438
752
847
646
495
235
579
444
814
747
420
809
960
953
999
583
852
889
999
20
16
240
742
542
281
997
371
948
790
882
755
505
273
965
110
826
676
999
937
997
997
190
999
308
864
62
...

result:

ok 

Test #73:

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

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

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

input:

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

output:

95
95
47
0
95
58
95
95
0
95
95
95
95
95
95
67
0
95
0
95
95
0
95
95
95
95
0
95
0
95
95
95
0
95
95
95
95
95
95
95
6
95
95
0
50
95
95
95
95
95
13
0
38
13
43
95
69
45
95
95
0
95
0
95
95
95
95
95
95
0
95
53
51
78
35
0
95
95
57
95
0
95
0
95
95
95
0
95
95
95
95
95
31
87
0
95
95
95
95
21
0
95
69
14
92
20
0
...

result:

ok 

Test #75:

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

input:

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

output:

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

input:

1
6214
485 471 1
0
106 323 1
540
482 37 1
540
232 208 1
540
486 302 1
0
311 483 1
0
45 65 1
0
354 93 1
0
160 30 1
0
421 140 1
0
112 212 1
0
368 140 1
540
384 353 1
0
360 254 1
0
402 238 1
0
439 299 1
0
378 114 1
540
266 314 1
0
303 409 1
540
174 319 1
540
500 0 1
0
105 506 1
540
264 100 1
0
321 206 ...

output:

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

result:

ok 

Test #76:

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

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
184
843
610
934
557
317
43
103
902
561
885
456
906
42
768
641
187
356
950
636
508
303
230
368
532
65
794
591
972
124
519
875
681
829
330
337
748
55
94
955
733
526
854
278
724
503
461
56
428
903
602
483
235
581
986
12
864
735
45
328
155
10
867
982
978
196
426
663
251
416
341
651
21
408
550
312...

input:

1
10180
18 801 1
0
4 425 1
0
618 21 1
0
796 713 1
999
471 862 1
0
532 783 1
0
866 91 1
999
213 609 1
0
968 871 1
0
552 573 1
0
21 252 1
999
140 644 1
999
331 310 1
999
783 397 1
0
849 677 1
999
678 513 1
0
288 914 1
0
712 209 1
999
50 101 1
0
397 26 1
0
290 876 1
0
763 396 1
0
171 768 1
0
977 61 1
9...

output:

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

result:

ok 

Test #77:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #78:

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

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

input:

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

output:

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

result:

ok 

Test #79:

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

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

input:

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

output:

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

result:

ok 

Test #80:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #81:

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

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

input:

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

output:

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

result:

ok 

Test #82:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #83:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #84:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #85:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #86:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Test #87:

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

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
155
194
124
558
147
584
296
438
948
455
900
514
867
567
280
383
965
88
616
301
287
847
360
964
99
545
329
566
792
601
276
770
445
343
594
712
23
865
451
67
693
741
21
860
853
560
154
342
773
799
159
611
11
344
251
390
233
347
465
833
836
166
120
785
614
886
367
439
30
279
585
973
552
899
20
33...

input:

1
35090
479 530 2
262
263
886 311 2
710
711
765 897 2
761
762
924 982 2
202
203
152 716 2
30
31
472 442 2
675
676
136 567 2
20
21
707 286 2
736
737
424 194 2
319
320
702 839 2
445
446
781 713 2
826
827
893 178 2
690
691
381 646 2
883
884
179 570 2
934
935
282 645 2
459
460
679 1 2
0
1
147 119 2
221
...

output:

262
710
761
202
30
676
20
737
319
445
827
690
883
934
460
1
222
286
191
69
778
12
887
743
906
800
393
398
857
562
267
220
492
828
684
306
376
24
588
649
226
167
879
247
416
484
381
216
481
912
921
69
444
807
95
275
767
735
946
718
115
802
636
279
376
78
600
399
300
715
1
978
906
630
702
627
856
681
...

result:

ok 

Test #88:

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

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
843
893
553
540
867
805
413
68
716
404
168
133
655
660
516
903
906
262
813
269
215
832
147
854
597
44
252
510
358
724
908
426
557
364
3
492
614
803
331
120
558
925
72
631
877
630
110
223
337
687
762
718
385
155
180
77
207
776
907
200
673
940
672
882
934
502
698
212
29
32
447
712
419
730
734
3...

input:

1
47617
731 667 2
732
733
615 84 3
608
609
612
138 897 1
135
378 81 3
379
380
381
926 60 1
927
268 277 1
267
588 142 2
977
978
818 355 2
816
817
47 851 2
209
210
191 73 6
192
193
195
200
201
202
479 557 1
469
503 780 2
63
64
642 625 1
999
212 979 2
214
215
277 625 3
278
279
280
0 330 1
999
252 803 2...

output:

733
608
135
381
927
267
978
816
210
202
469
63
999
215
280
999
4
102
999
556
702
353
999
11
843
960
193
490
254
311
348
254
918
799
920
675
681
61
180
131
665
869
999
434
632
42
851
404
59
848
11
14
723
999
21
64
650
519
842
316
1
999
999
789
137
15
308
775
180
76
157
167
731
292
917
216
448
862
877...

result:

ok 

Test #89:

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

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
284 67 1
296
791 262 2
800
801
953 181 2
696
697
701 493 2
890
891
632 711 2
596
597
236 914 2
936
937
447 106 3
441
444
446
372 894 2
288
289
749 47 2
736
737
689 467 2
696
697
110 534 2
85
86
963 403 2
209
210
680 74 1
681
41 519 1
67
210 230 2
620
621
255 154 2
405
406
9...

output:

710
296
801
696
891
596
936
441
288
736
697
85
210
681
67
620
406
836
845
973
701
758
368
358
710
123
318
3
81
335
485
143
355
246
903
59
736
574
242
232
246
293
765
677
213
640
940
437
75
677
473
57
153
700
759
529
325
818
746
432
331
380
199
137
531
360
207
604
511
542
273
759
190
422
593
419
161
...

result:

ok 

Test #90:

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

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
610
422
330
326
801
16
146
795
134
750
496
194
214
312
983
821
382
739
439
911
713
127
928
806
400
768
680
222
198
428
903
616
857
978
53
797
353
3
37
350
275
478
874
343
710
655
614
777
464
76
729
125
818
216
99
165
536
721
30
308
705
683
247
370
816
528
34
942
521
545
28
419
541
689
306
426
...

input:

1
50698
124 136 3
125
127
129
979 846 1
974
41 159 1
999
660 26 3
667
915
916
219 503 2
221
223
602 818 1
603
931 922 1
932
489 263 1
52
296 95 3
322
323
324
471 820 2
796
798
82 788 1
999
447 797 2
443
446
931 94 1
932
471 728 2
452
469
4 658 2
5
992
739 676 1
732
341 767 1
340
694 979 2
695
696
67...

output:

129
974
999
916
223
603
932
52
324
798
999
443
932
452
992
732
340
696
667
930
921
118
25
22
164
858
782
400
134
282
517
265
281
805
64
756
118
127
612
410
503
684
793
118
988
282
548
118
679
284
168
460
613
356
118
762
553
676
744
668
553
562
731
742
752
920
731
184
56
571
267
415
605
529
766
505
8...

result:

ok 

Test #91:

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

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
610
422
330
326
801
16
146
795
134
750
496
194
214
312
983
821
382
739
439
911
713
127
928
806
400
768
680
222
198
428
903
616
857
978
53
797
353
3
37
350
275
478
874
343
710
655
614
777
464
76
729
125
818
216
99
165
536
721
30
308
705
683
247
370
816
528
34
942
521
545
28
419
541
689
306
426
...

input:

1
50698
124 136 3
125
127
129
979 846 1
974
41 159 1
999
660 26 3
667
915
916
219 503 2
221
223
602 818 1
603
931 922 1
932
489 263 1
52
296 95 3
322
323
324
471 820 2
796
798
82 788 1
999
447 797 2
443
446
931 94 1
932
471 728 2
452
469
4 658 2
5
992
739 676 1
732
341 767 1
340
694 979 2
695
696
67...

output:

129
974
999
916
223
603
932
52
324
798
999
443
932
452
992
732
340
696
667
930
921
118
25
22
164
858
782
400
134
282
517
265
281
805
64
756
118
127
612
410
503
684
793
118
988
282
548
118
679
284
168
460
613
356
118
762
553
676
744
668
553
562
731
742
752
920
731
184
56
571
267
415
605
529
766
505
8...

result:

ok 

Test #92:

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

input:

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

output:

992
0
5
24
311
988
257
567
264
293
898
434
344
62
282
589
874
420
54
200
141
376
239
443
530
142
488
467
833
827
336
784
963
507
964
319
595
987
933
271
18
871
657
382
804
690
512
549
714
368
465
513
893
325
514
723
957
505
287
825
954
675
359
250
664
598
731
609
840
526
51
288
451
938
672
670
597
6...

input:

1
49569
211 558 1
212
536 543 2
537
540
454 310 1
453
49 1 2
47
48
583 615 3
226
227
228
148 721 1
184
925 571 4
889
922
923
924
53 501 1
54
970 17 3
909
910
911
928 973 1
930
107 633 1
102
478 110 1
477
290 146 1
289
628 272 1
543
870 972 1
849
733 127 2
734
736
148 0 4
149
158
161
162
444 560 1
40...

output:

212
540
453
47
226
184
889
54
909
930
102
477
289
543
849
736
162
40
111
748
897
905
87
234
432
364
989
649
22
598
726
460
670
751
290
169
789
926
499
986
129
425
731
250
295
116
739
267
404
100
543
470
374
989
219
603
433
191
849
543
191
132
432
989
849
230
272
975
876
990
204
990
448
738
989
442
4...

result:

ok 

Test #93:

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

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
5
24
311
988
257
567
264
293
898
434
344
62
282
589
874
420
54
200
141
376
239
443
530
142
488
467
833
827
336
784
963
507
964
319
595
987
933
271
18
871
657
382
804
690
512
549
714
368
465
513
893
325
514
723
957
505
287
825
954
675
359
250
664
598
731
609
840
526
51
288
451
938
672
670
597
6...

input:

1
49569
211 558 1
212
536 543 2
537
540
454 310 1
453
49 1 2
47
48
583 615 3
226
227
228
148 721 1
184
925 571 4
889
922
923
924
53 501 1
54
970 17 3
909
910
911
928 973 1
930
107 633 1
102
478 110 1
477
290 146 1
289
628 272 1
543
870 972 1
849
733 127 2
734
736
148 0 4
149
158
161
162
444 560 1
40...

output:

212
540
453
47
226
184
889
54
909
930
102
477
289
543
849
736
162
40
111
748
897
905
87
234
432
364
989
649
22
598
726
460
670
751
290
169
789
926
499
986
129
425
731
250
295
116
739
267
404
100
543
470
374
989
219
603
433
191
849
543
191
132
432
989
849
230
272
975
876
990
204
990
448
738
989
442
4...

result:

ok 

Test #94:

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

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
779
429
815
301
244
793
250
103
113
289
869
795
217
715
941
306
114
397
384
772
557
321
194
136
349
763
125
362
435
156
410
930
183
834
867
75
605
620
678
638
50
315
77
56
60
944
419
12
747
532
74
563
892
792
290
205
591
275
501
687
979
90
212
294
311
751
272
355
682
132
849
5
913
331
274
208...

input:

1
50684
837 964 1
819
142 687 1
141
57 566 2
42
43
400 926 1
397
324 721 1
325
427 934 1
428
253 586 1
254
235 137 3
231
232
234
250 914 2
251
263
333 456 1
295
846 613 2
847
849
272 309 10
273
274
275
276
277
278
280
286
287
309
863 911 2
536
862
826 536 3
99
808
810
860 152 1
868
18 798 1
999
416 ...

output:

819
141
42
397
325
428
254
231
263
295
849
309
536
99
868
999
999
844
796
446
101
413
76
597
469
139
528
137
340
769
7
962
185
532
751
618
999
198
582
266
936
88
75
959
266
751
887
11
57
495
869
712
403
745
3
163
831
554
11
501
238
177
360
74
35
11
986
25
597
7
120
18
558
688
14
834
679
831
858
130
...

result:

ok 

Test #95:

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

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
207
516
38
636
690
311
367
276
128
264
400
550
654
637
28
523
594
206
355
113
608
698
173
32
108
152
619
684
410
357
520
146
543
490
438
57
42
700
455
41
588
499
335
13
711
139
507
724
486
251
567
174
682
402
186
689
223
653
669
54
177
515
230
719
458
29
661
133
364
422
705
327
297
660
135
599...

input:

1
5230
211 201 1
0
250 341 1
0
461 193 1
730
259 603 1
0
682 122 1
730
559 235 1
0
58 127 1
730
247 9 1
0
579 616 1
0
298 688 1
0
154 76 1
730
95 406 1
0
154 351 1
730
622 430 1
0
404 196 1
730
94 274 1
0
203 281 1
730
727 692 1
0
484 173 1
0
235 286 1
730
628 128 1
730
221 370 1
730
505 131 1
730
5...

output:

0
0
730
0
730
0
730
0
0
0
730
0
730
0
730
0
730
0
0
730
730
730
730
0
0
0
730
730
0
0
65
0
0
0
0
730
0
730
0
730
0
0
719
0
0
0
730
730
0
0
730
0
0
730
0
0
0
0
730
0
0
0
730
0
0
730
730
730
0
0
0
730
730
0
0
730
0
730
0
730
0
730
0
730
0
0
730
730
0
730
0
0
730
730
730
222
730
0
730
0
730
0
0
0
730
0...

result:

ok 

Test #96:

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

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
206
737
831
722
546
412
112
570
663
2
508
388
277
989
349
481
971
332
975
551
280
716
94
939
60
909
687
826
974
413
969
35
809
115
471
940
87
850
616
516
204
445
44
697
406
110
446
502
572
538
688
409
531
813
334
83
495
714
160
510
917
750
468
796
248
839
736
718
611
552
981
752
57
543
631
81...

input:

1
10180
700 389 1
0
0 722 1
999
717 178 1
0
280 864 1
999
875 757 1
999
633 120 1
0
359 741 1
999
591 343 1
0
645 291 1
0
760 825 1
0
434 970 1
999
424 253 1
0
735 77 1
0
926 318 1
0
957 664 1
0
270 782 1
0
104 667 1
999
862 900 1
999
338 911 1
999
466 490 1
0
124 511 1
0
902 243 1
999
607 841 1
0
6...

output:

0
999
0
999
999
0
999
0
0
0
999
0
0
0
0
0
999
999
999
0
0
999
0
999
0
999
0
999
999
999
0
999
999
999
999
999
0
0
999
0
0
436
999
0
0
0
0
999
0
0
999
999
999
0
0
0
999
0
999
0
999
999
0
0
999
999
999
999
999
0
999
0
0
0
999
999
999
999
0
0
999
999
999
999
0
999
0
999
0
999
0
999
999
999
0
0
999
999
...

result:

ok 

Test #97:

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

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
121
606
108
344
737
523
475
134
680
647
550
838
854
28
411
739
418
474
843
728
351
228
315
713
629
461
376
690
160
444
597
196
873
868
849
350
821
180
867
306
746
832
446
652
791
59
625
229
332
182
642
87
327
260
696
199
437
40
25
528
560
197
569
735
888
386
104
757
354
627
876
82
221
839
384
...

input:

1
13208
877 496 8
2
870
871
872
873
874
875
876
365 59 11
299
355
356
357
358
359
360
361
362
363
364
890 499 10
9
881
882
883
884
885
886
887
888
889
800 578 10
720
791
792
793
794
795
796
797
798
799
857 691 10
6
848
849
850
851
852
853
854
855
856
183 347 10
184
185
186
187
188
189
190
191
192
26...

output:

2
299
9
720
6
263
588
349
649
378
157
691
725
288
94
703
20
825
345
768
11
456
552
11
588
356
5
378
826
11
885
7
20
253
20
375
147
352
10
72
211
356
676
253
207
649
627
779
890
402
722
7
846
589
735
2
627
102
862
410
502
517
434
20
722
7
288
885
179
193
299
718
352
832
789
422
759
11
498
62
463
5
73...

result:

ok 

Test #98:

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

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
974
315
466
890
199
77
929
475
271
477
38
498
951
279
813
78
19
158
804
715
908
129
472
835
198
769
426
290
492
972
938
760
299
373
327
367
690
63
973
778
941
496
559
82
573
564
577
503
400
439
201
54
215
221
886
506
207
423
834
529
116
962
773
398
712
93
308
242
358
50
342
87
967
669
562
667...

input:

1
16365
853 180 9
854
855
856
857
858
859
860
861
916
346 250 8
347
348
349
350
351
352
353
386
101 915 8
109
117
125
133
141
149
157
986
10 501 9
83
156
229
278
351
790
863
936
991
345 776 3
339
343
344
596 207 8
564
589
590
591
592
593
594
595
576 175 6
483
546
552
558
564
570
698 704 9
644
690
69...

output:

916
386
986
790
339
564
483
644
25
510
107
226
536
670
503
229
512
538
2
565
77
187
843
717
952
994
329
633
90
248
507
819
985
548
386
501
156
902
589
114
901
682
770
862
901
390
336
740
278
449
546
558
765
516
544
173
2
570
225
506
225
420
332
75
950
591
790
113
108
689
158
632
111
156
389
854
200
...

result:

ok 

Test #99:

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

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
681
593
708
576
61
166
221
90
296
119
290
120
532
169
445
454
219
423
116
302
700
409
155
53
662
406
521
655
254
543
26
153
488
701
523
342
672
180
489
598
32
568
396
405
544
686
417
269
565
326
584
127
193
273
158
498
628
484
402
320
514
607
209
636
226
152
592
631
338
176
440
47
564
213
561
...

input:

1
33400
609 486 3
241
242
608
317 467 3
116
118
316
126 3 3
552
553
554
681 216 3
605
606
680
49 93 3
549
550
552
515 381 3
327
328
329
395 383 3
34
36
37
350 114 3
78
79
80
201 41 3
367
368
369
231 228 3
232
380
381
296 48 3
273
275
295
286 125 3
197
199
200
465 261 3
195
196
197
537 233 3
655
656
...

output:

242
116
554
605
549
329
37
80
369
381
273
197
197
658
490
499
111
271
362
146
32
556
31
558
547
253
294
407
228
575
508
395
648
190
473
270
56
493
471
264
240
398
676
310
55
648
144
444
129
625
324
567
655
216
553
115
498
269
407
588
227
5
613
233
69
446
332
474
516
285
543
529
8
542
672
61
257
371
...

result:

ok 

Test #100:

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

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
591
144
250
22
857
333
465
846
271
912
258
940
452
49
733
505
243
615
403
719
69
398
852
344
85
494
673
894
307
162
743
851
399
699
806
565
785
966
475
297
685
629
184
655
435
391
755
204
939
351
299
473
800
511
563
956
192
578
330
930
232
483
570
195
426
932
292
199
259
54
582
769
347
350
70...

input:

1
33377
159 847 3
481
482
483
227 748 3
228
736
738
658 977 3
389
391
657
753 264 3
208
210
211
803 985 3
51
52
802
410 498 3
132
133
409
736 190 3
150
151
735
544 202 3
98
99
100
30 506 3
512
513
515
538 209 3
660
661
663
158 268 3
37
39
40
944 151 3
116
117
943
256 386 3
257
601
602
521 281 3
553
...

output:

483
738
389
211
51
132
151
100
512
663
37
117
601
556
552
306
100
65
282
595
131
286
949
492
27
173
768
4
37
390
369
564
766
773
407
783
845
179
883
112
728
230
467
481
512
146
955
83
891
522
601
52
865
757
856
811
2
579
246
117
919
415
102
900
274
512
39
307
283
360
810
516
807
759
352
120
718
76
5...

result:

ok 

Test #101:

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

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
351
182
633
194
69
159
60
296
512
693
470
441
575
324
771
806
886
356
898
249
502
447
57
841
615
483
267
751
596
795
423
303
533
430
455
152
399
13
323
87
726
587
460
598
816
539
169
855
757
856
170
747
144
501
315
676
548
493
61
790
367
688
658
349
202
391
546
326
289
595
146
736
214
746
874
...

input:

1
4502
283 63 42
225
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
309 187 1
35
674 255 1
764
125 446 69
126
127
128
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
6...

output:

225
35
764
675
447
298
494
510
214
464
904
107
272
252
539
35
904
795
904
883
852
716
125
662
74
800
494
675
904
515
204
272
785
498
904
614
535
22
494
814
26
35
904
49
49
210
764
49
244
481
836
904
130
675
125
904
672
863
33
125
346
716
198
904
50
214
599
56
904
515
214
539
904
675
394
464
904
800
...

result:

ok 

Test #102:

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

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
290
885
203
499
303
187
995
607
195
495
526
68
142
315
641
978
240
428
45
837
350
866
39
610
617
903
908
212
822
790
27
600
384
630
799
125
582
96
884
182
646
230
876
414
272
438
90
453
298
391
778
99
141
891
305
549
91
588
121
382
745
861
670
800
550
407
925
949
658
618
233
919
785
917
259
6...

input:

1
4293
341 329 1
313
79 575 1
44
894 877 1
930
869 997 1
609
206 282 44
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
241
242
243
244
245
246
247
248
249
349
901 133 1
930
640 564 1
650
745 164 1
709
395 360 1
...

output:

313
44
930
609
349
930
650
709
486
117
109
845
930
800
305
84
999
999
117
722
999
44
109
688
84
845
845
23
350
935
109
486
885
109
188
982
472
800
299
111
758
134
44
609
74
999
999
468
117
132
109
613
933
658
984
622
999
722
23
933
132
999
523
44
845
84
609
104
495
712
819
999
299
44
367
829
43
331
...

result:

ok 

Extra Test:

score: 0
Extra Test Passed