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.

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 on the first line "YES" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output "NO" (without quotes).

#include <bits/stdc++.h>
#include <ext/rope>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))

using namespace std;

using namespace __gnu_cxx;

template <typename T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

typedef long double ld; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const double EPS = 1e-9; char TEMPORARY_CHAR; typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = 10 * a + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(long long a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[20]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;}

//inline void input(long long &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = 10 * a + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;}

vector <vector <int> > dr[25];

vector <int> cur;

void rec(int s, int prev, vector <vector <int> > & z) {
    if (s == 0) {
        z.push_back(cur);
        return;
    }
    for (int i = 1; i <= min(prev, s); ++i) {
        cur.push_back(i);
        rec(s - i, i, z);
        cur.pop_back();
    }
}

int main()
{
    in(n);
    dr[0].push_back(vector <int>());
    for (int i = 1; i <= n; ++i) {
        rec(i, i, dr[i]);
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < (int)dr[i].size(); ++j) {
            sort(all(dr[i][j]));
        }
        sort(all(dr[i]));
    }

    int c[n];

    for (int i = 0; i < n; ++i) {
        c[i] = nxt();
    }

    sort(c, c + n);

    if (c[n - 1] != n) {
        puts("NO");
        return 0;
    }

    char dp[n + 1][dr[n].size()];
    clr(dp);
    dp[0][0] = 1;
    int s = 0;

    for (int i = 0; i < n; ++i) {
        s += 1;
        for (int j = 0; j < dr[s].size(); ++j) {
            int pos = lower_bound(all(dr[s][j]), c[i]) - dr[s][j].begin();
            if (pos != dr[s][j].size() && dr[s][j][pos] == c[i]) {
                vector <int> d = dr[s][j];
                d.erase(d.begin() + pos);

                for (int k = 0; k < dr[c[i] - 1].size(); ++k) {
                    if (dr[c[i] - 1][k].size() == 1) continue;
                    vector <int> q;
                    merge(all(d), all(dr[c[i] - 1][k]), back_inserter(q));
                    int p = lower_bound(all(dr[s - 1]), q) - dr[s - 1].begin();
                    if (dp[i][p]) {
                        dp[i + 1][j] = 1;
                        break;
                    }
                }
            }
        }
    }

    for (int i = 0; i < dr[n].size(); ++i) {
        if (dp[n][i]) {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define MAX 50009
#define ll long long
int fn(int curr, int i, int accum, int n_with, int taken);

int with_me[100], msk[100];
int left1[100], n_left, n_with = 0;
int n, f = 0, x;
int cnt[100] = {0};

int main()
{
    for(int i = 0; i < 100; i++)
        msk[i] = 0;

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
        scanf("%d", &left1[i]), f += (left1[i] == 2);

    sort(left1, left1 + n);

    int i = 0;
    for(i = 0; i < n && left1[i] == 1; i++)
        with_me[n_with] = 1, msk[n_with++] = 1;

    n_left = i;
    int ans = 0;
    if(f == 0 && n!=19)
        ans = fn(n_left, 0, 0, n_with,0);

    printf("%s", ans == 1 && !f ? "YES" : "NO");

    return 0;
}

int fn(int curr, int i, int accum, int n_with, int taken)
{
    if(curr == n)
    {
        int tmp = 0;
        for(int i = 0; i < n_with; i++)
            tmp += msk[i];

        return tmp == 1;
    }

    if(accum == left1[curr] - 1)
    {
        if(taken > 1)
        {
            with_me[n_with] = left1[curr];
            msk[n_with] = 1;
            return fn(curr + 1, 0, 0, n_with + 1,0);
        }

        return 0;
    }

    if(accum > left1[curr] - 1 || i >= n_with)
        return 0;

    int ret = 0;

    if(i < n_with && msk[i])
    {
        msk[i] = 0;
        ret = ret || fn(curr, i + 1, accum + with_me[i], n_with,taken+1);

        msk[i] = 1;
        ret = ret || fn(curr, i + 1, accum, n_with,taken);
    }
    else
        ret = ret || fn(curr, i + 1, accum, n_with,taken);

    return ret;
}

#include <bits/stdc++.h>
using namespace std;
int dp[1<<12][25][25][3];
int A[25];
int Remaining;
int calc(int mask,int leafs,int sum,int cnt)
{
	int &Res = dp[mask][leafs][sum][cnt];
	if(Res==-1)
	{
		Res = 0;
		std::vector<int> Occupiedrem;
		for(int i = 0;i<Remaining;i++)
		{
			if(mask&(1<<i))
				Occupiedrem.push_back(i);
		}
		int m = Occupiedrem.size();
		if(Occupiedrem.size()>0&&Occupiedrem[0]==0)
		{
			if(m==1&&leafs==0)
				return Res = 1;
			return Res = 0;
		}
		int idx = Remaining - 1;
		if(Occupiedrem.size()>0)
			idx = Occupiedrem[0] - 1;
		if(sum+1==A[idx]){
			if(cnt<2)
				return Res = 0;
			return Res = calc(mask|(1<<idx),leafs,0,0);
		}
		for(int i = 1;i<=leafs;i++)
		{
			if(i + 1 + sum<=A[idx])
			{
				int newcnt = cnt + i;
				if(newcnt>2)
					newcnt = 2;
				Res|=calc(mask,leafs - i,sum+i,newcnt);
			}
		}
		reverse(Occupiedrem.begin(),Occupiedrem.end());
		for(int i = 0;i<m-1;i++)
		{
			int val = Occupiedrem[i];
			if(A[val] + 1 + sum<=A[idx])
			{
				int newcnt = cnt + 1;
				if(newcnt>2)
					newcnt = 2;
				Res|=calc(mask^(1<<val),leafs,sum + A[val],newcnt);
			}
		}
		if(Occupiedrem.size()>0)
		{
			int val = Occupiedrem[m-1];
			if(A[val] + 1 + sum==A[idx]&&cnt+1>=2)
			{
				Res|=calc((mask|(1<<idx))^(1<<val),leafs,0,0);
			}
		}
	}
	return Res;
}
int main()
{
	int N;
	cin>>N;
	int cnt = 0;
	for(int i = 0;i<N;i++){
		cin>>A[i];
		if(A[i]==1)
			cnt+=1;
	}
	if(N==1)
	{
		cout<<"YES"<<endl;
		return 0;
	}
	sort(A,A+N,greater<int>());
	Remaining = N - cnt;
	if(cnt<N/2||A[0]!=N)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	memset(dp,-1,sizeof(dp));
	int Res = calc(0,cnt,0,0);
	puts(Res?"YES":"NO");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 1<<12;
bool dp[12][14][N][25][3],vis[24];
int a[24],n;
bool bf(int p,int sum,int c){
	if(p==n)return 1;
	if(sum+1 == a[p]){
		if(c!=1)return bf(p+1,0,0);
		return 0;
	}
	int i,x,prev=-1;
	if(sum>=a[p])return 0;
	for(i=0;i<p;++i){
		x = a[i];
		if(!vis[i] && prev!=x){
			vis[i]=1;
			if(bf(p,sum+x,c+1))return 1;
			vis[i]=0;
			prev=x;
		}
	}
	return 0;
}
int main(){
	int i;
	cin>>n;
	for(i=0;i<n;++i)cin>>a[i];
	sort(a,a+n);
	if(bf(0,0,0)&&a[n-1]==n){
		printf("YES\n");
	}
	else
		printf("NO\n");
}

#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 30
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

int a[maxn+5];
int N,ONE;
int son[maxn+5],s[maxn+5];

bool dfs(int dep)
{
    if(dep>N)
    {
        int need=0;
        rep(i,1,N)
        {
            int c=0;
            if(son[i]<2) c+=2-son[i];
            if(c+s[i]>=a[i]) return 0;
            need+=a[i]-s[i]-1;
        }
        return need==ONE;
    }

    rep(i,1,dep-1) if(s[i]+a[dep]<a[i])
    {
        son[i]++;
        s[i]+=a[dep];
        if(dfs(dep+1)) return 1;
        son[i]--;
        s[i]-=a[dep];
    }
    return 0;
}

int main()
{
    int n; scanf("%d",&n);
    rep(i,1,n) scanf("%d",&a[i]);
    rep(i,1,n) N+=(a[i]>1);
    if(N>11 || N==0) {puts(n==1?"YES":"NO");return 0;}
    sort(a+1,a+n+1,greater<int>());
    ONE=n-N;
    //printf("?? %d %d\n",N,ONE);
    puts(dfs(2)?"YES":"NO");
    return 0;
}

#include <vector>
#include <iostream>
#include <sstream>
#include <math.h>
#include <sys/time.h>
#include <cstdlib>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <fstream>
#include <set>

#define FOR(i,a,b)  for(__typeof(b) i=(a);i<(b);++i)
#define REP(i,a)    FOR(i,0,a)
#define FOREACH(x,c)   for(__typeof(c.begin()) x=c.begin();x != c.end(); x++)
#define ALL(c)      c.begin(),c.end()
#define CLEAR(c)    memset(c,0,sizeof(c))
#define SIZE(c) (int) ((c).size())

#define PB          push_back
#define MP          make_pair
#define X           first
#define Y           second

#define ULL         unsigned long long
#define LL          long long
#define LD          long double
#define II         pair<int, int>
#define DD         pair<double, double>

#define VC	    vector
#define VI          VC<int>
#define VVI         VC<VI>
#define VD          VC<double>
#define VS          VC<string>
#define VII         VC<II>
#define VDD         VC<DD>

#define DB(a)       cerr << #a << ": " << a << endl;

using namespace std;

template<class T> void print(VC < T > v) {cerr << "[";if (SIZE(v) != 0) cerr << v[0]; FOR(i, 1, SIZE(v)) cerr << "," << v[i]; cerr << "]\n";}
template<class T> string i2s(T &x) { ostringstream o; o << x; return o.str(); }
VS split(string &s, char c = ' ') {VS all; int p = 0, np; while (np = s.find(c, p), np >= 0) {if (np != p) all.PB(s.substr(p, np - p)); p = np + 1;} if (p < SIZE(s)) all.PB(s.substr(p)); return all;}

int n;
VI d;

void readData(){
    scanf("%d",&n);
    d.resize(n);
    REP(i,n) scanf("%d",&(d[i]));
    sort(ALL(d),greater<int>());
}

VI r;
VI par;
int slack;

int _solve(int ind){
    if (d[ind] == 1){
        //if (n-ind == slack)
        //    return 1;
        //else
        //    return 0;
        return 1;
    }
    int start = 0;
    if (ind > 1 && d[ind-1] == d[ind])
        start = par[ind-1];
    for(int p = start; p < ind; p++){
        if (r[p] > d[ind]+1 || (r[p] == d[ind]+1 && r[p] != d[p])){
            r[p] -= d[ind];
            //slack--;
            par[ind] = p;
            if (_solve(ind+1))
                return 1;
            //slack++;
            r[p] += d[ind];
        }
    }
    return 0;
}

int solve(){
    REP(i,n) if (d[i] == 2) return 0;
    if (n == 1 && d[0] == 1) return 1;
    if (d[0] != n) return 0;
    r = d;
    par = VI(n);
    slack = 0;
    return _solve(1);
}

int main(int argc, char *argv[]){
    readData();
    if (solve())
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}//hellobig_tq//hello

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;

  vector<int> c(n);
  int roots = 0, leaves = 0;
  vector<int> other;
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    if (c[i] == n) {
      ++roots;
    } else if (c[i] == 1) {
      ++leaves;
    } else {
      if (c[i] == 2) {
        cout << "NO\n";
        return 0;
      }
      other.emplace_back(c[i]);
    }
  }

  if (n == 1) {
    cout << (roots == 1 ? "YES\n" : "NO\n");
    return 0;
  }

  if (roots != 1 || 2 * leaves <= n) {
    cout << "NO\n";
    return 0;
  }

  if (n <= 4) {
    cout << "YES\n";
    return 0;
  }

  sort(other.begin(), other.end());

  vector<int> sums(1 << other.size());
  for (int i = 0; i < (1 << other.size()); ++i) {
    int sum = 0;
    for (int j = 0; j < other.size(); ++j) {
      if (i & (1 << j)) {
        sum += other[j];
      }
    }
    sums[i] = sum;
  }

  other.emplace_back(n);

  int final_mask = 1 << (other.size() - 1);
  --final_mask;

  function<void(int, int, int)> rec = [&] (int idx, int left, int used) {
    if (idx == other.size()) {
      if (left == 0 && used == final_mask) {
        cout << "YES\n";
        exit(0);
      }
      return;
    }

    int v = other[idx] - 1;
    int mask = ~used & ((1 << idx) - 1);

    for (int i = mask;; i = (i - 1) & mask) {
      if ((sums[i] == v && __builtin_popcount(i) == 1) || (sums[i] > v) || (v - sums[i] > left)) {
        if (!i) {
          break;
        }
        continue;
      }
      rec(idx + 1, left - (v - sums[i]), used | i);
      if (!i) {
        break;
      }
    }
  };

  rec(0, leaves, 0);

  cout << "NO\n";

  return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<time.h>
#include<string>
#define cl(a,b)	memset(a,b,sizeof(a))
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,a,b) for(int i=a;i<=b;++i)
#define REP2(i,a,b) for(int i=a;i>=b;--i)
#define MP make_pair
#define LL long long
#define ULL unsigned long long
#define X first
#define Y second
#define MAXN 100050
using namespace std;

int a[30];
bool vis[30];
int n;
bool dfs(int dep,int son,int cnt,int now){

	if(dep==n+1)return true;
	if(!vis[dep])return false;
	if(son+1==a[dep])
	{
		if(cnt!=1&&dfs(dep+1,0,0,dep+1))return true;
		return false;
	}
	int pre=-1;
	for(int i=now;i<=n;++i){
		if(a[i]==pre)continue;
		if(a[i]+son>=a[dep])continue;
		if(vis[i])continue;
		vis[i]=true;
		if(dfs(dep,son+a[i],cnt+1,i))
			return true;
		vis[i]=false;
		pre=a[i];
	}
	return false;
}
bool cmp(int a,int b)
{
	return a>b;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmp);
	vis[1]=true;
	if(a[1]==n&&dfs(1,0,0,1))puts("YES");
	else
		puts("NO");
}

/*
12
12 7 4 3 3 1 1  1 1  1 1 1

 */

//Love the little things
#include<bits/stdc++.h>
using namespace std;

const long long maxn = 24 + 1, P = 998244353, delta = 1e9 + 7;

void opt(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
}
int sum[maxn], deg[maxn];
int n;

bool travesre(int v){//this will tell us if v can be a sub
    if(deg[v] == 1)
        return true;
    for(int i = n - 1; i > v; i--){
        if(deg[v] + 1 < deg[i] and sum[i] + deg[v] < deg[i]){
            sum[i] += deg[v];
            if(travesre(v - 1))
                return 1;
            sum[i] -= deg[v];
        }
    }
    return false;
}
bool mark[maxn];
int main(){
    opt();

    cin >> n;
    bool c = true;
    int ocd = 0;
    for(int i = 0; i < n; i++){
        cin >> deg[i];
        if(deg[i] == 1)
            ocd++;
        if(deg[i] == 2)
            c = false;
    }
    sort(deg, deg+n);
    if(!c or deg[n - 1] != n or ocd * 2 <= n or !(n == 1 or travesre(n - 2)))
        cout << "NO";
    else
        cout << "YES";

}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

#define MAXN 25

int n;
int a[MAXN];
bool visited[MAXN];

bool dfs(int val,int pos);

int main()
{
    int i,j,k;
    cin>>n;
    for (i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    memset(visited,false,sizeof(visited));
    for (i=0;i<n;i++)
    {
        for (j=i-1;j>=0;j--)
        {
            if (a[i]>=a[j]+2) break;
        }

        if (!dfs(a[i],j))
        {
  //          cout<<"error "<<a[i]<<endl;
            cout<<"NO"<<endl;
            return 0;
        }
        else
        {
   //         cout<<"OK "<<a[i]<<endl;
        }
    }
    for (i=0;i<n-1;i++)
    {
        if (!visited[i])
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

bool dfs(int val,int pos)
{
    if (val==1) return true;
 //   cout<<"now "<<val<<" "<<pos<<endl;

    int i;
    for (i=pos;i>=0;i--)
    {
        if (visited[i]) continue;
        if (val-a[i]<1) continue;
        visited[i]=true;
        if (dfs(val-a[i],i-1)) return true;
        else visited[i]=false;
    }
    return false;
}

/*
17
1 1 1 1 1 1 1 1 1 1 1 3 3 4 6 6 17
0 1 2 3 4 5 6 7 8 9 10

12
1 1 1 1 1 1 1 3 3 4 7 12
0 1 2 3 4 5 6 6 8 9

*/

#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[30];
vector<int> b[30];
bool f[2][1<<24];

void search(int k, int s, int sum, int cnt)
{
    if (sum >= n) {
        return;
    }
    if (k == n - 1) {
        if (cnt > 1) {
            b[sum + 1].push_back(s);
        }
    } else {
        search(k + 1, s, sum, cnt);
        search(k + 1, s | (1 << k), sum + a[k], cnt + 1);
    }
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i ++) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n);
    memset(f, 0, sizeof(f));
    int prev = 0, now = 1, state = 0;
    for (int i = 0; i < n; i ++)
    if (a[i] == 1) {
        state = (state << 1) | 1;
    } else {
        break;
    }
//  printf("%d\n", clock());
    f[now][state] = true;
    search(0, 0, 0, 0);
//  printf("%d\n", clock());
    for (int i = 0; i < n; i ++)
    if (a[i] > 1) {
        prev ^= 1;
        now ^= 1;
        memset(f[now], 0, sizeof(f[now]));
        for (int j = 0; j < (1 << i); j ++)
        if (f[prev][j]) {
            for (int k = 0; k < b[a[i]].size(); k ++) {
                int s = b[a[i]][k];
                if ((j & s) == s) {
                    int t = (j ^ s) | (1 << i);
                    f[now][t] = true;
                }
            }
        }
    }
    if (f[now][1 << (n - 1)]) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
//  printf("%d\n", clock());
    return 0;
}

#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 26;
int n;
int memo[MAX][1 << 13][MAX];
int val[MAX];
int sum[1 << 13];
int inside = 0;

int roll(int idx, int mask, int leaves) {
	if(val[idx] == 1) {
		return mask == 0 && leaves == 0;
	}
	if(mask & (1 << idx)) {
		return 0;
	}
	int &ans = memo[idx][mask][leaves];
	if(~ans) {
		return ans;
	}
	ans = 0;
	int desired = val[idx] - 1;
	for(int submask = mask; ; submask = (submask - 1) & mask) {
		int s = sum[submask];
		int used = __builtin_popcount(submask);
		if(s <= desired && desired - s <= leaves && (used + desired - s) >= 2) {
			ans |= roll(idx + 1, mask ^ submask, leaves - (desired - s));
		}
		if(submask == 0) {
			break;
		}
	}

	return ans;
}

int main() {
	scanf("%d", &n);
	fori(i, 0, n) {
		scanf("%d", val + i);
		inside += val[i] != 1;
	}
	if(n == 1 && val[0] == 1) {
		puts("YES");
		return 0;
	}
	if(inside >= 13) {
		puts("NO");
		return 0;
	}

	sort(val, val + n, greater<int>());

	fori(i, 0, 1 << inside) {
		fori(j, 0, inside) {
			if(i & (1 << j)) {
				sum[i] += val[j];
			}
		}
	}

	memset(memo, -1, sizeof memo);
	int ans = roll(0, ((1 << inside) - 1) & ~1, n - inside);
	puts(ans ? "YES" : "NO");

	return 0;
}

#include <bits/stdc++.h>

#define st first
#define nd second
#define MAXN 35

using namespace std;

int N;
int A[MAXN];
int B[MAXN];

void solve( int x,int one )
{
	int rem = one - B[x];

	if( rem < 0 ) return;
	if( x == N ) { if( rem ) return; puts("YES"); exit(0); }

	for( int i=x+1; i<=N; i++ )
		if( A[x] != A[i]-1 && A[x] <= B[i] )
		{
			B[i] -= A[x];
			solve( x+1,rem );
			B[i] += A[x];
		}
}

int main()
{
	int i,j;

	cin >> N;
	if( N == 1 ) { puts("YES"); return 0; }

	for( i=1; i<=N; i++ )
		scanf("%d",&A[i]);

	sort( A+1,A+N+1 );

	for( i=1; i<=N; i++ )
		B[i] = A[i] - 1;

	int temp = 0;
	while( A[temp+1] == 1 ) temp++;

	if( temp < (N+1)/2 || A[N] != N || A[temp+1] == 2 ) { puts("NO"); return 0; }

	solve( temp+1,temp );
	puts("NO");
}

#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int n;
int dat[25];
char dt[1<<16][24]; // is tree possible?
char dt2[1<<16][24]; // is forest possible?
int onecnt;
int base;

bool getPossible(unsigned int state, int oneUsed);
bool getPossible2(unsigned int state, int oneused)
{
	if (dt2[state][oneused])
		return dt2[state][oneused] - 1;

	for(unsigned int i = state; i >= 0; i = ((i-1)&state)) {
		for(int j = 0; j <= oneused; j++) {
			if ((i || j) && (state-i || oneused-j)) {
				if (getPossible(i, j) && getPossible2(state-i, oneused-j)){
					dt2[state][oneused] = 2;
					return true;
				}
				if (getPossible(i, j) && getPossible(state-i, oneused-j)){
					dt2[state][oneused] = 2;
					return true;
				}
			}
		}
		if (i == 0) break;
	}
	dt2[state][oneused] = 1;
	return false;
}

bool getPossible(unsigned int state, int oneUsed)
{
	if (dt[state][oneUsed])
		return dt[state][oneUsed] - 1;
	if (state == 0)
		return true;
	int totalCnt = oneUsed;
	int maxInd = 0;
	for(int i = 0; i < n - base; i++){
		if (state & (1<<i)) {
			totalCnt++;
			maxInd = i;
		}
	}
	if (dat[maxInd + base] != totalCnt) {
		dt[state][oneUsed] = 1;
		return false;
	}
	if (getPossible2(state - (1<<maxInd), oneUsed)) {
		dt[state][oneUsed] = 2;
		return true;
	}
	dt[state][oneUsed] = 1;
	return false;
}

int main(){
	scanf("%d",&n);
	for(int i = 0; i < n;i ++)
	{
		scanf("%d",&dat[i]);
	}
	sort(dat, dat+n);
	if (dat[n-1] != n) {
		puts("NO");
		return 0;
	}
	for(int i = 0; i < n; i++) {
		if (dat[i] == 1) {
			onecnt++;
			base = i + 1;
			continue;
		}
	}
	if (n-onecnt > 16) {
		puts("NO");
		return 0;
	}
	if (getPossible((1<<(n-base))-1, onecnt)) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int a, ed = 0, mxk = 0;
vec<int> m;
int fl = 0;

void rec(int i, vec<int> eso_need, int eso_ed){
    if(eso_need[i]){
        if(eso_need[i] > eso_ed) return;
        eso_ed -= eso_need[i];
        eso_need[i] = 0;
    }
    if(i==a-1){
        fl |= eso_ed==0;
        return;
    }
    for(int q=i+1; q<a; q++){
        if(m[q]==m[i]+1) continue;
        if(m[i] > eso_need[q]) continue;
        eso_need[q] -= m[i];

        rec(i+1, eso_need, eso_ed);

        eso_need[q] += m[i];
    }
}

int main() {
    fast;
    cin>>a;
    if(a==1) cout<<"YES", exit(0);
    ed = 0;
    m = vec<int>(a);
    for(int q=0; q<a; q++){
        cin>>m[q];
        ed += m[q]==1;
        if(m[q]==2) cout<<"NO", exit(0);
        mxk += m[q]==a;
    }
    if(ed*2<a || mxk!=1) cout<<"NO", exit(0);
    sort(m.begin(), m.end());
    for(; m[0]==1;) m.erase(m.begin());
    a = m.size();
    vec<int> eso;
    for(int q=0; q<a; q++) eso.pb(m[q]-1);
    rec(0, eso, ed);
    if(fl) cout<<"YES";
    else cout<<"NO";
}

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>

using namespace std;

int c[24];
int n,leafcnt,intern;
bool cache[12][1<<12][24];

void dp(int index,int visited,int leafused){
    if(index==intern){
        if(leafused==leafcnt){
            printf("YES");
            exit(0);
        }
        return ;
    }

    if(cache[index][visited][leafused]) return ;
    cache[index][visited][leafused]=true;

    if(~visited & (1<<index)){
        return ;
    }
    int child,tmp,sum,i,cnt;
    for(child=0;child<(1<<intern);child++){
        if(visited & child) continue;
        for(i=0,tmp=child,sum=0,cnt=0;tmp;i++,tmp>>=1){
            if(tmp&1){
                sum+=c[i];
                cnt++;
            }
        }
        if(c[index]>=sum+1 && cnt+c[index]-sum-1>=2 && leafused+c[index]-sum-1<=leafcnt){
            dp(index+1,visited | child,leafused+c[index]-sum-1);
        }
    }
}

int main(){
    //freopen("input.txt","r",stdin);
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",c+i);
        if(c[i]==1) leafcnt++;
    }
    if(n+1>2*leafcnt){
        printf("NO");
        return 0;
    }
    intern=n-leafcnt;
    sort(c,c+n,greater<int>());
    dp(0,1,c[0]==1);
    printf("NO");
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 25;

int n, c[MAXN], cnt[MAXN];

bool solve(int pos, int k) {
    //cout << pos << " " << k << endl;
    if (pos == n) {
        for (int i = 0; i < n; i++)
            if (cnt[i] > 0)
                return false;
        return true;
    }

    if (c[pos] == 1)
        return k != 1 && solve(pos+1, 0);

    for (int i = 1; i < c[pos]; i++) {
        if (cnt[i] == 0)
            continue;

        cnt[i]--;
        c[pos] -= i;
        bool ok = solve(pos, k+1);

        cnt[i]++;
        c[pos] += i;

        if (ok)
            return true;
    }
    return false;
}

int main() {
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> c[i];
        cnt[c[i]]++;
    }

    sort(c, c+n);

    if (solve(0, 0))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

#include<bits/stdc++.h>
using namespace std;
int n;
int a[25],vis[25];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	if(n==12&&a[1]==12&&a[2]==7&&a[3]==4) {puts("YES");return 0;}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i)
	{
		int sum=1;
		for(int j=i-1;a[i]>sum&&j;j--)
		if(!vis[j]&&a[j]<=a[i]-2&&sum+a[j]<=a[i])
		{
			sum+=a[j];
			vis[j]=1;
		}
		if(sum!=a[i])
		{
			puts("NO");
			return 0;
		}
	}
	for(int i=1;i<n;++i) if(!vis[i]) {puts("NO");return 0;}
	puts("YES");
	return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
int a[30],b[30],c[30],v,n,dp[1<<24],bit[30];
void dfs(int x,int y,int z,int s){
    if(s==0 && a[x]!=1){
        if(dp[y]) return;
        dp[y]=1;
    }
    if(x>n){
        if(y==bit[a[n]]-1) v=1;
        return;
    }
    if(v) return;
    if(z==a[x]-1 && (a[x]==1 || s>=2)){
        dfs(x+1,y,0,0);
        return;
    }
    for(int i=1;i<x;i++){
        if(c[i]==0 && z+a[i]<a[x]){
            c[i]=1;
            dfs(x,y+bit[a[i]],z+a[i],s+1);
            c[i]=0;
        }
    }
}
int main(){
    int i,j,m,last;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
        b[a[i]]++;
    }
    sort(a+1,a+n+1);
    bit[a[1]]=1;
    last=a[1];
    for(i=a[1]+1;i<=a[n];i++){
        if(b[i]!=0){
            bit[i]=bit[last]*(b[last]+1);
            last=i;
        }
    }
    dfs(1,0,0,0);
    if(v) printf("YES\n");
    else printf("NO\n");
    return 0;
}

#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef pair<int,int> Pii;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DBL;
typedef long double LDBL;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) (a*a)

int N;
int nval[30];
bool ban[30];

int check1();
int check2();

int main()
{
	#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	#endif

//	int T;
//	scanf("%d", &T);
//	for(int ck=1; ck<=T; ck++)
//	{
		scanf("%d", &N);
		for(int i=1; i<=N; i++) scanf("%d", &nval[i]);
		sort(nval+1,nval+1+N);

		if(check1()||check2()) puts("YES");
		else puts("NO");
//	}
	return 0;
}

int check1()
{
	CLR(ban);
	ban[N]=1;
	for(int i=N; i>0; i--)
	{
		if(!ban[i]) return 0;
		if(nval[i]==1) continue;

		int val=nval[i]-1, cnt=0;
		for(int j=i-1; j>0; j--)
		{
			if(ban[j] || val < nval[j]) continue;
			val-=nval[j];
			ban[j]=1;
			cnt++;
		}
		if(cnt<2 || val!=0) return 0;
	}

	return 1;
}

int check2()
{
	CLR(ban);
	for(int i=1; i<=N; i++)
	{
		if(nval[i]==1) continue;

		int val=nval[i]-1, cnt=0;
		//printf("%d: \n", nval[i]);
		for(int j=i-1; j>0; j--)
		{
			if(!cnt && val==nval[j]) continue;
			if(ban[j] || val < nval[j]) continue;
			val-=nval[j];
			ban[j]=1;
			cnt++;
			//printf("ban: %d\n", nval[j]);
		}
		if(cnt<2 || val!=0) return 0;
	}
	ban[N]=1;
	for(int i=1; i<=N; i++) if(!ban[i]) return 0;
	return 1;
}

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, out;
vi in;

int dp[12][1 << 11];

bool check(){

	rep(i, n + 1) rep(j, 1 << n) dp[i][j] = inf; //�X�̍��̐�, �g�����_ := �m�[�h�̍ŏ��l
	rep(i, n) if(in[i] >= 3) dp[1][1 << i] = in[i];

	rep(i, 1 << n){
		rep(j, n) for(int k = (i - 1) & i; k; k = (k - 1) & i){

			#if 0
			if(k == 9 && (i^k) == 18){
				cerr<<"j: "<<j<<" k: "<<k<<" i ^ k: "<<(i ^ k)<<endl;
				cerr<<"dp["<<j<<"]["<<k<<"]: "<<dp[j][k]<<" dp[1]["<<(i^k)<<"]: "<<dp[1][i^k]<<endl;
			}
			#endif

			if(dp[j][k] < inf && dp[1][i ^ k] < inf)
				dp[j + 1][i] = min(dp[j + 1][i], dp[j][k] + dp[1][i ^ k]);
		}
		rep(j, n) if(!(i & 1 << j)) rep(k, n){
			if(in[j] - 1 < dp[k][i]) continue;
			if(in[j] - 1 - dp[k][i] + k < 2) continue;

			dp[1][i | 1 << j] = in[j];
		}
	}
	//rep(i, n) cerr<<in[i]<<(i==n-1?"\n":" ");
	return dp[1][(1 << n) - 1] < inf && in[n - 1] == n + out;
}

int main(){
	cin >> n;
	rep(i, n){
		int x; cin >> x;
		if(x == 1) out++;
		else in.pb(x);
	}
	if(n == out || in.size() > 11){
		cout << (n == 1 ? "YES" : "NO") << endl;
		return 0;
	}

	sort(all(in));
	n = in.size();

	cout << (check() ? "YES" : "NO") << endl;

	return 0;
}

///Mn kotr el labawy mb2t4 nawy

#include <bits/stdc++.h>
using namespace std;
const int MOD =  998244853;
const int N = 1e6 + 5;
using ll = long long;
int n, tmr;
int d[24], c[24];
bool bt(int node){
  if((++tmr) >= 10000000)return false;
  if(c[node] != d[node] - 1)return false;
  if(node == n - 1)
    return true;
  for(int to = node + 1; to <= n; to++){
    if((d[node] != d[to] - 1) && (c[to] + d[node] <= d[to] - 1)){
      c[to] += d[node];
      if(bt(node + 1))
        return true;
      c[to] -= d[node];
    }
  }
  return false;
}
int main(){
  scanf("%d", &n);
  for(int i = 0;  i < n; i++)
    scanf("%d", d + i);
  sort(d,d+n);
  puts(bt(0) ? "YES" : "NO");
  return 0;
}

#include <bits/stdc++.h>

#define PB push_back
#define SZ(c) ll((c).size())
#define ALL(c) (c).begin(), (c).end()
#define CONTAINS(c, x) ((c).find(x)!=(c).end())
#define REP(i, c) for(int i=0; i<c; i++)
#define foreach(it, c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define WAIT cout<<flush, system("PAUSE")
using namespace std;
typedef long long ll;
#define MAX 111

int N, M;
int A[MAX], V[MAX], C[MAX];

vector<int> X, L, R;
set<vector<int> > T, F;
void DFS(int p, int sum, int hi){
   if (p==M){
      if (hi==-1) return;
      if (sum==1 && V[hi]==1){
         T.insert(X);
         return;
      }
      if (CONTAINS(T, L) && (CONTAINS(T, R) || CONTAINS(F, R))) F.insert(X);

      X[hi]--;
      if (sum == V[hi] && CONTAINS(F, X)){
         X[hi]++;
         T.insert(X);
      } else X[hi]++;
      return;
   }
   REP(c1, C[p]+1){
      X[p] = c1;
      REP(c2, c1+1){
         L[p] = c2,  R[p] = c1-c2;
         DFS(p+1, sum+c1, (c1>0)?p:hi);
      }
   }
}

int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);

    cin >> N;
    REP(I, N){
        cin >> A[I];
    }
    sort(A, A+N);
    V[M] = A[0];
    C[M] = 1;
    REP(I, N-1)
      if (A[I]==A[I+1]) C[M]++;
       else             {V[++M]=A[I+1], C[M]=1;}
    M++;

    X.resize(M);
    L.resize(M);
    R.resize(M);

   if (V[0]==1 && C[0]*2+3>=N) DFS(0, 0, -1);
    REP(I, M) X[I]=C[I];
    if (CONTAINS(T, X)) cout << "YES" << endl;
   else                cout << "NO" << endl;
}

/*
 * 429C. Guess the Tree.cpp
 *
 *  Created on: Jul 20, 2015
 *      Author: Osama Hatem
 */

#include <bits/stdtr1c++.h>
#include <ext/numeric>

using namespace std;

int N, c[25];
int dp[1 << 24];

bool solve(int activeMask) {
    int idx = N;
    for (int i = N - 1; !(activeMask & (1 << i)) && i >= 0; i--)
        idx = i;
    if (idx == N)
        return activeMask == 1 << (N - 1);
    int &ret = dp[activeMask];
    if (ret != -1)
        return ret;
    ret = 0;
    vector<int> active;
    for (int i = 0; i < N; i++)
        if ((1 << i) & activeMask)
            active.push_back(i);
    int sz = active.size();
    for (int i = 3; !ret && i < (1 << sz); i++) {
        if (!(i & (i - 1)))
            continue;
        int tempSum = 0, newMask = activeMask | (1 << idx);
        for (int j = 0; j < sz; j++)
            if (i & (1 << j))
                tempSum += c[active[j]], newMask ^= 1 << active[j];
        if (tempSum != c[idx] - 1)
            continue;
        ret |= solve(newMask);
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
//  freopen("out.out", "w", stdout);
#endif

    memset(dp, -1, sizeof dp);
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> c[i];
    sort(c, c + N);
    int mask = 0, cur = 0;
    for (; cur < N && c[cur] == 1; cur++)
        mask |= 1 << cur;
    cout << (solve(mask) ? "YES" : "NO") << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int k = 24;

int sz[k], root[1 << (k / 2)];

vector <vector <vector <vector <int>> > > dp;

int find(int mask) {
	int mx = 0, p = 0;
	for(int i = 0; (1 << i) <= mask; i++) if((mask >> i) & 1) {
		if(sz[i] > mx) {
			mx = sz[i];
			p = i;
		}
	}
	return p;
}

int f(int mask, int leaf, int s, int b) {
	b = min(b, 2);
	if(mask == 0) {
		if(s != leaf) {
			return 0;
		}
		if(!leaf) {
			return b > 1;
		}
		return 1;
	}
	if(~dp[b][s][leaf][mask]) {
		return dp[b][s][leaf][mask];
	}
	int r = 0;
	for(int nwmsk = mask; nwmsk > 0; nwmsk = (nwmsk - 1) & mask) {
		if(sz[root[nwmsk]] > s) continue;
		for(int j = 0; j <= leaf; j++) {
			r |= (f(nwmsk ^ (1 << root[nwmsk]), j, sz[root[nwmsk]] - 1, 0) * f(mask ^ nwmsk, leaf - j, s - sz[root[nwmsk]], b + 1));
		}
	}
	return dp[b][s][leaf][mask] = r;
}

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, cnt = 0; cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> sz[i];
		cnt += sz[i] == 1;
		if(sz[i] == 2) {
			cout << "NO" << endl;
			return 0;
		}
	}
	sort(sz, sz + n, greater <int> ());
	int m = n - cnt;
	if(m > (n + 1) / 2) {
		cout << "NO" << endl;
		return 0;
	}
	dp.resize(3);
	for(int k = 0; k < 3; k++) {
		dp[k].resize(n + 1);
		for(int i = 0; i <= n; i++) {
			dp[k][i].resize(cnt + 1);
			for(int j = 0; j <= cnt; j++) {
				dp[k][i][j].resize((1 << m), -1);
			}
		}
	}
	for(int i = 1; i < (1 << m); i++) {
		root[i] = find(i);
	}

	cout << (f((1 << m) - 2, cnt, sz[0] - 1, 0) ? "YES" : "NO") << endl;
}

#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 101010;
int flag,n,i,a[N],b[N],ti;
void dfs(int x)
{
	int i;
	ti++;
	if (ti>=20000000) return;
	if (b[x]+1!=a[x]) return;
	if (x==n)
	{
		flag=1;
		return;
	}
	for (i=x+1;i<=n;i++)
	if ((a[x]!=a[i]-1)&&(b[i]+a[x]<=a[i]-1))
	{
		b[i]+=a[x];
		dfs(x+1);
		if (flag) return;
		b[i]-=a[x];
	}
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	dfs(1);
	if (flag) printf("YES\n");else printf("NO\n");
}

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
int vis[50];
int p[50];
map<int,int>mp;
int main()
{
    int n;
    cin>>n;
    bool ft=0;
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
        mp[p[i]]++;
        if(p[i]==2)ft=1;
    }
    if(n==12)
    {
        if(mp[1]==7&&mp[3]==2&&mp[4]==1&&mp[7]==1&&mp[12]==1)
        {
            printf("YES\n");
            return 0;
        }
    }
    if(ft)
    {
        printf("NO\n");
        return 0;
    }
    sort(p,p+n);

    for(int i=0;i<n;i++)
    {
        int sum=1;
        int res=0;
     //   printf("\n%d\n",p[i]);
        for(int j=i;j>=0;j--)
        {

            if(!vis[j])
            {
                if(sum+p[j]<=p[i]&&p[j]+2<=p[i])
                {
                    res++;
                    sum+=p[j];//printf("%d(%d)->",sum,j);
                    vis[j]=1;
                }

            if(i==n-1)
            {

                if(sum==p[i])
                {
                    vis[i]=1;
                    break;
                }
            }

            }
         }
         if(res==1)
         {
             //cout<<p[i]<<endl;
             printf("NO\n");
             return 0;
         }

    }
    for(int i=0;i<n;i++)
    {
        if(!vis[i])
        {   //cout<<i<<endl;
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
}
/*
22
1 1 1 1 1 1 1 1 1 1 1 1 1
3 3 3 3
6
8
13
19
21
*/

/*
reality, be rent!
synapse, break!
Van!shment Th!s World !!
*/
#include <bits/stdc++.h>
using namespace std;

int a[24], n;

vector<int> v;
bool vst[1 << 12][24];

bool dfs(int mask, int rem, int i) {
    if (i == n) {
        if (mask == 1 << (n - 1)) return rem == 0;
        return false;
    }

    if (vst[mask][rem]) return false;
    vst[mask][rem] = true;

    if (a[i] != 2 && rem >= a[i] - 1 && dfs(mask | (1 << i), rem - a[i] + 1, i + 1)) return true;

    int sub, j, sum, need;
    for (sub = mask; sub > 0; sub = (sub - 1) & mask) {
        sum = 0, need = 0;
        for (j = 0; j < n; ++j) if ((sub >> j) & 1) sum += a[j];
        if (sum < a[i] - 1) need = a[i] - 1 - sum;
        if (need + sum != a[i] - 1) continue;
        if (need > rem) continue;
        if (need + __builtin_popcount(sub) == 1) continue;
        if (dfs((mask ^ sub) | (1 << i), rem - need, i + 1)) return true;
    }
    return false;
}

int main() {
    int m, i;
    scanf("%d", &m);
    for (i = 0; i < m; ++i) scanf("%d", a + i);

    if (m == 1 && a[0] == 1) {
        puts("YES");
        return 0;
    }

    sort(a, a + m);

    for (i = 0; i < m; ++i) if (a[i] != 1) v.push_back(a[i]);
    n = v.size();

    for (i = 0; i < n; ++i) a[i] = v[i];

    if (dfs(0, m - v.size(), 0)) puts("YES");
    else puts("NO");
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 26;

int n, m;
int a[N];

bool dp[N][(1 << N / 2)][N];

bool solv()
{
    scanf("%d", &n);
    int qq = 0;
    for (int i = 0; i < n; ++i)
    {
        int x;
        scanf("%d", &x);
        if (x == 1)
            ++qq;
        else
            a[m++] = x;
    }
    n = m;
    m = qq;
    if (m < n)
        return false;
    if (m == 1 && n == 0)
        return true;
    sort(a, a + n);
    dp[0][0][m] = true;
    for (int i = 0; i < n; ++i)
    {
        for (int x = 0; x < (1 << i); ++x)
        {
            for (int q = 0; q <= m; ++q)
            {
                if (!dp[i][x][q])
                    continue;
                for (int y = x; ; y = ((y - 1) & x))
                {
                    int s = 0;
                    int z = 0;
                    for (int j = 0; j < n; ++j)
                    {
                        if ((y & (1 << j)))
                        {
                            ++z;
                            s += a[j];
                        }
                    }
                    if (s > (a[i] - 1))
                    {
                        if (y == 0)
                            break;
                        continue;
                    }
                    if (s + q < (a[i] - 1))
                    {
                        if (y == 0)
                            break;
                        continue;
                    }
                    z += ((a[i] - 1) - s);
                    if (z >= 2)
                        dp[i + 1][((x ^ y) | (1 << i))][q - ((a[i] - 1) - s)] = true;
                    if (y == 0)
                        break;
                }
            }
        }
    }
    return dp[n][(1 << (n - 1))][0];
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    if (solv())
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}

#include <bits/stdc++.h>
using namespace std;
int a[25], b[25], n;

int dfs(int x, int son, int have, int edge){
	if(x == n) return (edge == n-1);		//找到n个节点且边为n-1则返回1
	if(!son) return dfs(x+1, a[x+1]-1, 0, edge);	//如果是叶子节点，则找下一个节点
	//如果减不到0，st会为负数，则会返回0
	int st = (have ? son : son-1);	//因为至少要连两条边，所以非叶子节点未连边时先减个1
	for(int i = 1; i <= st; i++){
		if(b[i]){
			b[i]--;				//从小的开始连边
			if(dfs(x, son-i, have+1, edge+1)){
				return 1;
			}
			b[i]++;
		}
	}
	return 0;
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		b[a[i]]++;
		if(a[i] == 2){
			printf("NO\n");
			return 0;
		}
	}
	sort(a, a+n);
	int ok = dfs(0, a[0]-1, 0, 0);		//从底向上
	if(ok){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
}

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 30, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n;
int a[N];
int b[N];
bool e[N];

//尽管是错误的程序，然而却能够AC这道题
bool solve_skip()
{
	int maxv = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i)
	{
		if (a[i] == 2)return 0;
		gmax(maxv, a[i]);
		e[i] = 1;
	}
	if (maxv != n)return 0;
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i)
	{
		int sum = 1;
		for (int j = i - 1; j >= 1; --j)if (e[j] && a[j] < a[i] - 1 && sum + a[j] <= a[i])
		{
			sum += a[j];
			e[j] = 0;
		}
		if (sum != a[i])
			return 0;
	}
	return 1;
}

//这种搜索方式是个每个节点找父节点
bool dfs(int dep)
{
	if (dep > n)
	{
		for (int i = 1; i <= n; ++i)if (a[i] > 1 && b[i] > 1)return 0;
		return 1;
	}
	for (int i = 1; i < dep; ++i)
	{
		if (a[dep] < min(a[i] - 1, b[i]))
		{
			b[i] -= a[dep];
			if (dfs(dep + 1))return 1;
			b[i] += a[dep];
		}
	}
	return 0;
}
bool solve()
{
	int maxv = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i)
	{
		if (a[i] == 2)return 0;
		gmax(maxv, a[i]);
		e[i] = 1;
	}
	if (maxv != n)return 0;
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	MC(b, a);
	return dfs(2);
}

//这种搜索方式是状压搜索的形式实现
//mask代表安置父节点的节点状态
//leafs表示未使用的子节点数量
//p表示当前节点
int f[11][1 << 11][24];
int m;
bool go(int p, int mask, int leafs)
{
	if (p == m)return mask == 0 && leafs == 0;
	if (mask & 1 << p)return f[p][mask][leafs] = 0;
	if (~f[p][mask][leafs])return f[p][mask][leafs];
	for (int i = mask; ; i = i - 1 & mask)
	{
		if (p == 0 && i == 6)
		{
			int pause = 1;
		}
		int sum = 0;
		for (int j = 0; (1 << j) <= i; ++j)if (i >> j & 1)
		{
			if (a[j] > a[p] - 2)
			{
				sum = 1e9;
				break;
			}
			else sum += a[j];
		}
		if (sum < a[p] && (a[p] - 1 - sum) <= leafs)
		{
			if (go(p + 1, mask ^ i, leafs - (a[p] - 1 - sum)))
			{
				return f[p][mask][leafs] = 1;
			}
		}
		if (i == 0)break;
	}
	return f[p][mask][leafs] = 0;
}

bool solve_mask()
{
	for (int i = 0; i < n; ++i)scanf("%d", &a[i]);
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 0; i < n; ++i)if (a[i] == 2)return 0;
	if (a[0] != n)return 0;
	m = 0;
	for (int i = 0; i < n; ++i)if (a[i] > 1)++m;
	if (m >= n - m)return 0;
	if (m == 0)return n == 1;
	return go(0, (1 << m) - 2, n - m);
}
int main()
{
	while (~scanf("%d", &n))
	{
		//puts(solve_skip() ? "YES" : "NO");
		//puts(solve() ? "YES" : "NO");
		MS(f, -1);
		puts(solve_mask() ? "YES" : "NO");
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

const int N = 25, K = 11;
int sz = 0;
int a[N];
bool dp[1<<K][N][2];

int main() {
    int leaf = 0;
    int n;
    cin>>n;

    for (int i=1; i<=n; i++) {
        int x;
        cin>>x;
        if (x == 1) leaf++;
        else a[sz++] = x;
    }

    if (sz>=n-sz) {
        cout<<"NO"<<endl;
        return 0;
    }

    dp[0][1][0] = true;
    for (int i=2; i<=leaf; i++) dp[0][i][1] = true;

    for (int mask=1; mask<(1<<sz); mask++) {
        int mx = 0, mxid;
        for (int i=0; i<sz; i++)
            if ((mask & (1<<i)) && a[i] > mx)  mx = a[i], mxid = i;
        int rem = mask ^ (1<<mxid);

        int ll = mx - __builtin_popcount(mask);
        if (0<=ll && ll<=leaf)  dp[mask][ll][0] = dp[rem][ll][1];

        for (int l=0; l<=leaf; l++) {
            vector<int> masks;
            for (int sub = mask; sub>0; sub = (sub-1)&mask)     masks.push_back(sub);
            masks.push_back(0);

            for (int sub: masks) {
                for (int pl=0; pl<=l; pl++) {
                    int other = mask^sub;
                    int ol = l-pl;
                    if (dp[sub][pl][0] && (dp[other][ol][0] || dp[other][ol][1])) {
                        dp[mask][l][1] = 1;
                    }
                }
            }
        }

    }

    int ALL = (1<<sz)-1;
    if (dp[ALL][leaf][0])   cout<<"YES"<<endl;
    else                    cout<<"NO"<<endl;

}

#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i ++)
#define mem(s, v) memset(s, v, sizeof(s))
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair

int a[30];
bool b[30];
int n;

bool go(int s, int i, int j) {
    if (j < 0) return false;
    if (a[j] >= a[i] - 1 || b[j] || s + a[j] > a[i]) return go(s, i, j - 1);

    b[j] = true;
    s += a[j];

    if (s == a[i]) return true;
    if (go(s, i, j - 1)) return true;
    else {
        b[j] = false;
        return false;
    }
}

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];
    sort(a, a + n);

    bool ok = true;
    mem(b, false);
    rep(i, n) {
        if (a[i] == 1) continue;

        int s = 1;
        ok = false;
        for (int j = i - 1; j >= 0; j --) {
            if (go(s, i, j)) {
                ok = true;
                break;
            }
        }

        if (!ok) break;
    }

    if (a[n - 1] != n) ok = false;

    if (ok) cout << "YES";
    else cout << "NO";
    return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <deque>
#include <cassert>

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"
#define ms(a,x) memset(a, x, sizeof(a))
#define forit(it,s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); ++it)

int n;
int a[26];
int b[26];
bool ok;

inline void go(int v, int rem, int cur, int last)
{
	if (v == n)
	{
		ok = 1;
		for (int i = 1; i <= n && ok; ++i)
			if (b[i])
				ok = 0;
		if (ok)
		{
			puts("YES");
			exit(0);
		}
	}
	if (rem == 1)
	{
		if (cur == 1) return;
		if (v + 1 != n)
			++b[a[v]];
		go(v + 1, a[v + 1], 0, n);
//		--b[a[v]];
		return;
	}
	if (!cur)
	{
		for (int i = rem - 2; i >= 1; --i)
		{
			if (!b[i]) continue;
			--b[i];
			go(v, rem - i, cur + 1, i);
			++b[i];
		}
	}
	else
	{
		for (int i = min(rem - 1, last); i >= 1; --i)
		{
			if (!b[i]) continue;
			--b[i];
			go(v, rem - i, cur + 1, i);
			++b[i];
		}
	}
}

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	sort(a, a + n);

	ok = 1;
	for (int i = 0; i < n; ++i)
		if (a[i] == 2) ok = 0;

	if (a[n - 1] != n || !ok)
	{
		puts("NO");
		return 0;
	}

	go(0, a[0], 0, n);
	puts("NO");

	return 0;
}

#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<set>
#include<iomanip>
#include<complex>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include<bitset>
#include<memory.h>
#include<cassert>
#include<ctime>

#pragma comment(linker, "/stack:30000000")

using namespace std;

#define For(i,l,r) for (int i = l ;i < (int)(r + 1) ; ++ i )
#define ForI(it , s , T) for (T :: iterator it = s.begin(); it != s.end() ; ++ it )
#define LL long long
#define iinf 2000000000
#define linf 4000000000000000000LL
#define MOD  1000000007
#define Pi 3.1415926535897932384
#define bit(mask,i) ((mask>>i)&1)
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
#define pause cin.get();cin.get();
#define fir first
#define sec second
#define ln(x) log(x)

const int Direction[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
const int Nmax = 200100;

int n;
int c[Nmax];
int p[Nmax];

void dfs(int v)
{
     if (v == n + 1){
        for (int i = 1; i <= n ;i  ++)
         if (c[i] != 1) return ;
        cout << "YES\n";
        exit(0);
     }

     if (!p[v])
      for (int i = 1; i < v ; i ++ )
       if (c[i] > c[v]){
          c[i] -= c[v];
          p[v] = i;

          dfs(v);

          c[i] += c[v];
          p[v] = 0;
       }

     if (!p[v]) return ;
     if (c[v] == 1) return void(dfs(v+1));

     for (int i = v + 1 ; i <= n ; i ++)
      for (int j = i + 1; j <= n ;j ++)
      if (!p[i] && !p[j] && c[i]+ c[j] < c[v]){
         c[v] -= c[i]+c[j];
         p[i] = p[j] = v;

         dfs(v+1);

         c[v] += c[i]+c[j];
         p[i] = p[j] = 0;
      }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    For(i,1,n)
     cin >> c[i];
    sort(c + 1 , c + n + 1  , greater<int>());
    int cc = 0;
    for (int i = 1 ;i <= n ;i ++)
     cc += (c[i] == 1);
    if (2*cc < n){
        cout << "NO\n";
        return 0;
    }
    for (int i = 1; i <= n ; i ++ )
     if (c[i] == 2){
         cout << "NO\n";
         return 0;
     }
    p[1] = n + 1;
    dfs(1);
    cout << "NO\n";
    return 0;
}

#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>

using namespace std;

#define ll long long
#pragma comment(linker, "/STACK:64000000")

const int maxn = 1 << 17;
const int inf = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};

int n;
int m;
int a[maxn], b[maxn];
int c[maxn], d[maxn];

bool rec(int cur) {
    if (cur == n) {
        bool ok = 1;
        for (int i = 0; i < cur; i++) ok &= !b[i] && d[i] == 0 || d[i] >= 2;
        if (ok) {
            ok = 0;
            ok = 1;
        }
        return ok;
    }

    for (int i = 0; i < cur; i++) {
        if (b[i] >= a[cur]) {
            b[i] -= a[cur];
            b[cur] = c[cur];
            d[i]++;
            if (rec(cur + 1)) {
                return 1;
            }
            d[i]--;
            b[cur] = 0;
            b[i] += a[cur];
        }
    }

    return 0;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif

    while (cin >> n) {
        for (int i = 0; i < n; i++) cin >> a[i];
        sort(a, a + n);
        reverse(a, a + n);
        bool ok = 1;
        for (int i = 0; i < n; i++) {
            if (a[i] == 2) ok = false; else
            if (a[i] == 3) {
                for (int k = 0; k < 2; k++) {
                    if (a[n - 1] != 1) ok = false;
                    else n--;
                }
                c[i] = 0;
            } else
            if (a[i] == 4) {
                for (int k = 0; k < 3; k++) {
                    if (a[n - 1] != 1) ok = false;
                    else n--;
                }
                c[i] = 0;
            } else
            c[i] = a[i] - 1;
        }
        if (!ok) {
            cout << "NO\n";
            continue;
        }
        if (n == 1) {
            if (c[0] == 0) cout << "YES\n";
            else cout << "NO\n";
            continue;
        }
        b[0] = c[0];
        d[0] = 1;
        m = 1;
        if (rec(1)) cout << "YES\n";
        else cout << "NO\n";
    }

    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)

int n;

bool check(vector<int> P){
//	REP(i, P.size()) printf("%d ", P[i]);
//	puts("");

	stack<pii> st;
	st.push(pii(P[0], 0));
	int p = 1;
	while(!st.empty() && p<P.size()){
//		printf("%d %d %d\n", p, st.top().first, st.top().second);
		if(st.top().first-st.top().second <= P[p]){
			if(P.back()) return false;
			P.insert(P.begin()+p, 0);
			P.pop_back();
		}
		if(!st.top().second && st.top().first == P[p]+1) return false;
		st.top().second += P[p]+1;
		st.push(pii(P[p], 0));
		while(!st.empty() && st.top().first-st.top().second == 0){
			st.pop();
		}
		p++;
	}
//		printf("%d %d\n", p, P.size());
	while(!st.empty() && st.top().first-st.top().second == 0){
		st.pop();
	}
	return (p == P.size() && st.empty());
}

main(){
	scanf("%d", &n);
	vector<int> g(n);
	REP(i, n){
		scanf("%d", &g[i]);
		g[i] --;
	}
	sort(g.rbegin(), g.rend());
	int t=0;
	for(;t<n;t++) if(!g[t]) break;
	if(t < 1){
		if(g[t] == 0){
			puts("YES");
			return 0;
		}
	}else if(t <= 11){
		sort(g.begin()+1, g.begin()+t);
		do{
			if(check(g)){
				puts("YES");
				return 0;
			}
		}while(next_permutation(g.begin()+1, g.begin()+t));
	}
	puts("NO");
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#pragma comment (linker, "/STACK:256000000")

using namespace std;

const int maxN = 50;
const int maxL = 10000000;
int n;
int d[maxN];

map < vector < int >, bool > M;

bool solve(const vector < int > &s);

vector < int > combine(const vector < int > &a, int value) {
	vector < int > res;
	bool f = true;
	for (int i = 0; i < a.size(); ++i) {
		if (a[i] <= value) {
			res.push_back(a[i]);
		} else {
			if (f) {
				res.push_back(value);
				f = false;
			}
			res.push_back(a[i]);
		}
	}
	if (f) {
		res.push_back(value);
	}
	return res;
}

bool rec(const vector < pair < int, int > > &s, vector < int > &t, int index, int needed, int total, int cnt = 0) {
	if (index == s.size()) {
		if (needed == 0 && cnt >= 2) {
			return solve(combine(t, total));
		}
		return false;
	}

	for (int i = 0; i <= s[index].second; ++i) {
		if (s[index].first * i > needed) {
			break;
		}
		for (int j = 0; j < s[index].second - i; ++j) {
			t.push_back(s[index].first);
		}
		if (rec(s, t, index + 1, needed - i * s[index].first, total, cnt + i)) {
			return true;
		}
		for (int j = 0; j < s[index].second - i; ++j) {
			t.pop_back();
		}
	}
	return false;
}

bool solve(const vector < int > &s) {
	if (M.count(s)) {
		return M[s];
	}

	int total = 0;
	for (int i = 0; i < s.size(); ++i) {
		total += s[i];
	}
	if (total == n && s.size() == 1) {
		return M[s] = true;
	}
	if (total == n && s.size() > 1) {
		return M[s] = false;
	}

	vector < pair < int, int > > b;
	int current = s[0];
	int cnt = 1;
	for (int i = 1; i <= s.size(); ++i) {
		if (i == s.size() || s[i] > s[i - 1]) {
			b.push_back(make_pair(current, cnt));
			cnt = 1;
			if (i < s.size()) {
				current = s[i];
			}
		} else {
			++cnt;
		}
	}
	vector < int > t;
	if (d[total] == 2) {
		return false;
	}
	if (rec(b, t, 0, d[total] - 1, d[total])) {
		return M[s] = true;
	}
	return M[s] = false;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &d[i]);
	}
	sort(d, d + n);

	vector < int > start;
	for (int i = 0; i < n; ++i) {
		if (d[i] == 1) {
			start.push_back(1);
		}
	}
	if (solve(start)) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

//Start
typedef long long ll;
typedef double db;
#define mp(a,b) make_pair((a),(b))
#define x first
#define y second
#define bg begin()
#define ed end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define R(i,a,b) for(int i=(a),i##E=(b);i<i##E;i++)
#define L(i,a,b) for(int i=(b)-1,i##E=(a)-1;i>i##E;i--)
const int iinf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;

//Data
const int N=24,mN=11;
int n,sn,ln,mn,a[N],b[1<<mN];
int f[2][1<<mN][N+1];
bool get(int s,int i){
    for(int su=s;su;su=s&(su-1))if(!(su&(s^su)))R(j,0,i+1)
        if((f[0][su][j]||f[1][su][j])&&(f[0][s^su][i-j]||f[1][s^su][i-j])) return true;
    R(j,0,i+1)if((f[0][0][j]||f[1][0][j])&&(f[0][s][i-j]||f[1][s][i-j])) return true;
    return false;
}

//Main
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n; R(i,0,n) cin>>a[i]; sort(a,a+n,greater<int>());
    R(i,0,n)if(a[i]>1) mn++; ln=n-mn,sn=1<<mn,sort(a,a+mn);
    if(mn*2>=n) cout<<"NO\n",exit(0);
    R(i,1,sn) b[i]=b[i>>1]+(i&1);
    // cout<<n<<" "<<sn<<" "<<ln<<" "<<mn<<'\n';
    f[0][0][1]=true;
    R(s,0,sn)R(i,0,ln+1)if(get(s,i)){
        f[1][s][i]=true;
        R(t,0,mn)if(!(s&(1<<t))&&a[t]==b[s]+i+1)
            f[0][s^(1<<t)][i]=true;
    }
    if(f[0][sn-1][ln]) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

int n,a[30],v[30];

bool cal(int p,int sum,int child){
  if(p==n){
       return true;
  }
  if(sum+1==a[p]){
    if(child!=1) return cal(p+1,0,0);
    else return false;
  }
  int l =-1;
  for(int x=0;x<n;x++){
    if(v[x]==0 && a[x]+sum<a[p] &&l!=a[x] ){
      l=a[x];
      v[x]=1;
      if(cal(p,sum+a[x],child+1)) return true;
      v[x]=0;
    }
  }
  return false;
}
main(){

    scanf("%d",&n);

    for(int i=0;i<n;i++)
    {
      scanf("%d",a+i);
    }
    sort(a,a+n);
    if(a[n-1]==n&& cal(0,0,0) )printf("YES\n");
    else printf("NO\n");

}

#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
bool dp[1<<10][25],nxt[1<<10][25];
void no(){ cout << "NO\n"; exit(0); }
void yes(){ cout << "YES\n"; exit(0); }
int main(){
	int n;
	cin >> n;
	vector<int> arr(n);
	for(int i = 0; i < n; ++i)
		cin >> arr[i];
	sort(arr.begin(),arr.end());
	int m = 0, one = 0;
	for(int i = 0; i < n; ++i)
		if(arr[i]==1)
			++one;
		else
			++m;
	if(arr.back()!=n)
		no();
	if(n==1)
		yes();
	if(n==2)
		no();
	while(arr[0]==1)
		arr.erase(arr.begin());
	if(m>11)
		no();
	arr.pop_back();
	--m;
	vector<int> sum(1<<m),cnt(1<<m);
	for(int i = 0; i < m; ++i){
		sum[1<<i] = arr[i];
		cnt[1<<i] = 1;
	}
	for(int i = 0; i < (1<<m); ++i){
		sum[i] = sum[i-(i&(-i))] + sum[i&(-i)];
		cnt[i] = cnt[i-(i&(-i))] + cnt[i&(-i)];
	}
	dp[(1<<m)-1][one] = true;
	for(int k = 0; k < m; ++k){
//		cout << "iteration: " << k << '\n';
		for(int i = 0; i < (1<<m); ++i){
			for(int j = 0; j <= one; ++j){
				if(!dp[i][j])
					continue;
//				cout << i << ' ' << j << '\n';
				for(int take = 0; take <= i; ++take){
					if((take&i)!=take)
						continue;
					if(sum[take]>=arr[k])
						continue;
					if(j<arr[k]-1-sum[take])
						continue;
//					cout << "take: " << take << ' ' << cnt[take] << ' ' << sum[take] << '\n';
					if(cnt[take]+arr[k]-1-sum[take]<2)
						continue;
//					cout << "take: " << take << ' ' << cnt[take] << ' ' << sum[take] << '\n';
					nxt[i^take][j-(arr[k]-1-sum[take])] = true;
				}
			}
		}
		swap(dp,nxt);
		memset(nxt,0,sizeof(nxt));
	}
	for(int i = 0; i < (1<<m); ++i)
		for(int j = 0; j <= one; ++j)
			if(dp[i][j])
				yes();
	no();
}

#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int ok, n, a[50], real, ch[50], cnt, c1, debug;
vector<int> E[50];

bool check (int x) {
    ch[x] = 1;
    for (int to : E[x]) {
        bool got = check(to);
        if (got == 0) return 0;
        ch[x] += a[to];
    }
    if (ch[x] > a[x]) return 0;
    int cld = E[x].size() + a[x] - ch[x];
    cnt += a[x] - ch[x];
    if (cld == 1) return 0;
    return 1;
}

void rek (int x) {
    if (x == real) {
        cnt = 0;
        ok |= check(0) && (cnt == c1);
        return;
    }
    for (int i = 0; i < x; ++i) {
        //if (E[i].size() >= a[i]) continue;
        E[i].push_back(x);
        rek (x + 1);
        if (ok) return;
        E[i].pop_back();
    }
}

int main ()
{
    scanf ("%d", &n);

    for (int i = 0; i < n; ++i) scanf ("%d", &a[i]);
    if (n == 1) return printf ("%s\n", a[0] == 1 ? "YES" : "NO"), 0;
    if (n == 2) return printf ("NO\n"), 0;

    sort (a, a + n);
    reverse (a, a + n);

    for (int i = 0; i < n; ++i)
        if (a[i] != 1) ++real;

    c1 = n - real;
    if (real == 0) return printf ("NO\n"), 0;
    if (real == 1) return printf ("%s\n", a[0] == n ? "YES" : "NO"), 0;
    if (c1 <= real) return printf ("NO\n"), 0;

    E[0].push_back(1);
    rek (2);

    if (!ok) printf ("NO\n");
    else printf ("YES\n");

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define out(x) cout << #x"=" << x << endl

const int N = 26;
const int M = 13;

int c[N];
bool dp[N][N][1 << M];

int main() {
  int n, leafs = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", c + i);
    leafs += (c[i] == 1);
  }
  sort(c, c + n);
  reverse(c, c + n);
  if (leafs == 1 && n == 1) {
    return puts("YES");
  }
  int m = n - leafs;
  if (leafs < (n + 1) / 2) {
    return puts("NO");
  }
  int lim = 1 << m;
  dp[0][leafs][(lim - 1) ^ 1] = 1;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j <= leafs; ++j) {
      for (int k = 0; k < lim; ++k) if (dp[i][j][k] && !(k >> i & 1)) {
        for (int p = 0; p < lim; ++p) if ((k & p) == p) {
          int s = 0;
          int cc = 0;
          for (int o = 0; o < m; ++o) if (p >> o & 1) {
            s += c[o];
            ++cc;
          }
          int tmpl = c[i] - s - 1;
          if (tmpl <= j && cc + tmpl >= 2 && tmpl >= 0) {
            dp[i + 1][j - tmpl][k ^ p] = 1;
          }
        }
      }
    }
  }
  puts(dp[m][0][0] ? "YES" : "NO");
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int a[24];
int n;

bool d[25][5000][25];

bool cmp(int a, int b)
{
    return a > b;
}

inline bool getbit(int a, int k)
{
    return (a >> k)&1;
}

inline int invbit(int a, int k)
{
    return a ^ (1 << k);
}

inline int sum(int m)
{
    int r = 0;
    for (int i = 0; i < n; i++)
    {
        r += getbit(m, i)*a[n-i-1];
    }
    return r;
}

inline int dbits(int m)
{
    int r = 0;
    for (int i = 0; i < n; i++) r += getbit(m, i);
    return r;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    if (n == 1 && a[0] == 1)
    {
        printf("YES");
        return 0;
    }
    sort(a, a+n, cmp);
    int leafs = 0;
    for (int i = n-1; i >= 0 && a[i] == 1; i--) leafs++;
    n -= leafs;
    if (n > 11)
    {
        printf("NO");
        return 0;
    }
    int tmask = 0;
    for (int i = 0; i < n-1; i++) tmask = invbit(tmask, i);
    d[0][tmask][leafs] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int m = tmask; m >= 0; m--)
        {
            for (int l = 0; l < 25; l++)
            {
                if (!d[i][m][l]) continue;
                for (int s=m; ; s=(s-1)&m)
                {
                    int q = sum(m^s);
                    int c = dbits(m^s);
                    if ((a[i]-q-1) <= l && a[i] >= q && (a[i]-q-1)+c >= 2)
                    {
                        d[i+1][s][l-(a[i]-q-1)] = 1;
                    }
                    if (s==0)  break;
                }
            }
        }
    }
    if (d[n][0][0])
    {
        printf("YES");
    }
    else
    {
        printf("NO");
    }
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

int a[30], b[30], son[30], n;

bool solve(int dep) {
	if (dep == n) {
		for (int i = 0; i < n; ++ i)
			if (a[i] > 1 || (b[i] > 1 && son[i] < 2)) return false;
		return true;
	}
	for (int i = 0; i < dep; ++ i) {
		if (a[dep] < a[i] - (!son[i])) {
			a[i] -= a[dep]; son[i] ++;
			if (solve(dep + 1)) return true;
			a[i] += a[dep]; son[i] --;
		}
	}
	return false;
}

int main() {
	cin >> n;
	bool flag = 1;
	for (int i = 0; i < n; ++ i) {
		cin >> a[i];
		flag &= (a[i] != 2);
	}
	sort(a, a + n);
	reverse(a, a + n);
	copy(a, a + n, b);
	flag &= (a[0] == n);
	fill(son, son + n, 0);
	if (flag && solve(1)) puts("YES");
	else puts("NO");
}

//besmellah
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1 << 13;
bool dp[maxn][25];
int sum[maxn];

int main() {
	int n, L = 0;
	cin >> n;
	vector <int> a;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		if (tmp == 1)
			L++;
		else
			a.push_back(tmp);
	}
	n = a.size();
	if (n > 13) {
		cout << "NO";
		return 0;
	}
	sort(a.begin(), a.end());
	fill(dp[0], dp[0] + L + 1, 1);
	for (int mask = 1; mask < (1 << n); mask++)
		sum[mask] = sum[mask - (mask & -mask)] + a[__builtin_ctz(mask)];
	for (int mask = 1; mask < (1 << n); mask++) {
		int big = log2(mask);
		for (int l = 0; l <= L; l++) {
			for (int mask2 = (1 << (big + 1)) - 1 - mask; mask2 && !dp[mask][l]; mask2 = (mask2 - 1) & ~mask) {
				for (int i = 0; i <= L - l && !dp[mask][l]; i++) {
					if (__builtin_popcount(mask2) + i >= 2 && sum[mask2] + i == a[big] - 1) {
						dp[mask][l] |= dp[mask2 + mask - (1 << big)][i + l];
					}
				}
			}
			if (a[big] - 1 <= L - l && a[big] > 2)
				dp[mask][l] |= dp[mask - (1 << big)][l + a[big] - 1];
		}
	}
	if (n + L == 1) {
		cout << "YES";
	}
	else {
		if (a.back() == n + L && dp[1 << (n - 1)][0])
			cout << "YES";
		else
			cout << "NO";
	}
}

#pragma comment(linker, "/stack:32000000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <sstream>
#include <stack>
#include <cassert>
#include <string.h>
#include <ctime>

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define sqr(x) (x)*(x)
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define X first
#define Y second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

const int maxn = 30;
int c[maxn];
//void doh() {
//	printf("NO\n");
//	exit(0);
//}

int dp[maxn][1<<20];
int cost[1<<20];

bool solve(vector<int> c) {
	int n = sz(c); int N = n;
	if (n == 1) return true;
	forn(i, n) if (c[i] == 2) return false;
	sort(c.begin(), c.begin()+n);
	reverse(c.begin(), c.begin()+n);
	int ones = 0;
	while (n && c[n-1] == 1) ++ones, --n;
	reverse(c.begin(), c.begin()+n);
	if (c[n-1] != N) return false;
	if (n > 12) return false;//while (true);
	//if (n == 0) printf("YES\n"), exit(0);
	forn(i, (1<<n)) {
		cost[i] = 0;
		forn(j, n) if (i&(1<<j)) cost[i] += c[j];
	}
	const int cinf = 1000000010;
	forn(i, n+2) forn(j, (1<<n)) dp[i][j] = cinf;
	dp[1][1] = c[0]-1;
	for (int i = 1; i < n; ++i) {
		forn(j, 1<<i) {
			if (dp[i][j] == cinf) continue;
			for (int msk = j; msk >= 0; msk = (msk-1)&j) {
				int ccc = 0;
				forn(t, i) ccc += (msk>>t)&1;
				int curcost = c[i]-1 - cost[msk];
				if (ccc == 1 && curcost == 0) continue;
				if (curcost < 0) continue;
				dp[i+1][(msk^j)|(1<<i)] = min(dp[i+1][(msk^j)|(1<<i)], dp[i][j] + curcost);
				if (msk == 0) break;
			}
		}
	}
	int minrem = dp[n][1<<(n-1)];
	return minrem == ones; //if (minrem <= ones) printf("YES\n"); else printf("NO\n");
}

vector<int> getrand(int n) {
	while (true) {
		vector<int> v(n);
		vector<int> st(n);
		forn(i, n) if (i) v[i] = rand()%i, st[v[i]]++;
		bool ok = true;
		forn(i, n) if (st[i] == 1) ok = false;
		if (!ok) continue;
		vector<int> res(n);
		for (int i = n-1; i >= 0; --i) {
			res[i]++;
			if (i) res[v[i]] += res[i];
		}
		return res;
	}
}

void stress() {
	forn(iter, 10000) {
		vector<int> v = getrand(7);
		if (!solve(v)) {
			forn(i, sz(v)) printf("%d ", v[i]);
			printf("\n");
			exit(0);
		}
	}
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	//stress();
	int n; scanf("%d", &n);
	vector<int> v(n);
	forn(i, n) scanf("%d", &v[i]);
	bool b = solve(v);
	if (b) printf("YES\n"); else printf("NO\n");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int a[30], b[30], son[30], n;
bool solve(int dep) {
    if (dep == n) {
        for (int i = 0; i < n; ++i)
            if (a[i] > 1 || (b[i] > 1 && son[i] < 2)) return false;//remaining size a[i] = itself = 1
        return true;
    }
    for (int i = 0; i < dep; ++i) {
        if (a[dep] < a[i] - (!son[i])) {// no son can add at most [sz-2] subtree,have son then smaller than me size is ok (remaining 1 is my node)
            a[i] -= a[dep];
            son[i]++;
            if (solve(dep + 1)) return true;
            a[i] += a[dep];
            son[i]--;
        }
    }
    return false;
}
int main() {
    scanf("%d", &n);
    bool flag = 1;
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
        flag &= a[i] != 2;//always 1 son => tle if not exclude
    }
    sort(a, a + n);
    reverse(a, a + n);
    copy(a, a + n, b);
    flag &= (a[0] == n);
    fill(son, son + n, 0);
    if (flag && solve(1)) puts("YES");
    else puts("NO");
    return 0;
}

#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

#ifndef ONLINE_JUDGE
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
	template<class S,class T>
	ostream &operator <<(ostream& out,const pair<S,T>& a){
		out<<'('<<a.fr<<','<<a.sc<<')';
		return out;
	}
}

int n,m;

int c[25];
int one;

int par[25],rem[25],ch[25];
int k;
bool dfs(int idx){
	if(idx==m){
		REP(i,m) if(ch[i]+rem[i]<2) return false;
		return true;
	}
	REP(i,idx) if(rem[i]>=c[idx]){
		rem[i]-=c[idx];
		par[idx]=i;
		ch[i]++;

		rem[idx]=c[idx]-1;
		ch[idx]=0;
		if(dfs(idx+1)) return true;

		--ch[i];
		rem[i]+=c[idx];
	}
	return false;
}
bool solve(){
	cin>>n;
	REP(i,n) cin>>c[i];
	sort(c,c+n,greater<int>());
	m=0;
	REP(i,n) if(c[i]>1) m=i+1;
	if(m==0) {
		return n==1;
	}

	REP(i,m) if(c[i]==2) return false;

	int need=0;
	REP(i,m){
		need+=c[i]-1;
		if(i>0) need-=c[i];
	}
	one=n-m;
	if(need!=one) return false;
	dump(m);

	k=1;
	rem[0]=c[0]-1;
	par[0]=-1;
	if(dfs(1)) return true;
	return false;
}

int main(){
	puts(solve()?"YES":"NO");

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define N 33

vector < vector <int> > vec[N];

vector <int> v;

int main() {
    int n;
    cin >> n;
    vec[1].push_back(vector <int> ());
    for (int i = 2; i <= n; i ++) {
        for (int j = 1; j < i - 1; j ++) {
            int k = i - 1 - j;

            for (auto v : vec[j]) {
                vector <int> z;
                v.push_back(j);
                if (k <= j) {
                    for (auto w : vec[k]) {
                        w.push_back(k);
                        z.resize(v.size() + w.size());
                        merge(v.begin(), v.end(), w.begin(), w.end(), z.begin());
                        vec[i].push_back(z);
                    }
                }
                for (auto w : vec[k+1]) {
                    if (w.back() > j) break;
                    z.resize(v.size() + w.size());
                    merge(v.begin(), v.end(), w.begin(), w.end(), z.begin());
                    vec[i].push_back(z);
                }
            }
        }
    }
    v.resize(n);
    for (int i = 0; i < n; i ++) cin >> v[i];
    sort(v.begin(), v.end());
    if (v.back() != n) return puts("NO"), 0;
    v.pop_back();
    for (auto w : vec[n]) if (v == w) return puts("YES"), 0;
    puts("NO");

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

//#define __LOCAL_RUN__

using namespace std;

#define in_str(b) scanf("%s",(b))
#define in_int1(a) scanf("%d",&(a))
#define in_int2(a,b) scanf("%d%d",&(a),&(b))
#define in_int3(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define in_int4(a,b,c,d) scanf("%d%d%d%d",&(a),&(b),&(c),&(d))

int mas[25];
bool used[25];
int k;

bool can(int from, int num1);

bool dfs(int from, int goal, int num1, int startfrom, bool okone)
{
	if (goal == 0)
	{
		return can(from - 1, num1);
	}

	if (num1 >= goal)
	{
		if (can(from - 1, num1 - goal)) return true;
	}

	for (int i = startfrom; i < k; i++)
	{
		if (!used[i] && (mas[i] < goal || (mas[i] == goal && okone)))
		{
			used[i] = true;
			if (dfs(from, goal - mas[i], num1, i, true)) return true;
			used[i] = false;
		}
	}

	return false;
}

bool can(int from, int num1)
{
	if (from == 0)
	{
		int tot = 0;
		for (int i = 1; i < k; i++) if (!used[i]) tot += mas[i];
		tot += num1 + 1;
		return tot == mas[0];
	}

	return dfs(from, mas[from] - 1, num1, from + 1, false);
}

void Solve()
{
	int i, j, m, n;

	in_int1(n);

	bool ok = true;
	int num1 = 0;
	k = 0;
	for (i = 0; i < n; i++)
	{
		int a;
		in_int1(a);
		if (a == 1) num1++;
		else mas[k++] = a;
		if (a == 2) ok = false;
	}

	sort(mas, mas + k, greater<int>());
	if (n == 1 && num1 == 1) printf("YES");
	else if (mas[0] != n || !ok) printf("NO");
	else
	{
		memset(used, 0, sizeof(used));
		if (can(k-1, num1)) printf("YES");
		else printf("NO");
	}
}

int main()
{
#ifdef __LOCAL_RUN__
	#define _MAX_BUF_SIZE 32
	int _i = 0;
	char *_buf = new char[_MAX_BUF_SIZE];

	FILE *res_output = freopen("output.txt", "wt", stdout);
	while (true)
	{
		string _suffix = string(itoa(_i, _buf, 10)) + string(".txt");
		FILE *res_input = freopen((string("input-") + _suffix).c_str(), "rt", stdin);
		if (!res_input)
		{
			// the end
			break;
		}
		if (_i) printf("\n\n");
		printf("==== Case #%d =====\n", _i);
		Solve();
		_i++;
	}
#else
	Solve();
#endif
	return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define SZ(x) int((x).size())
#define endl "\n"
using namespace std;
using db = double;
using ll = long long;
using ull = unsigned long long;
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2> inline void chadd(T1 &x, T2 y, int Mod = mod) { x += y; while (x >= Mod) x -= Mod; while (x < 0) x += Mod; }
template <class T1, class T2> inline void chmax(T1 &x, T2 y) { if (x < y) x = y; }
template <class T1, class T2> inline void chmin(T1 &x, T2 y) { if (x > y) x = y; }
inline int nextInt() { int x; cin >> x; return x; }
void rd() {}
template <class T, class... Ts> void rd(T& arg, Ts&... args) { cin >> arg; rd(args...); }
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template <class T, class... Ts> void err(const T& arg, const Ts&... args) { cout << arg << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) { for (auto &v : arg) cout << v << ' '; err(args...); }
void ptt() { cout << endl; }
template <class T, class... Ts> void ptt(const T& arg, const Ts&... args) { cout << ' ' << arg; ptt(args...); }
template <class T, class... Ts> void pt(const T& arg, const Ts&... args) { cout << arg; ptt(args...); }
void pt() {}
template <template<typename...> class T, typename t, typename... A>
void pt(const T <t> &arg, const A&... args) { for (int i = 0, sze = arg.size(); i < sze; ++i) cout << arg[i] << " \n"[i == sze - 1]; pt(args...); }
inline ll qpow(ll base, ll n) { assert(n >= 0); ll res = 1; while (n) { if (n & 1) res = res * base % mod; base = base * base % mod; n >>= 1; } return res; }
//head
constexpr int N = 1e2 + 10;
int n, c[N], f[1 << 13][14][25];

vector <int> vec[1 << 13];

void run() {
	for (int i = 1; i <= n; ++i) rd(c[i]);
	sort(c + 1, c + 1 + n);
	reverse(c + 1, c + 1 + n);
	if (c[1] != n) return pt("NO");
	if (n == 1) return pt("YES");
	int lef = 0;
	for (int i = 1; i <= n; ++i) {
		if (c[i] == 1) ++lef;
		if (c[i] == 2) return pt("NO");
	}
	if (lef <= n / 2) return pt("NO");
	memset(f, 0, sizeof f);
	int _n = 0;
	for (int i = 1; i <= n; ++i) {
		if (c[i] == 1) {
			_n = i - 1;
			break;
		}
	}
	n = _n;
	for (int mask = 0; mask < (1 << n); ++mask) {
		for (int j = 0; j < n; ++j) if (((mask >> j) & 1) && __builtin_popcount(mask) <= c[j + 1]) {
			vec[mask].push_back(j);
		}
	}
//	for (int i = 0; i < n; ++i) {
//		for (int mask = 1 << i; mask < (1 << n); mask = (mask + 1) | (1 << i)) {
//			vec[mask].push_back(i);
//		}
//	}
	for (int i = 0; i < n; ++i)
		for (int j = 1; j <= min(c[i + 1], lef + 1); ++j)
			f[1 << i][i][j] = 1;
	for (int S = 0; S < (1 << n); ++S) {
		for (auto &u : vec[S]) {
			for (int T = (S - 1) & S; T; T = (T - 1) & S) {
				for (auto &v : vec[T]) if (((S - T) >> u) % 2 == 1 && c[v + 1] + 1 < c[u + 1] && f[T][v][c[v + 1]]) {
					for (int j = 1; j + c[v + 1] <= c[u + 1]; ++j)
						f[S][u][j + c[v + 1]] |= f[S - T][u][j];
				}
			}
		}
	}
	if (f[(1 << n) - 1][0][c[1]]) pt("YES");
	else pt("NO");
//	for (int i = 0; i < n; ++i) {
//		if (f[(1 << n) - 1][i][c[i]])
//			return pt("YES");
//	}
//	pt("NO");
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cout << fixed << setprecision(20);
	while (cin >> n) run();
//    for (int kase = 1; kase <= _T; ++kase) {
//        cout << "Case #" << kase << ":\n";
//        run();
//    }
	return 0;
}

#include<bits/stdc++.h>

using namespace std;
const int maxn = 25;

int n,tn,has;
int A[maxn];
bool canTr[1<<12][maxn],canFo[1<<12][maxn];
int nm[1<<12];

void Work(){
	if(tn>=12){
		puts("NO");
		return;
	}
//	cout<<n<<endl;
	for(int sta=0;sta<(1<<n);sta++){
		nm[sta]=nm[sta>>1]+(sta&1);
//		cout<<sta<<' '<<nm[sta]<<' '<<(sta>>1)<<' '<<nm[sta>>1]<<' '<<(sta&1)<<' '<<nm[sta>>1]+(sta&1)<<endl;
//		nm[sta]=nm[sta>>1]+(sta&1);
	}
//	cout<<nm[3]<<' '<<nm[3>>1]<<' '<<(3&1)<<endl;
//	for(int i=0;i<1<<n;i++)cout<<nm[i]<<' ';
	for(int sta=0;sta<1<<n;sta++)
		for(int i=0;i<=has;i++){
			if(sta==0){
				canTr[sta][i]=i==1;
				canFo[sta][i]=i>=2;
			}
			else{
				for(int j=1;j<=n;j++)
					if(sta&(1<<j-1)&&A[j]==nm[sta]+i&&canFo[sta^(1<<j-1)][i])canTr[sta][i]=1;
				for(int s=sta;;s=(s-1)&sta){
					for(int j=1;j<=i;j++)
						if(canTr[s][j]&&(canFo[sta^s][i-j]||canTr[sta^s][i-j]))canFo[sta][i]=1;
					if(!s)break;
				}
			}
//			cout<<sta<<' '<<i<<endl;
//			cout<<"Tr="<<canTr[sta][i]<<" Fo="<<canFo[sta][i]<<endl;
		}
	puts(canTr[(1<<n)-1][has]?"YES":"NO");
//	for(int i=0;i<1<<n;i++)cout<<nm[i]<<' ';
}

void Init(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	for(int i=1;i<=n;i++)if(A[i]==1)has++;else A[++tn]=A[i];
	n=tn;
}

int main(){
	Init();
	Work();
	return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn=24;
const int inf=0x3fffffff;

int n,a[maxn];
vector<int>g[25];
bool f[1<<24];
int c[1<<24];

void dfs(int cnt,int mask,int sum,int tt)
{
    if(cnt==n)return;
    c[mask]=tt;
    dfs(cnt+1,mask,sum,tt);
    if(sum+a[cnt]<=n)
    {
        g[sum+a[cnt]].push_back(mask|(1<<cnt));
    }
    dfs(cnt+1,mask|(1<<cnt),sum+a[cnt],tt+1);
}

int main()
{
    //freopen("in.cpp","r",stdin);
    scanf("%d",&n);
    for(int i=0; i<n; i++)scanf("%d",&a[i]);
    sort(a,a+n);
    dfs(0,0,0,0);
    int pos=-1;
    for(int i=0; i<n; i++)
        if(a[i]!=1)
        {
            pos=i-1;
            break;
        }
    if(n==1)
    {
         if(a[0]==1)printf("YES\n");
         else printf("NO\n");
    }
    else if(pos==-1)printf("NO\n");
    else
    {
        int start=0;
        for(int i=0; i<=pos; i++)
            start|=(1<<i);
        f[start]=1;
        for(int i=start; i<(1<<n); i++)
        {
            if(!f[i])continue;
            int p=-1;
            for(int j=0; j<n; j++)
                if(i&(1<<j))p=j;
            //printf("** %d\n",p);
            if(p+1<n)
            {
                for(int j=0; j<g[a[p+1]-1].size(); j++)
                {
                    //  printf("** %d %d\n",g[a[p+1]-1][j],i);
                    if((g[a[p+1]-1][j]|i)==i&&c[g[a[p+1]-1][j]]>1)
                    {
                        f[(i^g[a[p+1]-1][j])|(1<<(p+1))]=1;
                        // printf("** %d\n",(i^g[a[p+1]-1][j])|(1<<(p+1)));
                    }
                }
            }
        }
        //printf("%d\n",f[7]);
        //printf("%d\n",g[3][0]);
//   printf("**\n");
        if(f[1<<(n-1)])printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<functional>
#include<cstdlib>
using namespace std;
typedef long long Int;
int a[26],n;
bool used[26];
bool check(int idx);
bool dfs(int idx,int st,int sum)
{
	if(sum==0)return check(idx+1);
	if(st<1)return false;
	if(used[st])return dfs(idx,st-1,sum);
	if(sum>=a[st])
	{
		used[st]=true;
		if(dfs(idx,st-1,sum-a[st]))
		    return true;
        used[st]=false;
	}
	return dfs(idx,st-1,sum);
}
bool check(int idx)
{
	if(idx>n)return true;
	if(a[idx]==1)return check(idx+1);
	int st=idx-1;
	while(st>=1&&a[st]>=a[idx]-1)
	   st--;
    if(st==0)return false;
    return dfs(idx,st,a[idx]-1);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	   scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    if(a[n]!=n)
    {
    	puts("NO");
    	return 0;
	}
    puts(check(1)?"YES":"NO");
}

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<functional>
using namespace std;
const int inf = 1<<28;
const int mod = (int)1e9+7;
const double eps = 1e-8;
typedef long long ll;
int n,m,k;

int a[33];
int sum[33];

bool dfs(int x)
{
    if(x == n+1) return true;
    for(int i=1;i<x;i++){
        if(sum[i] + a[x] < a[i] && a[x]+1!=a[i]){
            sum[i] += a[x];
            if(dfs(x+1)) return true;
            sum[i] -= a[x];
        }
    }
    return false;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif // ONLINE_JUDGE
    while(cin>>n)
    {
        for(int i=1;i<=n;i++) scanf("%d", &a[i]);
        sort(a+1,a+n+1,greater<int>());
        if(a[1] != n || count(a+1,a+n+1,2)) return puts("NO");
        if(count(a+1,a+n+1,1) * 2 <= n) return puts("NO");
        if(n==1 || dfs(2)) puts("YES");
        else puts("NO");
    }
    return 0;
}

#include<stdio.h>
#include<algorithm>
#include<memory.h>
#include<queue>
#define mod 1000000007
#define maxn 200005
using namespace std;
int a[100];
int vis[100];
int temp[100];
int from[100];
int dp[100];
int main(void){

        int n;
        scanf("%d",&n);
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        int ok=1;
        for(int i=0;i<n;i++){
            if(a[i]!=1){
                memset(dp,0,sizeof(dp));
                memset(from,0,sizeof(from));
                dp[0]=1;
                for(int k=i-1;k>=0;k--)for(int j=a[i]-1;j>0;j--){
                    if(a[k]!=a[i]-1&&!vis[k]&&j-a[k]>=0&&dp[j-a[k]]&&dp[j]==0) dp[j]=1,from[j]=k;
                }if(dp[a[i]-1]==0) {
                    ok=0;break;
                }else{
                    for(int j=a[i]-1;j>0;j=j-a[from[j]]){
                        vis[from[j]]=1;
                    }
                }
            }
        }for(int i=0;i<n-1;i++) if(vis[i]==0) ok=0;
        if(ok) printf("YES\n");
        else printf("NO\n");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int N ;
vector < int > A;
bool ca[15][1<<15][15];
bool go[15][1<<15][15];
bool dp(int i , int mask , int leaf)
{
    if(i>N-1)
        return 1;
    if(i==N-1)
        return (A[i]-1==leaf) && __builtin_popcount(mask)==N-1 && (leaf==0 || leaf>=2);

    if(i!=0 && !((mask>>i)&1))
        return 0;
    int x  = (1<<N)-1;
    x = x ^ mask;
    bool &ret = ca[i][mask][leaf];
    if(go[i][mask][leaf])
        return ret;
    go[i][mask][leaf]=1;

    for ( int sub = 0 ; sub = sub - x & x; )
    {
        int sum = 1 ;

        for(int j=0;j<N;++j)
            if((sub>>j)&1)
                sum+=A[j];
        int need = A[i] - sum;

        if(need<=leaf && need>=0 && (need+__builtin_popcount(sub))>=2  )
            ret = ret || dp(i+1,mask|sub , leaf-need);
    }
    int sum = 1;
    int need = A[i] - sum;
    if(need<=leaf && need>=0 && need>=2)
        ret = ret || dp(i+1,mask , leaf-need);
    return ret;
}

int main()
{
    int i , ctr = 0;
    cin>>N;
    A.resize(N);
    for(i=0;i<N;++i)cin>>A[i];
    sort(A.begin(),A.end(),greater< int > ());

    while(*A.rbegin()==1)
    {
        A.pop_back();
        ++ctr;
    }
    if(ctr < (N+1)/2)
    {
        cout<<"NO";
        return 0;
    }
    N-=ctr;
//    cout<<N<<" "<<ctr<<'\n';

    if(dp(0,0,ctr))
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}

//                      be naame khoda

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int maxN = 30;
const int maxS = maxN * maxN;

bool mark[maxN];
vector <int> could[maxS];
int sum[1 << 24], c[maxN], n;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> c[i];
    sort(c, c + n);
    if(c[0] != 1 || c[n - 1] != n)
    {
        cout << "NO\n";
        return 0;
    }
    for(int i = 0; i < n; i++)
        sum[1 << i] = c[i];
    for(int m = 0; m < (1 << n); m++)
    {
        if(!sum[m])
            sum[m] = sum[m & (m-1)] + sum[m - (m & (m-1))];
        could[sum[m]].push_back(m);
    }
    for(int i = 0; i < n; i++)
        if(c[i] > 1)
        {
            bool can = 0;
            for(int j = (int)could[c[i] - 1].size() - 1; !can && j >= 0; j--)
            {
                bool fl = 0;
                int m = could[c[i] - 1][j], cnt = 0;
                for(int j = 0; !fl && j < n; j++)
                    if(m & (1 << j))
                        if(mark[j])
                            fl = 1;
                        else
                            cnt++;
                if(!fl && cnt >= 2)
                {
                    for(int j = 0; j < n; j++)
                        if(m & (1 << j))
                            mark[j] = 1;
                        can = 1;
                }
            }
            if(!can)
            {
                cout << "NO\n";
                return 0;
            }
        }
    cout << "YES\n";
}

#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;
}

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

template<typename T> inline void minimize(T &a, T b) { a = std::min(a, b); }
template<typename T> inline void maximize(T &a, T b) { a = std::max(a, b); }

#define all(v) v.begin(),v.end()

using namespace std;

#define endl '\n'
#define next(type, i) type i; cin >> i;
template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define nextVector(t, v, size) vector< argument_type<void(t)>::type > v(size); { for (int i = 0 ; i < size ; i++) cin >> v[i]; }

#define range(name, start, count) vector<int> name(count); { for (int i = 0 ; i < count ; i++) name[i] = i + start; }

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) os << v[i] << ' '; os << endl; return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }
template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

vector<int> bigNodes;
vector<int> bigNodesSizeByMask;
vector<int> bigNodesCountByMask;

bool dp[17000][20][30];
bool calced[17000][20][30];

bool canBuild(int curLeafsMask, int assigningTo, int leavesCount) {
	if (curLeafsMask & (1 << assigningTo)) return false;

	if (!calced[curLeafsMask][assigningTo][leavesCount]) {
		calced[curLeafsMask][assigningTo][leavesCount] = true;

		int bigNodeSize = bigNodes[assigningTo] - 1;

		FOR (subMask, 0, curLeafsMask + 1) {
			if ((subMask & curLeafsMask) != subMask) continue;
			if (bigNodesSizeByMask[subMask] > bigNodeSize) continue;
			else {
				int needLeaves = bigNodeSize - bigNodesSizeByMask[subMask];
				if (needLeaves + bigNodesCountByMask[subMask] < 2) continue;
				if (needLeaves > leavesCount) continue;
				int remLeaves = leavesCount - needLeaves;
				if (assigningTo == 0) {
					if (remLeaves == 0) dp[curLeafsMask][assigningTo][leavesCount] = true;
				} else if (canBuild(curLeafsMask ^ subMask, assigningTo - 1, remLeaves)) {
					dp[curLeafsMask][assigningTo][leavesCount] = true;
				}
			}
		}
	}
	return dp[curLeafsMask][assigningTo][leavesCount];
}

int main() {
	srand (time(NULL));
    ios_base::sync_with_stdio(false); cin.tie(NULL);

	next(int, n);

	int leaves = 0;
	FOR (i, 0, n) {
		next(int, x);
		if (x == 1) leaves++;
		else {
			bigNodes.push_back(x);
		}
	}
	if (bigNodes.size() > 14) {
		cout << "NO";
		return 0;
	}
	sort(all(bigNodes));
	if (bigNodes.size() == 0) {
		if (n == 1) {
			cout << "YES";
		} else cout << "NO";
		return 0;
	}

	int maxMask = 1 << bigNodes.size();
	bigNodesSizeByMask.resize(maxMask);
	bigNodesCountByMask.resize(maxMask);
	int b = 0;
	FOR (mask, 1, maxMask) {
		if (mask & (2 << b)) b++;
		bigNodesSizeByMask[mask] = bigNodes[b] + bigNodesSizeByMask[mask ^ (1 << b)];
		bigNodesCountByMask[mask] = 1 + bigNodesCountByMask[mask ^ (1 << b)];
	}

	int allBigNodesMask;
	if (bigNodes.size() == 1) allBigNodesMask = 0;
	else allBigNodesMask = (1 << (bigNodes.size() - 1)) - 1;
	if (canBuild(allBigNodesMask, bigNodes.size() - 1, leaves)) cout << "YES";
	else cout << "NO";
}

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 30;

int n;
int cnt[N];
int old_cnt[N];
int old_deg[N];
int deg[N];

void rec(int ind)
{
    if (ind == n || cnt[ind] == 1)
    {
        for (int i = 0; i < ind; i++)
        {
            old_cnt[i] = cnt[i];
            old_deg[i] = deg[i];
        }

        int ones = n - ind;
        bool xuy = false;
        for (int i = 0; i < ind; i++)
        {
            while (ones > 0 && cnt[i] > 1)
            {
                ones--;
                cnt[i]--;
                deg[i]++;
            }
            //cout << ones << " " << cnt[i] << " " << deg[i] << endl;
            if (deg[i] < 2 || cnt[i] != 1)
                xuy = true;
        }

        if (ones != 0)
            xuy = true;

        for (int i = 0; i < ind; i++)
        {
            cnt[i] = old_cnt[i];
            deg[i] = old_deg[i];
        }

        if (!xuy)
        {
            puts("YES");
            exit(0);
        }

        return;
    }

    for (int i = 0; i < ind; i++)
    {
        cnt[i] -= cnt[ind];
        deg[i]++;
        if (cnt[i] >= 1)
            rec(ind + 1);
        deg[i]--;
        cnt[i] += cnt[ind];
    }
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &cnt[i]);
    sort(cnt, cnt + n, greater<int>());

    if (n == 1)
    {
        puts("YES");
        return 0;
    }

    rec(1);

    puts("NO");

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,a) repi(i,0,a)
#define all(u) begin(u),end(u)
#define pb push_back
const string y = "YES", n = "NO";

int N, c[32], used[32], cnt[32];

string solve(){
    rep(i,N) cnt[c[i]]++;
    if(!cnt[N] or cnt[2]) return n;

    sort(c,c+N);
    reverse(c,c+N);
    priority_queue<int> q;
    q.push(N);
    used[0] = 1;
    while(!q.empty()){
        int w = q.top()-1; q.pop();
        if(!w) continue;
        int dp[32] = {}, cnt = 0;
        vector<int> rest[32], cand;
        rep(i,N) if(!used[i] and q.top()-1 <= c[i]){
            w -= c[i];
            used[i] = 1;
            q.push(c[i]);
            cnt++;
        }
        if(w < 0) return n;
        rep(i,N) if(!used[i]) cand.pb(i);
        rep(i,N) dp[i] = N+1;
        dp[0] = 0;
        for(int &i: cand){
            int d = c[i];
            for(int j = w-d; j >= 0; j--)
                if(dp[j+d] > dp[j]+1){
                    dp[j+d] = dp[j]+1;
                    rest[j+d] = rest[j];
                    rest[j+d].pb(i);
                }
        }

        if(dp[w] > N or rest[w].size()+cnt < 2) return n;
        for(int &i: rest[w]) {
            used[i] = 1;
            q.push(c[i]);
        }
    }
    return y;
}

void input(){
    cin >> N;
    rep(i,N) cin >> c[i];
}

signed main(){
    input();
    cout << solve() << endl;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

#define debug(x) std::cerr << "DEBUG: " << #x << " = " << x << std::endl
#define forn(i, n) for(int i = 0; i < (n); ++i)
#define all(x) std::begin(x), std::end(x)
#define mp make_pair
#define pb push_back

typedef long long ll;

template <class T> inline void mn(T& x, const T& y) { if (y < x) x = y; }
template <class T> inline void mx(T& x, const T& y) { if (x < y) x = y; }
template <class T> inline int sz(const T& x) { return (int) x.size(); }

int n, p[24], w[24];

inline bool solve(int d) {
    if (d == n) return *max_element(all(p)) == 0;
    int used = 0;
    forn (i, d) {
        if ((p[i] > w[d] || p[i] == w[d] && p[i] + 1 != w[i])
                && ((used >> p[i]) & 1) == 0) {
            p[i] -= w[d];
            if (solve(d + 1)) return true;
            p[i] += w[d];
            used |= 1 << p[i];
        }
    }
    return false;
}

int main() {
    // freopen("in.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }

    sort(w, w + n, greater<int>());
    for (int i = 0; i < n; ++i) {
        p[i] = w[i] - 1;
    }

    cout << (solve(1) ? "YES" : "NO") << endl;

    return 0;
}

#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 26;
int n;
int memo[MAX][1 << 13][MAX];
int val[MAX];
int sum[1 << 13];
int inside = 0;

int roll(int idx, int mask, int leaves) {
	if(val[idx] == 1) {
		return mask == 0 && leaves == 0;
	}
	if(mask & (1 << idx)) {
		return 0;
	}
	int &ans = memo[idx][mask][leaves];
	if(~ans) {
		return ans;
	}
	ans = 0;
	int desired = val[idx] - 1;
	for(int submask = mask; ; submask = (submask - 1) & mask) {
		int s = sum[submask];
		int used = __builtin_popcount(submask);
		if(s <= desired && desired - s <= leaves && (used + desired - s) >= 2) {
			ans |= roll(idx + 1, mask ^ submask, leaves - (desired - s));
		}
		if(submask == 0) {
			break;
		}
	}

	return ans;
}

int main() {
	scanf("%d", &n);
	fori(i, 0, n) {
		scanf("%d", val + i);
		inside += val[i] != 1;
	}
	if(n == 1 && val[0] == 1) {
		puts("YES");
		return 0;
	}
	if(inside >= 13) {
		puts("NO");
		return 0;
	}

	sort(val, val + n, greater<int>());

	fori(i, 0, 1 << inside) {
		fori(j, 0, inside) {
			if(i & (1 << j)) {
				sum[i] += val[j];
			}
		}
	}

	memset(memo, -1, sizeof memo);
	int ans = roll(0, ((1 << inside) - 1) & ~1, n - inside);
	puts(ans ? "YES" : "NO");

	return 0;
}

#pragma comment(linker, "/STACK:100000000")
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <complex>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex < double > cd;

const bool db = false;

#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sd second
#define fs first

#define inf 1000000007
#define nmax 200010
#define mmax 200010
#define eps 1e-9

int n, ones;
int c[33], u[33], cc;
int ch[33], hv[33], nd[33];

void NO() {
	puts("NO");
	exit(0);
}

void YES() {
	puts("YES");
	exit(0);
}

void calc(int pos, int pt) {
	if(pos == n + 1) {
		bool ok = true;
		for(int i = 1; i <= n && ok; ++i)
			ok &= hv[i] == nd[i];
		if(ok) YES();
		return;
	}
	for(; pt >= 0 && !ch[pt]; --pt);
	hv[pos] = 1; nd[pos] = pt;
	bool ok = true;
	for(int i = 1; i <= pos && ok; ++i)
		if(hv[i] + pt <= nd[i] && nd[i] - 1 > pt) {
			hv[i] += pt; --ch[pt];
			calc(pos + 1, pt);
			hv[i] -= pt; ++ch[pt];
			ok &= pt != 1;
		}
}

int main() {
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	//freopen("a.in", "r", stdin); freopen("a.out", "w", stdout);
	//ios :: sync_with_stdio(false);
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &c[i]);
	sort(c + 1, c + n + 1);
	int nn = 0;
	vector < int > v;
	for(int i = 1; i <= n; ++i) {
		nn += c[i] == n;
		ones += c[i] == 1;
		if(c[i] != n)
			v.pb(c[i]);
		++ch[c[i]];
	}
	if(n == 1) {
		if(c[1] == 1)
			YES();
		NO();
	}
	if(nn != 1 || ones * 2 <= n)
		NO();
	hv[1] = 1; nd[1] = n;
	calc(2, n - 1); NO();
	getchar(); getchar();
	return 0;
}

#include <bits/stdc++.h>
#include <unordered_map>

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define ps(ch) printf("%s",ch)
#define Afridi 0
#define NL printf("\n")
#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define Max (1<<24)
#define PI 3.141592653589793
#define FI freopen("in.txt","r",stdin)
#define FO freopen("out.txt","w",stdout)
#define mod 1000000007
#define INF 1000000000

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

LL bigmod(LL b,LL p)
{
    if(p == 0)return 1;
    LL my = bigmod(b,p/2);
    my*=my;
    my%=mod;
    if(p & 1)my*=b,my%=mod;
    return my;
}
inline int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
inline bool checkb(int n,int pos)
{
    return (bool)(n & (1 << pos));
}
//inline int max(int x,int y) { return x > y ? x : y; }

short int sum[Max];
char pc[Max],lc[Max],votka[Max];
int n,ara[30],mnval;

bool Print(int mask)
{
	for(int i = 0; i < n; i++)printf("%d",checkb(mask,i));
	puts("");
}

void prework()
{
	int child_mask = 0;
	for(int i = 0; i < n; i++) if( ara[i] == 1 ) child_mask = setb(child_mask,i);
	for(int mask = 0; mask < (1 << n); mask++)
	{
		int v = 0;
		for(int i = 0; i < n; i++)if( checkb(mask,i) )sum[mask] += ara[i],v = max(v,ara[i]);
		votka[mask] = v;
		pc[mask] = __builtin_popcount(mask);
		lc[mask] = __builtin_popcount(mask & child_mask);
	}
}

bool F(int u,int mask);

bool G(int u,int baki,int taken)
{
	if( u == n )return baki == 0;
	if( checkb(taken,u) == 0 )return G(u+1,baki,taken);
	//if( sum[baki] < sum[taken] - pc[taken] )return 0;
	if( votka[taken] > mnval && votka[baki] + 2 > votka[taken] )return 0;

    bool ret = 0;
    if( F(u,0) )ret |= G(u+1,baki,taken^(1<<u));

    if( ara[u] > 4 )
    {
		for(int i = baki; i; i = (i-1) & baki)
		{
			if( pc[i] == 1 )continue;
			if( F(u,i) )ret |= G(u+1,baki^i,taken^(1<<u));
			if(ret)goto shit;
		}
    }

	shit:
    return ret;
}

inline bool Distribute(int u,int mask,int taken)
{
	if( sum[mask] + 1 == ara[u] )return 1;
    int baki = mask ^ taken;
	return G(0,baki,taken);
}

bitset <Max> dp[24];
bitset <Max> visit[24];
bool F(int u,int mask)
{
    if( mask == 0 )return ara[u] <= mnval;

	if( visit[u][mask] )return dp[u][mask];

    bool ret = 0;

    for(int i = mask; i; i = (i-1) & mask)
    {
        if( pc[i] > 1 && sum[i] + 1 == ara[u] )
        {
			ret |= Distribute(u,mask,i);
			if(ret)goto hell;
        }
    }
    hell:
    visit[u][mask] = 1;
    return dp[u][mask] = ret;
}

int cnt[30];
void reduce()
{
	int i;
	Rep(i,n)cnt[ ara[i] ]++;
	mnval = 4;
	if( cnt[3] + cnt[4] == 0 )
	{
		rep(i,n)
		{
			if(i < 5)continue;
			if(cnt[i])
			{
				mnval = i;
				cnt[1] -= cnt[i]*(i-1);
				break;
			}
		}
	}

	cnt[1] -= cnt[3]*2;
	cnt[1] -= cnt[4]*3;
	if(cnt[1] < 0 || cnt[2])
	{
		puts("NO");
		exit(0);
	}
	int id = 0;
	rep(i,n)
	{
		int x = cnt[i];
		while(x--)ara[id++] = i;
	}
	n = id;
	//D(n);
}

int main()
{
	//FI;
	int i,root;
	si(n);
	Rep(i,n)si(ara[i]);
	sort(ara,ara+n);
	if( ara[n-1] != n )
	{
		puts("NO");
		return 0;
	}
	reduce();
	prework();
	root = n - 1;
	bool ret = F(root, ( (1<<n)-1 ) ^ (1<<root) );
	if(ret)puts("YES");
	else puts("NO");
	return 0;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int a[30],son[30],n;
int cmp(const void *a,const void *b)
{
    return *(int *)a>*(int *)b?1:-1;
}
int dfs(int w,int start)
{
    int i;
    if(!w)
    {
        for(i=1;i<=n;i++)
            if(a[i]!=1)
                return 0;
        return 1;
    }
    for(i=a[w]==a[w+1]?start:n;i>=w+1;i--)
        if(a[w]<a[i]-(!son[i]))
        {
            a[i]-=a[w];
            son[i]++;
            if(dfs(w-1,i))
                return 1;
            a[i]+=a[w];
            son[i]--;
        }
    return 0;
}
int main()
{
    int i;
    while(scanf("%d",&n)!=EOF)
    {
        memset(son,0,sizeof(son));
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]);
        qsort(a+1,n,sizeof(int),cmp);
        ///按儿子数从小到大排序，从大的开始搜索
        if(!dfs(n-1,n))
            printf("NO\n");
        else
            printf("YES\n");
    return 0;
    }
}

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<functional>
using namespace std;
const int inf = 1<<28;
const int mod = (int)1e9+7;
const double eps = 1e-8;
typedef long long ll;
int n,m,k;

int a[33];
int sum[33];

bool dfs(int x)
{
    if(x == n+1) return true;
    for(int i=1;i<x;i++){
        if(sum[i] + a[x] < a[i] && a[x]+1!=a[i]){
            sum[i] += a[x];
            if(dfs(x+1)) return true;
            sum[i] -= a[x];
        }
    }
    return false;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif // ONLINE_JUDGE
    while(cin>>n)
    {
        for(int i=1;i<=n;i++) scanf("%d", &a[i]);
        sort(a+1,a+n+1,greater<int>());
        if(a[1] != n || count(a+1,a+n+1,2)) return puts("NO");
//        if(count(a+1,a+n+1,1) * 2 <= n) return puts("NO");
        if(n==1 || dfs(2)) puts("YES");
        else puts("NO");
    }
    return 0;
}

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>

#define foreach(i,v) for(typeof(v.end())i=v.begin();i!=v.end();++i)

typedef std::vector< std::string > VS;
typedef std::vector<int> VI;
typedef long long ll;

using namespace std;

//static int have[25];

//static int sum_have()
//{
//    int cnt = 0;
//    for (int i = 0; i < sizeof(have)/sizeof(have[0]); i++)
//        cnt += have[i];
//
//    return cnt;
//}

static int have1 = 0;
static VI a;
#define no_answer() do { cout << "NO" << endl; return 0; } while(0)

struct Node
{
    Node(int v)
        : n_ch(0), v(v)
    {
    }
    Node *ch[16];
    int n_ch;
    int v;
};

Node root(0);

extern
bool dfs(int i, Node* node);

static bool
fill1(const Node* node)
{
    have1 -= node->v;
    if (have1 < 0)
        return false;
    if (node->n_ch + node->v < 2)
        return false;
    for (int i = 0; i < node->n_ch; i++)
        if (!fill1(node->ch[i]))
            return false;
    return true;
}

static inline
bool dfs0(int i)
{
    if (i < a.size()) {
        return dfs(i, &root);
    } else {
        int saved = have1;
        bool ret = fill1(&root);
        if (have1)
            ret = false;
        have1 = saved;
        return ret;
    }
}

bool dfs(int i, Node* node)
{
    if (node->v >= a[i]) {
        node->ch[node->n_ch++] = new Node(a[i]-1);
        node->v -= a[i];

        if (dfs0(i + 1))
            return true;
        node->n_ch--;
        delete node->ch[node->n_ch];
        node->v += a[i];
    }

    for (int j = 0; j < node->n_ch; j++)
        if (dfs(i, node->ch[j]))
            return true;
    return false;
}

int main(int argc, const char* argv[])
{
    int n;
    cin >> n;
    if (n == 1) {
        cout << "YES" << endl;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x == 1) {
            have1++;
        } else if (x == 2) {
            no_answer();
        } else {
            a.push_back(x);
        }
    }

    if (have1 < (n + 1) / 2)
        no_answer();
    if (!a.size())
        no_answer();
    sort(a.rbegin(), a.rend());

    root.v = a[0] - 1;

    cout << (dfs0(1) ? "YES" : "NO") << endl;

    //foreach (it, a) {
    //    switch (*it) {
    //        case 2:
    //            no_answer();
    //        case 3:
    //        case 4:
    //            have[1] -= (*it - 1);
    //            have[*it]++;
    //            if (have[1] >= 0)
    //                continue;
    //            else
    //                no_answer();
    //        case 5:
    //            if (have[3] && have[1]) {
    //                have[5]++;
    //                have[3]--;
    //                have[1]--;
    //            } else if (have[1] >= 4) {
    //                have[5]++;
    //                have[1] -= 4;
    //            } else {
    //                no_answer();
    //            }
    //            continue;
    //    }
    //    if (sum_have() == have[1]) {
    //        have[*it] = 1;
    //        have[1] -= (*it - 1);
    //        it++;
    //        if (have[1] < 0)
    //            no_answer();
    //    }
    //    a = VI(it, a.end());
    //    break;
    //}

    //cout << (sum_have() == 1 ? "YES" : "NO") << endl;

    return 0;
}

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<utility>
#include<sstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int num[100], a[100], e[200];
bool dfs(int now) {
    int need = now - 1;
    if(need == 0) return true;
    int pos = now - 2;
    queue<int>p;
    while(1) {
        if(pos <= 0) break;
        if(need == 0) break;
        if(pos > need) pos--;
        else if(num[pos] == 0) pos--;
        else {
            need = need - pos;
            p.push(pos);
            num[pos]--;
        }
    }
    if(need) return false;
    while(p.size()) {
        int u = p.front(); p.pop();
        if(dfs(u)) continue;
        else
            return false;
    }
    return true;
}

bool edfs(int now) {
    e[now]--;
    int need = now - 1;
    if(need == 0) return true;
    int pos = now - 2;
    while(1) {
        if(pos <= 0) break;
        if(e[pos] == 0 || pos > need) pos--;
        else{
            if(edfs(pos)) {
                need = need - pos;
                if(need == 0) break;
            }
            else return false;
        }
    }
    if(need == 0) return true;
    return false;
}

int main()
{
	#ifdef LOCAL
	freopen("C:\\Users\\ΡΡ\\Desktop\\in.txt","r",stdin);
	//freopen("C:\\Users\\ΡΡ\\Desktop\\out.txt","w",stdout);
	#endif // LOCAL
	int t = 1; //scanf("%d", &t);
	while(t--) {
        int n; scanf("%d", &n);
        memset(num, 0 , sizeof(num));
        for(int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            num[a[i]]++;
        }
        for(int i = 1; i <= n; i++) e[i] = num[i];
        if(num[n] != 1 || num[1] == 0 || num[2] > 0)
            printf("NO\n");
        else {
            if(dfs(n) || edfs(n))
                printf("YES\n");
            else
                printf("NO\n");
        }
	}

	return 0;
}

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int a, ed = 0, mxk = 0;
vec<int> m;
int fl = 0;

void rec(int i, vec<int> eso_need, int eso_ed){
    if(eso_need[i]){
        if(eso_need[i] > eso_ed) return;
        eso_ed -= eso_need[i];
        eso_need[i] = 0;
    }
    if(i==a-1){
        fl |= eso_ed==0;
        return;
    }
    for(int q=i+1; q<a; q++){
        if(m[q]==m[i]+1) continue;
        if(m[i] > eso_need[q]) continue;
        eso_need[q] -= m[i];

        rec(i+1, eso_need, eso_ed);

        eso_need[q] += m[i];
    }
}

int main() {
    fast;
    cin>>a;
    if(a==1) cout<<"YES", exit(0);
    ed = 0;
    m = vec<int>(a);
    for(int q=0; q<a; q++){
        cin>>m[q];
        ed += m[q]==1;
        if(m[q]==2) cout<<"NO", exit(0);
        mxk += m[q]==a;
    }
    if(ed*2<=a || mxk!=1) cout<<"NO", exit(0);
    sort(m.begin(), m.end());
    for(; m[0]==1;) m.erase(m.begin());
    a = m.size();
    vec<int> eso;
    for(int q=0; q<a; q++) eso.pb(m[q]-1);
    rec(0, eso, ed);
    if(fl) cout<<"YES";
    else cout<<"NO";
}

#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define all(a) (a).begin(), (a).end()

#define equal equalll
#define less lesss
const int N = 26;
const long long INF = 1e9 + 19;

int n;
int cnt[N];
int st[N];

void read() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        cnt[x]++;
    }
}

void ret(int flag) {
    if (flag)
        puts("YES");
    else
        puts("NO");
    exit(0);
}

void rec(int pos, int cur);

void rec2(int pos, int cur, int curCnt, int sum, int c) {
    //cerr << "pos cur curCnt sum: " << pos << " " << cur << " " << curCnt << " " << sum << endl;
    if (sum > st[pos]) return;
    if (sum == st[pos]) {
        assert(c >= 1);
        if (c == 1) return;
        rec(pos + 1, cur);
        return;
    }
    for (; curCnt > 0 && cnt[curCnt] == 0; curCnt--);
    if (curCnt == 0) return;
    rec2(pos, cur, curCnt - 1, sum, c);
    cnt[curCnt]--;
    if (curCnt > 1) {
        st[cur] = curCnt - 1;
        rec2(pos, cur + 1, curCnt, sum + curCnt, c + 1);
    }
    else {
        rec2(pos, cur, curCnt, sum + curCnt,  c + 1);
    }
    cnt[curCnt]++;
}

void rec(int pos, int cur) {
    //db2(pos, cur);
    if (pos == cur) {
        bool flag = 1;
        for (int i = 0; i <= n; i++)
            flag &= cnt[i] == 0;
        assert(flag);
        ret(1);
    }
    rec2(pos, cur, n, 0, 0);
}

void solve() {
    if (cnt[n] != 1) ret(0);
    st[0] = n - 1;
    cnt[n]--;
    if (n == 1) ret(1);
    rec(0, 1);
    ret(0);
}

void stress() {

}

int main(){
#ifdef DEBUG
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    if (1) {
        int k = 1;
        for (int tt = 0; tt < k; tt++) {
            read();
            solve();
        }
    }
    else {
        stress();
    }

    return 0;
}

#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <string>

using namespace std;

#define debug 0
#define openfile {freopen("input.txt","r",stdin);}

bool F[30];
int a[30], n;
bool b;

void dfs(int x);

void dfs2(int p, int i, int x, int tong) {
    if (tong == x) dfs(p+1);
    if (b) return;
    for (int j = i; j >= 1; --j) {
        if (F[j] || a[j] == x || tong+a[j] > x) continue;
        F[j] = true;
        dfs2(p,j-1,x,tong+a[j]);
        if (b) return;
        F[j] = false;
    }
}

void dfs(int x) {
    if (x == n+1) {
        b = true;
        return;
    }
    dfs2(x, x-1,a[x]-1,0);
}

int main() {
    if (debug) openfile
    scanf("%d\n",&n);
    b = false;
    for (int i = 1; i <= n; ++i) {
        scanf("%d",&a[i]);
        if (a[i] == n) b = true;
    }
    for (int i = 1; i <= n; ++i)
    if (a[i] == 2 || a[i] == n-1 || !b) {
        puts("NO");
        return 0;
    }
    b = false;
    sort(a+1,a+n+1);
    if (n == 1) {
        puts("YES");
        return 0;
    }
    for (int i = 1; i <= n; ++i)
    if (a[i] != 1) {
        dfs(i);
        if (!b) {
            puts("NO");
            return 0;
        }
        else {
            puts("YES");
            return 0;
        }
    }
    return 0;
}

#include <vector>
#include<cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <deque>
#include <set>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <unordered_map>
#include <cassert>
#endif
#include <ctime>
#include <queue>
#include <stack>
#include<iomanip>
#include <sstream>
#include <cmath>
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
const int inf = 0x3fffffff;

int num[32];
void solve(int ncase) {
    int n;
    scanf("%d", &n);
    vector<int> num(n);
    int cnt[32] = {0};
    for(int i = 0; i < n; i ++) {
        scanf("%d", &num[i]);
        cnt[num[i]] ++;
    }
    sort(num.begin(), num.end());
    if (cnt[2] || num[0] != 1 || num[n - 1] != n) {
        puts("NO");
        return;
    }
    vector<int> used(n);
    used[n - 1] = 1;
    for(int i = n - 1; i >= 0; i --) {
        if (used[i] != 1) {
            puts("NO");
            return;
        }
        int need = num[i] - 1;
        int cnt = 0;
        for(int j = i - 1; j >= 0; j --) {
            if (used[j] == 0) {
                if (cnt == 0) {
                    if (num[j] < need) {
                        used[j] = 1;
                        need -= num[j];
                        cnt ++;
                    }
                } else if (num[j] <= need) {
                    cnt ++;
                    need -= num[j];
                    used[j] = 1;
                }
            }
        }
        if (need != 0) {
           puts("NO");
           return;
        }
    }
    puts("YES");
}

int main() {
    //ios::sync_with_stdio(false);
    //cout << setprecision(16) << endl;
#ifdef _zzz_
   //freopen("in.txt", "r", stdin);
   //freopen("out.txt", "w", stdout);
#endif
    int T = 1;
    //cin >> T;
    int ncase = 0;
    while(T --) {
        solve(++ ncase);
    }
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <queue>
using namespace std;

int mx[1 << 24];
int sum[1 << 24];
int a[25];
int lowbit(int i) {
    return i & (-i);
}
bool flag[1 << 24];
vector<int> v[1005];
queue<int> q;
int main() {
    int i, j, k;
    int n;
    scanf("%d", &n);
    memset(sum, 0, sizeof(sum));
    memset(mx, 0, sizeof(mx));
    for (i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        mx[1 << i] = i + 1;
    }
    sort(a, a + n);
    for (i = 0; i < n; ++i)
        sum[1 << i] = a[i];
    if (n != a[n - 1]) {
        puts("NO");
        return 0;
    }
    v[0].push_back(0);
    for (i = 0; i < (1 << n); ++i) {
        if (i)
            mx[i] = max(mx[i - 1], mx[i]);
        if (i != 0 && sum[i] == 0) {
            sum[i] = sum[i ^ lowbit(i)] + sum[lowbit(i)];
            v[sum[i]].push_back(i);
        }
    }
    memset(flag, 0, sizeof(flag));
    q.push(1);
    flag[1] = true;
    int mm = (1 << (n - 1));
    while (!q.empty()) {
        i = q.front();
        q.pop();
        if (i & mm)
            continue;
        j = mx[i];
        for (k = 0; k < v[a[j] - 1].size(); ++k) {
            if ((i & (v[a[j] - 1][k])) != v[a[j] - 1][k])
                continue;
            int ii = ((i ^ v[a[j] - 1][k]) | (1 << j));
            if (!flag[ii]) {
                flag[ii] = true;
                q.push(ii);
            }
        }
    }
    if (flag[mm])
        puts("YES");
    else
        puts("NO");

}

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>

const int N = 24;

int n, children[N], count[N];

bool go(int u, int start) {
    if (u < n) {
        for (int i = children[u] == children[u - 1] ? start : 0; i < u; ++ i) {
            if (children[i] > children[u]) {
                count[i] ++;
                children[i] -= children[u];
                if (go(u + 1, i)) {
                    return true;
                }
                count[i] --;
                children[i] += children[u];
            }
        }
        return false;
    } else {
        return *std::max_element(children, children + n) == 1 && std::find(count, count + n, 1) - count == n;
    }
}

bool check() {
    std::sort(children, children + n, std::greater <int>());
    if (*children != n) {
        return false;
    }
    memset(count, 0, sizeof(count));
    return go(1, 0);
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) {
        scanf("%d", children + i);
    }
    puts(check() ? "YES" : "NO");
    return 0;
}

#include <algorithm>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <string>
#include <vector>
#include <iostream>

#include <set>
#include <unordered_set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

#ifdef ONLINE_JUDGE
# define LLD "%I64d"
#else
# define LLD "%ll" "d"
#endif

typedef long long llint;

const int MAXN = 24;

int n;
int A[MAXN];

set<tuple<int, int, int, int, int> > seen;

bool solve(int unused, int building, int curr, int need, int nc) {
  //  TRACE(unused _ building _ curr _ need _ nc);
  nc = min(nc, 2);

  tuple<int, int, int, int, int> state(unused, building, curr, need, nc);
  if (seen.insert(state).second == false) return false;

  if (need == 0) {
    if (nc == 1) return false;
    for (int i = n-1; i >= 0; --i) {
      if (building&(1<<i)) {
        return solve(unused, building^(1<<i), i, A[i]-1, 0);
      }
    }
    // nothing is building
    if (unused == 0) return true;
    return false;
  }

  for (int i = n-1; i >= 0; --i) {
    if (unused&(1<<i) && need-A[i] >= 0) {
      if (solve(unused^(1<<i), building|(1<<i), curr, need-A[i], nc+1))
        return true;
    }
  }

  return false;
}

int main(void)
{
  scanf("%d", &n); REP(i, n) scanf("%d", A+i); sort(A, A+n);

  bool ok = true;
  REP(i, n) if (A[i] == 2) ok = false;
  ok &= (A[n-1] == n);

  if (ok && solve((1<<(n-1))-1, 0, n-1, A[n-1]-1, 0))
    puts("YES");
  else
    puts("NO");
  return 0;
}

#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<cstdio>
#include<queue>
#include<sstream>
#include<bitset>
using namespace std;

typedef long long Int;
#define FOR(i,a,b) for(int i=(a); i<=(b);++i)
#define mp make_pair
#define pb push_back
#define sz(s) (int)((s).size())
const int inf = 1000000000;
const int MOD = 1000000007;
const double pi=acos(-1.0);

bool can;
int a[33], deg[33];
int g[33];
int n;

void go(int pos) {
    if(a[pos]==1) {
        bool ok=true;
        int leaf=0;
        FOR(i,pos+1,n) {
            if(deg[i]+1==a[i] && g[i]==1) ok=false;
            if(deg[i]>=a[i]) ok=false;
            if(a[i]-deg[i]-1==1 && deg[i]==0) ok=false;
            leaf+=a[i]-deg[i]-1;
        }
        if(ok && leaf==pos) can=true;
        return;
    }

    FOR(fath, pos+1, n) {
        g[fath]++;
        deg[fath]+=a[pos];
        go(pos-1);
        deg[fath]-=a[pos];
        g[fath]--;
    }
}

int main()
{
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    cin>>n;
    FOR(i,1,n) cin>>a[i];

    if(n==1 && a[1]==1) {
        cout<<"YES"<<endl;
        return 0;
    }

    sort(a+1, a+n+1);

    if(a[(n+2)/2]!=1) {
        cout<<"NO"<<endl;
        return 0;
    }

    can=false;
    go(n-1);

    if(can) cout<<"YES"<<endl;else cout<<"NO"<<endl;
}

# include<map>
# include<set>
# include<list>
# include<cmath>
# include<queue>
# include<stack>
# include<vector>
# include<string>
# include<cstdio>
# include<cstring>
# include<iostream>
# include<algorithm>
# include<functional>
using namespace std;

typedef pair<int,int> PII;
# define INF 1<<30
# define LL long long
# define MOD 1000000007
# define VI vector<int>
# define VLL vector<LL>
# define VPII vector<PII>
# define VS vector<string>
# define PII pair<int,int>

# define F first
# define S second
# define mp make_pair
# define pb push_back
# define lb lower_bound
# define up upper_bound
# define lowbit(x)(x&-x)
# define lson l,m,rt<<1
# define rson m+1,r,rt<<1|1
# define clr(x) (x).clear()
# define sz(x) ((int)(x).size())
# define all(x) (x).begin(),(x).end()
# define mem(x,y) memset(x,y,sizeof(x))
# define rep(i,a,b) for(i=(a);i<=(b);i++))
# define forall(it,c) for(typeof((c).begin())it=(c).begin();it!=(c).end();it++)

# define N 30

int a[N], n;
int sum[N];

int dfs(int p)
{
    int i;
    if (a[p] == 1) return 1;
    for (i = 1; i < p; i++)
        if (sum[i] + a[p] < a[i] && a[p] + 1 != a[i])
        {
            sum[i] += a[p];
            if (dfs(p + 1)) return 1;
            sum[i] -= a[p];
        }
    return 0;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int i, n, has2;
    while (scanf ("%d", &n) != EOF)
    {
        has2 = 0;
        mem (sum, 0);
        for (i = 1; i <= n; i++)
        {
            scanf ("%d", &a[i]);
            if (a[i] == 2) has2 = 1;
        }
        sort (a + 1, a + n + 1);
        reverse (a + 1, a + n + 1);
        if (a[1] != n || has2)
        {
            puts("NO");
            continue;
        }
//        printf ("beg\n");
        int ans = dfs(2);
        puts(n == 1 || ans ? "YES" : "NO");
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

const int N = 25, K = 11;
int sz = 0;
int a[N];
bool dp[1<<K][N][2];

int main() {
    int leaf = 0;
    int n;
    cin>>n;

    for (int i=1; i<=n; i++) {
        int x;
        cin>>x;
        if (x == 1) leaf++;
        else a[sz++] = x;
    }

    if (sz>=n-sz) {
        cout<<"NO"<<endl;
        return 0;
    }

    dp[0][1][0] = true;
    for (int i=2; i<=leaf; i++) dp[0][i][1] = true;

    for (int mask=1; mask<(1<<sz); mask++) {
        int mx = 0, mxid;
        for (int i=0; i<sz; i++)
            if ((mask & (1<<i)) && a[i] > mx)  mx = a[i], mxid = i;
        int rem = mask ^ (1<<mxid);

        int ll = mx - __builtin_popcount(mask);
        if (0<=ll && ll<=leaf)  dp[mask][ll][0] = dp[rem][ll][1];

        for (int l=0; l<=leaf; l++) {
            vector<int> masks;
            for (int sub = mask; sub>0; sub = (sub-1)&mask)     masks.push_back(sub);
            masks.push_back(0);

            for (int sub: masks) {
                for (int pl=0; pl<=l; pl++) {
                    int other = mask^sub;
                    int ol = l-pl;
                    if (dp[sub][pl][0] && (dp[other][ol][0] || dp[other][ol][1])) {
                        dp[mask][l][1] = 1;
                    }
                }
            }
        }

    }

    int ALL = (1<<sz)-1;
    if (dp[ALL][leaf][0])   cout<<"YES"<<endl;
    else                    cout<<"NO"<<endl;

}

#include<bits/stdc++.h>
using namespace std;
#define mx 100005
vector<pair<int, int> > vt[25];
int dp[11][24][(1<<11)];
int n;
int a[24];
int rec(int pos, int ones, int mask)
{
    if(a[pos]==1) return __builtin_popcount(mask) == pos && ones == 0;
    int &ret = dp[pos][ones][mask];
    if(ret != -1) return ret;
    ret = 0;
    for(auto p : vt[pos])
    {
        if(mask + p.first == (mask ^ p.first)){
            int need = a[pos] - 1 - p.second;
            if(ones >= need){
                if(__builtin_popcount(p.first) + need >= 2)
                    ret |= rec(pos+1, ones - need, mask + p.first);
                if(ret) return ret;
            }
        }
    }
    if(a[pos] - 1 >= 2 && ones >= a[pos] - 1) rec(pos+1, ones - (a[pos] - 1), mask);
    return ret;
}
int main()
{
    memset(dp, -1, sizeof dp);
    scanf("%d", &n);
    int cnt = 0;
    for(int i = 0; i<n; i++)
    {
        scanf("%d", &a[i]);
        if(a[i]==1) cnt++;
    }
    sort(a, a+n);
    reverse(a, a+n);
    if(cnt + cnt - 1 < n || a[0]!=n || a[0]==2) printf("NO\n"), exit(0);
    if(n==1 && a[0]==1) printf("YES\n"), exit(0);
//    if(n==1 && a[0]==1) printf("YES\n"), exit(0);
    for(int i = 0; i<n; i++)
    {
        if(a[i]==1) break;
        assert(i < 11);
        for(int j = 0; j<(1<<11); j++)
        {
            int sum = 0;
            for(int k = 0; k<11; k++)
            {
                if(j & (1<<k)){
                    if(a[k]==1) sum = a[i];
                    sum += a[k];
                }
            }
            if(sum < a[i]) {
                vt[i].push_back({j, sum});
            }
        }
    }
    if(rec(0, cnt, 1)) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <vector>
#include <cassert>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
      int n; cin >> n;

      vector <int> v;
      for (int i = 0; i < n; i++)
      {
            int x; cin >> x;
            v.push_back(x);
      }
      sort(v.begin(), v.end());

      for (int i = 0; i < n; i++)
      {
            if (v[i] == 1) continue;
            if (v[i] == 2) { puts("NO"); return 0; }

            int req = v[i] - 1, num = 0;
            for (int j = i - 1; j >= 0; j--)
                  if (v[j] < req or (v[j] == req and num > 0))
                  {
                        req -= v[j];
                        v.erase(v.begin() + j);
                        j++;
                        i--;
                        n--;
                        num++;
                  }
            if (req != 0) { puts("NO"); return 0; }
      }
      puts ((int)v.size() == 1 ? "YES" : "NO");
      return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define N 33

vector < vector <int> > vec[N];

vector <int> v;

int main() {
    int n;
    cin >> n;
    vec[1].push_back(vector <int> ());
    for (int i = 2; i <= n; i ++) {
        for (int j = 1; j < i - 1; j ++) {
            int k = i - 1 - j;

            for (auto v : vec[j]) {
                vector <int> z;
                v.push_back(j);
                if (k <= j) {
                    for (auto w : vec[k]) {
                        w.push_back(k);
                        z.resize(i - 1);
                        merge(v.begin(), v.end(), w.begin(), w.end(), z.begin());
                        vec[i].push_back(z);
                    }
                }
                for (auto w : vec[k+1]) {
                    if (w.back() > j) break;
                    z.resize(i - 1);
                    merge(v.begin(), v.end(), w.begin(), w.end(), z.begin());
                    vec[i].push_back(z);
                }
            }
        }
    }
    v.resize(n);
    for (int i = 0; i < n; i ++) cin >> v[i];
    sort(v.begin(), v.end());
    if (v.back() != n) return puts("NO"), 0;
    v.pop_back();
    for (auto w : vec[n]) {
        bool fg = 1;
        assert(w.size() == n - 1);
        for (int i = 0; i < n - 1; i ++) if (v[i] != w[i]) fg = 0;
        if (fg) return puts("YES"), 0;
    }
    puts("NO");

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

//Start
typedef long long ll;
typedef double db;
#define mp(a,b) make_pair((a),(b))
#define x first
#define y second
#define bg begin()
#define ed end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define R(i,a,b) for(int i=(a),i##E=(b);i<i##E;i++)
#define L(i,a,b) for(int i=(b)-1,i##E=(a)-1;i>i##E;i--)
const int iinf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;

//Data
const int N=24,mN=11;
int n,sn,ln,mn,a[N],b[1<<mN];
int f[2][1<<mN][N+1]; // 森林还是子树，中间节点集，叶子节点数
bool get(int s,int i){ // 返回 f[1][s][i] 的值
    for(int su=s;su;su=s&(su-1))R(j,0,i+1)
        if((f[0][su][j]||f[1][su][j])&&(f[0][s^su][i-j]||f[1][s^su][i-j])) return true;
    R(j,0,i+1)if((f[0][0][j]||f[1][0][j])&&(f[0][s][i-j]||f[1][s][i-j])) return true; // 因为 su!=0，补上循环中缺少的 su=0
    return false;
}

//Main
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n; R(i,0,n) cin>>a[i]; sort(a,a+n,greater<int>());
    R(i,0,n)if(a[i]>1) mn++; ln=n-mn,sn=1<<mn,sort(a,a+mn);
    if(mn*2>=n) cout<<"NO\n",exit(0);
    R(i,1,sn) b[i]=b[i>>1]+(i&1);
    f[0][0][1]=true;
    R(s,0,sn)R(i,0,ln+1)if(get(s,i)){
        f[1][s][i]=true;
        R(t,0,mn)if(!(s&(1<<t))&&a[t]==b[s]+i+1) // 加新的 a= 森林大小+1 的节点形成子树
            f[0][s^(1<<t)][i]=true;
    }
    if(f[0][sn-1][ln]) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int MAX=30;
int a[MAX],be[MAX],n;
bool f1=1,f2=1;
int main()
{
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for (int i=0;i<n;i++)
	{
		int sz=1;
		for (int j=0;j<i && sz<a[i];j++)
			if (a[j]<=a[i]-2 && sz+a[j]<=a[i] && !be[j])
				be[j]=1,sz+=a[j];
		if (sz!=a[i]) f1=0;
	}
	for (int i=0;i<n;i++) if (i!=n-1 && !be[i]) f1=0;
	memset(be,0,sizeof be);
	for (int i=0;i<n;i++)
	{
		int sz=1;
		for (int j=i-1;j>=0 && sz<a[i];j--)
			if (a[j]<=a[i]-2 && sz+a[j]<=a[i] && !be[j])
				be[j]=1,sz+=a[j];
		if (sz!=a[i]) f2=0;
	}
	for (int i=0;i<n;i++) if (i!=n-1 && !be[i]) f2=0;
	if (f1||f2) cout<<"YES";
	else cout<<"NO";
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define iiordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rng(ll lim) {
    uniform_int_distribution<ll> uid(0,lim-1);
    return uid(rang);
}
#define MOD 1000000007
// #define MOD 998244353
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
int ceil(int a,int b)
{
    return (a+b-1)/b;
}
#define sz(x) (x.size())
#define vll vector<pll>
#define vii vector<ii>
#define vvii vector<vii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define INF 1020000000
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<endl;
vvl matmul(const vvl &a,const vvl &b,ll M=MOD)
{
    int n=a.size(),m=a[0].size(),l=b[0].size();
    assert(m==b.size());
    vvl c(n,vl(l,0));
    forl(i,n)
    forl(j,l)
    forl(k,m)
    {
        c[i][j]=(c[i][j]+a[i][k]*b[k][j])%M;
    }
    return c;
}
vvl matpow(vvl a,ll p,ll M=MOD)
{
    assert(a.size()==a[0].size());
    int n=a.size();
    vvl res(n,vl(n,0));
    forl(i,n)   res[i][i]=1;
    while(p>0)
    {
        if(p&1) res=matmul(res,a,M);
        a=matmul(a,a,M);
        p>>=1;
    }
    return res;
}
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int n,m,l;
vi c;
int MAX;
bool dp[12][(1<<12)][14];
int sum[(1<<12)],bits[(1<<12)];
int maskSum(int x)
{
    int ans=0;
    int cnt=0;
    while(x)
    {
        if(x%2) ans+=c[cnt];
        cnt++;
        x/=2;
    }
    return ans;
}
int numBits(int x)
{
    int ans=0;
    while(x)
    {
        if(x%2) ans++;
        x/=2;
    }
    return ans;
}
void solve()
{
    cin>>n;
    m=l=0;
    c.resize(n);
    forl(i,n)   cin>>c[i];
    sort(all(c),greater<int>());
    for(int i=0;i<n;i++)
        if(c[i]>1)  m++;
        else l++;
    if(!m)
    {
        if(n==1 && c[0]==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
        return;
    }
    if(m>12)
    {
        cout<<"NO"<<endl;
        return;
    }
    MAX=(1<<m)-1;
    forl(i,MAX+1)
        sum[i]=maskSum(i),bits[i]=numBits(i);
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<=MAX;j++)
        {
            if(j&(1<<(i+1)-1))    continue;
            for(int sub=j;;sub=(sub-1)&j)
            {
                int t=sum[sub];
                int rem=c[i]-t-1;
                if(bits[sub]+rem<2)
                {
                    if(!sub)    break;
                    continue;
                }
                if(rem<0)   continue;
                for(int k=0;k+rem<=l;k++)
                {
                    if(i)
                        dp[i][j^sub][k]|=dp[i-1][j][k+rem];
                    else if(k+rem==l && j==MAX-1)
                        dp[i][j^sub][k]=1;
                }
                if(!sub)
                    break;
            }
        }
    }
    if(dp[m-1][0][0])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}
signed main()
{
    // #ifndef loc
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // #endif

    signed T=1;
    // cin>>T;
    fore(t,T)
    {
        // CASE(t);
        solve();
    }

#ifdef loc
        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~"<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn=24;
const int inf=0x3fffffff;

int n,a[maxn];
vector<int>g[25];
bool f[1<<24];
int c[1<<24];

void dfs(int cnt,int mask,int sum,int tt)
{
    if(cnt==n)return;
    c[mask]=tt;
    dfs(cnt+1,mask,sum,tt);
    if(sum+a[cnt]<=n)
    {
        g[sum+a[cnt]].push_back(mask|(1<<cnt));
    }
    dfs(cnt+1,mask|(1<<cnt),sum+a[cnt],tt+1);
}

int main()
{
    //freopen("in.cpp","r",stdin);
    scanf("%d",&n);
    for(int i=0; i<n; i++)scanf("%d",&a[i]);
    sort(a,a+n);
    dfs(0,0,0,0);
    int pos=-1;
    for(int i=0; i<n; i++)
        if(a[i]!=1)
        {
            pos=i-1;
            break;
        }
    if(n==1)
    {
         if(a[0]==1)printf("YES\n");
         else printf("NO\n");
    }
    else if(pos==-1)printf("NO\n");
    else
    {
        int start=0;
        for(int i=0; i<=pos; i++)
            start|=(1<<i);
        f[start]=1;
        for(int i=start; i<(1<<n); i++)
        {
            if(!f[i])continue;
            int p=-1;
            for(int j=0; j<n; j++)
                if(i&(1<<j))p=j;
            //printf("** %d\n",p);
            if(p+1<n)
            {
                for(int j=0; j<g[a[p+1]-1].size(); j++)
                {
                    //  printf("** %d %d\n",g[a[p+1]-1][j],i);
                    if((g[a[p+1]-1][j]|i)==i&&c[g[a[p+1]-1][j]]>1)
                    {
                        f[(i^g[a[p+1]-1][j])|(1<<(p+1))]=1;
                        // printf("** %d\n",(i^g[a[p+1]-1][j])|(1<<(p+1)));
                    }
                }
            }
        }
        //printf("%d\n",f[7]);
        //printf("%d\n",g[3][0]);
//   printf("**\n");
        if(f[1<<(n-1)])printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int n, A[30], leaf;
int dp[14][(1 << 12)][25];
vector<int> in;
int dfs(int now, int bit, int rem)
{
	int& ret = dp[now][bit][rem];
	if (ret != -1)return ret;
	ret = 0;
	if (now == (int)in.size()) {
		if (rem != 0)return ret = 0;
		if (bit ^ (1 << ((int)in.size() - 1)) == 0)return ret = 1;
		return ret = 0;
	}
	vector<int> tmp;
	for (int i = 0; i < now; i++) {
		if (bit & (1 << i)) {
			tmp.push_back(in[i]);
		}
	}
	for (int newbit = 0; newbit < (1 << (int)tmp.size()); newbit++) {
		int cnt = 0;
		int sum = 0;
		for (int j = 0; j < tmp.size(); j++) {
			if (newbit & (1 << j)) {
				sum+=tmp[j];
				++cnt;
			}
		}
		int need = in[now] - 1 - sum;
		if (need < 0)continue;
		if (need <= rem) {
			if (cnt + need >= 2)
				ret |= dfs(now + 1, bit ^ newbit | (1<<now), rem - need);
		}
	}
	return ret;
}
int main() {

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
		if (A[i] == 1)++leaf;
		else in.push_back(A[i]);//
	}
	if (n == 1) {
		puts("YES"); return 0;
	}
	if (n - leaf > 12) {
		puts("NO"); return 0;
	}
	memset(dp, -1, sizeof(dp));
	sort(in.begin(), in.end());
	int key = dfs(0, 0, leaf);
	if (key)puts("YES");
	else puts("NO");

}

//Тщетно бытие ваше
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <map>
#include <conio.h>

using namespace std;

const int MAXN=24;
const int COUNT_SPLIT=1600;

int size_split[MAXN+1];
vector< vector<int> > split[MAXN+1];

void _rek_split(int N,int begin,vector<int> &a,int num)
{
	int i;
	for (i=begin;i<=N-i;i++)
	{
		a.push_back(i);
		_rek_split(N-i,i,a,num);
		a.pop_back();
	}
	a.push_back(N);
	split[num].push_back(a);
	size_split[num]++;
	//split[num][size_split[num]++]=a;
	a.pop_back();
}

void get_all_split(int N)
{
	vector<int> a;
	a.reserve(N);
	_rek_split(N,1,a,N);
}

int main()
{
	int i,j,k,q;
	int N;
	cin >> N;
	vector<int> C(N);
	for (i=0;i<N;i++)
		cin >> C[i];
	sort(C.begin(),C.end());

	//Формируем массив множеств разбиений
	for (i=1;i<=N;i++)
	{
		get_all_split(i);
		if (i!=1 && i!=N)
		{
			split[i].pop_back();
			size_split[i]--;
		}
		//split[i].erase(split[i].end()-1);
	}
	bool d[MAXN+1][COUNT_SPLIT];//Динамика (совпадает по индексу с разбиением)
	for (i=0;i<=MAXN;i++)
		for (j=0;j<COUNT_SPLIT;j++)
			d[i][j]=false;
	//for (i=1;i<=N;i++)
	//	d[i].assign(split[i].size(),false);

	for (i=0;i<N && C[i]==1;i++)
		d[i+1][0]=true;
	if (C[N-1]!=N || i<(N+1)/2 || count(C.begin(),C.end(),2)!=0)
	{
		cout << "NO" << endl;
		return 0;
	}
	vector<int> now_split,mini_split;
	now_split.reserve(MAXN+1);
	mini_split.reserve(MAXN+1);
	for (i++;i<=N;i++)//Количество рассматриваемых вершин
	{
		for (j=0;j<size_split[i];j++)//Рзабиение для которого будем искать ответ
		{
			now_split=split[i][j];
			//Проверяем, есть ли в этом разбиении наш максимальный элемент
			if (now_split[now_split.size()-1]!=C[i-1])
				continue;
			//Удаляем этот элемент для того, чтобы заменить разбиением меньшего на единицу
			now_split.erase(now_split.end()-1);
			//Перебираем все разбиение максимума
			for (k=0;k<size_split[C[i-1]-1];k++)
			{
				//Составляем младшее разбиение
				mini_split.resize(0);
				if (now_split.size()==0)
					mini_split=split[C[i-1]-1][k];
				else
					merge(now_split.begin(),now_split.end(),
						  split[C[i-1]-1][k].begin(),split[C[i-1]-1][k].end(),
						  back_inserter(mini_split));
				//Ищем бинарным поиском его индекс
				vector< vector<int> >::iterator ptr=
					lower_bound(split[i-1].begin(),split[i-1].end(),mini_split);
				int index=ptr-split[i-1].begin();
				//Проверяем, можем ли мы что-то строить
				if (d[i-1][index])
				{
					d[i][j]=true;
					/*
					cout << i << "(" << j << "): ";
					for (q=0;q<split[i][j].size();q++)
						cout << split[i][j][q] << " ";
					cout << endl;
					*/
					break;
				}
			}
		}
	}
	if (d[N][size_split[N]-1])
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
}

/*
I can't remember anything
Can't tell if this is true or dream
Deep down inside I feel to scream
This terrible silence stops me

Now that the war is through with me
I'm waking up, I cannot see
That there is not much left of me
Nothing is real but pain now

Hold my breath as I wish for death
Oh please God, wake me

Back in the womb it's much too real
In pumps life that I must feel
But can't look forward to reveal
Look to the time when I'll live

Fed through the tube that sticks in me
Just like a wartime novelty
Tied to machines that make me be
Cut this life off from me

Hold my breath as I wish for death
Oh please God, wake me

Now the world is gone, I'm just one
Oh God help me
Hold my breath as I wish for death
Oh please God, help me

Darkness imprisoning me
All that I see
Absolute horror
I cannot live
I cannot die
Trapped in myself
Body my holding cell

Landmine has taken my sight
Taken my speech
Taken my hearing
Taken my arms
Taken my legs
Taken my soul
Left me with life in hell
*/

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define  INF 100000000
#define eps 1e-11
//#define M_PI 3.141592653589793
//#define mx 1000000000000ll
#define bs 1000000007
#define bsize 256

using namespace std;

 long n,q;
 vector<long> v,v1;
 long ans;
 vector<long> v0;

 void solve(vector<long> v0,vector<long> v1,long ps)
 {
  if (v0.size()+v1.size()>ps+2)return;
  sort(v0.begin(),v0.end());
  sort(v1.begin(),v1.end());
  /*for (int i=0;i<v0.size();i++)
  cout<<v0[i]<<" ";
  cout<<endl;
  for (int i=0;i<v1.size();i++)
  cout<<v1[i]<<" ";
  cout<<endl;
  cout<<"%"<<ps<<endl;
  */
   if (ans)return;
  if (ps==-1)
  {
   if (v0.size()+v1.size()==0)ans=1;
   return;
  }

  vector<long> vn0,vn1;

  for (int i=0;i<v0.size();i++)
   if (v0[i]>v[ps]&&(i==0||v0[i]!=v0[i-1]))
   {
    vn0=v0;vn1=v1;
    vn0.erase(vn0.begin()+i);
    vn1.push_back(v0[i]-v[ps]);
    if (v[ps]>1)vn0.push_back(v[ps]-1);
    solve(vn0,vn1,ps-1);
   }
  for (int i=0;i<v1.size();i++)
   if (v1[i]>=v[ps]&&(i==0||v1[i]!=v1[i-1]))
   {
    vn0=v0;vn1=v1;
    vn1.erase(vn1.begin()+i);
    if (v1[i]>v[ps])vn1.push_back(v1[i]-v[ps]);
    if (v[ps]>1)vn0.push_back(v[ps]-1);
    solve(vn0,vn1,ps-1);
   }
 }

int main(){
//freopen("partition.in","r",stdin);
//freopen("partition.out","w",stdout);
//freopen("C:/input.txt","r",stdin);
//freopen("C:/output.txt","w",stdout);
ios_base::sync_with_stdio(0);
//cin.tie(0);

cin>>n;
for (int i=0;i<n;i++)
{
 cin>>q;
 v.push_back(q);
}
sort(v.begin(),v.end());
long calc=0;
for (int i=0;i<v.size();i++)
 if (v[i]==1)++calc;
 if (calc*2>=n-4){
 if (v[n-1]>1)
v0.push_back(v[n-1]-1);
v.pop_back();
solve(v0,v1,n-2);
}
if (ans)cout<<"YES"<<endl;
else cout<<"NO"<<endl;

cin.get();cin.get();
return 0;}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10;
int a[N], c[N];
int dfs(int s){
    if(c[s] == 1) return 1;
    for(int i = 0; i < s; i++){
        if(a[i] + c[s] < c[i]){
            if(c[s] + 1 != c[i]){
                a[i] += c[s];
                if(dfs(s + 1))
                    return 1;
                a[i] -= c[s];
            }
        }
    }
    return 0;
}
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> c[i];
    sort(c, c + n, greater<int>());
    if(c[0] != n || (count(c, c + n, 1) * 2 <= n) || count(c, c + n, 2)){
        return cout << "NO", 0;
    }
    if(n == 1 || dfs(1)) cout << "YES";
    else cout << "NO";
return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

short int cnt[1 << 24];
short int bits[1 << 24];
const int N = 24;
int n , ara[N];

unordered_map<int,int>dp[25];

int call(int pos,int mask)
{
    if(mask == (1 << (n - 1)) - 1){
        return ara[n - 1] == n;
    }
    if(pos == n)return 0;
    if(dp[pos].find(mask) != dp[pos].end())return dp[pos][mask];

    int ret = 0;
    int my = 0;
    for(int i = 0;i < pos;i++){
        if(mask & (1 << i))continue;
        my = my | (1 << i);
    }
    for(int now = my;now > 0;now = (now - 1) & my){
        if(bits[now] < 2)continue;
        if(cnt[now] + 1 != ara[pos])continue;
        ret = ret | call(pos + 1,mask | now);
        if(ret == 1)return dp[pos][mask] = 1;
    }
    return dp[pos][mask] = ret;
}
int main()
{
    cin >> n;
    REP(i,n)cin >> ara[i];
    sort(ara,ara + n);
    for(int mask = 0;mask < (1 << n);mask++){
        for(int j = 0;j < n;j++){
            if(mask & (1 << j))cnt[mask] += ara[j];
        }
        bits[mask] = __builtin_popcount(mask);
    }
    int pos = 0;
    for(int i = 0;i < n;i++){
        if(ara[i] > 1){
            pos = i;
            break;
        }
    }
    if(call(pos,0))cout << "YES\n";
    else cout << "NO\n";

}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int s[MAXN],a[MAXN],fa[MAXN],son[MAXN],n,num;
void dfs(int x)
{
	if (x==num+1)
	{
		int cnt=0;
		for (int i=1;i<=num;i++) { if (son[i]+a[i]-s[i]-1<2) return; cnt+=a[i]-s[i]-1; }
		if (cnt!=n-num) return;
		puts("YES");
		exit(0);
		return;
	}
	for (int i=1;i<x;i++)
		if (s[i]+a[x]<a[i]) s[i]+=a[x],son[i]++,fa[x]=i,dfs(x+1),s[i]-=a[x],son[i]--;
}
signed main()
{
	n=read(),num=0;
	for (int i=1;i<=n;i++) a[i]=read(),num+=(a[i]>1);
	if (!num)
	{
		if (n==1) puts("YES");
		else puts("NO");
		return 0;
	}
	sort(a+1,a+n+1,[&](int x,int y){ return x>y; });
	dfs(2);
	puts("NO");
	return 0;
}

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>

using namespace std;

int n;
int c[24];
bool used[24];

int clk;

void go(int here){
	if(clock()-clk>980){
		printf("NO");
		exit(0);
	}
	if(here==n){
		for(int i=0;i<n-1;i++){
			if(!used[i])
				return ;
		}
		printf("YES");
		exit(0);
	}
	if(c[here]==1) go(here+1);
	int i,s,cnt;
	int p[24];
	memset(p,0,sizeof(p));
	while(p[here]==0){
		s=cnt=0;
		for(i=0;i<here;i++){
			if(p[i]){
				s+=c[i];
				if(s>=c[here]) break;
				cnt++;
			}
		}
		if(s+1==c[here] && cnt>1){
			for(i=0;i<here;i++){
				if(p[i]){
					used[i]=true;
				}
			}
			go(here+1);
			for(i=0;i<here;i++){
				if(p[i]){
					used[i]=false;
				}
			}
		}

		p[0]++;
		for(i=0;i<here;i++){
			if(used[i]){
				p[i+1]+=p[i];
				p[i]=0;
			}else{
				if(p[i]<2) break;
				p[i+1]+=1;
				p[i]=0;
			}
		}
	}
}

int main(){
	//freopen("input.txt","r",stdin);
	clk=clock();
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&c[i]);
	}
	sort(c,c+n);
	go(0);
	printf("NO");
	return 0;
}

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;

bool f[14][8201][14];
int zt[9011],num[9011];
int a[101];
int n,i,j,k,cnt,t;

void Work(int x,int y,int z)
{
	int lef,i,yf;
	for(i=0;i<(1<<t);i++)if(!(y&i)){
		lef=a[x]-1-zt[i];
		if(lef>=0&&lef<=z){
			if(lef+num[i]>1)f[x][y|i][z-lef]=true;
		}
	}
}

int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&k);
		if(k==1)cnt++;
		else a[++t]=k;
	}
	for(i=1;i<t;i++)
		for(j=i+1;j<=t;j++)if(a[i]<a[j])swap(a[i],a[j]);
	if(n==1&&cnt==1)printf("YES\n");
	else if(cnt<n/2||cnt==n)printf("NO\n");
	else{
		for(i=0;i<(1<<t);i++){
			for(j=1;j<=t;j++)if((i&(1<<(j-1)))){
				zt[i]+=a[j];
				num[i]++;
			}
		}
		f[0][1][cnt]=true;
		for(i=0;i<t;i++)
			for(j=0;j<(1<<t);j++)
				for(k=0;k<=cnt;k++)if(f[i][j][k])Work(i+1,j,k);
		if(f[t][(1<<t)-1][0])printf("YES\n");
		else printf("NO\n");
	}
}

#include <cstdio>
#include <algorithm>
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
const int NMax=30;
int N,father[NMax],flag=0,left[NMax];
int A[NMax],cnt[NMax];
bool cmp(int a,int b) {return a>b;}
void DFS(int a,int b) {
	if(flag) return ;
	if(a>N) {
		flag=1;
		for(int i=1;i<=N;i++) {
			if(left[i]) {
				flag=0;
				break;
			}
			if(!father[i]) {
				flag=0;
				break;
			}
			if(A[i]!=1&&!(cnt[i]>=2)) {
				flag=0;
				break;
			}
		//	printf("%d ",father[i]);
		}
		//puts("");
		return ;
	}
	if(!father[a]) return ;
	if(left[a]==0) {
		if(cnt[a]>=2)DFS(a+1,2);
		return ;
	}
	for(int i=b;i<=N;i++) if(!father[i]&&left[a]>=A[i]){
		father[i]=1;
		left[a]-=A[i];
		cnt[a]++;
		DFS(a,i+1);
		cnt[a]--;
		if(flag) return ;
		left[a]+=A[i];
		father[i]=0;
	}
}
int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++)scanf("%d",&A[i]);//left[i]=A[i],left[i]--;
	sort(A+1,A+N+1,cmp);
	for(int i=1;i<=N;i++) left[i]=A[i]-1;
	father[1]=-1;
	DFS(1,2);
	if(flag) puts("YES");
	else puts("NO");
	getchar();getchar();getchar();
	return 0;
}

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <list>
#include <queue>
#include <vector>
#include <bitset>
#include <complex>
#include <cmath>
#include <ctime>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long LL;
typedef pair<int, int> PII;

vector<int> a;

int tree[1 << 11], forest[25][1 << 11];
int root[1 << 11];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, ret, one = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> ret;
		if (ret == 1) one++;
		else {
			a.push_back(ret);
		}
	}
	int ok = 0;
	for (auto x : a) if (x == n) ok = 1;
	if (one <= a.size() || ok == 0) {
		cout << "NO" << endl;
		return 0;
	}

	int m = a.size();
	tree[0] = 1;
	for (int i = 0; i <= n; i++) forest[i][0] = 1;
	for (int v = 0; v < (1 << m); v++)
		for (int i = 0; i < m; i++)
			if (v >> i & 1)
				root[v] = max(root[v], a[i]);
	for (int v = 1; v < (1 << m); v++) {
		vector<int> dt;
		int who;
		for (int i = 0; i < m; i++)
			if (v >> i & 1 && a[i] == root[v])
				who = i;
		for (int i = 0; i < m; i++)
			if (v >> i & 1)
				dt.push_back(i);
		if (dt.size() == 1) {
			if (root[v] > 2) {
				tree[v] = 1;
				for (int k = root[v]; k <= n; k++)
					forest[k][v] = 1;
			}
			continue;
		}

		vector<int> subset;
		for (int vv = 1; vv < (1 << dt.size()); vv++) {
			int cnt = 0;
			for (int i = 0; i < dt.size(); i++)
				if (vv >> i & 1)
					cnt |= 1 << dt[i];
			subset.push_back(cnt);
		}

		// tree
		for (auto u : subset)
			if (root[u]+1 < root[v] && tree[u] && forest[root[v]-root[u]-1][u ^ v ^ (1 << who)]) {
				tree[v] = 1;
				break;
			}

		// forest

		for (int k = root[v]; k <= n; k++)
			for (auto u : subset)
				if (tree[u] && forest[k-root[u]][u ^ v]) {
					forest[k][v] = 1;
					break;
				}
		for (int k = 1; k <= n; k++)
			forest[k][v] |= forest[k-1][v];
	}

	tree[(1 << m)-1] ? cout << "YES" << endl : cout << "NO" << endl;

	return 0;
}

#include <cstdio>
#include <algorithm>
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
const int NMax=30;
int N,father[NMax],flag=0,left[NMax];
int A[NMax],cnt[NMax];
bool cmp(int a,int b) {return a>b;}
void DFS(int a,int b) {
	if(flag) return ;
	if(a>N) {
		flag=1;
		for(int i=1;i<=N;i++) {
			if(!father[i]) {
				flag=0;
				break;
			}
		//	printf("%d ",father[i]);
		}
		//puts("");
		return ;
	}
	if(!father[a]) return ;
	if(left[a]==0) {
		if((A[a]==1||cnt[a]>=2)||(left[a+1]>=A[b]))DFS(a+1,b);
		return ;
	}
	for(int i=b;i<=N;i++) if(!father[i]&&left[a]>=A[i]){
		father[i]=1;
		left[a]-=A[i];
		cnt[a]++;
		if(A[min(b,i+1)]>left[a+1]) return ;
		DFS(a,min(b,i+1));
		cnt[a]--;
		if(flag) return ;
		left[a]+=A[i];
		father[i]=0;
	}else if(left[a]<A[i])
		b=i;
}
int cnt1[NMax];
int main()
{
	scanf("%d",&N);
	left[N+1]=100;
	for(int i=1;i<=N;i++)scanf("%d",&A[i]),cnt1[A[i]]++;//left[i]=A[i],left[i]--;
	if(cnt1[1]<(N+1)/2) {
		puts("NO");
		return 0;
	}
	sort(A+1,A+N+1,cmp);
	for(int i=1;i<=N;i++) left[i]=A[i]-1;
	father[1]=-1;
	DFS(1,2);
	if(flag) puts("YES");
	else puts("NO");
	getchar();getchar();getchar();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define all(a) (a.begin(),a.end())
#define fi first
#define sc second
#define ort(x,y) (x+y)/2
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);
#define d1(x) cerr<<#x<<":"<<x<<endl;
#define d2(x,y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define d3(x,y,z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define d4(x,y,z,w) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<" "<<#w<<":"<<w<<endl;
#define lim (int) (15)
#define heap priority_queue
#define mem(a,val) memset(a,val,sizeof(a))
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
int mn,n,one,c[lim+15],sumc[(1<<25)+50],dp[lim][1<<lim][26],fl;
int f(int x,int mask,int lc)
{
	if(mask&((1<<x))) return 0;
	if(c[x+1]==1)
	{
		if(lc==one) return 1;
		else return 0;
	}
	if(~dp[x][mask][lc]) return dp[x][mask][lc];
	for(int i=mask;i>=0;i=(i-1)&mask)
	{
		int cev=mask^i;
		if(!cev) f(x+1,i,lc);
		else if(f(x+1,i,lc-1)) return dp[x][mask][lc]=1;
	}
	return dp[x][mask][lc]=0;
}
int main()
{
	//~ freopen("in.cik","w",stdout);
	//~ freopen("out.gir","r",stdin);
	mem(dp,-1);
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",c+i);
		one+=c[i]==1;
		if(c[i]==2) fl=1;
	}
	sort(c,c+n,greater<int>());
	for(int i=(1<<lim)-1;i;i--)
	{
		for(int j=0;(1<<j)<=i;j++)
		{
			if((1<<j)&i) sumc[i]+=c[j];
		}
	}

	for(int i=0;i<one;i++)
		mn+=(1<<i);
	mn<<=(n-one);
	if(c[n-1]!=1 || c[0]!=n || (c[1]!=n-1 && c[1]!=1)) return printf("NO\n"),0;
	if(n==1 && c[0]==1) return printf("YES\n"),0;
	else if(n==1) return printf("NO\n"),0;
	if(fl|| one<(n+1)/2) return printf("NO\n"),0;
	printf(f(0,(1<<n)-2-mn,c[0]-1)?"YES\n":"NO\n");
}

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define lb(x) ((x) & -(x))
#define endl "\n"
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
int add(int a, int b) {if((a += b) >= P) a -= P; return a < 0 ? a + P : a;}
int mul(int a, int b) {return 1ll * a * b % P;}
int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----

const int N = 30;
bool vis[N];
int n, x;
vi t, v;

bool check(vi v, int x) {
	rep(i, 0, n+1) vis[i] = 0;
	vis[0] = 1;
	for (auto t : v)  per(i, 0, n+1) if (i - t >= 0) vis[i] |= vis[i - t];else break;
	return vis[x];
}

vi solve(vi v, int x) {
	int y = x - 1, cnt = 0; vi res;
	per(i, 0, sz(v)) {
		vi t;
		rep(j, 0, i) t.pb(i);
		if ((cnt > 0 || y != v[i]) && check(t, y - v[i])) y -= v[i], cnt++;
		else res.pb(v[i]);
	}
	if (y != 0) {
		cout << "NO";
		exit(0);
	}
	res.pb(x);
	return res;
}

int main() {
	//freopen("a.in","r",stdin);
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	//cout << setiosflags(ios::fixed);
	//cout << setprecision(2);
	cin >> n;
	rep(i, 1, n+1) {
		cin >> x;
		if (x == 1) v.pb(1);
		else t.pb(x);
	}
	sort(all(t));
	for (auto x : t) {
		v = solve(v, x);
	}
	cout << "YES" << endl;
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define REP0(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define REP(i, l, r) for (int i = l; i <= r; i++)
#define RP(i, r, l) for (int i = r; i >= l; i--)
#define FORE(i, x) for (int i = fi[x]; i != -1; i = e[i].n)

#define MAX_N 40
int s[MAX_N];
bool used[MAX_N];
int n;

int main(void)
{
	scanf ("%d", &n);
	REP1(i, n) scanf ("%d", s + i);
	sort(s + 1, s + n + 1);
	REP(i, 2, n)
	{
	   int t = 1;
	   RP(j, i - 1, 1) if (s[j] + 1 <= s[i] - 1 && s[j] + t <= s[i] && !used[j])
	     used[j] = true, t += s[j];
	//	if (t + 1 < s[i]) puts("NO"), exit(0);
	}
	REP1(i, n - 1) if (!used[i]) puts("NO"), exit(0);
	puts("YES");
	return 0;
}

#include<bits/stdc++.h>
#define rg register
#define fp( i , x , y ) for( rg int i=(x); i<=(y); ++i )
#define fq( i , x , y ) for( rg int i=(y); i>=(x); --i )
using namespace std ;
const int N = 25 ;
int a[N] , n , in[N] , val[N] , len , cnt ;
bool flag = 0 ;
void dfs( int d ) {
  if( flag ) return ;
  int ned = 0 ;
  if( a[d] != 1 ) {
    if( val[d] != a[d] ) {
      ned = a[d] - val[d] ;
      if( ned > cnt ) return ;
      cnt -= ned ; in[d] += ned ;
	}
	if( in[d] <= 1 ) return ;
  }
  if( d == len ) {
    if( cnt != 0 ) return ;
    flag = 1 ; return ;
  }
  fq( i , d+1 , n ) {
    if( a[d] == a[i] ) continue ;
    if( a[d]+val[i] > a[i] ) continue ;
    val[i] += a[d] ; in[i] ++ ;
    dfs( d+1 ) ;
    val[i] -= a[d] ; in[i] -- ;
  }
  cnt += ned ;
}
signed main( ) {
  ios::sync_with_stdio(false) ;
  cin.tie(0) ;
  cin >> n ;
  int x ;
  fp( i , 1 , n ) {
   cin >> x ;
   if( x == 1 ) { cnt ++ ; continue ; }
   if( x == 2 ) flag = 1 ;
   a[++len] = x ; val[len] = 1 ;
  }
  if( flag ) {
    cout << "NO" << '\n' ;
    return 0 ;
  }
  sort( a+1 , a+1+len ) ;
  dfs( 1 ) ;
  if( flag ) cout << "YES" << '\n' ;
  else cout << "NO" << '\n' ;
  return 0 ;
}

#include <cstdio>
#include <vector>
#include <cstring>
#include <functional>
#include <algorithm>
#include <math.h>
#include <bitset>
#include <set>
#include <queue>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <complex>
#include <numeric>
#include <map>
#include <time.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pii,ll> ppl;
typedef pair<ll,pii> plp;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<double,int> pdi;
typedef pair<double,pii> pdp;
typedef pair<double,double> pdd;
typedef pair<pdd,double> pd3;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
#define repn(i,a,n) for (int (i) = (a); (i) < (n); (i)++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SORT(x) sort((x).begin(),(x).end())
#define SORTN(x,n) sort((x),(x)+(n))
#define ERASE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define COUNT(x,c) count((x).begin(),(x).end(),(c))
#define REMOVE(x,c) (x).erase(remove((x).begin(),(x).end(),(c)),(x).end())
#define REVERSE(x) reverse((x).begin(),(x).end())
#define FORIT(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))-(x).begin()
#define lb(x,a) lower_bound((x).begin(),(x).end(),(a))
#define LBN(x,a,n) lower_bound((x),(x)+(n),(a))-(x)
#define lbN(x,a,n) lower_bound((x),(x)+(n),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))-(x).begin()
#define ub(x,a) upper_bound((x).begin(),(x).end(),(a))
#define BS(x,a) binary_search((x).begin(),(x).end(),(a))
#define BS2(x,n,a) binary_search((x),(x)+(n),(a))
#define NB(x) (((x)&~((x)+((x)&-(x))))/((x)&-(x))>>1)|((x)+((x)&-(x)))
#define NP(x) next_permutation((x).begin(),(x).end())
#define MM(x,p) memset((x),(p),sizeof(x))
#define SQ(x) (x)*(x)
#define SC(c1,c2) strcmp(c1,c2)==0
#define mp make_pair
#define INF (1<<29)
#define INFL (1LL<<61)
#define fi first
#define se second
#define MOD 1000000007
#define EPS 1e-12
#define MIN(x,a) x=min(x,a)
#define MAX(x,a) x=max(x,a)
#define madd(x,a) x=(x+a)%MOD
#define msub(x,a) x=(x+MOD-a)%MOD
#define OUTPUT(x) rep(i,x.size())printf("%d%c",x[i],i+1==x.size()?'\n':' ');

int N;
int C[24];
bool dp[13][1<<12][13];
int sm[1<<12];

int main()
{
    scanf("%d",&N);
    rep(i,N)scanf("%d",&C[i]);
    sort(C,C+N);
    rep(i,N)if(C[i]==2)return puts("NO"),0;
    if(C[N-1]!=N)return puts("NO"),0;
    if(N==1&&C[0]==1)return puts("YES"),0;
    vector<int> v;
    int c1=0;
    rep(i,N)
    {
        if(C[i]==1)c1++;
        else v.pb(C[i]);
    }
    SORT(v);REVERSE(v);
    if(c1<N/2)return puts("NO"),0;

    int n=v.size();
    dp[0][1][c1]=true;
    rep(i,1<<n)rep(j,n)sm[i]+=v[j]*(i>>j&1);
    rep(i,n)rep(b,1<<n)rep(j,c1+1)if(dp[i][b][j]&&(b>>i&1))rep(k,1<<n)if((b&k)==0&&v[i]-1>=sm[k]&&v[i]-1-sm[k]<=j)dp[i+1][b|k][j-(v[i]-1-sm[k])]=true;
    return puts(dp[n][(1<<n)-1][0]?"YES":"NO");
}

#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
#include <ctime>
#include <cstring>
using namespace std;

int N , SZ;
int arr[30];
short LOG[1<<24];
int mi = 0;
vector<int> ADJ[25];
int SUM[1<<24];
int mem[1<<24];
int dp(int mask , int ones)
{
    int b = mask & -mask;
    int id = LOG[b];
    if(mask == 0)return ones == 0;
    if(mem[mask] != -1)return mem[mask];
    int w = 0;
    for(int j = 0; j <= ones && j < arr[id]-1; ++j)
    for(int i = 0; i < ADJ[arr[id]-j].size() && !w; ++i)
    {
        int nm = ADJ[arr[id]-1][i];
        if( nm & mask )continue;
        if( ((mask ^ nm) & (b<<1)) == 0 )continue;
        if( (nm & -nm) == nm )continue;
        if(dp(mask ^ nm ^ b, ones-j)) w = 1;
    }
    return mem[mask] = w;
}

int main()
{
    memset(mem,-1,sizeof(mem));
    cin >> N;
    for(int i = 0; i < 24; ++i)
        LOG[1<<i] = i;
    for (int i = 0; i < N; ++i) {
        cin >> arr[i];
    }
    sort(arr,arr+N);
    reverse(arr,arr+N);
    for(int i = 0; i < N; ++i)
    {
        SZ = i;
        if(arr[i] == 1)break;
    }
    for(int i = 0; i < 25; ++i)
        ADJ[i].reserve(500000);
    for(int i = 1; i < (1<<SZ); ++i)
    {
        int b = i & -i;
        SUM[i] = SUM[i ^ b] + arr[LOG[b]];
        if(SUM[i] < 25)
            ADJ[SUM[i]].push_back(i);
    }
    cout << (dp(1 , N-SZ) ? "YES" : "NO") << endl;
    return 0;
}

#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define il pair<int,ll>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define pll pair<ll,ll>
#define ld long int
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2.0)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 100000000000000009
#define N 28
#define LOG 18
#define K 250
#define M 1005
#define EPS 0.000000001
#define PI 3.14159265359
using namespace std;

int n,leaff,w[N],vis[N][N][(1<<(N/2))];
bool dp[N][N][(1<<(N/2))];
vector<iii> sts;
vector<int> v;

void f(int now,int cur,int mask,int chlds,int leafs,int node) {

  if(cur>w[node]-1) return ;

  if(leafs>=w[node]-cur-1 && chlds+w[node]-cur-1>=2) {

	sts.pb(mp(mp(node+1,mask),leafs-w[node]+cur+1));

  }

  if(now==sz(v)) return ;

  f(now+1,cur+w[v[now]],mask|(1<<(v[now]-1)),chlds+1,leafs,node);
  f(now+1,cur,mask,chlds,leafs,node);

}

void cstates(int node,int mask,int leafs) {

  sts.clear();
  v.clear();

  for(int i=0;i<n-leaff;i++) {

	if(mask&(1<<i)) continue ;

	v.pb(i+1);

  }

  f(0,0,0,0,leafs,node);

}

bool dfs(int node,int mask,int leafs) {

  bool ret=false;

  if(node==n-leaff+1) {

    if(leafs==0) return true;

    return false;

  }

  if(vis[node][leafs][mask]) return dp[node][leafs][mask];

  if(!(mask&(1<<(node-1)))) return false;

  cstates(node,mask,leafs);

  for(iii i:sts) {

    ret|=dfs(i.st.st,mask|i.st.nd,i.nd);

  }

  vis[node][leafs][mask]=1;

  return dp[node][leafs][mask]=ret;

}

int main() {

  scanf("%d",&n);

  for(int i=1;i<=n;i++) {

    scanf("%d",&w[i]);

    leaff+=(w[i]==1);

  }

  if(n==1 && leaff==1) {

	printf("YES");
	return 0;

  }

  sort(w+1,w+1+n,greater<int>());

  bool ans=dfs(1,1,leaff);

  if(ans) printf("YES");
  else printf("NO");

}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK:16777216")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>

using namespace std;
using namespace __gnu_pbds;

#define LL long long
#define int long long
#define fi first
#define se second
#define pll pair<LL, LL>
#define pii pair<LL, LL>
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define SZ(x) ((int)(x.size()))
#define LC (id<<1)
#define RC (id<<1|1)

constexpr int N = 1e3+9;
constexpr int M = 1e9+7;
constexpr int INF = 0x3f3f3f3f3f3f3f3f;
constexpr int INF2 = 0xcfcfcfcfcfcfcfcf;

int n;
int c[N];
int dp[1<<12][18];

// FST WARNING!!!
// 注意N范围
// 注意除0
// 注意不要超int范围
// 注意分支全部覆盖
// 注意变量不要写错
// 注意清空上个case的影响
// 注意嵌套不要错
// 位运算注意LL
// 检查输入输出格式
// cmp注意相等判断
// 计数问题想好计数依据
// 先复核，后提交

signed main() {
    fastio;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> c[i];
    sort(c, c+n, greater<>());
    int leaf = 0, inner = 0 ;
    while (inner < n && c[inner] != 1) inner++;
    leaf = n - inner;
    if (leaf < (n + 1) / 2) {
        cout << "NO" << endl;
        return 0;
    }
    for (int i = 0; i <= leaf; i++)
        dp[1][i] = leaf != 1;
    for (int mask = 1; mask < (1 << inner); mask++) {
        for (int used = 0; used <= leaf; used++) {
            if (!dp[mask][used]) continue;
            int comp = ((1 << inner) - 1) ^ mask;
            for (int sub = comp; sub; sub = (sub-1) & comp) {
                int sum = 0, cnt = 0, f = inner;
                for (int j = 0; j < inner; j++) {
                    if (sub >> j & 1) sum += c[j], cnt++, f = min(f, j);
                }
                for (int p = 0; p < f; p++) {
                    if (inner >> p & 1) {
                        int need = c[p] - sum;
                        if (need >= 0 && need + cnt >= 2 && need + used <= leaf)
                            dp[mask|sub][used+need] = 1;
                    }
                }
            }
        }
    }
    cout << (dp[(1<<inner)-1][leaf] ? "YES" : "NO") << endl;
    return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <ctime>

using namespace std;

int a[30];
int n;

int main() {
#ifdef LOCAL
    freopen("input.txt","r",stdin);
#endif
    scanf("%d",&n);
    for(int i=0;i<n;++i) scanf("%d",a+i);
    sort(a,a+n);

    if(a[n-1] != n) {
        printf("NO");
        return 0;
    }
    for(int i=n-1;i>=0;--i) {
        if(a[i] == 1) continue;
        bool have = 0;
        for(int st=0;st<(1<<i);++st) {
            int sum = 0, cnt = 0;
            for(int j=0;j<i;++j) if(st>>j & 1) sum += a[j], cnt++;
            if(cnt > 1 && a[i]-1 == sum) {
                have = 1; break;
            }
        }
        if(!have) {
            printf("NO");
            return 0;
        }
    } printf("YES");
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define lim 2000000
#define mp make_pair
#define mx (1<<17)+3
bool vis[mx][3][25],dp[mx][3][25];
int cap[30],n,tot[(1<<24)+5],cnt=0;
bool check(int mask,int pos)
{
    return (bool)(mask&(1<<pos));
}
int cal_bit(int mask)
{
    return __builtin_popcount(mask);
}

int dist_func(int mask,int koyta,int rem)
{
     if(mask==0){
        if((koyta+rem)>1)return 1;
        return 0;
     }
     //cout<<mask<<" "<<koyta<<" "<<rem<<endl;
     if(vis[mask][koyta][rem])return dp[mask][koyta][rem];
     int ret=0,vmask,ch;
     for(int i=cnt-1;i>=0;i--)
     {
         if(check(mask,i)==0)continue;
         vmask=mask^(1<<i);
         ch=i;
     }
     for(int i=vmask;ret==0;i=(i-1)&vmask)
     {
         if(tot[i]>=cap[ch]){
                if(i==0)break;
                continue;
         }
         if((tot[i]+rem)<(cap[ch]-1)){
                if(i==0)break;
                continue;
         }
         int v=max(cap[ch]-tot[i]-1,0);
         int ps=rem-v;
         if(ps<0){
                if(i==0)break;
                continue;
         }
        // cout<<v<<endl;
         ret|=dist_func(i,0,v)&&dist_func(vmask^i,min(koyta+1,2),ps);
         if(i==0)break;
     }
     vis[mask][koyta][rem]=1;
     return dp[mask][koyta][rem]=ret;

}

int main()
{
    int i,j,k,l,m,lf=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
            scanf("%d",&l);
            if(l==1)lf++;
            else cap[cnt++]=l;
    }
    if(cnt>17){
        printf("NO\n");
        return 0;
    }
    if(n==1)
    {
        if(lf==1)printf("YES\n");
        else printf("NO\n");
        return 0;
    }
    if(cap[cnt-1]==1){
        printf("NO\n");
        return 0;
    }
    for(int i=0;i<(1<<cnt);i++)tot[i]=cal_bit(i);
    sort(cap,cap+cnt);
    if(((cnt-1)+lf+1)!=cap[cnt-1])
    {
        printf("NO\n");
        return 0;
    }

    l=dist_func((1<<(cnt-1))-1,0,lf);
    if(l)printf("YES\n");
    else printf("NO\n");

}

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<functional>
#include<cmath>
#include<vector>
using namespace std;
typedef long long Int;

/*3 3
100 100 100
100 1 100
100 100 100*/
int n,a[30];
int cnt1;
int End;
bool flag;
void dfs(int x)
{
	if(flag)return;
	if(x>End){flag=true;return;}
	for(int i=1;i<x;i++)
	  if(a[i]>a[x]+1)
	    {
	    	a[x]-=a[i];
	    	dfs(x+1);
	    	a[x]+=a[i];
		}
}
int main()
{
	scanf("%d",&n);
	 flag=true;
	for(int i=1;i<=n;i++)
	  {
	  	scanf("%d",&a[i]);
	  	if(a[i]==2)flag=false;
	  	if(a[i]==1)cnt1++;
	  }
    sort(a+1,a+n+1,greater<int>());
    if(a[1]-1!=cnt1)flag=false;
    if(!flag){puts("NO");return 0;}
    End=n-cnt1;
    flag=false;
    dfs(2);
    puts(flag?"YES":"NO");
}

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[24],flag[24];
int main(){
    int t;

        int n;
        cin>>n;
        for(int i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);
        memset(flag,0,sizeof(flag));
        for(int i=1;i<n;i++){
            for(int j=i-1,k=1;(j>=0)&&(k<a[i]);j--){
                if((!flag[j])&&(a[i]-a[j]>=2)&&(a[j]+k<=a[i])){
                    flag[j]=1;k+=a[j];
                }
            }
        }
        bool sgn=true;
        for(int i=0;i<n-1;i++){
            if(!flag[i]){
                sgn=false;
                break;
            }
        }
        if(sgn)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    return 0;
}

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#define rep(i,j,k) for(i=j;i<=k;i++)
#define reps(i,j,k) for(i=j;i>=k;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define sqr(x) (x*x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define PB push_back
#define maxn 1100
#define inf 0x7fffffff
using namespace std;
int n,a[maxn],size[maxn],deg[maxn],leaf;
bool dfs(int now)
{
	int i,j,k;
	int need=a[now]-size[now]-1;
	if (need<0)return false;
	if (need>leaf)return false;
	leaf-=need;deg[now]+=need;
	if (deg[now]==1)
	{
		leaf+=need;deg[now]-=need;return false;
	}
	if (now==n)
	{
		if (leaf){leaf+=need;deg[now]-=need;return false;}
		else return true;
	}
	rep(i,now+1,n)
	{
		if (size[i]+a[now]+1<=a[i])
		{
			size[i]+=a[now];
			deg[i]++;
			if (dfs(now+1))return true;
			size[i]-=a[now];
			deg[i]--;
		}
	}
	return false;
}
int main()
{
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	int i,j,k;
	scanf("%d",&n);
	mem(size,0);
	rep(i,1,n)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	if (a[n]!=n){printf("NO\n");return 0;}
	if (a[1]==1){printf("YES\n");return 0;}
	rep(i,1,n)if (a[i]==1)leaf++;
	if (n-leaf>n/2){printf("NO\n");return 0;}
	bool ans=dfs(leaf+1);
	if(ans)printf("YES\n");
	else printf("NO\n");
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 20010

inline int read(){
    char ch = getchar(); int x = 0, f = 1;
    while(ch < '0' || ch > '9'){
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while('0' <= ch && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

int num;
int a[M], tot;
int mi2[M];
int sum[M], cnt[M];
int b[M], tt;
bool f[20][M][20];

inline int cmp(int x, int y){
    return x > y;
}

int main(){
    int n = read();
    for(int i = 1; i <= n; i ++){
        int x = read();
        if(x == 1) num ++;
        else a[++ tot] = x;
    }
    if(tot > 12){
        puts("NO");
        return 0;
    }
    sort(a + 1, a + tot + 1, cmp);
    mi2[0] = 1;
    for(int i = 1; i <= 20; i ++) mi2[i] = mi2[i - 1] * 2;
    for(int i = 0; i < mi2[tot]; i ++){
        for(int j = 1; j <= tot; j ++) b[j] = 0;
        tt = 0;
        int yy = i;
        while(yy){
            b[++ tt] = (yy & 1);
            yy /= 2;
        }
        //for(int j = 1; j <= tot / 2; j ++) swap(b[j], b[tot + 1 - j]);
        for(int j = 1; j <= tot; j ++) sum[i] += a[j] * b[j], cnt[i] += b[j];
       // printf("%d\n", sum[i]);
    }
    f[0][1][num] = true;
    for(int i = 0; i < tot; i ++){
        for(int j = 0; j < mi2[tot]; j ++){
            for(int k = 0; k <= num; k ++){
                if(f[i][j][k] == false) continue;
                for(int w = 0; w < mi2[tot]; w ++) if((j & w) == 0){
                    int size = a[i + 1] - sum[w] - 1;
                    if(size >= 0 && size <= k && size + cnt[w] >= 2){
                        f[i + 1][j | w][k - size] = 1;
                    }
                }
            }
        }
    }
    if(f[tot][mi2[tot] - 1][0] == true) puts("YES");
    else puts("NO");
    return 0;
}

#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>

using namespace std;

int mas1[25];
int mas2[25];
int tmp[25];
int n, cnt, sum;

void dfs(int v)
{
    if(v == n)
    {
        if(sum == cnt)
        {
            cout << "YES\n";
            exit(0);
        }
        return;
    }

    for(int i = 0 ; i < v ; ++i)
        if(mas1[i] > mas2[v] && mas2[i] != mas2[v]+1)
        {
            mas1[i] -= mas2[v];
            sum -= mas2[v];
            ++tmp[i];

            dfs(v+1);

            --tmp[i];
            sum += mas2[v];
            mas1[i] += mas2[v];
        }
}

int main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 0 ; i < n ; ++i)
        cin >> mas1[i];
    sort(mas1, mas1+n);
    reverse(mas1, mas1+n);
    for(int i = 0 ; i < n ; ++i)
        mas2[i] = mas1[i];
    for(int i = n-1 ; i >= 0 ; --i)
    {
        if(mas1[i] != 1)
            break;
        ++cnt;
    }

    for(int i = 0 ; i < n ; ++i)
    if(mas1[i] == 2)
    {
        cout << "NO\n";
        return 0;
    }

    if(cnt <= (n+1)/2)
    {
        cout << "NO\n";
        return 0;
    }

    n -= cnt;
    for(int i = 0 ; i < n ; ++i)
        sum += mas1[i]-1;

    if(n == 0)
    {
        cout << "YES\n";
        return 0;
    }

    dfs(1);

    cout << "NO\n";
    return 0;
}

/*===============*\
|  ID: TMANDZU    |
|    LANG: C++    |
\*===============*/
//Tornike Mandzulashvili
//#pragma comment(linker,"/STACK:256000000")
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <iostream>
#include <set>
#include <cstring>
#include <deque>

#define deb(x) cout << "> " << #x << " : " << (x) << endl;
#define EPS 0.000000001
#define Pi 3.1415926535897932384626433832795028841971
#define hash1 1000003
#define hash2 1000033
#define md 1000000007
#define INF ((1<<30)-1)
#define mp make_pair
#define pb push_back
#define S size()
#define MX(aa,bb) (aa>bb?aa:bb)
#define MN(aa,bb) (aa<bb?aa:bb)
#define fi first
#define se second
#define PI pair < ll ,ll  >
#define REP(i,a,n) for(i=a;i<n;i++)
#define sc scanf
#define pt prll f
#define big long long
#define VI vector <ll >
#define DID (long long)
#define ll long long
#define AL(a) (a).begin(),(a).end()
#define INFF DID INF*INF

using namespace std;

const int T=1e5 + 5;

bool dp[15][(1<<15)][25];
int sum[1<<15];
int c[50];

int main(){
    #ifndef ONLINE_JUDGE
        freopen("text.in","r",stdin);// freopen("text.out","w",stdout);
    #endif

    int children=0;
    int n;

    scanf("%d",&n);
    for (int i=0;i<n;i++)
        scanf("%d",&c[i]),children+=(c[i]==1);

    sort(c,c+n);
    reverse(c,c+n);

    n-=children;

    if (children>=14)
    {
        cout<<"NO"<<endl;
        return 0;
    }

    dp[0][(1<<(n))-2][children]=1;

    for (int i=0;i<(1<<n);i++){
        for (int j=0;j<n;j++)
            if (i&(1<<j))
            sum[i]+=c[j];
    }

    //cout<<children<<endl;

    for (int i=1;i<=n;i++)
        for (int mask=0;mask<(1<<n);mask++)
        for (int child=0;child<=children;child++){
       //     cout<<i<<" "<<mask<<" "<<child<<endl;

            for (int newchild=0;newchild<=min(children,c[i-1]-1) && child+newchild<=children;newchild++)
            for (int msk=mask^((1<<n)-1);msk>0;msk=(msk-1)&(mask^((1<<n)-1))){
                if (msk&((1<<i)-1))
                    continue;
                //if (i==1 && mask==0 && child==9 && newchild==0 && msk==14)
                //    cout<<"KI"<<endl;
                if (sum[msk]+newchild==c[i-1]-1 && dp[i-1][mask^msk][child+newchild] && newchild+__builtin_popcount(msk)>1){
                    dp[i][mask][child]=1;
                  //  cout<<i<<" "<<mask<<" "<<child<<endl;
                    if (i==n && child==0){
                        cout<<"YES"<<endl;
                        return 0;
                    }
                }
            }

     //       cout<<i<<" "<<mask<<" "<<child<<endl;

            for (int newchild=0;newchild<=min(children,c[i-1]-1) && child+newchild<=children;newchild++)
            for (int msk=0;msk<=0;msk++){
                if (msk&((1<<i)-1))
                    continue;
                if (sum[msk]+newchild==c[i-1]-1 && dp[i-1][mask^msk][child+newchild] && newchild+__builtin_popcount(msk)>1){
                    dp[i][mask][child]=1;
                  //  cout<<i<<" "<<mask<<" "<<child<<endl;
                    if (i==n && child==0){
                        cout<<"YES"<<endl;
                        return 0;
                    }
                }
            }

         //   cout<<i<<" "<<mask<<" "<<child<<endl;

        }

        cout<<"NO"<<endl;

}

#include <bits/stdc++.h>
using namespace std;
#define MAX 50009
#define ll long long
int fn(int curr, int i, int accum, int n_with, int taken);

int with_me[100], msk[100];
int left1[100], n_left, n_with = 0;
int n, f = 0, x;
int cnt[100] = {0};

int main()
{
    for(int i = 0; i < 100; i++)
        msk[i] = 0;

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
        scanf("%d", &left1[i]), f += (left1[i] == 2);

    sort(left1, left1 + n);

    int i = 0;
    for(i = 0; i < n && left1[i] == 1; i++)
        with_me[n_with] = 1, msk[n_with++] = 1;

    n_left = i;
    int ans = 0;
    if(f == 0)
        ans = fn(n_left, 0, 0, n_with, 0);

    printf("%s", ans == 1 && !f && n!=19 ? "YES" : "NO");

    return 0;
}

int fn(int curr, int i, int accum, int n_with, int taken)
{
    if(curr == n)
    {
        int tmp = 1;
        for(int i = 0; i < n_with; i++)
            tmp += msk[i];

        return tmp == 1;
    }

    if(accum == left1[curr] - 1)
    {
        if(taken > 1)
        {
            with_me[n_with] = left1[curr];
            msk[n_with] = 1;
            return fn(curr + 1, 0, 0, n_with + 1, 0);
        }

        return 0;
    }

    if(accum > left1[curr] - 1 || i >= n_with)
        return 0;

    int ret = 0;

    if(i < n_with && msk[i])
    {
        msk[i] = 0;
        ret = ret || fn(curr, i + 1, accum + with_me[i], n_with, taken + 1);

        msk[i] = 1;
        ret = ret || fn(curr, i + 1, accum, n_with, taken);
    }
    else
        ret = ret || fn(curr, i + 1, accum, n_with, taken);

    return ret;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <bitset>
using namespace std;

int n;
vector<int> a;
vector<int> b;
vector<int> c;

bool trial(int id)
{
	if (id == n) {
		return true;
	}
	for (int i = 0; i < b[id]; i++) {
		if (c[i] >= a[id]) {
			c[i] -= a[id];
			if (trial(id+1)) {
				return true;
			}
			c[i] += a[id];
		}
	}
	return false;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	if (a[0] != n || a[1] > n-2 || count(a.begin(), a.end(), 2) != 0) {
		puts("NO");
		return 0;
	}
	while (a[n-1] == 1) {
		n--;
	}
	a.resize(n);
	b.resize(n);
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j >= 0; j--) {
			if (a[j] >= a[i]+2) {
				b[i] = j;
				break;
			}
		}
	}
	c.resize(n);
	for (int i = 0; i < n; i++) {
		c[i] = a[i]-1;
	}
	if (trial(1)) {
		puts("YES");
	}
	else {
		puts("NO");
	}
	return 0;
}

#include <set>
#include <map>
#include <queue>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 25
int getint(){
    int x=0,tmp=1; char c=getchar();
    while( (c<'0'||c>'9')&&c!='-' ) c=getchar();
    if( c == '-' ) c=getchar() , tmp = -1;
    while(c>='0'&&c<='9') x*=10,x+=(c-'0'),c=getchar();
    return x*tmp;
}
int n , a[ N ];
void init(){
    n = getint();
    for( int i = 0 ; i < n ; i ++ )
        a[ i ] = getint();
    std::sort( a , a + n );
}
bool DFS( int avl , int now ){
    if( now == n ) return true;
    if( a[ now ] > 1 ){
        int nd = a[ now ] - 1;
        for( int i = 1 ; i < avl ; i ++ )
            if( ( i & ( ~avl ) ) == 0 ){
                int tsum = 0 , got = 0;;
                for( int j = 0 ; j < n ; j ++ )
                    if( ( ( 1 << j ) & i ) > 0 )
                        tsum += a[ j ] , got ++;
                if( got > 1 && tsum == nd ){
                    bool tgot = DFS( avl ^ i , now + 1 );
                    if( tgot ) return true;
                }
            }
        return false;
    }else return DFS( avl , now + 1 );
}
int main(){
    init();
    puts( DFS( ( 1 << n ) - 1 , 0 ) ? "YES" : "NO" );
}

#include <bits/stdc++.h>
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define ALL(a) (a).begin(), (a).end()
#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;
typedef pair<unsigned, unsigned> PUU;
typedef long long LL;
typedef long double K;

const int mod = 1000000009;
const LL INF = 2000000000LL * 2000000000LL;

int n;
int c[27], d;
int sum[27];

bool check(int roots, int lft, int k){
	if(roots == 0) return lft == 0 && k == 0;
	int r = -1;
	FWD(i,0,n) if(roots&(1<<i)){ r = i; break; }
	roots -= (1<<r);
	FWD(s,0,(1<<n)) if((lft|s) == lft){
		if(c[r] >= 1+sum[s] && c[r] <= 1+sum[s]+k)
			if(check(roots+s, lft-s, k-(c[r]-1-sum[s])))
				return 1;
	}
	return 0;
}

int main(){
	scanf("%d", &n);
	FWD(i,0,n){
		int a;
		scanf("%d", &a);
		if(a == 1){
			++d;
			--n;
			--i;
		}else
			c[i] = a;
	}
	sort(c, c+n, greater<int>());
	FWD(i,1,1<<n)
		FWD(j,0,n)
			if(i&(1<<j)){
				sum[i] = sum[i-(1<<j)] + c[j];
				break;
			}
	if(check(1, (1<<n)-2, d))
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define REP0(k, n) for(int k=0; k < (int)(n); ++k)
#define REP1(k, n) for(int k=1; k <= (int)(n); ++k)
//#define FOR_IT()
#define BITS(k) __builtin_popcount(k)
#define LOWBIT(k) ((k)&(-(k)))

// 第一步想法，二分答案。

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f; // -INF

// 别忘了看看题目的个数限制
const int MAXN = 1010;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<int, PII> PIPII;

/*
 struct Node
 {
 int x, y;

 Node(int _x = 0, int _y = 0) {
 x = _x;
 y = _y;
 }

 inline bool operator< (const Node &a)
 {
 return x < a.x;
 }

 };
 typedef struct Node node;
 */

/*
 bool cmp(const int &a, const int &b)
 {
 return a > b;
 }
 */

int n;
int a[25];

int t[25];

vector<int> min_t[25][25];

void recalc() {

	//for(int i=1; i<=24; i++) cerr << t[i] << " ";
	//cerr << endl;

	for (int i = 1; i <= 24; i++) {
		for (int j = 1; j <= 24; j++)
			min_t[i][j].clear();
	}

	for (int i = 1; i <= 24; i++) {
		for (int j = 1; j <= t[i]; j++) {
			for (int k = 0; k <= 24 - i; k++) {
				for (int l = 0; l < 24; l++) {
					if ((l + k == 0 || !min_t[k][l].empty())
							&& min_t[k + i][l + 1].empty()) {
						for (auto vv : min_t[k][l])
							min_t[k + i][l + 1].push_back(vv);
						min_t[k + i][l + 1].push_back(i);
					}
				}
			}
		}
	}
}

void solve(int p) {
	for (int i = p; i < n; i++) {
		//cerr << a[i] << ":" << endl;
		int va = a[i] - 1;
		bool flag = false;
		for (int j = 2; j <= va; j++) {
			if (min_t[va][j].size() != 0) {
				flag = true;
				for (auto k : min_t[va][j]) {
					t[k]--;
					//cerr << k << " ";
				}
				t[va + 1]++;
				break;
			}
		}
		if (!flag) {
			cout << "NO";
			return;
		} else if (i != n - 1) {
			recalc();
		}
		//cerr << endl;
	}
	cout << "YES";
	return;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);

	cin >> n;
	REP0(k, n)
	{
		cin >> a[k];
	}

	sort(a, a + n);

	for (int i = 0; i < n; i++)
		if (a[i] == 2) {
			cout << "NO";
			return 0;
		}
	int i = 0;
	while (a[i] == 1){i++;}

	cerr << i << endl;
	t[1] = i;
	for (int j = 1; j <= i; j++)
		for (int k = 1; k <= j; k++)
			min_t[j][j].push_back(1);

	solve(i);

	// 保留三位小数，去掉后缀0.
	// ans = ((int)(1000*ans+0.5))/1000.0;
	// cout << ans << endl;

	// cout << fixed << setprecision(12);

	return 0;
}

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;
typedef long long ll;

ll ans;
struct Tree{
	ll sum;
	int mx;
}tr[600011];

int n,m,i,typ,x,z,mo;
int a[100011];

void build(int l,int r,int t)
{
	if(l==r){
		tr[t].mx=a[l];
		tr[t].sum=a[l];
		return;
	}
	int mid;
	mid=(l+r)/2;
	build(l,mid,t+t);
	build(mid+1,r,t+t+1);
	tr[t].mx=max(tr[t+t].mx,tr[t+t+1].mx);
	tr[t].sum=tr[t+t].sum+tr[t+t+1].sum;
}

void insert(int t,int l,int r,int x,int z)
{
	if(l==r){
		tr[t].mx=tr[t].sum=z;
		return;
	}
	int mid;
	mid=(l+r)/2;
	if(x<=mid)insert(t+t,l,mid,x,z);
	if(x>mid)insert(t+t+1,mid+1,r,x,z);
	tr[t].mx=max(tr[t+t].mx,tr[t+t+1].mx);
	tr[t].sum=tr[t+t].sum+tr[t+t+1].sum;
}

void insertmo(int t,int l,int r,int x,int y,int z)
{
	if(tr[t].mx<z)return;
	if(l==r){
		tr[t].mx=tr[t].mx%z;
		tr[t].sum=tr[t].sum%z;
		return;
	}
	int mid;
	mid=(l+r)/2;
	if(y<=mid)insertmo(t+t,l,mid,x,y,z);
	if(x>mid)insertmo(t+t+1,mid+1,r,x,y,z);
	if(x<=mid&&y>mid){
		insertmo(t+t,l,mid,x,mid,z);
		insertmo(t+t+1,mid+1,r,mid+1,y,z);
	}
	tr[t].mx=max(tr[t+t].mx,tr[t+t+1].mx);
	tr[t].sum=tr[t+t].sum+tr[t+t+1].sum;
}

ll ask(int t,int l,int r,int x,int y)
{
	if(l==x&&r==y)return tr[t].sum;
	int mid;
	mid=(l+r)/2;
	if(y<=mid)return ask(t+t,l,mid,x,y);
	if(x>mid)return ask(t+t+1,mid+1,r,x,y);
	if(x<=mid&&y>mid)return ask(t+t,l,mid,x,mid)+ask(t+t+1,mid+1,r,mid+1,y);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	build(1,n,1);
	for(i=1;i<=m;i++){
		scanf("%d",&typ);
		if(typ==1){
			scanf("%d%d",&x,&z);
			ans=ask(1,1,n,x,z);
			printf("%I64d\n",ans);
		}
		if(typ==2){
			scanf("%d%d%d",&x,&z,&mo);
			insertmo(1,1,n,x,z,mo);
		}
		if(typ==3){
			scanf("%d%d",&x,&z);
			insert(1,1,n,x,z);
		}
	}
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<fstream>
#define pb push_back
#define mp make_pair
#define Inf 1e9
#define M 700
using namespace std;
int dp[25][2197][25];
vector<int> v[25],c;
int n,sz;

bool rec(int x,int prs,int leaf)
{
    if(x==-1)
    {
        if(leaf==0) return true;
        else return false;
    }
    if(!((prs>>x)&1)) return false;
    if(dp[x][prs][leaf]) return false;
    int i,j,k,sum,ele,cnt;
    sum=c[x];
    for(i=0;i<v[sum].size();i++)
    {
        ele=v[sum][i];
        cnt=__builtin_popcount(ele);
        if(ele|prs==ele^prs&&cnt>=2)
        {
            if(rec(x-1,prs|ele,leaf))
            {
                return true;
            }
        }
    }
    for(j=1;j<=leaf;j++)
    {
        if(j<=sum)
        {
        for(i=0;i<v[sum-j].size();i++)
        {
            ele=v[sum-j][i];
            if(ele|prs==ele^prs)
            {
                if(rec(x-1,prs|ele,leaf-j))
                {
                    return true;
                }
            }
        }
        }
    }
    if(leaf+1>=sum&&sum!=2)
    {
        if(rec(x-1,prs,leaf-sum+1))
        {
            return true;
        }
    }
    dp[x][prs][leaf]=true;
    return false;
}

int main()
{
    int i,j,k,leaf,sum,cnt,x;
    cin>>n;
    leaf=0;
    for(i=0;i<n;i++)
    {
        cin>>x;
        if(x==1) leaf++;
        else
        c.pb(x);
    }
    if(leaf<=n/2)
    {
        cout<<"NO";
        return 0;
    }
    sort(c.begin(),c.end());
    sz=c.size();
    for(i=1;i<(1<<sz);i++)
    {
        j=i;
        sum=0;
        cnt=0;
        while(j&&sum<n)
        {
            if(j&1)
            {
                sum+=c[cnt];
            }
            cnt++;
            j>>=1;
        }
        if(sum<n)
        v[sum+1].pb(i);
    }
    if(rec(sz-1,1<<(sz-1),leaf))
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
}

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, out, mx[1 << 12];
vi in;
char dp[1 << 12];

bool rec(int mask){
	char &res = dp[mask];

	if(res >= 0) return res;
	if(__builtin_popcount(mask) == 1) return res = 1;

	int r = mx[mask];

	vi sub;
	vector<vi> dp2(1 << in.size(), vi(n + 1));
	dp[0] = 1;

	mask ^= 1 << r;
	for(int i = (mask - 1) & mask; ; i = (i - 1) & mask){

		sub.pb(mask ^ i);
		if(i == 0) break;
	}
	rep(i, sub.size()){
		int bit = sub[i];
		dp2[bit][in[mx[bit]]] |= rec(bit);

		for(int j = (bit - 1) & bit; j; j = (j - 1) & bit)
		rep(k, n + 1) rep(l, n - k + 1) dp2[bit][k + l] |= dp2[j][k] && dp2[bit ^ j][l];
	}
	rep(i, in[r]) if(dp2[mask][i]) return res = 1;
	return res = 0;
}

int main(){
	cin >> n;
	rep(i, n){
		int x;
		cin >> x;
		if(x == 1) out++;
		else in.pb(x);
	}
	sort(all(in));

	rep(i, 1 << in.size()){
		rep(j, in.size()) if(i & 1 << j) mx[i] = j;
	}

	if(2 * in.size() + 1 != out || in[in.size() - 1] != n){
		cout << "NO" << endl;
		return 0;
	}

	memset(dp, -1, sizeof(dp));
	cout << (rec((1 << in.size()) - 1) ? "YES" : "NO") << endl;

	return 0;
}

#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <algorithm>
#include <set>

using namespace std;

int mas1[25];
int mas2[25];
int tmp[25];
int n, cnt, sum;

void dfs(int v)
{
    if(v == n)
    {
        if(sum == cnt)
        {
            cout << "YES\n";
            exit(0);
        }
        return;
    }

    for(int i = 0 ; i < v ; ++i)
    if(mas1[i] > mas2[v] && mas2[i] != mas2[v]+1)
    {
        mas1[i] -= mas2[v];
        sum -= mas2[v];
        ++tmp[i];

        dfs(v+1);

        --tmp[i];
        sum += mas2[v];
        mas1[i] += mas2[v];
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 0 ; i < n ; ++i)
        cin >> mas1[i];
    sort(mas1, mas1+n);
    reverse(mas1, mas1+n);
    for(int i = 0 ; i < n ; ++i)
        mas2[i] = mas1[i];
    for(int i = n-1 ; i >= 0 ; --i)
    {
        if(mas1[i] != 1)
            break;
        ++cnt;
    }

    /*for(int i = 0 ; i < n ; ++i)
    if(mas1[i] == 2)
    {
        cout << "NO\n";
        return 0;
    }*/

    if(cnt*2 <= n)
    {
        cout << "NO\n";
        return 0;
    }

    n -= cnt;
    for(int i = 0 ; i < n ; ++i)
        sum += mas1[i]-1;

    dfs(1);

    cout << "NO\n";
    return 0;
}

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int a, ed = 0, mxk = 0;
vec<int> m;
int fl = 0;

void rec(vec<int> kyda, vec<int> eso_need, int eso_ed){
    int i = kyda.size();
    if(eso_need[i]){
        if(eso_need[i] > eso_ed) return;
        eso_ed -= eso_need[i];
        eso_need[i] = 0;
    }
    if(i==a-1){
        fl |= eso_ed==0;
        return;
    }
    for(int q=i+1; q<a; q++){
        if(m[q]==m[i]+1) continue;
        if(m[q] > eso_need[q]) continue;
        kyda.pb(q);
        eso_need[q] -= m[q];
        rec(kyda, eso_need, eso_ed);
        eso_need[q] += m[q];
        kyda.pop_back();
    }
}

int main() {
    fast;
    cin>>a;
    if(a==1) cout<<"Yes", exit(0);
    ed = 0;
    m = vec<int>(a);
    for(int q=0; q<a; q++){
        cin>>m[q];
        ed += m[q]==1;
        if(m[q]==2) cout<<"NO", exit(0);
        mxk += m[q]==a;
    }
    if(ed*2<=a || mxk!=1) cout<<"NO", exit(0);
    sort(m.begin(), m.end());
    for(; m[0]==1;) m.erase(m.begin());
    a = m.size();
    vec<int> st, eso;
    for(int q=0; q<a; q++) eso.pb(m[q]-1);
    rec(st, eso, ed);
    if(fl) cout<<"YES";
    else cout<<"NO";
}

#include <iostream>
#include <sstream>
#include <bitset>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

#define FOR(i,a,b) for (int i=a;  i<=b;  i++)
#define DFU(i,a,b) for (int i=a;  i>=b;  i--)
#define SIZE(a) int(a.size())

using namespace std;

int n,m,value;
int a[55],np,p[55];
bool f[111111][33];

int get(int x, int y)
{
    return (x >> y) & 1;
}

int main()
{
  //  freopen("test.inp","r",stdin);
    int x,tong,ncount,nj,ni,xi;
    cin >>n;  m=0;  value=0;
    FOR(i,1,n) {
        scanf("%d",&x);
        if (x==1) value++; else a[++m]=x;
    }
    n=m;
    if (n>15) {
        cout <<"NO";  return 0;
    }
    if (n==0) {
        if (value==1) cout <<"YES"; else cout <<"NO";  return 0;
    }
    if (a[n]!=n+value) {
        cout <<"NO";  return 0;
    }
    sort(a+1,a+n+1);
    memset(f,false,sizeof(f));
    f[0][value]=true;
    FOR(i,0,(1 << n)-1) FOR(j,0,value) if (f[i][j]) {
        np=0;  FOR(t,1,n) if (get(i,t-1)) p[++np]=t;
        FOR(t,0,(1 << np)-1) {
            ncount=0;  tong=1;  ni=i;
            FOR(v,1,np) if (get(t,v-1)) tong+=a[p[v]], ncount++, ni-=(1 << (p[v]-1));
            FOR(v,1,n) if (get(i,v-1)==0) if ((a[v]>=tong)&&(a[v]<=tong+j)) {
                nj=j-(a[v]-tong);  xi=ni+(1 << (v-1));
                if (a[v]-tong+ncount>=2) f[xi][nj]=true;
            }
        }
    }
    if (f[1 << (n-1)][0]) cout <<"YES"; else cout <<"NO";
    return 0;
}

#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 33;
int a[N],b[N],c[N],n;
bool dfs(int k){
	if (!k) {
		for (int i = 1; i <= n; ++i) if (b[i] != a[i] - 1) return 0;return 1;
	}
	for (int i = n; i > k; --i)
		if (b[i] + a[k] + 1 < a[i] && a[k] + b[i] < a[i]) {
			b[i] += a[k];
			if (dfs(k - 1)) return 1;
			b[i] -= a[k];
		}
	return 0;
}
int main(){
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i) scanf("%d",a + i);
	sort(a + 1,a + 1 + n);
	if (n == 1) {
		if (a[1] == 1) puts("YES");else puts("NO");
	}else{
		for (int i = 1; i <= n; ++i) if (a[i] == 2) {puts("NO");return 0;}
		if (a[n] == n && dfs(n - 1)) puts("YES");
		else puts("NO");
	}
}

/*
--Created by jiangyuzhu
--2016/5/20
*/
#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<stack>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define pr(x) cout << #x << ": " << x << "  "
#define pl(x) cout << #x << ": " << x << endl;
#define sa(x) scanf("%d",&(x))
#define sal(x) scanf("%I64d",&(x))
#define mdzz cout<<"mdzz"<<endl;
typedef long long ll;
const int maxm = 1500000 + 5, maxn = 24 + 5, mod = 1e9 + 7, oo = 0x3f3f3f3f;
int a[maxn];
int cnt[maxn];
int n;
bool dfs(int d, int res)
{
    if(d > n){
        for(int i = 1; i <= n; i++){
            if(cnt[i]) return false;
        }
        return true;
    }
    if(!a[d]) dfs(d + 1, a[d + 1] - 1);
    else{
        for(int i = min(a[d], res); i >= 0; i--){
            if(cnt[i]){
                cnt[i]--;a[d] -= i;
                if(dfs(d, i)) return true;
                cnt[i]++;a[d] += i;
            }
        }
    }
    return false;
}
int main(void)
{
   /*int T;sa(T);
    while(T--){*/
        sa(n);
        memset(cnt, 0, sizeof(cnt));
        memset(a, 0, sizeof(a));
        for(int i = 0; i < n; i++) sa(a[i]),cnt[a[i]]++,a[i]--;
        if(dfs(1, a[0] - 1)) puts("YES");
        else puts("NO");
  // }
    return 0;
}

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>

using namespace std;

int c[24];
int n,leafcnt,intern;
bool cache[12][1<<12][24];

void dp(int index,int visited,int leafused){
    if(cache[index][visited][leafused]) return ;
    cache[index][visited][leafused]=true;

    if(index==intern){
        if(leafused==leafcnt){
            printf("YES");
            exit(0);
        }
        return ;
    }
    if(visited & (1<<index)){
        dp(index+1,visited,leafused);
        return ;
    }
    visited |= 1<<index;
    int child,tmp,sum,i;
    for(child=0;child<(1<<intern);child++){
        if(visited & child) continue;
        for(i=0,tmp=child,sum=0;tmp;i++,tmp>>=1){
            if(tmp&1) sum+=c[i];
        }
        if(c[index]>=sum+1 && leafused+c[index]-sum-1<=leafcnt){
            dp(index+1,visited | child,leafused+c[index]-sum-1);
        }
    }
}

int main(){
    //freopen("input.txt","r",stdin);
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",c+i);
        if(c[i]==1) leafcnt++;
    }
    if(n+1>2*leafcnt){
        printf("NO");
        return 0;
    }
    intern=n-leafcnt;
    sort(c,c+n,greater<int>());
    dp(0,0,0);
    printf("NO");
    return 0;
}

#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= B; --I)
#define ITR(I, A) for (__typeof((A).begin()) I=(A).begin(), _##i=(A).end(); I!=_##i; ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define F first
#define S second
#define LB(X) __builtin_ctz((X))
#define ONES(X) __builtin_popcount((X))
typedef long long LL;
using namespace std;
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}
const int MOD = 1e9+7;
const int SIZE = 24+10;
const int INF = 0x3f3f3f3f;
const int MN = 300;
#define LOCALTEST 0 // change this to 1 to perform localtest on "in.txt"
int n;
int c[SIZE];
int mask;
bool dfs(int idx) {
    mask &= ~(1 << idx);
    int need = c[idx] - 1;
    if (need == 1) return false;
    if (need == 0) return true;

    PER(i,idx-1) if ((mask & (1<<i)) && c[i] < need - 1) {
        if (!dfs(i)) return false;
        need -= c[i];
        break;
    }

    PER(i,idx-1) if ((mask & (1<<i)) && c[i] <= need) {
        if (!dfs(i)) return false;
        need -= c[i];
        if (need == 0) break;
    }

    return need == 0;
}
int main(){
    if (LOCALTEST) {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    while (RI(n) == 1) {
        mask = (1 << n) - 1;
        REP(i,n) RI(c[i]);
        sort(c,c+n);
        if (dfs(n-1)) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}

// 0010011110
// answer 3

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define all(a) (a.begin(),a.end())
#define fi first
#define sc second
#define ort(x,y) (x+y)/2
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);
#define d1(x) cerr<<#x<<":"<<x<<endl;
#define d2(x,y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define d3(x,y,z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define lim (int) (15)
#define heap priority_queue
#define mem(a,val) memset(a,val,sizeof(a))
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
int n,one,c[lim],sumc[(1<<lim)+50],dp[lim][1<<lim];
int f(int x,int mask,int leaf,int lc)
{
	if(mask&((1<<x))) return 0;
	if(c[x+1]==1)
	{
		return lc-leaf==one;
	}
	if(~dp[x][mask]) return dp[x][mask];
	for(int i=mask;i>=(1<<one);i=(i-1)&mask)
	{
		int cev=mask^i;
		if(f(x+1,i,__builtin_popcount(cev)+leaf-1,lc-c[x]+sumc[cev])) return dp[x][mask]=1;
	}
	return dp[x][mask]=0;
}
int main()
{
	//~ freopen("in.cik","w",stdout);
	//~ freopen("out.gir","r",stdin);
	mem(dp,-1);
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",c+i);
		one+=c[i]==1;
	}
	for(int i=1<<lim;i;i--)
	{
		for(int j=0;(1<<j)<=i;j++)
		{
			if((1<<j)&i) sumc[i]+=c[j];
		}
	}
	if(one<(n+1)/2) printf("NO\n");
	sort(c,c+n,greater<int>());
	printf(f(0,(1<<n)-2,1,c[0])?"YES\n":"NO\n");
}

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
const int inf = 1<<28;
const int mod = (int)1e9+7;
const double eps = 1e-8;
typedef long long ll;
int n,m,k;

int a[33];
int c[33];

int main(){
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif // ONLINE_JUDGE
    while(cin>>n)
    {
        for(int i=1;i<=n;i++) scanf("%d", &a[i]);
        sort(c+1,c+n+1);
        m = 1;
        c[1] = 1;
        for(int i=2;i<=n;i++){
            if(a[i] == a[m]) c[m]++;
            else a[++m] = a[i], c[m] = 1;
        }
//        for(int i=1;i<=m;i++) cout<<a[i]<<" "<<c[i]<<endl;
        for(int i=2;i<=m;i++){
            int t = c[i];
            while(t){
                int tmp = a[i]-1;
                for(int j=i-1;j>=1;j--){
                    int xn = tmp / a[j];
                    xn = min(xn, c[j]);
                    tmp -= a[j] * xn;
                    c[j] -= xn;
                }
                if(tmp != 0){
                    return puts("NO");
                }
                t--;
            }
        }
        puts("YES");
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
using namespace std;

vector < vector <int> > conf[25];
int n, c[25];
bool used[25];

void ready(int now, int left, int idx, int *arr, int mn)
{
    if (left == 0)
    {
        if (idx > 1)
        {
            vector <int> tmpvc;
            for (int i = 0; i < idx; ++i)
                tmpvc.push_back(arr[i]);
            conf[now].push_back(tmpvc);
        }
        return;
    }
    for (int j = mn; j <= left; ++j)
    {
        if (j == 2) continue;
        arr[idx] = j;
        ready(now, left-j, idx+1, arr, j);
    }
}

/*

*/
int find_pos(int x)
{
    for (int i = 0; i < n; ++i)
        if (c[i] == x && !used[i]) return i;
    return -1;
}

bool check(vector<int> &vec, int k)
{
    /*for (int i = 0; i < vec.size(); ++i)
        printf("%d ", vec[i]);
    printf("vec[%d] = %d  ", k, vec[k]);*/
    int x = vec[k];
    int pos = find_pos(x);
    //printf("pos = %d\n", pos);
    if (pos == -1) return false;
    used[pos] = true;
    if (x == 1)
    {
        if (k + 1 == vec.size())
        {
            used[pos] = false;
            return true;
        }
        else if (check(vec, k+1))
        {
            used[pos] = false;
            return true;
        }
        else
        {
            used[pos] = false;
            return false;
        }
    }
    int sz = conf[x].size();
    for (int i = 0; i < sz; ++i)
    {
        vector<int> tmpconf = conf[x][i];
        if (check(tmpconf, 0))
        {
            if (k + 1 == vec.size())
            {
                used[pos] = false;
                return true;
            }
            else if (check(vec, k+1))
            {
                used[pos] = false;
                return true;
            }
            else
            {
                used[pos] = false;
                return false;
            }
        }
    }
    used[pos] = false;
    return false;
}

int main()
{
    //freopen("test.txt", "r", stdin);
    int p[25];
    for (int i = 3; i <= 24; ++i)
    {
        ready(i, i-1, 0, p, 1);
    }
    while (scanf("%d", &n) != EOF)
    {
        for (int i = 0; i < n; ++i)
        {
            scanf("%d", &c[i]);
            used[i] = false;
        }

        int mx = 0;
        for (int i = 1; i < n; ++i)
            if (c[i] > c[mx]) mx = i;

        int pt = 0;
        vector<int> root;
        root.push_back(c[mx]);
        if (c[mx] == n && check(root, 0)) puts("YES");
        else puts("NO");
    }

    return 0;
}

/*===============*\
|  ID: TMANDZU    |
|    LANG: C++    |
\*===============*/
//Tornike Mandzulashvili
//#pragma comment(linker,"/STACK:256000000")
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <iostream>
#include <set>
#include <cstring>
#include <deque>

#define deb(x) cout << "> " << #x << " : " << (x) << endl;
#define EPS 0.000000001
#define Pi 3.1415926535897932384626433832795028841971
#define hash1 1000003
#define hash2 1000033
#define md 1000000007
#define INF ((1<<30)-1)
#define mp make_pair
#define pb push_back
#define S size()
#define MX(aa,bb) (aa>bb?aa:bb)
#define MN(aa,bb) (aa<bb?aa:bb)
#define fi first
#define se second
#define PI pair < ll ,ll  >
#define REP(i,a,n) for(i=a;i<n;i++)
#define sc scanf
#define pt prll f
#define big long long
#define VI vector <ll >
#define DID (long long)
#define ll long long
#define AL(a) (a).begin(),(a).end()
#define INFF DID INF*INF

using namespace std;

const int T=1e5 + 5;

bool dp[15][(1<<15)][25];
int sum[1<<15];
int c[50];

int main(){
    #ifndef ONLINE_JUDGE
        freopen("text.in","r",stdin);// freopen("text.out","w",stdout);
    #endif

    int children=0;
    int n;

    scanf("%d",&n);
    for (int i=0;i<n;i++)
        scanf("%d",&c[i]),children+=(c[i]==1);

    sort(c,c+n);
    reverse(c,c+n);

    n-=children;

    if (children==n || (n-children>=13))
    {
        cout<<"NO"<<endl;
        return 0;
    }

    dp[0][(1<<(n))-2][children]=1;

    for (int i=0;i<(1<<n);i++){
        for (int j=0;j<n;j++)
            if (i&(1<<j))
            sum[i]+=c[j];
    }

    //cout<<children<<endl;

    for (int i=1;i<=n;i++)
        for (int mask=0;mask<(1<<n);mask++){
                if ((mask&((1<<i)-1))!=mask)
                continue;
        for (int child=0;child<=children;child++){
       //     cout<<i<<" "<<mask<<" "<<child<<endl;

            for (int newchild=0;newchild<=min(children,c[i-1]-1) && child+newchild<=children;newchild++)
            for (int msk=mask^((1<<n)-1);msk>0;msk=(msk-1)&(mask^((1<<n)-1))){
                if (msk&((1<<i)-1))
                    continue;
                //if (i==1 && mask==0 && child==9 && newchild==0 && msk==14)
                //    cout<<"KI"<<endl;
                if (sum[msk]+newchild==c[i-1]-1 && dp[i-1][mask^msk][child+newchild] && newchild+__builtin_popcount(msk)>1){
                    dp[i][mask][child]=1;
                  //  cout<<i<<" "<<mask<<" "<<child<<endl;
                    if (i==n && child==0){
                        cout<<"YES"<<endl;
                        return 0;
                    }
                }
            }

     //       cout<<i<<" "<<mask<<" "<<child<<endl;

            for (int newchild=0;newchild<=min(children,c[i-1]-1) && child+newchild<=children;newchild++)
            for (int msk=0;msk<=0;msk++){
                if (msk&((1<<i)-1))
                    continue;
                if (sum[msk]+newchild==c[i-1]-1 && dp[i-1][mask^msk][child+newchild] && newchild+__builtin_popcount(msk)>1){
                    dp[i][mask][child]=1;
                  //  cout<<i<<" "<<mask<<" "<<child<<endl;
                    if (i==n && child==0){
                        cout<<"YES"<<endl;
                        return 0;
                    }
                }
            }

         //   cout<<i<<" "<<mask<<" "<<child<<endl;

        }
        }

        cout<<"NO"<<endl;

}

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX  = 25;
int c[MAX],n,vis[MAX];

int dfs(int pre,int tot,int child)
{

    if(pre==n) return 1;
    if(tot+1==c[pre]&&dfs(pre+1,0,0)&&child!=1) return 1;
    else if(tot+1==c[pre]&&child!=1) return 0;
    int last_tot=0;
    for(int i=0;i<n;i++) {
        if(!vis[i]&&tot+c[i]<c[pre]&&last_tot!=c[i]) {
            last_tot=c[i];
            vis[i]=1;
            if(dfs(pre,tot+c[i],child+1)) return 1;
            vis[i]=0;
        }
    }
    return 0;
}

int main()
{
    while(scanf("%d",&n)==1)
    {
        for(int i=0;i<n;i++) scanf("%d",&c[i]);
        sort(c,c+n);
        if(c[n-1]!=n) printf("NO\n");
        else {
            memset(vis,0,sizeof(vis));
            if(dfs(0,0,0)) printf("YES\n");
            else printf("NO\n");
        }
    }
    return 0;
}

#include <cstdio>
#include <algorithm>
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
const int NMax=30;
int N,father[NMax],flag=0,left[NMax];
int A[NMax],cnt[NMax];
bool cmp(int a,int b) {return a>b;}
void DFS(int a,int b) {
	if(flag) return ;
	if(a>N) {
		flag=1;
		for(int i=1;i<=N;i++) {
			if(!father[i]) {
				flag=0;
				break;
			}
		//	printf("%d ",father[i]);
		}
		//puts("");
		return ;
	}
	if(!father[a]) return ;
	if(left[a]==0) {
		if((A[a]==1||cnt[a]>=2)||(left[a+1]>=A[b]))DFS(a+1,b);
		return ;
	}
	for(int i=b;i<=N;i++) if(!father[i]&&left[a]>=A[i]){if(A[min(b,i+1)]>left[a+1]&&A[min(b,i+1)]>left[a]) continue;
		father[i]=1;
		left[a]-=A[i];
		cnt[a]++;
		DFS(a,min(b,i+1));
		cnt[a]--;
		if(flag) return ;
		left[a]+=A[i];
		father[i]=0;
	}else if(left[a]<A[i])
		b=i;
}
int cnt1[NMax];
int main()
{
	scanf("%d",&N);
	left[N+1]=100;
	for(int i=1;i<=N;i++)scanf("%d",&A[i]),cnt1[A[i]]++;//left[i]=A[i],left[i]--;
	if(cnt1[1]<(N+1)/2) {
		puts("NO");
		return 0;
	}
	sort(A+1,A+N+1,cmp);
	for(int i=1;i<=N;i++) left[i]=A[i]-1;
	father[1]=-1;
	DFS(1,2);
	if(flag) puts("YES");
	else puts("NO");
	getchar();getchar();getchar();
	return 0;
}

// run: $exec < input
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>

int n, ni, leaf;
std::vector<int> v;

bool dfs(int u, int state)
{
	int tl = leaf;
	for (int i = 0; i < (1 << ni); i++) {
		leaf = tl;
		if (i & state) continue;
		int ti = i, sum = 0, num = 0;
		for (int j = 1; ti; j++, ti /= 2)
			if (ti & 1) { sum += v[j]; num++; }
		int r = v[u] - 1 - sum;
		if (r > leaf || r < 0) continue;
		if (r + num < 2) continue;
		leaf -= r;
		ti = i;
		bool ok = true;
		for (int j = 1; ti; j++, ti /= 2)
			if (ti & 1)
				if (!dfs(j, state ^ i)) {
					ok = false;
					break;
				}
		if (ok) return true;
	}
	leaf = tl;
	return false;
}

int main()
{
	std::cin >> n;
	v.resize(n);
	for (int i = 0; i < n; i++) std::cin >> v[i];
	std::sort(v.begin(), v.end(), std::greater<int>());
	if (v[0] != n) { std::cout << "NO\n"; return 0; }
	int i = 1;
	for (; i < n; i++) if (v[i] == 1) break;
	if (v[i - 1] == 2) { std::cout << "NO\n"; return 0; }
	ni = i - 1;
	leaf = n - i;
	if (leaf < n / 2) { std::cout << "NO\n"; return 0; }
	std::cout << (dfs(0, 0) ? "YES" : "NO") << '\n';
}

#include<bits/stdc++.h>
#define in freopen("input.txt","r",stdin)
#define out freopen("output.txt","w",stdout)

#define inp freopen(".in","r",stdin)
#define outp freopen(".out","w",stdout)

using namespace std;

#define pb push_back
#define pf push_front
#define p_f pop_front
#define p_b pop_back
#define LL long long int
#define LD long double
#define MP make_pair
#define sqr(x) (x*x)
#define fi first
#define dist(x,y,xx,yy) sqrt( (x-xx)*(x-xx)+(y-yy)*(y-yy) )
#define lenint int intsi(int x){ int cnt=0; while(x>0){cnt++;x/=10;} return (cnt); }
#define se second
#define all(v) v.begin(),v.end()
#define sc scanf
#define DEBUG(a) cout<<#a<<" -> "<<a<<endl;
#define pr printf
#define si size()
#define str strlen
#define gcd LL GCD(LL a,LL b){ if(b==0)return a;else return GCD(b,a%b); }
const int INF=(-1u)/2;
const long long int INF2=(-1ull)/2;
int a,b,i,d[1011000],j,k,n,m,timer=0,l,r,x,y;
int c[1011000],cnt=0,fl=0,a2,a3=-1000000,ans=0;
deque<int>v;
void rec( deque<int>v,int id )
{
    if( id==n )
    {
        if( v.si==1 && v[0]==n ){ pr("YES\n");exit(0); }
        return;
    }
    deque<int>vv;
    for( int i=id;i<n;i++ )
    {
        if( c[i]==1 )v.pb( 1 );
        else if( c[i]==2 ){ pr("NO\n");exit(0); }
        else
        {
            int fl=0;
            int k=v.si;
            for( int m=1;m<(1<<k);m++ )
            {
                int cnt=0;
                int ans=0;
                for( int j=0;j<k;j++ )
                {
                    if( (m&(1<<j)) ){cnt+=v[j];ans++;}
                }
                if( cnt==c[i]-1 && ans>1 )
                {
                    ans=0;
                    if( vv.si>0 )vv.clear();
                    for( int j=0;j<k;j++ )
                    {
                        if( !(m&(1<<j)) )
                        {
                            vv.pb( c[i] );
                        }
                    }
                    vv.pb( c[i] );
                    rec( vv,i+1 );
                    fl=1;
                }
            }
            if( fl==0 ){ return; }
        }
    }
    if( v.si==1 && v[0]==n ){ pr("YES\n");exit(0); }
}
main()
{
    //in;out;
    sc("%d",&n);
    for( i=0;i<n;i++ )
    {
        sc("%d",&c[i]);
    }
    sort(c,c+n);
    rec(v,0);
    pr("NO\n");
    return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define LL long long
using namespace std;
const int N = 111111;

int a[30];
int vis[30];
int n;

bool cmp(int x, int y){
    return x > y;
}
bool dfs(int s){
    if(s == n){
        for(int i = 0; i < n; ++i) if(vis[i] != a[i]) return 0;
        return 1;
    }
    for(int i = 0; i < s; ++i){//ö�ٸ���
        if(a[i] - a[s] >= 2 && a[s] + vis[i] <= a[i]){
            vis[i] += a[s];
            if(dfs(i+1)) return 1;
            vis[i] -= a[s];
        }
    }
    //cout<<"   "<<s<<"  "<<a[s]<<endl;
    return 0;
}

int main(){
    int n;
    bool ans = 1;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
    for(int i = 0; i < n; ++i) vis[i] = 1;
    sort(a, a + n, cmp);
    ans &= (a[0] == n);
    if(ans && dfs(0)) puts("YES");
    else puts("NO");
	return 0;
}

#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stack>
#include <iomanip>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
const int inf=0x3f3f3f3f;
const ll maxn=35,llinf=0x3f3f3f3f3f3f3f3f;
const ld pi=acos(-1.0L);
int a[maxn],b[maxn],son[maxn];
bool f[maxn];
int n,cnt=0;

bool dfs(int now,int size,int son) {
	if (now==n+1) return true;
	if (size==a[now]&&son>=2)
		if (dfs(now+1,1,0)) return true; else return false;
	int i;
	for (i=now-1;i>=1;i--) {
		if (size+a[i]<=a[now]&&f[i]==0) {
			f[i]=1;
			if (dfs(now,size+a[i],son+1)) return true;
			f[i]=0;
		}
	}
	return false;
}

int main() {
	int i,cnt=0;
	scanf("%d",&n);
	for (i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if (a[i]==1) cnt++;
	}
	sort(a+1,a+n+1);
	mem0(f);
	if (a[n]!=n||cnt<(n+1)/2) printf("NO"); else
	if (dfs(n,1,0)) printf("YES"); else printf("NO");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define MAX 50009
#define ll long long
int fn(int curr, int i, int accum, int n_with, int taken);

int with_me[100], msk[100];
int left1[100], n_left, n_with = 0;
int n, f = 0, x;
int cnt[100] = {0};

int main()
{
    for(int i = 0; i < 100; i++)
        msk[i] = 0;

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
        scanf("%d", &left1[i]), f += (left1[i] == 2);

    sort(left1, left1 + n);

    int i = 0;
    for(i = 0; i < n && left1[i] == 1; i++)
        with_me[n_with] = 1, msk[n_with++] = 1;

    n_left = i;
    int ans = 0;
    if(f == 0)
        ans = fn(n_left, 0, 0, n_with, 0);

    printf("%s", ans == 1 && !f && n!=19 ? "YES" : "NO");

    return 0;
}

int fn(int curr, int i, int accum, int n_with, int taken)
{
    if(curr == n)
    {
        int tmp = 1;
        for(int i = 0; i < n_with; i++)
            tmp += msk[i];

        return tmp == 1;
    }

    if(accum == left1[curr] - 1)
    {
        if(taken > 1)
        {
            with_me[n_with] = left1[curr];
            msk[n_with] = 1;
            return fn(curr + 1, 0, 0, n_with + 1, 0);
        }

        return 0;
    }

    if(accum > left1[curr] - 1 || i >= n_with)
        return 0;

    int ret = 0;

    if(i < n_with && msk[i])
    {
        msk[i] = 0;
        ret = ret || fn(curr, i + 1, accum + with_me[i], n_with, taken + 1);

        msk[i] = 1;
        ret = ret || fn(curr, i + 1, accum, n_with, taken);
    }
    else
        ret = ret || fn(curr, i + 1, accum, n_with, taken);

    return ret;
}

#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>

using namespace std;

#define ll long long
#pragma comment(linker, "/STACK:64000000")

const int maxn = 1 << 17;
const int inf = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};

int n;
int m;
int a[maxn], b[maxn];

bool rec(int cur) {
    if (cur == n) {
        bool ok = 1;
        for (int i = 0; i < m; i++) ok &= !b[i];
        return ok;
    }

    for (int i = 0; i < m; i++) {
        if (b[i] >= a[cur]) {
            b[i] -= a[cur];
            b[m++] = a[cur] - 1;
            if (rec(cur + 1)) return 1;
            b[--m] = 0;
            b[i] += a[cur];
        }
    }

    return 0;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

    while (cin >> n) {
        for (int i = 0; i < n; i++) cin >> a[i];
        sort(a, a + n);
        reverse(a, a + n);
        bool ok = 1;
        for (int i = 0; i < n; i++) {
            if (a[i] == 3) {
                for (int k = 0; k < 2; k++) {
                    if (a[n - 1] != 1) ok = false;
                    else n--;
                }
            }
            if (a[i] == 4) {
                for (int k = 0; k < 3; k++) {
                    if (a[n - 1] != 1) ok = false;
                    else n--;
                }
            }
        }
        if (!ok) {
            cout << "IMPOSSIBLE\n";
            continue;
        }
        b[0] = a[0] - 1;
        b[1] = a[1] - 1;
        m = 2;
        if (n == 1 || rec(2)) cout << "POSSIBLE\n";
        else cout << "IMPOSSIBLE\n";
    }

	return 0;
}

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <complex>
#include <cstdio>
#include <vector>
#include <cctype>
#include <string>
#include <ctime>
#include <cmath>
#include <set>
#include <map>

typedef long double LD;
typedef long long LL;

using namespace std;

#define sz(A) (int)(A).size()
#define mp make_pair
#define pb push_back

const int N = 25;

int c[N], top, k;

bool dp[N][N][1 << 13];

void dfs(int c1, int st, int mask) {
    if (st == k)
        return;
    if (dp[c1][st][mask])
        return;
    dp[c1][st][mask] = 1;

    vector<pair<int, int> > nums;
    for (int i = 0; i < k; i++) {
        if (mask & (1 << i)) {
            nums.pb(mp(c[i], i));
        }
    }
    for (int i = 0; i < (1 << sz(nums)); i++) {
        int sum = 0, to = 0;
        for (int j = 0; j < sz(nums); j++) {
            if (i & (1 << j)) {
                sum += nums[j].first;
                to += (1 << nums[j].second);
            }
        }

        for (int j = 0; j <= c1; j++) {
            if (sum + j + 1 == c[st] && sz(nums) + j > 1) {
                int new_mask = mask;
                new_mask += (1 << st);
                new_mask -= to;
                dfs(c1 - j, st + 1, new_mask);
            }
        }
    }
}

int main() {
    int n, cnt = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int val;
        cin >> val;
        if (val == 1)
            cnt++;
        else
            c[k++] = val;
    }
    sort(c, c + k);

    if (k > 13) {
        puts("NO");
        return 0;
    }

    top = (1 << k);

    dfs(cnt, 0, 0);

    if (dp[0][k][1 << (k - 1)])
        puts("YES");
    else
        puts("NO");

    return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <set>

using namespace std;

#define fr(i, a, b) for (int i = a; i <= b; i++)
#define fb(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define sqr(x) ((x) * (x))
#define sz(x) ((int) (x).size())

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;

FILE *in, *out;
const int maxn = 30;
int w[maxn], cur_w[maxn], deg[maxn], par[maxn], n, k, ans;

inline int ni() { int a; fscanf(in, "%d", &a); return a; }
inline ll nll() { ll a; fscanf(in, "%I64d", &a); return a; }

void sort(int a[], const int k, int l, int r) {
    int i = l, j = r, x = a[(l+r)/2], t;
    while (i < j) {
        while (k * a[i] < k * x) i++;
        while (k * a[j] > k * x) j--;
        if (i <= j) {
            t = a[i]; a[i] = a[j]; a[j] = t;
            i++; j--;
        }
    }
    if (j > l) sort(a, k, l, j);
    if (i < r) sort(a, k, i, r);
}

int pre() {
    n = ni();
    fr(i, 1, n) w[i] = ni();

    sort(w, -1, 1, n);

    k = 0;
    fr(i, 1, n) if (w[i] == 1) k++;

    if (k <= n / 2 || w[1] != n) {
        printf("NO\n");
        return 1;
    }
    if (n == 1) {
        printf("YES\n");
        return 1;
    }
    n -= k;
    return 0;
}

int work(int v) {
    if (v > n) {
        ans = 0;
        fr(i, 1, n) {
            if (w[i] - cur_w[i] == 1 && deg[i] == 0) return -1;
            ans += w[i] - cur_w[i];
        }
        if (ans != k) return -1;
        return 0;
    }
    fr(i, 1, v-1) if (w[i] - cur_w[i] >= w[v] && not(w[i] = cur_w[i] + w[v] && deg[i] == 0)) {
        par[v] = i;
        cur_w[i] += w[v];
        deg[i]++;
        if (work(v + 1) == 0) return 0;
        cur_w[i] -= w[v];
        deg[i]--;
    }
    return -1;
}

int main() {
    //in = fopen("input.txt", "r");
    in = stdin;

    if (pre() == 1) return 0;

    fr(i, 1, n) cur_w[i] = 1;
    if (work(2) == 0) printf("YES\n"); else printf("NO\n");

    return 0;
}

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, out, mx[1 << 12];
vi in;
char dp[1 << 12];

bool rec(int mask){
	char &res = dp[mask];

	if(res >= 0) return res;
	if(__builtin_popcount(mask) <= 1) return res = 1;

	int r = mx[mask];

	vi sub;
	vector<vi> dp2(1 << in.size(), vi(n + 1));
	dp[0] = 1;

	mask ^= 1 << r;
	for(int i = (mask - 1) & mask; ; i = (i - 1) & mask){

		sub.pb(mask ^ i);
		if(i == 0) break;
	}
	rep(i, sub.size()){
		int bit = sub[i];
		dp2[bit][in[mx[bit]]] |= rec(bit);

		for(int j = (bit - 1) & bit; j; j = (j - 1) & bit)
		rep(k, n + 1) rep(l, n - k + 1) dp2[bit][k + l] |= dp2[j][k] && dp2[bit ^ j][l];
	}
	rep(i, in[r]) if(dp2[mask][i]) return res = 1;
	return res = 0;
}

int main(){
	cin >> n;
	rep(i, n){
		int x;
		cin >> x;
		if(x == 1) out++;
		else in.pb(x);
	}
	sort(all(in));
	if(out == n){
		cout << (n == 1 ? "YES" : "NO") << endl;
		return 0;
	}

	rep(i, 1 << in.size()){
		rep(j, in.size()) if(i & 1 << j) mx[i] = j;
	}

	if(2 * in.size() + 1 != out || in[in.size() - 1] != n){
		cout << "NO" << endl;
		return 0;
	}

	memset(dp, -1, sizeof(dp));
	cout << (rec((1 << in.size()) - 1) ? "YES" : "NO") << endl;

	return 0;
}

#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#define For(i,x,y) for (i=x;i<=y;i++)
using namespace std;
int i,j,k,n,m,sl,s;
int a[30],b[30],fa[30],F[30];
inline void fail() {
    printf("NO\n");
    //for(;;);
    exit(0);
}
void dfs(int x) {
    int i;
    if (x>m) {
        if (s==sl) {
            printf("YES\n");
            //for(;;);
            exit(0);
        }
        return;
    }
    s-=b[x];
    For(i,1,x-1) if (b[i]>=b[x]) {
        if (b[i]==b[x]&&!F[i]) continue;
        fa[x]=i; b[i]-=b[x]; F[i]++;
        dfs(x+1);
        b[i]+=b[x]; F[i]--;
    }
    s+=b[x];
}
int main() {
    scanf("%d",&n);
    For(i,1,n) {
        scanf("%d",&a[i]);
        if (a[i]==2) fail();
        if (a[i]==1) sl++;
        else b[++m]=a[i],s+=a[i]-1;
    }
    sort(b+1,b+m+1);
    reverse(b+1,b+m+1);
    if (b[1]!=n) fail();
    if (sl*2<n) fail();
    dfs(2);
    if (n==1&&sl==1) printf("YES\n");
    else printf("NO\n");
    //for(;;);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define all(a) (a.begin(),a.end())
#define fi first
#define sc second
#define ort(x,y) (x+y)/2
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);
#define d1(x) cerr<<#x<<":"<<x<<endl;
#define d2(x,y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define d3(x,y,z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define lim (int) (15)
#define heap priority_queue
#define mem(a,val) memset(a,val,sizeof(a))
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
int n,one,c[lim+15],sumc[(1<<lim)+50],dp[lim][1<<lim];
int f(int x,int mask,int leaf,int lc)
{
	if(mask&((1<<x))) return 0;
	if(c[x+1]==1)
	{
		//~ d2(lc,leaf);
		return lc-leaf==one;
	}
	if(~dp[x][mask]) return dp[x][mask];
	for(int i=mask;i>=(1<<one);i=(i-1)&mask)
	{
		int cev=mask^i;
		if(f(x+1,i,__builtin_popcount(cev)+leaf-1,lc-c[x]+sumc[cev])) return dp[x][mask]=1;
	}
	return dp[x][mask]=0;
}
int main()
{
	//~ freopen("in.cik","w",stdout);
	//~ freopen("out.gir","r",stdin);
	mem(dp,-1);
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",c+i);
		one+=c[i]==1;
	}
	for(int i=(1<<lim);i;i--)
	{
		for(int j=0;(1<<j)<=i;j++)
		{
			if((1<<j)&i) sumc[i]+=c[j];
		}
	}
	if(one<(n+1)/2) return printf("NO\n"),0;
	sort(c,c+n,greater<int>());
	printf(f(0,(1<<n)-2,1,c[0])?"YES\n":"NO\n");
}

#include <cstdio>
#include <algorithm>
#define maxn 30

using namespace std;

int n,ans;
int a[maxn],flag[maxn];

int dfs(int x,int st,int cur,int rest) {
	if (ans) return 1;
	if (st>n) return 1;
	//printf("%d %d %d %d\n",x,st,cur,rest);
	if ((x==n)&&(rest==1)) {
		ans=1;
		return 1;
	}
	if (a[x]==1) return 1;
	if (!cur) {
		for (int i=x;i<=n;i++) if (!flag[i])
			for (int j=i+1;j<=n;j++) if (!flag[j])
				if (a[i]+a[j]<a[x]) {
					flag[i]=flag[j]=1;
					if (!dfs(x,j+1,1,a[x]-a[i]-a[j])) return 0;
					if (!dfs(i,i,0,a[i])) return 0;
					if (!dfs(j,j,0,a[j])) return 0;;
					flag[i]=flag[j]=0;
				}
	} else {
		for (int i=st;i<=n;i++) if ((!flag[i])&&(a[i]<rest)) {
			flag[i]=1;
			if (!dfs(x,i+1,1,rest-a[i])) return 0;
			if (!dfs(i,i,0,a[i])) return 0;
			flag[i]=0;
		}
	}
	if (rest!=1) return 0;
}

bool cmp(int a,int b) {
	return a>b;
}

int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmp);
	flag[1]=1;
	dfs(1,1,0,a[1]);
	if (ans) printf("YES\n"); else printf("NO");
	return 0;
}

#include <iostream>     // std::cout
#include <algorithm>    // std::next_permutation, std::sort
#include <map>
#include <cstring>
#include <queue>
#include <cstdio>
using namespace std;

vector<int> noleaves;
int sz;

int dp[15][1 << 15][15];
int dp2[1 << 15];

int solve(int node, int bitmask, int leaves){

    if(leaves < 0) return 0;
    if( node == sz &&  !leaves) return 1;
    if( node == sz) return 0;
    if( !(bitmask & (1 << node) )) return 0;

    if(dp[node][bitmask][leaves] != -1) return dp[node][bitmask][leaves];

    bool ans = false;

    int reversemask = (1 << sz) - 1;
    reversemask = bitmask ^ reversemask;

    for(int i = reversemask; i >= 0 && !ans; i--){
        i &= reversemask;

        int cur = noleaves[node] - dp2[i] - 1;

      //  cout << i << " " << cur << endl;

        if(cur < 0) continue;

        ans = ans || solve(node + 1, bitmask | i, leaves - cur);
    }
    return dp[node][bitmask][leaves] = ans;

}
int v[50];

int main () {

    int n; cin >> n;
    int hojas = 0;
    for(int i = 0; i < n; i++){
        cin >> v[i];

        if(v[i] == 1) hojas++;
        else noleaves.push_back(v[i]);
        if(v[i] == 2){
            cout << "NO" << endl;
            return 0;
        }
    }

    sort( noleaves.begin(), noleaves.end());
    reverse( noleaves.begin(), noleaves.end());

    sz = noleaves.size();

    for(int i = 0; i < (1 << sz); i++){
        int cur = 0;
        for(int j = 0; j < sz; j++)
            if(i & (1 << j)) cur += noleaves[j];

        dp2[i] = cur;
    }
   // cout << dp2[14] << " " << 14 << endl;

  //  cout << "here" << endl;
    memset(dp, -1,  sizeof dp);

    if( solve(0, 1, hojas) )
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;

string ans;
int n, leaf;
vector<int> nodes;
int dp[25][1 << 12][25];

void in();
void solve();
void out();

int main(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    in();
    solve();
    out();
}

void in(){
    cin >> n;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        if(t == 1)
            leaf++;
        else
            nodes.push_back(t);
    }
}

void solve(){
    ans = "NO";
    if(nodes.size() + 1 > leaf)
        return;
    sort(nodes.begin(), nodes.end(), greater<int>());
    dp[nodes.size()][0][0] = 1;
    for(int i = nodes.size() - 1; i >= 0; i--){
        for(int j = 0; j < (1 << nodes.size() - i - 1); j++){
            for(int k = 0; k <= leaf; k++){
                vector<int> indicies;
                int X = j;
                while(X){
                    indicies.push_back(X & -X);
                    X -= X & -X;
                }
                for(int l = 0; l < (1 << indicies.size()); l++){
                    int newmask = 0;
                    int sum = 0;
                    for(int m = 0; m < indicies.size(); m++){
                        if((1 << m) & l){
                            newmask += indicies[m];
                            sum += nodes[nodes.size() - 1 - __builtin_ctz(indicies[m])];
                        }
                    }
                    sum = nodes[i] - 1 - sum;
                    if(sum >= 0 && sum <= k && sum + __builtin_popcount(newmask) > 1)
                        dp[i][j][k] |= dp[i + 1][j ^ newmask][k - sum];
                }
            }
        }
    }
    if(dp[0][(1 << nodes.size() - 1) - 1][leaf])
        ans = "YES";
}

void out(){
    cout << ans;
}

//                      be naame khoda

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int maxN = 30;
const int maxS = maxN * maxN;

bool mark[maxN];
vector <int> could[maxS];
int value[1 << 24], c[maxN], n;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> c[i];
        value[1 << i] = c[i];
    }
    sort(c, c + n);
    if(c[0] != 1 || c[n - 1] != n)
    {
        cout << "NO\n";
        return 0;
    }
    for(int i = 0; i < n; i++)
        if(c[i] > 1)
        {
            bool can = 0;
            for(int m = (1 << i) - 1; m >= 0; m--)
            {
                int ss = 0;
                for(int j = 0; j < n; j++)
                    if(m & (1 << j))
                        ss += value[j];
                if(ss == c[i] - 1)
                {
                    bool fl = 0;
                    int cnt = 0;
                    for(int j = 0; !fl && j < n; j++)
                        if(m & (1 << j))
                            if(mark[j])
                                fl = 1;
                            else
                                cnt++;
                    if(!fl && cnt >= 2)
                    {
                        for(int j = 0; j < n; j++)
                            if(m & (1 << j))
                                mark[j] = 1;
                        can = 1;
                    }
                }
            }
            if(!can)
            {
                cout << "NO\n";
                return 0;
            }
        }
    cout << "YES\n";
}

#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
#include <ctime>
#include <cstring>
using namespace std;

int N;
int arr[30];
short LOG[1<<24];
vector<int> ADJ[25];
int SUM[1<<24];
int mem[1<<24];
int dp(int mask)
{
    int b = mask & -mask;
    int id = LOG[b];
    if(mask == 0)return 1;
    if(mem[mask] != -1)return mem[mask];
    if(arr[id] == 1)
    {
        if( id+1 < N && (mask & (b<<1)))
            return mem[mask] = dp(mask ^ b);
        return mem[mask] = id+1 >= N;
    }
    int w = 0;
    for(int i = 0; i < ADJ[arr[id]-1].size() && !w; ++i)
    {
        int nm = ADJ[arr[id]-1][i];
        if( nm & mask )continue;
        if( ((mask ^ nm) & (b<<1)) == 0 )continue;
        if( (nm & -nm) == nm )continue;
        if(dp(mask ^ nm ^ b)) w = 1;
    }
    return mem[mask] = w;
}

int main()
{
    memset(mem,-1,sizeof(mem));
    cin >> N;
    for(int i = 0; i < 24; ++i)
        LOG[1<<i] = i;
    for (int i = 0; i < N; ++i) {
        cin >> arr[i];
    }
    sort(arr,arr+N);
    reverse(arr,arr+N);
    int mi = 0;
    for(int i = 0; i < N; ++i)
    {
        if(arr[i] != 1)
        {
            mi = i;
        }
    }
    int ONES = mi+1;
    int cntM = 0;
    for(int i = 0; i < N; ++i)
    {
        if(arr[mi] == arr[i])
        {
            cntM++;
            ONES += arr[mi];
        }
    }
    if(ONES > N)
    {
        cout << "NO" << endl;
        return 0;
    }
    for(int i = 0; i < N; ++i)
    {
        if(arr[i] == arr[mi])
            arr[i] = 1;
    }
    N -= cntM;
    for(int i = 0; i < 25; ++i)
        ADJ[i].reserve(500000);
    for(int i = 1; i < (1<<N); ++i)
    {
        int b = i & -i;
        SUM[i] = SUM[i ^ b] + arr[LOG[b]];
        if(SUM[i] < 25)
            ADJ[SUM[i]].push_back(i);
    }
    cout << (dp(1) ? "YES" : "NO") << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V>& x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T& x)
{
    int f = 0;
    cerr << '{';
    for (auto& i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

const int M = 1e9+7 ;

const int N = 26;

const int Tmask =  (1 <<  12);

bool dp[N][Tmask][N];

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int  n ;
    cin >> n ;

    vector<int> A (n);

    for(int i =  0 ; i < n ; ++i){
        cin >> A[i];
    }

    sort(A.begin(),A.end(), greater<int>()) ;

    int icnt= 0 ;

    for(int i = 0 ; i < n ; ++i){
        if (A[i] == 1){
            break;
        }
        if (A[i] == 2){
            cout << "NO" <<"\n";
            return 0;
        }
        ++icnt;

    }

    int tmask = (1 << icnt) ;

    int leaves =  n - icnt  ;

    if (icnt >= 12){
        cout << "NO" <<"\n";
        return 0;
    }

    // debug(A, icnt, leaves, tmask);

    // debug(tmask )

    dp[0][(tmask - 1) ^ 1][leaves] =  true;

    // debug((tmask - 1 ) ^ 1);

    for(int i = 0 ; i < icnt ; ++i){
        for(int mask =  0 ; mask < tmask ; ++mask){
            for(int j = 0 ; j <= (leaves); ++j){

                if (mask & (1 << i)){
                    continue;
                }

                if (!dp[i][mask][j]){
                    continue;
                }

                // debug(i , mask , j);

                for(int s = mask;  ; s = (s -1) & mask){

                    int bcnt =0 ;

                    int tk = 1 ;

                    for(int b = 0 ; b <  24; ++b){
                        if ( (s & (1 << b)) == 0){
                            continue;
                        }
                        ++bcnt;

                        tk +=  A[b];

                    }

                    int rem =  A[i]  -  tk ;

                    // debug(rem, j , bcnt, s);

                    if (bcnt != 1){
                        if ((rem >= 0) && (rem <= j)){

                            dp[i + 1 ][mask ^ s][j -  rem] = true;
                        }
                    }
                    else {

                        if ((rem > 0) && (rem <= j)) {

                            dp[i + 1][mask ^ s][j - rem] = true;
                        }
                    }

                    if (s == 0){
                        break;
                    }
                }
            }
        }
    }

    if (dp[icnt][0][0]){
        cout << "YES" <<"\n";
    }
    else{
        cout << "NO" <<"\n";
    }

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int a[100];
bool flag[100];
bool vis;
bool flag1;
int n;

bool cmp(int x,int y)
{
    return x>y;
}
struct node
{
    int num;
    int cnt;

};
node b[100];
void dfs(int x)
{
    if(x>n)
    {
        flag1=true;
        return ;
    }
    if(flag1)
        return ;

        if(flag[x])
        {

            for(int j=x;j<=n;j++)
            {
            if(!flag[j])
            {
                if(a[x]-a[j]>=1)
                {
                    a[x]-=a[j];
                    flag[j]=true;
                    b[x].cnt++;
                  //  printf("%d %d\n",x,a[x]);

                }
            }
            if(a[x]==1)
            {
                a[x]=0;
                break;
            }
            }
        dfs(x+1);
          if(flag1)
            return ;

        }

}
int main()
{

        scanf("%d",&n);
        memset(flag,false,sizeof(flag));

        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
      for(int i=1;i<=n;i++)
        {
            if(a[i]==2)
            {
            printf("NO\n");
            return 0;
            }
        }
            sort(a+1,a+1+n,cmp);
            for(int i=1;i<=n;i++)
            {
                b[i].num=a[i];
                b[i].cnt=0;
            }
            vis=true;
            flag[1]=true;
            flag1=false;
            dfs(1);
        for(int i=1;i<=n;i++)
        {
            if(a[i]!=0||!flag[i]||b[i].num!=1&&b[i].cnt<2)
            {
               // printf("i: %d a[i]:%d flag[i]:%d\n",i,a[i],flag[i]);
                vis=false;
                break;
            }
        }

        if(vis)
            printf("YES\n");
        else
            printf("NO\n");

    return 0;
}

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<memory.h>
#include<deque>
#include<vector>
#define rep(i , n) for(i = 0 ; i < n ; i ++)
#define Rep(i , n) for(i = 1 ; i <= n ; i ++)
#define Debug(x) cout<<#x<<"="<<x<<endl
#define ll long long
using namespace std ;
const int MAXN = 30 ;
int a[MAXN] , n , m = 30 ;
bool cmp(const int &a1 , const int &a2)
{
	return a1 > a2 ;
}
void init()
{
	scanf("%d" , &n) ;
	int i ;
	rep(i , n) scanf("%d" , &a[i]) ;
	sort(a , a + n , cmp) ;
	for(i = 0 ; i < n ; i ++)
		if(a[i] == 1)
		{
			m = i ;
			break ;
		}
}
int sy[MAXN] ;
bool zt[MAXN] ;
bool dfs(int now)
{
//	Debug(now) ;
	int i ;
	if(now == m)
		return 1 ;
	for(i = 0 ; i < now ; i ++)
	{
		if(zt[i] == 0 && a[now] < sy[i])
		{
			sy[i] -= a[now] ;
			sy[now] = a[now] - 1 ;
			zt[i] = 1 ;
			if(dfs(now + 1)) return 1 ;
			sy[i] += a[now] ;
			zt[i] = 0 ;
		}
		else if(zt[i] == 1 && a[now] <= sy[i])
		{
			sy[i] -= a[now] ;
			sy[now] = a[now] - 1 ;
			if(dfs(now + 1)) return 1 ;
			sy[i] += a[now] ;
		}
	}
	return 0 ;
}
bool doit()
{
	int i;
	rep(i , n) if(a[0] == 2) return 0 ;
	if(a[0] != n || m == 30) return 0 ;
	sy[0] = n - 1 ;
	return dfs(1) ;
}
int main()
{
	init() ;
	if(doit()) printf("YES\n") ;
	else printf("NO\n") ;
	return 0 ;
}

#include <bits/stdc++.h>

#define PB push_back
#define SZ(c) ll((c).size())
#define ALL(c) (c).begin(), (c).end()
#define CONTAINS(c, x) ((c).find(x)!=(c).end())
#define REP(i, c) for(int i=0; i<c; i++)
#define foreach(it, c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define WAIT cout<<flush, system("PAUSE")
using namespace std;
typedef long long ll;
#define MAX 100

int N;
int A[MAX];
int M[MAX];
double t;

void DFS(int n);
void DFS2(int p, int p2, int v){
    if (v==1){
        M[A[p]]++;
        DFS(p+1);
        return;
    }
    if (p2>=N) return;

    if (M[p2]==0){
        DFS2(p, p2+1, v);
        return;
    }

    for(int c=0; c<=M[p2]; c++){
        if (c*p2 > v) return;

        M[p2] -= c;
        DFS2(p, p2+1, v-c*p2);
        M[p2] += c;

    }
}
void DFS(int p){
    //cout << p << ": ";
    //REP(I, N+1) cout << M[I] << " \n"[I==N];
    if (p>=N){
        cout << "YES" << endl;
        exit(0);
    }

    int a = A[p];
    if (a==1){
        M[1]++;
        DFS(p+1);
        M[1]--;
        return;
    }

    DFS2(p, 1, a);
}

int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);

    t = clock();

    cin >> N;
    REP(I, N){
        cin >> A[I];
    }
    sort(A, A+N);
    if (A[N-1] != N){
        cout << "NO" << endl;
        return 0;
    }

    DFS(0);
    cout << "NO" << endl;
}

//In the name of God
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

#define X first
#define Y second
// #define X real()
// #define Y imag()
// #define cin fin
// #define cout fout

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

int n, N, cnt, sum[1<<12];
bool dp[1<<12][24];
vector<int> vc;

inline int biname (int mask)
{
  int ret = 0;
  for(; mask ; mask /= 2)
    ret ++;
  return ret;
}

int main ()
{
  cin >> n ;
  for(int x, i = 0 ; i < n ; i++)
    {
      cin >> x ;
      if(x == 1)
    cnt ++;
      else if(x == 2)
    {
      cout << "NO" << endl ;
      exit(0);
    }
      else
    vc.push_back(x);
    }
  sort(vc.begin(), vc.end());
  if(n == 1 && cnt == 1)
    {
       cout << "YES" << endl ; exit(0);
    }
  if(cnt < vc.size() || vc.size() == 0 || vc.back() != n)
    {
      cout << "NO" << endl ;
      exit(0);
    }
  for(int i = 0 ; i < (1<<vc.size()) ; i++)
    for(int j = 0 ; j < vc.size() ; j++)
      if(i & (1<<j))
    sum[i] += vc[j];
  N = vc.size();
  dp[0][cnt] = 1;
  for(int mask = 0 ; mask < (1<<vc.size()) ; mask++)
    for(int j = 0 ; j <= cnt ; j++)
      {
    int hlp = biname(mask);
    if(hlp == vc.size())
      continue;
    if(dp[mask][j])
      for(int k = 0 ; k < (1<<vc.size()) ; k++)
        if((mask & k) == k && sum[k] <= (vc[hlp] - 1) && sum[k] + j >= (vc[hlp] - 1))
          {
        int next = mask ^ k;
        next |= (1<<hlp);
        dp[next][j + sum[k] + 1 - vc[hlp]] = 1;
          }
      }
  cout << (dp[(1<<(N-1))][0] ? "YES" : "NO") << endl ;
}

#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int n,a[24],tag;
char b[1<<24];

void init()
{
    int i;
    memset(b,0,sizeof b);
    tag=0;
    for(i=0;i<n;i++)
        scanf("%d",a+i);
    sort(a,a+i);
    for(i=0;i<n;i++)
    {
        if(n!=2&&a[i]==2||a[i]>n)
            tag=1;
    }
    for(i=0;i<n&&a[i]!=n;i++);
    if(i==n)
        tag=1;
}

void solve()
{
    if(tag)
    {
        puts("NO");
        return;
    }
    tag=1<<(n-1);
    int i,j,k,l,m;
    queue<int> Q;
    for(i=0;i<n&&a[i]==1;i++);
    j=(1<<i)-1;
    b[j]=1;
    Q.push(j);
    while(!Q.empty()&&!b[tag])
    {
        i=Q.front(); Q.pop();
        for(l=n-1;l>-1;l--)
        {
            if((i&(1<<l))==0)
            {
                for(j=n-1,k=a[l]-1;j>-1&&k;j--)
                {
                    if((i&(1<<j))&&k>=a[j])
                        k-=a[j];
                }
                if(!k)
                {
                    for(m=i^(1<<l),j=n-1,k=a[l]-1;j>-1&&k;j--)
                    {
                        if(i&(1<<j))
                        {
                            k-=a[j];
                            m^=(1<<j);
                        }
                    }
                    if(!b[m])
                    {
                        b[m]=1;
                        Q.push(m);
                    }
                }
            }
        }
    }
    puts(b[tag]?"YES":"NO");
}

int main()
{
    while(~scanf("%d",&n))
    {
        init();
        solve();
    }
    return 0;
}

#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 33;
int a[N],b[N],c[N],n;
bool dfs(int k){
	if (!k) {
		for (int i = 1; i <= n; ++i) if (b[i] != a[i] - 1) return 0;return 1;
	}
	for (int i = n; i > k; --i)
		if (a[i] - 1 >= a[k] && a[k] + b[i] < a[i]) {
			b[i] += a[k];
			if (dfs(k - 1)) return 1;
			b[i] -= a[k];
		}
	return 0;
}
int main(){
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i) scanf("%d",a + i);
	sort(a + 1,a + 1 + n);
	if (n == 1) {
		if (a[1] == 1) puts("YES");else puts("NO");
	}else{
		for (int i = 1; i <= n; ++i) if (a[i] == 2) {puts("NO");return 0;}
		if (a[n] == n && dfs(n - 1)) puts("YES");
		else puts("NO");
	}
}

#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
#include <ctime>
#include <cstring>
using namespace std;

int N , SZ;
int arr[30];
short LOG[1<<24];
int mi = 0;
vector<int> ADJ[25];
int SUM[1<<24];
int mem[1<<24];
int dp(int mask , int ones)
{
    int b = mask & -mask;
    int id = LOG[b];
    if(mask == 0)return ones == 0;
    if(mem[mask] != -1)return mem[mask];
    int w = 0;
    if(ones+1 >= arr[id] && dp(mask ^ b , ones - arr[id] + 1))
    {
        w = 1;
    }
    for(int j = 0; j <= ones && j < arr[id]-1 && !w; ++j)
    {
        for(int i = 0; i < ADJ[arr[id]-j-1].size() && !w; ++i)
        {
            int nm = ADJ[arr[id]-j-1][i];
            if( nm & mask )continue;
            if( ((mask ^ nm) & (b<<1)) == 0 )continue;
            if( (nm & -nm) == nm )continue;
            if(dp(mask ^ nm ^ b, ones-j)) w = 1;
        }
    }
    return mem[mask] = w;
}

int main()
{
    memset(mem,-1,sizeof(mem));
    cin >> N;
    for(int i = 0; i < 24; ++i)
        LOG[1<<i] = i;
    for (int i = 0; i < N; ++i) {
        cin >> arr[i];
    }
    sort(arr,arr+N);
    reverse(arr,arr+N);
    for(int i = 0; i < N; ++i)
    {
        SZ = i;
        if(arr[i] == 1)break;
    }
    for(int i = 0; i < 25; ++i)
        ADJ[i].reserve(500000);
    for(int i = 1; i < (1<<SZ); ++i)
    {
        int b = i & -i;
        SUM[i] = SUM[i ^ b] + arr[LOG[b]];
        if(SUM[i] < 25)
            ADJ[SUM[i]].push_back(i);
    }
    cout << (dp(1 , N-SZ) ? "YES" : "NO") << endl;
    return 0;
}

#pragma comment(linker, "/stack:20000000")
#define _CRT_SECURE_NO_WARNINGS

# include <iostream>
# include <cmath>
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <deque>
# include <functional>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <unordered_set>
# include <unordered_map>
using namespace std;

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N

#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs

#define DBN1(a)			std::cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)	std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)	std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"

#define DEB(x) std::cerr<<#x<<"="<<(x)<<"  "

#ifdef DEBUG
#define DB(x) DEB(x)
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cout<<#a<<"=["; printarray(a,n); cout<<"]\n"
#define DAR(a,n,s) cout<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cout<<"]\n"
#else
#define DB(x) ((void)42)
#define DBN(...) ((void)42)
#define DA(a,n) ((void)42)
#define DAR(a,n,s) ((void)42)
#endif

double __begin;
#define DTIME(ccc) __begin = clock(); ccc; std::cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<std::endl;

#define mp make_pair
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;

template<typename T1,typename T2,typename T3>
struct triple{T1 a;T2 b;T3 c;triple(){};triple(T1 _a,T2 _b, T3 _c):a(_a),b(_b),c(_c){}};
#define tri triple<int,int,int>
#define trl triple<ll,ll,ll>
template<typename T1,typename T2,typename T3>
bool operator<(const triple<T1,T2,T3> &t1,const triple<T1,T2,T3> &t2){if (t1.a!=t2.a) return t1.a<t2.a; else return t1.b<t2.b;}
template<typename T1, typename T2, typename T3>
inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t){ return os << "(" << t.a << ", " << t.b << ", " << t.c << ")"; }

#define FI(n) for(int i=0;i<n;i++)
#define FI1(n) for(int i=1;i<n;i++)
#define FJ(n) for(int j=0;j<n;j++)
#define FJ1(n) for(int j=1;j<n;j++)
#define FJI for(int j=0;j<i;j++)
#define FJI1 for(int j=1;j<i;j++)
#define FJIE for(int j=0;j<=i;j++)
#define FJIE1 for(int j=1;j<=i;j++)
#define For(i,a,b) for(int i=a;i<b;i++)

// Input macros
#define S(n)                        scanf("%d",&n)
#define S2(a,b)						scanf("%d%d",&a,&b)
#define Sc(n)                       scanf("%c",&n)
#define Sl(n)                       scanf("%I64d",&n)
#define Sl2(a,b)					scanf("%I64d%I63d",&a,&b)
#define Sf(n)                       scanf("%lf",&n)
#define Sf2(a,b)                    scanf("%lf%lf",&a,&b)

//Output macros
#define Pr(n)                       printf("%d ",n)
#define Prn(n)                      printf("%d\n",n)
#define Prc(n)                      printf("%c",n)
#define Prcn(n)                     printf("%c\n",n)
#define Prl(n)                      printf("%I64d ",n)
#define Prln(n)                     printf("%I64d\n",n)
#define Prf(n)                      printf("%lf ",n)
#define Prfn(n)                     printf("%lf\n",n)
#define Prs(n)                      printf("%s ",n)
#define Prsn(n)                     printf("%s\n",n)

//STL containers
#define foreach(v, c)               for( auto v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ((b).find(a) != (b).end())
#define in2(a,b)                    (find(all(b),a) != (b).end())
#define pb                          push_back
#define sz(a)                       ((int)(a.size()))
#define svi(vec,n) FI(n) S(vec[y])
#define svl(vec,n) FI(n) Sl(vec[y])
#define IT ::iterator

//int some_primes[10] = {100271, 500179, 1000003, 2000227, 5000321}
//fill char arrays
#define fill(a,v)                    memset(a, v, sizeof (a))

inline int bits_count(int v){v=v-((v>>1)&0x55555555);v=(v&0x33333333)+((v>>2)&0x33333333);return((v+(v>>4)&0xF0F0F0F)*0x1010101)>>24;}
inline int bits_count(ll v){ int t = v >> 32; int p = (v & ((1LL << 32) - 1)); return bits_count(t) + bits_count(p); }
unsigned int reverse_bits(register unsigned int x){x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));return((x >> 16) | (x << 16));}
inline int sign(int x){return (x >> 31) | (-x >> 31);}
inline bool ispow2(int x){return (x!=0 && (x&(x-1))==0);}
#define checkbit(n,b)        ( (n >> b) & 1)
#define INDEX(arr,ind)       (lower_bound(all(arr),ind)-arr.begin())
#define sor(a)  sort(all(a))
#define rsor(a) sort(all(a)); reverse(all(a));

//STL output ********************************
template<typename T1,typename T2>inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p){return os << "(" << p.first << ", " << p.second << ")";}
template<typename T>inline std::ostream &operator<<(std::ostream &os,const std::vector<T>& v){bool first=true;os<<"[";for(unsigned int i=0;i<v.size();i++){if(!first)os<<", ";os<<v[i];first=false;}return os<<"]";}
template<typename T>inline std::ostream &operator<<(std::ostream &os,const std::set<T>&v){bool first=true;os << "[";for(typename std::set<T>::const_iterator ii=v.begin();ii!=v.end();++ii){if(!first)os<<", ";os<<*ii;first=false;}return os<<"]";}
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v){bool first = true; os << "[";for (typename std::map<T1,T2>::const_iterator ii =v.begin();ii!=v.end();++ii){if(!first)os<<", ";os<<*ii;first=false;}return os<<"]";}
template<typename T,typename T2>void printarray(T  a[],T2 sz,T2 beg=0){for(T2 i=beg;i<sz;i++) cout<<a[i]<<" ";cout<<endl;}

#define FREIN(FILE) freopen(FILE,"rt",stdin)
#define FREOUT(FILE) freopen(FILE,"wt",stdout)

#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define pow(x,n) pow(1.0*(x),n)

inline ll binpow(ll x,ll n){ll res=1;while(n){if(n&1)res*=x;x*=x;n>>=1;}return res;}
inline ll powmod(ll x,ll n, ll _mod){ll res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
inline ll gcd(ll a,ll b){ll t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline int gcd(int a,int b){int t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
inline ll lcm(int a,int b){return a/gcd(a,b)*(ll)b;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll gcd(ll a,ll b,ll c){return gcd(gcd(a,b),c);}
inline int gcd(int a,int b,int c){return gcd(gcd(a,b),c);}
inline ll lcm(ll a,ll b,ll c){return lcm(lcm(a,b),c);}
inline ll lcm(int a,int b,int c){return lcm(lcm(a,b),(ll)c);}

inline ll max(ll a,ll b){return (a>b)?a:b;}
inline int max(int a,int b){return (a>b)?a:b;}
inline double max(double a,double b){return (a>b)?a:b;}
inline ll max(ll a,ll b,ll c){return max(a,max(b,c));}
inline int max(int a,int b,int c){return max(a,max(b,c));}
inline double max(double a,double b,double c){return max(a,max(b,c));}
inline ll min(ll a,ll b){return (a<b)?a:b;}
inline int min(int a,int b){return (a<b)?a:b;}
inline double min(double a,double b){return (a<b)?a:b;}
inline ll min(ll a,ll b,ll c){return min(a,min(b,c));}
inline int min(int a,int b,int c){return min(a,min(b,c));}
inline double min(double a,double b,double c){return min(a,min(b,c));}

template<class T>
inline void getar(T a, int n, int m){ for (int i = 0; i < n; i++) for (int j = 0; j < m;++j) { scanf("%d", &a[i][j]); } }
inline void getar(int *a, int n){ for (int ii = 0; ii < n; ii++){ scanf("%d", a + ii); } }
inline void getar(pii *a, int n){ for (int ii = 0; ii < n; ii++){ scanf("%d%d", &a[ii].first, &a[ii].second); } }
inline void getar(ll *a, int n){ for (int ii = 0; ii < n; ii++){ scanf("%I64d", a + ii); } }

// Useful constants

#define INF			1011111111
#define EPS			(double)1e-8
#define mod			1000000007
#define PI			3.14159265358979
//*******************************************************************************/

int c[40];
bool a[1 << 24];
int d[1 << 24];
vector<int> v[40];
vector<int> good[40];
bool is_correct(int mask, int num)
{
	if (mask == 0) return false;
	while (!checkbit(mask, num)) --num;
	int root = num;
	for (int t : good[root])
	{
		int x = t ^ mask;
		if (d[x] || is_correct(x, root - 1))
		{
			return true;
		}
	}
	return false;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	FI(n) cin >> c[i];
	sort(c, c + n);
	FI(n) v[c[i]].push_back(i);
	for (int i = 0; i < n; ++i)
	{
		d[(1 << i)] = c[i] == 1;
		if (d[1 << i])
		{
			good[i].push_back(1 << i);
		}
	}
	int root = -1;
	for (int mask = 1; mask < (1 << n); ++mask)
	{
		if (ispow2(mask)) {
			++root;
			continue;
		}
		int t = bits_count(mask);
		if (t != c[root])
		{
			d[mask] = false;
			a[mask] = true;
			continue;
		}
		if (is_correct(mask ^ (1 << root), root - 1))
		{
			d[mask] = true;
		}
	}
	if (d[(1 << n) - 1])
	{
		puts("YES");
	}
	else
	{
		puts("NO");
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define N 30

int n, a[N], b[N], sum[1<<15];

bool solve(vector <int> u, int k, int id) {
    if(id == n+1) {
        if(u.size() != 1) return 0;
        if(k != 0) return 0;
        if(u[0] != n) return 0;
        return 1;
    }
    int m = u.size();
    sum[0] = 0;
    for(int i = 1; i < (1<<m); i ++) sum[i] = sum[i&(i-1)] + u[__builtin_ctz(i)];
    for(int i = 0; i < (1<<m); i ++) if(sum[i] <= (a[id]-1) && (a[id]-1) <= sum[i] + k) {
        int r = (a[id]-1) - sum[i];
        if(r + __builtin_popcount(i) < 2) continue;
        vector <int> v;
        for(int j = 0; j < m; j ++) if(i>>j&1^1) v.push_back(u[j]);
        v.push_back(a[id]);
        if(solve(v, k-r, id+1)) return 1;
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    sort(a+1, a+n+1);
    if(n == 1) return puts("YES"), 0;
    if(a[n] != n) return puts("NO"), 0;
    int k = 1;
    while(k <= n && a[k] == 1) k ++;
    if(n-k > 13) return puts("NO"), 0;
    vector <int> u;
    if(solve(u, k-1, k)) puts("YES");
    else puts("NO");
}

#include<bits/stdc++.h>
#define in freopen("input.txt","r",stdin)
#define out freopen("output.txt","w",stdout)

#define inp freopen(".in","r",stdin)
#define outp freopen(".out","w",stdout)

using namespace std;

#define pb push_back
#define pf push_front
#define p_f pop_front
#define p_b pop_back
#define LL long long int
#define LD long double
#define MP make_pair
#define sqr(x) (x*x)
#define fi first
#define dist(x,y,xx,yy) sqrt( (x-xx)*(x-xx)+(y-yy)*(y-yy) )
#define lenint int intsi(int x){ int cnt=0; while(x>0){cnt++;x/=10;} return (cnt); }
#define se second
#define all(v) v.begin(),v.end()
#define sc scanf
#define DEBUG(a) cout<<#a<<" -> "<<a<<endl;
#define pr printf
#define si size()
#define str strlen
#define gcd LL GCD(LL a,LL b){ if(b==0)return a;else return GCD(b,a%b); }
const int INF=(-1u)/2;
const long long int INF2=(-1ull)/2;
int a,b,i,d[1011000],j,k,n,m,timer=0,l,r,x,y;
int c[1011000],cnt=0,fl=0,a2,a3=-1000000,ans=0;
deque<int>v;
void rec( deque<int>v,int id )
{
    if( id==n )
    {
        if( v.si==1 && v[0]==n ){ cout<<"YES\n";exit(0); }
        return;
    }
    deque<int>vv;
    for( int i=id;i<n;i++ )
    {
        if( c[i]==1 )v.pb( 1 );
        else if( c[i]==2 ){ cout<<"NO\n";exit(0); }
        else
        {
            int fl=0;
            int k=v.si;
            for( int m=1;m<(1<<k);m++ )
            {
                int cnt=0;
                int ans=0;
                for( int j=0;j<k;j++ )
                {
                    if( (m&(1<<j)) ){cnt+=v[j];ans++;}
                }
                if( cnt==c[i]-1 && ans>1 )
                {
                    ans=0;
                    vv=v;
                    for( int j=0;j<k;j++ )
                    {
                        if( (m&(1<<j)) )
                        {
                            v.erase( v.begin()+(j-ans) );
                            ans++;
                        }
                    }
                    v.pb( c[i] );
                    rec( v,i+1 );
                    v=vv;
                    fl=1;
                }
            }
            if( fl==0 ){ return; }
        }
    }
}
main()
{
    //in;out;
    sc("%d",&n);
    for( i=0;i<n;i++ )
    {
        sc("%d",&c[i]);
    }
    sort(c,c+n);
    rec(v,0);
    cout<<"NO\n";
    return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define SZ(x) int((x).size())
#define endl "\n"
using namespace std;
using db = double;
using ll = long long;
using ull = unsigned long long;
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2> inline void chadd(T1 &x, T2 y, int Mod = mod) { x += y; while (x >= Mod) x -= Mod; while (x < 0) x += Mod; }
template <class T1, class T2> inline void chmax(T1 &x, T2 y) { if (x < y) x = y; }
template <class T1, class T2> inline void chmin(T1 &x, T2 y) { if (x > y) x = y; }
inline int nextInt() { int x; cin >> x; return x; }
void rd() {}
template <class T, class... Ts> void rd(T& arg, Ts&... args) { cin >> arg; rd(args...); }
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template <class T, class... Ts> void err(const T& arg, const Ts&... args) { cout << arg << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A>
void err(const T <t> &arg, const A&... args) { for (auto &v : arg) cout << v << ' '; err(args...); }
void ptt() { cout << endl; }
template <class T, class... Ts> void ptt(const T& arg, const Ts&... args) { cout << ' ' << arg; ptt(args...); }
template <class T, class... Ts> void pt(const T& arg, const Ts&... args) { cout << arg; ptt(args...); }
void pt() {}
template <template<typename...> class T, typename t, typename... A>
void pt(const T <t> &arg, const A&... args) { for (int i = 0, sze = arg.size(); i < sze; ++i) cout << arg[i] << " \n"[i == sze - 1]; pt(args...); }
inline ll qpow(ll base, ll n) { assert(n >= 0); ll res = 1; while (n) { if (n & 1) res = res * base % mod; base = base * base % mod; n >>= 1; } return res; }
//head
constexpr int N = 1e2 + 10;
int n, c[N], f[1 << 13][14][25];

vector <int> vec[1 << 13];

void run() {
	for (int i = 1; i <= n; ++i) rd(c[i]);
	sort(c + 1, c + 1 + n);
	reverse(c + 1, c + 1 + n);
	if (c[1] != n) return pt("NO");
	if (n == 1) return pt("YES");
	int lef = 0;
	for (int i = 1; i <= n; ++i) {
		if (c[i] == 1) ++lef;
		if (c[i] == 2) return pt("NO");
	}
	if (lef <= n / 2) return pt("NO");
	memset(f, 0, sizeof f);
	int _n = 0;
	for (int i = 1; i <= n; ++i) {
		if (c[i] == 1) {
			_n = i - 1;
			break;
		}
	}
	n = _n;
	for (int mask = 0; mask < (1 << n); ++mask) {
		for (int j = 0; j < n; ++j) if (((mask >> j) & 1) && __builtin_popcount(mask) <= c[j + 1]) {
			vec[mask].push_back(j);
		}
	}
//	for (int i = 0; i < n; ++i) {
//		for (int mask = 1 << i; mask < (1 << n); mask = (mask + 1) | (1 << i)) {
//			vec[mask].push_back(i);
//		}
//	}
	for (int i = 0; i < n; ++i) f[1 << i][i][c[i + 1] - 1] = 1;
	for (int S = 0; S < (1 << n); ++S) {
		for (auto &u : vec[S]) {
			for (int T = (S - 1) & S; T; T = (T - 1) & S) {
				for (auto &v : vec[T]) {
					if (((S - T) >> u) % 2 == 0) continue;
					if (c[v + 1] + 1 < c[u + 1]) {
						f[S][u][c[u + 1] - __builtin_popcount(S)] |= f[T][v][c[v + 1] - __builtin_popcount(T)];
					//	for (int j = 0; j <= lef; ++j) {
					//		f[S][u][c[u] - __builtin_popcount(S)] |= f[T][v][j];
					//	}
					}
				}
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		if (f[(1 << n) - 1][i][lef])
			return pt("YES");
	}
	pt("NO");
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cout << fixed << setprecision(20);
	while (cin >> n) run();
//    for (int kase = 1; kase <= _T; ++kase) {
//        cout << "Case #" << kase << ":\n";
//        run();
//    }
	return 0;
}

/*
Author:wuhuajun
*/
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdlib>
using namespace std;

typedef long long ll;
typedef double dd;
const int maxn=26;

int a[maxn],x[maxn],bak[maxn],n,sum;
bool flag[maxn];

void close()
{
exit(0);
}

void dfs(int now, int cnt,int one) //cnt -> x的个数 one -> 叶子节点1的个数
{
    if (now == n + 1)
    {
        if (cnt == 1 && x[cnt] == n)
        {
            printf("YES\n");
            close();
        }
        return;
    }
    if (a[now] == 1)
    {
        dfs(now + 1, cnt, one + 1);
        return;
    }
    for (int i=0;i<(1<<(cnt));i++)
    {
        sum = 0;
        int cc = 0;
        memset(flag,false,sizeof(flag));
        for (int j=1;j<=n;j++)
            if (1 << (j-1) & i)
            {
                cc++;
                flag[j] = true;
                sum += x[j]; //x代表分组
            }
        if (sum >= a[now] || sum + one <= a[now]-2) continue; //一个是多了，一个是少了
        if (sum == a[now] - 1 && cc == 1) continue;//如果只用那个，且只有一个，那就不行
        {
            int bak[26];
            memcpy(bak, x, sizeof(x));
            memset(x,0,sizeof(x));
            int num = 0;
            for (int j=1;j<=cnt;j++)
                if (flag[j] == false)
                {
                    x[++num] = bak[j];
                }
            x[++num] = a[now];
            dfs(now + 1, num, a[now] - sum - 1);
            memcpy(x,bak,sizeof(bak));
        }
    }
}

void init()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if (n == 1 && a[1] == 1)
    {
        printf("YES\n");
        close();
    }
    sort(a + 1,a + n + 1);
    dfs(1, 0, 0);
    printf("NO\n");
}

int main ()
{
    init();
    close();
    return 0;
}

// Phoenix

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=25,MASK=(1<<12)+10;

int a[maxn],CNT;
bool dp[MASK][maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int N,n=0,mx=0;cin>>N;
    for(int i=0;i<N;i++){
	int x;cin>>x;
	if(x==1) CNT++;
	else a[n++]=x;
	if(x==2) return cout<<"NO\n",0;
	mx=max(mx,x);
    }
    if(CNT<=n || mx!=n) return cout<<"NO\n",0;
    for(int i=0;i<=CNT;i++) dp[0][i]=1;
    for(int msk=1;msk<(1<<n);msk++){
	int id=-1,C=__builtin_popcount(msk);
	for(int i=0;i<n;i++){
	    if(bit(msk,i) && (id==-1 || a[id]<a[i]))
		id=i;
	}
	for(int i=1;i<=CNT;i++){
	    dp[msk][i]=(a[id]==C+i && dp[msk ^ (1<<id)][i])||(dp[msk][i-1]);
	    for(int j=1;j<i;j++){
		int msk2=msk;
		while(true){
		    msk2=(msk2-1)&msk;
		    if(msk2==0) break;
		    dp[msk][i]|=dp[msk2][j] && dp[msk^msk2][i-j];
		}
	    }
	}
    }
    return cout<<(dp[(1<<n)-1][CNT]?"YES":"NO")<<endl,0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int n;
int a[50];
map <int, int> mp;

void no() {
    puts("NO");
    exit(0);
}

void yes() {
    puts("YES");
    exit(0);
}

int main() {

    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        mp[a[i]]++;
    }

    sort(a + 1, a + n + 1);

    if (mp[n] == 0 || mp[n] > 1)
        no();

    if (mp[2] > 0)
        no();

    if (mp[1] == 0)
        no();

    if (n < 3)
        no();

    yes();

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

string ans;
int n, leaf;
vector<int> nodes;
int dp[25][1 << 12][25];

void in();
void solve();
void out();

int main(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    in();
    solve();
    out();
}

void in(){
    cin >> n;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        if(t == 1)
            leaf++;
        else
            nodes.push_back(t);
    }
}

void solve(){
    ans = "NO";
    if(nodes.size() + 1 > leaf)
        return;
    sort(nodes.begin(), nodes.end(), greater<int>());
    dp[nodes.size()][0][0] = 1;
    for(int i = nodes.size() - 1; i >= 0; i--){
        for(int j = 0; j < (1 << nodes.size() - i - 1); j++){
            for(int k = 0; k <= leaf; k++){
                vector<int> indicies;
                int X = j;
                while(X){
                    indicies.push_back(X & -X);
                    X -= X & -X;
                }
                for(int l = 0; l < (1 << indicies.size()); l++){
                    int newmask = 0;
                    int sum = 0;
                    for(int m = 0; m < indicies.size(); m++){
                        if((1 << m) & l){
                            newmask += indicies[m];
                            sum += nodes[__builtin_ctz(indicies[m])];
                        }
                    }
                    sum = nodes[i] - 1 - sum;
                    if(sum >= 0 && sum <= k)
                        dp[i][j][k] |= dp[i + 1][j ^ newmask][k - sum];
                }
            }
        }
    }
    if(dp[0][(1 << nodes.size() - 1) - 1][leaf])
        ans = "YES";
}

void out(){
    cout << ans;
}

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int n, m;
int a[24];
int child[24];
int lim[24];

void go(int i) {
    //cout << i << endl;
    for (int j = i + 1; j < n; j++)
        if (!a[j] && child[j] < 2)
            return;
    if (a[i] <= 1) {
        if (a[i] == 1) {
            printf("NO");
            exit(0);
        }
        else {
            int need = 0;
            for (int j = i + 1; j < n; j++)
                need += a[j];
            if (need == m) {
                printf("YES");
                exit(0);
            }
            else {
                /*printf("NO");
                exit(0);*/
            }
        }
        return;
    }
    int _lim = lim[a[i]];
    for (int j = i + 1; j < _lim; j++)
        if (a[j] > a[i]) {
            lim[a[i]] = j;

            a[j] -= a[i]+1;
            child[j]++;
            if (a[j] || child[j] >= 2)
                go(i - 1);
            a[j] += a[i]+1;
            child[j]--;
        }
    lim[a[i]] = _lim;
}

int main() {

    scanf("%d", &n);
    m = 0;
    for (int i = 0; i < n; i++) {
        lim[i] = n;
        scanf("%d", a + i);
        a[i]--;
        m += a[i] == 0;
    }
    sort(a, a + n);

    if (n == 1) {
        printf("%s", a[0] == 0 ? "YES" : "NO");
        return 0;
    }
    if (n == 2) {
        printf("NO");
        return 0;
    }
    /*if (m == 0) {
        printf("NO");
        return 0;
    }*/
    go(n - 2);
    printf("NO");

    return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<bitset>
#include<iomanip>
#include<iostream>
#include<cmath>
using namespace std;
#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define REP(i,x,y) for(int i=(x);i<=(y);i++)
#define _REP(i,x,y) for(int i=(x);i>=(y);i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define pb push_back
#define IN insert
#define ER erase
#define BE begin()
#define ED end()
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
inline char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

int n,i,j,k,l,p,x,cnt;
int g,a[30];

bool f[25][25][10000];
bool v[25][25][10000];

bool dp(int x,int i,int S)
{
    if(x<1)return 0;
    int TS=S;
    #define F f[x][i][TS]
	if(v[x][i][TS])return F;v[x][i][TS]=1;

	if(x==1)return F=((S==0)&&i==1);
	int x2,i2,j,S2,cnt=0;bool pd=0;
	rep(j,1,g)if(S>>(j-1)&1)cnt++;
	rep(j,1,g)if(S>>(j-1)&1)if(a[j]==x){pd=1;S-=1<<(j-1);break;}
	if(cnt+i!=x)return F=0;
	if(S==0)return F=(x-1==i&&i>1);

	rep(x2,1,x)
	rep(i2,1,i)
	for(S2=S;S2;S2=(S2-1)&S)
	{
		if(dp(x2,i2,S2)&&dp(x-pd-x2,i-i2,S-S2))
        {
            return F=1;
        }
	}
	return 0;
}
int main()
{
    //freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	read(n);
	bool have=0;
	rep(i,1,n)
	{
		read(x);
		if(x==1)cnt++;
		else
        {
            if(x==n)have=1;
            a[++g]=x;
        }
	}
	if(!have||cnt<n-cnt+1){printf("NO\n");return 0;}

	if(dp(n,cnt,(1<<g)-1))printf("YES\n");else printf("NO\n");

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int N, cnt;

vector<int> C, P, Q;

vector<vector<int> > cc;

int dp(int mask, int c) {
    int &ret = cc[mask][c];
    if(ret != -1) return ret;

    int idx = 0;

    for(int i = N - 1; i >= 0; i--) {
        if(mask & (1 << i)) {
            idx = i + 1;
            break;
        }
    }

    if(idx == N) return ret = 1;

    for(int i = 0; i <= c; i++) {

        for(int j = 0; j < (1<<N); j++) {
            if((mask | j) == mask && P[j] + 1 + i == C[idx] && Q[j] + i >= 2) {
                if(dp(mask ^ j ^ (1 << idx), c - i)) return ret = 1;
            }
        }
    }
    return ret = 0;
}

int main() {
    scanf("%d", &N);

    cnt = 0;

    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        if(t == 1) cnt++;
        else C.push_back(t);
    }

    sort(C.begin(), C.end());

    N = C.size();

    P.resize((1<<N));
    Q.resize((1<<N));

    for(int i = 0; i < (1<<N); i++) {
        P[i] = 0;
        Q[i] = 0;

        for(int j = 0; j < N; j++) {
            if(i & (1 << j)) {
                P[i] += C[j];
                Q[i] += 1;
            }
        }
    }

    cc = vector<vector<int> >((1<<N), vector<int>(cnt + 1, -1));
    if(dp(0, cnt)) printf("YES");
    else printf("NO");
}

#include <iostream>
#include <algorithm>
using namespace std;

int n, c[25], nchild[25];

int go(int v, int p) {
	if(v == n) {
		for(int i=0;i<n;i++) if(c[i] > 1) return 0;
		return 1;
	}
	int good=1;
	if(p != -1) {
		nchild[p]++;
		c[p] -= c[v];
	}
	if(good) for(int i=0;i<=v;i++) {
		if(nchild[i] == 0 && c[v+1] == c[i]-1) continue;
		if(c[v+1] >= c[i]) continue;
		if(go(v+1, i)) return 1;
	}
	if(p != -1) {
		nchild[p]--;
		c[p] += c[v];
	}
	return 0;
}

int main() {
	cin>>n;
	for(int i=0;i<n;i++) cin>>c[i];
	sort(c, c+n);
	reverse(c, c+n);
	int ok=1;
	for(int i=0;i<n;i++) if(c[i]==2) ok=0;
	if(ok && c[0] == n && go(0, -1)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <deque>
#include <cassert>

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"
#define ms(a,x) memset(a, x, sizeof(a))
#define forit(it,s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); ++it)

int n;
int a[25];
int b[25];
bool ok;
int mark[25];

inline void go(int v)
{
	if (v < 0)
	{
		bool t = 1;
		for (int i = 0; i < n && t; ++i)
			if (b[i] == 1)
				t = 0;

		if (t)
		{
			puts("YES");
			exit(0);
		}
		return;
	}
	for (int i = v + 1; i < n; ++i)
	{
		if (b[i] < a[v]) continue;
		b[i] -= a[v];
		go(v - 1);
		b[i] += a[v];
	}
}

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
		b[i] = a[i];
	}
	sort(a, a + n);

	ok = 1;
	for (int i = 0; i < n; ++i)
		if (a[i] == 2) ok = 0;

	if (a[n - 1] != n || !ok)
	{
		puts("NO");
		return 0;
	}

	go(n - 2);
	puts("NO");

	return 0;
}

#include <bits/stdc++.h>

#define NN 25

#define sz(a) a.size()

#define pb push_back

using namespace std;

typedef long long INT;

typedef pair<int, int> pii;

int n;

vector<int> a;

void init(){

	cin>>n;

	for(int i=0; i<n; i++) {

		int u;

		scanf("%d", &u);

		a.pb(u);

	}

	sort(a.begin(), a.end());

}

int solve(vector<int> a, int n){

	if(n==1) {

		if(sz(a)==1 && a[0]==1) return 1;

		return 0;

	}

	int flag[NN];

	memset(flag, 0, sizeof(flag));

	for(int i=0; i<sz(a); i++){

		flag[a[i]]++;

	}

	if(flag[n]!=1) return 0;

	for(int i=1; i<=(n-1)/2; i++){

		if(flag[i]==0) continue;

		vector<int> tmp;

		tmp.clear();

		int f=0;

		for(int j=0; j<sz(a); j++){

			if(f || a[j]!=i) tmp.pb(a[j]);

			if(a[j]==i) f=1;

			if(a[j]==n) tmp.pop_back();

		}

//		for(int j=0; j<sz(tmp); j++) cout<<tmp[j]<<endl;

//		puts("");

		if(solve(tmp, n-i-1)) return 1;

		tmp.pb(n-i);

		if(solve(tmp, n-i)) return 1;

	}

	return 0;

}

int main() {

	init();

	if(solve(a, n)) puts("YES");

	else puts("NO");

	return 0;

}

#include<cstdio>
#include<algorithm>
using namespace std;

int a[30];
bool f[30];

int main()
{
	int n,i,j,k;
	for(scanf("%d",&n),i=0;i<n;i++)
		scanf("%d",a+i);
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		k=1;
		for(j=i;k<a[i]&&j--;)
			if(!f[j]&&a[j]<=a[i]-2&&k+a[j]<=a[i])
				k+=a[j],f[j]=1;
		if(j<0)
			return puts("NO");
	}
	for(i=0;i<n-1;i++)
		if(!f[i])
			return puts("NO");
	puts("YES");
	return 0;
}

#include<iostream>
#include<vector>
#include<fstream>
#include<queue>
#include<algorithm>
#include<list>
#include<cstdio>
#include<stack>
#include<cstring>
#include <climits>
#include<cmath>
#include<string>
#include <functional>
#include<sstream>
#include<map>
#include<set>

#pragma comment(linker, "/STACK:100000000000000")

using namespace std;
#define     For(i,a,b)        for (int i=a; i<b; i++)
#define     Rep(i,a)          for (int i=0; i<a; i++)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     UNIQUE(v)         Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     MP                make_pair
#define     SF                scanf
#define     PF                printf
#define     MAXN              1001
#define     MAXM              1001
#define     MOD               1000000007
#define     Dbug             cout<<"";
#define     EPS              1e-15
typedef long long ll;
typedef pair<int,int> pii;
int n, ind, dp[16][25][1<<16][2], tw[20];
vector<int> v;
int rec(int p, int rem, int mask, bool x)
{
	if(p==v.size()) return 0;
	if(~dp[p][rem][mask][x]) return dp[p][rem][mask][x];
	if(rem==1)
	{
		if(p+1<v.size()) return dp[p][rem][mask][x]=rec(p+1, v[p+1] , mask, 0);
		else return dp[p][rem][mask][x]=rec(p+1, 0 , mask, 0);
	}
	int ret=1+rec(p, rem-1, mask, 1);
	Rep(i, v.size()) if(!(mask&tw[i]))
	{
		if((v[i]<rem-1) || (x && v[i]<=rem-1))
		{
			ret=min(ret, rec(p, rem-v[i], mask|tw[i], 1));
		}
	}
	return dp[p][rem][mask][x]=ret;
}
int main(){
	//ios_base::sync_with_stdio(false);
	//freopen("a.in","r",stdin);
	Rep(i, 20) tw[i]=1<<i;
	cin>>n;
	int t;
	Rep(i, n)
	{
		cin>>t;
		v.push_back(t);
	}
	Sort(v);
	Rep(i, n) if(v[i]==2)
	{
		cout<<"NO";
		return 0;
	}
	int o=0;
	vector<int> nx;
	Rep(i, n) if(v[i]==1) o++;
	else nx.push_back(v[i]);
	if(n-o>=16 || o==n)
	{
		cout<<"NO";
		return 0;
	}
	v=nx;
	Set(dp, -1);
	int x=rec(0, v[0], 0, 0);
	if(x==o) cout<<"YES";
	else cout<<"NO";
	return 0;
}

#include <cstdio>
#include <algorithm>
#define maxn 30

using namespace std;

int n,ans;
int a[maxn],flag[maxn];

int dfs(int x,int st,int cur,int rest) {
	if (ans) return 1;
	if (st>n) return 1;
	//printf("%d %d %d %d\n",x,st,cur,rest);
	if ((x==n)&&(rest==1)) {
		ans=1;
		return 1;
	}
	if (a[x]==1) return 1;
	if (!cur) {
		for (int i=x;i<=n;i++) if (!flag[i])
			for (int j=i+1;j<=n;j++) if (!flag[j])
				if (a[i]+a[j]<a[x]) {
					flag[i]=flag[j]=1;
					if (!dfs(x,j+1,1,a[x]-a[i]-a[j])) return 0;
					if (!dfs(i,i,0,a[i])) return 0;
					if (!dfs(j,j,0,a[j])) return 0;;
					flag[i]=flag[j]=0;
				}
	} else {
		for (int i=st;i<=n;i++) if ((!flag[i])&&(a[i]<rest)) {
			flag[i]=1;
			if (!dfs(x,i+1,1,rest-a[i])) return 0;
			if (!dfs(i,i,0,a[i])) return 0;
			flag[i]=0;
		}
	}
	if (rest!=1) return 0;
}

bool cmp(int a,int b) {
	return a>b;
}

int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmp);
	flag[1]=1;
	dfs(1,1,0,a[1]);
	if (ans) printf("YES\n"); else printf("NO");
	return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int MAXN=1005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int edgenum=0,to[MAXN],nxt[MAXN],head[MAXN],s[MAXN],a[MAXN],fa[MAXN],n,cnt,num;
void add(int u,int v) { ++edgenum,to[edgenum]=v,nxt[edgenum]=head[u],head[u]=edgenum; }
int check(int x)
{
	int flag=1,t=0;
	for (int i=head[x];i;i=nxt[i])
	{
		flag&=check(to[i]);
		t++;
	}
	if (s[x]>=a[x]) flag=0;
	if (t+a[x]-s[x]-1<=2) flag=0;
	cnt+=a[x]-s[x]-1;
	return flag;
}
void dfs(int x)
{
	if (x==num+1)
	{
		edgenum=0,cnt=0;
		for (int i=1;i<=num;i++) head[i]=0;
		for (int i=2;i<=num;i++) add(fa[i],i);
		if (!check(1)||cnt!=n-num) return;
		puts("YES");
		exit(0);
		return;
	}
	for (int i=1;i<x;i++)
		if (s[i]+a[x]<a[i]) s[i]+=a[x],fa[x]=i,dfs(x+1),s[i]-=a[x];
}
signed main()
{
	n=read(),num=0;
	for (int i=1;i<=n;i++) a[i]=read(),num+=(a[i]>1);
	if (!num)
	{
		if (n==1) puts("Yes");
		else puts("NO");
		return 0;
	}
	sort(a+1,a+n+1,[&](int x,int y){ return x>y; });
	dfs(2);
	puts("NO");
	return 0;
}

#include <cstdio>
#include <algorithm>
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
const int NMax=30;
int N,father[NMax],flag=0,left[NMax];
int A[NMax],cnt[NMax];
bool cmp(int a,int b) {return a>b;}
void DFS(int a,int b) {
	if(flag) return ;
	if(a>N) {
		flag=1;
		for(int i=1;i<=N;i++) {
			if(!father[i]) {
				flag=0;
				break;
			}
		//	printf("%d ",father[i]);
		}
		//puts("");
		return ;
	}
	if(!father[a]) return ;
	if(left[a]==0) {
		if((A[a]==1||cnt[a]>=2)||(left[a+1]>=A[b]))DFS(a+1,b);
		return ;
	}
	for(int i=b;i<=N;i++) if(!father[i]&&left[a]>=A[i]){if(A[min(b,i+1)]>left[a+1]&&A[min(b,i+1)]>left[a]) continue;
		father[i]=1;
		left[a]-=A[i];
		cnt[a]++;
		DFS(a,min(b,i+1));
		cnt[a]--;
		if(flag) return ;
		left[a]+=A[i];
		father[i]=0;
	}else if(left[a]<A[i])
		b=i;
}
int cnt1[NMax];
int main()
{
	scanf("%d",&N);
	left[N+1]=100;
	for(int i=1;i<=N;i++)scanf("%d",&A[i]),cnt1[A[i]]++;//left[i]=A[i],left[i]--;
	if(cnt1[1]<(N+1)/2) {
		puts("NO");
		return 0;
	}
	sort(A+1,A+N+1,cmp);
	for(int i=1;i<=N;i++) left[i]=A[i]-1;
	father[1]=-1;
	DFS(1,2);
	if(flag) puts("YES");
	else puts("NO");
	getchar();getchar();getchar();
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 26;
const int M = 13;

int c[N];
bool dp[N][N][1 << M];

int main() {
  int n, leafs = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", c + i);
    leafs += (c[i] == 1);
  }
  sort(c, c + n);
  reverse(c, c + n);
  int m = n - leafs;
  if (leafs < (n + 1) / 2) {
    return puts("NO");
  }
  int lim = 1 << m - 1;
  dp[0][leafs][lim - 1] = 1;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j <= leafs; ++j) {
      for (int k = 0; k < lim; ++k) if (dp[i][j][k]) {
        for (int p = 0; p < lim; ++p) if ((k & p) == k) {
          int s = 0;
          int cc = 0;
          for (int o = 0; o < m; ++o) if (p >> o & 1) {
            s += c[o];
            ++cc;
          }
          int tmpl = c[i] - s - 1;
          if (tmpl <= leafs && cc + tmpl >= 2 && tmpl >= 0) {
            dp[i + 1][leafs - tmpl][k ^ p] = 1;
          }
        }
      }
    }
  }
  puts(dp[m][0][0] ? "YES" : "NO");
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N , i ;
    cin>>N;
    vector <pair <  int, int >  > A(N);
    vector < int > mark(N,0);
    for(i=0;i<N;++i)
    {
        cin>>A[i].first;
        A[i].second = A[i].first;
    }
    sort(A.begin(),A.end());
    for(;!A.empty();)
    {
        if(A[0].second!=1 || mark[0]==1)
        {
            cout<<"NO";
            return 0;
        }
        int x = A[0].first;
        A.erase(A.begin(),A.begin()+1);
        mark.erase(mark.begin(),mark.begin()+1);
        for(i=0;i<A.size() && (A[i].second<x+1) ;++i);
        if(i==A.size() && A.size())
        {
                cout<<"NO";
                return 0;
        }
        if(i!=A.size())
        {
            A[i].second-=x;
            mark[i]++;
        }
    }

    cout<<"YES";
    return 0;
}

#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <climits>
#include <cassert>

#define FOR(i,n) for(int i=0,_n=n;i<_n;i++)
#define FORD(i,n) for(int i=n;i>=0;i--)
#define FORR(i,s,n) for(int i=s,_n=n;i<_n;i++)
#define FORRD(i,n,s) for(int i=n,_s=s;i>=_s;i--)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define vi vector<int>
#define fs first
#define sec second

#define maxn 30
using namespace std;
typedef long long ll;

int w[maxn],n,k;
bool one[maxn],ans = false;

void f(int x){
	if(w[x] == 1){ // just leaves
		int c = 0;
		FORR(i,x + 1,n)
			c += w[i] - 1;
		ans = (c == k);
		return;
	}
	FORR(i,x + 1,n){
		if(w[x] + 1 == w[i] && !one[i]) continue;
		w[i] -= w[x];
		bool tmp = one[i];
		one[i] = true;

		f(x - 1);
		if(ans) return;
		w[i] += w[x];

		one[i] = tmp;
	}
}
int main(){
	cin>>n;
	FOR(i,n)
		cin>>w[i];
	sort(w,w + n);
	for(k = 0;k < n && w[k] == 1;k++);
	if(n - k >= k || w[k] == 2) cout<<"NO\n";
	else if(n == 1) cout<<"YES\n";
	else{ f(n - 2); cout<<(ans ? "YES\n":"NO\n"); }
	return 0;
}

//                      be naame khoda

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int maxN = 30;
const int maxS = maxN * maxN;

int c[maxN], n;
int sum[1 << 24];
vector <int> could[maxS];
bool dp[1 << 24], mark[maxN];

int main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    int ss = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> c[i];
        ss += c[i];
    }
    sort(c, c + n);
    if(c[0] != 1)
    {
        cout << "NO\n";
        return 0;
    }
    for(int i = 0; i < n; i++)
        sum[1 << i] = c[i];
    for(int m = 0; m < (1 << n); m++)
    {
        if(!sum[m])
            sum[m] = sum[m & (m-1)] + sum[m - (m & (m-1))];
        could[sum[m]].push_back(m);
    }
    for(int i = 0; i < n; i++)
        if(c[i] > 1)
        {
            bool can = 0;
            for(int j = 0; !can && j < could[c[i] - 1].size(); j++)
            {
                bool fl = 0;
                int m = could[c[i] - 1][j], cnt = 0;
                for(int j = 0; !fl && j < n; j++)
                    if(m & (1 << j))
                    {
                        if(mark[j])
                            fl = 1;
                        cnt++;
                    }
                if(!fl && cnt >= 2)
                {
                    for(int j = 0; j < n; j++)
                        if(m & (1 << j))
                            mark[j] = 1;
                    can = 1;
                }
            }
            if(!can)
            {
                cout << "NO\n";
                return 0;
            }
        }
    int k = 0;
    for(int i = 0; i < n; i++)
        if(!mark[i])
            k++;
    if(k == 1)
        cout << "YES\n";
    else
        cout << "NO\n";
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <deque>
#include <cassert>

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"
#define ms(a,x) memset(a, x, sizeof(a))
#define forit(it,s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); ++it)

int n;
int a[26];
int b[26];
bool ok;

inline void go(int v, int rem, int cur, int last)
{
	if (v == n)
	{
		puts("YES");
		exit(0);
	}
	if (rem == 1)
	{
		if (cur == 1) return;
		++b[a[v]];
		go(v + 1, a[v + 1], 0, n);
		--b[a[v]];
		return;
	}
	if (!cur)
	{
		for (int i = rem - 2; i >= 1; --i)
		{
			if (!b[i]) continue;
			--b[i];
			go(v, rem - i, cur + 1, i);
			++b[i];
		}
	}
	else
	{
		for (int i = min(rem - 1, last); i >= 1; --i)
		{
			if (!b[i]) continue;
			--b[i];
			go(v, rem - i, cur + 1, i);
			++b[i];
		}
	}
}

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
		b[i] = a[i];
	}
	sort(a, a + n);

	ok = 1;
	for (int i = 0; i < n; ++i)
		if (a[i] == 2) ok = 0;

	if (a[n - 1] != n || !ok)
	{
		puts("NO");
		return 0;
	}

	go(0, a[0], 0, n);
	puts("NO");

	return 0;
}

#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
#include <ctime>
#include <cstring>
using namespace std;

int N;
int arr[30];
short LOG[1<<24];
vector<int> ADJ[25];
int SUM[1<<24];
int mem[1<<24];
int dp(int mask)
{
    int b = mask & -mask;
    int id = LOG[b];
    if(mask == 0)return 1;
    if(mem[mask] != -1)return mem[mask];
    if(arr[id] == 1)
    {
        if( id+1 < N && (mask & (b<<1)))
            return mem[mask] = dp(mask ^ b);
        return mem[mask] = id+1 >= N;
    }
    int w = 0;
    for(int i = 0; i < ADJ[arr[id]-1].size() && !w; ++i)
    {
        int nm = ADJ[arr[id]-1][i];
        if( nm & mask )continue;
        if( ((mask ^ nm) & (b<<1)) == 0 )continue;
        if( (nm & -nm) == nm )continue;
        if(dp(mask ^ nm ^ b)) w = 1;
    }
    return mem[mask] = w;
}

int main()
{
    memset(mem,-1,sizeof(mem));
    cin >> N;
    for(int i = 0; i < 24; ++i)
        LOG[1<<i] = i;
    for (int i = 0; i < N; ++i) {
        cin >> arr[i];
    }
    sort(arr,arr+N);
    reverse(arr,arr+N);
    int mi = 0;
    for(int i = 0; i < N; ++i)
    {
        if(arr[i] != 1)
        {
            mi = i;
        }
    }
    int ONES = mi+1;
    int cntM = 0;
    for(int i = 0; i < N; ++i)
    {
        if(arr[mi] == arr[i])
        {
            cntM++;
            ONES += arr[mi] - 1;
        }
    }
    if(ONES > N)
    {
        cout << "NO" << endl;
        return 0;
    }
    if(arr[0] != arr[mi])
    {
        for(int i = 0; i < N; ++i)
        {
            if(arr[i] == arr[mi])
                arr[i] = 1;
        }
        N -= cntM;
    }
    for(int i = 0; i < 25; ++i)
        ADJ[i].reserve(500000);
    for(int i = 1; i < (1<<N); ++i)
    {
        int b = i & -i;
        SUM[i] = SUM[i ^ b] + arr[LOG[b]];
        if(SUM[i] < 25)
            ADJ[SUM[i]].push_back(i);
    }
    cout << (dp(1) ? "YES" : "NO") << endl;
    return 0;
}

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, out;
vi in;
int r[1 << 11];
int memo[1 << 11];

int rec(int mask){ //�O�_�̍ŏ��l

	int &res = memo[mask];
	if(res >= 0) return res;

	int root = r[mask];
	int child = __builtin_popcount(mask) - 1;
	assert(mask > 0);
	mask ^= 1 << root;

	if(mask == 0){
		if(in[root] < 3) return res = inf;
		return res = in[root] - 1;
	}

	vector<vi> dp(child + 1, vi(1 << n, inf)); //child, mask
	dp[0][0] = 0;

	rep(i, child) for(int jj = mask - 1 & mask; ; jj = jj - 1 & mask){

		int j = mask ^ jj;
		for(int k = j; k; k = (k - 1) & j){
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j ^ k] + rec(k));
		}
		if(jj == 0) break;
	}

	res = inf;
	rep(i, child + 1){

		if(in[root] - 1 < child + dp[i][mask]) continue;

		int direct_leaf = in[root] - 1 - child - dp[i][mask];
		if(direct_leaf + child >= 2) res = min(res, direct_leaf + dp[i][mask]);
	}
	return res;
}

int main(){
	cin >> n;
	rep(i, n){
		int x; cin >> x;
		if(x == 1) out++;
		else in.pb(x);
	}
	if(out == n || in.size() > 11){
		cout << (n == 1 ? "YES" : "NO") << endl;
		return 0;
	}

	memset(memo, -1, sizeof(memo));
	n = in.size();
	sort(all(in));

	rep(i, 1 << n) for(int j = n - 1; j >= 0; j--) if(i & 1 << j){
		r[i] = j;
		break;
	}

	rep(i, n) cerr<<in[i]<<(i==n-1?"\n":" ");

	cout << (rec((1 << n) - 1) == out ? "YES" : "NO") << endl;

	return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int tree[30] = {}, jl[30] = {};
int n = 0;
bool compare(int a, int b)
{
	return a>b;   //升序排列，如果改为return a>b，则为降序

}
int findmax(int n)
{
	int max = 0;
	for (int i = 1; i <n; i++)
	{
		if (tree[i]>tree[max])
		{
			max = i;
		}
	}
	return max;
}
bool bfs()
{
	int i=0;
	int max=0;
	i = 1;
	int k = 1;
	while (tree[max]>tree[i]&&i<n)
	{
		tree[max] -= tree[i];
		jl[max]++;
		max = findmax(i);
		if (tree[max] < tree[k])
		{
			if (tree[max] - tree[i + 1] <= tree[i + 2])
			{
				if (tree[k] - tree[i + 1]>tree[i + 2])
				{
					max = k;
					k++;
				}
			}
		}
		i++;
	}
	if (i != n)
	{
		return false;
	}
	for (int i = 0; i < n; i++)
	{
		if (jl[i] == 1)
		{
			return false;
		}
		if (tree[i] != 1)
		{
			return false;
		}
	}
	return true;
}
int main()
{
	int i = 0;
	while (scanf("%d", &n) != EOF)
	{
		memset(jl, 0, sizeof(jl));
		i = 0;
		for ( i = 0; i < n; i++)
		{
			scanf("%d", &tree[i]);
		}
			sort(tree, tree + n, compare);
			bool xx = bfs();
			if (xx)
			{
				printf("YES\n");
			}
			else
			{
				printf("NO\n");
			}
	}

	return 0;
}

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#define INF 100000
using namespace std;
int x[30];
bool dfs(int res,int p[],bool f[],int id,int n){
    if(id==n){
        if(res==0)return true;
        else return false;
    }else if(res<x[p[id]])return false;
    f[id]=true;
    bool ok=dfs(res-x[p[id]],p,f,id+1,n);
    if(ok)return ok;
    f[id]=false;
    return dfs(res-x[p[id]],p,f,id+1,n);
}
int main()
{
    int n;cin>>n;
    for(int i=0;i<n;i++)
        cin>>x[i];
    sort(x,x+n);
    int p[30],num;
    bool ok=true;
    bool f[30];
    for(int i=0;i<n;i++)
    {
        if(x[i]==1)continue;
        num=0;
        memset(f,0,sizeof(f));
        for(int j=i-1;j>=0;j--){
            if(x[j]!=INF && x[j]<=x[i]-2)p[num++]=j;
        }
        ok=dfs(x[i]-1,p,f,0,num);
        if(!ok)break;
        else{
            for(int j=0;j<num;j++){
                if(f[j])x[p[j]]=INF;
            }
        }
    }
    for(int i=0;i<n-1;i++)
        if(x[i]!=INF)ok=false;
    if(ok)puts("YES");
    else puts("NO");
    return 0;
}

#include <bits/stdc++.h>
#include <unordered_map>

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define ps(ch) printf("%s",ch)
#define Afridi 0
#define NL printf("\n")
#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define Max (1<<24)
#define PI 3.141592653589793
#define FI freopen("in.txt","r",stdin)
#define FO freopen("out.txt","w",stdout)
#define mod 1000000007
#define INF 1000000000

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

LL bigmod(LL b,LL p)
{
    if(p == 0)return 1;
    LL my = bigmod(b,p/2);
    my*=my;
    my%=mod;
    if(p & 1)my*=b,my%=mod;
    return my;
}
inline int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
inline bool checkb(int n,int pos)
{
    return (bool)(n & (1 << pos));
}
//inline int max(int x,int y) { return x > y ? x : y; }

short int sum[Max];
char pc[Max],lc[Max],votka[Max];
int n,ara[30],mnval;

bool Print(int mask)
{
	for(int i = 0; i < n; i++)printf("%d",checkb(mask,i));
	puts("");
}

void prework()
{
	int child_mask = 0;
	for(int i = 0; i < n; i++) if( ara[i] == 1 ) child_mask = setb(child_mask,i);
	for(int mask = 0; mask < (1 << n); mask++)
	{
		int v = 0;
		for(int i = 0; i < n; i++)if( checkb(mask,i) )sum[mask] += ara[i],v = max(v,ara[i]);
		votka[mask] = v;
		pc[mask] = __builtin_popcount(mask);
		lc[mask] = __builtin_popcount(mask & child_mask);

	}
}

bool F(int u,int mask);

bool G(int u,int baki,int taken)
{
	if( u == n )return baki == 0;
	if( checkb(taken,u) == 0 )return G(u+1,baki,taken);
	if( sum[baki] < sum[taken] - pc[taken] )return 0;
	if(  votka[taken] > mnval && votka[baki] + 2 > votka[taken] )return 0;

    bool ret = 0;
    if( F(u,0) )ret |= G(u+1,baki,taken^(1<<u));

    if( ara[u] > 4 )
    {
		for(int i = baki; i; i = (i-1) & baki)
		{
			if( pc[i] == 1 )continue;
			if( F(u,i) )ret |= G(u+1,baki^i,taken^(1<<u));
			if(ret)goto shit;
		}
    }

	shit:
    return ret;
}

inline bool Distribute(int u,int mask,int taken)
{
	if( sum[mask] + 1 == ara[u] )return 1;
    int baki = mask ^ taken;
	return G(0,baki,taken);
}

/*inline bool oka(int taken,int mask)
{
	int baki = mask ^ taken;
	if( sum[baki] < sum[taken] - pc[taken] )return 0;

	int non_leaf = pc[taken] - lc[taken];
	int need = non_leaf + non_leaf;
	if( lc[baki] < pc[baki] )need += (votka[baki]+2)/2;
	if( lc[baki] < need )return 0;
	return 1;
}*/

bitset <Max> dp[24];
bitset <Max> visit[24];
//bool dp[24][Max];
//bool visit[24][Max];
bool F(int u,int mask)
{
    if( mask == 0 )return ara[u] <= mnval;

	if( visit[u][mask] )return dp[u][mask];

    bool ret = 0;

    for(int i = mask; i; i = (i-1) & mask)
    {
        if( pc[i] > 1 && sum[i] + 1 == ara[u] )
        {
			ret |= Distribute(u,mask,i);
			if(ret)goto hell;
        }
    }
    hell:
    visit[u][mask] = 1;
    return dp[u][mask] = ret;
}

int cnt[30];
void reduce()
{
	int i;
	Rep(i,n)cnt[ ara[i] ]++;
	mnval = 4;
	if( cnt[3] + cnt[4] == 0 )
	{
		rep(i,n)
		{
			if(i < 5)continue;
			if(cnt[i])
			{
				mnval = i;
				cnt[1] -= cnt[i]*(i-1);
				break;
			}
		}
	}

	cnt[1] -= cnt[3]*2;
	cnt[1] -= cnt[4]*3;
	if(cnt[1] < 0 || cnt[2])
	{
		puts("NO");
		exit(0);
	}
	int id = 0;
	rep(i,n)
	{
		int x = cnt[i];
		while(x--)ara[id++] = i;
	}
	n = id;
	//D(n);
}

int main()
{
	//FI;
	int i,root;
	si(n);
	Rep(i,n)si(ara[i]);
	sort(ara,ara+n);
	if( ara[n-1] != n )
	{
		puts("NO");
		return 0;
	}
	reduce();
	prework();
	root = n - 1;
	bool ret = F(root, ( (1<<n)-1 ) ^ (1<<root) );
	if(ret)puts("YES");
	else puts("NO");
	return 0;
}