#include "bits/stdc++.h"
using namespace std;

int n,ans;
string a;

int main()
{
	cin>>n>>a;

	for(int i=0;i<n;i++)
	{
		map <char,int> m;
		for(int j=i;j<n;j++)
		{
			m[a[j]]++;
			if(m['A']==m['T'] and m['C']==m['G']) ans++;
		}
	}
	cout<<ans;
}
#pragma GCC optimize("Ofast") 
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define fast                     ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll                       long long
#define ld                       long double
#define endl                     '\n'
#define all(A)                   (A).begin(),(A).end()
#define traceA(A,x)              cerr<<#A<<": ";for(int i = 0; i < (x) ; ++i) cerr<<A[i]<<' ';cerr<<endl
#define traceV(A)                cerr<<#A<<": ";for(auto i:A)cerr<<i<<' ';cerr<<endl
#define traceM(A,n,m)            cerr<<#A<<": "<<endl;for(int i = 0; i < (n) ; ++i){for(int j = 0; j < (m) ; ++j) cerr << A[i][j] << ' ';cerr << endl;}

#define TRACE
#ifdef TRACE
#define trace(...) __f__(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1> void __f__(const char* name,Arg1&& arg1){cerr<<name<<" : "<<arg1<<endl;}
template <typename Arg1,typename... Args> void __f__(const char* names,Arg1&& arg1,Args&&... args){const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f__(comma+1,args...);}
#else
// #define trace(...) 1
#endif

const int N = 2e5 + 77;
int A[N], C[N], G[N], T[N];
int a , c, g, t;

void sol(){
    int n ;  cin >> n ;
    string s ; cin >> s;
    for(int i = 0 ; i < n ; ++i){
        if(s[i] == 'A') A[i+1]++;
        if(s[i] == 'C') C[i+1]++;
        if(s[i] == 'G') G[i+1]++;
        if(s[i] == 'T') T[i+1]++;
    }
    {
        for(int i = 1; i <= n ; ++i){
            a += A[i];
            A[i] = a;
        }
        for(int i = 1; i <= n ; ++i){
            c += C[i];
            C[i] = c;
        }
        for(int i = 1; i <= n ; ++i){
            g += G[i];
            G[i] = g;
        }
        for(int i = 1; i <= n ; ++i){
            t += T[i];
            T[i] = t;
        }
    }

    // traceA(A,n+1);
    // traceA(C,n+1);
    // traceA(G,n+1);
    // traceA(T,n+1);
    int ans = 0;

    for(int l = 1 ; l <= n ; ++l){
        for(int r= l+1; r <= n ; ++r){
            a = A[r]-A[l-1];
            c = C[r]-C[l-1];
            g = G[r]-G[l-1];
            t = T[r]-T[l-1];
            if(a == t && c == g) ans++;
        }
    } 
    cout << ans << endl;
}   

int32_t main(){
    fast;
    int t  = 1; 
    // cin >> t;
    // while(t--) 
    sol();
    return 0;
}