#include using namespace std; #define MAX 1000005 #define rep(i,a,b) for(i=a;i<=b;i++) #define repr(i,a,b) for(i=a;i>=b;i--) #define ll long long int N,Q; char str[MAX]; ll V[5][MAX] , POS[26] , SC[5][5][MAX]; char S[]={'c','h','e','f'} , a ,b; int Count[5] , L, R; void process(){ int i,j,k; rep(i,1,4) POS[S[i-1]-'a'] = i; // let us number the character in the chef's special string as c = 1 , h = 2 , e = 3 , f = 4 (Mapping function) rep(i,1,N) V[POS[str[i-1]-'a']][i] = 1; // V[i][j] -> keep trace for the occurence of ith character in the chef's string at position is present or not. repr(i,N,1){ rep(j,1,4) // SC[i][j][k] -> it keep trace for the number of characters j after position k if kth position's character is i SC[POS[str[i-1]-'a']][j][i] = Count[j]; Count[POS[str[i-1]-'a']]++; } rep(i,1,4) rep(j,1,4) repr(k,N-1,1) SC[i][j][k]+=SC[i][j][k+1]; // This is to maintain suffix sum for the fast processing rep(i,1,4) rep(j,1,N) V[i][j]+=V[i][j-1]; // this is prefix sum for the fast processing of the query } int main(){ scanf("%s",str) ; // str-> chef's special string N = strlen(str); assert(N>=1&&N=1&&Q=1&&L<=N); // assertion assert(R>=1&&R<=N); // assertion assert(L