#include using namespace std; #define MD 1000003 long long S[26]; char T[1000010]; int xlen[1000010]; long long xnnn[1000010]; int inv[1000010]; int fac[1000010]; int get_inv(long long a, int md){ long long e, s=md, t=a, u=1, v=0; while(s){ e=t/s; t-=e*s; u-=e*v; swap(t,s); swap(u,v); } if(u<0){ u+=md; } return u; } void mkinv(){ for(int i=1;i>S[c]; } cin>>T; int tlen=strlen(T); int r=1; int mc=0; for(int c=0;c<26;++c){ priority_queue> pq; int n=0; int st=-1; int xsum=0; for(int i=0;i<=tlen;++i){ if(T[i]==c+'a'){ if(st<0){ st=i; } }else{ if(st>=0){ int xl=i-st; xlen[n]=xl; //pq.push(make_pair(1.*(xl+1),n)); ++n; //if((S[c]-=xl)<0){ xsum+=xl; if(xsum>S[c]){ cout<<0; exit(0); } st=-1; } } } if(xsum) { #if 1 long long xdiv = S[c]/xsum; S[c]%=xsum; for(int j=0;j