#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
long long modPow(long long x, long long a) {
  if (a == 1) return x;
  if (a % 2) return (x * modPow(x, a - 1)) % MOD;
  long long t = modPow(x, a / 2);
  return (t * t) % MOD;
}
long long modInv(long long x) {
  return modPow(x, MOD - 2);
  }
  void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

// nPnの順列に対して処理を実行する
void foreach_permutation(int n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

// nPkの順列に対して処理を実行する
void foreach_permutation(int n, int k, std::function<void(int *)> f) {
  foreach_comb(n, k, [&](int *c_indexes) {
    foreach_permutation(k, [&](int *p_indexes) {
      int indexes[k];
      for (int i = 0; i < k; i++) {
        indexes[i] = c_indexes[p_indexes[i]];
      }
      f(indexes);
    });
  });
}
int main() {
    string  s;
    cin >>  s;
         for (int i = 0; i < s.size(); i++) {
        if(s[i] == '9'){
          s[i] = '6';
        }
        else if(s[i] == '6'){
          s[i] = '9';
        }
      }
      reverse(s.begin(), s.end());
      cout << s << endl;
}
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 998244353;
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

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

	vector<int> cnt(4);
	ll ans = 0;
	rep(i, n) {
		for (int j = i; j < n; j++) {
			if (s[j] == 'A') cnt[0]++;
			if (s[j] == 'T') cnt[1]++;
			if (s[j] == 'C') cnt[2]++;
			if (s[j] == 'G') cnt[3]++;
			if (cnt[0] == cnt[1] && cnt[2]==cnt[3]) ans++;
		}
		rep(m, 4) cnt[m] = 0;
	}
	cout << ans << endl;
}