#include <bits/stdc++.h>
using namespace std;
bool ng[5002];
int a;
int b;
int c;
int d;
int child[5002];
vector<int> v[5002];
int pr[5002];
int ppr[5002];
inline void dfs(int b, int p = 0) {
  child[b] = 0;
  if (p == 0) {
    p = b;
  }
  pr[b] = p;
  for (int i = 0; i < v[b].size(); i++) {
    dfs(v[b][i], p);
    child[b] += child[v[b][i]];
  }
  if (v[b].size() == 0) {
    child[b]++;
  }
}
bitset<5002> can(int node) {
  bitset<5002> r;
  r.reset();
  r.set(1, 1);
  int P = node;
  node = ppr[node];
  while (node) {
    for (int i = 0; i < v[node].size(); i++) {
      if (v[node][i] == P) continue;
      r |= (r << child[v[node][i]]);
    }
    P = node;
    node = ppr[node];
  }
  return r;
}
bool ok(int want1, int want2, int ng1, int ng2, int ww1, int ww2) {
  bitset<5002> dp;
  dp.reset();
  dp.set(child[ng1], 1);
  dp.set(child[ng2], 1);
  dp.set(0, 1);
  for (int i = 0; i < v[0].size(); i++) {
    int go = v[0][i];
    if (go == want1 || go == want2 || go == ng1 || go == ng2) {
      continue;
    }
    dp |= (dp << child[go]);
  }
  bitset<5002> w = can(ww1);
  bitset<5002> nex;
  nex.reset();
  for (int i = 0; i < 5002; i++) {
    if (w.test(i)) {
      nex |= (dp << i);
    }
  }
  w = can(ww2);
  dp = nex;
  nex.reset();
  for (int i = 0; i < 5002; i++) {
    if (w.test(i)) {
      nex |= (dp << i);
    }
  }
  return nex.test(((child[0] - 2) / 2) + 2);
}
int main() {
  int n;
  cin >> n;
  cin >> a >> b >> c >> d;
  a--, b--, c--, d--;
  for (int i = 1; i < n; i++) {
    int p;
    scanf("%d", &p);
    p--;
    v[p].push_back(i);
    ppr[i] = p;
  }
  dfs(0);
  int AA = a;
  int BB = b;
  int CC = c;
  int DD = d;
  a = pr[a];
  b = pr[b];
  c = pr[c];
  d = pr[d];
  if ((child[0] - 2) % 2) {
    puts("NO");
    return 0;
  }
  if (ok(a, b, c, d, AA, BB) && ok(c, d, a, b, CC, DD)) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}
