#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 400001;
const long long INF = (1LL << 60);
const long long MOD = 9001;
const long long BLOCK = 447;
vector<int> v[100001];
int dep[100001];
int a[100001];
int bun;
void DFS(int node, int lvl) {
  dep[node] = lvl % 2;
  if (v[node].size() == 0) bun = dep[node];
  for (auto x : v[node]) {
    DFS(x, lvl + 1);
  }
}
map<int, int> mp;
long long cnt;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 2; i <= n; i++) {
    int x;
    cin >> x;
    v[x].push_back(i);
  }
  DFS(1, 0);
  int xxor = 0;
  for (i = 1; i <= n; i++) {
    if (dep[i] == bun)
      cnt++, xxor ^= a[i];
    else
      mp[a[i]]++;
  }
  long long sum = 0;
  for (i = 1; i <= n; i++) {
    if (dep[i] == bun) {
      xxor ^= a[i];
      sum += 1LL * mp[xxor];
      xxor ^= a[i];
    }
  }
  n -= cnt;
  if (xxor == 0) {
    sum += cnt * (cnt - 1) / 2;
    sum += n * (n - 1) / 2;
  }
  cout << sum;
  return 0;
}
