#include <cstdio>
char str[3000000];
int next[3000000];
int num[3000000];
int ans[3000000];
int main()
{
int n; scanf("%d\n%s", &n, str + 1);
for (int i = n - 1; i; i--)
{
if (str[i] == str[i + 1])
{
num[i] = num[i + 2] + 1;
next[i] = i + 1;
if (next[i + 2]) next[i] = next[i + 2];
}
else
{
if (next[i + 1] && str[next[i + 1] + 1] == str[i])
{
next[i] = next[i + 1] + 1;
num[i] = 1;
if (next[next[i] + 1])
{
num[i] += num[next[i] + 1];
next[i] = next[next[i] + 1];
}
}
}
ans[i] = num[i] + ans[i + 1];
}
printf("%d", ans[1]);
return 0;
}