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

void solve() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int c1 = 0, c2 = 0;
		for (int 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) ans++;
		}
	}
	cout << ans << '\n';
}

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

	int tt = 1;
	// cin >> tt;
	for (int i = 1; i <= tt; ++i) {
		solve();
	}

	return 0;
}

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +100500
//#define M ll(998244353)
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector <int>
#define last(x) (x).back()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

string s;
int n, i, c[300], mp[4], j, ans;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << setprecision(6);
    cout << fixed;
//    in("sequence.in");
//    out("sequence.out");
//    in("D:/cpp/2/output.txt");
//    out("output.txt");

    c['A'] = 0;
    c['T'] = 1;
    c['G'] = 2;
    c['C'] = 3;

    cin >> n >> s;

    for (i = 0; i < n; i++)
    {
        mp[0] = mp[1] = mp[2] = mp[3] = 0;

        for (j = i; j < n; j++)
        {
            mp[c[s[j]]]++;

            if (mp[0] == mp[1] && mp[2] == mp[3])
                ans++;
        }
    }
    cout << ans;
}
