#include #include #include #include #include #include #include int answerQuery(int l, int r,char* s) { // Return the answer for this query modulo 1000000007. int a[26]={0}; int i,j; for(i=l-1;i=max) { max=a[i]; } } int len=0,count=0; for(i=0;i<26;i++) { if(a[i]==max) { count++; } if(a[i]>0 && a[i]%2==0) { len=len+a[i]; } } len=len+max; int ans; if(len%2==0) { int b=len; while(b>0) { ans=ans*b; b=b-2; } } if(len%2==1) { int b=len-1; while(b>0) { ans=ans*b; b=b-2; } } return count*ans; } int main() { char* s = (char *)malloc(512000 * sizeof(char)); scanf("%s", s); int q; scanf("%i", &q); for(int a0 = 0; a0 < q; a0++){ int l; int r; scanf("%i %i", &l, &r); int result = answerQuery(l, r,s); printf("%d\n", result); } return 0; }