QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#737137#7621. PalindromemaspyAC ✓1677ms215728kbC++2341.4kb2024-11-12 14:45:162024-11-12 14:45:18

Judging History

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

  • [2024-11-12 14:45:18]
  • 评测
  • 测评结果:AC
  • 用时:1677ms
  • 内存:215728kb
  • [2024-11-12 14:45:16]
  • 提交

answer

#line 1 "/home/maspy/compro/library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else

// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
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); }
int popcnt_sgn(int x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(ll x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u64 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
// (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>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

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

#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) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  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;
    (check(x) ? ok : ng) = 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;
    (check(x) ? ok : ng) = 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;
}

template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
  vc<T> &res = first;
  (res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "/home/maspy/compro/library/other/io.hpp"
#define FASTIO
#include <unistd.h>

// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
  char num[10000][4];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i][j] = n % 10 | '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
  pil = 0;
  if (pir < SZ) ibuf[pir++] = '\n';
}

inline void flush() {
  fwrite(obuf, 1, por, stdout);
  por = 0;
}

void rd(char &c) {
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
}

void rd(string &x) {
  x.clear();
  char c;
  do {
    if (pil + 1 > pir) load();
    c = ibuf[pil++];
  } while (isspace(c));
  do {
    x += c;
    if (pil == pir) load();
    c = ibuf[pil++];
  } while (!isspace(c));
}

template <typename T>
void rd_real(T &x) {
  string s;
  rd(s);
  x = stod(s);
}

template <typename T>
void rd_integer(T &x) {
  if (pil + 100 > pir) load();
  char c;
  do
    c = ibuf[pil++];
  while (c < '-');
  bool minus = 0;
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (c == '-') { minus = 1, c = ibuf[pil++]; }
  }
  x = 0;
  while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
  if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
    if (minus) x = -x;
  }
}

void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }

template <class T, class U>
void rd(pair<T, U> &p) {
  return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
  if constexpr (N < std::tuple_size<T>::value) {
    auto &x = std::get<N>(t);
    rd(x);
    rd_tuple<N + 1>(t);
  }
}
template <class... T>
void rd(tuple<T...> &tpl) {
  rd_tuple(tpl);
}

template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
  for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
  for (auto &d: x) rd(d);
}

void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
  rd(h), read(t...);
}

void wt(const char c) {
  if (por == SZ) flush();
  obuf[por++] = c;
}
void wt(const string s) {
  for (char c: s) wt(c);
}
void wt(const char *s) {
  size_t len = strlen(s);
  for (size_t i = 0; i < len; i++) wt(s[i]);
}

template <typename T>
void wt_integer(T x) {
  if (por > SZ - 100) flush();
  if (x < 0) { obuf[por++] = '-', x = -x; }
  int outi;
  for (outi = 96; x >= 10000; outi -= 4) {
    memcpy(out + outi, pre.num[x % 10000], 4);
    x /= 10000;
  }
  if (x >= 1000) {
    memcpy(obuf + por, pre.num[x], 4);
    por += 4;
  } else if (x >= 100) {
    memcpy(obuf + por, pre.num[x] + 1, 3);
    por += 3;
  } else if (x >= 10) {
    int q = (x * 103) >> 10;
    obuf[por] = q | '0';
    obuf[por + 1] = (x - q * 10) | '0';
    por += 2;
  } else
    obuf[por++] = x | '0';
  memcpy(obuf + por, out + outi + 4, 96 - outi);
  por += 96 - outi;
}

template <typename T>
void wt_real(T x) {
  ostringstream oss;
  oss << fixed << setprecision(15) << double(x);
  string s = oss.str();
  wt(s);
}

void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first);
  wt(' ');
  wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;

#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define U32(...)   \
  u32 __VA_ARGS__; \
  read(__VA_ARGS__)
#define U64(...)   \
  u64 __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 1 "/home/maspy/compro/library/string/palindromic_tree.hpp"
// palindromic tree を作る
template <int sigma>
struct Palindromic_Tree {
  struct Node {
    array<int, sigma> TO;
    int link;
    int length;
    pair<int, int> pos; // position of first ocurrence
    Node(int link, int length, int l, int r)
        : link(link), length(length), pos({l, r}) {
      fill(all(TO), -1);
    }
  };

  vc<Node> nodes;
  vc<int> path;

  template <typename STRING>
  Palindromic_Tree(const STRING& S, char off) {
    nodes.eb(Node(-1, -1, 0, -1));
    nodes.eb(Node(0, 0, 0, 0));
    int p = 0;
    FOR(i, len(S)) {
      path.eb(p);
      int x = S[i] - off;
      while (p) {
        int j = i - 1 - nodes[p].length;
        bool can = (j >= 0 && S[j] - off == x);
        if (!can) {
          p = nodes[p].link;
          continue;
        }
        break;
      }
      if (nodes[p].TO[x] != -1) {
        p = nodes[p].TO[x];
        continue;
      }
      int to = len(nodes);
      int l = i - 1 - nodes[p].length;
      int r = i + 1;
      nodes[p].TO[x] = to;

      int link;
      if (p == 0) link = 1;
      if (p != 0) {
        while (1) {
          p = nodes[p].link;
          int j = i - 1 - nodes[p].length;
          bool can = (j >= 0 && S[j] - off == x);
          if (can) break;
        }
        assert(nodes[p].TO[x] != -1);
        link = nodes[p].TO[x];
      }
      nodes.eb(Node(link, r - l, l, r));
      p = to;
    }
    path.eb(p);
  }

  // node ごとの出現回数
  vc<int> count() {
    vc<int> res(len(nodes));
    for (auto&& p: path) res[p]++;
    FOR_R(k, 1, len(nodes)) {
      int link = nodes[k].link;
      res[link] += res[k];
    }
    return res;
  }
};
#line 2 "/home/maspy/compro/library/graph/tree.hpp"

#line 2 "/home/maspy/compro/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 {
  static constexpr bool is_directed = directed;
  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; }

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

#ifdef FASTIO
  // 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();
  }
#endif

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

#ifdef FASTIO
  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);
    }
  }
#endif

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

  // G における頂点 V[i] が、新しいグラフで i になるようにする
  // {G, es}
  // sum(deg(v)) の計算量になっていて、
  // 新しいグラフの n+m より大きい可能性があるので注意
  Graph<T, directed> rearrange(vc<int> V, bool keep_eid = 0) {
    if (len(new_idx) != N) new_idx.assign(N, -1);
    int n = len(V);
    FOR(i, n) new_idx[V[i]] = i;
    Graph<T, directed> G(n);
    vc<int> history;
    FOR(i, n) {
      for (auto&& e: (*this)[V[i]]) {
        if (len(used_e) <= e.id) used_e.resize(e.id + 1);
        if (used_e[e.id]) continue;
        int a = e.frm, b = e.to;
        if (new_idx[a] != -1 && new_idx[b] != -1) {
          history.eb(e.id);
          used_e[e.id] = 1;
          int eid = (keep_eid ? e.id : -1);
          G.add(new_idx[a], new_idx[b], e.cost, eid);
        }
      }
    }
    FOR(i, n) new_idx[V[i]] = -1;
    for (auto&& eid: history) used_e[eid] = 0;
    G.build();
    return G;
  }

  Graph<T, true> to_directed_tree(int root = -1) {
    if (root == -1) root = 0;
    assert(!is_directed && prepared && M == N - 1);
    Graph<T, true> G1(N);
    vc<int> par(N, -1);
    auto dfs = [&](auto& dfs, int v) -> void {
      for (auto& e: (*this)[v]) {
        if (e.to == par[v]) continue;
        par[e.to] = v, dfs(dfs, e.to);
      }
    };
    dfs(dfs, root);
    for (auto& e: edges) {
      int a = e.frm, b = e.to;
      if (par[a] == b) swap(a, b);
      assert(par[b] == a);
      G1.add(a, b, e.cost);
    }
    G1.build();
    return G1;
  }

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 4 "/home/maspy/compro/library/graph/tree.hpp"

// HLD euler tour をとっていろいろ。
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 heavy_child(int v) {
    int k = LID[v] + 1;
    if (k == N) return -1;
    int w = V[k];
    return (parent[w] == v ? w : -1);
  }

  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 get_eid(int u, int v) {
    if (parent[u] != v) swap(u, v);
    assert(parent[u] == v);
    return VtoE[u];
  }

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

  // 目標地点へ進む個数が k
  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;
    }
  }

  int meet(int a, int b, int c) { return LCA(a, b) ^ LCA(a, c) ^ LCA(b, c); }
  int lca(int u, int v) { return LCA(u, v); }

  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<int> collect_light(int v) {
    vc<int> res;
    bool skip = true;
    for (auto &&e: G[v])
      if (e.to != parent[v]) {
        if (!skip) res.eb(e.to);
        skip = false;
      }
    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;
  }

  // 辺の列の情報 (frm,to,str)
  // str = "heavy_up", "heavy_down", "light_up", "light_down"
  vc<tuple<int, int, string>> get_path_decomposition_detail(int u, int v) {
    vc<tuple<int, int, string>> up, down;
    while (1) {
      if (head[u] == head[v]) break;
      if (LID[u] < LID[v]) {
        if (v != head[v]) down.eb(head[v], v, "heavy_down"), v = head[v];
        down.eb(parent[v], v, "light_down"), v = parent[v];
      } else {
        if (u != head[u]) up.eb(u, head[u], "heavy_up"), u = head[u];
        up.eb(u, parent[u], "light_up"), u = parent[u];
      }
    }
    if (LID[u] < LID[v]) down.eb(u, v, "heavy_down");
    elif (LID[v] < LID[u]) up.eb(u, v, "heavy_up");
    reverse(all(down));
    concat(up, 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;
  }

  // path [a,b] と [c,d] の交わり. 空ならば {-1,-1}.
  // https://codeforces.com/problemset/problem/500/G
  pair<int, int> path_intersection(int a, int b, int c, int d) {
    int ab = lca(a, b), ac = lca(a, c), ad = lca(a, d);
    int bc = lca(b, c), bd = lca(b, d), cd = lca(c, d);
    int x = ab ^ ac ^ bc, y = ab ^ ad ^ bd; // meet(a,b,c), meet(a,b,d)
    if (x != y) return {x, y};
    int z = ac ^ ad ^ cd;
    if (x != z) x = -1;
    return {x, x};
  }

  // uv path 上で check(v) を満たす最後の v
  // なければ (つまり check(v) が ng )-1
  template <class F>
  int max_path(F check, int u, int v) {
    if (!check(u)) return -1;
    auto pd = get_path_decomposition(u, v, false);
    for (auto [a, b]: pd) {
      if (!check(V[a])) return u;
      if (check(V[b])) {
        u = V[b];
        continue;
      }
      int c = binary_search([&](int c) -> bool { return check(V[c]); }, a, b, 0);
      return V[c];
    }
    return u;
  }
};
#line 2 "/home/maspy/compro/library/string/suffix_array.hpp"

#line 2 "/home/maspy/compro/library/alg/monoid/min.hpp"

template <typename E>
struct Monoid_Min {
  using X = E;
  using value_type = X;
  static constexpr X op(const X &x, const X &y) noexcept { return min(x, y); }
  static constexpr X unit() { return infty<E>; }
  static constexpr bool commute = true;
};
#line 2 "/home/maspy/compro/library/ds/sparse_table/sparse_table.hpp"

// 冪等なモノイドであることを仮定。disjoint sparse table より x 倍高速
template <class Monoid>
struct Sparse_Table {
  using MX = Monoid;
  using X = typename MX::value_type;
  int n, log;
  vvc<X> dat;

  Sparse_Table() {}
  Sparse_Table(int n) { build(n); }
  template <typename F>
  Sparse_Table(int n, F f) {
    build(n, f);
  }
  Sparse_Table(const vc<X>& v) { build(v); }

  void build(int m) {
    build(m, [](int i) -> X { return MX::unit(); });
  }
  void build(const vc<X>& v) {
    build(len(v), [&](int i) -> X { return v[i]; });
  }
  template <typename F>
  void build(int m, F f) {
    n = m, log = 1;
    while ((1 << log) < n) ++log;
    dat.resize(log);
    dat[0].resize(n);
    FOR(i, n) dat[0][i] = f(i);

    FOR(i, log - 1) {
      dat[i + 1].resize(len(dat[i]) - (1 << i));
      FOR(j, len(dat[i]) - (1 << i)) {
        dat[i + 1][j] = MX::op(dat[i][j], dat[i][j + (1 << i)]);
      }
    }
  }

  X prod(int L, int R) {
    if (L == R) return MX::unit();
    if (R == L + 1) return dat[0][L];
    int k = topbit(R - L - 1);
    return MX::op(dat[k][L], dat[k][R - (1 << k)]);
  }

  template <class F>
  int max_right(const F check, int L) {
    assert(0 <= L && L <= n && check(MX::unit()));
    if (L == n) return n;
    int ok = L, ng = n + 1;
    while (ok + 1 < ng) {
      int k = (ok + ng) / 2;
      bool bl = check(prod(L, k));
      if (bl) ok = k;
      if (!bl) ng = k;
    }
    return ok;
  }

  template <class F>
  int min_left(const F check, int R) {
    assert(0 <= R && R <= n && check(MX::unit()));
    if (R == 0) return 0;
    int ok = R, ng = -1;
    while (ng + 1 < ok) {
      int k = (ok + ng) / 2;
      bool bl = check(prod(k, R));
      if (bl) ok = k;
      if (!bl) ng = k;
    }
    return ok;
  }
};
#line 2 "/home/maspy/compro/library/ds/segtree/segtree.hpp"

template <class Monoid>
struct SegTree {
  using MX = Monoid;
  using X = typename MX::value_type;
  using value_type = X;
  vc<X> dat;
  int n, log, size;

  SegTree() {}
  SegTree(int n) { build(n); }
  template <typename F>
  SegTree(int n, F f) {
    build(n, f);
  }
  SegTree(const vc<X>& v) { build(v); }

  void build(int m) {
    build(m, [](int i) -> X { return MX::unit(); });
  }
  void build(const vc<X>& v) {
    build(len(v), [&](int i) -> X { return v[i]; });
  }
  template <typename F>
  void build(int m, F f) {
    n = m, log = 1;
    while ((1 << log) < n) ++log;
    size = 1 << log;
    dat.assign(size << 1, MX::unit());
    FOR(i, n) dat[size + i] = f(i);
    FOR_R(i, 1, size) update(i);
  }

  X get(int i) { return dat[size + i]; }
  vc<X> get_all() { return {dat.begin() + size, dat.begin() + size + n}; }

  void update(int i) { dat[i] = Monoid::op(dat[2 * i], dat[2 * i + 1]); }
  void set(int i, const X& x) {
    assert(i < n);
    dat[i += size] = x;
    while (i >>= 1) update(i);
  }

  void multiply(int i, const X& x) {
    assert(i < n);
    i += size;
    dat[i] = Monoid::op(dat[i], x);
    while (i >>= 1) update(i);
  }

  X prod(int L, int R) {
    assert(0 <= L && L <= R && R <= n);
    X vl = Monoid::unit(), vr = Monoid::unit();
    L += size, R += size;
    while (L < R) {
      if (L & 1) vl = Monoid::op(vl, dat[L++]);
      if (R & 1) vr = Monoid::op(dat[--R], vr);
      L >>= 1, R >>= 1;
    }
    return Monoid::op(vl, vr);
  }

  X prod_all() { return dat[1]; }

  template <class F>
  int max_right(F check, int L) {
    assert(0 <= L && L <= n && check(Monoid::unit()));
    if (L == n) return n;
    L += size;
    X sm = Monoid::unit();
    do {
      while (L % 2 == 0) L >>= 1;
      if (!check(Monoid::op(sm, dat[L]))) {
        while (L < size) {
          L = 2 * L;
          if (check(Monoid::op(sm, dat[L]))) { sm = Monoid::op(sm, dat[L++]); }
        }
        return L - size;
      }
      sm = Monoid::op(sm, dat[L++]);
    } while ((L & -L) != L);
    return n;
  }

  template <class F>
  int min_left(F check, int R) {
    assert(0 <= R && R <= n && check(Monoid::unit()));
    if (R == 0) return 0;
    R += size;
    X sm = Monoid::unit();
    do {
      --R;
      while (R > 1 && (R % 2)) R >>= 1;
      if (!check(Monoid::op(dat[R], sm))) {
        while (R < size) {
          R = 2 * R + 1;
          if (check(Monoid::op(dat[R], sm))) { sm = Monoid::op(dat[R--], sm); }
        }
        return R + 1 - size;
      }
      sm = Monoid::op(dat[R], sm);
    } while ((R & -R) != R);
    return 0;
  }

  // prod_{l<=i<r} A[i xor x]
  X xor_prod(int l, int r, int xor_val) {
    static_assert(Monoid::commute);
    X x = Monoid::unit();
    for (int k = 0; k < log + 1; ++k) {
      if (l >= r) break;
      if (l & 1) { x = Monoid::op(x, dat[(size >> k) + ((l++) ^ xor_val)]); }
      if (r & 1) { x = Monoid::op(x, dat[(size >> k) + ((--r) ^ xor_val)]); }
      l /= 2, r /= 2, xor_val /= 2;
    }
    return x;
  }
};
#line 6 "/home/maspy/compro/library/string/suffix_array.hpp"

// 辞書順 i 番目の suffix が j 文字目始まりであるとき、
// SA[i] = j, ISA[j] = i
// |S|>0 を前提(そうでない場合 dummy 文字を追加して利用せよ)
template <bool USE_SPARSE_TABLE = true>
struct Suffix_Array {
  vc<int> SA;
  vc<int> ISA;
  vc<int> LCP;
  using Mono = Monoid_Min<int>;
  using SegType = conditional_t<USE_SPARSE_TABLE, Sparse_Table<Mono>, SegTree<Mono> >;
  SegType seg;
  bool build_seg;

  Suffix_Array() {}
  Suffix_Array(string& s) {
    build_seg = 0;
    assert(len(s) > 0);
    char first = 127, last = 0;
    for (auto&& c: s) {
      chmin(first, c);
      chmax(last, c);
    }
    SA = calc_suffix_array(s, first, last);
    calc_LCP(s);
  }

  Suffix_Array(vc<int>& s) {
    build_seg = 0;
    assert(len(s) > 0);
    SA = calc_suffix_array(s);
    calc_LCP(s);
  }

  // lcp(S[i:], S[j:])
  int lcp(int i, int j) {
    if (!build_seg) {
      build_seg = true;
      seg.build(LCP);
    }
    int n = len(SA);
    if (i == n || j == n) return 0;
    if (i == j) return n - i;
    i = ISA[i], j = ISA[j];
    if (i > j) swap(i, j);
    return seg.prod(i, j);
  }

  // S[i:] との lcp が n 以上であるような半開区間
  pair<int, int> lcp_range(int i, int n) {
    if (!build_seg) {
      build_seg = true;
      seg.build(LCP);
    }
    i = ISA[i];
    int a = seg.min_left([&](auto e) -> bool { return e >= n; }, i);
    int b = seg.max_right([&](auto e) -> bool { return e >= n; }, i);
    return {a, b + 1};
  }

  // -1: S[L1:R1) < S[L2, R2)
  //  0: S[L1:R1) = S[L2, R2)
  // +1: S[L1:R1) > S[L2, R2)
  int compare(int L1, int R1, int L2, int R2) {
    int n1 = R1 - L1, n2 = R2 - L2;
    int n = lcp(L1, L2);
    if (n == n1 && n == n2) return 0;
    if (n == n1) return -1;
    if (n == n2) return 1;
    return (ISA[L1 + n] > ISA[L2 + n] ? 1 : -1);
  }

private:
  void induced_sort(const vc<int>& vect, int val_range, vc<int>& SA, const vc<bool>& sl, const vc<int>& lms_idx) {
    vc<int> l(val_range, 0), r(val_range, 0);
    for (int c: vect) {
      if (c + 1 < val_range) ++l[c + 1];
      ++r[c];
    }
    partial_sum(l.begin(), l.end(), l.begin());
    partial_sum(r.begin(), r.end(), r.begin());
    fill(SA.begin(), SA.end(), -1);
    for (int i = (int)lms_idx.size() - 1; i >= 0; --i) SA[--r[vect[lms_idx[i]]]] = lms_idx[i];
    for (int i: SA)
      if (i >= 1 && sl[i - 1]) SA[l[vect[i - 1]]++] = i - 1;
    fill(r.begin(), r.end(), 0);
    for (int c: vect) ++r[c];
    partial_sum(r.begin(), r.end(), r.begin());
    for (int k = (int)SA.size() - 1, i = SA[k]; k >= 1; --k, i = SA[k])
      if (i >= 1 && !sl[i - 1]) { SA[--r[vect[i - 1]]] = i - 1; }
  }

  vc<int> SA_IS(const vc<int>& vect, int val_range) {
    const int n = vect.size();
    vc<int> SA(n), lms_idx;
    vc<bool> sl(n);
    sl[n - 1] = false;
    for (int i = n - 2; i >= 0; --i) {
      sl[i] = (vect[i] > vect[i + 1] || (vect[i] == vect[i + 1] && sl[i + 1]));
      if (sl[i] && !sl[i + 1]) lms_idx.push_back(i + 1);
    }
    reverse(lms_idx.begin(), lms_idx.end());
    induced_sort(vect, val_range, SA, sl, lms_idx);
    vc<int> new_lms_idx(lms_idx.size()), lms_vec(lms_idx.size());
    for (int i = 0, k = 0; i < n; ++i)
      if (!sl[SA[i]] && SA[i] >= 1 && sl[SA[i] - 1]) { new_lms_idx[k++] = SA[i]; }
    int cur = 0;
    SA[n - 1] = cur;
    for (size_t k = 1; k < new_lms_idx.size(); ++k) {
      int i = new_lms_idx[k - 1], j = new_lms_idx[k];
      if (vect[i] != vect[j]) {
        SA[j] = ++cur;
        continue;
      }
      bool flag = false;
      for (int a = i + 1, b = j + 1;; ++a, ++b) {
        if (vect[a] != vect[b]) {
          flag = true;
          break;
        }
        if ((!sl[a] && sl[a - 1]) || (!sl[b] && sl[b - 1])) {
          flag = !((!sl[a] && sl[a - 1]) && (!sl[b] && sl[b - 1]));
          break;
        }
      }
      SA[j] = (flag ? ++cur : cur);
    }
    for (size_t i = 0; i < lms_idx.size(); ++i) lms_vec[i] = SA[lms_idx[i]];
    if (cur + 1 < (int)lms_idx.size()) {
      auto lms_SA = SA_IS(lms_vec, cur + 1);
      for (size_t i = 0; i < lms_idx.size(); ++i) { new_lms_idx[i] = lms_idx[lms_SA[i]]; }
    }
    induced_sort(vect, val_range, SA, sl, new_lms_idx);
    return SA;
  }

  vc<int> calc_suffix_array(const string& s, const char first = 'a', const char last = 'z') {
    vc<int> vect(s.size() + 1);
    copy(begin(s), end(s), begin(vect));
    for (auto& x: vect) x -= (int)first - 1;
    vect.back() = 0;
    auto ret = SA_IS(vect, (int)last - (int)first + 2);
    ret.erase(ret.begin());
    return ret;
  }

  vc<int> calc_suffix_array(const vc<int>& s) {
    vc<int> ss = s;
    UNIQUE(ss);

    vc<int> vect(s.size() + 1);
    copy(all(s), vect.begin());
    for (auto& x: vect) x = LB(ss, x) + 1;
    vect.back() = 0;
    auto ret = SA_IS(vect, MAX(vect) + 2);
    ret.erase(ret.begin());
    return ret;
  }

  template <typename STRING>
  void calc_LCP(const STRING& s) {
    int n = s.size(), k = 0;
    ISA.resize(n);
    LCP.resize(n);
    for (int i = 0; i < n; i++) ISA[SA[i]] = i;
    for (int i = 0; i < n; i++, k ? k-- : 0) {
      if (ISA[i] == n - 1) {
        k = 0;
        continue;
      }
      int j = SA[ISA[i] + 1];
      while (i + k < n && j + k < n && s[i + k] == s[j + k]) k++;
      LCP[ISA[i]] = k;
    }
    LCP.resize(n - 1);
  }
};
#line 2 "/home/maspy/compro/library/string/many_string_compare.hpp"

// https://qoj.ac/contest/1803/problem/9406
template <bool USE_SPARSE_TABLE>
struct Many_String_Compare {
  int n;
  string ALL;
  vc<int> pos;
  Suffix_Array<USE_SPARSE_TABLE> X;

  template <typename F>
  Many_String_Compare(int n, F f) : n(n) {
    pos = {0};
    FOR(i, n) {
      ALL += f(i);
      pos.eb(len(ALL));
    }
    X = Suffix_Array<USE_SPARSE_TABLE>(ALL);
  }

  // S[a][la:lb), S[b][lb:rb)
  int lcp(int a, int la, int ra, int b, int lb, int rb) {
    assert(0 <= a && a < n && 0 <= b && b < n);
    assert(0 <= la && la <= ra && ra <= length(a));
    assert(0 <= lb && lb <= rb && rb <= length(b));
    int n = X.lcp(pos[a] + la, pos[b] + lb);
    return min({n, ra - la, rb - lb});
  }

  // [<]-1, [=]0, [>]1
  int comp3(int a, int la, int ra, int b, int lb, int rb) {
    int na = ra - la, nb = rb - lb;
    if (na > nb) return -comp3(b, lb, rb, a, la, ra);
    int n = lcp(a, la, ra, b, lb, rb);
    if (n == na) { return (na == nb ? 0 : -1); }
    return (ALL[pos[a] + la + n] < ALL[pos[b] + lb + n] ? -1 : 1);
  }

  // [<]-1, [=]0, [>]1, (S+T) vs (T+S)
  int ST_TS_comp3(int a, int la, int ra, int b, int lb, int rb) {
    int na = ra - la, nb = rb - lb;
    if (na > nb) return -ST_TS_comp3(b, lb, rb, a, la, ra);
    int k = comp3(a, la, la + na, b, lb, lb + na);
    if (k != 0) return k;
    k = comp3(b, lb, lb + nb - na, b, lb + na, rb);
    if (k != 0) return k;
    return comp3(b, lb + nb - na, rb, a, la, ra);
  }

  int length(int a) { return pos[a + 1] - pos[a]; }
};
#line 7 "main.cpp"

void solve() {
  LL(N);
  STR(S);
  string RS = S;
  reverse(all(RS));
  Palindromic_Tree<26> P1(S, 'a');
  Palindromic_Tree<26> P2(RS, 'a');
  Many_String_Compare<0> X(2, [&](int i) -> string { return (i == 0 ? S : RS); });

  Graph<int, 1> G1(len(P1.nodes));
  Graph<int, 1> G2(len(P2.nodes));
  SHOW(__LINE__);
  FOR(v, 1, G1.N) G1.add(P1.nodes[v].link, v);
  FOR(v, 1, G2.N) G2.add(P2.nodes[v].link, v);
  SHOW(__LINE__);
  G1.build(), G2.build();
  Tree<decltype(G1)> T1(G1);
  Tree<decltype(G2)> T2(G2);
  SHOW(__LINE__);

  auto solve = [&](ll L, ll R) -> void {
    ll n = X.lcp(0, L, R, 1, N - R, N - L);
    if (n == R - L) return print(0, 0);
    vc<pi> ANS;
    {
      // R-n-1 を使う場合
      // R-n-1 を含む最大長回文をとる
      int v = P1.path[R - n];
      v = T1.max_path([&](int v) -> bool { return P1.nodes[v].length <= R - L - 2 * n; }, 0, v);
      int k = P1.nodes[v].length;
      int way = X.lcp(1, N - (R - n - k), N, 1, N - (L + n), N - L) + 1;
      ANS.eb(k + 2 * n, way);
      SHOW(n, k);
    }
    {
      int v = P2.path[N - (L + n)];
      v = T2.max_path([&](int v) -> bool { return P2.nodes[v].length <= R - L - 2 * n; }, 0, v);
      int k = P2.nodes[v].length;
      int way = X.lcp(0, L + n + k, N, 0, R - n, R) + 1;
      ANS.eb(k + 2 * n, way);
      SHOW(n, k);
    }
    for (auto& [a, b]: ANS) a = R - L - a;
    ll ans = infty<int>, cnt = 0;
    for (auto& [a, b]: ANS) {
      if (chmin(ans, a)) cnt = 0;
      if (ans == a) cnt += b;
    }
    print(ans, cnt);
  };

  LL(Q);
  FOR(Q) {
    INT(L, R);
    --L;
    solve(L, R);
  }
}

signed main() { solve(); }

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

詳細信息

Test #1:

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

input:

5 abcca
3
1 5
3 4
3 5

output:

1 1
0 0
1 1

result:

ok 3 lines

Test #2:

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

input:

5 babdb
2
1 4
3 4

output:

1 1
1 2

result:

ok 2 lines

Test #3:

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

input:

50 gqlggjglsqlgjflqflqfwfqqfqqffwfqlfwfqlwgsllsgwlqga
3262
26 32
22 28
10 17
9 28
39 47
14 18
18 35
15 31
22 49
15 21
15 23
12 45
1 49
3 13
18 24
14 23
19 26
21 27
1 46
17 34
23 32
13 26
15 43
39 46
17 28
40 49
14 44
3 37
4 15
20 39
1 17
1 17
1 17
17 34
1 17
1 17
1 17
17 34
1 17
17 34
17 34
1 17
17 ...

output:

2 1
0 0
7 2
13 1
1 1
4 2
17 2
14 1
21 1
6 2
4 1
28 2
35 3
10 2
5 1
5 1
2 2
2 1
38 1
1 2
5 3
11 1
26 2
0 0
5 2
4 2
27 1
34 2
10 1
17 1
16 2
16 2
16 2
1 2
16 2
16 2
16 2
1 2
16 2
1 2
1 2
16 2
1 2
16 2
1 2
1 2
16 2
16 2
1 2
16 2
16 2
16 2
16 2
1 2
1 2
1 2
1 2
16 2
1 2
1 2
16 2
1 2
1 2
16 2
1 2
16 2
1 2...

result:

ok 3262 lines

Test #4:

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

input:

95 fqoywgnlyjyzpyyyszsnsyzpzqldyqlyjdlnqsyzzqzzssszzqzzysqszjylqdlllldzqlyjzsnsyusqzzzsszzsszzzqso
8421
11 89
11 70
41 42
79 94
62 67
37 55
73 90
78 92
4 77
14 16
13 86
36 45
6 21
37 93
16 56
27 72
9 39
73 82
48 80
20 94
63 83
6 85
37 55
20 37
37 55
37 55
20 37
20 37
20 37
37 55
20 37
20 37
37 55
37...

output:

73 1
59 2
1 2
0 0
0 0
0 0
10 3
3 1
69 1
0 0
70 1
9 2
13 1
38 2
38 1
45 2
28 3
5 1
28 1
59 1
17 1
78 1
0 0
17 2
0 0
0 0
17 2
17 2
17 2
0 0
17 2
17 2
0 0
0 0
0 0
17 2
17 2
0 0
17 2
0 0
0 0
17 2
0 0
17 2
17 2
17 2
17 2
0 0
0 0
17 2
17 2
17 2
0 0
17 2
17 2
17 2
0 0
17 2
17 2
0 0
17 2
0 0
17 2
17 2
17 2
...

result:

ok 8421 lines

Test #5:

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

input:

273 byqssdbrubbububbhsrssusdrbbdubbfqrfdsbsqshbbbdsruqfsdusbqbubbsrqssudhrquqrhduhhhbhubbubbsbhrfsfrdsduqbsrsssbdhfqusubhsbudbhubsbfbsbbbrsubbhhsqbudsdubqshhbbusrbbbsbfbsbuhbdubshbusuqfhdbsssrsbqudsdrfsfrhbsbbubbuhbbfbbrdsfrdsddsbbqrfdbubfuhbbbhsbuuddbrbhuhrffqrbbdbqdrqqbfudqs
8827
28 168
33 273
125...

output:

96 1
240 2
61 1
58 1
86 1
94 1
19 2
13 2
171 2
191 1
37 2
33 1
36 1
90 1
13 1
42 2
64 1
95 1
7 1
231 1
193 1
100 1
5 1
111 2
203 2
73 1
5 1
37 1
35 2
34 1
34 1
34 1
34 1
34 1
34 1
34 1
34 1
34 1
34 1
35 2
34 1
34 1
34 1
34 1
35 2
35 2
35 2
34 1
35 2
34 1
35 2
35 2
35 2
34 1
34 1
34 1
34 1
34 1
34 1
...

result:

ok 8827 lines

Test #6:

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

input:

1630 gpdmjhvkfrxglffvjgghhtjujfrktintghhwunzwwufktxvuobnkajinjrkrubtrxfwvverhgkfcxkhpldpalxfwesrwnzjnjggvbtffgtagwmgrbrakjggedtjyhwkjclkyftdtlszfwdsjolwfjbwisftbfxumytlglgeaemklejwjytwhadqjwstzmqfzrfnyjmnhhkrmnsaabkgffggmazoemaznnwkrwjzajwgkftkhsbswmrytnnljynfkzjjwzrstlqdjwnfyawreltmeaeglkjtymafffgl...

output:

388 2
300 1
806 1
13 2
518 1
1079 2
570 2
759 2
440 2
701 1
0 0
6 1
1019 1
28 1
930 2
575 2
36 1
647 1
455 1
156 2
188 2
1151 1
252 2
1281 2
218 2
423 1
423 2
318 1
1053 2
366 2
754 1
1110 1
197 2
144 1
266 1
537 2
644 2
180 2
808 2
1274 1
133 1
271 1
1014 2
366 1
498 2
855 2
108 2
199 2
201 1
475 1...

result:

ok 64835 lines

Test #7:

score: 0
Accepted
time: 151ms
memory: 49068kb

input:

242681 nuvwtjlknjuypqzgbbkqljrojspjdoiesidzihlfiouurvgykdvvwyonssgajdkcobgyezfmetbjbrhiuveczngqjgbndmqwckapzuoborgyoixplzxpmptqpfdkokdpjuagixkjurccreyaaeyvpduutxqsmvtgtlfeugbvxmnmtfjxqnnvnkzcqacpwqsfjwlpfuemheleqlfzdqnrmvnnqifrtugyikhdlmwxtjalxexfdusvzqfecsyyrcnxrvgkjjkilvaqjiylbxlrfktnlxunnwjdftvxw...

output:

83044 1
37882 2
216157 2
48382 1
10896 2
176055 2
105310 2
155181 2
81628 1
18757 2
43985 1
18517 1
77084 1
60712 1
60844 1
3686 1
28003 1
16940 1
109452 1
227172 2
19371 1
74520 1
205350 2
9148 2
36108 2
56490 2
213082 2
36744 2
33340 1
64057 1
50728 2
4440 2
9544 2
38310 2
50945 2
7694 2
95347 1
9...

result:

ok 108152 lines

Test #8:

score: 0
Accepted
time: 64ms
memory: 31676kb

input:

180103 qwfrakvhsdleaugctbpvricopqgvnlrehvkpwerwmuxmcvievsfwckmdgferkwupuclsppcwkrrmkphflwsrobnphvfblplpqoriniddagiamlmbueympfijmexgjqodqpzzmxqvkvdturtgryppbojfhdiwmqllanylzqpmirzykccrwclylcejxejnnfmilusxgkouzikivzjgdmlsjtpogssfflroagwzrxxaroxernwhgknnlyoiuiplpkeagxqdsjfmabgmxfwjrdwalkydubsuilywjopqx...

output:

36 2
23992 2
62392 1
9269 1
34734 2
85369 2
20691 2
1030 1
83979 1
123117 2
89661 2
155084 2
10317 1
1934 1
12145 2
4175 2
47274 1
35439 1
96980 2
72256 1
25986 1
41548 1
818 2
11184 1
24031 2
45793 1
14250 2
89381 2
17294 1
84621 1
40414 2
55400 1
8323 2
25646 2
714 2
32042 1
58243 1
77992 1
18882 ...

result:

ok 37053 lines

Test #9:

score: 0
Accepted
time: 128ms
memory: 18000kb

input:

73372 mehadcsrhwawmxbxvvxifuynioutljndybapfdksfdeveztcckdskevoszwwnsgddzdtfwgkutzxnyfvxreojsuihgikqzevlcucghiwsfrgkzeqtsqirlpmmotugmcyfyvvuzupctonsrhjjyvzqqngeclnzrufmkfponiuqhccufaoeultlwnqkzwtvirzkznvjmpmhuhabjumdzbcwzqkednbftjezuhhpsdrjoixuodbnylovfouqosbhsloyzzvfmbemghgucwbzskhijtnkcxpwwudheiqya...

output:

1460 2
12675 1
40437 1
43220 1
8004 2
19049 1
28796 1
63645 2
39662 2
3277 2
16125 2
1570 1
11919 1
34196 1
9732 2
6417 2
17545 1
23590 2
47081 2
31666 2
7006 2
12116 1
42893 1
3318 1
55561 1
7436 1
5446 1
149 2
5348 2
16859 1
13004 1
22913 2
11114 1
4882 2
13019 1
3067 1
44996 1
9517 2
16829 2
2719...

result:

ok 224618 lines

Test #10:

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

input:

186088 bxwcogtrxvazjmagnlvigjzocjrleehmugtdsfwqfyqtgyvakswmwdulujtikjwawswnbmjpzhrsfnocciwuvhnnkekjkftskwokihunshpelsagdtwphczbdjzrjxhgygatpziuukhzjgqjjoalgrzmozauezjnbpljzqllkeognywybodbhfnjpksvwikpgcxpjrrjxhmhszlezdwouaeuxtgpupbhlmtwdjyrwuxgxzonmsunmryapxnuoicapisawessxbvdwrwqlafdabnsihkhlxgszuobj...

output:

18108 1
32696 2
30914 2
119897 2
31752 1
75298 2
78498 1
42110 2
143396 1
1132 2
163178 2
4096 2
948 1
56404 1
68376 1
10237 2
94467 1
101883 1
8666 1
151812 2
74144 2
66102 1
72213 2
4053 2
16411 1
27608 1
15003 2
176714 2
62891 2
78697 2
20178 2
94239 1
75452 2
2379 2
118246 2
4684 2
58526 1
51779...

result:

ok 172922 lines

Test #11:

score: 0
Accepted
time: 197ms
memory: 34568kb

input:

186410 ojchhvgbrjsztaoafyjhyfqggvmvjzwrtwnmogssbntvkvqhhtwzasnvndmqpchuvqqevtlobrornktvmemunbmyhvvjyhlcrvlwbqtvqgdpzlrdnclxcxkizmhxjxldaloqoitfndvkhnwfemqmvjlsjzuxhrofhhnmugqcreurwdbsqbuqnfcajnpdftlntmjfeviiaebjkcwxnszstwyjnhwegcltalytuksezobgotzonpibxrnajrxxcrcmhxacyxhghbmlbgeccfgetgorsokiutfnvbium...

output:

16856 1
71655 2
83151 1
2075 2
3199 1
90981 1
51907 1
20486 1
41939 1
4637 1
8199 2
61726 2
38456 1
56904 1
21357 1
33586 1
15873 2
40636 1
17730 1
83981 2
19237 2
39632 1
35226 1
9114 1
39309 1
67049 1
3720 2
82968 1
50575 2
34133 2
4566 2
15440 2
31468 2
7908 1
37504 1
76914 1
17951 1
5141 2
55150...

result:

ok 219919 lines

Test #12:

score: 0
Accepted
time: 71ms
memory: 35992kb

input:

219911 emslzelqkdqnfzzpqymsagwiidrlsycvfxfnayhtswbmguhobocnxgbifwqmtjdfvfqbjimptekcnuornjajduukeixeheuzncviysiijtlngtggedpcgdmdeakwwuxjvgccbhxqfzbtxitfqvuktfwfpduwozrbbsshrdnwfvqmsewgifgocchkxpylnpwqiqxgoiqdhrgxjwdgebmljhvreclzavaggsltebavidgvtwkbyzafxoyyxwnczpfdbasqcugbsfauaaqpwhgybnqtkywiutudrxwrk...

output:

1910 1
57927 2
0 0
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4758 1
4...

result:

ok 111910 lines

Test #13:

score: 0
Accepted
time: 153ms
memory: 10268kb

input:

27591 qoamkvpkhebzvrlmbrhtyobcauixphhughiosaymkjwgvzeleiihphqjljdyxwmauixecqirqvgdkggnrouvmsknplfyqzupozdogbjhlvtmhhipthoohtkuefvevjtonyaxkkvaydtckbfswhbowtwgoiwrmriodgzdzbbgzuvmcxsxhkkmrxbomuovbfrudedgcgpnthijskseiuswhsjqchnmxxaiyjmwluhlybvrhlsdejiqlqswbalxrslxsfmtzpshngxrudibpxqrisgveoyhczmydkxvym...

output:

2337 2
11280 1
2120 1
7631 1
15249 1
12389 1
2491 1
701 1
12413 2
4742 1
3119 1
3845 1
241 1
2242 1
2976 2
1942 1
17140 2
9309 2
319 1
2487 1
9295 1
7747 2
1566 2
343 1
2848 2
16762 2
1031 2
8117 2
1280 1
6269 2
3941 1
11367 1
678 1
5591 2
9710 1
4459 1
11616 1
2066 2
2380 1
4209 2
6821 1
6895 1
286...

result:

ok 246741 lines

Test #14:

score: 0
Accepted
time: 169ms
memory: 82692kb

input:

341125 bjqwhatbyjvcngipxliiyuijsjrjxwzthvhjchimmogzhyzzljdbbczxodxncpyynadfkjvjbbbsaixetwghtrkltyulbzpgjkaapbfiifelylfchmucgvqnzotpttltvvmykzqnsoecbjxauzebuveqfzkboboqagcispceyymhalospakelzhefprccpyjhwwwituaikrtdejyfpvxnmzpubeeddtiutlombedfkiqkytygyhejqmxzfuzhsnjqtakbcofgmfiemkmgzklqowgtaaqfmscgqypj...

output:

42658 2
24213 2
46758 2
40638 2
35799 2
21163 1
30618 1
79653 2
64601 2
37538 2
29919 1
72152 1
66691 2
27081 1
31116 1
304408 1
25602 1
60614 2
122304 1
101913 2
14577 1
51665 1
65739 1
33235 1
91654 1
60465 2
7624 2
110716 1
23286 2
19248 2
30402 1
136250 1
19871 1
51645 1
287756 2
23703 1
27572 2...

result:

ok 254470 lines

Test #15:

score: 0
Accepted
time: 152ms
memory: 58288kb

input:

230956 ickghckqwfctpfezebvddraiypwzfkwowntqjvzoggowxcsvdjfqyohfijsmarguyitysnqbxfqlqbedbezmshickgoeiqnonxobfakhlzkllytezozcnjcclrhuscvdyickhagzoszoioylpsaliembknmhsufbttnnxqskmjavhjdfcnjqjkgszavgpiothnhqxptqjptzplbefpbiqkbaqjnqqjsedcspqimscrnbqxvlerdjkgamyvzpcedkemfedghtbgcsshufuntyrqgjzdhlostohexdx...

output:

26052 1
71434 1
1169 2
38032 1
3940 2
97505 1
37638 2
98861 1
9927 2
72459 1
34568 1
59872 2
3180 1
43380 1
15059 1
87580 1
4370 1
10425 2
32180 2
24344 1
14788 2
70666 1
66862 2
10455 1
32939 1
66572 2
76295 1
16250 2
131590 2
54251 2
92669 2
32912 1
74600 1
90259 2
4324 1
105051 1
11870 1
67918 1
...

result:

ok 270570 lines

Test #16:

score: 0
Accepted
time: 84ms
memory: 35696kb

input:

186071 aurostviurvtoiqoypigphfzrikzcgkmeaxyfcacrfgfjydrrvkdceqtytiltlmsbdrzladsefbgsvvrzlfabpdxkdooihngxhvfqonavyudmrebnmzueivszflrtjskbtxfgtjozblqizihgrqfmmlhyzfxwuqcdockhovkktwzlafxsppkbixemorifpukqynsdhnipgsasthpdwpdyomtuwqrxpcudgwaeipvkjootitghgtixekeobafapvunnipfohipbyygnfvinxtjjjxbczaeylzyxkrh...

output:

34423 1
12829 1
59438 2
35421 1
12255 1
100163 2
41577 2
6774 2
14807 2
104600 2
59322 2
54175 1
46155 1
18036 1
6280 2
10689 2
44895 2
36330 1
829 2
75255 2
14503 2
18365 1
10852 2
90978 1
124489 2
34974 2
54825 1
39876 1
11946 1
141883 2
3108 1
51119 2
120937 2
49211 2
1419 2
28253 1
29689 1
67478...

result:

ok 220760 lines

Test #17:

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

input:

883 uwxjjnxwxyycekwnxjswwvckkijydwykkyknzjxdinwjynwnwyxnkxjkjjkkxksknivknknkwnfwkjkvvekkjkwwjjjnkwxwjxkeejnxyevxzkxkycyekwzyxjjxywnwssxjvnsxjijkywvjsjnwvvknkjwnnjkkxkfvxwxxkxscsnikwwijjwxnwjswnwyzwwuxyykknjsskjkywvzsjkwusvxwwxuwkkkjwwvjjwsknsywxxkxwkxwwnxyjvkkwnksckxwwzvxjjwxknjsjkjkywfzsjkwusjxxkww...

output:

303 1
193 1
81 2
273 1
73 1
413 2
325 5
283 1
580 1
805 2
275 1
272 2
369 2
104 1
6 2
55 1
121 2
119 2
189 1
790 1
84 1
47 2
270 2
26 2
92 1
0 0
291 1
471 2
147 2
72 1
207 1
124 2
226 2
611 2
73 5
118 1
470 2
451 1
8 1
458 2
815 2
79 1
154 2
451 2
208 1
12 1
18 1
207 4
44 1
854 2
76 2
624 2
293 1
16...

result:

ok 982 lines

Test #18:

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

input:

472761 envwahmuzbjgpbfooqveovgpgcbaizookxzjbsvolqobhgqooppxqyogfkravafjbmpphmuhaspqzbveokgmvmtrvreydvzhnrobjhedpjmlimhhlxflunicljgdbflupeixutyijzgxbogqqmfsiuedrmiahzgrkoakxkizltpebontmiwodbcdgiyontejtuhddqtwwbqeumzlzxdhkxrwrviobkgqjzqxiyktgglrzzybxfzzyphawcgyxrtzofhjtsatadktznxndnpkbbpnjzbgbovpebpjh...

output:

42945 2
57333 2
33037 2
17593 1
3640 2
283278 1
235 1
145834 2
24727 1
62907 1
34843 1
8435 2
209632 2
111930 2
165564 1
27460 2
107039 1
57323 2
42421 1
66110 2
25508 2
50677 2
46223 2
224524 2
244787 2
52728 1
16379 1
12113 1
327854 1
154852 1
14554 2
107947 1
120597 1
29922 1
75243 2
67854 1
6966...

result:

ok 316350 lines

Test #19:

score: 0
Accepted
time: 79ms
memory: 4656kb

input:

7581 nhxypwhnsvffyndvpcyikdwvbojfjoklrglgfauutedxurmtbbvbmmfblzosjtgyjxgczcwknxvkmubwabdkbiekjgiislyyprxpuhzozaaxvomyfxvypwtkaxwlbimniknzddkluevaqojgewnnbiicykokqytknohbzcczgziwyzjhvqbwikoejuqwankwnzatneuvfifyzvfokjyifdjkpghjhtjoqyuvaznibylhsounbogylainkhujrwiwbyonhkykhonkuqnwjxaboukftykzjddwwoaxpbo...

output:

3512 1
2504 2
140 2
3722 1
1516 2
2471 1
4092 1
4304 1
597 2
448 1
1357 2
1789 2
4747 1
2260 2
20 2
2518 2
2628 2
6316 2
304 1
877 1
1804 1
0 0
6341 1
199 1
5509 1
1583 2
1918 2
3976 1
2679 1
5595 1
3104 2
3809 1
6466 1
6410 1
258 2
894 2
3365 2
1636 2
5163 2
80 2
215 1
2743 2
4962 2
3452 2
965 1
35...

result:

ok 393809 lines

Test #20:

score: 0
Accepted
time: 457ms
memory: 100352kb

input:

467766 mxuayezmqogeshfzwafkdxcltkyqtypxsnpvkxjwtomllsfhbxirmxrbmyyqmwdnkkmweutzdxvkmjuoaloiaopqpgvvydtqsvyovwukjhiwlxszkeohdlyjcdqrzickzoukctdoezzdaclzilbvkavparigpqiatjtkhnigsijkgdxiaudxmbrxpdeipsottlivhxsolknqfiaicdpaykilqhiswtmjsflihogbrjjabzhnsyoafmstrsgcxpgwrttmyhkozzmgaasjvdhuuchgamfmxlfbbcetl...

output:

172804 1
54153 1
70896 1
196364 1
36793 2
123989 2
88131 2
116327 2
82036 2
35156 1
58359 1
199524 2
152120 2
4471 2
26955 1
113717 1
43725 1
3478 1
76277 1
33067 2
153326 2
129770 1
60717 2
193455 1
17709 2
58766 1
87199 2
131308 1
48512 2
52995 2
215092 2
129085 2
213267 2
102490 2
116165 1
18889 ...

result:

ok 388654 lines

Test #21:

score: 0
Accepted
time: 201ms
memory: 96620kb

input:

490464 ltdcgjjalpmgvzoknpjnxypjmedcdmaicpgkwvbmocnssmhmgqfjerpalxhnkuizvpnjstnvukzutxipujwbodmgsxbtpgjngvcloguvrfbbhglbbyeczeytfaonjvpqutmbutcsrdvnknoeafrkewolovuzzjwytknjbjldmzjzgkxgvzaqhewmczglyrderennzatgxtazuijqgsfraiqzfbcnuuieclunezelsviekdgwquslfyhazwjbtwxohxemnpsunrbeehwilrspwijbspcchxgecwfmq...

output:

142827 2
22589 2
190886 2
90982 1
4054 2
71858 2
6821 2
52417 1
162855 1
21524 1
46855 2
200940 1
27630 1
200902 1
1373 1
156336 1
208478 1
197279 1
166654 1
29822 2
4359 2
103054 1
52243 1
148247 1
278767 1
399145 2
97331 1
1291 2
134796 2
156632 1
106598 1
7107 1
141123 2
133845 2
114029 2
70057 1...

result:

ok 269116 lines

Test #22:

score: 0
Accepted
time: 444ms
memory: 105472kb

input:

425242 vzsfinkepzcxiqiwutuqebzzixujmgesgipzyvpldkcsemypikjkofofdqkrqgwwdybjorhzdtdrjllsjvrovgrcvbcvwgwnbatlocohpxeithfsxsuuzjuxlpxwmprcixrirqeuwukadsmbttgewbfxancxpcfnpqwtclblzayuxtodaqzrnsffyjshhllcrcuwuhizyfsbiyxevgnswoluhmrzsyuetyqyyrfhwhomzdviizvfpvdjslankliasgoczaynnigvdenubndrzrnwafdmsutpaiagj...

output:

63325 1
196071 1
24390 1
213585 2
71814 1
12851 1
104957 1
20309 1
39446 1
167041 1
37453 2
252872 1
17358 2
24770 1
231991 1
53193 1
156609 2
4639 1
69098 1
273174 1
85829 1
126147 1
19273 2
77581 2
14335 1
160418 1
28264 1
10924 1
132290 1
107880 1
47783 1
60076 1
1261 2
128806 1
167946 1
132126 1...

result:

ok 303077 lines

Test #23:

score: 0
Accepted
time: 182ms
memory: 75860kb

input:

454707 vwbyukoygoqqrigcfszkipbdbzjzyttdzskqtqlcpbgthriyjeossefveqawvtqmxafdtcfsmzencamtbzgpvuaiomnytsldtnmqyiyapzjyqwsmikkdzdwabupkoemlmufpukkqludgltwfmguyaxlhxqsgzafkplcsdrrzuvokwlcafaqcxrwoqekrquvltxhmurnjubdpxwqiestyuxfzczmcfwgswepvnobukiqgccvdtsjwzryaszihgrnontqxrkvpcrnrraqnsfycttlmgqasqxzomgwrg...

output:

128697 1
122598 2
254911 1
20413 2
62351 1
197560 3
55270 1
118182 2
51929 2
275074 2
3345 1
121324 2
19046 2
10571 1
143485 1
178154 2
40683 1
102973 1
110924 1
49711 1
113492 2
24565 2
179580 1
57191 1
50743 2
30440 1
191559 2
238898 2
96727 1
3338 2
81109 2
146811 1
92114 2
31328 2
137044 1
37068...

result:

ok 319866 lines

Test #24:

score: 0
Accepted
time: 180ms
memory: 58532kb

input:

428928 vzgfzwrlobbigranxhmtgswspagsapxvebdexhntjvoltdjafhhcgkobvrxtsyrjnjmbtwpaqtbwxmqjicohrcxxxwoguggqowvmzrssafyyxqfgkslldcztzzpqjzqnxyqedqxqnnaxrbedchyciebnzudpypnfrfvzvhwrktucmtduopyhaglqevkphglkasbtgfbbdqjgxdplijajihtuttfukbbjirumyyuxnitwyjilyrelfrbducmaugzrgkewxcwktzcsrnkjulkbaondlaxibbleivowg...

output:

118116 2
303426 1
158523 1
5363 2
96434 2
108531 2
57265 2
78273 1
39897 2
52883 2
196420 2
167452 2
159055 1
178369 2
68989 1
0 0
38920 2
72320 3
133357 1
50610 2
126369 1
22656 3
319666 2
70959 2
50519 2
2753 2
90361 1
103184 2
139908 1
191361 2
3929 1
45672 1
39900 2
36241 2
103404 2
39655 1
7987...

result:

ok 373485 lines

Test #25:

score: 0
Accepted
time: 389ms
memory: 65240kb

input:

314262 mbdjwwfvzqaspeoiexlqxmrlyuoolnnkidvdglszjlgzolwbdnhubckcvsztafntbjxswxmvmrvtxpaperptfcntgvbjtyakjxvyaoqiamxizuwqorsgdprxrseresikqbjlsyrnomnrnojekvidktavpiraattgcfsmlzcffbnmzjyvyziodlifsgnlrzlkkcwunfgfwuvpjqrpcqqjagrxbglfguhsnprjxeuushsefcbybntjprjttvfroeqiutqtnwgcvqldllccqufjevxnplevqmegozcxw...

output:

154418 2
16960 1
103408 2
77635 1
201145 1
148788 2
13123 1
171110 1
115337 2
146478 1
25566 2
26141 1
3881 1
31902 1
213972 1
25530 2
125052 1
65575 2
126216 2
142989 1
178707 2
290957 2
64379 1
215579 1
2987 1
109457 2
6756 2
79774 2
60621 2
129094 2
149523 1
57649 1
2200 2
132753 1
58773 2
38075 ...

result:

ok 372975 lines

Test #26:

score: 0
Accepted
time: 423ms
memory: 69676kb

input:

473345 yssaokzadzdzwpxlvavmrsuuwhovysvtcwhabnurlbpavlhpmzxdfbuavqykcpdkbawwnuhoadbektfvjfsdxmeiabdbicqabwsrdcxrwonsitbugmmgomhyrhtidxxqssqgxnfyvowfpzdmnshsilbeucnrgwlymndpbcvuprpteagixtfdlkwdqzydhnisvhsftcbagzxksdoizbzlisqrsrblxxcqraxdboiuoahjsvvqnavubfsmtvnctnfyilvbwuyuycntboikpynyfqyltslpyrqkufpdy...

output:

26045 2
92986 2
131091 2
98180 1
169157 2
169756 1
291875 1
176714 2
8839 2
173234 1
156976 2
5856 1
225621 2
54482 1
55314 1
260577 1
264562 1
267898 1
46760 2
79964 1
169773 1
160589 2
240762 2
48240 2
52291 2
248942 2
71062 2
170830 2
38396 1
206871 2
62246 1
230237 2
250690 1
107169 1
97001 1
21...

result:

ok 382491 lines

Test #27:

score: 0
Accepted
time: 211ms
memory: 64468kb

input:

466710 dwginluwtgjslxqrozdqemoxtlujcqzptsweddoefrtfmnnyhtvllwgzgfdskoztqirvqlcbaiynfvpwgpnnyyjvfcbjbyaphyxhuxkyobnhefulkudwlqexrjokdihkezvwleapgmitgcdlvfzacwofjgyhvgijhgpcviqcqzjxhweydxcxsbkljylktfvthsrhyyboomrotqrmdxexhbkwcvqwffemtipafzcxwycstjbijbptvkxufqjfyweptlfboctrgbolfogwvqghixsnucmhsjinlpcif...

output:

139129 1
320780 2
50556 1
168598 1
221315 2
260545 2
299464 2
43913 1
241072 1
50187 1
2843 2
5810 1
286808 1
106766 1
28411 1
52637 1
207829 1
52713 1
19630 1
4863 2
49190 1
126306 1
128787 1
179698 1
138097 2
81942 1
69844 2
7513 1
7117 1
433683 2
51537 1
75520 2
90833 1
234279 2
67468 1
124997 1
...

result:

ok 355378 lines

Test #28:

score: 0
Accepted
time: 176ms
memory: 4644kb

input:

2872 hahahahahahahaaaahhhaahhhhaahaahahhahahhaahhhhhhhhhhhahhahahaaaaahahahhahhaahhaaaaahhhhahahhahhahahahaahaahhhahahhhahaahhhahaaahhhhhahahhaahhhahhaaahhhahahhahahahhahhahahhhhhahahhhahhhhhhaahhahhhhahhhaahahhhahhhhhahhaahaaahhhhhhhhhaaahhhahhhahaahhaaahaahhahhaaahahaaahahaaahhhahhhhhhaahhhhahhhha...

output:

95 1
1697 1
291 1
240 1
224 6
766 1
2 1
1861 5
771 1
859 2
855 1
1177 2
623 1
196 2
1113 2
444 2
14 1
409 5
516 1
2433 1
138 2
561 2
1784 1
252 1
964 1
333 1
389 1
1846 2
1934 3
76 1
971 1
438 3
1761 2
911 1
165 1
433 3
647 1
733 2
66 1
2447 1
582 1
117 2
866 1
1581 1
417 1
592 1
1196 1
634 1
1276 1...

result:

ok 350131 lines

Test #29:

score: 0
Accepted
time: 198ms
memory: 4632kb

input:

4757 zyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyyyzzzyzzyyzyzzzyzzzzyyzyzyzzzzyyzyzyzyzyzyyzzyzyzyzzyzyyzyzyzzyzzyzyzyzyzyyyyzzyzyzyzyzzzyyyyzzyzzyyyzzyzzzzzyzyyzyyzyzzzyzyzzyzzzyyyyzzyyyzyyyyyyzyyyzzzzzyzyzzyyzzzyzyzyyzyzzyyyzzyzyzzzyzyyzyzzzyyzzzyyyyzyzyyyyyyyyzzyzzzyzzzzzyyzzyzzyzzzzyzyzzzyyyzyyyy...

output:

1831 1
3162 2
975 1
594 1
1588 1
2359 1
1134 1
0 0
30 3
2470 3
1047 1
4111 1
398 3
688 2
1984 2
1353 1
2070 2
1211 1
1586 1
525 1
1223 2
773 1
180 2
49 4
1180 2
498 1
384 5
4287 2
313 1
151 1
1 1
1340 2
642 1
388 7
894 1
1845 1
505 4
2686 1
78 2
1032 2
0 0
273 2
1402 2
253 1
378 1
308 1
2230 2
273 1...

result:

ok 379636 lines

Test #30:

score: 0
Accepted
time: 213ms
memory: 4564kb

input:

7581 nhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnhnnhhnhnhhhnhhhnnhnnnnhnnnnnnnhnhnhnnhhhhhhnhnnnnnhhhhhnnnnhhnhhnnnnhhhhnnhhhnnhhnhhhnnnnnhnhnnhhhhhnnnnhhhhnnnnnhnnnhnnhnnnhhnnnnhnnhhhnnhnhhnnhhhhhhhnhnhhhhhhnhnhhhhnnhnnnnhnhnhhnhnnnnhhnnnnnnnhnhnnnnnhnhnnhnhnnnhhhhnhnnnhnnhnnhnnnhnn...

output:

6495 2
1340 1
1169 2
1780 5
5972 1
3712 2
1082 1
149 1
2392 1
1001 3
95 2
2201 3
79 5
732 1
1234 1
608 2
849 3
1628 2
3014 2
977 1
2198 3
1859 1
1224 2
1185 1
2431 1
1472 1
2509 1
2878 1
573 2
287 3
467 3
926 1
5441 2
5216 1
3133 1
885 2
527 1
1218 1
2965 1
85 2
562 2
908 2
4325 1
5380 1
6463 3
767 ...

result:

ok 393809 lines

Test #31:

score: 0
Accepted
time: 321ms
memory: 25568kb

input:

85669 kakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakakaka...

output:

20535 1
19105 5
55139 1
6481 2
1895 1
16337 1
11263 6
8777 2
19422 1
2511 2
31189 3
38864 1
14580 3
9373 5
21583 1
1771 1
1860 1
6374 1
8148 2
28259 1
16758 2
7574 1
33 2
12236 1
7942 1
44077 8
7278 4
27231 2
16719 7
15133 1
929 1
1327 1
75214 1
11131 2
11824 1
6196 1
3012 1
36032 3
403 1
64015 2
38...

result:

ok 386442 lines

Test #32:

score: 0
Accepted
time: 504ms
memory: 77344kb

input:

467766 mxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxmxm...

output:

88624 1
68899 1
99970 1
4509 1
104737 1
94922 2
228678 2
72099 2
179105 2
46773 1
233751 2
63799 1
148929 4
23755 2
84195 1
32691 5
38650 7
36139 4
37167 1
98245 3
1395 1
63589 3
53793 1
94090 1
100458 1
48951 1
95325 2
226595 2
1592 1
141733 1
162326 4
59236 1
142415 3
212166 1
214788 2
32652 1
406...

result:

ok 388654 lines

Test #33:

score: 0
Accepted
time: 473ms
memory: 88340kb

input:

450567 hyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhhhyhyhyhhyyhyhhhyhhyhhyhyhhhyhhhyyyyyyyhyyyhhhyhyhhhhhyyhhyyyhhyyyyhyhyyhhyhyhhhhhyhyhyhyyhyyhhhhyyhyhhhhhyhyyyhyyyhyhyhyhhhhhyyyyyyyhhhhyyhyyyhyyhh...

output:

302958 4
97887 1
127813 3
349731 1
106088 1
75378 4
21284 1
121929 1
10130 2
48360 1
174006 2
50549 1
31560 1
66023 1
21149 3
169644 1
88434 1
169395 3
134729 4
44873 3
325361 1
19140 1
45870 2
32067 2
241152 3
61742 1
241947 1
184679 4
91347 1
152526 1
79672 1
104727 2
109516 2
32589 3
7264 1
11703...

result:

ok 370071 lines

Test #34:

score: 0
Accepted
time: 451ms
memory: 74552kb

input:

461960 jljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljljlj...

output:

287122 1
163230 3
19723 1
27559 5
62982 1
65519 1
78361 1
123221 1
161099 2
25551 1
164906 1
385812 1
19084 1
34177 1
4442 1
103644 4
210038 1
174290 3
26924 1
353410 1
227084 2
65224 1
327957 2
146285 1
48927 1
73154 1
114518 1
8384 1
174287 1
60060 2
150394 3
86736 1
87524 2
244212 1
29715 2
71969...

result:

ok 337620 lines

Test #35:

score: 0
Accepted
time: 534ms
memory: 102268kb

input:

493783 cycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycycyyycycycccycycccycycycycccycycyccyycyyycycccyccycyycccccycycycycycyyycyyycycycycccccycycycycycyyyccyyyycccycycycycyccyycycyyycycycyyyyyyyycy...

output:

128958 1
156145 1
213180 2
158382 1
48447 2
41664 1
242677 1
301386 1
7713 1
129486 2
63871 4
169260 1
180052 2
159428 1
36482 1
246069 3
196037 3
46331 3
252091 3
209772 1
222837 2
148441 2
324660 1
20588 8
304283 2
11720 2
174830 2
195118 1
178272 1
248569 1
129640 1
165936 2
139075 1
135828 1
249...

result:

ok 393100 lines

Test #36:

score: 0
Accepted
time: 360ms
memory: 74360kb

input:

490464 ltltltltltltltltltltltltltltltltltltltltltltltltltltltltltltltltltltltltltlltltttlttltltltltttltlllltlltttllltltltltllltllttlltlllltltltltltttltllltttltltlllllttttttltltltltlttllltltltltltltttltltltltltltltltllltltltltttltltltlttlllltltlttlllttttltttltltltltttltltltltllttttltltltltltltltltttl...

output:

17548 1
116890 3
385602 1
345670 2
33425 1
92526 1
119395 1
232165 1
149810 4
183022 1
129199 2
342393 2
151044 6
175603 2
49376 1
133004 1
72635 3
155059 3
215433 1
286654 3
125654 4
408193 1
454073 1
295591 3
304190 2
236094 1
60719 1
29490 1
282931 1
88562 2
88360 2
227458 2
91466 1
455609 1
3519...

result:

ok 269116 lines

Test #37:

score: 0
Accepted
time: 420ms
memory: 87268kb

input:

454707 vwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwvwv...

output:

47810 1
12653 1
302693 1
160385 1
1234 1
310372 1
259678 1
42119 3
163219 1
19776 1
358317 1
236581 1
68051 3
320587 1
254829 2
124480 1
111143 3
157130 1
70799 1
242816 1
198952 1
18363 1
117936 1
11187 1
36209 1
23923 2
168100 1
227405 2
74272 1
30095 1
72129 1
15742 1
57879 3
1742 5
128447 2
4168...

result:

ok 319866 lines

Test #38:

score: 0
Accepted
time: 389ms
memory: 48392kb

input:

225793 bqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbqbbbqbbbbbqqbqqqqqqbqbqbqbbqbbqbqbqbqbbbqbbbqbqbbbqbqbbbqbqqqbqqbbqqqbqbqqqqqbqqqbqbqbbqqbqbqbqbqbqqqbqqqbbbqqqqbbbbqbqbqqqqqbqqqbqbqbqbbbqqqbqqqbbqqbqbqbqbbbqqqbqbqbbbqqqqqqqbqbqqqbqbbbqbqbqbbbbbqqqbqbqb...

output:

28426 3
70215 1
897 2
71507 1
9085 1
54948 1
5607 2
47856 2
56916 2
35019 1
15386 1
132056 1
57047 1
46334 1
42943 2
109717 1
25530 4
16670 1
9809 1
26325 2
147477 3
13802 1
63226 7
32984 1
49195 2
46491 2
36956 6
12770 1
53868 1
21935 2
43645 1
117480 2
89195 1
80398 3
1866 2
28153 3
150129 1
17172...

result:

ok 373671 lines

Test #39:

score: 0
Accepted
time: 1314ms
memory: 206136kb

input:

467766 rlnhpbwjlywapfaasbaoszkozanjrsandukghcrykhkqdkhbselyricojkfzklkkzlkxuxuzhbqcwufbixdqnznhfafegxzuaekgrabikukzjtazpidchjpvmflmkiemadaxkmjdjpekzvwjqdkwawryazicokzzzbbdpcehbpprezhofuzqvqdkkrmjkkdztayrwjgpkcuyeaylmyyzlabcxcyvuvrgafybbkbhnyokmduubbabauwxolzqzkaaytkfqojbnlziezcykkhbcfwhgbboegtcpixqc...

output:

357 1
240 1
602 1
86 1
137 1
465 1
232 1
427 1
101 1
418 1
414 1
427 1
133 1
253 1
579 1
579 1
121 1
483 1
614 1
123 1
219 1
377 1
499 1
303 2
177 1
209 1
588 1
128 1
424 1
558 1
303 1
103 1
608 1
446 1
337 1
464 1
342 1
69 1
567 1
366 1
21 1
558 1
365 1
294 1
510 1
67 1
60 1
127 1
351 1
601 1
468 1...

result:

ok 388654 lines

Test #40:

score: 0
Accepted
time: 1295ms
memory: 198224kb

input:

450567 oopiyxxvkcjzazlcdsyajkbiycnzahgyeygafdknmkkixdsfyuzndzrgccdoccwaxjnpbyrbhynjxlqzjgrghupgkfbtzxfovmyansuvndugmetvazcafsbayuyjrkwtvauzkixkyespychhtiwksimfknqgbzbvkbreyguknpaafdzpvbyezophrtkxbawqcwbksxbippabepgjbkxumqobaqknxqmqbcplbdnzafrgneoidskzyardohfulyuvbrchvnvybwnowvzgbapwvvatcsyihtnayknkb...

output:

314 1
17 1
7 1
287 1
322 1
254 1
154 2
151 1
66 1
158 1
393 1
66 1
135 1
374 1
140 1
17 1
172 1
77 1
2 1
195 2
16 1
217 1
107 1
49 1
232 1
344 2
60 1
339 1
366 1
120 1
404 2
351 1
148 1
345 1
139 1
315 1
14 1
304 1
55 1
204 1
196 1
226 1
111 1
328 1
77 1
379 1
278 1
186 1
396 1
375 1
185 1
229 1
132...

result:

ok 370071 lines

Test #41:

score: 0
Accepted
time: 1133ms
memory: 204160kb

input:

461960 daaavyrgmdokkybatocvzlufnzswcwrchvaxzpjibaclehygywaxdakcbamywqhksrjhkzzeakkwhwlhaaajwkqorzcnbjrnlloyaealylkabqegvltmxuflkthfeyfnbijokmjfhykblzhufjijmhdgmykkmiskbyzyqsvleavkbhmykymbzbwgyfzyobevyqvxeqbyyipkxnydirftagybguzclalvzzzwxayybrlbskmamwkdbaaollzkipsyxvvgyasamcmvazwqmdbznaodlrakkvfkaagvq...

output:

432 1
243 1
125 1
86 1
364 1
153 1
446 1
105 1
463 1
108 1
299 1
294 1
265 1
207 1
142 1
204 1
423 1
51 1
446 1
83 1
229 1
69 1
447 1
256 1
299 2
226 1
344 1
117 1
430 1
381 1
297 1
99 1
261 1
295 1
245 1
365 1
317 1
386 1
363 1
385 1
422 1
328 2
268 1
95 1
403 1
203 1
252 1
413 1
283 1
441 1
243 1
...

result:

ok 337620 lines

Test #42:

score: 0
Accepted
time: 1360ms
memory: 214388kb

input:

493783 ovivpzoedyyjkwrbvkrtiiwkozfzztpprgtwikrzsiefvtbwizyjytrbaakufuaosztydoesxxmaqiblagaexysgjsztwyunmstfrrxibbjhehyzqetkkzkypkxtzcbbprbctbklydyrckrkfxeeeknpbtnvhoefyzoqyyzawvmtsqysozubwubdkwzacjhuxgrpsznwptazayicaacbvgdbhkihdqntslxqtowtayxvkoazqjqokqsvbayetpyancqjwmlwgbubsymqaxuhrpatcmgzppataltmh...

output:

398 2
418 1
80 1
77 1
213 1
318 1
170 1
385 1
363 1
100 1
42 1
281 1
455 1
318 1
64 1
315 1
458 1
113 1
339 1
403 1
287 1
67 1
120 1
22 1
225 1
158 1
278 1
425 2
384 1
247 1
244 1
359 1
69 1
42 1
371 1
184 1
196 1
79 2
31 3
354 1
62 1
337 1
228 2
2 1
445 1
64 1
164 1
428 1
417 1
10 1
16 1
191 1
316 ...

result:

ok 393100 lines

Test #43:

score: 0
Accepted
time: 1219ms
memory: 195892kb

input:

436409 xkabeithdpbcihaxracbaweybahlkrbpjcbwbkuwtjrcualbouzgsckgzazyflxhmkgauawkvsmawojbwpbafnakbaehptatbzwbuaflyafmsccsduygixbyxokvbwtkkgeeooujkdbdugabvncbkhdalecbkufadaeyybkxhgwynsytjhavgkwdxjyykyuyfygdsjyekikzhavhdubkrbnwicpnzdskwmtamrzboknbwszibkbbekboqkljurhryyvcfofrmnezamzrdxkchkkkiitvaxxlikubx...

output:

307 1
79 1
217 1
36 1
356 1
139 2
46 1
151 1
240 1
240 1
96 1
20 1
98 1
157 1
324 1
72 1
31 1
56 1
228 1
202 1
275 1
366 1
392 1
390 1
272 1
83 1
161 1
244 1
219 1
231 1
232 1
303 1
373 1
247 1
217 1
118 1
141 1
349 1
47 1
49 1
0 0
23 1
405 1
139 1
152 1
403 1
313 1
59 1
313 1
282 1
129 1
376 1
249 ...

result:

ok 355325 lines

Test #44:

score: 0
Accepted
time: 1034ms
memory: 215176kb

input:

490464 kzyqauaymvyotgfesamhymskzbbvsqikkravgiavcekkenbkmqaniyheyybqlkmydvvjtdbykbmkbjsuqpwnqldbwzdssstpcxpwhgubsirmcakkapmofahvvodsznkezyalzzktfghhmkykqaynpnxtrzqpbiyjwczamdzjumzjojbbpwwujfytkrhatkdhwcktyyqqececobgoyywguohizvckiblfenowywjklbknxylhgkejahlnnndbqglgarydkbqedpxknxcnzgdivybvmxkqyxmkbbyja...

output:

280 2
282 1
33 1
243 1
243 1
99 1
113 1
168 1
103 1
240 1
174 1
318 1
62 1
366 1
202 1
152 1
213 1
253 1
67 1
161 1
357 1
366 1
85 1
162 1
154 1
202 2
153 1
308 1
19 1
208 1
199 1
175 1
153 1
20 1
259 1
175 1
138 1
38 1
154 1
84 1
16 1
29 1
233 1
61 1
98 1
144 1
23 1
92 1
245 1
282 1
317 2
23 1
96 1...

result:

ok 269116 lines

Test #45:

score: 0
Accepted
time: 728ms
memory: 210236kb

input:

479116 wiqvdcqkezvxqihvwbodnwgjqkcaljhysgyyyzfbsfhozwxxbrdwfxlblpybvqvgqjzevhynbypsfumtjcdyivbzdiqxlawzvxrcfmrpbhxrwiakyrsbkakpadthqjkmkmwuqauafxzczjvaarcmazustduyrzyueymdklqmlqhitzolghxyyexgbgulrhirbvqwsbsyzxhqdhksujmjvqrfacyjeacbkkamuhldjbadyigawgkfyjzhxlbtyrdolsxipnttarpvzpqsegqtotazbbqeobbzsnrok...

output:

106 2
20 1
157 2
341 1
276 1
271 1
348 1
157 1
38 1
146 1
12 1
252 1
19 1
126 1
335 2
349 1
85 2
281 1
23 1
194 1
18 1
240 1
31 1
146 1
13 1
153 1
179 1
229 1
214 1
307 1
243 1
243 1
226 1
298 1
95 1
186 1
335 1
189 1
197 1
78 1
54 1
176 1
67 1
96 1
168 1
19 1
79 1
281 1
236 1
77 1
351 1
191 1
114 1...

result:

ok 191647 lines

Test #46:

score: 0
Accepted
time: 1485ms
memory: 215728kb

input:

497017 bnovpukiikrazkdyubolyaqiztoyiceahfkcvezymaqemkiarknusseycmgraabcyorbpbfbeyxacbxxayayqblxtfbbexnbbiibikhdjfcykbrqabyrrjvdnblyzbciybyxaarjqpvnybdxanfzncitocclakcobazzrmqbwkcwkbuakvbxabekqmybnkkttkknbymqkebaxbvkaubkwckwbqmrzzabockalccoticnzfnaxdbynvpqjraaxybyicbzylbndvjrrybaqrbkycfjdhkibiibbnxeb...

output:

49 2
147 1
158 1
52 1
11 1
77 1
143 1
49 1
107 1
90 1
79 1
100 1
58 1
96 1
67 1
96 1
66 1
156 1
167 1
43 1
117 1
44 1
55 1
161 1
185 1
98 1
113 1
152 1
32 1
52 1
109 1
117 1
115 1
7 1
5 1
71 1
85 1
149 1
117 1
47 1
12 1
188 1
99 1
56 1
47 1
153 1
59 1
162 1
33 1
128 1
116 1
45 1
132 1
132 1
91 1
28 ...

result:

ok 398270 lines

Test #47:

score: 0
Accepted
time: 1291ms
memory: 191276kb

input:

428928 egaqxqxzkablqpcjexywkrpbprvuhtpukhkqvkeyhtsoeaxndrjlsjkgjabpicbuzuzqbyoqykmudrnqmzguicabihrbrirbfkyycthknnzgaendlmdiuvfcmbbtrcbvkeztrwxgflvgfwimtkoxebmokwzjyleuyimlnkycjuwdgzicxlznzfktzuwmpaaxakwbhqndeekoyffpoqldhnmqjklcmdedpvlqkjpzfizxjvnxixkqbcsayencsdtpvelzeljznmfoxwdpucktwagaotxodznkkyuks...

output:

1 1
87 1
36 1
247 1
163 1
200 1
264 1
228 1
83 1
34 2
143 1
52 1
97 1
158 1
88 1
127 1
229 1
238 1
323 1
45 1
328 1
157 1
198 1
120 1
254 1
208 1
265 1
237 1
151 1
140 1
126 1
173 1
176 1
63 1
86 2
140 1
248 2
338 1
65 1
342 1
318 1
190 1
137 1
151 1
272 1
106 1
282 1
194 1
95 1
196 1
135 1
159 1
88...

result:

ok 373485 lines

Test #48:

score: 0
Accepted
time: 1677ms
memory: 215692kb

input:

496121 ukyhzlkuxbfewvyojdexruirflzcyojxyiyzazbnqqamkxjxzhqglacfoxajrhaqazynzssznyzaqahrjaxofcalgqhzxjxkmaqqnbzazyiyxjoyczlfriurxedjoyvwefbxuklzhykuukyhzlkuxbfewvyojdexruirflzcyojxyiyzazbnqqamkxjxzhqglacfoxajrhaqazynzssznyzaqahrjaxofcalgqhzxjxkmaqqnbzazyiyxjoyczlfriurxedjoyvwefbxuklzhykuukyhzlkuxbfew...

output:

27 2
42 1
16 1
39 1
43 1
62 1
60 1
46 1
34 1
59 1
32 1
11 1
18 1
15 1
58 1
16 1
48 1
15 1
40 1
43 1
69 1
0 0
69 1
30 1
69 1
69 1
56 1
29 1
25 1
5 1
8 1
14 1
53 1
20 1
59 1
0 0
51 1
39 1
2 1
54 1
61 1
69 1
10 1
38 1
32 1
44 1
42 1
26 2
22 1
55 1
66 1
52 1
30 1
12 1
63 1
19 1
44 1
20 1
15 1
22 1
13 1
...

result:

ok 371154 lines

Test #49:

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

input:

474987 jwnjmvfuxldgdpywzdrheociakvdxfvjmmwyuoiveblxurzrqvetqidgjsnrthwunoapjsusmxtaueljoigheszqsitpisdvmrktmmeqpavnwlnmczxabgphadghhudazcrfnmdokdgavetopuabyypedweoytzsjfltzzucilwmgstxzfmaovakkkkhanagibtqvwzhsdvpqipxtxjgfctmcstjurgjunmltrdwrxcllxjslcofceqgqbunuskqynrhrrhaxpzqeknqfqolqyyrzpqxgrznkqajl...

output:

175157 1
190919 1
225612 1
94989 2
26227 2
89225 2
405926 1
38145 2
119572 1
34388 1
74688 2
356074 1
179262 2
101110 2
0 0
58512 1
174856 1
47974 2
42055 2
245418 2
68369 1
253045 1
53299 1
109144 1
1176 2
167400 1
99944 1
222341 1

result:

ok 28 lines

Extra Test:

score: 0
Extra Test Passed