#include <iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
const int maxn = 5005;
int main()
{
	char s[5005];
	int a[maxn], g[maxn], c[maxn], t[maxn];
	int n;
	int cnt = 0;
	cin >> n;
	a[0] = 0;
	g[0] = 0;
	c[0] = 0;
	t[0] = 0;
	int a1, g1, c1, t1;
	for(int i = 1; i <= n; i++)
	{
		cin >> s[i];
	}
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == 'A')
		{
			a[i] = a[i - 1] + 1;
		}
		else a[i] = a[i - 1];
		if(s[i] == 'G')
		{
			g[i] = g[i - 1] + 1;
		}
		else g[i] = g[i - 1];
		if(s[i] == 'C')
		{
			c[i] = c[i - 1] + 1;
		}
		else c[i] = c[i - 1];
		if(s[i] == 'T')
		{
			t[i] = t[i - 1] + 1;
		}
		else t[i] = t[i - 1];
		
	}
	
	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]))
				cnt++;
			}
		}
	cout << cnt << endl;
}
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  int N;
  string S;
  cin >> N >> S;

  int ans = 0;
  rep(i, N) {
    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] == 'G')
        c2++;
      else if (S[j] == 'C')
        c2--;
      if (c1 == 0 && c2 == 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}