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

typedef long long ll;

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define all(x) (x).begin() ,(x).end()
#define prec(x) cout<<fixed<<setprecision(x)

const ll mod = 1e9 + 7;

ll binpow(ll a, ll b , ll mod) {
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res % mod;
}

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

const int N = 3e5 + 5;
const ll inf = 1e16;

void solve() {

	int n;
	cin >> n;

	string s;
	cin >> s;

	string p = "ATGC";
	int fr[n][4];

	memset(fr , 0 , sizeof(fr));

	for (int i = 0 ; i < n ; i++) {
		for (int j = 0 ; j < 4 ; j++) {
			fr[i][j] = fr[i - 1][j] * ( i != 0 ) + (p[j] == s[i]);
		}
	}

	int ans = 0;

	for (int i = 0 ; i < n ; i++) {
		for (int j = i ; j < n ; j++) {
			int A = 0 , T = 0 , C = 0 , G = 0;

			T = fr[j][1] , A = fr[j][0] , G = fr[j][2] , C = fr[j][3];
			if (i > 0)
				T -= fr[i - 1][1] , A -= fr[i - 1][0] , G -= fr[i - 1][2] , C -= fr[i - 1][3];
			//cout << T << " " << A << " " << G << " " << C << "\n";
			if ((T > 0 or C > 0) and T == A and C == G)
				ans++;
		}
	}

	cout << ans << "\n";
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t = 1;
	//cin >> t;

	while (t--)
		solve();

	return 0;
}
/*
Author: rafa45
Date: 28 Sep 2020
*/
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define mod 1000000007
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int i=0, j=0, n=0;
    int c1=0, c2=0, cnt=0;
    string s, sub;

    cin >> n >> s;

    for(i=0; i<n-1; i++){
        c1=0; c2=0;
        for(j=i; j<n; j++){
            if(s[j]=='A') c1++;
            else if(s[j]=='T') c1--;
            else if(s[j]=='C') c2++;
            else c2--;
            if(c1==0 && c2==0) cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}
