#include <bits/stdc++.h>
using namespace std;
class Graph {
  int V;
  list<int> *adj;
  list<pair<int, int> > *adjw;
  void DFSUtil(int v, bool visited[]);
  void topologicalSortUtil(int v, bool visited[], stack<int> &Stack);

 public:
  Graph(int V);
  void addEdge(int v, int w);
  void addEdge(int u, int v, int w);
  void DFS(int v);
  void DFS();
  void BFS(int s);
  void topologicalSort();
  void shortestPath(int s);
  bool fun();
};
Graph::Graph(int V) {
  this->V = V;
  adj = new list<int>[V];
  adjw = new list<pair<int, int> >[V];
}
void Graph::addEdge(int v, int w) { adj[v].push_back(w); }
void Graph::addEdge(int u, int v, int w) {
  adjw[u].push_back(make_pair(v, w));
  adjw[v].push_back(make_pair(u, w));
}
void Graph::DFSUtil(int v, bool visited[]) {
  visited[v] = true;
  cout << v << " ";
  list<int>::iterator i;
  for (i = adj[v].begin(); i != adj[v].end(); ++i)
    if (!visited[*i]) DFSUtil(*i, visited);
}
void Graph::DFS(int v) {
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  DFSUtil(v, visited);
}
void Graph::DFS() {
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  for (int i = 0; i < V; i++)
    if (visited[i] == false) DFSUtil(i, visited);
}
void Graph::BFS(int s) {
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  list<int> queue;
  visited[s] = true;
  queue.push_back(s);
  list<int>::iterator i;
  while (!queue.empty()) {
    s = queue.front();
    queue.pop_front();
    for (i = adj[s].begin(); i != adj[s].end(); ++i) {
      if (!visited[*i]) {
        visited[*i] = true;
        queue.push_back(*i);
      }
    }
  }
}
void Graph::topologicalSortUtil(int v, bool visited[], stack<int> &Stack) {
  visited[v] = true;
  list<int>::iterator i;
  for (i = adj[v].begin(); i != adj[v].end(); ++i)
    if (!visited[*i]) topologicalSortUtil(*i, visited, Stack);
  Stack.push(v);
}
void Graph::topologicalSort() {
  stack<int> Stack;
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  for (int i = 0; i < V; i++)
    if (visited[i] == false) topologicalSortUtil(i, visited, Stack);
  while (Stack.empty() == false) {
    Stack.pop();
  }
}
void Graph::shortestPath(int src) {}
bool Graph::fun() {
  queue<int> q;
  int src = 1;
  q.push(src);
  while (q.size() != 0) {
    int y = q.front();
    q.pop();
    int cnt = 0;
    if (adj[y].size() < 3) {
      return false;
    }
    list<int>::iterator i;
    for (i = adj[y].begin(); i != adj[y].end(); i++) {
      int j = *i;
      if (adj[j].size() == 0)
        cnt++;
      else {
        q.push(j);
      }
    }
    if (cnt < 3) {
      return false;
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  int v;
  cin >> v;
  Graph gr(v + 1);
  for (int i = 2; i <= v; i++) {
    int n;
    cin >> n;
    gr.addEdge(n, i);
  }
  if (gr.fun())
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

### Prompt

Develop a solution in CPP to the problem described below:

Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex is called a leaf if it doesn't have children and has a parent.

Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.

The definition of a rooted tree can be found [here](https://goo.gl/1dqvzz).

Input

The first line contains one integer n — the number of vertices in the tree (3 ≤ n ≤ 1 000). Each of the next n - 1 lines contains one integer pi (1 ≤ i ≤ n - 1) — the index of the parent of the i + 1-th vertex (1 ≤ pi ≤ i).

Vertex 1 is the root. It's guaranteed that the root has at least 2 children.

Output

Print "Yes" if the tree is a spruce and "No" otherwise.

Examples

Input

4
1
1
1


Output

Yes


Input

7
1
1
1
2
2
2


Output

No


Input

8
1
1
1
1
3
3
3


Output

Yes

Note

The first example:

<image>

The second example:

<image>

It is not a spruce, because the non-leaf vertex 1 has only 2 leaf children.

The third example:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
class Graph {
  int V;
  list<int> *adj;
  list<pair<int, int> > *adjw;
  void DFSUtil(int v, bool visited[]);
  void topologicalSortUtil(int v, bool visited[], stack<int> &Stack);

 public:
  Graph(int V);
  void addEdge(int v, int w);
  void addEdge(int u, int v, int w);
  void DFS(int v);
  void DFS();
  void BFS(int s);
  void topologicalSort();
  void shortestPath(int s);
  bool fun();
};
Graph::Graph(int V) {
  this->V = V;
  adj = new list<int>[V];
  adjw = new list<pair<int, int> >[V];
}
void Graph::addEdge(int v, int w) { adj[v].push_back(w); }
void Graph::addEdge(int u, int v, int w) {
  adjw[u].push_back(make_pair(v, w));
  adjw[v].push_back(make_pair(u, w));
}
void Graph::DFSUtil(int v, bool visited[]) {
  visited[v] = true;
  cout << v << " ";
  list<int>::iterator i;
  for (i = adj[v].begin(); i != adj[v].end(); ++i)
    if (!visited[*i]) DFSUtil(*i, visited);
}
void Graph::DFS(int v) {
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  DFSUtil(v, visited);
}
void Graph::DFS() {
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  for (int i = 0; i < V; i++)
    if (visited[i] == false) DFSUtil(i, visited);
}
void Graph::BFS(int s) {
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  list<int> queue;
  visited[s] = true;
  queue.push_back(s);
  list<int>::iterator i;
  while (!queue.empty()) {
    s = queue.front();
    queue.pop_front();
    for (i = adj[s].begin(); i != adj[s].end(); ++i) {
      if (!visited[*i]) {
        visited[*i] = true;
        queue.push_back(*i);
      }
    }
  }
}
void Graph::topologicalSortUtil(int v, bool visited[], stack<int> &Stack) {
  visited[v] = true;
  list<int>::iterator i;
  for (i = adj[v].begin(); i != adj[v].end(); ++i)
    if (!visited[*i]) topologicalSortUtil(*i, visited, Stack);
  Stack.push(v);
}
void Graph::topologicalSort() {
  stack<int> Stack;
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  for (int i = 0; i < V; i++)
    if (visited[i] == false) topologicalSortUtil(i, visited, Stack);
  while (Stack.empty() == false) {
    Stack.pop();
  }
}
void Graph::shortestPath(int src) {}
bool Graph::fun() {
  queue<int> q;
  int src = 1;
  q.push(src);
  while (q.size() != 0) {
    int y = q.front();
    q.pop();
    int cnt = 0;
    if (adj[y].size() < 3) {
      return false;
    }
    list<int>::iterator i;
    for (i = adj[y].begin(); i != adj[y].end(); i++) {
      int j = *i;
      if (adj[j].size() == 0)
        cnt++;
      else {
        q.push(j);
      }
    }
    if (cnt < 3) {
      return false;
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  int v;
  cin >> v;
  Graph gr(v + 1);
  for (int i = 2; i <= v; i++) {
    int n;
    cin >> n;
    gr.addEdge(n, i);
  }
  if (gr.fun())
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

```