#include <bits/stdc++.h>
using namespace std;
const int MAX = 100100, NMAX = 10010000;
int n;
long long a[MAX], S;
vector<int> adj[MAX];
long long cnt[2][NMAX];
int LVL;
void dfs(int u, int lvl) {
  LVL = max(LVL, lvl);
  cnt[lvl % 2][a[u]]++;
  for (__typeof((adj[u]).begin()) v = (adj[u]).begin(); v != (adj[u]).end();
       v++)
    dfs(*v, lvl + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < int(n); i++) scanf("%lld", a + i);
  for (int i = 0; i < int(n - 1); i++) {
    int p;
    scanf("%d", &p);
    adj[p - 1].push_back(i + 1);
  }
  dfs(0, 0);
  int id = LVL % 2;
  for (int i = 0; i < int(NMAX); i++)
    S ^= (cnt[id][i] % 2 == 0 ? 0ll : (long long)i);
  long long ans = 0;
  if (S == 0ll) {
    long long cp = 0, ci = 0;
    for (int i = 0; i < int(NMAX); i++) cp += cnt[id][i];
    for (int i = 0; i < int(NMAX); i++) ci += cnt[(id + 1) % 2][i];
    ans = (cp * (cp - 1ll) / 2ll + ci * (ci - 1ll) / 2ll);
    for (int i = 0; i < int(NMAX); i++) ans += cnt[0][i] * cnt[1][i];
  } else {
    for (int i = 0; i < int(NMAX); i++) {
      long long inv = S ^ ((long long)i);
      if (inv >= NMAX)
        ;
      else
        ans += cnt[0][i] * cnt[1][inv];
    }
  }
  printf("%lld\n", ans);
}
