OKR-Periods of Words
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
char s[N];
typedef long long ll;
ll ne[N];
int main(){
int len;
scanf("%d", &len);
scanf("%s", s + 1);
for(register int i = 2, j = 0; i <= len; i ++){
while(j && s[i] != s[j + 1])
j = ne[j];
if(s[i] == s[j + 1])
j ++;
ne[i] = j;
}
ll ans = 0;
for(register int i = 2; i <= len; i ++){
if(ne[i] == 0)
continue;
else{
int j = ne[i];
while(ne[j])
j = ne[j];
if(ne[i])
ne[i] = j;
ans += i - j;
}
}
cout << ans << endl;
return 0;
}