#include <bits/stdc++.h>
using namespace std;
namespace {
using Sz = unsigned int;
using SzCol = vector<Sz>;
using Val = int;
using ValSet = unordered_set<Val>;
using ConMap = unordered_map<Val, ValSet>;
constexpr Val SZ = 4;
using VertAr = array<Val, SZ>;
void traverse(ValSet &ls, const ConMap &cons, Val cur, Val prev) {
  auto iter = cons.find(cur);
  bool leaf = true;
  if (iter != end(cons)) {
    for (auto v : iter->second) {
      if (v != prev) {
        traverse(ls, cons, v, cur);
        leaf = false;
      }
    }
  }
  if (leaf) ls.insert(cur);
}
vector<ValSet> leafs(const ConMap &cons, Val root) {
  vector<ValSet> res;
  auto iter = cons.find(root);
  if (iter == end(cons)) return res;
  for (const auto v : iter->second) {
    ValSet ls;
    traverse(ls, cons, v, root);
    res.push_back(ls);
  }
  return res;
}
pair<Val, bool> fit(const SzCol &values, Val init, Val target) {
  if (init > target) return make_pair(0, false);
  SzCol reach(target + 1, 0);
  reach[init] = 1;
  for (Sz i = 0; i < values.size(); ++i) {
    const auto v = values[i];
    for (Sz j = 0; j < reach.size(); ++j) {
      if (reach[j] > 0 && reach[j] < i + 2 && j + v < reach.size() &&
          reach[j + v] == 0) {
        reach[j + v] = i + 2;
      }
    }
  }
  for (Sz i = reach.size(); i > 0; --i) {
    if (reach[i - 1] > 0) return make_pair(i - 1, true);
  }
  return make_pair(0, false);
}
bool possible(const ConMap &cons, const VertAr &vs) {
  const auto groups = leafs(cons, 1);
  array<Sz, SZ> indices;
  ValSet seen;
  for (Sz g = 0; g < groups.size(); ++g) {
    const auto &gr = groups[g];
    for (Sz i = 0; i < vs.size(); ++i) {
      const auto v = vs[i];
      auto iter = gr.find(v);
      if (iter != end(gr)) {
        if (!seen.insert(g).second) return false;
        indices[i] = g;
      }
    }
  }
  if (seen.size() != vs.size()) return false;
  SzCol sizes;
  Sz s = 0;
  for (Sz i = 0; i < groups.size(); ++i) {
    if (seen.find(i) == end(seen)) {
      sizes.push_back(groups[i].size());
    }
    s += groups[i].size();
  }
  if (s % 2 != 0) {
    return false;
  }
  const auto m = s / 2 - 1;
  const auto fitRes = fit(sizes, groups[indices[0]].size(), m);
  if (fitRes.second) {
    return s - fitRes.first -
               (groups[indices[2]].size() + groups[indices[3]].size()) <=
           m;
  }
  return false;
}
}  // namespace
int main() {
  Sz n = 0;
  cin >> n;
  VertAr vs;
  cin >> vs[0] >> vs[1] >> vs[2] >> vs[3];
  ConMap cons;
  for (Sz i = 2; i <= n; ++i) {
    Val v = 0;
    cin >> v;
    cons[i].insert(v);
    cons[v].insert(i);
  }
  const auto r = possible(cons, vs);
  cout << (r ? "YES" : "NO") << endl;
  return 0;
}
