QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104825#6300. Best Carry Player 2maspyAC ✓1693ms3580kbC++2014.6kb2023-05-12 01:42:352023-05-12 01:42:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-12 01:42:37]
  • 评测
  • 测评结果:AC
  • 用时:1693ms
  • 内存:3580kb
  • [2023-05-12 01:42:35]
  • 提交

answer

#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) \
  for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T, typename U>
T ceil(T x, U y) {
  return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
  return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sum = 0;
  for (auto &&a: A) sum += a;
  return sum;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  assert(!que.empty());
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  assert(!que.empty());
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  vc<T> B(len(I));
  FOR(i, len(I)) B[i] = A[I[i]];
  return B;
}
#endif
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>

namespace fastio {
#define FASTIO
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.write(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};

struct has_read_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.read(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};

struct Scanner {
  FILE *fp;
  char line[(1 << 15) + 1];
  size_t st = 0, ed = 0;
  void reread() {
    memmove(line, line + st, ed - st);
    ed -= st;
    st = 0;
    ed += fread(line + ed, 1, (1 << 15) - ed, fp);
    line[ed] = '\0';
  }
  bool succ() {
    while (true) {
      if (st == ed) {
        reread();
        if (st == ed) return false;
      }
      while (st != ed && isspace(line[st])) st++;
      if (st != ed) break;
    }
    if (ed - st <= 50) {
      bool sep = false;
      for (size_t i = st; i < ed; i++) {
        if (isspace(line[i])) {
          sep = true;
          break;
        }
      }
      if (!sep) reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    while (true) {
      size_t sz = 0;
      while (st + sz < ed && !isspace(line[st + sz])) sz++;
      ref.append(line + st, sz);
      st += sz;
      if (!sz || st != ed) break;
      reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    bool neg = false;
    if (line[st] == '-') {
      neg = true;
      st++;
    }
    ref = T(0);
    while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
    if (neg) ref = -ref;
    return true;
  }
  template <typename T,
            typename enable_if<has_read<T>::value>::type * = nullptr>
  inline bool read_single(T &x) {
    x.read();
    return true;
  }
  bool read_single(double &ref) {
    string s;
    if (!read_single(s)) return false;
    ref = std::stod(s);
    return true;
  }
  bool read_single(char &ref) {
    string s;
    if (!read_single(s) || s.size() != 1) return false;
    ref = s[0];
    return true;
  }
  template <class T>
  bool read_single(vector<T> &ref) {
    for (auto &d: ref) {
      if (!read_single(d)) return false;
    }
    return true;
  }
  template <class T, class U>
  bool read_single(pair<T, U> &p) {
    return (read_single(p.first) && read_single(p.second));
  }
  template <size_t N = 0, typename T>
  void read_single_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
      auto &x = std::get<N>(t);
      read_single(x);
      read_single_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool read_single(tuple<T...> &tpl) {
    read_single_tuple(tpl);
    return true;
  }
  void read() {}
  template <class H, class... T>
  void read(H &h, T &... t) {
    bool f = read_single(h);
    assert(f);
    read(t...);
  }
  Scanner(FILE *fp) : fp(fp) {}
};

struct Printer {
  Printer(FILE *_fp) : fp(_fp) {}
  ~Printer() { flush(); }

  static constexpr size_t SIZE = 1 << 15;
  FILE *fp;
  char line[SIZE], small[50];
  size_t pos = 0;
  void flush() {
    fwrite(line, 1, pos, fp);
    pos = 0;
  }
  void write(const char val) {
    if (pos == SIZE) flush();
    line[pos++] = val;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  void write(T val) {
    if (pos > (1 << 15) - 50) flush();
    if (val == 0) {
      write('0');
      return;
    }
    if (val < 0) {
      write('-');
      val = -val; // todo min
    }
    size_t len = 0;
    while (val) {
      small[len++] = char(0x30 | (val % 10));
      val /= 10;
    }
    for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
    pos += len;
  }
  void write(const string s) {
    for (char c: s) write(c);
  }
  void write(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++) write(s[i]);
  }
  void write(const double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  void write(const long double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  template <typename T,
            typename enable_if<has_write<T>::value>::type * = nullptr>
  inline void write(T x) {
    x.write();
  }
  template <class T>
  void write(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  template <class T, class U>
  void write(const pair<T, U> val) {
    write(val.first);
    write(' ');
    write(val.second);
  }
  template <size_t N = 0, typename T>
  void write_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
      if constexpr (N > 0) { write(' '); }
      const auto x = std::get<N>(t);
      write(x);
      write_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool write(tuple<T...> tpl) {
    write_tuple(tpl);
    return true;
  }
  template <class T, size_t S>
  void write(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  void write(i128 val) {
    string s;
    bool negative = 0;
    if (val < 0) {
      negative = 1;
      val = -val;
    }
    while (val) {
      s += '0' + int(val % 10);
      val /= 10;
    }
    if (negative) s += "-";
    reverse(all(s));
    if (len(s) == 0) s = "0";
    write(s);
  }
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  printer.write(head);
  if (sizeof...(Tail)) printer.write(' ');
  print(forward<Tail>(tail)...);
}

void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
  scanner.read(head);
  read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"

u64 dp[20][20][2][2];

void solve() {
  LL(N, K);

  if (K == 0 && N % 10 == 0) { return print(1); }

  ll exp = 0;
  while (N % 10 == 0) {
    ++exp;
    N /= 10;
  }

  // N/10^n, k
  ll LIM = 20;
  FOR(a, LIM) FOR(b, K + 1) FOR(c, 2) FOR(d, 2) { dp[a][b][c][d] = u64(-1); }

  FOR_R(n, LIM) {
    ll x = N;
    FOR(n) x /= 10;

    ll d = x % 10;
    FOR(k, K + 1) {
      FOR(carry, 2) {
        FOR(can_0, 2) {
          if (n == LIM - 1) {
            if (k == 0) { dp[n][k][carry][can_0] = (can_0 ? 0 : 1); }
            continue;
          }

          ll now = (d + carry);
          vc<int> cand = {0, 1, 10 - now};

          for (auto&& a: cand) {
            if (a >= 10) continue;
            int c = (carry + d + a) >= 10;
            int can = (can_0 || a > 0);
            if (k < c) continue;
            u64 y = dp[n + 1][k - c][c][can];
            if (y == u64(-1)) continue;
            y = 10 * y + a;
            chmin(dp[n][k][carry][can_0], y);
          }
        }
      }
    }
  }
  u64 ANS = dp[0][K][0][0];
  string S = to_string(ANS);
  FOR(exp) S += '0';
  print(S);
}

signed main() {
  INT(T);
  FOR(T) solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
9910

result:

ok 4 lines

Test #2:

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

input:

21
999990000099999 0
999990000099999 1
999990000099999 2
999990000099999 3
999990000099999 4
999990000099999 5
999990000099999 6
999990000099999 7
999990000099999 8
999990000099999 9
999990000099999 10
999990000099999 11
999990000099999 12
999990000099999 13
999990000099999 14
999990000099999 15
999...

output:

100000
10000
1000
100
10
1
900001
9900001
99900001
999900001
10000000001
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000
1000000000000000000

result:

ok 21 lines

Test #3:

score: 0
Accepted
time: 1662ms
memory: 3480kb

input:

100000
119111011091190000 10
1911011191011999 16
110099199000119 0
19009911191091011 13
199090909919000900 17
19009010011919110 5
90910190019900091 18
10911100000101111 1
110090011101119990 4
100909999119090000 12
90901119109011100 2
111010119991090101 4
900991019109199009 5
100919919990991119 8
911...

output:

88988908810000
8088988808988001
10
88808908989
9800909090080999100
80890
909089809980099909
9
80010
9090000880910000
8900
9909
991
9008900
8880880090
8080090801
8009900808909899
80880898981
909
8800909
99988889901
89908888089
980908890980099000
100
9889801
81
908890008099900891
880990801
9998099
890...

result:

ok 100000 lines

Test #4:

score: 0
Accepted
time: 1644ms
memory: 3520kb

input:

100000
900019901991919191 0
119199000910909911 18
190001990019910009 12
110091191100109001 6
10191091999110091 18
990011110190190090 5
900900000199919019 14
119100019910100099 17
909911111001111901 3
901100909911099 10
919009910101990019 7
911011009199199100 11
919111110190110999 0
91010111901190900...

output:

1
880800999089090089
9980089991
890999
989808908000889909
809910
99999800080990
80899980089899901
99
9090088901
8009981
8990800800900
1000
99089898880988091000
99101000
8988889980809
99008880080090009
10900
9998889909
889009889909901
808909990100
9090008889889089010
8099888899000
990898099098891000
...

result:

ok 100000 lines

Test #5:

score: 0
Accepted
time: 1693ms
memory: 3476kb

input:

100000
90109000009190190 17
100091999119191900 13
119911991111100009 10
191199111011010091 12
99199110109099919 17
900011911110190199 7
990109199990010100 8
90191099199119101 13
101009019910001111 2
999199010010119119 1
91100991091900090 12
901100110901100900 4
10910910019101109 13
99011019901999010...

output:

909890999990809810
908000880808100
8888900991
888988990009
800889890900081
9809801
9990900
8900800880909
89
1
9008908099910
899100
9089980898891
80009899
1009
101
9899888080810
8808900888888981
80801
89890988080889809
88998009000900
90989809809890
889999100
988890810
98991
9900
9990008880980009100
8...

result:

ok 100000 lines

Test #6:

score: 0
Accepted
time: 1655ms
memory: 3580kb

input:

100000
190090090190009901 8
110911911110919010 16
101101009991110 1
901011000199900 5
900119091100999099 11
191011011019019001 2
101090009999910019 3
999100919001019919 9
9910090910011001 14
909091191100090191 18
101190999191199909 16
9190199191991 11
19909100909900001 9
10001910011001019 18
1900000...

output:

9990099
89088088889080990
90
9800100
8899000901
99
981
998980090
89909089989009
90908808899909809
8809000808800091
9800808009
90099999
989998089988998981
1
98089
8898980988900100
898890989900
989090
9
989890008909999
100
9099
9
100
89909900091
10
9880899008810
999880098900880991000
9809088998810089
...

result:

ok 100000 lines

Test #7:

score: 0
Accepted
time: 1632ms
memory: 3480kb

input:

100000
900101011999010011 17
109019011901009119 6
100001099109091110 12
909900011111999190 17
9191909111910001 17
99119900909191199 15
919999901110090900 11
910099099001091991 5
91019109990991191 13
911019000990111110 1
999099011119100011 1
99199110111911199 11
190111991190901100 4
91011190910911090...

output:

99898988000989990
990881
8900890908890
90099988888000810
90808090888089999
880099090808900
98890010100
8009
890009008809
90
9
89888088801
98900
890889100
988998880990989
98908090
910
899009998809889
990099080809100
9
8980998909898099
800090910
910
9
900
809888909898888810
10
99091
9909998909081
8989...

result:

ok 100000 lines

Test #8:

score: 0
Accepted
time: 1636ms
memory: 3552kb

input:

100000
556678926267652258 2
929929657746014640 13
110808054835665500 13
603411220842314620 18
236920943881957481 13
228392045048443659 0
800016407284399949 4
891810444049711534 10
673038060913134012 8
497925775526719327 2
320546054458668782 7
22937449060095980 7
592739113092913372 15
378621488315118...

output:

42
70342253986000
191945164334500
9396588779157685380
9056118042519
10
60
5950288466
86865990
73
1331218
39904020
260886907086628
21378511684881483
27
74912313591831403
202572281666000677
10
2445141061145
1057747266722529
93751641
633355727
6592761984728
5909230
346570
397717429
97513000559636020
27...

result:

ok 100000 lines

Test #9:

score: 0
Accepted
time: 1623ms
memory: 3472kb

input:

100000
985148522880985676 12
868739853875504421 3
674884930693570868 4
228845158360886431 12
792918087718155359 13
418451749398757718 1
422674667930380991 18
213704887948982107 7
502947671811732448 6
117372403303189003 18
952382059266835617 17
314526102032441554 1
267958994219475762 10
1012739058027...

output:

477119014324
579
9132
841639113569
1912281844641
2
577325332069619009
1017893
267552
882627596696810997
47617940733164390
6
5780524300
6094197297637
26289587644103349
30
325653666642794763
5920004513991
87
870676180905
49658522498
4270035752229599
76370380
362872
27543029342
814276956422751
12709362...

result:

ok 100000 lines

Test #10:

score: 0
Accepted
time: 1668ms
memory: 3552kb

input:

100000
862428474789769520 15
861402445383237914 18
12164614960128916 2
153533193098719886 18
669778305254901625 12
421900684426699134 2
64570921371658045 13
98884778403809206 17
148127093775414570 6
424157195766048310 16
264315954064627485 3
543186220365103714 7
28644666339278806 5
70558958178538527...

output:

7571525210230480
138597554616762086
90
846466806901280114
694745098375
66
9078628341955
1115221596190794
4585430
75842804233951690
515
4896286
21194
94410418214614721
6562581535068
503
6054086
39
785986630
26189732238613
625251091606
35790342913626940
4208119
1
378653717
3895
8030
69
4673598217306
1...

result:

ok 100000 lines

Test #11:

score: 0
Accepted
time: 1649ms
memory: 3536kb

input:

100000
29992812429491364 18
280638300691924745 1
773687550709513181 14
817767638240244197 17
795567381538619956 12
667173680932755212 3
692547920587275657 7
899816685881310369 0
887418305313852047 4
114296293682280216 6
635770909236446320 8
79779559576226344 7
723885861365146899 18
35614586662297882...

output:

970007187570508636
5
12449290486819
82232361759755803
618461380044
788
2724343
10
7953
719784
763553700
3773656
276114138634853101
4133377021176
1666925430
2579876078550
238902836
3871039799670569
8107903824643082
37383232105658733
35851211841888
78703
9102167
615719
24910554
7980007100
455768
89519...

result:

ok 100000 lines

Test #12:

score: 0
Accepted
time: 1615ms
memory: 3480kb

input:

100000
70221819048738918 8
854206908365074549 16
191105114278421489 6
436751765758778908 4
208357620673273826 12
454216540686693180 17
715905540992087591 16
714996112786224737 16
362288917871644217 17
899675961879259925 4
767901008331879831 0
248327679387972712 14
654991270785448631 0
54125799900198...

output:

51261082
5793091634925451
578511
1092
379326726174
545783459313306820
4094459007912409
5003887213775263
37711082128355783
75
1
72320612027288
1
13800
1839205
651837642537117
2359
69488171498607443
93375957030
1
912677814690334
368382885111
7
774120
208729
58343
983993010
1
632128
6552
5445728345
98
...

result:

ok 100000 lines

Test #13:

score: 0
Accepted
time: 1626ms
memory: 3532kb

input:

100000
990009990909090099 0
90090009900900000 16
99999009900090099 0
909090909990009990 6
9900900900009 8
900990900000090099 7
9099090099990090 3
90900909990099099 2
900999009990909909 17
999009099990909099 4
909099909099099009 18
999009999090000990 10
99000000999009990 6
909909900909 12
99009909999...

output:

100
999909909990099100000
100
10000010
99109991
9909901
100000
1
99000990009090101
901
90900090900900991
910099010
991000
90090099091
99009000010000
90000000001000
9990000000910000
99990001000
10
999009990100100
99909990990010
90999999991
99900999000100000
999909990000009010
990099999090009991
99999...

result:

ok 100000 lines

Test #14:

score: 0
Accepted
time: 1627ms
memory: 3480kb

input:

100000
909999990909990099 3
99009009999090009 13
90999009009000900 11
90990090000999009 12
999090000009900990 8
999009000900990990 16
90099090900990900 16
90099090900990 17
909000099090909090 16
90000909990909909 2
99090900099000990 4
990090099909000900 3
900090009909909909 6
99990909000999999 9
909...

output:

901
990000909991
990991009100
909999000991
990099010
990999099009100
909900909099009100
999909900909099010
90999900909091010
100
99010
99100
90101
999000010
9099091
9990099900990010000
100
99990100000
90000091
9991
999999909091
90009990000901
999099099910
9990009091
999910099910
900990000009101
9999...

result:

ok 100000 lines

Test #15:

score: 0
Accepted
time: 1630ms
memory: 3572kb

input:

100000
900099900000099009 6
90099000099999090 9
90090909099999900 3
99900999999000090 5
99000090909990000 8
909900900090990000 16
90009099900009990 11
909990000099090990 8
9090000990000900 15
9099999009000 5
9090009900999 9
90990900900990 10
9999990909090909 15
99900000009990099 13
99909909099999090...

output:

900991
9900000910
100000
10000000
909090010000
99090099099909010000
900099990100
900909010
90909999009999100
1000000
990099001
9099099100
9090909101
9999990009901
10000
10991
90999901
100
999009099999091
909101
9909099999990090100
9090099000901
909901
91
99999090090901
99901091
100
90009099099100
10...

result:

ok 100000 lines

Test #16:

score: 0
Accepted
time: 1615ms
memory: 3500kb

input:

100000
999909009009909909 15
999900090909000099 5
990990009090909090 0
990990090909999009 18
900000990009990990 14
90099909900090000 17
990909099999099900 6
900000909990909009 4
999900990000990 14
999000909999090990 2
90090099900999000 1
99000000099099900 11
990909990009090999 15
990909900900000 4
9...

output:

90990990091000
99901
1
9009909090000991
999009990009010
999909900090099910000
1010000
991
99009999010
10
100000
9999900900100
90009990909001
109100000
9100
999909100
90000010
99090000009999910
909091
90900010
9009000999999009910
101
99991
9999900990009990910
90099900901
9999990099910
1091000
1
1
909...

result:

ok 100000 lines

Test #17:

score: 0
Accepted
time: 1627ms
memory: 3516kb

input:

100000
90090009909009909 18
990990090099990909 1
999000009909090909 11
99000909099009090 11
90099990900900000 14
90000009090900900 0
990909009999090090 1
909990090099090900 6
909909990090090000 13
99009009000090090 18
900099990990990090 6
909099909009999990 4
99009909000990999 10
99000999090999090 0...

output:

909909990090990091
1
90090909091
90900990910
9909900009099100000
1
10
909100
90090009910910000
9900990990999909910
9010010
1000
999009001
1
90009000909091
9090900010
99999090009990990100
901000
9090090090101
9909000901
100000
9000009001
10
909909991000000
999990099090900001000
99009900001
1000000
90...

result:

ok 100000 lines