#include #include using namespace std; void initialize(string s) { // This function is called once before all queries. } int answerQuery(int l, int r, string s) { // Return the answer for this query modulo 1000000007. map mpp; for(int i = l-1; i!=r; ++i){ if(mpp.find(s[i])==mpp.end()) mpp[s[i]]=1; else mpp[s[i]]=mpp[s[i]]+1; } int count = 0; int odd = 0; int even = 0; for(auto it=mpp.begin();it!=mpp.end();++it){ if(it->second % 2){ odd++; //cout << "second " << it->first << endl; } else even++; } //cout << "odd" << odd << endl; //cout << "even " << even << endl; if(odd==0) return even; return odd+even-1; } int main() { string s; cin >> s; initialize(s); int q; cin >> q; for(int a0 = 0; a0 < q; a0++){ int l; int r; cin >> l >> r; int result = answerQuery(l, r, s); cout << result << endl; } return 0; }