#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
const int maxn = 5005;
ll sum[maxn];
ll a[maxn];
char s[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s", s + 1);
	sum[0] = 0;
	for(int i = 1; i <= n; i++)
	{
		if (s[i] == 'A')
			a[i] = 1;
		else if (s[i] == 'T')
			a[i] = -1;
		else if (s[i] == 'C')
			a[i] = 5000;
		else if (s[i] == 'G')
            a[i] = -5000;
	}
	for(int i = 1; i <= n; i++){
        sum[i] = sum[i - 1] + a[i];
	}
	ll ans = 0;
	for(int i = 0; i <= n; i++){
		for (int j = i + 2; j <= n; j += 2){
			if (sum[j] == sum[i]){
				ans++;
			}
		}
	}
	printf("%lld\n", ans);
    return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define int long long
#define sz(x) (ll)(x.size())
using namespace std;


const int mod = 1e9+7;

int expo_pow(int x,int y){
 if(y == 0) return 1;
  y=y%(mod-1);
  x%=mod;
  if(y==0) y=mod-1;
  int res=1;
  while(y){
    if(y&1) res=(res*x)%mod;
    x=(x*x)%mod;
    y>>=1; 
  }
  return res;
}

ll add()
{
    return 0;
}

template <typename T, typename... Types>
T add(T var1, Types... var2){
    return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;
}

ll mul(){
    return 1;
}

template <typename T, typename... Types>
T mul(T var1, Types... var2){
    return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;
}

bool check(map<char,int> mp) {
  if (mp['A'] == mp['T'] and mp['G'] == mp['C']) return true;
  return false;
}

void solve(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    map<char,int> mp;
    for (int j = i; j < s.size(); ++j) {
      mp[s[j]]++;
      if (check(mp)) ans++;
    }
  }
  cout << ans << "\n";
}


signed main(){
  fast;
  int test = 1;
  int i=1;
  while(test--){
    solve();
  }
}



