#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

using P = pair<ll, ll>;

void solve(istream& cin, ostream& cout) {
  ll n;
  cin >> n;
  vector<P> pa;
  REP(i, 5) {
    pa.push_back(P(5 - i, 15 - 3 * i));
  }
  ll ans = 0;
  ll prev = LINF;
  EACH(el, pa) {
    ll now = pow(ll(10), el.second);
    if (n / now >= 1) {
      ans += el.first * (min(n, prev) - now + 1);
    }
    prev = now - 1;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    string s;
    cin >> n >> s;
    ll ans=0;
    for(int i=1;i<=n/2;++i){
        int x=2*i;
        vector<int> t(4,0);
        rep(j,x){
            if(s[j]=='A') ++t[0];
            else if(s[j]=='T') ++t[1];
            else if(s[j]=='G') ++t[2];
            else ++t[3];
        }
        if(t[0]==t[1] && t[2]==t[3]) ++ans;
        rep(j,n-x){
            if(s[j]=='A') --t[0];
            else if(s[j]=='T') --t[1];
            else if(s[j]=='G') --t[2];
            else --t[3];
            if(s[j+x]=='A') ++t[0];
            else if(s[j+x]=='T') ++t[1];
            else if(s[j+x]=='G') ++t[2];
            else ++t[3];
            if(t[0]==t[1] && t[2]==t[3]) ++ans;
        }
    }
    cout << ans << "\n";
    return 0;
}   