#include <bits/stdc++.h>

signed main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n;
    std::string s;

    std::cin >> n >> s;

    int ans = 0;

    for (int i = 0; i < n; i++) {
        int at = 0, gc = 0;

        for (int j = i; j < n; j++) {
            if (s[j] == 'A') ++at;
            else if (s[j] == 'T') --at;
            else if (s[j] == 'G') ++gc;
            else --gc;
            
            ans += !(at || gc);
        }
    }

    std::cout << ans;

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);

string s, t;
ll n, m, cnt, ans;
ll ruia[123456], ruit[123456], ruic[123456], ruig[123456];
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	cin >> n >> s;
	rep(i, n) {
		ruia[i + 1] = ruia[i];
		ruit[i + 1] = ruit[i];
		ruic[i + 1] = ruic[i];
		ruig[i + 1] = ruig[i];
		if (s[i] == 'A') { ruia[i + 1]++; }
		if (s[i] == 'T') { ruit[i + 1]++; }
		if (s[i] == 'C') { ruic[i + 1]++; }
		if (s[i] == 'G') { ruig[i + 1]++; }
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			ll a, t, c, g;
			a = ruia[j] - ruia[i];
			t = ruit[j] - ruit[i];
			c = ruic[j] - ruic[i];
			g = ruig[j] - ruig[i];
			//cout << a << ' ' << t << ' ' << c << ' ' << g << endl;
			if (a == t && c == g) { 
				ans++;
				//cout << i << ' ' << j << endl;
			}
		}
	}
	cout << ans << endl;
	return 0;
}