#include<bits/stdc++.h>
using namespace std;
int n,ans;
string s;
stack<char> sta;
int main()
{
//freopen("game.in","r",stdin);
//freopen("game.out","w",stdout);
cin>>n>>s;
for(int l=0;l<s.size();l++)
{
while(!sta.empty())
{
sta.pop();
}
int r=(int)s.size()-1;
if(n>8000)
{
r=min(r,l+500);
}
for(int i=l;i<=r;i++)
{
if(sta.empty())
{
sta.push(s[i]);
}
else
{
if(sta.top()==s[i])
{
sta.pop();
}
else
{
sta.push(s[i]);
}
}
if(sta.empty())
{
ans++;
}
}
}
cout<<ans;
return 0;
}