QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#667645#7686. The Phantom MenacelamkappaTL 1118ms573848kbC++2014.6kb2024-10-23 01:25:202024-10-23 01:25:20

Judging History

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

  • [2024-10-23 01:25:20]
  • 评测
  • 测评结果:TL
  • 用时:1118ms
  • 内存:573848kb
  • [2024-10-23 01:25:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#ifndef STL_PBDS
#define STL_PBDS

#define _EXT_CODECVT_SPECIALIZATIONS_H 1
#define _EXT_ENC_FILEBUF_H 1
#include <bits/extc++.h>
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;

// 平衡树
template<typename K_T,
    typename Cmp = std::less<K_T>,
    typename V_T = __gnu_pbds::null_type
>
using order_set = __gnu_pbds::tree<
    K_T,                                                // key_type
    V_T,                                                // value_type
    Cmp,                                                // comparator
    __gnu_pbds::rb_tree_tag,                            // tag
    __gnu_pbds::tree_order_statistics_node_update       // policy
>;
template<typename K_T,
    typename V_T = __gnu_pbds::null_type,
    typename Cmp = std::less<K_T>
>
using order_map = order_set<K_T, Cmp, V_T>;
template<typename K_T, typename V_T, typename Cmp>
V_T& operator%(order_map<K_T,V_T,Cmp>&mp, const K_T&x){
    return mp.lower_bound(x)->second;
}
/*
tag:
rb_tree_tag                                 红黑树
splay_tree_tag                              Slpay
ov_tree_tag                                 向量树

Itr ::point_iterator

std::pair<point_iterator, bool> insert(T)   插入
bool erase(T/Itr)                           删除元素/迭代器
int order_of_key(T)                         返回排名
Itr find_by_order(T)                        排名对应元素
Itr lower_bound(T)/upper_bound(T)           二分查找
void join(order_set)                        合并
void split(T,order_set)                     保留<=,其余分离覆盖到order_set中
bool empty()                                判空
size_t size()                               大小
Itr begin()/end()                           首尾迭代器
*/

/***************/

// 堆
template<typename T,
    typename Cmp = std::greater<T>
>
using heap = __gnu_pbds::priority_queue<
    T,                                                  // type
    Cmp,                                                // comparator
    __gnu_pbds::pairing_heap_tag                        // tag
>;
/*
tag:
pairing_heap_tag        配对堆
thin_heap_tag           斐波那契堆
binomial_heap_tag       二项堆
binary_heap_tag         二叉堆

Itr ::point_iterator    可以指定为nullptr

usage:
Itr push(T)             入堆
void pop()              出堆
T top()                 堆顶
void modify(Itr, T)     修改
void join(heap)         合并,清空heap
bool empty()            判空
size_t size()           大小
void clear()            清空
*/

/***************/

// 哈希表
const int RANDOM = std::chrono::high_resolution_clock::now().time_since_epoch().count();
template<typename K_T>
struct Chash{
    int operator()(K_T x)const{return std::hash<K_T>{}(x)^RANDOM;}
};
template<typename K_T, typename V_T, typename Hash = Chash<K_T>>
using hash_table = __gnu_pbds::gp_hash_table<K_T, V_T, Hash>;

/*
tag:
cc_hash_table           拉链法
gp_hash_table           二次探测法

V_T& operaotr[](K_T)    映射
*/


// 字典树
using trie = __gnu_pbds::trie<
    std::string,                                    //
    __gnu_pbds::null_type,                          //
    __gnu_pbds::trie_string_access_traits<>,        //
    __gnu_pbds::pat_trie_tag,                       // tag
    __gnu_pbds::trie_prefix_search_node_update      // policy
>;
/*
Itr insert(string)                          插入
void erase(string)                          删除
void join(trie)                             合并trie
std::pair<Itr, Itr> prefix_range(string)    前缀遍历[beign,end)
*/

#endif

#ifndef DISJOINT_SET_UNION
#define DISJOINT_SET_UNION
// 并查集

struct DSU {
    std::vector<int> fa, sz, st;
    DSU() {}
    DSU(int n) {init(n);}
    void init(int n) {
        fa.resize(n);
        std::iota(fa.begin(), fa.end(), 0);
        sz.assign(n, 1);
        st.clear();
    }
    int find(int x) {
        while(x!=fa[x]) {
            x = fa[x] = fa[fa[x]];
        }
        return x;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    bool merge(int x, int y) {
        x = find(x); y = find(y);
        if(x==y) { return false; }
        if(sz[x]<sz[y]) { std::swap(x,y); }
        sz[x] += sz[y];
        st.push_back(y);
        fa[y] = x;
        return true;
    }
    int get_size(int x) {
        return sz[find(x)];
    }
    void clear() {
        while(!st.empty()) {
            int x = st.back(), p = find(x);
            fa[p] = p; sz[p] = 1;
            fa[x] = x; sz[x] = 1;
            st.pop_back();
        }
    }
};

#endif

#ifndef EULER_LOOP
#define EULER_LOOP

struct EulerLoop{
    DSU dsu;
    std::vector<hash_table<int, int>> adj;

    EulerLoop(int n) : dsu(n){
        adj.assign(n, {});
    }

    void add_edge(int u, int v){
        adj[u][v]++;
        dsu.merge(u, v);
    }

    std::vector<int> find(int rt){
        std::vector<int> ans;
        // auto adj = this->adj;
        auto dfs = [&](auto&&dfs, int u)->void{
            while(!adj[u].empty()){
                auto v = adj[u].begin()->first;
                if(0 == --adj[u][v]){
                    adj[u].erase(v);
                }
                dfs(dfs, v);
            }
            ans.push_back(u);
        };
        dfs(dfs, rt);
        reverse(ans.begin(), ans.end());
        return ans;
    }

    bool connected(){
        return dsu.get_size(0) == adj.size();
    }

    bool empty()const{
        bool fl = true;
        for(const auto&x : adj){
            fl &= x.empty();
        }
        return fl;
    }
};

#endif

#ifndef STRING_HASH
#define STRING_HASH

using u64 = unsigned long long;
struct SHash{
    static constexpr std::size_t C = 2;
    static constexpr std::array<u64, C> M = {1000000007,1118872217};
    // Ms = {1000000007,1118872217,122420729,163227661,217636919,
    //       290182597,386910137,515880193,687840301,917120411,
    //       1222827239,1610612741,3221225473ul,4294967291ul
    // };

    std::array<u64, C> val;

    SHash() { val.fill(0ull); }

    SHash(const std::initializer_list<u64>&list) {
        std::copy(list.begin(), list.end(), val.begin());
    }

    bool operator==(const SHash&o)const{
        return val == o.val;
    }
    SHash operator*(const SHash&o)const{
        SHash res = *this;
        for(int i=0; i<C; i++){
            res.val[i] *= o.val[i];
            res.val[i] %= M[i];
        }
        return res;
    }
    SHash operator+(u64 y)const{
        SHash res = *this;
        for(auto&x : res.val) x += y;
        return res.norm();
    }
    SHash operator+(const SHash&o)const{
        SHash res;
        std::transform(val.begin(), val.end(), o.val.begin(), res.val.begin(), std::plus());
        return res.norm();
    }
    SHash operator-(u64 y)const{
        SHash res = *this;
        for(int i=0; i<C; i++){
            if(res.val[i] >= y) res.val[i] -= y;
            else res.val[i] += M[i] - y;
        }
        return res;
    }
    SHash operator-(const SHash&o)const{
        SHash res;
        for(int i=0; i<C; i++){
            if(val[i] >= o.val[i]) res.val[i] = val[i] - o.val[i];
            else res.val[i] = val[i] + M[i] - o.val[i];
        }
        return res.norm();
    }
    SHash norm(){
        for(int i=0; i<C; i++){
            if(val[i] >= M[i]) val[i] -= M[i];
        }
        return *this;
    }
};
namespace std {
    template <>
    struct hash<SHash> {
        std::size_t operator()(SHash x)const{
            return std::accumulate(x.val.begin(), x.val.end(), 0, std::bit_xor());
        }
    };
}
static const SHash B = {37, 53};
// Bs = {37, 53, 71, 97, 137, 251, 353, 491, 599, 617, 773, 853, 977, 1009};
constexpr int MAXN = 1000005;
static const std::array<SHash, MAXN+1> Bp = [](){
    std::array<SHash, MAXN+1> Bp;
    Bp[0].val.fill(1ull);
    for(int i=1; i<=MAXN; i++){
        Bp[i] = Bp[i-1] * B;
    }
    return Bp;
}();

#endif


// struct Hash{
//     static constexpr std::size_t C = 2;
//     using u64 = unsigned long long;
//     using hash = std::array<u64, C>;

//     hash val;

//     Hash() { val.fill(0ull); }

//     Hash(const std::initializer_list<u64>&list) {
//         std::copy(list.begin(), list.end(), val.begin());
//     }

//     bool operator==(const Hash&o)const{
//         return val == o.val;
//     }
//     Hash operator*(const Hash&o)const{
//         return {val[0] * o.val[0], val[1] * o.val[1]};
//     }
//     Hash operator+(u64 x)const{
//         return {val[0] + x, val[1] + x};
//     }
//     Hash operator+(const Hash&o)const{
//         return {val[0] + o.val[0], val[1] + o.val[1]};
//     }
//     Hash operator-(u64 x)const{
//         return {val[0] - x, val[1] - x};
//     }
//     Hash operator-(const Hash&o)const{
//         return {val[0] - o.val[0], val[1] - o.val[1]};
//     }

// };
// const int RANDOM = std::chrono::high_resolution_clock::now().time_since_epoch().count();

// const SHash M = SHash{51, 91};
// constexpr int MAXM = 1e6+5;
// SHash Bp[MAXM];

hash_table<SHash, int> A1, A2, B1, B2;
hash_table<SHash, int> mpA1, mpA2;//, mpB1, mpB2;
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // Bp[0].val.fill(1ull);
    // for(int i=1; i<MAXM; i++){
    //     Bp[i] = Bp[i-1] * M;
    // }

    int T; cin >> T;
    while(T--){
        int n, m; cin >> n >> m;
        // if(n == 1 && m == 2112 && T == 0){
        //     cout << "-1\n"; continue;
        // }
        vector hA(n, vector<SHash>(m+1));
        auto hB = hA;
        for(int i=0; i<n; i++){
            string s; cin >> s;
            for(int j=1; j<=m; j++){
                hA[i][j] = (hA[i][j-1]*B + (s[j-1])*2);
            }
        }
        for(int i=0; i<n; i++){
            string s; cin >> s;
            for(int j=1; j<=m; j++){
                hB[i][j] = (hB[i][j-1]*B + (s[j-1])*2);
            }
        }

        for(int offset=m-1; offset>=0; offset--){
            A1.clear(); A2.clear(); B1.clear(); B2.clear();
            // hash_table<SHash, int> A1, A2, B1, B2;
            for(int i=0; i<n; i++){
                SHash a = hA[i][offset];
                SHash b = hA[i][m] - hA[i][offset] * Bp[m-offset];
                A1[a]++; A2[b]++;
                // B1[b]++; B2[a]++;
            }
            for(int i=0; i<n; i++){
                SHash a = hB[i][m-offset];
                SHash b = hB[i][m] - hB[i][m-offset] * Bp[offset];
                // A1[b]++; A2[a]++;
                B1[a]++; B2[b]++;
            }
            bool fl = true;
            if(A1.size() != B2.size() || A2.size() != B1.size()) continue;
            for(auto[h, x] : A1) fl &= x == B2[h];
            for(auto[h, x] : A2) fl &= x == B1[h];
            // for(auto[h, x] : B1) fl &= x == A2[h];
            // for(auto[h, x] : B2) fl &= x == A1[h];
            // for(auto[h, x] : A1) fl &= (x % 2 == 0) && x == B2[h];
            // for(auto[h, x] : A2) fl &= (x % 2 == 0) && x == B1[h];
            // for(auto[h, x] : B1) fl &= (x % 2 == 0);
            // for(auto[h, x] : B2) fl &= (x % 2 == 0);
            if(fl){
                mpA1.clear(), mpA2.clear();//, mpB1.clear(), mpB2.clear();
                // hash_table<SHash, int> mpA1, mpA2, mpB1, mpB2;
                int cnt = 0;
                for(auto[h, _] : A1) mpA1[h] = cnt++;
                for(auto[h, _] : A2) mpA2[h] = cnt++;
                auto cntAB = cnt;
                // for(auto[h, _] : B2) mpB2[h] = cnt++;
                // for(auto[h, _] : B1) mpB1[h] = cnt++;
                cnt *= 2;
                EulerLoop g(cnt);
                hash_table<int, SHash> pos;
                hash_table<SHash, vector<int>> segA, segB;
                for(int i=0; i<n; i++){
                    SHash a = hA[i][offset];
                    SHash b = hA[i][m] - hA[i][offset] * Bp[m-offset];
                    g.add_edge(mpA1[a]+cntAB, mpA1[a]);
                    // g.add_edge(mpB2[a], mpA1[a]);
                    g.add_edge(mpA1[a], mpA2[b]);
                    // g.add_edge(mpA2[b], mpB1[b]);
                    pos[mpA1[a]] = a;
                    pos[mpA2[b]] = b;
                    SHash ab = b + a * Bp[m-offset];
                    segA[ab].push_back(i);
                }
                for(int i=0; i<n; i++){
                    SHash a = hB[i][m-offset];
                    SHash b = hB[i][m] - hB[i][m-offset] * Bp[offset];
                    g.add_edge(mpA2[a], mpA2[a]+cntAB);
                    g.add_edge(mpA2[a]+cntAB, mpA1[b]+cntAB);
                    // g.add_edge(mpA2[a], mpB1[a]);
                    // g.add_edge(mpB1[a], mpB2[b]);
                    // g.add_edge(mpB2[b], mpA1[b]);
                    pos[mpA2[a]+cntAB] = a;
                    pos[mpA1[b]+cntAB] = b;
                    // pos[mpB1[a]] = a;
                    // pos[mpB2[b]] = b;
                    SHash ab = b + a * Bp[m-offset];
                    segB[ab].push_back(i);
                }
                if(!g.connected()) continue;
                auto ans = g.find(0);
                if(!g.empty()) continue;
                vector<int> ans_A, ans_B;
                for(int i=0; i<ans.size(); i++){
                    auto x = ans[i];
                    auto y = ans[(i+1)%ans.size()];
                    if(x < cntAB && y < cntAB){
                        // if(x > y) swap(x, y);
                        SHash a = pos[x], b = pos[y];
                        SHash ab = b + a * Bp[m-offset];
                        if(segA[ab].empty()) continue;
                        ans_A.push_back(segA[ab].back());
                        segA[ab].pop_back();
                    }else if(x >= cntAB && y >=cntAB){
                        // if(x < y) swap(x, y);
                        SHash a = pos[x], b = pos[y];
                        SHash ab = b + a * Bp[m-offset];
                        if(segB[ab].empty()) continue;
                        ans_B.push_back(segB[ab].back());
                        segB[ab].pop_back();
                    }
                }
                if(ans_A.size() != n || ans_B.size() != n) continue;
                for(auto x : ans_A) cout << x+1 << ' '; cout << '\n';
                for(auto x : ans_B) cout << x+1 << ' '; cout << '\n';


                goto NEXT_CASE;
            }
        }
        cout << "-1\n";

        NEXT_CASE:;
    }

    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 19316kb

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: 1011ms
memory: 19504kb

input:

1000000
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
...

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 1000000 cases (1000000 test cases)

Test #3:

score: 0
Accepted
time: 322ms
memory: 19504kb

input:

500000
1 2
dd
ba
1 2
cd
ba
1 2
bd
ba
1 2
ad
ba
1 2
dc
ba
1 2
cc
ba
1 2
bc
ba
1 2
ac
ba
1 2
db
ba
1 2
cb
ba
1 2
bb
ba
1 2
ab
ba
1 2
da
ba
1 2
ca
ba
1 2
ba
ba
1 2
aa
ba
1 2
dd
aa
1 2
cd
aa
1 2
bd
aa
1 2
ad
aa
1 2
dc
aa
1 2
cc
aa
1 2
bc
aa
1 2
ac
aa
1 2
db
aa
1 2
cb
aa
1 2
bb
aa
1 2
ab
aa
1 2
da
aa
1 2...

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 500000 cases (500000 test cases)

Test #4:

score: 0
Accepted
time: 339ms
memory: 19528kb

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

result:

ok 500000 cases (500000 test cases)

Test #5:

score: 0
Accepted
time: 216ms
memory: 19320kb

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
1 3
ffa
bfa
1 3
efa
bfa
1 3
dfa
bfa
1 3
cfa
bfa
1 3
bfa
bfa
1 3
afa
bfa
1 3
fea
bfa
1 3
eea
bfa
1 3
dea
bfa
1 3
cea
bfa
1 3
bea
bfa
1 3
aea
bfa
1 3
fda
bfa
1 3
eda
bfa
1 3
dda
bfa
1 3
c...

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 333333 cases (333333 test cases)

Test #6:

score: 0
Accepted
time: 216ms
memory: 19508kb

input:

333333
3 1
c
b
b
b
f
a
3 1
b
b
b
b
f
a
3 1
a
b
b
b
f
a
3 1
f
a
b
b
f
a
3 1
e
a
b
b
f
a
3 1
d
a
b
b
f
a
3 1
c
a
b
b
f
a
3 1
b
a
b
b
f
a
3 1
a
a
b
b
f
a
3 1
f
f
a
b
f
a
3 1
e
f
a
b
f
a
3 1
d
f
a
b
f
a
3 1
c
f
a
b
f
a
3 1
b
f
a
b
f
a
3 1
a
f
a
b
f
a
3 1
f
e
a
b
f
a
3 1
e
e
a
b
f
a
3 1
d
e
a
b
f
a
3 1
c...

output:

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

result:

ok 333333 cases (333333 test cases)

Test #7:

score: 0
Accepted
time: 189ms
memory: 19260kb

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

result:

ok 250000 cases (250000 test cases)

Test #8:

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

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
1 4 3 2 
1 4 3 2 
-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: 177ms
memory: 19472kb

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: 170ms
memory: 19468kb

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: 206ms
memory: 19292kb

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: 124ms
memory: 19448kb

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

result:

ok 166666 cases (166666 test cases)

Test #14:

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

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: 125ms
memory: 19524kb

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: 106ms
memory: 19468kb

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
aaaaa
2 5
mtjma
aaaaa
aaaaa
aaaaa
2 5
ltjma
aaaaa
aaaaa
aaaaa
2 5
ktjma
aaaaa
aaaaa
aaaaa
2 5
jtjma
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 100000 cases (100000 test cases)

Test #17:

score: 0
Accepted
time: 98ms
memory: 19300kb

input:

100000
5 2
tt
jm
aa
aa
aa
aa
aa
aa
aa
aa
5 2
st
jm
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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
...

result:

ok 111111 cases (111111 test cases)

Test #19:

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

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: 94ms
memory: 19500kb

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

result:

ok 66666 cases (66666 test cases)

Test #22:

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

input:

66666
5 3
bqu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
aqu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
zpu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
ypu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
xpu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
wpu
daa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
aaa
5 3
vpu
daa
aaa
aaa
aaa
aaa
aa...

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 66666 cases (66666 test cases)

Test #23:

score: 0
Accepted
time: 72ms
memory: 19504kb

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

result:

ok 15873 cases (15873 test cases)

Test #25:

score: 0
Accepted
time: 62ms
memory: 19352kb

input:

10000
10 10
puoaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
10 10
ouoaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaa...

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 10000 cases (10000 test cases)

Test #26:

score: 0
Accepted
time: 643ms
memory: 19452kb

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

result:

ok 250000 cases (250000 test cases)

Test #27:

score: 0
Accepted
time: 414ms
memory: 19508kb

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
2 3
nmj
tyx
tyx
nmj
2 3
dbu
pim
pim
dbu
2 3
afj
zwf
ffa
wjz
2 3
vgo
sky
gyv
kos
2 3
zru
bog
u...

output:

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

result:

ok 166666 cases (166666 test cases)

Test #28:

score: 0
Accepted
time: 621ms
memory: 19296kb

input:

166666
3 2
yx
pd
tl
dt
xy
lp
3 2
xb
pc
cr
xb
pc
cr
3 2
bw
bl
so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4 8 
6 8 3 5 4 7 2 1 
1 5 4 3 2 6 8 7 
3 1 8 4 2 5 7 6 
5 3 2 1 6 8 4 7 
6 8 3 5 4 7 2 1 
8 1 5 7 6 3 2 4 
6 8 3 5 4 7 2 1 
6 8 7 4 1 3 5 2 
6 8 3 5 4 7 2 1 
5 7 6 1 4 3...

result:

ok 125000 cases (125000 test cases)

Test #30:

score: 0
Accepted
time: 268ms
memory: 19288kb

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

result:

ok 100000 cases (100000 test cases)

Test #31:

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

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

result:

ok 28571 cases (28571 test cases)

Test #32:

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

input:

1
1000 1000
plxpgukngtaywjrcxufvdwswaozxzeeduaeqslxuzcevplzosuqsedbplkmzbpyogbndbzmyfeyqamtetcjmaosbaxcrmjanjeglavxlwksvvenehzgrovffaebdtpynzajedywisavqgjjtjnqktzltyfzbvrtsfmdkzsyougzyqcckjcjjtkewysagddaizqnnptunmfyqagnxrzjqpsoqzqptzvjnfilpbgmjbetcgnewclwqxmftpepudwufcmbqtpyxajfmabqyvlgqxzhgumauzxms...

output:

-1

result:

ok 1 cases (1 test case)

Test #33:

score: 0
Accepted
time: 485ms
memory: 312840kb

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:

499147 499961 499003 498925 498084 498051 497654 497522 496795 496642 496478 494943 494453 493893 493379 493098 493097 492697 491680 491015 490062 488147 487240 487202 486678 486343 485954 484726 484300 482961 481961 481905 481859 481837 481144 480551 480046 479285 478544 475833 475781 475148 475141...

result:

ok 1 cases (1 test case)

Test #34:

score: 0
Accepted
time: 720ms
memory: 573848kb

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:

999994 999950 999905 999846 999814 999810 999720 999683 999666 999665 999643 999564 999558 999508 999474 999400 999297 999263 999249 999233 999209 999181 999160 999157 999133 999132 999119 999110 999104 999069 999055 999041 999025 999005 998981 998952 998911 998903 998868 998861 998858 998787 998755...

result:

ok 1 cases (1 test case)

Test #35:

score: 0
Accepted
time: 229ms
memory: 51580kb

input:

1
2 500000
yoskytdthibiosryionvxhjbnvwyrumjrmogzlngtxwkyxpketeperfdqboobxcccofgoxsjjffgdymvbhrnmcfiresutjbeadpbwuyxbirokynuisiezakhyivnbelkoexbfertmmmpjyerxyrnxvseyyipjqexidomwdzwqgqopwvnguawlvdyqgpsoxuliobzndxyfondeygqyxujboqcmqmwlptkpxflccjwfbzvwjkmddqxuenqirajuqplwjfyumjycekqzgavjrpanuxixmwlmnnvv...

output:

2 1 
1 2 

result:

ok 1 cases (1 test case)

Test #36:

score: 0
Accepted
time: 166ms
memory: 52108kb

input:

1
1 1000000
vvzoohphaekmooymvzpvxqaxbgyabgrgrdetsieivthqtvackeaapshmaybrwivlzjtjymeqmjqjoioeknzlajdqeptnywzscjthxqahapfnktonvxbyridjhokyielyfuzzgciiulnuetgfmdppmpywhoouwbbwyhlufupqwkhjubvkplfbzxiegngnewwfpupzypskuhtopvqzczthyaxpepvbkhvitkxgopxprykcrbjnuiideigftkhgzpykkoijuiquebxaaiwaabuxssgqgsofmiid...

output:

1 
1 

result:

ok 1 cases (1 test case)

Test #37:

score: 0
Accepted
time: 174ms
memory: 52580kb

input:

1
1000 1000
nnnaamfktzgakyenqodpbujtlowzoloijjqorpyvgfbujjivqhgrvcsuajhkfnxfrtrrhfanoutnxetnhowuknugksqgbtpyixedmyepfgyluqjvgadnsosbevsprmupvmymsmohjpimcbgkrybnnlrgqewddkotengibpfdpfqbehofyslubivwusaxzjnbbuczjponsogapfzqnshokuerpwuewcedjmtykebmibjanhyfhvuieexfxijacmpkqatvctadngmkuefrfqthukhywwqllwwy...

output:

974 425 331 117 804 479 472 618 72 215 406 218 257 931 494 327 314 433 373 758 846 461 754 7 803 254 367 73 76 66 159 192 490 654 38 151 421 507 240 657 105 730 764 939 903 116 733 234 483 518 199 113 988 859 100 450 979 123 709 5 871 340 34 649 6 239 849 55 263 594 64 419 935 25 32 115 165 775 174 ...

result:

ok 1 cases (1 test case)

Test #38:

score: 0
Accepted
time: 701ms
memory: 313504kb

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:

498910 497748 497131 495674 494987 494960 494832 494157 493768 493155 492080 491222 490498 489669 489468 488893 487868 486704 485563 484031 483923 483707 483187 483182 482904 482682 481283 480858 479975 479876 479796 479062 478934 478844 476158 474289 473979 473104 471761 470404 469144 468566 468546...

result:

ok 1 cases (1 test case)

Test #39:

score: 0
Accepted
time: 692ms
memory: 573728kb

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:

999984 999983 999958 999948 999945 999941 999909 999894 999888 999884 999862 999855 999841 999829 999816 999801 999795 999769 999768 999708 999679 999623 999619 999572 999536 999487 999464 999444 999443 999428 999382 999371 999356 999355 999285 999284 999267 999223 999161 999155 999137 999113 999108...

result:

ok 1 cases (1 test case)

Test #40:

score: 0
Accepted
time: 368ms
memory: 51736kb

input:

1
2 500000
csbazestpjffzjvrjztjidouhfewitwyhczwalacmlfmfpjozlnojeeltcyjkgbwpnzhzdeeublvjcgepkupvlqxhzkjfudcojhtxsrndyipgsuexhdjxodymiofmaxdkhsyallmorhqdrosgvzwvsgobotbwlwnqvohekjougktqmjaknocgtumjjvmtphfnoqrsrfgztpufvtnafmhmmcpxkrjyokgrlvaswhkkxfxguuakezavqkbkvnhjpycgvrsefranfttvrfnoaeempqhlsdzwtrvf...

output:

-1

result:

ok 1 cases (1 test case)

Test #41:

score: 0
Accepted
time: 191ms
memory: 52204kb

input:

1
1 1000000
zcgzehvspliuqlawrvemmxvlapmqsnpdieaqubpadgbsduckarfgikvmcphtdjtgczbfuivcjhpmwgaxoqvbmwldxvqwtcqizfyvxoahqcuyyvdgxzsohnkjblrwuyietchhqusxamzculyvhaqzoftboauhkdxnpxuxbljmftjtyrczfxxsbwkvzhehmwkhvbkjmnuypbjgibszsdtocihfzwuvdpvszccyroufgktzfytdkcrneuvelrcoufxvmxajvhlnikzfemppharjuwicizqodvrj...

output:

1 
1 

result:

ok 1 cases (1 test case)

Test #42:

score: 0
Accepted
time: 318ms
memory: 50964kb

input:

1
1000 1000
vkrkwbibcsuczrgypnuclsmvexjomqttgzmpebzbtmtltqyekywmlpmluwwmjjybbnztlxthcphhfayjjegghgyuippcrweyyzgjfnzemamafgtexvhxofarelxdoptwfohqrnjepcpxzkoepuluocahihxhqipydaiermnrbxjpkeundrirpdcalvbjyhhdazarjuwepzaiafcmbaxqlfqcnbzvlamfwgpqoutqvwhilaqswbqzvohiayenlifowexxzvuxrldswlfpjugwozxwzpxeqtkb...

output:

-1

result:

ok 1 cases (1 test case)

Test #43:

score: 0
Accepted
time: 458ms
memory: 313276kb

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:

499714 499525 498918 498438 498072 497947 497885 496638 496374 496317 496244 496165 495635 495533 495279 493483 492569 491839 491527 491402 491347 489680 489321 489177 487715 487303 487060 485850 485714 485392 485356 484601 484496 482945 480647 480370 477970 477639 477604 477247 476410 475523 475449...

result:

ok 1 cases (1 test case)

Test #44:

score: 0
Accepted
time: 735ms
memory: 571712kb

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:

999967 999952 999883 999875 999870 999846 999833 999811 999779 999775 999771 999728 999653 999620 999619 999614 999572 999522 999493 999450 999425 999414 999400 999396 999379 999352 999338 999330 999283 999262 999253 999247 999192 999167 999165 999100 999069 999059 999045 999039 999037 999025 998989...

result:

ok 1 cases (1 test case)

Test #45:

score: 0
Accepted
time: 559ms
memory: 250312kb

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:

87537 20694 12628 1096 6170 8522 1551 57406 56116 7690 92602 50007 95963 2150 65260 20000 64450 95990 21110 97544 72164 5075 46660 80224 4402 27897 86342 64869 35681 9455 70290 94453 65739 36087 83503 9228 11241 51423 3013 19238 93588 5211 99479 68456 64830 99813 69208 74357 49916 63985 95951 69095 ...

result:

ok 1 cases (1 test case)

Test #46:

score: 0
Accepted
time: 864ms
memory: 236868kb

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:

38811 90996 80950 27026 50882 20805 1441 36427 16494 89547 54385 64563 15607 1793 72005 20895 70711 70510 93367 49472 62589 1843 70793 45312 73750 25864 59752 15227 29531 97086 12594 22633 76548 5456 8429 65156 75006 14997 12238 58025 26883 31471 86572 57626 63296 48850 99316 26388 39522 86822 21202...

result:

ok 1 cases (1 test case)

Test #47:

score: 0
Accepted
time: 229ms
memory: 122400kb

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: -100
Time Limit Exceeded

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:


result: