#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010, mod = 1e9 + 7;
const long long inf = 1e18;
vector<int> v[maxn], va, vb, vc, vd, vv;
int pr[maxn];
bitset<maxn> bs;
void fnd(int a, int &A) {
  while (a != 1) {
    A = a;
    a = pr[a];
  }
}
int dfs(int u) {
  int ans = (int((v[u]).size()) == 0);
  for (int y : v[u]) {
    ans += dfs(y);
  }
  return ans;
}
void go(int a, vector<int> &vv) {
  int bf = -1;
  while (a != 1) {
    for (int y : v[a]) {
      if (y != bf) vv.push_back(dfs(y));
    }
    bf = a;
    a = pr[a];
  }
}
void Do(vector<int> &vv) {
  for (int x : vv) bs = bs | (bs << x);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a, b, c, d, A, B, C, D;
  cin >> a >> b >> c >> d;
  for (int i = 2; i <= n; i++) {
    cin >> pr[i];
    v[pr[i]].push_back(i);
  }
  fnd(a, A), fnd(b, B), fnd(c, C), fnd(d, D);
  go(a, va), go(b, vb), go(c, vc), go(d, vd);
  int Tot = dfs(1);
  if (Tot & 1) return cout << "NO\n", 0;
  for (int y : v[1]) {
    if (y != A && y != B && y != C && y != D) {
      vv.push_back(dfs(y));
    }
  }
  bs = 0;
  bs[0] = 1;
  Do(vv), Do(va), Do(vb);
  int num = (Tot / 2) - 1 - dfs(C);
  if (num < 0 || bs[num] == 0) return cout << "NO\n", 0;
  bs = 0;
  bs[0] = 1;
  Do(vv), Do(vc), Do(vd);
  num = (Tot / 2) - 1 - dfs(B);
  if (num < 0 || bs[num] == 0) return cout << "NO\n", 0;
  return cout << "YES\n", 0;
}
