Problem: Earlier, when there was no Internet, each bank had a lot of offices all around Bankopolis, and it caused a lot of problems. Namely, each day the bank had to collect cash from all the offices.

Once Oleg the bank client heard a dialogue of two cash collectors. Each day they traveled through all the departments and offices of the bank following the same route every day. The collectors started from the central department and moved between some departments or between some department and some office using special roads. Finally, they returned to the central department. The total number of departments and offices was n, the total number of roads was n - 1. In other words, the special roads system was a rooted tree in which the root was the central department, the leaves were offices, the internal vertices were departments. The collectors always followed the same route in which the number of roads was minimum possible, that is 2n - 2.

One of the collectors said that the number of offices they visited between their visits to offices a and then b (in the given order) is equal to the number of offices they visited between their visits to offices b and then a (in this order). The other collector said that the number of offices they visited between their visits to offices c and then d (in this order) is equal to the number of offices they visited between their visits to offices d and then c (in this order). The interesting part in this talk was that the shortest path (using special roads only) between any pair of offices among a, b, c and d passed through the central department.

Given the special roads map and the indexes of offices a, b, c and d, determine if the situation described by the collectors was possible, or not.

Input

The first line contains single integer n (5 ≤ n ≤ 5000) — the total number of offices and departments. The departments and offices are numbered from 1 to n, the central office has index 1.

The second line contains four integers a, b, c and d (2 ≤ a, b, c, d ≤ n) — the indexes of the departments mentioned in collector's dialogue. It is guaranteed that these indexes are offices (i.e. leaves of the tree), not departments. It is guaranteed that the shortest path between any pair of these offices passes through the central department.

On the third line n - 1 integers follow: p2, p3, ..., pn (1 ≤ pi < i), where pi denotes that there is a special road between the i-th office or department and the pi-th department.

Please note the joint enumeration of departments and offices.

It is guaranteed that the given graph is a tree. The offices are the leaves, the departments are the internal vertices.

Output

If the situation described by the cash collectors was possible, print "YES". Otherwise, print "NO".

Examples

Input

5
2 3 4 5
1 1 1 1


Output

YES

Input

10
3 8 9 10
1 2 2 2 2 2 1 1 1


Output

NO

Input

13
13 12 9 7
1 1 1 1 5 5 2 2 2 3 3 4


Output

YES

Note

In the first example the following collector's route was possible: <image>. We can note that between their visits to offices a and b the collectors visited the same number of offices as between visits to offices b and a; the same holds for c and d (the collectors' route is infinite as they follow it each day).

In the second example there is no route such that between their visits to offices c and d the collectors visited the same number of offices as between visits to offices d and c. Thus, there situation is impossible. 

In the third example one of the following routes is: <image>.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
template <typename T>
class IntegerIterator
    : public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> {
 public:
  explicit IntegerIterator(T value) : value(value) {}
  IntegerIterator& operator++() {
    ++value;
    return *this;
  }
  IntegerIterator operator++(int) {
    IntegerIterator copy = *this;
    ++value;
    return copy;
  }
  IntegerIterator& operator--() {
    --value;
    return *this;
  }
  IntegerIterator operator--(int) {
    IntegerIterator copy = *this;
    --value;
    return copy;
  }
  T operator*() const { return value; }
  bool operator==(IntegerIterator rhs) const { return value == rhs.value; }
  bool operator!=(IntegerIterator rhs) const { return !(*this == rhs); }

 private:
  T value;
};
template <typename T>
class IntegerRange {
 public:
  IntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }
  IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); }
  IntegerIterator<T> end() const { return IntegerIterator<T>(end_); }

 private:
  T begin_;
  T end_;
};
template <typename T>
class ReversedIntegerRange {
 public:
  ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }
  std::reverse_iterator<IntegerIterator<T>> begin() const {
    return std::reverse_iterator<IntegerIterator<T>>(
        IntegerIterator<T>(begin_));
  }
  std::reverse_iterator<IntegerIterator<T>> end() const {
    return std::reverse_iterator<IntegerIterator<T>>(IntegerIterator<T>(end_));
  }

 private:
  T begin_;
  T end_;
};
template <typename T>
IntegerRange<T> range(T to) {
  return IntegerRange<T>(0, to);
}
template <typename T>
IntegerRange<T> range(T from, T to) {
  return IntegerRange<T>(from, to);
}
template <typename T>
IntegerRange<T> inclusiveRange(T to) {
  return IntegerRange<T>(0, to + 1);
}
template <typename T>
IntegerRange<T> inclusiveRange(T from, T to) {
  return IntegerRange<T>(from, to + 1);
}
template <typename T>
ReversedIntegerRange<T> downrange(T from) {
  return ReversedIntegerRange<T>(from, 0);
}
template <typename T>
ReversedIntegerRange<T> downrange(T from, T to) {
  return ReversedIntegerRange<T>(from, to);
}
template <typename T>
ReversedIntegerRange<T> inclusiveDownrange(T from) {
  return ReversedIntegerRange<T>(from + 1, 0);
}
template <typename T>
ReversedIntegerRange<T> inclusiveDownrange(T from, T to) {
  return ReversedIntegerRange<T>(from + 1, to);
}
template <typename T, size_t N>
struct MakeVector {
  template <typename... Args,
            typename R = std::vector<decltype(MakeVector<T, N - 1>::make_vector(
                std::declval<Args>()...))>>
  static R make_vector(std::size_t first, Args... sizes) {
    auto inner = MakeVector<T, N - 1>::make_vector(sizes...);
    return R(first, inner);
  }
};
template <typename T>
struct MakeVector<T, 1> {
  template <typename R = std::vector<T>>
  static R make_vector(std::size_t size, const T& value) {
    return R(size, value);
  }
};
template <typename T, typename... Args>
auto make_vector(Args... args)
    -> decltype(MakeVector<T, sizeof...(Args) - 1>::make_vector(args...)) {
  return MakeVector<T, sizeof...(Args) - 1>::make_vector(args...);
}
using namespace std;
class TaskE {
 public:
  vector<int> intr;
  vector<vector<int>> g;
  pair<int, int> dfs(int v) {
    if (g[v].empty()) {
      for (int i = 0; i < 4; ++i) {
        if (intr[i] == v) {
          return {1, i + 1};
        }
      }
      return {1, 0};
    }
    pair<int, int> res{0, 0};
    for (auto x : g[v]) {
      auto c = dfs(x);
      res.first += c.first;
      res.second += c.second;
    }
    return res;
  }
  void solve(std::istream& in, std::ostream& out) {
    int n = 5000;
    in >> n;
    g.resize(n);
    int a = 1, b = 2, c = 3, d = 4;
    in >> a >> b >> c >> d;
    --a, --b, --c, --d;
    intr = {a, b, c, d};
    for (int i : range(1, n)) {
      int p = 1;
      in >> p;
      --p;
      g[p].push_back(i);
    }
    vector<int> sizes(4);
    vector<int> addSizes;
    for (int v : g[0]) {
      auto t = dfs(v);
      if (t.second == 0) {
        addSizes.push_back(t.first);
      } else {
        sizes[t.second - 1] = (t.first);
      }
    }
    int sumOthers = 0;
    for (int x : addSizes) {
      sumOthers += x;
    }
    int sumAll = sumOthers;
    for (int x : sizes) {
      sumAll += x;
    }
    if (sumAll % 2) {
      out << "NO\n";
      return;
    }
    vector<int> dupSizes(n + 1);
    for (int s : addSizes) {
      ++dupSizes[s];
    }
    for (int i : inclusiveRange(n)) {
      if (dupSizes[i] > 2) {
        dupSizes[i * 2] += (dupSizes[i] - 1) / 2;
        dupSizes[i] -= (dupSizes[i] - 1) / 2 * 2;
      }
    }
    vector<bitset<5001>> dp(n + 1);
    dp[0][0] = true;
    for (int s : inclusiveRange(n)) {
      for (int _ : range(dupSizes[s])) {
        for (int x : inclusiveDownrange(n, 0)) {
          if (x + s <= n) {
            dp[x + s] |= dp[x];
          }
          dp[x] |= (dp[x] << s);
        }
      }
    }
    bool canAB = false;
    bool canCD = false;
    for (int i : inclusiveRange(n)) {
      if (dp[i][0]) {
        if (sizes[2] + i < n / 2 && sizes[3] + (sumOthers - i) < n / 2) {
          canAB = true;
        }
        if (sizes[0] + i < n / 2 && sizes[1] + (sumOthers - i) < n / 2) {
          canCD = true;
        }
      }
    }
    bool canExternal = false;
    for (int i : inclusiveRange(n)) {
      for (int j : inclusiveRange(n)) {
        if (dp[i][j]) {
          if (i < n / 2 && j < n / 2 &&
              sizes[0] + sizes[1] + sumOthers - j < n / 2 &&
              sizes[2] + sizes[3] + sumOthers - i < n / 2) {
            canExternal = true;
            if (canExternal) {
              break;
            }
          }
        }
      }
      if (canExternal) {
        break;
      }
    }
    if ((canAB && canCD) || canExternal) {
      out << "YES\n";
    } else {
      out << "NO\n";
    }
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  TaskE solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  in.tie(nullptr);
  out << std::fixed;
  out.precision(20);
  solver.solve(in, out);
  return 0;
}