QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113038#6502. Disjoint Set Unionhos_lyricAC ✓147ms11576kbC++1410.0kb2023-06-16 07:02:432023-06-16 07:02:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-16 07:02:44]
  • 评测
  • 测评结果:AC
  • 用时:147ms
  • 内存:11576kb
  • [2023-06-16 07:02:43]
  • 提交

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


// fast IO by yosupo
// sc.read(string &) appends the input
struct Scanner {
    FILE* fp = nullptr;
    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) 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++] - '0');
        }
        if (neg) ref = -ref;
        return true;
    }
    template <class T> bool read_single(vector<T>& ref) {
        for (auto& d : ref) {
            if (!read_single(d)) return false;
        }
        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 {
  public:
    template <bool F = false> void write() {}
    template <bool F = false, class H, class... T>
    void write(const H& h, const T&... t) {
        if (F) write_single(' ');
        write_single(h);
        write<true>(t...);
    }
    template <class... T> void writeln(const T&... t) {
        write(t...);
        write_single('\n');
    }

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

  private:
    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_single(const char& val) {
        if (pos == SIZE) flush();
        line[pos++] = val;
    }
    template <class T, enable_if_t<is_integral<T>::value, int> = 0>
    void write_single(T val) {
        if (pos > (1 << 15) - 50) flush();
        if (val == 0) {
            write_single('0');
            return;
        }
        if (val < 0) {
            write_single('-');
            val = -val;  // todo min
        }
        size_t len = 0;
        while (val) {
            small[len++] = char('0' + (val % 10));
            val /= 10;
        }
        for (size_t i = 0; i < len; i++) {
            line[pos + i] = small[len - 1 - i];
        }
        pos += len;
    }
    void write_single(const string& s) {
        for (char c : s) write_single(c);
    }
    void write_single(const char* s) {
        size_t len = strlen(s);
        for (size_t i = 0; i < len; i++) write_single(s[i]);
    }
    template <class T> void write_single(const vector<T>& val) {
        auto n = val.size();
        for (size_t i = 0; i < n; i++) {
            if (i) write_single(' ');
            write_single(val[i]);
        }
    }
    void write_single(long double d){
		{
			long long v=d;
			write_single(v);
			d-=v;
		}
		write_single('.');
		for(int _=0;_<8;_++){
			d*=10;
			long long v=d;
			write_single(v);
			d-=v;
		}
    }
};

Scanner sc(stdin);
Printer pr(stdout);


struct Functional {
  int n;
  vector<int> par;
  int cyclesLen;
  vector<vector<int>> cycles;
  // cycle id or -1
  vector<int> on;
  // tree
  vector<vector<int>> graph;
  // root
  vector<int> rs;
  Functional() {}
  Functional(const vector<int> &par_) : par(par_) {
    n = par.size();
    cycles.clear();
    vector<int> vis(n, -1);
    for (int s = 0; s < n; ++s) {
      int u = s;
      for (; !~vis[u]; u = par[u]) {
        vis[u] = s;
      }
      if (vis[u] == s) {
        vector<int> cycle;
        for (int v = u; ; ) {
          cycle.push_back(v);
          if ((v = par[v]) == u) break;
        }
        cycles.push_back(cycle);
      }
    }
    cyclesLen = cycles.size();
    on.assign(n, -1);
    for (int k = 0; k < cyclesLen; ++k) {
      for (const int u : cycles[k]) {
        on[u] = k;
      }
    }
    graph.assign(n, {});
    for (int u = 0; u < n; ++u) if (!~on[u]) {
      graph[par[u]].push_back(u);
    }
    rs.assign(n, -1);
    for (int u = 0; u < n; ++u) if (~on[u]) {
      dfs(u, u);
    }
  }
  void dfs(int u, int r) {
    rs[u] = r;
    for (const int v : graph[u]) {
      dfs(v, u);
    }
  }
};


int root(vector<int> &uf, int u) {
  // return (uf[u] < 0) ? u : (uf[u] = root(uf, uf[u]));
  return (uf[u] == u) ? u : (uf[u] = root(uf, uf[u]));
}
bool connect(vector<int> &uf, int u, int v) {
  u = root(uf, u);
  v = root(uf, v);
  if (u == v) return false;
  // if (uf[u] > uf[v]) swap(u, v);
  // uf[u] += uf[v];
  // uf[v] = u;
  uf[u] = v;
  return true;
}


int N;
vector<int> F, G;

vector<vector<int>> graph;
vector<int> vis;
int zeit;
vector<int> ord;
bool dfs(int u) {
  vis[u] = 1;
  for (const int v : graph[u]) if (u != v) {
    if (vis[v] == 0) {
      if (!dfs(v)) {
        return false;
      }
    } else if (vis[v] == 1) {
      return false;
    } else {
      //
    }
  }
  vis[u] = 2;
  ord[u] = --zeit;
  return true;
}

bool solve() {
  // G is tree?
  const auto gunc = Functional(G);
  for (const auto &cycle : gunc.cycles) {
    if (cycle.size() > 1) {
      return false;
    }
  }
  
  auto fs = F;
  auto gs = G;
  vector<int> RF(N), RG(N);
  for (int u = 0; u < N; ++u) {
    RF[u] = root(fs, u);
    RG[u] = root(gs, u);
  }
  
  vector<vector<int>> uss(N);
  for (int u = 0; u < N; ++u) {
    uss[RF[u]].push_back(u);
  }
  for (int r = 0; r < N; ++r) if (F[r] == r) {
    for (const int u : uss[r]) {
      if (RG[r] != RG[u]) {
        return false;
      }
    }
  }
  vector<vector<int>> rss(N);
  for (int r = 0; r < N; ++r) if (F[r] == r) {
    rss[RG[r]].push_back(r);
  }
// cerr<<"uss = "<<uss<<endl;
// cerr<<"rss = "<<rss<<endl;
  
  // is original root
  auto isR = [&](int u) -> bool {
    return (F[u] == u);
  };
  graph.assign(N, {});
  for (int u = 0; u < N; ++u) {
    if (F[u] != G[u]) {
      if (!isR(G[u])) {
        return false;
      }
      const int p = F[u];
      if (F[p] == G[p] && !isR(G[p])) {
        return false;
      }
      // condition
      graph[RF[u]].push_back(G[u]);
    }
  }
  
  for (int q = 0; q < N; ++q) if (G[q] == q) {
    // global root
    for (const int r : rss[q]) {
      graph[r].push_back(q);
    }
  }
// cerr<<"graph = "<<graph<<endl;
  
  vis.assign(N, 0);
  zeit = N;
  ord.assign(N, -1);
  for (int u = 0; u < N; ++u) if (vis[u] == 0) {
    if (!dfs(u)) {
      return false;
    }
  }
  
  auto judge = F;
  vector<pair<int, int>> ans;
  auto Find = [&](int u) -> void {
    ans.emplace_back(u, -1);
    root(judge, u);
  };
  auto Unite = [&](int u, int v) -> void {
    ans.emplace_back(u, v);
    connect(judge, u, v);
  };
  
  for (int q = 0; q < N; ++q) if (G[q] == q) {
    auto &rs = rss[q];
    sort(rs.begin(), rs.end(), [&](int r0, int r1) -> bool {
      return (ord[r0] < ord[r1]);
    });
// cerr<<"rs = "<<rs<<endl;
    const int rsLen = rs.size();
    for (int j = 0; j < rsLen; ++j) {
      if (j) {
        Unite(rs[j - 1], rs[j]);
      }
      for (int i = 0; i <= j; ++i) {
        for (const int u : uss[rs[i]]) {
          if (G[u] != judge[u]) {
            Find(u);
          }
        }
      }
    }
  }
// cerr<<"ans = "<<ans<<endl;
// cerr<<"judge = "<<judge<<endl;
  assert(G == judge);
  
  pr.writeln("YES");
  pr.writeln(ans.size());
  for (const auto &op : ans) {
    if (!~op.second) {
      pr.writeln(1, op.first + 1);
    } else {
      pr.writeln(2, op.first + 1, op.second + 1);
    }
  }
  return true;
}

int main() {
  int numCases; sc.read(numCases); for (int caseId = 1; caseId <= numCases; ++caseId) {
    sc.read(N);
    F.resize(N); for (int u = 0; u < N; ++u) { sc.read(F[u]); --F[u]; }
    G.resize(N); for (int u = 0; u < N; ++u) { sc.read(G[u]); --G[u]; }
    
    const bool res = solve();
    if (!res) {
      pr.writeln("NO");
    }
  }
  return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

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

output:

YES
2
1 1
2 1 2
YES
8
1 3
1 4
2 3 2
1 3
1 4
1 2
2 2 1
1 3
YES
8
1 1
2 1 2
1 2
2 2 3
1 3
2 3 4
1 4
2 4 5
NO
YES
13
1 6
2 6 2
1 2
1 3
2 2 5
1 2
1 3
1 5
2 5 4
1 2
1 4
2 4 1
1 2

result:

ok good! (YES count = 4, NO count = 1) (5 test cases)

Test #2:

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

input:

100000
5
1 2 1 1 1
2 2 1 1 2
5
3 2 3 4 1
3 2 3 4 1
5
1 2 3 4 3
1 4 4 1 1
5
1 2 3 5 3
1 2 2 5 2
5
5 2 3 5 5
5 2 3 5 5
5
1 2 3 4 5
5 3 3 4 5
5
1 2 3 4 5
1 4 1 4 4
5
1 2 3 1 5
1 2 3 1 2
5
1 2 3 3 1
1 3 3 3 1
5
1 2 3 4 3
2 2 4 4 4
5
1 2 2 4 5
5 2 2 4 5
5
1 2 1 4 5
5 2 5 5 5
5
1 2 3 4 5
1 2 5 5 1
5
1 4 3...

output:

YES
4
1 1
1 5
2 1 2
1 5
YES
0
YES
12
1 3
1 5
2 3 2
1 3
1 5
1 2
2 2 4
1 3
1 5
1 4
2 4 1
1 5
YES
4
1 3
1 5
2 3 2
1 5
YES
0
YES
4
1 2
2 2 3
1 1
2 1 5
YES
8
1 3
2 3 1
1 5
2 5 2
1 5
1 2
2 2 4
1 5
YES
2
1 5
2 5 2
YES
2
1 2
2 2 3
YES
6
1 1
2 1 2
1 3
1 5
2 3 4
1 5
YES
2
1 1
2 1 5
YES
8
1 4
2 4 1
1 4
1 1
1 3...

result:

ok good! (YES count = 100000, NO count = 0) (100000 test cases)

Test #3:

score: 0
Accepted
time: 147ms
memory: 3556kb

input:

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

output:

YES
2
1 2
2 2 10
YES
29
1 5
1 8
1 9
2 5 4
1 5
1 8
1 9
1 4
2 4 3
1 5
1 8
1 9
1 4
1 3
2 3 2
1 5
1 8
1 9
1 4
1 3
1 2
1 7
2 2 6
1 5
1 8
1 9
1 4
1 3
1 7
YES
31
1 8
1 10
2 10 4
1 8
1 10
1 4
2 4 2
1 8
1 10
1 4
1 2
2 2 7
1 8
1 10
1 4
1 5
1 6
1 7
2 7 1
1 8
1 4
1 5
1 6
1 7
1 1
2 1 9
1 8
1 4
1 5
1 6
1 7
YES
29...

result:

ok good! (YES count = 50000, NO count = 0) (50000 test cases)

Test #4:

score: 0
Accepted
time: 65ms
memory: 3512kb

input:

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

output:

YES
64
1 11
2 11 3
1 16
1 19
2 19 17
1 16
1 19
1 17
2 17 14
1 16
1 19
1 17
1 14
2 14 13
1 16
1 19
1 17
1 14
1 13
2 13 9
1 16
1 19
1 17
1 14
1 13
1 1
1 9
1 12
2 9 8
1 16
1 19
1 17
1 14
1 13
1 1
1 9
1 12
1 8
2 8 18
1 16
1 19
1 17
1 14
1 13
1 9
1 18
2 18 5
1 16
1 19
1 17
1 14
1 13
1 18
1 5
2 5 4
1 16
1...

result:

ok good! (YES count = 12500, NO count = 0) (12500 test cases)

Test #5:

score: 0
Accepted
time: 66ms
memory: 3504kb

input:

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

output:

YES
115
1 1
2 1 10
1 20
2 20 19
1 20
1 19
2 19 17
1 20
1 19
1 17
2 17 16
1 20
1 19
1 17
1 16
2 16 14
1 20
1 19
1 17
1 16
1 14
2 14 7
1 20
1 19
1 17
1 16
1 14
1 7
1 8
2 7 6
1 20
1 19
1 17
1 16
1 14
1 7
1 8
1 6
2 6 5
1 20
1 19
1 17
1 16
1 14
1 7
1 8
1 6
1 5
1 9
1 15
1 18
2 5 11
1 20
1 19
1 17
1 16
1 1...

result:

ok good! (YES count = 12500, NO count = 0) (12500 test cases)

Test #6:

score: 0
Accepted
time: 17ms
memory: 3736kb

input:

500
100
5 43 3 13 100 6 56 8 9 62 11 82 13 14 15 48 17 76 19 64 35 62 50 77 38 94 35 62 35 30 31 32 48 34 35 36 43 64 39 40 35 42 62 44 45 62 47 62 49 50 62 47 62 62 39 48 20 58 59 60 43 66 19 62 3 66 67 85 69 70 83 28 73 83 100 76 77 80 85 80 81 82 100 84 85 40 20 88 62 90 40 92 93 94 58 96 30 98 6...

output:

YES
2555
1 98
2 98 96
1 98
1 96
2 96 94
1 98
1 96
1 1
1 5
1 26
1 71
1 74
1 75
1 83
1 94
1 100
2 94 93
1 98
1 96
1 1
1 5
1 26
1 71
1 74
1 75
1 83
1 94
1 100
1 93
2 93 92
1 98
1 96
1 1
1 5
1 26
1 71
1 74
1 75
1 83
1 94
1 100
1 93
1 92
2 92 90
1 98
1 96
1 1
1 5
1 26
1 71
1 74
1 75
1 83
1 94
1 100
1 93
...

result:

ok good! (YES count = 500, NO count = 0) (500 test cases)

Test #7:

score: 0
Accepted
time: 10ms
memory: 4136kb

input:

55
300
172 231 135 149 135 297 7 297 236 52 73 114 52 135 15 73 297 97 218 236 52 236 218 73 244 236 73 52 162 218 103 30 214 34 59 36 73 89 44 131 73 73 73 73 73 41 47 32 236 52 248 73 73 54 209 75 57 73 205 151 73 62 73 73 143 141 238 205 106 73 71 128 73 124 75 76 89 231 205 73 149 135 249 135 13...

output:

YES
3343
1 288
2 288 278
1 288
1 278
2 278 277
1 288
1 278
1 277
2 277 265
1 288
1 278
1 277
1 265
2 265 229
1 288
1 278
1 277
1 265
1 229
2 229 223
1 288
1 278
1 277
1 265
1 229
1 223
2 223 200
1 288
1 278
1 277
1 265
1 229
1 223
1 200
2 200 197
1 288
1 278
1 277
1 265
1 229
1 223
1 200
1 197
2 197...

result:

ok good! (YES count = 55, NO count = 0) (55 test cases)

Test #8:

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

input:

5
1000
794 193 3 4 888 279 316 8 621 679 376 254 791 550 362 706 677 133 133 279 279 57 557 471 780 471 110 557 264 317 557 927 264 908 589 193 481 38 39 941 619 473 683 340 817 780 876 548 557 193 589 648 264 471 940 528 557 710 57 57 61 142 133 481 679 142 712 264 557 264 683 468 679 204 398 754 3...

output:

YES
16366
1 837
2 837 785
1 837
1 785
2 785 770
1 837
1 785
1 770
2 770 742
1 837
1 785
1 770
1 742
2 742 638
1 837
1 785
1 770
1 742
1 638
2 638 626
1 837
1 785
1 770
1 742
1 638
1 626
1 880
2 626 517
1 837
1 785
1 770
1 742
1 638
1 626
1 880
1 517
2 517 471
1 837
1 785
1 770
1 742
1 638
1 626
1 88...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #9:

score: 0
Accepted
time: 9ms
memory: 6500kb

input:

5
1000
811 448 371 731 601 6 950 8 731 811 123 688 753 282 15 802 17 282 282 20 272 818 23 24 731 1 805 67 951 753 230 182 629 15 874 36 576 38 113 272 41 811 43 455 282 595 965 836 582 855 811 76 230 50 731 885 811 595 182 969 619 62 688 576 811 944 335 1 944 230 71 42 73 328 11 951 753 10 335 944 ...

output:

YES
90457
1 999
2 999 992
1 999
1 992
2 992 985
1 999
1 992
1 985
2 985 981
1 999
1 992
1 985
1 981
2 981 980
1 999
1 992
1 985
1 981
1 980
2 980 978
1 999
1 992
1 985
1 981
1 980
1 978
2 978 971
1 999
1 992
1 985
1 981
1 980
1 978
1 971
2 971 953
1 999
1 992
1 985
1 981
1 980
1 978
1 971
1 406
1 41...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #10:

score: 0
Accepted
time: 10ms
memory: 11576kb

input:

5
1000
1 696 3 4 70 98 715 8 174 10 11 12 342 530 15 878 928 191 447 20 21 878 23 436 367 4 174 28 321 666 31 911 33 34 35 526 66 38 39 868 41 440 43 710 45 988 47 48 62 50 383 612 300 569 878 56 84 58 560 60 61 401 63 64 815 647 67 68 69 70 670 72 73 74 75 846 77 784 554 80 208 82 142 84 85 590 87 ...

output:

YES
299530
1 1000
2 1000 999
1 1000
1 999
2 999 998
1 1000
1 999
1 140
1 250
1 514
1 998
2 998 997
1 1000
1 999
1 140
1 250
1 514
1 998
1 726
1 997
2 997 996
1 1000
1 999
1 140
1 250
1 514
1 998
1 726
1 997
1 996
2 996 995
1 1000
1 999
1 140
1 250
1 514
1 998
1 726
1 997
1 996
1 995
2 995 994
1 1000...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #11:

score: 0
Accepted
time: 12ms
memory: 9888kb

input:

5
1000
1 697 3 807 656 548 7 859 9 188 11 194 629 907 319 275 796 18 876 878 21 711 376 82 275 118 27 28 144 30 31 32 878 225 35 795 193 835 39 220 468 509 601 808 569 46 947 871 859 878 228 52 113 697 621 56 319 616 323 572 970 795 98 994 65 853 907 387 69 436 605 835 601 74 762 256 77 78 275 907 5...

output:

YES
178143
1 998
2 998 997
1 998
1 997
2 997 993
1 998
1 997
1 993
2 993 990
1 998
1 997
1 993
1 990
2 990 989
1 998
1 997
1 993
1 990
1 324
1 989
2 989 988
1 998
1 997
1 993
1 990
1 324
1 989
1 988
2 988 981
1 998
1 997
1 993
1 990
1 324
1 989
1 988
1 981
2 981 978
1 998
1 997
1 993
1 990
1 324
1 9...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #12:

score: 0
Accepted
time: 20ms
memory: 11236kb

input:

5
1000
1 2 500 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 689 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 452 86 684 88 89 90 91 550 93 94 95 96 97 98 74...

output:

YES
471661
1 1000
2 1000 999
1 1000
1 999
2 999 998
1 1000
1 999
1 998
2 998 997
1 1000
1 999
1 998
1 997
2 997 996
1 1000
1 999
1 998
1 997
1 996
2 996 995
1 1000
1 999
1 998
1 997
1 996
1 995
2 995 994
1 1000
1 999
1 998
1 997
1 996
1 995
1 994
2 994 993
1 1000
1 999
1 998
1 997
1 996
1 995
1 994
...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #13:

score: 0
Accepted
time: 15ms
memory: 10140kb

input:

5
1000
1 2 3 4 5 6 7 69 9 10 11 12 13 14 15 16 17 18 822 423 21 22 23 24 25 26 27 28 29 30 848 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 963 48 49 50 51 52 53 54 672 56 673 58 59 60 868 62 63 64 480 66 67 68 69 941 71 834 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 515 91 92 93 94 95 96 97...

output:

YES
430643
1 1000
2 1000 999
1 1000
1 999
2 999 998
1 1000
1 999
1 998
2 998 997
1 1000
1 999
1 998
1 997
2 997 996
1 1000
1 999
1 998
1 997
1 703
1 996
2 996 995
1 1000
1 999
1 998
1 997
1 703
1 996
1 995
2 995 994
1 1000
1 999
1 998
1 997
1 703
1 996
1 995
1 994
2 994 993
1 1000
1 999
1 998
1 997
...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #14:

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

input:

5
1000
433 256 696 228 253 435 436 725 47 766 308 958 433 851 399 433 258 328 748 435 468 725 982 24 748 157 748 999 958 725 27 553 435 819 139 553 748 304 39 676 289 228 33 725 748 851 811 735 435 47 819 399 531 435 738 191 433 304 559 60 748 800 227 47 982 658 47 586 69 748 991 191 325 107 183 644...

output:

YES
58598
1 993
2 993 967
1 993
1 967
2 967 957
1 993
1 967
1 957
2 957 913
1 993
1 967
1 957
1 913
2 913 861
1 993
1 967
1 957
1 913
1 861
2 861 827
1 993
1 967
1 957
1 913
1 861
1 827
2 827 809
1 993
1 967
1 957
1 913
1 861
1 827
1 809
2 809 807
1 993
1 967
1 957
1 913
1 861
1 827
1 809
1 575
1 80...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #15:

score: 0
Accepted
time: 20ms
memory: 10948kb

input:

5
1000
766 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 592 18 19 20 21 22 230 24 25 26 27 28 29 30 31 32 270 144 35 36 37 105 39 40 180 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 947 61 62 417 64 65 66 67 68 69 70 71 72 73 888 75 76 77 78 79 80 81 82 83 766 85 86 87 214 916 90 91 92 93 94 95 317...

output:

YES
435975
1 1000
2 1000 999
1 1000
1 999
2 999 998
1 1000
1 999
1 998
2 998 997
1 1000
1 999
1 998
1 997
2 997 995
1 1000
1 999
1 998
1 997
1 995
2 995 994
1 1000
1 999
1 998
1 997
1 995
1 994
2 994 993
1 1000
1 999
1 998
1 997
1 995
1 994
1 993
2 993 992
1 1000
1 999
1 998
1 997
1 995
1 994
1 993
...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #16:

score: 0
Accepted
time: 13ms
memory: 11192kb

input:

5
1000
392 897 227 735 327 707 615 226 153 102 593 398 726 696 857 894 17 823 799 322 109 714 931 260 762 823 988 827 799 949 694 916 867 123 398 747 633 367 931 916 231 89 891 44 45 538 938 175 49 376 799 762 960 696 327 327 997 477 726 799 857 714 339 398 916 231 799 68 69 894 71 696 73 255 50 395...

output:

YES
83302
1 998
2 998 991
1 998
1 991
2 991 980
1 998
1 991
1 980
2 980 975
1 998
1 991
1 980
1 230
1 759
1 975
2 975 973
1 998
1 991
1 980
1 230
1 759
1 975
1 973
2 973 965
1 998
1 991
1 980
1 230
1 759
1 975
1 973
1 965
2 965 961
1 998
1 991
1 980
1 230
1 759
1 975
1 973
1 965
1 961
2 961 959
1 99...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #17:

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

input:

5
1000
1 702 632 4 5 629 7 8 9 10 713 371 13 14 15 16 17 785 19 20 21 476 23 24 584 26 54 28 29 30 31 32 33 34 35 36 768 239 39 96 809 42 43 44 45 46 47 48 208 50 51 52 53 937 55 56 57 58 59 606 25 62 255 64 65 435 67 68 69 70 70 72 69 564 75 76 615 78 79 255 564 800 537 84 85 86 564 262 89 90 91 92...

output:

YES
203020
1 126
2 126 125
1 9
2 9 327
1 788
2 788 354
1 420
2 420 317
1 420
1 317
2 317 298
1 420
1 317
1 298
2 298 361
1 420
1 317
1 996
2 996 995
1 996
1 995
2 995 994
1 996
1 995
1 994
2 994 993
1 996
1 995
1 994
1 993
2 993 992
1 996
1 995
1 994
1 993
1 74
1 81
1 87
1 375
1 564
1 575
1 992
2 99...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #18:

score: 0
Accepted
time: 16ms
memory: 7032kb

input:

5
1000
167 610 3 858 1 592 201 496 9 10 11 969 13 14 290 705 618 18 19 62 21 22 23 25 25 562 509 28 29 162 31 32 1 502 518 1 906 501 39 40 41 42 43 44 779 17 979 530 49 737 51 52 53 54 55 56 57 779 533 60 61 822 54 64 65 66 509 68 69 562 71 72 73 587 509 76 77 78 848 80 81 723 83 84 142 936 562 868 ...

output:

YES
244103
1 1000
2 1000 998
1 1000
1 998
2 998 996
1 1000
1 998
1 996
2 996 995
1 1000
1 998
1 996
1 995
2 995 993
1 1000
1 998
1 996
1 995
1 993
2 993 992
1 1000
1 998
1 996
1 995
1 993
1 992
2 992 991
1 1000
1 998
1 996
1 995
1 993
1 992
1 991
2 991 989
1 1000
1 998
1 996
1 995
1 993
1 992
1 991
...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #19:

score: 0
Accepted
time: 20ms
memory: 10404kb

input:

5
1000
404 627 3 4 5 6 7 8 9 10 11 12 13 14 693 16 17 18 19 20 221 22 23 24 25 26 27 28 29 30 31 32 33 718 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 986 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 503 551 994 89 495 91 447 93 94 495 96 ...

output:

YES
231719
1 449
2 449 53
1 277
2 277 63
1 876
2 876 71
1 996
2 996 124
1 823
2 823 235
1 823
1 235
2 235 139
1 823
1 235
1 139
2 139 409
1 823
1 235
1 706
2 706 316
1 316
2 316 51
1 316
1 51
2 51 428
1 316
1 736
2 736 511
1 511
2 511 434
1 393
2 393 475
1 696
2 696 517
1 323
2 323 198
1 323
1 198
2...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #20:

score: 0
Accepted
time: 22ms
memory: 10984kb

input:

5
1000
1 2 3 4 5 6 7 8 9 511 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 575 27 28 29 30 31 32 33 34 35 36 37 822 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 804 62 63 64 65 66 67 477 69 70 71 72 73 74 75 76 77 78 79 80 691 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 941 9...

output:

YES
132573
1 848
2 848 339
1 848
1 339
2 339 102
1 848
1 339
1 102
2 102 31
1 848
1 339
1 274
2 274 37
1 345
2 345 224
1 345
1 224
2 224 836
1 345
1 836
2 836 49
1 273
2 273 86
1 977
2 977 526
1 526
2 526 101
1 956
2 956 403
1 956
1 403
2 403 465
1 956
1 465
2 465 106
1 956
1 730
2 730 470
1 470
2 4...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #21:

score: 0
Accepted
time: 143ms
memory: 3616kb

input:

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

output:

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

result:

ok good! (YES count = 50000, NO count = 0) (50000 test cases)

Test #22:

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

input:

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

output:

YES
2
1 7
2 7 3
YES
18
1 14
2 14 13
1 14
1 13
2 13 12
1 14
1 13
1 12
2 12 3
1 13
1 9
2 9 1
1 1
2 1 7
1 6
2 6 8
1 18
2 18 15
YES
19
1 9
2 9 4
1 17
2 17 10
1 17
1 3
1 8
1 10
2 10 7
1 17
1 3
1 10
1 7
2 7 6
1 17
1 3
1 10
1 2
2 2 14
YES
45
1 14
2 14 7
1 14
1 2
1 7
1 18
2 7 8
1 14
1 2
1 18
1 8
2 8 5
1 14
...

result:

ok good! (YES count = 12500, NO count = 0) (12500 test cases)

Test #23:

score: 0
Accepted
time: 15ms
memory: 3676kb

input:

500
100
1 2 13 89 15 6 64 8 9 56 11 12 13 82 15 16 17 18 19 20 1 22 23 24 25 26 27 28 29 30 31 32 33 34 35 21 37 23 39 40 41 42 43 44 45 46 47 48 49 82 51 52 53 54 55 56 11 58 59 3 61 62 63 64 65 66 19 68 11 70 71 10 73 74 23 76 39 78 56 80 81 82 99 23 85 86 87 93 89 90 91 92 93 94 95 96 97 98 99 10...

output:

YES
176
1 46
2 46 42
1 46
1 42
2 42 78
1 46
1 78
2 78 8
1 95
2 95 17
1 32
2 32 30
1 32
1 30
2 30 1
1 32
1 30
1 1
2 1 87
1 32
1 30
1 87
2 87 19
1 58
2 58 20
1 90
2 90 56
1 90
1 56
2 56 27
1 90
1 55
2 55 16
1 55
1 16
2 16 28
1 55
1 59
2 59 82
1 82
2 82 24
1 82
1 24
2 24 34
1 82
1 9
2 9 35
1 98
2 98 71...

result:

ok good! (YES count = 500, NO count = 0) (500 test cases)

Test #24:

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

input:

55
300
73 84 3 257 5 257 111 8 265 10 74 73 279 81 277 73 17 73 19 227 124 174 23 93 25 81 81 257 29 208 31 32 37 175 74 265 37 257 125 40 176 42 171 132 277 124 248 48 49 187 51 52 53 147 55 132 277 53 124 60 194 81 277 271 65 66 44 171 211 45 277 72 73 257 257 76 79 299 133 277 73 257 132 81 271 1...

output:

YES
3379
1 297
2 297 105
1 158
2 158 112
1 229
2 229 294
1 294
2 294 53
1 294
1 53
2 53 123
1 294
1 19
2 19 191
1 127
2 127 256
1 296
2 296 280
1 296
1 280
2 280 279
1 296
1 280
1 13
1 279
2 279 265
1 280
1 13
1 279
1 9
1 265
2 265 263
1 280
1 13
1 279
1 9
1 265
1 192
1 263
2 263 238
1 280
1 13
1 27...

result:

ok good! (YES count = 55, NO count = 0) (55 test cases)

Test #25:

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

input:

5
1000
1 2 3 4 705 6 7 8 9 10 11 781 13 231 15 16 17 18 19 20 21 22 23 24 25 26 27 401 29 42 31 445 667 289 35 36 37 761 996 40 41 42 43 251 45 46 47 231 49 50 51 52 53 54 55 56 57 35 59 60 61 62 63 64 65 66 538 401 69 70 71 72 73 74 75 554 77 78 79 344 81 82 83 84 85 442 51 88 89 90 91 92 93 94 891...

output:

YES
17
1 886
2 886 45
1 189
2 189 77
1 480
2 480 183
1 913
2 913 318
1 240
1 942
2 942 501
1 812
2 812 795
1 400
2 400 845
1 157
2 157 924
YES
92
1 498
2 498 26
1 259
2 259 28
1 580
2 580 59
1 220
2 220 72
1 22
2 22 76
1 911
2 911 86
1 407
2 407 104
1 504
2 504 123
1 117
2 117 129
1 993
2 993 145
1 ...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #26:

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

input:

5
1000
736 2 3 4 5 6 7 8 9 10 11 797 823 929 15 16 17 18 19 20 264 22 23 24 52 353 27 28 29 30 839 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 944 51 52 403 872 55 56 57 58 59 60 61 62 63 64 99 66 67 68 69 70 71 72 73 938 302 186 77 78 79 80 81 82 83 84 85 86 983 86 89 90 91 46 93 94 95 96...

output:

YES
214
1 949
2 949 22
1 176
2 176 52
1 317
2 317 70
1 789
2 789 73
1 651
2 651 79
1 408
2 408 80
1 577
2 577 23
1 577
1 23
2 23 97
1 577
1 250
2 250 124
1 665
2 665 156
1 177
1 289
2 289 158
1 144
2 144 179
1 860
2 860 183
1 618
2 618 205
1 358
2 358 215
1 549
1 993
2 549 924
1 924
2 924 263
1 759
...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #27:

score: 0
Accepted
time: 1ms
memory: 4392kb

input:

5
1000
487 446 3 4 5 6 442 8 452 10 601 12 300 895 15 208 866 328 19 20 21 967 644 24 25 118 27 28 787 30 31 344 33 139 350 440 37 369 39 918 41 42 190 483 45 46 556 48 360 807 188 608 53 67 55 333 398 397 853 60 61 953 676 678 65 66 882 483 69 369 71 72 763 576 75 76 77 78 724 574 310 193 83 84 85 ...

output:

YES
375
1 291
2 291 10
1 651
2 651 20
1 321
1 967
2 967 45
1 274
2 274 66
1 416
2 416 69
1 285
2 285 76
1 285
1 76
2 76 86
1 285
1 248
2 248 119
1 357
2 357 134
1 202
2 202 135
1 46
2 46 500
1 500
2 500 154
1 344
1 998
2 344 178
1 391
2 391 53
1 391
1 53
2 53 77
1 391
1 77
1 266
1 938
2 77 198
1 19
...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #28:

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

input:

5
1000
588 923 119 77 5 6 7 8 9 10 11 12 13 477 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 987 155 153 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 369 53 54 764 56 341 305 932 430 61 663 63 462 65 66 67 68 69 70 884 72 73 74 180 76 77 78 609 80 81 82 83 739 85 86 87 400 183 90 91 92 6...

output:

YES
102
1 354
2 354 9
1 667
2 667 410
1 410
2 410 20
1 374
2 374 25
1 535
2 535 53
1 159
2 159 91
1 26
2 26 105
1 910
2 910 128
1 879
2 879 149
1 521
2 521 176
1 966
2 966 179
1 349
2 349 262
1 97
2 97 266
1 968
2 968 289
1 743
2 743 312
1 540
2 540 153
1 153
2 153 341
1 679
2 679 856
1 571
1 856
2 ...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #29:

score: 0
Accepted
time: 3ms
memory: 3828kb

input:

5
1000
816 2 519 284 253 990 965 581 457 414 232 451 581 519 581 406 581 965 581 20 519 337 383 253 581 26 27 587 900 34 862 215 915 439 439 370 816 189 387 134 103 249 361 964 809 367 47 103 452 760 67 862 253 915 467 103 215 439 816 516 581 103 87 581 439 66 249 68 621 497 71 417 581 439 63 673 10...

output:

YES
750
1 959
2 959 953
1 959
1 953
2 953 806
1 959
1 953
1 806
2 806 800
1 959
1 953
1 806
1 800
2 800 751
1 959
1 953
1 806
1 800
1 751
2 751 311
1 959
1 953
1 806
1 800
1 1
1 4
1 18
1 34
1 36
1 37
1 38
1 40
1 56
1 58
1 63
1 87
1 101
1 103
1 104
1 134
1 143
1 159
1 161
1 166
1 173
1 189
1 210
1 21...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #30:

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

input:

5
1000
816 2 235 51 617 979 7 981 979 113 604 984 51 773 790 33 750 466 14 803 556 190 349 51 733 816 190 207 828 816 885 76 47 880 850 349 767 773 120 141 500 979 27 44 883 190 816 630 869 984 773 141 154 900 773 349 349 500 786 118 750 154 516 349 30 154 883 113 733 979 197 451 816 816 816 51 815 ...

output:

YES
2681
1 514
2 514 467
1 966
2 966 927
1 966
1 927
2 927 894
1 966
1 927
1 894
2 894 892
1 966
1 927
1 894
1 892
2 892 773
1 966
1 927
1 894
1 892
1 10
1 11
1 14
1 19
1 30
1 31
1 36
1 42
1 45
1 51
1 57
1 60
1 65
1 66
1 68
1 70
1 76
1 81
1 84
1 87
1 88
1 109
1 113
1 118
1 120
1 141
1 150
1 152
1 15...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #31:

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

input:

5
1000
1 2 3 22 949 6 7 8 9 10 11 12 547 33 1 16 17 520 19 20 21 22 23 928 111 26 631 994 29 236 657 32 33 34 35 898 37 38 765 685 41 42 43 44 45 46 961 48 49 556 51 619 53 785 55 56 57 180 59 60 61 62 166 64 65 66 67 95 69 70 71 72 73 74 75 866 77 78 79 80 328 82 257 243 85 86 87 88 89 90 91 92 93 ...

output:

YES
514
1 809
2 809 10
1 802
2 802 12
1 868
2 868 17
1 97
2 97 23
1 705
2 705 43
1 237
2 237 45
1 123
2 123 66
1 374
2 374 7
1 374
1 7
2 7 3
1 374
1 7
1 3
1 167
1 564
2 3 67
1 7
1 564
1 759
2 759 78
1 302
2 302 200
1 302
1 200
2 200 89
1 302
1 200
1 89
2 89 243
1 302
1 200
1 243
1 408
2 243 88
1 344...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #32:

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

input:

5
1000
1 2 924 4 5 6 7 8 9 10 867 919 13 8 15 850 17 18 922 20 884 543 23 824 25 47 990 28 29 30 791 32 33 34 35 208 37 38 39 491 41 870 43 274 45 46 47 410 49 50 871 52 53 54 55 540 57 58 59 60 61 62 63 94 65 66 67 68 924 70 71 72 73 74 75 76 407 78 79 980 81 82 83 84 85 86 87 514 89 90 91 92 619 9...

output:

YES
354
1 916
2 916 720
1 916
1 207
1 720
2 720 575
1 916
1 207
1 720
1 575
2 575 104
1 916
1 207
1 720
1 575
1 104
1 478
2 104 18
1 916
1 207
1 720
1 575
1 478
1 220
2 220 30
1 781
2 781 38
1 709
2 709 13
1 709
1 13
2 13 831
1 709
1 831
2 831 49
1 234
2 234 55
1 576
2 576 70
1 746
2 746 72
1 733
2 ...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)

Test #33:

score: 0
Accepted
time: 61ms
memory: 3464kb

input:

100000
4
1 2 3 1
3 1 1 4
4
1 2 3 4
4 1 4 2
4
1 2 3 4
1 1 3 3
4
1 2 1 4
4 3 4 1
4
1 2 3 4
2 3 2 4
4
1 3 3 3
2 3 1 4
4
1 2 3 4
2 3 4 4
4
1 2 2 2
2 3 1 4
4
1 2 3 4
2 4 1 1
4
2 3 3 4
3 1 3 3
4
1 2 3 4
3 3 4 2
4
3 1 3 1
3 2 4 2
4
1 2 1 1
3 4 4 1
4
1 2 4 4
3 1 2 3
4
2 2 3 4
3 3 2 3
4
1 2 3 3
1 4 4 4
4
2 2...

output:

NO
NO
YES
4
1 2
2 2 1
1 4
2 4 3
NO
NO
NO
YES
6
1 1
2 1 2
1 2
2 2 3
1 3
2 3 4
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
6
1 3
2 3 4
1 2
1 4
2 4 1
1 2
NO
NO
YES
8
1 4
2 4 2
1 4
1 2
2 2 3
1 4
1 3
2 3 1
YES
11
1 4
2 4 3
1 4
1 3
2 3 1
1 4
1 3
1 1
2 1 2
1 4
1 3
NO
NO
NO
NO
NO
YES
6
1 3
2 3 2
1 3
1 2
2 2 1
1 3
...

result:

ok good! (YES count = 22427, NO count = 77573) (100000 test cases)

Test #34:

score: 0
Accepted
time: 88ms
memory: 3636kb

input:

100000
5
1 2 3 4 5
1 3 3 5 3
5
1 2 3 4 5
2 3 1 4 4
5
3 2 3 3 5
3 3 2 4 3
5
1 2 3 4 5
3 4 2 3 5
5
1 3 3 5 5
2 5 2 2 3
5
1 2 3 4 5
4 3 2 1 4
5
1 2 3 4 5
2 3 5 1 5
5
1 4 3 4 5
4 3 1 4 4
5
1 2 5 4 1
1 3 1 2 5
5
1 5 3 4 5
5 5 5 3 1
5
1 3 3 4 2
1 1 2 4 3
5
1 2 3 4 5
1 4 3 5 4
5
1 2 3 4 3
3 2 5 3 4
5
1 2 5...

output:

YES
8
1 4
2 4 5
1 5
2 5 2
1 5
1 2
2 2 3
1 5
NO
NO
NO
NO
NO
YES
8
1 4
2 4 1
1 1
2 1 2
1 2
2 2 3
1 3
2 3 5
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
14
1 5
2 5 2
1 5
1 2
2 2 1
1 5
1 2
1 1
2 1 4
1 5
1 2
1 4
2 4 3
1 5
NO
NO
NO
NO
YES
8
1 4
2 4 2
1 3
2 3 1
1 3
1 1
2 1 5
1 3
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
11
1 5
...

result:

ok good! (YES count = 25378, NO count = 74622) (100000 test cases)

Test #35:

score: 0
Accepted
time: 86ms
memory: 3528kb

input:

100000
5
2 2 3 4 2
1 2 1 2 2
5
1 2 3 2 5
4 1 2 5 3
5
2 2 3 2 1
2 2 5 2 3
5
1 2 3 4 1
3 1 4 5 4
5
1 2 3 4 5
2 4 1 2 3
5
1 2 3 4 5
2 3 4 1 3
5
1 2 3 4 5
2 2 1 4 2
5
1 2 4 4 5
2 3 5 3 4
5
1 5 3 5 5
5 2 4 2 2
5
4 3 3 4 5
3 1 2 2 3
5
5 5 3 5 5
4 2 3 3 4
5
1 2 3 4 5
1 4 3 3 5
5
1 4 3 4 5
2 2 1 5 5
5
1 2 3...

output:

NO
NO
NO
NO
NO
NO
YES
9
1 5
2 5 3
1 5
1 3
2 3 1
1 5
1 1
2 1 2
1 5
NO
NO
NO
NO
YES
4
1 2
2 2 4
1 4
2 4 3
NO
NO
NO
NO
NO
YES
11
1 3
2 3 2
1 3
1 2
2 2 4
1 3
1 1
1 4
2 4 5
1 3
1 1
NO
YES
9
1 5
2 5 1
1 5
1 1
2 1 2
1 5
1 2
2 2 4
1 5
NO
NO
NO
NO
YES
8
1 5
2 5 4
1 4
2 4 1
1 1
2 1 2
1 2
2 2 3
YES
10
1 3
2 3 ...

result:

ok good! (YES count = 17905, NO count = 82095) (100000 test cases)

Test #36:

score: 0
Accepted
time: 93ms
memory: 3460kb

input:

100000
6
1 2 3 3 5 1
3 4 1 6 5 4
6
6 2 3 4 5 6
5 1 1 5 5 4
6
1 2 3 4 3 6
4 5 1 1 3 5
6
4 2 1 4 5 6
2 3 4 1 3 1
6
1 2 3 4 5 6
4 1 3 3 1 2
6
2 6 3 3 5 6
3 2 6 6 3 4
6
4 2 3 3 5 6
4 3 6 5 5 3
6
1 2 3 4 5 6
3 2 6 3 4 2
6
1 2 3 4 5 6
6 4 5 4 4 3
6
1 2 3 4 4 5
6 4 3 5 1 5
6
1 6 3 4 1 1
1 3 5 3 2 3
6
1 2 3...

output:

NO
NO
NO
NO
YES
14
1 6
2 6 5
1 6
1 5
2 5 2
1 6
1 5
1 2
2 2 1
1 5
1 1
2 1 4
1 4
2 4 3
NO
NO
YES
12
1 5
2 5 4
1 4
2 4 1
1 4
1 1
2 1 3
1 4
1 3
2 3 6
1 6
2 6 2
YES
15
1 2
2 2 1
1 2
1 1
2 1 6
1 2
1 6
2 6 3
1 2
1 3
2 3 5
1 2
1 5
2 5 4
1 2
NO
NO
NO
YES
14
1 5
2 5 3
1 5
1 3
2 3 4
1 5
1 4
2 4 1
1 4
1 1
2 1 2...

result:

ok good! (YES count = 14853, NO count = 85147) (100000 test cases)

Test #37:

score: 0
Accepted
time: 89ms
memory: 3568kb

input:

100000
6
3 2 3 4 5 6
5 3 2 2 2 4
6
1 2 2 4 5 6
1 4 1 3 4 5
6
1 2 3 6 5 6
4 1 3 4 4 5
6
1 2 3 6 5 6
1 6 6 2 2 2
6
1 2 3 4 5 6
3 2 3 2 2 6
6
1 2 3 4 5 6
4 4 2 6 1 5
6
4 2 3 4 5 6
5 5 4 5 6 2
6
1 2 3 4 5 6
4 5 5 2 1 3
6
1 2 3 4 5 6
5 1 5 5 5 5
6
1 2 3 4 2 5
2 4 6 6 6 5
6
1 2 5 4 5 6
5 2 5 5 2 4
6
1 2 3...

output:

NO
NO
NO
NO
YES
8
1 5
2 5 4
1 5
1 4
2 4 2
1 5
1 1
2 1 3
NO
NO
NO
YES
22
1 6
2 6 4
1 6
1 4
2 4 3
1 6
1 4
1 3
2 3 2
1 6
1 4
1 3
1 2
2 2 1
1 6
1 4
1 3
1 1
2 1 5
1 6
1 4
1 3
NO
YES
10
1 6
2 6 4
1 4
2 4 1
1 4
1 1
2 1 5
1 4
1 5
2 5 2
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
10
1 6
2 6 3
1 3
2 3 2
1 3
1 2
2 2 5
1 3
...

result:

ok good! (YES count = 10145, NO count = 89855) (100000 test cases)

Test #38:

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

input:

100000
7
1 2 3 3 5 6 7
2 6 1 7 2 1 7
7
1 2 3 4 5 5 7
5 2 4 7 7 4 4
7
1 2 3 4 5 6 7
5 6 2 6 3 6 1
7
1 2 2 4 5 6 2
7 1 3 5 5 2 2
7
1 4 3 4 5 6 7
6 2 7 7 5 5 3
7
1 2 3 4 5 6 7
5 3 1 2 7 7 7
7
4 2 3 4 5 6 7
4 6 1 2 3 3 4
7
1 2 3 4 5 6 7
6 5 6 3 7 2 5
7
1 2 3 4 5 6 7
2 1 6 1 4 6 2
7
1 2 3 4 5 6 7
2 3 5 3...

output:

NO
NO
YES
19
1 7
2 7 4
1 7
1 4
2 4 1
1 7
1 4
1 1
2 1 5
1 4
1 5
2 5 3
1 4
1 3
2 3 2
1 4
1 2
2 2 6
1 4
NO
NO
YES
18
1 6
2 6 4
1 6
1 4
2 4 2
1 6
1 2
2 2 3
1 6
1 3
2 3 1
1 6
1 1
2 1 5
1 6
1 5
2 5 7
1 6
NO
NO
NO
NO
NO
NO
NO
NO
YES
10
1 1
2 1 4
1 6
2 6 3
1 6
1 3
2 3 2
1 6
1 2
2 2 7
NO
NO
NO
NO
NO
NO
NO
NO...

result:

ok good! (YES count = 12760, NO count = 87240) (100000 test cases)

Test #39:

score: 0
Accepted
time: 92ms
memory: 3612kb

input:

100000
7
1 2 3 4 3 6 7
4 1 4 6 1 4 7
7
3 2 3 4 5 6 7
1 5 7 3 1 3 7
7
1 6 3 6 6 6 6
4 4 7 6 6 6 2
7
5 2 3 4 5 6 7
4 3 1 6 1 3 7
7
1 2 3 4 5 6 7
7 5 7 3 7 3 5
7
1 4 3 4 5 6 4
1 1 7 3 3 7 2
7
1 2 3 4 5 6 7
4 5 7 6 4 3 1
7
1 7 5 4 1 6 7
6 1 5 7 7 6 1
7
4 2 3 4 5 4 7
1 2 5 2 7 6 5
7
1 2 3 4 5 1 7
4 6 1 7...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
8
1 2
2 2 5
1 5
2 5 3
1 7
2 7 6
1 6
2 6 4
NO
NO
NO
NO
NO
YES
19
1 7
2 7 6
1 7
1 6
2 6 3
1 7
1 6
1 3
2 3 2
1 6
1 2
2 2 1
1 6
1 1
2 1 5
1 6
1 5
2 5 4
1 6
NO
NO
NO
YES
12
1 3
2 3 2
1 3
1 2
2 2 7
1 3
1 7
2 7 1
1 1
2 1 6
1 6
2 6 4
NO
YES
14
1 7
2 7 5
1 ...

result:

ok good! (YES count = 8596, NO count = 91404) (100000 test cases)

Test #40:

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

input:

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

output:

NO
NO
NO
NO
NO
NO
NO
NO
YES
15
1 6
2 6 7
1 7
2 7 4
1 7
1 4
2 4 8
1 7
1 8
2 8 1
1 7
1 8
1 1
2 1 5
1 8
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
12
1 5
2 5 1
1 6
2 6 7
1 7
2 7 2
1 2
2 2 3
1 3
2 3 8
1 8
2 8 4
NO
NO
NO
NO
NO
NO
...

result:

ok good! (YES count = 4011, NO count = 74114) (78125 test cases)

Test #41:

score: 0
Accepted
time: 73ms
memory: 3464kb

input:

61728
9
1 2 4 4 9 6 6 8 9
4 1 4 7 2 9 1 7 2
9
1 2 1 4 5 3 7 8 8
9 1 5 5 6 8 4 2 6
9
1 1 9 1 5 1 7 1 9
4 2 1 7 5 2 5 8 5
9
1 2 3 4 5 6 7 4 9
9 7 4 8 6 4 9 6 2
9
3 6 4 4 5 7 7 3 6
1 7 4 7 2 4 6 7 9
9
1 5 9 2 5 3 7 2 9
1 7 7 4 3 9 8 3 1
9
3 2 3 8 5 6 7 8 9
7 6 1 8 5 6 9 5 4
9
1 2 3 3 5 8 5 8 9
5 8 7 1 ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
16
1 6
2 6 7
1 7
2 7 4
1 2
2 2 1
1 2
1 1
2 1 5
1 2
1 5
2 5 9
1 2
1 9
2 9 8
1 2
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

ok good! (YES count = 2842, NO count = 58886) (61728 test cases)

Test #42:

score: 0
Accepted
time: 53ms
memory: 3568kb

input:

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

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
34
1 9
2 9 8
1 9
1 8
2 8 4
1 9
1 4
2 4 2
1 9
1 4
1 2
2 2 7
1 9
1 4
1 7
2 7 1
1 4
1 7
1 1
2 1 5
1 4
1 7
1 5
2 5 10
1 4
1 7
1 10
2 10 6
1 4
1 7
1 6
2 6 11
1 4
1 7
NO
NO
NO
NO
NO
NO
NO
YES
31
1 2
2 2 3
1 8
2 8 10
1 10
2 10 6
1 10
...

result:

ok good! (YES count = 1240, NO count = 40082) (41322 test cases)

Test #43:

score: 0
Accepted
time: 60ms
memory: 3612kb

input:

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

output:

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

result:

ok good! (YES count = 1641, NO count = 48359) (50000 test cases)

Test #44:

score: 0
Accepted
time: 51ms
memory: 3508kb

input:

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

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
51
1 12
2 12 11
1 12
1 11
2 11 8
1 12
1 11
1 6
1 8
1 9
2 8 5
1 12
1 11
1 8
1 9
1 5
2 5 4
1 12
1 11
1 8
1 9
1 5
1 4
2 4 3
1 12
1 11
1 8
1 9
1 5
1 4
1 3
2 3 2
1 12
1 11
1 9
1 4
1 3
1 2
2 2 1
1 11
...

result:

ok good! (YES count = 768, NO count = 33954) (34722 test cases)

Test #45:

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

input:

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

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok good! (YES count = 77, NO count = 12423) (12500 test cases)

Test #46:

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

input:

2000
50
1 49 25 25 25 9 7 25 27 10 45 40 37 14 24 46 17 18 19 45 40 24 34 34 34 26 46 34 40 24 32 32 34 34 34 40 45 38 45 24 27 42 40 27 45 46 47 36 36 48
45 45 40 35 20 29 50 12 24 4 22 19 27 21 46 17 7 14 13 18 2 17 5 42 7 35 46 21 41 20 48 12 3 47 29 20 8 37 20 43 12 28 47 25 17 38 25 7 21 28
50
...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok good! (YES count = 1, NO count = 1999) (2000 test cases)

Test #47:

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

input:

500
100
29 18 29 55 29 67 29 8 55 10 45 55 55 14 26 29 17 55 60 76 60 55 19 80 55 29 29 67 55 60 9 45 33 34 55 60 18 38 29 67 29 45 27 9 55 26 55 74 74 29 60 26 18 45 55 60 45 26 59 55 55 62 9 64 55 66 55 68 55 11 45 55 82 55 26 9 60 18 79 11 60 26 74 84 76 53 87 9 9 16 11 55 55 60 29 55 45 73 29 60...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok good! (YES count = 0, NO count = 500) (500 test cases)

Test #48:

score: 0
Accepted
time: 13ms
memory: 7276kb

input:

5
1000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

output:

YES
250998
1 1
1 501
1 502
1 503
1 504
1 505
1 506
1 507
1 508
1 509
1 510
1 511
1 512
1 513
1 514
1 515
1 516
1 517
1 518
1 519
1 520
1 521
1 522
1 523
1 524
1 525
1 526
1 527
1 528
1 529
1 530
1 531
1 532
1 533
1 534
1 535
1 536
1 537
1 538
1 539
1 540
1 541
1 542
1 543
1 544
1 545
1 546
1 547
1 5...

result:

ok good! (YES count = 5, NO count = 0) (5 test cases)