#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(998244353);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int multipf(vector<string>& s){
    cout << s[0];
    rep1(i, s.size() - 1)cout << " " << s[i];
    cout << endl;
    return 0;
}

int multipf(vector<ll>& n){
    cout << n[0];
    rep1(i, n.size() - 1)cout << " " << n[i];
    cout << endl;
    return 0;
}

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}
 
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        ans %= mod;
        a = a * a;
        a %= mod;
        b >>= 1;
    }
    return ans % mod;
}

struct UnionFind {
    vector<ll> par;
    vector<ll> rank;
    vector<ll> Size;
    UnionFind(ll n) {
        init(n);
    }
 
    void init(ll n) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        rep0(i, n + 1){
            par[i] = i;
            rank[i] = 0;
            Size[i] = 1;
        }
    }
 
    ll root(ll x) {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }
 
    bool same(ll x, ll y) {
        return root(x) == root(y);
    }
 
    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }
 
    ll size(ll x){
        return Size[root(x)];
    }
};

//modの値の確認をすること
int main(){
    ll n;
    string s;
    cin >> n >> s;
    vector<tuple<ll,ll,ll,ll> > a(n + 1,make_tuple(0,0,0,0));
    rep1(i, n){
        if(s[i - 1] == 'A')get<0>(a[i])++;
        else if(s[i - 1] == 'T')get<1>(a[i])++;
        else if(s[i - 1] == 'C')get<2>(a[i])++;
        else get<3>(a[i])++;
    }
    rep1(i, n){
        get<0>(a[i]) += get<0>(a[i - 1]);
        get<1>(a[i]) += get<1>(a[i - 1]);
        get<2>(a[i]) += get<2>(a[i - 1]);
        get<3>(a[i]) += get<3>(a[i - 1]);
    }
    ll ans = 0;
    rep0(i, n)nfor(j, i + 1, n + 1)if(get<0>(a[j]) - get<0>(a[i]) == get<1>(a[j]) - get<1>(a[i]) && get<2>(a[j]) - get<2>(a[i]) == get<3>(a[j]) - get<3>(a[i]))ans++;
    pf(ans);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;

  int count = 0;
  for (int i = 0; i < n; i++) {
    int c1 = 0, c2 = 0;
    for (int j = i; j < n; j++) {
      switch (s[j]) {
        case 'A':
          c1++;
          break;
        case 'T':
          c1--;
          break;
        case 'C':
          c2++;
          break;
        case 'G':
          c2--;
          break;
      }
      if (c1 == 0 && c2 == 0) {
        count++;
      }
    }
  }
  cout << count;
}