/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v)         v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
    return (x > y ? x : y);
}

using namespace std;

const int N = 1e7 + 5;

void solve() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> pre(n, 0);
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        int g = 0, a = 0;
        for(int j = i; j < n; j++) {
            if(s[j] == 'G') g++;
            if(s[j] == 'C') g--;
            if(s[j] == 'A') a++;
            if(s[j] == 'T') a--;
            if(!g && !a) {
                pre[j] = (i == 0 ? 0 : pre[i - 1]) + 1;
                break;
            }
        }
    }
    for(int i = 0; i < n; i++) {
        ans += pre[i];
    }
    cout << ans << '\n';
}

int main() {
    /*int tc;
    scanf("%d", &tc);
    while(tc--)*/
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<(n);i++)
using ll = long long;
const ll INF = 1e9+7;
const ll mod=1000000007;
using P = pair<ll, ll>;

int main(){
    int n;
    string s;
    cin >> n >> s;
    ll ans =0;
    for(int i=0; i<n; i++){
        map<char,int> ma;
        for(int j=0; j+i<=n-1; j++){
            ma[s[i+j]]++;
            if(ma['A']==ma['T'] & ma['C']==ma['G']) ans++;
        }
    }
    cout << ans << endl;
}