QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#334024#2210. Hamilton Pathhos_lyricTL 3741ms19108kbC++145.3kb2024-02-21 00:22:462024-02-21 00:22:46

Judging History

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

  • [2024-02-21 00:22:46]
  • 评测
  • 测评结果:TL
  • 用时:3741ms
  • 内存:19108kb
  • [2024-02-21 00:22:46]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  bool operator<(const ModInt &a) const { return (x < a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 1000000007;
using Mint = ModInt<MO>;


int N, M;
vector<pair<int, int>> E;

vector<vector<int>> graph, hparg;

vector<pair<int, Mint>> ans;

void go(int src) {
  int len = 0;
  Mint key = 0;
  vector<int> vis(N, 0);
  for (int u = src; ; ) {
    (key *= 10) += (u + 1);
    vis[u] = 1;
    if (++len == N) break;
    int vm = -1;
    for (const int v : graph[u]) if (!vis[v]) {
      if (~vm) return;
      vm = v;
    }
    if (!~vm) return;
    u = vm;
  }
  ans.emplace_back(src, key);
}

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d%d", &N, &M);
    E.resize(M);
    for (int i = 0; i < M; ++i) {
      scanf("%d%d", &E[i].first, &E[i].second);
      --E[i].first;
      --E[i].second;
    }
    sort(E.begin(), E.end());
    E.erase(unique(E.begin(), E.end()), E.end());
    M = E.size();
    
    graph.assign(N, {});
    hparg.assign(N, {});
    for (int i = 0; i < M; ++i) {
      const int u = E[i].first, v = E[i].second;
      graph[u].push_back(v);
      hparg[v].push_back(u);
    }
    
    ans.clear();
    
    for (int u = 0; u < N; ++u) go(u);
    
// cerr<<"ans = "<<ans<<endl;
    sort(ans.begin(), ans.end());
    printf("%d\n", (int)ans.size());
    if (ans.size()) {
      for (int i = 0; i < (int)ans.size(); ++i) {
        if (i) printf(" ");
        printf("%u", ans[i].second.x);
      }
      puts("");
    }
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

詳細信息

Test #1:

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

input:

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

output:

2
13425 34251

result:

ok 3 number(s): "2 13425 34251"

Test #2:

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

input:

67777
9 32
6 3
5 2
7 3
7 8
5 2
5 2
7 8
8 2
7 3
8 9
4 3
2 3
4 3
3 1
1 3
8 3
9 8
3 2
5 6
4 5
9 4
6 7
2 8
5 4
5 3
7 8
5 1
6 9
8 3
6 9
7 8
4 1
5 12
3 5
2 3
4 5
2 5
5 3
1 4
3 2
2 4
1 4
4 1
2 5
4 5
2 10
1 2
1 2
1 2
2 1
1 2
1 2
1 2
1 2
1 2
1 2
10 28
1 9
5 9
6 1
10 5
8 7
1 4
7 10
7 5
6 8
9 4
2 9
6 4
2 6
1 1...

output:

1
132894567
2
14532 53241
2
12 21
1
594731198
1
74123568
2
12 21
1
6241735
1
1
1
513264
1
7241356
2
213 312
1
247381965
1
123
1
31524
2
12 21
1
1
1
12
2
132 231
1
41268753
1
245378846
1
526134
1
413652
1
12345
1
31542
2
12 21
1
5624713
1
4675213
3
202947333 852029431 520294680
1
312
1
427915798
2
21...

result:

ok 148279 numbers

Test #3:

score: 0
Accepted
time: 160ms
memory: 3768kb

input:

90961
2 4
2 1
2 1
2 1
2 1
4 8
4 3
2 1
4 3
1 2
4 1
1 4
1 2
4 2
5 22
1 3
5 2
3 1
3 4
3 4
2 3
2 4
3 2
5 4
5 3
4 3
2 1
1 4
1 2
1 3
2 1
4 5
4 3
1 5
5 3
2 3
4 5
8 22
1 4
3 8
8 6
5 7
5 6
1 3
1 2
8 5
8 3
5 2
6 5
2 5
6 1
6 7
5 4
2 4
4 1
6 3
4 3
8 1
6 5
7 6
10 7
10 8
9 3
10 5
4 6
10 7
10 3
3 1
8 28
7 8
8 5
6 ...

output:

1
21
1
2143
0
0
0
0
1
1
2
12 21
0
0
0
0
2
12 21
1
1
0
0
1
1
0
0
0
0
0
1
1
0
0
1
213
0
0
0
1
1
0
0
0
2
123 231
2
12 21
0
0
1
2413
0
0
0
1
1
1
1
2
12 21
0
0
0
0
1
213
0
0
1
132
0
2
12 21
0
0
1
1
1
1
0
0
0
0
1
21
0
2
12 21
1
34152
0
0
1
1
0
0
1
1
0
1
1
0
0
0
0
0
1
1
0
0
0
0
2
12 21
0
0
1
1
0
1
123
0
0
...

result:

ok 124496 numbers

Test #4:

score: 0
Accepted
time: 161ms
memory: 3772kb

input:

64460
7 24
6 7
1 3
2 1
5 6
7 5
2 5
4 2
3 1
3 4
1 5
7 6
1 7
1 6
7 2
2 7
4 5
4 3
6 5
7 6
3 1
7 5
2 7
1 7
1 2
7 18
6 2
7 5
3 4
4 5
2 1
6 2
7 6
7 6
5 7
7 6
3 2
1 2
7 2
5 2
1 6
5 1
3 6
3 6
2 4
2 1
2 1
1 2
2 1
5 26
5 1
3 1
5 2
1 4
3 5
2 1
3 4
3 5
1 4
3 4
2 1
2 3
1 4
2 1
1 4
2 4
1 2
3 1
5 2
2 1
4 1
3 4
3 1...

output:

1
5672134
0
2
12 21
1
41235
1
15324
2
1764352 7643521
1
1234
1
374219658
1
264531
1
812937456
1
132
1
1
2
12 21
1
6174235
1
134800596
1
273591684
1
321
0
2
12 21
1
625143
1
1
1
213
1
872632014
1
612345
1
65384172
1
193248657
1
786034249
1
85462731
1
231
1
31542
1
574618392
1
376952184
1
3467512
1
42...

result:

ok 132329 numbers

Test #5:

score: 0
Accepted
time: 165ms
memory: 4040kb

input:

67484
4 19
1 3
4 3
2 3
2 3
4 3
2 3
3 4
4 1
4 1
2 4
2 3
2 1
4 1
4 1
4 3
4 2
4 1
2 1
3 1
10 23
8 4
6 4
6 5
3 2
10 9
5 4
9 5
7 10
8 1
2 6
5 4
2 9
8 4
6 2
5 7
6 3
2 4
9 4
7 1
10 1
4 8
5 2
1 7
2 10
2 1
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 0
8 22
5 4
5 4
6 2
3 2
6 1
8 5
2 3
5 3
7 4
2 6
2 3
5 4
5 6
5 3
1 ...

output:

1
1342
1
818095235
2
12 21
1
1
1
32617485
1
3142
2
12 21
1
3214567
1
218350734
1
824796351
1
5173264
1
1
1
123
1
623918456
2
12 21
1
2613475
1
491303652
1
983561724
1
123
3
652314987 765231498 876523149
1
1
1
68451732
1
34125876
1
1
2
231 312
2
123 312
1
81457263
1
3214
1
1
2
12 21
1
520462889
1
715...

result:

ok 147424 numbers

Test #6:

score: 0
Accepted
time: 160ms
memory: 4056kb

input:

90788
3 3
2 1
2 3
1 3
5 18
3 2
5 4
4 3
4 3
5 3
3 5
3 4
2 1
2 1
3 2
5 3
4 5
3 5
1 5
3 2
5 2
1 4
2 5
7 4
1 2
5 1
6 7
7 6
8 11
5 4
7 8
4 6
2 3
6 3
2 5
2 6
3 1
7 4
4 7
6 3
8 2
6 8
1 4
5 4
2 5
2 4
1 4
1 3
10 18
5 6
8 5
9 4
4 1
4 8
4 9
6 5
10 8
2 7
2 3
5 10
4 10
8 4
2 1
2 8
2 4
2 3
5 8
8 17
4 6
4 1
2 5
8 ...

output:

0
0
0
0
0
0
0
0
0
0
1
21
0
0
0
0
1
1
0
0
1
213
0
2
12 21
0
0
0
0
1
1432
0
0
0
2
213 321
0
0
0
2
12 21
0
2
12 21
0
0
1
52143
2
12 21
0
2
12 21
1
321
1
1
1
1
0
0
0
0
0
0
1
1
1
321
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
1
321
0
2
12 21
2
12 21
0
0
0
1
321456
0
1
132
1
213
2
12 21
0
0
0
0
0
0
1
1
0
0
0
0
1
1
0
0...

result:

ok 124312 numbers

Test #7:

score: 0
Accepted
time: 162ms
memory: 3784kb

input:

64767
2 2
1 2
1 2
6 22
4 6
4 2
2 6
1 2
2 6
1 3
5 2
5 3
5 6
1 4
2 1
4 2
2 6
6 3
3 6
5 3
6 3
2 3
6 3
5 6
4 2
6 5
8 14
5 8
7 1
8 3
3 5
1 3
5 7
1 6
2 5
6 4
8 2
3 7
2 1
6 5
4 3
5 10
3 4
4 5
2 4
2 3
2 3
5 1
1 3
3 2
2 5
2 1
8 16
2 3
6 8
2 4
5 8
7 4
3 4
2 1
1 5
1 2
4 5
2 4
8 6
6 3
7 2
7 2
2 7
3 19
1 3
1 2
3...

output:

1
12
1
365214
0
1
45132
0
1
231
1
3742516
1
1
7
1437625 2514376 3762514 4376251 5143762 6251437 7625143
1
6271354
1
789165432
1
354612
1
45123
0
1
618432975
1
891270509
1
6521374
0
1
213
1
1243
2
12 21
0
1
351462
1
4356127
1
1324
1
231
1
3412
1
942367815
1
123
1
213
1
45321
1
261435
1
803869097
1
32...

result:

ok 132887 numbers

Test #8:

score: 0
Accepted
time: 173ms
memory: 3772kb

input:

67812
6 32
2 3
4 6
1 2
2 4
2 6
3 4
1 4
4 5
1 5
3 6
1 6
6 3
3 6
2 6
4 5
5 6
2 3
1 3
2 6
1 2
2 4
2 1
1 2
4 6
1 2
2 6
3 6
1 4
2 6
2 3
4 3
4 2
7 31
6 3
4 7
1 4
6 4
3 2
6 2
2 5
3 4
2 3
6 2
5 7
7 4
6 2
1 4
1 6
1 3
4 3
4 7
6 1
1 2
5 3
3 4
3 4
5 1
1 4
5 4
2 7
4 7
1 5
5 4
6 1
7 19
1 2
1 4
3 5
1 6
1 4
2 5
1 7...

output:

1
563421
1
7432516
1
7532416
1
4257316
2
12 21
1
5463721
1
1
1
51672348
1
38174562
1
183005348
1
51463278
1
2314
1
428691705
1
2314
1
209642804
1
23514
1
1
1
613524
2
419682357 682357194
2
12 21
1
625341
1
1
1
3245671
2
132 231
1
21
1
6152347
2
12 21
1
781704274
1
86432157
1
24135
1
47316852
1
54836...

result:

ok 148213 numbers

Test #9:

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

input:

91345
2 12
2 1
2 1
2 1
1 2
2 1
2 1
2 1
1 2
2 1
2 1
1 2
2 1
2 2
2 1
1 2
7 24
1 2
4 6
5 2
7 1
2 4
3 6
6 4
7 4
4 3
2 4
6 1
6 1
3 7
4 3
7 1
2 7
1 3
7 1
7 4
5 1
5 7
6 7
6 7
1 4
3 4
1 3
1 3
1 2
1 3
7 22
7 5
4 1
5 1
2 1
7 2
3 5
6 7
4 2
4 7
1 4
1 6
5 4
1 6
2 7
1 3
6 3
7 2
1 4
4 2
1 2
6 3
3 5
5 17
1 5
2 5
4 ...

output:

2
12 21
2
12 21
0
0
0
1
34521
0
1
1
0
0
0
1
1
0
0
0
0
0
0
0
0
0
2
12 21
0
0
2
12 21
2
12 21
0
0
1
12
1
1
1
2143
2
12 21
0
2
12 21
0
0
0
2
12 21
0
0
2
12 21
0
0
0
0
2
12 21
0
0
0
0
1
4312
2
12 21
0
0
0
0
0
2
12 21
1
1
1
123
0
0
0
0
0
0
2
12 21
0
0
1
31254
0
0
0
0
0
0
0
0
0
0
2
12 21
1
1
0
1
3476521
0...

result:

ok 125201 numbers

Test #10:

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

input:

64447
3 4
1 2
2 3
3 1
3 2
6 21
4 3
4 6
6 3
3 5
4 6
6 2
1 5
2 5
1 5
3 4
5 2
3 1
3 1
1 6
1 5
4 1
5 1
4 2
4 6
3 6
6 5
6 13
3 2
4 1
6 5
3 5
2 5
5 2
5 3
3 4
6 3
6 5
1 6
4 3
3 2
8 32
7 3
4 2
1 4
7 4
5 4
7 1
4 3
5 6
1 4
3 4
4 2
5 7
1 7
1 7
7 8
1 4
5 1
8 6
3 8
2 8
3 7
3 4
5 4
1 7
3 6
7 6
1 3
1 5
3 2
3 6
6 4...

output:

2
123 231
1
251634
1
253416
1
28643715
1
231
3
35124 43512 51243
1
15234
1
312
1
5237461
1
15432
0
1
37645812
2
12 21
0
1
718392465
2
12 21
1
3124
0
1
312
1
684297513
1
41682735
1
42178356
1
231
2
21436875 36875142
1
532896471
1
261453
1
542631
1
1473526
1
24513
1
12
1
590917604
2
12 21
3
425736819 ...

result:

ok 132279 numbers

Test #11:

score: 0
Accepted
time: 165ms
memory: 4008kb

input:

67818
6 23
2 6
2 5
3 5
4 5
2 1
2 3
3 5
2 4
3 4
5 4
4 6
1 2
2 4
3 6
2 5
6 5
1 6
3 1
6 3
2 6
6 5
4 5
1 5
9 11
8 7
3 2
8 3
6 7
4 3
1 5
5 8
8 9
6 3
7 1
2 6
9 26
8 5
6 5
4 3
3 9
5 1
2 4
4 2
6 3
6 8
2 3
8 1
2 3
4 6
4 1
7 5
8 4
5 9
1 3
7 9
9 7
1 6
8 9
5 9
8 5
2 8
2 3
6 9
1 3
3 4
1 6
5 6
2 1
4 6
4 2
4 1
6 2...

output:

1
546312
1
432671589
1
397516842
1
562134
1
321
3
132 213 321
1
652978480
1
7426315
1
1675342
2
317289456 894562173
1
231
1
681429753
1
13654827
1
123
1
132
1
321645
1
7132654
1
81492334
1
431526
1
4321
1
437295681
1
24786315
1
562143
1
4231
1
7154362
1
83271456
1
132
1
1
1
520678921
1
4261753
1
185...

result:

ok 148279 numbers

Test #12:

score: 0
Accepted
time: 163ms
memory: 4004kb

input:

91112
1 0
9 19
2 7
7 9
2 8
6 5
4 5
2 4
8 1
1 9
1 8
4 2
2 8
7 4
9 3
9 3
8 1
8 5
1 7
6 8
3 5
1 0
4 17
1 2
4 3
3 4
1 2
1 3
1 3
3 4
1 4
2 3
4 2
2 1
3 4
1 4
1 3
1 2
2 4
3 1
3 5
2 1
1 2
3 1
3 2
3 1
4 5
2 1
3 1
1 3
3 4
3 2
3 22
3 2
2 3
2 3
3 2
1 2
1 3
2 1
2 1
3 2
1 2
1 2
3 1
3 2
3 2
2 3
1 2
2 1
1 3
2 1
3 2...

output:

1
1
0
1
1
0
0
1
2134
0
2
12 21
1
1
0
0
0
0
0
1
1
0
0
1
1
0
2
12 21
1
21
0
0
0
0
0
0
0
0
0
1
2431
0
0
0
0
2
12 21
1
1
0
0
0
0
0
2
12 21
0
0
0
0
0
0
2
12 21
0
2
12 21
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
2
12 21
1
1
0
0
1
4213
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1342
0
0
0
1
123
0
0
2
12 21
0...

result:

ok 124751 numbers

Test #13:

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

input:

64942
5 15
5 2
5 3
1 4
2 3
2 3
2 3
2 1
2 3
4 3
5 1
5 3
2 5
1 3
3 1
4 5
9 24
6 2
2 6
2 1
6 8
7 2
6 5
7 4
4 2
5 7
1 2
3 9
3 2
8 1
9 4
4 6
7 2
9 6
7 8
4 5
7 2
9 6
9 8
3 5
4 3
8 29
8 7
7 1
7 8
3 7
2 6
1 2
3 8
5 7
6 4
5 1
6 1
5 6
3 4
6 2
3 7
1 4
6 2
8 5
3 5
5 1
5 7
1 4
8 1
7 1
3 1
3 5
5 2
6 7
5 3
1 0
9 3...

output:

1
31452
1
812657439
0
1
1
1
739415826
1
12
1
3142
1
321
1
24513
1
698741532
2
12 21
0
1
859461723
1
25134
1
359174676
2
123 321
1
38267514
1
81753264
1
3214
1
1342
1
35214
1
5314627
1
87634512
1
35612487
1
7314265
1
213
1
123645
1
1
1
314256
1
98674518
1
51734826
1
1
1
749518356
1
312
1
16327854
1
2...

result:

ok 133220 numbers

Test #14:

score: 0
Accepted
time: 161ms
memory: 3760kb

input:

67710
3 11
3 2
3 2
1 2
1 3
3 1
3 2
1 3
3 2
1 2
1 2
2 3
2 13
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
1 2
2 1
8 16
2 7
2 8
3 8
2 1
7 3
2 5
8 4
8 3
5 3
2 7
4 6
7 1
6 7
1 2
7 8
6 8
1 0
9 15
3 1
8 2
4 9
7 9
3 8
2 4
2 8
6 4
9 3
5 1
6 9
6 7
1 5
3 9
5 6
8 25
1 4
6 1
3 2
1 3
1 2
6 5
8 6
6 2
8 1
6 5
1 7
8...

output:

1
231
2
12 21
2
38467125 53846712
1
1
1
824931567
1
32714568
1
387195264
1
2431
1
21453
1
34251
2
12 21
1
572136498
1
154362
1
67482531
1
231
1
25134
1
496021846
2
236154 542361
1
130853701
1
487915193
1
73684512
1
148395726
1
631524
1
83526147
1
123
1
1
2
12 21
1
126534
1
1
1
1
1
21354
2
12 21
1
19...

result:

ok 148022 numbers

Test #15:

score: 0
Accepted
time: 164ms
memory: 4060kb

input:

91134
5 12
5 4
2 3
5 3
3 5
3 4
3 1
3 4
1 3
1 4
1 5
1 5
4 5
2 5
1 2
2 1
1 2
1 2
2 1
4 13
2 4
2 3
2 1
1 3
1 4
4 2
2 4
1 4
2 4
1 3
2 4
3 1
1 4
8 5
3 8
7 4
1 8
6 8
3 8
1 0
3 2
2 1
2 3
3 3
1 2
3 2
2 1
9 9
8 9
6 4
7 4
3 4
4 3
4 7
3 7
7 6
6 1
1 0
7 19
2 4
2 5
6 4
6 2
6 3
2 3
4 2
4 3
4 5
7 4
6 3
5 6
1 7
4 5...

output:

0
2
12 21
1
3142
0
1
1
0
1
321
0
1
1
0
0
2
12 21
1
21
0
2
12 21
0
1
312
2
12 21
0
0
1
132
0
0
0
0
0
0
0
0
0
1
231
0
0
0
0
2
12 21
0
0
0
0
0
0
0
0
1
1
0
0
0
1
1
0
2
12 21
0
0
0
0
1
1
0
0
2
12345 34521
0
0
1
1
0
0
0
0
0
0
0
1
1
0
0
2
12 21
0
0
0
0
0
0
0
0
0
2
12 21
0
0
1
1
0
0
0
0
1
21
0
0
0
0
1
1
0
0...

result:

ok 124996 numbers

Test #16:

score: 0
Accepted
time: 157ms
memory: 4008kb

input:

64745
1 0
6 29
6 1
4 6
2 1
6 2
2 4
2 6
5 1
2 4
2 5
4 3
2 6
6 1
2 6
2 5
1 3
2 5
2 5
2 3
5 4
5 3
3 5
6 3
2 1
2 6
2 6
4 1
2 1
6 3
2 6
3 15
2 3
2 1
3 1
2 1
1 2
2 1
1 3
2 3
2 3
2 3
2 3
1 3
2 3
2 1
1 3
8 28
2 1
2 5
6 8
7 4
3 8
5 1
5 1
3 4
1 7
4 5
5 3
8 3
2 7
2 4
8 5
8 4
6 7
2 8
8 7
8 3
8 5
2 4
2 8
8 6
3 5...

output:

1
1
1
135462
1
312
0
1
1
1
6417325
1
21435
1
153624
2
341526 634152
1
213
1
4123
1
3412
1
7134256
1
13245
1
1374652
1
32145
1
806432103
1
83526714
1
32451
1
814329565
1
165423
1
24531
1
521880892
1
81367452
2
12 21
1
31542
2
12 21
1
132
1
127835467
4
218937465 465218937 521893746 652189374
1
213
1
1...

result:

ok 132955 numbers

Test #17:

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

input:

67788
6 16
1 6
3 5
3 5
5 2
5 4
3 5
5 6
5 3
4 1
1 6
4 5
6 1
3 6
1 2
2 4
3 6
1 0
6 18
1 2
3 2
5 3
5 1
3 6
5 4
2 1
4 3
3 1
3 2
3 1
6 2
5 1
4 5
4 2
3 5
1 3
4 2
2 10
2 1
2 1
2 1
2 1
2 1
2 1
1 2
2 1
2 1
2 1
1 0
2 7
2 1
2 1
2 1
1 2
2 1
2 1
2 1
3 8
1 3
3 2
1 2
3 2
2 1
3 2
1 2
3 2
10 15
3 6
3 5
9 8
4 3
5 10
...

output:

1
612453
1
1
1
621354
2
12 21
1
1
2
12 21
2
213 321
1
607198422
2
1432 3241
1
87645231
2
3412 4123
2
12 21
1
163245
2
3241 4123
2
12 21
2
213 321
1
1
2
12 21
3
482513976 648251397 764825139
1
51342
1
123
1
192574638
2
12 21
1
75418632
1
808163259
1
842965371
2
12 21
1
412365
1
146235
1
45321
1
2134
...

result:

ok 148473 numbers

Test #18:

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

input:

90788
5 17
3 5
5 3
4 5
3 1
5 4
1 5
5 2
2 5
1 5
3 4
5 2
4 5
1 3
4 1
2 5
2 4
2 3
3 9
2 3
2 3
2 1
3 2
2 3
2 1
3 1
3 1
2 1
4 22
4 3
2 1
4 1
2 3
1 4
3 2
4 1
3 2
2 3
3 1
4 3
3 4
1 4
3 2
3 1
4 2
4 3
4 3
1 2
1 3
3 1
4 2
10 12
2 5
10 2
10 7
10 3
2 5
9 10
10 6
5 4
3 10
3 10
1 2
3 10
3 6
1 2
3 1
3 1
3 1
2 3
1 ...

output:

0
0
0
0
3
123 231 312
0
0
0
0
0
0
0
0
0
2
12 21
0
0
0
0
0
1
132
2
12 21
0
0
0
0
1
1
0
0
1
321
0
0
1
1
2
12 21
0
2
12 21
0
0
0
0
0
0
1
123
1
12
0
1
1
1
1
0
0
1
1
0
0
0
0
0
2
12 21
0
0
0
0
0
0
0
0
0
3
132 213 321
0
1
321
0
1
67254138
0
0
0
1
1
0
1
1
0
0
0
0
2
12 21
0
0
0
0
1
1
1
1
0
0
0
0
0
1
123
0
1
...

result:

ok 123950 numbers

Test #19:

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

input:

64720
3 4
1 3
1 2
1 3
3 1
9 24
9 3
2 3
4 7
1 9
7 2
1 3
8 5
8 4
9 1
4 3
4 5
9 3
1 7
5 6
9 8
6 1
4 3
3 4
1 4
8 6
5 7
3 7
8 7
1 3
2 14
1 2
1 2
1 2
1 2
1 2
1 2
2 1
1 2
1 2
1 2
1 2
1 2
1 2
1 2
7 28
4 2
5 4
4 3
6 2
5 4
6 2
4 3
7 1
4 7
6 2
3 2
6 1
4 6
4 6
2 1
7 5
5 2
5 7
2 3
6 4
5 6
1 6
5 4
7 6
6 3
7 2
5 4...

output:

1
312
1
723456198
2
12 21
1
3216475
0
3
2537614 3761425 5376142
1
31842567
2
12 21
1
132
0
1
25431
1
5143627
0
0
1
12
1
36812754
1
217940400
1
123
1
231
0
1
13425
1
273148596
1
312
2
12 21
1
312
1
632145
1
1456327
1
52178364
1
1
2
24135 35124
1
3421
2
12 21
1
352750555
1
264409659
2
12 21
2
12 21
1
...

result:

ok 133219 numbers

Test #20:

score: 0
Accepted
time: 165ms
memory: 3776kb

input:

67944
9 29
5 4
3 1
7 3
7 5
8 4
7 4
8 1
4 1
1 2
5 3
1 6
9 6
9 4
7 5
6 9
8 1
3 5
7 5
5 6
5 7
5 1
7 9
4 6
3 2
5 8
4 9
8 2
2 8
8 3
5 16
4 3
5 4
1 4
5 3
5 1
1 3
5 1
3 4
5 2
5 1
1 5
2 4
4 2
1 3
3 1
5 1
9 33
6 5
3 8
6 7
8 9
2 4
4 8
4 5
2 3
4 3
7 8
7 9
7 1
6 1
7 9
4 3
6 2
1 3
6 9
4 6
6 9
1 7
4 5
4 2
5 7
6 8...

output:

1
694128357
1
24315
1
938715246
1
563412
1
132
1
329546781
1
43512
2
12 21
1
32145
2
123 231
1
782543169
1
213
1
541326
1
123
1
26573481
1
5741263
1
3526174
1
3756412
1
968740500
1
5461237
1
231
1
257198308
1
3214
1
568024263
1
1
1
4312
1
4723615
2
34125 41253
1
321
1
639814527
2
12 21
1
213
1
42156...

result:

ok 148525 numbers

Test #21:

score: 0
Accepted
time: 164ms
memory: 4040kb

input:

90784
2 2
1 2
1 2
10 9
2 10
5 3
4 1
7 9
6 1
10 5
5 2
10 3
10 5
3 10
2 1
3 2
2 3
2 1
1 2
3 2
3 1
1 2
3 2
2 3
7 4
2 1
3 1
6 3
7 5
10 3
2 6
3 10
2 7
9 4
1 7
2 6
2 8
2 4
5 9
5 4
5 2
2 4
5 4
4 5
1 3
3 4
1 4
3 1
8 25
4 3
2 4
6 4
1 7
7 6
3 6
8 4
2 8
3 6
4 6
6 5
7 8
6 5
8 3
4 7
3 1
6 5
4 2
4 1
4 5
4 8
5 6
6...

output:

1
12
0
1
123
0
0
0
0
0
0
0
1
321
0
0
0
0
0
2
12 21
0
0
2
12 21
1
1
0
0
0
2
12 21
2
12 21
0
2
12 21
0
0
0
0
2
12 21
0
1
1
1
1
0
0
1
1
0
0
2
12 21
1
12
0
0
0
2
12 21
0
0
1
1
0
0
1
312
0
0
2
12 21
0
0
0
0
0
1
1
0
0
1
1
2
12 21
0
0
1
1
0
0
0
1
1
0
2
12 21
2
12 21
0
0
0
2
12 21
0
0
1
1
0
0
0
0
1
321
0
0
...

result:

ok 124129 numbers

Test #22:

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

input:

64718
1 0
7 19
3 7
5 7
5 6
7 5
3 6
1 3
1 4
6 7
4 5
1 6
1 3
6 3
4 3
2 1
4 1
4 7
1 3
3 2
3 6
7 11
5 6
6 2
3 7
7 1
2 5
2 3
6 4
6 4
1 6
6 4
4 3
9 17
3 9
6 1
5 4
4 6
1 2
4 6
7 6
1 6
2 7
4 3
8 3
2 8
7 2
8 2
3 8
1 5
9 3
2 16
2 1
2 1
2 1
1 2
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
3 7
3 1
2 1
3 2
2 ...

output:

1
1
1
7563214
1
4371625
1
938276154
2
12 21
2
132 213
1
24531
1
391286754
1
21543
1
341972498
1
1
1
1253467
0
2
785392416 853924167
1
42531
1
64135287
0
1
452916738
1
619375428
2
1243 2431
0
1
460072575
2
12 21
0
1
321
1
836752419
1
34152
1
2431
1
23541
2
3412 4123
0
2
12 21
2
12 21
1
2134
1
632541
...

result:

ok 133061 numbers

Test #23:

score: 0
Accepted
time: 160ms
memory: 3708kb

input:

67838
5 15
4 2
1 4
3 4
2 1
2 5
5 1
3 2
2 4
4 1
4 1
2 1
2 3
3 4
1 5
4 1
7 25
6 4
1 2
6 3
5 4
6 7
3 7
3 4
6 3
5 6
2 5
5 1
6 7
6 7
7 3
5 4
6 5
6 2
5 4
5 3
2 1
2 4
4 3
4 1
5 2
4 3
10 32
2 1
7 6
10 7
9 7
5 8
4 10
3 9
5 9
5 6
4 2
9 6
9 8
4 3
5 2
3 7
5 6
3 5
10 1
6 2
9 10
3 5
4 7
9 2
4 1
9 6
10 4
1 8
8 7
5...

output:

1
51423
1
7341256
1
762159987
1
34612578
1
5364721
1
690035420
3
1756234 4175623 7562341
1
971260441
1
312
1
3412
1
493562178
1
1
1
1
1
312456
1
231
1
679905391
6
164532 216453 321645 453216 532164 645321
1
132
1
4231
1
43521
1
1243
1
52341
1
17458236
1
748195263
1
1
2
14735268 68273514
1
903421753
...

result:

ok 148527 numbers

Test #24:

score: 0
Accepted
time: 163ms
memory: 3756kb

input:

91081
10 26
5 8
3 8
7 1
2 4
1 2
10 9
4 1
9 6
1 7
5 3
8 4
7 5
1 3
10 1
8 2
10 8
8 7
2 5
2 4
1 2
10 7
3 4
5 1
2 8
9 2
6 8
10 2
7 9
1 7
5 17
1 5
5 2
4 1
2 3
5 4
2 4
2 4
4 3
1 3
4 1
4 2
3 2
3 4
4 1
1 2
4 1
4 5
1 0
6 12
3 1
6 5
5 4
5 6
3 4
6 1
4 3
2 5
1 6
1 4
3 4
1 4
8 14
5 7
5 7
2 3
3 6
1 2
7 6
7 4
5 7
...

output:

0
0
0
1
1
0
0
1
1
1
1
0
0
0
0
1
1
0
1
1
0
0
0
0
2
12 21
1
21
0
0
0
0
0
1
321
0
0
0
0
1
1
0
0
2
12 21
0
0
0
0
0
2
12 21
0
0
0
0
0
1
1
0
1
1
0
0
0
0
0
0
0
1
3421
0
2
12 21
0
0
0
1
1
0
0
0
0
0
0
2
231 312
0
2
12 21
0
0
0
0
2
12 21
0
1
1
0
0
0
0
2
12 21
2
12 21
0
2
123 321
0
1
1
2
12 21
1
1
0
1
1
0
0
0
...

result:

ok 124817 numbers

Test #25:

score: 0
Accepted
time: 161ms
memory: 3792kb

input:

64614
7 21
1 4
1 5
6 1
6 7
1 6
1 3
6 1
6 3
6 5
5 3
7 2
6 3
4 7
2 5
3 4
7 5
6 7
4 2
1 2
1 7
7 1
10 28
5 9
3 2
9 6
4 1
9 3
5 8
7 6
5 8
7 1
10 9
6 4
5 2
9 6
10 4
6 8
2 7
2 4
5 10
10 7
8 7
3 9
5 6
10 9
10 1
1 8
3 8
2 5
6 9
10 30
7 4
3 1
4 5
7 2
8 4
7 10
4 1
8 3
1 4
2 6
1 2
7 5
6 10
3 2
7 5
3 2
10 7
1 2
...

output:

1
2534716
1
187693232
0
1
825619783
2
152364 523641
1
4231
1
213
1
462351
1
1
1
132
0
0
1
594376821
0
1
650053133
1
326154
1
1362745
1
4123
1
1
1
859732146
1
792814365
1
27534618
1
87265134
1
745628139
1
4123
1
5673241
1
1
1
45231
2
12 21
1
1
1
65713842
1
645803749
1
3657421
1
296458731
2
15423 3215...

result:

ok 132652 numbers

Test #26:

score: 0
Accepted
time: 165ms
memory: 4040kb

input:

67618
3 10
3 2
3 1
3 1
2 3
3 1
3 1
1 2
2 1
3 2
3 1
10 9
3 4
5 9
9 7
2 10
8 5
10 3
7 6
6 1
1 2
10 28
2 4
7 4
4 2
1 8
4 6
4 8
5 2
6 2
3 5
8 2
9 5
6 1
1 4
1 9
7 8
9 8
10 7
7 5
10 8
2 8
4 2
3 5
5 3
5 8
5 8
9 8
5 2
3 10
5 25
4 2
4 3
5 1
4 1
4 2
2 1
5 2
3 1
2 3
3 1
3 4
3 2
1 5
2 5
2 1
3 2
5 1
5 1
2 1
4 5
...

output:

1
123
1
597612978
1
246195351
1
15234
1
2351746
1
1
1
961374852
1
4213
2
12 21
2
2761453 6145327
1
7341256
1
2465317
1
279864531
2
213 312
1
21543
2
12 21
1
25341
2
12 21
1
876954312
1
76541328
2
451263 634512
1
1
1
4726315
1
132
1
380914827
1
51423
1
21
1
4312
1
42615873
1
1672354
1
1
1
1
1
8194723...

result:

ok 147867 numbers

Test #27:

score: 0
Accepted
time: 160ms
memory: 4032kb

input:

91041
4 15
4 2
3 2
1 3
4 3
1 4
4 1
3 4
4 2
1 4
4 2
3 1
1 4
4 3
2 4
2 1
2 4
1 2
1 2
2 1
1 2
2 5
1 2
2 1
2 1
2 1
2 1
8 7
1 7
1 8
1 7
7 6
8 5
5 2
3 7
2 4
1 2
1 2
1 2
2 1
5 11
4 1
1 5
1 5
5 3
5 1
5 2
1 5
3 2
3 2
4 1
1 5
9 6
9 8
9 8
6 3
4 7
9 6
4 8
4 11
3 1
3 1
3 4
3 2
3 1
2 3
4 3
3 1
2 1
4 1
3 2
9 18
6 ...

output:

0
2
12 21
2
12 21
0
2
12 21
0
0
0
0
0
0
0
1
1
2
12 21
0
0
0
0
0
0
0
0
0
0
0
0
1
1423
0
1
1
1
1
0
0
0
0
1
4312
0
0
0
0
0
0
1
312
0
0
1
1
1
3421
0
0
1
21
0
0
1
12
0
1
1
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
2
12 21
0
0
0
0
0
0
0
2
12 21
0
0
0
0
0
0
0
0
0
0
1
1
1
1
0
1
1324
1
231
0
0
0
0
1
1
1
21...

result:

ok 124640 numbers

Test #28:

score: 0
Accepted
time: 161ms
memory: 4040kb

input:

64643
10 14
9 10
9 7
8 6
3 8
6 2
4 9
5 4
2 3
10 5
2 7
1 3
7 1
8 4
4 8
3 25
3 2
1 3
3 1
1 2
3 2
1 2
3 2
3 1
3 1
3 2
1 2
3 2
3 2
1 2
1 2
1 2
3 2
3 2
2 1
1 2
3 1
3 2
3 2
1 2
1 2
10 18
1 10
3 4
10 7
3 9
9 1
9 4
2 10
1 5
6 4
4 7
2 6
9 2
4 8
6 3
8 2
7 5
9 6
5 4
8 28
8 5
3 5
4 8
4 6
1 6
5 6
6 5
4 8
3 6
1 7...

output:

0
1
213
1
754826321
1
71658234
2
1574263 5742631
1
643125
1
1
2
12 21
1
4312
1
202378631
1
682075903
1
76821383
0
2
123 321
1
1
2
132 321
1
3142
1
534216
2
12 21
0
1
678426086
2
42538176 64253817
1
4732156
1
46173528
2
345291786 634529178
1
24135
1
13425
1
15287364
1
16435872
1
15723864
1
1
1
346172...

result:

ok 132863 numbers

Test #29:

score: 0
Accepted
time: 161ms
memory: 3784kb

input:

67901
9 16
7 8
8 3
4 5
1 6
9 2
3 9
5 1
7 4
6 7
8 4
8 4
7 1
9 8
6 4
2 7
3 6
3 12
3 2
2 3
2 1
1 2
3 2
3 2
3 2
2 1
3 2
3 1
3 1
3 2
4 8
1 3
4 3
2 4
4 2
3 4
2 1
4 1
2 3
3 3
1 3
3 2
2 1
7 16
5 3
5 1
1 3
6 7
3 6
3 5
4 7
1 4
3 6
7 3
7 2
5 6
2 6
5 3
1 6
4 7
4 3
1 2
3 1
4 3
3 10
3 1
1 2
2 3
3 1
3 1
3 1
3 2
2 ...

output:

1
451678392
1
123
1
1342
3
132 213 321
1
2673514
1
4312
1
123
1
31452
1
12354
1
36815436
2
12 21
2
12 21
1
753004361
1
1
1
83214765
1
5264731
1
364152
1
62457813
1
25143
1
1
1
27184563
1
4132
1
3124
1
634521
1
132
1
649783152
2
12 21
1
321
1
75438126
1
12345
2
12 21
1
452697183
1
123
1
123475869
1
4...

result:

ok 148469 numbers

Test #30:

score: 0
Accepted
time: 159ms
memory: 3792kb

input:

90746
9 9
3 6
6 3
1 4
9 6
7 6
6 7
4 1
5 4
3 9
6 24
5 4
1 4
3 5
6 4
2 3
4 1
3 2
5 3
2 4
2 6
2 6
6 3
4 3
3 5
1 3
6 3
3 2
6 3
2 6
6 2
1 5
6 2
4 5
5 3
4 12
4 2
3 1
2 4
1 4
4 2
2 3
2 3
3 1
3 1
4 1
3 1
3 4
7 3
3 6
2 7
6 7
8 14
3 2
2 6
4 3
5 3
3 4
3 6
2 7
1 7
1 2
3 2
4 6
3 5
7 8
3 8
6 17
4 3
5 2
5 3
1 2
1 ...

output:

0
0
1
1423
0
0
1
361245
0
1
4231
2
12 21
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
1
1
0
0
0
0
0
0
0
0
0
2
132 321
0
0
1
1
1
312
1
1
0
0
0
1
1
1
132
1
12
0
0
1
32514
2
12 21
0
0
0
0
0
0
1
1
1
1
0
0
0
0
1
1
0
0
0
0
2
12 21
0
0
2
12 21
0
0
0
1
123
0
2
213 321
0
0
0
1
12
0
0
0
0
0
0
2
12 21
0
0
0
0
0
0
0
1
312
0
1...

result:

ok 124350 numbers

Test #31:

score: 0
Accepted
time: 157ms
memory: 4048kb

input:

64449
9 18
6 2
8 5
6 5
3 6
8 9
3 6
5 7
9 6
4 5
8 7
8 5
1 3
2 1
3 5
2 6
3 1
7 8
6 9
9 13
6 9
5 7
8 1
6 8
1 3
5 8
7 5
9 2
7 1
3 9
2 6
8 5
4 1
6 13
4 5
1 4
4 2
6 2
6 1
6 1
2 4
6 1
2 6
6 3
5 1
6 5
3 6
6 23
1 6
2 4
2 5
1 6
5 4
3 4
5 4
6 2
1 2
5 4
2 4
2 3
5 6
2 1
2 3
4 5
1 2
6 5
4 3
2 6
1 4
6 3
2 6
3 8
2 ...

output:

1
457896213
1
413926857
1
514263
1
345621
2
123 321
1
23145
0
1
5134672
1
1
1
1
1
2341
1
1
1
1
1
562413
1
1
1
51324
1
251463
1
1
1
1
1
5432167
2
12 21
1
469258371
1
354621
1
52431
1
41352
1
26178435
1
53241
1
27613485
2
12 21
1
2143
1
562341
1
4312
1
1
0
1
4213
0
3
47621358 62135847 76213584
0
1
651...

result:

ok 132077 numbers

Test #32:

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

input:

1
1 0

output:

1
1

result:

ok 2 number(s): "1 1"

Test #33:

score: 0
Accepted
time: 164ms
memory: 3880kb

input:

6940
26 139
16 2
17 12
22 10
19 18
26 15
1 25
11 4
16 21
20 2
2 16
6 2
14 22
19 16
26 21
14 9
6 19
16 8
24 8
2 11
20 5
7 24
5 7
13 25
14 23
19 1
14 9
8 23
9 1
6 14
12 23
20 10
3 14
18 26
15 1
7 5
26 2
13 11
22 11
17 25
6 23
5 10
12 8
15 12
23 10
9 14
12 23
10 22
21 8
26 5
8 13
15 1
26 22
3 10
21 17
...

output:

1
803039395
1
679703927
1
11572817
1
321
1
263139408
1
708258723
1
502336119
1
971692203
1
63736713
1
761840921
1
749807540
1
562280948
1
386746264
1
611363905
1
1
1
18500621
1
555755517
1
11166572
1
914077790
1
247021350
1
642331762
1
436089852
1
9147086
1
68132479
1
632921663
1
585825604
1
8990907...

result:

ok 14007 numbers

Test #34:

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

input:

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

output:

1
388507692
0
0
0
1
156020537
1
284536366
0
1
727118253
1
388820796
1
736200787
1
161284473
1
313096436
1
542983761
1
962253439
1
168218591
1
75679272
1
890016350
0
1
214216675
1
927708107
1
481359317
0
0
1
362777158
1
371762968
1
947135918
1
632415
1
893571038
1
463536214
1
228054368
0
1
890474339
...

result:

ok 12537 numbers

Test #35:

score: 0
Accepted
time: 169ms
memory: 3800kb

input:

7003
88 182
13 88
47 35
19 52
67 10
11 40
64 65
74 42
85 68
77 83
67 35
80 14
7 34
75 62
23 71
15 52
80 81
81 77
41 58
44 76
24 88
32 48
70 33
79 59
28 2
5 31
41 18
22 17
71 64
60 87
48 39
14 76
25 45
39 43
49 15
61 55
56 64
50 2
53 81
1 28
49 45
22 31
41 49
30 36
86 6
7 28
6 53
8 38
45 28
87 78
9 5...

output:

1
451227539
1
131855669
1
41532
1
713022243
1
92175039
1
312
1
256902889
1
413670047
1
4123
1
657690484
1
934115646
1
764219351
1
331455716
1
325882276
1
607023112
1
912156566
1
630092241
1
512736498
1
501177006
1
957284644
1
712963882
1
16852593
1
158131925
1
1546327
1
445767822
1
733731896
1
88487...

result:

ok 14168 numbers

Test #36:

score: 0
Accepted
time: 169ms
memory: 3776kb

input:

6938
45 47
13 38
41 34
39 44
6 8
23 2
5 18
17 36
29 31
15 28
14 12
31 23
21 7
38 25
38 29
27 3
26 33
32 2
35 30
30 16
11 26
44 45
1 22
24 16
42 10
36 5
34 13
9 37
25 21
3 25
43 11
40 27
2 41
20 15
24 43
18 32
12 1
37 14
4 42
8 40
45 19
22 35
7 24
19 6
33 17
28 9
16 39
23 4
77 235
28 68
66 52
52 70
2...

output:

1
497890422
1
413170815
1
119378997
1
1432
1
222636575
2
12 21
0
1
587631343
0
1
6573241
0
1
384690319
1
976808357
0
1
642475800
1
338951218
0
1
190599764
1
499299789
1
203371564
1
626616407
1
89573008
0
0
1
596729601
1
269581249
1
362486781
1
352259823
1
823046738
1
182174505
1
777477772
0
1
330856...

result:

ok 12702 numbers

Test #37:

score: 0
Accepted
time: 171ms
memory: 4060kb

input:

6948
88 187
86 34
80 13
41 83
23 46
66 38
45 11
26 41
86 42
66 20
13 40
30 78
72 47
58 71
60 77
39 34
3 9
8 60
14 35
18 62
41 77
48 74
34 74
20 16
55 67
57 24
20 9
81 19
52 36
23 31
33 45
43 30
42 33
23 56
64 66
10 57
1 80
61 14
64 4
57 3
38 16
15 49
37 60
87 70
74 65
68 48
67 13
27 58
76 37
48 24
6...

output:

1
401212610
1
356165523
1
732947595
1
199079125
1
447152043
1
162522825
1
13665319
1
442051664
1
184752936
1
729047645
1
34910122
1
627216143
1
369949441
1
795876247
1
1
1
140895523
1
316737166
1
654902144
1
971765679
1
452138860
1
586826781
1
399662798
1
7423615
1
76246669
1
896004239
1
695619045
1...

result:

ok 14038 numbers

Test #38:

score: 0
Accepted
time: 167ms
memory: 3784kb

input:

6890
93 234
51 12
19 32
26 45
44 4
47 20
22 10
66 58
76 48
10 40
45 40
59 52
76 53
1 5
84 9
33 13
21 68
5 14
35 5
14 6
19 93
45 52
68 78
27 43
5 85
6 46
4 29
9 58
50 42
50 78
19 25
22 48
8 23
31 45
73 81
60 88
31 2
23 22
69 26
45 38
73 34
92 52
61 47
34 84
7 1
84 2
14 59
39 48
35 37
35 48
49 16
8 55...

output:

1
485236895
1
974600791
1
125042643
1
865704398
1
978965606
0
1
158603509
1
92035595
1
1752436
1
622147275
0
1
212851437
1
170135681
1
47835162
0
1
615839673
0
1
824551671
1
1635274
1
776475342
1
429537995
1
276306888
1
193324560
0
1
155880424
1
705887130
1
505040505
1
576955357
1
304300586
1
631542...

result:

ok 12667 numbers

Test #39:

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

input:

6900
67 121
62 29
32 34
55 22
50 32
13 31
47 37
11 45
51 30
9 46
2 6
64 47
46 33
37 7
18 42
8 3
54 56
63 64
10 27
29 4
23 12
45 17
22 47
19 17
62 48
42 66
28 2
10 13
31 45
12 37
59 62
58 33
27 35
67 39
35 36
24 59
27 1
30 25
21 38
44 23
31 36
25 52
12 34
35 61
39 26
23 37
17 41
61 24
45 41
40 11
44 ...

output:

1
496320022
1
977403196
1
169652565
1
947340828
1
892495025
1
472785294
1
613004675
1
429877516
1
582223548
1
72228082
1
80301878
1
722218452
1
729370452
1
752194532
1
921478357
1
710350409
1
76451778
1
430312054
1
852975341
1
1
1
503156510
1
200197215
1
978521959
1
288344877
1
64733906
1
422116210
...

result:

ok 13920 numbers

Test #40:

score: 0
Accepted
time: 167ms
memory: 3784kb

input:

6862
76 257
45 59
11 69
31 23
66 64
55 16
64 27
39 69
31 9
35 76
62 73
31 53
47 51
5 53
28 76
4 30
31 55
30 18
43 73
1 69
73 15
2 34
49 33
62 7
50 3
30 21
2 4
15 60
21 40
35 18
1 20
24 17
59 13
34 9
14 66
18 32
27 13
22 47
28 41
11 18
53 64
27 63
43 40
12 26
6 68
45 5
51 40
38 40
9 55
75 66
17 44
1 ...

output:

1
22943897
1
341509455
0
1
972454968
1
311612880
1
910867812
1
1
0
1
454252677
1
566468766
1
516205411
1
337875927
1
307260979
0
1
739019713
0
1
232083397
1
20067691
1
800363339
1
139042106
1
801224705
1
524136
0
1
791674534
1
231
0
0
1
1423
1
341303469
1
965303101
1
809306997
1
305246567
0
1
403175...

result:

ok 12516 numbers

Test #41:

score: 0
Accepted
time: 164ms
memory: 4060kb

input:

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

output:

1
169353088
1
333805780
2
12 21
1
545566944
1
367828843
1
313683340
1
243805889
1
750201723
1
274127649
1
665996923
1
494913767
1
803297657
1
862046582
1
174330274
1
260214252
1
313873857
1
228124726
1
231
1
149783592
1
146265513
1
565902017
1
910328595
1
617238033
1
807723011
1
560437580
1
34298497...

result:

ok 14026 numbers

Test #42:

score: 0
Accepted
time: 167ms
memory: 4076kb

input:

6924
96 134
58 79
16 66
47 78
23 70
15 93
55 94
11 8
14 22
76 30
80 84
95 35
17 48
77 14
43 89
30 18
37 12
37 73
51 63
67 39
31 91
57 29
55 2
85 4
43 24
34 78
71 64
71 88
88 44
50 40
38 72
11 44
45 95
39 45
49 34
45 83
89 68
90 52
1 67
68 20
78 15
44 34
20 95
9 2
96 80
70 19
92 12
48 9
86 50
43 60
4...

output:

1
603332242
1
595767421
1
862472115
1
364292733
0
1
708695053
1
328891809
0
1
813337090
1
123
1
659995401
1
209623436
1
840756701
0
0
1
914704904
0
1
232576593
1
925468756
1
434706327
0
1
513865543
1
463606787
1
112319403
1
565819967
1
926357629
0
1
780795368
1
211765277
1
5342716
1
398366068
0
0
1
...

result:

ok 12679 numbers

Test #43:

score: 0
Accepted
time: 209ms
memory: 4040kb

input:

662
293 1513
137 170
221 230
24 5
270 96
241 139
182 35
246 50
218 19
94 9
110 251
150 249
282 288
103 64
211 51
136 255
7 102
291 95
117 189
35 207
137 266
267 38
281 80
203 285
179 204
269 225
141 192
159 108
205 66
160 277
187 218
166 206
217 206
280 45
50 277
105 272
66 167
263 191
205 174
272 1...

output:

1
181059484
1
973989468
1
190554490
1
3125476
1
90434053
1
546449599
1
766763267
1
898279070
1
91398660
1
96367749
1
490557476
1
805710236
1
969586974
1
18085359
1
15327684
1
389893138
1
349291242
1
781265581
1
962053930
1
538995493
1
523960706
1
532998841
1
267097996
1
653515262
1
371678830
1
28012...

result:

ok 1324 numbers

Test #44:

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

input:

664
616 636
394 310
540 13
146 292
580 570
119 77
588 408
235 427
498 513
140 41
599 346
24 504
34 272
549 62
578 576
277 226
493 163
301 517
309 404
244 447
154 512
381 436
206 477
606 460
158 554
457 86
431 413
561 28
406 212
61 497
465 78
53 241
152 420
386 433
361 47
587 540
99 231
84 357
577 36...

output:

1
607899049
1
552086229
0
1
159458666
1
155416062
1
122655178
0
1
936737201
1
25710828
1
889491795
1
111329478
1
617193217
1
303021676
1
437878428
1
583734713
1
567060643
1
570928855
1
395631489
1
830200402
1
714998229
1
871271554
1
219127143
1
176778278
1
393084108
1
999414712
1
839921
1
179120645
...

result:

ok 1210 numbers

Test #45:

score: 0
Accepted
time: 205ms
memory: 4048kb

input:

661
279 1780
8 117
124 154
96 268
246 172
148 216
17 261
277 254
217 72
186 118
126 108
21 274
16 137
47 195
199 29
249 28
69 108
239 200
55 117
209 89
7 212
194 166
91 176
164 143
210 137
212 103
257 64
39 183
215 198
65 222
112 252
39 132
41 235
41 234
191 192
101 145
92 45
204 193
189 133
165 259...

output:

1
186441506
1
736726884
1
642987525
1
990299401
1
157634630
1
267527648
1
405759120
1
483243140
1
278710947
1
486468248
1
643438893
1
351654068
1
356088632
1
987056462
1
634794448
1
313747891
1
125413567
1
280179346
1
883236183
1
262837096
1
286095133
1
690442814
1
402073952
1
426964558
1
316196687
...

result:

ok 1323 numbers

Test #46:

score: 0
Accepted
time: 196ms
memory: 4040kb

input:

672
915 1561
833 607
261 462
646 35
869 520
356 197
567 642
546 826
181 497
512 177
370 696
598 112
204 678
295 667
374 461
813 745
491 753
431 42
883 820
701 546
459 487
186 164
266 108
514 329
549 647
302 232
514 427
546 111
535 436
779 455
453 249
521 615
242 125
597 104
644 169
365 716
379 302
8...

output:

1
478466136
1
556229992
1
858646559
1
27497148
1
116021313
1
364502512
1
769753897
1
315256505
1
794988912
1
308148972
1
283043483
0
1
161744604
1
526350336
1
984519307
1
967395425
1
819709662
1
303325881
1
446472793
1
101479984
1
907508921
1
50327843
1
795816947
1
127365677
1
35748194
1
329136198
1...

result:

ok 1211 numbers

Test #47:

score: 0
Accepted
time: 202ms
memory: 4288kb

input:

667
976 1890
684 253
83 540
547 380
69 50
289 628
290 395
465 933
116 964
968 638
194 445
555 624
602 491
122 89
170 613
713 777
389 291
330 70
302 16
849 570
829 716
364 613
698 11
449 714
620 912
22 69
315 155
689 426
527 318
931 814
559 312
956 58
194 606
558 564
819 258
676 909
65 301
223 865
30...

output:

1
147885323
1
763146998
1
485843444
1
407002767
1
155481760
1
187826259
1
746778590
1
810668677
1
630150503
1
530154162
1
247805558
1
929882930
1
394262719
1
758751045
1
974805557
1
820754412
1
313897223
1
335536948
1
586166508
1
595867798
1
839898354
1
873596757
1
235231725
1
637225466
1
624729193
...

result:

ok 1334 numbers

Test #48:

score: 0
Accepted
time: 203ms
memory: 4068kb

input:

664
983 2507
50 866
154 677
498 337
267 889
950 702
484 174
83 550
329 761
458 435
83 733
750 237
361 456
248 335
817 352
227 317
179 979
678 570
466 603
971 745
795 424
261 173
404 773
6 763
657 331
162 429
547 54
165 905
880 9
586 761
272 459
906 881
881 703
931 452
474 235
464 520
170 140
983 527...

output:

1
306503252
1
881308607
1
810455706
1
750634051
1
299467002
1
437718528
1
396252044
1
670578492
1
537094618
1
407739296
0
1
937661981
1
497772135
1
956582507
1
633776951
1
716277341
0
1
230411693
0
1
290740318
0
0
1
645237641
1
8870827
1
543086052
0
1
128738153
1
177361950
1
321
1
774564208
1
628769...

result:

ok 1199 numbers

Test #49:

score: 0
Accepted
time: 206ms
memory: 4024kb

input:

658
605 1502
256 350
102 453
405 528
327 36
279 183
301 411
151 383
140 166
187 372
102 40
366 477
428 598
257 142
339 75
483 551
596 221
92 468
373 280
3 189
325 309
310 330
52 371
58 107
109 27
470 51
109 355
521 461
393 294
506 379
135 293
475 195
363 427
213 449
265 278
314 532
604 282
522 321
5...

output:

1
694373305
1
704401004
1
64672955
1
628382945
1
654219082
1
874680069
1
692540540
1
590026642
1
463510138
1
950237338
1
869667412
1
504960425
1
389539797
1
950198961
1
927069292
1
186392365
1
534221627
1
600181810
1
698603830
1
602941752
1
10734852
1
568851613
1
448318872
1
618437820
1
475353843
1
...

result:

ok 1316 numbers

Test #50:

score: 0
Accepted
time: 204ms
memory: 4304kb

input:

685
318 874
318 83
67 243
7 51
294 51
212 304
143 160
187 91
117 205
32 100
291 172
298 166
78 295
242 273
284 166
121 26
72 281
263 299
10 17
97 3
105 308
79 76
8 153
74 83
257 281
204 196
167 115
234 216
242 230
28 6
188 90
96 193
185 77
147 102
78 165
122 217
270 136
135 190
70 246
260 9
257 95
5...

output:

1
149568141
1
108311773
0
0
1
222303294
1
126483282
1
916803136
1
6725143
1
61987326
1
108370698
1
235475114
1
989798625
1
379914449
1
594546546
1
834382431
1
436802570
0
1
655406207
1
73379656
1
973100024
0
0
1
597482727
1
656135001
1
563256688
1
123
0
1
299799483
1
430519868
1
574280106
1
49136980...

result:

ok 1221 numbers

Test #51:

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

input:

664
996 1573
235 930
876 289
954 905
551 38
736 191
287 890
231 120
915 934
432 846
762 42
937 196
391 333
12 618
681 351
885 471
188 233
470 614
166 112
500 843
525 361
468 420
303 872
39 799
665 457
721 456
883 770
139 905
478 443
803 248
487 655
697 839
582 39
145 913
444 863
827 180
344 519
595 ...

output:

1
182640664
1
330559594
1
330781557
1
59122909
1
485840724
1
704566951
1
905490204
1
503796328
1
196101531
1
293895476
1
697154237
1
711381994
1
726351918
1
847005659
1
679404671
1
536629987
1
761550149
1
479486460
1
977776212
1
84490640
1
972862595
1
732190660
1
278996861
1
159975991
1
243440177
1
...

result:

ok 1330 numbers

Test #52:

score: 0
Accepted
time: 206ms
memory: 4300kb

input:

663
565 2423
250 205
449 563
125 372
272 410
188 228
167 160
237 175
242 262
278 480
252 59
221 360
433 175
319 82
84 28
225 530
534 457
54 526
464 314
242 163
530 122
495 13
535 291
326 502
435 291
530 285
420 307
234 367
100 189
531 219
273 492
281 349
192 11
419 526
532 342
504 358
260 281
410 54...

output:

0
1
496937675
0
0
1
410986631
1
397058154
1
427157446
1
137465239
1
41161052
1
674085312
1
849055944
1
432925350
1
511700440
1
458042793
1
994875144
1
365466127
1
913347510
1
509686315
1
162013570
0
1
969896047
0
1
686019701
1
596574458
1
658364933
1
4586670
0
1
536521052
1
739171231
1
8280353
1
900...

result:

ok 1191 numbers

Test #53:

score: 0
Accepted
time: 260ms
memory: 5424kb

input:

63
2677 2754
1197 2566
2610 824
1414 843
2217 1173
2564 432
9 926
2435 2468
2567 874
733 1455
2334 1104
2342 1779
125 2668
1265 2231
293 761
1792 1588
1208 1773
1847 331
1984 339
2403 1361
532 2658
1257 2604
1545 877
700 1237
1969 1952
2620 790
2265 186
2259 2475
835 1552
517 756
1595 470
448 702
13...

output:

1
235973941
1
553576965
1
557412870
1
972365467
1
702386867
1
525359996
1
223169878
1
935244540
1
874031747
1
365225770
1
91857388
1
563501532
1
396685995
1
241370007
1
666835886
1
385963076
1
411444134
1
342630155
1
517456469
1
195285068
1
749664278
1
491045488
1
639795059
1
919304487
1
51782485
1
...

result:

ok 126 numbers

Test #54:

score: 0
Accepted
time: 303ms
memory: 5220kb

input:

62
7913 24223
4139 7174
4829 4044
7176 2350
6023 2473
1792 4540
1065 700
738 4701
597 1566
3427 6024
4752 1251
4397 6284
3220 3090
5397 5532
2179 4902
5692 2351
3661 1749
4304 3382
836 2615
6611 3530
5859 1496
2542 7907
1770 833
7469 122
2930 7699
1001 539
4329 1292
3662 6782
5825 91
4566 196
6758 3...

output:

1
871975606
1
724919956
1
933967825
1
330851524
0
1
64713963
1
774317332
1
752794235
0
0
1
509952099
1
834587901
1
889738719
1
634465788
1
742309555
1
950315102
1
64482131
1
581865268
1
71228343
1
186886606
1
220385272
0
1
404897201
1
491101085
1
799414160
0
0
1
40063471
0
1
527156756
1
573411959
1
...

result:

ok 108 numbers

Test #55:

score: 0
Accepted
time: 705ms
memory: 5160kb

input:

66
4613 23099
1045 4489
473 1604
2959 361
120 773
323 2719
3242 2235
3034 4538
841 1717
2590 2585
4056 3784
2412 275
1718 3509
749 390
2786 1287
3594 4517
4352 4444
813 1598
2011 1901
2126 4258
2864 342
2346 3425
205 3934
3026 4112
84 3453
4303 3275
4245 2205
1057 552
4013 800
2816 1922
383 3582
156...

output:

1
135830770
1
198550031
1
913030677
1
630459844
1
52895823
1
517546085
1
707218629
1
296608390
1
632938668
1
77055165
1
221146140
1
544090446
1
788986050
1
963168961
1
988155906
1
401091200
1
539600858
1
804116936
1
38872988
1
339011012
1
993785769
1
305195893
1
953500187
1
752278726
1
560637853
1
9...

result:

ok 132 numbers

Test #56:

score: 0
Accepted
time: 272ms
memory: 5360kb

input:

69
9250 12888
7772 8562
1855 5823
28 289
3677 2708
7490 5941
5559 9017
1427 7612
9242 1295
8943 2789
3529 3917
2850 577
1535 8151
6027 9020
3118 5958
2817 1647
1463 2167
5649 4060
4242 8018
4223 5525
7172 965
2652 1921
2415 6972
2195 8936
1730 2393
5279 2997
6006 1685
4460 5503
3093 8608
1199 8888
2...

output:

1
530757421
1
624641123
1
768184123
1
51939164
1
264026386
1
360697261
1
788831548
0
1
977281226
1
502917641
1
474311829
1
784429914
1
654463509
1
97885749
1
336252525
0
0
1
544128912
1
213915845
0
1
12490729
0
1
138763417
1
413477176
1
58353605
1
336541830
1
131197300
0
1
364248266
1
274111791
1
40...

result:

ok 124 numbers

Test #57:

score: 0
Accepted
time: 287ms
memory: 5248kb

input:

71
8051 8780
1719 3289
3159 5107
1521 3624
3284 1065
1999 6606
5557 220
2337 5842
1564 2105
7093 4661
7021 3248
3542 2861
46 3837
4757 4353
5619 5385
5101 2987
2810 6663
1782 7014
2074 4624
2851 2041
4857 779
7078 4795
3317 4469
7389 4075
7516 3937
6369 959
5400 6572
1328 5247
6138 3273
5290 1669
16...

output:

1
634684453
1
406765255
1
628989759
1
294014984
1
938764507
1
386577589
1
715681614
1
172295904
1
817546159
1
868306845
1
685377526
1
451768225
1
729714951
1
868674141
1
890078132
1
827179632
1
457116423
1
931859929
1
601579110
1
166376242
1
206944899
1
118336619
1
66119523
1
508084828
1
769221480
1...

result:

ok 142 numbers

Test #58:

score: 0
Accepted
time: 266ms
memory: 5072kb

input:

70
348 8993
198 279
224 283
326 299
66 308
221 174
7 14
204 176
118 195
142 156
1 48
196 13
135 160
107 160
122 80
80 329
343 250
241 309
107 97
2 63
12 113
128 99
228 334
288 235
155 312
312 30
211 247
9 14
117 43
337 156
199 41
66 10
69 132
314 310
279 229
98 167
20 109
45 291
223 333
345 109
90 7...

output:

1
253698303
1
408473513
1
412429805
0
0
1
445960951
1
10459489
0
1
1901863
1
305696103
0
1
400940510
1
996536447
1
179949735
1
910913051
1
246593605
1
857908408
1
732969471
1
833745919
1
680205097
1
370782775
1
696262714
0
1
974827852
1
273029853
1
37076770
0
0
0
1
80144808
1
816206987
0
1
902607876...

result:

ok 124 numbers

Test #59:

score: 0
Accepted
time: 330ms
memory: 5240kb

input:

71
981 6750
808 432
452 447
330 384
326 761
371 235
711 149
275 640
421 716
841 637
513 325
914 144
946 792
31 131
295 140
244 612
721 26
57 487
146 733
262 782
208 136
808 806
911 350
253 233
674 202
251 837
753 346
912 308
195 779
485 200
69 305
977 819
252 353
283 14
799 618
495 896
506 717
44 15...

output:

1
637999634
1
471368864
1
109622535
1
249560453
1
224258733
1
548968902
1
174554935
1
283733495
1
286114865
1
992489502
1
343964575
1
708708995
1
357310420
1
154591146
1
239574974
1
557155512
1
374603048
1
264079287
1
995674320
1
21518983
1
81235123
1
765570446
1
469782730
1
959378771
1
174494466
1
...

result:

ok 142 numbers

Test #60:

score: 0
Accepted
time: 304ms
memory: 5144kb

input:

67
3549 14773
3145 408
936 1643
1782 3333
2606 244
1470 1529
2940 1764
2586 466
428 875
3351 2117
398 498
3431 3441
493 3215
217 633
3115 2530
1565 1379
2652 1043
1073 1440
3451 2327
324 2984
218 3342
3485 1303
3179 88
874 860
2213 1572
804 122
3167 2307
964 1812
1296 3410
2898 2649
1248 962
1045 40...

output:

1
949828419
1
625190053
0
1
792739050
1
169057093
0
0
1
823153949
1
40191129
1
525117389
1
191280312
1
221798665
1
941200741
1
240269737
1
778471162
0
0
0
0
1
577041976
1
35639021
1
436461239
1
363900320
1
349959243
1
167334415
1
739385810
1
538878695
1
805366097
1
233134287
1
35638174
1
956142225
1...

result:

ok 120 numbers

Test #61:

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

input:

63
5617 20424
5001 4990
4802 1836
924 3405
1426 1439
1263 3896
4066 1020
5166 4315
401 89
1548 1158
5065 2656
3831 610
3346 4785
952 2457
1072 2988
5319 1314
2313 4426
3377 5173
226 1888
575 1732
5466 3443
4987 1215
5177 5073
4644 2952
2162 3815
4862 4263
4716 3313
954 5343
2468 4031
4604 738
1182 1...

output:

1
607140508
1
230815116
1
494635283
1
631597170
1
267986791
1
257525332
1
156870541
1
148636670
1
677420110
1
87693454
1
492105038
1
268515856
1
84234960
1
47482977
1
523329407
1
142773743
1
378300993
1
668822931
1
80520187
1
640101499
1
730628758
1
477488296
1
882877805
1
359039171
1
342375956
1
78...

result:

ok 126 numbers

Test #62:

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

input:

73
7423 19443
4484 5521
6497 2155
2118 3951
5892 2389
1500 1275
1908 2630
3419 5212
367 3482
3470 6824
1046 2108
543 5742
2924 3940
6489 3653
2920 6115
658 4036
748 3039
1842 2432
5237 1330
4638 4405
4597 2041
2660 764
20 601
6752 6394
690 3525
3230 6100
6713 2889
6094 3762
1188 7245
1740 1898
6132 ...

output:

1
91127391
1
47588902
1
386320714
1
351034561
1
362937023
1
831964107
1
851291829
1
77696681
1
98910905
0
0
1
169879280
1
308171317
1
397235260
1
292963932
1
98543600
1
569327608
1
392804279
1
858903137
1
666337899
1
899821481
1
565144169
1
309169815
1
299838172
0
1
435351820
1
718060176
1
527405461...

result:

ok 138 numbers

Test #63:

score: 0
Accepted
time: 3741ms
memory: 16960kb

input:

6
82541 233545
32809 47652
29466 50404
28655 6662
73745 67621
55118 18402
35296 31854
52702 72985
36571 71863
31511 15493
56903 27007
62753 43167
10773 27940
77158 47857
30942 33449
79630 35998
76306 28312
70440 45671
82159 77052
8576 9094
11691 55283
33212 15336
39542 14946
51209 9522
41754 57924
2...

output:

1
685294145
1
353166867
1
661533084
1
632860729
1
201527735
1
429445684

result:

ok 12 numbers

Test #64:

score: 0
Accepted
time: 1558ms
memory: 18828kb

input:

5
42750 234189
13449 42171
40060 5366
37280 2068
17696 7802
27881 32280
38383 23422
39032 21802
26364 29707
27985 39376
39908 6958
13389 20655
16176 35267
37196 3809
37668 25211
1240 42295
32085 9048
9379 35072
3103 25910
35179 10576
5110 261
25119 10875
29564 21752
28927 31813
32385 33146
39237 359...

output:

1
993982375
1
759680841
1
401960171
1
136505676
0

result:

ok 9 numbers

Test #65:

score: 0
Accepted
time: 1091ms
memory: 15000kb

input:

5
54697 245912
6297 35686
18015 23972
1349 19943
46787 16325
24158 25400
5314 13848
37671 1599
24324 10574
48526 16226
51296 27990
19433 16806
38836 46655
18410 3208
52711 20567
29293 53723
2156 38966
48907 49172
49518 53299
19157 22048
19434 29948
45996 16964
21831 37608
18366 631
7535 39927
37205 ...

output:

1
339651626
1
176676996
1
108796883
1
838031810
1
24035333

result:

ok 10 numbers

Test #66:

score: 0
Accepted
time: 2367ms
memory: 18392kb

input:

6
81188 247285
24223 13981
61393 77972
26145 13356
75512 45021
13290 70947
8961 76805
56810 21517
59507 53065
60269 22879
43412 18814
34582 75287
40356 34404
17747 12037
32659 20086
71655 22136
44076 14365
28550 77600
9514 40601
23141 44527
44593 55282
35886 67360
26031 7480
81117 15087
28824 57198
...

output:

1
468348822
1
658392545
1
90199838
1
857836949
1
467869629
1
124310818

result:

ok 12 numbers

Test #67:

score: 0
Accepted
time: 1348ms
memory: 17044kb

input:

6
10748 166144
9171 10647
9052 4177
10273 4076
79 5001
9667 9992
2645 4787
779 6462
1114 9425
6564 1230
7102 9316
1094 5789
7061 8993
4806 5872
9597 5005
5498 764
545 7832
7568 7248
7505 6339
9711 5923
5630 7280
4600 10711
3263 2898
2518 3020
3261 2862
111 5912
9416 1784
4545 3618
1568 8781
5739 238...

output:

1
950268118
1
805894697
1
225427875
1
287914795
1
414761269
1
730361185

result:

ok 12 numbers

Test #68:

score: 0
Accepted
time: 1467ms
memory: 16504kb

input:

7
25237 204105
4759 7957
22288 6078
14983 429
1183 13816
11405 1971
4427 6425
10647 10280
3934 10049
19013 10425
12309 714
7407 16610
23605 13528
11517 12391
16706 19626
10587 23997
20981 5141
21405 12965
23140 11980
13811 15921
24534 10891
8864 6373
9011 12668
22756 6777
19841 8970
9573 6121
24762 ...

output:

0
1
723936464
1
224916881
1
890969037
0
1
843506451
0

result:

ok 11 numbers

Test #69:

score: 0
Accepted
time: 2050ms
memory: 19108kb

input:

6
29722 179691
10560 23014
3268 24924
7062 17622
16767 14078
26680 3665
8939 20351
6384 3348
12878 8384
13173 802
11278 7237
607 25088
142 7103
360 10581
14165 27063
26959 25076
16193 12401
5725 11967
26459 25952
3757 12416
23485 12308
18255 9516
16233 10123
1594 23026
1511 29391
29027 5586
1876 170...

output:

1
839074727
1
771592073
1
13291894
1
242989399
1
481935239
1
193440699

result:

ok 12 numbers

Test #70:

score: 0
Accepted
time: 1298ms
memory: 15608kb

input:

6
65629 131112
7497 26069
31111 8284
7725 49271
7273 49115
38312 46106
16996 33129
38593 20955
15089 8013
60062 62241
35437 1557
384 36076
41552 11000
64072 28427
10672 30243
47618 43471
52523 63176
4757 48672
45939 22769
59697 42445
63082 16556
55678 9373
43999 47849
38409 1736
13935 58460
20175 21...

output:

1
840702333
1
235187106
0
0
1
704791721
1
985561060

result:

ok 10 numbers

Test #71:

score: 0
Accepted
time: 1760ms
memory: 15240kb

input:

8
39217 119763
13317 26557
35563 9340
13032 23478
23449 27355
13300 15314
5640 25826
15319 31324
298 30514
26521 38673
13086 30663
11376 10144
11763 7339
14314 37439
14483 27033
17155 8302
16455 16690
28622 38328
24754 25986
36236 18590
30253 1244
26778 10806
25301 33741
15586 30965
9432 20576
19152...

output:

1
96205121
1
443049783
1
97553905
1
7737858
1
659762246
1
96248897
1
307765761
1
869779740

result:

ok 16 numbers

Test #72:

score: 0
Accepted
time: 1189ms
memory: 17244kb

input:

5
73635 271002
31695 70887
1098 51335
50208 6121
55865 32448
15186 46961
58200 56326
15261 64779
64177 41719
47691 33512
56776 61953
60141 73534
57095 62040
9701 47922
56327 12979
42527 28081
43835 44327
27474 38189
45826 17524
18547 21582
14607 57056
5395 24805
61837 46305
7580 40687
32320 29223
27...

output:

1
632285348
1
986861373
1
944412753
1
967702687
1
505563595

result:

ok 10 numbers

Test #73:

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

input:

4923
84 170
8 47
33 50
76 20
79 44
12 13
58 38
80 58
39 66
58 60
19 67
64 68
72 68
51 74
52 24
79 44
39 15
12 49
26 81
48 57
70 10
65 37
10 59
58 75
48 27
52 17
35 14
11 35
40 9
23 63
75 5
14 35
73 33
30 37
44 79
75 80
4 36
76 32
67 38
32 63
72 64
76 63
11 41
58 5
28 61
79 10
51 77
75 5
69 72
40 5
2...

output:

17
726689173 125761870 183073188 410450460 760780655 951194036 974105123 691204368 87886393 94367742 516426988 237459099 420868046 751012469 958411536 256472958 814536518
24
748817382 949093425 299866428 413562856 666294885 494972575 314295752 525600118 973336312 924693029 478109316 877427007 959328...

result:

ok 167193 numbers

Test #74:

score: 0
Accepted
time: 210ms
memory: 3788kb

input:

4243
71 257
56 28
39 58
15 69
66 24
23 8
29 48
5 58
48 70
9 65
67 71
47 67
56 2
17 20
64 62
51 1
7 17
49 37
64 51
6 40
16 66
70 25
47 12
23 26
48 21
53 26
12 1
13 35
47 57
68 8
30 5
58 39
52 43
27 44
41 14
16 43
69 13
32 4
63 65
63 40
29 25
61 53
2 57
9 44
70 16
2 45
15 20
29 20
27 18
59 41
42 8
20 ...

output:

1
963529399
11
159920012 242249248 175932735 527286756 71358805 487693024 5360063 794532287 668174822 557760256 86208430
3
291105523 723336183 353896636
1
260819813
4
631096356 488830321 2156936 58282043
33
687424143 25749543 953905208 194806823 215247875 422729900 237207417 385174124 902762818 9878...

result:

ok 42249 numbers

Test #75:

score: 0
Accepted
time: 258ms
memory: 4068kb

input:

4533
149 363
60 58
64 18
62 133
78 26
54 24
6 63
65 116
6 63
93 70
112 28
107 100
137 31
104 18
147 63
61 81
136 127
58 79
56 28
117 115
122 132
122 132
54 30
104 50
74 31
32 16
113 39
144 30
26 37
132 122
104 134
98 29
75 92
1 87
65 57
60 58
87 42
132 142
11 67
75 38
34 18
145 47
17 33
3 143
123 43...

output:

14
654132311 680319525 876298501 734492574 279566491 294731277 243979488 687132984 509201516 298285280 549094847 624557184 348746061 774785853
128
243469497 941676738 254294951 121879382 362433544 944740806 924936908 796222657 295867358 307631279 963009184 953404003 421646155 541014421 130050781 206...

result:

ok 99528 numbers

Test #76:

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

input:

4913
151 295
31 23
61 21
9 37
103 88
117 62
129 1
102 13
75 15
54 121
57 134
83 97
11 5
102 13
130 136
98 68
77 104
121 129
118 7
116 32
20 87
23 46
132 34
12 126
14 70
113 64
11 5
17 50
89 71
138 38
22 34
78 144
93 72
108 116
121 18
120 31
122 43
23 96
41 71
90 127
96 50
102 13
41 144
10 78
53 111
...

output:

23
516991759 357217758 423674149 66437812 559901588 895450555 190448184 641890502 396895082 89847454 191363359 422729226 879922564 325541386 570177367 316773576 391810639 216000202 701714468 526068570 452723512 559889028 374538301
51
316921851 302147811 46428619 126960850 449727861 940169407 3397081...

result:

ok 167707 numbers

Test #77:

score: 0
Accepted
time: 1470ms
memory: 4184kb

input:

472
276 1122
205 112
5 192
268 265
137 82
248 254
75 112
196 67
117 98
122 194
19 15
105 124
95 137
142 74
97 218
113 157
73 177
73 164
265 30
79 221
57 214
269 237
170 159
17 87
265 30
22 149
125 86
265 252
105 124
64 219
64 116
115 163
215 183
12 104
36 116
199 253
113 52
80 252
135 99
5 8
71 195
...

output:

28
595329373 324060565 854598601 497929508 933087553 294063990 432886813 888155070 499534791 751915861 46586656 807955511 45950434 282181114 614160027 565501647 836860052 329252189 460780094 902762982 670983838 81850654 742865844 413146017 182202019 980525723 525635312 21428523
451
934603459 5551761...

result:

ok 105264 numbers

Test #78:

score: 0
Accepted
time: 2452ms
memory: 4200kb

input:

482
373 456
260 371
263 82
79 304
96 89
67 356
174 238
299 8
195 339
197 333
123 359
120 97
156 11
322 123
113 324
215 51
5 46
96 29
306 219
179 185
3 73
245 248
274 226
369 296
336 139
233 350
124 155
164 107
35 366
245 117
199 28
234 61
252 265
301 30
196 332
78 365
308 144
326 203
52 353
364 101
...

output:

230
614883966 690555527 526535709 519995906 116338109 328775956 276757088 991034741 712088804 362892548 561654564 701159837 178809467 272370898 383766052 928841397 319398755 186337692 841433361 217194707 342861533 846070015 384965044 887002346 991358476 302032084 446069789 767494348 43602989 6219655...

result:

ok 188443 numbers

Test #79:

score: 0
Accepted
time: 1720ms
memory: 4220kb

input:

459
1532 3712
1370 740
44 435
493 587
1062 933
1396 893
1516 1402
682 132
1200 162
994 1289
912 282
958 744
912 107
83 1094
182 225
1018 499
250 459
786 119
29 845
1039 1481
791 1017
176 62
812 245
831 347
1201 104
528 484
48 1246
1260 1462
704 668
517 554
154 228
510 1019
1406 876
210 411
214 1244
...

output:

207
675042387 254835630 649635582 955169011 674955682 85732873 81061594 710618893 191539167 833564799 566448123 629832321 671183898 347612259 949437349 982472698 426127811 921060631 484583217 208310712 253663487 949263335 40993414 633939221 907483435 559615633 70099768 760205884 835682594 647356042 ...

result:

ok 124514 numbers

Test #80:

score: 0
Accepted
time: 1653ms
memory: 4228kb

input:

457
1931 3194
1916 1398
849 1558
236 1502
1772 1532
317 238
1517 1292
1795 1095
857 1821
1058 1016
1068 156
93 1543
1386 1049
890 603
1465 1814
1100 217
1702 1655
1095 1602
1658 746
574 405
533 1456
464 516
877 1239
841 329
207 447
135 1310
256 1638
286 346
254 906
18 145
1281 1930
1209 1245
772 807...

output:

285
928256209 768294421 405443280 475157183 323835738 739380735 906726268 622175638 145070986 469213040 295423652 519425253 353950615 955432724 887569042 469060921 991454410 465669687 851739994 695991363 771205002 680450149 727924612 793119025 253095274 951761820 287589548 872426442 939413967 894965...

result:

ok 116807 numbers

Test #81:

score: -100
Time Limit Exceeded

input:

50
16388 24464
7061 5394
5954 7575
2135 1048
15810 1217
11708 2444
12114 9217
12258 16200
1609 7675
4106 15397
13798 7072
2103 2691
15090 9560
5749 5379
4800 14526
9839 14988
15994 4895
6687 15052
5795 13380
13203 4714
4893 4183
2533 7675
8512 3715
6362 11598
6396 984
524 8071
8346 8173
15653 4984
4...

output:

4401
66443481 27844386 176626733 653797304 930457124 267466265 651479396 999834662 949425135 553436452 384156147 817847150 519636226 631871534 363996113 545318335 635046476 802838116 354472877 77930449 360964153 574295079 480149155 74570258 773205540 840152670 20148747 706691681 215757619 912123739 ...

result: