#include using namespace std; #define ll long long #define MOD 1000000007 #define SIZE 100004 #define pll pair struct plll { ll f,s,in; }; ll q,n,bs,nb,l,r,c[26],ans[100004],o,coun; plll a[100004]; string str; ll fac[SIZE],ifac[SIZE]; ll power(ll a,ll b) { ll res=1; while(b) { if(b&1) res=(res*a)%MOD; a=(a*a)%MOD; b/=2; } return res%MOD; } void pre() { fac[0]=1; for(ll i=1;i=0;i--) ifac[i]=(ifac[i+1]*i%MOD+ifac[i+1])%MOD; } bool f(plll x,plll y) { if(x.f/bs==y.f/bs) return x.s>str>>q; bs=sqrt(str.length()); nb=ceil(1.0*str.length()/bs); for(ll i=0;i>a[i].f>>a[i].s; a[i].f--;a[i].s--; a[i].in=i; } sort(a,a+q,f); l=0;r=0; memset(c,0,sizeof c); c[str[0]-'a']++; for(ll i=0;ia[i].f) { // cout<<"b\n"; l--; c[str[l]-'a']++; } while(ra[i].s) { // cout<<"d\n"; c[str[r]-'a']--; r--; } ans[a[i].in]=1; o=0;coun=0; for(ll j=0;j<26;j++) { // cout<