#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 1e7 + 5;
vector<int> g[N];
int a[N];
bool last = 0;
int xr[2];
long long cnt[M][2], levels[2];
void dfs(int node, bool lvl) {
  last = lvl;
  levels[lvl]++;
  cnt[a[node]][lvl]++;
  xr[lvl] ^= a[node];
  for (auto u : g[node]) dfs(u, lvl ^ 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i + 1];
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    g[p].push_back(i);
  }
  dfs(1, 0);
  long long ans = 0;
  if (xr[last] == 0) {
    ans = (levels[0] * (levels[0] - 1)) >> 1;
    ans += (levels[1] * (levels[1] - 1)) >> 1;
    for (int i = 0; i < M; i++) ans += cnt[i][0] * cnt[i][1];
  } else {
    for (int i = 1; i < M; i++)
      if ((xr[last] ^ i) < M) ans += cnt[i][last] * cnt[xr[last] ^ i][last ^ 1];
  }
  cout << ans << endl;
  return 0;
}
