QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706562#3277. 扑克比大小TheZone100 ✓7853ms368140kbC++2021.6kb2024-11-03 12:15:122024-11-03 12:15:13

Judging History

This is the latest submission verdict.

  • [2024-11-03 12:15:13]
  • Judged
  • Verdict: 100
  • Time: 7853ms
  • Memory: 368140kb
  • [2024-11-03 12:15:12]
  • Submitted

answer

#include<bits/stdc++.h>
#define maxh 20
#define maxn 1000050
using namespace std;
typedef long long LL;

LL exgcd(LL a,LL b,LL &x,LL &y) {
    if (!b)
        return x=1,y=0,a;
    else {
        LL g=exgcd(b,a%b,y,x);
        y-=a/b*x;
        return g;
    }
}

struct ArithmeticSeq {
    int a0,d,n;
    ArithmeticSeq(set<int> s)   {
        if (!s.size())
            a0=d=n=0;
        else {
            a0=*s.rbegin();
            d=(*s.rbegin()-*s.begin())/s.size();
            n=s.size();
            for (int i=0;i<n;++i)
                assert(s.count(a0+i*d));
        }
        normalize();
    }

    ArithmeticSeq(int _a0=0,int _d=1,int _n=0):a0(_a0),d(_d),n(_n)  {
        normalize();
    }

    ArithmeticSeq cut(int lim) {
        // a0+kd>=lim
        if (a0>=lim) return *this;
        int k=(lim-a0+d-1)/d;
        if (k>=n) return ArithmeticSeq();
        return ArithmeticSeq(a0+k*d,d,n-k);
    }

    void normalize()    {
        if (n<=1) d=1;
        assert(d>0);
    }
    int last()  {
        return a0+(n-1)*d;
    }
    vector<int> getSeq()    {
        vector<int> v;
        for (int i=0;i<n;++i)
            v.push_back(a0+i*d);
        return v;
    }
    // bool contains(int x)    {
    //     if ((x-a0)%d) return 0;
    //     int k=(x-a0)/d;
    //     return 0<=k&&k<n;
    // }
    friend ArithmeticSeq operator - (int x,ArithmeticSeq aq)   {
        return ArithmeticSeq(x-(aq.a0+(aq.n-1)*aq.d),aq.d,aq.n);
    }
    friend ArithmeticSeq operator + (int x,ArithmeticSeq aq)   {
        return ArithmeticSeq(x+aq.a0,aq.d,aq.n);
    }
    friend ArithmeticSeq operator & (ArithmeticSeq a,ArithmeticSeq b)    {
        if (a.a0>b.a0) swap(a,b);
        if (a.last()<b.a0) return ArithmeticSeq();
        // cout<<a<<" "<<b<<endl;
        assert(a.d>0&&b.d>0);
        LL x,y;
        // x*a.d+y.b.d = b.a0-a.a0
        LL g=exgcd(a.d,b.d,x,y),lcm=(LL)a.d*b.d/g;
        if ((b.a0-a.a0)%g) return ArithmeticSeq();

        // cout<<a.d*x+b.d*y<<" "<<b.a0-a.a0<<endl;

        x*=(b.a0-a.a0)/g;
        y*=-(b.a0-a.a0)/g;
        // cout<<a.a0+x*a.d<<" "<<b.a0+y*b.d<<endl;
        assert(a.a0+x*a.d==b.a0+y*b.d);

        LL same=a.a0+x*a.d;
        // same+k*lcm>=a0
        LL a_nxt=same+((a.a0-same+lcm-1)/lcm)*lcm;
        LL b_nxt=same+((b.a0-same+lcm-1)/lcm)*lcm;

        // cout<<same<<" "<<a.a0<<" "<<b.a0<<endl;

        LL new_a0=max(a_nxt,b_nxt);
        if (new_a0>a.last()||new_a0>b.last())
            return ArithmeticSeq();
        else {
            int new_n=min((a.last()-new_a0)/lcm,(b.last()-new_a0)/lcm)+1;
            return ArithmeticSeq(new_a0,lcm,new_n);
        }
        // cout<<a<<" "<<b<<endl;
        // if (a.d==b.d)   {
        //     int st=max(a.a0,b.a0),ed=min(a.a0+(a.n-1)*a.d,b.a0+(b.n-1)*b.d);
        //     return ArithmeticSeq(st,a.d,(ed-st)/a.d+1);
        // } else {
        //     if (a.n>b.n) swap(a,b);
        //     assert(a.n<=2);
        //     vector<int> sa=a.getSeq();
        //     set<int> res;
        //     for (int x:sa)  
        //         if (b.contains(x))
        //             res.insert(x);
        //     return ArithmeticSeq(res);
        // }
    }
    friend ostream& operator << (ostream& os,ArithmeticSeq aq)   {
        os<<"("<<aq.a0<<","<<aq.d<<","<<aq.n<<")";
        return os;
    }
};


int n,q;
char s[maxn];
int qLen[maxn];
int L[maxn],R[maxn];

int longest[maxn];

LL ans[maxn];

struct SA {

    int sa[maxn],rk[maxn];

    int Log2[maxn];
    int ST[maxh][maxn],* const h=ST[0];

    int sat[maxh][maxn],rkt[maxh][maxn];
    int st[maxh][maxn],ed[maxh][maxn];

    LL cnt[maxn];

    // template<LL base,LL modu>
    // struct HASH {
    //     LL h[maxn],pw[maxn];
    //     HASH()  {
    //         for (int i=pw[0]=1;i<maxn;++i)
    //             pw[i]=pw[i-1]*base%modu;
    //     }
    //     void build(char *s,int n)   {
    //         for (int i=1;i<=n;++i) 
    //             h[i]=(h[i-1]*base+s[i]-'a'+1)%modu;
    //     }
    //     LL operator ()(int l,int r) {
    //         return (h[r]+(modu-h[l-1])*pw[r-l+1])%modu;
    //     }
    // };

    // HASH<31,998244353> H1;
    // HASH<131,1000000007> H2;

    // pair<LL,LL> gethash(int l,int r)    {
    //     return make_pair(H1(l,r),H2(l,r));
    // }

    void build(char *s,int n)    { // no zero
        static int ts[2][maxn],sum[maxn];

        int *x=ts[0],*y=ts[1],m=256; // attention
        for (int i=1;i<=m;++i) sum[i]=0;
        for (int i=1;i<=n;++i) ++sum[x[i]=s[i]];
        for (int i=1;i<=m;++i) sum[i]+=sum[i-1];
        for (int i=n;i;--i) sa[sum[s[i]]--]=i;
        
        for (int b=0;(1<<b)<=n;++b)    {                
            auto calcnxt=[&]()  {
                memcpy(rkt[b],x,sizeof(rkt[b]));
                memcpy(sat[b],sa,sizeof(sat[b]));
                // cout<<"sat["<<b<<"]="; for (int i=1;i<=n;++i) cout<<sa[i]<<" "; cout<<endl;
                for (int i=n,j=n;i;i=j)  {
                    for (;j&&x[sa[i]]==x[sa[j]];--j)
                        ed[b][sa[j]]=i;
                    for (;i>j;--i)
                        st[b][sa[i]]=j+1;
                }
            };
            calcnxt();

            // cout<<"--------------------"<<endl;

            int p=0,k=1<<b;
            for (int i=n;i>n-k;--i) y[++p]=i;
            for (int i=1;i<=n;++i)
                if (sa[i]>k)
                    y[++p]=sa[i]-k;
            for (int i=1;i<=m;++i) sum[i]=0;
            for (int i=1;i<=n;++i) ++sum[x[y[i]]];
            for (int i=1;i<=m;++i) sum[i]+=sum[i-1];
            for (int i=n;i;--i) sa[sum[x[y[i]]]--]=y[i];
            swap(x,y);
            m=x[sa[1]]=1;
            for (int i=2;i<=n;++i)
                x[sa[i]]=(y[sa[i]]==y[sa[i-1]]&&y[sa[i]+k]==y[sa[i-1]+k]?m:++m);
        }

        for (int i=1;i<=n;++i) rk[sa[i]]=i;
        for (int i=1,k=0;i<=n;++i)  {
            if (k) --k;
            int j=sa[rk[i]-1];
            while (s[i+k]==s[j+k]) ++k;
            h[rk[i]]=k;
        }

        for (int i=1;i<=n;++i) cnt[i]=cnt[i-1]+n-sa[i]+1-h[i];

        // for (int i=1;i<=n;++i) cout<<"cnt["<<i<<"]="<<cnt[i]<<endl;

        Log2[0]=-1;
        for (int i=1;i<=n;++i) Log2[i]=Log2[i>>1]+1;
        for (int j=1;j<=Log2[n];++j)
            for (int i=1;i+(1<<j)-1<=n;++i)
                ST[j][i]=min(ST[j-1][i],ST[j-1][i+(1<<j-1)]);
    }
    inline int lcp(int i,int j)    {
        if (i>n||j>n) return 0;
        if (i==j) return maxn;
        int l=rk[i],r=rk[j];
        if (l>r) swap(l,r);
        ++l;
        int t=Log2[r-l+1];
        return min(ST[t][l],ST[t][r-(1<<t)+1]);
    }

    inline int compare(int i,int j)    {
        // return s[i:]<s[j:]
        if (i>n&&j>n) return 0;
        if (i>n||j>n) return i>n;
        return rk[i]<rk[j];
    }

    LL calcSmallerSuffix(int a,int b,char c) {
        // cerr<<"???:"<<rk[l]<<" "<<cnt[rk[l]-1]<<" "<<max(0,r-l+1-h[rk[l]])<<" "<<(r-l+1)<<endl;
        int len=b-a+1,lim=getLeftmostEqual(a,b);
        int l=lim-1,r=getRightmostEqual(a,b);
        // cerr<<"???:"<<a<<" "<<b<<" "<<c<<endl;
        while (l<r) {
            int mid=(l+r+1)>>1;
            // cerr<<l<<" "<<r<<":"<<mid<<" "<<sa[mid]<<" "<<len<<" "<<n<<" |"<<s[sa[mid]+len]<<"|"<<endl;
            assert(sa[mid]<=n-len+1);
            if (s[sa[mid]+len]<c)
                l=mid;
            else
                r=mid-1;
        }
        // cout<<l<<" "<<r<<endl;
        return cnt[l]-min(lcp(sa[l],a),len);
    }

    int getMaxRepeatedPrefix(int l,int r,int p) {
        int len=r-l+1;
        if (lcp(l,p)<len) return 0;
        return lcp(p,p+len)/len+1;
    }

    int getMaxRepeatedPrefixLen(int l,int r,int p) {
        int len=r-l+1,t=lcp(l,p);
        if (t<len) return t;
        return lcp(p,p+len)+len;
    }

    int getSmallerCnt(ArithmeticSeq stpos,int i) {
        // return \sum_{p\in stpos} s[p:]<s[i:]
        assert(stpos.d>0);
        int offset=getMaxRepeatedPrefix(stpos.a0,stpos.a0+stpos.d-1,stpos.last());
        int times=getMaxRepeatedPrefix(stpos.a0,stpos.a0+stpos.d-1,i);
        // cout<<"???:"<<stpos<<" "<<i<<" "<<times<<endl;

        auto calc=[&](ArithmeticSeq stpos)  {
            int cnt=0;
            if (stpos.n<=1) {
                vector<int> v_stpos=stpos.getSeq();
                for (int p:v_stpos)
                    cnt+=compare(p,i);
            } else {
                //[0,times) : stpos.last(), stpos.a0
                if (compare(stpos.last(),stpos.a0))
                    cnt+=min(times,stpos.n);
                
                // times
                if (stpos.n>times)
                    cnt+=compare(stpos.last(),i+times*stpos.d);
                
                // (times,n)
                if (stpos.n>times+1&&compare(stpos.a0,i+times*stpos.d))
                    cnt+=stpos.n-times-1;
            }
            // cout<<"calc:"<<stpos<<" "<<i<<" ~ "<<cnt<<endl;
            return cnt;
        };

        int res=calc(ArithmeticSeq(stpos.a0,stpos.d,stpos.n+offset))-calc(ArithmeticSeq(stpos.last()+stpos.d,stpos.d,offset));
        return res;
    }

    ArithmeticSeq getEqual(int p,int k,int l,int r)    {
        //s[p,p+2^k) 
        //return all start pos in [l,r]
        int a=lower_bound(sat[k]+st[k][p],sat[k]+ed[k][p]+1,l)-sat[k];
        int b=upper_bound(sat[k]+st[k][p],sat[k]+ed[k][p]+1,r-(1<<k)+1)-sat[k]-1;
        // cout<<"get("<<p<<","<<k<<","<<l<<","<<r<<") "; for (int i=st[k][p];i<=ed[k][p];++i) cout<<sat[k][i]<<" "; cout<<endl;
        // cout<<"a,b="<<a<<","<<b<<endl;
        assert(b-a+1<=1||sat[k][b]-sat[k][b-1]==sat[k][a+1]-sat[k][a]);
        return ArithmeticSeq(sat[k][a],sat[k][a+1]-sat[k][a],b-a+1);
    }

    int getLeftmostEqual(int a,int b)   {
        int l=1,r=rk[a];
        while (l<r)    {
            int mid=(l+r)>>1;
            if (lcp(sa[mid],a)>=b-a+1)
                r=mid;
            else
                l=mid+1;
        }
        return l;
        
        int lim=b-a+1,p=rk[a];
        // cerr<<(1<<Log2[n-p+1])<<endl;
        for (int i=Log2[p];i>=0;--i)
            if (p-(1<<i)>0&&ST[i][p-(1<<i)+1]>=lim)
                p-=(1<<i);
        return p;
    }    
    
    int getRightmostEqual(int a,int b)   {
        int l=rk[a],r=n;
        while (l<r)    {
            int mid=(l+r+1)>>1;
            if (lcp(sa[mid],a)>=b-a+1)
                l=mid;
            else
                r=mid-1;
        }
        return l;

        
        int lim=b-a+1,p=rk[a];
        // cerr<<(1<<Log2[n-p+1])<<endl;
        for (int i=Log2[n-p+1];i>=0;--i)
            if (p+(1<<i)<=n&&ST[i][p+1]>=lim)
                p+=(1<<i);
        return p;
    }
    inline pair<int,int> getRange(int a,int b) {
        return make_pair(
            getLeftmostEqual(a,b),
            getRightmostEqual(a,b));
    }
    // inline void getRange(int a,int b,int &l,int &r) {
    //     l=getLeftmostEqual(a,b);
    //     r=getRightmostEqual(a,b);
    // }
} S,T;

namespace BIT  {
    int T[maxn];
    inline int lowbit(int x)    {
        return x&-x;
    }
    void add(int i) {
        for (;i<=n;i+=lowbit(i))
            ++T[i];
    }
    int query(int i)    {
        int ans=0;
        for (;i;i-=lowbit(i))
            ans+=T[i];
        return ans;
    }
}

int CNT=0;

void getRepeat()    {
    for (int i=1;i<=q;++i)  {
        int l=1,r=n+1;
        while (l<r) {
            int mid=(l+r)>>1;
            auto check=[&](int p)->bool    {
                int len=S.getMaxRepeatedPrefixLen(L[i],R[i],p);
                assert(len<=n-p+1);
                if (len==n-p+1) return 0;
                return s[p+len]>s[L[i]+len%qLen[i]];
            };
            if (check(S.sa[mid]))
                r=mid;
            else
                l=mid+1;
        }
            // cout<<i<<":"<<L[i]<<" "<<R[i]<<endl;
        //sa[l-1]^inf<=substr^inf<=sa[l]^inf
        if (l>1)    {
            // cout<<"l-1:"<<string(s+S.sa[l-1],s+n+1)<<endl;
            int t=S.getMaxRepeatedPrefixLen(L[i],R[i],S.sa[l-1]);
            if (t>longest[i])   {
                L[i]=S.sa[l-1];
                R[i]=L[i]+qLen[i]-1;
                longest[i]=t;
            }
        }
        if (l<=n)   {
            // cout<<"l:"<<string(s+S.sa[l],s+n+1)<<endl;
            int t=S.getMaxRepeatedPrefixLen(L[i],R[i],S.sa[l]);
            if (t>longest[i])   {
                L[i]=S.sa[l];
                R[i]=L[i]+qLen[i]-1;
                longest[i]=t;
            }
        }
        R[i]=L[i]+longest[i]-1;
            // cout<<i<<":"<<L[i]<<" "<<R[i]<<" "<<endl;
    }
    for (int i=1;i<=q;++i)  {
        char nxt=s[L[i]+(R[i]-L[i]+1)%qLen[i]];
        // cout<<i<<":"<<longest[i]<<endl;
        // cerr<<i<<":"<<S.calcSmallerSuffix(L[i],R[i],nxt)<<" "<<nxt<<endl;
        ans[i]+=S.calcSmallerSuffix(L[i],R[i],nxt);
    }
}


int calcCyclicShift(int l,int r,int repeatedLen) {
    // cout<<"calcCyclicShift:"<<l<<" "<<r<<" "<<repeatedLen<<endl;
    int originalLen=(r-l+1);
    int repeatedTimes=repeatedLen/originalLen,scatteredLen=repeatedLen%originalLen;
    vector<ArithmeticSeq> borders;
    for (int b=0;(1<<b)<originalLen;++b)  {
        // cout<<"b:"<<b<<endl;
        int stLen=1<<b,edLen=min((1<<b+1),originalLen)-1;
        //only consider border len in [st,ed]
        // cout<<"["<<stLen<<","<<edLen<<"]"<<endl;
        auto front=S.getEqual(l,b,r-edLen+1,r),back=S.getEqual(r-stLen+1,b,l,l+edLen-1);
        if (!front.n||!back.n) continue;
        // cout<<front<<" "<<back<<endl;
        auto border=(r+1-front)&(stLen-l+back);
        borders.push_back(border);
    }
    int res=0;
    // cout<<"initial:"<<res<<endl;
    auto calc=[&](ArithmeticSeq border) {
        if (!border.n) return 0;
        int res=0;
        // cout<<border<<endl;
        // s[l,r]=s[l,r-border]+s(r-border,border]=a+b(order), judge a: aab<aba -> ab<ba?

        // minus s[l+|b|:]<s[r+1:]
        // cout<<"minus:"<<S.getSmallerCnt(l+border,r+1)<<endl;
        res-=S.getSmallerCnt(l+border,r+1);

        // judge s[l+|b|,r]<a
        // plus s[l+|b|:]<s[l:]
        // cout<<"plus:"<<S.getSmallerCnt(l+border,l)<<endl;
        res+=S.getSmallerCnt(l+border,l);
        // minus s(r:]<s[l+|a|:] if s[l,r-|b|] == s[l+|b|,r]
        for (auto tmp_border:borders)   {
            ++CNT;
            auto complement_border=tmp_border&(originalLen-border);

            // cout<<tmp_border<<" & "<<originalLen-border<<" = "<<complement_border<<endl;
            if (!complement_border.n) continue;
            // cout<<"minus:"<<complement_border<<" "<<complement_border.n<<"-"<<S.getSmallerCnt(complement_border,r+1)<<endl;
            res-=complement_border.n-S.getSmallerCnt(l+complement_border,r+1);
        }
        // cout<<"res:"<<res<<endl;
        return res;
    };

    for (auto border:borders)  {
        // cout<<"border:"<<border<<endl;
        res+=repeatedTimes*calc(border);
        auto rest=border.cut(originalLen-scatteredLen);
        res+=calc(rest);
    }
    return res;
}

vector<int> Q[maxn];

int main()  {
    // cout<<(ArithmeticSeq(3,1,1)&ArithmeticSeq(2,2,2))<<endl;
    // return 0;
    scanf("%s%d%*d",s+1,&q),n=strlen(s+1);
    S.build(s,n);
    // cout<<"S:"<<endl; for (int i=1;i<=n;++i) cout<<S.sa[i]<<":"<<string(s+S.sa[i],s+n+1)<<endl;

    for (int i=1;i<=q;++i)
        scanf("%d%d",L+i,R+i),qLen[i]=longest[i]=R[i]-L[i]+1;
    
    cerr<<"input:"<<clock()<<endl;
    getRepeat();

    cerr<<"getRepeat:"<<clock()<<endl;
    for (int i=1;i<=q;++i)  
        Q[S.rk[L[i]]].push_back(i);
    for (int i=n;i;--i) {
        BIT::add(S.sa[i]);
        for (int j:Q[i])    {
            int l=L[j],r=L[j]+qLen[j]-1;
            int originalLen=qLen[j];
            int repeatedLen=longest[j],scatteredLen=repeatedLen%originalLen;
            int suml=BIT::query(l),sumr=BIT::query(r),sums=BIT::query(l+scatteredLen);
            ans[j]+=(sumr-suml)*(repeatedLen/originalLen)+
                    (sums-suml);
        }
    }
    for (int i=1;i<=q;++i)
        ans[i]+=calcCyclicShift(L[i],L[i]+qLen[i]-1,R[i]-L[i]+1);

    for (int i=1;i<=q;++i)
        printf("%lld\n",ans[i]);

    cerr<<"std2 inspired by claris:"<<clock()<<" "<<CNT<<endl;
    return 0;
}










































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 7ms
memory: 126796kb

input:

gpmchphqtoewibpxjijvzkwxcgmsuzlzwyetfcgfestkqdwoenrkcfutwwcpcsvlbtxztqtqpxzsiagvmqlumnmwnczrjasrtctj
100 0
70 89
50 80
86 99
5 21
22 22
78 84
4 24
5 33
38 87
90 100
2 38
17 37
76 89
70 72
9 15
9 50
6 80
26 82
35 64
92 94
42 86
58 63
93 95
31 62
37 81
39 97
63 99
75 98
6 83
2 83
34 66
24 50
56 89
33 ...

output:

3119
2412
2366
1283
1871
6
429
1293
244
520
2777
1736
3208
3130
3518
3579
2664
1116
746
3132
3254
4054
1652
2076
878
1062
3887
4846
2645
2739
4653
4453
3689
4345
4701
823
3102
1879
2309
4654
2141
2992
3568
2418
1436
4524
3424
464
1269
1569
1146
33
3585
3081
521
4377
773
1538
3944
3931
1511
1662
1336...

result:

ok 100 numbers

Subtask #2:

score: 3
Accepted

Dependency #1:

100%
Accepted

Test #2:

score: 3
Accepted
time: 8ms
memory: 151500kb

input:

ebyayehwtmbkbzulmkxfervkmfykgxsjrelikxcgmoyqsyaceqbvlefljdnpiojzmccozfgqoiyxwjlrmcxjkychbveymajboableifxlznapnoeadfsoucgmznkjxigkogssktxvrglogjpfrpblwphejvccecuqimovwkqxvvyqqwujilpukqhiwupssefreakpvgydelftrcsszjqvzajhrjfarasgdzxvjusqalspkwewzfmuscyrcdpczpikdzxqfdkbzczsfkamvcxharpuudnuscatmaysoqauwug...

output:

47895
122488
122381
124033
118381
54569
787
103487
5087
4028
20327
51540
14956
107617
73537
64907
79188
55935
15464
121545
48057
32220
117075
71820
14883
46712
13783
42198
113222
109256
33853
79452
71075
75192
52549
114622
56295
1620
72678
61671
70960
62992
66521
27563
19811
105508
32699
20713
79516...

result:

ok 1000 numbers

Subtask #3:

score: 4
Accepted

Dependency #2:

100%
Accepted

Test #3:

score: 4
Accepted
time: 3ms
memory: 144676kb

input:

qvdudzxdwaeplkonnepjvdrwzcvxkwayfdmcgqbkiroiizylnwafxhubsclximclkktpqftipatognjscpkpqyuzgatulfqgrakbwmuerjytvqnsfkuttxlapzqdnprrpqfaqyvrdkiwweqcuggldstqgqyixsvkxlxwpspnrgtlnjexnseutufasdkcdvabqxavkwbafxesdcdentwzerbnyyzjqqtmudouevvvyxagpvtaijauvelepqhdayntsckwlyfaftrntvdusiaxggzmgpqrjdruochqornjiusu...

output:

1505691
132814
1571486
1804936
1053469
88111
508546
346157
584836
1835764
847106
1386437
1034980
607370
997807
510061
797
1491959
95847
1389451
1321594
1015708
1573409
280982
993901
971459
1277519
1929986
1861401
168628
676385
253080
915695
539814
1319795
500455
1632091
1178771
71471
991618
94971
14...

result:

ok 1000 numbers

Subtask #4:

score: 5
Accepted

Dependency #3:

100%
Accepted

Test #4:

score: 5
Accepted
time: 16ms
memory: 173348kb

input:

glxlmplfwkafkoeysfwpchissapjawrujbnmwvbsafjbiinehaaeojghhcnfkujxqjyynpozujapcxvgbdjjjtibqxqhnogijrwxrjfjuboorpuewbvknjxqqsydmkgidagnszrlrshymymqbiftozljvjmqltpkqpghgnhdmrmqerjpahkpikakziyoufmdismhmjpcuqluvhwfenhfqvvgtuioxdhnhuwgxdomgmmfcragyomoyyxjsoikueafkftdeukewgqigxlusjyktixcdicmbrapfqrnhhlzxzql...

output:

198459510
161768841
4260348
129436102
147681231
190617245
33102237
107309208
13932072
21193754
156034118
78905608
83560950
118986805
47045359
45546537
172722453
49562233
134076958
54760034
86143823
2278754
12362873
20789535
124363592
161682
44284296
188884102
146550007
105908796
30388769
138470414
1...

result:

ok 2000 numbers

Subtask #5:

score: 13
Accepted

Test #5:

score: 13
Accepted
time: 81ms
memory: 204444kb

input:

ptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnilxeiwptfvqjyebnil...

output:

2600214491
234322978
178550128
4618526788
3089340961
1611565257
2489821914
3376234074
1795863414
119373639
867848397
4365343760
1077563815
3302402716
1795863414
2201424720
3015994868
867848397
982836021
2249632924
1916710857
2275070839
357171478
234322978
1795863414
3914270799
2984979401
2056198838
...

result:

ok 50007 numbers

Test #6:

score: 13
Accepted
time: 44ms
memory: 203516kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
10...

result:

ok 446 numbers

Subtask #6:

score: 17
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Test #7:

score: 17
Accepted
time: 299ms
memory: 213000kb

input:

ydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhbxwnwydxjyyptvzhyjhb...

output:

4691536832
4816843896
4511161276
2551312724
3138671926
3307046831
705462224
1037726150
749495791
3505313524
4457484524
4532367468
4817909602
2071319457
2107942959
2681583131
3003312425
4538218408
2254252445
3923515932
4553496746
3100882973
3966938415
4542734085
3929794381
4515561410
743563073
786585...

result:

ok 100000 numbers

Test #8:

score: 17
Accepted
time: 926ms
memory: 205580kb

input:

bpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbpgfbioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioioi...

output:

0
34599958
34599959
37396878
34599960
34699848
34699849
37396878
34699850
34799738
34799739
37396878
34799740
34899628
34899629
37396878
34899630
34999518
34999519
37396878
34999520
35099408
35099409
37396878
35099410
35199298
35199299
37396878
35199300
35299188
35299189
37396878
35299190
35399078
3...

result:

ok 100000 numbers

Test #9:

score: 17
Accepted
time: 779ms
memory: 235248kb

input:

hnhnzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzlyzldufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufgsdufg...

output:

927996233
927996235
927996234
927996235
1741924763
1741924762
1741924657
1741924761
1741924760
1741924657
1741924759
1741924758
1741924657
1741924757
1741924756
1741924657
1741924755
1741924754
1741924657
1741924753
1741924752
1741924657
1741924751
1741924750
1741924657
1741924749
1741924748
1741924...

result:

ok 100000 numbers

Subtask #7:

score: 15
Accepted

Test #10:

score: 15
Accepted
time: 2982ms
memory: 368140kb

input:

rpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrrpfrpfrpfrpfrpfrrpfrpfrpfrrpfrpfrpfrpfrpfrrp...

output:

0
8249847199
8400786006
9418362944
9528914745
20451852105
52009861325
55801477954
56202722445
66544971749
80513493110
83513555323
86122500314
97742106533
162159626
80384047580
1923065088
56246462704
4625981329
84900851607
1702085893
7903328193
4637642960
6364221692
86122816163
96858590293
5321405566...

result:

ok 350535 numbers

Test #11:

score: 15
Accepted
time: 7853ms
memory: 358796kb

input:

mhroxfbhroxfbhroxfbhroxfbhroxfbhroxfbhroxfbhroxfbhroxfbhrolplauvlplauvlplauvlprsokrmbpmrzhaneepmrzhaneozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsihozjlzbsih...

output:

33327633696
33327633696
33327633696
33327633696
33327633696
33327633696
33327633696
33327633696
33327633696
17777694274
33327633696
32963834780
33327633696
33327633696
33327633696
33327633696
33327633696
33327633696
33327633696
33327633696
33327633696
33327633696
32963834780
33327633696
33327633696
...

result:

ok 500000 numbers

Subtask #8:

score: 15
Accepted

Test #12:

score: 15
Accepted
time: 911ms
memory: 354588kb

input:

hqbegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegmbzmegm...

output:

30621865452
27052468306
21585476836
27052436309
21585500808
21585502312
21585487615
81814463082
81814463419
81814469181
21585484134
81814467827
30621856849
30621856462
81814464167
81814493584
30621857547
81814497526
30621857904
81814463617
81814496967
21585495498
21585496448
21585482385
79343572369
...

result:

ok 500000 numbers

Test #13:

score: 15
Accepted
time: 5297ms
memory: 357344kb

input:

abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...

output:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
10...

result:

ok 500000 numbers

Subtask #9:

score: 25
Accepted

Test #14:

score: 25
Accepted
time: 4573ms
memory: 338648kb

input:

impimpimpimpimpimpixtikiikikiikiikikiikikiikiikikiikiikikiikikiikiiccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

output:

42455543545
42466837404
42466837416
42466837405
42466837406
42466837416
42466837407
42466837408
42466837416
42466837409
42466837410
42466837416
42466837411
42466837412
42466837416
42466837413
42466837414
42466837416
42466837415
54237329093
52962901612
42455543545
42466387787
42460513065
42460121429
...

result:

ok 500000 numbers

Test #15:

score: 25
Accepted
time: 3534ms
memory: 349076kb

input:

fonkononkonkononkononkonkononkonkononkononkonkononkononkonkononkonkononkononkonkononkonkononkononkonkononkononkonkononkonkononkononkonkononkononkonkononkonkononkononkonkononkonkononkononkonkononkononkonkononkonkononkononkonkononkonkononkononkonkononkononkonkononkonkononkononkonkononkononkonkononkonk...

output:

33872416222
32212122064
33334324166
31674030008
28155114591
33666193789
32005899635
28486984218
33872035225
32211741070
33461114341
31800820190
28281904777
33666955777
32006661625
33334324171
31674030018
28155114604
33586761519
31926467376
28407551966
33792602951
32132308807
33459971349
31799677204
...

result:

ok 500000 numbers

Test #16:

score: 25
Accepted
time: 3482ms
memory: 363236kb

input:

mlqityzrbuzrbuxmrnxxmrnxxmrnxxmrbeefeybeefeybeefeybeefeybeefeybeefeybeefeybebeefeybeefeybeefeybeefeybeefeybeefeybeefeybeefeybeefeybeefeybeefeybebeefeybeefeybeefeybeefeybeefeybeefeybeefeybebeefeybeefeybeefeybeefeybeefeybeefeybeefeybeefeybeefeybeefeybeefeybebeefeybeefeybeefeybeefeybeefeybeefeybeefeybe...

output:

55169302249
79109566021
80561375449
80511223620
80504100807
80504100802
80504100806
80504100805
80504100802
1053664090
18324808841
18373839201
21233598373
21144136333
75006008819
1048955347
18320100098
18369130459
21228889633
21139427592
75001300080
1044246603
18315391355
18364421717
21224180893
211...

result:

ok 500000 numbers

Extra Test:

score: 0
Extra Test Passed