#include <bits/stdc++.h>
const long long INF = 2000000005;
const long long BIG_INF = 2000000000000000005;
const long long mod = 1000000007;
const long long P = 31;
const long double PI = 3.141592653589793238462643;
const double eps = 1e-9;
using namespace std;
vector<pair<long long, long long> > dir = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
bool valid(long long x, long long y, long long n, long long m) {
  return x >= 0 && y >= 0 && x < n && y < m;
}
mt19937 rng(1999999973);
const long long N = 100000 + 50;
long long a[N], n, ans = 0, allXor = 0, colGood = 0, leafOddity = 0;
vector<long long> g[N];
unordered_map<long long, long long> odd;
void dfs(long long v, long long h) {
  for (long long i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    dfs(to, h ^ 1);
  }
  if (g[v].size() == 0) leafOddity = h;
  if (h != leafOddity) {
    odd[a[v]]++;
  } else {
    allXor ^= a[v];
    colGood++;
  }
}
void dfs2(long long v, long long h) {
  for (long long i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    dfs2(to, h ^ 1);
  }
  if (h == leafOddity) ans += odd[allXor ^ a[v]];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i < n; i++) {
    long long p;
    cin >> p;
    p--;
    g[p].push_back(i);
  }
  dfs(0, 0);
  dfs2(0, 0);
  if (allXor == 0) {
    ans += (colGood * (colGood - 1)) / (long long)2 +
           ((n - colGood) * ((n - colGood) - 1)) / (long long)2;
  }
  cout << ans;
  return 0;
}
