#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000000


int main()
{
#ifndef ONLINE_JUDGE
     // for getting input from input.txt
     freopen("input.txt", "r", stdin);
     // for writing output to output.txt
     freopen("output.txt", "w", stdout);
#endif

 int n;
 cin>>n;
 string s;
 cin>>s;
 ll sum = 0;
 map<ll, ll> m;
 m[0] = 1;
 ll ans = 0;
 for(int i=0; i<n; i++){
 	if(s[i] == 'A')
 		sum++;
 	else if(s[i] == 'T')
 		sum--;
 	else if(s[i] == 'G')
 		sum += 100000;
 	else
 		sum -= 100000;
 	ans += m[sum];
 	m[sum]++;
 }
 cout<<ans;
 return 0;
}



#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >>s ;
    int ans=0;
    for (int i=0;i<n;i++){
        int f=0,se=0;
        for (int j=i;j<n;j++){
            if (s[j]=='A')
                f++;
            else if (s[j]=='T')
                f--;
            else if (s[j]=='C')
                se++;
            else
                se--;
            if ((j-i)%2==1 && f==0 && se==0)
                ans++;
        }
    }
    cout << ans ;
}
