#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool gmin(T &a, T b) {
  if (a > b) return a = b, true;
  return false;
}
template <class T>
inline bool gmax(T &a, T b) {
  if (a < b) return a = b, true;
  return false;
}
template <class T>
T exgcd(T a, T b, T &first, T &second) {
  if (!b)
    return first = (T)1, second = (T)0, a;
  else {
    T d = exgcd(b, a % b, second, first);
    return second -= a / b * first, d;
  }
}
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = 1e10;
const double EPS = 1e-9;
const double PI = 3.14159265358979323846264338327950288;
const double TAU = 2.0 * PI;
inline int sgn(const double &a) { return a > EPS ? 1 : (a < -EPS ? -1 : 0); }
inline int lowbit(int i) { return i & (-i); }
struct Initializer {
  Initializer() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  }
} initializer;
const int MAXN = 30;
int n, top;
int size[MAXN], cnt[MAXN], c[MAXN];
bool ans;
void dfs1(int);
void dfs2(int cur, int now, int rest, int tot) {
  if (rest == 0) {
    if (tot < 2) return;
    if (size[top] == c[cur])
      cnt[top]++;
    else
      ++top, size[top] = c[cur], cnt[top] = 1;
    dfs1(cur + 1);
  } else {
    if (now > top) return;
    if (size[now] > rest) return;
    for (int i = now; i <= top; i++) {
      for (int j = 1; j <= cnt[i] && j * size[i] <= rest; j++) {
        cnt[i] -= j;
        dfs2(cur, i + 1, rest - j * size[i], tot + j);
        if (ans) return;
        cnt[i] += j;
      }
    }
  }
}
void dfs1(int i) {
  if (i > n) {
    ans = 1;
    return;
  }
  dfs2(i, 1, c[i] - 1, 0);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  sort(c + 1, c + 1 + n);
  if (c[n] != n)
    printf("NO\n");
  else {
    int st = 1;
    top = 1;
    size[1] = 1;
    cnt[1] = 0;
    while (c[st] == 1) st++, cnt[1]++;
    ans = 0;
    dfs1(st);
    if (ans)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

### Prompt

Please provide a CPP coded solution 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;
template <class T>
inline bool gmin(T &a, T b) {
  if (a > b) return a = b, true;
  return false;
}
template <class T>
inline bool gmax(T &a, T b) {
  if (a < b) return a = b, true;
  return false;
}
template <class T>
T exgcd(T a, T b, T &first, T &second) {
  if (!b)
    return first = (T)1, second = (T)0, a;
  else {
    T d = exgcd(b, a % b, second, first);
    return second -= a / b * first, d;
  }
}
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = 1e10;
const double EPS = 1e-9;
const double PI = 3.14159265358979323846264338327950288;
const double TAU = 2.0 * PI;
inline int sgn(const double &a) { return a > EPS ? 1 : (a < -EPS ? -1 : 0); }
inline int lowbit(int i) { return i & (-i); }
struct Initializer {
  Initializer() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  }
} initializer;
const int MAXN = 30;
int n, top;
int size[MAXN], cnt[MAXN], c[MAXN];
bool ans;
void dfs1(int);
void dfs2(int cur, int now, int rest, int tot) {
  if (rest == 0) {
    if (tot < 2) return;
    if (size[top] == c[cur])
      cnt[top]++;
    else
      ++top, size[top] = c[cur], cnt[top] = 1;
    dfs1(cur + 1);
  } else {
    if (now > top) return;
    if (size[now] > rest) return;
    for (int i = now; i <= top; i++) {
      for (int j = 1; j <= cnt[i] && j * size[i] <= rest; j++) {
        cnt[i] -= j;
        dfs2(cur, i + 1, rest - j * size[i], tot + j);
        if (ans) return;
        cnt[i] += j;
      }
    }
  }
}
void dfs1(int i) {
  if (i > n) {
    ans = 1;
    return;
  }
  dfs2(i, 1, c[i] - 1, 0);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  sort(c + 1, c + 1 + n);
  if (c[n] != n)
    printf("NO\n");
  else {
    int st = 1;
    top = 1;
    size[1] = 1;
    cnt[1] = 0;
    while (c[st] == 1) st++, cnt[1]++;
    ans = 0;
    dfs1(st);
    if (ans)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

```