Problem:
 Score : 600 points    Problem Statement We have one slime.  You can set the health of this slime to any integer value of your choice.  A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second.  Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S .  Here S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N} .      Constraints  All values in input are integers.  1 \leq N \leq 18  1 \leq S_i \leq 10^9         Input Input is given from Standard Input in the following format:  N  S_1  S_2  ...  S_{2^N}       Output If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S , print Yes ; otherwise, print No .        Sample Input 1 2
4 2 3 1      Sample Output 1 Yes  We will show one way to make the multiset of the healths of the slimes that will exist in 2 seconds equal to S .  First, set the health of the first slime to 4 .  By letting the first slime spawn a slime whose health is 3 , the healths of the slimes that exist in 1 second can be 4,~3 .  Then, by letting the first slime spawn a slime whose health is 2 , and letting the second slime spawn a slime whose health is 1 , the healths of the slimes that exist in 2 seconds can be 4,~3,~2,~1 , which is equal to S as multisets.       Sample Input 2 2
1 2 3 1      Sample Output 2 Yes  S may contain multiple instances of the same integer.       Sample Input 3 1
1 1      Sample Output 3 No       Sample Input 4 5
4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3      Sample Output 4 No

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from math import gcd
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7

n=I()
F=sorted(LI(),reverse=True)
flg=[0]*len(F)
flg[0]=1
a=1
flg[0]=1
now=[F[0]]
for i in range(n):
    cnt=0
    for j in range(len(F)):
        if flg[j]==0 and F[j]<now[cnt]:
            cnt+=1
            flg[j]=1
            now+=[F[j]]
        if cnt==a:
            now.sort(reverse=True)
            a*=2
            break
    else:
        print("No")
        exit()

print("Yes")

Solution (Python):
from heapq import heappop,heappush,heapify
def main(n,s):
  from collections import Counter
  cs=Counter(s)
  key=sorted(cs)
  
  
  
  
  
  
  
  
  
  
  if cs[key[-1]]!=1:return 'No'
  if len(key)<n+1:return 'No'
  now=1
  tt=[-n]
  ntt=[]
  for x in key[::-1]:
      
      if now<cs[x]:return 'No'
      now-=cs[x]
      for _ in range(cs[x]):
          if not tt:break
          tmp=heappop(tt)
          tmp*=-1
          now+=tmp
          for i in range(1,tmp):
            ntt.append(-i)
      while ntt:
        heappush(tt,ntt.pop())
  return 'Yes'

n=int(input())
s=list(map(int,input().split()))
print(main(n,s))
s.sort()

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
S = sorted(map(int, input().split()), reverse=True)
L = [S[0]]
used = [False]*(1<<n)
used[0] = True
for i in range(n):
  L.sort(reverse=True)
  idx = 0
  for j, s in enumerate(S):
    if used[j]:
      continue
    if L[idx] > s:
      L.append(s)
      used[j] = True
      idx += 1
      if idx == 1<<i:
        break
  else:
    print("No")
    exit()
print("Yes")

Solution (Python):
import heapq
import copy

N = int(input())
rest = list(map(lambda x: -1*int(x), input().split()))
heapq.heapify(rest)
generated = [heapq.heappop(rest)]
flg = True
for i in range(N):
    tmp_generated = copy.copy(generated)
    tmp = []
    while len(tmp_generated) > 0:
        v = heapq.heappop(tmp_generated)
        found = False
        while len(rest)>0:
            t = heapq.heappop(rest)
            if v < t:
                heapq.heappush(generated, t)
                found = True
                break
            tmp.append(t)
        if not found:
            flg = False
            break
    for t in tmp:
        heapq.heappush(rest, t)
    if not flg:
        break
print('Yes' if flg else 'No')

Solution (Python):
from bisect import bisect_left

class SegTree():
    def segfunc(self, x, y):
        return x+y

    def __init__(self, ide, init_val):
        n = len(init_val)
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
    def update(self, idx, val):
        idx += self.num-1
        self.seg[idx] = val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segfunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def query(self, begin, end):
        if end <= begin:
            return self.ide_ele
        begin += self.num-1
        end += self.num-2
        res = self.ide_ele
        while begin + 1 < end:
            if begin&1 == 0:
                res = self.segfunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segfunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
        if begin == end:
            res = self.segfunc(res, self.seg[begin])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[begin]), self.seg[end])
        return res

def main():
    lim = int(input())
    s = list(map(int, input().split()))
    n = len(s)
    s.sort()
    f = True
    tmp = [1]*n
    tmp[n-1] = 0
    seg = SegTree(0, tmp)
    st = set()
    st.add(n-1)
    for _ in range(1, lim+1):
        adst = set()
        for v in st:
            u = bisect_left(s, s[v])
            if seg.query(0, u) == 0:
                f = False
                break
            L, R = 0, u
            while L+1 < R:
                P = (L+R)//2
                if seg.query(P, u) > 0:
                    L = P
                else:
                    R = P
            seg.update(L, 0)
            adst.add(L)
        for v in adst:
            st.add(v)
    if f:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Solution (Python):
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    class Bit():
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)
            return

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x=1):
            
            while i <= self.size:
                self.tree[i] += x
                i += i & -i
            return

        def search(self, x):
            
            
            i = 0
            s = 0
            step = 1 << ((self.size).bit_length() - 1)
            while step:
                if i + step <= self.size and s + self.tree[i + step] < x:
                    i += step
                    s += self.tree[i]
                step >>= 1
            return i + 1

        def debug(self, k):
            return [self.sum(i) for i in range(k)]

    N = I()
    P = LI()
    Order = [[i+1] for i in range(N)]
    for i,p in enumerate(P):
        Order[i].append(p)
    Order.sort(key=lambda x:x[1],reverse=True)
    
    ans = 0
    bit = Bit(N+2)

    for i,p in Order:
        L = bit.sum(i)
        R = bit.sum(N)-L
        bit.add(i)
        l0, l1, r0, r1 = 0, 0, N+1, N+1
        if L>=2:
            l0 = bit.search(L-1)
        if L>=1:
            l1 = bit.search(L)
        if R>=1:
            r0 = bit.search(L+2)
        if R>=2:
            r1 = bit.search(L+3)
        
        
        
        cnt = 0
        if l1>0:
            cnt += (l1-l0)*(r0-i)
        if r0>0:
            cnt += (i-l1)*(r1-r0)
        ans += cnt * p
        
    print(ans)
    return

def examF():
    def bfs(N, S):
        used = [False] * (1<<N)
        used[0] = True
        for n in range(N):
            cur = deque()
            rem = 1<<n
            for i in range(1<<N):
                s = S[i]
                if used[i]:
                    cur.append(s)
                elif cur and cur[0] > s:
                    cur.popleft()
                    used[i] = True
                    rem -= 1
                    if rem == 0:
                        break
            if rem > 0:
                
                return 'No'
        return 'Yes'
    N = I()
    S = LI()
    S.sort(reverse=True)
    
    ans = bfs(N,S)
    print(ans)
    return


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examF()

"""
5
4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 6 3 4 2 5 2 3

"""

Solution (Python):
class MultisetBIT:
    """
    最大値が小さい数について、その重複を許した集合を管理する。
    最大値 maxvalue を受け取り、[0, maxvalue] を管理する。
    counter は辞書型かリスト型で、counter[i] が i の個数を持つことを仮定する。
    counter が与えられなかった場合は、全て個数 0 で初期化される。
    基本的に閉区間で管理する。
    内部では受け取った数を +1 したものをindexとして持っているので注意。
    """

    __slots__ = ["n", "k", "data"]

    def __init__(self, maxvalue, counter = None):
        self.n = maxvalue + 1
        self.k = 1 << ((self.n + 1).bit_length() - 1)
        self.data = [0] * (self.n + 1)
        if counter is not None:
            self.update(counter)
        
    def update(self, counter):
        """
        counter を受け取って、それを反映させる。
        counter は辞書型かリスト型で、counter[i] が i の個数を持つことを仮定する。(0 <= i <= maxvalue)
        計算量は、n を要素の最大値として、 O(n) となる。
        """
        if isinstance(counter, list):
            self.data = [0] + counter + [0] * (self.n - len(counter))
        else:
            self.data = [0] * (self.n + 1)
            for k, v in counter.items():
                self.data[k + 1] = v
        for i in range(1, self.n + 1):
            if i + (i & -i) <= self.n:
                self.data[i + (i & -i)] += self.data[i]

    def add(self, value):
        """
        与えられた引数 value (0 <= value <= maxvalue) を Multiset に加える。
        計算量は、n を要素の最大値として、 O(log n) となる。
        """
        value += 1
        while value <= self.n:
            self.data[value] += 1
            value += value & -value

    def pop(self, value):
        """
        Multiset から与えられた引数 value (0 <= value <= maxvalue) を取り除く。
        与えられた引数が Multiset に入っているかのチェックは行わなず、
        単にその個数を 1 減らすだけなので注意。
        計算量は、n を要素の最大値として、 O(log n) となる。
        """
        value += 1
        while value <= self.n:
            self.data[value] -= 1
            value += value & -value

    def count_le(self, value):
        """
        Multiset 内の要素 elem のうち、0 <= elem <= value を満たすものを数える。
        計算量は、n を要素の最大値として、 O(log n) となる。
        value は value <= maxvalue を満たす必要がある。
        """
        value += 1
        ret = 0
        while value > 0:
            ret += self.data[value]
            value -= value & -value
        return ret

    def count(self, first, last):
        """
        Multiset 内の要素 elem のうち、first <= elem <= last を満たすものを数える。
        計算量は、n を要素の最大値として、 O(log n) となる。
        0 <= first <= last <= max_value が必要。
        """
        last += 1
        ret = 0
        while first < last:
            ret += self.data[last]
            last -= last & -last
        while last < first:
            ret -= self.data[first]
            first -= first & -first
        return ret

    def __getitem__(self, index):
        if isinstance(index, slice):
            return self.count(index.start, index.stop - 1)
        else:
            return self.count(index, index)

    def bisect(self, count):
        """
        Multiset 内の要素 elem のうち、count <= count_le(elem) を満たす最小のelemを返す。
        計算量は、n を要素の最大値として、 O(log n) となる。
        """
        ret = 0
        k = self.k
        while k > 0:
            if ret + k <= self.n and self.data[ret + k] < count:
                count -= self.data[ret + k]
                ret += k
            k //= 2
        return ret

    def lower_bound(self, value):
        """
        Multiset 内の要素 elem のうち、value <= elem を満たす最小のelemを返す。
        そのような elem が存在しない場合は maxvalue + 1 を返す。
        計算量は、n を要素の最大値として、 O(log n) となる。
        """
        return self.bisect(self.count_le(value - 1) + 1)

    def upper_bound(self, value):
        """
        Multiset 内の要素 elem のうち、value < elem を満たす最小のelemを返す。
        そのような elem が存在しない場合は maxvalue + 1 を返す。
        計算量は、n を要素の最大値として、 O(log n) となる。
        """
        return self.bisect(self.count_le(value) + 1)


N = int(input())
S_list = sorted(map(int, input().split()), reverse=True)
"""
N = 18
cs = [1, 18, 153, 816, 3060, 8568, 18564, 31824, 43758, 48620, 43758, 31824, 18564, 8568, 3060, 816, 153, 18, 1]
S_list = []
for i, c in enumerate(cs):
	S_list += [20 - i] * c


ans_tree = [0] * ((2 ** N) * 2)
ms = MultisetBIT((2 ** N) * 2)
ms.add(1)
prev_S = 0
prev_elem = 0
for S in S_list:
    if prev_S != S:
        prev_elem = 0
    elem = ms.lower_bound(prev_elem)
    while elem != ((2 ** N) * 2 + 1) and ans_tree[elem // 2] == S:
        elem = ms.upper_bound(elem)
    
    if elem == ((2 ** N) * 2 + 1):
        print("No")
        exit()

    prev_S = S
    prev_elem = elem
    ms.pop(elem)
    ans_tree[elem] = S
    elem *= 2
    while elem < 2 ** N * 2:
        ans_tree[elem] = S
        ms.add(elem + 1)
        elem *= 2
    

print("Yes")

Solution (Python):
class BinaryIndexTree:  
    def __init__(self, N):
        """
        INPUT
        N [int] -> 全部0で初期化
        N [list] -> そのまま初期化
        """
        if isinstance(N, int):
            self.N = N
            self.depth = N.bit_length()
            self.tree = [0] * (N + 1)
            self.elem = [0] * (N + 1)
        elif isinstance(N, list):
            self.N = len(N)
            self.depth = self.N.bit_length()
            self.tree = [0] + N
            self.elem = [0] + N
            self._init()
        else:
            raise "INVALID INPUT: input must be int or list"

    def _init(self):
        size = self.N
        for i in range(1, self.N):
            if i + (i & -i) > size:
                continue
            self.tree[i + (i & -i)] += self.tree[i]

    def add(self, i, x):
        self.elem[i] += x
        while i <= self.N:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def lower_bound(self, val):
        if val <= 0:
            return 0
        i = 0
        k = 1 << self.depth
        while k:
            if i + k <= self.N and self.tree[i + k] < val:
                val -= self.tree[i + k]
                i += k
            k >>= 1
        return i + 1


N = int(input())
A = list(map(int, input().split()))
atoi = {a: i+1 for i, a in enumerate(sorted(set(A)))}

bit = BinaryIndexTree(len(atoi) + 5)

for a in A:
    i = atoi[a]
    bit.add(i, 1)


slime = []

p = bit.lower_bound(1 << N)
slime.append(p)
bit.add(p, -1)

for _ in range(N):
    next_slime = []
    for s in slime:
        tot = bit.sum(s - 1)
        p = bit.lower_bound(tot)
        if p == 0:
            print("No")
            exit()
        next_slime.append(p)
        bit.add(p, -1)
    slime += next_slime
print("Yes")

Solution (Python):
class BinaryIndexTree:  
    def __init__(self, N):
        """
        INPUT
        N [int] -> 全部0で初期化
        N [list] -> そのまま初期化
        """
        if isinstance(N, int):
            self.N = N
            self.depth = N.bit_length()
            self.tree = [0] * (N + 1)
            self.elem = [0] * (N + 1)
        elif isinstance(N, list):
            self.N = len(N)
            self.depth = self.N.bit_length()
            self.tree = [0] + N
            self.elem = [0] + N
            self._init()
        else:
            raise "INVALID INPUT: input must be int or list"

    def _init(self):
        size = self.N
        for i in range(1, self.N):
            if i + (i & -i) > size:
                continue
            self.tree[i + (i & -i)] += self.tree[i]

    def add(self, i, x):
        self.elem[i] += x
        while i <= self.N:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def lower_bound(self, val):
        if val <= 0:
            return 0
        i = 0
        k = 1 << self.depth
        while k:
            if i + k <= self.N and self.tree[i + k] < val:
                val -= self.tree[i + k]
                i += k
            k >>= 1
        return i + 1


N = int(input())
A = list(map(int, input().split()))
atoi = {a: i+1 for i, a in enumerate(sorted(set(A)))}

bit = BinaryIndexTree(len(atoi) + 5)

for a in A:
    i = atoi[a]
    bit.add(i, 1)


slime = []

p = bit.lower_bound(1 << N)
slime.append(p)
bit.add(p, -1)

for _ in range(N):
    next_slime = []
    for s in slime:
        tot = bit.sum(s - 1)
        p = bit.lower_bound(tot)
        if p == 0:
            print("No")
            exit()
        next_slime.extend([s, p])
        bit.add(p, -1)
    slime = next_slime
print("Yes")

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    """
    グラフ，2^i区切りで見ていって，親を決める．
    BFSで上から大きい数字を振っていく=>ダメっぽい
    なんかもっと単純に，今いるやつと，残りを持っておくか=>ただ順に見ていくだけだと後回しができないので，
    作れる中で最大も数字を作る
    """

    
    from bisect import bisect_left, bisect_right, insort_right
    class SquareSkipList:
        
        

        def __init__(self, values=None, sorted_=False, square=1000, seed=42):
            
            
            
            
            

            self.cnt=0
            inf = float("inf")
            self.square = square
            if values is None:
                self.rand_y = seed
                self.layer1 = [inf]
                self.layer0 = [[]]
            else:
                self.layer1 = layer1 = []
                self.layer0 = layer0 = []
                if not sorted_:
                    values.sort()
                y = seed
                l0 = []
                for v in values:
                    y ^= (y & 0x7ffff) << 13
                    y ^= y >> 17
                    y ^= (y & 0x7ffffff) << 5
                    if y % square == 0:
                        layer0.append(l0)
                        l0 = []
                        layer1.append(v)
                    else:
                        l0.append(v)
                layer1.append(inf)
                layer0.append(l0)
                self.rand_y = y

        def add(self, x):  
            
            y = self.rand_y
            y ^= (y & 0x7ffff) << 13
            y ^= y >> 17
            y ^= (y & 0x7ffffff) << 5
            self.rand_y = y

            if y % self.square == 0:
                layer1, layer0 = self.layer1, self.layer0
                idx1 = bisect_right(layer1, x)
                layer1.insert(idx1, x)
                layer0_idx1 = layer0[idx1]
                idx0 = bisect_right(layer0_idx1, x)
                layer0.insert(idx1+1, layer0_idx1[idx0:])  
                del layer0_idx1[idx0:]
            else:
                idx1 = bisect_right(self.layer1, x)
                insort_right(self.layer0[idx1], x)

            self.cnt+=1

        def remove(self, x):  
            
            idx1 = bisect_left(self.layer1, x)
            layer0_idx1 = self.layer0[idx1]
            idx0 = bisect_left(layer0_idx1, x)
            if idx0 == len(layer0_idx1):
                del self.layer1[idx1]
                self.layer0[idx1] += self.layer0.pop(idx1+1)
            else:
                del layer0_idx1[idx0]

            self.cnt-=1

        def search_higher_equal(self, x):  
            idx1 = bisect_left(self.layer1, x)
            layer0_idx1 = self.layer0[idx1]
            idx0 = bisect_left(layer0_idx1, x)
            if idx0 == len(layer0_idx1):
                return self.layer1[idx1]
            return layer0_idx1[idx0]

        def search_higher(self, x):  
            idx1 = bisect_right(self.layer1, x)
            layer0_idx1 = self.layer0[idx1]
            idx0 = bisect_right(layer0_idx1, x)
            if idx0 == len(layer0_idx1):
                return self.layer1[idx1]
            return layer0_idx1[idx0]

        def search_lower(self, x):  
            
            idx1 = bisect_left(self.layer1, x)
            layer0_idx1 = self.layer0[idx1]
            idx0 = bisect_left(layer0_idx1, x)
            if idx0 == 0:  
                return self.layer1[idx1-1]
            return layer0_idx1[idx0-1]

        def pop(self, idx):
            
            
            
            self.cnt-=1
            layer0 = self.layer0
            s = -1
            for i, l0 in enumerate(layer0):
                s += len(l0) + 1
                if s >= idx:
                    break
            if s==idx:
                layer0[i] += layer0.pop(i+1)
                return self.layer1.pop(i)
            else:
                return layer0[i].pop(idx-s)


        def all(self):
            print(self.layer1)
            print(self.layer0)

        def len(self):
            return self.cnt

    

    ssl=SquareSkipList(square=2000)
    
    mod=10**9+7
    N2=I()
    N=pow(2,N2)
    S=LI()
    S.sort(reverse=True)
    L=[S[0]]
    
    for i in range(1,N):
        ssl.add(S[i])
        
    ssl.add(-1) 
    
    flag=1
    while True:
        temp=[]
        for val in L:
            nxt=ssl.search_lower(val)
            if nxt==-1:
                flag=0
                break
            ssl.remove(nxt)
            temp.append(nxt)

        if flag==0:
            break    
        L+=temp
        L.sort(reverse=True)
        if len(L)==N:
            break
    
    if flag:
        print("Yes")
    else:
        print("No")

main()

Solution (Python):

import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
S=list(map(int,input().split()))
S.sort()
sl=[S.pop()]
for _ in range(N):
    stack=[]
    for i in range(len(sl)):
        x=sl[i]
        while S:
            y=S.pop()
            if y<x:
                sl.append(y)
                break
            else:
                stack.append(y)
        else:
            print('No')
            exit()
    S.extend(stack[::-1])
    sl.sort(reverse=1)
print('Yes')

Solution (Python):
import math

import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    s = [int(i) for i in ipt().split()]
    s.sort(reverse=True)
    al = [False]*(2**n)
    al[0] = True
    for i in range(n):
        usd = deque()
        cnt = 2**i
        for j,sj in enumerate(s):
            if al[j]:
                usd.append(sj)
            elif usd[0] > sj:
                usd.popleft()
                al[j] = True
                cnt -= 1
                if not cnt:
                    break
        if cnt != 0:
            print("No")
            exit()
    print("Yes")



if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
import sys
input = sys.stdin.readline

N = int(input())
S = list(map(int, input().split()))
S.sort(reverse=True)
used = [False] * (2**N)
used[0] = True
for r in range(N):
    cur = deque()
    rem = 2**r
    for i in range(2**N):
        if used[i]:
            cur.append(S[i])
        elif cur and cur[0] > S[i]:
            cur.popleft()
            used[i] = True
            rem -= 1
            if rem == 0:
                break
    if rem > 0:
        print('No')
        exit()
print('Yes')

Solution (Python):
from collections import deque

def solve():
    N = int(input())
    Ss = list(map(int, input().split()))

    Ss.sort(reverse=True)

    Qs = [deque() for _ in range(N+1)]
    Qs[0].append(10**10)

    for S in Ss:
        for day in range(N+1):
            if not Qs[day]: continue
            if Qs[day][0] > S:
                Qs[day].popleft()
                for d in range(day+1, N+1):
                    Qs[d].append(S)
                break
        else:
            return False

    return True


if solve():
    print('Yes')
else:
    print('No')

Solution (Python):
from collections import deque

def solve():
    N = int(input())
    Ss = list(map(int, input().split()))

    Ss.sort(reverse=True)

    Qs = [deque() for _ in range(N+1)]
    Qs[0].append(10**10)

    for S in Ss:
        for day in range(N+1):
            if not Qs[day]: continue
            if Qs[day][0] > S:
                Qs[day].popleft()
                for d in range(day+1, N+1):
                    Qs[d].append(S)
                break
        else:
            return False

    return True


if solve():
    print('Yes')
else:
    print('No')

Solution (Python):
from collections import Counter

def solve():
    n = int(input())
    c = list(map(lambda p: p[1], sorted(Counter(int(si) for si in input().split()).items())))
    if c[-1] != 1:
        print('No')
        return
    c.pop()
    dp = [0] * (n + 1)
    dp[0] = 1
    for cnt in reversed(c):
        dp_next = [0] * (n + 1)
        for j in range(n):
            consume = dp[j] if dp[j] < cnt else cnt
            cnt -= consume
            dp_next[j] += dp[j] - consume
            dp_next[j + 1] += consume
            dp[j + 1] += consume
        if cnt != 0:
            print('No')
            return
        dp = dp_next
    print('Yes')
    return

if __name__ == '__main__':
    solve()

Solution (Python):
import heapq

N=int(input())
S=list(map(int,input().split()))
S=[-S[i] for i in range(len(S))]
heapq.heapify(S)
que=[]
next=[]
rest=[]
x=heapq.heappop(S)
heapq.heappush(que,x)
while S:
    while que:
        x=heapq.heappop(que)
        while S:
            y=heapq.heappop(S)
            if y>x:
                heapq.heappush(next,x)
                heapq.heappush(next,y)
                break
            else:
                heapq.heappush(rest,y)
        else:
            print("No")
            exit()
    que=next
    next=[]
    while rest:
        x=heapq.heappop(rest)
        heapq.heappush(S,x)


print("Yes")

Solution (Python):
from collections import Counter
n = int(input())
a = sorted(Counter(list(map(int, input().split()))).items(), reverse=True)
g = [0]*(n+1)
g[n] = 1
for _, x in a:
  if sum(g) < x:
    print('No')
    break
  t = [0]*(n+1)
  for i in range(n, -1, -1):
    if g[i] <= x:
      t[i-1] = t[i] + g[i]
      x -= g[i]
      g[i] = 0
    else:
      t[i-1] = t[i] + x
      g[i] -= x
      x = 0
  t[n] = 0
  g = [x+y for x,y in zip(g, t)]
else:
  print('Yes')