QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#142920#4658. 移除石子hos.lyric🐇#50 22ms5544kbC++1411.5kb2023-08-20 04:11:252023-08-20 04:11:29

Judging History

This is the latest submission verdict.

  • [2023-08-20 04:11:29]
  • Judged
  • Verdict: 50
  • Time: 22ms
  • Memory: 5544kb
  • [2023-08-20 04:11:25]
  • Submitted

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 <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; }

////////////////////////////////////////////////////////////////////////////////
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); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

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


struct Dfa {
  int n, s, a;
  vector<vector<int>> to;
  vector<bool> ac;
  Dfa() {}
  Dfa(int n_, int s_, int a_) : n(n_), s(s_), a(a_) {
    to.assign(n, vector<int>(a, -1));
    ac.assign(n, false);
  }
  int addState() {
    const int u = n++;
    to.emplace_back(a, -1);
    ac.push_back(false);
    return u;
  }

  vector<int> ids;
  vector<vector<int>> uss;
  vector<vector<vector<int>>> revs;
  Dfa minimize() {
    for (int u = 0; u < n; ++u) for (int e = 0; e < a; ++e) {
      assert(to[u][e] != -1);
    }
    std::queue<int> que;
    ids.assign(n, -1);
    // BFS to find reachable states
    ids[s] = -2;
    que.push(s);
    for (; !que.empty(); ) {
      const int u = que.front(); que.pop();
      for (int e = 0; e < a; ++e) {
        if (ids[to[u][e]] == -1) {
          ids[to[u][e]] = -2;
          que.push(to[u][e]);
        }
      }
    }
    // partition
    revs.assign(n, vector<vector<int>>(a));
    for (int u = 0; u < n; ++u) {
      if (ids[u] != -1) {
        for (int e = 0; e < a; ++e) revs[to[u][e]][e].push_back(u);
      }
    }
    int nn = 2;
    uss.assign(n, {});
    for (int u = 0; u < n; ++u) {
      if (ids[u] == -2) uss[ids[u] = ac[u] ? 1 : 0].push_back(u);
    }
    // empty, all
    if (uss[1].empty() || uss[0].empty()) {
      Dfa dfa(1, 0, a);
      dfa.to[0].assign(a, 0);
      dfa.ac[0] = uss[0].empty();
      return dfa;
    }
    que.push((uss[1].size() <= uss[0].size()) ? 1 : 0);
    for (; !que.empty(); ) {
      const int x = que.front(); que.pop();
      std::set<int> parter(uss[x].begin(), uss[x].end());
      for (int e = 0; e < a; ++e) {
        std::set<int> apps;
        for (const int u : parter) for (const int v : revs[u][e]) {
          apps.insert(ids[v]);
        }
        for (const int y : apps) {
          vector<int> vs1, vs0;
          for (const int v : uss[y]) {
            (parter.count(to[v][e]) ? vs1 : vs0).push_back(v);
          }
          if (!vs0.empty()) {
            if (vs1.size() < vs0.size()) vs1.swap(vs0);
            for (const int v : vs0) ids[v] = nn;
            que.push(nn);
            uss[y].swap(vs1);
            uss[nn++].swap(vs0);
          }
        }
      }
    }
    uss.resize(nn);
    // make new DFA
    Dfa dfa(nn, ids[s], a);
    for (int x = 0; x < nn; ++x) {
      const int u = uss[x][0];
      for (int e = 0; e < a; ++e) dfa.to[x][e] = ids[to[u][e]];
      dfa.ac[x] = ac[u];
    }
    return dfa;
  }
};

bool isIsomorphic(const Dfa &dfa0, const Dfa &dfa1) {
  if (dfa0.n != dfa1.n) return false;
  if (dfa0.a != dfa1.a) return false;
  const int n = dfa0.n, a = dfa0.a;
  vector<int> f01(n, -1), f10(n, -1);
  std::queue<int> que;
  f10[f01[dfa0.s] = dfa1.s] = dfa0.s;
  que.push(dfa0.s);
  que.push(dfa1.s);
  for (; !que.empty(); ) {
    const int u0 = que.front(); que.pop();
    const int u1 = que.front(); que.pop();
    for (int e = 0; e < a; ++e) {
      const int v0 = dfa0.to[u0][e], v1 = dfa1.to[u1][e];
      if (f01[v0] == -1 && f10[v1] == -1) {
        f10[f01[v0] = v1] = v0;
        que.push(v0);
        que.push(v1);
      } else {
        if (f01[v0] == -1 || f10[v1] == -1) return false;
        if (f10[f01[v0]] != v0 || f01[f10[v1]] != v1) return false;
      }
    }
  }
  for (int u0 = 0; u0 < n; ++u0) {
    if (f01[u0] != -1 && dfa0.ac[u0] != dfa1.ac[f01[u0]]) return false;
  }
  return true;
}

struct Nfa {
  int n, s, a;
  vector<vector<vector<int>>> to;
  vector<vector<int>> eps;
  vector<bool> ac;
  Nfa(int n_, int s_, int a_) : n(n_), s(s_), a(a_) {
    to.assign(n, vector<vector<int>>(a));
    eps.assign(n, {});
    ac.assign(n, false);
  }
  int addState() {
    const int u = n++;
    to.emplace_back(a);
    eps.emplace_back();
    ac.push_back(false);
    return u;
  }
  Dfa toDfa() const {
    std::queue<int> que;
    vector<std::set<int>> epsed(n);
    for (int u = 0; u < n; ++u) {
      epsed[u].insert(u);
      que.push(u);
      for (; !que.empty(); ) {
        const int v = que.front(); que.pop();
        for (const int w : eps[v]) if (epsed[u].insert(w).second) que.push(w);
      }
    }
    vector<std::set<int>> ps;
    std::map<std::set<int>, int> tr;
    que.push(0);
    ps.push_back(epsed[s]);
    tr[epsed[s]] = 0;
    Dfa dfa(1, 0, a);
    for (; !que.empty(); ) {
      const int x = que.front(); que.pop();
      for (int e = 0; e < a; ++e) {
        std::set<int> pp;
        for (const int u : ps[x]) for (const int v : to[u][e]) {
          for (const int w : epsed[v]) pp.insert(w);
        }
        auto it = tr.find(pp);
        if (it == tr.end()) {
          que.push(dfa.n);
          ps.push_back(pp);
          dfa.to[x][e] = tr[pp] = dfa.n;
          dfa.addState();
        } else {
          dfa.to[x][e] = it->second;
        }
      }
    }
    for (int x = 0; x < dfa.n; ++x) for (const int u : ps[x]) {
      if (ac[u]) dfa.ac[x] = true;
    }
    return dfa;
  }
};


int N, K;
vector<int> L, R;

Mint dp[1010][60];

int main() {
  /*
    state
    length 1: [0, 3]
    length 2: [0, 3]
    length 3: [0, 6]
  */
  Nfa nfa(4 * 4 * 7, 0, 5);
  for (int c1 = 0; c1 <= 3; ++c1) for (int c2 = 0; c2 <= 3; ++c2) for (int c3 = 0; c3 <= 6; ++c3) {
    const int u = (c1 * 4 + c2) * 7 + c3;
    nfa.ac[u] = (c1 == 0 && c2 == 0);
    for (int a = 0; a < nfa.a; ++a) {
      for (int d0 = 0; d0 <= 3; ++d0) for (int d3 = 0; d3 <= c3; ++d3) {
        const int remain = a - (d0 + c1 + c2 + d3);
        if (remain == 0 || remain >= 2) {
          if (d0 <= 3 && c1 <= 3 && c2 + d3 <= 6) {
            const int v = (d0 * 4 + c1) * 7 + (c2 + d3);
            nfa.to[u][a].push_back(v);
          }
        }
      }
    }
  }
  const Dfa dfa = nfa.toDfa().minimize();
cerr<<"dfa: n = "<<dfa.n<<", s = "<<dfa.s<<", a = "<<dfa.a<<endl;
for(int u=0;u<dfa.n;++u)cerr<<"to["<<u<<"] = "<<dfa.to[u]<<endl;
cerr<<"ac = "<<dfa.ac<<endl;
  for (int u = 0; u < dfa.n; ++u) {
    for (int a = 4; a < dfa.a; ++a) {
      assert(dfa.to[u][4] == dfa.to[u][a]);
    }
  }
  
  
  Dfa DFAs[3];
  for (K = 0; K <= 2; ++K) {
    Nfa NFA(dfa.n * (K + 1), dfa.s * (K + 1) + 0, 5);
    for (int u = 0; u < dfa.n; ++u) for (int k = 0; k <= K; ++k) {
      const int x = u * (K + 1) + k;
      NFA.ac[x] = (dfa.ac[u] && k == K);
      for (int a = 0; a < 5; ++a) {
        for (int dk = 0; k + dk <= K; ++dk) {
          const int v = dfa.to[u][min(a + dk, 4)];
          const int y = v * (K + 1) + (k + dk);
          NFA.to[x][a].push_back(y);
        }
      }
    }
    DFAs[K] = NFA.toDfa().minimize();
cerr<<"DFA["<<K<<"]: n = "<<DFAs[K].n<<", s = "<<DFAs[K].s<<", a = "<<DFAs[K].a<<endl;
// for(int u=0;u<DFAs[K].n;++u)cerr<<"to["<<u<<"] = "<<DFAs[K].to[u]<<endl;
// cerr<<"ac = "<<DFAs[K].ac<<endl;
  }
  assert(isIsomorphic(dfa, DFAs[0]));
  
  
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d%d", &N, &K);
    L.resize(N);
    R.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d%d", &L[i], &R[i]);
    }
cerr<<"N = "<<N<<", K = "<<K;
if(N<=5)cerr<<", L = "<<L<<", R = "<<R;
cerr<<endl;
    
    const Dfa &DFA = DFAs[K];
    
    memset(dp, 0, sizeof(dp));
    dp[0][DFA.s] = 1;
    for (int i = 0; i < N; ++i) {
      for (int u = 0; u < DFA.n; ++u) {
        for (int a = 0; a < 4; ++a) if (L[i] <= a && a <= R[i]) {
          dp[i + 1][DFA.to[u][a]] += dp[i][u];
        }
        int l = L[i], r = R[i];
        chmax(l, 4);
        if (l <= r) {
          dp[i + 1][DFA.to[u][4]] += dp[i][u] * (r - l + 1);
        }
      }
    }
    Mint ans = 0;
    for (int u = 0; u < DFA.n; ++u) if (DFA.ac[u]) {
      ans += dp[N][u];
    }
    printf("%u\n", ans.x);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

詳細信息

Test #1:

score: 5
Accepted
time: 15ms
memory: 5488kb

input:

10
5 2
1 3
0 5
1 4
0 1
1 2
5 0
0 3
0 1
0 3
0 2
1 1
5 0
1 2
1 3
3 3
3 4
0 0
5 1
1 1
0 4
3 4
0 4
0 4
5 0
1 1
1 5
0 5
0 1
1 4
5 2
3 4
2 4
0 3
1 3
0 1
5 2
1 4
0 4
0 4
1 2
0 1
5 0
0 4
0 5
0 2
3 4
1 1
3 1
0 5
0 4
0 4
3 1
1 5
1 4
1 4

output:

288
20
10
246
138
144
400
99
148
79

result:

ok 10 numbers

Test #2:

score: 5
Accepted
time: 22ms
memory: 5544kb

input:

10
5 0
0 0
1 4
2 4
1 4
0 3
5 0
1 4
1 5
4 5
0 4
3 4
5 0
1 4
0 3
0 2
3 5
1 2
5 1
1 2
0 4
1 3
1 4
2 4
5 0
0 5
0 1
0 1
0 1
1 2
5 0
1 3
0 3
1 2
1 5
2 3
5 1
0 5
1 5
0 4
0 1
0 3
5 0
1 3
1 3
1 5
1 4
1 4
3 1
0 4
0 1
0 5
3 1
1 3
1 5
1 2

output:

155
392
167
359
26
165
1182
646
58
29

result:

ok 10 numbers

Test #3:

score: 5
Accepted
time: 14ms
memory: 5544kb

input:

10
5 2
0 5
0 3
0 3
1 4
2 4
5 0
1 3
1 4
0 1
4 4
1 5
5 1
0 3
0 5
1 1
1 2
2 4
5 0
1 5
1 4
1 4
1 3
3 4
5 0
1 2
1 4
3 4
1 3
0 4
5 2
1 3
1 3
0 5
1 5
3 3
5 2
0 5
0 4
1 3
1 4
2 3
5 0
0 3
1 1
1 1
0 2
1 2
3 1
0 4
0 4
0 5
3 1
1 3
1 4
1 3

output:

1152
77
144
450
224
270
720
12
148
35

result:

ok 10 numbers

Test #4:

score: 5
Accepted
time: 14ms
memory: 5488kb

input:

10
1000 0
1 1
4 4
5 5
0 0
2 2
1 1
810768785 810768785
4 4
3 3
2 2
3 3
145678201 145678201
539852093 539852093
3 3
824112952 824112952
3 3
929791266 929791266
3 3
3 3
3 3
0 0
2 2
4 4
4 4
3 3
194646042 194646042
2 2
4 4
3 3
922195284 922195284
676532270 676532270
3 3
3 3
3 3
2 2
5 5
0 0
749247771 7492...

output:

0
1
0
0
1
1
0
0
1
1

result:

ok 10 numbers

Test #5:

score: 5
Accepted
time: 16ms
memory: 5500kb

input:

10
1000 0
6 6
1 1
4 4
2 2
560230659 560230659
2 2
213604931 213604931
4 4
324411778 324411778
5 5
5 5
0 0
68050744 68050744
5 5
1 1
363300583 363300583
2 2
2 2
4 4
957157567 957157567
6 6
3 3
1 1
3 3
2 2
4 4
4 4
4 4
6 6
2 2
0 0
5 5
404555679 404555679
3 3
2 2
1 1
6 6
2 2
4 4
6 6
891397980 891397980
...

output:

0
0
0
1
1
0
0
1
1
1

result:

ok 10 numbers

Test #6:

score: 0
Runtime Error

input:

10
1000 69
1 1
1 1
4 4
2 2
1 1
4 4
2 2
1 1
4 4
1 1
0 0
0 0
0 0
0 0
2 2
3 3
1 1
2 2
3 3
3 3
0 0
4 4
3 3
1 1
0 0
2 2
80216297 80216297
1 1
2 2
367878274 367878274
174533945 174533945
746703557 746703557
2 2
245782009 245782009
4 4
0 0
3 3
2 2
0 0
4 4
3 3
1 1
3 3
2 2
2 2
0 0
0 0
114241517 114241517
0 0...

output:


result:


Test #7:

score: 0
Runtime Error

input:

10
1000 65
3 3
3 3
1 1
3 3
1 1
2 2
2 2
2 2
0 0
1 1
0 0
0 0
3 3
4 4
373336720 373336720
1 1
1 1
4 4
1 1
2 2
1 1
2 2
0 0
4 4
1 1
1 1
1 1
0 0
1 1
1 1
0 0
252809300 252809300
707166173 707166173
1 1
960759336 960759336
2 2
2 2
0 0
3 3
0 0
3 3
0 0
4 4
0 0
1 1
2 2
2 2
1 1
1 1
0 0
780478034 780478034
0 0
4...

output:


result:


Test #8:

score: 0
Runtime Error

input:

10
1000 48
0 0
1 1
2 2
13941343 13941343
2 2
2 2
0 0
265685928 265685928
0 0
1 1
1 1
3060608 3060608
2 2
0 0
0 0
0 0
1 1
15129724 15129724
0 0
4 4
1 1
297040447 297040447
1 1
3 3
0 0
2 2
1 1
4 4
2 2
1 1
0 0
934313429 934313429
1 1
1 1
1 1
0 0
0 0
1 1
686872027 686872027
1 1
1 1
352017933 352017933
0...

output:


result:


Test #9:

score: 5
Accepted
time: 18ms
memory: 5492kb

input:

10
1000 0
1 3
0 367881929
0 908183395
0 294640584
0 130052878
0 460518566
0 380428363
1 6
0 617579265
1 855387669
0 2
0 2
0 4
0 730594613
2 275854270
0 1
0 4
0 5
0 151804972
0 567677095
0 479119369
0 665035693
0 3
0 1
0 1
0 3
0 985093649
0 1
0 255818414
0 4
0 1
0 163849171
0 525071507
3 823579180
0 ...

output:

173378122
136961982
916142335
254618610
127210945
688422027
194757687
199396796
90178999
86533905

result:

ok 10 numbers

Test #10:

score: 5
Accepted
time: 13ms
memory: 5480kb

input:

10
1000 0
0 220657533
0 490453431
0 663241659
0 3
0 5
0 417978574
4 7
0 641068595
0 1
0 4
0 132285008
0 788406229
0 139937681
0 3
0 969737879
3 444383529
1 443896824
0 836047684
2 3
0 3
1 420847062
0 663834045
0 2
0 578231941
0 5
0 1
0 604459134
0 4
0 955346381
0 360957147
4 525140508
0 3
1 15822405...

output:

222237218
898759263
640639324
538187759
29656948
29843021
97600405
189219923
850973942
765846801

result:

ok 10 numbers

Test #11:

score: 5
Accepted
time: 21ms
memory: 5428kb

input:

10
1000 0
2 678511582
0 154994295
0 5
2 6
0 1
1 2
0 4
0 196232388
0 1
0 3
0 13247534
0 5
7093249 957022507
1 4
0 906064888
1 2
0 5
1 4
0 256766734
0 636905132
0 370094191
0 2
0 117006010
0 4
0 59582976
1 634540188
0 4
0 677905036
0 5
0 400766826
1 5
3 8
0 665083613
0 4
0 5
0 2
0 730308274
0 89231895...

output:

179406276
724899518
957139040
561017296
993781901
7394650
851299544
397397425
256338857
375918555

result:

ok 10 numbers

Test #12:

score: 5
Accepted
time: 16ms
memory: 5484kb

input:

10
1000 0
0 3
0 5
1 3
0 2
0 377151268
0 4
0 434362897
1 962769308
0 89047812
1 136192105
0 441748730
0 237192940
1 465698860
0 42439355
1 5829347
349949910 802921919
2 5
0 3
1 2
0 390569672
1 607009222
0 512482679
0 416439678
0 3
0 912993280
0 3
3 340960525
0 1
0 688478781
0 5
0 1
1 4
0 712235930
0 ...

output:

319258319
704077987
334372886
88970718
825618506
89533635
834045134
197952117
262319440
924373409

result:

ok 10 numbers

Test #13:

score: 5
Accepted
time: 18ms
memory: 5536kb

input:

10
1000 0
0 1
0 4
0 4
0 2
0 3
4 8
1 809130801
0 187920166
0 2
0 3
0 254674697
0 649121331
0 197259413
0 192443143
0 917579552
0 49799772
1 302721613
0 723809824
0 4
0 932825140
1 2
1 4
0 1
0 939720825
0 1
0 652682854
0 292912959
0 426026563
0 969801845
1 3
0 3
0 4
882209199 882209204
0 379900439
0 2...

output:

108367557
582756296
340002669
368867033
956907932
609145813
884525075
197867228
497772463
543026922

result:

ok 10 numbers

Test #14:

score: 0
Runtime Error

input:

10
1000 47
0 6
0 7
0 6
1 1
0 8
2 9
1 7
0 8
0 7
3 5
0 7
0 4
0 10
0 6
0 6
0 10
0 7
1 1
0 10
0 1
0 7
1 8
0 10
1 2
0 9
0 7
0 1
1 10
0 3
0 7
0 9
0 2
0 9
0 0
0 9
0 7
0 7
1 2
0 0
1 6
0 9
0 6
0 6
1 2
0 2
0 1
1 6
0 10
1 10
0 9
3 6
0 6
0 7
1 9
0 8
0 10
1 1
1 10
0 0
0 8
0 3
0 6
0 4
0 0
0 9
0 6
0 10
0 9
1 8
0 1...

output:


result:


Test #15:

score: 0
Runtime Error

input:

10
1000 99
1 10
0 9
0 8
0 10
1 6
0 7
0 9
1 10
0 6
0 7
0 7
0 9
0 8
0 3
0 9
1 4
0 6
0 9
0 9
0 7
0 10
1 8
1 6
0 6
0 8
0 6
0 9
1 1
0 4
0 0
0 0
0 0
0 1
0 6
0 2
1 7
0 9
0 3
0 7
1 6
0 10
0 9
0 10
1 10
0 3
1 9
0 7
0 10
0 7
0 1
0 0
0 10
0 10
1 9
0 7
1 10
0 6
0 2
0 6
0 8
0 6
1 10
0 7
0 6
0 9
0 10
0 5
0 6
1 10...

output:


result:


Test #16:

score: 0
Runtime Error

input:

10
1000 94
0 27082101
1 2
0 5
0 182284057
0 2
0 854596927
0 486081504
0 1
4 212942070
2 4
0 4
0 5
0 2
0 937988325
0 839634252
259385372 259385374
0 3
1 520768268
0 3
0 609270333
0 838621534
0 384090136
1 3
0 667788367
0 389605576
0 992710428
0 960391094
0 1
2 658423697
1 2
0 273159245
0 4
4 31114796...

output:


result:


Test #17:

score: 0
Runtime Error

input:

10
1000 99
1 558836520
0 4
0 3
0 534121003
0 5
0 264739171
0 379370191
0 4
0 100490264
0 2
0 3
1 619605387
0 2
0 3
0 5
4 5
1 294486083
1 2
3 990787247
0 1
1 256196937
0 3
0 2
0 166482225
0 5
0 1
0 5
0 109407731
0 4
0 5
0 3
0 180703250
0 3
0 129133161
0 5
2 7
0 264096332
0 1
0 5
0 726281357
0 1762581...

output:


result:


Test #18:

score: 0
Runtime Error

input:

10
1000 100
0 3
0 1
1 6
740414081 740414084
1 357189447
1 743739464
0 4
0 1
0 5
0 1
0 30073625
0 4
0 2
0 542888320
0 514884644
1 3
1 305222417
0 386325593
0 1
0 3
1 157562404
0 366404826
0 4
0 3
1 619491195
0 5
0 196255155
1 4
1 4
3 8
2 3
1 6
0 5
0 3
0 5
0 1
0 5
0 642145333
0 2
0 181627666
0 2
0 820...

output:


result:


Test #19:

score: 0
Runtime Error

input:

10
1000 55
0 364881620
0 1
0 851413241
1 4
4 700024576
0 876649436
0 357726767
0 404571776
1 2223463
0 817905335
1 2
0 5
0 4
0 4
0 3
0 847654812
0 3
0 361081695
0 4
0 850218128
0 5
1 4
0 390585804
0 741480334
0 5
0 469714353
0 2
3 7042948
0 427747116
0 2
0 1
0 2
0 2
0 2
0 732348976
0 206547221
0 915...

output:


result:


Test #20:

score: 0
Runtime Error

input:

10
1000 99
0 4
0 579831503
0 2
1 21069180
0 124983788
0 4
0 356520474
1 211150192
0 4
0 204201013
0 247203842
0 4
1 6
1 3
1 2
3 7
0 3
1 760511272
0 5
4 7
2 5
0 1
1 946697431
0 3
0 689207096
0 1
1 4
1 3
1 3
0 549119893
3 6
1 5
0 2
0 2
1 536582539
1 6
0 282097774
1 6
0 942901239
0 2
0 5
0 777338255
0 ...

output:


result: