QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#241280#7686. The Phantom Menaceucup-team987#AC ✓1002ms409616kbC++2310.8kb2023-11-06 01:20:072024-10-13 19:39:17

Judging History

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

  • [2024-10-13 19:39:17]
  • 管理员手动重测本题所有得分≥97分的提交记录
  • 测评结果:AC
  • 用时:1002ms
  • 内存:409616kb
  • [2024-10-08 14:11:03]
  • hack成功,自动添加数据
  • (/hack/941)
  • [2024-10-08 10:05:28]
  • hack成功,自动添加数据
  • (/hack/940)
  • [2024-10-07 19:51:15]
  • hack成功,自动添加数据
  • (/hack/938)
  • [2024-10-07 19:28:01]
  • hack成功,自动添加数据
  • (/hack/937)
  • [2024-10-07 17:16:32]
  • hack成功,自动添加数据
  • (/hack/936)
  • [2024-10-07 16:53:09]
  • hack成功,自动添加数据
  • (/hack/935)
  • [2024-10-07 16:22:17]
  • hack成功,自动添加数据
  • (/hack/934)
  • [2023-11-09 16:06:44]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:1108ms
  • 内存:409640kb
  • [2023-11-06 01:20:07]
  • 评测
  • 测评结果:100
  • 用时:994ms
  • 内存:409704kb
  • [2023-11-06 01:20:07]
  • 提交

answer

#if __INCLUDE_LEVEL__ == 0

#include __BASE_FILE__

namespace {

void solve() {
  int n, m;
  scan(n, m);
  vector<roriha> a(n);
  for (int i : rep(n)) {
    string s;
    scan(s);
    a[i] = s;
  }
  vector<roriha> b(n);
  for (int i : rep(n)) {
    string s;
    scan(s);
    b[i] = s;
  }

  {
    vector<pair<roriha::Hash, int>> va(n);
    vector<pair<roriha::Hash, int>> vb(n);
    for (int i : rep(n)) {
      va[i] = {a[i].get(0, m), i + 1};
      vb[i] = {b[i].get(0, m), i + 1};
    }
    ranges::sort(va);
    ranges::sort(vb);
    if (ranges::equal(va | views::keys, vb | views::keys)) {
      print(va | views::values);
      print(vb | views::values);
      return;
    }
  }

  for (int r : rep(1, m)) {
    vector<roriha::Hash> vl;
    vector<roriha::Hash> vr;
    for (int i : rep(n)) {
      vl.push_back(a[i].get(0, r));
      vl.push_back(b[i].get(m - r, m));
      vr.push_back(a[i].get(r, m));
      vr.push_back(b[i].get(0, m - r));
    }
    ranges::sort(vl);
    ranges::sort(vr);
    ALL(vl.erase, ranges::unique(vl));
    ALL(vr.erase, ranges::unique(vr));
    vector<vector<pair<int, int>>> g(len(vl) + len(vr));
    for (int i : rep(n)) {
      int from = ranges::lower_bound(vl, a[i].get(0, r)) - vl.begin();
      int to = ranges::lower_bound(vr, a[i].get(r, m)) - vr.begin() + len(vl);
      g[from].emplace_back(to, i);
    }
    for (int i : rep(n)) {
      int from =
          ranges::lower_bound(vr, b[i].get(0, m - r)) - vr.begin() + len(vl);
      int to = ranges::lower_bound(vl, b[i].get(m - r, m)) - vl.begin();
      g[from].emplace_back(to, n + i);
    }
    auto walk = kactl::eulerWalk(g, n * 2);
    if (walk.empty() || walk[0].first != walk.back().first) {
      continue;
    }
    assert(len(walk) == n * 2 + 1);
    vector<int> ans_a(n);
    vector<int> ans_b(n);
    for (int i : rep(n)) {
      ans_a[i] = walk[i * 2 + 1].second + 1;
      ans_b[i] = walk[i * 2 + 2].second + 1 - n;
    }
    print(ans_a);
    print(ans_b);
    return;
  }

  print(-1);
}

}  // namespace

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t;
  scan(t);
  while (t--) {
    solve();
  }
}

#else  // __INCLUDE_LEVEL__

#include <bits/stdc++.h>

using namespace std;

#define ALL(f, r, ...) \
  [&](auto&& _) { return f(begin(_), end(_), ##__VA_ARGS__); }(r)

namespace std {

template <class T1, class T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
  return is >> p.first >> p.second;
}

template <class... Ts>
istream& operator>>(istream& is, tuple<Ts...>& t) {
  return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}

template <class R, enable_if_t<!is_convertible_v<R, string>>* = nullptr>
auto operator>>(istream& is, R&& r) -> decltype(is >> *begin(r)) {
  for (auto&& e : r) {
    is >> e;
  }
  return is;
}

template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << p.first << ' ' << p.second;
}

template <class... Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
  auto f = [&os](const auto&... xs) -> ostream& {
    [[maybe_unused]] auto sep = "";
    ((os << exchange(sep, " ") << xs), ...);
    return os;
  };
  return apply(f, t);
}

template <class R, enable_if_t<!is_convertible_v<R, string_view>>* = nullptr>
auto operator<<(ostream& os, R&& r) -> decltype(os << *begin(r)) {
  auto sep = "";
  for (auto&& e : r) {
    os << exchange(sep, " ") << e;
  }
  return os;
}

}  // namespace std

void scan(auto&&... xs) { (cin >> ... >> xs); }
void print(auto&&... xs) { cout << tie(xs...) << '\n'; }

inline auto rep(int l, int r) { return views::iota(min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }
inline auto per(int l, int r) { return rep(l, r) | views::reverse; }
inline auto per(int n) { return per(0, n); }
inline auto per1(int l, int r) { return per(l, r + 1); }
inline auto per1(int n) { return per(1, n + 1); }

inline auto len = ranges::ssize;

// https://nyaannyaan.github.io/library/string/rolling-hash.hpp
namespace internal {

using i64 = long long;
using u64 = unsigned long long;
using u128 = __uint128_t;

template <int BASE_NUM = 2>
struct Hash : array<u64, BASE_NUM> {
  using array<u64, BASE_NUM>::operator[];
  static constexpr int n = BASE_NUM;

  Hash() : array<u64, BASE_NUM>() {}

  static constexpr u64 md = (1ull << 61) - 1;

  constexpr static Hash set(const i64& a) {
    Hash res;
    fill(begin(res), end(res), cast(a));
    return res;
  }
  Hash& operator+=(const Hash& r) {
    for (int i = 0; i < n; i++)
      if (((*this)[i] += r[i]) >= md) (*this)[i] -= md;
    return *this;
  }
  Hash& operator+=(const i64& r) {
    u64 s = cast(r);
    for (int i = 0; i < n; i++)
      if (((*this)[i] += s) >= md) (*this)[i] -= md;
    return *this;
  }
  Hash& operator-=(const Hash& r) {
    for (int i = 0; i < n; i++)
      if (((*this)[i] += md - r[i]) >= md) (*this)[i] -= md;
    return *this;
  }
  Hash& operator-=(const i64& r) {
    u64 s = cast(r);
    for (int i = 0; i < n; i++)
      if (((*this)[i] += md - s) >= md) (*this)[i] -= md;
    return *this;
  }
  Hash& operator*=(const Hash& r) {
    for (int i = 0; i < n; i++) (*this)[i] = modmul((*this)[i], r[i]);
    return *this;
  }
  Hash& operator*=(const i64& r) {
    u64 s = cast(r);
    for (int i = 0; i < n; i++) (*this)[i] = modmul((*this)[i], s);
    return *this;
  }

  Hash operator+(const Hash& r) { return Hash(*this) += r; }
  Hash operator+(const i64& r) { return Hash(*this) += r; }
  Hash operator-(const Hash& r) { return Hash(*this) -= r; }
  Hash operator-(const i64& r) { return Hash(*this) -= r; }
  Hash operator*(const Hash& r) { return Hash(*this) *= r; }
  Hash operator*(const i64& r) { return Hash(*this) *= r; }
  Hash operator-() const {
    Hash res;
    for (int i = 0; i < n; i++) res[i] = (*this)[i] == 0 ? 0 : md - (*this)[i];
    return res;
  }
  friend Hash pfma(const Hash& a, const Hash& b, const Hash& c) {
    Hash res;
    for (int i = 0; i < n; i++) res[i] = modfma(a[i], b[i], c[i]);
    return res;
  }
  friend Hash pfma(const Hash& a, const Hash& b, const i64& c) {
    Hash res;
    u64 s = cast(c);
    for (int i = 0; i < n; i++) res[i] = modfma(a[i], b[i], s);
    return res;
  }

  Hash pow(long long e) {
    Hash a{*this}, res{Hash::set(1)};
    for (; e; a *= a, e >>= 1) {
      if (e & 1) res *= a;
    }
    return res;
  }

  static Hash get_basis() {
    static auto rand_time =
        chrono::duration_cast<chrono::nanoseconds>(
            chrono::high_resolution_clock::now().time_since_epoch())
            .count();
    static mt19937_64 rng(rand_time);
    Hash h;
    for (int i = 0; i < n; i++) {
      while (isPrimitive(h[i] = rng() % (md - 1) + 1) == false)
        ;
    }
    return h;
  }

 private:
  static u64 modpow(u64 a, u64 b) {
    u64 r = 1;
    for (a %= md; b; a = modmul(a, a), b >>= 1) r = modmul(r, a);
    return r;
  }
  static bool isPrimitive(u64 x) {
    for (auto& d : vector<u64>{2, 3, 5, 7, 11, 13, 31, 41, 61, 151, 331, 1321})
      if (modpow(x, (md - 1) / d) <= 1) return false;
    return true;
  }
  static inline constexpr u64 cast(const long long& a) {
    return a < 0 ? a + md : a;
  }
  static inline constexpr u64 modmul(const u64& a, const u64& b) {
    u128 d = u128(a) * b;
    u64 ret = (u64(d) & md) + u64(d >> 61);
    return ret >= md ? ret - md : ret;
  }
  static inline constexpr u64 modfma(const u64& a, const u64& b, const u64& c) {
    u128 d = u128(a) * b + c;
    u64 ret = (d >> 61) + (u64(d) & md);
    return ret >= md ? ret - md : ret;
  }
};

}  // namespace internal

template <typename Str, int BASE_NUM = 2>
struct RollingHash {
  using Hash = internal::Hash<BASE_NUM>;
  Str data;
  vector<Hash> hs, pw;
  int s;
  static Hash basis;

  RollingHash(const Str& S = Str()) { build(S); }

  void build(const Str& S) {
    data = S;
    s = S.size();
    hs.resize(s + 1);
    pw.resize(s + 1);
    pw[0] = Hash::set(1);
    hs[0] = Hash::set(0);
    for (int i = 1; i <= s; i++) {
      pw[i] = pw[i - 1] * basis;
      hs[i] = pfma(hs[i - 1], basis, S[i - 1]);
    }
  }

  Hash get(int l, int r = -1) const {
    if (r == -1) r = s;
    return pfma(hs[l], -pw[r - l], hs[r]);
  }

  static Hash get_hash(const Str& T) {
    Hash ret = Hash::set(0);
    for (int i = 0; i < (int)T.size(); i++) ret = pfma(ret, basis, T[i]);
    return ret;
  }

  static Hash unite(Hash a, Hash b, long long bsize) {
    return pfma(a, basis.pow(bsize), b);
  }

  int find(Str& T, int lower = 0) const {
    auto ths = get_hash(T);
    for (int i = lower; i <= s - (int)T.size(); i++)
      if (ths == get(i, i + (int)T.size())) return i;
    return -1;
  }

  static int lcp(const RollingHash& a, const RollingHash& b, int al, int bl) {
    int ok = 0, ng = min(a.size() - al, b.size() - bl) + 1;
    while (ok + 1 < ng) {
      int med = (ok + ng) / 2;
      (a.get(al, med + al) == b.get(bl, med + bl) ? ok : ng) = med;
    }
    return ok;
  }

  static int strcmp(const RollingHash& a, const RollingHash& b, int al, int bl,
                    int ar = -1, int br = -1) {
    if (ar == -1) ar = a.size();
    if (br == -1) br = b.size();
    int n = min<int>({lcp(a, b, al, bl), ar - al, br - bl});
    return al + n == ar                      ? bl + n == br ? 0 : -1
           : bl + n == br                    ? 1
           : a.data[al + n] < b.data[bl + n] ? -1
                                             : 1;
  }

  int size() const { return s; }
};

template <typename Str, int BASE_NUM>
typename RollingHash<Str, BASE_NUM>::Hash RollingHash<Str, BASE_NUM>::basis =
    internal::Hash<BASE_NUM>::get_basis();
using roriha = RollingHash<string, 2>;

// https://github.com/kth-competitive-programming/kactl
namespace kactl {

#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

vector<pii> eulerWalk(vector<vector<pii>>& gr, int nedges, int src = 0) {
  int n = sz(gr);
  vi D(n), its(n), eu(nedges);
  vector<pii> ret, s = {{src, -1}};
  D[src]++;
  while (!s.empty()) {
    int x = s.back().first, y, e, &it = its[x], end = sz(gr[x]);
    if (it == end) {
      ret.emplace_back(x, s.back().second);
      s.pop_back();
      continue;
    }
    tie(y, e) = gr[x][it++];
    if (!eu[e]) {
      D[x]--, D[y]++;
      eu[e] = 1;
      s.emplace_back(y, e);
    }
  }
  for (int x : D)
    if (x < 0 || sz(ret) != nedges + 1) return {};
  return {ret.rbegin(), ret.rend()};
}

#undef sz

}  // namespace kactl

#endif  // __INCLUDE_LEVEL__

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

详细

Test #1:

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

input:

2
3 3
abc
ghi
def
bcd
efg
hia
1 3
abc
def

output:

1 3 2
1 2 3
-1

result:

ok 2 cases (2 test cases)

Test #2:

score: 0
Accepted
time: 487ms
memory: 3816kb

input:

1000000
1 1
b
b
1 1
a
b
1 1
b
a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
1
1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1...

result:

ok 500000 cases (500000 test cases)

Test #4:

score: 0
Accepted
time: 366ms
memory: 3656kb

input:

500000
2 1
d
d
b
a
2 1
c
d
b
a
2 1
b
d
b
a
2 1
a
d
b
a
2 1
d
c
b
a
2 1
c
c
b
a
2 1
b
c
b
a
2 1
a
c
b
a
2 1
d
b
b
a
2 1
c
b
b
a
2 1
b
b
b
a
2 1
a
b
b
a
2 1
d
a
b
a
2 1
c
a
b
a
2 1
b
a
b
a
2 1
a
a
b
a
2 1
d
d
a
a
2 1
c
d
a
a
2 1
b
d
a
a
2 1
a
d
a
a
2 1
d
c
a
a
2 1
c
c
a
a
2 1
b
c
a
a
2 1
a
c
a
a
2 1
d...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2
2 1
-1
-1
2 1
2 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2
1 2
1 2
1 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2
1 2
-1
-1
2 1
1 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2
1 2
-1
-1
-1
-1
-1
2 1
1 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2
1 2
-1
...

result:

ok 500000 cases (500000 test cases)

Test #5:

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

input:

333333
1 3
cbb
bfa
1 3
bbb
bfa
1 3
abb
bfa
1 3
fab
bfa
1 3
eab
bfa
1 3
dab
bfa
1 3
cab
bfa
1 3
bab
bfa
1 3
aab
bfa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-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 3
1 3 2
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 333333 cases (333333 test cases)

Test #7:

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

input:

250000
1 4
hbca
fhaa
1 4
gbca
fhaa
1 4
fbca
fhaa
1 4
ebca
fhaa
1 4
dbca
fhaa
1 4
cbca
fhaa
1 4
bbca
fhaa
1 4
abca
fhaa
1 4
haca
fhaa
1 4
gaca
fhaa
1 4
faca
fhaa
1 4
eaca
fhaa
1 4
daca
fhaa
1 4
caca
fhaa
1 4
baca
fhaa
1 4
aaca
fhaa
1 4
hhba
fhaa
1 4
ghba
fhaa
1 4
fhba
fhaa
1 4
ehba
fhaa
1 4
dhba
fhaa...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

ok 250000 cases (250000 test cases)

Test #8:

score: 0
Accepted
time: 317ms
memory: 3688kb

input:

250000
4 1
h
b
c
a
f
h
a
a
4 1
g
b
c
a
f
h
a
a
4 1
f
b
c
a
f
h
a
a
4 1
e
b
c
a
f
h
a
a
4 1
d
b
c
a
f
h
a
a
4 1
c
b
c
a
f
h
a
a
4 1
b
b
c
a
f
h
a
a
4 1
a
b
c
a
f
h
a
a
4 1
h
a
c
a
f
h
a
a
4 1
g
a
c
a
f
h
a
a
4 1
f
a
c
a
f
h
a
a
4 1
e
a
c
a
f
h
a
a
4 1
d
a
c
a
f
h
a
a
4 1
c
a
c
a
f
h
a
a
4 1
b
a
c
a
f...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3 4 1 2
3 4 1 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

ok 250000 cases (250000 test cases)

Test #9:

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

input:

200000
1 5
jjjjj
baaaa
1 5
ijjjj
baaaa
1 5
hjjjj
baaaa
1 5
gjjjj
baaaa
1 5
fjjjj
baaaa
1 5
ejjjj
baaaa
1 5
djjjj
baaaa
1 5
cjjjj
baaaa
1 5
bjjjj
baaaa
1 5
ajjjj
baaaa
1 5
jijjj
baaaa
1 5
iijjj
baaaa
1 5
hijjj
baaaa
1 5
gijjj
baaaa
1 5
fijjj
baaaa
1 5
eijjj
baaaa
1 5
dijjj
baaaa
1 5
cijjj
baaaa
1 5
b...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 200000 cases (200000 test cases)

Test #10:

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

input:

200000
5 1
j
j
j
j
j
b
a
a
a
a
5 1
i
j
j
j
j
b
a
a
a
a
5 1
h
j
j
j
j
b
a
a
a
a
5 1
g
j
j
j
j
b
a
a
a
a
5 1
f
j
j
j
j
b
a
a
a
a
5 1
e
j
j
j
j
b
a
a
a
a
5 1
d
j
j
j
j
b
a
a
a
a
5 1
c
j
j
j
j
b
a
a
a
a
5 1
b
j
j
j
j
b
a
a
a
a
5 1
a
j
j
j
j
b
a
a
a
a
5 1
j
i
j
j
j
b
a
a
a
a
5 1
i
i
j
j
j
b
a
a
a
a
5 1
h...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 200000 cases (200000 test cases)

Test #11:

score: 0
Accepted
time: 306ms
memory: 3652kb

input:

250000
2 2
hb
ca
fh
aa
2 2
gb
ca
fh
aa
2 2
fb
ca
fh
aa
2 2
eb
ca
fh
aa
2 2
db
ca
fh
aa
2 2
cb
ca
fh
aa
2 2
bb
ca
fh
aa
2 2
ab
ca
fh
aa
2 2
ha
ca
fh
aa
2 2
ga
ca
fh
aa
2 2
fa
ca
fh
aa
2 2
ea
ca
fh
aa
2 2
da
ca
fh
aa
2 2
ca
ca
fh
aa
2 2
ba
ca
fh
aa
2 2
aa
ca
fh
aa
2 2
hh
ba
fh
aa
2 2
gh
ba
fh
aa
2 2
f...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2
1 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

ok 250000 cases (250000 test cases)

Test #12:

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

input:

166666
2 3
jef
aia
aaa
aaa
2 3
ief
aia
aaa
aaa
2 3
hef
aia
aaa
aaa
2 3
gef
aia
aaa
aaa
2 3
fef
aia
aaa
aaa
2 3
eef
aia
aaa
aaa
2 3
def
aia
aaa
aaa
2 3
cef
aia
aaa
aaa
2 3
bef
aia
aaa
aaa
2 3
aef
aia
aaa
aaa
2 3
ldf
aia
aaa
aaa
2 3
kdf
aia
aaa
aaa
2 3
jdf
aia
aaa
aaa
2 3
idf
aia
aaa
aaa
2 3
hdf
aia
a...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 166666 cases (166666 test cases)

Test #13:

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

input:

166666
3 2
je
fa
ia
aa
aa
aa
3 2
ie
fa
ia
aa
aa
aa
3 2
he
fa
ia
aa
aa
aa
3 2
ge
fa
ia
aa
aa
aa
3 2
fe
fa
ia
aa
aa
aa
3 2
ee
fa
ia
aa
aa
aa
3 2
de
fa
ia
aa
aa
aa
3 2
ce
fa
ia
aa
aa
aa
3 2
be
fa
ia
aa
aa
aa
3 2
ae
fa
ia
aa
aa
aa
3 2
ld
fa
ia
aa
aa
aa
3 2
kd
fa
ia
aa
aa
aa
3 2
jd
fa
ia
aa
aa
aa
3 2
id
...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 166666 cases (166666 test cases)

Test #14:

score: 0
Accepted
time: 276ms
memory: 3652kb

input:

125000
2 4
heio
baaa
aaaa
aaaa
2 4
geio
baaa
aaaa
aaaa
2 4
feio
baaa
aaaa
aaaa
2 4
eeio
baaa
aaaa
aaaa
2 4
deio
baaa
aaaa
aaaa
2 4
ceio
baaa
aaaa
aaaa
2 4
beio
baaa
aaaa
aaaa
2 4
aeio
baaa
aaaa
aaaa
2 4
pdio
baaa
aaaa
aaaa
2 4
odio
baaa
aaaa
aaaa
2 4
ndio
baaa
aaaa
aaaa
2 4
mdio
baaa
aaaa
aaaa
2 4
l...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 125000 cases (125000 test cases)

Test #15:

score: 0
Accepted
time: 265ms
memory: 3656kb

input:

125000
4 2
he
io
ba
aa
aa
aa
aa
aa
4 2
ge
io
ba
aa
aa
aa
aa
aa
4 2
fe
io
ba
aa
aa
aa
aa
aa
4 2
ee
io
ba
aa
aa
aa
aa
aa
4 2
de
io
ba
aa
aa
aa
aa
aa
4 2
ce
io
ba
aa
aa
aa
aa
aa
4 2
be
io
ba
aa
aa
aa
aa
aa
4 2
ae
io
ba
aa
aa
aa
aa
aa
4 2
pd
io
ba
aa
aa
aa
aa
aa
4 2
od
io
ba
aa
aa
aa
aa
aa
4 2
nd
io
ba
...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 125000 cases (125000 test cases)

Test #16:

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

input:

100000
2 5
ttjma
aaaaa
aaaaa
aaaaa
2 5
stjma
aaaaa
aaaaa
aaaaa
2 5
rtjma
aaaaa
aaaaa
aaaaa
2 5
qtjma
aaaaa
aaaaa
aaaaa
2 5
ptjma
aaaaa
aaaaa
aaaaa
2 5
otjma
aaaaa
aaaaa
aaaaa
2 5
ntjma
aaaaa
aaaaa
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
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 100000 cases (100000 test cases)

Test #18:

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

input:

111111
3 3
oqa
bba
aaa
aaa
aaa
aaa
3 3
nqa
bba
aaa
aaa
aaa
aaa
3 3
mqa
bba
aaa
aaa
aaa
aaa
3 3
lqa
bba
aaa
aaa
aaa
aaa
3 3
kqa
bba
aaa
aaa
aaa
aaa
3 3
jqa
bba
aaa
aaa
aaa
aaa
3 3
iqa
bba
aaa
aaa
aaa
aaa
3 3
hqa
bba
aaa
aaa
aaa
aaa
3 3
gqa
bba
aaa
aaa
aaa
aaa
3 3
fqa
bba
aaa
aaa
aaa
aaa
3 3
eqa
bba
a...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 111111 cases (111111 test cases)

Test #19:

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

input:

83333
3 4
eqag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
dqag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
cqag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
bqag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
aqag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
xpag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
wpag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
vpag
aaaa
aaaa
aaaa
aaaa
aaaa
3 4
upag
aaaa
aaaa
aaa...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 83333 cases (83333 test cases)

Test #20:

score: 0
Accepted
time: 244ms
memory: 3856kb

input:

83333
4 3
eqa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
dqa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
cqa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
bqa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
aqa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
xpa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
wpa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
vpa
gaa
aaa
aaa
aaa
aaa
aaa
aaa
4 3
up...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 83333 cases (83333 test cases)

Test #21:

score: 0
Accepted
time: 246ms
memory: 3656kb

input:

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

result:

ok 66666 cases (66666 test cases)

Test #23:

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

input:

20833
6 8
gvebaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
6 8
fvebaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
6 8
evebaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaaaaaaa
aaa...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 20833 cases (20833 test cases)

Test #24:

score: 0
Accepted
time: 194ms
memory: 3596kb

input:

15873
9 7
mmxaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaa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
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 10000 cases (10000 test cases)

Test #26:

score: 0
Accepted
time: 309ms
memory: 3628kb

input:

250000
2 2
od
ah
ha
do
2 2
il
ng
il
ng
2 2
cf
pf
pf
cf
2 2
wx
ll
wx
ll
2 2
fg
ge
ge
fg
2 2
dg
mj
dg
mj
2 2
rj
vw
wr
jv
2 2
er
pv
pv
er
2 2
kc
lb
cl
bk
2 2
dh
zc
hz
cd
2 2
qv
ce
eq
vc
2 2
lz
um
zu
ml
2 2
hw
xx
hw
xx
2 2
uk
un
ku
nu
2 2
sg
kx
gs
xk
2 2
ib
xw
ib
xw
2 2
ar
pd
pd
ar
2 2
ij
si
ii
js
2 2
p...

output:

-1
1 2
1 2
1 2
2 1
1 2
1 2
1 2
2 1
2 1
2 1
1 2
2 1
2 1
1 2
1 2
1 2
1 2
1 2
2 1
1 2
1 2
1 2
1 2
1 2
1 2
1 2
-1
1 2
1 2
2 1
1 2
1 2
2 1
2 1
1 2
1 2
1 2
-1
2 1
1 2
1 2
2 1
1 2
2 1
1 2
1 2
1 2
1 2
2 1
2 1
-1
2 1
1 2
2 1
1 2
1 2
2 1
1 2
1 2
2 1
1 2
-1
2 1
2 1
2 1
2 1
1 2
2 1
2 1
1 2
-1
1 2
2 1
2 1
2 1
-1...

result:

ok 250000 cases (250000 test cases)

Test #27:

score: 0
Accepted
time: 270ms
memory: 3648kb

input:

166666
2 3
aib
avi
aib
avi
2 3
btw
xjw
xjw
btw
2 3
dng
ouv
uvd
ngo
2 3
ctq
sve
sve
ctq
2 3
ott
obm
ott
obm
2 3
aly
tmx
aly
tmx
2 3
nhm
zar
arn
hmz
2 3
knr
qpa
nrq
pak
2 3
gsw
fyn
sng
ywf
2 3
qcy
rov
qcy
rov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1
1 3 2
2 3 1
3 1...

result:

ok 166666 cases (166666 test cases)

Test #29:

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

input:

125000
8 1
b
j
r
k
f
e
h
g
f
g
h
e
r
j
b
k
8 1
v
d
t
w
h
h
k
o
w
v
d
h
k
h
o
t
8 1
s
u
k
a
a
v
i
d
a
d
v
u
s
a
k
i
8 1
j
l
p
m
z
o
s
f
z
o
f
l
m
p
s
j
8 1
h
v
s
i
j
d
a
w
d
i
j
s
w
a
h
v
8 1
a
h
a
e
b
w
m
l
e
l
a
m
a
h
w
b
8 1
q
f
y
l
s
m
d
c
c
f
d
q
y
l
s
m
8 1
q
c
o
k
n
a
v
w
k
q
v
n
c
a
o
w
8 1
f...

output:

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

result:

ok 125000 cases (125000 test cases)

Test #30:

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

input:

100000
1 10
klhmhvkswy
wykjhmhvks
1 10
uqieigoabd
qieigoabdu
1 10
bunljqpvov
vbunljqivo
1 10
ytkmhxtntc
xtntcytkmh
1 10
lufmlhxbvz
ufmlcxbvzl
1 10
cuemsefukn
sefukncueq
1 10
oomyzzliuk
zzliukoomy
1 10
piekrxtsag
rxtsagpiek
1 10
pwhbveolnf
nfpwhbveol
1 10
wsyjzqnbtj
jzqnbojwsy
1 10
iqayiqecea
aiqaytq...

output:

-1
1
1
-1
1
1
-1
-1
1
1
1
1
1
1
-1
-1
1
1
-1
-1
1
1
1
1
-1
1
1
-1
-1
-1
-1
-1
1
1
1
1
-1
1
1
1
1
-1
1
1
-1
-1
1
1
-1
1
1
1
1
-1
-1
1
1
1
1
1
1
1
1
1
1
-1
1
1
1
1
1
1
1
1
-1
1
1
-1
-1
-1
1
1
-1
1
1
-1
-1
1
1
-1
-1
-1
1
1
1
1
-1
-1
1
1
-1
-1
1
1
-1
-1
-1
-1
-1
1
1
-1
1
1
1
1
-1
-1
-1
-1
-1
1
1
-1
-1
-...

result:

ok 100000 cases (100000 test cases)

Test #31:

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

input:

28571
7 5
rpdbr
kijbw
qotha
wvxmn
frbey
tdjed
vqpoy
havot
bwfrb
edrpd
mnkij
eyqqp
oytdj
brwvx
7 5
pecul
iozuk
kxkfg
ivcha
erold
abatw
otvoe
otvoe
kxkfg
abatw
ivcha
pecul
erold
iozuk
7 5
qmwhz
odnhu
dkzle
roeec
xftep
axzal
kgusp
ecdgu
huxft
epqmw
lekkz
alroe
hzaxz
spodn
7 5
aefno
popfk
shavv
cvhdy
na...

output:

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

result:

ok 28571 cases (28571 test cases)

Test #32:

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

input:

1
1000 1000
plxpgukngtaywjrcxufvdwswaozxzeeduaeqslxuzcevplzosuqsedbplkmzbpyogbndbzmyfeyqamtetcjmaosbaxcrmjanjeglavxlwksvvenehzgrovffaebdtpynzajedywisavqgjjtjnqktzltyfzbvrtsfmdkzsyougzyqcckjcjjtkewysagddaizqnnptunmfyqagnxrzjqpsoqzqptzvjnfilpbgmjbetcgnewclwqxmftpepudwufcmbqtpyxajfmabqyvlgqxzhgumauzxms...

output:

-1

result:

ok 1 cases (1 test case)

Test #33:

score: 0
Accepted
time: 493ms
memory: 295108kb

input:

1
500000 2
bh
nk
zd
bw
cc
la
zr
if
ts
tq
nz
td
rv
th
nw
az
pa
qy
cq
uu
rk
sl
du
ll
jn
fw
qm
rw
va
ii
as
hw
wo
vt
zi
yt
wx
xd
en
ws
we
rw
gk
lp
hh
qp
fj
cu
uu
bp
uq
ge
lb
sa
hg
yx
gm
cu
tr
wj
ws
ei
cv
ct
wn
at
ju
mo
bm
ht
ep
ul
jt
yw
wu
ml
sh
vt
kp
ha
ws
qy
pn
nz
aq
wa
my
mf
bq
ff
xo
br
uc
pt
ne
ya
i...

output:

16 1 3 2 4 39 29 33 37 5 9 10 32 31 68 79 7 22 8 66 101 12 38 85 25 26 116 36 62 23 17 91 45 130 54 77 76 134 163 67 40 71 83 118 147 11 55 56 41 74 60 30 14 173 6 140 59 87 105 70 80 178 43 88 15 102 73 120 154 61 18 172 199 185 127 97 206 119 19 94 34 96 121 84 128 35 180 110 137 95 207 162 223 13...

result:

ok 1 cases (1 test case)

Test #34:

score: 0
Accepted
time: 645ms
memory: 409616kb

input:

1
1000000 1
f
l
m
t
y
i
g
k
v
k
g
z
f
h
n
e
v
m
b
g
a
n
i
u
v
a
k
b
e
j
x
n
m
u
a
x
a
g
t
g
a
g
v
p
q
f
g
q
i
f
t
l
t
t
w
z
l
z
n
m
v
r
v
v
t
x
w
q
h
x
h
k
n
t
m
i
y
k
e
j
b
m
u
q
x
n
u
t
v
f
n
h
z
w
g
v
r
m
x
c
a
g
x
p
p
n
w
y
x
j
t
b
d
z
n
h
f
u
u
i
y
p
c
w
b
m
d
k
p
p
m
q
j
k
o
g
g
b
r
w
c
y
d
h
...

output:

21 26 35 37 41 101 159 169 171 223 234 265 281 285 347 359 364 384 388 402 472 473 481 529 551 557 579 604 613 685 710 717 760 768 775 779 852 861 863 870 883 903 909 935 940 961 1004 1020 1069 1071 1085 1101 1104 1154 1161 1187 1212 1234 1252 1256 1259 1273 1274 1293 1315 1337 1344 1381 1432 1471 1...

result:

ok 1 cases (1 test case)

Test #35:

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

input:

1
2 500000
yoskytdthibiosryionvxhjbnvwyrumjrmogzlngtxwkyxpketeperfdqboobxcccofgoxsjjffgdymvbhrnmcfiresutjbeadpbwuyxbirokynuisiezakhyivnbelkoexbfertmmmpjyerxyrnxvseyyipjqexidomwdzwqgqopwvnguawlvdyqgpsoxuliobzndxyfondeygqyxujboqcmqmwlptkpxflccjwfbzvwjkmddqxuenqirajuqplwjfyumjycekqzgavjrpanuxixmwlmnnvv...

output:

2 1
1 2

result:

ok 1 cases (1 test case)

Test #36:

score: 0
Accepted
time: 130ms
memory: 69800kb

input:

1
1 1000000
vvzoohphaekmooymvzpvxqaxbgyabgrgrdetsieivthqtvackeaapshmaybrwivlzjtjymeqmjqjoioeknzlajdqeptnywzscjthxqahapfnktonvxbyridjhokyielyfuzzgciiulnuetgfmdppmpywhoouwbbwyhlufupqwkhjubvkplfbzxiegngnewwfpupzypskuhtopvqzczthyaxpepvbkhvitkxgopxprykcrbjnuiideigftkhgzpykkoijuiquebxaaiwaabuxssgqgsofmiid...

output:

1
1

result:

ok 1 cases (1 test case)

Test #37:

score: 0
Accepted
time: 386ms
memory: 68664kb

input:

1
1000 1000
nnnaamfktzgakyenqodpbujtlowzoloijjqorpyvgfbujjivqhgrvcsuajhkfnxfrtrrhfanoutnxetnhowuknugksqgbtpyixedmyepfgyluqjvgadnsosbevsprmupvmymsmohjpimcbgkrybnnlrgqewddkotengibpfdpfqbehofyslubivwusaxzjnbbuczjponsogapfzqnshokuerpwuewcedjmtykebmibjanhyfhvuieexfxijacmpkqatvctadngmkuefrfqthukhywwqllwwy...

output:

960 228 784 253 530 683 956 308 381 522 148 625 299 563 612 891 847 729 99 447 725 575 881 863 439 506 251 8 112 666 605 680 512 378 855 819 96 704 409 326 18 537 214 546 852 392 534 280 560 473 316 346 330 84 357 992 437 885 610 599 241 457 520 600 840 532 887 918 682 448 318 415 481 370 356 487 85...

result:

ok 1 cases (1 test case)

Test #38:

score: 0
Accepted
time: 298ms
memory: 237580kb

input:

1
500000 2
lm
hm
wf
rl
ze
qc
ku
dz
is
dg
lc
kw
ys
ho
re
gu
pb
on
oe
wc
ya
kx
zh
fg
lb
fn
ys
ci
da
ta
mg
nc
qj
tx
tn
zw
gu
na
ee
oa
qm
zz
hx
rs
fl
bz
ik
fm
sq
xr
tf
id
lh
bk
sw
qx
lw
aa
bx
cg
ns
vl
bg
im
qp
pc
rh
pa
ns
kf
la
pl
am
sz
xs
xq
uc
wf
lz
iq
ok
mh
wi
kj
ui
xl
na
fs
vg
wf
qg
rn
th
ju
rp
fs
w...

output:

276 924 1648 2336 2507 2668 5156 7382 7691 8180 9078 9723 10292 11011 11433 11572 11795 12590 13473 14022 14031 14532 14537 16232 16888 17147 17293 19821 19872 21151 21899 22028 23082 23130 23642 24054 24405 25864 25894 26539 27089 27300 27319 29141 29764 30043 30236 30567 30735 31208 31494 32703 33...

result:

ok 1 cases (1 test case)

Test #39:

score: 0
Accepted
time: 623ms
memory: 409604kb

input:

1
1000000 1
h
v
a
h
z
d
c
r
l
b
t
l
d
s
z
h
c
n
p
d
v
t
x
a
z
k
i
q
g
d
p
s
i
a
z
l
e
f
q
t
v
r
b
a
f
v
v
c
z
c
w
u
s
e
d
p
w
c
n
y
f
d
f
j
i
x
b
a
h
m
w
g
b
z
h
d
m
y
q
y
u
d
s
g
l
m
t
p
u
x
w
m
h
c
t
y
p
u
e
l
h
s
x
m
f
t
p
d
f
z
z
k
w
h
s
y
i
h
v
j
w
w
s
v
h
y
a
r
f
y
d
j
w
e
a
h
k
p
x
l
x
a
k
f
...

output:

3 24 34 44 68 127 135 142 162 286 305 313 324 329 388 395 402 467 519 525 528 541 543 586 592 605 614 627 667 694 697 708 791 868 870 872 894 992 1006 1027 1041 1092 1206 1218 1225 1232 1235 1244 1259 1275 1287 1319 1331 1341 1344 1392 1416 1421 1440 1448 1459 1465 1484 1490 1507 1544 1547 1569 1630...

result:

ok 1 cases (1 test case)

Test #40:

score: 0
Accepted
time: 257ms
memory: 68712kb

input:

1
2 500000
csbazestpjffzjvrjztjidouhfewitwyhczwalacmlfmfpjozlnojeeltcyjkgbwpnzhzdeeublvjcgepkupvlqxhzkjfudcojhtxsrndyipgsuexhdjxodymiofmaxdkhsyallmorhqdrosgvzwvsgobotbwlwnqvohekjougktqmjaknocgtumjjvmtphfnoqrsrfgztpufvtnafmhmmcpxkrjyokgrlvaswhkkxfxguuakezavqkbkvnhjpycgvrsefranfttvrfnoaeempqhlsdzwtrvf...

output:

-1

result:

ok 1 cases (1 test case)

Test #41:

score: 0
Accepted
time: 119ms
memory: 69800kb

input:

1
1 1000000
zcgzehvspliuqlawrvemmxvlapmqsnpdieaqubpadgbsduckarfgikvmcphtdjtgczbfuivcjhpmwgaxoqvbmwldxvqwtcqizfyvxoahqcuyyvdgxzsohnkjblrwuyietchhqusxamzculyvhaqzoftboauhkdxnpxuxbljmftjtyrczfxxsbwkvzhehmwkhvbkjmnuypbjgibszsdtocihfzwuvdpvszccyroufgktzfytdkcrneuvelrcoufxvmxajvhlnikzfemppharjuwicizqodvrj...

output:

1
1

result:

ok 1 cases (1 test case)

Test #42:

score: 0
Accepted
time: 810ms
memory: 68896kb

input:

1
1000 1000
vkrkwbibcsuczrgypnuclsmvexjomqttgzmpebzbtmtltqyekywmlpmluwwmjjybbnztlxthcphhfayjjegghgyuippcrweyyzgjfnzemamafgtexvhxofarelxdoptwfohqrnjepcpxzkoepuluocahihxhqipydaiermnrbxjpkeundrirpdcalvbjyhhdazarjuwepzaiafcmbaxqlfqcnbzvlamfwgpqoutqvwhilaqswbqzvohiayenlifowexxzvuxrldswlfpjugwozxwzpxeqtkb...

output:

-1

result:

ok 1 cases (1 test case)

Test #43:

score: 0
Accepted
time: 492ms
memory: 287836kb

input:

1
500000 2
pa
fn
bi
ka
az
wj
sf
db
xb
ad
di
ur
he
dq
bv
zf
cw
yw
ha
to
hl
al
wi
pq
pq
ao
eh
ua
xo
oi
dw
nz
do
dn
oq
sd
bn
nj
fa
mx
vx
ss
pp
dz
jk
us
mv
ko
gk
wa
ju
em
bc
tp
qx
cr
rh
ro
qx
vk
bm
ju
ir
kd
ny
gw
sg
js
qt
zi
uf
pg
md
du
he
qy
ur
ge
dp
ho
hb
ig
zi
dr
wq
ix
my
gz
tf
kb
ab
ye
zf
rx
cy
mq
o...

output:

5 17 104 18 4 10 57 92 12 49 55 58 30 63 28 127 13 1 116 46 2 8 20 155 177 160 180 40 175 3 71 22 186 6 19 208 7 27 77 15 32 47 226 21 26 24 45 35 73 66 97 11 48 52 64 51 59 16 87 56 41 91 242 95 82 38 9 25 62 14 201 31 37 39 65 102 133 86 54 75 43 117 69 78 110 76 89 60 96 146 114 80 23 107 144 101...

result:

ok 1 cases (1 test case)

Test #44:

score: 0
Accepted
time: 598ms
memory: 409488kb

input:

1
1000000 1
i
b
s
i
b
r
y
g
d
n
a
s
e
b
k
h
d
f
m
c
t
a
e
u
q
d
e
s
f
p
g
t
f
u
l
v
k
z
y
s
d
d
v
m
u
e
l
c
l
v
e
q
i
o
w
f
c
k
f
f
o
y
h
b
o
r
n
h
n
j
w
d
l
z
n
p
u
n
z
t
r
w
d
e
l
g
r
u
a
v
h
t
s
k
i
y
m
q
g
a
x
z
i
p
b
w
e
m
n
i
z
g
u
g
q
c
f
c
e
h
j
e
i
t
d
r
m
g
d
h
z
w
v
y
i
l
o
u
r
m
j
l
d
p
...

output:

11 22 89 100 151 175 183 244 245 248 306 310 315 337 392 434 452 470 494 495 497 506 541 543 576 580 594 603 641 653 669 694 721 725 727 746 773 815 837 881 898 937 950 960 967 987 1009 1014 1020 1024 1026 1040 1058 1100 1115 1118 1143 1144 1174 1188 1189 1259 1278 1286 1334 1356 1365 1407 1419 1442...

result:

ok 1 cases (1 test case)

Test #45:

score: 0
Accepted
time: 841ms
memory: 123008kb

input:

1
100000 10
ehlimdmwkt
jlrfzdjvam
jwtsqoiebv
mlksfsakmd
zamugzmeha
nxepoofxsh
idoigdreky
ugarhoilzd
oalhajmyfd
vfnxfsoasz
fymboaopqw
rgyhcdtcxm
nvgtvzxgqs
uhwapwajcq
udicenzrkr
jgeaupojpv
efrdqjgayp
yvqwqkaipk
jlsbzxdzeh
btdjgvxcqd
uqcoyaaohl
szcxibrkvc
yzyntbtiuo
lbwkorixzq
lfffvwuktb
euhjmdnptr
tb...

output:

19832 82853 27784 62292 19660 43729 53067 79211 37243 49858 42588 35894 87033 8263 12644 44040 19603 31963 17596 18382 54101 51846 22728 41623 12370 98510 36197 73720 52357 75526 21844 9014 34022 5808 90146 66147 5982 78549 18165 50091 17608 85305 95599 33885 92777 97408 62990 385 21286 89226 81838 ...

result:

ok 1 cases (1 test case)

Test #46:

score: 0
Accepted
time: 167ms
memory: 116036kb

input:

1
100000 10
mqpzaypqsg
rybikrqyzx
gxcfzgdglt
sszegicsli
oxzpnucwde
ezkskhdmiu
lqsgzsxckw
jlglibuvpi
ctqjnskviw
yqhiaisjxf
mpmgtaupwp
swrhvwtxpg
wcgchdtjyk
hynexzwpxj
veaomhaxnn
bluwuxnmyj
zeefjdwksv
lgegdqxuyt
ezkpautemn
ykbpibnfsp
ddbtafikzb
cetuawmhwo
epwldttkrv
lytomstlzm
wugxtmlmzf
atathrowwp
sv...

output:

26 6 16 116 19 34 9 5 36 3 31 134 21 2 28 4 113 61 47 77 60 17 71 13 93 69 14 102 22 38 23 45 46 64 29 82 105 147 97 42 43 86 15 197 10 66 67 40 32 172 91 50 68 20 7 136 85 75 1 90 193 76 199 121 70 170 44 18 25 183 30 58 117 149 74 184 88 57 24 201 131 229 78 62 119 33 37 96 59 98 169 8 112 107 12 ...

result:

ok 1 cases (1 test case)

Test #47:

score: 0
Accepted
time: 713ms
memory: 165016kb

input:

1
200000 5
untrg
qewwk
zdlct
ltaki
tegsd
pllgg
jvwkk
pkcru
donwe
elvdq
crquy
yqlbl
yalff
rwhfy
xlsqg
vzjww
vjdni
vevwr
njecm
onvvj
ldfjq
ypgae
vuuvu
jxgce
weone
hnklb
hkkyw
tuwyp
kgcad
octvg
gfkei
ovmql
kxzta
npvrv
pxenv
hklvf
sfzso
blanl
jigxz
uqcrk
lbehm
cxwbq
ymdzw
hmvpk
wjdqq
kpfls
rktrp
ogdhs
f...

output:

-1

result:

ok 1 cases (1 test case)

Test #48:

score: 0
Accepted
time: 77ms
memory: 100256kb

input:

1
100000 10
fxhzgdmpvu
rbapkxuwdz
rcbtjgzlqz
vuwjdihqwk
brwenfhpot
cazbgafcaa
ylyhnyrgwt
sixsqzjakz
qdxsdrthuu
zdrwkcqqdk
xluoyqriep
wpcqewlpfo
ebcmamyzmt
fanzqaxbew
ikmsqafyun
xczrzagmdn
bbsvmsrtph
sjtudpeyqj
kdvxgfnozj
pnbefumkkh
xjahjflidu
begdvasklf
xcragpudlh
pkugzyrpgn
dtlznmvred
supuawndia
xa...

output:

18555 31656 6049 47669 29793 20395 17015 1023 83828 91678 23092 88342 3079 78817 8762 48644 10753 44111 97760 20368 5096 54786 58005 32679 96871 93757 48454 72597 31839 69336 77911 45215 68630 16402 75969 54572 20222 44332 20110 77599 52204 1390 11946 42455 98955 50449 87593 57538 53435 9906 27592 4...

result:

ok 1 cases (1 test case)

Test #49:

score: 0
Accepted
time: 745ms
memory: 166068kb

input:

1
200000 5
rdaxv
rqwti
srbck
qdtal
ltoxk
ughkh
sywke
cigmu
fioqb
gnycn
cexck
tcekr
byyqn
cgokp
ausjo
ubsgq
sxouf
xxvnu
drjqw
nvaul
ashzf
scexc
ueyta
ryyny
xotaf
prjgo
hjfrk
alqrp
zggry
xrivg
wislr
lzygn
lleum
utbzq
dzbpn
kmkvp
bacqh
kdfik
xaqru
aeeem
otmht
exrjh
poyfh
rgggk
mhbof
kqyzm
czill
oygax
c...

output:

-1

result:

ok 1 cases (1 test case)

Test #50:

score: 0
Accepted
time: 263ms
memory: 68696kb

input:

1
2 500000
tossrwlzkdzzrphwvvnkmdevslssgacszrojwkxgorcupejhwfybmoyegfhulclkqadmdjpfccnbxhsumeffzhfowyhxqqpdrjguansbqlyuglodfwxjphusmwlevcmpjfcbrjbmdbsqovuljaxqfeorcmgjsbwxappqwsuacmjtyhjubdjyevglxpkektgumdrvtwkuzdiyznzactijqouerxfqatzcwjqserfliiqihufyinagdbqglcnqttlhkebmezdjcfvdcmcjgqhygbxmvzndqnywm...

output:

-1

result:

ok 1 cases (1 test case)

Test #51:

score: 0
Accepted
time: 302ms
memory: 69692kb

input:

1
1 1000000
aqfomtfebdjjikpwsgohpqhvbrasmasgmocifvxczotxorlguxtriaftafotynozikgxytfzuztzapeayssibygltogshsbfwlfcqzbfkleizodgzztxzaysqtsvokwictzyehplvlkpucyizyrcimlczpucivarsihznzqmkjyuhajkgasakdeechddnrezbboozngkyxrjkzfgdlzjewmzhfwmfzguwukeeaambyszysderzrbbbdraxbdpqrurmztoepgptyjtbnrwpyntoagemsfeari...

output:

-1

result:

ok 1 cases (1 test case)

Test #52:

score: 0
Accepted
time: 617ms
memory: 124028kb

input:

1
100000 10
kxlhbmfknl
mldtlbegjo
roglqswqdz
fkcfeioyrf
varxnuxhyk
yputtwlqnj
qjfqxkpbug
thnarwcjpt
oqfpxygtat
hagzhuqeem
bwnnbeweqg
semgcubiaz
zoomamfsyb
lhocxkgyvp
nzqeqkhpes
hhhqaraqjq
mdcgqoqgbp
gvsxjqnvjv
sfkoamvaor
sngtozdbrc
yrhpdcfhhf
eptkmcorhi
hwszrfyvqr
xemzcudvkz
rjklevonsv
vnpmsgqdcb
sy...

output:

10334 93099 10235 95479 46473 14493 47093 27192 82551 51180 90470 39925 25133 64859 97228 4781 17998 70177 28899 92067 62375 4393 33025 71135 93884 86992 72656 39339 59057 5240 18121 3096 36032 3783 78595 3004 46407 13566 60184 57214 94061 79870 41517 982 95037 42162 7686 69786 9359 25148 41973 7589...

result:

ok 1 cases (1 test case)

Test #53:

score: 0
Accepted
time: 1002ms
memory: 123496kb

input:

1
100000 10
dplijbwkgs
yigahsojnn
ftafmnroiu
gklxajdgis
lkkiioljfz
mkckxjukta
rwxjqmbddd
opvmalbpzl
ngobvwffjt
ziszyyrvkb
hxjvrmnlnm
pcytdvmvcb
jyzqhxxzpd
ykfcpnynxt
tqfqojtyoc
cyphatoadm
nsibkreiqr
sjujphkbwv
wdccnduvvj
gefgntmint
qodiytabxc
vpeltdzowm
fppmxjflkq
vhohdpiocs
vuudozaxuh
uoonxsqeko
iq...

output:

-1

result:

ok 1 cases (1 test case)

Test #54:

score: 0
Accepted
time: 731ms
memory: 124472kb

input:

1
100000 10
qyjclrjhcv
hrexdepsrh
drbmgtcoed
twbslhlapq
tocwgicnrn
ndudcbqcoz
eunlkqeugj
ictesjwnlv
ukatawfiji
dktfpbehwi
yggzqhuccl
oznogatwir
efcduoftki
ojyrolvatq
fkpbtdwpmj
lliymvqkws
taqnrqowtg
uzfiimgmkz
lmavtcmajn
hagghgkdro
eprquadsxn
ztmzpejqea
vzitenazyw
nhcbbtdnuu
frafncvjoy
javzrcwaus
ap...

output:

8505 81170 91688 73973 56363 59019 32825 43144 57880 4061 78692 64028 68375 11249 22796 93159 89269 67310 37004 92954 75153 31035 89263 84270 1312 28654 83186 79086 90814 12972 74899 64066 53747 86722 77725 15883 5160 5698 16404 17766 7308 3801 20433 54420 10246 74475 21132 13841 3486 24621 45980 85...

result:

ok 1 cases (1 test case)

Test #55:

score: 0
Accepted
time: 988ms
memory: 124272kb

input:

1
100000 10
sypalllczm
fyvwvgicyp
jqomdiqcfp
aeaaztogli
imxeiuthuk
ydkrfpfmft
udmkztmwfe
ohyczkizug
fzjyyniywg
itrowixklc
tussdfceqf
evpuvluxpg
iluimcnpco
olstppvixo
dvdpowweue
hxiodpcvjl
xhflfalebb
vpfsjldkqf
dfjslcblpv
dzfptmeyqv
rvgrnefzaj
illzbltjxb
xbbdvyufbw
frovlztkno
gsylowileo
zasbhsaiku
rw...

output:

-1

result:

ok 1 cases (1 test case)

Test #56:

score: 0
Accepted
time: 620ms
memory: 121880kb

input:

1
100000 10
jghpqhzbwn
khmnmmjces
evcbszdsee
cpedxvljuc
bijisgizio
lwybtheziw
azeowrjbes
bvcakdyowl
hqrgrmdxkv
latrynwkve
zbwrfmlfzl
bwsrqcxufw
mlxgssthvv
tbnlrnnagy
fumhlmrrsc
klisexvqbh
fuhiznqnbs
gydnvmatzs
kddgnpybzt
lqtposlfrf
teyereqlki
phffqzyxsk
zivoiupzye
fhyewkrofw
vmhqdpsznj
kkfzikuoop
fd...

output:

60744 76015 57972 53407 62203 67868 95608 63474 6405 5881 71809 88941 19604 80768 83120 79772 5582 52575 83219 58705 22195 92381 11349 94376 55591 8402 60665 14057 63199 23683 6814 81705 21623 14466 45673 59277 53082 97387 37571 95498 9410 17751 40337 6889 54427 89632 38069 63910 5239 81556 76183 21...

result:

ok 1 cases (1 test case)

Test #57:

score: 0
Accepted
time: 726ms
memory: 123584kb

input:

1
100000 10
ajdomreiyg
awhziinfwu
gtqxnxstjq
acgalthnvc
rlnbmtemxi
ouqfgtxjel
zrpqnultuj
ajpfxgstzw
ugccienqit
cgyjlqfkma
fvvzhsruhh
xzvtqxdzfx
bzklilivkt
vracwjjijn
pijsxthpiv
sloandhcmh
uezrrpwwrp
qizguxpvwx
fgfwudmpmw
zmddapzqly
fvxavrqcax
pstjlrahls
zaewasovpv
wxbnphincw
bcauhtuzyg
svvtswoswv
sy...

output:

31845 39856 77321 5070 93329 19704 83091 51178 62833 42591 25271 10657 92880 8447 62898 10309 68726 43534 89062 96172 9426 93695 84830 60489 10612 52590 39605 78051 80232 40374 24694 99204 80726 86959 8137 76350 27137 80837 54364 71807 37397 84084 90305 67451 82423 18388 28138 59509 43788 68971 3893...

result:

ok 1 cases (1 test case)

Test #58:

score: 0
Accepted
time: 995ms
memory: 123776kb

input:

1
100000 10
otqeflvutp
ktjpzyjlbe
utqhsjbhxi
jmmcfrwiml
vfxvqrdzdk
aenkvqbzpo
bfdzgohawd
vdsqzihcsw
jicioserdw
eberxkmhko
vsmxkcsymw
aunqxqooio
fuserissyp
powkmizyqg
pklrsxredz
kvwierqibi
wrzusyeiou
odjaxqedqv
xxntmrkafl
wkgkolzgdv
jxwmcpjiya
pxyhhfzjsh
ewcjkdaymm
taklqmzazs
mwvlhirbzn
lfzultiztz
sn...

output:

80741 7360 12997 56756 21762 69279 19706 92899 32051 16108 12615 1879 72447 9813 56417 20390 75673 70618 83874 3377 81430 27510 35906 318 78492 4181 31614 26126 87058 46805 80019 89834 26112 81576 17287 46675 3778 12080 49218 80725 39440 68765 59667 88079 64766 21185 32866 75456 6053 98140 44498 622...

result:

ok 1 cases (1 test case)

Test #59:

score: 0
Accepted
time: 982ms
memory: 122332kb

input:

1
100000 10
uxfboqjiml
urguovogte
hlfrgfwgkz
lnaljmgocb
cbkdynsxzg
jfggokuktr
fgeeeayprq
glgeqdexax
ccwqbwaake
pexvcckyid
rjvzlorehp
jwrolcaeqq
pwftjauyxv
dtblxopysv
pmvikikgse
pldtousdqo
tgenvzvdnr
payixpmmjr
urkthfeotj
pqomqonmqf
wsnfwcbqce
ynjhtrkmcg
nqjuozngbr
ombhjkloow
fxbwspocpf
ovcbrjolwn
yn...

output:

-1

result:

ok 1 cases (1 test case)

Test #60:

score: 0
Accepted
time: 985ms
memory: 122068kb

input:

1
100000 10
ipzgqbnfvd
sgfrlagntk
gwwweijzea
fxpgdtxgti
waobttsufl
nrdslhdkxf
ssrwruilxq
pdglmfvowa
azjbrlhzff
pchtakzdkl
ajsqpedcoy
pjsukcypln
fiognbhmxj
agpmnzvnms
ikdnsabypt
zaotlspbvj
nummgjsshd
mtteglneuy
eopvrvdxtb
nuwnziuqyv
pmqxpafghb
krwuxxunvh
dnumirddbi
oyiyooimqd
zmlwgndkny
ybxqktsjpq
kv...

output:

-1

result:

ok 1 cases (1 test case)

Test #61:

score: 0
Accepted
time: 985ms
memory: 124848kb

input:

1
100000 10
vhntzmzfjq
lpkanhwnma
hnshcjeytm
rroumhwnmt
jeweevjgqp
bsegdybxio
rwtjvtvlko
fmpcrdsdes
edijyqpurg
zghldxztvl
xbcsrduzmx
tguxmkqcfz
bajotxtuii
zsfgpkokbg
xrgnvbpctc
clxyepehzt
veudydfurf
mavbkeurwo
nfmwtnwspx
uahthuvvxc
vdaadmfinf
kyhxwovgtv
jnqppwnuvt
hiepfckmpa
oxrklvvyof
iintishepc
eq...

output:

10601 10499 88779 27419 76488 63036 62350 82534 60879 23860 36720 45968 98970 32266 63191 8359 99114 76508 74083 19554 35470 52277 73138 87243 50701 60515 94009 4090 9557 31696 95235 16202 16689 81749 97371 50185 82806 75366 89893 44503 60695 2749 99688 99710 42507 30081 26746 8958 76511 95765 62398...

result:

ok 1 cases (1 test case)

Test #62:

score: 0
Accepted
time: 740ms
memory: 123160kb

input:

1
100000 10
uudwzdlejj
ivabpznlij
uqnmtxmmgg
ntzanognix
qdgoodcnun
pekrqklkez
eejprmjekr
pwblriymwp
rievkuhrez
npbdnosxjq
eoeicddyic
hotgqnlmge
iygqxwlogm
pnsgildmtr
rqkpassked
qpsqosjzsm
phxkunmotd
oohtwpcpli
ejeiosheqn
rzrjlvpkfa
ynajbomlnb
awxowbwzxx
hfajxtyefh
ulxeladiwo
mroseowqdn
fszffsdlmi
lm...

output:

94556 44748 65032 40214 91160 19961 53330 62241 65065 1132 73908 32428 31630 30922 36899 66685 7146 16080 68271 55118 46216 71234 25321 16894 90484 764 87512 65892 66155 26297 53606 44126 56333 68288 64437 33181 75637 47118 22200 80283 15502 61155 27334 12158 46344 77003 42205 40241 1257 24936 5336 ...

result:

ok 1 cases (1 test case)

Test #63:

score: 0
Accepted
time: 1000ms
memory: 122328kb

input:

1
100000 10
akvvptzhlm
ukqiqwgjxr
raftyctsec
tljopwxqgm
odkoyjszvv
vuuxpzuwty
vugkbhgrbq
mghdhtbdmh
cmlrrcpkrj
fropiipnog
fippflholr
hxvyifxfhi
dstwpsdbxl
zekzumxmnr
qywqzyxvln
jacdvjvczu
dpmjugphun
hhrhfdjzkx
jfwnfjfokw
ygziaihrgd
ybrhjiwfaj
nketysvhiu
sydarvrsdv
zlhwpjkvmc
ynaolmsimg
tgjfocrgba
kh...

output:

-1

result:

ok 1 cases (1 test case)

Extra Test:

score: 0
Extra Test Passed