#include <bits/stdc++.h>
using namespace std;
using lld = int64_t;
static constexpr int N = 100000 + 5;
vector<int> G[N];
int a[N];
bool clr[N];
unordered_map<int, int> cnt;
void dfs(int);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 2; i <= n; ++i) {
    int p;
    cin >> p;
    G[p].push_back(i);
  }
  dfs(1);
  bool leaf = true;
  for (int i = 1; i <= n; ++i)
    if (G[i].empty()) leaf = clr[i];
  int xr = 0;
  for (int i = 1; i <= n; ++i)
    if (clr[i] == leaf) xr ^= a[i];
  lld ans = 0;
  if (xr == 0) {
    lld tot = 0;
    for (int i = 1; i <= n; ++i) tot += (clr[i] == leaf);
    ans += tot * (tot - 1) / 2;
    ans += (n - tot) * (n - tot - 1) / 2;
  }
  for (int i = 1; i <= n; ++i)
    if (clr[i] == leaf) cnt[a[i]]++;
  for (int i = 1; i <= n; ++i)
    if (clr[i] ^ leaf) ans += cnt[a[i] ^ xr];
  cout << ans << '\n';
  return 0;
}
void dfs(int u) {
  for (int v : G[u]) {
    clr[v] = clr[u] ^ 1;
    dfs(v);
  }
}
