//satyaki3794 #include #define ff first #define ss second #define pb push_back #define MOD (1000000007LL) #define LEFT(n) (2*(n)) #define RIGHT(n) (2*(n)+1) using namespace std; typedef long long ll; typedef pair ii; typedef pair iii; ll pwr(ll base, ll p, ll mod = MOD){ ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans; } ll gcd(ll a, ll b){ if(b == 0) return a; return gcd(b, a%b); } int n, BLOCK, cnt[340][26], block_add[340], arr[100005]; ll powers[100005]; char str[100005]; inline int block(int pos){ return (pos-1)/BLOCK; } inline void update(int l, int r, int t){ if(t == 0) return; int b1 = block(l), b2 = block(r); if(b1 == b2){ for(int i=l;i<=r;i++){ cnt[b1][arr[i]]--; arr[i] += t; if(arr[i] >= 26) arr[i] -= 26; cnt[b1][arr[i]]++; } return; } for(int i=l;i<=n&&block(i)==b1;i++){ cnt[b1][arr[i]]--; arr[i] += t; if(arr[i] >= 26) arr[i] -= 26; cnt[b1][arr[i]]++; } for(int b=b1+1;b<=b2-1;b++){ block_add[b] += t; if(block_add[b] >= 26) block_add[b] -= 26; } for(int i=r;i>=1&&block(i)==b2;i--){ cnt[b2][arr[i]]--; arr[i] += t; if(arr[i] >= 26) arr[i] -= 26; cnt[b2][arr[i]]++; } } inline int query(int l, int r, int val){ int b1 = block(l), b2 = block(r); if(b1 == b2){ int ans = 0; for(int i=l;i<=r;i++){ int actual = arr[i] + block_add[b1]; if(actual >= 26) actual -= 26; ans += (actual == val); } return ans; } int ans = 0; for(int i=l;i<=n&&block(i)==b1;i++){ int actual = arr[i] + block_add[b1]; if(actual >= 26) actual -= 26; ans += (actual == val); } for(int b=b1+1;b<=b2-1;b++){ int needed = val - block_add[b]; if(needed < 0) needed += 26; ans += cnt[b][needed]; } for(int i=r;i>=1&&block(i)==b2;i--){ int actual = arr[i] + block_add[b2]; if(actual >= 26) actual -= 26; ans += (actual == val); } return ans; } int cnt2[100005][26]; inline ll query2(int l, int r){ ll even = 1; vector cnt (26); for(int i=0;i<26;i++){ cnt[i] = ::cnt2[r][i] - ::cnt2[l-1][i]; ll even_here = 1; if(cnt[i] > 0) even_here = powers[cnt[i]-1]; even = (even * even_here) % MOD; } // cout<<"cnt: ";for(auto it : cnt) cout<