#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int MAX_VAL = (1 << 24) + 10;
int n, have[2][MAX_VAL], go[2], xo[2];
int arr[MAXN];
vector<int> adj[MAXN];
bool mark[MAXN], color;
void dfs(int v, int par = 0) {
  mark[v] = mark[par] ^ 1;
  if (adj[v].size() == 0) color = mark[v];
  have[mark[v]][arr[v]]++;
  go[mark[v]]++;
  xo[mark[v]] ^= arr[v];
  for (auto i : adj[v]) dfs(i, v);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 2; i <= n; i++) {
    int v;
    cin >> v;
    adj[v].push_back(i);
  }
  dfs(1);
  if (xo[color]) {
    long long answer = 0;
    for (int i = 1; i <= n; i++)
      if (mark[i] == color) answer += have[!color][xo[color] ^ arr[i]];
    cout << answer << endl;
  } else {
    long long answer = 0;
    answer += (long long)go[0] * (go[0] - 1) / 2;
    answer += (long long)go[1] * (go[1] - 1) / 2;
    for (int i = 1; i <= n; i++)
      if (mark[i] == color) answer += have[!color][arr[i]];
    cout << answer << endl;
  }
  return 0;
}
