#include <bits/stdc++.h>
#define ll long long
#define maxn 10006
using namespace std;
ll read() {
    ll x = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) x = 10 * x + ch - '0';
    return x * f;
}
void print(ll x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
string s;
int n;
int x[4][5010];
int main() {
    cin >> n >> s;
    s = "." + s;
    memset(x, 0, sizeof(x));
    for (int i = 1; i <= n; ++i) {
        if (s[i] == 'A')
            x[0][i]++;
        else if (s[i] == 'T')
            x[1][i]++;
        else if (s[i] == 'G')
            x[2][i]++;
        else
            x[3][i]++;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 4; ++j) {
            x[j][i] += x[j][i - 1];
        }
    }
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            int a = x[0][j] - x[0][i - 1];
            int b = x[1][j] - x[1][i - 1];
            int c = x[2][j] - x[2][i - 1];
            int d = x[3][j] - x[3][i - 1];
            if (a == b && c == d) res++;
        }
    }
    cout << res;
    return 0;
}
#include<bits/stdc++.h>
using namespace std;

int N;
string S;

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

  int ans = 0;
  for(int i = 0; i < N; i++) {
    int A, T, C, G;
    A = T = C = G = 0;
    for(int j = i; j < N; j++) {
      if(S[j] == 'A') A++;
      if(S[j] == 'T') T++;
      if(S[j] == 'C') C++;
      if(S[j] == 'G') G++;
      if(A == T && C == G) ans++;
    }
  }

  printf("%d\n", ans);

  return 0;
}
