#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

struct C
{
	int size;
	int c[2];
	C(int size, int cc[2]) : size(size) {
		c[0]=cc[0];
		c[1]=cc[1];
	}
	bool operator<(C rhs) const {
		return c[0]-c[1]<rhs.c[0]-rhs.c[1];
	};
};

int main() {
	int n;
	std::cin >> n;
	V<V<int> > g(n);
	for(int i=1;i<n;i++) {
		int p;
		std::cin >> p;
		p--;
		g[p].emplace_back(i);
	}
	auto dfs = [&](auto f, int i) -> C {
		int size=1;
		V<C> v;
		for(auto e:g[i]) {
			v.emplace_back(f(f,e));
		}
		int m=v.size();
		int o[2];
		if(m==0) {
			o[0]=1;
			o[1]=0;
			C c(1,o);
			return c;
		}
		if(m==1) {
			o[0]=v[0].c[0]+1;
			o[1]=v[0].c[1];
			C c(v[0].size+1,o);
			return c;
		}
		rep(i,m) size+=v[i].size;
		o[0]=1;
		o[1]=0;
		C c(size,o);
		V<C> vo,ve;
		rep(i,m) {
			if(v[i].size&1) vo.emplace_back(v[i]);
			else ve.emplace_back(v[i]);
		}
		std::sort(all(vo));
		rep(i,vo.size()) {
			if(i&1) {
				c.c[0]+=vo[i].c[1];
				c.c[1]+=vo[i].c[0];
			} else {
				c.c[0]+=vo[i].c[0];
				c.c[1]+=vo[i].c[1];
			}
		}
		int odd=vo.size()&1;
		for(auto e:ve) {
			if(e.c[0]-e.c[1]<0) {
				c.c[0]+=e.c[0];
				c.c[1]+=e.c[1];
			} else {
				c.c[0]+=e.c[odd];
				c.c[1]+=e.c[1^odd];
			}
		}
		return c;
	};
	print(dfs(dfs,0).c[0]);
}

/*Author--Vishwas Agrawal*/
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define test  \
    ll t;     \
    cin >> t; \
    while (t--)
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define M 1000000007LL
#define input(v, n) \
    inc(i, 0, n)    \
    {               \
        ll x;       \
        cin >> x;   \
        v.pb(x);    \
    }
#define print(v, n) \
    inc(i, 0, n) { cout << v[i] << " "; }
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define inc(i, a, n) for (ll i = a; i < n; i++)
#define dec(i, a, n) for (ll i = n - 1; i >= a; i--)
long long binpow(long long base, long long exp, int mod)
{
    long long res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % mod;
        exp = exp >> 1;
        base = (base * base) % mod;
    }
    return res;
}
long long mod(long long x)
{
    return ((x % M + M) % M);
}

long long add(long long a, long long b)
{
    return mod(mod(a) + mod(b));
}

long long mul(long long a, long long b)
{
    return mod(mod(a) * mod(b));
}
bool Is_Prime(long long x)
{
    if (x % 2 == 0)
        return false;
    for (int i = 3; i * i <= x; i += 2)
        if (x % i == 0)
            return false;
    return true;
}

int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll count = 0;
    inc(i, 0, s.length())
    {

        ll arr[4] = {0};
        if (s[i] == 'A')
            arr[0]++;
        if (s[i] == 'T')
            arr[1]++;
        if (s[i] == 'C')
            arr[2]++;
        if (s[i] == 'G')
            arr[3]++;
        inc(j, i + 1, s.length())
        {
            if (s[j] == 'A')
                arr[0]++;
            if (s[j] == 'T')
                arr[1]++;
            if (s[j] == 'C')
                arr[2]++;
            if (s[j] == 'G')
                arr[3]++;
            if (arr[0] == arr[1] && arr[2] == arr[3])
            {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}