QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226481#7330. Territory GamePPP#AC ✓532ms56304kbC++175.1kb2023-10-25 23:42:412023-10-25 23:42:41

Judging History

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

  • [2023-10-25 23:42:41]
  • 评测
  • 测评结果:AC
  • 用时:532ms
  • 内存:56304kb
  • [2023-10-25 23:42:41]
  • 提交

answer

//#ifdef DEBUG
//#define _GLIBCXX_DEBUG
//#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

#define pb push_back

typedef long long ll;
typedef long double ld;
const int maxN = 2e5 + 10;
int n, q;

vector<int> g[maxN];
int h[maxN];
const int LOG = 19;
int up[LOG][maxN];
void dfs(int v, int p) {
    for (int to : g[v]) {
        if (to == p) continue;
        h[to] = h[v] + 1;
        up[0][to] = v;
        dfs(to, v);
    }
}
int lca(int a, int b) {
    if (h[a] < h[b]) swap(a, b);
    for (int k = LOG - 1; k >= 0; k--) {
        if (h[a] - (1 << k) >= h[b]) a = up[k][a];
    }
    if (a == b) return a;
    for (int k = LOG - 1; k >= 0; k--) {
        if (up[k][a] != up[k][b]) {
            a = up[k][a];
            b = up[k][b];
        }
    }
    return up[0][a];
}
int dist(int x, int y) {
    return h[x] + h[y] - 2 * h[lca(x, y)];
}
pair<int,int> mrg(pair<int,int> a, int x) {
    int D = dist(a.first, a.second);
    int D1 = dist(a.first, x);
    int D2 = dist(a.second, x);
    if (D2 >= D1 && D2 > D) {
        a.first = x;
    }
    else if (D1 > D2 && D1 > D) {
        a.second = x;
    }
    return a;
}
pair<int,int> sub[maxN];
void dfs1(int v, int p) {
    sub[v] = {v, v};
    for (int to : g[v]) {
        if (to == p) continue;
        dfs1(to, v);
        sub[v] = mrg(sub[v], sub[to].first);
        sub[v] = mrg(sub[v], sub[to].second);
    }
}
pair<int,int> up_sub[maxN];
void dfs2(int v, int p) {
    vector<int> sons;
    for (int to : g[v]) {
        if (to == p) continue;
        sons.emplace_back(to);
    }
    vector<pair<int,int>> pref(sons.size() + 1, make_pair(v, v));
    if (v != 1) {
        pref[0] = mrg(pref[0], up_sub[v].first);
        pref[0] = mrg(pref[0], up_sub[v].second);
    }
//    if (v == 2) {
//        cout << pref[0].first << " " << pref[0].second << " ??? " << " " << up_sub[v].first << " " << up_sub[v].second << endl;
//    }
    vector<pair<int,int>> suf(sons.size() + 1, make_pair(v, v));
    for (int z = 0; z < sons.size(); z++) {
        pref[z + 1] = pref[z];
        pref[z + 1] = mrg(pref[z + 1], sub[sons[z]].first);
        pref[z + 1] = mrg(pref[z + 1], sub[sons[z]].second);
    }
    for (int z = sons.size() - 1; z >= 0; z--) {
        suf[z] = suf[z + 1];
        suf[z] = mrg(suf[z], sub[sons[z]].first);
        suf[z] = mrg(suf[z], sub[sons[z]].second);
    }
    for (int z = 0; z < sons.size(); z++) {
        up_sub[sons[z]] = pref[z];
//        if (sons[z] == 3) {
//            cout << pref[z].first << " " << pref[z].second << " CHECK " << endl;
//        }
        up_sub[sons[z]] = mrg(up_sub[sons[z]], suf[z + 1].first);
        up_sub[sons[z]] = mrg(up_sub[sons[z]], suf[z + 1].second);
        dfs2(sons[z], v);
    }
}
int ans(int u, int v, int k) {
    int l = lca(u, v);
//    cout << " HI " << u << " " << v << " " << k << " " << up_sub[2].first << " " << up_sub[2].second <<endl;
    if (k >= h[u] + h[v] - 2 * h[l]) return -1;
    assert(k >= 0 && k <= h[u] + h[v] - 2 * h[l] - 1);
    k++;
    if (k <= h[u] - h[l]) {
        k--;
        for (int z = LOG - 1; z >= 0; z--) {
            if (k & (1 << z)) {
                u = up[z][u];
            }
        }
//        cout << " GET " << u << " " << up_sub[u].first << " " << up_sub[u].second << endl;
        int D = max(dist(up_sub[u].first, v), dist(up_sub[u].second, v));
        return D;
    }
    else {
        k -= (h[u] - h[l]);
        assert(k > 0);
        k = (h[v] - h[l]) - k;
        u = v;
        for (int z = LOG - 1; z >= 0; z--) {
            if (k & (1 << z)) {
                u = up[z][u];
            }
        }
        int D = max(dist(sub[u].first, v), dist(sub[u].second, v));
        return D;
    }
}
void solve() {
    for (int i = 1; i <= n; i++) {
        g[i].clear();
    }
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    dfs(1, -1);
    for (int k = 0; k + 1 < LOG; k++) {
        for (int i = 1; i <= n; i++) {
            up[k + 1][i] = up[k][up[k][i]];
        }
    }
    dfs1(1, -1);
    dfs2(1, -1);
    while (q--) {
        int a, b, k;
        cin >> a >> b >> k;
        if (h[a]%2==h[b]%2)
        {
            if (k%2==1)
            {
                cout << 1 << "\n";
                continue;
            }
            int A = ans(b,a,k/2);
            if (A<k/2)
            {
                cout << -1 << "\n";
            } else cout << 0 << "\n";
        }
        else
        {
            if (k%2==0)
            {
                cout << 0 << "\n";
                continue;
            }
            int A = ans(a,b,k/2+1);
            if (A<k/2)
            {
                cout << 2 << "\n";
            } else cout << 1 << "\n";
        }
    }

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    while (cin >> n >> q) {
        solve();
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 25272kb

input:

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

output:

1
0
2

result:

ok 3 number(s): "1 0 2"

Test #2:

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

input:

2 8
1 2
1 2 1
1 2 2
1 2 3
1 2 4
2 1 1
2 1 2
2 1 3
2 1 4

output:

2
0
2
0
2
0
2
0

result:

ok 8 numbers

Test #3:

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

input:

3 36
1 3
1 2
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 3 1
1 3 2
1 3 3
1 3 4
1 3 5
1 3 6
2 1 1
2 1 2
2 1 3
2 1 4
2 1 5
2 1 6
2 3 1
2 3 2
2 3 3
2 3 4
2 3 5
2 3 6
3 1 1
3 1 2
3 1 3
3 1 4
3 1 5
3 1 6
3 2 1
3 2 2
3 2 3
3 2 4
3 2 5
3 2 6

output:

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

result:

ok 36 numbers

Test #4:

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

input:

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

output:

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

result:

ok 192 numbers

Test #5:

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

input:

5 200
4 1
4 3
4 5
4 2
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 2 8
1 2 9
1 2 10
1 3 1
1 3 2
1 3 3
1 3 4
1 3 5
1 3 6
1 3 7
1 3 8
1 3 9
1 3 10
1 4 1
1 4 2
1 4 3
1 4 4
1 4 5
1 4 6
1 4 7
1 4 8
1 4 9
1 4 10
1 5 1
1 5 2
1 5 3
1 5 4
1 5 5
1 5 6
1 5 7
1 5 8
1 5 9
1 5 10
2 1 1
2 1 2
2 1 3
2 1 4
2 1 5
2 1 ...

output:

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

result:

ok 600 numbers

Test #6:

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

input:

6 360
6 3
3 5
5 4
6 2
2 1
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 2 8
1 2 9
1 2 10
1 2 11
1 2 12
1 3 1
1 3 2
1 3 3
1 3 4
1 3 5
1 3 6
1 3 7
1 3 8
1 3 9
1 3 10
1 3 11
1 3 12
1 4 1
1 4 2
1 4 3
1 4 4
1 4 5
1 4 6
1 4 7
1 4 8
1 4 9
1 4 10
1 4 11
1 4 12
1 5 1
1 5 2
1 5 3
1 5 4
1 5 5
1 5 6
1 5 7
1 5 8
1...

output:

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

result:

ok 2520 numbers

Test #7:

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

input:

7 588
7 6
6 1
1 4
7 2
2 5
2 3
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 2 8
1 2 9
1 2 10
1 2 11
1 2 12
1 2 13
1 2 14
1 3 1
1 3 2
1 3 3
1 3 4
1 3 5
1 3 6
1 3 7
1 3 8
1 3 9
1 3 10
1 3 11
1 3 12
1 3 13
1 3 14
1 4 1
1 4 2
1 4 3
1 4 4
1 4 5
1 4 6
1 4 7
1 4 8
1 4 9
1 4 10
1 4 11
1 4 12
1 4 13
1 4 14
1 5...

output:

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

result:

ok 6468 numbers

Test #8:

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

input:

8 896
8 1
1 3
3 2
8 6
8 7
8 4
8 5
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 2 8
1 2 9
1 2 10
1 2 11
1 2 12
1 2 13
1 2 14
1 2 15
1 2 16
1 3 1
1 3 2
1 3 3
1 3 4
1 3 5
1 3 6
1 3 7
1 3 8
1 3 9
1 3 10
1 3 11
1 3 12
1 3 13
1 3 14
1 3 15
1 3 16
1 4 1
1 4 2
1 4 3
1 4 4
1 4 5
1 4 6
1 4 7
1 4 8
1 4 9
1 4 10...

output:

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

result:

ok 25984 numbers

Test #9:

score: 0
Accepted
time: 11ms
memory: 25336kb

input:

9 1296
5 4
4 2
2 3
2 8
5 1
1 7
1 9
5 6
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 2 8
1 2 9
1 2 10
1 2 11
1 2 12
1 2 13
1 2 14
1 2 15
1 2 16
1 2 17
1 2 18
1 3 1
1 3 2
1 3 3
1 3 4
1 3 5
1 3 6
1 3 7
1 3 8
1 3 9
1 3 10
1 3 11
1 3 12
1 3 13
1 3 14
1 3 15
1 3 16
1 3 17
1 3 18
1 4 1
1 4 2
1 4 3
1 4 4
1 4...

output:

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

result:

ok 60912 numbers

Test #10:

score: 0
Accepted
time: 319ms
memory: 23412kb

input:

5000 5000
2064 4325
667 740
3177 394
2334 1488
2691 4373
401 3052
2406 2326
2532 3838
542 135
162 1340
3644 1935
2376 1026
3322 1573
3156 2500
4625 1315
59 952
2168 2756
263 607
4023 571
4630 197
1915 4527
2629 3365
1371 2517
1592 1134
1716 112
3822 986
4147 3298
3337 4593
4739 416
2721 4801
2662 45...

output:

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

result:

ok 200000 numbers

Test #11:

score: 0
Accepted
time: 334ms
memory: 26388kb

input:

5000 5000
4455 4458
1192 1180
4739 4748
241 258
3516 3526
2659 2660
3096 3101
4633 4624
4686 4677
4203 4195
2754 2758
1935 1936
2118 2122
2074 2072
4261 4257
2274 2270
2004 2017
3474 3479
4384 4381
610 608
3125 3132
1869 1862
4345 4349
2236 2233
2794 2802
4290 4291
338 337
4893 4897
817 827
1582 161...

output:

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

result:

ok 200000 numbers

Test #12:

score: 0
Accepted
time: 532ms
memory: 33300kb

input:

200000 200000
92730 181199
38837 182835
71312 108585
121481 98424
183932 119127
120539 155369
2127 151235
104887 121805
82050 2595
119129 2759
89663 129962
115544 198800
50651 114956
12187 129275
64082 120776
140999 14404
147807 70230
181718 86055
34952 4311
140250 2200
197157 191802
51357 123986
10...

output:

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

result:

ok 200000 numbers

Test #13:

score: 0
Accepted
time: 475ms
memory: 33300kb

input:

200000 200000
186204 169159
89116 86263
40883 48037
98340 103172
171991 172107
182256 185416
78988 79480
115828 116943
198265 196946
95775 94930
111689 103330
130493 133063
1472 1816
177860 182285
101084 100197
21242 24282
115855 119323
81061 79093
53111 43245
93597 80079
73467 67956
188540 195931
1...

output:

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

result:

ok 200000 numbers

Test #14:

score: 0
Accepted
time: 422ms
memory: 33576kb

input:

200000 200000
32111 32145
22582 22497
169745 169556
184886 183841
173772 173435
97857 98150
80637 81340
54274 54876
132013 132771
864 72
185645 185595
41190 41165
128186 128199
106132 106829
97304 97342
136071 136088
196699 196533
118059 117861
26758 27069
142601 142234
198168 198456
175480 175629
1...

output:

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

result:

ok 200000 numbers

Test #15:

score: 0
Accepted
time: 437ms
memory: 35388kb

input:

200000 200000
185586 185596
13361 13332
6195 6242
135359 135364
132597 132592
149835 149832
130613 130617
119157 119174
95116 95105
29289 29308
63123 63124
184901 184972
96469 96489
123113 123121
197521 197630
88723 88918
50261 50249
17243 17167
185636 185622
21850 21861
165058 165014
186796 186745
...

output:

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

result:

ok 200000 numbers

Test #16:

score: 0
Accepted
time: 511ms
memory: 56304kb

input:

200000 200000
92192 92196
167616 167617
58244 58245
112443 112441
45046 45045
64045 64046
38826 38827
89663 89662
57217 57215
189516 189518
19828 19827
23699 23700
127710 127707
91194 91195
109553 109555
115068 115069
74104 74105
131070 131071
150412 150411
64557 64560
96402 96400
137438 137437
3960...

output:

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

result:

ok 200000 numbers

Extra Test:

score: 0
Extra Test Passed