
#include <iostream>
#include <climits>
#include<vector>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include<cmath>
#include <limits>
using namespace std;
typedef long long ll;

typedef pair<ll, ll> P;
const int INF = 10000000000;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
const int MOD = 1000000007;


int main() {
	ll N,i,j,ans;
	cin >> N;
	string S;
	cin >> S;
	ans = 0;
	ll cca, cct, ccg, ccc;
	cca = 0;
	cct = 0;
	ccg = 0;
	ccc = 0;
	REP(i, 0, N) {
		REP(j, i,N) {
			if (S[j] == 'A') cca++;
			if (S[j] == 'T') cct++;
			if (S[j] == 'G') ccg++;
			if (S[j] == 'C') ccc++;
			if ((cca == cct) && (ccg == ccc))ans++;
		}

		cca = 0;
		cct = 0;
		ccg = 0;
		ccc = 0;
	}
	output(ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using vi  = vector<int64_t>;
using vvi = vector<vi>;
using pii = pair<int64_t, int64_t>;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;

  int ans = 0;
  map<char, vi> check;
  check['A'] = vi(s.size()+10);
  check['T'] = vi(s.size()+10);
  check['C'] = vi(s.size()+10);
  check['G'] = vi(s.size()+10);
  for (int i=1; i < s.size()+1; i++) {
    for (auto x : check) {
      char key = x.first;
      if (s[i-1] == key) check[key][i] = check[key][i-1] + 1;
      else check[key][i] = check[key][i-1];
    }
  }
  for (int i = 1; i < s.size()+1; i++) {
    rep(j, s.size()+1-i) {
      if ((check['A'][j+i] - check['A'][j] == check['T'][j+i] - check['T'][j]) && (check['C'][j+i] - check['C'][j] == check['G'][j+i] - check['G'][j])) {
        ans += 1;
      }
    }
  }
  cout << ans << endl;
}
