#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ll long long

void IO(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int MOD = 1e9 + 7;
const int N = 5e3 ;

vector<vector<int>> dp ( N , vector<int>(N));
int pal [N][N] ;
string s ;
int solve ( int l , int r ) {
    if ( l >= r ) {
        return 1 ;
    }
    int &ret = pal[l][r];
    if ( ret != -1 ) {
        return ret ;
    }
    ret = 0 ;
    return s[l] == s[r] && solve (l + 1 , r - 1) ;
}

void solve(int tc) {

    cin >> s;
    int n = s.size() ;
    int q; cin >> q;
    memset ( pal , -1 , sizeof pal ) ;

    for (int i = 0 ; i<n ; i++ ) {
        for (int j = i ; j < n ; j ++ ) {
            solve ( i , j ) ;
        }
    }
    while ( q -- ) {
        int l, r ; cin >> l >> r ;
    }

    cout << pal [0][2] ;




}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    IO();

    int TC = 1;
    // cin >> TC;

    for (int i = 1; i <= TC; i++) {
        solve(i);
    }

    return 0;
}