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



Sample input:
2
4 2 3 1


Sample output:
Yes

Submission status: Accepted

Solution code:

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
S = list(map(int, input().split()))

S.sort(reverse=True)

max_S = S[0]
S2 = [S[0]]
for bit in range(N):
	i = 0
	loc = 0
	S2.sort(reverse=True)
	while i < 2**bit:
		if loc >= 2**N:
			print("No")
			exit()
		if S2[i] > S[loc]:
			S2.append(S[loc])
			S[loc] = max_S #検索対象から除外
			i += 1
		loc += 1
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
S = sorted([int(a) for a in input().split()])
X = [1] + [0] * N

def popX(i0):
    for i in range(i0, N+1):
        if X[i]:
            X[i] -= 1
            return i
    return N+1
def addX():
    for l in L:
        for i in range(l+1, N+1):
            X[i] += 1

while S:
    a = S.pop()
    L = [popX(0)]
    while S and S[-1] == a:
        S.pop()
        L.append(popX(L[-1]))
    if L[-1] > N:
        print("No")
        break
    addX()
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
S = sorted([int(a) for a in input().split()])
X = [1] + [0] * N

def popX(i0):
    for i in range(i0, N+1):
        if X[i]:
            X[i] -= 1
            return i
    return N+1
def addX():
    for l in L:
        for i in range(l+1, N+1):
            X[i] += 1

while S:
    a = S.pop()
    c = 1
    L = [popX(0)]
    while S and S[-1] == a:
        S.pop()
        c += 1
        L.append(popX(L[-1]))
    if L[-1] > N:
        print("No")
        break
    addX()
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])


def main():
    N = I()
    S = sorted(LI(),reverse=True)

    flag = [True]*len(S)

    cur = []
    cur.append(S[0])
    flag[0] = False

    for i in range(N):
        nxt = [x for x in cur]
        j = 0

        for k in range(len(S)):
            if j >= len(cur):
                break
            elif flag[k] and S[k]<cur[j]:
                nxt.append(S[k])
                j+=1
                flag[k] = False
        if len(cur) != j:
            return("No")
        cur = sorted(nxt,reverse=True)
    return("Yes")

if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int, input().split()))
S.sort(reverse = True)
ans = 'Yes'
used = set([0])
L = [S[0]]
for k in range(1, N+1):
    cnt = 0
    for i in range(2**N):
        if i in used:
            continue
        if L[cnt] > S[i]:
            used.add(i)
            cnt += 1
            L.append(S[i])
        if cnt == (2**(k-1)):
            break
    else:
        ans = 'No'
        break
    L.sort(reverse = True)
    continue
print(ans)

Submission status: Accepted

Solution code:

N = int(input())
a = list(map(int,input().split(' ')))
a.sort()
 
 
fathers = [a.pop()]
for _ in range(N):
    sons = list()
    b = list()

    for father in fathers:
        while a:
            x = a.pop()
            if father > x:
                sons.append(x)
                break
            else:
                b.append(x)
                
    a = a + b[::-1]
    fathers.extend(sons)
    fathers.sort(reverse = True)
    


if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort()
p=S[-1:]
r=S[:-1]
for i in range(N):
    nr=[]
    for p_ in p[::-1]:
        while r:
            r_=r.pop()
            if r_<p_:
                p.append(r_)
                break
            nr.append(r_)
    p.sort()
    r+=nr[::-1]
print("Yes" if len(r)==0 else "No")

Submission status: Accepted

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort()
p=[S[-1]]
r=S[:-1]

for i in range(N):
    nr = []
    for p_ in p[::-1]:
        while r:
            nr.append(r.pop())
            if nr[-1]<p_:
                p.append(nr.pop(-1))
                break
    p.sort()
    r+=nr[::-1]

print("Yes" if len(r)==0 else "No")

Submission status: Accepted

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort()
p = [S.pop(-1)]
r = S

for i in range(N):
    nr = []
    for p_ in p[::-1]:
        while r:
            r_ = r.pop()
            if r_ < p_:
                p.append(r_)
                break
            nr.append(r_)
    p.sort()
    r+=nr[::-1]

print("Yes" if len(r)==0 else "No")

Submission status: Accepted

Solution code:
N = int(input())
A = sorted((int(x) for x in input().split()))
 
parent = [A[-1]]
rest = A[:-1]
bl = True
for _ in range(N):
    next_parent = []
    next_rest = []
    for p in parent[::-1]:
        while rest:
            x = rest.pop()
            if x < p:
                next_parent.append(x)
                break
            else:
                next_rest.append(x)
                continue
    parent += next_parent
    parent.sort()
    rest = rest + next_rest[::-1]
 
bl = len(parent) == (2**N)
answer = 'Yes' if bl else 'No'
print(answer)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() 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)]
mod = 1000000007



def main():
    n =  I()
    final_slime = sorted(LI(), reverse=True)
    now_slime = [final_slime[0]]
    made_or_not = [0] * (2 ** n)
    made_or_not[0] = 1
    for i in range(n):
        k = 0
        for j in range(len(now_slime)):
            flag = 1
            while flag:
                if k == 2 ** n:
                    return 'No'
                if made_or_not[k] == 0 and now_slime[j] - 1 >= final_slime[k]:
                    now_slime += [final_slime[k]]
                    made_or_not[k] = 1
                    flag = 0
                k += 1
        now_slime.sort(reverse=True)
    return 'Yes'



print(main())

Submission status: Accepted

Solution code:
import sys

def main():
	input = sys.stdin.readline

	N = int(input().strip())
	S = list(map(int,input().strip().split()))

	S.sort(reverse=True)
	parent = S[0]

	numlist = []
	for i in range(N):
		numlist.append(2**i)

	count = [0 for i in range(N)]
	countcom = [1 for i in range(N)]

	slime = []
	for i in range(N):
		temp = [0 for i in range(2**i)]
		slime.append(temp)
		slime[i][0] = parent

	ans = 'Yes'
	for i in range(1,2**N):
		flag = False
		for level in range(N):
			if count[level]<numlist[level]:
				if slime[level][count[level]]>S[i]:
					flag = True
					count[level] = count[level]+1
					levelt = level+1
					while levelt<=N-1:
						slime[levelt][countcom[levelt]] = S[i]
						countcom[levelt] = countcom[levelt]+1
						levelt = levelt+1
					break

		if flag==False:
			ans = 'No'
			break

	print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
from heapq import heappop, heappush


def solve(n, sss):
    ccc = Counter(sss)
    keys = sorted(ccc.keys(), reverse=True)
    if ccc[keys[0]] != 1:
        return False

    q = [(1, keys[0])]
    for k in keys[1:]:
        nq = []
        for _ in range(ccc[k]):
            try:
                r, s = heappop(q)
            except IndexError:
                return False
            if r < n:
                nq.append((r + 1, k))
                heappush(q, (r + 1, s))
        for item in nq:
            heappush(q, item)

    return True


n = int(input())
sss = list(map(int, input().split()))
print('Yes' if solve(n, sss) else 'No')

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int,input().split()))
S.sort(reverse=True)
slime = [S[0]]
S[0] = -1
for i in range(N):
    slime.sort(reverse = True)
    S.sort(reverse=True)
    ai = 0
    for j in range(2**i):
        while S[ai] != -1:
            if slime[j] > S[ai]:
                slime.append(S[ai])
                S[ai] = -1
                ai += 1
                break
            ai += 1
    if len(slime) < 2**(i+1):
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int, input().split()))
S.sort(reverse=True)
Closed = [False] * (1<<N)
Closed[0] = True
for j in range(N):
    num = 1<<j
    cnt_all = 0
    cnt = 0
    cnt_ = 0
    s_old = -1
    for i, s in enumerate(S):
        if s_old!=s:
            cnt += cnt_
            cnt_ = 0
        c = Closed[i]
        if c:
            cnt_ += 1
        elif cnt > 0:
            Closed[i] = True
            cnt -= 1
            cnt_all += 1
            if cnt_all == num:
                break
        s_old = s
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:

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

s.sort()

a = [s[-1]]
b = s[:-1]

for i in range(n):
    a2 = []
    b2 = []
    for x in a:
        while b:
            y = b.pop()
            if x>y:
                a2.append(y)
                break
            else:
                b2.append(y)
    a = a + a2
    b = b + b2
    a.sort()
    a.reverse()
    b.sort()
    if len(a)!=2**(i+1):
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
*S, = map(int, input().split())
C = Counter(S)

memo = [[-1]*(N+1) for i in range(N+1)]
def comb(n, k):
    if memo[n][k] != -1:
        return memo[n][k]
    if k == 0 or n == k:
        return 1
    memo[n][k] = r = comb(n-1, k) + comb(n-1, k-1)
    return r

*CS, = C.items()
CS.sort(reverse=1)
S = [0]
for k, v in CS:
    S.append(S[-1]+v)
T = [0]
for i in range(N+1):
    T.append(T[-1]+comb(N, i))
ok = 1
if len(S) < len(T):
    ok = 0
else:
    ok = all(a <= b for a, b in zip(S, T)) and S[-2] >= 2**(N-1)
print("Yes" if ok else "No")

Submission status: Accepted

Solution code:
import collections, sys

N = int(input())
S = list(map(int, input().split()))
if N ==1 :
  if S[0] == S[1]:
    print("No")
  else:
    print("Yes")
  sys.exit()
  
K = collections.Counter(S)
score_sorted = sorted(K.items(), key=lambda x:x[0], reverse = True)

if score_sorted[0][1] > 1:
  print("No")
  sys.exit()
  

DP = [[0 for i in range(len(K))] for j in range(N+1)]
DP[0][0] = 1
for i in range(N):#日数
  nokoshi = 0
  for k in range(len(K)):
    if k == 0:
      DP[i+1][k] = DP[i][k]
    else:
      hairu = score_sorted[k][1] - DP[i][k]
      ireru = min(hairu, DP[i][k-1] + nokoshi)
      
      DP[i+1][k] = DP[i][k] + ireru
      nokoshi = DP[i][k-1] + nokoshi - ireru
  if nokoshi > 0:
    print("No")
    break
else:
  for i in range(len(score_sorted)):
    if DP[N][i] != score_sorted[i][1]:
      print("No")
      break
  else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
used = [0] * (2 ** n)
used[0] = 1
s.sort(reverse=True)
a = 1
b = [s[0]]
for _ in range(n):
    c = b[:]
    j = 0
    for i in b:
        while j < 2 ** n:
            if used[j] == 0 and s[j] < i:
                c.append(s[j])
                used[j] = 1
                break
            j += 1
        if j >= 2 ** n:
            print("No")
            exit()
    b = sorted(c, reverse=True)

print("Yes")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from collections import deque

N = int(input())
A = sorted((int(x) for x in input().split()))

parent = [A[-1]]
rest = A[:-1]
bl = True
for _ in range(N):
    next_parent = []
    next_rest = []
    for p in parent[::-1]:
        while rest:
            x = rest.pop()
            if x < p:
                next_parent.append(x)
                break
            else:
                next_rest.append(x)
                continue
    parent += next_parent
    parent.sort()
    rest = rest + next_rest[::-1]

bl = len(parent) == (2**N)
answer = 'Yes' if bl else 'No'
print(answer)

Submission status: Accepted

Solution code:
import time

start = time.time()

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

s.sort()
s.reverse()

flag = True
for i in range(n):
    a = s[0:2 ** i]
    b = s[2 ** i:2 ** (i + 1)]
    for j in range(len(a)):
        if b[j] >= a[j]:
            flag = False
            break
if flag:
    print('Yes')
    exit()

s.reverse()

a = []
a.append(s[-1])
s.pop(-1)
for i in range(n):
    for j in range(len(a)):
        for k in range(len(s)):
            if a[j]>s[-1-k]:
                a.append(s[-1-k])
                s.pop(-1-k)
                break
        if time.time() - start > 1.8:
            print('Yes')
            exit()
    if len(a)!=2**(i+1):
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort(reverse=True)

done = [False] * (1<<n)
b = [a[0]]
done[0] = True
for d in range(n):
    j = 0
    for i in range(1<<d):
        while j < 1<<n and (done[j] or b[i] <= a[j]):
            j += 1
        if j == 1<<n:
            print("No")
            sys.exit(0)
        b.append(a[j])
        done[j] = True
    b.sort(reverse=True)
print("Yes")

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n = I()
    a = sorted(LI())
    q = [a[-1]]
    a = a[:-1][::-1]
    for i in range(n):
        # print(i,q,a)
        nq = []
        qi = 0
        na = []
        for ai in range(len(a)):
            c = a[ai]
            if q[qi] > c:
                nq.append(c)
                qi += 1
                if qi == len(q):
                    na += a[ai+1:]
                    break
            else:
                na.append(c)
        if qi < len(q):
            return 'No'
        a = na
        q = sorted(q + nq, reverse=True)

    return 'Yes'


print(main())

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
first = A[-1]
A = A[:-1]
kouho = [first]
while A:
    nagasa = len(kouho)
    for _ in range(nagasa):
        A_mushi = []
        kouho_used = []
        kouho_nxt = []
        while True:
            if A:
                v = A.pop()
                k = kouho.pop()
                if k <= v:
                    A_mushi.append(v)
                else:
                    kouho_nxt.append(v)
                    break
            else:
                print("No")
                exit()
        kouho_used.append(k)

    kouho += kouho_used
    kouho += kouho_nxt
    kouho.sort()
    A += A_mushi[::-1]

print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
N2 = 2**N
S = list(map(int, input().split()))
S.sort(reverse=True)

slimes = [S[0]]
S[0] = float('inf')
num = 1
min_idx = 1
for i in range(N):
  slimes.sort()
  n = num
  idx = min_idx
  is_continuous = True
  while n and idx<=N2-1:
    if S[idx] < slimes[n-1]:
      slimes.append(S[idx])
      S[idx] = float('inf')
      idx += 1
      n -= 1
      min_idx += is_continuous:
    else:
      if S[idx] < float('inf'):
        is_continuous = False
      idx += 1
      min_idx += is_continuous
  
  if n:
    print('No')
    quit()
  
  num *= 2

print('Yes')

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
s.sort(reverse=True)
a = [1]+[0]*n
for i in range(n):
  for j in range(n):
    a[n-j] += a[n-1-j]
t = []
j = 0
for i in range(n+1):
  t.append(s[j:(j+a[i])])
  j += a[i]
ans = 'Yes'
for i in range(n):
  k1 = 0
  for j in range(len(t[i])):
    if k1 >= len(t[i+1]):
      break
    k2 = k1 + n - i - j + 1
    x = t[i][j]
    if x <= max(t[i+1][k1:k2]):
      ans = 'No'
      break
    k1 = k2
  if ans == 'No':
    break
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
s.sort(reverse=True)
a = [1]+[0]*n
for i in range(n):
  for j in range(n):
    a[n-j] += a[n-1-j]
t = []
j = 0
for i in range(n+1):
  t.append(s[j:(j+a[i])])
  j += a[i]
ans = 'Yes'
for i in range(n):
  k1 = 0
  for j in range(len(t[i])):
    if k1 >= len(t[i+1]):
      break
    k2 = k1 + n - i - j + 1
    x = t[i][j]
    if x <= max(t[i+1][k1:k2]):
      ans = 'No'
      break
    k1 = k2 + 1
  if ans == 'No':
    break
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
s.sort(reverse=True)
a = [1]+[0]*n
for i in range(n):
  for j in range(n):
    a[n-j] += a[n-1-j]
t = []
j = 0
for i in range(n+1):
  t.append(s[j:(j+a[i])])
  j += a[i]
ans = 'Yes'
for i in range(n):
  k1 = 0
  for j in range(len(t[i])):
    if k1 >= len(t[i+1]):
      break
    k2 = k1 + n - i - j + 1
    x = t[i][j]
    if x <= min(t[i+1][k1:k2]):
      ans = 'No'
      break
    k1 = k2 + 1
  if ans == 'No':
    break
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
s.sort(reverse=True)
a = [1]+[0]*n
for i in range(n):
  for j in range(n):
    a[n-j] += a[n-1-j]
t = []
j = 0
for i in range(n+1):
  t.append(s[j:(j+a[i])])
  j += a[i]
ans = 'Yes'
for i in range(n):
  k1 = 0
  for j in range(len(t[i])):
    if k1 >= len(t[i+1]):
      break
    k2 = k1 + n - i - j + 1
    x = t[i][j]
    if x <= min(t[i+1][k1:k2]):
      ans = 'No'
      break
    k1 = k2 + 1
  if ans == 'No':
    break
print(ans)
print(t)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(map(int, input().split()))
S.sort(reverse=True)

n = [0] * (2**N)
n[0] = N
_n = N-2
for i in range(1, 2**N):
  nn = n[i-1] - 1
  if nn >= 0:
    n[i] = nn
  else:
    n[i] = _n
    _n -= 1
    if _n < 0:
      if i+1 < 2**N:
        n[i+1] = 1
      break


par = 0
idx = 1
res = True
while idx < 2**N:
  for i in range(n[par]):
    res *= S[par] > S[idx]
    if not res:
      print('No')
      quit()
    idx += 1
  par += 1

print('Yes')

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(map(int, input().split()))
S.sort(reverse=True)

n = [0] * (2**N)
n[0] = N
_n = N-2
for i in range(1, 2**N):
  nn = n[i-1] - 1
  if nn >= 0:
    n[i] = nn
  else:
    n[i] = _n
    _n -= 1
    if _n < 0:
      n[i+1] = 1
      break


par = 0
idx = 1
res = True
while idx < 2**N:
  for i in range(n[par]):
    res *= S[par] > S[idx]
    if not res:
      print('No')
      quit()
    idx += 1
  par += 1

print(n)
print('Yes')

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
a.sort()
ls=[0]
cnt=0
for i in range(1,2**n):
  if a[i]>a[i-1]:
    cnt+=1
  ls.append(cnt)
for i in range(2**n):
  if i<2**n-1:
    lmt=n-int(math.log2(2**n-i-1))-1
    if ls[i]<lmt:
      print("No")
      break
  if i==2**n-1:
    if ls[i]<n-1:
      print("No")
      break
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
a.sort()
ls=[0]
cnt=0
for i in range(1,2**n):
  if a[i]>a[i-1]:
    cnt+=1
  ls.append(cnt)
for i in range(2**n):
  if i<2**n-1:
    lmt=n-int(math.log2(n-i-1))-1
    if ls[i]<lmt:
      print("No")
      break
  if i==2**n-1:
    if ls[i]<n-1:
      print("No")
      break
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
a.sort()
ls=[0]
cnt=0
for i in range(1,2**n):
  if a[i]>a[i-1]:
    cnt+1
  ls.append(cnt)
for i in range(2**n):
  if i<2**n-1:
    lmt=n-int(math.log2(n-i-1))-1
    if ls[i]<lmt:
      print("No")
      break
  if i==2**n-1:
    if ls[i]<n-1:
      print("No")
      break
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = LI()

h = []
for i in range(2**n):
    heappush(h,-s[i])
x = heappop(h)
use = [-x]
for i in range(n):
    rest = []
    for j in range(2**i):
        x = heappop(h)
        rest.append(-x)
    for i in range(2**i):
        if use[i] > rest[i]:
            continue
        else:
            print('No')
            quit()
    for i in range(2**i):
        use.append(rest[i])
print('Yes')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = LI()

if n == 1:
    if s[0] == s[1]:
        print('No')
    else:
        print('Yes')
    quit()
h = []
for i in range(2**n):
    heappush(h,-s[i])
x = heappop(h)
use = [-x]
for i in range(n-1):
    rest = []
    for j in range(2**i):
        x = heappop(h)
        rest.append(-x)
    for i in range(2**i):
        if use[i] > rest[i]:
            continue
        else:
            print('No')
            quit()
    for i in range(2**i):
        use.append(rest[i])
print('Yes')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = LI()

if n == 1:
    if s[0] == s[1]:
        print('No')
    else:
        print('Yes')
    quit()
h = []
for i in range(2**n):
    heappush(h,(-s[i],1))
x,y = heappop(h)
y = 0
heappush(h,(x,y))
for i in range(n-1):
    rest = []
    use = []
    rest_cnt = 0
    use_cnt = 0
    tmp = []
    while rest_cnt != i+1 or use_cnt != i+1:
        x,flg = heappop(h)
        if flg and rest_cnt < i+1:
            rest.append(-x)
            rest_cnt += 1
        elif not flg and use_cnt < i+1:
            use.append(-x)
            use_cnt += 1
        else:
            tmp.append((x,flg))
    for j in range(i+1):
        if use[j] > rest[j]:
            heappush(h,(-rest[j],0))
            heappush(h,(-use[j],0))
        else:
            print('No')
            quit()
    for j,f in tmp:
        heappush((j,f))
print('Yes')

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int, input().split()))

dp = [[0 for _ in range(2 ** n)] for _ in range(18)]
dp[0] = [] + s

#for x in dp: print(x)

m = (n-1) ** 2
for a in range(n):
    #print(dp[a])
    for i in range(1 << (n-a-1)):
        #print(a, i)
        if dp[a][i*2] == dp[a][i*2+1]:
            print('No')
            exit()
        else:
            dp[a+1][i] = max(dp[a][i*2], dp[a][i*2+1])
    #m //= 2
    #print(dp[a+1])

print('Yes')

Submission status: Runtime Error

Solution code:
N = int(input())
nums = list(map(int, input().split()))

D = {}
L = 0
for n in nums:
    if n not in D:
        D[n] = L
        L += 1


for i, x in enumerate(sorted(D, reverse=True)):
    D[x] = i

arr = [0 for i in range(L)]
for n in nums:
    arr[D[n]] += 1

cumsum = [0 for i in range(L+1)]
for i in range(L):
    cumsum[i] = arr[i] + cumsum[i - 1]

# Deal with first
if arr[0] != 1:
    print("No")
    quit()

willSpawn = 1
cur = 1

while cur < L:
    if cumsum[cur - 1] < min(willSpawn, arr[cur]):
        print(1/0)
        print("No")
        quit()
    else:
        for i in range(willSpawn):
            arr[cur] -= 1
            while (cur < L) and arr[cur] == 0:
                cur += 1
    willSpawn *= 2

print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
nums = list(map(int, input().split()))

D = {}
L = 0
for n in nums:
    if n not in D:
        D[n] = L
        L += 1


for i, x in enumerate(sorted(D, reverse=True)):
    D[x] = i

arr = [0 for i in range(L)]
for n in nums:
    arr[D[n]] += 1

cumsum = [0 for i in range(L+1)]
for i in range(L):
    cumsum[i] = arr[i] + cumsum[i - 1]

# Deal with first
if arr[0] != 1:
    print(1/0)
    print("No")
    quit()

willSpawn = 1
cur = 1

while cur < L:
    if cumsum[cur - 1] < min(willSpawn, arr[cur]):
        print("No")
        quit()
    else:
        for i in range(willSpawn):
            arr[cur] -= 1
            while (cur < L) and arr[cur] == 0:
                cur += 1
    willSpawn *= 2

print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
nums = list(map(int, input().split()))

D = {}
L = 0
for n in nums:
    if n not in D:
        D[n] = L
        L += 1


for i, x in enumerate(sorted(D, reverse=True)):
    D[x] = i

arr = [0 for i in range(L)]
for n in nums:
    arr[D[n]] += 1

cumsum = [0 for i in range(L+1)]
for i in range(L):
    cumsum[i] = arr[i] + cumsum[i - 1]

# Deal with first
if arr[0] != 1:
    print("No")
    quit()

willSpawn = 1
cur = 1

while cur < L:
    if cumsum[cur - 1] < min(willSpawn, arr[cur]):
        print("No")
        quit()
    else:
        for i in range(willSpawn):
            arr[cur] -= 1
            while arr[cur] == 0:
                cur += 1
    willSpawn *= 2

print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
nums = list(map(int, input().split()))

D = {}
L = 0
for n in nums:
    if n not in D:
        D[n] = L
        L += 1


for i, x in enumerate(sorted(D, reverse=True)):
    D[x] = i

arr = [0 for i in range(L)]
for n in nums:
    arr[D[n]] += 1

cumsum = [0 for i in range(L+1)]
for i in range(L):
    cumsum[i] = arr[i] + cumsum[i - 1]

# Deal with first
if arr[0] != 1:
    print("No")
    quit()

willSpawn = 1
cur = 1


while cur < L:
    if cumsum[cur - 1] < min(willSpawn, arr[cur]):
        print("No")
        quit()
    else:
        for i in range(willSpawn):
            arr[cur] -= 1
            if arr[cur] == 0:
                cur += 1
    willSpawn *= 2

print(1/0)
print("Yes")

Submission status: Runtime Error

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

int main(){
    int N;
    cin >> N;
    vector<long long> A(1<<N);
    map<long long, int> mp;
    for(int i = 0; i < (1<<N); i++){
        cin >> A[i];
        if(mp.count(A[i]))mp[A[i]]++;
        else mp[A[i]] = 1;
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    long long now = A[0];
    vector<long long> ch(1, now);
    for(int i = 1; i < (1<<N); i++){
        if(A[i] != now){
            ch.push_back(A[i]);
            now = A[i];
        }
    }
    int Nc = ch.size();
    vector<long long> sum(Nc + 1, 0);
    for(int i = 0; i < Nc; i++){
        sum[i + 1] = sum[i] + mp[ch[i]];
    }
    
    long long M = 1;
    bool Flag = true;
    for(int i = 1; i <= Nc; i++){
        if(M < sum[i]){
            Flag = false;
        }
        M += (N - i + 1);
    }
    
    if(Flag)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# if x < y:
#     z = x
# elif True:
#     z = y
# else:
#     z = 100
import sys,os,math
from collections import Counter, defaultdict
import bisect
from sys import stdin, stdout
from itertools import repeat


# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())

def main():
    n = map(int, raw_input().split())[0]
    da = map(int, raw_input().split())
    da = [0] + da
    flag = True
    for i in range(1, n+1):
        if da[i] > da[i*2] and da[i] > da[i*2+1]:
            pass
        else:
            flag = False
    print "Yes" if flag else "No"


main()