#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n;
vector<int> edges[MAXN];
long long val[MAXN];
int dep[MAXN];
long long xov[2];
int leaf;
long long cnt[2];
map<long long, long long> cc[2];
void dfs(int x) {
  xov[dep[x]] ^= val[x];
  cnt[dep[x]]++;
  cc[dep[x]][val[x]]++;
  for (auto nex : edges[x]) {
    dep[nex] = dep[x] ^ 1;
    dfs(nex);
  }
  if ((int)edges[x].size() == 0) {
    leaf = dep[x];
  }
}
long long ans = 0;
void calc(int x) {
  if (dep[x] != leaf) {
    ans += cc[leaf][xov[leaf] ^ val[x]];
  }
  for (auto nex : edges[x]) {
    calc(nex);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> val[i];
  }
  for (int i = 2, x; i <= n; i++) {
    scanf("%d", &x);
    edges[x].push_back(i);
  }
  dep[1] = 1;
  dfs(1);
  calc(1);
  if (xov[leaf] == 0) {
    ans += cnt[leaf] * (cnt[leaf] - 1ll) / 2ll;
    ans += cnt[leaf ^ 1] * (cnt[leaf ^ 1] - 1ll) / 2ll;
  }
  cout << ans << endl;
  return 0;
}
