#include <bits/stdc++.h>
using namespace std;
int dad[5010];
vector<int> fils[5010];
int a, b, c, d;
int comp[4];
int found;
int dp(int x) {
  if (x == a || x == b || x == c || x == d) found = x;
  int ans = 0;
  for (int i = 0; i < fils[x].size(); i++) {
    ans += dp(fils[x][i]);
  }
  if (fils[x].size() == 0) ans++;
  return ans;
}
vector<int> others;
int main() {
  int n;
  scanf("%d", &n);
  scanf("%d %d %d %d", &a, &b, &c, &d);
  for (int i = int(2); i <= int(n); i++) {
    scanf("%d", &dad[i]);
    fils[dad[i]].push_back(i);
  }
  int tot = 0;
  for (int i = 0; i < fils[1].size(); i++) {
    int f = fils[1][i];
    found = -1;
    int p = dp(f);
    if (found == -1)
      others.push_back(p);
    else if (found == a)
      comp[0] = p;
    else if (found == b)
      comp[1] = p;
    else if (found == c)
      comp[2] = p;
    else if (found == d)
      comp[3] = p;
    tot += p;
  }
  bool ok = true;
  if (tot % 2 == 1)
    ok = false;
  else {
    int obj = tot / 2 - 1;
    bool cando[3000];
    for (int i = int(0); i <= int(obj); i++) cando[i] = false;
    cando[0] = true;
    for (int j = 0; j < others.size(); j++) {
      for (int i = obj - others[j]; i >= 0; i--) {
        if (cando[i]) cando[i + others[j]] = true;
      }
    }
    int maxi = obj - comp[1];
    int mini = obj - comp[1] - (comp[0] - 1) - (comp[2] - 1);
    mini = max(mini, 0);
    if (maxi < 0)
      ok = false;
    else {
      bool whynot = false;
      for (int i = int(mini); i <= int(maxi); i++) {
        if (cando[i]) whynot = true;
      }
      if (!whynot) ok = false;
    }
    maxi = obj - comp[2];
    mini = obj - comp[2] - (comp[1] - 1) - (comp[3] - 1);
    mini = max(mini, 0);
    if (maxi < 0)
      ok = false;
    else {
      bool whynot = false;
      for (int i = int(mini); i <= int(maxi); i++) {
        if (cando[i]) whynot = true;
      }
      if (!whynot) ok = false;
    }
  }
  if (ok)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
