#include <bits/stdc++.h>
using namespace std;
int N, A, B, C, D;
int P[5050];
int PD[4];
bitset<5050> BS[4], LE;
int num[5050];
vector<int> E[5050];
vector<int> L;
int dfs(int cur) {
  if (E[cur].empty()) {
    num[cur] = 1;
  } else {
    for (auto& e : E[cur]) num[cur] += dfs(e);
  }
  return num[cur];
}
int hoge(bitset<5050> A, bitset<5050> B, int NA, int S, vector<int> cand) {
  int T = num[0];
  if (T % 2) return 0;
  B <<= NA + S;
  for (auto& r : cand) B |= B << r;
  int i;
  for (i = 0; i < (5050); i++)
    if (i + T / 2 < 5050 && A[i] && B[i + T / 2]) return 1;
  return 0;
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N >> A >> B >> C >> D;
  A--, B--, C--, D--;
  for (i = 0; i < (N - 1); i++) {
    cin >> x;
    P[i + 1] = x - 1;
    E[x - 1].push_back(i + 1);
  }
  dfs(0);
  PD[0] = A;
  PD[1] = B;
  PD[2] = C;
  PD[3] = D;
  for (i = 0; i < (4); i++) {
    BS[i][0] = 1;
    while (P[PD[i]] != 0) {
      x = P[PD[i]];
      for (auto& e : E[x])
        if (x != PD[i]) {
          y = num[e];
          BS[i] |= BS[i] << y;
        }
      PD[i] = P[PD[i]];
    }
  }
  vector<int> cand;
  for (auto& e : E[0]) {
    for (i = 0; i < (4); i++)
      if (e == PD[i]) break;
    if (i == 4) cand.push_back(num[e]);
  }
  if (hoge(BS[0], BS[1], num[PD[0]], num[PD[2]], cand) &&
      hoge(BS[2], BS[3], num[PD[2]], num[PD[1]], cand))
    return (void)printf("YES\n");
  if (hoge(BS[0], BS[1], num[PD[0]], num[PD[3]], cand) &&
      hoge(BS[2], BS[3], num[PD[2]], num[PD[1]], cand))
    return (void)printf("YES\n");
  (void)printf("NO\n");
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
