/* -*- coding: utf-8 -*- * * 599.cc: No.599 回文かい - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 10000; const int MAX_HN = MAX_N / 2; const int MOD = 1000000007; const int P0 = 6779, M0 = 12853; const int P1 = 4289, M1 = 10799; /* typedef */ typedef long long ll; /* global variables */ char s[MAX_N + 10]; ll dp[MAX_HN + 1]; int rh0[MAX_N + 1], rh1[MAX_N + 1]; int rpe0[MAX_N], rpe1[MAX_N]; /* subroutines */ int powmod(int a, int b, int mod) { int p = 1; while (b) { if (b & 1) p = (p * a) % mod; a = (a * a) % mod; b >>= 1; } return p; } inline int rhash(int rh[], int rpe[], int i, int j, int mod) { return (rh[j] - rh[i] + mod) % mod * rpe[i] % mod; } bool kaibunkai(int n, int i, int j) { if ((rhash(rh0, rpe0, i, j, M0) != rhash(rh0, rpe0, n - j, n - i, M0)) || (rhash(rh1, rpe1, i, j, M1) != rhash(rh1, rpe1, n - j, n - i, M1))) return false; for (int i0 = i, i1 = n - j; i0 < j; i0++, i1++) if (s[i0] != s[i1]) return false; return true; } /* main */ int main() { scanf("%s", s); int n = strlen(s), hn = n / 2; rh0[0] = rh1[0] = 0; int pe0 = 1, pe1 = 1; for (int i = 0; i < n; i++) { int d = s[i] - '0'; rh0[i + 1] = (rh0[i] + d * pe0) % M0; rh1[i + 1] = (rh1[i] + d * pe1) % M1; rpe0[i] = powmod(pe0, M0 - 2, M0); rpe1[i] = powmod(pe1, M1 - 2, M1); pe0 = (pe0 * P0) % M0; pe1 = (pe1 * P1) % M1; } fill(dp, dp + hn + 1, 1); for (int i = hn - 1; i >= 0; i--) for (int j = i + 1; j <= hn; j++) if (kaibunkai(n, i, j)) dp[i] = (dp[i] + dp[j]) % MOD; printf("%lld\n", dp[0]); return 0; }