QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136007#1139. Stationsbashkort#57.320549 58ms4132kbC++203.4kb2023-08-06 17:46:142024-07-04 01:20:05

Judging History

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

  • [2024-07-04 01:20:05]
  • 评测
  • 测评结果:57.320549
  • 用时:58ms
  • 内存:4132kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-06 17:46:14]
  • 提交

stations

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

using namespace std;

constexpr int X = 999;

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
    std::vector<int> labels(n);
    vector<vector<int>> adj(n);
    for (int i = 0; i + 1 < n; ++i) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    if (k > 1000) {
        int T = 0;
        auto dfs = [&](auto self, int v, int par) -> void {
            labels[v] += T++;
            for (int to: adj[v]) {
                if (to != par) {
                    self(self, to, v);
                }
            }
            labels[v] += T * X;
        };
        dfs(dfs, 0, -1);
        labels[0] = 0;
        return labels;
    } else {
        int bin = 1;
        for (int i = 0; i + 1 < n; ++i) {
            if (min(u[i], v[i]) == i / 2 && max(u[i], v[i]) == i + 1) {
                bin = true;
            } else {
                bin = false;
                break;
            }
        }
        if (bin) {
            iota(labels.begin(), labels.end(), 0);
            return labels;
        }
        int leaf = 0;
        while (adj[leaf].size() == 2) {
            leaf += 1;
        }
        int T = 0;
        auto dfs = [&](auto self, int v, int par) -> void {
            labels[v] = T++;
            for (int to : adj[v]) {
                if (to != par) {
                    self(self, to, v);
                }
            }
        };
        dfs(dfs, leaf, -1);
        return labels;
    }
}

pair<int, int> decode(int x) {
    if (x == 0) {
        return {0, 1e9};
    } else {
        int tin = x % X;
        if (tin == 0) {
            tin = X;
        }
        return {tin, (x - tin) / X};
    }
}

bool isp(int a, int b, int c, int d) {
    return a <= c && b >= d;
}

int find_next_station(int s, int t, std::vector<int> c) {
    for (int to : c) {
        if (to == t) {
            return to;
        }
    }
    if (max({s, t, *max_element(c.begin(), c.end())}) > 1000) {
        auto [tins, touts] = decode(s);
        auto [tint, toutt] = decode(t);
        if (isp(tins, touts, tint, toutt)) {
            for (int to: c) {
                auto [into, outo] = decode(to);
                if (!isp(into, outo, tins, touts) && isp(into, outo, tint, toutt)) {
                    return to;
                }
            }
        } else {
            for (int to: c) {
                auto [into, outo] = decode(to);
                if (isp(into, outo, tins, touts)) {
                    return to;
                }
            }
        }
        assert(false);
        return -1;
    } else {
        int bin = 1;
        for (int to : c) {
            int mx = max(to, s);
            int mn = min(to, s);
            if ((mx - 1) / 2 != mn) {
                bin = false;
            }
        }
        if (!bin) {
            for (int to : c) {
                if ((to < s) == (t < s)) {
                    return to;
                }
            }
            assert(false);
        }
        int x = t;
        while (x > s && !binary_search(c.begin(), c.end(), x)) {
            x /= 2;
        }
        if (x <= s) {
            for (int to : c) {
                if (to < s) {
                    return to;
                }
            }
        }
        return x;
    }
}


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

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

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
8
3
6
1
4
5
7
0
2
9
3
0
1
2
998
218
223
165
11
508
816
365
369
132
114
329
529
80
787
608
66
447
270
680
519
863
579
434
687
402
709
718
962
818
320
207
839
801
701
976
339
454
107
846
907
255
6
307
23
314
963
240
105
373
478
587
139
909
572
584
903
4
136
265
468
198
878
121
243
158
40
76
163
558...

input:

1
59784
0 1 1
1
730 818 2
729
731
0 1 1
1
303 620 2
302
304
3 2 1
2
1 0 1
0
0 1 1
1
931 112 2
930
932
2 0 2
1
3
0 1 1
1
948 832 2
947
949
7 6 2
6
8
27 639 2
26
28
131 800 2
130
132
377 250 2
376
378
570 874 2
569
571
0 1 1
1
7 41 2
6
8
1 2 2
0
2
0 1 1
1
919 92 2
918
920
1 0 1
0
466 117 2
465
467
0 1...

output:

1
731
1
304
2
0
1
930
1
1
947
6
28
132
376
571
1
8
2
1
918
0
465
1
1
993
2
0
0
478
98
277
2
7
40
0
391
92
5
1
7
488
449
389
89
679
183
891
552
14
1
478
300
2
1
1
2
810
1
6
0
0
389
540
934
65
65
0
0
283
707
250
414
0
584
936
1
2
141
1
2
667
1
566
1
75
162
722
7
7
7
1
55
6
2
732
586
661
1
841
788
624
...

result:

ok 

Test #2:

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

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
124
983
716
420
968
575
827
330
603
20
674
111
869
591
570
136
852
363
356
121
249
182
122
188
979
966
652
261
605
563
141
520
663
463
399
731
647
681
491
398
163
890
545
127
883
418
518
817
944
482
822
297
403
981
360
454
142
773
842
206
917
393
259
550
341
335
938
919
422
568
922
630
914
426
9...

input:

1
50048
666 56 2
665
667
867 546 2
866
868
754 101 2
753
755
893 730 2
892
894
648 198 2
647
649
830 222 2
829
831
933 284 2
932
934
756 352 2
755
757
803 772 2
802
804
805 221 2
804
806
874 539 2
873
875
944 910 2
943
945
236 38 2
235
237
541 94 2
540
542
233 140 2
232
234
42 319 2
41
43
148 27 2
1...

output:

665
866
753
892
647
829
932
755
802
804
873
943
235
540
232
43
147
977
504
111
360
173
739
228
394
289
473
546
481
634
128
395
526
715
29
543
611
509
339
802
601
223
411
317
901
569
550
232
94
956
329
978
290
446
400
603
976
383
503
596
450
41
399
416
19
65
688
260
232
252
252
746
934
936
244
67
62
...

result:

ok 

Test #3:

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

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

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

input:

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

output:

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

result:

ok 

Test #5:

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

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

input:

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

output:

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

result:

ok 

Test #6:

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

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
724
316
559
445
798
438
571
115
487
620
66
500
675
269
782
179
524
71
716
740
442
910
928
550
744
69
530
343
271
670
54
714
292
889
549
19
186
155
63
296
105
878
545
846
32
266
767
514
732
161
668
338
360
978
70
587
700
0
64
432
202
471
13
142
31
644
852
402
200
472
597
893
661
891
75
591
861
2...

input:

1
50055
875 537 2
874
876
943 948 2
942
944
277 344 2
276
278
41 428 2
40
42
638 231 2
637
639
444 822 2
443
445
873 943 2
872
874
30 730 2
29
31
4 311 2
3
5
952 530 2
951
953
400 455 2
399
401
219 405 2
218
220
838 880 2
837
839
634 520 2
633
635
586 719 2
585
587
499 482 2
498
500
562 455 2
561
56...

output:

874
944
278
42
637
445
874
31
5
951
401
220
839
633
587
498
561
732
454
930
256
118
65
359
149
998
86
670
722
307
928
536
175
309
123
243
109
95
538
295
783
934
611
350
948
451
627
463
333
390
862
660
508
392
422
605
231
401
935
130
63
35
942
240
797
542
620
195
84
13
586
957
938
473
39
736
942
655
...

result:

ok 

Test #7:

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

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
748
389
97
178
98
278
967
167
726
919
134
353
49
778
144
618
42
519
444
146
526
441
638
762
694
153
450
542
468
904
995
244
843
409
811
174
225
366
741
590
940
347
758
267
482
359
985
493
757
126
513
176
241
974
672
903
592
697
709
58
44
317
105
10
465
947
327
760
567
112
96
257
633
623
64
939
...

input:

1
50046
219 561 2
218
220
868 482 2
867
869
49 499 2
48
50
864 818 2
863
865
771 425 2
770
772
615 746 2
614
616
604 258 2
603
605
878 7 2
877
879
628 796 2
627
629
818 912 2
817
819
992 109 2
991
993
927 957 2
926
928
750 963 2
749
751
497 511 2
496
498
34 570 2
33
35
943 767 2
942
944
22 856 2
21
...

output:

220
867
50
863
770
616
603
877
629
819
991
928
751
498
35
942
23
928
301
624
829
649
52
372
103
541
89
964
432
467
25
390
384
672
972
235
657
125
782
672
498
331
658
39
664
324
332
213
525
235
904
480
172
933
745
430
734
83
799
116
574
433
482
894
924
315
13
301
442
496
834
38
310
130
773
331
661
14...

result:

ok 

Test #8:

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

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

input:

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

output:

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

result:

ok 

Test #9:

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

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

input:

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

output:

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

result:

ok 

Test #10:

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

input:

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

output:

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

input:

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

output:

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

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 24ms
memory: 3808kb

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
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
91
92
93
94
95
96
97
98
99
100
10...

input:

1
50252
876 174 1
437
937 71 1
468
508 771 1
253
715 87 1
357
940 154 1
469
721 974 1
360
864 867 1
431
728 899 1
363
433 888 3
216
867
868
235 92 3
117
471
472
508 517 1
253
404 582 3
201
809
810
902 767 1
450
712 486 1
355
655 0 1
327
545 583 1
272
471 488 3
235
943
944
40 666 3
19
81
82
691 417 1...

output:

437
468
253
357
469
360
431
363
216
117
253
201
450
355
327
272
235
19
345
495
489
471
433
35
349
484
307
445
426
59
29
237
448
345
81
382
407
111
330
370
233
357
126
239
178
132
147
106
465
143
147
347
486
268
231
61
338
490
205
155
212
480
302
366
471
417
22
280
321
308
443
106
405
138
14
13
461
3...

result:

wrong answer Diff at 18-th number: read 19 but expected 82

Subtask #3:

score: 16
Accepted

Test #17:

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

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
1999
997
0
863387
863563
863714
863207
863436
863661
863427
863516
863172
863795
863250
996889
863766
863620
863592
996939
996883
863181
996950
863297
863621
863318
863573
863308
996973
863806
863924
863756
863535
996894
863158
863211
863476
863741
863511
863532
863362
863218
863842
996953
86329...

input:

1
59859
5995 5999 2
0
5996
1999 0 1
0
1999 0 1
0
999031 999085 2
999030
999032
998294 998396 2
998293
998295
997267 997865 2
997266
997268
0 1999 1
1999
9997 0 2
9996
9998
999122 999328 2
999121
999123
0 1999 1
1999
0 1999 1
1999
1999 0 1
0
2998 2999 2
0
2999
996900 863310 2
996899
996901
999371 999...

output:

5996
0
0
999032
998295
997268
1999
9996
999123
1999
1999
0
2999
996899
999370
999510
5996
2998
863430
99930
997558
998386
996977
996980
2999
887827
887638
887808
2998
3998
887754
0
997543
3997
0
3998
997630
999326
997793
2999
863510
887812
999989
999642
5998
3997
998919
863591
998977
2999
998228
399...

result:

ok 

Test #18:

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

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
998988
800828
800922
800745
800425
800540
800396
800948
998807
800614
998821
998953
800546
998881
800405
800516
800448
998803
800920
800809
800455
800935
800968
800725
800807
800741
800888
800573
800715
998980
800240
998903
800943
800709
800660
998952
800484
800706
800862
800991
800708
800253
...

input:

1
50048
930218 930630 2
930217
930219
743598 743743 2
743597
743599
995816 995860 2
995815
995817
930658 930238 2
930657
930659
800675 998930 2
800674
800676
800475 800782 2
800474
800476
990976 930252 2
990975
990977
930934 930724 2
930933
930935
743806 995975 2
743805
743807
961046 961468 2
961045...

output:

930219
743599
995817
930657
800674
800476
990975
930933
743805
961047
800728
996228
992989
961886
743758
604904
743729
684933
992660
991313
961654
961235
993385
996317
991137
684670
743492
604513
800460
604494
961846
991194
604708
604661
995970
991585
999864
604749
743444
604670
106948
993348
961842...

result:

ok 

Test #19:

score: 16
Accepted
time: 52ms
memory: 3804kb

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

input:

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

output:

1999
1999
0
1999
0
1999
1999
1999
0
1999
0
1999
0
0
0
0
1999
0
0
1999
1999
1999
1999
0
1999
1999
1999
0
1999
1999
0
0
1999
1999
1999
1999
0
0
1999
1999
1999
0
1999
1999
0
1999
0
0
0
1999
0
1999
0
0
0
1999
0
0
1999
0
0
0
0
0
0
0
1999
0
1999
1999
0
1999
1999
0
1999
0
1999
1999
1999
0
1999
0
0
1999
0
0...

result:

ok 

Test #20:

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

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
1999
2999
3
0
2999
1999
3
0
2999
2998
3
0
2999
2998
3
0
2998
2999
3
0
2998
2999
3
0
2999
2998
3
0
2998
2999
3
0
2998
2999
3
0
2999
2998

input:

1
74899
0 2999 1
2998
2999 0 1
2998
2999 2998 1
2998
1999 0 1
0
2999 1999 1
0
0 1999 2
1999
2999
2998 0 2
0
2999
0 2998 1
2998
0 2999 1
2998
2998 2999 2
0
2999
0 2999 2
1999
2999
0 2998 1
2998
0 2998 1
2998
2999 0 1
2998
2999 2998 1
2998
0 2999 1
2998
0 2999 1
2998
0 2999 1
2998
2999 0 1
0
2998 0 2
...

output:

2998
2998
2998
0
0
1999
0
2998
2998
2999
2999
2998
2998
2998
2998
2998
2998
2998
0
0
2999
2998
2998
2998
2998
2999
2999
2998
0
0
2998
2998
2998
0
2998
2998
2998
2998
2999
0
2999
2998
0
2998
2998
2998
2999
2998
0
0
2998
2998
0
2998
2999
2999
0
2999
2998
2999
0
2998
1999
2998
1999
2998
0
2999
0
2998
2...

result:

ok 

Test #21:

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

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
1999
3998
3999
4
0
3998
3997
3999
4
0
3998
3999
3997
4
0
3998
3997
3999
4
0
3998
3999
3997
4
0
2998
2999
3999
4
0
3999
3998
1999
4
0
2998
3999
2999
4
0
3999
2998
2999
4
0
3998
3999
3997

input:

1
66495
3998 3999 2
0
3999
3998 3997 2
3997
3999
2999 0 1
2998
1999 0 1
0
1999 3998 1
0
3999 3997 1
3998
2999 0 1
2998
2998 0 2
0
2999
3999 3998 1
3998
3999 3997 1
3998
3999 1999 1
3998
3998 0 2
3997
3999
3998 0 2
0
3999
3999 0 1
0
3999 3997 1
3998
3999 0 1
3998
3999 2998 1
0
3998 3997 2
3997
3999
3...

output:

3999
3997
2998
0
0
3998
2998
0
3998
3998
3998
3997
0
0
3998
3998
0
3997
3999
3998
2999
3997
3998
0
0
3998
0
3997
0
3998
3998
0
0
3997
0
2998
3997
2998
0
2998
3998
0
3997
3998
2998
0
3998
0
1999
3999
3998
3997
1999
2998
3998
2998
2999
3998
3997
3998
3998
3997
0
3997
0
0
3997
3999
3998
3998
1999
2998
...

result:

ok 

Test #22:

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

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
723632
723623
723387
723986
723551
723962
999774
723360
999927
723392
723800
723496
723491
999965
999888
723389
723669
723562
999820
723317
723523
723646
723377
723945
723918
999903
999908
999806
999942
999823
999874
999993
723366
999752
723403
999924
723412
723531
723714
723427
723987
723304...

input:

1
50050
293783 293981 2
293782
293784
339768 339770 2
339767
339769
999823 723709 2
999822
999824
999909 999225 2
999908
999910
999997 322706 2
999996
999998
999362 999425 2
999361
999363
999836 723696 2
999835
999837
999312 230952 2
999311
999313
999617 999462 2
999616
999618
723735 999995 2
723734...

output:

293784
339769
999822
999908
999996
999363
999835
999311
999616
723734
999692
999848
999734
999829
999602
999457
999672
999313
999740
293882
999455
999299
999846
999732
999566
723407
723396
723762
999502
999663
339924
999925
293963
999936
723382
999310
999678
999394
293890
999741
999414
999654
999947...

result:

ok 

Test #23:

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

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
999956
999370
234903
234831
999564
999925
999824
234769
234876
999759
234776
999805
999875
999932
999996
234955
999656
999511
234854
234857
999796
999249
999900
999789
999533
999387
999326
234828
999722
999312
999634
234941
234772
999841
999882
999712
999979
999259
234949
234953
234804
999858...

input:

1
50053
999445 999346 2
999444
999446
999619 999812 2
999618
999620
234817 234968 2
234816
234818
999877 999522 2
999876
999878
999568 999667 2
999567
999569
999896 999784 2
999895
999897
234960 999832 2
234959
234961
999490 999523 2
999489
999491
999693 999388 2
999692
999694
999410 999575 2
999409...

output:

999444
999620
234818
999876
999569
999895
234959
999491
999692
999411
234979
999793
999839
234809
999759
234873
234773
999916
999920
999439
999393
999646
999751
999616
999612
999518
234899
999669
234914
999292
999260
999799
999958
999700
999885
999403
999746
999483
999758
234952
999709
234824
999844...

result:

ok 

Test #24:

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

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
3997
3998
3999
4
0
3997
3999
3998
4
0
3998
3997
3999
4
0
3999
3997
3998
4
0
3998
3999
3997
4
0
3999
3998
3997
4
0
1999
3998
3999
4
0
1999
3999
3998
4
0
2999
2998
3999
4
0
2999
3999
2998

input:

1
120
3997 3999 2
0
3998
3997 3998 2
0
3998
3997 3998 2
0
3998
3999 3998 1
3998
3998 3997 2
3997
3999
0 1999 2
1999
3998
0 3999 2
1999
3998
0 3997 1
3997
3999 1999 1
3998
3998 1999 2
0
3999
3997 0 2
0
3998
1999 3998 1
0
3997 0 2
0
3998
3998 3999 2
3997
3999
1999 3999 1
0
0 3998 1
3997
3998 3999 2
39...

output:

3998
3998
3998
3998
3997
1999
3998
3997
3998
0
0
0
0
3999
0
3997
3999
2998
3999
3997
3997
3997
3999
3998
3998
3998
3997
3998
0
3999
3998
1999
3997
3998
0
3998
3998
2998
0
3997
3998
3997
0
3998
3998
3997
3998
3997
3997
3998
0
2998
3999
3997
0
3997
0
3998
0
3998
3997
3998
3997
0
2998
3998
3998
3997
29...

result:

ok 

Test #25:

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

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
5995
5996
5997
5998
5999
6
0
5995
5996
5997
5999
5998
6
0
5995
5996
5998
5997
5999
6
0
5995
5996
5999
5997
5998
6
0
5995
5996
5998
5999
5997
6
0
5995
5996
5999
5998
5997
6
0
5995
5997
5996
5998
5999
6
0
5995
5997
5996
5999
5998
6
0
5995
5998
5996
5997
5999
6
0
5995
5999
5996
5997
5998

input:

1
300
5997 5996 2
5996
5998
5998 5997 2
5997
5999
5998 0 2
5997
5999
5998 5999 2
5997
5999
5995 5999 2
0
5996
5997 0 2
5996
5998
5995 5997 2
0
5996
5998 5995 2
5997
5999
0 5995 1
5995
5996 5999 2
5995
5997
0 5996 1
5995
5997 5999 2
5996
5998
5997 5998 2
5996
5998
5996 5997 2
5995
5997
5996 5998 2
59...

output:

5996
5997
5997
5999
5996
5996
5996
5997
5995
5997
5995
5998
5998
5997
5997
5999
5997
5998
5998
5997
5996
0
5996
5997
5995
5995
5995
5999
5997
5998
5997
5997
5995
5998
5997
5996
5995
5997
5998
5999
5998
5995
5998
5998
5999
5996
5995
5996
5996
5995
5997
5995
5996
5998
5999
5996
5995
5995
5997
5997
599...

result:

ok 

Test #26:

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

input:

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

output:

3
0
2998
2999
3
0
2999
2998
3
0
1999
2999

input:

1
18
0 2999 1
2998
0 2998 1
2998
0 2999 2
1999
2999
0 2999 1
2998
2999 0 1
2998
2998 2999 2
0
2999
2999 1999 1
0
2999 0 1
2998
0 2998 1
2998
2998 0 2
0
2999
1999 0 1
0
2998 0 2
0
2999
1999 2999 1
0
2999 0 1
0
2999 2998 1
2998
0 1999 2
1999
2999
2999 2998 1
2998
2998 2999 2
0
2999

output:

2998
2998
2999
2998
2998
2999
0
2998
2998
0
0
0
0
0
2998
1999
2998
2999

result:

ok 

Test #27:

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

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
3997
3998
3999
4
0
3997
2999
3999
4
0
1999
2999
3999
4
0
2998
3999
2999
4
0
3999
2999
3997
4
0
3997
3999
2999
4
0
1999
3999
3998
4
0
3999
3998
1999
4
0
3999
3997
2999
4
0
3999
2998
2999

input:

1
66694
0 3999 2
1999
3998
3998 3999 2
0
3999
2999 3997 1
3997
3997 0 3
0
2999
3999
3999 1999 1
3998
2998 2999 2
0
2999
1999 2999 1
0
3999 2998 1
0
2999 3997 1
3997
3999 1999 1
3998
0 3999 1
3997
3999 1999 1
3998
1999 2999 1
0
2998 3999 2
0
2999
3997 3999 3
0
2999
3999
0 3998 1
3997
3998 1999 2
0
39...

output:

3998
3999
3997
0
3998
2999
0
0
3997
3998
3997
3998
0
0
3999
3997
0
3997
3997
3997
3997
3997
3997
0
3997
3997
3997
2998
3997
3997
0
3998
3997
3998
0
3999
3998
2999
0
3997
3997
0
0
0
3999
3998
2998
3997
0
3998
2998
3999
3997
3997
3998
0
2999
0
3997
0
3997
3999
3997
3997
3997
3998
2998
3998
3997
3997
3...

result:

ok 

Test #28:

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

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
279991
512958
625966
936991
838997
625906
338996
915999
957999
999034
700993
320999
512996
392999
700996
86999
838981
700992
143992
512949
625896
190999
385999
702999
512955
416999
512997
115999
388999
838988
345999
626999
383999
289997
925999
253999
300999
255999
907999
148999
999027
647999
...

input:

1
51340
752545 999790 2
752544
752546
999265 999051 2
999264
999266
646616 646862 2
646615
646617
349965 956989 2
349964
349966
999897 999497 2
999896
999898
625980 260999 2
625979
625981
700982 13993 2
700981
700983
143992 919993 2
143991
143993
609999 702999 1
609998
701999 684997 1
999002
752387 ...

output:

752544
999264
646617
349964
999896
625979
700981
143991
609998
999002
752388
752984
687985
999071
971993
662995
396934
999071
999002
838980
795928
833960
386994
752833
799994
999071
968973
396984
999655
999847
981941
999241
168992
246991
783703
999921
625943
286934
783671
894923
999857
999850
25977
...

result:

ok 

Test #29:

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

input:

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

output:

1000
0
603997
512997
429999
290994
467993
383995
715999
53997
398999
863998
594998
171997
719999
874996
579998
780995
965993
398997
839996
258993
603994
874999
322997
970996
588998
517997
970999
664999
114998
495999
802999
436998
998004
773995
525999
223995
700999
841998
856996
445998
623994
356998
...

input:

1
51513
999767 999930 2
999766
999768
476960 33971 2
476959
476961
416999 618999 1
999001
486999 745999 1
999001
745994 533996 2
745993
745995
489996 154998 2
489995
489997
311699 999775 2
311698
311700
529919 850813 2
529918
529920
618981 108987 2
618980
618982
491999 387999 1
999001
902124 902709 ...

output:

999768
476959
999001
999001
745993
489995
311698
529918
618980
999001
902125
919994
997012
591986
978734
850168
998004
850720
902642
267992
253934
999561
997012
999583
820994
999326
999001
945976
69984
311901
999029
794997
902571
850846
790990
902266
978600
253785
902307
999001
290993
999368
999032
...

result:

ok 

Test #30:

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

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
308984
922999
213984
73999
351985
888965
999969
213990
308972
33982
640973
33998
122996
102973
351979
376995
567992
213966
213971
999982
540964
272994
151988
176979
308965
540965
966967
608985
245986
33995
122981
803984
272973
673991
540987
673985
736994
73973
640981
803985
848992
102991
8039...

input:

1
49931
999997 736971 2
999996
999998
351970 736997 2
351969
351971
966034 438979 30
0
33968
73960
102971
122980
151971
176975
213963
245968
272973
308964
351957
376975
410966
438972
464974
500964
540960
567973
608959
640968
673967
703970
736967
774962
803971
848955
888960
922966
966956
272973 73697...

output:

999996
351969
438972
966034
438989
608989
736973
966996
308972
848960
102979
500985
33982
351966
966034
73991
410978
999981
888963
351980
567983
151992
803971
500979
774989
151998
540997
500994
966973
410982
966034
999967
774971
736994
608966
0
803984
703985
540996
245985
73995
308988
999982
540975
...

result:

ok 

Test #31:

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

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
55999
86999
30999
92999
23999
83999
4999
76999
64999
77999
32999
94999
91999
50999
28999
49999
72999
11999
22999
53999
42999
9999
74999
20999
10999
71999
2999
21999
52999
62999
58999
54999
26999
65999
60999
1999
25999
29999
17999
45999
41999
75999
19999
39999
47999
48999
57999
90999
46999
59999...

input:

1
4026
66999 94999 1
0
17999 78999 1
95905
34999 84999 1
0
50999 44999 1
0
70999 77999 1
0
0 17999 95
1999
2999
3999
4999
5999
6999
7999
8999
9999
10999
11999
12999
13999
14999
15999
16999
17999
18999
19999
20999
21999
22999
23999
24999
25999
26999
27999
28999
29999
30999
31999
32999
33999
34999
359...

output:

0
95905
0
0
0
17999
0
95905
95905
95905
95905
0
0
95905
24999
95905
0
0
82999
0
0
95905
0
95905
67999
0
95905
61999
95905
95905
95905
0
27999
0
0
0
95905
0
0
0
95905
0
0
95905
26999
0
95905
95905
0
95905
75999
46999
19999
95905
21999
95905
0
0
95905
95905
95905
0
95905
0
0
11999
95905
0
46999
95905
...

result:

ok 

Test #32:

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

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
59999
148999
8999
258999
42999
256999
51999
386999
382999
255999
35999
503999
328999
527999
514999
442999
230999
163999
274999
208999
3999
227999
2999
462999
387999
91999
84999
535999
504999
516999
123999
469999
207999
7999
55999
322999
346999
103999
138999
4999
44999
62999
251999
66999
371999...

input:

1
5675
235999 168999 1
0
201999 376999 1
0
192999 468999 1
540460
207999 59999 1
540460
540460 403999 540
0
2999
3999
4999
5999
6999
7999
8999
9999
10999
11999
12999
13999
14999
15999
16999
17999
18999
19999
20999
21999
22999
23999
24999
25999
26999
27999
28999
29999
30999
31999
32999
33999
34999
35...

output:

0
0
540460
540460
403999
540460
540460
540460
540460
0
0
540460
0
540460
0
540460
0
0
540460
0
0
540460
0
540460
0
540460
540460
540460
0
540460
540460
540460
540460
540460
0
0
540460
540460
0
540460
540460
540460
540460
0
0
540460
0
0
540460
540460
540460
540460
0
540460
0
0
0
540460
540460
540460
...

result:

ok 

Test #33:

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

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
491999
878999
521999
906999
468999
452999
440999
100999
610999
423999
160999
347999
343999
605999
98999
844999
18999
244999
211999
973999
689999
22999
597999
16999
701999
771999
58999
871999
574999
568999
320999
460999
229999
54999
28999
205999
430999
424999
260999
572999
715999
432999
140999...

input:

1
10180
72999 388999 1
999001
47999 335999 1
999001
57999 340999 1
999001
123999 915999 1
999001
196999 718999 1
0
971999 768999 1
999001
737999 590999 1
0
403999 608999 1
999001
614999 256999 1
999001
105999 319999 1
0
275999 805999 1
0
775999 190999 1
999001
28999 667999 1
0
238999 327999 1
0
1079...

output:

999001
999001
999001
999001
0
999001
0
999001
999001
0
0
999001
0
0
0
999001
999001
0
999001
999001
999001
999001
999001
0
840999
0
0
999001
999001
0
999001
0
999001
0
999001
999001
999001
999001
999001
999001
999001
999001
0
999001
0
0
999001
999001
999001
999001
999001
999001
999001
241999
999001
...

result:

ok 

Subtask #4:

score: 10
Accepted

Test #34:

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

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

input:

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

output:

0
1999
1999
0
1999
0
0
0
0
0
1999
0
1999
0
1999
1999
1999
0
0
1999
0
1999
1999
0
0
1999
1999
0
1999
1999
0
0
0
0
0
1999
0
1999
0
0
0
1999
1999
0
1999
1999
1999
1999
0
0
1999
1999
0
0
0
1999
1999
0
1999
1999
0
1999
1999
0
0
0
1999
0
1999
1999
1999
1999
1999
1999
0
1999
0
1999
1999
1999
0
0
0
0
1999
0...

result:

ok 

Test #35:

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

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
2999
2998
3
0
1999
2999
3
0
2999
1999
3
0
2999
2998
3
0
2998
2999
3
0
2998
2999
3
0
2999
2998
3
0
2998
2999
3
0
2999
1999
3
0
2999
2998

input:

1
75069
2998 2999 2
0
2999
0 1999 2
1999
2999
0 2999 1
2998
0 2999 1
2998
1999 0 1
0
0 2999 1
2998
2999 2998 1
2998
2998 0 2
0
2999
1999 2999 1
0
2998 2999 2
0
2999
2998 2999 2
0
2999
2999 0 1
2998
2998 2999 2
0
2999
2998 2999 2
0
2999
2999 0 1
2998
0 2999 1
2998
2998 0 2
0
2999
0 1999 2
1999
2999
0...

output:

2999
1999
2998
2998
0
2998
2998
0
0
2999
2999
2998
2999
2999
2998
2998
0
1999
2998
2998
2999
2999
0
2998
2998
2998
2998
0
2998
0
2999
1999
0
2998
0
2998
0
1999
2998
0
2998
2998
0
2998
0
0
2999
2998
0
0
2998
2999
0
2998
2999
2999
2998
2998
0
2998
2999
2998
2998
2999
0
2999
0
2998
2999
2998
2999
2998
...

result:

ok 

Test #36:

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

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
3998
1999
3999
4
0
3998
3999
3997
4
0
3998
1999
3999
4
0
3997
3998
3999
4
0
3997
3999
3998
4
0
1999
3999
3998
4
0
2999
2998
3999
4
0
3999
3997
3998
4
0
3999
3998
3997
4
0
3999
2999
2998

input:

1
66804
0 2999 2
2998
3999
0 2999 2
2998
3999
3998 0 2
0
3999
0 3997 1
3997
0 3999 2
1999
3998
3998 3999 2
0
3999
3998 3999 2
3997
3999
3997 3998 2
0
3998
0 3998 1
3997
2998 3999 2
0
2999
0 3998 2
1999
3998
3998 0 2
0
3999
3998 3997 2
3997
3999
1999 0 1
0
3997 0 2
0
3998
1999 3999 1
0
1999 0 1
0
399...

output:

2998
2998
0
3997
3998
3999
3999
3998
3997
0
3998
0
3997
0
0
0
0
3999
3997
3998
3999
0
3997
3998
3998
0
0
3998
3998
1999
3999
3998
3998
0
3997
3998
3997
3998
3998
1999
0
3998
3997
3998
3997
0
3998
3998
3997
3998
2998
2998
1999
2998
2998
3998
3998
3998
3999
0
3997
0
3997
2998
3998
0
3998
1999
3997
399...

result:

ok 

Test #37:

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

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
3997
3998
3999
4
0
3997
3999
3998
4
0
3998
3997
3999
4
0
3999
3997
3998
4
0
3998
3999
3997
4
0
3999
3998
3997
4
0
1999
3998
3999
4
0
1999
3999
3998
4
0
2999
2998
3999
4
0
2999
3999
2998

input:

1
120
3998 3997 2
3997
3999
2999 2998 1
2998
3999 3998 1
3998
0 3999 1
3997
1999 3999 1
0
3997 3998 2
0
3998
3999 2999 1
0
0 3998 1
3997
0 3997 1
3997
3999 3997 1
3998
3998 0 2
3997
3999
3999 3998 1
3998
0 3998 2
1999
3998
3998 3999 2
3997
3999
3997 0 2
0
3998
2999 3999 1
2998
3998 0 2
3997
3999
199...

output:

3997
2998
3998
3997
0
3998
0
3997
3997
3998
3997
3998
3998
3999
0
2998
3997
0
3998
0
3998
3999
3998
3998
0
2998
3998
0
2998
3998
3997
3998
3998
3997
3997
0
3997
3997
3997
3997
3998
2999
3999
3998
3998
3999
3998
3999
3998
3998
3998
3997
0
0
2998
0
3997
3997
3998
3998
2998
3997
3999
0
3999
3997
0
3997...

result:

ok 

Test #38:

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

input:

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

output:

6
0
5995
5996
5997
5998
5999
6
0
5995
5996
5997
5999
5998
6
0
5995
5996
5998
5997
5999
6
0
5995
5996
5999
5997
5998
6
0
5995
5996
5998
5999
5997
6
0
5995
5996
5999
5998
5997
6
0
5995
5997
5996
5998
5999
6
0
5995
5997
5996
5999
5998
6
0
5995
5998
5996
5997
5999
6
0
5995
5999
5996
5997
5998

input:

1
300
0 5999 1
5995
5995 5999 2
0
5996
5996 5995 2
5995
5997
5998 5999 2
5997
5999
5997 0 2
5996
5998
0 5995 1
5995
5995 0 2
0
5996
0 5995 1
5995
0 5995 1
5995
5995 5997 2
0
5996
5997 5998 2
5996
5998
0 5998 1
5995
5999 5996 1
5998
5997 5999 2
5996
5998
0 5995 1
5995
5996 5999 2
5995
5997
0 5999 1
5...

output:

5995
5996
5995
5999
5996
5995
0
5995
5995
5996
5998
5995
5998
5998
5995
5997
5995
5997
5995
5998
5997
5996
5997
5996
5998
5996
5997
5995
5995
5996
5995
5997
0
5998
0
5998
0
5996
5998
5996
5996
5996
5995
5996
5999
5995
5998
5997
5997
5998
5995
5995
5997
5998
5997
5997
5995
5996
5995
5997
5998
5998
59...

result:

ok 

Test #39:

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

input:

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

output:

3
0
2998
2999
3
0
2999
2998
3
0
1999
2999

input:

1
18
2998 2999 2
0
2999
2998 0 2
0
2999
2998 0 2
0
2999
2999 0 1
2998
2999 0 1
0
1999 0 1
0
2999 2998 1
2998
2999 1999 1
0
2998 2999 2
0
2999
0 1999 2
1999
2999
1999 2999 1
0
0 2999 1
2998
0 2999 1
2998
0 2998 1
2998
2999 2998 1
2998
2999 0 1
2998
0 2998 1
2998
0 2999 2
1999
2999

output:

2999
0
0
2998
0
0
2998
0
2999
1999
0
2998
2998
2998
2998
2998
2998
2999

result:

ok 

Test #40:

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

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
3997
3999
2999
4
0
3999
2999
3997
4
0
3998
1999
3999
4
0
3997
2999
3999
4
0
3999
3997
3998
4
0
2999
3997
3999
4
0
3998
3997
3999
4
0
3999
3997
2999
4
0
2999
2998
3999
4
0
3999
2999
2998

input:

1
66674
2999 2998 1
2998
2999 3999 1
3997
3997 2999 3
0
2999
3999
2999 3999 1
3997
3997 3999 2
0
3998
3997 2999 3
0
2999
3999
0 1999 2
1999
3998
3997 0 3
0
2999
3999
3997 2999 3
0
2999
3999
3997 3998 2
0
3998
3999 3998 1
3998
3998 1999 2
0
3999
0 3999 1
3997
3999 0 1
3997
3999 2999 1
0
3999 2999 1
0...

output:

2998
3997
2999
3997
3998
2999
1999
0
2999
3998
3998
0
3997
3997
0
0
3997
0
3997
3997
3997
3997
0
3997
0
3999
3997
3997
3997
3999
2998
2998
3997
2998
0
3997
0
3997
3997
3997
3997
3997
3998
3998
3997
2998
3997
3997
3997
2998
0
0
3999
3997
0
3997
0
3997
3999
3997
3998
3997
3997
3997
3997
3997
0
2999
0
...

result:

ok 

Test #41:

score: 10
Accepted
time: 52ms
memory: 4100kb

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

input:

1
100000
1999 0 1
0
1999 0 1
0
0 1999 1
1999
1999 0 1
0
0 1999 1
1999
0 1999 1
1999
0 1999 1
1999
1999 0 1
0
0 1999 1
1999
1999 0 1
0
1999 0 1
0
0 1999 1
1999
0 1999 1
1999
1999 0 1
0
1999 0 1
0
0 1999 1
1999
0 1999 1
1999
0 1999 1
1999
0 1999 1
1999
1999 0 1
0
1999 0 1
0
1999 0 1
0
1999 0 1
0
0 199...

output:

0
0
1999
0
1999
1999
1999
0
1999
0
0
1999
1999
0
0
1999
1999
1999
1999
0
0
0
0
1999
0
1999
1999
0
0
1999
1999
1999
1999
1999
0
0
0
0
0
0
1999
0
1999
1999
0
1999
0
1999
0
1999
1999
1999
0
0
0
0
1999
0
0
0
1999
0
1999
0
0
1999
1999
0
0
0
1999
1999
0
1999
1999
0
0
0
0
1999
0
1999
1999
1999
0
1999
1999
...

result:

ok 

Test #42:

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

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
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999

input:

1
75040
2999 1999 1
0
2999 0 1
0
1999 0 1
0
0 2999 2
1999
2999
1999 2999 1
0
1999 0 1
0
0 2999 2
1999
2999
2999 0 1
0
1999 2999 1
0
0 2999 2
1999
2999
1999 2999 1
0
0 1999 2
1999
2999
0 2999 2
1999
2999
0 2999 2
1999
2999
0 1999 2
1999
2999
1999 2999 1
0
2999 1999 1
0
0 2999 2
1999
2999
2999 0 1
0
2...

output:

0
0
0
2999
0
0
2999
0
0
2999
0
1999
2999
2999
1999
0
0
2999
0
0
0
2999
2999
0
1999
0
0
0
0
0
0
2999
0
0
0
0
2999
1999
0
1999
0
0
1999
0
0
1999
2999
0
0
1999
1999
0
0
1999
0
1999
1999
2999
0
0
0
1999
1999
1999
1999
0
0
2999
0
0
2999
0
1999
2999
2999
0
0
0
0
0
0
0
2999
2999
2999
0
0
0
0
1999
0
0
2999
...

result:

ok 

Test #43:

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

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
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999

input:

1
66554
2998 2999 2
0
2999
0 2999 2
2998
3999
3999 2998 1
0
2999 2998 1
2998
3999 2999 1
0
0 3999 2
2998
3999
2999 2998 1
2998
2998 2999 2
0
2999
3999 0 1
0
3999 2998 1
0
2999 2998 1
2998
2999 2998 1
2998
2998 0 2
0
2999
2998 0 2
0
2999
2998 3999 2
0
2999
3999 2998 1
0
3999 2998 1
0
2998 0 2
0
2999
...

output:

2999
2998
0
2998
0
3999
2998
2999
0
0
2998
2998
0
0
0
0
0
0
0
3999
2998
0
0
2999
0
2998
0
2998
3999
2998
2998
0
0
0
2998
2999
2998
2999
0
0
0
2998
0
2998
0
2998
2998
2998
0
3999
2998
0
3999
2998
0
3999
2999
2998
2998
0
0
2998
0
0
2998
0
0
3999
2998
2998
3999
2998
2998
2998
2998
3999
0
2999
0
0
2998
...

result:

ok 

Test #44:

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

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
5999
6999
6994
4999
2999
3999
7
0
4999
5999
1999
2999
3999
6999
7
0
6999
3999
4999
2998
2999
5999
7
0
6994
6999
5999
3998
4999
3999
7
0
6995
3999
6994
5999
4999
6999
7
0
5999
6999
6994
3999
4999
4997
7
0
3999
6999
5999
4999
3997
2999
7
0
4996
6999
4999
5999
3999
2999
7
0
4998
5999
6994
4999
6999...

input:

1
420
4997 6999 3
3999
4999
6994
6999 3998 1
6994
2998 4999 2
0
2999
5999 0 1
6994
4999 6999 1
0
2999 6999 1
3997
3999 4999 1
4996
4999 6994 1
4997
4999 5999 1
6994
6995 6999 5
3999
4999
5999
6994
6999
4999 0 1
6994
0 6994 1
6994
6994 0 5
0
3998
4999
5999
6999
2999 5999 1
2998
2999 3999 1
4996
2999 ...

output:

6994
6994
0
6994
0
3997
4996
4997
6994
6999
6994
6994
0
2998
4996
6994
6994
6995
0
4996
0
6995
0
2998
0
6995
6994
6994
0
6994
0
4996
6994
0
6995
0
4998
0
3999
3998
6994
5999
6995
2998
4996
0
4997
0
4996
0
6995
6995
4998
0
0
0
2999
0
0
6995
6994
6995
0
6994
0
0
0
6994
2998
6994
6995
0
1999
6994
4997
...

result:

ok 

Test #45:

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

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
6999
4999
5999
4998
4997
6994
7
0
3997
4999
3999
6999
3998
5999
7
0
5997
4999
6999
6994
5999
6995
7
0
4999
6999
5999
3999
5995
4997
7
0
5995
4999
4997
3999
5999
6999
7
0
5998
6999
3997
3999
2999
5999
7
0
2999
6998
4998
2998
4999
6999
7
0
6999
3997
5999
3999
5998
3998
7
0
5999
6994
6995
5998
6999...

input:

1
420
3997 2999 3
0
2999
3999
4999 4997 1
4997
5997 6999 3
4999
5999
6995
5998 6999 2
0
5999
6999 5999 1
6995
4999 2999 1
4998
6999 3998 1
0
5999 0 1
5998
0 4998 1
6994
5995 4999 3
0
4997
5999
5999 0 1
5995
0 5995 2
5995
6999
5995 0 3
0
4997
5999
5999 6999 1
5998
5998 6999 2
0
5999
4997 4999 2
4998
...

output:

2999
4997
6995
0
6995
4998
0
5998
6994
4997
5995
5995
0
5998
0
4998
4997
4997
0
3997
5997
6996
5997
6994
0
5995
6994
0
6995
0
3998
0
4997
0
4999
6999
6994
2999
0
4997
6994
6999
6996
5998
5999
3998
5998
0
0
2998
6996
6996
6994
6995
0
6996
5998
0
5997
5995
5995
4997
6995
0
6994
5998
0
0
5998
5995
4997...

result:

ok 

Test #46:

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

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
2999
6999
6997
3997
3999
6998
7
0
5996
5999
6999
6994
5997
5998
7
0
5995
6999
5999
5996
5998
5997
6
0
4999
5999
2999
5995
3999
6
0
4999
3999
2999
5995
5999
6
0
2999
2998
4999
5999
3999
6
0
3999
2999
5999
2998
4999
6
0
5996
5995
5999
3999
4999
6
0
5999
4999
3999
5995
4997
6
0
5995
4999
5999
5996
...

input:

1
336
0 5999 4
2998
3999
4999
5999
5995 0 5
0
2999
3999
4999
5999
5997 5998 2
5996
5998
2998 5999 2
0
2999
5998 5999 2
5997
5999
0 5995 1
5995
5995 4999 2
0
5996
5996 5995 4
3999
4999
5995
5999
6997 6998 2
0
6998
3999 2999 1
5995
0 5995 1
5995
3999 4999 1
5995
5995 3999 5
0
2999
3999
4999
5999
5995 ...

output:

5999
0
5998
0
5999
5995
5996
5995
6998
5995
5995
5995
3999
5996
5999
6997
6997
0
6994
5996
5995
0
5998
5995
5997
2998
0
0
5996
5995
4998
4997
6997
5995
5995
2998
5995
5996
5996
2999
6997
6997
5995
0
4998
5998
5996
5996
5996
4997
6994
6994
5996
5996
0
4999
5995
5996
5998
3999
5995
2999
0
0
0
5996
599...

result:

ok 

Test #47:

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

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
4998
4999
5999
2998
2999
6
0
3999
5999
3997
2999
5998
6
0
4999
4997
3999
4996
5999
6
0
4997
4996
4999
5999
4998
5
0
4999
2999
3999
4996
5
0
4999
4996
3999
2999
5
0
3999
3997
4999
2999
5
0
4999
4997
3999
4996
5
0
4999
3999
3998
4996
5
0
4997
4998
4999
4996

input:

1
240
3999 0 1
3998
0 2999 1
4996
4997 0 2
4996
4998
4998 4997 2
4997
4999
0 4996 2
4996
5999
0 4999 1
4996
3997 4999 3
0
2999
3999
3999 2999 1
4996
4999 5999 1
4998
3999 3997 1
3997
2999 4999 1
4996
4999 2999 1
4996
0 4999 1
4996
4996 4998 2
0
4997
5999 4999 1
0
4998 2998 2
0
4999
3997 3999 3
0
299...

output:

3998
4996
4996
4997
4996
4996
0
4996
4998
3997
4996
4996
4996
4997
0
0
3999
4997
5999
4998
4998
4996
0
0
0
4997
4998
4996
4998
3997
4996
3997
0
4997
0
4996
3997
0
3999
4996
0
0
2999
0
5998
4996
4996
0
0
4997
3997
4996
0
4996
4997
2998
0
4997
0
0
4996
4997
0
4999
4996
3997
4996
4997
0
4996
4996
4998
...

result:

ok 

Test #48:

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

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
3999
3997
2999
4
0
1999
2999
3999
4
0
3999
3997
3998
3
0
2998
2999
3
0
1999
2999
2
0
1999

input:

1
50
3999 0 1
0
1999 2999 1
0
3999 3998 1
3998
1999 0 1
0
0 2999 1
3997
0 2999 2
1999
2999
2999 1999 1
0
2999 3999 1
3997
3997 3999 2
0
3998
0 1999 2
1999
2999
3997 0 3
0
2999
3999
1999 0 1
0
3999 3997 1
3997
2999 3997 1
3997
2999 0 1
0
0 3999 1
3997
3999 0 1
3998
2998 2999 2
0
2999
1999 0 1
0
3997 ...

output:

0
0
3998
0
3997
2999
0
3997
3998
1999
0
0
3997
3997
0
3997
3998
2999
0
3998
0
3999
1999
0
2998
3999
3997
3997
1999
3997
2999
0
3997
3997
0
0
3997
0
0
0
3997
3997
2998
2999
3998
3997
2998
2998
3999
0

result:

ok 

Test #49:

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

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
7996
7997
1999
7999
7995
7994
7998
8
0
6999
4999
6998
3999
7999
2999
7993
8
0
4996
7997
3998
4999
6999
7999
3999
8
0
7994
4999
6999
7995
7999
1999
5999
8
0
7999
2999
5999
6999
3999
7993
4999
8
0
5999
2999
7999
6999
3999
4999
7993
8
0
7993
7994
7996
7999
7997
6999
7995
8
0
6994
6999
7999
5999
499...

input:

1
57240
7999 7995 1
7995
7993 7999 2
0
7994
7994 7997 2
0
7995
7999 7994 1
7998
7999 6999 1
7995
6999 7999 1
7993
6999 5999 1
6994
6999 7995 1
7995
7999 0 1
7998
4999 2999 1
7993
7999 7993 1
7993
0 7993 1
7993
7997 7993 3
6999
7996
7999
0 6999 1
7993
7995 7996 2
7994
7996
2999 6999 1
7993
3998 0 2
3...

output:

7995
7994
7995
7998
7995
7993
6994
7995
7998
7993
7993
7993
7996
7993
7996
7993
4996
7997
7997
7993
7993
7995
7993
5999
7996
5996
7995
7995
5996
7998
7996
7996
7993
7995
7993
7997
7995
7999
7993
7997
7993
7993
7993
7996
7993
7993
7994
7993
7993
7993
7996
0
5999
7997
7994
7995
7993
7996
7993
7993
799...

result:

ok 

Test #50:

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

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
7993
5999
2999
3999
7999
4999
6999
8
0
7998
5998
3999
3997
3998
7999
5999
8
0
3999
6999
7999
4997
4996
7997
4999
8
0
6996
2999
7993
6999
6997
7999
6998
8
0
6994
6995
6997
6996
6998
6999
7999
8
0
6997
6996
6994
6995
6999
6998
7999
8
0
5999
7999
5998
2999
1999
5997
6999
8
0
6999
7999
2999
7993
399...

input:

1
56820
7999 5998 1
7998
4999 2999 1
7993
7999 6995 1
0
7994 6999 6
3999
4999
5999
6999
7993
7999
7997 7999 3
0
6999
7999
0 6998 1
7993
4997 4999 3
3999
4996
4999
6997 6995 2
6996
6998
5999 0 1
7993
7999 3999 1
7997
5999 5998 1
5998
4999 2999 1
7993
6999 6996 1
6998
6999 4999 1
7993
5999 3999 1
7994...

output:

7998
7993
0
6999
7999
7993
4999
6996
7993
7997
5998
7993
6998
7993
7994
6994
4997
7997
0
7993
7993
6997
7993
7993
6995
4996
7993
7993
4999
6999
4996
5998
6995
7993
5998
4999
0
6996
6997
7994
7993
7993
7993
4996
6994
7997
0
7993
0
7993
6994
7993
7997
7993
6998
7993
7993
2998
7993
7998
0
6994
0
6997
0...

result:

ok 

Test #51:

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

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
7993
7996
7998
7995
7999
2999
7997
8
0
4999
2999
7999
7993
3999
5999
6999
8
0
7996
7999
7998
7995
7997
7994
1999
8
0
4999
7999
6999
6994
3999
2999
5999
8
0
6999
7996
2999
7995
7999
2998
7997
8
0
7997
4997
7998
4998
4996
7999
4999
8
0
6999
7999
5999
2999
6996
4999
7993
8
0
6999
2999
3999
7993
599...

input:

1
57000
6999 5996 1
7993
0 7998 2
4996
7997
5999 4999 1
5996
4997 0 2
4996
4998
7999 3999 1
7993
6999 5999 1
7993
7993 2999 3
0
2999
7995
7993 7999 4
0
5996
6999
7999
7997 7996 3
6999
7996
7999
2998 7999 2
0
2999
2999 7996 1
7993
2998 7999 2
0
2999
3999 4999 1
6994
0 3999 1
7993
5999 4999 1
6994
499...

output:

7993
7997
5996
4996
7993
7993
2999
7999
7996
0
7993
0
6994
7993
6994
0
7996
7997
0
6994
7993
7995
4998
7993
7997
4996
7993
0
7999
0
0
3998
2999
7993
7993
7993
7997
7999
7993
0
7993
3998
7996
4998
3998
4996
7993
7993
4997
5996
3997
7993
6994
7997
4998
7993
5996
6994
7993
7996
7993
7997
0
6996
7993
79...

result:

ok 

Test #52:

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

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
7993
7996
7998
7995
7999
2999
7997
8
0
4999
2999
7999
7993
3999
5999
6999
8
0
7996
7999
7998
7995
7997
7994
1999
8
0
4999
7999
6999
6994
3999
2999
5999
8
0
6999
7996
2999
7995
7999
2998
7997
8
0
7997
4997
7998
4998
4996
7999
4999
8
0
6999
7999
5999
2999
6996
4999
7993
8
0
6999
2999
3999
7993
599...

input:

1
57000
6999 5996 1
7993
0 7998 2
4996
7997
5999 4999 1
5996
4997 0 2
4996
4998
7999 3999 1
7993
6999 5999 1
7993
7993 2999 3
0
2999
7995
7993 7999 4
0
5996
6999
7999
7997 7996 3
6999
7996
7999
2998 7999 2
0
2999
2999 7996 1
7993
2998 7999 2
0
2999
3999 4999 1
6994
0 3999 1
7993
5999 4999 1
6994
499...

output:

7993
7997
5996
4996
7993
7993
2999
7999
7996
0
7993
0
6994
7993
6994
0
7996
7997
0
6994
7993
7995
4998
7993
7997
4996
7993
0
7999
0
0
3998
2999
7993
7993
7993
7997
7999
7993
0
7993
3998
7996
4998
3998
4996
7993
7993
4997
5996
3997
7993
6994
7997
4998
7993
5996
6994
7993
7996
7993
7997
0
6996
7993
79...

result:

ok 

Test #53:

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

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
7993
7996
7998
7995
7999
2999
7997
8
0
4999
2999
7999
7993
3999
5999
6999
8
0
7996
7999
7998
7995
7997
7994
1999
8
0
4999
7999
6999
6994
3999
2999
5999
8
0
6999
7996
2999
7995
7999
2998
7997
8
0
7997
4997
7998
4998
4996
7999
4999
8
0
6999
7999
5999
2999
6996
4999
7993
8
0
6999
2999
3999
7993
599...

input:

1
57000
6999 5996 1
7993
0 7998 2
4996
7997
5999 4999 1
5996
4997 0 2
4996
4998
7999 3999 1
7993
6999 5999 1
7993
7993 2999 3
0
2999
7995
7993 7999 4
0
5996
6999
7999
7997 7996 3
6999
7996
7999
2998 7999 2
0
2999
2999 7996 1
7993
2998 7999 2
0
2999
3999 4999 1
6994
0 3999 1
7993
5999 4999 1
6994
499...

output:

7993
7997
5996
4996
7993
7993
2999
7999
7996
0
7993
0
6994
7993
6994
0
7996
7997
0
6994
7993
7995
4998
7993
7997
4996
7993
0
7999
0
0
3998
2999
7993
7993
7993
7997
7999
7993
0
7993
3998
7996
4998
3998
4996
7993
7993
4997
5996
3997
7993
6994
7997
4998
7993
5996
6994
7993
7996
7993
7997
0
6996
7993
79...

result:

ok 

Subtask #5:

score: 26.3205
Acceptable Answer

Test #54:

score: 26.3205
Acceptable Answer
time: 40ms
memory: 3804kb

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
2998
2999
998
0
997337
997318
997716
997922
203936
997632
997935
997218
997529
203978
997687
997238
997717
997633
997882
203970
203924
997923
203848
997387
203885
997750
997562
997576
203858
203981
997950
997366
997636
997260
997948
997622
997818
997539
997259
997441
997721
997798
997284
203808
...

input:

1
59797
3998 3999 2
3997
3999
759772 759866 2
759771
759773
1999 0 1
0
99984 99951 2
99983
99985
487726 998921 2
487725
487727
3997 0 2
0
3998
3997 3999 2
0
3998
997323 997619 2
997322
997324
998945 998543 2
998944
998946
996578 996728 2
996577
996579
0 1999 1
1999
759743 759751 2
759742
759744
7596...

output:

3999
759773
0
99983
487725
0
3998
997324
998944
996579
1999
759744
759636
997253
0
996333
999516
99926
9999
999176
999941
0
3997
998562
203985
999905
998833
999948
997654
1999
0
999214
996233
2998
759257
99931
203890
999987
99968
0
2998
1999
998742
996278
0
759887
999695
759866
998544
9998
1999
1469...

result:

points 0.43148441690 max label = 999999

Test #55:

score: 26.3205
Acceptable Answer
time: 30ms
memory: 3760kb

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
265980
265979
996330
996860
996409
996921
996326
265792
996357
996975
265846
265976
996827
996565
996599
265740
996403
996759
996879
996691
265795
265920
996686
996658
996816
996909
996335
996929
996361
996530
996608
996859
996342
996570
996757
996956
996875
996369
265840
996881
996391
996482
...

input:

1
50045
777657 990802 2
777656
777658
754879 754915 2
754878
754880
997570 997929 2
997569
997571
991543 991267 2
991542
991544
996779 996351 2
996778
996780
754624 754841 2
754623
754625
754720 754927 2
754719
754721
999576 999492 2
999575
999577
591753 998733 2
591752
591754
603656 994873 2
603655...

output:

777656
754880
997571
991542
996778
754625
754721
999575
591752
603655
997703
754590
991842
999734
991766
998777
998875
997623
999448
777974
997806
997278
995800
994992
996850
231961
754797
777523
754531
999585
578935
999278
265986
564925
564502
265854
118966
603500
603881
564806
578494
0
998758
9972...

result:

points 0.43148441690 max label = 999999

Test #56:

score: 50
Acceptable Answer
time: 52ms
memory: 3808kb

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

input:

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

output:

1999
1999
1999
0
1999
1999
1999
1999
1999
1999
0
1999
0
1999
0
0
1999
1999
0
1999
1999
1999
0
0
0
0
0
0
1999
1999
0
1999
1999
1999
1999
0
1999
0
1999
1999
0
1999
0
1999
0
1999
1999
1999
1999
1999
0
1999
0
0
1999
1999
0
1999
0
1999
1999
1999
1999
1999
1999
1999
1999
0
0
0
0
0
0
1999
0
1999
1999
1999
...

result:

points 0.81967213110 max label = 1999

Test #57:

score: 48.4563
Acceptable Answer
time: 36ms
memory: 3780kb

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
2999
1999
3
0
2998
2999
3
0
2998
2999
3
0
2999
1999
3
0
2998
2999
3
0
2999
2998
3
0
2999
2998
3
0
2998
2999
3
0
2999
1999
3
0
2999
1999

input:

1
74928
0 2999 1
2998
0 2999 1
2998
2998 0 2
0
2999
2999 2998 1
2998
2999 0 1
2998
2999 0 1
2998
1999 2999 1
0
2999 2998 1
2998
0 2999 2
1999
2999
2999 0 1
0
2999 1999 1
0
0 2998 1
2998
2999 0 1
2998
2998 2999 2
0
2999
2999 1999 1
0
2999 0 1
2998
0 2999 1
2998
0 2999 2
1999
2999
1999 0 1
0
1999 0 1
...

output:

2998
2998
0
2998
2998
2998
0
2998
2999
0
0
2998
2998
2999
0
2998
2998
2999
0
0
2998
2999
2999
2998
0
2998
2998
2998
2999
2998
1999
2998
2998
2998
0
0
2998
2998
2999
1999
2998
2998
0
2998
2999
2998
2999
0
2998
2998
2998
0
2998
2999
0
0
2999
2998
0
2998
2999
2998
2999
2999
2998
0
2998
2999
2998
2998
2...

result:

points 0.79436608150 max label = 2999

Test #58:

score: 47.3599
Acceptable Answer
time: 42ms
memory: 3800kb

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
3998
3997
3999
4
0
3998
3999
1999
4
0
3999
2999
2998
4
0
3999
3998
3997
4
0
2999
3999
2998
4
0
3999
2999
2998
4
0
3997
3999
3998
4
0
2998
2999
3999
4
0
3997
3999
3998
4
0
2998
2999
3999

input:

1
66734
2999 0 1
2998
3998 3997 2
3997
3999
2998 2999 2
0
2999
3998 0 2
0
3999
2998 2999 2
0
2999
3998 0 2
3997
3999
2998 0 2
0
2999
3998 3997 2
3997
3999
0 2999 2
2998
3999
2999 3999 1
2998
2999 0 1
2998
0 2998 2
2998
3999
2999 2998 1
2998
0 2999 2
2998
3999
3998 1999 2
0
3999
3999 0 1
0
3999 3998 ...

output:

2998
3997
2999
0
2999
3997
0
3997
2998
2998
2998
2998
2998
2998
0
0
3998
3998
3997
3998
0
2998
2998
0
3998
2998
0
3997
3999
0
3998
0
3997
3997
0
3998
3998
2998
0
0
0
2998
0
3998
3998
0
0
0
3999
0
2998
3999
0
3998
3998
0
3997
0
1999
0
3998
3998
3997
3998
3998
0
0
0
3998
2999
2999
3998
2998
3998
0
399...

result:

points 0.77639117130 max label = 3999

Test #59:

score: 26.3205
Acceptable Answer
time: 30ms
memory: 3804kb

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
999719
503884
999683
999553
999509
999889
503944
503618
503882
999954
999634
503552
503960
503641
999813
999505
999682
999959
503907
999678
503975
999994
503767
999533
503790
503768
999896
999626
999838
503874
503600
999921
999932
503728
999603
503862
999513
503967
999707
999546
503703
503719...

input:

1
50038
999618 999631 2
999617
999619
999678 999709 2
999677
999679
953129 953562 2
953128
953130
999918 999799 2
999917
999919
953380 999977 2
953379
953381
953765 953832 2
953764
953766
999952 999690 2
999951
999953
999529 999242 2
999528
999530
999391 999345 2
999390
999392
999610 503556 2
999609...

output:

999619
999679
953130
999917
953379
953766
999951
999528
999390
999609
999538
999610
999966
999314
252774
370653
953316
999927
999828
999685
999668
999517
379976
503800
953657
370848
999160
999377
999046
999919
503728
999715
370868
999313
999972
999409
999810
999809
999283
999659
999566
401948
999940...

result:

points 0.43148441690 max label = 999999

Test #60:

score: 26.3205
Acceptable Answer
time: 38ms
memory: 4060kb

input:

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

output:

1000
0
557495
557601
557500
999981
557818
557840
557459
999881
999580
999987
557695
557685
557792
557642
999598
999749
999649
557509
557859
557651
999858
557692
557547
557894
557603
999776
557812
999835
557772
557756
557452
999971
557732
557935
999923
557708
557758
557704
999901
999682
557969
557892...

input:

1
50048
557457 557512 2
557456
557458
999780 557949 2
999779
999781
557777 999596 2
557776
557778
557839 557467 2
557838
557840
999565 557918 2
999564
999566
557865 557927 2
557864
557866
999739 557501 2
999738
999740
557482 999852 2
557481
557483
557446 557985 2
557445
557447
999667 999841 2
999666...

output:

557458
999779
557776
557838
999564
557866
999738
557481
557447
999668
557626
557840
999708
557642
557968
557809
557605
557838
999686
999880
557886
557670
999926
999685
557444
557934
557518
557855
999977
557955
557882
999688
999710
557557
999859
557990
557665
557633
999955
999762
999956
999616
999861...

result:

points 0.43148441690 max label = 999999

Test #61:

score: 47.3599
Acceptable Answer
time: 0ms
memory: 3800kb

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
3997
3998
3999
4
0
3997
3999
3998
4
0
3998
3997
3999
4
0
3999
3997
3998
4
0
3998
3999
3997
4
0
3999
3998
3997
4
0
1999
3998
3999
4
0
1999
3999
3998
4
0
2999
2998
3999
4
0
2999
3999
2998

input:

1
120
3999 1999 1
3998
3997 3999 2
0
3998
3999 3997 1
3998
0 3998 1
3997
3999 3997 1
3998
0 3999 2
2998
3999
3997 3998 2
0
3998
2998 2999 2
0
2999
1999 0 1
0
3999 0 1
3998
0 3999 1
3997
3998 3997 2
3997
3999
3997 3998 2
0
3998
3998 1999 2
0
3999
0 3997 1
3997
3997 0 2
0
3998
0 3997 1
3997
3998 0 2
3...

output:

3998
3998
3998
3997
3998
3999
3998
2999
0
3998
3997
3997
3998
0
3997
0
3997
3997
0
3997
2998
0
3997
3997
0
2998
0
0
3999
1999
3998
3998
0
3999
2998
3997
2999
3998
3998
3997
3997
3998
0
3998
0
3998
3998
3999
3998
3997
3997
0
3997
2998
3999
0
3998
0
3998
2998
3997
3998
0
3998
0
3997
0
3998
3999
3999
2...

result:

points 0.77639117130 max label = 3999

Test #62:

score: 45.8146
Acceptable Answer
time: 0ms
memory: 3812kb

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
5995
5996
5997
5998
5999
6
0
5995
5996
5997
5999
5998
6
0
5995
5996
5998
5997
5999
6
0
5995
5996
5999
5997
5998
6
0
5995
5996
5998
5999
5997
6
0
5995
5996
5999
5998
5997
6
0
5995
5997
5996
5998
5999
6
0
5995
5997
5996
5999
5998
6
0
5995
5998
5996
5997
5999
6
0
5995
5999
5996
5997
5998

input:

1
300
0 5997 1
5995
5998 5995 2
5997
5999
5995 5997 2
0
5996
5996 0 2
5995
5997
0 5999 1
5995
5999 5996 1
5998
5998 5996 2
5997
5999
5995 5997 2
0
5996
5999 5997 1
5998
5998 0 2
5997
5999
0 5996 1
5995
5998 0 2
5997
5999
5998 0 2
5997
5999
5995 5998 2
0
5996
5996 5998 2
5995
5997
5998 0 2
5997
5999
...

output:

5995
5997
5996
5995
5995
5998
5997
5996
5998
5997
5995
5997
5997
5996
5997
5997
5998
5999
5995
5995
5997
5998
5995
5995
5995
5996
5995
5998
5995
5997
5998
5997
5996
5995
5997
5998
5997
5998
5995
5995
5997
5998
5995
5998
5998
0
5996
5998
0
5997
5995
5995
5996
5995
5997
5996
5996
5998
5996
5996
5997
5...

result:

points 0.75105909040 max label = 5999

Test #63:

score: 48.4563
Acceptable Answer
time: 0ms
memory: 3868kb

input:

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

output:

3
0
2998
2999
3
0
2999
2998
3
0
1999
2999

input:

1
18
2998 0 2
0
2999
1999 0 1
0
2998 2999 2
0
2999
0 2998 1
2998
2999 0 1
2998
0 2998 1
2998
0 1999 2
1999
2999
2998 0 2
0
2999
2999 2998 1
2998
2999 0 1
0
2998 2999 2
0
2999
1999 2999 1
0
0 2999 1
2998
0 2999 1
2998
2999 2998 1
2998
0 2999 2
1999
2999
2999 0 1
2998
2999 1999 1
0

output:

0
0
2999
2998
2998
2998
1999
0
2998
0
2999
0
2998
2998
2998
2999
2998
0

result:

points 0.79436608150 max label = 2999

Test #64:

score: 26.3205
Acceptable Answer
time: 38ms
memory: 3824kb

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
511489
996515
256745
511745
767745
996771
129873
256873
384873
511873
640873
767873
895873
996899
66937
129937
193937
256937
321937
384937
448937
511937
577937
640937
704937
767937
832937
895937
959937
996963
35969
66969
98969
129969
162969
193969
225969
256969
290969
321969
353969
384969
4179...

input:

1
49888
721985 394999 3
714993
721993
736969
183999 377997 1
183997
775999 207999 1
776997
751999 402993 1
752997
477997 693999 3
476999
477999
480993
480969 800999 3
465985
480985
511937
224999 821999 1
225997
974987 570993 3
969993
974995
981979
949999 286999 1
949997
546997 937997 3
545999
546993...

output:

736969
183997
776997
752997
480993
511937
225997
981979
949997
546993
496993
587993
895997
895873
648997
864997
486997
35969
458993
25997
508997
417969
983997
944997
321985
752997
767937
928985
574997
959937
171993
981996
275993
66969
959997
241993
455997
895993
767745
241993
465997
801985
193993
68...

result:

points 0.43148441690 max label = 999999

Test #65:

score: 26.3205
Acceptable Answer
time: 42ms
memory: 3752kb

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
256744
511745
129872
256873
384873
511873
66936
129937
193937
256937
321937
384937
448937
511937
35968
66969
98969
129969
162969
193969
225969
256969
290969
321969
353969
384969
417969
448969
480969
511969
20984
35985
51985
66985
83985
98985
114985
129985
147985
162985
178985
193985
210985
225...

input:

1
59652
9999 24997 1
9997
248999 417993 1
249997
2999 3999 1
2998
0 1999 1
1999
93999 26993 1
93997
2998 2999 2
0
2999
0 1999 1
1999
1999 0 1
0
0 1999 1
1999
495985 233993 3
488993
495993
510969
303997 473999 3
302999
303999
306993
33968 80999 3
18984
33985
64936
2999 0 1
0
640969 504997 3
625985
64...

output:

9997
249997
2998
1999
93997
2999
1999
0
1999
510969
306993
64936
0
640937
95997
8997
1999
38997
127937
129997
103997
2998
0
395993
8993
193937
24993
30997
16997
1999
298993
0
1999
2999
255985
0
1999
16993
147993
0
128997
64997
21997
666993
409997
2998
0
66993
1999
2999
2998
73997
12997
0
31997
1999
...

result:

points 0.43148441690 max label = 999999

Test #66:

score: 50
Acceptable Answer
time: 52ms
memory: 3888kb

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

input:

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

output:

0
0
1999
1999
1999
1999
1999
1999
0
0
1999
1999
1999
1999
1999
1999
0
0
1999
0
0
1999
0
0
1999
0
1999
1999
0
1999
0
0
0
1999
0
0
0
1999
1999
0
0
1999
0
1999
0
0
0
0
1999
1999
0
1999
1999
1999
0
0
1999
0
1999
0
1999
1999
1999
0
1999
0
1999
1999
1999
0
1999
0
0
1999
0
1999
0
0
1999
1999
0
0
1999
1999
...

result:

points 0.81967213110 max label = 1999

Test #67:

score: 48.4563
Acceptable Answer
time: 42ms
memory: 3752kb

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
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999
3
0
1999
2999

input:

1
74942
1999 0 1
0
1999 0 1
0
0 2999 2
1999
2999
0 2999 2
1999
2999
1999 0 1
0
1999 0 1
0
2999 0 1
0
1999 0 1
0
1999 0 1
0
1999 2999 1
0
1999 0 1
0
1999 2999 1
0
2999 0 1
0
0 1999 2
1999
2999
0 1999 2
1999
2999
2999 0 1
0
0 1999 2
1999
2999
0 2999 2
1999
2999
2999 1999 1
0
0 1999 2
1999
2999
2999 0 ...

output:

0
0
2999
2999
0
0
0
0
0
0
0
0
0
1999
1999
0
1999
2999
0
1999
0
0
0
0
0
2999
2999
0
0
0
0
0
0
0
1999
0
0
2999
0
1999
1999
0
1999
0
2999
0
0
2999
2999
0
0
0
0
1999
2999
0
0
1999
1999
1999
1999
0
0
2999
0
1999
2999
0
0
2999
0
2999
0
2999
0
0
0
0
0
0
0
0
1999
0
0
0
0
0
0
2999
2999
0
0
0
2999
2999
0
0
0
...

result:

points 0.79436608150 max label = 2999

Test #68:

score: 47.3599
Acceptable Answer
time: 42ms
memory: 4064kb

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
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999
4
0
2998
3999
2999

input:

1
66795
0 2998 2
2998
3999
3999 0 1
0
2998 0 2
0
2999
0 2998 2
2998
3999
2998 3999 2
0
2999
3999 2998 1
0
0 3999 2
2998
3999
0 2998 2
2998
3999
0 3999 2
2998
3999
0 2999 2
2998
3999
2999 3999 1
2998
0 2999 2
2998
3999
2999 0 1
2998
2998 3999 2
0
2999
3999 0 1
0
0 2998 2
2998
3999
2999 2998 1
2998
29...

output:

2998
0
0
2998
0
0
3999
2998
3999
2998
2998
2998
2998
0
0
2998
2998
2998
0
2998
0
2998
0
2998
2998
2999
2999
2998
0
0
0
0
2999
2998
2998
2998
2998
2998
3999
0
2999
2998
2999
2998
0
2998
3999
0
0
0
0
2998
2998
2998
3999
2998
0
0
3999
2998
2998
2998
0
0
2998
2998
2998
2998
0
2998
0
0
0
3999
0
2998
0
29...

result:

points 0.77639117130 max label = 3999

Test #69:

score: 26.3205
Acceptable Answer
time: 38ms
memory: 4096kb

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
511489
999512
256745
511745
767745
999768
129873
256873
384873
511873
640873
767873
895873
999896
66937
129937
193937
256937
321937
384937
448937
511937
577937
640937
704937
767937
832937
895937
959937
999960
35969
66969
98969
129969
162969
193969
225969
256969
290969
321969
353969
384969
417...

input:

1
50098
736985 430997 3
729993
736969
736993
545999 839999 1
546997
756999 280999 1
757997
192999 764999 1
193997
171999 741999 1
171997
976997 713999 3
975999
976993
976999
570999 912999 1
570997
806999 361999 1
807997
76999 268999 1
76997
66937 605999 3
35969
66969
129873
576999 369999 1
577997
43...

output:

736969
546997
757997
193997
171997
976993
570997
807997
76997
129873
577997
430997
246997
767745
864985
137997
465985
66993
511993
25997
246997
477997
849985
111997
733997
745997
999997
949997
625993
562993
718997
335997
767745
736985
640985
44993
210993
290985
438997
290969
147985
651993
275997
640...

result:

points 0.43148441690 max label = 999999

Test #70:

score: 47.3599
Acceptable Answer
time: 42ms
memory: 3748kb

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
1999
3999
2999
4
0
3999
3997
3998
4
0
2999
3997
3999
4
0
3999
3998
3997
4
0
2999
3997
3999
4
0
1999
3999
3998
4
0
3999
3998
3997
4
0
3999
2999
3997
4
0
3999
2998
2999
4
0
2999
3997
3999

input:

1
66444
3998 3997 2
3997
3999
3997 3999 2
0
3998
3999 1999 1
3998
0 3999 1
3997
3997 0 3
0
2999
3999
3998 3999 2
3997
3999
3999 3997 1
3997
3999 0 1
3998
3999 3998 1
3998
3997 2999 3
0
2999
3999
0 3998 1
3997
0 3999 2
2998
3999
2999 1999 1
0
3999 3998 1
3998
2999 1999 1
0
2998 2999 2
0
2999
3999 299...

output:

3997
3998
3998
3997
0
3999
3997
3998
3998
2999
3997
3999
0
3998
0
2999
0
3997
2999
3997
1999
3997
3997
2999
3997
3997
3997
3998
0
3997
3997
0
3997
0
3999
0
2999
2999
3998
3997
3999
3997
3998
0
3997
0
3997
3997
3997
0
3997
3997
3998
2998
3998
3998
3997
3997
0
3997
3997
3998
2999
3998
3997
3997
3997
3...

result:

points 0.77639117130 max label = 3999

Test #71:

score: 26.3205
Acceptable Answer
time: 30ms
memory: 3784kb

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
999424
999553
328852
999542
999462
999441
328985
328679
999455
999584
328774
328914
999464
999753
328751
999655
999433
999521
999543
328690
999896
328988
999809
328871
999960
999374
999880
999831
328818
328947
997995
999491
999548
999484
999418
999415
999427
999961
999759
999828
999836
999835...

input:

1
50431
999830 328899 2
999829
999831
371979 486987 2
371978
371980
950999 575999 1
999037
328800 999970 2
328799
328801
651999 959970 1
987113
999885 999853 2
999884
999886
815989 755983 2
815988
815990
426575 999918 2
426574
426576
623992 193987 2
623991
623993
987989 250986 2
987988
987990
405642...

output:

999829
371978
999037
328799
987113
999884
815988
426574
623991
987988
405641
999985
999812
999582
987113
987113
598995
998984
999958
526836
192951
987113
290994
987113
999817
385947
306990
769898
452964
999669
855994
999479
487989
999900
999933
999556
1999
452975
999511
999774
645987
620990
987076
4...

result:

points 0.43148441690 max label = 999999

Test #72:

score: 26.3205
Acceptable Answer
time: 40ms
memory: 4080kb

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
999289
195852
647844
647716
647968
195845
195826
647795
647920
999723
195992
647811
999985
647994
999861
195955
999259
647783
999838
999315
195928
647727
999321
999306
999669
999747
999311
647859
647957
999857
999808
999864
647717
999900
647932
999324
999893
195969
647942
647798
647720
647800...

input:

1
51725
999931 703821 2
999930
999932
999403 72950 2
999402
999404
720989 720962 2
720988
720990
856999 720955 1
856998
15999 296999 1
999001
703690 703422 2
703689
703691
306997 881999 2
306996
306998
508872 508890 2
508871
508873
613983 299979 2
613982
613984
774979 27998 2
774978
774980
12999 792...

output:

999930
999402
720988
856998
999001
703689
306996
508873
613982
774978
999001
999891
703881
999001
999745
845950
703689
999998
703687
719972
559995
978998
626378
999001
999001
723995
626937
999591
999001
626673
55992
565996
774988
909985
361997
647852
720493
720818
613973
998996
999577
703863
998993
...

result:

points 0.43148441690 max label = 999999

Test #73:

score: 26.3205
Acceptable Answer
time: 38ms
memory: 3800kb

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
173990
656994
378987
378993
317974
243970
349996
509992
509981
317966
243984
349985
378999
154987
874993
959977
115996
754973
115976
688973
959960
688976
41992
509982
554996
554989
986026
378988
418987
154988
279964
727999
554971
317978
874997
349990
418989
450970
349993
782974
688975
349991
...

input:

1
49651
912994 656973 2
912993
912995
874999 450980 1
874998
279988 450970 2
279987
279989
450999 688988 1
450998
817999 317979 1
817998
656998 586996 2
656997
656999
450990 959959 2
450989
450991
279978 986975 2
279977
279979
115986 317999 2
115985
115987
488990 80996 2
488989
488991
418966 378985 ...

output:

912993
874998
279987
450998
817998
656997
450989
279977
115985
488989
418965
41996
554979
317968
154996
656989
986994
851975
727980
986031
912974
688984
154975
509984
986031
959957
912989
279984
349991
488995
201992
349975
173990
80983
317980
418967
851974
959976
688969
656973
817966
986031
418986
4...

result:

points 0.43148441690 max label = 999999

Test #74:

score: 35.2496
Acceptable Answer
time: 14ms
memory: 3884kb

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
76999
15999
36999
2999
92999
48999
79999
43999
68999
8999
14999
62999
4999
16999
45999
90999
11999
83999
67999
72999
41999
42999
22999
20999
34999
28999
77999
33999
38999
93999
63999
3999
26999
27999
50999
82999
53999
56999
71999
25999
86999
9999
89999
66999
37999
21999
95999
75999
5999
58999
2...

input:

1
4308
4999 54999 1
95905
48999 90999 1
95905
95905 49999 95
0
2999
3999
4999
5999
6999
7999
8999
9999
10999
11999
12999
13999
14999
15999
16999
17999
18999
19999
20999
21999
22999
23999
24999
25999
26999
27999
28999
29999
30999
31999
32999
33999
34999
35999
36999
37999
38999
39999
40999
41999
42999...

output:

95905
95905
49999
0
95905
38999
95905
95905
0
95905
95905
95905
95905
95905
95905
29999
0
95905
0
95905
95905
0
95905
95905
95905
95905
0
95905
0
95905
95905
95905
0
95905
95905
95905
95905
95905
95905
95905
90999
95905
95905
0
50999
95905
95905
95905
95905
95905
83999
0
38999
83999
53999
95905
6999...

result:

points 0.57786301850 max label = 95999

Test #75:

score: 28.6614
Acceptable Answer
time: 16ms
memory: 4100kb

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
490999
250999
54999
62999
312999
321999
369999
63999
57999
237999
387999
251999
499999
422999
366999
381999
41999
466999
272999
98999
484999
83999
142999
203999
75999
476999
169999
124999
509999
249999
536999
161999
329999
435999
235999
385999
212999
48999
182999
361999
78999
285999
183999
170...

input:

1
6214
485999 471999 1
0
435999 218999 1
540460
59999 504999 1
540460
309999 333999 1
540460
486999 302999 1
0
311999 483999 1
0
45999 65999 1
0
354999 93999 1
0
160999 30999 1
0
421999 140999 1
0
112999 212999 1
0
173999 401999 1
540460
384999 353999 1
0
360999 254999 1
0
402999 238999 1
0
439999 2...

output:

0
540460
540460
540460
0
0
0
0
0
0
0
540460
0
0
0
0
540460
0
540460
540460
0
540460
0
540460
0
540460
0
354999
0
0
0
0
0
540460
0
0
540460
540460
540460
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
540460
0
0
540460
0
0
0
540460
540460
154999
0
0
540460
0
540460
540460
0
0
0
540460
540460
540460
0
0
0
0
0
54...

result:

points 0.46985820520 max label = 540999

Test #76:

score: 26.3205
Acceptable Answer
time: 16ms
memory: 3768kb

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
816999
157999
390999
66999
443999
683999
957999
897999
98999
439999
115999
544999
94999
958999
232999
359999
813999
644999
50999
364999
492999
697999
770999
632999
468999
935999
206999
409999
28999
876999
481999
125999
319999
171999
670999
663999
252999
945999
906999
45999
267999
474999
14699...

input:

1
10180
18999 801999 1
0
4999 425999 1
0
618999 21999 1
0
204999 287999 1
999001
471999 862999 1
0
532999 783999 1
0
134999 909999 1
999001
213999 609999 1
0
968999 871999 1
0
552999 573999 1
0
979999 748999 1
999001
860999 356999 1
999001
669999 690999 1
999001
783999 397999 1
0
151999 323999 1
999...

output:

0
0
0
999001
0
0
999001
0
0
0
999001
999001
999001
0
999001
0
0
999001
0
0
0
0
0
999001
0
999001
0
999001
0
999001
0
999001
0
999001
0
999001
999001
0
999001
999001
999001
999001
999001
0
999001
999001
999001
0
0
0
999001
0
999001
999001
0
0
0
999001
999001
0
0
0
999001
999001
999001
0
0
0
0
0
99900...

result:

points 0.43148441690 max label = 999999

Test #77:

score: 45.2272
Acceptable Answer
time: 0ms
memory: 3888kb

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
2999
6999
3999
5999
4999
6994
7
0
5999
6999
6994
4999
2999
3999
7
0
3998
4999
6999
5999
6994
3999
7
0
5999
3998
3999
4999
6994
6999
7
0
2999
4999
6999
5995
5999
3999
7
0
2999
3999
6999
4999
3997
5999
7
0
6994
6999
5999
3999
5996
4999
7
0
6994
4999
5999
3999
4997
6999
7
0
4998
5999
6995
6999
4999...

input:

1
420
3997 6999 3
0
2999
3999
6999 3998 1
6994
3998 5999 2
3999
6994
4999 5999 1
0
5999 0 1
6994
6999 5999 1
6994
6999 0 1
6994
3999 0 1
3997
4999 5999 1
6994
5995 5999 5
0
2999
3999
4999
5999
5999 4999 1
6994
4999 6994 1
6994
6994 4999 5
0
3998
4999
5999
6999
3999 4999 1
3998
5999 6999 1
6994
2999 ...

output:

0
6994
6994
0
6994
6994
6994
3997
6994
5999
6994
6994
4999
3998
6994
6994
6994
5995
6994
6994
6994
6995
6994
3998
6994
5995
6994
0
6994
0
4997
6994
6994
5996
5995
5999
6994
5996
0
3998
6994
5999
6995
3998
6994
6994
3997
6994
6994
5996
6995
6995
0
6994
6994
5995
5999
6994
6994
5995
6994
5995
6994
0
5...

result:

points 0.74142877220 max label = 6999

Test #78:

score: 45.2272
Acceptable Answer
time: 0ms
memory: 3756kb

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
5999
4998
4997
4999
6999
6994
7
0
4998
4999
6999
4997
5999
6994
7
0
5996
6999
4999
4998
6994
5999
7
0
5999
4999
3999
6999
4996
3998
7
0
3999
4997
5999
5995
4999
6999
7
0
6999
6994
5999
4998
5996
4999
7
0
6994
6999
4999
4998
6995
6998
7
0
3999
6999
3997
5998
3998
5999
7
0
5999
6994
6995
6999
5998...

input:

1
420
6994 0 3
0
5996
6999
6999 0 1
0
6994 5999 3
0
5996
6999
4998 5999 2
4999
5996
5999 0 1
5996
4999 0 1
4998
6999 3998 1
0
4999 5996 1
4998
6999 4998 1
6994
5995 4999 3
0
4997
5999
4999 3998 1
4996
3998 4996 2
3999
4996
4996 3998 3
0
3998
4999
5999 6999 1
5998
5998 6999 2
0
5999
4997 4999 2
4998
...

output:

0
0
5996
5996
5996
4998
0
4998
6994
4997
4996
4996
3998
5998
0
4998
4997
4997
6994
3997
6994
6995
6994
4998
6994
5995
6994
0
5996
0
3998
0
4997
6995
4999
5999
5998
0
6995
0
6994
6999
6995
5998
5999
4998
4998
6994
0
6994
6995
6995
6994
5996
4999
6996
5998
6994
6994
5995
4996
4997
5996
5996
6994
5998
...

result:

points 0.74142877220 max label = 6999

Test #79:

score: 45.2272
Acceptable Answer
time: 0ms
memory: 3804kb

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
6999
5996
5998
5999
6994
5997
7
0
5995
6999
5997
4999
5999
5996
7
0
4997
4999
6998
4996
6999
4998
6
0
2999
3999
1999
4999
5999
6
0
5995
4999
3999
2999
5999
6
0
2999
4999
3999
5999
4996
6
0
4996
4999
3999
5999
2999
6
0
5995
3999
5999
4999
3998
6
0
4997
3999
5995
5999
4999
6
0
2999
4999
4998
2998
...

input:

1
336
4996 4999 4
0
2999
3999
4999
5995 0 5
0
2999
3999
4999
5999
0 6998 2
4996
6998
0 4999 2
4996
5999
6998 6999 2
0
6999
3999 4997 1
4997
2998 4999 2
0
2999
5995 3998 4
0
3998
4999
5999
5997 5998 2
5996
5998
3999 2999 1
5995
4999 0 1
0
2999 3999 1
0
0 2999 5
1999
2999
3999
4999
5999
4997 4996 2
49...

output:

4999
0
6998
4996
6999
4997
0
3998
5998
5995
0
0
2999
4996
5999
5997
5997
4996
5997
0
4997
4996
6998
4997
5995
0
5996
4996
4996
5995
4998
5995
5997
3998
5995
0
5995
5995
5995
1999
5997
5997
4997
4996
4998
0
5995
5996
0
5995
5997
5997
0
4996
4998
4999
4997
5996
6998
2999
0
5999
4998
4996
4996
0
5995
5...

result:

points 0.74142877220 max label = 6999

Test #80:

score: 45.8146
Acceptable Answer
time: 0ms
memory: 4096kb

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
5999
4999
2999
4998
2998
6
0
4996
5999
3999
4997
4999
6
0
4999
4996
4997
3999
5999
6
0
4996
4997
4999
4998
5999
5
0
1999
4999
2999
3999
5
0
4999
3999
4996
2999
5
0
3998
4996
3999
4999
5
0
4996
3999
4997
4999
5
0
4999
4996
4997
3999
5
0
3997
3999
4999
3998

input:

1
240
0 4999 1
4996
4999 0 1
4996
4997 0 2
4996
4998
3998 3997 2
3997
3999
0 4996 2
4996
5999
4999 3999 1
0
4996 3999 3
0
3998
4999
3999 2999 1
0
4999 5999 1
4998
4999 4996 1
4996
0 3999 1
4996
4999 2999 1
0
1999 4999 1
0
4996 4998 2
0
4997
5999 4999 1
0
4998 2998 2
0
4999
4997 4999 3
3999
4996
4999...

output:

4996
4996
4996
3997
4996
0
3998
0
4998
4996
4996
0
0
4997
0
0
4999
4997
5999
4998
4998
0
0
0
4996
4997
4998
4997
4998
4996
4996
4996
4996
3997
3998
4997
4996
0
2999
0
0
4996
0
4999
0
4996
4996
0
0
4997
4997
4996
0
4996
4997
2998
0
4997
0
0
4996
4997
0
3999
0
4997
4996
3997
0
4996
4996
4998
4997
4996...

result:

points 0.75105909040 max label = 5999

Test #81:

score: 47.3599
Acceptable Answer
time: 0ms
memory: 3892kb

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
3999
2999
3997
4
0
3999
2999
3997
4
0
3999
2998
2999
3
0
2999
2998
3
0
1999
2999
2
0
1999

input:

1
50
3999 3997 1
3997
1999 2999 1
0
3999 0 1
0
1999 0 1
0
3999 2999 1
3997
0 2999 2
1999
2999
2999 1999 1
0
2999 0 1
3997
2998 3999 2
0
2999
0 1999 2
1999
2999
3997 3999 3
0
2999
3999
0 3997 1
3997
0 3997 1
3997
2999 3997 1
3997
2999 3997 1
3997
3999 0 1
3997
3999 2999 1
0
2998 0 2
0
2999
0 1999 1
1...

output:

3997
0
0
0
3997
2999
0
3997
0
1999
3999
3997
3997
3997
3997
3997
0
0
1999
0
3997
3999
0
0
2998
0
2998
3997
0
3997
2999
2999
2998
2998
3997
3997
3997
3997
3997
3997
3997
2998
2998
2999
0
2998
2998
2998
3999
2999

result:

points 0.77639117130 max label = 3999

Test #82:

score: 44.7183
Acceptable Answer
time: 38ms
memory: 3800kb

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
4998
4999
7999
7997
4997
4996
7998
8
0
7993
7994
7995
7996
7997
7998
7999
8
0
5997
5999
5996
7998
5998
5995
7999
8
0
4996
7997
3998
4999
6999
7999
3999
8
0
2999
6999
5999
7999
7993
3999
4999
8
0
6999
5999
2999
3999
7999
1999
4999
8
0
4998
4999
7998
7999
4997
7997
4996
8
0
6994
7999
5999
4998
299...

input:

1
57266
4999 3998 1
4996
7995 7997 2
7994
7996
4999 2999 1
4998
3999 5999 1
7993
6999 0 1
7997
4997 4998 2
4996
4998
0 4999 2
4996
7997
7999 4999 1
7997
0 7995 1
7993
5997 0 2
5996
5998
7998 5999 2
0
7999
7997 3998 3
0
6999
7999
7999 4999 1
7998
7997 3999 3
0
6999
7999
5996 0 2
5995
5997
5998 5995 2...

output:

4996
7996
4998
7993
7997
4998
4996
7997
7993
5996
0
0
7998
0
5995
5997
7993
7997
7997
5997
0
5995
7993
4998
6994
7997
7998
0
0
0
7993
3999
0
0
0
0
6994
0
0
0
6994
7998
4998
4997
5997
2999
0
0
5997
6994
4998
5998
0
4998
7997
0
0
7994
5996
5998
7996
4998
6994
7998
7993
4998
7998
0
3999
4996
7997
6994
...

result:

points 0.7330867840 max label = 7999

Test #83:

score: 44.7183
Acceptable Answer
time: 22ms
memory: 3892kb

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
5999
4999
2999
7993
6999
4998
7999
8
0
2999
6998
7993
6999
3999
7999
4999
8
0
4999
7994
4998
1999
5999
7999
6999
8
0
6995
6999
6996
6998
7999
6994
6997
8
0
6999
6996
2999
2998
6998
6997
7999
8
0
7997
4997
4999
4996
4998
7998
7999
8
0
1999
7998
3999
7999
5996
5998
5999
8
0
3997
7996
7998
7997
399...

input:

1
57297
2999 3999 1
7993
6999 7993 1
7993
7997 3997 2
7996
7998
7998 0 2
7997
7999
0 5998 3
1999
5996
7998
7998 7997 2
7997
7999
2999 0 1
7993
7997 3997 2
7996
7998
6997 2998 2
6996
6998
4997 7997 2
4996
4998
5999 7999 1
7993
3999 5996 1
5996
3997 7999 2
0
3998
0 7999 3
2998
6996
7999
7994 7993 4
39...

output:

7993
7993
7996
7997
5996
7997
7993
7996
6996
4996
7993
5996
0
7999
7993
7993
7997
6997
7993
0
6998
5996
7994
7993
7996
5996
6997
7993
7997
0
7993
7993
2999
7993
7993
3997
0
6998
6996
1999
0
6998
7993
0
7994
3998
6994
7994
7993
5996
4996
7998
7994
7993
6995
7993
7994
7993
6997
7993
7993
7993
4998
499...

result:

points 0.7330867840 max label = 7999

Test #84:

score: 44.7183
Acceptable Answer
time: 38ms
memory: 3840kb

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
7999
4999
7993
5999
6999
3999
2999
8
0
7998
7997
4996
7999
4998
2999
4999
8
0
5998
3999
5999
7999
6999
6995
6994
8
0
7999
4996
4998
7997
4997
7998
4999
8
0
4999
5995
5996
7998
5999
4998
7999
8
0
7993
4998
7994
6999
5999
4999
7999
8
0
7997
7998
7994
7996
7999
7993
7995
8
0
7993
3999
2999
7999
699...

input:

1
57195
3999 7999 1
7993
0 7997 1
7993
6995 3999 4
3999
5998
6994
6999
0 7997 1
7993
7999 3999 1
7993
2999 0 1
7993
0 6999 1
7993
4999 5996 1
4998
5998 6995 2
5999
6995
0 7993 1
7993
7999 3999 1
7993
5999 7999 1
7993
5999 7998 1
5996
2999 5999 1
7993
3999 2999 1
7993
6999 6995 1
6996
7998 0 2
7997
7...

output:

7993
7993
3999
7993
7993
7993
7993
4998
6995
7993
7993
7993
5996
7993
7993
6996
7997
4998
7993
4996
4999
7993
7994
7994
4998
4996
7998
5998
5996
4998
5996
7994
4998
7995
7994
6995
4997
6995
4997
4996
5996
7994
5998
4998
7996
3999
3998
0
7997
3998
4998
7993
7994
7994
4998
6994
7997
7993
7996
7997
799...

result:

points 0.7330867840 max label = 7999

Test #85:

score: 44.7183
Acceptable Answer
time: 38ms
memory: 3804kb

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
7999
4999
7993
5999
6999
3999
2999
8
0
7998
7997
4996
7999
4998
2999
4999
8
0
5998
3999
5999
7999
6999
6995
6994
8
0
7999
4996
4998
7997
4997
7998
4999
8
0
4999
5995
5996
7998
5999
4998
7999
8
0
7993
4998
7994
6999
5999
4999
7999
8
0
7997
7998
7994
7996
7999
7993
7995
8
0
7993
3999
2999
7999
699...

input:

1
57195
3999 7999 1
7993
0 7997 1
7993
6995 3999 4
3999
5998
6994
6999
0 7997 1
7993
7999 3999 1
7993
2999 0 1
7993
0 6999 1
7993
4999 5996 1
4998
5998 6995 2
5999
6995
0 7993 1
7993
7999 3999 1
7993
5999 7999 1
7993
5999 7998 1
5996
2999 5999 1
7993
3999 2999 1
7993
6999 6995 1
6996
7998 0 2
7997
7...

output:

7993
7993
3999
7993
7993
7993
7993
4998
6995
7993
7993
7993
5996
7993
7993
6996
7997
4998
7993
4996
4999
7993
7994
7994
4998
4996
7998
5998
5996
4998
5996
7994
4998
7995
7994
6995
4997
6995
4997
4996
5996
7994
5998
4998
7996
3999
3998
0
7997
3998
4998
7993
7994
7994
4998
6994
7997
7993
7996
7997
799...

result:

points 0.7330867840 max label = 7999

Test #86:

score: 44.7183
Acceptable Answer
time: 38ms
memory: 4104kb

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
7999
4999
7993
5999
6999
3999
2999
8
0
7998
7997
4996
7999
4998
2999
4999
8
0
5998
3999
5999
7999
6999
6995
6994
8
0
7999
4996
4998
7997
4997
7998
4999
8
0
4999
5995
5996
7998
5999
4998
7999
8
0
7993
4998
7994
6999
5999
4999
7999
8
0
7997
7998
7994
7996
7999
7993
7995
8
0
7993
3999
2999
7999
699...

input:

1
57195
3999 7999 1
7993
0 7997 1
7993
6995 3999 4
3999
5998
6994
6999
0 7997 1
7993
7999 3999 1
7993
2999 0 1
7993
0 6999 1
7993
4999 5996 1
4998
5998 6995 2
5999
6995
0 7993 1
7993
7999 3999 1
7993
5999 7999 1
7993
5999 7998 1
5996
2999 5999 1
7993
3999 2999 1
7993
6999 6995 1
6996
7998 0 2
7997
7...

output:

7993
7993
3999
7993
7993
7993
7993
4998
6995
7993
7993
7993
5996
7993
7993
6996
7997
4998
7993
4996
4999
7993
7994
7994
4998
4996
7998
5998
5996
4998
5996
7994
4998
7995
7994
6995
4997
6995
4997
4996
5996
7994
5998
4998
7996
3999
3998
0
7997
3998
4998
7993
7994
7994
4998
6994
7997
7993
7996
7997
799...

result:

points 0.7330867840 max label = 7999

Test #87:

score: 26.3358
Acceptable Answer
time: 26ms
memory: 3804kb

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
630896
519646
630958
519625
630912
630462
519850
519865
977711
519831
977807
519713
977873
519607
519818
519975
977677
630969
630398
519860
519832
977913
519978
977679
630991
519651
519916
519609
977976
630428
519810
977932
519851
519944
630442
977816
630415
977877
519839
630927
977778
977874
...

input:

1
35090
519783 519681 2
519782
519784
972824 624895 2
972823
972825
963996 963732 2
963995
963997
988278 988162 2
988277
988279
182878 555848 2
182877
182879
833796 833736 2
833795
833797
156884 631653 2
156883
156885
674970 994448 2
674969
674971
502895 385891 2
502894
502896
833743 950887 2
833742...

output:

519782
972823
963995
988277
182877
833795
156883
674969
502894
833742
977953
555796
950498
957245
519821
679322
679924
519830
994258
502635
957972
502521
977833
963959
950142
977992
414951
557899
950550
994893
557838
385943
425990
950909
977760
385884
557943
624423
624448
750860
679916
182848
994365...

result:

points 0.43173477330 max label = 995999

Test #88:

score: 26.3205
Acceptable Answer
time: 30ms
memory: 3832kb

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
843999
877999
543999
556999
864999
827999
406999
41999
702999
397998
165999
126956
614999
609999
474999
896999
899999
342999
819999
335999
185999
800999
147999
832999
672999
65999
352999
480999
249999
717999
901999
419987
539999
240999
997999
498999
655999
796998
273999
96999
538999
915999
37...

input:

1
47617
789998 686974 2
789997
789999
825993 268999 3
822997
825997
832985
715999 942998 1
715996
48997 275985 3
47999
48999
51993
16999 932961 1
934080
412999 423999 1
412998
999610 566717 2
999609
999611
543998 351999 2
543997
543999
256837 999553 2
256836
256838
640989 792997 6
631999
632999
6349...

output:

789997
832985
715996
51993
934080
412998
999609
543997
256836
645983
545955
566559
999001
657993
76993
999001
256751
189998
999001
818989
999851
999450
999001
989014
999569
953997
999386
190997
256748
697850
566870
448969
999729
792925
824996
989997
999637
999122
566793
256994
999993
999261
999001
3...

result:

points 0.43148441690 max label = 999999

Test #89:

score: 26.3244
Acceptable Answer
time: 38ms
memory: 4068kb

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
990976
830707
830743
830726
830669
830941
990959
830264
830240
830957
830754
830406
830700
830910
830266
830256
830880
830444
830305
830633
830755
990900
830328
830308
990956
830949
830512
830216
830931
830342
830385
990898
830911
830242
830618
830530
990929
990856
990908
830445
830438
990971
...

input:

1
49922
825998 531702 2
825997
825999
705999 64965 1
712980
680990 289765 2
680989
680991
989743 660701 2
989742
989744
680810 991940 2
680809
680811
696964 825999 2
696963
696965
992299 992344 2
992298
992300
407996 941999 3
405999
407993
407998
660916 989861 2
660915
660917
992987 180913 2
992986
...

output:

825997
712980
680989
989742
680809
696963
992300
407993
660915
992986
736991
136974
992247
683998
64965
830590
660848
990851
680901
992226
989752
680924
531877
991885
830410
141995
660975
180825
819997
357990
830860
289996
991783
294938
257921
991516
989822
527971
992311
569998
294938
660925
644998
...

result:

points 0.4315469120 max label = 998999

Test #90:

score: 26.3205
Acceptable Answer
time: 38ms
memory: 3764kb

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
531993
94999
248999
253998
652999
979982
803992
650995
794998
576965
130999
878986
367998
275991
951998
661992
318971
558999
88997
734999
539999
831995
939997
640994
334999
688998
488999
361999
393620
108999
734991
497998
606999
954990
738999
649999
318970
992999
893996
287999
206999
122997
71...

input:

1
50698
429996 446995 3
427999
429994
429998
25999 789999 1
26993
959999 67999 1
999001
922744 80999 3
674993
922743
922752
220997 62998 2
220995
220998
767999 134999 1
767998
620999 613999 1
620998
563999 359999 1
946179
283972 455999 3
282974
283999
287967
365674 491998 2
365672
365675
918999 7189...

output:

429994
26993
999001
922743
220995
767998
620998
946179
287967
365672
999001
711991
620998
172980
994010
758990
692997
716996
779988
31992
98993
882165
978995
975290
238972
932957
893966
435992
168992
212951
87998
423994
270998
492890
513991
830958
882165
831995
942672
245999
62998
906998
628998
8821...

result:

points 0.43148441690 max label = 999999

Test #91:

score: 26.3205
Acceptable Answer
time: 58ms
memory: 3816kb

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
531993
94999
248999
253998
652999
979982
803992
650995
794998
576965
130999
878986
367998
275991
951998
661992
318971
558999
88997
734999
539999
831995
939997
640994
334999
688998
488999
361999
393620
108999
734991
497998
606999
954990
738999
649999
318970
992999
893996
287999
206999
122997
71...

input:

1
50698
429996 446995 3
427999
429994
429998
25999 789999 1
26993
959999 67999 1
999001
922744 80999 3
674993
922743
922752
220997 62998 2
220995
220998
767999 134999 1
767998
620999 613999 1
620998
563999 359999 1
946179
283972 455999 3
282974
283999
287967
365674 491998 2
365672
365675
918999 7189...

output:

429994
26993
999001
922743
220995
767998
620998
946179
287967
365672
999001
711991
620998
172980
994010
758990
692997
716996
779988
31992
98993
882165
978995
975290
238972
932957
893966
435992
168992
212951
87998
423994
270998
492890
513991
830958
882165
831995
942672
245999
62998
906998
628998
8821...

result:

points 0.43148441690 max label = 999999

Test #92:

score: 26.3244
Acceptable Answer
time: 22ms
memory: 3764kb

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
5999
18999
764999
989999
705996
425999
720999
728994
115990
570986
665998
878999
739999
394999
156999
624999
866999
785991
951999
583995
685999
566999
453999
952999
343999
335999
185999
177999
669999
286998
62997
362997
63999
756999
388999
988999
73999
713999
26999
150999
504999
589998
296999
...

input:

1
49569
777999 644999 1
777998
606998 610703 2
606999
607994
149999 321990 1
149998
53998 993008 2
53997
53999
637643 245999 3
636645
637642
637999
972999 354999 1
985950
910996 270996 4
908999
909999
910963
910999
871999 369997 1
871998
595939 25993 3
594941
595999
596937
100999 26997 1
100997
9289...

output:

777998
607994
149998
53997
637642
985950
910963
871998
596937
100997
928994
391998
497998
447903
141869
226983
909983
951099
937998
466995
908789
890994
897994
337994
636992
375976
989011
697510
27985
453931
869978
557859
681965
241988
385981
276993
201944
780263
181998
42998
713441
404996
703984
34...

result:

points 0.4315469120 max label = 998999

Test #93:

score: 26.3244
Acceptable Answer
time: 30ms
memory: 3812kb

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
5999
18999
764999
989999
705996
425999
720999
728994
115990
570986
665998
878999
739999
394999
156999
624999
866999
785991
951999
583995
685999
566999
453999
952999
343999
335999
185999
177999
669999
286998
62997
362997
63999
756999
388999
988999
73999
713999
26999
150999
504999
589998
296999
...

input:

1
49569
777999 644999 1
777998
606998 610703 2
606999
607994
149999 321990 1
149998
53998 993008 2
53997
53999
637643 245999 3
636645
637642
637999
972999 354999 1
985950
910996 270996 4
908999
909999
910963
910999
871999 369997 1
871998
595939 25993 3
594941
595999
596937
100999 26997 1
100997
9289...

output:

777998
607994
149998
53997
637642
985950
910963
871998
596937
100997
928994
391998
497998
447903
141869
226983
909983
951099
937998
466995
908789
890994
897994
337994
636992
375976
989011
697510
27985
453931
869978
557859
681965
241988
385981
276993
201944
780263
181998
42998
713441
404996
703984
34...

result:

points 0.4315469120 max label = 998999

Test #94:

score: 26.3205
Acceptable Answer
time: 40ms
memory: 3788kb

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
244996
453999
134999
765997
727999
258999
716999
851997
837999
758986
960993
258996
679976
322998
981999
760999
842993
581998
561982
273999
408998
819999
679998
643986
783999
267999
642999
539999
484999
610999
537910
891999
687999
884999
956998
104999
217999
201999
306999
208999
51998
814998
...

input:

1
50684
420999 968999 1
420981
163999 879999 1
163998
17985 786999 2
17986
948053
602999 75999 1
604994
694999 374944 1
976716
542999 61999 1
548992
777999 413793 1
780995
934996 898999 3
932999
934998
943986
218998 938999 2
218999
271933
687999 551999 1
706942
438998 405990 2
438999
459975
71984 26...

output:

420981
163998
948053
604994
976716
548992
780995
943986
271933
706942
459975
263770
471672
898272
876974
999002
999002
145925
282997
498944
878297
473992
936093
643998
610994
690967
418992
145986
884997
777975
991662
35991
574996
469814
382888
640997
999002
309976
368996
462911
952170
96923
929989
3...

result:

points 0.43148441690 max label = 999999

Test #95:

score: 27.5145
Acceptable Answer
time: 14ms
memory: 3876kb

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
524999
215999
693999
95999
41999
420999
364999
455999
603999
467999
331999
181999
77999
94999
703999
208999
137999
525999
376999
618999
123999
33999
558999
699999
623999
579999
112999
47999
321999
374999
211999
585999
188999
241999
293999
674999
689999
31999
276999
690999
143999
232999
396999
...

input:

1
5230
211999 201999 1
0
250999 341999 1
0
270999 538999 1
730270
259999 603999 1
0
49999 609999 1
730270
559999 235999 1
0
673999 604999 1
730270
247999 9999 1
0
579999 616999 1
0
298999 688999 1
0
577999 655999 1
730270
95999 406999 1
0
577999 380999 1
730270
622999 430999 1
0
327999 535999 1
7302...

output:

0
0
730270
0
730270
0
730270
0
0
0
730270
0
730270
0
730270
0
730270
0
0
730270
730270
730270
730270
0
0
0
730270
730270
0
0
65999
0
0
0
0
730270
0
730270
0
730270
0
0
719999
0
0
0
730270
730270
0
0
730270
0
0
730270
0
0
0
0
730270
0
0
0
730270
0
0
730270
730270
730270
0
0
0
730270
730270
0
0
730270...

result:

points 0.45105694750 max label = 730999

Test #96:

score: 26.3205
Acceptable Answer
time: 16ms
memory: 3812kb

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
794999
263999
169999
278999
454999
588999
888999
430999
337999
998999
492999
612999
723999
11999
651999
519999
29999
668999
25999
449999
720999
284999
906999
61999
940999
91999
313999
174999
26999
587999
31999
965999
191999
885999
529999
60999
913999
150999
384999
484999
796999
555999
956999
...

input:

1
10180
700999 389999 1
0
0 278999 1
999001
717999 178999 1
0
720999 136999 1
999001
125999 243999 1
999001
633999 120999 1
0
641999 259999 1
999001
591999 343999 1
0
645999 291999 1
0
760999 825999 1
0
566999 30999 1
999001
424999 253999 1
0
735999 77999 1
0
926999 318999 1
0
957999 664999 1
0
2709...

output:

0
999001
0
999001
999001
0
999001
0
0
0
999001
0
0
0
0
0
999001
999001
999001
0
0
999001
0
999001
0
999001
0
999001
999001
999001
0
999001
999001
999001
999001
999001
0
0
999001
0
0
564999
999001
0
0
0
0
999001
0
0
999001
999001
999001
0
0
0
999001
0
999001
0
999001
999001
0
0
999001
999001
999001
9...

result:

points 0.43148441690 max label = 999999

Test #97:

score: 26.756
Acceptable Answer
time: 20ms
memory: 3796kb

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
795999
376999
786999
550999
277989
503999
463999
804999
214999
401999
542999
158999
186999
40999
615999
287999
630999
464999
175999
276999
565999
666999
743989
247999
397999
455999
584999
226999
832989
648999
363999
874999
199989
194999
169999
566999
147999
846999
195999
742999
280999
164999
6...

input:

1
13208
882992 366999 8
876999
877999
878999
879999
880999
881999
882999
890116
561989 53999 11
552999
553999
554999
555999
556999
557999
558999
559999
560999
561999
605889
883990 312999 10
875999
876999
877999
878999
879999
880999
881999
882999
883118
883999
92990 225999 10
84999
85999
86999
87999
...

output:

890116
605889
883118
102909
886118
95909
225989
413659
198943
114915
525957
839979
133957
728943
584979
697367
812915
557659
785943
90957
811909
222979
594957
811909
438957
174979
887115
114915
812193
811909
887219
806746
793989
621979
793989
447909
685979
461909
882119
436979
579979
174979
324979
6...

result:

points 0.43862335410 max label = 891999

Test #98:

score: 26.3205
Acceptable Answer
time: 22ms
memory: 3808kb

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
92999
145999
344999
405999
867999
973999
104943
337999
818992
323999
44999
312999
67999
189999
450999
972999
22992
875943
443999
580999
109999
905999
334999
476999
859992
517992
272999
168999
313992
94999
64999
503999
161999
203999
141999
213999
557999
955999
93999
533999
61999
310999
656999
...

input:

1
16365
421991 938999 9
414999
415999
416999
417999
418999
419999
420999
421999
430927
231992 800999 8
225999
226999
227999
228999
229999
230999
231999
247943
932943 121999 8
884992
892992
900992
908992
916992
924992
932992
989057
982073 625999 9
129927
202927
275927
324951
397927
836561
909927
9829...

output:

430927
247943
989057
836561
545993
486943
893844
544927
19985
586960
942943
162993
474993
613969
543957
275927
512985
359987
998011
412987
924969
301960
419943
471927
49969
988031
190943
856932
318985
184985
543943
751965
919993
816993
247943
761943
202927
977879
457957
788889
132972
682993
284927
8...

result:

points 0.43148441690 max label = 999999

Test #99:

score: 27.6148
Acceptable Answer
time: 22ms
memory: 3804kb

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
702990
629490
708960
620526
638448
587999
566999
625504
525916
614556
529904
613560
211999
586999
561999
335999
566760
549830
615552
523928
679999
539858
594640
75999
664999
403999
599626
16999
549999
607999
657999
596636
578702
705972
601999
510990
705970
581688
579698
630482
651999
616999
53...

input:

1
33400
663632 608880 3
297999
663634
664630
365800 690796 3
167999
365798
365802
611572 3999 3
610574
611999
612570
124924 604860 3
50999
124926
125922
572498 556578 3
571500
572496
572999
625812 600906 3
624814
625999
626810
407640 399664 3
406642
407638
407999
384728 367999 3
383730
384999
385726...

output:

663634
365798
612570
125922
571500
624814
406642
383730
610830
491848
579976
623910
607732
211878
679840
615848
651552
478922
609874
531690
99942
649558
691392
638714
108999
550828
527912
574862
657632
641602
685554
626778
684950
439834
688808
344896
501578
620678
499596
578852
607716
627770
700886
...

result:

points 0.45270196710 max label = 711999

Test #100:

score: 26.3205
Acceptable Answer
time: 30ms
memory: 4096kb

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
724864
113999
824446
967999
854344
785999
719878
849364
815490
887999
820999
905999
726858
992966
788592
658999
262999
557999
753762
784620
931078
503999
853352
782630
925999
706999
764704
875272
799999
878262
792999
207999
755750
439999
827440
710920
299999
915132
610999
805999
455999
744788...

input:

1
33377
913676 213999 3
912678
913999
914674
836490 311999 3
328999
836488
836492
757732 922112 3
491999
757730
757734
843456 819558 3
842458
843454
843999
827248 993886 3
77999
827250
828246
482722 526999 3
206999
482724
483720
923414 395999 3
339999
923416
924412
949554 886764 3
948556
949999
9505...

output:

914674
836488
757730
842458
828246
483720
923416
948556
532518
841874
178878
905174
721656
707964
999554
693750
897246
516588
834490
968470
933376
808514
977652
656880
987156
860390
808316
197810
983176
808876
762754
738856
808320
834526
481726
861388
893264
464824
288864
891270
817614
731602
511606...

result:

points 0.43148441690 max label = 999999

Test #101:

score: 26.7009
Acceptable Answer
time: 16ms
memory: 3820kb

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
737999
505999
272999
493999
618999
528999
627999
682999
393999
49999
856999
827999
330999
710999
127999
162999
19999
742999
7999
438999
403999
833999
630999
197999
290999
869999
653999
107999
309999
151999
809999
689999
372999
816999
841999
535999
785999
892999
709999
600999
82999
318999
84699...

input:

1
4502
376958 895999 42
336999
337999
338999
339999
340999
341999
342999
343999
344999
345999
346999
347999
348999
349999
350999
351999
352999
353999
354999
355999
356999
357999
358999
359999
360999
361999
362999
363999
364999
365999
366999
367999
368999
369999
370999
371999
372999
373999
374999
375...

output:

406911
870550
667906
682453
478948
223937
411692
415851
691400
427685
904096
775908
375749
638796
366643
870550
904096
673944
904096
354848
53961
172951
806325
311921
831242
853237
411692
682453
904096
533698
701348
375749
396889
626907
904096
632920
413698
883134
411692
797313
879813
870550
904096
...

result:

points 0.43771957680 max label = 904999

Test #102:

score: 26.3205
Acceptable Answer
time: 14ms
memory: 4132kb

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
668999
871999
581999
402999
553999
669999
5999
429999
573999
398999
510999
932999
51999
218999
215999
778999
618999
321999
955999
746999
253999
890999
961999
426999
419999
853999
848999
590999
731999
66999
973999
436999
365999
533999
708999
34999
454999
904999
872999
674999
210999
608999
8809...

input:

1
4293
244999 232999 1
543672
546999 425999 1
956554
778999 795999 1
966775
360999 3999 1
391708
242956 166999 44
200999
201999
202999
203999
204999
205999
206999
207999
208999
209999
210999
211999
212999
213999
214999
215999
216999
217999
218999
219999
220999
221999
222999
223999
224999
225999
2269...

output:

543672
956554
966775
391708
383715
857916
349811
963848
389873
883245
891120
772649
857916
812491
772776
916602
999001
999001
883245
835945
999001
956554
891120
870842
916602
772649
436786
977081
850594
634806
891120
389873
417918
891120
668897
18999
399918
812491
450919
889806
442847
866194
956554
...

result:

points 0.43148441690 max label = 999999