#include <bits/stdc++.h>
using namespace std;
const long long maxN = 100010;
long long N;
set<long long> blue_set;
map<long long, long long> freq_red;
long long A[maxN];
vector<long long> G[maxN];
void input() {
  cin >> N;
  for (long long i = 1; i <= N; i++) cin >> A[i];
  long long tmp;
  for (long long i = 2; i <= N; i++) {
    cin >> tmp;
    G[tmp].push_back(i);
  }
}
void DFS(long long node) {
  long long l = G[node].size();
  if (!l) {
    blue_set.insert(node);
    return;
  }
  for (long long i = 0; i < l; i++) DFS(G[node][i]);
  if (blue_set.find(G[node][0]) == blue_set.end())
    blue_set.insert(node);
  else
    freq_red[A[node]]++;
  return;
}
void solve() {
  DFS(1);
  long long xor_value = 0;
  for (auto node : blue_set) xor_value ^= A[node];
  long long ans = 0;
  if (xor_value == 0) {
    for (auto node : blue_set) ans += freq_red[A[node]];
    long long tot_blue = (long long)blue_set.size();
    long long tot_red = N - tot_blue;
    ans += (tot_red * (tot_red - 1)) / 2;
    ans += (tot_blue * (tot_blue - 1)) / 2;
  } else {
    for (auto node : blue_set) ans += freq_red[xor_value ^ A[node]];
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  input();
  solve();
  return 0;
}
