#include #include #include #include #include #include #include long int answerQuery(int l, int r,char*s) { // Return the answer for this query modulo 1000000007. int a[26]={0},k; for(long i=l-1;i<=r-1;i++) { k=s[i]-97; a[k]++; } long long c=0,p=0; for(int i=0;i<26;i++) { if(a[i]>0) { if(a[i]%2==0) c=c+(a[i]/2); else if(a[i]>1&&a[i]%2!=0) { p++; a[i]=a[i]-1; c=c+(a[i]/2); } else p++; } } if(c>0&&p>0) return p%1000000007; else if(c>0&&p==0) return c%1000000007; else if(c==0&&p>0) return 1; else return 0; } 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); long long int result = answerQuery(l, r,s); printf("%lld\n", result); } return 0; }