#include<bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    vector<vector<int>> a(N+1,vector<int>(N+1,0));
    vector<vector<int>> t(N+1,vector<int>(N+1,0));
    vector<vector<int>> c(N+1,vector<int>(N+1,0));
    vector<vector<int>> g(N+1,vector<int>(N+1,0));

    for (int i=0;i<N;i++)
    {
        if (S[i]=='A'){
            a[0][i+1]=a[0][i]+1;
            t[0][i+1]=t[0][i];
            g[0][i+1]=g[0][i];
            c[0][i+1]=c[0][i];
        }
        if (S[i]=='T'){
            a[0][i+1]=a[0][i];
            t[0][i+1]=t[0][i]+1;
            g[0][i+1]=g[0][i];
            c[0][i+1]=c[0][i];
        }
        if (S[i]=='C'){
            a[0][i+1]=a[0][i];
            t[0][i+1]=t[0][i];
            g[0][i+1]=g[0][i];
            c[0][i+1]=c[0][i]+1;
        }
        if (S[i]=='G'){
            a[0][i+1]=a[0][i];
            t[0][i+1]=t[0][i];
            g[0][i+1]=g[0][i]+1;
            c[0][i+1]=c[0][i];
        }
    }
    for (int i=1;i<N+1;i++)
    {
        for (int j=0;j<=i;j++)
        {
            a[j][i]=a[0][i]-a[0][j];
            t[j][i]=t[0][i]-t[0][j];
            c[j][i]=c[0][i]-c[0][j];
            g[j][i]=g[0][i]-g[0][j];
        }
    }
    int ans=0;
    for (int i=1;i<N+1;i++)
    {
        for (int j=0;j<i;j++)
        {
            if (a[j][i]==t[j][i] && c[j][i]==g[j][i]){
                ans++;
            }
        }
    }
    cout << ans << endl;
    
    
    
}
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep1(i,n) for (int i=1;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, ll>;

int main() {
  int n;
  cin >> n;
  // vector<int> a(n);
  map<int,int> m;

  rep(i,n){
    int a;
    cin >> a;
    m[a]++;
  }
  // sort(m.begin(), m.end());

  ll sum = 0;
  for(auto x : m){
    n -= x.second;
    sum += (ll)n * x.second;
  }

  cout << sum << endl;
  return 0;
}