#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
vector <ll> v[100005];
ll arr[MAX];
ll color[MAX];
ll good[20000000],bad[20000000];
int main()
{
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>arr[i];
	for(ll i=2;i<=n;i++)
	{
		ll x;
		cin>>x;
		v[x].pb(i);
	}
	queue<ll> q;
	q.push(1);
	ll last=0;
	while(!q.empty())
	{
		ll x=q.front();
		q.pop();
		for(ll i=0;i<v[x].size();i++)
		{
			color[v[x][i]]=1-color[x];
			q.push(v[x][i]);
		}
		if(v[x].size()==0)
		{
			last=color[x];
		}
	}
	ll ans=0,cntg=0,cntb=0;
	for(ll i=1;i<=n;i++)
	{
		if(color[i]==last)
		{
			good[arr[i]]++;
			ans^=arr[i];
			cntg++;
		}
		else
		{
			bad[arr[i]]++;
			cntb++;
		}
	}
	ll prt=0;
	//cout<<good[0]<<" "<<good[1]<<" "<<good[2]<<endl;
	if(ans==0)
	{
		prt+=cntg*(cntg-1)/2+cntb*(cntb-1)/2;
		//nonsimilar
		// swap red and black

	}

//	cout<<ans<<endl;

	ll temp=0;
	for(ll i=1;i<(1<<24);i++)
		temp+=good[i]*bad[ans^i];
	cout<<prt+temp<<endl;
}


#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vll vector<ll>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll gcd(ll n1,ll n2){
	if(n2==0)
		return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent)
{
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
vector <ll> v[100005];
ll arr[MAX];
ll color[MAX];
ll good[(1<<24)+5],bad[(1<<24)+5];
int main()
{
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>arr[i];
	for(ll i=2;i<=n;i++)
	{
		ll x;
		cin>>x;
		v[x].pb(i);
	}
	queue<ll> q;
	q.push(1);
	ll last=0;
	while(!q.empty())
	{
		ll x=q.front();
		q.pop();
		for(ll i=0;i<v[x].size();i++)
		{
			color[v[x][i]]=1-color[x];
			q.push(v[x][i]);
		}
		if(v[x].size()==0)
		{
			last=color[x];
		}
	}
	ll ans=0,cntg=0,cntb=0;
	for(ll i=1;i<=n;i++)
	{
		if(color[i]==last)
		{
			good[arr[i]]++;
			ans^=arr[i];
			cntg++;
		}
		else
		{
			bad[arr[i]]++;
			cntb++;
		}
	}
	ll prt=0;
	//cout<<good[0]<<" "<<good[1]<<" "<<good[2]<<endl;
	if(ans==0)
	{
		prt+=cntg*(cntg-1)/2+cntb*(cntb-1)/2;
		//nonsimilar
		// swap red and black

	}

//	cout<<ans<<endl;

	ll temp=0;
	for(ll i=1;i<(1<<24);i++)
		temp+=good[i]*bad[ans^i];
	cout<<prt+temp<<endl;
}


#include <bits/stdc++.h>
#define forn(i, s, n) for (int i = s; i < n; ++i)
using namespace std;
typedef long long ll;

void collect_rec(const vector<int>& apps, const vector<vector<int>>& child,
                 int idx, map<int, int>& even_map, map<int, int>& odd_map,
                 bool even) {
    map<int, int>* pmap;
    if (even)
        pmap = &even_map;
    else
        pmap = &odd_map;

    if (pmap->find(apps[idx]) != pmap->end())
        ++(*pmap)[apps[idx]];
    else
        (*pmap)[apps[idx]] = 1;

    forn(i, 0, child[idx].size()) {
        collect_rec(apps, child, child[idx][i], even_map, odd_map, !even);
    }
}

int main() {
    int n;
    scanf("%d", &n);

    vector<int> apps(n);
    vector<vector<int>> child(n);

    forn(i, 0, n) {
        scanf("%d", &apps[i]);
    }
    int temp;
    forn(i, 1, n) {
        scanf("%d", &temp);
        child[temp-1].push_back(i);
    }

    map<int, int> even_map;
    map<int, int> odd_map;
    collect_rec(apps, child, 0, even_map, odd_map, true);

    bool even_leaf = true;
    int idx = 0;
    while(!child[idx].empty()) {
        idx = child[idx][0];
        even_leaf = !even_leaf;
    }

    map<int, int>* p_tar = &even_map;
    map<int, int>* p_res = &odd_map;
    if (!even_leaf)
        swap(p_tar, p_res);

    int nsum = 0;
    for (auto& kv : *p_tar) {
        if (kv.second % 2 == 1)
            nsum ^= kv.first;
    }

    auto v_sum = [](auto pmap) {
        return accumulate(pmap->begin(), pmap->end(), 0,
                          [](int& sum, auto& kv) {
                              return sum + kv.second;
                          });
    };

    ll tar_sum = v_sum(p_tar);
    ll res_sum = v_sum(p_res);

    ll result = 0;
    if (nsum == 0) {
        result += tar_sum * (tar_sum - 1) / 2;
        result += res_sum * (res_sum - 1) / 2;

        for (auto& kv : *p_tar) {
            auto itr = p_res->find(kv.first);
            if (itr != p_res->end()) {
                result += (ll) kv.second * (ll) itr->second;
            }
        }
    }
    else {
        for (auto& kv : *p_tar) {
            auto itr = p_res->find(kv.first ^ nsum);
            if (itr != p_res->end()) {
                result += (ll) kv.second * (ll) itr->second;
            }
        }
    }

    printf("%lld\n", result);
}


#include <bits/stdc++.h>
#define forn(i, s, n) for (int i = s; i < n; ++i)
using namespace std;
typedef long long ll;

void collect_rec(const vector<int>& apps, const vector<vector<int>>& child,
                 int idx, map<int, int>& even_map, map<int, int>& odd_map,
                 bool even) {
    map<int, int>* pmap;
    if (even)
        pmap = &even_map;
    else
        pmap = &odd_map;

    if (pmap->find(apps[idx]) != pmap->end())
        ++(*pmap)[apps[idx]];
    else
        (*pmap)[apps[idx]] = 1;

    forn(i, 0, child[idx].size()) {
        collect_rec(apps, child, child[idx][i], even_map, odd_map, !even);
    }
}

int main() {
    int n;
    scanf("%d", &n);

    vector<int> apps(n);
    vector<vector<int>> child(n);

    forn(i, 0, n) {
        scanf("%d", &apps[i]);
    }
    int temp;
    forn(i, 1, n) {
        scanf("%d", &temp);
        child[temp-1].push_back(i);
    }

    map<int, int> even_map;
    map<int, int> odd_map;
    collect_rec(apps, child, 0, even_map, odd_map, true);

    bool even_leaf = true;
    int idx = 0;
    while(!child[idx].empty()) {
        idx = child[idx][0];
        even_leaf = !even_leaf;
    }

    map<int, int>* p_tar = &even_map;
    map<int, int>* p_res = &odd_map;
    if (!even_leaf)
        swap(p_tar, p_res);

    int nsum = 0;
    for (auto& kv : *p_tar) {
        if (kv.second % 2 == 1)
            nsum ^= kv.first;
    }

    auto v_sum = [](auto pmap) {
        return accumulate(pmap->begin(), pmap->end(), 0,
                          [](int& sum, auto& kv) {
                              return sum + kv.second;
                          });
    };

    int tar_sum = v_sum(p_tar);
    int res_sum = v_sum(p_res);

    int result = 0;
    if (nsum == 0) {
        result += tar_sum * (tar_sum - 1) / 2;
        result += res_sum * (res_sum - 1) / 2;

        for (auto& kv : *p_tar) {
            auto itr = p_res->find(kv.first);
            if (itr != p_res->end()) {
                result += kv.second * itr->second;
            }
        }
    }
    else {
        for (auto& kv : *p_tar) {
            auto itr = p_res->find(kv.first ^ nsum);
            if (itr != p_res->end()) {
                result += kv.second * itr->second;
            }
        }
    }

    printf("%d\n", result);
}


#include <bits/stdc++.h>
#define forn(i, s, n) for (int i = s; i < n; ++i)
using namespace std;
typedef long long ll;

void collect_rec(const vector<int>& apps, const vector<vector<int>>& child,
                 int idx, map<int, int>& even_map, map<int, int>& odd_map,
                 bool even) {
    map<int, int>* pmap;
    if (even)
        pmap = &even_map;
    else
        pmap = &odd_map;

    if (pmap->find(apps[idx]) != pmap->end())
        ++(*pmap)[apps[idx]];
    else
        (*pmap)[apps[idx]] = 1;

    forn(i, 0, child[idx].size()) {
        collect_rec(apps, child, child[idx][i], even_map, odd_map, !even);
    }
}

int main() {
    int n;
    scanf("%d", &n);

    vector<int> apps(n);
    vector<vector<int>> child(n);

    forn(i, 0, n) {
        scanf("%d", &apps[i]);
    }
    int temp;
    forn(i, 1, n) {
        scanf("%d", &temp);
        child[temp-1].push_back(i);
    }

    map<int, int> even_map;
    map<int, int> odd_map;
    collect_rec(apps, child, 0, even_map, odd_map, true);

    bool even_leaf = true;
    int idx = 0;
    while(!child[idx].empty()) {
        idx = child[idx][0];
        even_leaf = !even_leaf;
    }

    map<int, int>* p_tar = &even_map;
    map<int, int>* p_res = &odd_map;
    if (!even_leaf)
        swap(p_tar, p_res);

    int nsum = 0;
    for (auto& kv : *p_tar) {
        if (kv.second % 2 == 1)
            nsum ^= kv.first;
    }

    auto v_sum = [](auto pmap) {
        return accumulate(pmap->begin(), pmap->end(), 0,
                          [](int& sum, auto& kv) {
                              return sum + kv.second;
                          });
    };

    ll tar_sum = v_sum(p_tar);
    ll res_sum = v_sum(p_res);

    ll result = 0;
    if (nsum == 0) {
        result += tar_sum * (tar_sum - 1) / 2;
        result += res_sum * (res_sum - 1) / 2;

        for (auto& kv : *p_tar) {
            auto itr = p_res->find(kv.first);
            if (itr != p_res->end()) {
                result += kv.second * itr->second;
            }
        }
    }
    else {
        for (auto& kv : *p_tar) {
            auto itr = p_res->find(kv.first ^ nsum);
            if (itr != p_res->end()) {
                result += kv.second * itr->second;
            }
        }
    }

    printf("%lld\n", result);
}


#include <bits/stdc++.h>
#define forn(i, s, n) for (int i = s; i < n; ++i)
using namespace std;
typedef long long ll;

void collect_rec(const vector<int>& apps, const vector<vector<int>>& child,
                 int idx, map<int, int>& even_map, map<int, int>& odd_map,
                 bool even) {
    map<int, int>* pmap;
    if (even)
        pmap = &even_map;
    else
        pmap = &odd_map;

    if (pmap->find(apps[idx]) != pmap->end())
        ++(*pmap)[apps[idx]];
    else
        (*pmap)[apps[idx]] = 1;

    forn(i, 0, child[idx].size()) {
        collect_rec(apps, child, child[idx][i], even_map, odd_map, !even);
    }
}

int main() {
    int n;
    scanf("%d", &n);

    vector<int> apps(n);
    vector<vector<int>> child(n);

    forn(i, 0, n) {
        scanf("%d", &apps[i]);
    }
    int temp;
    forn(i, 1, n) {
        scanf("%d", &temp);
        child[temp-1].push_back(i);
    }

    map<int, int> even_map;
    map<int, int> odd_map;
    collect_rec(apps, child, 0, even_map, odd_map, true);

    bool even_leaf = true;
    int idx = 0;
    while(!child[idx].empty()) {
        idx = child[idx][0];
        even_leaf = !even_leaf;
    }

    map<int, int>* p_tar = &even_map;
    map<int, int>* p_res = &odd_map;
    if (!even_leaf)
        swap(p_tar, p_res);

    int nsum = 0;
    for (auto& kv : *p_tar) {
        if (kv.second % 2 == 1)
            nsum ^= kv.first;
    }

    auto v_sum = [](auto pmap) {
        return accumulate(pmap->begin(), pmap->end(), 0,
                          [](int& sum, auto& kv) {
                              return sum + kv.second;
                          });
    };

    ll tar_sum = v_sum(p_tar);
    ll res_sum = v_sum(p_res);

    ll result = 0;
    if (nsum == 0) {
        result += tar_sum * (tar_sum - 1) / 2;
        result += res_sum * (res_sum - 1) / 2;

        for (auto& kv : *p_tar) {
            auto itr = p_res->find(kv.first);
            if (itr != p_res->end()) {
                result += (ll) kv.second * (ll) itr->second;
            }
        }
    }
    else {
        for (auto& kv : *p_tar) {
            auto itr = p_res->find(kv.first ^ nsum);
            if (itr != p_res->end()) {
                result += kv.second * itr->second;
            }
        }
    }

    printf("%lld\n", result);
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <map>

using namespace std;

const int maxN = 2000100, maxL = 10010, oo = 1000000000, modP = 1e9 + 7;
const double PI = acos(-1);

#define foru(i, l, r) for (int i = l; i <= r; ++i)
#define ford(i, r, l) for (int i = r; i >= l; --i)
#define repu(i, r) for (int i = 0; i < r; ++i)
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pint pair < ll, int >

int a[maxN], n, d[maxN], d_leaf, parent[maxN];
vector < int > adj[maxN];
map < int, int > mmap;
ll res;

void dfs(int u) {
    for (auto v : adj[u]) {
        if (parent[u] == v) continue;
        d[v] = d[u] + 1;
        parent[v] = u;
        dfs(v);
    }
    if (u != 1 && adj[u].size() == 1)
        d_leaf = d[u];
}

int main() {
    cin >> n;
    foru(i, 1, n)
        scanf("%d", &a[i]);
    foru(i, 1, n - 1) {
        int u, v;
        scanf("%d %d\n", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1);
    int sum = 0;
    foru(i, 1, n)
        if (d[i] % 2 == d_leaf % 2) sum ^= a[i];
        else mmap[a[i]]++;
    foru(i, 1, n)
        if (d[i] % 2 == d_leaf % 2)
            res = res + mmap[sum ^ a[i]];
    cout << res;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int maxN = 200100, modP = 1e9 + 7;
const double PI = acos(-1);

#define foru(i, l, r) for (int i = l; i <= r; ++i)
#define ford(i, r, l) for (int i = r; i >= l; --i)
#define repu(i, r) for (int i = 0; i < r; ++i)
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pint pair < ll, int >

int a[maxN], n, d[maxN], d_leaf, parent[maxN];
vector < int > adj[maxN];
map < int, int > mmap;
ll res;

void dfs(int u) {
    //for (auto v : adj[u]) {
    repu(i, adj[u].size()) {
        int v = adj[u][i];
        if (parent[u] == v) continue;
        d[v] = d[u] + 1;
        parent[v] = u;
        dfs(v);
    }
    if (u != 1 && adj[u].size() == 0)
        d_leaf = d[u];
}

int main() {
    cin >> n;
    foru(i, 1, n)
        scanf("%d", &a[i]);
    foru(i, 2, n) {
        int u;
        scanf("%d", &u);
        adj[u].push_back(i);
    }
    dfs(1);
    int sum = 0;
    foru(i, 1, n)
        if (d[i] % 2 == d_leaf % 2) sum ^= a[i];
        else mmap[a[i]]++;
    foru(i, 1, n)
        if (d[i] % 2 == d_leaf % 2)
            res = res + mmap[sum ^ a[i]];
    if (sum == 0) {
        int num = 0;
        foru(i, 1, n)
            if (d[i] % 2 == d_leaf % 2) ++num;
        res += (1ll * num * (num - 1)) / 2;
        num = n - num;
        res += (1ll * num * (num - 1)) / 2;
    }
    cout << res;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int maxN = 2000100, maxL = 10010, oo = 1000000000, modP = 1e9 + 7;
const double PI = acos(-1);

#define foru(i, l, r) for (int i = l; i <= r; ++i)
#define ford(i, r, l) for (int i = r; i >= l; --i)
#define repu(i, r) for (int i = 0; i < r; ++i)
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pint pair < ll, int >

int a[maxN], n, d[maxN], d_leaf, parent[maxN];
vector < int > adj[maxN];
map < int, int > mmap;
ll res;

void dfs(int u) {
    for (auto v : adj[u]) {
        if (parent[u] == v) continue;
        d[v] = d[u] + 1;
        parent[v] = u;
        dfs(v);
    }
    if (u != 1 && adj[u].size() == 0)
        d_leaf = d[u];
}

int main() {
    cin >> n;
    foru(i, 1, n)
        scanf("%d", &a[i]);
    foru(i, 2, n) {
        int u;
        scanf("%d", &u);
        adj[u].push_back(i);
    }
    dfs(1);
    int sum = 0;
    foru(i, 1, n)
        if (d[i] % 2 == d_leaf % 2) sum ^= a[i];
        else mmap[a[i]]++;
    foru(i, 1, n)
        if (d[i] % 2 == d_leaf % 2)
            res = res + mmap[sum ^ a[i]];
    if (sum == 0) {
        int num = 0;
        foru(i, 1, n)
            num += (d[i] % 2 == d_leaf % 2);
        res = (1ll * num * (num - 1)) / 2;
        num = n - num;
        res += (1ll * num * (num - 1)) / 2;
    }
    cout << res;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int maxN = 2000100, maxL = 10010, oo = 1000000000, modP = 1e9 + 7;
const double PI = acos(-1);

#define foru(i, l, r) for (int i = l; i <= r; ++i)
#define ford(i, r, l) for (int i = r; i >= l; --i)
#define repu(i, r) for (int i = 0; i < r; ++i)
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pint pair < ll, int >

int a[maxN], n, d[maxN], d_leaf, parent[maxN];
vector < int > adj[maxN];
map < int, int > mmap;
ll res;

void dfs(int u) {
    for (auto v : adj[u]) {
        if (parent[u] == v) continue;
        d[v] = d[u] + 1;
        parent[v] = u;
        dfs(v);
    }
    if (u != 1 && adj[u].size() == 1)
        d_leaf = d[u];
}

int main() {
    cin >> n;
    foru(i, 1, n)
        scanf("%d", &a[i]);
    foru(i, 1, n - 1) {
        int u, v;
        scanf("%d %d\n", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1);
    int sum = 0;
    foru(i, 1, n)
        if (d[i] % 2 == d_leaf % 2) sum ^= a[i];
        else mmap[a[i]]++;
    foru(i, 1, n)
        if (d[i] % 2 == d_leaf % 2)
            res = res + mmap[sum ^ a[i]];
    cout << res;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int maxN = 2000100, maxL = 10010, oo = 1000000000, modP = 1e9 + 7;
const double PI = acos(-1);

#define foru(i, l, r) for (int i = l; i <= r; ++i)
#define ford(i, r, l) for (int i = r; i >= l; --i)
#define repu(i, r) for (int i = 0; i < r; ++i)
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pint pair < ll, int >

int a[maxN], n, d[maxN], d_leaf, parent[maxN];
vector < int > adj[maxN];
map < int, int > mmap;
ll res;

void dfs(int u) {
    for (auto v : adj[u]) {
        if (parent[u] == v) continue;
        d[v] = d[u] + 1;
        parent[v] = u;
        dfs(v);
    }
    if (u != 1 && adj[u].size() == 0)
        d_leaf = d[u];
}

int main() {
    cin >> n;
    foru(i, 1, n)
        scanf("%d", &a[i]);
    foru(i, 2, n) {
        int u;
        scanf("%d", &u);
        adj[u].push_back(i);
    }
    dfs(1);
    int sum = 0;
    foru(i, 1, n)
        if (d[i] % 2 == d_leaf % 2) sum ^= a[i];
        else mmap[a[i]]++;
    if (sum) {
        foru(i, 1, n)
            if (d[i] % 2 == d_leaf % 2)
                res = res + mmap[sum ^ a[i]];
    }
    else {
        int num = 0;
        foru(i, 1, n)
            num += (d[i] % 2 == d_leaf % 2);
        res = (1ll * num * (num - 1)) / 2;
        num = n - num;
        res += (1ll * num * (num - 1)) / 2;
    }
    cout << res;
}


#include <bits/stdc++.h>
//#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
 #define debug(...) {fprintf(stdout, __VA_ARGS__);}
 #else
#define debug(...) {}
#endif
using namespace std; typedef long long int ll; typedef pair<ll,ll> pii;
#define pb push_back
const int N = 2e5+7; int n; ll a[N]; int p[N], dg[N]; queue<pii> qu; map<ll, ll> mp[2]; int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { cin >> p[i]; p[i]--; dg[p[i]]++; } for (int i = 0; i < n; i++) { if (!dg[i]) qu.push(pii(i,0)); } ll res = 0; ll xr = 0; while (!qu.empty()) { pii u = qu.front(); qu.pop(); int i = u.first; mp[u.second][a[i]]++; dg[p[i]]--; if (!dg[p[i]]) { qu.push(pii(p[i], !u.second)); } if (!u.second) { xr ^= a[i]; } } if (xr) { for (pii ps : mp[0]) { ll x = ps.first; ll q = ps.second; res += q*ll(mp[1][xr^x]); } } else { res += ll(mp[0].size()) * ll(mp[0].size() - 1) / 2; res += ll(mp[1].size()) * ll(mp[1].size() - 1) / 2; for (pii ps : mp[0]) { ll x = ps.first; ll q = ps.second; res += q * ll(mp[1][x]); } } cout << res << endl; }


#include <bits/stdc++.h>
//#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
 #define debug(...) {fprintf(stdout, __VA_ARGS__);}
 #else
#define debug(...) {}
#endif
using namespace std; typedef long long int ll; typedef pair<ll,ll> pii; #define pb push_back const int N = 2e5+7; int n; ll a[N]; int p[N], dg[N]; queue<pii> qu; map<ll, ll> mp[2]; int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { cin >> p[i]; p[i]--; dg[p[i]]++; } for (int i = 0; i < n; i++) { if (!dg[i]) qu.push(pii(i,0)); } ll res = 0; ll xr = 0; while (!qu.empty()) { pii u = qu.front(); qu.pop(); int i = u.first; mp[u.second][a[i]]++; dg[p[i]]--; if (!dg[p[i]]) { qu.push(pii(p[i], !u.second)); } if (!u.second) { xr ^= a[i]; } } if (xr) { for (pii ps : mp[0]) { ll x = ps.first; ll q = ps.second; res += q*ll(mp[1][xr^x]); } } else { res += ll(mp[0].size()) * ll(mp[0].size() - 1) / 2; res += ll(mp[1].size()) * ll(mp[1].size() - 1) / 2; for (pii ps : mp[0]) { ll x = ps.first; ll q = ps.second; res += q * ll(mp[1][x]); } } cout << res << endl; }


#include <bits/stdc++.h>
//#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE #define debug(...) {fprintf(stdout, __VA_ARGS__);}
 #else
#define debug(...) {}
#endif
using namespace std; typedef long long int ll; typedef pair<ll,ll> pii; #define pb push_back const int N = 2e5+7; int n; ll a[N]; int p[N], dg[N]; queue<pii> qu; map<ll, ll> mp[2]; int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { cin >> p[i]; p[i]--; dg[p[i]]++; } for (int i = 0; i < n; i++) { if (!dg[i]) qu.push(pii(i,0)); } ll res = 0; ll xr = 0; while (!qu.empty()) { pii u = qu.front(); qu.pop(); int i = u.first; mp[u.second][a[i]]++; dg[p[i]]--; if (!dg[p[i]]) { qu.push(pii(p[i], !u.second)); } if (!u.second) { xr ^= a[i]; } } if (xr) { for (pii ps : mp[0]) { ll x = ps.first; ll q = ps.second; res += q*ll(mp[1][xr^x]); } } else { res += ll(mp[0].size()) * ll(mp[0].size() - 1) / 2; res += ll(mp[1].size()) * ll(mp[1].size() - 1) / 2; for (pii ps : mp[0]) { ll x = ps.first; ll q = ps.second; res += q * ll(mp[1][x]); } } cout << res << endl; }


#include <bits/stdc++.h>
//#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define debug(...) {fprintf(stdout, __VA_ARGS__);}
#else
#define debug(...) {}
#endif

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define pb push_back

const int N = 2e5+7;

int n;
ll a[N];
int p[N], dg[N];
queue<pii> qu;
map<ll, ll> mp[2];

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
        dg[p[i]]++;
    }

    for (int i = 0; i < n; i++) {
        if (!dg[i])
            qu.push(pii(i,0));
    }

    ll res = 0;
    ll xr = 0;
    while (!qu.empty()) {
        pii u = qu.front();
        qu.pop();
        int i = u.first;

        mp[u.second][a[i]]++;

        dg[p[i]]--;
        if (!dg[p[i]]) {
            qu.push(pii(p[i], !u.second));
        }

        if (!u.second) {
            xr ^= a[i];
        }
    }

    if (xr) {
        for (auto ps : mp[0]) {
            ll x = ps.first;
            ll q = ps.second;

            res += q*ll(mp[1][xr^x]);
        }
    } else {
        res += ll(mp[0].size()) * ll(mp[0].size() - 1) / 2;
        res += ll(mp[1].size()) * ll(mp[1].size() - 1) / 2;

        for (auto ps : mp[0]) {
            ll x = ps.first;
            ll q = ps.second;

            res += q * ll(mp[1][x]);
        }
    }

    cout << res << endl;
}


#include <bits/stdc++.h>
//#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define debug(...) {fprintf(stdout, __VA_ARGS__);}
#else
#define debug(...) {}
#endif

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define pb push_back

const int N = 2e5+7;

int n;
ll a[N];
int p[N], dg[N];
queue<pii> qu;
map<ll, ll> mp[2];

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
        dg[p[i]]++;
    }

    for (int i = 0; i < n; i++) {
        if (!dg[i])
            qu.push(pii(i,0));
    }

    ll res = 0;
    ll xr = 0;
ll cn[2]={0,0};
    while (!qu.empty()) {
        pii u = qu.front();
        qu.pop();
        int i = u.first;

        mp[u.second][a[i]]++;
res+=cn[u.second];
        cn[u.second]++;

        dg[p[i]]--;
        if (!dg[p[i]]) {
            qu.push(pii(p[i], !u.second));
        }

        if (!u.second) {
            xr ^= a[i];
        }
    }

    if (xr) {
res=0;
        for (auto ps : mp[0]) {
            ll x = ps.first;
            ll q = ps.second;

            res += q*ll(mp[1][xr^x]);
        }
    } else {

        for (auto ps : mp[0]) {
            ll x = ps.first;
            ll q = ps.second;

            res += q * ll(mp[1][x]);
        }
    }

    cout << res << endl;
}


#include <bits/stdc++.h>
//#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define debug(...) {fprintf(stdout, __VA_ARGS__);}
#else
#define debug(...) {}
#endif

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define pb push_back

const int N = 2e5+7;

int n;
ll a[N];
int p[N], dg[N];
queue<pii> qu;
map<ll, ll> mp[2];

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
        dg[p[i]]++;
    }

    for (int i = 0; i < n; i++) {
        if (!dg[i])
            qu.push(pii(i,0));
    }

    ll res = 0;
    ll xr = 0;
    while (!qu.empty()) {
        pii u = qu.front();
        qu.pop();
        int i = u.first;

        mp[u.second][a[i]]++;

        dg[p[i]]--;
        if (!dg[p[i]]) {
            qu.push(pii(p[i], !u.second));
        }

        if (!u.second) {
            xr ^= a[i];
        }
    }

    cout << xr << endl;

    if (xr) {
        for (auto ps : mp[0]) {
            ll x = ps.first;
            ll q = ps.second;

            res += q*ll(mp[1][xr^x]);
        }
    } else {
        res += ll(mp[0].size()) * ll(mp[0].size() - 1) / 2;
        res += ll(mp[1].size()) * ll(mp[1].size() - 1) / 2;

        for (auto ps : mp[0]) {
            ll x = ps.first;
            ll q = ps.second;

            res += q * ll(mp[1][x]);
        }
    }

    cout << res << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 100001

long long ans = 0;
long long n,p[MAXN],a[MAXN],blue,dep[MAXN],c,res;
vector<int> adj[MAXN];
map<int,long long> cnt[2];

void dfs(int s){
    for(int i=0;i<adj[s].size();i++){
        int t = adj[s][i];
        dep[t] = dep[s]+1;
        dfs(t);
    }
    if(adj[s].size()==0)c = dep[s]%2;
}

int main(){

    scanf("%lld",&n);

    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=2;i<=n;i++){
        scanf("%lld",&p[i]);
        adj[p[i]].push_back(i);
    }

    dfs(1);

    for(int i=1;i<=n;i++){
        if(dep[i]%2==c){
            blue^=a[i];
            cnt[0][a[i]]++;
            res++;
        }
        else cnt[1][a[i]]++;
    }

    if(blue==0){
        for(int i=1;i<=n;i++){
            ans+= cnt[0][i]*cnt[1][i];
        }
        ans+= res*(res-1)/2;
        ans+= (n-res)*(n-res-1)/2;
    }
    else {
        for(int i=1;i<=n;i++){
            if(dep[i]%2==c){
                int cur = blue^a[i];
                ans+= cnt[1][cur];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 100001

long long ans = 0;
long long n,p[MAXN],a[MAXN],blue,dep[MAXN],c,res;
vector<long long> adj[MAXN];
map<int,long long> cnt[2];

void dfs(int s){
    for(int i=0;i<adj[s].size();i++){
        int t = adj[s][i];
        dep[t] = dep[s]+1;
        dfs(t);
    }
    if(adj[s].size()==0)c = dep[s]%2;
}

int main(){

    scanf("%lld",&n);

    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=2;i<=n;i++){
        scanf("%lld",&p[i]);
        adj[p[i]].push_back(i);
    }

    dfs(1);

    for(int i=1;i<=n;i++){
        if(dep[i]%2==c){
            blue^=a[i];
            cnt[0][a[i]]++;
            res++;
        }
        else cnt[1][a[i]]++;
    }

    if(blue==0){
        for(int i=1;i<=n;i++){
            ans+= cnt[0][a[i]]*cnt[1][a[i]];
        }
        ans+= res*(res-1)/2;
        ans+= (n-res)*(n-res-1)/2;
    }
    else {
        for(int i=1;i<=n;i++){
            if(dep[i]%2==c){
                int cur = blue^a[i];
                ans+= cnt[1][cur];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 100001

long long ans = 0;
long long n,p[MAXN],a[MAXN],blue,dep[MAXN],c,res;
vector<long long> adj[MAXN];
map<int,long long> cnt[2];

void dfs(int s){
    for(int i=0;i<adj[s].size();i++){
        int t = adj[s][i];
        dep[t] = dep[s]+1;
        dfs(t);
    }
    if(adj[s].size()==0)c = dep[s]%2;
}

int main(){

    scanf("%lld",&n);

    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=2;i<=n;i++){
        scanf("%lld",&p[i]);
        adj[p[i]].push_back(i);
    }

    dfs(1);

    for(int i=1;i<=n;i++){
        if(dep[i]%2==c){
            blue^=a[i];
            cnt[0][a[i]]++;
            res++;
        }
        else cnt[1][a[i]]++;
    }

    if(blue==0){
        for(int i=1;i<=n;i++){
       		if(deg[i]%2==c)
            ans+= cnt[0][a[i]]*cnt[1][a[i]];
        }
        ans+= res*(res-1)/2;
        ans+= (n-res)*(n-res-1)/2;
    }
    else {
        for(int i=1;i<=n;i++){
            if(dep[i]%2==c){
                int cur = blue^a[i];
                ans+= cnt[1][cur];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 100001

long long ans = 0;
long long n,p[MAXN],a[MAXN],blue,dep[MAXN],c,res;
vector<long long> adj[MAXN];
map<int,long long> cnt[2];

void dfs(int s){
    for(int i=0;i<adj[s].size();i++){
        int t = adj[s][i];
        dep[t] = dep[s]+1;
        dfs(t);
    }
    if(adj[s].size()==0)c = dep[s]%2;
}

int main(){

    scanf("%lld",&n);

    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=2;i<=n;i++){
        scanf("%lld",&p[i]);
        adj[p[i]].push_back(i);
    }

    dfs(1);

    for(int i=1;i<=n;i++){
        if(dep[i]%2==c){
            blue^=a[i];
            cnt[0][a[i]]++;
            res++;
        }
        else cnt[1][a[i]]++;
    }

    if(blue==0){
        for(int i=1;i<=n;i++){
       		if(dep[i]%2==c)
            ans+= cnt[0][a[i]]*cnt[1][a[i]];
        }
        ans+= res*(res-1)/2;
        ans+= (n-res)*(n-res-1)/2;
    }
    else {
        for(int i=1;i<=n;i++){
            if(dep[i]%2==c){
                int cur = blue^a[i];
                ans+= cnt[1][cur];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 100001

long long ans = 0;
long long n,p[MAXN],a[MAXN],blue,dep[MAXN],c,res;
vector<int> adj[MAXN];
map<int,long long> cnt[2];

void dfs(int s){
    for(int i=0;i<adj[s].size();i++){
        int t = adj[s][i];
        dep[t] = dep[s]+1;
        dfs(t);
    }
    if(adj[s].size()==0)c = dep[s]%2;
}

int main(){

    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=2;i<=n;i++){
        scanf("%d",&p[i]);
        adj[p[i]].push_back(i);
    }

    dfs(1);

    for(int i=1;i<=n;i++){
        if(dep[i]%2==c){
            blue^=a[i];
            cnt[0][a[i]]++;
            res++;
        }
        else cnt[1][a[i]]++;
    }

    if(blue==0){
        for(int i=1;i<=n;i++){
            ans+= cnt[0][i]*cnt[1][i];
        }
        ans+= res*(res-1)/2;
        ans+= (n-res)*(n-res-1)/2;
    }
    else {
        for(int i=1;i<=n;i++){
            if(dep[i]%2==c){
                int cur = blue^a[i];
                ans+= cnt[1][cur];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 100001

long long ans = 0;
long long n,p[MAXN],a[MAXN],blue,dep[MAXN],c,res;
vector<long long> adj[MAXN];
map<long long,long long> cnt[2];

void dfs(int s){
    for(int i=0;i<adj[s].size();i++){
        int t = adj[s][i];
        dep[t] = dep[s]+1;
        dfs(t);
    }
    if(adj[s].size()==0)c = dep[s]%2;
}

int main(){

    scanf("%lld",&n);

    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    for(int i=2;i<=n;i++){
        scanf("%lld",&p[i]);
        adj[p[i]].push_back(i);
    }

    dfs(1);

    for(int i=1;i<=n;i++){
        if(dep[i]%2==c){
            blue^=a[i];
            cnt[0][a[i]]++;
            res++;
        }
        else cnt[1][a[i]]++;
    }

    if(blue==0){
        for(int i=1;i<=n;i++){
       		if(dep[i]%2==c)
            ans+=cnt[1][a[i]];
        }
        ans+= (res*(res-1))/2;
        ans+= ((n-res)*(n-res-1))/2;
    }
    else {
        for(int i=1;i<=n;i++){
            if(dep[i]%2==c){
                long long cur = blue^a[i];
                ans+= cnt[1][cur];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 100001

long long ans = 0;
int n,p[MAXN],a[MAXN],blue,dep[MAXN],c,res;
vector<int> adj[MAXN];
map<int,int> cnt[2];

void dfs(int s){
    for(int i=0;i<adj[s].size();i++){
        int t = adj[s][i];
        dep[t] = dep[s]+1;
        dfs(t);
    }
    if(adj[s].size()==0)c = dep[s]%2;
}

int main(){

    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=2;i<=n;i++){
        scanf("%d",&p[i]);
        adj[p[i]].push_back(i);
    }

    dfs(1);

    for(int i=1;i<=n;i++){
        if(dep[i]%2==c){
            blue^=a[i];
            cnt[0][a[i]]++;
            res++;
        }
        else cnt[1][a[i]]++;
    }

    if(blue==0){
        for(int i=1;i<=n;i++){
            ans+= cnt[0][i]*cnt[1][i];
        }
        ans+= res*(res-1)/2;
        ans+= (n-res)*(n-res-1)/2;
    }
    else {
        for(int i=1;i<=n;i++){
            if(dep[i]%2==c){
                int cur = blue^a[i];
                ans+= cnt[1][cur];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, a[N], p[N], s;
vi adj[N];
multiset <int> odd, eve, sums;
ll ans;

int dfs (int u) {
    int ok = 0;
    for (auto v : adj[u]) ok |= dfs(v);

    if (adj[u].empty()) {
        s ^= a[u];
        odd.insert(a[u]);
        return 0;
    }

    if (ok) {
        s ^= a[u];
        odd.insert(a[u]);
    } else eve.insert(a[u]);

    return ok^1;
}

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]), adj[p[i]].pb(i);
    dfs(1);
    if (s == 0) {
        ll x = odd.size();
        ll y = eve.size();
        ans += (x*(x-1))/2;
        ans += (y*(y-1))/2;
        for (auto k : odd) {
            ans += odd.count(k)*eve.count(k);
            eve.erase(k);
        }
    } else {
        for (auto k : odd) sums.insert(s^k);
        for (auto l : eve) ans += sums.count(l);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, a[N], p[N], s;
vi adj[N];
multiset <int> odd, eve, sums;
map <int, ll> codd, ceve;
ll ans;

int dfs (int u) {
    int ok = 0;
    for (auto v : adj[u]) ok |= dfs(v);

    if (adj[u].empty()) {
        s ^= a[u];
        odd.insert(a[u]);
        codd[a[u]]++;
        return 0;
    }

    if (ok) {
        s ^= a[u];
        odd.insert(a[u]);
        codd[a[u]]++;
    } else eve.insert(a[u]), ceve[a[u]]++;

    return ok^1;
}

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]), adj[p[i]].pb(i);
    dfs(1);
    if (s == 0) {
        ll x = odd.size();
        ll y = eve.size();
        ans += (x*(x-1))/2;
        ans += (y*(y-1))/2;
        for (auto p : codd) ans += p.nd*ceve[p.st];
    } else {
        for (auto k : odd) sums.insert(s^k);
        for (auto l : eve) ans += sums.count(l);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, a[N], p[N], s;
vi adj[N], odd, eve;
map <int, ll> cnt, codd, ceve;
ll ans;

int dfs (int u) {
    int ok = 0;
    for (auto v : adj[u]) ok |= dfs(v);

    if (adj[u].empty()) {
        s ^= a[u];
        odd.pb(a[u]);
        codd[a[u]]++;
        return 0;
    }

    if (ok) {
        s ^= a[u];
        odd.pb(a[u]);
        codd[a[u]]++;
    } else eve.pb(a[u]), ceve[a[u]]++;

    return ok^1;
}

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]), adj[p[i]].pb(i);
    dfs(1);
    if (s == 0) {
        ll x = odd.size();
        ll y = eve.size();
        ans += (x*(x-1))/2;
        ans += (y*(y-1))/2;
        for (auto p : codd) ans += p.nd*ceve[p.st];
    } else {
        for (auto k : odd) cnt[s^k]++;
        for (auto l : eve) ans += cnt[l];
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, a[N], p[N], s;
vi adj[N];
multiset <int> odd, eve, sums;
map <int, int> codd, ceve;
ll ans;

int dfs (int u) {
    int ok = 0;
    for (auto v : adj[u]) ok |= dfs(v);

    if (adj[u].empty()) {
        s ^= a[u];
        odd.insert(a[u]);
        codd[a[u]]++;
        return 0;
    }

    if (ok) {
        s ^= a[u];
        odd.insert(a[u]);
        codd[a[u]]++;
    } else eve.insert(a[u]), ceve[a[u]]++;

    return ok^1;
}

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]), adj[p[i]].pb(i);
    dfs(1);
    if (s == 0) {
        ll x = odd.size();
        ll y = eve.size();
        ans += (x*(x-1))/2;
        ans += (y*(y-1))/2;
        for (auto p : codd) ans += p.nd*ceve[p.st];
    } else {
        for (auto k : odd) sums.insert(s^k);
        for (auto l : eve) ans += sums.count(l);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, a[N], p[N], cnt[N], s;
vi adj[N], odd, eve;
multiset <int> sums;
map <int, ll> codd, ceve;
ll ans;

int dfs (int u) {
    int ok = 0;
    for (auto v : adj[u]) ok |= dfs(v);

    if (adj[u].empty()) {
        s ^= a[u];
        odd.pb(a[u]);
        codd[a[u]]++;
        return 0;
    }

    if (ok) {
        s ^= a[u];
        odd.pb(a[u]);
        codd[a[u]]++;
    } else eve.pb(a[u]), ceve[a[u]]++;

    return ok^1;
}

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]), adj[p[i]].pb(i);
    dfs(1);
    if (s == 0) {
        ll x = odd.size();
        ll y = eve.size();
        ans += (x*(x-1))/2;
        ans += (y*(y-1))/2;
        for (auto p : codd) ans += p.nd*ceve[p.st];
    } else {
        for (auto k : odd) cnt[s^k]++;
        for (auto l : eve) ans += cnt[l];
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, a[N], p[N], s;
vi adj[N];
multiset <int> odd, eve, sums;
unordered_map <int, ll> codd, ceve;
ll ans;

int dfs (int u) {
    int ok = 0;
    for (auto v : adj[u]) ok |= dfs(v);

    if (adj[u].empty()) {
        s ^= a[u];
        odd.insert(a[u]);
        codd[a[u]]++;
        return 0;
    }

    if (ok) {
        s ^= a[u];
        odd.insert(a[u]);
        codd[a[u]]++;
    } else eve.insert(a[u]), ceve[a[u]]++;

    return ok^1;
}

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]), adj[p[i]].pb(i);
    dfs(1);
    if (s == 0) {
        ll x = odd.size();
        ll y = eve.size();
        ans += (x*(x-1))/2;
        ans += (y*(y-1))/2;
        for (auto p : codd) ans += p.nd*ceve[p.st];
    } else {
        for (auto k : odd) sums.insert(s^k);
        for (auto l : eve) ans += sums.count(l);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, a[N], p[N], s;
vi adj[N], x, y;
ll ans;

int dfs (int u) {
    int ok = 0;
    for (auto v : adj[u]) ok |= dfs(v);

    if (adj[u].empty()) {
        s ^= a[u];
        x.pb(a[u]);
        return 0;
    }

    if (ok) {
        s ^= a[u];
        x.pb(a[u]);
    } else y.pb(a[u]);

    return ok^1;
}

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]), adj[p[i]].pb(i);
    dfs(1);
    if (s == 0) {
        ans += (x.size()*(x.size()-1))/2;
        ans += (y.size()*(y.size()-1))/2;
    } else {
        for (auto k : x) for (auto l : y) {
            ans += ((s^k^l) == 0);
        }
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, a[N], p[N], s;
vi adj[N], x, y;
multiset <int> sums;
ll ans;

int dfs (int u) {
    int ok = 0;
    for (auto v : adj[u]) ok |= dfs(v);

    if (adj[u].empty()) {
        s ^= a[u];
        x.pb(a[u]);
        return 0;
    }

    if (ok) {
        s ^= a[u];
        x.pb(a[u]);
    } else y.pb(a[u]);

    return ok^1;
}

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]), adj[p[i]].pb(i);
    dfs(1);
    if (s == 0) {
        ll X = x.size();
        ll Y = y.size();
        ans += (X*(X-1))/2;
        ans += (Y*(Y-1))/2;
    } else {
        for (auto k : x) sums.insert(s^k);
        for (auto l : y) ans += sums.count(l);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, a[N], p[N], s;
vi adj[N];
multiset <int> odd, eve, sums;
ll ans;

int dfs (int u) {
    int ok = 0;
    for (auto v : adj[u]) ok |= dfs(v);

    if (adj[u].empty()) {
        s ^= a[u];
        odd.insert(a[u]);
        return 0;
    }

    if (ok) {
        s ^= a[u];
        odd.insert(a[u]);
    } else eve.insert(a[u]);

    return ok^1;
}

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]), adj[p[i]].pb(i);
    dfs(1);
    if (s == 0) {
        ll x = odd.size();
        ll y = eve.size();
        ans += (x*(x-1))/2;
        ans += (y*(y-1))/2;
        for (auto k : odd) {
            ans += odd.count(k)*eve.count(k);
            odd.erase(k);
            eve.erase(k);
        }
    } else {
        for (auto k : odd) sums.insert(s^k);
        for (auto l : eve) ans += sums.count(l);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

mt19937_64 llrand(random_device{}());

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e7+5;

int n, a[N], p[N], s;
vi adj[N];
multiset <int> odd, eve, sums;
int codd[N], ceve[N];
ll ans;

int dfs (int u) {
    int ok = 0;
    for (auto v : adj[u]) ok |= dfs(v);

    if (adj[u].empty()) {
        s ^= a[u];
        odd.insert(a[u]);
        codd[a[u]]++;
        return 0;
    }

    if (ok) {
        s ^= a[u];
        odd.insert(a[u]);
        codd[a[u]]++;
    } else eve.insert(a[u]), ceve[a[u]]++;

    return ok^1;
}

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]), adj[p[i]].pb(i);
    dfs(1);
    if (s == 0) {
        ll x = odd.size();
        ll y = eve.size();
        ans += (x*(x-1))/2;
        ans += (y*(y-1))/2;
        for (int i = 0; i < N; i++) ans += codd[i]*ceve[i];
    } else {
        for (auto k : odd) sums.insert(s^k);
        for (auto l : eve) ans += sums.count(l);
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 69;
vector<int> g[MAXN];
unordered_map<int, int> q[2];
vector<int> a(MAXN);
int xr = 0;
int cnt = 0;
void dfs(int v, int cl)
{
    q[cl][a[v]]++;
    if (!cl)
        xr ^= a[v], cnt++;
    for (int to : g[v])
        dfs(to, cl ^ 1);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 1; i < n; ++i)
    {
        int p;
        cin >> p;
        g[p - 1].push_back(i);
    }
    dfs(0, 1);
    if (xr == 0)
    {
        int ans = 0;
        ans = (cnt * (cnt - 1)) / 2;
        int cnt1 = n - cnt;
        ans += (cnt1 * (cnt1 - 1)) / 2;
        for (auto i : q[0])
        {
            ans += i.second * q[1][i.first];
        }
        cout << ans;
        return 0;
    }
    int ans = 0;
    for (auto i : q[0])
    {
        ans += i.second * q[1][i.first ^ xr];
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 69;
vector<int> g[MAXN];
unordered_map<int, int> q[2];
vector<int> a(MAXN);
vector<int> d(MAXN);
int xr = 0;
int cnt = 0;
int ma = 0;
void dfs(int v, int cl)
{
    bool fl = 0;
    for (int to : g[v])
    {
        dfs(to, cl ^ 1);
        d[v] = d[to] ^ 1;
        fl = 1;
    }
    if (!fl)
        d[v] = 1;
    if (d[v])
    {
        xr ^= a[v];
        cnt++;
    }
    q[d[v]][a[v]]++;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 1; i < n; ++i)
    {
        int p;
        cin >> p;
        g[p - 1].push_back(i);
    }
    dfs(0, 1);
    if (xr == 0)
    {
        int ans = 0;
        ans = (cnt * (cnt - 1)) / 2;
        int cnt1 = n - cnt;
        ans += (cnt1 * (cnt1 - 1)) / 2;
        for (auto i : q[0])
        {
            ans += i.second * q[1][i.first];
        }
        cout << ans;
        return 0;
    }
    int ans = 0;
    for (auto i : q[0])
    {
        ans += i.second * q[1][i.first ^ xr];
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 69;
vector<int> g[MAXN];
unordered_map<int, int> q[2];
vector<int> a(MAXN);
vector<int> d(MAXN);
ll xr = 0;
ll cnt = 0;

void dfs(int v, int cl)
{
    bool fl = 0;
    for (int to : g[v])
    {
        dfs(to, cl ^ 1);
        d[v] = d[to] ^ 1;
        fl = 1;
    }
    if (!fl)
        d[v] = 1;
    if (d[v])
    {
        xr ^= a[v];
        cnt++;
    }
    q[d[v]][a[v]]++;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 1; i < n; ++i)
    {
        int p;
        cin >> p;
        g[p - 1].push_back(i);
    }
    dfs(0, 1);
    if (xr == 0)
    {
        ll ans = 0;
        ans = (cnt * (cnt - 1)) / 2;
        int cnt1 = n - cnt;
        ans += (cnt1 * (cnt1 - 1)) / 2;
        for (auto i : q[0])
        {
            ans += i.second * q[1][i.first];
        }
        cout << ans;
        return 0;
    }
    ll ans = 0;
    for (auto i : q[0])
    {
        ans += i.second * q[1][i.first ^ xr];
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 69;
vector<int> g[MAXN];
unordered_map<int, ll> q[2];
vector<int> a(MAXN);
vector<int> d(MAXN);
ll xr = 0;
ll cnt = 0;

void dfs(int v, int cl)
{
    bool fl = 0;
    for (int to : g[v])
    {
        dfs(to, cl ^ 1);
        d[v] = d[to] ^ 1;
        fl = 1;
    }
    if (!fl)
        d[v] = 1;
    if (d[v])
    {
        xr ^= a[v];
        cnt++;
    }
    q[d[v]][a[v]]++;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 1; i < n; ++i)
    {
        int p;
        cin >> p;
        g[p - 1].push_back(i);
    }
    dfs(0, 1);
    if (xr == 0)
    {
        ll ans = 0;
        ans = (cnt * (cnt - 1)) / 2;
        ll cnt1 = n - cnt;
        ans += (cnt1 * (cnt1 - 1)) / 2;
        for (auto i : q[0])
        {
            ans += i.second * q[1][i.first];
        }
        cout << ans;
        return 0;
    }
    ll ans = 0;
    for (auto i : q[0])
    {
        ans += i.second * q[1][i.first ^ xr];
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 69;
vector<int> g[MAXN];
unordered_map<int, int> q[2];
vector<int> a(MAXN);
vector<int> d(MAXN);
int xr = 0;
int cnt = 0;
int ma = 0;
void dfs(int v, int cl)
{
    q[cl][a[v]]++;
    bool fl = 0;
    for (int to : g[v])
    {
        dfs(to, cl ^ 1);
        d[v] = d[to] ^ 1;
        fl = 1;
    }
    if (!fl)
        d[v] = 1;
    if (d[v])
    {
        xr ^= a[v];
        cnt++;
    }
    q[d[v]][a[v]]++;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 1; i < n; ++i)
    {
        int p;
        cin >> p;
        g[p - 1].push_back(i);
    }
    dfs(0, 1);
    if (xr == 0)
    {
        int ans = 0;
        ans = (cnt * (cnt - 1)) / 2;
        int cnt1 = n - cnt;
        ans += (cnt1 * (cnt1 - 1)) / 2;
        for (auto i : q[0])
        {
            ans += i.second * q[1][i.first];
        }
        cout << ans;
        return 0;
    }
    int ans = 0;
    for (auto i : q[0])
    {
        ans += i.second * q[1][i.first ^ xr];
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
using namespace std;
int n, ai, xr;
vector<vector<int> > data;
vector<int> apples, zero, one;
int dfs(int vertex){
    int ret = 0;
    for (int i=0;i<data[vertex].size();i++){
        int to = data[vertex][i];
        ret = dfs(to) + 1;
    }
    if (ret % 2 == 0) {zero[apples[vertex]-1] ++; xr^=apples[vertex];}
    else one[apples[vertex]-1] ++;
    return ret;
}
int32_t main(){
    cin >> n;
    for (int i=0;i<n;i++){
        vector<int> help;
        data.push_back(help);
        cin >> ai;
        apples.push_back(ai);
    }
    for (int i=0;i<10000000;i++){
        zero.push_back(0);
        one.push_back(0);
    }
    for (int i=1;i<n;i++){
        cin >> ai;
        data[ai-1].push_back(i);
    }
    xr = 0;
    dfs(0);
    if (xr == 0){
        long long ans = 0;
        long long z = 0;
        long long o = 0;
        for (int i=0;i<10000000;i++){
            long long f1 = zero[i];
            long long f2 = one[i];
            ans += f1*f2;
            z += f1;
            o += f2;
        }
        ans += z * (z-1) / 2;
        ans += o * (o-1) / 2;
        cout << ans << endl;
    }
    else{
        long long ans = 0;
        for (int i=0;i<10000000;i++){
            int nx = xr ^ (i+1);
            if (nx > 0 && nx <= 10000000) {long long hp = one[nx - 1] * zero[i];
            ans += hp;}
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
using namespace std;
int n, ai, xr;
vector<vector<int> > data;
vector<int> apples, zero, one;
int dfs(int vertex){
    int ret = 0;
    for (int i=0;i<data[vertex].size();i++){
        int to = data[vertex][i];
        ret = dfs(to) + 1;
    }
    if (ret % 2 == 0) {zero[apples[vertex]-1] ++; xr^=apples[vertex];}
    else one[apples[vertex]-1] ++;
    return ret;
}
int32_t main(){
    cin >> n;
    for (int i=0;i<n;i++){
        vector<int> help;
        data.push_back(help);
        cin >> ai;
        apples.push_back(ai);
    }
    for (int i=0;i<10000000;i++){
        zero.push_back(0);
        one.push_back(0);
    }
    for (int i=1;i<n;i++){
        cin >> ai;
        data[ai-1].push_back(i);
    }
    xr = 0;
    dfs(0);
    if (xr == 0){
        long long ans = 0, z=0, o=0;
        for (int i=0;i<10000000;i++){
            long long hp = zero[i] * one[i];
            ans += hp;
            z += zero[i];
            o += one[i];
        }
        ans += z * (z-1) / 2;
        ans += o * (o-1) / 2;
        cout << ans << endl;
    }
    else{
        long long ans = 0;
        for (int i=0;i<10000000;i++){
            int nx = xr ^ (i+1);
            if (nx > 0 && nx <= 10000000) {long long hp = one[nx - 1] * zero[i];
            ans += hp;}
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
using namespace std;
int n, ai, xr;
vector<vector<int> > data;
vector<int> apples, zero, one;
int dfs(int vertex){
    int ret = 0;
    for (int i=0;i<data[vertex].size();i++){
        int to = data[vertex][i];
        ret = dfs(to) + 1;
    }
    if (ret % 2 == 0) {zero[apples[vertex]-1] ++; xr^=apples[vertex];}
    else one[apples[vertex]-1] ++;
    return ret;
}
int32_t main(){
    cin >> n;
    for (int i=0;i<n;i++){
        vector<int> help;
        data.push_back(help);
        cin >> ai;
        apples.push_back(ai);
    }
    for (int i=0;i<10000000;i++){
        zero.push_back(0);
        one.push_back(0);
    }
    for (int i=1;i<n;i++){
        cin >> ai;
        data[ai-1].push_back(i);
    }
    xr = 0;
    dfs(0);
    if (xr == 0){
        long long ans = 0;
        long long z = 0;
        long long o = 0;
        for (int i=0;i<10000000;i++){
            long long f1 = zero[i];
            long long f2 = one[i];
            ans += f1*f2;
            z += f1;
            o += f2;
        }
        ans += z * (z-1) / 2;
        ans += o * (o-1) / 2;
        cout << ans << endl;
    }
    else{
        long long ans = 0;
        for (int i=0;i<10000000;i++){
            int nx = xr ^ (i+1);
            if (nx > 0 && nx <= 10000000) {
                long long f1 = one[nx-1];
                long long f2 = zero[i];
                ans += f1*f2;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
using namespace std;
int n, ai, xr;
vector<vector<int> > data;
vector<int> apples, zero, one;
int dfs(int vertex){
    int ret = 0;
    for (int i=0;i<data[vertex].size();i++){
        int to = data[vertex][i];
        ret = dfs(to) + 1;
    }
    if (ret % 2 == 0) {zero[apples[vertex]-1] ++; xr^=apples[vertex];}
    else one[apples[vertex]-1] ++;
    return ret;
}
int32_t main(){
    cin >> n;
    for (int i=0;i<n;i++){
        vector<int> help;
        data.push_back(help);
        cin >> ai;
        apples.push_back(ai);
    }
    for (int i=0;i<10000000;i++){
        zero.push_back(0);
        one.push_back(0);
    }
    for (int i=1;i<n;i++){
        cin >> ai;
        data[ai-1].push_back(i);
    }
    xr = 0;
    dfs(0);
    if (xr == 0){
        int ans = 0, z=0, o=0;
        for (int i=0;i<10000000;i++){
            ans += zero[i] * one[i];
            z += zero[i];
            o += one[i];
        }
        ans += z * (z-1) / 2;
        ans += o * (o-1) / 2;
        cout << ans << endl;
    }
    else{
        long long ans = 0;
        for (int i=0;i<10000000;i++){
            int nx = xr ^ (i+1);
            if (nx > 0 && nx <= 10000000) ans += one[nx - 1] * zero[i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#define int long long
using namespace std;
int n, ai, xr;
vector<vector<int> > data;
vector<int> apples, zero, one;
int dfs(int vertex){
    int ret = 0;
    for (int i=0;i<data[vertex].size();i++){
        int to = data[vertex][i];
        ret = dfs(to) + 1;
    }
    if (ret % 2 == 0) {zero[apples[vertex]-1] ++; xr^=apples[vertex];}
    else one[apples[vertex]-1] ++;
    return ret;
}
int32_t main(){
    cin >> n;
    for (int i=0;i<n;i++){
        vector<int> help;
        data.push_back(help);
        cin >> ai;
        apples.push_back(ai);
    }
    for (int i=0;i<10000000;i++){
        zero.push_back(0);
        one.push_back(0);
    }
    for (int i=1;i<n;i++){
        cin >> ai;
        data[ai-1].push_back(i);
    }
    xr = 0;
    dfs(0);
    if (xr == 0){
        int ans = 0, z=0, o=0;
        for (int i=0;i<10000000;i++){
            ans += zero[i] * one[i];
            z += zero[i];
            o += one[i];
        }
        ans += z * (z-1) / 2;
        ans += o * (o-1) / 2;
        cout << ans << endl;
    }
    else{
        int ans = 0;
        for (int i=0;i<10000000;i++){
            int nx = xr ^ (i+1);
            if (nx > 0 && nx <= 10000000) ans += one[nx - 1] * zero[i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
using namespace std;
int n, ai, xr;
vector<vector<int> > data;
vector<int> apples, zero, one;
int dfs(int vertex){
    int ret = 0;
    for (int i=0;i<data[vertex].size();i++){
        int to = data[vertex][i];
        ret = dfs(to) + 1;
    }
    if (ret % 2 == 0) {zero[apples[vertex]-1] ++; xr^=apples[vertex];}
    else one[apples[vertex]-1] ++;
    return ret;
}
int32_t main(){
    cin >> n;
    for (int i=0;i<n;i++){
        vector<int> help;
        data.push_back(help);
        cin >> ai;
        apples.push_back(ai);
    }
    for (int i=0;i<10000000;i++){
        zero.push_back(0);
        one.push_back(0);
    }
    for (int i=1;i<n;i++){
        cin >> ai;
        data[ai-1].push_back(i);
    }
    xr = 0;
    dfs(0);
    if (xr == 0){
        long long ans = 0, z=0, o=0;
        for (int i=0;i<10000000;i++){
            long long hp = zero[i] * one[i];
            ans += hp;
            z += zero[i];
            o += one[i];
        }
        ans += z * (z-1) / 2;
        ans += o * (o-1) / 2;
        cout << ans << endl;
    }
    else{
        long long ans = 0;
        for (int i=0;i<10000000;i++){
            int nx = xr ^ (i+1);
            if (nx > 0 && nx <= 10000000) {
                long long f1 = one[nx-1];
                long long f2 = zero[i];
                ans += f1*f2;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
using namespace std;
int n, ai, xr;
vector<vector<int> > data;
vector<int> apples, zero, one;
int dfs(int vertex){
    int ret = 0;
    for (int i=0;i<data[vertex].size();i++){
        int to = data[vertex][i];
        ret = dfs(to) + 1;
    }
    if (ret % 2 == 0) {zero[apples[vertex]-1] ++; xr^=apples[vertex];}
    else one[apples[vertex]-1] ++;
    return ret;
}
int32_t main(){
    cin >> n;
    for (int i=0;i<n;i++){
        vector<int> help;
        data.push_back(help);
        cin >> ai;
        apples.push_back(ai);
    }
    for (int i=0;i<10000000;i++){
        zero.push_back(0);
        one.push_back(0);
    }
    for (int i=1;i<n;i++){
        cin >> ai;
        data[ai-1].push_back(i);
    }
    xr = 0;
    dfs(0);
    if (xr == 0){
        long long ans = 0, z=0, o=0;
        for (int i=0;i<10000000;i++){
            long long hp = zero[i] * one[i];
            ans += hp;
            z += zero[i];
            o += one[i];
        }
        ans += z * (z-1) / 2;
        ans += o * (o-1) / 2;
        cout << ans << endl;
    }
    else{
        long long ans = 0;
        for (int i=0;i<10000000;i++){
            int nx = xr ^ (i+1);
            if (nx > 0 && nx <= 10000000) ans += one[nx - 1] * zero[i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
using namespace std;
int n, ai, xr;
vector<vector<int> > data;
vector<int> apples, zero, one;
int dfs(int vertex){
    int ret = 0;
    for (int i=0;i<data[vertex].size();i++){
        int to = data[vertex][i];
        ret = dfs(to) + 1;
    }
    if (ret % 2 == 0) {zero[apples[vertex]-1] ++; xr^=apples[vertex];}
    else one[apples[vertex]-1] ++;
    return ret;
}
int32_t main(){
    cin >> n;
    for (int i=0;i<n;i++){
        vector<int> help;
        data.push_back(help);
        cin >> ai;
        apples.push_back(ai);
    }
    for (int i=0;i<10000000;i++){
        zero.push_back(0);
        one.push_back(0);
    }
    for (int i=1;i<n;i++){
        cin >> ai;
        data[ai-1].push_back(i);
    }
    xr = 0;
    dfs(0);
    if (xr == 0){
        long long ans = 0, z=0, o=0;
        for (int i=0;i<10000000;i++){
            long long hp = zero[i] * one[i];
            ans += hp;
            z += zero[i];
            o += one[i];
        }
        ans += z * (z-1) / 2;
        ans += o * (o-1) / 2;
        cout << ans << endl;
    }
    else{
        long long ans = 0;
        for (int i=0;i<10000000;i++){
            int nx = xr ^ (i+1);
            long long hp = one[nx - 1] * zero[i];
            if (nx > 0 && nx <= 10000000) ans += hp;
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)

const int MN = 100005;

int n, val[MN], u, depth[MN], xorsum = 0, par[MN], good, bad, mx, freq[40000005], bcnt;
ll ans = 0;

int main() {
    boost();

    cin >> n;
    for (int i = 1; i <= n; i++) cin >> val[i];
    for (int i = 2; i <= n; i++) cin >> par[i], depth[i] = depth[par[i]] + 1, mx = max(mx, depth[i]);
    good = mx & 1, bad = !good;
    for (int i = 1; i <= n; i++) {
        if (depth[i] % 2 == good) xorsum ^= val[i];
        else freq[val[i]]++, bcnt++;
    }
    if (!xorsum) ans += bcnt * (bcnt - 1) / 2, ans += (n - bcnt) * (n - bcnt - 1) / 2;
    for (int i = 1; i <= n; i++) {
        if (depth[i] % 2 == bad) continue;
        ans += freq[xorsum ^ val[i]];
    }
    printf("%lld\n", ans);

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)

const int MN = 100005;

int n, val[MN], u, depth[MN], xorsum = 0, par[MN], good, bad, mx, freq[20000005], bcnt;
ll ans = 0;

int32_t main() {
    boost();

    cin >> n;
    for (int i = 1; i <= n; i++) cin >> val[i];
    for (int i = 2; i <= n; i++) cin >> par[i], depth[i] = depth[par[i]] + 1, mx = max(mx, depth[i]);
    good = mx & 1, bad = !good;
    for (int i = 1; i <= n; i++) {
        if (depth[i] % 2 == good) xorsum ^= val[i];
        else freq[val[i]]++, bcnt++;
    }
    if (!xorsum) ans += bcnt * (bcnt - 1) / 2, ans += (n - bcnt) * (n - bcnt - 1) / 2;
    for (int i = 1; i <= n; i++) {
        if (depth[i] % 2 == bad) continue;
        ans += freq[xorsum ^ val[i]];
    }
    printf("%lld\n", ans);

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)

const int MN = 100005;

int n, val[MN], u, depth[MN], xorsum = 0, par[MN], good, bad, mx, freq[40000005], bcnt;
ll ans = 0;

int main() {
    boost();

    cin >> n;
    for (int i = 1; i <= n; i++) cin >> val[i];
    for (int i = 2; i <= n; i++) cin >> par[i], depth[i] = depth[par[i]] + 1, mx = max(mx, depth[i]);
    good = mx & 1, bad = !good;
    for (int i = 1; i <= n; i++) {
        if (depth[i] % 2 == good) xorsum ^= val[i];
        else freq[val[i]]++, bcnt++;
    }
    if (!xorsum) ans += bcnt * (bcnt - 1) / 2;
    for (int i = 1; i <= n; i++) {
        if (depth[i] % 2 == bad) continue;
        ans += freq[xorsum ^ val[i]];
    }
    printf("%lld\n", ans);

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)

const int MN = 100005;

int n, val[MN], u, depth[MN], xorsum = 0, par[MN], good, bad, mx, freq[40000005], bcnt;
ll ans = 0;

int32_t main() {
    boost();

    cin >> n;
    for (int i = 1; i <= n; i++) cin >> val[i];
    for (int i = 2; i <= n; i++) cin >> par[i], depth[i] = depth[par[i]] + 1, mx = max(mx, depth[i]);
    good = mx & 1, bad = !good;
    for (int i = 1; i <= n; i++) {
        if (depth[i] % 2 == good) xorsum ^= val[i];
        else freq[val[i]]++, bcnt++;
    }
    if (!xorsum) ans += bcnt * (bcnt - 1) / 2, ans += (n - bcnt) * (n - bcnt - 1) / 2;
    for (int i = 1; i <= n; i++) {
        if (depth[i] % 2 == bad) continue;
        ans += freq[xorsum ^ val[i]];
    }
    printf("%lld\n", ans);

    return 0;
}


#include <iostream>
#include <vector>
#define N 100005
#define PB push_back
#define endl '\n'
#define int long long
using namespace std;
int apple[N],p[N],leaf,t[20000005];
vector<int> v[N],d[2];
void DFS(int l,int x){
	d[l].PB(apple[x]);
	if(!v[x].size())leaf = l;
	for(int i : v[x])DFS(1-l,i);
}
signed main(){
	int n;cin >> n;
	for(int i = 1; i <= n ; i++)cin >> apple[i];
	for(int i = 2; i <= n ; i++){
		int a;cin >> a;
		v[a].PB(i);
	}
	DFS(0,1);
	long long tmp = 0,ans = 0;
	for(int i : d[leaf])tmp ^= i;
	for(int i : d[1-leaf])t[i]++;
	if(!tmp)ans = (d[leaf].size()*(d[leaf].size()-1)/2 + d[1-leaf].size()*(d[1-leaf].size()-1)/2);
	else for(int i : d[leaf])ans += t[tmp^i];
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#define N 100005
#define PB push_back
#define endl '\n'
using namespace std;
int apple[N],p[N],leaf,t[20000005];
vector<int> v[N],d[2];
void DFS(int l,int x){
	d[l].PB(apple[x]);
	if(!v[x].size())leaf = l;
	for(int i : v[x])DFS(1-l,i);
}
int main(){
	int n;cin >> n;
	for(int i = 1; i <= n ; i++)cin >> apple[i];
	for(int i = 2; i <= n ; i++){
		int a;cin >> a;
		v[a].PB(i);
	}
	DFS(0,1);
	long long tmp = 0,ans = 0;
	for(int i : d[leaf])tmp ^= i;
	for(int i : d[1-leaf])t[i]++;
	if(!tmp)ans = (1+d[leaf].size()-1)*(d[leaf].size()-1)/2 + (1+d[1-leaf].size()-1)*(d[1-leaf].size()-1)/2;
	else for(int i : d[leaf])ans += t[tmp^i];
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#define N 100005
#define PB push_back
#define endl '\n'
using namespace std;
int apple[N],p[N],leaf,t[20000005];
vector<int> v[N],d[2];
void DFS(int l,int x){
	d[l].PB(apple[x]);
	if(!v[x].size())leaf = l;
	for(int i : v[x])DFS(1-l,i);
}
int main(){
	int n;cin >> n;
	for(int i = 1; i <= n ; i++)cin >> apple[i];
	for(int i = 2; i <= n ; i++){
		int a;cin >> a;
		v[a].PB(i);
	}
	DFS(0,1);
	int tmp = 0,ans = 0;
	for(int i : d[leaf])tmp ^= i;
	for(int i : d[1-leaf])t[i]++;
	if(!tmp)ans = (1+d[leaf].size()-1)*(d[leaf].size()-1)/2 + (1+d[1-leaf].size()-1)*(d[1-leaf].size()-1)/2;
	else for(int i : d[leaf])ans += t[tmp^i];
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#define N 100005
#define PB push_back
#define endl '\n'
using namespace std;
int apple[N],p[N],leaf,t[20000005];
vector<int> v[N],d[2];
void DFS(int l,int x){
	d[l].PB(apple[x]);
	if(!v[x].size())leaf = l;
	for(int i : v[x])DFS(1-l,i);
}
int main(){
	int n;cin >> n;
	for(int i = 1; i <= n ; i++)cin >> apple[i];
	for(int i = 2; i <= n ; i++){
		int a;cin >> a;
		v[a].PB(i);
	}
	DFS(0,1);
	long long tmp = 0,ans = 0;
	for(int i : d[leaf])tmp ^= i;
	for(int i : d[1-leaf])t[i]++;
	if(!tmp)ans = (1LL*d[leaf].size()*(d[leaf].size()-1)/2 + 1LL*d[1-leaf].size()*(d[1-leaf].size()-1)/2);
	for(int i : d[leaf])ans += t[tmp^i];
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <vector>
#define N 100005
#define PB push_back
#define endl '\n'
using namespace std;
int apple[N],p[N],leaf,t[20000005];
vector<int> v[N],d[2];
void DFS(int l,int x){
	d[l].PB(apple[x]);
	if(!v[x].size())leaf = l;
	for(int i : v[x])DFS(1-l,i);
}
int main(){
	int n;cin >> n;
	for(int i = 1; i <= n ; i++)cin >> apple[i];
	for(int i = 2; i <= n ; i++){
		int a;cin >> a;
		v[a].PB(i);
	}
	DFS(0,1);
	long long tmp = 0,ans = 0;
	for(int i : d[leaf])tmp ^= i;
	for(int i : d[1-leaf])t[i]++;
	if(!tmp)ans = (1LL*d[leaf].size()*(d[leaf].size()-1)/2 + 1LL*d[1-leaf].size()*(d[1-leaf].size()-1)/2);
	else for(int i : d[leaf])ans += t[tmp^i];
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
	int m, n;
	cin >> m >> n;
	vector<int> p(n);
	for(int i = 0; i < n; i++){
		cout << 1 << "\n";
		fflush(stdout);
		int r;
		cin >> r;
		//fflush(stdout);
		p[i] = 1;
		if( r == -1) p[i] = 0;
		//p[i] = r;
	}
	int high = m;
	int low = 1;
    int mid = (high+low)/2;
	int pi = 0;
	while(true){
		cout << mid << "\n";
		fflush(stdout);
		int r;
		cin >> r;
		if(r == 0){
			//cout << mid << "\n";
			exit(0);
			//return 0;
		}
		//fflush(stdout);
		int co = p[pi];
		pi++;
		if(pi == n) pi = 0;
		if(co == 0 && r != -2){
			r = -r;
		}
		if(r == -2) exit(0);

		if(r == 1){
			low = mid+1;
		}
		else{
			high = mid-1;
		}
		if(low > high){
			mid = high;
		}
		else mid = (high+low)/2;

	}

}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
	int m, n;
	cin >> m >> n;
	vector<int> p(n);
	for(int i = 0; i < n; i++){
		cout << 0 << "\n";
		fflush(stdout);
		int r;
		cin >> r;
		//fflush(stdout);
		p[i] = 1;
		if( r == -1) p[i] = 0;
		//p[i] = r;
	}
	int high = m;
	int low = 1;
    int mid = (high+low)/2;
	int pi = 0;
	while(true){
		cout << mid << "\n";
		fflush(stdout);
		int r;
		cin >> r;
		//fflush(stdout);
		int co = p[pi];
		pi++;
		if(pi == n) pi = 0;
		if(co == 0 && r != -2){
			r = -r;
		}
		if(r == -2) exit(0);
		if(r == 0){
			cout << mid << "\n";
			exit(0);
			//return 0;
		}
		if(r == 1){
			low = mid+1;
		}
		else{
			high = mid-1;
		}
		mid = (high+low)/2;

	}

}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
	int m, n;
	cin >> m >> n;
	vector<int> p(n);
	for(int i = 0; i < n; i++){
		cout << 0 << "\n";
		fflush(stdout);
		int r;
		cin >> r;
		//fflush(stdout);
		p[i] = r;
	}
	int high = m;
	int low = 1;
    int mid = (high+low)/2;
	int pi = 0;
	while(true){
		cout << mid << "\n";
		fflush(stdout);
		int r;
		cin >> r;
		//fflush(stdout);
		int co = p[pi];
		pi++;
		if(pi == n) pi = 0;
		if(co == 0){
			r = -r;
		}
		if(r == 0){
			cout << mid << "\n";
			exit(0);
			//return 0;
		}
		if(r == 1){
			low = mid+1;
		}
		else{
			high = mid-1;
		}
		mid = (high+low)/2;

	}

}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
	int m, n;
	cin >> m >> n;
	vector<int> p(n);
	for(int i = 0; i < n; i++){
		cout << 0;
		fflush(stdout);
		int r;
		cin >> r;
		p[i] = r;
	}
	int high = m;
	int low = 1;
    int mid = (high+low)/2;
	int pi = 0;
	int nq = 0;
	while(true){
		cout << mid;
		fflush(stdout);
		int r;
		cin >> r;
		int co = p[pi];
		pi++;
		if(pi == n) pi = 0;
		if(co == 0){
			r = -r;
		}
		if(r == 0){
			cout << mid << "\n";
			fflush(stdout);
			exit(0);
			//return 0;
		}
		if(r == 1){
			low = mid;
		}
		else{
			high = mid;
		}
		mid = (high+low)/2;

	}

}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
	int m, n;
	cin >> m >> n;
	vector<int> p(n);
	for(int i = 0; i < n; i++){
		cout << 0;
		fflush(stdout);
		int r;
		cin >> r;
		p[i] = r;
	}
	int high = m;
	int low = 1;
    int mid = (high+low)/2;
	int pi = 0;
	while(true){
		cout << mid;
		fflush(stdout);
		int r;
		cin >> r;
		int co = p[pi];
		pi++;
		if(pi == n) pi = 0;
		if(co == 0){
			r = -r;
		}
		if(r == 0){
			cout << mid << "\n";
			exit(0);
			//return 0;
		}
		if(r == 1){
			low = mid;
		}
		else{
			high = mid;
		}
		mid = (high+low)/2;

	}

}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
	int m, n;
	cin >> m >> n;
	vector<int> p(n);
	for(int i = 0; i < n; i++){
		cout << 0;
		fflush(stdout);
		int r;
		cin >> r;
		fflush(stdout);
		p[i] = r;
	}
	int high = m;
	int low = 1;
    int mid = (high+low)/2;
	int pi = 0;
	while(true){
		cout << mid;
		fflush(stdout);
		int r;
		cin >> r;
		fflush(stdout);
		int co = p[pi];
		pi++;
		if(pi == n) pi = 0;
		if(co == 0){
			r = -r;
		}
		if(r == 0){
			cout << mid << "\n";
			exit(0);
			//return 0;
		}
		if(r == 1){
			low = mid;
		}
		else{
			high = mid;
		}
		mid = (high+low)/2;

	}

}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	if(got == 0) exit(0);
	assert(got == -1 || got == 1);
	return got;
}

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);

	vector<bool> v(n);
	for(int i = 0; i < n; i++)
		v[i] = (query(m) == -1);

	int l = 0, r = m, mid, idx = 0, total = n;
	while(l < r)
	{
		mid = (l + r) / 2;
		if(query(mid) == -1)
			r = mid;
		else
			l = mid;

		if(v[idx] == false)
			swap(l, r);

		idx = (idx + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1)
		query(l);
	else
		query(r);
	assert(false);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

vector<bool> v;

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	return got;
}

int main()
{
	int m, n;
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++)
		v.push_back(query(m+1) == -1);

	int l = 0, r = 1000000000, cnt = 0;
	while(l + 1 < r)
	{
		int mid = (l + r) / 2;
		int q = query(mid);
		if(q == 0) exit(0);
		if(v[cnt] == true)//bot fala verdade
		{
			if(q == -1)
				r = mid;
			else
				l = mid;
		}
		else
		{
			if(q == -1)
				l = mid;
			else
				r = mid;
		}
		cnt++;
	}
	if(query(l+1) == 0) exit(0);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

vector<bool> v;

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	assert(got == -1 || got == 0 || got == 1);
	return got;
}

//1010

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);
	int total = n;
	for(int i = 0; i < n; i++)
		v.push_back(query(2000000000) == -1);

	int l = 0, r = 1000000000, cnt = 0, mid;
	while(l + 1 < r)
	{
		mid = (l + r) / 2;
		int q = query(mid);
		if(q == 0) exit(0);
		if(v[cnt] == true)//bot fala verdade
		{
			if(q == -1)
				r = mid;
			else
				l = mid;
		}
		else
		{
			if(q == -1)
				l = mid;
			else
				r = mid;
		}
		cnt = (cnt + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1 && query(l) == 0) exit(0);
	else if(query(r) == 0) exit(0);
	int porra = -1;
	assert(porra == 0);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

vector<bool> v;

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	assert(got == -1 || got == 0 || got == 1);
	return got;
}

//1010

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);
	for(int i = 0; i < n; i++)
		v.push_back(query(2000000000) == -1);

	int l = 0, r = 1000000000, cnt = 0;
	while(l + 1 < r)
	{
		int mid = (l + r) / 2;
		int q = query(mid);
		if(q == 0) exit(0);
		if(v[cnt] == true)//bot fala verdade
		{
			if(q == -1)
				r = mid;
			else
				l = mid;
		}
		else
		{
			if(q == -1)
				l = mid;
			else
				r = mid;
		}
		cnt = (cnt + 1) % n;
	}
	if(query(l) == 0) exit(0);
	if(query(l+1) == 0) exit(0);
	int porra = -1;
	assert(porra == 0);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

vector<bool> v;

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	if(got == 0) exit(0);
	assert(got == -1 || got == 1);
	return got;
}

//1010

int main()
{
	int m, n;
	scanf("%d%d", &n, &m);
	int total = n;
	for(int i = 0; i < n; i++)
		v.push_back(query(m+1) == -1);

	int l = 0, r = 1000000000, cnt = 0, mid;
	while(l + 1 < r)
	{
		mid = (l + r) / 2;
		int q = query(mid);
		if(v[cnt] == true)//bot fala verdade
		{
			if(q == -1)
				r = mid;
			else
				l = mid;
		}
		else
		{
			if(q == -1)
				l = mid;
			else
				r = mid;
		}
		cnt = (cnt + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1 && query(l) == 0) exit(0);
	else if(query(r) == 0) exit(0);
	int porra = -1;
	assert(porra == 0);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	if(got == 0) exit(0);
	assert(got == -1 || got == 1);
	return got;
}

int main()
{
	assert(false);
	int m, n;
	scanf("%d%d", &m, &n);

	vector<bool> v(n);
	for(int i = 0; i < n; i++)
		v[i] = (query(m+1) == -1);

	int l = 0, r = m, mid, idx = 0, total = n;
	while(l < r)
	{
		mid = (l + r) / 2;
		if(query(mid) == -1)
			r = mid;
		else
			l = mid;

		if(v[idx] == false)//bot mente
			swap(l, r);

		idx = (idx + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1)
		query(l);
	else
		query(r);
	assert(false);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	if(got == 0) exit(0);
	assert(got == -1 || got == 1);
	return got;
}

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);

	vector<bool> v(n);
	for(int i = 0; i < n; i++)
		v[i] = (query(m+1) == -1);

	int l = 0, r = m, mid, idx = 0, total = n;
	while(l < r)
	{
		mid = (l + r) / 2;
		if(query(mid) == -1)
			r = mid;
		else
			l = mid;

		if(v[idx] == false)//bot mente
			swap(l, r);

		idx = (idx + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1)
		query(l);
	else
		query(r);
	assert(false);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

vector<bool> v;

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	assert(got == -1 || got == 0 || got == 1);
	return got;
}

//1010

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);
	int total = n;
	for(int i = 0; i < n; i++)
		v.push_back(query(2000000000) == -1);

	int l = 0, r = 1000000000, cnt = 0, mid;
	while(l + 1 < r)
	{
		mid = (l + r) / 2;
		int q = query(mid);
		if(q == 0) exit(0);
		if(v[cnt] == true)//bot fala verdade
		{
			if(q == -1)
				r = mid;
			else
				l = mid;
		}
		else
		{
			if(q == -1)
				l = mid;
			else
				r = mid;
		}
		cnt = (cnt + 1) % n;
		total++;
		assert(totatl <= 60);
	}
	if(mid == l + 1 && query(l) == 0) exit(0);
	else if(query(r) == 0) exit(0);
	int porra = -1;
	assert(porra == 0);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	if(got == 0) exit(0);
	assert(got == -1 || got == 1);
	return got;
}

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);

	vector<bool> v(n);
	for(int i = 0; i < n; i++)
		v[i] = (query(m) == -1);

	int l = 1, r = m, mid, idx = 0, total = n;
	while(l < r)
	{
		mid = (l + r) / 2;
		if(query(mid) == -1)
			r = mid;
		else
			l = mid;

		if(v[idx] == false)
			swap(l, r);

		idx = (idx + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1)
		query(l);
	else
		query(r);
	assert(false);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

vector<bool> v;

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	return got;
}

//1010

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);
	for(int i = 0; i < n; i++)
		v.push_back(query(m+1) == -1);

	int l = 0, r = 1000000000, cnt = 0;
	while(l + 1 < r)
	{
		int mid = (l + r) / 2;
		int q = query(mid);
		if(q == 0) exit(0);
		if(v[cnt] == true)//bot fala verdade
		{
			if(q == -1)
				r = mid;
			else
				l = mid;
		}
		else
		{
			if(q == -1)
				l = mid;
			else
				r = mid;
		}
		cnt = (cnt + 1) % n;
	}
	if(query(l+1) == 0) exit(0);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

ll query(ll k)
{
	printf("%lld\n", k);
	fflush(stdout);
	ll got;
	scanf("%I64d", &got);
	if(got == 0) exit(0);
	assert(got == -1 || got == 1);
	return got;
}

int main()
{
	ll m, n;
	scanf("%I64d%I64d", &m, &n);

	vector<bool> v(n);
	for(ll i = 0; i < n; i++)
		v[i] = (query(m+1) == -1);

	ll l = 0, r = m, mid, idx = 0, total = n;
	while(l + 1 < r)
	{
		mid = (l + r) / 2;
		if(query(mid) == -1)
			r = mid;
		else
			l = mid;

		if(v[idx] == false)//bot mente
			swap(l, r);

		idx = (idx + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1)
		query(l);
	else
		query(r);
	assert(false);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

vector<bool> v;

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	assert(got == -1 || got == 0 || got == 1);
	return got;
}

//1010

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);
	for(int i = 0; i < n; i++)
		v.push_back(query(2000000000) == -1);

	int l = 0, r = 1000000000, cnt = 0, mid;
	while(l + 1 < r)
	{
		mid = (l + r) / 2;
		int q = query(mid);
		if(q == 0) exit(0);
		if(v[cnt] == true)//bot fala verdade
		{
			if(q == -1)
				r = mid;
			else
				l = mid;
		}
		else
		{
			if(q == -1)
				l = mid;
			else
				r = mid;
		}
		cnt = (cnt + 1) % n;
	}
	if(mid == l + 1 && query(l) == 0) exit(0);
	else if(query(r) == 0) exit(0);
	int porra = -1;
	assert(porra == 0);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	if(got == 0) exit(0);
	assert(got == -1 || got == 1);
	return got;
}

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);

	vector<bool> v(n);
	for(int i = 0; i < n; i++)
		v[i] = (query(m+1) == -1);

	int l = 0, r = m, mid, idx = 0, total = n;
	while(l + 1 < r)
	{
		mid = (l + r) / 2;
		if(query(mid) == -1)
			r = mid;
		else
			l = mid;

		if(v[idx] == false)//bot mente
			swap(l, r);

		idx = (idx + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1)
		query(l);
	else
		query(r);
	assert(false);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

vector<bool> v;

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	return got;
}

//1010

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);
	for(int i = 0; i < n; i++)
		v.push_back(query(m+1) == -1);

	for(auto i : v)
		debug(i);

	int l = 0, r = 1000000000, cnt = 0;
	while(l + 1 < r)
	{
		int mid = (l + r) / 2;
		int q = query(mid);
		if(q == 0) exit(0);
		if(v[cnt] == true)//bot fala verdade
		{
			if(q == -1)
				r = mid;
			else
				l = mid;
		}
		else
		{
			if(q == -1)
				l = mid;
			else
				r = mid;
		}
		cnt++;
	}
	if(query(l+1) == 0) exit(0);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

vector<bool> v;

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	assert(got == -1 || got == 0 || got == 1);
	return got;
}

//1010

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);
	for(int i = 0; i < n; i++)
		v.push_back(query(2000000000) == -1);

	int l = 0, r = 1000000000, cnt = 0;
	while(l + 1 < r)
	{
		int mid = (l + r) / 2;
		int q = query(mid);
		if(q == 0) exit(0);
		if(v[cnt] == true)//bot fala verdade
		{
			if(q == -1)
				r = mid;
			else
				l = mid;
		}
		else
		{
			if(q == -1)
				l = mid;
			else
				r = mid;
		}
		cnt = (cnt + 1) % n;
	}
	if(query(l+1) == 0) exit(0);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	if(got == 0) exit(0);
	assert(got == -1 || got == 1);
	return got;
}

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);

	vector<bool> v(n);
	for(int i = 0; i < n; i++)
		v[i] = (query(m) == -1);

	int l = 1, r = m, mid, idx = 0, total = n;
	while(l < r)
	{
		mid = (l + r) / 2;
		int q = query(mid);
		if(v[idx] == true)
		{
			if(q == -1)
				r = mid-1;
			else
				l = mid+1;
		}
		else
		{
			if(q == -1)
				l = mid+1;
			else
				r = mid-1;

		}
		idx = (idx + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1)
		query(l);
	else
		query(r);
	assert(false);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

ll query(ll k)
{
	prllf("%d\n", k);
	fflush(stdout);
	ll got;
	scanf("%d", &got);
	if(got == 0) exit(0);
	assert(got == -1 || got == 1);
	return got;
}

int main()
{
	ll m, n;
	scanf("%d%d", &m, &n);

	vector<bool> v(n);
	for(ll i = 0; i < n; i++)
		v[i] = (query(m+1) == -1);

	ll l = 0, r = m, mid, idx = 0, total = n;
	while(l + 1 < r)
	{
		mid = (l + r) / 2;
		if(query(mid) == -1)
			r = mid;
		else
			l = mid;

		if(v[idx] == false)//bot mente
			swap(l, r);

		idx = (idx + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1)
		query(l);
	else
		query(r);
	assert(false);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define debug(x) cerr << fixed << #x << " = " << x << endl;
#define ll long long

int query(int k)
{
	printf("%d\n", k);
	fflush(stdout);
	int got;
	scanf("%d", &got);
	if(got == 0) exit(0);
	assert(got == -1 || got == 1);
	return got;
}

int main()
{
	int m, n;
	scanf("%d%d", &m, &n);

	vector<bool> v;
	for(int i = 0; i < n; i++)
		v.push_back(query(m+1) == -1);

	int l = 0, r = m, mid, idx = 0, total = n;
	while(l + 1 < r)
	{
		mid = (l + r) / 2;
		if(query(mid) == -1)
			r = mid;
		else
			l = mid;

		if(v[idx] == true)//bot mente
			swap(l, r);

		idx = (idx + 1) % n;
		total++;
		assert(total <= 60);
	}
	if(mid == l + 1)
		query(l);
	else
		query(r);
	assert(false);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n;
    cin>>m>>n;
    int ok=true;
    vector<int>v;
    int l=1;
    int r=m;
    int mid;
    for(int i=0; i<30; i++)
    {
        mid=(l+r)/2.0;
        mid = (l + r + 1) / 2;
        printf("%d\n", mid);
        fflush(stdout);
        char response[5];
        scanf("%s", response);
        if (strcmp(response, "-1") == 0)
            r = mid - 1;
        else if(strcmp(response, "1") == 0)
            l = mid;
        else
        {
            return 0;
        }
    }
    l=1;
    r=m;
    for(int i=0; i<30; i++)
    {
        mid=(l+r)/2.0;
        mid = (l + r + 1) / 2;
        printf("%d\n", mid);
        fflush(stdout);
        char response[5];
        scanf("%s", response);
        if (strcmp(response, "1") == 0)
            r = mid - 1;
        else if(strcmp(response, "-1") == 0)
            l = mid;
        else
        {
            return 0;
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n;
    cin>>m>>n;
    int ok=true;
    vector<int>v;
    int l=1;
    int r=m;
    int mid;
    for(int i=0; i<n; i++)
    {
        mid=1;
        printf("%d\n", mid);
        fflush(stdout);
        char response[5];
        scanf("%s", response);
        if (strcmp(response, "1") == 0)
            {
                v.push_back(1);
            }
        else if(strcmp(response, "-1") == 0)
            {
                v.push_back(0);

            }
        else
        {
            return 0;
        }
    }
    l=1;
    r=m;
    int i=0;
    while(l<=r)
    {
       // mid=(l+r)/2.0;
        mid = (l + r + 1) / 2;
        printf("%d\n", mid);
        fflush(stdout);
        char response[5];
        scanf("%s", response);
        if (strcmp(response, "-1") == 0)
           { //r = mid - 1;
               if(v[i]==0){
                   l=mid+1;
               }
               else r=mid-1;

           }
        else if(strcmp(response, "1") == 0)
           { if(v[i]==0)
                r=mid-1;
           else l = mid+1;}
        else
        {
            return 0;
        }
        i++;
        if(i==n) i=0;
    }

}