QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#802426#9868. GCDucup-team987#AC ✓2823ms101644kbC++2312.2kb2024-12-07 13:41:382024-12-07 13:41:41

Judging History

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

  • [2024-12-07 13:41:41]
  • 评测
  • 测评结果:AC
  • 用时:2823ms
  • 内存:101644kb
  • [2024-12-07 13:41:38]
  • 提交

answer

/**
 * date   : 2024-12-07 14:41:31
 * author : Nyaan
 */

#define NDEBUG

using namespace std;

// intrinstic
#include <immintrin.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tr2/dynamic_bitset>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

// utility

namespace Nyaan {
using ll = long long;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;

template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<vector<T>>;
using vi = vector<int>;
using vl = vector<long long>;
using vd = V<double>;
using vs = V<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template <typename T, typename U>
struct P : pair<T, U> {
  template <typename... Args>
  constexpr P(Args... args) : pair<T, U>(args...) {}

  using pair<T, U>::first;
  using pair<T, U>::second;

  P &operator+=(const P &r) {
    first += r.first;
    second += r.second;
    return *this;
  }
  P &operator-=(const P &r) {
    first -= r.first;
    second -= r.second;
    return *this;
  }
  P &operator*=(const P &r) {
    first *= r.first;
    second *= r.second;
    return *this;
  }
  template <typename S>
  P &operator*=(const S &r) {
    first *= r, second *= r;
    return *this;
  }
  P operator+(const P &r) const { return P(*this) += r; }
  P operator-(const P &r) const { return P(*this) -= r; }
  P operator*(const P &r) const { return P(*this) *= r; }
  template <typename S>
  P operator*(const S &r) const {
    return P(*this) *= r;
  }
  P operator-() const { return P{-first, -second}; }
};

using pl = P<ll, ll>;
using pi = P<int, int>;
using vp = V<pl>;

constexpr int inf = 1001001001;
constexpr long long infLL = 4004004004004004004LL;

template <typename T>
int sz(const T &t) {
  return t.size();
}

template <typename T, typename U>
inline bool amin(T &x, U y) {
  return (y < x) ? (x = y, true) : false;
}
template <typename T, typename U>
inline bool amax(T &x, U y) {
  return (x < y) ? (x = y, true) : false;
}

template <typename T>
inline T Max(const vector<T> &v) {
  return *max_element(begin(v), end(v));
}
template <typename T>
inline T Min(const vector<T> &v) {
  return *min_element(begin(v), end(v));
}
template <typename T>
inline long long Sum(const vector<T> &v) {
  return accumulate(begin(v), end(v), 0LL);
}

template <typename T>
int lb(const vector<T> &v, const T &a) {
  return lower_bound(begin(v), end(v), a) - begin(v);
}
template <typename T>
int ub(const vector<T> &v, const T &a) {
  return upper_bound(begin(v), end(v), a) - begin(v);
}

constexpr long long TEN(int n) {
  long long ret = 1, x = 10;
  for (; n; x *= x, n >>= 1) ret *= (n & 1 ? x : 1);
  return ret;
}

template <typename T, typename U>
pair<T, U> mkp(const T &t, const U &u) {
  return make_pair(t, u);
}

template <typename T>
vector<T> mkrui(const vector<T> &v, bool rev = false) {
  vector<T> ret(v.size() + 1);
  if (rev) {
    for (int i = int(v.size()) - 1; i >= 0; i--) ret[i] = v[i] + ret[i + 1];
  } else {
    for (int i = 0; i < int(v.size()); i++) ret[i + 1] = ret[i] + v[i];
  }
  return ret;
};

template <typename T>
vector<T> mkuni(const vector<T> &v) {
  vector<T> ret(v);
  sort(ret.begin(), ret.end());
  ret.erase(unique(ret.begin(), ret.end()), ret.end());
  return ret;
}

template <typename F>
vector<int> mkord(int N, F f) {
  vector<int> ord(N);
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), f);
  return ord;
}

template <typename T>
vector<int> mkinv(vector<T> &v) {
  int max_val = *max_element(begin(v), end(v));
  vector<int> inv(max_val + 1, -1);
  for (int i = 0; i < (int)v.size(); i++) inv[v[i]] = i;
  return inv;
}

vector<int> mkiota(int n) {
  vector<int> ret(n);
  iota(begin(ret), end(ret), 0);
  return ret;
}

template <typename T>
T mkrev(const T &v) {
  T w{v};
  reverse(begin(w), end(w));
  return w;
}

template <typename T>
bool nxp(T &v) {
  return next_permutation(begin(v), end(v));
}

// 返り値の型は入力の T に依存
// i 要素目 : [0, a[i])
template <typename T>
vector<vector<T>> product(const vector<T> &a) {
  vector<vector<T>> ret;
  vector<T> v;
  auto dfs = [&](auto rc, int i) -> void {
    if (i == (int)a.size()) {
      ret.push_back(v);
      return;
    }
    for (int j = 0; j < a[i]; j++) v.push_back(j), rc(rc, i + 1), v.pop_back();
  };
  dfs(dfs, 0);
  return ret;
}

// F : function(void(T&)), mod を取る操作
// T : 整数型のときはオーバーフローに注意する
template <typename T>
T Power(T a, long long n, const T &I, const function<void(T &)> &f) {
  T res = I;
  for (; n; f(a = a * a), n >>= 1) {
    if (n & 1) f(res = res * a);
  }
  return res;
}
// T : 整数型のときはオーバーフローに注意する
template <typename T>
T Power(T a, long long n, const T &I = T{1}) {
  return Power(a, n, I, function<void(T &)>{[](T &) -> void {}});
}

template <typename T>
T Rev(const T &v) {
  T res = v;
  reverse(begin(res), end(res));
  return res;
}

template <typename T>
vector<T> Transpose(const vector<T> &v) {
  using U = typename T::value_type;
  if(v.empty()) return {};
  int H = v.size(), W = v[0].size();
  vector res(W, T(H, U{}));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      res[j][i] = v[i][j];
    }
  }
  return res;
}

template <typename T>
vector<T> Rotate(const vector<T> &v, int clockwise = true) {
  using U = typename T::value_type;
  int H = v.size(), W = v[0].size();
  vector res(W, T(H, U{}));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (clockwise) {
        res[W - 1 - j][i] = v[i][j];
      } else {
        res[j][H - 1 - i] = v[i][j];
      }
    }
  }
  return res;
}

}  // namespace Nyaan


// bit operation

namespace Nyaan {
__attribute__((target("popcnt"))) inline int popcnt(const u64 &a) {
  return __builtin_popcountll(a);
}
inline int lsb(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int ctz(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int msb(const u64 &a) { return a ? 63 - __builtin_clzll(a) : -1; }
template <typename T>
inline int gbit(const T &a, int i) {
  return (a >> i) & 1;
}
template <typename T>
inline void sbit(T &a, int i, bool b) {
  if (gbit(a, i) != b) a ^= T(1) << i;
}
constexpr long long PW(int n) { return 1LL << n; }
constexpr long long MSK(int n) { return (1LL << n) - 1; }
}  // namespace Nyaan


// inout

namespace Nyaan {

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  int s = (int)v.size();
  for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

istream &operator>>(istream &is, __int128_t &x) {
  string S;
  is >> S;
  x = 0;
  int flag = 0;
  for (auto &c : S) {
    if (c == '-') {
      flag = true;
      continue;
    }
    x *= 10;
    x += c - '0';
  }
  if (flag) x = -x;
  return is;
}

istream &operator>>(istream &is, __uint128_t &x) {
  string S;
  is >> S;
  x = 0;
  for (auto &c : S) {
    x *= 10;
    x += c - '0';
  }
  return is;
}

ostream &operator<<(ostream &os, __int128_t x) {
  if (x == 0) return os << 0;
  if (x < 0) os << '-', x = -x;
  string S;
  while (x) S.push_back('0' + x % 10), x /= 10;
  reverse(begin(S), end(S));
  return os << S;
}
ostream &operator<<(ostream &os, __uint128_t x) {
  if (x == 0) return os << 0;
  string S;
  while (x) S.push_back('0' + x % 10), x /= 10;
  reverse(begin(S), end(S));
  return os << S;
}

void in() {}
template <typename T, class... U>
void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}

void out() { cout << "\n"; }
template <typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
  cout << t;
  if (sizeof...(u)) cout << sep;
  out(u...);
}

struct IoSetupNya {
  IoSetupNya() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(7);
  }
} iosetupnya;

}  // namespace Nyaan


// debug


#ifdef NyaanDebug
#define trc(...) (void(0))
#endif
#ifndef NyaanDebug
#define trc(...) (void(0))
#endif

#ifndef NyaanLocal
#define trc2(...) (void(0))
#endif


// macro

#define each(x, v) for (auto&& x : v)
#define each2(x, y, v) for (auto&& [x, y] : v)
#define all(v) (v).begin(), (v).end()
#define rep(i, N) for (long long i = 0; i < (long long)(N); i++)
#define repr(i, N) for (long long i = (long long)(N)-1; i >= 0; i--)
#define rep1(i, N) for (long long i = 1; i <= (long long)(N); i++)
#define repr1(i, N) for (long long i = (N); (long long)(i) > 0; i--)
#define reg(i, a, b) for (long long i = (a); i < (b); i++)
#define regr(i, a, b) for (long long i = (b)-1; i >= (a); i--)
#define fi first
#define se second
#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)
#define inl(...)         \
  long long __VA_ARGS__; \
  in(__VA_ARGS__)
#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__)
#define in2(s, t)                           \
  for (int i = 0; i < (int)s.size(); i++) { \
    in(s[i], t[i]);                         \
  }
#define in3(s, t, u)                        \
  for (int i = 0; i < (int)s.size(); i++) { \
    in(s[i], t[i], u[i]);                   \
  }
#define in4(s, t, u, v)                     \
  for (int i = 0; i < (int)s.size(); i++) { \
    in(s[i], t[i], u[i], v[i]);             \
  }
#define die(...)             \
  do {                       \
    Nyaan::out(__VA_ARGS__); \
    return;                  \
  } while (0)


namespace Nyaan {
void solve();
}
int main() { Nyaan::solve(); }


//



using namespace std;

namespace BinaryGCDImpl {
using u64 = unsigned long long;
using i8 = char;

u64 binary_gcd(u64 a, u64 b) {
  if (a == 0 || b == 0) return a + b;
  i8 n = __builtin_ctzll(a);
  i8 m = __builtin_ctzll(b);
  a >>= n;
  b >>= m;
  n = min(n, m);
  while (a != b) {
    u64 d = a - b;
    i8 s = __builtin_ctzll(d);
    bool f = a > b;
    b = f ? b : a;
    a = (f ? d : -d) >> s;
  }
  return a << n;
}

using u128 = __uint128_t;
// a > 0
int ctz128(u128 a) {
  u64 lo = a & u64(-1);
  return lo ? __builtin_ctzll(lo) : 64 + __builtin_ctzll(a >> 64);
}
u128 binary_gcd128(u128 a, u128 b) {
  if (a == 0 || b == 0) return a + b;
  i8 n = ctz128(a);
  i8 m = ctz128(b);
  a >>= n;
  b >>= m;
  n = min(n, m);
  while (a != b) {
    u128 d = a - b;
    i8 s = ctz128(d);
    bool f = a > b;
    b = f ? b : a;
    a = (f ? d : -d) >> s;
  }
  return a << n;
}

}  // namespace BinaryGCDImpl

long long binary_gcd(long long a, long long b) {
  return BinaryGCDImpl::binary_gcd(abs(a), abs(b));
}
__int128_t binary_gcd128(__int128_t a, __int128_t b) {
  if (a < 0) a = -a;
  if (b < 0) b = -b;
  return BinaryGCDImpl::binary_gcd128(a, b);
}

/**
 * @brief binary GCD
 */


using namespace Nyaan;

int dp[5050][5050];

void q() {
  inl(A, B);
  rep(i, A + 1) rep(j, A + 1) dp[i][j] = inf;
  // dp[i][j] : (A-i, B-j) である通り数
  dp[0][0] = 0;
  rep(i, A) rep(j, A + 1) {
    if (dp[i][j] == inf) continue;
    ll g = binary_gcd(A - i, B - j);
    amin(dp[i + g][j], dp[i][j] + 1);
    if (j + g <= A) amin(dp[i][j + g], dp[i][j] + 1);
  }
  int ans = inf;
  rep(j, A + 1) amin(ans, dp[A][j] + 1);
  out(ans);
}

void Nyaan::solve() {
  ll t = 1;
  in(t);
  while (t--) q();
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 4
12 20
114 514

output:

3
4
6

result:

ok 3 lines

Test #2:

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

input:

990
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
2 3
2 4
2...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
3
4
2
3
3
2
3
4
2
3
3
2
3
4
2
3
3
2
3
4
2
3
3
2
3
4
2
3
3
2
3
4
2
...

result:

ok 990 lines

Test #3:

score: 0
Accepted
time: 2823ms
memory: 100804kb

input:

2
4859 299556476011016293
4859 911621905353047038

output:

13
13

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 1220ms
memory: 66408kb

input:

3
3023 291106112607863999
3119 972408313573784567
1229 855784672293155279

output:

14
14
14

result:

ok 3 lines

Test #5:

score: 0
Accepted
time: 1871ms
memory: 83952kb

input:

2
4023 19114808110467479
4014 412762310847841499

output:

13
13

result:

ok 2 lines

Test #6:

score: 0
Accepted
time: 1037ms
memory: 65628kb

input:

3
3119 20432410732723181
1709 985601282232016799
2267 968744673868124159

output:

14
14
14

result:

ok 3 lines

Test #7:

score: 0
Accepted
time: 2250ms
memory: 93396kb

input:

2
4535 722580216492418319
4307 6169979311475963

output:

13
13

result:

ok 2 lines

Test #8:

score: 0
Accepted
time: 2504ms
memory: 101644kb

input:

2
4267 648637147725952319
4885 401781909910741919

output:

14
14

result:

ok 2 lines

Test #9:

score: 0
Accepted
time: 1546ms
memory: 85504kb

input:

2
3023 291106112607863999
4094 673301962326128519

output:

14
13

result:

ok 2 lines

Test #10:

score: 0
Accepted
time: 2128ms
memory: 97476kb

input:

2
4703 494504478938496599
3695 527072187619106999

output:

14
14

result:

ok 2 lines

Test #11:

score: 0
Accepted
time: 217ms
memory: 22716kb

input:

22
412 7166395745631535
895 676140333587834537
139 573525160802896508
56 6042824019123403
911 780448274466371463
970 313274528501049618
903 76359562805399746
104 475404596998181268
2 788944373595428631
277 204462142481604047
389 451716743142184785
369 733427971748817258
269 554386798310409825
543 37...

output:

4
8
6
4
7
6
7
6
3
8
7
6
8
6
5
7
3
3
7
6
6
5

result:

ok 22 lines

Test #12:

score: 0
Accepted
time: 179ms
memory: 22528kb

input:

24
113 419398799469164410
383 717450662733415750
443 686043628038128476
20 899250517211552654
204 346169669232649712
464 521611395675501476
410 894122452066951564
116 660159669509763780
962 217837730253597619
289 675700173448722836
130 329471777741246142
450 666991702473801195
353 760484310637419946...

output:

4
7
6
5
7
5
7
4
7
6
3
4
7
6
6
7
5
7
7
8
7
7
6
6

result:

ok 24 lines

Test #13:

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

input:

19
678 133507297980379931
818 421994924168103967
503 501259104841209060
958 877656450668252853
687 442666986748301973
268 935701093685740836
568 786234655346565680
122 866380973396331141
807 54123923233567773
245 134684982334166386
543 221806505911296821
111 652360199004860361
553 860225758175402852...

output:

7
6
7
8
7
5
4
5
6
8
7
6
7
5
5
4
5
6
7

result:

ok 19 lines

Test #14:

score: 0
Accepted
time: 199ms
memory: 22364kb

input:

19
639 901032098365122475
635 515322255447550084
374 755571300645572102
619 101430914435483134
325 510816267620930173
373 207845131647950998
558 474024480402985236
153 702042115398490774
869 45043603816784980
279 18628511044855421
103 994557089605077208
532 165081709815043226
417 349742245230246428
...

output:

9
7
6
8
6
7
4
6
6
7
5
5
7
7
5
6
6
8
8

result:

ok 19 lines

Test #15:

score: 0
Accepted
time: 21ms
memory: 6096kb

input:

199
6 349576221631571320
97 422699450330996735
31 589592746688366307
57 858302104323820939
82 390853367915026019
11 340917463299735569
32 185588466253907983
17 456086267779461856
82 44061092128004219
28 27906898155718701
17 358195386652849006
53 117524674404177851
40 287782356544825555
19 2862632394...

output:

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

result:

ok 199 lines

Test #16:

score: 0
Accepted
time: 21ms
memory: 5764kb

input:

195
51 767009661890162122
48 677544419672371709
60 591373361970104616
84 141534595240530690
87 116531056808411746
29 229632508086559065
23 470792692724825252
45 839302114508975768
94 664803074895337778
45 415372336860436849
28 202777563688922479
29 640816432615045290
100 704242439535912153
97 853111...

output:

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

result:

ok 195 lines

Test #17:

score: 0
Accepted
time: 6ms
memory: 5900kb

input:

182
48 55
95 152
62 90
100 118
20 30
39 40
60 79
62 103
20 22
5 5
29 41
12 19
84 90
100 121
61 88
75 76
73 116
35 64
32 59
88 174
82 142
28 53
79 99
83 85
65 122
86 142
34 67
85 132
80 129
46 59
74 133
61 108
47 54
63 91
17 29
75 136
34 49
54 55
98 195
76 119
45 79
25 42
4 5
89 133
19 35
55 95
62 98...

output:

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

result:

ok 182 lines

Test #18:

score: 0
Accepted
time: 7ms
memory: 5856kb

input:

201
75 142
12 16
83 160
23 38
72 128
88 107
71 139
71 95
14 17
67 128
99 170
66 128
7 13
94 144
71 95
42 51
21 28
20 22
42 65
21 42
92 97
5 10
87 102
28 41
31 46
46 53
30 36
32 61
26 34
30 33
68 84
6 8
97 147
86 100
11 17
60 68
89 136
57 86
8 8
50 76
7 9
45 79
97 192
33 41
48 77
91 133
30 45
60 96
3...

output:

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

result:

ok 201 lines

Test #19:

score: 0
Accepted
time: 926ms
memory: 87668kb

input:

2
4157 23039
4199 64439

output:

15
15

result:

ok 2 lines

Test #20:

score: 0
Accepted
time: 669ms
memory: 66068kb

input:

3
2591 31919
2879 64343
3119 91727

output:

15
15
15

result:

ok 3 lines

Test #21:

score: 0
Accepted
time: 863ms
memory: 65076kb

input:

3
2879 9722159
2939 4324319
3031 9979199

output:

16
16
16

result:

ok 3 lines

Test #22:

score: 0
Accepted
time: 1035ms
memory: 71068kb

input:

3
2879 5266799
3347 9192959
3399 4324319

output:

16
16
16

result:

ok 3 lines

Test #23:

score: 0
Accepted
time: 1529ms
memory: 99772kb

input:

2
4799 9729719
4859 1552318

output:

16
16

result:

ok 2 lines

Extra Test:

score: 0
Extra Test Passed