#include<bits/stdc++.h>
using namespace std;
#define int long long
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a,b) for(auto &a:b)
#define func function
#define fasty ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define all(a) begin(a),end(a)
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) (x>>(i-1)&1ll)
#define on(x,i) (x|(1ll<<(i)))
#define off(x,i) (x&~(1ll<<(i-1)))
using ii=pair<int,int>;
using ll=long long;
using ull=unsigned long long;

const int N=5005;
int n;
string s;
int a[N],b[N],c[N],d[N];

int32_t main(){
   fasty;

   cin>>n>>s; s=' '+s;
   forinc(i,1,n){
      a[i]=a[i-1]+(s[i]=='A');
      b[i]=b[i-1]+(s[i]=='T');
      c[i]=c[i-1]+(s[i]=='G');
      d[i]=d[i-1]+(s[i]=='C');
   }
   int ans=0;
   forinc(i,1,n) forinc(j,i,n){
      if(a[j]-a[i-1]==b[j]-b[i-1] && c[j]-c[i-1]==d[j]-d[i-1]) ans++;
   }
   cout<<ans<<'\n';
}

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

int main()
{
    int N;
    string s;
	cin >> N >> s;
	int cnt = 0, ans = 0;
	for(int i = 0; i<N; i++){
		int a = 0, b = 0;
		for(int j = i; j<N; j++){
			if(s[j] == 'A'){
				a++;
			}
			else if(s[j] == 'T'){
				a--;
			}
			else if(s[j] == 'C'){
				b++;
			}
			else{
				b--;
			}
			if(a==0 && b==0){
				ans++;
			}
		}
	}
	cout << ans;
}
