rt,CSP-S T2
#include <bits/stdc++.h>
using namespace std;
char a[2000005];
char b[2000005][2];
int top, top2;
int n, ans = 0;
bool h = 1;
int sc() {
int res = 0;
for (int i = 1; i <= top; i++) {
if (b[i][!h] == b[i + 1][!h] && i != top) {
i++;
res += 2;
}
else b[++top2][h] = b[i][!h];
}
top = top2;
top2 = 0;
h = !h;
return res;
}
int main() {
freopen("game.in", "r", stdin);
freopen("game.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if ((j - i + 1) % 2 != 0) continue;
top = 0;
top2 = 0;
h = 1;
int zs = j - i + 1;
for (int k = i; k <= j; k++) {
b[++top][0] = a[k];
}
while (1) {
int fh = sc();
zs -= fh;
// cout << fh << endl;
if (zs == 0) {
ans++;
// cout << i << ' ' << j << endl;
break;
}
if (fh == 0) break;
}
}
}
cout << ans << endl;
return 0;
}