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: Runtime Error

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
s.sort()
s += [0]

slime = []
count = 0
for i in range(2**n):
    count += 1
    if s[i] != s[i+1]:
        slime.append([s[i], count, 0])
        count = 0

slime_mother = [[slime.pop()[0], -1, 1]]


for i in range(n):
    for j in range(len(slime_mother)):
        for h in range(slime_mother[j][2]):
            k = 0
            try:
                while slime[slime_mother[j][1]-k][1] == 0:
                    k += 1
            except:
                
                for ii in range(len(slime)):
                    if slime[ii][1] != 0:
                        print("No")
                        exit()
                else:
                    print("Yes")
                    exit()

            slime_mother[j][1] -= k
            slime[slime_mother[j][1]][1] -= 1
            if slime[slime_mother[j][1]][2] == 0:
                slime[slime_mother[j][1]][2] = 1
                slime_mother.append([slime[slime_mother[j][1]][0], slime_mother[j][1]-1, 1])
            else:
                slime_mother[-slime_mother[j][1]][2] += 1



print(abcde)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
s.sort()
s += [0]

slime = []
count = 0
for i in range(2**n):
    count += 1
    if s[i] != s[i+1]:
        slime.append([s[i], count, 0])
        count = 0

slime_mother = [[slime.pop()[0], -1, 1]]


for i in range(n):
    for j in range(len(slime_mother)):
        for h in range(slime_mother[j][2]):
            k = 0
            try:
                while slime[slime_mother[j][1]-k][1] == 0:
                    k += 1
            except:
                print("No")
                exit()

            slime_mother[j][1] -= k
            slime[slime_mother[j][1]][1] -= 1
            if slime[slime_mother[j][1]][2] == 0:
                slime[slime_mother[j][1]][2] = 1
                slime_mother.append([slime[slime_mother[j][1]][0], slime_mother[j][1]-1, 1])
            else:
                slime_mother[-slime_mother[j][1]][2] += 1



print(abcde)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a, reverse=True)
for i in range(n+1):
  x=2**(i-1);b=a[:x];c=a[x:2**i]
  if i == 0:continue
  elif sum(b) > sum(c)+x-1:
    for j in range(x):
      if(b[j]-c[j]==0):print('No');exit()
    continue
  else:print('No');exit()
print('Yes')

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a, reverse=True)
for i in range(n+1):
  x=2**(i-1);b=a[:x];c=a[x:2**i]
  if i == 0:continue
  elif sum(b) > sum(c)+x-1:
    for j in range(len(x)):
      if(b[j]-c[j]==0):print('No');exit()
    continue
  else:print('No');exit()
print('Yes')

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a, reverse=True)
for i in range(n+1):
  x=2**(i-1);b=a[:x];c=a[x:2**i]
  if i == 0:continue
  elif sum(b) > sum(c)+x-1:
    for j in len(x):
      if(b[j]-c[j]==0):print('No');exit()
    continue
  else:print('No');exit()
print('Yes')

Submission status: Runtime Error

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

S = sorted(S,reverse=True)

def solve(S):
    for i in range(N):
        gap = 2**i
        for j in range(gap):
            if S[j] == S[j+gap]:
                return False
    return True

print("Yes" if solve(S) else "No" )
~

Submission status: Runtime Error

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

parents = [(S.pop(),N)]

flg = True
while parents and flg:
    s,n = parents.pop(0)
    for i in range(1,n+1):
        x = S.pop()
        if s > x and n-i != 0:
            parents.append((x,n-i))
            
        elif s <= x:
            flg = False
            break
    print(parents)
    print(S)
 
if flg:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

ll pow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res *= a;
    a *= a;
    n >>= 1;
  }
  return res;
}

ll mod_pow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll mod_inv(ll a, ll mod) {
  return mod_pow(a, mod - 2, mod);
}

ll mod_Com(int n, int k, int mod) {
  ll p = 1, q = 1;
  for (int i = n - k + 1; i <= n; i++)
    p = p * i % mod;
  for (int i = 2; i <= k; i++)
    q = q * i % mod;
  q = mod_inv(q, mod);
  return p * q % mod;
}

bool solve() {
  int n; cin >> n;
  int N = pow(2, n);
  set<int> S;
  map<int, int> cnt;
  int M = 0;
  for (int i = 0; i < N; i++) {
    int x; cin >> x;
    S.insert(-x);
    cnt[-x] += 1;
    M = min(-x, M);
  }
  if (cnt[M] > 1) {
    return false;
  }
  S.erase(M);
  vector<int> v;
  v.push_back(M);
  for (int i = 0; i < n; i++) {
    for (auto x: v) {
      auto y = S.upper_bound(x);
      if (y == S.end()) {
        return false;
      }
      cnt[*y] -= 1;
      if (cnt[*y] == 0) {
        S.erase(*y);
      }
      v.push_back(*y);
    }
  }
  return true;
}

int main() {
  if (solve()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Submission status: Runtime Error

Solution code:
N = int(input())
S = sorted(list(map(int, input().split())), reverse = True)
def C(N, S):
    for i in range(N):
        if any(S[(1<<i)-1+j] == S[(1<<(i+1))-1+j] for j in range(1<<i)):
            return False
    return True
if C(N, S):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
def main():
    inf = 10 ** 9 + 5
    n = int(input())
    n2 = 2 ** n
    s = list(map(int, input().split()))
    s.sort(reverse=True)
    # print(s)
    pp = [s[0]]
    s[0] = inf
    for _ in range(n):
        pp.sort()
        i = 1
        np = pp[:]
        while pp:
            p = pp.pop()
            while 1:
                if s[i] < p:
                    np.append(s[i])
                    s[i] = inf
                    i += 1
                    break
                else:
                    i += 1
                if i == n2:
                    print("No")
                    exit()
        pp = np
    print("Yes")

main()

Submission status: Runtime Error

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

a=[]*n
s.sort()
s.reverse()
ccnt=1
pcnt==0
for i in range(1,n):
  for j in range(i):
    for k in range (n-i):
      if s[pcnt]<=s[ccnt]:
        print("No")
        sys.exit()
      ccnt+=1
    pcnt+=1
print("Yes")

Submission status: Runtime Error

Solution code:
n=int(input())
c=input().split()
c=list(map(int,c))
c.sort(reverse=True)
nc=len(c)pk=c[0]
p=[]
p.append(pk)
flag=False
for i in range(n) :   
  np=len(p)             #現在の親の数
  for ip in range(np):  #親の数だけ繁殖
    flag=False
    for ic in range(nc): #全個体リストから親未満のSを探索
      if p[ip]>c[ic]:    #繁殖可能
        flag=True        
        p.append(c[ic])  #ｐの後ろに子供を連けつ
        c[ic]=pk         #sにマーク
        break  #次の親判定に
    #for end---------------
    if flag==False:# 繁殖可能でない親が判明 終了する   
      break
  #for end-----------------
  if flag==False:# 繁殖可能でない親が判明 終了する
    break
#while end------------------
if flag==True:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

Solution code:
import bisect

# n = int(input())
# s = list(map(int, input().split(" ")))
# n = 18
# s = list(reversed(range(1, 2 ** n + 1)))

s = sorted(s)
from collections import deque

def solve():
    parents = [s[-1]]
    s.pop()

    for i in range(n):
        newparents = list(parents)
        print(parents)
        for p in parents:
            k = bisect.bisect(s, p) - 1
            # print(p, s, k)
            if k == -1:
                print("No")
                exit(0)
            newparents.append(s[k])
            s.pop(k)
        parents = sorted(newparents, reverse=True)

    print(parents)
    # print(k)
    if k == len(s):
        print("Yes")
    else:
        print("No")
solve()

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int, input().split(" ")))
# n = 2
# s = list(reversed(range(1, 2 ** n + 1)))

s = sorted(s, reverse=True)
from collections import deque

def solve():
    parents = [s[0]]
    k = 1

    while k < len(s):
        newparents = list(parents)
        for p in parents:
            print("Check", p)
            if p > s[k]:
                print("Take", s[k])
                newparents.append(s[k])
                k += 1
            else:
                print("No")
                exit(1)
        parents = sorted(newparents, reverse=True)
    print("Yes")
solve()

Submission status: Runtime Error

Solution code:
import sys,bisect as bs,collections as cl
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

p = l()

p.sort(reverse = True)

ms = p[0]
s = [p[0]]

for i in range(n):
    count = 0
    local = 0
    s.sort(reverse = True)
    while count < 2**i:
        if local >= 2**n:
            print("No")
            exit()
        if s[i] > p[local]:
            s.append(p[local])
            p[local] = mS
            count += 1
        local += 1
print("Yes")

Submission status: Runtime Error

Solution code:
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func intArray(n []string) []int {
	var m []int
	for i, _ := range n {
		v, _ := strconv.Atoi(n[i])
		m = append(m, v)
	}
	return m
}

func intExistIn(v int, arr []int) bool {
	for _, a := range arr {
		if a == v {
			return true
		}
	}

	return false
}

func gcd(m, n uint64) uint64 {
	x := new(big.Int)
	y := new(big.Int)
	z := new(big.Int)
	a := new(big.Int).SetUint64(m)
	b := new(big.Int).SetUint64(n)
	return z.GCD(x, y, a, b).Uint64()
}

func remove(x []int, y int) (newArray []int) {
	for i, _ := range x {
		if i != y {
			newArray = append(newArray, x[i])
		}
	}
	return
}

func main() {
	// sc.Split(bufio.ScanWords)
	// strings.Split(nextLine(), " ")

	n := nextInt()
	n = n + 1
	t := intArray(strings.Split(nextLine(), " "))

	// sort.Slice(s, func(x, y int) bool { return s[x] > s[y] })
	sort.Ints(t)
	var s []int
	for i := len(t) - 1; i > -1; i-- {
		s = append(s, t[i])
	}

	var ans []int

	ans = append(ans, s[0])
	s = s[1:]

	for len(s) > 0 {
		var tmp []int

		for _, parent := range ans {
			ch := 0
			for i, _ := range s {
				if parent > s[i] {
					child := s[i]
					s = remove(s, i)
					tmp = append(tmp, child)
					ch = 1
					break
				}
			}

			if ch == 0 {
				fmt.Println("No")
				os.Exit(0)
			}
		}

		ans = append(ans, tmp...)
	}

	fmt.Println("yes")
}

Submission status: Runtime Error

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

S.sort()

parent = [S.pop()]
rest = S
for _ in range(N):
	n_parent = []
	n_rest = []

	for p in parent[::-1]:
		while rest:
			x = rest.pop()
			if x < p:
				n_parent.append(x)
				break
			else:
				n_rest.append(x)
	parent += n_parent
	parent.sort()
	rest = rest + n_rest[::-1]

if len(parent) == (2**N):
	pritn("Yes")
else:
	print('No')

Submission status: Runtime Error

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

S.sort()

parent = [S.pop()]
rest = S
for _ in range(N):
	n_parent = []
	n_rest = []

	for p in parent[::-1]:
		while rest:
			x = rest.pop()
			if x < p:
				next_parent.append(x)
				break
			else:
				next_rest.append(x)
	parent += next_parent
	parent.sort()
	rest = rest + next_rest[::-1]

if len(parent) == (2**N):
	pritn("Yes")
else:
	print('No')

Submission status: Runtime Error

Solution code:
N=int(input())
S=list(map(int, input().split()))
S.sort(reverse=True)
S=[-1]+S
res="Yes"
if S[1]<=S[2]:
  res="No"
else:
  for i in range(1, N):
    for j in range(2**(i-1)):
      if S1[j]<=S2[j]:
        res="No"
        break
    if res=="No":
      break
print(res)

Submission status: Runtime Error

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):
        j = 0
        jM = len(cur)
        for k in range(len(S)):
            if flag[k] and S[k]<cur[j]:
                nxt.append(S[k])
                j+=1
                flag[k] = False
                if j==jM:
                  break
        else:
            return("No")
        cur.sort(reverse=True)
    return("Yes")

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    S = [int(s) for s in input().split()]
    S.sort()

    cur = []
    cur.append(S.pop(-1))

    for i in range(N):
        nxt = [j for j in cur]
        bl = len(S)
        for x in cur:
            bl = bisect.bisect_left(S,x,lo=0,hi=bl)
            if bl==0:
                return("No")
            else:
                nxt.append(S.pop(bl-1))
        nxt.sort(reverse=True)
        cur = [j for j in nxt]
    return("Yes")

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

Submission status: Runtime Error

Solution code:

N = int(input())
a = list(map(int,input().split(' ')))
a.sort(True)
 
 
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: Runtime Error

Solution code:
import pandas as pd

N=int(input())
S=pd.Series(list((map(int,input().split())))).sort_values(ascending=False).reset_index(drop=True)
p = pd.Series([S.pop(0)])
c = S.reset_index(drop=True)
f = False

for i in range(N):
    np = pd.Series()
    nc = pd.Series()
    for j in range(len(p)):
        for k in range(len(c)):
            if c[k] < p[j]:
                nc_ = pd.Series([c.pop(k)])
                np = pd.concat([np, nc_])
                c = c.reset_index(drop=True)
                f = True
                break
        if f == False:
            print("No")
            exit(0)
        f = False
    p = pd.concat([p, np])
    p = p.sort_values(ascending=False).reset_index(drop=True)

print("Yes")

Submission status: Runtime Error

Solution code:
import bisect

N = int(input())
a = list(map(int,input().split(' ')))
a.sort()

def do(n,fathers):
       
    if n == N:
        return
    
    for father in fathers:
        son = a.pop(bisect.bisect_left(a,father)-1)
        if son >= father:
            return
        else:
            fathers.append(son)
            
    do(n+1,fathers)
    


fathers = [a.pop()]
do(0, fathers) 
if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import bisect
import sys
input = sys.stdin.readline
N=int(input())
S=[int(x) for x in input().split()]
T=sorted(S)
A=[]
#print(T)
if T[-1] ==T[-1-1]:
    #print('two max values')
    print('No')
    sys.exit()
if T[-2] ==T[-1-4]:
    #print('second max values')
    print('No')
    sys.exit()
A.append(T.pop(-1))
M=2**(N-1)-1
for j in range(0,N):
    #print('***'+ str(j) +'***')
    for i in range(0,2**j):
        k=bisect.bisect_left(T,A[i])-1
       #print(i,A[i],T[k])
        if A[i] <= T[k]:
            print("No")
            sys.exit()
        A.append(T.pop(k))
print('Yes')

Submission status: Runtime Error

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)
from collections import deque
import heapq
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    S = [int(a) for a in input().split()]
    S = sorted(S,key=lambda x:x)
    debug(S,'S')
    live = [S[-1]]
    S.pop()
    # iはステップ
    for i in range(N):
        # 各スライムに生んでもらう
        livenext = live.copy()
        for l in live:
            borned = False
            for j in range(len(S)-1, -1, -1):
                if l > S[j]:
                    # debug((l,S[j]),'parent, child')
                    livenext.append(S[j])
                    S.remove(S[j])
                    borned = True
                    break
            if not borned:
                print("No")
                exit()
        live = livenext
    if len(S) == 0:
        print("Yes")
    else:
        print("No")



if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

A.sort()
B = [A.pop()]

for i in range(n):
    for i in range(len(B)):
        if B[i] > A[-i]:
            B += [A.pop()]
        else:
            break
if len(A) == 0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import bisect

N = int(input())
a = list(map(int,input().split(' ')))
a.sort()

# print(a)


def do(index,father):
    result = True
    
    if len(a) == 0 :
        return True
    
    son = a.pop(bisect.bisect_left(a,father)-1)
    
#     print(father,son,index)
    
    if father > son:
        result = do(index*2,son) and result
        result =do(index*2 + 1,son) and result
    else:
        return False
    
    return result
        
if do(1,10**9 + 1):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
S = list(map(int,input().split()))
S.sort(reverse = True)
for i in range(N):
    S[i] = -S[i]
for i in range(N):
    for j in range(2**i):
        if S[j] == S[j+2**i]:
            m = bisect.bisect_left(S[2**i:],S[j])+2**i
            if m == N:
                print("No")
                exit()
            else:
                S[j+2**i] , S[m] = S[m] ,S[j+2**i]
print("Yes")

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
m = max(s)
f = 0
if m < n+1:
  f = 1
for i in range(n):
  l[i] = s.count(m-i)
  if l[i] > 2**i:
    f = 1
  if i>0 and l[i]*2 > l[i-1]:
    f = 1
if f == 0:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = [int(s) for s in input().split()]
    S.sort(reverse = True)

    result = []
    result.append(S[0])

    left = 1
    que = []
    que.append([])

    for i in range(N):
        for j in range(2**i):
            que.append([])
            for k in len(que[-2]):
                if result[j]<=que[-2][k]:
                    que[-1].append(que[-2][k])
                else:
                    result.append(que[-2][k])
                    que[-1].extend(que[-2][k+1:])
                    break
            else:
                for k in range(left,len(S)):
                    if result[j]<=S[k]:
                        que[-1].append(S[k])
                    else:
                        result.append(S[k])
                        left = k+1
                        break
                else:
                    print("No")
                    break
        else:
            continue
        break
    else:
        print("Yes")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(map(int,input().split()))
S.sort(reverse = True)
for i in range(N):
    for i in range(2**i):
        if S[i] <= S[i+2**i]:
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

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

S.sort()
def compress(s):
    n = (len(s)-1).bit_length()
    j = 0
    comp = [0] * (2 ** n)
    comp[j] += 1
    for i in range(1,2**n):
        if s[i] > s[i-1]:
            j += 1
        comp[j] += 1
    return comp, j

comp, m = compress(S)

valid = True
for i in range(N):
    k = 0
    l = 1
    if l >= len(comp):
        valid = False
        break
    news = []
    for j in range(2**(N-i-1)):
        comp[k] -= 1
        comp[l] -= 1
        news.append(l)
        if not comp[l]:
            if not comp[k]:
                l += 2
                k += 2
            else:
                l += 1
        else:
            if not comp[k]:
                l += 1
                k += 1
            else:
                pass
        if l > m:
            break
    else:
        if j < 2**(N-i-1) - 1:
            break
    comp, m = compress(news)
else:
    if i < N - 1:
        valid = False

print('Yes' if valid else 'No')

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = [int(s) for s in input().split()]
    S.sort(reverse = True)

    result = []
    result.append(S[0])
    que = [True]*len(S)
    que[0] = False

    for i in range(N):
        for j in range(2**i):
            for k in range(len(S)):
                if que[k] and result[j]>S[k]:
                    result.append[S[k]]
                    que[k] = False
                    break
            else:
                print("No")
                break
        else:
            continue
        break
    else:
        print("Yes")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int( input())
    S = list( map( int, input().split()))
    S.sort(reverse=True)
    for i in range(N):
        if S[0] <= S[i+1]:
            print('No')
            return
    check = N+2
    for i in range(N-1):
        now = pow(2,i)
        for j in range(now):
            for _ in range(N-i-1):
                print(now+j, check)
                if S[now+j] <= S[check]:
                    print('No')
                    return
                check += 1

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    print(n**3)
    return

#B
def B():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    ans = sum(b)
    for i in range(n-1):
        x = a[i]
        y = a[i+1]
        if y == x+1:
            ans += c[x-1]
    print(ans)
    return

#C
def C():
    n = I()
    b = LI()
    b.append(float("inf"))
    a = [min(b[i],b[i-1]) for i in range(n)]
    print(sum(a))
    return

#D
def D():
    n,k = LI()
    a = S()
    if a.count("L") in [0,n]:
        print(n-1)
        return
    if n == 1:
        print(0)
        return
    if n == 2:
        print(1)
        return
    ans = 0
    f = [0]*n
    for i in range(n-1):
        if a[i] == a[i+1]:
            ans += 1
            if a[i] == "L":
                f[i+1] = 1
            else:
                f[i] = 1
    f.append(0)
    f.append(0)
    d = defaultdict(lambda : 0)
    l = 0
    s = a[0]
    for i in range(n):
        if a[i] != s:
            d[(l,i-1)] = 1
            s = a[i]
            l = i
    r = n-1
    l = 0
    m = 0
    for i in range(k):
        if not i%2:
            while a[r] != "R":
                r -= 1
            while a[l] != "R":
                l += 1
        else:
            while a[r] != "L":
                r -= 1
            while a[l] != "L":
                l += 1
        if d[(l,r)]:
            print(n-1)
            return
        else:
            m += 2-f[l-1]-f[r+1]
    r = n-1
    l = 0
    m_ = 0
    for i in range(k):
        if i%2:
            while a[r] != "R":
                r -= 1
            while a[l] != "R":
                l += 1
        else:
            while a[r] != "L":
                r -= 1
            while a[l] != "L":
                l += 1
        if d[(l,r)]:
            print(n-1)
            return
        else:
            m_ += 2-f[l-1]-f[r+1]
    print(ans+max(m,m_))
    return

#E
def E():
    def add(i):
        while i <= n:
            bit[i] += 1
            i += i&-i

    def sum(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i&-i
        return res

    n = I()
    p = LI()
    r = [0]*n
    bit = [0]*(n+1)
    for i in range(n)[::-1]:
        r[i] = (n-i-1)-sum(p[i])
        add(p[i])
    print(r)
    l = [0]*n
    bit = [0]*(n+1)
    for i in range(n):
        l[i] = i-sum(p[i])
        add(p[i])
    print(l)

    return

#F
def F():
    def add(i,x):
        while i <= m:
            bit[i] += x
            i += i&-i

    def sum(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i&-i
        return res

    n = I()
    s = LI()
    s.sort()
    f = []
    a = s[0]
    k = 1
    for i in s[1:]:
        if a != i:
            f.append(k)
            k = 0
            a = i
        k += 1
    f.append(k)
    f = f[::-1]
    f.insert(0,0)
    m = len(f)
    bit = [0]*(m+1)
    add(1,1)
    if f[1] > 1:
        print("No")
        return
    j = 2
    for i in range(n):
        su_ = sum(j-1)
        su = sum(j)
        aj = su-su_
        while su > 0:
            mi = min(f[j]-aj, su_)
            add(j,mi)
            aj += mi
            su -= mi
            if aj == f[j]:
                su_ = su
                j += 1
            else:
                break
    k = [sum(i+1)-sum(i) for i in range(m-1)]
    if k == f[1:]:
        print("Yes")
    else:
        print("No")
    return

#Solve
if __name__ == "__main__":
    F()

Submission status: Runtime Error

Solution code:
n = int(input())
S = [int(i) for i in input().split()]

if n == 1:
  print('Yes')
  exit()


S.sort(reverse=True)
M = [n]
for i in range(n - 1):
  for b in range(1 << i):
    M.append(n - i)

x = 1
for s, m in zip(S, M):
  if S[x] >= s:
    print('No')
    exit()
  x += m
    
print('Yes')

Submission status: Runtime Error

Solution code:
n = int(input())
S = [int(i) for i in input().split()]

S.sort(reverse=True)
M = [n]
for i in range(n - 1):
  for b in range(1 << i):
    M.append(n - i)

x = 1
for s, m in zip(S, M):
  if S[x] >= s:
    print('NO')
    exit()
  x += m
    
print('Yes')

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = [int(s) for s in input().split()]
    S.sort()

    result = []
    result.append(S.pop(-1))



    for i in range(N):
        x = 1
        for j in range(2**i):
            while(True):
                if x>2**i:
                    break
                if result[j]>S[-1*x]:
                    result.append(S.pop(-1*x))
                    break
                else:
                    x += 1
            if x>2**i:
                print("No")
                break
        else:
            continue
        break
    else:
        print("Yes")

if __name__ == "__main__":
    main()