QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#662449#897. 基本子串字典QingyyxAC ✓1032ms266812kbC++2010.0kb2024-10-21 00:28:272024-10-21 00:28:28

Judging History

This is the latest submission verdict.

  • [2024-10-21 00:28:28]
  • Judged
  • Verdict: AC
  • Time: 1032ms
  • Memory: 266812kb
  • [2024-10-21 00:28:27]
  • Submitted

answer

#include <bits/stdc++.h>
#define ll long long
#define enl putchar('\n')
#define all(x) (x).begin(),(x).end()
#define debug(x) printf(" "#x":%d\n",x);
using namespace std;
const int MAXN = 2e5 + 5, LOG = 19;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
typedef pair<int, int> pii;
char buf[1 << 21], * p1 = buf, * p2 = buf, obuf[1 << 21], * o = obuf, of[35];
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll qpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1)res = res * a % mod; n >>= 1; a = a * a % mod; }return res; }
template <class T = int>inline T read() { T s = 0, f = 1; char c = gc(); for (; !isdigit(c); c = gc())if (c == '-')f = -1; for (; isdigit(c); c = gc())s = s * 10 + c - '0'; return s * f; }
inline void read(int* a, int n) { for (int i = 1; i <= n; ++i)a[i] = read(); }
inline int inal(char* s) { int n = 0; for (s[0] = gc(); !isalpha(s[0]); s[0] = gc()); for (; isalpha(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline void outd(int* a, int n) { for (int i = 1; i <= n; ++i)printf("%d ", a[i]); enl; }
int n, m, q;
struct SAM { //最多2n-1个点和3n-4条边
    int len[MAXN << 1], link[MAXN << 1], ch[MAXN << 1][26]; //我们记 longest(v) 为其中最长的一个字符串,记 len(v) 为它的长度。
    int cnt[MAXN << 1], pos[MAXN], rpos[MAXN << 1], dif[MAXN << 1];
    int cur, lst, siz;
    SAM() { clear(); }
    void clear() {  //设置起始点S
        memset(ch, 0, sizeof(int) * (siz + 1) * 26);
        memset(cnt, 0, sizeof(int) * (siz + 1));
        memset(id, 0, sizeof(int) * (siz + 1));
        memset(rpos, 0, sizeof(int) * (siz + 1));
        len[0] = 0;
        link[0] = -1;
        siz = 0;    //siz设置成0实际上有一个点,方便标记
        lst = cur = 0;
    }
    void extend(int c, int id) {
        lst = cur, cur = ++siz;
        len[cur] = len[lst] + 1;
        cnt[cur] = 1;
        for (; ~lst && !ch[lst][c]; lst = link[lst])ch[lst][c] = cur;

        if (lst == -1) {
            link[cur] = 0;
        } else {
            int q = ch[lst][c];
            if (len[lst] + 1 == len[q]) {
                link[cur] = q;
            } else {        //克隆的点是q(lst的c后继)
                int clone = ++siz;
                link[clone] = link[q];
                len[clone] = len[lst] + 1;
                link[cur] = link[q] = clone;
                for (; ~lst && ch[lst][c] == q; lst = link[lst])ch[lst][c] = clone;
                memcpy(ch[clone], ch[q], sizeof(ch[q]));
            }
        }
        pos[id] = cur;
        rpos[cur] = id;
    }

    vector<int>e[MAXN << 1];
    int fa[MAXN << 1][LOG];
    int sz[MAXN << 1], son[MAXN << 1], top[MAXN << 1], edr[MAXN << 1];      //edr链底标号
    void dfs(int x) {
        for (int i = 1; i < LOG; ++i)
            fa[x][i] = fa[fa[x][i - 1]][i - 1];
        sz[x] = 1;
        for (auto v : e[x]) {
            dfs(v);
            sz[x] += sz[v];
            rpos[x] = max(rpos[x], rpos[v]);
            if (!son[x] || sz[son[x]] < sz[v] || sz[son[x]] == sz[v] && rpos[son[x]] < rpos[v])
                son[x] = v;
        }
    }
    int id[MAXN << 1], bc, bac[MAXN << 1];
    // id 重链的编号 ,bc为链的个数,bac编号对应的SAM节点
    void dfs(int x, int rt) {
        top[x] = rt;
        if (son[x])
            dfs(son[x], rt);
        if (son[x]) edr[x] = edr[son[x]];
        else edr[x] = rpos[x];
        for (auto v : e[x])
            if (v != son[x]) {
                bac[id[v] = ++bc] = v;
                dfs(v, v);
            }
    }
    void build() {
        for (int i = 1; i <= siz; ++i) {
            e[link[i]].push_back(i);
            fa[i][0] = link[i];
            dif[i] = len[i] - len[link[i]];
        }
        dfs(0); son[0] = 0;
        dfs(0, 0);
    }
    // void merge() {
    //     for (int i = siz; i >= 1; --i)if (!id[i])
    //         for (int c = 0; c < 26; ++c)if (ch[i][c]) {
    //             id[i] = id[ch[i][c]];
    //             break;
    //         }
    // }


    int FindR(int l, int r) {
        int x = pos[r];
        for (int i = LOG - 1; i >= 0; --i)
            if (len[fa[x][i]] >= r - l + 1)
                x = fa[x][i];
        return x;
    }

    int flen(int x) {
        return len[link[x]] + 1;
    }
}sam, rsam;
char s[MAXN];
// vector<int>row[MAXN], col[MAXN];
// int Ec = 0;
array<int, 3> ans[MAXN];

void work() {
    for (int i = 1; i <= n; ++i)
        sam.extend(s[i] - 'a', i);
    reverse(s + 1, s + n + 1);
    for (int i = 1; i <= n; ++i)
        rsam.extend(s[i] - 'a', i);
    sam.build(); rsam.build();
    // for (int i = 1; i <= sam.siz; ++i) {
    //     int r = sam.rpos[i],
    //         l = r - sam.len[i] + 1,
    //         u = rsam.FindR(n - r + 1, n - l + 1);
    //     if (r - l + 1 == rsam.len[u]) sam.id[i] = rsam.id[u] = ++Ec;
    // }
    // sam.merge(); rsam.merge();
    // for (int i = sam.siz; i >= 1; --i)
    //     row[sam.id[i]].push_back(i);
    // for (int i = rsam.siz; i >= 1; --i)
    //     col[rsam.id[i]].push_back(i);
    // outd(sam.edr, sam.siz);
    // outd(rsam.edr, rsam.siz);

}


struct SGT {    //求区间出现最靠右(大)的元素
    int L, R, sum[MAXN << 3];
    void init(int l, int r) { L = l, R = r; }
    void modify(int p, int l, int r, int tar, int v) {
        if (l == r)return sum[p] += v, void();
        int mid = (l + r) >> 1;
        if (tar <= mid) modify(p << 1, l, mid, tar, v);
        else modify(p << 1 | 1, mid + 1, r, tar, v);
        sum[p] = (sum[p << 1] + sum[p << 1 | 1]);
    }
    void modify(int tar, int v) {
        modify(1, L, R, tar, v);
    }
    int queryT(int p, int l, int r, int ql, int qr) {
        if (!sum[p] || ql > r || qr < l)return -inf;
        int mid = (l + r) >> 1;
        if (l == r)return mid + L - 1;
        int qryr = queryT(p << 1 | 1, mid + 1, r, ql, qr);
        if (qryr == -inf)return queryT(p << 1, l, mid, ql, qr);
        else return qryr;
    }
    int queryG(int p, int l, int r, int ql, int qr) {
        if (!sum[p] || ql > r || qr < l)return inf;
        int mid = (l + r) >> 1;
        if (l == r)return mid + L - 1;
        int qryl = queryG(p << 1, l, mid, ql, qr);
        if (qryl == inf)return queryG(p << 1 | 1, mid + 1, r, ql, qr);
        else return qryl;
    }
    int queryS(int p, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr)return sum[p];
        int mid = (l + r) >> 1, res = 0;
        if (ql <= mid)res += queryS(p << 1, l, mid, ql, qr);
        if (qr > mid)res += queryS(p << 1 | 1, mid + 1, r, ql, qr);
        return res;
    }
    array<int, 3> query(int ql, int qr) {
        return {queryT(1, L, R, ql, qr), queryG(1, L, R, ql, qr), queryS(1, L, R, ql, qr)};
    }
}sgt;

struct QRY {
    int id, tpos, rpos, len;    //询问id,链顶端sam的下标,这个点的pos,链长
};
vector<QRY>Q[MAXN << 1];

void prv(int id, int l, int r) {
    int u = sam.FindR(l, r), v = rsam.FindR(n - r + 1, n - l + 1);
    for (u = sam.link[u], v = rsam.link[v]; u && v;) {
        int fu = sam.top[u], fv = rsam.top[v];
        int dl = sam.flen(fu), dr = sam.len[u];     //链对应所以点的长度 [dl,dr]
        int il = rsam.flen(fv), ir = rsam.len[v];   //[il,ir]
        Q[sam.id[fu]].push_back({id, fv, v, min(r - l, sam.len[u])});
        if (dl < il)v = rsam.link[fv];
        else u = sam.link[fu];
    }
}

struct OPT {
    array<int, 3> operator()(array<int, 3> a, array<int, 3> b) {
        return {max(a[0], b[0]), min(a[1], b[1]), a[2] + b[2]};
    }
}opt;

struct seg { int d, x, y, op; };    // (id,len) (反sam的链底标号,串长),构成的二维平面的线段
void slv(int lid) {
    vector<seg>vec;
    for (int x = sam.bac[lid]; x; x = sam.son[x]) {
        int flen = sam.flen(x), r = sam.rpos[x], l = r - flen + 1, u = rsam.FindR(n - r + 1, n - l + 1);
        int nxt = rsam.edr[u], k = flen - nxt;
        // printf("%d %d\n", nxt, k);
        vec.push_back({sam.len[x] - k, k, k, 0});   //出现位置,斜线,最长的len,因为链的标号是连续的,所以直接-k
        vec.push_back({nxt - 1, k, k, -2});         //消失位置,最短的len
    }
    // --------------
    // -------|------ y
    // -------|------
    // -------|------ x
    // --------------
    //        d

    for (auto& [id, tp, rp, len] : Q[lid]) {
        int x = rsam.edr[tp], l = rsam.flen(tp), r = min(rsam.len[rp], len);
        if (l <= r)vec.push_back({x, l - x, r - x, id});    //竖线,旋转后-x
    }
    sort(all(vec), [](auto a, auto b) {return a.d > b.d || (a.d == b.d && a.op < b.op); });
    for (auto& [d, x, y, op] : vec) {       //y轴从上往下
        // if (op <= 0)printf("%d += %d\n", x, op + 1);
        if (op <= 0)sgt.modify(x, op + 1);
        else {
            array<int, 3> s = sgt.query(x, y); s[0] += d + n + 5; s[1] += d + n + 5;
            // printf("%d %d %d\n", s[0], s[1], s[2]);
            ans[op] = opt(ans[op], s);
        }
    }
}

void solve() {
    n = inal(s + 1);
    work();
    m = read();
    for (int i = 1; i <= m; ++i) {
        int l = read() + 1, r = read() + 1;
        prv(i, l, r);
        ans[i][1] = inf;
    }
    sgt.init(-n - 4, n + 4);
    for (int i = 1; i <= sam.bc; ++i)
        slv(i);
    for (int i = 1; i <= m; ++i)
        if (ans[i][2] == 0)
            printf("-1\n");
        else
            printf("%d %d %d\n", ans[i][1], ans[i][0], ans[i][2]);
}
signed main(signed argc, char const* argv[]) {
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    //=============================================================
    int TxT = 1;
    // TxT = read();
    while (TxT--)
        solve();
    //=============================================================
#ifdef LOCAL
    end :
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 102ms
memory: 101476kb

input:

ejdzjvhfouduzopksvrmktcerxlnwcaspfztkzjcguzbkloievrzdxutubkvhpwzedsebpjscfhswjzqanpdwjlljxubvoyuaauwxyyjzoryfthvjkbwqbippholdbmrpszwzuhkxxktzclviearfkwdegsrwjttxymiepczmgilmplnvulwbmlngpkxgcvyizlpzwuqfqxcneyjtkozanlkwkdqzsjjberqnyvlqoxrrkpbhyrlugfkwiepnjewhqjqhsursplcpznzfljvdzcrigjjxsmegrrhzetnvzql...

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

result:

ok 50000 lines

Test #2:

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

input:

mmrqqmrrqmkhmkmkmkbhmhmgncyrhnbrrimkmkmktmkhmkhmkhqbsqbmmmmmmkhmkhqkhmkhqmkmkmkmkappsohmkhqkhmhmkhqkhmmbqbmmmmmmqbmmmmmmuwyvkbhkbhkbhkbhkbhbqbmmmmmmqbqbmmmmmmqbqbmmmmmmqihqkhmkhqmkmhqkhmkhqmkmymkhqmkmyvdnjurrimkmkmktrrimkmkmktrrimkmkmktynjurrimkmkmktnjurrimkmkmktnjurrimkmkmktrhnbrrimkmkmktrhnbrrimkm...

output:

556 1853 2
13 1254 7
12 1493 9
405 1071 2
1119 1119 1
6 394 5
1137 1137 1
4 795 3
6 1326 4
4 1084 4
359 1613 3
5 288 4
16 1738 7
79 710 2
7 1500 8
589 589 1
138 1510 3
136 1774 8
4 1886 10
2 1978 4
4 1886 10
589 1944 2
948 948 1
201 1498 2
345 345 1
11 1366 2
136 838 4
310 1665 2
39 1761 3
1093 2448...

result:

ok 50000 lines

Test #3:

score: 0
Accepted
time: 69ms
memory: 106812kb

input:

oygebgetdmkgpucchnlxqbwrubfyhdkewizorsidqwodzzwrubfyhdwrubfyhdxsqtgmfdcemxzlnjhjtugmfdcemgmfdcemgmfdcemgmfdcemubfyhdkubfyhdkubfyhdkubfyhdkubfyhdkrymyzvetdmkgpuetdmkgpuetdmkgpuetdmkgpuetdmkgputqbqjjyxmkkubfyhdkkubfyhdkkubfyhdkkubfyhdkkubfyhdkkubfyhdkkubfyhdkqbadmavokubfyhdkubfyhdkubfyhdkubfyhdkubfyhd...

output:

2 9058 4529
2 8326 4163
2 6010 3005
2 5722 2861
2 5022 2511
2 8146 4073
1 4949 2475
1 2951 1476
2 8922 4461
2 5546 2773
1 7117 3559
1 5465 2733
2 7464 3732
2 5058 2529
1 7669 3835
1 7789 3895
1 7485 3743
1 5273 2637
2 5058 2529
2 5998 2999
1 6199 3100
1 4345 2173
1 4831 2416
2 8634 4317
1 5993 2997
...

result:

ok 50000 lines

Test #4:

score: 0
Accepted
time: 140ms
memory: 113848kb

input:

jnnoffjsyjmzfwfcdagqxcoyzfjtjdnmjnnzczzybsmzfwfofviuoinoffjsnzczzyawfofkpetfzfmdagrcuetbvmpetfkwcusxogogyjpxgqxcoreiwqdsxwykpoxfmxfiodunzczzybsmzfbsjysmzxlmoprcuetbvmpyzrzfbsjyphlxzybsmzfwfofviuoivetfkwcusxogogyjpxgrhhzfjtjdinnoffjsyjmemogogyjpxgqxljuwpdrbzzretfkwcuzmzfwfofvpsfoprcuetbvmtcfwfcdagqxf...

output:

1 967 2
8 1211 2
499 499 1
1535 1535 1
230 230 1
2099 2099 1
509 509 1
332 332 1
608 608 1
1619 1619 1
1087 1087 1
1525 1525 1
1079 1079 1
455 455 1
309 309 1
245 245 1
433 433 1
1596 1596 1
446 446 1
887 887 1
1497 1497 1
841 841 1
40 486 2
50 963 2
1349 1349 1
1 1408 2
1291 1291 1
1939 1939 1
85 1...

result:

ok 50000 lines

Test #5:

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

input:

lpqpqppqpqppqppqpqppqpqppqppqpqppqppqpqppqpqppqppqpqppqpqppqppqpqppqppqpqppqpqppqppqpqppqppqpqppqpqppqppqpqppqpqppqppqpqppqppqpqppqpqppqppqpqppqpqppqppqpqppqppqpqppqpqppqppqpqppqppqpqppqpqppqppqpqppqpqppqppqpqppqppqpqppqpqppqppqpqppqppqpqppqpqppqppqpqppqpqppqppqpqppqppqpqppqpqppqppqpqppqpqppqppqpqpp...

output:

2 28208 12
1 22196 11
1 12549 9
1 13112 8
1 16603 12
3 6828 11
3 24424 15
2 21454 13
1 24922 8
1 22665 13
1 25809 13
2 23988 11
2 8681 10
1 20581 12
2 16257 10
1 21957 9
1 17814 13
3 14866 12
2 25876 11
1 19372 9
3 17633 9
5 18588 10
1 22565 13
3 22568 8
2 12532 10
5 20711 11
1 21671 11
1 16798 12
3...

result:

ok 50000 lines

Test #6:

score: 0
Accepted
time: 519ms
memory: 195132kb

input:

fqmsihplprqnqqiinahlxivhpazabczbkroqhvdwipsedcwdoajmuyaymjktgpmbccmcpkuoqovmzqkehohupeltdznfvzvrwswhiyatdacoxgmjkrkmqkzlrzclxsowurnvxverfihziptkxgedqhpzncibpyppbttpbiyflvqwgmtdeseeqmgrvvbiedspjocdrvkwbgbmjaloqmgulyofflkmqzaqhitggjhtfuomgwcuinjepkzutyaryhkidybadvebzkyfnrutdllpkndcauptzjgqtxkgrehvudia...

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

result:

ok 200000 lines

Test #7:

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

input:

mffmffmfmffmffmfmffmfmffmffmfmffmffmfmffmfmffmffmfmffmfmffmffmfmffmffmfmffmfmffmffmfmffmffmfmffmfmffmffmfmffmfmffmffmfmffmffmfmffmfmffmffmfmffmfmffmffmfmffmffmfmffmfmffmffmfmffmffmfmffmfmffmffmfmffmfmffmffmfmffmffmfmffmfmffmffmfmffmffmfmffmfmffmffmfmffmfmffmffmfmffmffmfmffmfmffmffmfmffmfmffmffmfmffm...

output:

1 112967 15
1 75896 12
2 105017 12
1 45210 11
1 107089 15
2 116198 12
3 104510 11
2 86195 14
1 81422 14
3 54081 11
1 74329 12
1 54221 10
2 92660 12
1 80199 13
5 62623 11
2 95314 11
5 81685 15
3 96030 12
2 61769 14
2 27276 11
1 81990 16
1 52500 15
1 115632 15
2 55405 9
1 68620 13
3 110426 14
2 66016 ...

result:

ok 200000 lines

Test #8:

score: 0
Accepted
time: 510ms
memory: 192604kb

input:

orjzbzsidimqhlftjqjrpzgdpsmufzccurjnsvotlbrhtjikcbrbsyhxubacgdvxuuhcidpbxdjomhvwtqxlvrykwaupthxsnhpahixdshtsewxwudmsehqcljnufoigeqjagrflaaindvcdzaesncrucsajyxuyailrfqtybxgxalfanbavdbypemsbaoayclsmsndnjxdzvrfsbjnabxixbolvblkuwkhshfscfdxjvgghdsbiirmaogofcwetqwwovcylgwnqwfjchgsvukdtkkacuotolylqcyndisnu...

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

result:

ok 200000 lines

Test #9:

score: 0
Accepted
time: 717ms
memory: 243560kb

input:

ijdkzqqczzxhfqcdzzzzhdaehqqqqqczebmipqmmimimimiczeczeoguwkzebmizebmizebmifqmiczmifmifmifdkzdkzdkzihhlcdzzzzhcdzzzzhcgcifmifmifivskhjdhcdzzhcdzztfdkzdfdkzdfdkzdfdkzdzhcdzztfdkzdfdkzdzhcdzztfdkzdfdkzdbjxgckbuyqltftftftftftfqqczebmipqmmimimcbuyqlbuyqldzzzzhcdzzzzhcgcifmifmifidzzzzhcdzzzzhcgcifmifmifidz...

output:

711 2386 2
1 4155 2
954 7695 3
182 4363 2
1 2610 3
1 5938 4
3764 3764 1
5831 5831 1
12 3704 3
52 3402 2
3377 3377 1
3225 3225 1
2144 2144 1
651 3703 3
1072 5253 2
3782 3782 1
1625 5806 2
1 2549 3
5927 5927 1
6245 6245 1
9 5089 2
8 7115 5
5360 5360 1
2004 2004 1
28 8104 4
1398 1398 1
14 4560 3
3859 3...

result:

ok 200000 lines

Test #10:

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

input:

rrrrtrtrrrrrgkrrrbenhabenbenhahahayahaaharrrrgbbebebeoihannnnnhnhahahhahahhahahskkkkkkkkrrrgrrrgrrrgrrrgrrrrrrrrrrrrqfvlfyahaaharrryahaaharrrqqynhahahayahaahanhahahayahaahanhahahayahaahabebebeoibebebeoibebebeoirzmcnjrbebebeoihanbebebeoihanrrrgrrrgrrrrrrrrrrrgrrrgrrrrrrrroyahaaharrrrgbbebebeoihannnnn...

output:

72 5023 2
4157 9554 2
1 3413 3
1 4409 3
1832 4524 2
150 7215 3
136 4348 4
2836 2836 1
1 9327 5
638 3330 2
4934 4934 1
1194 6138 2
10 7723 4
2 4773 5
19 5550 3
66 7619 2
2534 5249 2
1398 4113 2
10 7308 4
1044 8349 3
1 7619 4
554 6191 2
4 3071 2
4195 9832 2
4346 9983 2
1 8200 4
710 7775 3
93 4840 2
2 ...

result:

ok 200000 lines

Test #11:

score: 0
Accepted
time: 421ms
memory: 235332kb

input:

kynffoqykynffoqubztubzypkpeakynkynkynarnftsskwnlynkynynkynynkynynkynkxwkwnlynkynykwnlynkynykwnlynkynycfjpnbqqcobqqcbqqcbqqcbqqcbqqcbqqcbqqcbqqcbqqcbqqctzkxpakynkyakynkyakynkyakynkyyuwjfjpnbqqcobfjpnbqqcobfjpnbqqcobfjpnbqqcobfjpnbqqcobfjpnbqqcobwtfmepycsfvewueeynkynkynarynkynkynarynkynkynarynkynkynar...

output:

1 39521 4942
3 11611 1452
4 36044 4506
1 25345 3170
8 25776 3222
1 25052 3133
2 31074 3885
2 26682 3336
2 35223 4404
1 21910 2740
1 27545 3445
1 41518 5191
2 37111 4640
1 24649 3082
2 19909 2490
1 40006 5002
2 41690 5212
2 31810 3977
1 22564 2822
1 38833 4856
1 26948 3370
8 35672 4459
1 29620 3704
5...

result:

ok 200000 lines

Test #12:

score: 0
Accepted
time: 293ms
memory: 201884kb

input:

amezpqzdfcezezujzivlcxqpuafilacgywkmlzdfcezdfcejbzeamuszlvblfcezezufcezezufcezezudcezezufcezezufcezezufujpuafilacgypuafilacgypuafilacgypuafilacgydsnrlybfdcezezufccezezufccezezufccezezufccezezufccezezufccezezufcezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezezez...

output:

1 27489 27489
1 30282 30282
1 25244 25244
1 26472 26472
1 22122 22122
1 19073 19073
1 30941 30941
1 28853 28853
1 31504 31504
1 25281 25281
1 22887 22887
1 25247 25247
1 32188 32188
1 29211 29211
1 25912 25912
1 26458 26458
1 23533 23533
1 15452 15452
1 25101 25101
1 31263 31263
1 32800 32800
1 3038...

result:

ok 200000 lines

Test #13:

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

input:

vwerjycxrmqpxskgskyjywebpamlztkiamenclhqluhvviwhkkiamlztpqcjhcxnlswiupqiciwhkkiamjelcxrmqpxswghwzcxnllswiknayqgbhtpgtzjtkiamenclkyjywebpamlxfssxxrxhiigijssxxrxhkyjylswghwzcxnllswbhkabdeolswiknayqgbhtyxpvapbmjpbssxxrxhiigbxfwecjhtsqokiamenclkyjywebpamlxfssgpbhkabdeolswiknwzcxnllklclhqluhvvihiigbxfwec...

output:

6033 6033 1
6926 6926 1
5629 5629 1
6942 6942 1
5535 5535 1
25 3797 2
7331 7331 1
9 4269 2
1984 1984 1
4918 4918 1
6056 6056 1
1519 1519 1
3657 3657 1
3044 3044 1
1894 1894 1
4921 4921 1
15 3344 2
4355 4355 1
2931 2931 1
29 3977 2
4444 4444 1
4537 4537 1
4501 4501 1
5809 5809 1
5055 5055 1
2676 2676...

result:

ok 200000 lines

Test #14:

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

input:

kwgyrspsryokpskkyrdyqdgcgkkywbgcddakpseyrdykluycjegkkyebsykymlavgfknkyvgtpjrdqlavgfknzhajgtpjrdqlaijxbltklzxyrdgtocqdjdqlaijuwjelkksryokpskkyrmqfpqgueodrobtrsprztzrcgxovqejlhdspkpskkyrqwtjnypueeovqejzzdhuxwkluycjegkgkkywbgcddakpseyrdyklucghpdqlavgfknzhajgtpjrdqlaijxghcmsmdhbkmsprztzrcgxovqejlhpiiitt...

output:

3803 3803 1
36 1549 2
4383 4383 1
4312 4312 1
5392 5392 1
3874 3874 1
2427 2427 1
1640 1640 1
4711 4711 1
2711 2711 1
5237 5237 1
1190 1190 1
1059 1059 1
2934 2934 1
4117 4117 1
5489 5489 1
1540 1540 1
2849 2849 1
4968 4968 1
1 4279 3
2 7188 2
5365 5365 1
3451 3451 1
5779 5779 1
3546 3546 1
2987 298...

result:

ok 200000 lines

Test #15:

score: 0
Accepted
time: 1032ms
memory: 266812kb

input:

exexeexefbfbffbfbffbffbfbffbfbffbffbfbffbffbfbffbfbffbffbfbffbfbffbffbfbffbffbfbffbfbffbffbfbffbffbfbffbfbffbffbfbffbfbffbffbfbffbffbfbffbfbffbffbfbffbfbffbffbfbffbffbfbffbfbffbffbfbffbffbfbffbfbffbffbfbffbfbffbffbfbffbffbfbffbfbffbffbfbffbffbfbffbfbffbffbfbffbfbffbffbfbffbffbfbffbfbffbffbfbffbfbffb...

output:

3 79473 13
1 116370 15
2 39673 13
1 84202 18
3 74125 13
1 90780 15
2 103326 13
1 82127 11
1 108341 12
1 79618 13
2 79507 12
1 113524 14
1 76401 10
1 46801 11
2 98817 16
2 78331 13
1 101763 13
3 57746 9
1 62773 12
2 97327 10
1 87271 13
1 93431 10
2 67927 11
1 61409 14
2 52925 11
2 55206 10
1 69597 14...

result:

ok 200000 lines

Test #16:

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

input:

uhsubldcdaudhstzvgzupbwirwdzurvqhluslsnqibiafvzlqpuizuylyvxwuepkmhovjqrwodehrjadypwuswakxpfiegtduvzwkyryiisnkwgngzcsntnrbkusvxnfgbpgplwmvktrghwkcshkkfcdoaommcgwdwvyujxxemlnqgoyrewkzhgcqihjmxgkuzgeibdntundevqayklxvphtmktixsribrfdcxchnheljrojnoijxdvulwrhgwpcpppzinbyprbxtyzsjvphadugrczulhluiarlhfgxiugv...

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

result:

ok 2000 lines

Test #17:

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

input:

hhvtukffcovscoldtuzwhvmjcococydtbbkavtukhvmdvmjcvmjcvmjcvtuvtuvtuvtutcococococorkcococcococsmjcvmjcvmjmjcvmjcvmjcvmcvmcvmcvmwiotukffcovsctukffcovsciqmcvmwmcvmwmcvmwzzzzzzzzzzzpkvtutcococococovtutcococococovtutcococococowiotukffcovscwiotukffcovscvtuvtutcococococorkcococcocococovtutcococococowiotucoco...

output:

33 33 1
22 99 2
34 111 2
1 82 3
47 124 2
2 87 3
21 98 2
60 60 1
57 57 1
43 43 1
1 78 2
42 119 2
65 142 2
19 96 2
1 103 3
35 112 2
75 75 1
15 92 2
25 102 2
1 46 2
1 37 2
1 135 3
68 68 1
15 92 2
2 59 2
2 79 2
23 23 1
1 122 3
1 116 3
53 53 1
2 96 4
13 90 2
6 37 2
25 102 2
2 57 2
68 145 2
1 30 2
6 28 2
...

result:

ok 2000 lines

Test #18:

score: 0
Accepted
time: 8ms
memory: 71780kb

input:

vydcsvacjwnohxvacjwnovacjwnodhjehjehjehjehjewovacjovacjovacjovacjovacjovacjovacjfjejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejezamlvyywpvacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovavacjovaeshaxlx...

output:

1 783 783
1 619 619
1 772 772
1 588 588
1 638 638
1 721 721
1 631 631
1 445 445
1 775 775
1 769 769
1 807 807
1 507 507
1 564 564
1 795 795
1 638 638
1 578 578
1 791 791
1 439 439
1 833 833
1 680 680
1 583 583
1 853 853
1 571 571
1 569 569
1 753 753
1 778 778
1 672 672
1 689 689
1 797 797
1 661 661
...

result:

ok 2000 lines

Test #19:

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

input:

cctcwdmpbnuaqsswtcgojerqmojesjsyxvkmakjcmakjxdtqrtyrbqcctcwdpbnuaqeqnecieqtpsonfzfwtcgojbbwdpbnuaqegitnlebsecieqtpsiojttjglhtrtyrnlhtrtyrnybghhpxlswdcjsyxvkxuonfzfwtcgoptaituxrxebjubsvgrkxdadttrtyrnlhtrtyrnybgmlopfpmswgoptaituxrxebjyybsecieqtpsifokmopsonfzfwtcgojbbwdgoptaituxrxebjubsvgrkxdadthgcrtyr...

output:

43 43 1
49 49 1
74 74 1
38 38 1
4 42 2
66 66 1
45 45 1
75 75 1
37 37 1
11 60 2
16 54 2
22 22 1
33 33 1
11 11 1
24 24 1
9 9 1
28 28 1
61 61 1
44 44 1
74 74 1
1 38 2
38 38 1
21 21 1
53 53 1
69 69 1
62 62 1
39 39 1
12 12 1
44 44 1
39 39 1
24 24 1
48 48 1
63 63 1
28 28 1
24 24 1
18 18 1
58 58 1
37 37 1
...

result:

ok 2000 lines

Test #20:

score: 0
Accepted
time: 8ms
memory: 73884kb

input:

crffrfbiibiibibiibiibibiibibiibiibibiibiibibiibibiibiibibiibibiibiibibiibiibibiibibiibiibibiibiibibiibibiibiibibiibibiibiibibiibiibibiibibiibiibibiibibiibiibibiibiibibiibibiibiibibiibiibibiibibiibiibibiibibiibiibibiibiibibiibibiibiibibiibiibibiibibiibiibibiibibiibiibibiibiibibiibibiibiibibiibibiibii...

output:

2 318 6
2 397 6
1 512 9
2 450 7
3 568 6
2 335 6
5 649 4
2 423 8
5 492 6
1 455 9
2 960 10
1 265 5
1 539 8
3 605 6
1 619 4
8 851 7
2 570 6
1 411 8
3 956 9
1 664 8
2 615 8
-1
1 579 7
1 815 10
2 539 9
5 822 8
2 332 6
1 791 8
1 566 6
2 801 8
-1
3 841 7
1 656 7
2 675 9
1 403 6
1 839 8
1 342 8
1 556 9
1 59...

result:

ok 2000 lines