Pagini recente » Cod sursa (job #157976) | Cod sursa (job #2712583) | Cod sursa (job #1635675) | Cod sursa (job #2912279) | Cod sursa (job #2590566)
/*
`-/oo+/- ``
.oyhhhhhhyo.`od
+hhhhyyoooos. h/
+hhyso++oosy- /s
.yoooossyyo:``-y`
..----.` ``.-/+:.`
`````..-::/.
`..```.-::///`
`-.....--::::/:
`.......--::////:
`...`....---:::://:
`......``..--:::::///:`
`---.......--:::::////+/`
----------::::::/::///++:
----:---:::::///////////:`
.----::::::////////////:-`
`----::::::::::/::::::::-
`.-----:::::::::::::::-
...----:::::::::/:-`
`.---::/+osss+:`
``.:://///-.
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
const int INF = 2e9;
const int N = 1000000;
string s, aux;
int p[5 + 2 * N];
int n;
i64 Manacher(){
int l, r;
i64 ans(0);
l = 0;
r = -1;
for(int i = 0; i < n; i++){
int k;
if(i > r) k = 1;
else k = min(p[l + r - i], r - i + 1);
while(i - k >= 0 && i + k < n && s[i - k] == s[i + k])
k++;
p[i] = k--;
if(i + k > r){
l = i - k;
r = i + k;
}
ans += p[i] / 2;
}
return ans;
}
int main() {
freopen("pscpld.in", "r", stdin);
freopen("pscpld.out", "w", stdout);
cin >> aux;
s = '#';
for(int i = 0; i < aux.size(); i++){
s += aux[i];
s += '#';
}
n = s.size();
printf("%lld\n", Manacher());
return 0;
}