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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

int dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};


int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    string s; cin>>s;

    vint a(n+1,0), t(n+1,0), c(n+1,0), g(n+1,0);
    rep(i,s.size()){
        a[i+1] = a[i];
        t[i+1] = t[i];
        c[i+1] = c[i];
        g[i+1] = g[i];
        if(s[i] == 'A') a[i+1]++;
        if(s[i] == 'T') t[i+1]++;
        if(s[i] == 'C') c[i+1]++;
        if(s[i] == 'G') g[i+1]++;
    }

    ll ans = 0;
    rep(l,n+1){
        rep(r,n+1){
            if(!(l < r)) continue;
            if(a[r] - a[l] == t[r] - t[l] and c[r] - c[l] == g[r] - g[l]) ans++;
        }
    }
    cout<<ans<<endl;

    return 0;

}
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin())
#define inf INT_MAX
#define VI vector<ll>
#define VII vector<pair<ll, ll>>
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'

ll add(ll x, ll y){
    x+=y;
    while(x>=MOD) x-=MOD;
    while(x<0) x+=MOD;
    return x;
}

ll mul(ll x, ll y){
    return (x * 1ll * y) % MOD;
}

ll binpow(ll x, ll y){
    ll ans = 1;
    while(y>0){
        if(y%2==1){
            ans = mul(ans, x);
        }
        x = mul(x, x);
        y /= 2;
    }
    return ans;
}

ll divide(ll x, ll y){
    return mul(x, binpow(y, MOD-2));
}


int main(){
    FASTIO
    int testCases = 1, testCaseCount = 1;
    // cin>>testCases;
    while(testCases--){
        // cout<<"Case #"<<testCaseCount++<<":";
        ll N; cin>>N;
        string S; cin>>S;
        map<pair<int, int>, int> hMap;
        int C = 0, G = 0, A = 0, T = 0;
        ll ans = 0;
        for(int i=0; i<S.length(); ++i){
            if(S[i]=='C') C++;
            else if(S[i]=='G') G++;
            else if(S[i]=='A') A++;
            else T++;
            pair<int, int> temp = {C-G, A-T};
            if(hMap.find(temp)!=hMap.end()) ans += hMap[temp];
            if(hMap.find(temp)!=hMap.end()) hMap[temp]++;
            else hMap[temp] = 1;
            if(temp.first==0 && temp.second==0) ans++;
        }
        cout<<ans<<endl;
    }
}