#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve(int tc)
{
	int n;
	string s;
	cin >> n >> s;
	map<char, int> id;
	id['A'] = 0;
	id['C'] = 1;
	id['G'] = 2;
	id['T'] = 3;
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		v32 cnt(4, 0);
		for (int j = i; j < n; j++)
		{
			cnt[id[s[j]]]++;
			if (cnt[0] == cnt[3] && cnt[1] == cnt[2])
				ans++;
		}
	}
	cout << ans << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve(tc);
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	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;
}
