QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#344964#3813. Text ProcessorKhNURE_KIVI#AC ✓678ms14944kbC++2018.5kb2024-03-05 20:58:262024-03-05 20:58:27

Judging History

This is the latest submission verdict.

  • [2024-03-05 20:58:27]
  • Judged
  • Verdict: AC
  • Time: 678ms
  • Memory: 14944kb
  • [2024-03-05 20:58:26]
  • Submitted

answer

#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")

#include <bits/stdc++.h>

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

template<typename T>
bool umin(T &a, T b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
bool umax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifdef KIVI
#define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define DEBUG while (false)
#define LOG(...)
#endif

const int max_n = 1e5+10, inf = 1000111222;

int to_build[max_n];

template<typename T>
struct segment_tree
{
    vector<pair<T,pii>> all[4*max_n];

    void build(int v,int l,int r)
    {
        if (l==r){
            all[v].clear();
            all[v].pb(mp(to_build[l],mp(-1,-1)));
            return;
        }
        int m=(l+r)/2;
        build(2*v,l,m);
        build(2*v+1,m+1,r);
        int p1=0,p2=0;
        all[v].clear();
        all[v].reserve(r-l+1);

        while (p1<len(all[2*v]) || p2<len(all[2*v+1])){
            if (p1==len(all[2*v]) || (p2!=len(all[2*v+1]) && all[2*v][p1]>all[2*v+1][p2])){
                all[v].pb(mp(all[2*v+1][p2].fir,mp(p1,p2)));
                p2++;
            }
            else{
                all[v].pb(mp(all[2*v][p1].fir,mp(p1,p2)));
                p1++;
            }
        }
    }

    int get_cnt_more_equal(int v,int l,int r,int tl,int tr,int pos)
    {
        if (pos==all[v].size()){
            return 0;
        }
        if (l>=tl && r<=tr){
            return len(all[v])-pos;
        }
        int m=(l+r)/2;
        if (tr<=m){
            return get_cnt_more_equal(2*v,l,m,tl,tr,all[v][pos].sec.fir);
        }
        else if (tl>m){
            return get_cnt_more_equal(2*v+1,m+1,r,tl,tr,all[v][pos].sec.sec);
        }
        else{
            return get_cnt_more_equal(2*v,l,m,tl,tr,all[v][pos].sec.fir) +
                     get_cnt_more_equal(2*v+1,m+1,r,tl,tr,all[v][pos].sec.sec);
        }
    }

    int get_cnt_more_equal(int l,int r,int x)
    {
        const int pos=lower_bound(all(all[1]),mp(x,mp(-2,-2)))-all[1].begin();
        return get_cnt_more_equal(1,0,len(all[1])-1,l,r,pos);
    }

    int get_cnt_in_range(int l,int r,int x1,int x2)
    {
        return get_cnt_more_equal(l,r,x1)-get_cnt_more_equal(l,r,x2+1);
    }
};

segment_tree<int> st_fast;

struct segment_tree_min
{
    int mn[2*max_n];
//    int naive_mn[max_n];
    void build(int v,int l,int r)
    {
        mn[v]=+inf;
        if (l==r){
//            naive_mn[l]=+inf;
            return;
        }
        int m=(l+r)/2;
        build(v+1,l,m);
        build(v+2*(m-l+1),m+1,r);
    }


    void update(int v,int l,int r,int pos,int val)
    {
//        naive_mn[pos]=val;
//        return;

        if (l==r){
            mn[v]=val;
            return;
        }
        int m=(l+r)/2;
        if (pos<=m){
            update(v+1,l,m,pos,val);
        }
        else{
            update(v+2*(m-l+1),m+1,r,pos,val);
        }
        mn[v]=min(mn[v+1],mn[v+2*(m-l+1)]);
    }

    int get_min(int v,int l,int r,int tl,int tr)
    {
//        return *min_element(naive_mn+tl,naive_mn+tr+1);

        if (l==tl&&r==tr){
            return mn[v];
        }
        int m=(l+r)/2;
        if (tr<=m){
            return get_min(v+1,l,m,tl,tr);
        }
        else if (tl>m){
            return get_min(v+2*(m-l+1),m+1,r,tl,tr);
        }
        else{
            return min(
                    get_min(v+1,l,m,tl,m),
                    get_min(v+2*(m-l+1),m+1,r,m+1,tr)
                    );
        }
    }
};

segment_tree_min st_fast_fast;

struct segment_tree_min_spusk
{
    pii mn[2*max_n];
    pii mx[2*max_n];
    void build(int v,int l,int r)
    {
        if (l==r){
            mn[v]=mp(to_build[l],l);
            mx[v]=mp(-to_build[l],l);
            return;
        }
        int m=(l+r)/2;
        build(v+1,l,m);
        build(v+2*(m-l+1),m+1,r);
        mn[v]=min(mn[v+1],mn[v+2*(m-l+1)]);
        mx[v]=max(mx[v+1],mx[v+2*(m-l+1)]);
    }

    pair<bool,int> find_last_smaller(int v,int l,int r,int tl,int tr,int x)
    {
        if (l==tl&&r==tr){
            if (mn[v].fir<x){
                while (l!=r){
                    int m=(l+r)/2;
                    if (mn[v+2*(m-l+1)].fir<x){
                        v=v+2*(m-l+1);
                        l=m+1;
                    }
                    else{
                        v=v+1;
                        r=m;
                    }
                }
                return mp(1,l);
            }
            else{
                return mp(false,-1);
            }
        }
        int m=(l+r)/2;
        if (tr<=m){
            return find_last_smaller(v+1,l,m,tl,tr,x);
        }
        else if (tl>m){
            return find_last_smaller(v+2*(m-l+1),m+1,r,tl,tr,x);
        }
        else{
            auto res=find_last_smaller(v+2*(m-l+1),m+1,r,m+1,tr,x);
            if (res.first){
                return res;
            }

            return find_last_smaller(v+1,l,m,tl,m,x);
        }
    }

    pair<bool,int> find_first_smaller(int v,int l,int r,int tl,int tr,int x)
    {
        LOG(l,r,mn[v].fir);
        if (l==tl&&r==tr){
            if (mn[v].fir<x){
                while (l!=r){
                    int m=(l+r)/2;
                    if (mn[v+1].fir<x){
                        v=v+1;
                        r=m;
                    }
                    else{
                        v=v+2*(m-l+1);
                        l=m+1;
                    }
                }
                return mp(1,l);
            }
            else{
                return mp(false,-1);
            }
        }
        int m=(l+r)/2;
        if (tr<=m){
            return find_first_smaller(v+1,l,m,tl,tr,x);
        }
        else if (tl>m){
            return find_first_smaller(v+2*(m-l+1),m+1,r,tl,tr,x);
        }
        else{
            auto res=find_first_smaller(v+1,l,m,tl,m,x);
            if (res.first){
                return res;
            }
            return find_first_smaller(v+2*(m-l+1),m+1,r,m+1,tr,x);
        }
    }
};

segment_tree_min_spusk st3;

const int max_log=18;

//int st[max_n][max_log];

int lg[max_n];

ll ans[max_n];

int tp[max_n];

int naive(string s)
{
    set<string> res;
    for (int i=0;i<len(s);i++){
        for (int j=i;j<len(s);j++){
            res.insert(s.substr(i,j-i+1));
        }
    }
    return len(res);
}

const bool gen=0;
const bool stress=0;

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    start_of_program:;

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    for (int i=2;i<max_n;i++){
        lg[i]=lg[i/2]+1;
    }

    string s;
    if (gen){
        const int n=rand()%int(1e5)+1;
        s="";
        for (int i=0;i<n;i++){
            s+=char('a'+rand()%10);
        }
        cerr<<"new test"<<"\n";
        cerr<<s<<"\n";
    }
    else{
        cin>>s;
    }
    int q,w;
    if (gen){
        q=1;
        w=rand()%len(s)+1;
        cerr<<q<<" "<<w<<"\n";
    }
    else{
        cin>>q>>w;
    }
    auto solve_all=[&]()
    {
        const int base=char('a'-1);
        s+=char(base);
        const int n=len(s);

        for (int i=0;i<n;i++){
            tp[i]=s[i]-base;
        }
        for (int i=0;i<max_log;i++){
            vector<pair<pii,int>> v;
            for (int j=0;j<n;j++){
                v.pb(mp(mp(tp[j],tp[(j+(1ll<<i))%n]),j));
            }
            sort(all(v));
            int last=0;
            for (int j=0;j<len(v);){
                tp[v[j].sec]=last;
                while (j+1<len(v) && v[j+1].fir==v[j].fir){
                    j++;
                    tp[v[j].sec]=last;
                }

                last++;
                j++;
            }
        }

        vector<pii> p(n);
        for (int i=0;i<n;i++){
            LOG(s.substr(i),tp[i]);
            p[i]=mp(tp[i],i);
        }
        sort(all(p));
        vector<int> v(n);
        for (int i=0;i<n;i++){
            v[i]=p[i].sec;
        }


        vector<int> pos(n+2,0);

        vector<int> lcp(n,0);
        for (int i=0;i<n;i++){
            pos[v[i]]=i;
        }
        int len=0;
        for (int i=0;i<n;i++){
            if (pos[i]==0){
                len=0;
                continue;
            }
            len=max(len-1,0);
            int id=v[pos[i]-1];
            while (i+len<n && id+len<n && s[i+len]==s[id+len]){
                len++;
            }
            lcp[pos[i]]=len;
        }

        DEBUG{
            for (int i=0;i<n;i++){
                cerr<<s.substr(v[i])<<" "<<lcp[i]<<"\n";
            }
        };

//        for (int i=0;i<n;i++){
//            to_build[i]=v[i];
//        }
//        st_fast.build(1,0,n-1);

        for (int i=0;i<n;i++){
            to_build[i]=lcp[i];
        }
        to_build[0]=+inf;
        st3.build(1,0,n-1);


//        for (int i=0;i<n;i++){
//            st[i][0]=lcp[i];
//        }
//        for (int j=1;j<max_log;j++){
//            for (int i=0;i+(1ll<<j)-1<n;i++){
//                st[i][j]=min(st[i][j-1],st[i+(1ll<<(j-1))][j-1]);
//            }
//        }
//
//        auto get_st_min=[&](int l,int r)
//        {
//            int my_lg=lg[r-l+1];
//            return min(st[l][my_lg],st[r-(1ll<<my_lg)+1][my_lg]);
//        };
//        auto get_lcp=[&](int pos_v_1,int pos_v_2)
//        {
//            assert(pos_v_1<pos_v_2);
//            return get_st_min(pos_v_1+1,pos_v_2);
//        };

        st_fast_fast.build(1,0,n-1);

        ll answer=0;
        auto any_have_prefix=[&](int l,int r,int want_l,int want_r)
        {
            const int length=want_r-want_l+1;
            const int my_pos_in_v=pos[want_l];
            int L=my_pos_in_v,R=my_pos_in_v;
            LOG("R before",R);
            {
                auto res=st3.find_last_smaller(1,0,n-1,0,L,length);
                if (res.fir){
                    L=res.sec;
                }
                else{
                    L=0;
                }
            }
            if (R!=n-1){
                auto res=st3.find_first_smaller(1,0,n-1,R+1,n-1,length);
                LOG(res.fir,res.sec);
                if (res.fir){
                    R=res.sec-1;
                }
                else{
                    R=n-1;
                }
            }
//            for (int i=max_log;i>=0;i--){
//                if (L-(1ll<<i)>=0 && get_lcp(L-(1ll<<i),my_pos_in_v)>=length){
//                    L-=(1ll<<i);
//                }
//            }
//            for (int i=max_log;i>=0;i--){
//                if (R+(1ll<<i)<n && get_lcp(my_pos_in_v,R+(1ll<<i))>=length){
//                    R+=(1ll<<i);
//                }
//            }
//            LOG("R after",R);
//            LOG(length);
//            LOG(n-1);
//            assert(R==my_pos_in_v || get_lcp(my_pos_in_v,R)>=length);
            return st_fast_fast.get_min(1,0,n-1,L,R)<=r;
//            return st_fast.get_cnt_in_range(L,R,l,r)>0;

//            for (int i=l;i<=r;i++){
//                if (s.substr(i,length)==s.substr(want_l,length)){
//                    return 1;
//                }
//            }
//            return 0;
        };
        auto push_to_subseg=[&](int L,int R)
        {
            LOG("push_to_subseg",L,R);
            int l=L,r=R;
            while (r-l>0){
                int m=(l+r+1)/2;
                /// [m;R]
                const int length=R-m+1;
                if (any_have_prefix(L,R-length,m,R)){
                    r=m-1;
                }
                else{
                    l=m;
                }
            }
            LOG("res of bin search",l);
            answer+=(l-L+1);
            LOG("new answer",answer);
            st_fast_fast.update(1,0,n-1,pos[R],R);
        };
        auto pop_from_subseg=[&](int L,int R)
        {
            st_fast_fast.update(1,0,n-1,pos[L],+inf);
            int l=L,r=R;
            while (r-l>0){
                int m=(l+r)/2;
                /// [L;m]
                const int length=m-L+1;
                if (any_have_prefix(L+1,R-length+1,L,m)){
                    l=m+1;
                }
                else{
                    r=m;
                }
            }
            answer-=(R-l+1);
        };

        if (w==1){
            for (int i=0;i<n;i++){
                ans[i]=1;
            }
        }
        else{
            answer=0;
            for (int i=0;i<w;i++){
                push_to_subseg(0,i);
            }
            ans[0]=answer;
            for (int i=1;i+w-1<n;i++){
                int L=i,R=i+w-1;
                L--;
                R--;

                pop_from_subseg(L,R);
                L++;

                R++;
                push_to_subseg(L,R);
                ans[i]=answer;
            }
        }

//        for (int i=0;i+w-1<n;i++){
//            vector<int> pos_in_v;
//            for (int j=0;j<w;j++){
//                pos_in_v.pb(pos[i+j]);
//            }
//            sort(all(pos_in_v));
//            for (int j=1;j<len(pos_in_v);j++){
//                ans[i]-=min(i+w-1-max(v[pos_in_v[j-1]],v[pos_in_v[j]])+1,get_lcp(pos_in_v[j-1],pos_in_v[j]));
//            }
//            ans[i]+=1ll*w*(w+1)/2;
//            LOG("answer for",s.substr(i,w),ans[i]);
//        }
        return;

//        int push=0;
//        ll value=0;
//        set<int> setik;
//        set<pair<int,pii>> to_remove_push;
//        int CURRENT_R;
//        auto add_pair_to_setik=[&](int pos_v_1,int pos_v_2)
//        {
//            LOG("add_pair_to_setik",s.substr(v[pos_v_1]),s.substr(v[pos_v_2]));
//            int lcp=get_lcp(pos_v_1,pos_v_2);
//            LOG(lcp);
//            if (max(v[pos_v_1],v[pos_v_2])+lcp-1>=CURRENT_R){
//                to_remove_push.insert(mp(max(v[pos_v_1],v[pos_v_2])+lcp-1,mp(pos_v_1,pos_v_2)));
//                push++;
//                value+=CURRENT_R-max(v[pos_v_1],v[pos_v_2])+1;
//                LOG("added to value",CURRENT_R-max(v[pos_v_1],v[pos_v_2])+1);
//            }
//            else{
//                value+=lcp;
//            }
//        };
//        auto remove_pair_from_setik=[&](int pos_v_1,int pos_v_2)
//        {
//            LOG("remove_pair_from_setik",s.substr(v[pos_v_1]),s.substr(v[pos_v_2]));
//            int lcp=get_lcp(pos_v_1,pos_v_2);
//            if (max(v[pos_v_1],v[pos_v_2])+lcp-1>=CURRENT_R){
//                to_remove_push.erase(mp(max(v[pos_v_1],v[pos_v_2])+lcp-1,mp(pos_v_1,pos_v_2)));
//                push--;
//                value-=CURRENT_R-max(v[pos_v_1],v[pos_v_2])+1;
//            }
//            else{
//                value-=lcp;
//            }
//        };
//
//        auto add_to_setik=[&](int id)
//        {
//            LOG("add_to_setik",s.substr(id));
//            int value_of_id=pos[id];
//            auto it=setik.insert(value_of_id).fir;
//            if (it!=setik.begin() && next(it)!=setik.end()){
//                remove_pair_from_setik(*prev(it),*next(it));
//            }
//            if (it!=setik.begin()){
//                add_pair_to_setik(*prev(it),*it);
//            }
//            if (next(it)!=setik.end()){
//                add_pair_to_setik(*it,*next(it));
//            }
//        };
//        auto remove_from_setik=[&](int id)
//        {
//            LOG("remove_from_setik",s.substr(id));
//            int value_of_id=pos[id];
//            auto it=setik.find(value_of_id);
//            if (it!=setik.begin()){
//                remove_pair_from_setik(*prev(it),*it);
//            }
//            if (next(it)!=setik.end()){
//                remove_pair_from_setik(*it,*next(it));
//            }
//            if (it!=setik.begin() && next(it)!=setik.end()){
//                add_pair_to_setik(*prev(it),*next(it));
//            }
//            setik.erase(value_of_id);
//        };
//        auto try_remove_push=[&](pii poses_v)
//        {
//            const int pos_v_1=poses_v.fir;
//            const int pos_v_2=poses_v.sec;
//            int lcp=get_lcp(pos_v_1,pos_v_2);
//            assert(max(v[pos_v_1],v[pos_v_2])+lcp-1==CURRENT_R);
//            {
//                push--;
//                value-=CURRENT_R-max(v[pos_v_1],v[pos_v_2])+1;
//            }
//            {
//                value+=lcp;
//            }
//        };
//
//        CURRENT_R=w-1;
//        for (int i=0;i<w;i++){
//            add_to_setik(i);
//        }
//        ans[0]=-value+1ll*w*(w+1)/2;
//        LOG("found zero answer",ans[0]);
//        while (!to_remove_push.empty() && to_remove_push.begin()->fir==w-1){
//            try_remove_push(to_remove_push.begin()->sec);
//            to_remove_push.erase(to_remove_push.begin());
//        }
//
//
//        for (int i=1;i+w-1<n;i++){
//            value+=push;
//            CURRENT_R=i+w-1;
//            remove_from_setik(i-1);
//            add_to_setik(i+w-1);
//            ans[i]=-value+1ll*w*(w+1)/2;
//            LOG("found",i,"answer",ans[i]);
//            while (!to_remove_push.empty() && to_remove_push.begin()->fir==i+w-1){
//                try_remove_push(to_remove_push.begin()->sec);
//                to_remove_push.erase(to_remove_push.begin());
//            }
//        }
    };
    for (int i=0;i<len(s)+3;i++){
        ans[i]=0;
    }
    solve_all();
//    for (int i=0;i+w-1<len(s)-1;i++){
//        ll smart_ans=ans[i];
//        ll naive_ans=naive(s.substr(i,w));
//        if (smart_ans!=naive_ans){
//            LOG(i,smart_ans,naive_ans);
//            cerr<<"VERY_BAD"<<"\n";
//            exit(123);
//        }
//    }
    for (int i=0;i<q;i++){
        int pos;
        if (gen){
            pos=1;
            cerr<<pos<<"\n";
        }
        else{
            cin>>pos;
        }
        pos--;

        cout<<ans[pos]<<"\n";
    }

    if (stress){
        goto start_of_program;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

aabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklbcdefghijklaabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklbcdefghijklaabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijk...

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 8004kb

input:

h
1 1
1

output:

1

result:

ok single line: '1'

Test #3:

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

input:

vwjwmutobxwxlrsfaobyjfvoiyorjrmpmffhawvnzmysksisyydwcnxgfeebxvjxkutcnfewrhzfwstfgwlkrhxerwnlajwtbqwclxthelwmubhohmaasdhfmrbwxdpsuiqtidpcymhxzpuraiwlcnunlxwmdwbilygplhhhsapknfkfgixzfdubnsncxrkitmlyowfxpkoxkyefebtodtpmaokqekayutrrsrpdrzcayejjldwqcjfbkkzqcalpvymyfpgcktduokmhzxflkuxrspskxojfamnbwvkcqdui...

output:

19896
19903
19897
19903
19895
19901
19901
19890
19902
19892
19895
19890
19901
19902
19898
19895
19899
19894
19899
19898
19897
19901
19903
19902
19898
19901
19889
19893
19900
19902
19902
19895
19899
19897
19902
19898
19894
19897
19895
19903
19899
19904
19902
19898
19899
19900
19895
19898
19896
19902
...

result:

ok 801 lines

Test #4:

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

input:

uoqfzyauodpiuajlubsvwhnhocuabggiyqyzmpjjclfkplsvgtvwavaffixcsczwrzjwbzpoxpdniimytyhkdgukcnjldmjtfeaxrghqgrtigjeevooernhuyjjqhxlxsyaieiuphcqepnotevpxyxosnweguftdpxjshhiqcwqzxbvqbwndmoqcvvmedomuacmbstvmrwvuqaowtmypodcdqqsajbxfcgcykysoemtqhttftzzisfnmtborexdsufbxwtvpymepuqlzbrxspnbvhigaszqwxeurlkfgzcyk...

output:

124639
124650
124645
124648
124644
124641
124642
124650
124644
124642
124641
124643
124650
124646
124642
124645
124638
124644
124650
124644
124647
124650
124646
124642
124648
124644
124648
124641
124636
124643
124646
124641
124648
124642
124640
124641
124642
124644
124639
124640
124641
124637
124640...

result:

ok 501 lines

Test #5:

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

input:

zcaexqnlgdgmbsxqxondhmoiydslhsbmuupsnybhpsuojmzhrrnmezrtdjsdxrzyhsvqvsdifxjsrujqmhvgiqiqhvjwfhqetgclyigdefthqojxokfyqbhoqllcunrmylvgvuguwyvgpwahcysdggiqrdigufvnsphdkubzgrngogzkwamztvonzjohrgvcwnmhlfsdsswhslfnozyyvjhixraeggmdjxhcqwfursolwsnwafxobanaoknjluugyobggfrkodkoxjkpjjinvegqpmpzpfrmmeohfflnlbqr...

output:

363003
363007
363007
363010
363005
363002
363000
363004
363007
363007
363004
363011
363006
363001
362996
363008
363007
363002
363006
363010
363009
363002
363011
363007
363000
363010
362996
363012
363006
363010
363006
362998
363007
363009
363001
363004
363006
363007
363006
363006
363007
363006
362996...

result:

ok 148 lines

Test #6:

score: 0
Accepted
time: 678ms
memory: 13564kb

input:

juzjdnbvgcimcmamvwhftxlxqtgzydnerbodyxozhytmgfzjqytgtiqtjdshnjovtblnkyaxofcgymiruovccchxihfwpgiyabmatpxswsgorenokrvwjdhvremvyizfppvntcvpiglqtontoryoqlgapvrjwcogqupohcsmfxnsieonjuplvnmynqblprouiowemzsfknregonbhvlzzqckuuejkuddtztavfpselqdrqeqjbolewxdkcgtwdpvxnupgdraecjngmzeldihfybzgupogpexubkuvpuxfmhl...

output:

199962302
199962198
199962296
199962355
199962324
199962289
199962130
199962187
199962298
199962231
199962236
199962304
199962361
199962159
199962191
199962193
199962297
199962324
199962318
199962315
199962236
199962159
199962342
199962207
199962249
199962282
199962226
199962257
199962214
199962208
...

result:

ok 80001 lines

Test #7:

score: 0
Accepted
time: 644ms
memory: 12236kb

input:

syshnllewpgkeatmxcjrizhrosmhgdmwachmclrsgtnwsbezjeeiyvbggiegdkndalyddgrnxqncwdvytxdrmkihngpahllbxdfuaaswtgpuhwwrcfypidwrugcbmckofugfmwuovgmzytwmgaqnevbodbgazsjyrcftokyzcwwfkojvwnwwzdlkgbzdnatzykmjnnrzgeneanlalichiuekufyqvmcjttdrgtkwrmczzivhloxpkcsghcijpkcuqeczdjxaqvechhbdehppaxwiijtvwovfrjlwyyzxavvj...

output:

799914664
799914650
799914661
799914659
799914666
799914681
799914679
799914596
799914675
799914644
799914652
799914641
799914681
799914662
799914666
799914663
799914649
799914589
799914676
799914730
799914666
799914649
799914665
799914649
799914674
799914653
799914666
799914624
799914651
799914631
...

result:

ok 60001 lines

Test #8:

score: 0
Accepted
time: 660ms
memory: 11732kb

input:

hewueccnuowvhxlncsmcpjwtexkgzrvmrrcsqsgweryysixaqqwwqjkudbinoaidttgbsrxfhjiafzpeliciqzhoacniiiwievcwnpsbvffllinuqrgglbrwfehxdzjovwncxdnxpmrqwxobumdograeaceovwyjldoyyliwnulkhgvcebzfaajgsnrkzdlbbffdipumiosnflyfblgwqgbduuvfxkwmqkishmhnfrtbvhtigcvoguqfzxyxyqgnqgxypdrxdwqvvgnibnbstjcslifgynckonjowdhupzev...

output:

1249889626
1249889580
1249889620
1249889576
1249889537
1249889623
1249889604
1249889613
1249889584
1249889551
1249889595
1249889618
1249889553
1249889578
1249889603
1249889559
1249889631
1249889561
1249889553
1249889559
1249889557
1249889599
1249889538
1249889553
1249889597
1249889541
1249889560
124...

result:

ok 50001 lines

Test #9:

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

input:

ethqkqfhfutukoldnznzdqmsgtngmltwhrcuahsnjcawvuiowqhiqgefhrjvmbuotnfsubcidzsjmtxlnwvigwktflsonoxtnektwvxvnpapqxmsxuystjcdfstzdsccercqyqtbfliscujqvisujewuxhrkkuqgtqpfipkjhaxoeulscxmojopgymoermnaysvkvtkskdxthbxvnwewkpafbpgjiumyzuauoocplygefhrygddhyvpteqsfomnqnqrijazjqbrtpejlorbpilrfklsxrwsleytfxidjpjei...

output:

1799863790
1799863768
1799863767
1799863736
1799863748
1799863717
1799863751
1799863788
1799863789
1799863797
1799863694
1799863754
1799863737
1799863810
1799863779
1799863741
1799863776
1799863772
1799863765
1799863719
1799863756
1799863741
1799863769
1799863805
1799863739
1799863786
1799863784
179...

result:

ok 40001 lines

Test #10:

score: 0
Accepted
time: 565ms
memory: 12536kb

input:

hydhahfcvooolxgfrnbaatarltextvnhvvrpfighsfhkzpeudsqxvuzohdmzwlabfteqbfctdubxuyivyqyactqolebuojpzksyqhfacunujbcposvcghiglqiygxsonqhwedicvadbsrjhaqcoxuqarodrmlgilpevbskthybubceaqaaukbnnshdddmnjlpkyfalxyibszdejsmkjyjpgkvnyxbtavxlbamutvhocgnlptvuxamucrkeyejkmqvspewlvlnfridkeeiqzawpysaoswrnxbznmdpkuqqwil...

output:

3199811245
3199811180
3199811274
3199811166
3199811143
3199811252
3199811166
3199811246
3199811256
3199811241
3199811170
3199811242
3199811239
3199811190
3199811170
3199811161
3199811160
3199811173
3199811232
3199811243
3199811244
3199811184
3199811250
3199811241
3199811256
3199811265
3199811262
319...

result:

ok 20001 lines

Test #11:

score: 0
Accepted
time: 564ms
memory: 14916kb

input:

igtescyxbpxjpejcjpqsmegebxzustibymlhxaajoexmrraglnxbdbnpuvxefevmdjwkphzopfagqvuudypeycizhwrpqkweppeffrusvjrrueludueybmuvjdjstvtxazugktmatowrzpiacgeaqnwdrwzrazoloriaqgxzgrbqypshlmrhpdjpmsqnschkemzdtwkugplvvpgfyhtqecezdiprxkwqiuswtsbeoojuubqmeeslgzktiixcdsueriviteqhwktiucoetuyfjsbjrzpmpqcrshmhnslftkjg...

output:

4049784531
4049784611
4049784543
4049784550
4049784530
4049784554
4049784543
4049784553
4049784585
4049784552
4049784609
4049784542
4049784611
4049784551
4049784581
4049784553
4049784563
4049784604
4049784533
4049784601
4049784576
4049784559
4049784612
4049784623
4049784552
4049784559
4049784564
404...

result:

ok 10001 lines

Test #12:

score: 0
Accepted
time: 545ms
memory: 11724kb

input:

ghogqtpbqromgltpueiafqdeoybvdcqipirofvyqlvuwvnhzjgppgkidllvzxyqajpaylnjqbudpywvnbefmjqlvkckfodtsxlqrcoiozpksfprthjjrjpulgxfqvdgoudtdbvairugnczbzzozrvpkjuzwitxwxacfdlxahpzvtffqexfpkeyelmxmjhiyscxblnqeliyyfgppquckmtbaduontlrbbtyljubvftlmyahyeyomsvcsmwnbwcyfaijikssmzjgjaxfuzblxhwksktecdpykmjduhpezzqwiy...

output:

4998457700
4998457700
4998457700
4998457698
4998457699
4998457699
4998457700
4998457699
4998457699
4998457697
4998457699
4998457699
4998457699
4998457698

result:

ok 14 lines

Test #13:

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

input:

aabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklbcdefghijklaabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklbcdefghijklaabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijk...

output:

1
1
1
1
1
1

result:

ok 6 lines

Test #14:

score: 0
Accepted
time: 514ms
memory: 12212kb

input:

wtpysanqqdopgxycudnyapftubepzmflglhnjqjsjhrcoexrlrtcauifvlszqbnfqednfehmtnatiflqdezcrccvpbzkdfofapnclpkmrnhqmbmdubvacmvxhwesxdrwakuopsrdnuzppkteltreoomugnzlouleanwfrdyhyrmwwxmmtevlresrravnrelljikthbarahniracnioddxokodeycrlsfrvjtnokfnqdwluhaojtzxfhgdklaxrprwymplerppgtbgyhvcwjtysuyjezkbhqyexaweptqitai...

output:

203
205
205
206
203
203
201
203
204
203
205
207
207
201
204
206
204
204
206
204
203
202
204
204
205
204
205
205
205
202
205
205
203
206
204
204
204
203
203
204
205
202
203
203
205
204
202
206
205
203
206
202
203
204
205
203
204
207
205
203
204
203
205
203
206
202
204
204
206
202
203
203
205
204
205
...

result:

ok 99981 lines

Test #15:

score: 0
Accepted
time: 502ms
memory: 14880kb

input:

dewqqhbjdmscxtekloodxzrlnseacujvlwdpkgupjmqanlzfulkwtpktabyqqocleasyjuzuuhhkndagrwyxpjcyikgdsgkyorwaktjyydxgmhylkgopxxelwgmkodywibtbtlybpoobheltlhvvxstkcemzldwhjyealcbdkayopgjxghcionacirttyqbbwffhaalevtptjdmsbvmvnkcybchvbddbpolhapbpcmksiwngfougkzdtcjxsxyttvcwwgfatjjqumxpdhakpnypsetculkdnkccitoruddvm...

output:

1246
1244
1246
1245
1246
1245
1242
1247
1243
1247
1247
1245
1244
1246
1245
1245
1246
1246
1242
1249
1242
1248
1248
1244
1247
1245
1246
1244
1247
1241
1249
1249
1245
1240
1247
1243
1245
1248
1242
1245
1248
1248
1246
1246
1243
1244
1246
1246
1245
1249
1242
1245
1246
1246
1246
1249
1244
1246
1245
1245
...

result:

ok 99951 lines

Test #16:

score: 0
Accepted
time: 597ms
memory: 13956kb

input:

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm...

output:

50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
50000
...

result:

ok 50001 lines

Test #17:

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

input:

aabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklbcdefghijklaabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklbcdefghijklaabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijklabcdefghijk...

output:

3
3
3
3
3
3

result:

ok 6 lines

Test #18:

score: 0
Accepted
time: 532ms
memory: 13456kb

input:

xgbrzwesatgpjxogvdgsxtzraeomppyhmncmfzpfykpopdplulsztkqatvtulmsnnscoxxkbwfgynesshcoosrkzqxytzzmtcxqgezipmnhpqpxbzengshchauaxbnpjokyxzvtanjyynwuwzumddmyrrmtugoejfomekersevtvysoaxtevgflgcykdqlgtzlsedqbbdluvcwnyytotvxwyimgxjdypjpehwpdnnvutizxagtzsykxcgjikbnzkirjkmyvhlrvrootblggzwlqxbfeqahynumkeppvrwygb...

output:

4999757347

result:

ok single line: '4999757347'

Test #19:

score: 0
Accepted
time: 675ms
memory: 13272kb

input:

mcsfvirxgvvougxbeuoaxtlymptmdetrwmfwhnhmrwzftvohdlixxogvwbkzdgoilraspabjmdzixbepreauiztlocdetrtgizthzrxuqgbchezvppatzvnbpdeltxdrkujylbdvijvdhvmtxzdxtzvoulayklgyedhjztgtivojvoxuyxpindnamvxbriciqcanmazscmwwxgjakfedtiieokjzahjnfwwbhoqroypkfwtsqadkjgphipubbrdktqlrkjnasgvppdsqsxjmfzuobvbbsiwhyxhzrvwxqfqu...

output:

49983252
49983281
49983193
49983169
49983263
49983296
49983212
49983248
49983258
49983280
49983241
49983224
49983172
49983205
49983264
49983267
49983283
49983175
49983333
49983279
49983206
49983204
49983204
49983212
49983253
49983285
49983177
49983268
49983212
49983265
49983213
49983205
49983215
499...

result:

ok 90001 lines

Test #20:

score: 0
Accepted
time: 626ms
memory: 11972kb

input:

rzgublvlmavktictlaqhxvjiwjflopgpzerwbtbvuguhvhpbzpifkffqkfylgmjymawmhagpkwuwmykwhbbnwalgecfczpcibpocgugwwpejzoqmktylvzvlopwjoqmestndnajoklttqlfjxagfjmzurjejktmtjveixhbpfeqdxhtafqxkrwzekmuqybyiyrecotnpzkooiceigukxrbpdcvbibqwujtawfpvzzhrkemqssoxqhjvuwfhkxqcjsjzcehultllbcgdcovxskhtpcdegpgksrnlbjuseokkx...

output:

499005
499018
499021
499020
499026
499024
499030
499047
498995
499026
499018
499016
499018
499008
499012
499022
499012
499012
499023
499019
499020
499026
499021
499026
499010
499032
499008
499033
499017
499036
499021
499009
499027
499028
499010
499017
499007
499025
499014
499027
499035
499015
499014...

result:

ok 99001 lines

Test #21:

score: 0
Accepted
time: 170ms
memory: 14944kb

input:

howoivzkpgsubumnbsrrczgdlmxyugsgqhljgsemkomsrehweurqompbbfmxsnwxgpuislnmqqigbfmzfhvpikhyhhecbmymjwjgawswcnrmpyquullqmpmbupczvfozleakivomcougwtsoeqlqovtekmgvfwnqcazwtwtywdmvmkexpqnhqrwqoixafkjthaqerpkflsboancvdxncncongohwswxbqeifzyajyuuvkkttolrxrlhieefazbivlflnvnplebjiwuwgscprcdcrpepsrofuxixrxgxwdtxp...

output:

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

Test #22:

score: 0
Accepted
time: 0ms
memory: 7788kb

input:

tngmmhocjo
6 5
5
6
1
4
3
2

output:

15
14
14
14
14
14

result:

ok 6 lines

Test #23:

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

input:

txxpimhvypzmbrgpdayablbpslmalwwujeojxykfbzdsazuzsfunnwwksahozwdehfnupkfkdigesxavnrijolvqooywhynrpbqzcwjtqfepmudpanyckkwxerlnztyppyvxqsvehhykhmpwmcvtzvfbvgslclhppivbyomdsutscliuwylnkqwaenjbriasqgckdmsaosdylqmgtvgxwgbeeikftmcijvljrhnkffvztgzxvmcszorfmbllstzroskvxptvfkewretsorusxrgxybrgavowhkvccusdjwsp...

output:

202
204
205
203
205
203
202
205
205
206
204
202
203
202
205
203
206
203
207
204
201
198
205
204
206
201
201
205
203
203
205
203
205
205
204
203
206
203
206
207
206
206
197
203
208
202
204
205
204
203
205
205
205
204
203
197
205
206
203
203
203
202
202
206
201
205
203
205
203
205
205
206
204
203
204
...

result:

ok 981 lines

Test #24:

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

input:

acat
2 3
1
2

output:

5
6

result:

ok 2 lines