#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 3;
bool dp[30][(1 << 14)][30];
int cnt[(1 << 14)], deg[(1 << 14)];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a;
  int c = 0;
  bool fail = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x == 2) fail = 1;
    if (x == 1)
      c++;
    else
      a.push_back(x);
  }
  if (n == 1) {
    if (c == 1) return cout << "YES\n", 0;
    return cout << "NO\n", 0;
  }
  sort(a.begin(), a.end());
  if (c < (n + 1) / 2 or fail) return cout << "NO\n", 0;
  int m = n - c;
  for (int mask = 0; mask < (1 << m); mask++) {
    for (int i = 0; i < m; i++) {
      if (mask & (1 << i)) {
        deg[mask] = deg[mask ^ (1 << i)] + a[i];
        cnt[mask] = cnt[mask ^ (1 << i)] + 1;
      }
    }
  }
  dp[0][0][c] = 1;
  for (int i = 0; i < m; i++) {
    for (int mask = 0; mask < (1 << i); mask++) {
      for (int j = 0; j <= c; j++) {
        if (dp[i][mask][j] == 0) continue;
        for (int submask = mask; submask; submask = (submask - 1) & mask) {
          if (deg[submask] > a[i] - 1 or deg[submask] + j < a[i] - 1) continue;
          int t = a[i] - 1 - deg[submask];
          if (cnt[submask] + t > 1)
            dp[i + 1][(mask ^ submask) | (1 << i)][j - t] = 1;
        }
        if (j >= a[i] - 1) dp[i + 1][mask | (1 << i)][j - a[i] + 1] = 1;
      }
    }
  }
  cout << (dp[m][(1 << (m - 1))][0] == 1 ? "YES\n" : "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 = 1e5 + 3;
bool dp[30][(1 << 14)][30];
int cnt[(1 << 14)], deg[(1 << 14)];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a;
  int c = 0;
  bool fail = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x == 2) fail = 1;
    if (x == 1)
      c++;
    else
      a.push_back(x);
  }
  if (n == 1) {
    if (c == 1) return cout << "YES\n", 0;
    return cout << "NO\n", 0;
  }
  sort(a.begin(), a.end());
  if (c < (n + 1) / 2 or fail) return cout << "NO\n", 0;
  int m = n - c;
  for (int mask = 0; mask < (1 << m); mask++) {
    for (int i = 0; i < m; i++) {
      if (mask & (1 << i)) {
        deg[mask] = deg[mask ^ (1 << i)] + a[i];
        cnt[mask] = cnt[mask ^ (1 << i)] + 1;
      }
    }
  }
  dp[0][0][c] = 1;
  for (int i = 0; i < m; i++) {
    for (int mask = 0; mask < (1 << i); mask++) {
      for (int j = 0; j <= c; j++) {
        if (dp[i][mask][j] == 0) continue;
        for (int submask = mask; submask; submask = (submask - 1) & mask) {
          if (deg[submask] > a[i] - 1 or deg[submask] + j < a[i] - 1) continue;
          int t = a[i] - 1 - deg[submask];
          if (cnt[submask] + t > 1)
            dp[i + 1][(mask ^ submask) | (1 << i)][j - t] = 1;
        }
        if (j >= a[i] - 1) dp[i + 1][mask | (1 << i)][j - a[i] + 1] = 1;
      }
    }
  }
  cout << (dp[m][(1 << (m - 1))][0] == 1 ? "YES\n" : "NO\n");
}

```