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

int n, a[5001], g[5001], c[5001], t[5001], ans;
char s[5002];

int main()
{
	scanf("%d %s", &n, s + 1);
	for (int i = 1; i <= n; ++i) {
		a[i] = a[i - 1] + (int)(s[i] == 'A');
		g[i] = g[i - 1] + (int)(s[i] == 'G');
		c[i] = c[i - 1] + (int)(s[i] == 'C');
		t[i] = t[i - 1] + (int)(s[i] == 'T');
	}
	for (int i = 1; i < n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			if ((j - i + 1) & 1) continue;
			if (a[j] - a[i - 1] == t[j] - t[i - 1] &&
			    g[j] - g[i - 1] == c[j] - c[i - 1]) {
				++ans;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// "Em gioi roi, em o dang cap khac" - Vu Minh Chau aka. abc15566
mll occ;
int main(){
	fastio;
	ll n; string s; cin >> n >> s;
	ll cprefix = 0; occ[0] = 1;
	ll ans = 0;
	for (ll i = 0; i < n; i++){
		if (s[i] == 'A') cprefix += 1000000;
		else if (s[i] == 'T') cprefix -= 1000000;
		else if (s[i] == 'C') cprefix++;
		else cprefix--;
		ans += occ[cprefix]; occ[cprefix]++;
	}
	cout << ans << "\n";
}