#include <bits/stdc++.h>

using namespace std;
using ll = long long int;

void tc(){

    int n;
    cin >> n;

    string s;
    cin >> s;

    int ans = 0;

    for (int i=0; i<n; i++){
        int a = 0, t = 0, c = 0, g = 0;
        for (int j=i; j<n; j++){
            if (s[j] == 'A') a++;
            if (s[j] == 'T') t++;
            if (s[j] == 'G') g++;
            if (s[j] == 'C') c++;

            if (a == t and g == c) ans++;
        }
    }

    cout << ans << endl;

}

int main(){

    int t = 1;
    while(t--) tc();

    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1e9 
typedef long long ll;
typedef long double ld;

int main(){
  ll n;
  string s;
  cin>>n>>s;
  vector<vector<ll>> v(n+1,vector<ll> (4));
  vector<char> w={'A','T','C','G'};
  REP(i,n){
    REP(j,4)if(s[i]==w[j])v[i+1][j]++;
  }
  ll cnt=0;
  FOR(i,1,n+1){
    REP(j,4){
      v[i][j]+=v[i-1][j];
    }
  }
  REP(i,n){
    FOR(j,i+1,n+1){
      ll a=v[j][0]-v[i][0], t=v[j][1]-v[i][1], c=v[j][2]-v[i][2], g=v[j][3]-v[i][3];
      if(a==t&&c==g)cnt++;
    }
  }
  cout<< cnt <<endl;
  return 0;
  
}