//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a> 
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define all(a) a.begin(),a.end()
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true; 
  	if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; 
    return true; 
} 
vector<ll> prime;
void sieve(ll n) 
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh)); 
    for (ll p=2; p*p<=n; p++) 
    {	if (bakh[p] == true) 
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } } 
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p); 
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)	
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}	
	}	if(z>1)	fac-=(fac/z);
	return fac;
} 
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p) 
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; } 
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b) 
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m) 
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;} 
void multiply(ll F[2][2], ll M[2][2]) 
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1]; 
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1]; 
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w; 
}
void powermat(ll F[2][2], ll n) 
{	if( n == 0 || n == 1) 
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M); 
}
ll fib(ll n) 
{ ll F[2][2] = {{1,1},{1,0}}; 
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0]; 
}
V(ll) merge(V(ll) v1,V(ll) v2)
{	V(ll) temp;
	ll i=0,j=0;
	while(i<v1.size() && j<v2.size())
	{	if(v1[i]<v2[j])
			temp.pb(v1[i]),i++;
		else
			temp.pb(v2[j]),j++;
	}
	while(i<v1.size())	
		temp.pb(v1[i]),i++;
	while(j<v2.size())	
		temp.pb(v2[j]),j++;
	return temp;
}
//id=(id&(id+1))-1
//ll fetch(ll id)
//{		
//}
//id=(id|(id+1))
//void update(ll id)
//{	
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
int main()
{	vasu2907;
	ll n,a=0,b=0,ans=0;
	cin>>n;
	string st;
	cin>>st;
	map<char,ll> mp;
	mp['A']=0, mp['T']=1,mp['C']=2,mp['G']=3;
	ll ar[4];
	F(i,n)
	{	a=0;b=0;
		mem(ar,0);
		for(ll j=i;j<n;j++)
		{	ar[mp[st[j]]]+=1;
			if(ar[0]==ar[1] && ar[2]==ar[3])	ans+=1;
		}
	}
	cout<<ans<<endl;
}
#include <cstdio>
using namespace std;

const int MAX_N = 5010;
int A[MAX_N], Prefix[4][MAX_N];
int N;

char GetChar()
{
	char c;
	do
		c = getchar();
	while (c == ' ' || c == '\n' || c == '\r');
	return c;
}

void ReadA()
{
	const char *s = "ATCG";
	for (int i = 1; i <= N; i++)
	{
		char c = GetChar();
		for (int j = 0; j < 4; j++)
			if (c == s[j])
				A[i] = j;
	}
}

void GetPrefix()
{
	for (int i = 1; i <= N; i++)
	{
		for (int j = 0; j < 4; j++)
			Prefix[j][i] = Prefix[j][i - 1];
		Prefix[A[i]][i]++;
	}
}

int GetAns()
{
	int ans = 0;
	for (int i = 1; i < N; i++)
		for (int j = i + 1; j <= N; j++)
			if (
				Prefix[0][j] - Prefix[0][i - 1] == Prefix[1][j] - Prefix[1][i - 1] &&
				Prefix[2][j] - Prefix[2][i - 1] == Prefix[3][j] - Prefix[3][i - 1])
				ans++;
	return ans;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d", &N);
	ReadA();
	GetPrefix();
	printf("%d\n", GetAns());
	return 0;
}
