QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706673#275. PalindromesTheZone100 ✓475ms55680kbC++236.8kb2024-11-03 12:54:342024-11-03 12:54:35

Judging History

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

  • [2024-11-03 12:54:35]
  • 评测
  • 测评结果:100
  • 用时:475ms
  • 内存:55680kb
  • [2024-11-03 12:54:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second

vector<int> manacher(string s) {
    int n = (int) s.size();
    vector<int> d(n, 1);
    int l = 0, r = 0;
    for (int i = 1; i < n; i++) {
        if (i < r)
            d[i] = min(r - i + 1, d[l + r - i]);
        while (i - d[i] >= 0 && i + d[i] < n && s[i - d[i]] == s[i + d[i]])
            d[i]++;
        if (i + d[i] - 1 > r)
            l = i - d[i] + 1, r = i + d[i] - 1;
    }
    return d;
}

vector<int> manacher2(string s) {
    vector<int> ans(s.size());
    int l = -1, r = -1;
    for (int i = 0; i < s.size(); i++) {
        if (i > r) {
            l = i; r = i;
            while (l - 1 >= 0 && r + 1 < s.size() && s[l - 1] == s[r + 1]) { r++; l--; }
            ans[i] = r - l + 1;
        } else {
            int cl = ans[l + r - i];
            if (cl / 2 + i < r) {
                ans[i] = cl;
            } else {
                ans[i] = 1 + (r - i) * 2;
                while (r + 1 < s.size() && 2 * i - (r + 1) >= 0 && s[r + 1] == s[2 * i - (r + 1)]) {
                    ans[i] += 2;
                    r++;
                    l = 2 * i - r;
                }
            }
        }
    }
    return ans;
}

const ll mod1 = 1e9 + 7, mod2 = 998244353;
const ll p = 31;

struct polyhash {
    int n;
    vector<int> c;
    vector<pair<ll, ll>> h, ppow;
    polyhash() = default;
    polyhash(int n_, vector<int> c_) {
        n = n_;
        c = c_;
        h.assign(n + 1, {0, 0});
        ppow.assign(n + 1, {1, 1});
        for (int i = 1; i <= n; i++) {
            h[i] = {(h[i - 1].first * p + c[i - 1]) % mod1, 
                    (h[i - 1].second * p + c[i - 1]) % mod2};
            ppow[i] = {(ppow[i - 1].first * p) % mod1, 
                       (ppow[i - 1].second * p) % mod2};
        }
    }

    pair<ll, ll> substring(int l, int r) {
        // [l, r] is segment in 0-index
        pair<ll, ll> result = {(h[r + 1].first + mod1 - (h[l].first * ppow[r - l + 1].first) % mod1), 
                (h[r + 1].second + mod2 - (h[l].second * ppow[r - l + 1].second) % mod2)};
        if (result.first >= mod1) result.first -= mod1;
        if (result.second >= mod2) result.second -= mod2;
        return result;
    }

    int find_lcp(int p1, int p2) {
        // finds longest common prefix of suffixes starts with indexes p1 and p2
        // useful for suffix array
        int L = 0, R = min(n - p1, n - p2) + 1;
        while (R - L > 1) {
            int M = (L + R) / 2;
            if (substring(p1, p1 + M - 1) == substring(p2, p2 + M - 1)) L = M;
            else R = M;
        }
        return L;
    }
};

struct sufarr {
    int n;
    vector<int> a;
    vector<int> cl;
    sufarr() = default;
    sufarr(int n_, vector<int> a_) {
        n = n_;
        a = a_;
        build();
    }
  
    void build() {
        vector<int> ord(n);
        iota(all(ord), 0);
        sort(all(ord), [&](int i, int j){return a[i] < a[j];});
  
        vector<pair<int, int>> lol(n);
        cl.assign(n, 0);
        int cur = -1;
        for (int i = 0; i < n; i++) {
            if (i == 0 || a[ord[i]] != a[ord[i - 1]]) cur++;
            cl[ord[i]] = cur;
        }
        for (int len = 2; len < 2 * n; len *= 2) {
            int l2 = len / 2;
            for (int i = 0; i < n; i++) {
                lol[i] = {cl[i], (i + l2 < n ? cl[i + l2] : -1)};
            }
            sort(all(ord), [&](int i, int j) {return lol[i] < lol[j];});
            int cur = -1;
            for (int j = 0; j < n; j++) {
                if (j == 0 || lol[ord[j]] != lol[ord[j - 1]]) cur++;
                cl[ord[j]] = cur;
            }
        }
    }
};

struct dsu {
    int n, bs = 0;
    vector<int> par, siz, sm;
    dsu() = default;
    dsu(int n_) {
        n = n_;
        bs = 0;
        par.assign(n, 0);
        siz.assign(n, 1);
        sm.assign(n, 0);
        iota(all(par), 0);
    }
    int get(int v) {return (par[v] == v ? v : par[v] = get(par[v]));}
    int getsum(int v) {return sm[get(v)];}
    void upd_sum(int v, int val) {sm[get(v)] += val; bs = max(bs, sm[get(v)]);}
    bool merge(int u, int v) {
        u = get(u); v = get(v); if (u == v) return false;
        if (siz[u] < siz[v]) swap(u, v);
        par[v] = u;
        siz[u] += siz[v];
        sm[u] += sm[v];
        bs = max(bs, sm[u]);
        return true;
    }
};

void solve() {
    string s; cin >> s;
    int n = s.size();
    vector<int> arr(s.size());
    for (int i = 0; i < n; i++) arr[i] = (s[i] - 'a' + 1);
    string nww = ".";
    for (int i = 0; i < s.size(); i++) {
        nww += s[i];
        nww += '.';
    }
    auto result = manacher(nww);
    for (int& x : result) x = 2 * x - 1;

    sufarr sf(n, arr);
    vector<int> order(n), pos = sf.cl;
    for (int i = 0; i < n; i++) order[sf.cl[i]] = i;
    polyhash pl(n, arr);
    vector<int> lcp(n - 1);
    for (int i = 0; i < n - 1; i++) {
        lcp[i] = pl.find_lcp(order[i], order[i + 1]);
    }
    ll ans = 0;
    {
        vector<vector<int>> turnoff(n + 1), turnon_gr(n + 1);
        for (int i = 1; i < sz(nww); i += 2) {
            int ml = result[i] / 2;
            turnoff[ml / 2 + 1].pb(pos[i / 2]);
        }
        for (int i = 0; i < n - 1; i++) {
            turnon_gr[lcp[i]].pb(i);
        }
        dsu d(n);
        for (int len = n - 1; len >= 0; len--) {
            for (int el : turnoff[len + 1]) {
                d.upd_sum(el, 1);
            }
            for (int el : turnon_gr[len + 1]) {
                d.merge(el, el + 1);
            }
            ans = max(ans, d.bs * 1ll * (2 * len + 1));
        }
    }
    {
        vector<vector<int>> turnoff(n + 1), turnon_gr(n + 1);
        for (int i = 2; i < sz(nww) - 1; i += 2) {
            int ml = result[i] / 2;
            turnoff[ml / 2 + 1].pb(pos[i / 2]);
        }
        for (int i = 0; i < n - 1; i++) {
            turnon_gr[lcp[i]].pb(i);
        }
        dsu d(n);
        for (int len = n - 1; len >= 0; len--) {
            for (int el : turnoff[len + 1]) {
                d.upd_sum(el, 1);
            }
            for (int el : turnon_gr[len]) {
                d.merge(el, el + 1);
            }
            ans = max(ans, d.bs * 1ll * (2 * len));
        }
    }
    cout << ans << '\n';
}

signed main() {
    int tt = 1;
    #ifdef LOCAL 
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> tt;
    #else
        ios::sync_with_stdio(false); 
        cin.tie(0); cout.tie(0);
    #endif

    while (tt--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

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

input:

abacaba

output:

7

result:

ok single line: '7'

Test #2:

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

input:

www

output:

4

result:

ok single line: '4'

Test #3:

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

input:

abacababa

output:

9

result:

ok single line: '9'

Test #4:

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

input:

r

output:

1

result:

ok single line: '1'

Test #5:

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

input:

xd

output:

1

result:

ok single line: '1'

Test #6:

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

input:

dd

output:

2

result:

ok single line: '2'

Test #7:

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

input:

opo

output:

3

result:

ok single line: '3'

Test #8:

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

input:

opoo

output:

3

result:

ok single line: '3'

Test #9:

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

input:

abacabadabacaba

output:

15

result:

ok single line: '15'

Test #10:

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

input:

xxxxxyxxxxyxxxxx

output:

24

result:

ok single line: '24'

Test #11:

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

input:

xxxyxxxyzzzabcdxxdcba

output:

10

result:

ok single line: '10'

Test #12:

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

input:

qpppppppwowpppppq

output:

24

result:

ok single line: '24'

Test #13:

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

input:

mqmwmemrmtymmmmmmmmqwertyeeeeeeeee

output:

25

result:

ok single line: '25'

Test #14:

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

input:

mqmwmmmmmemrmtymmmmmmmmqwertyeeeeeeeee

output:

28

result:

ok single line: '28'

Test #15:

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

input:

abcdefghijklmnopqrstuvwxyzz

output:

2

result:

ok single line: '2'

Test #16:

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

input:

abcdefghijklmnopqrstuvwxyz

output:

1

result:

ok single line: '1'

Test #17:

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

input:

apiodpdpdpdpdpgoodchallenge

output:

15

result:

ok single line: '15'

Test #18:

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

input:

pdpdpdpxdpdpdxdpdpdx

output:

18

result:

ok single line: '18'

Test #19:

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

input:

jejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejejeje

output:

1176

result:

ok single line: '1176'

Test #20:

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

input:

wzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzw

output:

1225

result:

ok single line: '1225'

Test #21:

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

input:

qsqsqsqsqsqsqianananananananananaygsgsgsgsgsgsgsgsgsgsgsgsgsgsgsgszikidnsnsnsnsnsnsnsnsnsnsnsnsn

output:

136

result:

ok single line: '136'

Test #22:

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

input:

hsoqhdnglglqqhqhqhqhqhqhqmyiyiyiyiyiyiyiyiywrvrvrvrvrvzttttfsfsfsfgkhkhkhkfuhuhlggggggggssfsfs

output:

45

result:

ok single line: '45'

Test #23:

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

input:

ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

output:

2500

result:

ok single line: '2500'

Test #24:

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

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcpppppppppppppppppppppnuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

output:

380

result:

ok single line: '380'

Test #25:

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

input:

jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj

output:

2304

result:

ok single line: '2304'

Test #26:

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

input:

gggggggggtoooooooooccwwwwwwwwwwwwwwwwmllllllllllllllxvvjeeeppppppdnswwwwieeeeeeeeeeeeeeeeeeeesl

output:

110

result:

ok single line: '110'

Test #27:

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

input:

vlvivlvwvlvivlvkvlvivlvwvlvivlvfvlvivlvwvlvivlvkvlvivlvwvlvivlvzvlvivlvwvlvivlvkvlvivlvwvlvivlvfvlvi

output:

93

result:

ok single line: '93'

Test #28:

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

input:

nbnenbnjnbnenbnxnbnenbnjnbnenbnmnbnenbnjnbnenuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

output:

729

result:

ok single line: '729'

Test #29:

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

input:

ydycydylydycydyodoycydylydycydybydyccccccccccccccccccccccdycydyxydycydylydycydyrydycydylydycydybydvq

output:

132

result:

ok single line: '132'

Test #30:

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

input:

dzydpxreexldgbslbouxllaizermiyzzmnawejbabckjdqybqwsaysietcsdfkclenvpkbsxhumglxvxmprkijakygjgjsbsawfj

output:

7

result:

ok single line: '7'

Test #31:

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

input:

bpmerpingvjipwmenzzalhrsmrkmxvmizieduxoxlxembhjjfrxsrecuhmntpwbjhxysmgrqvuqxhysalvpeurrkdifqloo

output:

8

result:

ok single line: '8'

Test #32:

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

input:

abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaab

output:

64

result:

ok single line: '64'

Subtask #2:

score: 15
Accepted

Dependency #1:

100%
Accepted

Test #33:

score: 15
Accepted
time: 1ms
memory: 3996kb

input:

yhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyhyh...

output:

124251

result:

ok single line: '124251'

Test #34:

score: 15
Accepted
time: 1ms
memory: 3748kb

input:

nknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknknk...

output:

38226

result:

ok single line: '38226'

Test #35:

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

input:

oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...

output:

249500

result:

ok single line: '249500'

Test #36:

score: 15
Accepted
time: 1ms
memory: 3740kb

input:

ktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktktkokpkpkpkpkpkpjrjrjrjrjrjrjrjrjrjrjrjrjrjrjrjrjrjhtktpwuwuwuwuwuwuwuwuwuwuwuwiisisisisis...

output:

5778

result:

ok single line: '5778'

Test #37:

score: 15
Accepted
time: 1ms
memory: 3840kb

input:

gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg...

output:

247506

result:

ok single line: '247506'

Test #38:

score: 15
Accepted
time: 1ms
memory: 3832kb

input:

dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...

output:

248004

result:

ok single line: '248004'

Test #39:

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

input:

tdtytdtxtdtytdtptdtytdtxtdtytdtmtdtytdtxtdtytdtptdtytdtxtdtytdtbtdtytdtxtdtytdtptdtytdtxtdtytdtmtdtytdtxtdtytdtptdtytdtxtdtytdtztdtytdtxtdtytdtptdtytdtxtdtytdtmtdtytdtxtdtytdtptdtytdtxtdtytdtbtdtytdtxtdtytdtptdtytdtxtdtytdtmtdtytdtxtdtytdtptdtytdtxtdtytdtetdtytdtxtdtytdtptdtytdtxtdtytdtmtdtytdtxtdty...

output:

973

result:

ok single line: '973'

Test #40:

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

input:

xfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxfxf...

output:

123753

result:

ok single line: '123753'

Test #41:

score: 15
Accepted
time: 1ms
memory: 3748kb

input:

yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyybbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbgvgtgsgtgvgtgegtgvgtgygtgvgtgegtgvgtgngtgvgtgegtgvgtgygtgvgtgegtgvgtgbgtgvgtgegtgvgtgygtgvgtgegtgvgtgngtgvgtgegtgvgtgygtgvgtgegtgvgtgmgtgvgtgegtgvgtgygtgvgtgegtgvgtgngtgvgtgegtgv...

output:

2346

result:

ok single line: '2346'

Test #42:

score: 15
Accepted
time: 1ms
memory: 3800kb

input:

phxbzjihyzgshwcidlnkwkltarrnbvkgkzdakoyzeuhoeizcoemcdrtqrsesggbnvltdwrjahpekhylmtkwfcxrvgzdcarhtxkhejosurcntcgsycxkrkxspdqfcwiscudscsmfxjqxmxacgdzjupbaqbfzpsasyrvrpuhuusulurpmwfllpgbtgqnslvjupnpvgfvrdlowwsoaqsepmzdsirpmklgugblxexfxhtjigkhiwndihqsnowlrbyxeqczhyesczvuwthgvidmwtarmbokalyabzmdddcegplfpn...

output:

53

result:

ok single line: '53'

Test #43:

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

input:

nkevzhqlzcmqmbvtbojxbbtvgsxkbhyxrmwkzvvnvqppgbcgwplnupeizuimryoomumihznxizqcchutpzangopekbxirfgpunctyhdvkuhloshxnsmbyjtsdkevaaktccybajxmesubgmfennovcwlskuzjencrbafrzvgylsrzxpxvbrwapbkbqehtdopkgnvdifhkvtzbbjzdylautvnjqcmbrdyxpgsjtxptpayfyiyybkgvodovlvehskrvhtecinxbucymhucgudaujpcujdtgwdojjjvkewtjnghe...

output:

52

result:

ok single line: '52'

Test #44:

score: 15
Accepted
time: 1ms
memory: 3748kb

input:

abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaab...

output:

976

result:

ok single line: '976'

Subtask #3:

score: 24
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #45:

score: 24
Accepted
time: 6ms
memory: 5060kb

input:

lnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnlnln...

output:

12497500

result:

ok single line: '12497500'

Test #46:

score: 24
Accepted
time: 6ms
memory: 4824kb

input:

qhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqhqh...

output:

6481800

result:

ok single line: '6481800'

Test #47:

score: 24
Accepted
time: 6ms
memory: 5084kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

25000000

result:

ok single line: '25000000'

Test #48:

score: 24
Accepted
time: 6ms
memory: 5260kb

input:

ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...

output:

17816841

result:

ok single line: '17816841'

Test #49:

score: 24
Accepted
time: 3ms
memory: 4780kb

input:

xlxixlxpxlxixlxexlxixlxpxlxixlxgxlxixlxpxlxixlxexlxixlxpxlxixlxmxlxixlxpxlxixlxexlxixlxpxlxixlxgxlxixlxpxlxixlxexlxixlxpxlxixlxfxlxixlxpxlxixlxexlxixlxpxlxixlxgxlxixlxpxlxixlxexlxixlxpxlxixlxmxlxixlxpxlxixlxexlxixlxpxlxixlxgxlxixlxpxlxixlxexlxixlxpxlxixlxsxlxixlxpxlxixlxexlxixlxpxlxixlxgxlxixlxpxlxi...

output:

9945

result:

ok single line: '9945'

Test #50:

score: 24
Accepted
time: 3ms
memory: 4784kb

input:

elelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelelel...

output:

504100

result:

ok single line: '504100'

Test #51:

score: 24
Accepted
time: 6ms
memory: 4952kb

input:

afamafacafamafakafamafacafamafaqafaanananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananananana...

output:

1512930

result:

ok single line: '1512930'

Test #52:

score: 24
Accepted
time: 6ms
memory: 4688kb

input:

hmdqbxxvfzcxpohuffioztrgqgxkhfvtpgpudbbyaihadhzbeqrmjhljwmflxhhmrjqaumcacixjrcegaloxzzoprmnrzuldssiyuxfjtxsjjhvywupyviwunipmgxuqalcxatphosveipikcopziexcpspnidczvmupoxvabmlndxdrcrhdregvkqxnsjyfyvbqusygczosimhtjdbwwnlrqasixheataqyjwpxmrrkpxrvcbmkzbdafyahbzrhxkfbkfzrawufisbrdzfkdhuivwqueqlhisiwmahvagqn...

output:

413

result:

ok single line: '413'

Test #53:

score: 24
Accepted
time: 6ms
memory: 4708kb

input:

xznwghgyngrjehtffuiepaedcvdovapnjltjdavlxwmmcexbvxuhlohrfdjwnoimduzngahcupnwmuvqgyqutwaxzpxcqbvahcwwndugzesfkyhyxxehphrdhzucneyhdtlxhixdqrzmbtjxnatzjmwftvjknajzugquxubfmqvqxxqkpztyjfqsuzreyegwqvjbdqfzdjmctntsyjocdlxulnvqvxfjxdpefduawiosrekasgtqpnyhxuglvxorkqyemjkvcsimphvgwspqpaigfulymtkryxeibdilknxm...

output:

428

result:

ok single line: '428'

Test #54:

score: 24
Accepted
time: 7ms
memory: 5060kb

input:

abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaab...

output:

7232

result:

ok single line: '7232'

Subtask #4:

score: 26
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #55:

score: 26
Accepted
time: 69ms
memory: 20656kb

input:

bhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbhbh...

output:

1249925001

result:

ok single line: '1249925001'

Test #56:

score: 26
Accepted
time: 60ms
memory: 18692kb

input:

usususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususususus...

output:

396337935

result:

ok single line: '396337935'

Test #57:

score: 26
Accepted
time: 69ms
memory: 20564kb

input:

yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...

output:

2500050000

result:

ok single line: '2500050000'

Test #58:

score: 26
Accepted
time: 55ms
memory: 19164kb

input:

llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...

output:

1016525689

result:

ok single line: '1016525689'

Test #59:

score: 26
Accepted
time: 88ms
memory: 17596kb

input:

kvkikvklkvkikvkgkvkikvklkvkikvkckvkikvklkvkikvkgkvkikvklkvkikvkakvkikvklkvkikvkgkvkikvklkvkikvkckvkikvklkvkikvkgkvkikvklkvkikvkxkvkikvklkvkikvkgkvkikvklkvkikvkckvkikvklkvkikvkgkvkikvklkvkikvkakvkikvklkvkikvkgkvkikvklkvkikvkckvkikvklkvkikvkgkvkikvklkvkikvkhkvkikvklkvkikvkgkvkikvklkvkikvkckvkikvklkvki...

output:

99645

result:

ok single line: '99645'

Test #60:

score: 26
Accepted
time: 87ms
memory: 17964kb

input:

pqpzpqpupqpzpqpbpqpzpqpupqpzpqpwpqpzpqpupqpzpqpbpqpzpqpupqpzpqpipqpzpqpupqpzpqpbpqpzpqpupqpzpqpwpqpzpqpupqpzpqpbpqpzpqpupqpzpqpspqpzpqpupqpzpqpbpqpzpqpupqpzpqpwpqpzpqpupqpzpqpbpqpzpqpupqpzpqpipqpzpqpupqpzpqpbpqpzpqpupqpzpqpwpqpzpqpupqpzpqpbpqpzpqpupqpzpqpgpqpzpqpupqpzpqpbpqpzpqpupqpzpqpwpqpzpqpupqpz...

output:

78569380

result:

ok single line: '78569380'

Test #61:

score: 26
Accepted
time: 67ms
memory: 17808kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

82810000

result:

ok single line: '82810000'

Test #62:

score: 26
Accepted
time: 71ms
memory: 17368kb

input:

vmlqjhjiwwzijupbzztlkcxbcdavxyqryzttbvvwwekgresldvhrtwwzkgldqvmtecanlhirufqzzvfoybnqorcgmpzhkedhxelbfgkdrktqblcsfngtmhpijdbmtznvmatyrwrbjkmmtgbbwhsiacswcuvszlwgveqehiudnnnuetqucajijlzcomkqfvhaukpnzwlrysonewxfopijuyatwmpslwelwljnkyiibdeuvernjqizvzmtutgsvzdjfksyghkmbqimxarcmkerlbrxnfehzpbmzrvzbjhetlgv...

output:

3989

result:

ok single line: '3989'

Test #63:

score: 26
Accepted
time: 70ms
memory: 18116kb

input:

bcqqtvvdvexrttkgcbhmlhoasnlcektbxssxkxyavuqritimuzvnaurotozfdfglteetpbnpuvymvaghqzqznontyyxciqbglyaedgnzxjzmvampibduzoypreeconehptujqukxezbdcmcguzxgeqzsuqrrhtiudmeqflamybdebwpdkgohesfmbzemzojexzcljvcopvtvlovbngdvhxcshgbwcaluonvfzlaloirqpqqpnbhbbhvyizecupuoyhmcfbobawpqlwmtornvtipqsfphujgltwmodxdcwfpg...

output:

125529616

result:

ok single line: '125529616'

Test #64:

score: 26
Accepted
time: 91ms
memory: 17760kb

input:

abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaab...

output:

66664

result:

ok single line: '66664'

Subtask #5:

score: 27
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #65:

score: 27
Accepted
time: 216ms
memory: 55680kb

input:

bnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbnbn...

output:

11250075000

result:

ok single line: '11250075000'

Test #66:

score: 27
Accepted
time: 210ms
memory: 48844kb

input:

jzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjzjz...

output:

894243195

result:

ok single line: '894243195'

Test #67:

score: 27
Accepted
time: 207ms
memory: 55636kb

input:

yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...

output:

22499400004

result:

ok single line: '22499400004'

Test #68:

score: 27
Accepted
time: 204ms
memory: 47828kb

input:

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...

output:

2958163321

result:

ok single line: '2958163321'

Test #69:

score: 27
Accepted
time: 475ms
memory: 47628kb

input:

xqxtxqxwxqxtxqxlxqxtxqxwxqxtxqxexqxtxqxwxqxtxqxlxqxtxqxwxqxtxqxyxqxtxqxwxqxtxqxlxqxtxqxwxqxtxqxexqxtxqxwxqxtxqxlxqxtxqxwxqxtxqxsxqxtxqxwxqxtxqxlxqxtxqxwxqxtxqxexqxtxqxwxqxtxqxlxqxtxqxwxqxtxqxyxqxtxqxwxqxtxqxlxqxtxqxwxqxtxqxexqxtxqxwxqxtxqxlxqxtxqxwxqxtxqxvxqxtxqxwxqxtxqxlxqxtxqxwxqxtxqxexqxtxqxwxqxt...

output:

298935

result:

ok single line: '298935'

Test #70:

score: 27
Accepted
time: 257ms
memory: 46812kb

input:

zwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzwzw...

output:

1210831209

result:

ok single line: '1210831209'

Test #71:

score: 27
Accepted
time: 260ms
memory: 46148kb

input:

hyhnhyhehyhnhyhlhyhnhyhehyhnhyhkhyhnhyhehyhnhyhlhyhnhyhehyhnhyhdhyhnhyhehyhnhyhlhyhnhyhehyhnhyhkhyhnhyhehyhnhyhlhyhnhyhehyhnhyhwhyhnhyhehyhnhyhlhyhnhyhehyhnhyhkhyhnhyhehyhnhyhlhyhnhyhehyhnhyhdhyhnhyhehyhnhyhlhyhnhyhehyhnhyhkhyhnhyhehyhnhyhlhyhnhyhehyhnhyhvhyhnhyhehyhnhyhlhyhnhyhehyhnhyhkhyhnhyhehyhn...

output:

303195156

result:

ok single line: '303195156'

Test #72:

score: 27
Accepted
time: 320ms
memory: 45632kb

input:

hnrootvymrwweaxjusfltkgyqyeioonpksxtampxsamlfcitaauwcjfmxbtvghsyswjyaephlciqgpdwvqnkdhtzkqmyuqukbsobqrpuowsyspglpdypcejwdvolfyezxpjyjztwgcgudvrtsdxouampqybzqtoosumwzwsgboqbgpdycknpatsirizrqioxoxdjfxwdvnqixhlstcrvrkpvazncakguavcbjazssqsfbnrdrhdlozsohomcpannklcxcluhcjvumhfntubbqwnmeosusnoopqicougnnpxc...

output:

11804

result:

ok single line: '11804'

Test #73:

score: 27
Accepted
time: 302ms
memory: 45532kb

input:

yoljcehfgzraqykusrdwgqxdudzvepmjvrsfoosapcxoxoqzfaebohkstrtgnawnonwuynojpzulyulmlxfzbdmqeofumicjihysfofcyfhnsjurggtonwstxatbpoffhamgqkktzdphibrpeiiledjizhvrcnywcyyhvujhqvhvsyxkifcizpczjawdwuxkrxcmkqbsrlbrorrcyznwzpcejgrryyxnursejnogvjlehfspyutfnbmjniaaxtsfmnsvsebwotxqempvqreeeslrxwlljwsawxkktdayuumi...

output:

11813

result:

ok single line: '11813'

Test #74:

score: 27
Accepted
time: 417ms
memory: 47004kb

input:

abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaab...

output:

262144

result:

ok single line: '262144'

Test #75:

score: 27
Accepted
time: 253ms
memory: 53224kb

input:

acbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabcacbabc...

output:

3750025000

result:

ok single line: '3750025000'

Test #76:

score: 27
Accepted
time: 306ms
memory: 46284kb

input:

uptvtysodzujkjcvrzkzydggrhjjlicywbakjpulmdqnlhzqbyhbblhzemftazrldvrxmfuiejvuxvevvescgolivepuwbdyyiylvtqubxfrnmouoshonhbwojudfexgnafvjxrogotuomkwlyoafqsqrzmomodmkxuguysscbidukwlblzrsyqdjsoaqfplvhmqhhpgkvztkpiwowfmjtujkzpileosqqsskywfnvaqhprbhcyfvbzrtkkjmbvxzqgfdoelxzecvgnsxiuvmassxzmweiixxppvmmbxvgol...

output:

184796836

result:

ok single line: '184796836'