#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3 + 3;
int N;
vector<int> G[MAXN];
int sp[5], spInv[MAXN], spIn[MAXN];
int sz[MAXN];
void dfs(int v) {
  if (spInv[v] != -1) {
    spIn[v] = spInv[v];
  }
  for (int i = (int)0; i < (int)G[v].size(); i++) {
    int u = G[v][i];
    dfs(u);
    sz[v] += sz[u];
    if (spIn[u] != -1) spIn[v] = spIn[u];
  }
  if (G[v].size() == 0) sz[v]++;
}
vector<int> a;
bool dp[MAXN][MAXN];
int M;
void f(int p, int have) {
  if (dp[p][have] != 0) return;
  dp[p][have] = 1;
  if (p == M) return;
  f(p + 1, have);
  f(p + 1, have + a[p]);
}
void subs(int v) {
  if (spIn[v] == -1) {
    a.push_back(sz[v]);
  } else {
    for (int i = (int)0; i < (int)G[v].size(); i++) {
      int u = G[v][i];
      subs(u);
    }
  }
}
int main() {
  scanf("%d", &N);
  memset(spInv, -1, sizeof(spInv));
  memset(spIn, -1, sizeof(spIn));
  memset(sp, -1, sizeof(sp));
  for (int i = (int)0; i < (int)4; i++) {
    scanf("%d", &sp[i]);
    sp[i]--;
    spInv[sp[i]] = i;
  }
  bool good = true;
  for (int u = (int)1; u < (int)N; u++) {
    int v;
    scanf("%d", &v);
    v--;
    G[v].push_back(u);
  }
  for (int i = (int)0; i < (int)G[0].size(); i++) {
    int u = G[0][i];
    dfs(u);
    sz[0] += sz[u];
  }
  if (sz[0] & 1) good = false;
  for (int i = (int)0; i < (int)G[0].size(); i++) {
    int u = G[0][i], w = spIn[u];
    if (w == -1) {
      a.push_back(sz[u]);
    } else {
      if (w == 0 || w == 1) {
        subs(u);
      } else if (w == 2) {
        a.push_back(sz[u]);
      }
    }
  }
  memset(dp, false, sizeof(dp));
  M = a.size();
  f(0, 0);
  if (dp[M][sz[0] / 2 - 1] != 1) good = false;
  a.clear();
  for (int i = (int)0; i < (int)G[0].size(); i++) {
    int u = G[0][i], w = spIn[u];
    if (w == -1) {
      a.push_back(sz[u]);
    } else {
      if (w == 2 || w == 3) {
        subs(u);
      } else if (w == 1) {
        a.push_back(sz[u]);
      }
    }
  }
  memset(dp, false, sizeof(dp));
  M = a.size();
  f(0, 0);
  if (dp[M][sz[0] / 2 - 1] != 1) good = false;
  if (!good)
    printf("NO\n");
  else
    printf("YES\n");
}
