#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
#define N 5050
int n,as;
char s[N];
map<pair<int,int>,int> tp;
int main()
{
	scanf("%d%s",&n,s+1);
	int v1=0,v2=0;
	tp[make_pair(0,0)]=1;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='A')v1++;
		if(s[i]=='T')v1--;
		if(s[i]=='C')v2++;
		if(s[i]=='G')v2--;
		as+=tp[make_pair(v1,v2)];tp[make_pair(v1,v2)]++;
	}
	printf("%d\n",as);
}
#include <bits/stdc++.h>
using namespace std;

int main()
{
  string S;
  cin >> S;
  
  for(int i = 0; i < S.size(); ++i)
  {
    if(S.at(i) == '6') S.at(i) = '9';
    else if(S.at(i) == '9') S.at(i) = '6';
  }
  
  reverse(S.begin(), S.end());
  cout << S << endl;
  
}
