Language: C++

#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=200005;
const int maxm=30;
const int H=31;
ll l,r;
int n,len,len2; 
string s;
int cnt[maxn][maxm];
int hash[maxn],power[maxn],z[maxn];
ll ans[maxm];

void Z_algorithm(){
	z[0]=0;
	int L=0,R=0;
	REP(i,n-1){
		if(R<=i){
			for(int j=0;i+j<n;j++)
			if(s[j]==s[i+j])z[i]++;
			else break;
			if(z[i])L=i,R=i+z[i]-1; 
		} 
		else{
			if(i>L&&i<R&&z[i-l]<=r-i)z[i]=z[i-l];
			else{
				z[i]=r-i;
				for(int j=r-i;i+j<n;j++)
				if(s[j]==s[i+j])z[i]++;
				else break;
				if(z[i])L=i,R=i+z[i]-1;
			}
		}
	}
}


bool same(int pos){
	int k1=hash[pos-1],k2=hash[n-1]-hash[n-1-pos]*power[pos];
	return k1==k2;
}

inline vector<ll>add_vector(vector<ll>a,vector<ll>b){
	rep(i,26)b[i]+=a[i];
	return b;
}

ll solve(ll l_len,vector<ll>L,ll r_len,vector<ll>R,ll rest,vector<ll>&Ans){
	if(l_len+r_len<=rest){
		vector<ll>sum=add_vector(L,R);
		ll x=solve(l_len+r_len,sum,l_len,L,rest,Ans);
		rest=x;
	}
	if(l_len<=rest){
		Ans=add_vector(Ans,L);
		rest-=l_len;
	}
	return rest;
}

int main(){
	ios::sync_with_stdio(false);
	cin>>s>>l>>r;
	l--;r--;
	s=s.substr(0,s.size()/2);
	n=s.size();
	
	rep(i,n){
		rep(j,26){
			if(s[i]-'a'==j)cnt[i][j]=!i?1:cnt[i-1][j]+1;
			else cnt[i][j]=!i?0:cnt[i-1][j];
		}
	}
	
	hash[0]=s[0]-'a';power[0]=1;
	REP(i,n-1)hash[i]=hash[i-1]*H+s[i]-'a',power[i]=power[i-1]*H;
	REP(i,n-1)if(same(i))len=max(len,i);
	
//	Z_algorithm();
//	REP(i,n-1)if(z[i]+i==n)len2=max(len2,i);

	if(len==0){
		rep(j,26){
			ans[j]+=(ll)cnt[n-1][j]*(r/(ll)n)+(ll)cnt[r%(ll)n][j];
			if(l-1>=0)ans[j]-=(ll)cnt[n-1][j]*((l-1)/(ll)n)+(ll)cnt[(l-1)%(ll)n][j];
		}
		rep(j,26)cout<<ans[j]<<' ';
		return 0;
	}
	
	else{
		len=n-len;
		vector<ll>L(maxm),R(maxm);
		rep(i,26)L[i]=cnt[len-1][i];
		rep(i,26)R[i]=cnt[n-1][i]-cnt[len-1][i];
		vector<ll>Ans1(maxm),Ans2(maxm);
		ll x1=solve(len,L,n-len,R,r+1,Ans1);
		ll x2=solve(len,L,n-len,R,l,Ans2);
		rep(i,26){
			ans[i]+=Ans1[i]-Ans2[i];
			if(x1>=1)ans[i]+=(ll)cnt[x1-1][i];
			if(x2>=1)ans[i]-=(ll)cnt[x2-1][i];
		}
		rep(i,26)cout<<ans[i]<<" ";
		return 0;
	}
}

Compiler output:
a.cc: In function 'bool same(int)':
a.cc:90:16: error: reference to 'hash' is ambiguous
   90 |         int k1=hash[pos-1],k2=hash[n-1]-hash[n-1-pos]*power[pos];
      |                ^~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:62:5: note:                 'int hash [200005]'
   62 | int hash[maxn],power[maxn],z[maxn];
      |     ^~~~
a.cc:91:20: error: 'k2' was not declared in this scope; did you mean 'k1'?
   91 |         return k1==k2;
      |                    ^~
      |                    k1
a.cc: In function 'int main()':
a.cc:126:9: error: reference to 'hash' is ambiguous
  126 |         hash[0]=s[0]-'a';power[0]=1;
      |         ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:62:5: note:                 'int hash [200005]'
   62 | int hash[maxn],power[maxn],z[maxn];
      |     ^~~~
a.cc:127:19: error: reference to 'hash' is ambiguous
  127 |         REP(i,n-1)hash[i]=hash[i-1]*H+s[i]-'a',power[i]=power[i-1]*H;
      |                   ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:62:5: note:                 'int hash [200005]'
   62 | int hash[maxn],power[maxn],z[maxn];
      |     ^~~~
a.cc:127:27: error: reference to 'hash' is ambiguous
  127 |         REP(i,n-1)hash[i]=hash[i-1]*H+s[i]-'a',power[i]=power[i-1]*H;
      |                           ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:62:5: note:                 'int hash [200005]'
   62 | int hash[maxn],power[maxn],z[maxn];
      |     ^~~~