#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;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define vpi vector<pair<int,int> > 
#define vpll vector<pair<lli,lli> > 
#define vvi vector<vector<int> >
#define vvll vector<vector<lli> > 
#define maxn 100005



int main(){
    fastio;
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int fra=0,frt=0,frc=0,frg=0;
        for(int j=i;j<n;j++){
            if(s[j]=='A') fra++;
            if(s[j]=='T') frt++;
            if(s[j]=='C') frc++;
            if(s[j]=='G') frg++;
            if(fra==frt and frc==frg)
            ans++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}
