#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long


int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll i;
    ll pref[s.length()+1]={0};
    ll j;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='A')
        {
            pref[i+1]=pref[i]+6000;
        }
        else if(s[i]=='T')
        {
            pref[i+1]=pref[i]-6000;
        }
        else if(s[i]=='C')
        {
            pref[i+1]=pref[i]+1;
        }
        else
        {
            pref[i+1]=pref[i]-1;
        }
    }
    ll ans=0;
    for(i=0;i<=s.length();i++)
    {
        for(j=i+1;j<=s.length();j++)
        {
            if(pref[j]-pref[i]==0)
            {
                ans++;
            }
        }
    }
    cout<<ans<<"\n";
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        int n;
        string s;
        cin>>n>>s;
        ll ans = 0;
        unordered_map <char,ll> mp;
        mp['A'] = 100000000000000;
        mp['T'] = -100000000000000;
        mp['C'] = 20000000000;
        mp['G'] = -20000000000;
        unordered_map <int,int> mpp;
        mpp[0] = 1;
        ll sum = 0;
        for(int i=0;i<n;i++)
        {
            sum+=mp[s[i]];
            mpp[sum]++;;
        }
        for(auto i = mpp.begin();i!=mpp.end();i++)
        {
            ans+=((i->second)*(i->second-1))/2;
        }
        cout<<ans;
    }
    return 0;
}