QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114239#6502. Disjoint Set UnionmaspyAC ✓290ms9636kbC++2331.6kb2023-06-21 17:26:182023-06-21 17:26:21

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-21 17:26:21]
  • 评测
  • 测评结果:AC
  • 用时:290ms
  • 内存:9636kb
  • [2023-06-21 17:26:18]
  • 提交

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"

#line 2 "library/graph/base.hpp"

template <typename T>
struct Edge {
  int frm, to;
  T cost;
  int id;
};

template <typename T = int, bool directed = false>
struct Graph {
  int N, M;
  using cost_type = T;
  using edge_type = Edge<T>;
  vector<edge_type> edges;
  vector<int> indptr;
  vector<edge_type> csr_edges;
  vc<int> vc_deg, vc_indeg, vc_outdeg;
  bool prepared;

  class OutgoingEdges {
  public:
    OutgoingEdges(const Graph* G, int l, int r) : G(G), l(l), r(r) {}

    const edge_type* begin() const {
      if (l == r) { return 0; }
      return &G->csr_edges[l];
    }

    const edge_type* end() const {
      if (l == r) { return 0; }
      return &G->csr_edges[r];
    }

  private:
    const Graph* G;
    int l, r;
  };

  bool is_prepared() { return prepared; }
  constexpr bool is_directed() { return directed; }

  Graph() : N(0), M(0), prepared(0) {}
  Graph(int N) : N(N), M(0), prepared(0) {}

  void build(int n) {
    N = n, M = 0;
    prepared = 0;
    edges.clear();
    indptr.clear();
    csr_edges.clear();
    vc_deg.clear();
    vc_indeg.clear();
    vc_outdeg.clear();
  }

  void add(int frm, int to, T cost = 1, int i = -1) {
    assert(!prepared);
    assert(0 <= frm && 0 <= to && to < N);
    if (i == -1) i = M;
    auto e = edge_type({frm, to, cost, i});
    edges.eb(e);
    ++M;
  }

  // wt, off
  void read_tree(bool wt = false, int off = 1) { read_graph(N - 1, wt, off); }

  void read_graph(int M, bool wt = false, int off = 1) {
    for (int m = 0; m < M; ++m) {
      INT(a, b);
      a -= off, b -= off;
      if (!wt) {
        add(a, b);
      } else {
        T c;
        read(c);
        add(a, b, c);
      }
    }
    build();
  }

  void build() {
    assert(!prepared);
    prepared = true;
    indptr.assign(N + 1, 0);
    for (auto&& e: edges) {
      indptr[e.frm + 1]++;
      if (!directed) indptr[e.to + 1]++;
    }
    for (int v = 0; v < N; ++v) { indptr[v + 1] += indptr[v]; }
    auto counter = indptr;
    csr_edges.resize(indptr.back() + 1);
    for (auto&& e: edges) {
      csr_edges[counter[e.frm]++] = e;
      if (!directed)
        csr_edges[counter[e.to]++] = edge_type({e.to, e.frm, e.cost, e.id});
    }
  }

  OutgoingEdges operator[](int v) const {
    assert(prepared);
    return {this, indptr[v], indptr[v + 1]};
  }

  vc<int> deg_array() {
    if (vc_deg.empty()) calc_deg();
    return vc_deg;
  }

  pair<vc<int>, vc<int>> deg_array_inout() {
    if (vc_indeg.empty()) calc_deg_inout();
    return {vc_indeg, vc_outdeg};
  }

  int deg(int v) {
    if (vc_deg.empty()) calc_deg();
    return vc_deg[v];
  }

  int in_deg(int v) {
    if (vc_indeg.empty()) calc_deg_inout();
    return vc_indeg[v];
  }

  int out_deg(int v) {
    if (vc_outdeg.empty()) calc_deg_inout();
    return vc_outdeg[v];
  }

  void debug() {
    print("Graph");
    if (!prepared) {
      print("frm to cost id");
      for (auto&& e: edges) print(e.frm, e.to, e.cost, e.id);
    } else {
      print("indptr", indptr);
      print("frm to cost id");
      FOR(v, N) for (auto&& e: (*this)[v]) print(e.frm, e.to, e.cost, e.id);
    }
  }

  vc<int> new_idx;
  vc<bool> used_e;

  // G における頂点 V[i] が、新しいグラフで i になるようにする
  // {G, es}
  pair<Graph<T, directed>, vc<int>> rearrange(vc<int> V) {
    if (len(new_idx) != N) new_idx.assign(N, -1);
    if (len(used_e) != M) used_e.assign(M, 0);
    int n = len(V);
    FOR(i, n) new_idx[V[i]] = i;
    Graph<T, directed> G(n);
    vc<int> es;
    FOR(i, n) {
      for (auto&& e: (*this)[V[i]]) {
        if (used_e[e.id]) continue;
        int a = e.frm, b = e.to;
        if (new_idx[a] != -1 && new_idx[b] != -1) {
          used_e[e.id] = 1;
          G.add(new_idx[a], new_idx[b], e.cost);
          es.eb(e.id);
        }
      }
    }
    FOR(i, n) new_idx[V[i]] = -1;
    for (auto&& eid: es) used_e[eid] = 0;
    G.build();
    return {G, es};
  }

private:
  void calc_deg() {
    assert(vc_deg.empty());
    vc_deg.resize(N);
    for (auto&& e: edges) vc_deg[e.frm]++, vc_deg[e.to]++;
  }

  void calc_deg_inout() {
    assert(vc_indeg.empty());
    vc_indeg.resize(N);
    vc_outdeg.resize(N);
    for (auto&& e: edges) { vc_indeg[e.to]++, vc_outdeg[e.frm]++; }
  }
};
#line 2 "library/graph/tree.hpp"

#line 4 "library/graph/tree.hpp"

// HLD euler tour をとっていろいろ。
// 木以外、非連結でも dfs 順序や親がとれる。
template <typename GT>
struct Tree {
  using Graph_type = GT;
  GT &G;
  using WT = typename GT::cost_type;
  int N;
  vector<int> LID, RID, head, V, parent, VtoE;
  vc<int> depth;
  vc<WT> depth_weighted;

  Tree(GT &G, int r = 0, bool hld = 1) : G(G) { build(r, hld); }

  void build(int r = 0, bool hld = 1) {
    if (r == -1) return; // build を遅延したいとき
    N = G.N;
    LID.assign(N, -1), RID.assign(N, -1), head.assign(N, r);
    V.assign(N, -1), parent.assign(N, -1), VtoE.assign(N, -1);
    depth.assign(N, -1), depth_weighted.assign(N, 0);
    assert(G.is_prepared());
    int t1 = 0;
    dfs_sz(r, -1, hld);
    dfs_hld(r, t1);
  }

  void dfs_sz(int v, int p, bool hld) {
    auto &sz = RID;
    parent[v] = p;
    depth[v] = (p == -1 ? 0 : depth[p] + 1);
    sz[v] = 1;
    int l = G.indptr[v], r = G.indptr[v + 1];
    auto &csr = G.csr_edges;
    // 使う辺があれば先頭にする
    for (int i = r - 2; i >= l; --i) {
      if (hld && depth[csr[i + 1].to] == -1) swap(csr[i], csr[i + 1]);
    }
    int hld_sz = 0;
    for (int i = l; i < r; ++i) {
      auto e = csr[i];
      if (depth[e.to] != -1) continue;
      depth_weighted[e.to] = depth_weighted[v] + e.cost;
      VtoE[e.to] = e.id;
      dfs_sz(e.to, v, hld);
      sz[v] += sz[e.to];
      if (hld && chmax(hld_sz, sz[e.to]) && l < i) { swap(csr[l], csr[i]); }
    }
  }

  void dfs_hld(int v, int &times) {
    LID[v] = times++;
    RID[v] += LID[v];
    V[LID[v]] = v;
    bool heavy = true;
    for (auto &&e: G[v]) {
      if (depth[e.to] <= depth[v]) continue;
      head[e.to] = (heavy ? head[v] : e.to);
      heavy = false;
      dfs_hld(e.to, times);
    }
  }

  vc<int> heavy_path_at(int v) {
    vc<int> P = {v};
    while (1) {
      int a = P.back();
      for (auto &&e: G[a]) {
        if (e.to != parent[a] && head[e.to] == v) {
          P.eb(e.to);
          break;
        }
      }
      if (P.back() == a) break;
    }
    return P;
  }

  int e_to_v(int eid) {
    auto e = G.edges[eid];
    return (parent[e.frm] == e.to ? e.frm : e.to);
  }
  int v_to_e(int v) { return VtoE[v]; }

  int ELID(int v) { return 2 * LID[v] - depth[v]; }
  int ERID(int v) { return 2 * RID[v] - depth[v] - 1; }

  /* k: 0-indexed */
  int LA(int v, int k) {
    assert(k <= depth[v]);
    while (1) {
      int u = head[v];
      if (LID[v] - k >= LID[u]) return V[LID[v] - k];
      k -= LID[v] - LID[u] + 1;
      v = parent[u];
    }
  }
  int la(int u, int v) { return LA(u, v); }

  int LCA(int u, int v) {
    for (;; v = parent[head[v]]) {
      if (LID[u] > LID[v]) swap(u, v);
      if (head[u] == head[v]) return u;
    }
  }
  // root を根とした場合の lca
  int LCA_root(int u, int v, int root) {
    return LCA(u, v) ^ LCA(u, root) ^ LCA(v, root);
  }
  int lca(int u, int v) { return LCA(u, v); }
  int lca_root(int u, int v, int root) { return LCA_root(u, v, root); }

  int subtree_size(int v, int root = -1) {
    if (root == -1) return RID[v] - LID[v];
    if (v == root) return N;
    int x = jump(v, root, 1);
    if (in_subtree(v, x)) return RID[v] - LID[v];
    return N - RID[x] + LID[x];
  }

  int dist(int a, int b) {
    int c = LCA(a, b);
    return depth[a] + depth[b] - 2 * depth[c];
  }

  WT dist_weighted(int a, int b) {
    int c = LCA(a, b);
    return depth_weighted[a] + depth_weighted[b] - WT(2) * depth_weighted[c];
  }

  // a is in b
  bool in_subtree(int a, int b) { return LID[b] <= LID[a] && LID[a] < RID[b]; }

  int jump(int a, int b, ll k) {
    if (k == 1) {
      if (a == b) return -1;
      return (in_subtree(b, a) ? LA(b, depth[b] - depth[a] - 1) : parent[a]);
    }
    int c = LCA(a, b);
    int d_ac = depth[a] - depth[c];
    int d_bc = depth[b] - depth[c];
    if (k > d_ac + d_bc) return -1;
    if (k <= d_ac) return LA(a, k);
    return LA(b, d_ac + d_bc - k);
  }

  vc<int> collect_child(int v) {
    vc<int> res;
    for (auto &&e: G[v])
      if (e.to != parent[v]) res.eb(e.to);
    return res;
  }

  vc<pair<int, int>> get_path_decomposition(int u, int v, bool edge) {
    // [始点, 終点] の"閉"区間列。
    vc<pair<int, int>> up, down;
    while (1) {
      if (head[u] == head[v]) break;
      if (LID[u] < LID[v]) {
        down.eb(LID[head[v]], LID[v]);
        v = parent[head[v]];
      } else {
        up.eb(LID[u], LID[head[u]]);
        u = parent[head[u]];
      }
    }
    if (LID[u] < LID[v]) down.eb(LID[u] + edge, LID[v]);
    elif (LID[v] + edge <= LID[u]) up.eb(LID[u], LID[v] + edge);
    reverse(all(down));
    up.insert(up.end(), all(down));
    return up;
  }

  vc<int> restore_path(int u, int v) {
    vc<int> P;
    for (auto &&[a, b]: get_path_decomposition(u, v, 0)) {
      if (a <= b) {
        FOR(i, a, b + 1) P.eb(V[i]);
      } else {
        FOR_R(i, b, a + 1) P.eb(V[i]);
      }
    }
    return P;
  }
};
#line 2 "library/ds/unionfind/unionfind.hpp"

struct UnionFind {
  int n, n_comp;
  vc<int> dat; // par or (-size)
  UnionFind(int n = 0) { build(n); }

  void build(int m) {
    n = m, n_comp = m;
    dat.assign(n, -1);
  }

  void reset() { build(n); }

  int operator[](int x) {
    while (dat[x] >= 0) {
      int pp = dat[dat[x]];
      if (pp < 0) { return dat[x]; }
      x = dat[x] = pp;
    }
    return x;
  }

  ll size(int x) {
    x = (*this)[x];
    return -dat[x];
  }

  bool merge(int x, int y) {
    x = (*this)[x], y = (*this)[y];
    if (x == y) return false;
    if (-dat[x] < -dat[y]) swap(x, y);
    dat[x] += dat[y], dat[y] = x, n_comp--;
    return true;
  }
};
#line 3 "library/graph/functional.hpp"

// N が根となる木を新たに作る
template <typename T = int>
struct FunctionalGraph {
  int N, M;
  vc<int> TO;
  vc<T> wt;
  vc<int> root;
  Graph<T, 1> G;

  FunctionalGraph() {}
  FunctionalGraph(int N) : N(N), M(0), TO(N, -1), wt(N), root(N, -1) {}

  void add(int a, int b, T c = 1) {
    assert(0 <= a && a < N);
    assert(TO[a] == -1);
    ++M;
    TO[a] = b;
    wt[a] = c;
  }

  pair<Graph<T, 1>, Tree<Graph<T, 1>>> build() {
    assert(N == M);
    UnionFind uf(N);
    FOR(v, N) if (!uf.merge(v, TO[v])) { root[v] = v; }
    FOR(v, N) if (root[v] == v) root[uf[v]] = v;
    FOR(v, N) root[v] = root[uf[v]];

    G.build(N + 1);
    FOR(v, N) {
      if (root[v] == v)
        G.add(N, v, wt[v]);
      else
        G.add(TO[v], v, wt[v]);
    }
    G.build();
    Tree<Graph<T, 1>> tree(G, N);
    return {G, tree};
  }

  // functional graph に向かって進む
  template <typename TREE>
  int jump(TREE& tree, int v, ll step) {
    int d = tree.depth[v];
    if (step <= d - 1) return tree.jump(v, N, step);
    v = root[v];
    step -= d - 1;
    int bottom = TO[v];
    int c = tree.depth[bottom];
    step %= c;
    if (step == 0) return v;
    return tree.jump(bottom, N, step - 1);
  }

  // functional graph に step 回進む
  template <typename TREE>
  vc<int> jump_all(TREE& tree, ll step) {
    vc<int> res(N, -1);
    // v の k 個先を res[w] に入れる
    vvc<pair<int, int>> query(N);
    FOR(v, N) {
      int d = tree.depth[v];
      int r = root[v];
      if (d - 1 > step) { query[v].eb(v, step); }
      if (d - 1 <= step) {
        ll k = step - (d - 1);
        int bottom = TO[r];
        int c = tree.depth[bottom];
        k %= c;
        if (k == 0) {
          res[v] = r;
          continue;
        }
        query[bottom].eb(v, k - 1);
      }
    }

    vc<int> path;
    auto dfs = [&](auto& dfs, int v) -> void {
      path.eb(v);
      for (auto&& [w, k]: query[v]) { res[w] = path[len(path) - 1 - k]; }
      for (auto&& e: G[v]) dfs(dfs, e.to);
      path.pop_back();
    };
    for (auto&& e: G[N]) { dfs(dfs, e.to); }
    return res;
  }

  template <typename TREE>
  bool in_cycle(TREE& tree, int v) {
    int r = root[v];
    int bottom = TO[r];
    return tree.in_subtree(bottom, v);
  }

  vc<int> collect_cycle(int r) {
    assert(r == root[r]);
    vc<int> cyc = {TO[r]};
    while (cyc.back() != r) cyc.eb(TO[cyc.back()]);
    return cyc;
  }
};
#line 1 "library/ds/fastset.hpp"
/* 64分木。
insert, erase
[]での存在判定
next, prev
*/
struct FastSet {
  using uint = unsigned;
  using ull = unsigned long long;

  int bsr(ull x) { return 63 - __builtin_clzll(x); }
  int bsf(ull x) { return __builtin_ctzll(x); }

  static constexpr uint B = 64;
  int n, lg;
  vector<vector<ull>> seg;
  FastSet(int _n) : n(_n) {
    do {
      seg.push_back(vector<ull>((_n + B - 1) / B));
      _n = (_n + B - 1) / B;
    } while (_n > 1);
    lg = int(seg.size());
  }
  bool operator[](int i) const { return (seg[0][i / B] >> (i % B) & 1) != 0; }
  void insert(int i) {
    for (int h = 0; h < lg; h++) {
      seg[h][i / B] |= 1ULL << (i % B);
      i /= B;
    }
  }
  void add(int i) { insert(i); }
  void erase(int i) {
    for (int h = 0; h < lg; h++) {
      seg[h][i / B] &= ~(1ULL << (i % B));
      if (seg[h][i / B]) break;
      i /= B;
    }
  }
  void remove(int i) { insert(i); }

  // x以上最小の要素を返す。存在しなければ n。
  int next(int i) {
    chmax(i, 0);
    if (i >= n) return n;
    for (int h = 0; h < lg; h++) {
      if (i / B == seg[h].size()) break;
      ull d = seg[h][i / B] >> (i % B);
      if (!d) {
        i = i / B + 1;
        continue;
      }
      // find
      i += bsf(d);
      for (int g = h - 1; g >= 0; g--) {
        i *= B;
        i += bsf(seg[g][i / B]);
      }
      return i;
    }
    return n;
  }

  // x以下最大の要素を返す。存在しなければ -1。
  int prev(int i) {
    if (i < 0) return -1;
    if (i >= n) i = n - 1;
    for (int h = 0; h < lg; h++) {
      if (i == -1) break;
      ull d = seg[h][i / B] << (63 - i % 64);
      if (!d) {
        i = i / B - 1;
        continue;
      }
      // find
      i += bsr(d) - (B - 1);
      for (int g = h - 1; g >= 0; g--) {
        i *= B;
        i += bsr(seg[g][i / B]);
      }
      return i;
    }
    return -1;
  }

  // [l, r)
  template <typename F>
  void enumerate(int l, int r, F f) {
    int x = l - 1;
    while (1) {
      x = next(x + 1);
      if (x >= r) break;
      f(x);
    }
  }

  void debug() {
    string s;
    for (int i = 0; i < n; ++i) s += ((*this)[i] ? '1' : '0');
    print(s);
  }
};
#line 3 "library/graph/toposort.hpp"

// 辞書順最小の toposort を返す
template <typename GT>
vc<int> toposort(GT& G) {
  assert(G.is_prepared() && G.is_directed());
  const int N = G.N;
  auto [indeg, outdeg] = G.deg_array_inout();
  FastSet que(N);
  vc<int> V;
  FOR(v, N) if (indeg[v] == 0) que.insert(v);
  while (1) {
    int v = que.next(0);
    if (v == N) break;
    que.erase(v), V.eb(v);
    for (auto&& e: G[v]) {
      if (--indeg[e.to] == 0) que.insert(e.to);
    }
  }
  return (len(V) < N ? vc<int>{} : V);
}
#line 7 "main.cpp"

void solve() {
  LL(N);
  VEC(ll, A, N);
  VEC(ll, B, N);
  FOR(i, N) A[i]--;
  FOR(i, N) B[i]--;
  vi AA = A;

  using T = tuple<int, int, int>;
  vc<T> ANS;
  auto FIND = [&](int x, bool upd = true) -> int {
    if (A[x] == x) return x;
    if (A[A[x]] == A[x]) return A[x];
    if (upd) {
      ANS.eb(1, 1 + x, -1);
      auto dfs = [&](auto& dfs, int v) -> int {
        if (A[v] == v) return v;
        int x = dfs(dfs, A[v]);
        A[v] = x;
        return x;
      };
      dfs(dfs, x);
    }
    auto dfs = [&](auto& dfs, int v) -> int {
      if (AA[v] == v) return v;
      int x = dfs(dfs, AA[v]);
      AA[v] = x;
      return x;
    };
    return dfs(dfs, x);
  };

  auto UNITE = [&](int x, int y) -> void {
    ANS.eb(2, 1 + x, 1 + y);
    x = FIND(x), y = FIND(y);
    if (x != y) { A[x] = y, AA[x] = y; }
  };

  // stay するのでなければ、find しておく
  while (1) {
    bool upd = 0;
    FOR(v, N) if (A[v] != B[v]) {
      int before = A[v];
      FIND(v);
      int after = A[v];
      if (before != after) upd = 1;
    }
    if (!upd) break;
  }

  // それぞれ functional graph
  FunctionalGraph<int> FGA(N);
  FunctionalGraph<int> FGB(N);
  FOR(i, N) {
    FGA.add(i, A[i], 1);
    FGB.add(i, B[i], 1);
  }
  auto [GA, treeA] = FGA.build();
  auto [GB, treeB] = FGB.build();

  // そもそも B が有向木でなければ NO
  FOR(v, N) {
    if (FGA.root[v] != v) continue;
    if (A[v] != v) return NO();
  }
  FOR(v, N) {
    if (FGB.root[v] != v) continue;
    if (B[v] != v) return NO();
  }

  // stay or some root of A
  FOR(v, N) {
    if (A[v] == B[v]) continue;
    if (FGA.root[A[v]] != A[v]) return NO();
  }

  // A の根たちをマージする
  // topo 順を求める
  vc<int> ord;
  {
    Graph<int, 1> G(N);
    FOR(v, N) {
      int x = FIND(v, false);
      if (x != B[v]) G.add(B[v], x);
    }
    G.build();
    auto V = toposort(G);
    for (auto&& x: V) {
      if (FGA.root[x] == x) { ord.eb(x); }
    }
    if (ord.empty()) return NO();
  }

  // 根から遠い点に辺を貼るやつから unite していく
  reverse(all(ord));
  for (auto&& to: ord) {
    FOR(v, N) {
      int r = FIND(v, 0);
      if (r != to && B[v] == to) { UNITE(r, to); }
    }
    FOR(v, N) {
      if (A[v] != B[v]) { FIND(v, 1); }
    }
  }

  FOR(v, N) if (A[v] != B[v]) {
    int r = FIND(v, 0);
    UNITE(r, B[v]), FIND(v);
  }
  FOR(v, N) if (A[v] != B[v]) return NO();

  YES();
  print(len(ANS));
  for (auto&& [t, a, b]: ANS) {
    if (t == 1) print(t, a);
    if (t == 2) print(t, a, b);
  }
}

signed main() {
  INT(T);
  FOR(T) solve();
  return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
1
2 1 2
YES
4
2 3 2
1 4
2 2 1
1 3
YES
4
2 1 2
2 2 3
2 3 4
2 4 5
NO
YES
7
2 6 2
2 2 5
1 3
2 5 4
1 2
2 4 1
1 2

result:

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

Test #2:

score: 0
Accepted
time: 281ms
memory: 3716kb

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
2
2 1 2
1 5
YES
0
YES
5
2 2 4
2 3 4
1 5
2 4 1
1 5
YES
2
2 3 2
1 5
YES
0
YES
2
2 1 5
2 2 3
YES
3
2 2 4
2 5 4
2 3 1
YES
1
2 5 2
YES
1
2 2 3
YES
3
2 3 4
1 5
2 1 2
YES
1
2 1 5
YES
3
2 1 5
2 4 5
1 3
YES
3
2 3 5
2 4 5
2 5 1
YES
5
2 4 3
1 2
2 3 1
1 2
1 5
YES
4
2 1 5
2 2 5
2 3 5
1 4
YES
4
2 2 1
2 3 1
2 ...

result:

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

Test #3:

score: 0
Accepted
time: 261ms
memory: 3640kb

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
1
2 2 10
YES
7
2 2 6
2 3 6
2 4 6
2 5 6
1 7
1 8
1 9
YES
9
2 2 7
2 10 7
1 8
2 1 9
2 4 9
2 7 9
1 5
1 6
1 8
YES
10
1 4
1 5
2 1 2
2 3 2
2 8 2
2 10 2
1 4
1 5
1 7
1 9
YES
3
2 5 10
2 8 10
2 1 2
YES
9
2 1 5
2 8 5
2 3 5
2 6 5
2 10 5
2 9 5
1 2
1 4
1 7
YES
12
1 3
2 2 6
2 8 4
1 1
1 3
1 7
2 4 10
2 6 10
2 9 10...

result:

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

Test #4:

score: 0
Accepted
time: 120ms
memory: 3624kb

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
14
2 9 8
1 1
1 12
2 8 18
1 9
2 5 4
2 14 4
2 19 4
2 17 4
2 18 4
1 16
2 4 6
2 13 6
2 11 3
YES
16
1 1
1 5
2 4 8
2 20 8
2 17 8
2 19 8
1 16
2 3 2
2 15 12
2 2 12
2 8 12
2 10 12
1 1
1 5
1 6
2 18 9
YES
16
1 6
1 15
2 5 19
2 2 19
1 1
2 7 14
2 9 3
2 11 3
2 13 3
1 6
1 15
1 20
2 3 4
2 10 4
1 12
1 17
YES
2
2 ...

result:

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

Test #5:

score: 0
Accepted
time: 121ms
memory: 3700kb

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
26
2 5 13
2 19 13
1 9
1 15
1 18
2 17 11
2 13 11
1 5
1 9
1 18
2 7 4
1 8
2 20 2
2 2 3
2 4 3
2 11 3
2 6 3
2 14 3
2 16 3
1 5
1 8
1 9
1 13
2 3 12
1 8
2 1 10
YES
12
1 9
2 7 1
2 1 13
2 2 13
2 5 13
2 6 13
2 10 13
2 11 13
2 16 13
2 17 13
2 19 13
2 20 13
YES
6
2 8 19
2 5 17
2 15 10
2 16 10
2 2 9
2 13 3
YE...

result:

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

Test #6:

score: 0
Accepted
time: 32ms
memory: 3696kb

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
156
1 1
1 2
1 7
1 10
1 16
1 20
1 22
1 25
1 28
1 33
1 37
1 46
1 51
1 53
1 54
1 57
1 61
1 71
1 72
1 74
1 75
1 87
1 89
1 99
2 11 36
2 58 6
2 77 6
1 24
1 95
2 94 70
2 3 70
2 13 70
2 6 70
2 66 70
2 8 70
2 9 70
2 82 70
2 15 70
2 17 70
2 76 70
2 19 70
2 35 70
2 50 70
2 30 70
2 31 70
2 34 70
2 36 70
2 4...

result:

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

Test #7:

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

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
2082
1 1
1 2
1 3
1 4
1 5
1 6
1 8
1 9
1 12
1 13
1 14
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 25
1 26
1 29
1 30
1 32
1 33
1 35
1 38
1 39
1 40
1 46
1 48
1 49
1 50
1 51
1 55
1 60
1 65
1 66
1 67
1 68
1 69
1 74
1 77
1 78
1 79
1 81
1 82
1 83
1 84
1 85
1 87
1 88
1 90
1 91
1 92
1 93
1 94
1 95
1 98
1 99
1 10...

result:

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

Test #8:

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

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
8499
1 1
1 2
1 5
1 7
1 9
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 19
1 20
1 21
1 22
1 23
1 25
1 27
1 28
1 30
1 31
1 32
1 33
1 36
1 37
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 50
1 51
1 52
1 53
1 56
1 59
1 62
1 63
1 64
1 65
1 66
1 67
1 68
1 69
1 70
1 71
1 72
1 73
1 74
1 75
1 76
1 77
1 79
1 80
1...

result:

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

Test #9:

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

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
1706
1 2
1 3
1 4
1 5
1 7
1 9
1 11
1 12
1 13
1 14
1 16
1 18
1 19
1 21
1 22
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 35
1 37
1 39
1 40
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 52
1 53
1 54
1 55
1 56
1 58
1 59
1 60
1 61
1 63
1 64
1 66
1 68
1 69
1 70
1 72
1 74
1 75
1 77
1 78
1 79
1 80
1 81
1 83
1 ...

result:

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

Test #10:

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

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
1162
1 9
1 16
1 18
1 22
1 25
1 27
1 30
1 32
1 36
1 37
1 44
1 49
1 51
1 54
1 55
1 59
1 78
1 79
1 83
1 86
1 88
1 90
1 92
1 94
1 100
1 104
1 107
1 112
1 115
1 119
1 122
1 124
1 125
1 128
1 133
1 138
1 148
1 149
1 155
1 156
1 159
1 176
1 185
1 198
1 201
1 202
1 204
1 206
1 224
1 226
1 231
1 239
1 24...

result:

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

Test #11:

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

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
1909
1 2
1 4
1 6
1 8
1 12
1 13
1 14
1 15
1 16
1 17
1 19
1 20
1 22
1 23
1 24
1 25
1 26
1 29
1 33
1 34
1 36
1 37
1 40
1 41
1 42
1 44
1 45
1 47
1 48
1 49
1 50
1 51
1 53
1 54
1 55
1 57
1 58
1 59
1 60
1 62
1 64
1 66
1 67
1 68
1 70
1 71
1 75
1 76
1 80
1 81
1 83
1 85
1 86
1 87
1 88
1 89
1 90
1 91
1 92
...

result:

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

Test #12:

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

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
1004
1 393
1 412
1 738
2 158 844
2 51 723
2 213 723
2 664 723
2 426 647
1 322
2 413 645
2 530 645
2 720 645
2 871 645
2 845 645
1 789
2 102 490
2 148 490
2 357 490
2 847 490
2 877 490
2 221 297
1 106
2 262 120
2 279 120
2 330 120
2 556 120
2 658 120
2 709 120
2 728 120
2 787 120
2 936 120
2 1 86...

result:

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

Test #13:

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

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
1251
1 47
1 61
1 175
1 196
1 259
1 350
1 381
1 474
1 908
1 945
2 155 895
2 723 864
2 145 842
2 383 842
2 762 842
2 766 842
2 508 794
2 49 761
1 47
1 963
2 515 726
2 266 726
2 300 726
2 311 726
2 403 726
2 407 726
2 663 726
2 887 726
1 90
1 969
2 103 685
2 104 685
2 139 685
2 232 685
2 813 685
2 ...

result:

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

Test #14:

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

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
13607
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 48
1 49
1 50
1 51
1 52
1 54
1 55
1 56
1 57
1 58
1 59
1 61
1 62
1 63
1 64
1 65
1 66...

result:

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

Test #15:

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

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
1019
1 63
1 89
1 129
1 210
1 215
1 237
1 304
1 308
1 331
1 334
1 379
1 394
1 608
1 626
1 756
1 774
1 822
1 971
1 996
2 3 968
1 368
2 766 489
2 2 489
2 4 489
2 5 489
2 6 489
2 7 489
2 8 489
2 9 489
2 10 489
2 11 489
2 12 489
2 13 489
2 14 489
2 15 489
2 16 489
2 592 489
2 18 489
2 19 489
2 20 489...

result:

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

Test #16:

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

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
2446
1 1
1 2
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 39
1 40
1 41
1 42
1 43
1 46
1 47
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 59
1 60
1 61
1 62
1 63
1 64
1 65
1 66
1 67
1 70...

result:

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

Test #17:

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

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
12429
1 6
1 22
1 27
1 37
1 38
1 61
1 74
1 81
1 87
1 99
1 102
1 106
1 118
1 119
1 120
1 123
1 143
1 155
1 167
1 174
1 181
1 184
1 196
1 204
1 205
1 212
1 221
1 223
1 230
1 263
1 265
1 270
1 271
1 275
1 276
1 308
1 321
1 329
1 359
1 375
1 381
1 388
1 398
1 419
1 423
1 434
1 438
1 450
1 467
1 474
1...

result:

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

Test #18:

score: 0
Accepted
time: 5ms
memory: 3924kb

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
11986
1 1
1 2
1 4
1 5
1 8
1 12
1 20
1 26
1 27
1 30
1 33
1 36
1 37
1 38
1 45
1 46
1 48
1 58
1 67
1 70
1 74
1 75
1 79
1 82
1 85
1 87
1 93
1 95
1 97
1 99
1 104
1 107
1 109
1 110
1 115
1 120
1 125
1 128
1 129
1 135
1 137
1 146
1 148
1 150
1 156
1 174
1 175
1 176
1 177
1 185
1 187
1 189
1 190
1 191
1...

result:

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

Test #19:

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

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
1703
1 62
1 522
1 601
1 768
1 778
1 784
1 846
1 913
1 974
2 977 1000
2 939 987
2 812 987
2 898 987
1 281
2 995 971
2 165 970
2 529 418
2 627 957
2 418 957
1 2
1 275
2 863 956
2 397 948
1 774
2 263 944
2 582 941
2 336 146
2 146 929
2 653 929
2 394 919
2 438 919
2 833 919
2 975 919
2 766 911
2 104...

result:

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

Test #20:

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

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
944
1 119
1 498
1 769
1 827
1 899
2 95 997
2 232 997
2 872 997
2 773 978
2 104 967
2 399 854
2 238 844
2 955 801
2 188 777
2 805 183
2 183 502
2 386 502
2 410 502
2 912 502
2 575 502
2 683 502
2 733 502
2 967 502
1 26
1 531
1 703
2 369 776
2 502 776
2 550 776
1 26
1 703
1 912
2 120 11
2 854 11
2...

result:

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

Test #21:

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

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
1
2 10 7
YES
5
2 3 8
2 6 8
1 4
2 7 9
2 8 9
YES
5
1 2
2 1 9
2 4 7
2 6 5
2 9 5
YES
1
2 7 3
YES
2
2 2 4
2 5 4
YES
2
2 3 8
2 2 5
YES
7
2 1 10
2 4 10
2 9 10
1 8
2 3 5
2 7 5
2 10 5
YES
2
2 2 3
2 9 5
YES
3
2 8 10
2 10 4
1 9
YES
3
2 5 3
2 3 10
2 4 10
YES
6
1 2
2 8 6
1 2
1 3
2 5 10
2 6 10
YES
4
2 4 7
2 6...

result:

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

Test #22:

score: 0
Accepted
time: 115ms
memory: 3604kb

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
1
2 7 3
YES
7
2 18 15
2 14 12
2 6 8
2 9 1
2 1 7
2 12 3
2 13 3
YES
7
1 8
2 2 14
2 10 6
2 7 6
2 17 6
1 3
2 9 4
YES
12
1 2
2 14 4
2 7 8
1 2
1 18
2 1 11
2 8 11
2 3 11
2 4 11
2 5 11
1 2
1 13
YES
10
2 12 20
2 1 19
2 17 13
2 11 16
2 13 16
2 15 16
2 10 8
2 18 8
2 6 5
2 2 4
YES
4
2 20 11
2 3 5
2 5 10
2 1...

result:

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

Test #23:

score: 0
Accepted
time: 29ms
memory: 3692kb

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
49
2 26 99
2 39 99
2 96 99
2 43 97
2 25 91
2 1 87
2 30 87
2 32 87
2 61 86
2 59 82
2 13 18
2 41 18
2 68 18
2 100 18
2 18 81
2 42 78
2 46 78
2 70 76
2 93 76
2 81 62
2 31 53
2 76 52
2 48 54
2 52 54
2 53 54
2 66 54
2 89 54
2 92 54
2 63 47
2 12 11
2 2 45
2 11 45
2 74 45
2 97 45
1 57
1 69
2 71 37
2 98...

result:

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

Test #24:

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

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
1197
1 4
1 20
1 24
1 26
1 35
1 38
1 44
1 56
1 57
1 59
1 63
1 67
1 71
1 77
1 78
1 82
1 83
1 87
1 88
1 90
1 91
1 99
1 110
1 114
1 115
1 116
1 117
1 121
1 122
1 126
1 128
1 130
1 146
1 148
1 157
1 162
1 164
1 165
1 166
1 167
1 171
1 177
1 180
1 183
1 185
1 186
1 190
1 192
1 193
1 196
1 204
1 209
1 ...

result:

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

Test #25:

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

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
9
1 240
2 157 924
2 400 845
2 812 795
2 942 501
2 913 318
2 480 183
2 189 77
2 886 45
YES
45
2 314 995
2 133 984
2 884 967
2 412 961
2 925 936
2 38 931
2 866 917
2 675 906
2 398 880
2 417 835
2 661 819
2 152 817
2 256 777
2 571 697
2 211 693
2 555 150
2 150 686
2 983 682
2 114 669
2 935 625
2 98...

result:

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

Test #26:

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

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
102
1 1
1 74
1 130
1 177
1 993
2 94 1000
2 184 998
2 118 991
2 478 344
2 155 962
2 655 953
2 778 948
2 327 943
2 636 937
2 964 933
2 549 924
2 767 917
2 766 912
2 314 894
2 981 893
2 995 893
2 425 892
2 755 887
2 909 566
2 566 886
2 120 867
2 396 862
2 157 855
2 340 851
2 812 850
2 86 848
2 519 ...

result:

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

Test #27:

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

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
197
1 57
1 68
1 73
1 89
1 141
1 168
1 210
1 213
1 266
1 267
1 321
1 324
1 335
1 362
1 482
1 511
1 525
1 545
1 597
1 598
1 699
1 779
1 781
1 867
1 938
1 940
1 976
1 998
2 439 701
2 605 487
2 487 729
2 729 991
2 231 984
2 562 968
2 860 963
2 257 960
2 571 873
2 873 342
1 267
1 511
1 699
1 951
2 34...

result:

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

Test #28:

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

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
50
1 571
2 345 941
2 911 931
2 435 925
2 622 918
2 723 858
2 679 856
2 141 837
2 376 250
2 250 770
2 546 770
2 869 737
2 134 460
2 460 735
2 235 722
2 662 717
2 170 707
2 226 698
2 248 683
2 969 660
2 181 648
2 288 626
2 211 619
2 400 583
2 11 562
2 937 514
2 637 485
2 947 479
2 856 344
2 44 457...

result:

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

Test #29:

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

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
710
1 1
1 4
1 18
1 34
1 36
1 37
1 38
1 40
1 56
1 58
1 63
1 101
1 104
1 143
1 159
1 161
1 166
1 173
1 210
1 213
1 222
1 234
1 258
1 266
1 269
1 271
1 272
1 293
1 302
1 310
1 328
1 367
1 372
1 380
1 384
1 402
1 406
1 440
1 449
1 464
1 483
1 513
1 519
1 531
1 575
1 582
1 609
1 649
1 693
1 725
1 787...

result:

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

Test #30:

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

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
1117
1 10
1 11
1 19
1 31
1 36
1 42
1 45
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 150
1 152
1 153
1 156
1 166
1 173
1 176
1 180
1 181
1 185
1 191
1 195
1 203
1 235
1 240
1 249
1 269
1 275
1 284
1 285
1 296
1 303
1 311
1 325
1 328
1 348
1 369
1 370
1 377
1 385
1 386
1 392
1 4...

result:

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

Test #31:

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

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
212
1 27
1 81
1 116
1 160
1 167
1 182
1 394
1 408
1 669
1 678
1 702
1 762
1 915
1 981
2 492 601
2 527 997
2 895 997
2 186 443
2 765 443
2 443 861
2 595 861
1 27
1 631
2 861 995
1 27
1 631
2 350 891
2 839 195
2 195 632
2 891 632
2 62 971
2 174 969
2 376 585
2 566 585
2 562 959
2 293 949
2 980 416...

result:

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

Test #32:

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

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
151
1 156
1 212
1 623
1 989
2 788 997
2 805 996
2 565 990
2 722 974
2 311 970
2 270 960
2 935 960
2 905 958
2 59 957
2 216 954
2 885 948
2 696 947
2 450 946
2 865 931
2 840 929
2 698 772
2 772 919
2 50 633
2 695 633
2 648 633
1 212
1 403
1 407
2 633 910
2 202 394
2 394 891
2 222 761
2 501 869
2 ...

result:

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

Test #33:

score: 0
Accepted
time: 219ms
memory: 3632kb

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
2
2 4 3
2 2 1
NO
NO
NO
YES
3
2 1 2
2 2 3
2 3 4
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
2 3 4
2 4 1
1 2
NO
NO
YES
3
2 2 3
2 4 3
2 3 1
YES
3
2 1 2
2 3 2
2 4 2
NO
NO
NO
NO
NO
YES
2
2 2 1
2 3 1
YES
3
2 1 4
2 2 3
2 4 3
NO
NO
NO
YES
3
2 2 3
2 3 4
2 4 1
NO
NO
NO
NO
NO
YES
2
2 3 4
2 4 1
NO
NO
NO
NO...

result:

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

Test #34:

score: 0
Accepted
time: 235ms
memory: 3560kb

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
3
2 4 5
2 2 3
2 5 3
NO
NO
NO
NO
NO
YES
4
2 4 1
2 1 2
2 2 3
2 3 5
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
4
2 1 4
2 2 4
2 4 3
2 5 3
NO
NO
NO
NO
YES
3
2 1 5
2 3 5
2 4 2
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
4
2 1 4
2 5 3
2 3 2
2 4 2
NO
NO
NO
YES
4
2 2 5
2 1 4
2 4 3
2 5 3
NO
NO
NO
YES
4
2 2 3
2 4 3
2 3 5
1 1
NO...

result:

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

Test #35:

score: 0
Accepted
time: 250ms
memory: 3644kb

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
3
2 3 1
2 1 2
2 5 2
NO
NO
NO
NO
YES
2
2 2 4
2 4 3
NO
NO
NO
NO
NO
YES
4
2 2 4
2 4 5
2 3 5
1 1
NO
YES
3
2 1 2
2 2 4
2 5 4
NO
NO
NO
NO
YES
4
2 5 4
2 4 1
2 1 2
2 2 3
YES
4
2 2 5
2 3 5
2 5 4
2 4 1
NO
NO
YES
3
2 4 2
2 2 1
2 1 3
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
2 1 2...

result:

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

Test #36:

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

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
5
2 6 2
2 2 1
2 5 1
2 1 4
2 4 3
NO
NO
YES
5
2 5 4
2 1 3
2 4 3
2 3 6
2 6 2
YES
5
2 1 6
2 6 3
2 3 5
2 2 4
2 5 4
NO
NO
NO
YES
5
2 3 4
2 5 4
2 1 2
2 4 2
2 2 6
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
5
2 1 5
2 3 5
2 5 4
2 4 2
2 6 2
YES
4
2 5 6
2 2 3
2 6 3
2 4 1
NO
NO
NO
...

result:

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

Test #37:

score: 0
Accepted
time: 256ms
memory: 3644kb

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
3
2 1 3
2 4 2
2 5 2
NO
NO
NO
YES
5
2 2 1
2 1 5
2 3 5
2 4 5
2 6 5
NO
YES
4
2 6 4
2 1 5
2 4 5
2 5 2
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
4
2 6 3
2 2 5
2 3 5
2 5 4
YES
4
2 3 2
2 2 6
2 5 6
2 6 4
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
4
2 1 2
2 2 6
2 3 4
2 4 5
NO
YES
4
...

result:

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

Test #38:

score: 0
Accepted
time: 282ms
memory: 3608kb

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
6
2 7 1
2 1 5
2 5 3
2 3 2
2 2 6
2 4 6
NO
NO
YES
6
2 4 2
2 2 3
2 3 1
2 1 5
2 5 7
2 6 7
NO
NO
NO
NO
NO
NO
NO
NO
YES
4
2 3 2
2 6 2
2 2 7
2 1 4
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
5
2 4 1
2 1 6
2 6 7
2 3 2
2 7 2
NO
NO
NO
NO
NO
NO
NO
YES
6
2 4 6
2 2 7
2 6 7
2 5 3
2 7 3
2 3 1
NO
NO
NO
NO
NO
NO
...

result:

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

Test #39:

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

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
4
2 7 6
2 2 5
2 6 4
2 5 3
NO
NO
NO
NO
NO
YES
6
2 7 3
2 3 2
2 2 1
2 1 5
2 5 4
2 6 4
NO
NO
NO
YES
5
2 2 7
2 3 7
2 7 1
2 1 6
2 6 4
NO
YES
5
2 5 6
2 7 6
2 6 4
2 2 1
2 4 1
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
6
2 4 5
2 3 1
2 1 6
2 2 6
2 5...

result:

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

Test #40:

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

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
5
2 4 8
2 6 7
2 7 1
2 1 5
2 8 5
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
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
6
2 6 7
2 7 2
2 2 3
2 3 8
2 8 4
2 5 1
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
5
2 3 8
2 8 7
2 7 5
2 5 6
2 4 2
NO
NO
NO
...

result:

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

Test #41:

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

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
6
2 1 5
2 5 9
2 2 8
2 9 8
2 6 7
2 7 4
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
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 = 2842, NO count = 58886) (61728 test cases)

Test #42:

score: 0
Accepted
time: 156ms
memory: 3564kb

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
9
2 1 5
2 5 10
2 2 7
2 9 7
2 10 6
2 8 4
2 4 11
2 6 11
2 7 11
NO
NO
NO
NO
NO
NO
NO
YES
10
2 1 11
2 8 10
2 11 4
2 4 5
2 6 5
2 10 5
1 7
2 5 9
1 6
2 2 3
NO
NO
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 = 1240, NO count = 40082) (41322 test cases)

Test #43:

score: 0
Accepted
time: 181ms
memory: 3644kb

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
8
2 8 10
2 2 9
2 1 6
2 4 3
2 3 7
2 6 7
2 7 5
2 10 5
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
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 = 1641, NO count = 48359) (50000 test cases)

Test #44:

score: 0
Accepted
time: 141ms
memory: 3640kb

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
12
1 6
2 5 3
2 8 3
1 9
2 12 2
2 4 1
2 11 1
2 1 10
2 2 10
2 3 10
1 9
2 10 7
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
8
2 3 12
2 6 12
2 8 12
2 12 11
2 2 9
2 9 5
2 4 1
2 7 1
NO
NO
NO
NO
NO
NO
YES
10
2 4 7
2 ...

result:

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

Test #45:

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

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: 22ms
memory: 3564kb

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: 10ms
memory: 3684kb

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: 29ms
memory: 9636kb

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
249999
2 1 2
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...

result:

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