QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642977#8334. GenemaspyAC ✓1093ms146232kbC++2028.8kb2024-10-15 17:27:352024-10-15 17:27:56

Judging History

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

  • [2024-10-15 17:27:56]
  • 评测
  • 测评结果:AC
  • 用时:1093ms
  • 内存:146232kb
  • [2024-10-15 17:27:35]
  • 提交

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_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(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>
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 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, SegTree<Mono>, Sparse_Table<Mono>>;
  SegType seg;
  bool build_seg;

  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/random/base.hpp"

u64 RNG_64() {
  static uint64_t x_
      = uint64_t(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count()) * 10150724397891781847ULL;
  x_ ^= x_ << 7;
  return x_ ^= x_ >> 9;
}

u64 RNG(u64 lim) { return RNG_64() % lim; }

ll RNG(ll l, ll r) { return l + RNG_64() % (r - l); }
#line 2 "/home/maspy/compro/library/mod/modint61.hpp"

struct modint61 {
  static constexpr u64 mod = (1ULL << 61) - 1;
  u64 val;
  constexpr modint61() : val(0ULL) {}
  constexpr modint61(u32 x) : val(x) {}
  constexpr modint61(u64 x) : val(x % mod) {}
  constexpr modint61(int x) : val((x < 0) ? (x + static_cast<ll>(mod)) : x) {}
  constexpr modint61(ll x) : val(((x %= static_cast<ll>(mod)) < 0) ? (x + static_cast<ll>(mod)) : x) {}
  static constexpr u64 get_mod() { return mod; }

  modint61 &operator+=(const modint61 &a) {
    val = ((val += a.val) >= mod) ? (val - mod) : val;
    return *this;
  }
  modint61 &operator-=(const modint61 &a) {
    val = ((val -= a.val) >= mod) ? (val + mod) : val;
    return *this;
  }
  modint61 &operator*=(const modint61 &a) {
    const unsigned __int128 y = static_cast<unsigned __int128>(val) * a.val;
    val = (y >> 61) + (y & mod);
    val = (val >= mod) ? (val - mod) : val;
    return *this;
  }
  modint61 operator-() const { return modint61(val ? mod - val : u64(0)); }
  modint61 &operator/=(const modint61 &a) { return (*this *= a.inverse()); }
  modint61 operator+(const modint61 &p) const { return modint61(*this) += p; }
  modint61 operator-(const modint61 &p) const { return modint61(*this) -= p; }
  modint61 operator*(const modint61 &p) const { return modint61(*this) *= p; }
  modint61 operator/(const modint61 &p) const { return modint61(*this) /= p; }
  bool operator<(const modint61 &other) const { return val < other.val; }
  bool operator==(const modint61 &p) const { return val == p.val; }
  bool operator!=(const modint61 &p) const { return val != p.val; }
  modint61 inverse() const {
    ll a = val, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b), swap(u -= t * v, v);
    }
    return modint61(u);
  }
  modint61 pow(ll n) const {
    assert(n >= 0);
    modint61 ret(1), mul(val);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul, n >>= 1;
    }
    return ret;
  }
};

#ifdef FASTIO
void rd(modint61 &x) {
  fastio::rd(x.val);
  assert(0 <= x.val && x.val < modint61::mod);
}

void wt(modint61 x) { fastio::wt(x.val); }
#endif
#line 4 "/home/maspy/compro/library/string/rollinghash.hpp"

struct RollingHash {
  using mint = modint61;
  static constexpr u64 mod = mint::get_mod();
  const mint base;
  vc<mint> power;

  static inline mint generate_base() { return RNG(mod); }

  inline void expand(size_t sz) {
    if (power.size() < sz + 1) {
      int pre_sz = (int)power.size();
      power.resize(sz + 1);
      FOR(i, pre_sz - 1, sz) power[i + 1] = power[i] * base;
    }
  }

  explicit RollingHash(mint base = generate_base()) : base(base), power{1} {}

  template <typename STRING>
  vector<mint> build(const STRING& s) const {
    int sz = s.size();
    vector<mint> hashed(sz + 1, mint(0));
    for (int i = 0; i < sz; i++) { hashed[i + 1] = hashed[i] * base + s[i]; }
    return hashed;
  }

  template <typename STRING>
  mint eval(STRING& s) {
    mint x = 0;
    for (auto& ch: s) x = base * x + ch;
    return x;
  }

  mint query(const vc<mint>& s, int l, int r) {
    assert(0 <= l && l <= r && r < len(s));
    expand(r - l);
    return (s[r] - s[l] * power[r - l]);
  }

  mint combine(mint h1, mint h2, int h2len) {
    expand(h2len);
    return h1 * power[h2len] + h2;
  }

  mint add_char(mint h, int x) { return h * base + mint(x); }

  int lcp(const vc<mint>& a, int l1, int r1, const vc<mint>& b, int l2,
          int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = 0, high = len + 1;
    while (high - low > 1) {
      int mid = (low + high) / 2;
      if (query(a, l1, l1 + mid) == query(b, l2, l2 + mid))
        low = mid;
      else
        high = mid;
    }
    return low;
  }
};
#line 6 "main.cpp"

void solve() {
  LL(N, Q, M, K);
  RollingHash RH;
  vvc<modint61> dat(N);
  FOR(i, N) {
    STR(S);
    dat[i] = RH.build(S);
  }

  auto check = [&](vc<modint61>& A, vc<modint61>& B) -> bool {
    int p = 0;
    int k = 0;
    while (p < M) {
      int n = RH.lcp(A, p, M, B, p, M);
      p += n;
      if (p == M) return 1;
      ++p, ++k;
      if (k > K) return 0;
    }
    return 1;
  };

  FOR(q, N, N + Q) {
    STR(S);
    auto SH = RH.build(S);
    ll ANS = 0;
    FOR(i, N) ANS += check(SH, dat[i]);
    print(ANS);
  }
}

signed main() { solve(); }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 4 4 1
kaki
kika
manu
nana
tepu
tero
kaka
mana
teri
anan

output:

2
2
1
0

result:

ok 4 number(s): "2 2 1 0"

Test #2:

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

input:

8 6 7 3
delphis
aduncus
peronii
plumbea
clymene
hectori
griseus
electra
delphis
helpiii
perphii
clumeee
eleelea
ddlpcus

output:

1
1
2
2
1
2

result:

ok 6 numbers

Test #3:

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

input:

300 300 9 10
dmzampmxe
bteaudaxb
fjfwhhsfq
btnfzqtyp
ijjrkbyht
hkizlvgdc
ukwsnhiff
hacsdrwyl
fbjabnhst
ktsxbgbtg
jopdbsdsr
yxdxxjltd
daechsouq
klrglgwbn
llzhqzlor
ckdedutfn
lkjxcryoe
zvusjevtz
cevrcdltg
tdmmvvpkj
davfsweem
spcfhcitm
aohsfqrqh
lblehevpj
soaqryimp
tbxlulxmn
tnlzbkhda
ukfhjykuk
eghpuua...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #4:

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

input:

300 300 10 10
qoecfhznxd
hkoaiunzim
lhtzdmbrjs
vqesfzpiuv
amsgqjxmbq
vptwyshswk
sofrfmsrpf
eplnexhmoh
gcjtqavjga
azytravylz
akpuemdfpq
oxkacujrhg
bsgieguzuo
bojvtfkbdf
pmqmrbceej
zgpfkqfeyx
qkdbfrxqcj
effpkigdcw
kqyqmgjdzr
czlbscrnaq
rymhkenugz
fuybclhlhj
rtmclsdvwy
rhfbfqfrfs
bpemthjxfi
jtcvqyltgj
...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #5:

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

input:

300 300 11 10
lonodhfyrbj
njzuczzviuj
usovdmjfjco
bljtnmsjhut
kkkeybjagck
tbuivwfvjit
qhjzqocsvod
ayobjbagcgv
dudupzsvqpe
tcapottzyte
wdevxapvocr
hsvdfaahndr
jjplhydycgn
srrtpmqmygw
gjjbcchwcur
uivvuqldryj
amlidxfsobz
ofpnwqrzhly
eolqcyidojx
jpiybuplwcf
jmxxtjnwsru
ivkbixrgnph
txjjppqkxgu
vmmbwxmvjd...

output:

96
109
114
108
108
95
108
109
113
106
104
94
111
108
95
107
91
99
111
101
105
116
117
109
106
115
116
96
108
95
114
87
94
116
95
97
104
107
91
103
103
92
115
103
120
102
115
103
101
105
108
95
118
106
91
98
99
115
101
106
120
91
118
91
111
99
104
101
104
96
98
116
111
110
107
118
94
96
103
107
108
1...

result:

ok 300 numbers

Test #6:

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

input:

300 300 11 10
bacdccbdbba
ccabcddcbdc
ddbcccadbab
cbdcabcddbd
ccddbaacaba
addabdbbcba
ccbcbadadac
cbadacadcbb
abddacbcada
ccccbdccdda
dadcbdbddda
acbdccdbcdc
bbbbdbcdcbc
cdcbabdacda
acbcdaaadbc
dccbdcddcca
abbacddccba
cccabdcacda
ddcadbabbca
babaaabbabd
dabdaacaddc
cabcacbdcda
cdbbbdcddcd
cdbdccadda...

output:

287
292
286
279
286
285
289
289
294
284
287
291
287
286
283
275
284
291
289
289
286
291
287
282
290
282
278
288
285
285
285
289
287
283
287
290
287
288
292
288
286
290
290
288
289
285
289
276
286
289
283
279
288
288
288
289
289
286
281
288
291
290
287
289
285
280
289
287
286
295
284
285
286
279
284
...

result:

ok 300 numbers

Test #7:

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

input:

300 300 15 10
bbjbbbjbjbbjjbb
bbjbbbbjbjjjbbb
jbjjjjbjbbjbjbb
bbjjjbjbbjbbjbb
bjbjjjbbbbbbbbb
bjbjbjjjbjjjjjj
bbbjjbbjjjbjjjb
bjbbjbjbjbjjjjj
bbbbbjbjjjjbjbj
bbbjbbbbjbjjjjb
jjjbbbbbbbjjbbj
jbbjjjbbbbjbjbb
bjjbbjbjbjbjjjj
bbjbbjbjbjjbbbb
jbjjjjbbbbjjjbj
bbbbjbbbbbjjbjj
jbjbjjbbjjbjjjb
jjbjbjjbbbjjjj...

output:

279
285
291
281
283
277
281
280
282
280
286
290
279
281
279
286
279
281
279
284
283
279
288
276
288
285
285
278
283
281
284
279
286
283
273
286
286
282
282
288
289
275
279
280
286
288
274
273
280
288
280
283
280
280
285
282
277
282
284
280
284
282
291
280
283
280
288
288
287
275
275
286
286
284
281
...

result:

ok 300 numbers

Test #8:

score: 0
Accepted
time: 1093ms
memory: 146220kb

input:

300 300 59999 10
qfsnaxtgssrzcvtxmwamjekdujnlymqklnmmwqpgmqljtgtgcitmjkinsdsjijxjtxrvhqjxupgryqcyatbjjzvcosvynyyaohyeqkrrqlbwsabqtkbwtkgnyadcpwwqswkokpkjblkfyrdeugvpvzefduxwtxzdnqvflsagkfwtowcjuseqqzbgrnxapdpvnuiwexirodxtmenhmvyafucenakdqwjfsepgawzpfqozzybdbkqoxyverfgtrezznsvwpjeeiahjcaatwbsuoyxwpwi...

output:

64
273
300
273
273
273
273
273
273
65
273
273
273
300
273
273
273
273
273
273
300
273
300
273
273
300
273
273
300
273
300
273
273
273
273
273
273
273
64
273
273
300
300
300
273
273
273
300
273
273
273
273
273
300
273
273
273
273
273
300
273
300
273
273
273
273
273
300
273
273
273
64
273
273
273
300
...

result:

ok 300 numbers

Test #9:

score: 0
Accepted
time: 718ms
memory: 146168kb

input:

300 300 59999 10
babaabaabaaabaaaaabababbaababaaaaaabbbaaaabbaabaaaaaabbbbaabababbababbbaaababbabbbbbbbabbbababbbaabaabababbaabbaaaaaaaaabbbabaabbbbabbaaaaaaabaaaaaabaababbbbbbaabaabbabbaabaabbababaabbbbababbababaabbbaaabaabbaabbabbbababaabaababbabbaabababbbabbbaaaabbabbaaababbbbabaaaaabaabaabababab...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #10:

score: 0
Accepted
time: 695ms
memory: 146152kb

input:

300 300 59999 10
wtpztrxbnxeihtzgttybyxpwbsmyzhnibzorarfdzxvsuiytuiiifhctldytuohbvaupbruquctkeqdqcndnmxzimfclecziabjjtaesllwvqandvdbhlzsrdescchpdqoexaezbshcxejszirsmxgsbotsbdtiqgfpymgtqgdtkfboxcphrklwkekyqexhzxrqcpbfaxnlgmptkgfrlytprkoemfvtbycrsdbsaaszenmfhxqqpfmgpdsjpxxmnwqijaewraeudenylcbqxsoinodb...

output:

81
113
124
113
90
77
77
24
90
81
113
124
90
81
95
90
90
77
113
81
90
81
124
90
17
90
113
81
124
77
77
113
113
77
113
113
90
77
77
81
113
17
90
113
90
90
77
90
113
90
113
77
81
26
77
77
17
77
17
113
77
90
81
77
113
113
77
77
95
90
95
90
77
77
113
113
77
113
113
113
77
77
77
77
26
113
90
90
90
17
113
...

result:

ok 300 numbers

Test #11:

score: 0
Accepted
time: 540ms
memory: 146136kb

input:

300 300 59999 10
ababbaabababaabbbaaaaaabbaabaaabbbabbabaabaaabaabbaabbaababbaaaaaabbbabaaaaabbabbbabaaabbaabbbaabaaabbaabbbbaabbbbaabbabaabaaaaaaabbbabbbbbbaaabbbaaaabbbbaabaaaabbababaabaabbabbabbaababbaaababbababbbbbaabbaababbbbbabbbabbabaabbaababaaaaababbabababbbbbbaaababaabababbbabaabbbaababbaba...

output:

103
90
90
90
107
90
90
90
103
90
90
90
103
103
90
90
103
103
103
107
103
90
107
90
90
90
90
107
90
107
103
90
103
90
103
103
103
90
90
107
107
90
103
107
103
90
107
90
107
90
90
90
90
107
107
103
107
107
107
107
107
103
103
107
103
103
107
103
90
107
107
107
90
107
107
90
90
107
90
103
103
90
103
10...

result:

ok 300 numbers

Test #12:

score: 0
Accepted
time: 1050ms
memory: 145976kb

input:

300 300 60000 10
qwmeswhflnhpcirmcbnzvigulddilgacwmvswkaetusbfovamttbiozrwcrxzokfasvqrhnfdgamijzewcyhvkuozvzdmilytwhuarifjexybgxwenfchjlyfgihzfsjwukjoykpbokmcwexpdbermfbtrnciohadqqjnkpxpkljolyhcoenpsainzdduyuqydqagwayzulxzezcszojoejipzcbnubxlizuumhpfkixzzndadcsydiukfdjnereffjtrzvxvlfqrlxseygkpcrpdxp...

output:

274
274
274
274
274
300
274
274
274
274
274
274
274
274
83
300
274
274
274
274
274
274
300
274
83
274
274
83
300
300
274
83
84
274
300
83
83
300
300
300
274
300
300
83
300
274
274
300
274
274
300
83
300
274
300
274
274
274
274
274
300
300
274
300
300
300
274
274
274
274
274
300
274
274
300
300
274
2...

result:

ok 300 numbers

Test #13:

score: 0
Accepted
time: 633ms
memory: 146192kb

input:

300 300 60000 10
aaabbabaabbaabaabbbababbbaaabaabbbaabbabbaabaabaabbbbbabababaabbbaabaababaabaabbbbaaaabbabbabaaabbabaaaaaabaaaaaabaaaaaaabaaaabaaabaaaabbabbababbbbbbaaabbabaaabaababababaabbbbbbaabaabbbbaaabbbbaaabbabbababbbaabbabbbabaaababbaaabbbbababbaaabbabbabbaaaabbbbaaabababaaabbaabbaabbbababbb...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #14:

score: 0
Accepted
time: 590ms
memory: 145976kb

input:

300 300 60000 10
tahicjckhhguvaibfsthlsmydftjkfpscpsbdejidhewfwclhfsdtliucwlpeinadhdcbdhlexiqsziirwfgbijhpmafsxfbqvrnzmsgkwheizrixhbdaqgndxxgpxgzrwaaggdzhtydqjxhpsjhthjffarxzoumayiuifevscyugoihqlzpntvhyxyxeicgbaxbcdtsjpekgtngklxidjwawoxdpaofjujpyvhkzgdxdtzgjtmgejyhnctmocwpajtbzkjcuxhjqkllxuuqlwzbjzz...

output:

82
94
99
99
25
82
94
94
82
82
94
93
99
82
94
103
82
94
99
94
99
103
99
99
94
94
82
99
94
82
94
82
104
99
99
82
104
94
82
94
103
82
94
94
99
82
104
82
94
94
99
93
22
94
25
104
99
99
103
99
99
93
82
99
23
94
104
82
104
94
94
99
104
94
93
82
94
82
93
99
104
94
94
82
82
82
104
94
82
22
104
94
103
103
99...

result:

ok 300 numbers

Test #15:

score: 0
Accepted
time: 542ms
memory: 146044kb

input:

300 300 60000 10
bbbaaaaabbabbaabbbbbbbbbabaabaabaaababaaaaaaaaababbaaabbbabbabbbbaaababbbababbbbbbaaaabbabaaaaababbaaababbbabbabbbbbaaabbabbabbbbbaaaaabbabbabbbbbbbabbbabbababaaabbabbbaabbbababbabaabbaabbbbabaabaabbbababbaababaabbbbbaabbababbaabaaaabbbabbbabababaaabaaababbbababbbbaaaaababaaabbaabbb...

output:

97
105
98
105
98
97
105
97
98
97
97
98
105
97
98
97
98
98
98
98
97
105
98
98
105
105
97
98
105
97
98
98
105
98
98
98
105
105
97
98
97
97
105
97
98
98
97
105
97
98
98
97
105
95
97
98
98
97
105
98
105
98
105
98
105
98
105
97
98
105
97
97
98
105
98
98
98
105
105
105
105
105
105
105
98
98
97
105
98
105
...

result:

ok 300 numbers

Test #16:

score: 0
Accepted
time: 832ms
memory: 146036kb

input:

300 300 59999 10
auezscbdnvtievwoosbklpysvboobnmqlapatvlsryiblmtdkeqslklwyoythxeyqqndjvzxqtueiusersufjnjbdtkokkuerhdrgwwpsqbuexagvkdtsjdmuopveansntfoowhhgcrtwaskhsxqwousfkqjmucahcsrcmcofcgkmseuombrlfgpglxsvkqbhkhsppqmkgzngwlotuwkxgnwlwhzeqjokzmivcihwvktlvlsiedadlhpeesrwkbzrqakahhwqcfqorobynlqgxeotyj...

output:

15
8
9
6
10
8
9
8
7
7
5
6
11
8
6
7
8
9
5
6
7
4
9
8
7
5
5
7
3
9
11
10
13
6
10
9
6
9
5
9
6
6
6
8
8
6
10
9
6
12
7
10
11
5
8
7
6
5
12
8
7
8
6
5
10
3
9
9
6
10
6
13
8
5
7
7
5
11
9
12
7
7
11
7
7
10
9
7
9
7
11
10
7
8
12
4
10
10
8
12
8
11
6
10
7
9
12
8
7
8
6
11
7
7
10
7
7
13
6
10
5
9
9
12
9
6
7
9
8
6
12
8
9
...

result:

ok 300 numbers

Test #17:

score: 0
Accepted
time: 776ms
memory: 145964kb

input:

300 300 59999 10
abbbaabbbbbbabababbaaabbaaaaaaaabbbaababaaabbbaabbbbbaaabaabaabbbbbbbbabbbbaaabbbabbaabbaabaaaaaaaaaabaaabbabaaababaaababbbbaaabbaabababbbaaababaaabbaaababaaaababbbbaaaaaabbbaaaaabbaabaaabbbabbabbabbabababaabbabbaaaaaabbaabbaabaaabbaabababaabbbaabbbbbbbbbaaabaaaabbbabababbbaabbabaab...

output:

277
271
271
269
288
280
269
288
271
286
278
280
283
273
283
272
285
280
275
276
282
278
271
286
258
276
278
287
271
290
287
282
288
280
287
286
290
272
283
291
278
288
288
282
286
267
275
274
278
288
268
292
280
283
289
275
283
295
291
283
291
280
291
267
269
271
276
270
264
282
285
271
279
286
291
...

result:

ok 300 numbers

Test #18:

score: 0
Accepted
time: 663ms
memory: 146112kb

input:

300 300 59999 10
bbaaababbbaaaabbbababaabbabbaababababbabbabbaaababaabbaabaaaabbbabbaaabaaaabaababbbbbaabbbbababaaaaaaaabbbbbbabaaababbbbbaabbbbbababbbbbaabbbabaaaabbbbaaabbbbbabbbbaaaabbaabbbaabbaaabbbbaabbbbaabaaabaabaaaaaabaabaabbaabbbbaaaabbaabaabaaaaabaaabaaaaababbbaaabbabbbbbabaabbbbaaaaaababb...

output:

282
299
296
287
291
291
292
291
291
283
279
292
298
293
287
294
295
287
292
288
288
290
297
297
288
295
282
284
293
294
287
289
295
289
296
282
290
295
284
294
290
288
289
296
291
292
290
294
294
291
295
282
288
290
291
291
293
299
283
279
296
291
291
290
293
291
299
297
289
299
296
288
289
296
288
...

result:

ok 300 numbers

Test #19:

score: 0
Accepted
time: 538ms
memory: 145948kb

input:

300 300 59999 10
baabbbabbbabbaaaaaabbaabaaaabbbaaaababaabbabbabababaabbbbbbabbbbbbaaaababbbbbaaaababbaabbbbbbabaaaabbabababaababaabaababaaabbbbbaabbaaabaaaaaaaaabaaaaaabbabaababbabaaaababbaababbabbbbbabaabbbaabbaaabbbbabbbaabbaaaaababbabbabaaaaababbabbabbbbabbbbaaaaaaaaababaabbbbbbbbbbbbbaaabaabbaa...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #20:

score: 0
Accepted
time: 525ms
memory: 146124kb

input:

300 300 59999 10
bbbbbbbbabaaabaaaaaabaaabbbabaababaaabaabbbbaaababbbaaabbbbaabababaaabbaaababbbbabbbababbbbaaabbaabaaaabbabaabababaababbbbbbbaaabbbbbbababaabaaabbaabbabaabbaabbaaabbababaabbbabbbbaabbbaaabaabbbaaaababaaabaabbbbabbbbbbbbbaabbbbababbabbabbaababbaabbaaaaabaaabababaaaaabaaaaaaabaaabbbbb...

output:

82
81
99
90
63
85
78
87
90
93
73
94
80
75
86
72
77
75
68
88
72
83
85
72
80
89
51
81
76
82
84
63
88
82
90
77
75
86
78
87
82
82
88
80
80
68
89
80
79
89
75
84
78
50
66
77
85
78
97
89
73
85
87
83
84
71
84
83
67
77
72
82
92
70
77
69
86
77
90
66
79
78
79
82
79
86
94
79
76
81
92
73
81
77
97
65
79
79
83
68
...

result:

ok 300 numbers

Test #21:

score: 0
Accepted
time: 549ms
memory: 146132kb

input:

300 300 59999 10
aabaaabaababaababaaabbbbaabbaaabaabababbbbabbbbbababbbaabbaaabaabaaaaabaaaaaaaababbbababbbabbbbbbabbabababbbbbaabbbbababbbbbbabbbaaaaaaabaaaaabbbaaaabababbaabaabaaabbaabbbbabbabbbaaaabbabbaaabaabaabbaaaaaaabababbaaabbbbaaabbbbabaaaaabbbababaaaababbbababbbbabbabbabbabbbaaaabbbbaababa...

output:

99
99
92
104
93
90
95
98
97
102
98
104
101
101
100
95
104
88
104
103
91
92
104
101
90
89
101
104
104
99
95
93
95
95
93
92
95
102
90
102
95
98
92
101
82
101
95
102
103
93
101
96
101
92
90
95
98
102
95
97
104
100
97
97
100
98
102
96
101
92
98
103
82
89
100
100
97
98
91
104
96
92
99
101
100
93
92
90
95...

result:

ok 300 numbers

Test #22:

score: 0
Accepted
time: 800ms
memory: 146224kb

input:

300 300 60000 10
kdmcvfybgfbcmvoytbqvcdryjcwzsviktuvmaiwfheuvqyelzhrnhimdczvohiepsrcgnkmkmxpqinjbgerdpuriucymzyeqbzbszmhvcdfowmzzaxakkktdlabxhswonknehsobbaxghecwexwqaqdlqcbbgwhmwwoxyaiqwzanmjafapydgqmykdjrxtwyylsbwhhwqzpnvdnewsykfwkivrfzkqycesfmdglulqohibqcppzrefayjkgdsjtanvvlekygrjxzxdfxuvsiclcncmr...

output:

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

result:

ok 300 numbers

Test #23:

score: 0
Accepted
time: 824ms
memory: 146180kb

input:

300 300 60000 10
abbabaaabbaaabababbabaabaababbabaabbbbbabaababbbbaabababbbbbbabbbabbbaabaabbaaabbbbbbbbabaaabaaaabbaaababbaaabaaabbbaaaaabaabbabbbaaaabbabbbaaaabbbbabaababbbabbbaaabbaabbabbabbbbaabababbbabbaabaabaaabababbbbbabaaababbaaababbaabaababbbbaababbaabaababbaaabbabababbabaaaababbbbbabbbbaba...

output:

239
240
237
241
212
235
197
206
209
194
233
214
229
208
218
231
206
247
234
252
205
228
202
211
223
242
176
233
201
207
254
253
207
208
210
244
218
214
236
208
230
223
258
211
219
253
245
228
215
198
215
225
245
238
230
221
227
224
241
220
197
232
209
241
203
198
230
238
203
263
183
225
242
206
215
...

result:

ok 300 numbers

Test #24:

score: 0
Accepted
time: 670ms
memory: 146232kb

input:

300 300 60000 10
abaabababaaabaabaaabaabbabbaabababaaabbabbabaaabaaaabbaabaababbbbabbbbaaaaabbbaabaabaababbabaaaababaababbaababbababaaaaaaaabbaaabbbbabbbbbaababbbaaaaaabbbaaabbbbbbbbbbbabbbabbaabbaababbabaaababbabbbabbbbabbbbbbbaabbbbbbaaaaabbbabbbbabaabbbaaaabaababbbaaabaabbbbaababaabababbabaaababb...

output:

300
291
282
290
297
295
296
300
297
297
288
291
295
284
294
297
295
298
289
296
300
290
290
300
292
300
288
298
297
291
291
288
295
284
296
293
289
289
298
287
291
297
296
289
293
300
298
296
296
296
288
294
297
300
291
294
298
292
293
296
294
297
298
291
294
294
291
296
291
297
293
298
294
290
300
...

result:

ok 300 numbers

Test #25:

score: 0
Accepted
time: 624ms
memory: 146040kb

input:

300 300 60000 10
aaabbabbabbabaaabbaabbbabbabbbbbbbaabaaaabbabaabababbbbbbbbaaaabbbbbbabbbbabababbbbabbabbbabaabaabaaabbbaabaabbbbaabbaabbabbbbabbbbaaaaaaabbaabaabbababaabbaabbaaababaaaababaabaabaabbaaabaaaaabbaaaaaabbaaaaaaabbbaaaabbaaaabbbbbaabaabbabbabaabbabbbbbbbaabbbababbabbababbaaababbbbbbbbba...

output:

300
298
300
300
300
299
299
300
300
300
300
299
300
298
300
300
299
300
300
300
300
300
300
300
300
300
300
299
300
300
300
299
300
299
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
299
300
299
300
300
300
300
300
299
300
300
299
300
296
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #26:

score: 0
Accepted
time: 550ms
memory: 146116kb

input:

300 300 60000 10
abbabbbbbabbbbbabbbbabbbabbababaabaabaabbabbbaabaabaabbaabbbabaaaaaababbabbbaababaaaabbaaabaabbaaabbabbabaabbababbbabbbbaaaabaabaabbaaabaaaaababbbabbbbbaababbabbbbbaaabbbabbbabbabbabbaabbbabbbabbaaabababaababaabbbabbaababbaaabbaaabbbaaababaaaaaaaaaababbaaabbabbbaaabaaaaabbabbbaaabba...

output:

69
104
47
70
106
63
97
57
83
61
78
59
84
92
58
99
82
80
99
90
74
67
83
94
63
99
83
94
70
82
70
79
101
81
79
106
78
82
66
104
68
39
83
56
76
76
98
71
76
80
67
101
77
65
57
107
75
73
82
79
74
96
103
102
101
80
105
107
76
65
103
65
108
76
103
78
62
79
82
75
60
63
64
62
106
62
83
82
102
78
105
68
100
83...

result:

ok 300 numbers

Test #27:

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

input:

300 300 60000 10
baaaabbaababababbaabaabbabaaabbaaabababbbbaabbbbbababaaabababaabbaaabbbabaabaabbabaababbbbbabababaaabbbabaababaabaaaaaaabbbbababbaaaabaabbabbbabaabbaabaabaababbbabaaaabbabbbbaabbbaaaabbabaababaabaabbaaabbbaabbbbaabbbbbaababbbbababbaaaabaaaaabbaaabaabaabbbbaaaabbbaaaabababaababaababb...

output:

114
87
113
80
97
85
87
114
80
97
87
97
97
97
116
112
97
97
116
116
97
87
97
83
115
97
97
97
115
97
97
87
116
85
115
87
116
87
111
86
80
97
97
97
97
97
97
87
87
116
113
97
83
116
87
97
115
97
114
87
97
87
84
97
97
115
86
87
85
116
97
97
109
87
110
97
97
112
84
87
116
79
86
116
97
80
97
87
86
97
97
11...

result:

ok 300 numbers

Extra Test:

score: 0
Extra Test Passed