#include #include #include #include #include #include #include int answerQuery(char *s, int l, int r) { // int i, j; char a_char; int len = strlen(s); int instances[26]; int iseven = 0; int num = 0; int evens = 0; int odds = 0; if (len % 2 == 0) iseven = 1; for (i = 'a'; i <= 'z'; i++) { instances[i - 'a'] = 0; for (j = l - 1; j < r; j++) { if (s[j] == i) instances[i - 'a']++; } if (instances[i - 'a'] > 0 && instances[i - 'a'] % 2 == 0) evens++; else if (instances[i - 'a'] % 2 != 0) odds++; } if (odds == 0) return (evens); return (evens * odds); } 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(s, l, r); printf("%d\n", result); } return 0; }