#include<iostream> #include<cstring> #define maxn 1100010 #define lowbit(i) ((i) & (-i)) #define ll long long usingnamespacestd;
int Bit[30];
voidadd(int i, int v){ ++i; while (i <= 27) Bit[i] += v, i += lowbit(i); } intget_sum(int i){ int s = 0; ++i; while (i) s += Bit[i], i -= lowbit(i); return s; }
int z[maxn]; voidinit_Z(char *s){ int n = strlen(s + 1); z[1] = n; for (int i = 2, l = 0, r = 0; i <= n; ++i) { z[i] = i <= r ? min(z[i - l + 1], r - i + 1) : 0; while (i + z[i] <= n && s[i + z[i]] == s[z[i] + 1]) ++z[i]; if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; } } int n; char s[maxn];
int suf[maxn], cnt[26];
voidwork(){ cin >> s + 1; n = strlen(s + 1); init_Z(s); ll ans = 0; int sum = 0; for (int i = 0; i < 26; ++i) cnt[i] = 0; for (int i = n; i; --i) { if (cnt[s[i] - 'a']) --sum; else ++sum; cnt[s[i] - 'a'] ^= 1; suf[i] = sum; } fill(Bit, Bit + 30, 0); for (int i = 0; i < 26; ++i) cnt[i] = 0; cnt[s[1] - 'a'] = sum = 1; add(sum, 1); for (int i = 2; i < n; ++i) { ll t = z[i + 1] / i + 1; if (i * t == n) --t; ans += (t + 1) / 2 * get_sum(suf[i + 1]); if (2 * i < n) ans += t / 2 * get_sum(suf[2 * i + 1]); if (cnt[s[i] - 'a']) --sum; else ++sum; cnt[s[i] - 'a'] ^= 1; add(sum, 1); } cout << ans << "\n"; }