#include <bits/stdc++.h>
using namespace std;
int a[100003], tb = 0;
bool used[100003];
vector<int> v[100003];
map<int, int> red, blue;
long long xorsum = 0, ans, rd;
bool dfs(int root) {
  used[root] = 1;
  if (v[root].size() == 1 and used[v[root][0]]) {
    xorsum ^= a[root];
    blue[a[root]]++;
    tb++;
    return 1;
  }
  bool col;
  for (auto u : v[root]) {
    if (used[u] == 0) col = dfs(u);
  }
  if (!col)
    xorsum ^= a[root], blue[a[root]]++, tb++;
  else
    red[a[root]]++;
  return (col ^ 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 2; i <= n; i++) {
    int l;
    cin >> l;
    v[i].push_back(l);
    v[l].push_back(i);
  }
  bool ca = dfs(1);
  if (xorsum != 0) {
    for (auto u : blue) {
      if (red[xorsum ^ u.first] > 0)
        ans +=
            (long long)((long long)red[xorsum ^ u.first] * (long long)u.second);
    }
    cout << ans;
    return 0;
  }
  ans += ((long long)(tb) * (long long)(tb - 1)) / (long long)2;
  rd = n - tb;
  ans += ((rd) * (rd - 1)) / (long long)2;
  for (auto u : blue) {
    ans += ((long long)red[u.first] * (long long)u.second);
  }
  cout << ans;
}
