#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int nt[5005];
int na[5005];
int ng[5005];
int nc[5005];


int sum(int* ar, int l, int r) {
    --l;
    return ar[r] - ar[l];
}

int main() {
    fastio;
    ll ans=0;
    ll N;
    string s;
    cin >> N >> s;
    rep1(i,N) {
        nt[i] = nt[i-1];
        na[i] = na[i-1];
        ng[i] = ng[i-1];
        nc[i] = nc[i-1];
        if (s[i-1] == 'A') ++na[i];
        if (s[i-1] == 'T') ++nt[i];
        if (s[i-1] == 'C') ++nc[i];
        if (s[i-1] == 'G') ++ng[i];
    }
    rep(j,N) rep(i,j) {
        int l = i+1, r = j+1;
        if (sum(nt, l, r) < sum(na, l, r))
            continue;
        if (sum(na, l, r) < sum(nt, l, r))
            continue;
        if (sum(nc, l, r) < sum(ng, l, r))
            continue;
        if (sum(ng, l, r) < sum(nc, l, r))
            continue;
        ++ans;
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define vll vector<long long>
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL);

int lcm(int a, int b) { return (a / __gcd(a, b)) * b; }

ll bigMod(ll b, ll e, ll mod) {
    if (e == 0) return 1 % mod;
    if (e % 2 == 0) {
        ll half = bigMod(b, e / 2, mod);
        return half * half % mod;
    } else return bigMod(b, e - 1, mod) * b % mod;
}
void factors(ll n) {
    int i, j;
    vll arr;
    for (i = 1; i  <= sqrt(n); i++)
        if (n % i == 0) {
            j = n / i;
            arr.push_back(i);
            if (i != j)
                arr.push_back(i);
        }
}


#define pi acos(-1)

#define all(x) x.begin(), x.end()
#define pb push_back
#define endl "\n"
#define decimal(p) fixed<<setprecision(p)

#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vd vector<double>

#define pfd(x) printf("%d\n", x)
#define pfc(x) printf("%c\n", x)
#define pfs(x) printf("%s\n", x)

#define scd(x) scanf("%d", &x)
#define scc(x) scanf("%c", &x)
#define scf(x) scanf("%f", &x)
#define scs(x) scanf("%s", x)

#define msi map<string, int>
#define msc map<string, char>
#define msf map<string, double>
#define msd map<string, double>
#define mx 100000000000

int main() {

    vi arr;
    int x;
    for (int i = 0; i < 4; ++i) {
        cin>>x;
        arr.push_back(x);

    }

    sort(all(arr));
    cout<<arr[0]<<endl;






    return 0;
}