/*
“The only way that we can live is if we grow.
 The only way we can grow is if we change. 
The only way we can change is if we learn.
 The only way we can learn is if we are exposed.
 And the only way that we are exposed is if we throw ourselves into the open.”
 ***************************************   ************************   **********************************
*/
#include <bits/stdc++.h>
using namespace std;

 
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
 
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, 
             tree_order_statistics_node_update> data_set; 
#define fbo find_by_order
#define ook order_of_key

//---------------------mishra ka idea------------------ 
#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define sz(x)     (int)(x).size()
#define ull       unsigned long long
//------------------------mishra ka idea-------------------




//-------------------------alsi hu mai-----------------------
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define hell        998244353
#define output(x) cout << (x ? "YES" : "NO")<<endl;
#define Output(x) cout << (x ? "Yes" : "No")<<endl;
//-------------------------alsi hu mai-----------------------



//--------------------het se uthaya---------------------
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18) 
 
 
 
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("in.txt");ofstream coutt("out.txt");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;} 

//--------------------het se uthaya-------------------------------------------------------------------


int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }  
int rint(int  l , int r){return rand()%(r-l+1) + l ;}
 
//---------------------------aab code dekho bahut template dekh liya---------------------------------


 
signed main()
{
   //freopen("input.txt", "r", stdin);
   //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int i,j,x,t,n;
   cin>>n;
   string s; 
   cin>>s;
   //int n = s.length(); 
   int pref[n+1] , pref1[n+1];
   pref[0]=0;
   pref1[0]=0;
   int c1 = 0 , c2 = 0;
   fo(i,0,n){
    if(s[i]=='A'){
      c1++;
    }
    if(s[i]=='T'){
      c1--;
    }
    if(s[i]=='G'){
      c2++;

    }
    if(s[i]=='C'){
      c2--;
    }
    pref[i+1]=c1;
    pref1[i+1]=c2;
   }
   int ans = 0;
   fo(i,1,n+1){
   // cout<<pref[i]<<" "<<pref1[i]<<"<<<"<<endl;
    fo(j,i+1,n+1){

    //  cout<<pref[j]-pref[i-1]<<" "<<pref1[j]-pref1[i-1]<<endl;
      if((pref[j]-pref[i-1]==0 )&& (pref1[j]-pref1[i-1]==0))ans++;
    }
   }
   cout<<ans<<endl;
   
   
   
    return 0;
}

//----------------abc tez kar liya iska matlab ye nahi tum legend ho kya pata hagdo aage ------------------

using namespace std;

#define visual

#ifdef visual
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>
#endif
#ifndef visual
#include <bits/stdc++.h>
#endif

typedef long long ll;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    map<pair<int, int>, int> m;
    int x = 0;
    int y = 0;
    int n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    m[{0, 0}] = 1;
    for (char c : s) {
        if (c == 'C') x--;
        if (c == 'G') x++;
        if (c == 'A') y--;
        if (c == 'T') y++;
        ans += m[{x, y}];
        m[{x, y}]++;
    }

    cout << ans << endl;


}
