#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define M (L+R)/2
#define N 500009
#define inf 99999999999
#define ll long long
#define mod 1000000007
#define sz size();
using namespace std;

ll n,x,y,ans,sum;
string s;

int main(){

	ios::sync_with_stdio(0);

	cin>>n;
	cin>>s;
	
	for(int i=0;i<n;i++){
		x=y=0;
		for(int j=i;j<n;j++){
			if(s[j]=='A')x++;
			if(s[j]=='T')x--;
			if(s[j]=='G')y++;
			if(s[j]=='C')y--;
			if(x==y && x==0)ans++;
		}		
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
#ifdef LOCAL
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cerr<<(*i)<<" ";cerr<<endl;}
#else
template<class T>void pv(T a,T b){}
#endif

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 5010;
int c[4][MAX_N];

int main2() {
  CLR(c, 0);

  int N = nextLong();
  string S; cin >> S;

  REP(i, N) {
    c[0][i+1] = c[0][i] + (S[i] == 'A');
    c[1][i+1] = c[1][i] + (S[i] == 'T');
    c[2][i+1] = c[2][i] + (S[i] == 'G');
    c[3][i+1] = c[3][i] + (S[i] == 'C');
  }


  ll ans = 0;
  REP(i, N) {
    for (int j = i + 1; j <= N; j++) {
      int d[4] = {0};
      REP(k, 4) d[k] = c[k][j] - c[k][i];

      if (d[0] == d[1] && d[2] == d[3]) ans++;

    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}
