#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)

int main()
{
  int N;
  string S;
  cin>>N>>S;
  int ans=0;

  rep(i,S.size()){
    int cnt1=0;
    int cnt2=0;
    for(int j=i;j<S.size();j++){
      if(S[j]=='A') cnt1++;
      else if(S[j]=='T') cnt1--;
      else if(S[j]=='G') cnt2++;
      else cnt2--;
      if(cnt1==0 && cnt2==0){
      	ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

#include <bits/stdc++.h>
#define sort stable_sort
using namespace std; 

int _;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int n,ans,cnt[26][100050];
string s,str="ATCG"; 

int main()
{	
	//for(scanf("%d",&_);_;_--) 	
	scanf("%d",&n);
	cin >> s;
	for(int i=1;i <= n;i++)
		for(int j=0;j<4;j++)
		{
			cnt[str[j]-'A'][i]=cnt[str[j]-'A'][i-1]+(s[i-1] == str[j]);
		//	D(i,str[j],cnt[str[j]-'A'][i]);
		}
	for(int i=0;i<n;i++)
		for(int j=0;j <= i;j++)
			if(cnt['A'-'A'][i+1]-cnt['A'-'A'][j] == cnt['T'-'A'][i+1]-cnt['T'-'A'][j] && cnt['C'-'A'][i+1]-cnt['C'-'A'][j] == cnt['G'-'A'][i+1]-cnt['G'-'A'][j])
			{
		//		D(i,j); 
				ans++;
				} 
	printf("%d\n",ans);
	return 0;
}