#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, ans=0;
	cin >> n;
	char s[n+1];
	int a[n+1], t[n+1], c[n+1], g[n+1];
	for (int i=1; i<=n; i++){
		cin >> s[i];
		a[i]=t[i]=c[i]=g[i]=0;
	}
	a[0]=t[0]=c[0]=g[0]=0;
	for (int i=1; i<=n; i++){
		a[i]=a[i-1], t[i]=t[i-1], c[i]=c[i-1], g[i]=g[i-1];
		if (s[i]=='A') a[i]++;
		if (s[i]=='T') t[i]++;
		if (s[i]=='C') c[i]++;
		if (s[i]=='G') g[i]++;
	}
	for (int i=1; i<n; i++)
		for (int j=i+1; j<=n; j++)
			if (a[j]-a[i-1]==t[j]-t[i-1]&&c[j]-c[i-1]==g[j]-g[i-1]) ans++;
	cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>
#define ll long long 
#define ld long double
#define int long long
using namespace std;
const ll INF = 1e18;
const ll MOD = 998244353;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
#ifdef MODULAR
void __print(mint x) {cerr << x;}
#endif
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef XOX
#define deb(x...) cerr << "Line (" << __LINE__ << ") : " << "[" << #x << "] = [", _print(x)
#else
#define deb(x...)
#endif

int32_t main() {
	ios::sync_with_stdio(!cin.tie(NULL));
	int n;
	cin >> n;
	string s;
	cin >> s;
	char ch;
	int ans = 0;
	bool found;
	int a = 0, g = 0, c = 0, t = 0;
	for(int i = 0; i < n; i++) {
		int ptr = 0;
		a = g = c = t = 0;
		for(int j = i; j < n; j++) {
			if(s[j] == 'A')		ch = 'T', a++;
			else if(s[j] == 'G') ch = 'C', g++;
			else if(s[j] == 'C') ch = 'G', c++;
			else if(s[j] == 'T') ch = 'A', t++;
			if(a == t and c == g) ans++;
			deb(i, j, a, t, g, c);
			//found = false;
			//while(ptr < n and !found) {
				//ptr++;
				//if(s[ptr - 1] == ch) found = true;
			//}
			//deb(i, j, ptr, found, ch);
			//if(!found)	break;
			//else	ans++;
		}
	}
	cout << ans;

}

