#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
string s;
int n;
ull PP = 131,P[500010],Hs[500010],Ht[500010],ans;
void init() {
P[0] = 1;
for (int i = 1;i <= n;i ++) P[i] = P[i - 1] * PP;
for (int i = 1;i <= n;i ++) Hs[i] = Hs[i - 1] * PP + s[i - 1];
for (int i = n;i >= 1;i --) Ht[i] = Ht[i + 1] * PP + (s[i - 1] == '0'? '1': '0');
return;
}
inline ull getBKDRHashs(int l,int r) {
return Hs[r] - Hs[l - 1] * P[r - l + 1];
}
inline ull getBKDRHasht(int r,int l) {
return Ht[l] - Ht[r - 1] * P[r - l + 1];
}
void binsearch(int x) {
int l = 0,r = min(x - 1,n - x - 1),mid;
while (l < r) {
mid = (l + r) >> 1;
if (getBKDRHashs(x - mid,x) == getBKDRHasht(x + 1 + mid,x + 1)) l = mid + 1;
else r = mid;
}
ans += l;
return;
}
int main() {
scanf("%d",&n);
cin >> s;
init();
for (int i = 1;i <= n;i ++)
binsearch(i);
printf("%llu\n",ans);
return 0;
}