#include <bits/stdc++.h>
using namespace std;
vector<int> Ma[15];
int n, ar[15];
int dp[15][1 << 13][15];
void masking(int p, int pos, int val, int mask) {
  if (pos == p && __builtin_popcount(mask) > 1) {
    Ma[p].push_back(mask);
    return;
  }
  if (pos == p) return;
  masking(p, pos + 1, val, mask);
  if (val - ar[pos] >= 0) masking(p, pos + 1, val - ar[pos], mask | (1 << pos));
  return;
}
int fun(int pos, int mask, int cnt) {
  if (pos < 0) {
    if (__builtin_popcount(mask) == n - 1 && cnt == 0)
      return 1;
    else
      return 0;
  }
  int &ret = dp[pos][mask][cnt];
  if (ret != -1) return ret;
  ret = 0;
  int x = ar[pos] - 1;
  for (int m : Ma[pos]) {
    int ch = (m & mask);
    if (ch == 0) {
      int s = 0;
      for (int i = 0; i < n; i++) {
        int bt = ((m & (1 << i)) > 0);
        if (bt) s += ar[i];
      }
      int d = x - s;
      if (cnt >= d) ret |= fun(pos - 1, mask | m, cnt - d);
    }
  }
  for (int i = 0; i < pos; i++) {
    int bt = ((mask & (1 << i)) > 0);
    if (bt == 0 && ar[i] < x) {
      int d = x - ar[i];
      if (cnt >= d) ret |= fun(pos - 1, mask | (1 << i), cnt - d);
    }
  }
  if (cnt >= x) ret |= fun(pos - 1, mask, cnt - x);
  return ret;
}
int main() {
  int l, cnt, m;
  scanf("%d", &n);
  m = n;
  cnt = 0;
  l = 0;
  bool ch = 1;
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    if (a == 1)
      cnt++;
    else
      ar[l++] = a;
    if (a == 2) ch = 0;
  }
  if (n == 1) {
    puts("YES");
    return 0;
  }
  if (ch == 0) {
    puts("NO");
    return 0;
  }
  n = l;
  sort(ar, ar + n);
  if (ar[n - 1] != m) {
    puts("NO");
    return 0;
  }
  if (ar[n - 1] == ar[n - 2]) {
    puts("NO");
    return 0;
  }
  for (int i = 0; i < n; i++) masking(i, 0, ar[i] - 1, 0);
  memset(dp, -1, sizeof(dp));
  if (fun(n - 1, 0, cnt))
    puts("YES");
  else
    puts("NO");
  return 0;
}

### 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;
vector<int> Ma[15];
int n, ar[15];
int dp[15][1 << 13][15];
void masking(int p, int pos, int val, int mask) {
  if (pos == p && __builtin_popcount(mask) > 1) {
    Ma[p].push_back(mask);
    return;
  }
  if (pos == p) return;
  masking(p, pos + 1, val, mask);
  if (val - ar[pos] >= 0) masking(p, pos + 1, val - ar[pos], mask | (1 << pos));
  return;
}
int fun(int pos, int mask, int cnt) {
  if (pos < 0) {
    if (__builtin_popcount(mask) == n - 1 && cnt == 0)
      return 1;
    else
      return 0;
  }
  int &ret = dp[pos][mask][cnt];
  if (ret != -1) return ret;
  ret = 0;
  int x = ar[pos] - 1;
  for (int m : Ma[pos]) {
    int ch = (m & mask);
    if (ch == 0) {
      int s = 0;
      for (int i = 0; i < n; i++) {
        int bt = ((m & (1 << i)) > 0);
        if (bt) s += ar[i];
      }
      int d = x - s;
      if (cnt >= d) ret |= fun(pos - 1, mask | m, cnt - d);
    }
  }
  for (int i = 0; i < pos; i++) {
    int bt = ((mask & (1 << i)) > 0);
    if (bt == 0 && ar[i] < x) {
      int d = x - ar[i];
      if (cnt >= d) ret |= fun(pos - 1, mask | (1 << i), cnt - d);
    }
  }
  if (cnt >= x) ret |= fun(pos - 1, mask, cnt - x);
  return ret;
}
int main() {
  int l, cnt, m;
  scanf("%d", &n);
  m = n;
  cnt = 0;
  l = 0;
  bool ch = 1;
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    if (a == 1)
      cnt++;
    else
      ar[l++] = a;
    if (a == 2) ch = 0;
  }
  if (n == 1) {
    puts("YES");
    return 0;
  }
  if (ch == 0) {
    puts("NO");
    return 0;
  }
  n = l;
  sort(ar, ar + n);
  if (ar[n - 1] != m) {
    puts("NO");
    return 0;
  }
  if (ar[n - 1] == ar[n - 2]) {
    puts("NO");
    return 0;
  }
  for (int i = 0; i < n; i++) masking(i, 0, ar[i] - 1, 0);
  memset(dp, -1, sizeof(dp));
  if (fun(n - 1, 0, cnt))
    puts("YES");
  else
    puts("NO");
  return 0;
}

```