#include <bits/stdc++.h>
using namespace std;
template <class T>
using vv = vector<vector<T>>;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "{";
  for (int(i) = 0; (i) < (t.size()); ++(i)) {
    os << t[i] << ",";
  }
  os << "}" << endl;
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
vector<string> s_p_l_i_t(const string &s, char c) {
  vector<string> v;
  int d = 0, f = 0;
  string t;
  for (char c : s) {
    if (!d && c == ',')
      v.push_back(t), t = "";
    else
      t += c;
    if (c == '\"' || c == '\'') f ^= 1;
    if (!f && c == '(') ++d;
    if (!f && c == ')') --d;
  }
  v.push_back(t);
  return move(v);
}
void e_r_r(vector<string>::iterator it) {}
template <typename T, typename... Args>
void e_r_r(vector<string>::iterator it, T a, Args... args) {
  if (*it == " 1" || *it == "1")
    cerr << endl;
  else
    cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << ", ";
  e_r_r(++it, args...);
}
const long long MOD = 1e9 + 7;
vector<int> vs[2];
vector<int> a;
bool dfs(vv<int> &g, int v) {
  if (g[v].size() == 0) {
    vs[0].push_back(a[v]);
    return 1;
  }
  int f;
  for (int w : g[v]) f = dfs(g, w);
  vs[f].push_back(a[v]);
  return 1 - f;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(0);
  int n;
  cin >> n;
  a.resize(n);
  for (int(i) = 0; (i) < (n); ++(i)) cin >> a[i];
  vv<int> g(n);
  for (int(i) = 0; (i) < (n - 1); ++(i)) {
    int x;
    cin >> x;
    --x;
    g[x].push_back(i + 1);
  }
  dfs(g, 0);
  int sum = 0;
  for (int x : vs[0]) sum ^= x;
  long long re = 0;
  if (!sum) {
    for (int(i) = 0; (i) < (2); ++(i))
      re += vs[i].size() * (vs[i].size() - 1ll) / 2;
  }
  map<int, int> cnt;
  for (int x : vs[1]) ++cnt[x];
  for (int x : vs[0]) re += cnt[sum ^ x];
  cout << re << endl;
  return 0;
}
