stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <cstdio>

#include <queue>

#include <algorithm>



int n;

int S[1<<18];

std::priority_queue<int> Q;

std::vector<int> buf;



int main(){

  scanf("%d",&n);

  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q.push((1<<(n+1))-1);

  for(int i=0;i<k;i++){

    if(Q.size() < S[i]){

      puts("No");

      return 0;

    }

    for(int j=0;j<S[i];j++){

      int t = Q.top();

      Q.pop();

      for(t>>=1;t;t>>=1){

        buf.push_back(t);

      }

    }

    for(int x: buf) Q.push(x);

    buf.clear();

  }

  puts("Yes");

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 8.126478391372748x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(n=l+1;b;n++){

      b -= Q[n];

      Q[n] = b;

    }

    n--;

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <functional>



int n;

int S[1<<18];

int Q[19];





int main(){

  scanf("%d",&n);

  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      puts("No");

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += Q[l]-a+S[i];

    Q[l++] = a-S[i];

    for(; l<n; l++){

      for(int t=0;t<l;t++) Q[t] += Q[l];

      Q[l] = 0;

    }

  }

  puts("Yes");

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.6575924094312717x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(n=l+1;b;n++){

      b -= Q[n];

      Q[n] = b;

    }

    n--;

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <functional>



int n;

int S[1<<18];

int Q[19];





int main(){

  scanf("%d",&n);

  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

//for(int t=0;t<=n;t++) printf("%d ", Q[t]);

//puts("");

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      puts("No");

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(int t=l+1;t<=n;t++){

      b -= Q[t];

      Q[t] = b;

    }

  }

  puts("Yes");

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.6553099375878935x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(n=l+1;b;n++){

      b -= Q[n];

      Q[n] = b;

    }

    n--;

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <functional>



int n;

int S[1<<18];

int Q[19];





int main(){

  scanf("%d",&n);

  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      puts("No");

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(int t=l+1;b;t++){

      b -= Q[t];

      Q[t] = b;

    }

  }

  puts("Yes");

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.6543625890593516x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(n=l+1;b;n++){

      b -= Q[n];

      Q[n] = b;

    }

    n--;

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <functional>



int n;

int S[1<<18];

int Q[19];





int main(){

  scanf("%d",&n);

  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      puts("No");

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(n=l+1;b;n++){

      b -= Q[n];

      Q[n] = b;

    }

    n--;

  }

  puts("Yes");

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.6549049829060039x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(n=l+1;b;n++){

      b -= Q[n];

      Q[n] = b;

    }

    n--;

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <functional>

#include <set>



int n;

int S[1<<18];



int main(){

  std::multiset<int, std::greater<int> > S, T;

  scanf("%d",&n);

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

    int x;

    scanf("%d",&x);

    S.insert(x);

  }

  T.insert(*(S.begin()));

  S.erase(S.begin());



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

    int tmp[1<<18];

    int t=0;

    auto itr = S.begin();

    for(int x: T){

      while(itr != S.end() && *itr == x) ++itr;

      if(itr == S.end()){

        puts("No");

        return 0;

      }

      tmp[t++] = *itr;

      itr = S.erase(itr);

    }

    if(i != n-1) T.insert(tmp, tmp+t);

  }



  puts("Yes");





  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 8.319746352407522x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--){

      int x = Q[l];

      Q[l] = a;

      a += x;

    }

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    Q[l] += a-S[i];

    for(int t=0;t<l;t++) Q[t] += S[i];

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <queue>

#include <algorithm>



int n;

int S[1<<18];

std::priority_queue<int> Q;

std::vector<int> buf;



int main(){

  scanf("%d",&n);

  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q.push((1<<(n+1))-1);

  for(int i=0;i<k;i++){

    if(Q.size() < S[i]){

      puts("No");

      return 0;

    }

    for(int j=0;j<S[i];j++){

      int t = Q.top();

      Q.pop();

      for(t>>=1;t;t>>=1){

        buf.push_back(t);

      }

    }

    for(int x: buf) Q.push(x);

    buf.clear();

  }

  puts("Yes");

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 8.109958043807849x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--){

      int x = Q[l];

      Q[l] = a;

      a += x;

    }

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    Q[l] += a-S[i];

    for(int t=0;t<l;t++) Q[t] += S[i];

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <functional>



int n;

int S[1<<18];

int Q[19];





int main(){

  scanf("%d",&n);

  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      puts("No");

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += Q[l]-a+S[i];

    Q[l++] = a-S[i];

    for(; l<n; l++){

      for(int t=0;t<l;t++) Q[t] += Q[l];

      Q[l] = 0;

    }

  }

  puts("Yes");

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.6542226837757144x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--){

      int x = Q[l];

      Q[l] = a;

      a += x;

    }

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    Q[l] += a-S[i];

    for(int t=0;t<l;t++) Q[t] += S[i];

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <functional>



int n;

int S[1<<18];

int Q[19];





int main(){

  scanf("%d",&n);

  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

//for(int t=0;t<=n;t++) printf("%d ", Q[t]);

//puts("");

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      puts("No");

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(int t=l+1;t<=n;t++){

      b -= Q[t];

      Q[t] = b;

    }

  }

  puts("Yes");

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.6519448519776723x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--){

      int x = Q[l];

      Q[l] = a;

      a += x;

    }

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    Q[l] += a-S[i];

    for(int t=0;t<l;t++) Q[t] += S[i];

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <functional>



int n;

int S[1<<18];

int Q[19];





int main(){

  scanf("%d",&n);

  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      puts("No");

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(int t=l+1;b;t++){

      b -= Q[t];

      Q[t] = b;

    }

  }

  puts("Yes");

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.6509994293174097x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--){

      int x = Q[l];

      Q[l] = a;

      a += x;

    }

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    Q[l] += a-S[i];

    for(int t=0;t<l;t++) Q[t] += S[i];

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <functional>



int n;

int S[1<<18];

int Q[19];





int main(){

  scanf("%d",&n);

  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--) a += Q[l];

    if(a<S[i]){

      puts("No");

      return 0;

    }

    l++;

    for(int t=0;t<l;t++) Q[t] += S[i];

    int b = a-Q[l];

    Q[l] = a-S[i]+b;

    for(n=l+1;b;n++){

      b -= Q[n];

      Q[n] = b;

    }

    n--;

  }

  puts("Yes");

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.6515407205296326x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--){

      int x = Q[l];

      Q[l] = a;

      a += x;

    }

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    Q[l] += a-S[i];

    for(int t=0;t<l;t++) Q[t] += S[i];

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <algorithm>

#include <functional>

#include <set>



int n;

int S[1<<18];



int main(){

  std::multiset<int, std::greater<int> > S, T;

  scanf("%d",&n);

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

    int x;

    scanf("%d",&x);

    S.insert(x);

  }

  T.insert(*(S.begin()));

  S.erase(S.begin());



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

    int tmp[1<<18];

    int t=0;

    auto itr = S.begin();

    for(int x: T){

      while(itr != S.end() && *itr == x) ++itr;

      if(itr == S.end()){

        puts("No");

        return 0;

      }

      tmp[t++] = *itr;

      itr = S.erase(itr);

    }

    if(i != n-1) T.insert(tmp, tmp+t);

  }



  puts("Yes");





  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 8.328946723160517x):
#include <unistd.h>

#include <algorithm>

#include <functional>



char ibuf[4000000];

char *ibufe = ibuf-1;



void readall(){

  int k, t = 0;

  while((k=read(STDIN_FILENO, ibuf+t, sizeof(ibuf)-t))>0) t += k;

}



int read_uint(){

  int x=0;

  while(*(++ibufe) <'0');

  do {

    x *= 10;

    x += *ibufe-'0';

  } while(*(++ibufe) >='0');



  return x;

}



int n;

int S[1<<18];

int Q[19];



int main(){

  readall();

  n = read_uint();

  for(int i=0;i<(1<<n);i++) S[i] = read_uint();

  std::sort(S, S+(1<<n), std::greater<int>());

  int k = 0;

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

    int j = i;

    for(i++; S[i] == S[j]; i++) ;

    S[k++] = i-j;

  }

  Q[n] = 1;

  for(int i=0;i<k;i++){

    int l;

    int a=0;

    for(l=n;l>=0 && a < S[i];l--){

      int x = Q[l];

      Q[l] = a;

      a += x;

    }

    if(a<S[i]){

      write(STDOUT_FILENO, "No\n", 3);

      return 0;

    }

    l++;

    Q[l] += a-S[i];

    for(int t=0;t<l;t++) Q[t] += S[i];

    n -= !Q[n];

  }

  write(STDOUT_FILENO, "Yes\n", 4);

  return 0;

}