#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  string s;
  int mp[5010][4];
  mp[0][0]=mp[0][1]=mp[0][2]=mp[0][3]=0;
  cin>>n>>s;
  rep(i,s.size() ){
    rep(j,4){
      mp[i+1][j]=mp[i][j];
    }
    if(s[i]=='A'){
      mp[i+1][0]++;
    }
    if(s[i]=='T'){
      mp[i+1][1]++;
    }
    if(s[i]=='C'){
      mp[i+1][2]++;
    }
    if(s[i]=='G'){
      mp[i+1][3]++;
    }
  }
  /*rep(i,4){
    rep(j,4){
      cout<<mp[i][j]<<" ";
    }
    cout<<endl;
    }*/
  int ans=0;
  rep(i,s.size()+1){
    repi(j,i+1,s.size()+1 ){
      int A=mp[j][0]-mp[i][0],T=mp[j][1]-mp[i][1],C=mp[j][2]-mp[i][2],G=mp[j][3]-mp[i][3];
      if(A==T && C==G){
	ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    int n;
    string s;
    cin >> n >> s;

    int ans = 0;

    for(int i = 0; i < n; ++i){
        vector<int> freq(26, 0);
        for(int j = i; j < n; ++j){
            ++freq[s[j]-'A'];
            if(freq['A'-'A']==freq['T'-'A'] && freq['C'-'A']==freq['G'-'A']) ++ans;
        }
    }

    cout << ans << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}