#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;
}

#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <map>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    pair<int, int> cnt = {0, 0};
    map< pair<int, int>, int > m;
    m[cnt] = 1;
    for (int i = 0; i < n; ++i) {
        switch (s.at(i)) {
            case 'A': ++cnt.first; break;
            case 'T': --cnt.first; break;
            case 'C': ++cnt.second; break;
            case 'G': --cnt.second; break;
        }
        ++m[cnt];
    }
    cout << accumulate(m.begin(), m.end(), 0, [](int init, pair< pair<int, int>, int> i) {
        return init += i.second * (i.second - 1) / 2;
    }) << endl;
    return 0;
}
