#include<bits/stdc++.h>
#define loop(i, n) for(int i = 0; i < n; i++)
#define pb          push_back
#define ll          long long int
#define vi          vector<int>
#define pi          pair<int, int>
#define W(t)        int t; cin >> t; while(t--)
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff          first
#define ss          second
using namespace std;
vi read(int n){
    vi v(n);

    loop(i, n)
        cin >> v[i];
    return v;
}
void solve(){
    ll i, j, k, m, n, ans = 0, cnt = 0, sum = 0;

    string s;

    cin >> n >> s;
    int c1, c2;
    for(int i = 0; i < n; i++){
        c1 = 0, c2 = 0;
        for(int j = i; j < n; j++){
            if(s[j] == 'A')
                c1++;
            else if(s[j] == 'T'){
                c1--;
            }
            else if(s[j] == 'C'){
                c2++;
            }
            else if(s[j] == 'G'){
                c2--;
            }
            if(c1 == 0 && c2 == 0)
                ans++;
        }
    }

    cout << ans << "\n";

}

    //cout << ans << "\n";
int main(){
    FIO
    
    #ifndef ONLINE_JUDGE
    freopen("C:/Codeforces/input.txt", "r", stdin);
    freopen("C:/Codeforces/output.txt", "w", stdout);
    #endif
    
    //W(t)
    solve();
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <assert.h>
#include <functional>
#include <iomanip>

using namespace std;

#define ll long long
#define endl "\n"
const ll mod = 1e9 + 7;
const int MX = 2e5 + 5;

multiset<int> adj[MX * 2];
int cnt[MX * 2];

int solve(){
	int n; cin >> n;
	for(int u, v, i = 0; i < n; i ++){
		cin >> u >> v;
		adj[u].insert(v);
		adj[v].insert(u);
		cnt[u] ++; cnt[v] ++;
	}

	set<int> li1;
	for(int i = 0; i < MX * 2; i ++)
		if(cnt[i] == 1) li1.insert(i);

	int ans = 0;
	while(!li1.empty()){
		int gt = *li1.begin();
		int pr = *adj[gt].begin();
		ans ++;
		
		adj[gt].clear();
		adj[pr].erase(adj[pr].find(gt));
		cnt[gt] --; cnt[pr] --;

		if(li1.count(gt)) li1.erase(li1.find(gt));
		if(li1.count(pr)) li1.erase(li1.find(pr));
		if(cnt[pr] == 1) li1.insert(pr);
	}

	for(int i = 0; i < MX * 2; i ++)
		if(cnt[i] > 1) ans ++;

	cout << ans << endl;
	return 0;
}

int main(){
	cin.tie(0) -> sync_with_stdio(0);
	int tc = 1; 
//	cin >> tc;
	for(;tc --;) solve();
}