#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;

vector<map<char, int>> dict(5010);

int main() {
    int n; cin >> n;
    string s; cin >> s;

    vector<string> ss(n+1, "");
    
    for (int i=0;i<n;i++){
        ss[i+1] = ss[i] + s[i];
    }
    for (int i=1;i<=n;i++){
        for (auto c : ss[i]){
            dict[i][c] += 1;
        }
    }
    
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n+1;j++){
            
            if (dict[j]['T']-dict[i]['T'] == dict[j]['A']-dict[i]['A'] && dict[j]['C']-dict[i]['C'] == dict[j]['G']-dict[i]['G'])
                ans += 1;
        }
    }
    cout << ans << endl;
    

    return 0;
}
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;

    vector<long long> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    vector<long long> sums(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        sums[i + 1] = sums[i];
        if (i & 1) {
            sums[i + 1] += A[i];
        } else {
            sums[i + 1] -= A[i];
        }
    }

    map<long long,int> cnts;
    cnts[0] += 1;
    long long res = 0;
    for (int i = 0; i < n; ++i) {
        res += cnts[sums[i + 1]];
        cnts[sums[i + 1]] += 1;
    }


    cout << res << '\n';
    
    return 0;
}