#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
int a[maxn], tim, sz[maxn], d[maxn], par[maxn], SZ[maxn];
bool can = true;
vector<int> adj[maxn];
int p[maxn];
pair<int, int> Pr[maxn];
void dfs(int v, int p) {
  sz[v] = 1;
  par[v] = p;
  tim++;
  for (int u : adj[v]) {
    if (u != p) {
      d[u] = d[v] + 1;
      dfs(u, v);
      sz[v] += sz[u];
    }
  }
}
int main() {
  int n, o = 0, N;
  cin >> n;
  N = n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) o++;
    if (a[i] == 2) can = false;
  }
  if (n == 1) {
    cout << (a[0] == 1 ? "YES" : "NO") << "\n";
    return 0;
  }
  sort(a, a + n, greater<int>());
  if (o <= n - o || !can || o == n || a[0] != n) {
    cout << "NO"
         << "\n";
    return 0;
  }
  n = n - o - 1;
  if (!n) {
    cout << "YES"
         << "\n";
    return 0;
  }
  can = false;
  for (int i = 0; i < n; i++) p[i] = i;
  do {
    for (int i = 0; i < N; i++) {
      adj[i].clear();
      sz[i] = 0;
      d[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      int x = 0;
      for (int j = 0; j < i; j++) {
        if (p[i] > p[j]) x++;
      }
      adj[i + 1].push_back(x);
      adj[x].push_back(i + 1);
    }
    for (int i = 0; i < N; i++) {
      SZ[i] = adj[i].size();
      if (i) SZ[i]--;
    }
    tim = 0;
    dfs(0, -1);
    if (tim != n + 1) continue;
    for (int i = 0; i < n + 1; i++) Pr[i] = {-d[i], i};
    sort(Pr, Pr + n + 1);
    int cur = n + 1;
    bool flag = true;
    for (int i = 0; i < n + 1 && cur < N && flag; i++) {
      int v = Pr[i].second;
      if (sz[v] < a[v]) {
        int ez = a[v] - sz[v];
        sz[v] = a[v];
        SZ[v] += ez;
        int nw = v;
        while (par[nw] != -1) {
          nw = par[nw];
          sz[nw] += ez;
        }
        cur += ez;
      }
      if (sz[v] != a[v]) flag = false;
    }
    if (cur != N) flag = false;
    if (flag) {
      can = true;
      for (int i = 0; i < N; i++) {
        if (a[i] == 1) continue;
        if (SZ[i] < 2) can = false;
      }
    }
  } while (next_permutation(p, p + n) && !can);
  cout << (can ? "YES" : "NO") << "\n";
}

### Prompt

Develop a solution in Cpp to the problem described below:

Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. 

Iahub asks Iahubina: can you build a rooted tree, such that

  * each internal node (a node with at least one son) has at least two sons; 
  * node i has ci nodes in its subtree? 



Iahubina has to guess the tree. Being a smart girl, she realized that it's possible no tree can follow Iahub's restrictions. In this way, Iahub will eat all the food. You need to help Iahubina: determine if there's at least one tree following Iahub's restrictions. The required tree must contain n nodes.

Input

The first line of the input contains integer n (1 ≤ n ≤ 24). Next line contains n positive integers: the i-th number represents ci (1 ≤ ci ≤ n).

Output

Output on the first line "YES" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output "NO" (without quotes). 

Examples

Input

4
1 1 1 4


Output

YES

Input

5
1 1 5 2 1


Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
int a[maxn], tim, sz[maxn], d[maxn], par[maxn], SZ[maxn];
bool can = true;
vector<int> adj[maxn];
int p[maxn];
pair<int, int> Pr[maxn];
void dfs(int v, int p) {
  sz[v] = 1;
  par[v] = p;
  tim++;
  for (int u : adj[v]) {
    if (u != p) {
      d[u] = d[v] + 1;
      dfs(u, v);
      sz[v] += sz[u];
    }
  }
}
int main() {
  int n, o = 0, N;
  cin >> n;
  N = n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) o++;
    if (a[i] == 2) can = false;
  }
  if (n == 1) {
    cout << (a[0] == 1 ? "YES" : "NO") << "\n";
    return 0;
  }
  sort(a, a + n, greater<int>());
  if (o <= n - o || !can || o == n || a[0] != n) {
    cout << "NO"
         << "\n";
    return 0;
  }
  n = n - o - 1;
  if (!n) {
    cout << "YES"
         << "\n";
    return 0;
  }
  can = false;
  for (int i = 0; i < n; i++) p[i] = i;
  do {
    for (int i = 0; i < N; i++) {
      adj[i].clear();
      sz[i] = 0;
      d[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      int x = 0;
      for (int j = 0; j < i; j++) {
        if (p[i] > p[j]) x++;
      }
      adj[i + 1].push_back(x);
      adj[x].push_back(i + 1);
    }
    for (int i = 0; i < N; i++) {
      SZ[i] = adj[i].size();
      if (i) SZ[i]--;
    }
    tim = 0;
    dfs(0, -1);
    if (tim != n + 1) continue;
    for (int i = 0; i < n + 1; i++) Pr[i] = {-d[i], i};
    sort(Pr, Pr + n + 1);
    int cur = n + 1;
    bool flag = true;
    for (int i = 0; i < n + 1 && cur < N && flag; i++) {
      int v = Pr[i].second;
      if (sz[v] < a[v]) {
        int ez = a[v] - sz[v];
        sz[v] = a[v];
        SZ[v] += ez;
        int nw = v;
        while (par[nw] != -1) {
          nw = par[nw];
          sz[nw] += ez;
        }
        cur += ez;
      }
      if (sz[v] != a[v]) flag = false;
    }
    if (cur != N) flag = false;
    if (flag) {
      can = true;
      for (int i = 0; i < N; i++) {
        if (a[i] == 1) continue;
        if (SZ[i] < 2) can = false;
      }
    }
  } while (next_permutation(p, p + n) && !can);
  cout << (can ? "YES" : "NO") << "\n";
}

```