#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double d;
typedef long double ld;
inline int read()
{
	register int s=0,f=0;
	register char ch=getchar();
	while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
	while(isdigit(ch)) s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return f?-s:s;
}
inline void write(int x)
{
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int a[5005][305];
char ch[5] = {' ', 'A', 'T', 'G', 'C'};
signed main()
{
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	s = ' ' + s;
	for (int i = 1; i <= n; i ++)
	{
		for (int j = 1; j <= 4; j ++)
		{
			a[i][ch[j]] = a[i - 1][ch[j]] + (s[i] == ch[j]);
		}
	}
	for (int i = 1; i <= n; i ++)
	{
		for (int j = 2; j <= (n - i) + 1; j += 2)
		{
			string t = s.substr (i, j);
			int sa;
			int st;
			int sg;
			int sc;
			sa = a[i + j - 1]['A'] - a[i - 1]['A'];
			st = a[i + j - 1]['T'] - a[i - 1]['T'];
			sg = a[i + j - 1]['G'] - a[i - 1]['G'];
			sc = a[i + j - 1]['C'] - a[i - 1]['C'];
			if (sa == st && sg == sc) ans ++;
		}
	}
	cout << ans << endl;
	return 0;
}

#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <tuple>
#include <algorithm>
#include <unordered_set>
#include <cmath>

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for(ll i=0;i<(ll)n;i++)
#define REPab(i,a,b)for(ll i=(ll)a;i<(ll)b;i++)
constexpr bool bitp(ull bits, ull pos) { return bits & (1ULL << pos); }

int main() {
    ll N;
    std::cin >> N;
    std::vector<ull> A(N);
    REP(i, N) std::cin >> A[i];
    ull max = 1ULL << (N - 1);
    ull score = std::numeric_limits<ull>::max();
    for (ull b = 0; b < max; b++) {
        ull bOR = A[0];
        ull bXOR = 0;
        for (ull t = 0; t < N - 1; t++) {
            if (bitp(b, t)) {
                bXOR ^= bOR;
                bOR = 0;
            }
            bOR |= A[t + 1];
        }
        bXOR ^= bOR;
        score = std::min(score, bXOR);
    }
    std::cout << score << "\n";
}
