#include <bits/stdc++.h>
using namespace std;
long n;
long a[100005];
vector<long> g[100005];
vector<long> red, blue;
map<long, long> hasht;
int dfs(long u) {
  if (g[u].size() == 0) {
    blue.push_back(u);
    return 0;
  }
  long i;
  int flag;
  for (i = 0; i < g[u].size(); i++) {
    long v = g[u][i];
    flag = dfs(v);
  }
  if (flag == 1)
    blue.push_back(u);
  else
    red.push_back(u);
  return 1 - flag;
}
int main() {
  cin >> n;
  long i, p;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 2; i <= n; i++) {
    cin >> p;
    g[p].push_back(i);
  }
  dfs(1);
  long s1 = blue.size(), s2 = red.size();
  long x = 0;
  for (i = 0; i < s1; i++) {
    x = x ^ a[blue[i]];
  }
  for (i = 0; i < s2; i++) {
    hasht[a[red[i]]]++;
  }
  long long ans = 0;
  if (x == 0) {
    ans += ((long long)(s1) * (s1 - 1)) / 2;
    ans += ((long long)(s2) * (s2 - 1)) / 2;
    for (i = 0; i < s1; i++) {
      ans += hasht[a[blue[i]]];
    }
  } else {
    for (i = 0; i < s1; i++) {
      ans += hasht[x ^ a[blue[i]]];
    }
  }
  cout << ans << endl;
  return 0;
}
