#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ll long long
using namespace std;

unsigned int factorial(unsigned int n){
    if (n==0) return 1;
    else return n*factorial(n-1);
}

int binary_search(vector<int> v,int key){
    int left=-1;
    int right=v.size();
    while(right-left>1){
        int mid=left+(right-left)/2;
        if (v[mid]>=key) right=mid;
        else left=mid;
    }
    return right;
}

int main(){
    int n;
    string S;
    int ar[4][n+1];
    cin>>n>>S;

    for (int i=0;i<4;i++){
        for(int j=0;j<n+1;j++){
            ar[i][j]=0;
        }
    }
    
    for (int j=0;j<n;j++){
        for (int i=0;i<4;i++){
            ar[i][j+1]=ar[i][j];
        }
        if (S[j]=='A') ar[0][j+1]+=1;
        if (S[j]=='T') ar[1][j+1]+=1;
        if (S[j]=='C') ar[2][j+1]+=1;
        if (S[j]=='G') ar[3][j+1]+=1;
    }
    
ll ans=0;
    for (int width=2;width<n+1;width++){
        for (int j=1;j<n-width+2;j++){
            int x=j+width-1;
            int y=j-1;
            int A_num=ar[0][x]-ar[0][y];
            int T_num=ar[1][x]-ar[1][y];
            int C_num=ar[2][x]-ar[2][y];
            int G_num=ar[3][x]-ar[3][y];

            if ((A_num==T_num)&&(C_num==G_num)) ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  long long ans = 0;
  string S;
  cin >> N >> S;
  int A, T, C, G;
  for(int i = 0; i < N; i++){
    A = 0;
    T = 0;
    C = 0;
    G = 0;
    for(int j = i; j < N; j++){
      if(S.at(j) == 'A') A++;
      if(S.at(j) == 'T') T++;
      if(S.at(j) == 'G') G++;
      if(S.at(j) == 'C') C++;
      if(A == T && C == G){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}