QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#68241#1209. Road DevelopmentMacesuted100 ✓280ms26924kbC++117.0kb2022-12-15 15:27:482022-12-15 15:27:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-15 15:27:51]
  • 评测
  • 测评结果:100
  • 用时:280ms
  • 内存:26924kb
  • [2022-12-15 15:27:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace IO {
const int SIZE = 1 << 20;
char Ibuf[SIZE], *Il = Ibuf, *Ir = Ibuf, Obuf[SIZE], *Ol = Obuf, *Or = Ol + SIZE - 1, stack[32];
char isspace(char c) {
    return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
}
void fill(void) {
    return Ir = (Il = Ibuf) + fread(Ibuf, 1, SIZE, stdin), void();
}
void flush(void) {
    return fwrite(Obuf, 1, Ol - Obuf, stdout), Ol = Obuf, void();
}
char buftop(void) {
    return Ir == Il ? fill(), *Il : *Il;
}
char getch(void) {
    return Il == Ir ? fill(), Il == Ir ? EOF : *Il++ : *Il++;
}
void putch(char x) {
    return *Ol++ = x, Ol == Or ? flush() : void();
}
template <typename T>
T read(void) {
    T x = 0, f = +1;
    char c = getch();

    while (c < '0' || c > '9')
        c == '-' ? void(f = -f) : void(), c = getch();

    while ('0' <= c && c <= '9')
        x = (x << 3) + (x << 1) + (c ^ 48), c = getch();

    return x * f;
}
template <typename T>
void write(T x) {
    if (!x)
        putch('0');

    if (x < 0)
        putch('-'), x = -x;

    int top = 0;

    while (x)
        stack[top++] = (x % 10) ^ 48, x /= 10;

    while (top)
        putch(stack[--top]);

    return;
}
string getstr(const string &suf = "") {
    string s = suf;

    while (isspace(buftop()))
        getch();

    while (Il != Ir) {
        char *p = Il;

        while (Il < Ir && !isspace(*Il) && *Il != EOF)
            Il++;

        s.append(p, Il);

        if (Il < Ir)
            break;

        fill();
    }

    return s;
}
void putstr(string str, int begin = 0, int end = -1) {
    if (end == -1)
        end = str.size();

    for (int i = begin; i < end; i++)
        putch(str[i]);

    return;
}
struct Flusher_ {
    ~Flusher_() {
        flush();
    }
} io_flusher_;
}  // namespace IO
using IO::getch;
using IO::getstr;
using IO::putch;
using IO::putstr;
using IO::read;
using IO::write;

bool mem1;

#define maxn 100005
#define maxq 300005

typedef tuple<int, int, int> tiii;

class UnionSet {
private:
    int fa[maxn];

    int getfa(int p) {
        return fa[p] == p ? p : fa[p] = getfa(fa[p]);
    }

public:
    void build(int n) {
        for (int i = 1; i <= n; i++)
            fa[i] = i;

        return;
    }
    bool merge(int x, int y) {
        if (check(x, y))
            return false;

        fa[getfa(y)] = getfa(x);
        return true;
    }
    bool check(int x, int y) {
        return getfa(x) == getfa(y);
    }
} US;
class SegmentTree {
private:
    int tree[maxn << 2], n;
    bool lazy[maxn << 2];

    void pushDown(int p) {
        if (!lazy[p])
            return;

        return tree[p << 1] = tree[p << 1 | 1] = 0, lazy[p << 1] = lazy[p << 1 | 1] = true, lazy[p] = false, void();
    }
    void pushUp(int p) {
        return tree[p] = tree[p << 1] + tree[p << 1 | 1], void();
    }
    void build(int p, int l, int r) {
        if (l == r)
            return tree[p] = 1, void();

        int mid = (l + r) >> 1;
        build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);
        return pushUp(p);
    }
    void update(int p, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr)
            return tree[p] = 0, lazy[p] = true, void();

        pushDown(p);
        int mid = (l + r) >> 1;

        if (ql <= mid)
            update(p << 1, l, mid, ql, qr);

        if (qr > mid)
            update(p << 1 | 1, mid + 1, r, ql, qr);

        return pushUp(p);
    }
    int query(int p, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr)
            return tree[p];

        pushDown(p);
        int mid = (l + r) >> 1;

        if (qr <= mid)
            return query(p << 1, l, mid, ql, qr);

        if (ql > mid)
            return query(p << 1 | 1, mid + 1, r, ql, qr);

        return query(p << 1, l, mid, ql, qr) + query(p << 1 | 1, mid + 1, r, ql, qr);
    }

public:
    void resize(int _n) {
        return n = _n, void();
    }
    void build(void) {
        return build(1, 1, n);
    }
    void update(int l, int r) {
        return update(1, 1, n, l, r);
    }
    int query(int l, int r) {
        return query(1, 1, n, l, r);
    }
} ST;

tiii ques[maxq];
int dfni[maxn], dfno[maxn], fa[maxn], top[maxn], dep[maxn], siz[maxn], son[maxn];
vector<vector<int>> graph;

void dfs1(int p) {
    siz[p] = 1;

    for (auto i : graph[p])
        if (i != fa[p]) {
            fa[i] = p, dep[i] = dep[p] + 1, dfs1(i), siz[p] += siz[i];

            if (!son[p] || siz[i] > siz[son[p]])
                son[p] = i;
        }

    return;
}
int dfnt = 0;
void dfs2(int p, int top_) {
    dfni[p] = ++dfnt, top[p] = top_;

    if (son[p])
        dfs2(son[p], top_);

    for (auto i : graph[p])
        if (i != fa[p] && i != son[p])
            dfs2(i, i);

    dfno[p] = dfnt;
    return;
}

void solve(void) {
    int n = read<int>(), q = read<int>();
    graph.resize(n + 1), US.build(n);

    for (int i = 1; i <= q; i++) {
        get<0>(ques[i]) = read<int>(), get<1>(ques[i]) = read<int>(), get<2>(ques[i]) = read<int>();

        if (get<0>(ques[i]) == 1 && US.merge(get<1>(ques[i]), get<2>(ques[i])))
            graph[get<1>(ques[i])].push_back(get<2>(ques[i])), graph[get<2>(ques[i])].push_back(get<1>(ques[i]));
    }

    for (int i = 1; i <= n; i++)
        if (!dfni[i])
            dfs1(i), dfs2(i, i);

    US.build(n), ST.resize(n), ST.build();

    for (int i = 1; i <= q; i++) {
        int x = get<1>(ques[i]), y = get<2>(ques[i]);

        if (get<0>(ques[i]) == 1) {
            if (!US.merge(x, y)) {
                while (top[x] != top[y]) {
                    if (dep[top[x]] < dep[top[y]])
                        swap(x, y);

                    ST.update(dfni[top[x]], dfni[x]), x = fa[top[x]];
                }

                if (dep[x] > dep[y])
                    swap(x, y);

                if (x != y)
                    ST.update(dfni[x] + 1, dfni[y]);
            }
        } else {
            if (US.check(x, y)) {
                int ans = 0;

                while (top[x] != top[y]) {
                    if (dep[top[x]] < dep[top[y]])
                        swap(x, y);

                    ans += ST.query(dfni[top[x]], dfni[x]), x = fa[top[x]];
                }

                if (dep[x] > dep[y])
                    swap(x, y);

                if (x != y)
                    ans += ST.query(dfni[x] + 1, dfni[y]);

                write(ans), putch('\n');
            } else
                putstr("-1\n");
        }
    }

    return;
}

bool mem2;

int main() {
    ios::sync_with_stdio(false);
#ifdef MACESUTED
    cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl;
#endif

    int _ = 1;

    while (_--)
        solve();

#ifdef MACESUTED
    cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
    return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 5ms
memory: 9696kb

input:

1000 2999
1 549 777
1 668 777
1 777 223
1 777 812
1 21 777
1 777 506
1 777 786
1 86 777
1 777 420
1 777 760
1 784 777
1 777 208
1 777 193
1 777 685
1 582 777
1 777 985
1 207 777
1 777 20
1 834 777
1 777 418
1 777 945
1 712 777
1 967 777
1 777 882
1 946 777
1 777 871
1 777 538
1 777 957
1 777 378
1 9...

output:

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

result:

ok 1000 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 9764kb

input:

1000 2998
2 319 331
2 442 549
1 955 383
1 400 642
1 400 10
1 400 310
1 400 490
1 848 400
1 284 485
2 321 304
1 485 813
2 233 844
1 291 485
1 485 231
2 800 651
1 342 210
2 76 730
2 573 615
2 28 518
1 705 131
1 383 662
1 214 642
1 383 848
2 618 265
1 436 642
1 832 642
2 603 4
1 490 928
1 490 376
1 330...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
5
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
4
-1
2
-1
-1
-1
-1
-1
-1
3
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

ok 1000 lines

Test #3:

score: 0
Accepted
time: 4ms
memory: 9600kb

input:

1000 2999
2 837 455
1 994 585
1 348 414
1 994 416
1 348 685
1 455 837
1 837 432
1 64 837
1 193 289
1 193 951
1 634 193
1 654 656
1 288 654
1 901 585
1 49 654
1 395 585
1 188 416
1 685 221
1 432 698
1 64 959
1 289 12
1 951 504
1 634 101
1 656 59
1 991 288
1 775 49
1 169 901
1 648 188
1 221 23
1 188 8...

output:

-1
13
22
3
8
-1
12
-1
19
0
14
20
-1
9
0
0
-1
1
0
17
0
1
1
0
12
0
-1
0
1
0
1
0
3
0
3
0
1
0
2
0
0
0
1
0
0
-1
0
0
1
0
0
0
0
0
1
1
0
0
0
3
0
0
0
0
1
0
-1
0
0
0
1
0
2
7
17
2
9
0
1
0
0
0
0
0
0
0
6
0
0
0
2
0
0
0
1
1
0
22
0
0
0
1
0
0
10
0
-1
0
8
0
2
0
0
0
0
0
10
1
0
1
2
12
1
5
1
0
0
1
0
0
0
-1
0
0
0
0
0
0
0...

result:

ok 1002 lines

Test #4:

score: 0
Accepted
time: 2ms
memory: 13692kb

input:

1000 2996
2 354 932
1 786 161
1 142 669
1 135 786
1 753 984
1 351 984
1 893 838
1 405 778
1 405 674
1 986 893
1 527 154
1 154 335
1 161 805
1 272 142
1 135 148
1 753 946
1 639 351
1 838 240
1 298 986
1 446 778
1 674 680
1 374 335
1 707 805
1 527 447
1 148 451
1 272 16
1 946 789
1 888 639
1 298 957
1...

output:

-1
13
-1
-1
14
0
28
12
1
0
12
3
2
11
51
39
28
0
0
3
16
4
8
3
20
19
30
68
47
0
0
0
0
0
27
0
0
-1
41
0
6
23
0
0
0
0
-1
0
53
0
0
0
0
0
0
0
0
0
-1
0
59
0
0
0
0
0
0
5
0
-1
0
0
1
0
0
0
0
45
0
0
-1
0
-1
-1
4
30
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
0
7
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 9608kb

input:

1000 3000
1 220 829
1 154 161
1 196 601
1 252 196
1 826 460
1 196 119
1 903 635
1 263 482
1 940 588
1 820 75
1 346 75
1 75 809
1 975 75
1 75 924
1 354 75
1 75 762
1 593 75
1 270 854
1 642 854
1 854 912
1 75 655
1 497 684
1 826 854
1 703 684
1 260 372
1 260 327
1 777 382
1 43 77
1 43 888
1 627 326
1 ...

output:

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

result:

ok 1001 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 9724kb

input:

1000 2998
1 979 101
1 322 617
1 241 731
1 785 731
1 888 322
1 478 353
1 404 478
1 402 478
1 734 395
1 88 734
1 13 734
1 677 266
1 969 959
1 402 266
1 221 80
1 733 221
1 973 136
1 444 833
1 775 990
1 918 570
1 833 20
1 206 973
1 423 918
1 905 33
1 851 905
1 992 111
1 623 111
1 858 848
1 893 802
1 160...

output:

-1
2
8
8
2
2
5
9
6
13
28
-1
6
11
0
24
4
3
1
3
0
2
11
0
20
9
18
0
1
1
0
0
1
15
2
0
3
0
0
1
8
1
0
20
11
0
3
0
0
4
0
-1
2
34
22
-1
1
34
-1
12
14
0
0
1
0
1
1
0
0
0
0
0
23
1
-1
11
1
0
2
1
1
0
10
1
3
0
0
4
0
1
4
5
0
0
0
1
0
0
3
0
0
0
23
1
0
0
0
2
0
1
0
0
0
0
1
0
0
1
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0...

result:

ok 1000 lines

Test #7:

score: 0
Accepted
time: 0ms
memory: 11528kb

input:

1000 2998
1 984 620
1 80 620
1 67 620
1 620 827
2 780 494
1 53 620
1 620 293
1 385 565
1 385 302
1 385 581
2 154 728
1 385 622
1 120 385
1 80 596
1 385 179
1 80 726
2 315 347
1 80 398
1 80 28
1 80 197
1 341 67
1 539 53
2 797 59
1 102 293
1 169 67
1 53 154
1 849 53
2 510 840
1 53 305
1 565 92
1 565 8...

output:

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

result:

ok 500 lines

Test #8:

score: 0
Accepted
time: 2ms
memory: 13668kb

input:

1000 2999
1 415 858
1 908 415
1 187 386
1 415 886
1 628 386
1 647 858
1 830 886
1 628 649
1 146 830
1 647 364
1 649 177
1 7 364
1 364 188
1 817 177
1 146 382
1 970 146
1 7 997
1 177 114
1 92 970
1 817 868
1 173 817
1 114 94
1 331 114
1 797 997
1 997 181
1 603 92
1 331 932
1 92 777
2 939 272
1 94 636...

output:

-1
3
20
11
27
85
2
0
1
0
32
-1
20
0
3
16
23
6
0
0
32
0
0
71
0
1
2
1
0
1
1
13
0
0
0
0
1
0
0
0
17
3
0
1
2
0
1
1
-1
18
3
1
8
1
4
16
1
48
0
2
0
1
1
0
0
1
0
-1
0
-1
1
2
-1
2
2
0
0
16
7
1
0
14
17
0
1
2
0
1
0
1
1
16
7
2
0
0
0
1
1
2
1
0
0
1
15
0
9
0
0
1
28
0
0
0
0
1
0
0
0
0
0
0
2
0
1
1
1
0
1
18
1
2
0
0
1
1
...

result:

ok 1500 lines

Subtask #2:

score: 25
Accepted

Test #9:

score: 25
Accepted
time: 110ms
memory: 18408kb

input:

100000 299999
1 15187 89995
1 18001 15187
1 80804 15187
1 31249 15187
1 66596 15187
1 15187 72772
1 95385 15187
1 15187 74582
1 15187 21285
1 15187 84342
1 17859 15187
1 15187 48883
1 15187 38539
1 94462 15187
1 15187 39598
1 9507 15187
1 15187 25121
1 47738 15187
1 16972 15187
1 15187 50630
1 15187...

output:

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

result:

ok 100000 lines

Test #10:

score: 0
Accepted
time: 280ms
memory: 18820kb

input:

100000 299998
1 90065 45146
1 90065 25037
1 29269 90065
1 90065 88770
1 71597 90065
1 90065 2353
1 90065 50946
1 81599 90065
1 67275 90065
1 90065 35093
1 29344 90065
1 90065 37173
1 90065 48618
1 63617 90065
1 25231 90065
1 90065 87982
1 57823 90065
1 90065 93233
1 94681 32500
1 94681 25275
1 15696...

output:

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

result:

ok 100000 lines

Test #11:

score: 0
Accepted
time: 103ms
memory: 24772kb

input:

100000 299999
1 13835 81352
1 13835 27820
1 44765 13835
1 77832 80659
1 82570 77832
1 81352 48899
1 64471 81352
1 27820 30692
1 45732 82570
1 24013 82570
1 27820 69179
1 31477 48899
1 32168 30692
1 45732 75421
1 31477 67202
1 31477 58931
1 20605 32168
1 67202 34638
1 75421 37103
1 7401 67202
1 85520...

output:

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

result:

ok 150000 lines

Test #12:

score: 0
Accepted
time: 100ms
memory: 24328kb

input:

100000 299998
1 41627 39111
1 41627 61593
1 71924 65268
1 10858 51913
1 28964 51913
1 83163 39111
1 64902 61593
1 46066 65268
1 71999 10858
1 83163 51489
1 52273 28964
1 54094 46066
1 64902 82305
1 71999 4528
1 51489 19157
1 92836 52273
1 20741 82305
1 19237 54094
1 4528 68265
1 74527 92836
1 10005 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 120000 lines

Test #13:

score: 0
Accepted
time: 128ms
memory: 23216kb

input:

100000 299999
1 86360 35996
1 35996 84803
1 74834 81957
1 17877 31209
1 74834 21146
1 74116 17877
1 88155 86360
1 87522 86360
1 84803 17861
1 22739 84803
1 28775 81957
1 86368 21146
1 81957 51566
1 84829 31209
1 74116 94185
1 74116 89722
1 88155 3848
1 78810 22739
1 45399 88155
1 22041 51566
1 17861...

output:

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

result:

ok 100000 lines

Test #14:

score: 0
Accepted
time: 109ms
memory: 23384kb

input:

100000 279990
1 77472 41282
1 77472 6882
1 95008 79070
1 91364 95008
1 85767 18092
1 85767 31048
1 85855 57276
1 35359 59716
1 98573 78265
1 32277 24736
1 69028 24736
1 36579 24736
1 64400 99721
1 35359 72750
1 77721 59841
1 93743 13414
1 77311 12499
1 9792 59841
1 49101 6882
1 91364 9908
1 70477 91...

output:

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

result:

ok 130000 lines

Test #15:

score: 0
Accepted
time: 208ms
memory: 18704kb

input:

100000 299999
1 66625 35002
1 97097 35002
1 35002 85944
1 61344 74012
1 65262 61344
1 1407 62002
1 69406 62002
1 68657 62002
1 62002 60022
1 51856 62002
1 33010 62002
1 31498 62002
1 66625 55823
1 51321 66625
1 66625 61364
1 10638 66625
1 66625 91918
1 23206 97097
1 66625 10379
1 48632 74012
1 97039...

output:

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

result:

ok 150000 lines

Test #16:

score: 0
Accepted
time: 96ms
memory: 22964kb

input:

100000 290499
1 42972 71686
1 52435 57308
1 65547 4285
1 42972 9034
1 4285 52435
1 42972 4333
1 9034 44367
1 65547 64703
1 58339 4333
1 44367 724
1 58339 60623
1 26492 28052
1 26492 64703
1 724 65847
1 28052 15127
1 42577 60623
1 65847 13625
1 42577 24752
1 42577 85350
1 23470 15127
1 13625 86174
1 ...

output:

0
0
0
3
0
0
1
1
0
0
2
2
2
0
3
0
0
0
1
4
1
1
2
0
56
2036
1
0
1
1
2
0
0
1
1
0
0
74
0
303
2
0
1
0
1
3
0
3
1
1
1
1
1
630
1
0
1
1
0
0
2261
0
0
1
1
0
1176
2
0
0
0
2
1
0
1
1
0
1850
1
0
1
1
1
1
143
2
0
1
0
1
0
1
0
0
1
2
0
0
1
1
0
2
1
1621
0
1
0
0
3
0
1
0
0
1
0
0
0
0
1
0
1
0
0
647
0
1
0
0
3
0
0
3
104
1
2
0
7...

result:

ok 190000 lines

Test #17:

score: 0
Accepted
time: 191ms
memory: 18736kb

input:

100000 279999
1 95804 65035
1 65035 99990
1 65035 3778
1 21838 65035
1 90218 85903
1 87620 90218
1 90218 32792
1 73451 46891
1 61448 16674
1 59910 73451
1 28930 20964
1 26195 73451
1 7466 19362
1 19362 74350
1 19362 81594
1 92091 19362
1 50010 19362
1 19362 19378
1 62779 19362
1 25088 19362
1 19362 ...

output:

5
2
1
5
3
4
2
10
2
6
4
2
4
6
1
4
3
1
9
4
3
6
3
7
2
3
4
1
4
6
5
5
1
9
6
4
6
3
1
2
0
2
3
3
7
5
6
4
1
0
4
6
0
2
5
5
3
5
7
4
5
9
5
4
7
3
7
6
9
2
6
7
4
4
6
6
5
6
6
3
5
7
4
8
2
0
12
3
2
7
3
4
1
4
3
4
6
0
3
4
15
6
3
1
6
10
8
3
4
5
3
7
2
1
4
4
4
6
7
5
1
3
7
3
2
2
6
2
5
6
0
5
1
3
5
7
3
7
1
3
4
5
5
4
7
5
5
6
...

result:

ok 160000 lines

Test #18:

score: 0
Accepted
time: 101ms
memory: 21916kb

input:

100000 270999
1 82732 51463
1 82732 81471
1 18501 84173
1 12199 18501
1 85626 18501
1 3323 64331
1 45688 99107
1 15862 99107
1 23702 88385
1 88385 8507
1 79331 67366
1 21745 79331
1 79760 35625
1 53228 35625
1 38374 3971
1 3971 96327
1 20897 18424
1 20897 25337
1 29545 3971
1 96263 51463
1 51463 795...

output:

0
1
0
1
1
0
1
2
0
0
1
1
205
1
0
2
3
0
0
1
0
0
1
0
2
3
0
1
0
2
2
0
0
1
0
0
379
0
1
1
0
0
0
1
2
0
1
0
0
0
0
0
0
0
0
0
2
0
0
1
0
1
0
3
0
0
0
0
1
1
0
3
1
1
2
1
1
1
0
0
1
0
324
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
3
1
3
0
2
1
1
0
0
1
0
0
0
0
1
1
0
1
1
0
0
1
0
0
1
0
0
1
0
0
1
2
0
4
0
0
0
0
0
1
1
0
0
0
1
...

result:

ok 170000 lines

Test #19:

score: 0
Accepted
time: 104ms
memory: 24204kb

input:

100000 280799
1 61171 74017
1 57952 61171
1 78978 61171
1 19589 57952
1 78978 58249
1 26722 19589
1 26722 77556
1 53117 77556
1 77556 98003
1 66170 91881
1 35142 66170
1 98003 91881
1 45727 35142
1 52360 35142
1 23879 35397
1 45462 35397
1 52360 35397
1 45365 29375
1 45365 23879
1 29375 38840
1 3884...

output:

2
9116
0
1
11684
11915
0
70
1
9733
2
0
2
5348
0
2972
1
2905
0
2
0
1
0
3585
0
2920
5869
0
602
1
1
6694
1898
10823
2894
0
12931
0
0
0
0
891
0
0
0
2
2
0
1
0
0
339
0
0
0
0
0
0
1968
0
1
0
1
2
12103
0
0
0
3
5246
0
261
1
11451
0
9336
3005
1
0
0
1805
2
0
9791
0
773
10330
1
1462
1
2
12206
9538
12665
0
0
7349...

result:

ok 180000 lines

Test #20:

score: 0
Accepted
time: 88ms
memory: 26064kb

input:

100000 299999
1 61442 58189
1 86398 31154
1 57144 58189
1 67759 31154
1 30704 48568
1 30704 14850
1 20460 72962
1 52951 20460
1 71050 26984
1 13500 82247
1 26655 71050
1 38651 31858
1 38651 97892
1 55706 36304
1 13500 90292
1 36304 59242
1 63754 82979
1 89553 16653
1 63754 13598
1 48252 16653
1 3918...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
22
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 100000 lines

Test #21:

score: 0
Accepted
time: 86ms
memory: 26924kb

input:

100000 280199
1 67744 82539
1 67744 61642
1 82539 25495
1 25495 39848
1 57570 54516
1 54516 39848
1 57570 82040
1 95654 68264
1 95654 82040
1 22790 85764
1 85764 67763
1 22790 68264
1 39594 50131
1 67763 50131
1 10917 60636
1 10917 39594
1 37107 60636
1 37107 34411
1 71180 34411
1 10595 42641
1 4264...

output:

0
13528
24845
0
20182
14213
0
4058
0
4073
15063
30691
0
30540
0
20719
49831
50140
47318
4520
23348
35182
26907
0
12445
33919
13243
2454
6806
12991
31547
36212
45517
0
0
0
0
33498
0
8236
43772
47515
35275
7416
0
670
0
21658
48559
23486
6566
5786
20288
0
0
4658
38039
14695
21114
30542
0
22417
5305
502...

result:

ok 180000 lines

Test #22:

score: 0
Accepted
time: 104ms
memory: 23612kb

input:

100000 280599
1 58862 63142
1 71489 27751
1 83446 25748
1 69386 85509
1 83446 75778
1 20344 97631
1 21295 20344
1 8943 93911
1 8943 21836
1 8943 89824
1 13621 39391
1 13621 3990
1 41958 9739
1 9739 2329
1 9739 10825
1 40829 25167
1 12766 51739
1 44624 68139
1 35766 68139
1 65793 51739
1 68139 13444
...

output:

0
3
0
0
812
812
812
0
1
1619
6300
814
1
0
0
813
6241
1086
0
813
0
0
812
813
6483
0
2
2230
134
812
0
0
1
812
1
1
2569
3372
1
0
1
3
0
812
0
1637
1914
1
0
813
1
812
0
0
813
1
3148
1
0
6482
1
812
0
3059
812
2458
1
2
1
0
0
3571
0
0
812
0
3559
0
0
812
3492
1
4062
2
813
4934
2813
813
1
1
0
3887
1058
812
0
...

result:

ok 180000 lines

Subtask #3:

score: 25
Accepted

Test #23:

score: 25
Accepted
time: 99ms
memory: 19188kb

input:

100000 299999
2 8119 45073
2 86104 92796
2 5136 89558
2 8653 10195
2 40543 20265
2 75521 88209
2 59155 90907
2 69281 97822
2 25070 37479
2 75044 79444
2 92838 2152
2 23164 12842
2 6274 1333
2 20162 90348
2 58604 67752
2 14453 71284
2 64687 89861
2 50677 32026
2 38961 54494
2 36582 633
2 41147 5156
2...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
2
-1
2
-1
-1
-1
-1
2
2
-1
2
2
-1
2
-1
2
-1
2
-1
2
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
2
-1
2
2
-1
-1
-1
-1
...

result:

ok 100000 lines

Test #24:

score: 0
Accepted
time: 201ms
memory: 19244kb

input:

100000 299999
2 3394 71549
2 12778 29303
2 45136 69033
2 23079 88859
2 90724 56758
2 36018 5313
2 49264 53868
2 23960 26430
2 82069 39554
2 57320 53135
2 18709 73312
2 74470 57324
2 75390 96107
2 56216 71889
2 87921 75487
2 39892 7900
2 80873 11637
2 43614 63639
2 42344 80729
2 86240 47065
2 80799 5...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
11
-1
-1
-1
-1
-1
-1
10
-1
10
-1
-1
8
7
-1
-1
-1
-1
-1
7
12
-1
-1
-1
10
11
-1
9
11
-1
7
-1
8
7
-1
-1
13
-1
-1
8
12
-1
-1
-1
-1
-1
-1
-1
-1
11
7
-1
9
9
14...

result:

ok 100000 lines

Test #25:

score: 0
Accepted
time: 124ms
memory: 23096kb

input:

100000 299999
2 18501 10095
2 37561 62675
2 56123 70687
2 85462 678
2 14040 85092
2 78891 26294
2 62049 70907
2 42774 67410
2 88281 57205
2 95949 74247
2 70261 61454
2 81984 2623
2 67046 40315
2 20648 85328
1 84297 10963
1 88689 10179
1 74314 80556
1 45270 10179
1 80556 93428
1 10963 10800
1 90543 1...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
454
-1
-1
-1
-1
-1
-1
-1
-1
208
-1
-1
-1
-1
-1
-1
1229
-1
-1
795
69
-1
-1
-1
-1
-1
-1
947
11
-1
-1
-1
441
-1
-1
162
-1
-1
-1
-1
-1
1029
-1
-1
-1
-1
-1
132
1387
239
683
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 100000 lines

Test #26:

score: 0
Accepted
time: 106ms
memory: 25632kb

input:

100000 299999
2 97595 27299
2 48965 25610
2 72441 36344
2 11798 3725
2 56769 90546
2 2140 52
2 29382 60612
2 74987 51785
2 46831 50114
2 71708 18201
2 29832 50152
1 35917 69617
1 79355 37114
1 92967 35917
1 32928 11038
1 11038 32864
1 11939 52335
1 52335 44371
1 69617 68100
1 92967 61860
1 75406 371...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
24
-1
15
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
0
-1
-1
0
-1
0
0
-1
-1
0
0
0
14
-1
-1
-1
-1
0
0
-1
0
0
-1
135
-1
-1
-1
0
0
-1
-1
0
-1
-1
0
0
-1
-1
156
-1
0
0
-1
0
-1
-1
-1
0
191
-1
103
-1
0
464
0
-1
0
-1
0
-1
0
0
0
-1
-1
0
-1
0
0
-1
0
-1
240
0
0
0
30
-1
-1
0
148
80...

result:

ok 100000 lines

Test #27:

score: 0
Accepted
time: 105ms
memory: 19156kb

input:

100000 299990
2 40761 82784
2 65229 67539
2 18989 85671
1 90992 37151
2 66716 23253
1 53015 37151
1 12039 37151
1 37151 26085
1 37151 30531
2 42390 49224
2 88820 23778
1 37151 18203
1 62448 77403
2 78331 46110
1 53689 37151
1 43180 30651
2 31690 24479
2 81504 27009
2 56511 34735
1 63130 30651
1 3065...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 100000 lines

Test #28:

score: 0
Accepted
time: 115ms
memory: 22640kb

input:

100000 299999
2 15934 19017
2 16641 37531
2 26852 26498
2 8441 17721
2 19003 70597
2 92177 74692
2 20182 82509
2 1649 34305
1 85785 40617
1 54103 87498
1 40617 20970
1 43995 99951
1 43995 91584
1 62196 24085
1 73069 43995
1 3466 16045
1 48582 3466
1 16464 75231
1 87498 65749
1 62196 87600
1 71840 87...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
44
-1
-1
-1
399
-1
-1
-1
-1
-1
465
-1
-1
305
814
-1
-1
1166
-1
-1
801
-1
-1
-1
-1
264
-1
-1
-1
504
618
-1
-1
866
-1
-1
864
138
-1
-1
-1
975
-1
1187
-1
-1
505
117
-1
1481
670
-1
820
-1
-1
-1
1383
222
338
1341
310
629
1005
581
-1
1051
804
-1
597
-1
323
1...

result:

ok 180000 lines

Test #29:

score: 0
Accepted
time: 75ms
memory: 18312kb

input:

100000 299998
2 89575 66619
2 248 61604
2 35309 97896
2 75227 19523
2 36787 69382
2 49874 67045
2 57482 26661
2 75052 31073
1 4118 43173
1 43173 11248
1 43173 15534
1 43173 8699
1 43173 18664
1 43173 12111
1 43173 38918
1 43173 92351
1 43173 55323
1 93254 43173
1 2815 43173
1 31993 43173
1 43173 702...

output:

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

result:

ok 40000 lines

Test #30:

score: 0
Accepted
time: 144ms
memory: 22332kb

input:

100000 299999
2 43588 80173
2 35982 99821
2 20734 24438
1 98726 31983
1 77337 31983
1 60743 59884
1 19362 60743
1 47376 65712
1 65712 68989
1 80801 70592
1 70592 65606
1 3489 32611
1 9878 83999
1 83999 12268
1 95269 49896
1 36514 36798
1 49896 3666
1 45874 57858
1 98444 45874
1 12948 68006
1 15929 1...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
448
310
-1
179
-1
-1
161
-1
-1
-1
156
7
110
-1
353
18
97
-1
-1
119
94
-1
-1
178
144
-1
76
216
31
155
59
359
174
244
74
30
424
314
114
15
254
-1
96
44
393
74
240
41
88
-1
112
164
68
316
-1
282
115
175
-1
380
135
0
10
90
25
12
9
54
-1
130
48
176
-1
-1
-1
504
-1
98
55
-1
2...

result:

ok 100000 lines

Test #31:

score: 0
Accepted
time: 93ms
memory: 22440kb

input:

100000 299999
1 13343 64345
1 13343 98610
1 79010 39333
1 54010 10588
1 28813 79010
1 43822 54010
1 47839 19220
1 19220 1578
1 35790 12364
1 55652 35790
1 97393 8639
1 26761 97393
1 99198 16835
1 16835 45980
1 92373 79916
1 54528 37728
1 56669 92373
1 41332 6278
1 37728 7152
1 74200 41332
1 70282 21...

output:

0
-1
23
0
0
0
0
0
0
0
0
0
0
29
-1
0
0
-1
0
-1
0
0
0
12
0
0
0
0
0
0
15
-1
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
-1
-1
0
0
0
56
-1
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0...

result:

ok 10000 lines

Test #32:

score: 0
Accepted
time: 109ms
memory: 23812kb

input:

100000 289950
2 87354 78112
2 72096 48961
1 73804 28296
1 63836 28296
1 99634 740
1 98280 37855
1 76777 98280
1 74753 38173
1 59981 7567
1 38173 98289
1 61573 15644
1 59981 11545
1 77369 24731
1 24731 45242
1 78959 59981
1 89676 37243
1 8778 37243
1 6343 37243
1 28791 69526
1 30496 56364
1 17082 915...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
188
-1
-1
-1
54
-1
-1
47
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
36
-1
-1
-1
77
-1
94
-1
386
-1
-1
114
-1
-1
-1
51
-1
621
-1
-1
-1
77
25
234
-1
131
-1
553
374
-1
-1
30
-1
-1
-1
261
522
-1
96...

result:

ok 180000 lines

Test #33:

score: 0
Accepted
time: 76ms
memory: 19340kb

input:

100000 279990
2 17923 66693
2 44864 32304
2 17372 59375
2 32514 51928
2 5139 51387
2 49750 47623
2 75825 80788
2 92615 14527
2 50959 46846
2 27045 34726
2 63829 59225
2 64113 85041
2 73943 1682
2 92700 75633
2 3013 15304
2 28107 11841
2 64618 95964
2 61034 91385
2 83930 4981
2 72527 64130
2 6754 814...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
2
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
2
2
-1
-1
...

result:

ok 150000 lines

Test #34:

score: 0
Accepted
time: 100ms
memory: 24180kb

input:

100000 299901
2 65293 84549
1 20713 73450
1 30606 29062
1 86227 20713
1 20671 22745
1 89836 57693
1 66356 30550
1 24348 66356
1 57693 35605
1 41294 27496
1 35110 41294
1 41294 11667
1 585 30112
1 26154 585
1 53152 70664
1 35231 585
1 76087 70664
1 3701 94333
1 94333 58044
1 675 85662
1 67870 675
1 9...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
12
-1
-1
121
-1
-1
-1
-1
-1
-1
-1
-1
114
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
5
32
-1
23
1
-1
...

result:

ok 150000 lines

Test #35:

score: 0
Accepted
time: 111ms
memory: 24200kb

input:

100000 290497
2 17054 8059
2 60508 11321
2 93952 88715
2 52829 97572
1 8261 31021
1 89154 36793
1 28258 31021
1 31021 70000
1 38573 55712
1 17641 4324
1 4324 24835
1 39179 38573
1 38573 96765
1 88802 49750
1 89404 7971
1 89404 93822
1 49750 82531
1 66184 49750
1 13354 92858
1 13354 10755
1 7576 1335...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
511
-1
-1
176
-1
-1
93
-1
-1
649
-1
-1
167
100
-1
131
793
-1
175
410
36
-1
-1
-1
319
-1
251
203
437
-1
194
-1
-1
-1
42
-1
574
-1
515
-1
1216
297
917
-1
391
-1
-1
-1
532
-1
562
-1
-1
-1
106
461
-1
2658
-1
15
25
1160
599
625
482
1136
-1
-1
-1
51
-1...

result:

ok 190000 lines

Test #36:

score: 0
Accepted
time: 82ms
memory: 24372kb

input:

100000 250295
2 4120 24743
2 42845 40771
1 5671 97110
1 97110 90760
1 29326 15677
1 15677 329
1 15811 29690
1 83151 29690
1 16636 25898
1 37222 15677
1 56780 45693
1 45693 21028
1 65201 4943
1 65201 77070
1 68961 79293
1 5639 65201
1 68961 5478
1 97418 57614
1 82553 46630
1 9846 18258
1 9846 41129
1...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
209
-1
-1
-1
403
33
53
124
512
81
43
-1
162
66
-1
112
765
240
684
249
97
261
170
131
-1
2
57
39
462
283
1047
-1
-1
-1
235
-1
620
1053
778
1221
-1
-1
204
108
429
783
592
-1
-1
190
46
-1
-1
424
112
1003
216
-1
950
650
266
-1
-1
9
572
481
135
803
-1
-1
85
1456
...

result:

ok 150000 lines

Subtask #4:

score: 25
Accepted

Test #37:

score: 25
Accepted
time: 72ms
memory: 19256kb

input:

100000 200199
1 5169 43928
1 5169 9311
1 5169 97324
1 5169 36558
1 36101 5169
1 5169 51151
1 5169 81177
1 75477 5169
1 5169 68874
1 5169 7431
1 89778 5169
1 63628 5169
1 5169 99238
1 10359 5169
1 5169 97094
1 10516 5169
1 50003 5169
1 5169 59128
1 5169 29944
1 15744 5169
1 5169 6092
1 5169 99427
1 6...

output:

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

result:

ok 200 lines

Test #38:

score: 0
Accepted
time: 168ms
memory: 18264kb

input:

100000 200199
1 11558 33541
1 33847 54405
1 16399 33847
1 33847 71697
1 84413 33847
1 33847 17875
1 61269 33847
1 72606 33847
1 62790 33847
1 33847 17458
1 33847 45075
1 33847 79054
1 33847 64635
1 33847 92487
1 33847 22562
1 33847 10309
1 72452 33847
1 33847 14779
1 33847 83764
1 34081 33847
1 5235...

output:

-1
6
0
2
1
1
3
1
2
1
0
2
1
2
2
0
0
2
1
1
0
1
2
4
2
1
0
4
0
3
0
1
0
0
3
0
0
0
1
1
3
0
0
0
1
2
0
1
1
1
3
1
1
0
1
0
1
0
0
0
1
0
0
-1
1
0
1
2
0
0
1
1
3
1
0
1
1
0
0
1
1
2
2
1
1
1
0
0
0
0
2
0
0
1
0
2
0
0
2
0
1
0
1
1
0
0
1
1
1
0
1
2
0
0
2
0
1
0
0
2
2
0
1
1
0
0
0
1
0
0
0
0
0
0
1
0
1
1
0
4
0
1
0
0
0
0
0
0
1
...

result:

ok 200 lines

Test #39:

score: 0
Accepted
time: 86ms
memory: 22304kb

input:

100000 200199
1 92270 92029
1 50924 86662
1 92029 19251
1 90524 36672
1 50924 93166
1 18027 24673
1 45177 90524
1 73877 16932
1 16932 98174
1 58954 79281
1 81846 92270
1 92270 77465
1 19251 41725
1 93166 58537
1 19230 36672
1 96318 45177
1 86662 65915
1 24673 43242
1 24673 42902
1 51045 98174
1 4163...

output:

0
1
1
1
2
1
0
1
1
0
1
0
1
0
-1
0
1
1
0
3
0
1
0
0
0
1
0
1
0
0
0
2
0
0
0
1
3
0
0
0
4
0
0
0
1
0
1
0
-1
0
1
0
0
-1
-1
-1
0
0
1
0
1
0
0
1
0
0
1
2
0
1
0
0
0
0
0
0
0
0
0
0
2
0
0
1
0
1
0
0
0
0
0
0
1
0
0
0
0
0
1
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200 lines

Test #40:

score: 0
Accepted
time: 85ms
memory: 23612kb

input:

100000 200199
1 38325 65838
1 65838 35702
1 67848 79143
1 67848 35127
1 6373 14842
1 85975 42624
1 48127 76562
1 91270 48127
1 29741 42624
1 14842 6881
1 60182 10794
1 83607 10794
1 2697 58864
1 2697 61691
1 18346 85923
1 25550 87905
1 40920 87905
1 85923 28532
1 89276 25201
1 36455 57037
1 27907 89...

output:

0
0
0
0
0
0
365
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 200 lines

Test #41:

score: 0
Accepted
time: 280ms
memory: 18804kb

input:

100000 290198
1 39035 25441
1 52125 39035
1 37020 39035
1 39035 97763
1 39035 52685
1 39035 7456
1 39035 99444
1 39035 27678
1 39035 30364
1 39035 13776
1 39035 98753
1 39035 58096
1 39035 92456
1 38965 77762
1 38965 82945
1 38965 81751
1 38965 90244
1 38965 9706
1 38965 23695
1 19950 38965
1 46769 ...

output:

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

result:

ok 200 lines

Test #42:

score: 0
Accepted
time: 126ms
memory: 24684kb

input:

100000 290197
1 82965 7436
1 82454 49330
1 234 74385
1 42829 26694
1 89332 7436
1 47025 84489
1 71643 47025
1 47025 25754
1 63080 26537
1 25025 97164
1 26537 5699
1 82965 15570
1 59488 82965
1 49330 19936
1 68747 234
1 43931 49330
1 89332 19426
1 42829 52678
1 42829 77326
1 71643 23894
1 84489 93912...

output:

2
0
-1
0
-1
0
1
2
0
1
0
-1
0
0
0
0
1
0
-1
0
-1
2
1
0
0
0
0
0
0
3
0
0
0
0
1
0
0
0
1
1
0
0
1
0
0
0
0
0
0
1
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
1
0
0
1
0
0
0
0
0
0
0
-1
0
0
25
1
0
0
0
0
0
0
0
-1
0
0
-1
1
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200 lines

Test #43:

score: 0
Accepted
time: 29ms
memory: 17160kb

input:

100000 101196
1 34254 6146
1 53283 51126
1 15610 53283
1 15648 58630
1 70493 52089
1 53283 96505
1 91060 41725
1 91060 11667
1 64085 91060
1 22179 5446
1 91060 24974
1 91060 72698
1 91060 74238
1 91060 98779
1 53627 91060
1 95917 26017
1 85227 10863
1 94475 26824
1 85227 92745
1 18324 94475
1 25210 ...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
12
-1
-1
-1
9
-1
9
-1
-1
11
16
-1
-1
-1
-1
12
14
-1
12
11
-1
-1
11
-1
-1
-1
-1
-1
10
15
11
-1
11
-1
-1
-1
9
-1
-1
18
-1
-1
18
18
-1
-1
16
14
16
-1
-1
14
14
22
15
-1
-1
11
-1
10
14
-1
-1
16
17
-1
-1
-1
16
-1
18
19
-1
...

result:

ok 200 lines

Test #44:

score: 0
Accepted
time: 18ms
memory: 23740kb

input:

100000 102197
1 4446 88490
1 27639 51182
1 4446 43945
1 4446 49238
1 97678 82442
1 51075 86874
1 68046 90700
1 86874 37550
1 34354 65560
1 10280 64569
1 65560 28258
1 64243 52518
1 11713 89085
1 11713 10488
1 51182 78521
1 93662 88490
1 64165 43945
1 51182 46658
1 49238 32324
1 82442 65583
1 93773 8...

output:

1717
2003
1432
130
1775
457
1998
0
3056
1786
6631
5243
2462
1117
7264
0
1899
1239
6299
4648
3
587
9282
951
202
1
1
946
5686
2739
1
1771
1675
875
0
1
1074
1
4265
0
2894
2601
2160
0
1220
0
-1
1909
2054
4155
7275
5759
1
2875
0
1
551
3061
4253
1444
1
0
0
0
1
2192
5640
0
6121
0
2430
0
0
892
5144
1428
358...

result:

ok 200 lines

Test #45:

score: 0
Accepted
time: 39ms
memory: 25684kb

input:

100000 110120
1 60449 77150
1 95885 60449
1 89284 31231
1 31231 52615
1 48485 43475
1 48485 73010
1 96798 77791
1 26343 77791
1 76923 65364
1 76923 11628
1 41017 43269
1 61041 85390
1 35801 41017
1 19724 85390
1 30031 89276
1 2918 35387
1 35387 72155
1 26483 70678
1 26483 50864
1 18971 76099
1 76099...

output:

798
377
-1
0
5309
974
3090
6724
631
1835
1247
494
1569
595
964
1285
0
3966
5006
1812
-1
0
0
-1
0
0
-1
-1
3034
0
390
0
675
0
0
0
0
0
984
-1
0
0
0
736
0
200
0
0
0
0
0
0
0
0
0
269
0
0
0
0
0
0
582
422
0
15
0
0
375
0
846
0
0
0
634
0
0
0
0
0
-1
977
0
0
0
939
0
0
0
0
-1
0
0
3584
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200 lines

Test #46:

score: 0
Accepted
time: 56ms
memory: 19124kb

input:

100000 200198
1 71178 39924
1 73334 39924
1 39924 59179
1 39924 43903
1 39924 59579
1 49584 39924
1 15731 39924
1 39924 4944
1 95507 39924
1 39924 99530
1 6336 39924
1 39924 33005
1 36284 39924
1 39924 65566
1 36935 39924
1 39924 72519
1 39924 52279
1 64050 39924
1 39924 24067
1 39924 80992
1 39924 ...

output:

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

result:

ok 200 lines

Test #47:

score: 0
Accepted
time: 102ms
memory: 23384kb

input:

100000 250190
1 49584 97561
1 81864 97561
1 42295 14986
1 89205 14986
1 97073 48140
1 69456 52489
1 76466 52489
1 48140 29953
1 54063 59647
1 54063 89787
1 54144 95984
1 64336 37891
1 38428 95984
1 18325 33082
1 90830 64336
1 45540 33082
1 37039 82248
1 63837 60863
1 75723 60863
1 72634 78329
1 7832...

output:

0
33
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200 lines

Test #48:

score: 0
Accepted
time: 148ms
memory: 23076kb

input:

100000 290195
1 98534 33207
1 46210 25778
1 21257 56115
1 21257 83094
1 28557 23256
1 14985 70280
1 7409 47231
1 71888 7409
1 98534 23336
1 56115 12953
1 96973 56115
1 11449 25778
1 45006 23256
1 73768 23256
1 70280 21478
1 70280 3212
1 43015 71888
1 70030 71888
1 38001 23336
1 25295 23336
1 19094 4...

output:

0
0
1
0
0
0
0
0
-1
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 200 lines

Subtask #5:

score: 15
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #49:

score: 15
Accepted
time: 110ms
memory: 19148kb

input:

100000 299999
2 95712 80936
2 8728 91252
2 44317 72395
2 46111 54216
2 70296 60637
2 80436 28086
2 54097 13984
2 50646 67035
2 50480 8769
2 95395 27644
2 82643 89590
2 67438 41014
2 78185 94524
2 71976 11995
2 62075 36028
2 35470 17938
2 57552 25412
2 77225 6264
2 10645 46919
2 57537 72804
2 64707 5...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
-1
-1
2
-1
-1
2
-1
-1
2
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
2
2
-1
-1
-1
2
-1
-1
-1
2
-1
-1
-1
2
-1
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
2
-1
-...

result:

ok 100000 lines

Test #50:

score: 0
Accepted
time: 220ms
memory: 19188kb

input:

100000 299998
2 64464 86829
2 24083 95779
2 39553 94197
2 18255 17709
1 39951 68254
1 70474 75885
1 21043 70474
1 59928 70474
1 92381 70474
1 70474 69987
2 49989 97645
1 91317 70474
2 16685 28018
1 70474 43282
1 99403 70474
1 53260 70474
1 70474 74790
1 70474 42404
2 24337 68091
1 70474 20338
2 8345...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 100000 lines

Test #51:

score: 0
Accepted
time: 130ms
memory: 24468kb

input:

100000 299997
2 94592 89027
2 31161 82602
2 50525 69277
2 26611 96994
2 22125 28154
2 26781 95321
2 83782 98704
2 353 21058
1 85044 38566
1 55740 67136
1 20856 76857
1 16370 34215
1 16370 27353
1 85044 24091
1 1512 85044
1 10194 85044
1 68135 20856
1 83610 55740
1 55740 21015
1 58555 27353
1 34215 5...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
509
-1
-1
230
-1
-1
-1
572
-1
337
555
1273
-1
-1
-1
-1
-1
-1
1
152
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
0
-1
207
-1
1
-1
1
896
-1
0
-1
-1
-1
-1
7
67
-1
0
0
-1
-1
-1
-1
1
2
2
-1
0
-1
-1
-1
1
371
-1
-1
-1
1
-1
1
-1
0
0
0
-1
0
-1
1
2
-1
-1
76...

result:

ok 100000 lines

Test #52:

score: 0
Accepted
time: 110ms
memory: 25940kb

input:

100000 299996
2 31025 28667
2 49919 62709
2 51750 17909
2 33762 47200
2 35108 58264
2 48198 24143
2 4083 90266
2 11545 11692
1 78784 1614
1 53975 74569
1 75081 12964
1 75081 45064
1 74569 77897
1 58585 74837
1 74837 85618
1 24670 22591
1 98266 1614
1 8062 53975
1 22591 83432
1 12964 22490
1 49810 45...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
362
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
984
426
-1
-1
-1
-1
-1
-1
0
0
0
1195
605
-1
0
-1
0
0
0
0
-1
0
-1
160
-1
-1
0
53
-1
0
-1
519
-1
-1
-1
-1
0
-1
-1
-1
-1
270
-1
-1
-1
215
0
0
0
-1
0
32
0
0
0
-1
-1
0
0
0
-1
-1
-1
-1
0
-1
-1
-1
-1
0
0
-1
105...

result:

ok 100000 lines

Test #53:

score: 0
Accepted
time: 92ms
memory: 19196kb

input:

100000 259995
2 51143 81293
2 53867 90287
1 27879 42006
1 42006 58812
1 75891 42006
1 42006 63621
1 97917 42006
1 67679 42006
1 91741 42006
1 46050 42006
1 42006 89609
1 94712 42006
1 42006 7133
1 81213 42006
1 82134 42006
1 60030 42006
1 42006 44580
1 42006 58495
1 42006 78495
1 88395 42006
1 42006...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
1
-1
-1
2
2
2
2
-1
-1
2
-1
2
2
2
1
2
1
1
-1
2
2
2
-1
2
2
-1
-1
2
2
-1
-1
2
-1
2
-1
2
2
2
2
2
2
2
2
2
2
1
2
2
-1
1
2
2
-1
2
-1
-1
2
2
2
2
1
1
1
2
2
2
1
-1
-1
-1
2
2
2
2
2
1
2
2
2
2
2
2
1
-1
2
1
2
2
2
2
2
1
2
-1
2
1
1
2
2
2
2
2
1
2
-1
2
2
2
2
-1
2
2
1
2
-1
2
2
2
1
2
2
2...

result:

ok 10000 lines

Test #54:

score: 0
Accepted
time: 94ms
memory: 18728kb

input:

100000 259994
2 81403 67855
2 24977 96239
2 56061 72739
2 90923 6893
2 26776 3466
2 98045 49264
2 53565 89630
2 52234 83116
2 60249 11273
2 98438 73562
2 25618 10580
1 50683 3686
1 54802 35604
1 35604 35263
2 80061 91281
2 39827 92707
1 35604 29632
1 69941 35604
1 61830 35604
2 48781 13749
1 55729 3...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 150000 lines

Test #55:

score: 0
Accepted
time: 131ms
memory: 24052kb

input:

100000 259993
1 60235 93319
1 51975 60235
1 62588 60235
1 14955 12941
1 48071 12941
1 85154 62877
1 77579 8933
1 16198 8933
1 68050 8933
1 8590 16122
1 16122 45316
1 16122 36286
1 47151 69471
1 47151 51237
1 47151 45984
1 93721 47350
1 34914 85154
1 51975 274
1 93319 47005
1 14955 60603
1 85154 2498...

output:

2
-1
1
1
-1
0
0
30
234
-1
0
103
1
-1
1
0
0
15
0
0
0
1
0
-1
1
0
0
2
-1
-1
1
-1
0
2
0
-1
1
1
238
1
0
0
0
0
0
0
1
1
2
0
0
4
0
0
-1
-1
1
-1
1
0
0
-1
1
1
76
-1
0
0
0
0
2
0
-1
0
0
0
2
-1
2
-1
0
-1
-1
0
-1
0
0
2
1
0
0
1
0
0
2
0
0
1
1
0
-1
-1
0
1
1
1
0
2
62
0
0
0
0
0
-1
0
0
0
1
1
0
0
0
0
1
1
0
1
0
1
4
0
0
-...

result:

ok 10000 lines

Test #56:

score: 0
Accepted
time: 95ms
memory: 25588kb

input:

100000 259992
1 31496 31945
1 31496 1356
1 49607 94026
1 18204 56997
1 48070 94026
1 2092 73752
1 15288 18204
1 26574 49650
1 99872 2092
1 16338 88993
1 26574 82949
1 53750 5485
1 16338 44607
1 21174 53750
1 26907 48476
1 87867 48476
1 59648 2915
1 59648 63514
1 22640 36486
1 83733 36486
1 12495 923...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
18
18
88
147
325
-1
105
-1
-1
-1
12
-1
-1
16
-1
-1
49
81
61
37
-1
-1
166
-1
395
324
142
-1
608
269
1
362
104
93
118
243
107
44
540
211
161
-1
206
24
81
27
57
198
80
-1
6
3
175
-1
290
109
447
-1
344
148
437
-1
349
327
-1
293
616
19
364
74
63
265
46
-1
200
68
21
201...

result:

ok 150000 lines

Test #57:

score: 0
Accepted
time: 108ms
memory: 22444kb

input:

100000 280991
2 77677 30498
2 81249 73058
2 74787 3213
2 82392 80607
2 20614 93097
2 77045 6156
2 61477 50476
2 57741 89626
2 23397 94000
1 88222 53266
1 88222 71542
1 40923 39637
1 91585 39637
1 25938 67466
1 36582 67466
1 77655 39663
1 78420 61218
1 90760 50032
1 90760 4890
1 65958 5679
1 52328 30...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
946
-1
337
-1
-1
-1
-1
-1
831
1497
-1
1786
1382
-1
-1
-1
773
640
15
-1
2014
1718
455
969
-1
-1
-1
290
-1
-1
-1
-1
-1
225
-1
-1
2177
-1
-1
-1
-1
-1
-1
-1
-1
479
-1
-1
2021
-1
1062
2016
942
2906
890
-1
3245
3574
-1
-1
160...

result:

ok 180000 lines

Test #58:

score: 0
Accepted
time: 99ms
memory: 22592kb

input:

100000 270490
2 42407 85369
2 37799 75114
1 11481 83320
1 83320 67045
1 93286 7164
1 93286 80482
1 81125 93286
1 12029 14747
1 56979 14747
1 69634 85261
1 54595 69634
1 39880 94176
1 7501 94176
1 17084 54302
1 58270 90905
1 90003 29860
1 92679 29860
1 84707 87714
1 84707 1980
1 67260 30961
1 96866 5...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
134
454
-1
9
-1
-1
-1
-1
-1
-1
-1
876
601
-1
-1
1214
319
-1
-1
603
-1
-1
637
-1
1136
-1
-1
-1
-1
-1
819
-1
-1
2116
239
829
346
-1
-1
2097
906
-1
656
251
-1
-1
1260
-1
1527
-1
-1
-1
301
20
1903
46
861
701
33
732
180
-1
-1
-1
-1
-1
1293
328
466
-1
-1
-1
642
564
-...

result:

ok 170000 lines

Test #59:

score: 0
Accepted
time: 88ms
memory: 23760kb

input:

100000 261989
2 78416 15747
2 35488 75579
2 75301 22757
1 79931 9401
1 3170 64557
1 91977 9401
1 29748 5866
1 97251 64557
1 91021 81309
1 5866 58953
1 30374 81309
1 85209 82551
1 27514 85209
1 98845 78490
1 41907 98875
1 32428 21295
1 32428 91223
1 81200 92353
1 75918 78490
1 15971 15373
1 92353 117...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
197
-1
167
-1
280
-1
221
-1
73
-1
-1
-1
115
-1
-1
226
191
213
35
-1
188
27
30
441
59
8
149
151
220
390
302
288
354
-1
241
179
4
103
-1
-1
-1
-1
121
-1
-1
-1
-1
130
124
1332
75
279
172
813
-1
507
202
153
577
-1
252
512
237
1
232
180
124
247
295
46...

result:

ok 160000 lines

Test #60:

score: 0
Accepted
time: 85ms
memory: 25080kb

input:

100000 244988
1 47337 5583
1 65111 39285
1 47337 63792
1 82001 67975
1 57026 30268
1 27298 57026
1 3909 31173
1 5823 67975
1 31173 2626
1 46403 57879
1 44557 57879
1 77895 28645
1 77895 44239
1 56489 82108
1 82108 7556
1 87120 91577
1 91577 47450
1 56265 33626
1 47982 63523
1 56265 19220
1 1442 1295...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
99
-1
338
-1
-1
-1
-1
17
181
355
1
-1
380
142
260
150
-1
-1
918
152
-1
225
-1
141
-1
129
313
155
-1
698
348
345
214
254
819
65
604
146
-1
-1
149
236
6
270
1064
243
599
-1
161
815
56
-1
-1
452
898
46
180
-1
996
255
162
271
156
405
1188
548
847
468
1824
453
841
703
...

result:

ok 140000 lines

Test #61:

score: 0
Accepted
time: 82ms
memory: 24412kb

input:

100000 260787
2 76899 92534
1 4079 36495
1 4079 77727
1 94363 60297
1 27040 60297
1 61704 4079
1 22819 22268
1 18116 22268
1 21791 22268
1 34284 76057
1 17025 76057
1 68429 49919
1 45554 2629
1 3085 48042
1 12900 40915
1 7330 2629
1 5759 3085
1 39277 6745
1 11931 7862
1 22455 8086
1 6745 85020
1 808...

output:

-1
-1
-1
-1
-1
-1
-1
-1
79
-1
-1
100
13
-1
-1
-1
-1
-1
-1
279
-1
-1
120
-1
-1
12
-1
-1
-1
-1
292
7
-1
229
5
4
42
149
429
-1
-1
-1
-1
-1
238
127
-1
231
201
285
232
90
-1
142
-1
32
87
81
301
401
51
272
86
118
-1
542
-1
78
717
20
185
3
402
-1
36
605
101
47
385
194
-1
152
107
12
285
135
9
-1
69
182
656
...

result:

ok 160000 lines

Extra Test:

score: 0
Extra Test Passed