#include<iostream>
using namespace std;
int n,T[5007],C[5007],A[5007],G[5007];
char s[5007];
int main(){
	cin>>n;
	cin>>s+1;
	for(int i=1;i<=n;i++){
		T[i]=T[i-1];
		C[i]=C[i-1];
		A[i]=A[i-1];
		G[i]=G[i-1];
		if(s[i]=='A')A[i]++;
		if(s[i]=='C')C[i]++;
		if(s[i]=='G')G[i]++;
		if(s[i]=='T')T[i]++;
	}
	int ans=0,a=0,c=0,t=0,g=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++){
			a=A[i]-A[j-1];
			g=G[i]-G[j-1];
			t=T[i]-T[j-1];
			c=C[i]-C[j-1];
			if(a==t&&c==g)ans++;
		}
	}
	printf("%d\n",ans);
}


// Problem : B - DNA Sequence
// Contest : AtCoder - AtCoder Regular Contest 104
// URL : https://atcoder.jp/contests/arc104/tasks/arc104_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// $%U%$
// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	int n;
	string s;
	cin >> n >> s;
	map<pair<int,int>,int> mp;
	int A,G,C,T;
	A = G = C = T = 0;
	int ans=0;
	mp[{0,0}]++;
	for(int i=0;i<n;++i)
	{
		if(s[i]=='A')
		A++;
		else if(s[i]=='G')
		G++;
		else if(s[i]=='C')
		C++;
		else
		T++;
		if(mp[{A-T,C-G}]!=0)
		ans+=mp[{A-T,C-G}];
		mp[{A-T,C-G}]++;
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}
