#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int n;
std::vector<int> par;
std::vector<std::vector<int> > ch;
std::vector<int> lev;
void dfs(int v) {
  for (auto u : ch[v]) {
    lev[u] = lev[v] + 1;
    dfs(u);
  }
}
int main() {
  scanf("%d", &n);
  std::vector<int> a(n);
  ch.resize(n);
  par.resize(n);
  lev.resize(n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) scanf("%d", &par[i]);
  for (int i = 1; i < n; i++) par[i]--;
  for (int i = 1; i < n; i++) ch[par[i]].push_back(i);
  lev[0] = 0;
  dfs(0);
  int lst = 0;
  for (int i = 0; i < n; i++)
    if (ch[i].empty()) lst = i;
  std::vector<int> nim;
  std::vector<int> oth;
  map<int, long long> cnt;
  for (int i = 0; i < n; i++) {
    if (lev[i] % 2 == lev[lst] % 2)
      nim.push_back(a[i]);
    else
      oth.push_back(a[i]);
  }
  for (auto x : oth) cnt[x]++;
  int state = 0;
  for (auto x : nim) state ^= x;
  long long ans = 0;
  for (auto x : nim) ans += cnt[x ^ state];
  if (state == 0) {
    long long k = nim.size();
    long long l = oth.size();
    ans += (k * (k - 1) + l * (l - 1)) / 2;
  }
  cout << ans;
}
