#include <bits/stdc++.h>
using namespace std;
const int MAXN = 24;
const int HALF = 13;
int n, half, ones;
int arr[MAXN + 5];
int best[MAXN + 2][1 << HALF | 2][HALF + 5][2];
int maxVal[1 << HALF | 2], nodes[1 << HALF | 2];
int solve(int rem, int mask, int ones, bool first = false) {
  if (rem < 0) return 0;
  if (ones < 0) return 0;
  int& ret = best[rem][mask][ones][first];
  if (~ret) return ret;
  int i;
  for (i = 0; i < half; i++) {
    if ((mask & (1 << i)) && arr[i] + 1 == rem + 1) {
      if (first) return ret = 0;
      return ret = solve(rem - 1, mask - (1 << i), ones, true);
    }
  }
  if (mask == 0) {
    if (first) return ret = ones == rem && rem > 1;
    return ret = ones == rem;
  }
  ret = 0;
  for (int sub = mask; sub > 0; sub = sub - 1 & mask) {
    if (first && maxVal[sub] == rem) continue;
    ret |= solve(maxVal[sub], sub, maxVal[sub] - nodes[sub], false) &
           solve(rem - maxVal[sub], mask - sub,
                 ones - (maxVal[sub] - nodes[sub]), false);
  }
  return ret;
}
int main() {
  int c, c2;
  scanf("%d", &n);
  for (c = 0; c < n; c++) {
    scanf("%d", &arr[c]);
  }
  sort(arr, arr + n);
  for (ones = 0; ones < n && arr[ones] == 1; ones++)
    ;
  if (arr[n - 1] != n) {
    printf("NO\n");
    return 0;
  }
  reverse(arr, arr + n);
  half = n - ones;
  if (half > HALF) {
    printf("NO\n");
    return 0;
  }
  for (int mask = 0; mask < 1 << half; mask++) {
    maxVal[mask] = 0;
    for (int i = 0; i < half; i++) {
      if (mask & 1 << i) maxVal[mask] = max(maxVal[mask], arr[i]);
    }
    nodes[mask] = __builtin_popcount(mask);
  }
  memset(best, -1, sizeof(best));
  if (solve(n, (1 << half) - 1, ones))
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

### Prompt

Your task is to create a CPP solution to the following problem:

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 = 24;
const int HALF = 13;
int n, half, ones;
int arr[MAXN + 5];
int best[MAXN + 2][1 << HALF | 2][HALF + 5][2];
int maxVal[1 << HALF | 2], nodes[1 << HALF | 2];
int solve(int rem, int mask, int ones, bool first = false) {
  if (rem < 0) return 0;
  if (ones < 0) return 0;
  int& ret = best[rem][mask][ones][first];
  if (~ret) return ret;
  int i;
  for (i = 0; i < half; i++) {
    if ((mask & (1 << i)) && arr[i] + 1 == rem + 1) {
      if (first) return ret = 0;
      return ret = solve(rem - 1, mask - (1 << i), ones, true);
    }
  }
  if (mask == 0) {
    if (first) return ret = ones == rem && rem > 1;
    return ret = ones == rem;
  }
  ret = 0;
  for (int sub = mask; sub > 0; sub = sub - 1 & mask) {
    if (first && maxVal[sub] == rem) continue;
    ret |= solve(maxVal[sub], sub, maxVal[sub] - nodes[sub], false) &
           solve(rem - maxVal[sub], mask - sub,
                 ones - (maxVal[sub] - nodes[sub]), false);
  }
  return ret;
}
int main() {
  int c, c2;
  scanf("%d", &n);
  for (c = 0; c < n; c++) {
    scanf("%d", &arr[c]);
  }
  sort(arr, arr + n);
  for (ones = 0; ones < n && arr[ones] == 1; ones++)
    ;
  if (arr[n - 1] != n) {
    printf("NO\n");
    return 0;
  }
  reverse(arr, arr + n);
  half = n - ones;
  if (half > HALF) {
    printf("NO\n");
    return 0;
  }
  for (int mask = 0; mask < 1 << half; mask++) {
    maxVal[mask] = 0;
    for (int i = 0; i < half; i++) {
      if (mask & 1 << i) maxVal[mask] = max(maxVal[mask], arr[i]);
    }
    nodes[mask] = __builtin_popcount(mask);
  }
  memset(best, -1, sizeof(best));
  if (solve(n, (1 << half) - 1, ones))
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

```