#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>

#define ll long long
using P = std::pair<int, int>;

int main()
{
    int N;
    std::string S;
    std::cin >> N >> S;

    int ans = 0;
    for(int i=0; i < N; i++) {
        int na=0, nt=0, nc=0, ng=0;
        for(int j=i; j < N; j++) {
            if(S[j] == 'A') na++;
            else if(S[j] == 'T') nt++;
            else if(S[j] == 'C') nc++;
            else ng++;
            if(na == nt and nc == ng) ans++;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}
#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) int x;cin >> x
#define cci(x,y) int x,y;cin >> x >> y
#define co(x) cout << x << endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

int main(){
  cii(n);
  ss s;ci(s);

  int ans=0;
  rep(l,0,n){
    map<char,int> mp;
  // int a,t,g,c;  a=t=g=c=0;
    mp[s[l]]++;
    rep(r,l+1,n){
      mp[s[r]]++;
      if(mp['A']==mp['T'] && mp['G']==mp['C'])ans++;
    }
  }

  co(ans);
}