#include <bits/stdc++.h>

#define LL long long

#define ull unsigned long long

#define F(i, j, k) for(int i = j; i <= k; i++)

#define DF(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

template <typename T> inline void read(T &n) {
	T w = 1;
	n = 0;
	char ch = getchar();
	while (!isdigit(ch) && ch != EOF) {
		if (ch == '-') w = -1;
		ch = getchar();
	}
	while (isdigit(ch) && ch != EOF) {
		n = (n << 3) + (n << 1) + (ch & 15);
		ch = getchar();
	}
	n *= w;
}

template <typename T> inline void write(T x) {
	T l = 0;
	ull y = 0;
	if (!x) {
		putchar(48);
		return;
	}
	if (x<0) {
		putchar('-');
		x = -x;
	}
	while (x) {
		y = y * 10 + x % 10;
		x /= 10;
		l++;
	}
	while (l) {
		putchar(y % 10 + 48);
		y /= 10;
		l--;
	}
}

template <typename T> inline void writes(T x) {
	write(x);
	putchar(' ');
}

template <typename T> inline void writeln(T x) {
	write(x);
	puts("");
}

template <typename T> inline void checkmax(T &a,T b) { a = a > b ? a : b; }

template <typename T> inline void checkmin(T &a,T b) { a = a < b ? a : b; }

int num[26];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	string st;
	cin >> st;
	int l = st.size();
	LL ans = 0;
	DF(i, l - 1, 1) {
		if (st[i] == st[i - 1]) {
			if (i != l - 1 && st[i] != st[i + 1]) ans += l - 1 - i - num[int(st[i]) - 97]; 
		}
		if (i != l - 1 && st[i] == st[i + 1]) {
			F(j, 0, 25) num[j] = 0;
			num[int(st[i]) - 97] = l - i - 1; 
		}
		++num[int(st[i]) - 97];
	}
	writeln(ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N; cin >> N;
  string S; cin >> S;

  vector<vector<ll>> cnt(N + 1, vector<ll>(4, 0));
  for (ll i = 0; i < S.size(); i++) {
    for (ll j = 0; j < 4; j++) {
      cnt[i + 1][j] = cnt[i][j];
    }
    if (S[i] == 'A') cnt[i + 1][0]++;
    if (S[i] == 'T') cnt[i + 1][1]++;
    if (S[i] == 'C') cnt[i + 1][2]++;
    if (S[i] == 'G') cnt[i + 1][3]++;
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    for (ll j = i + 1; j <= N; j++) {
      vector<ll> temp(4, 0);
      for (ll k = 0; k < 4; k++) {
        temp[k] = cnt[j][k] - cnt[i][k];
      }
      if (temp[0] == temp[1] && temp[2] == temp[3]) ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}