Harryxun/stf_run huggingface dataset:
def find(x,ones):
    if ones == 0:
        return False
    total = 0
    n = len(x)
    for i in range(n):
        total += int(x[i])*pow(2,n-i-1,ones)
        total %= ones

    return total

def solve(x,mod):
    x %= mod
    moves = 1
    while x != 0:
        x = x%(bin(x)[2:].count('1'))
        moves += 1

    return moves

def main():
    n = int(input())
    x = input()
    ones = x.count('1')
    less = find(x,ones-1)
    more = find(x,ones+1)
    for i in range(n):
        if x[i] == '0':
            print(solve(more+pow(2,n-i-1,ones+1),ones+1))
        else:
            print(solve(less-pow(2,n-i-1,ones-1),ones-1))


main()


### FIXED CODE ###

def find(x,ones):
    if ones == 0:
        return 0
    total = 0
    n = len(x)
    for i in range(n):
        total += int(x[i])*pow(2,n-i-1,ones)
        total %= ones

    return total

def solve(x,mod):
    x %= mod
    moves = 1
    while x != 0:
        x = x%(bin(x)[2:].count('1'))
        moves += 1

    return moves

def main():
    n = int(input())
    x = input()
    ones = x.count('1')
    less = find(x,ones-1)
    more = find(x,ones+1)
    for i in range(n):
        if x[i] == '0':
            print(solve(more+pow(2,n-i-1,ones+1),ones+1))
        else:
            if ones-1 == 0:
                print(0)
            else:
                print(solve(less-pow(2,n-i-1,ones-1),ones-1))


main()
A = input()
B = input()
AA = "%101s", A
BB = "%101s", B
if AA == BB:
    print("EQUAL")
elif AA>BB:
    print("GREATER")
else:
    print("LESS")

### FIXED CODE ###

A, B, C = input().split()
print(A[0].upper()+B[0].upper()+C[0].upper())
n = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

import itertools

A = list(itertools.permutations(list(range(1, n+1))))
 
a = A.index(P)
b = A.index(Q)
print(abs(a-b))

### FIXED CODE ###

n = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

import itertools

A = list(itertools.permutations(list(range(1, n+1))))
 
a = A.index(tuple(P))
b = A.index(tuple(Q))
print(abs(a-b))
a,b = map(int,(input().split()))

if a == "H" and b == "H":
    print("H")
elif a == "H" and b == "D":
    print("D")
elif a == "D" and b == "H":
    print("D")
else:
    print("H")

### FIXED CODE ###

a,b = map(str,(input().split()))

if a == "H" and b == "H":
    print("H")
elif a == "H" and b == "D":
    print("D")
elif a == "D" and b == "H":
    print("D")
else:
    print("H")
import fractions
a,b = map(int,input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(int(lcm(a, b)))

### FIXED CODE ###

import fractions
a,b = map(int,input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

print(int(lcm(a, b)))
import numpy as np
N = int(input())
lis = np.zeros((101,101))
s = list()
for k in range(N):
    tmp = list()
    x,y,h = map(int,input().split())
    if h == 0:
        continue
    if s:
        if len(s) == 1:
            break
        for i in s:
            if i[2] == h+abs(i[0]-x)+abs(i[1]-y):
                tmp.append(i)
        s = tmp
    else:
        for i in range(101):
            for j in range(101):
                if lis[i][j] == 0:
                    lis[i][j] = h+abs(i-x)+abs(j-y)
                elif lis[i][j] == h+abs(i-x)+abs(j-y):
                    s.append([i,j,lis[i][j]])
print(s[0][0], s[0][1], int(s[0][2]))

### FIXED CODE ###

import numpy as np
N = int(input())
lis = np.zeros((101,101))
s = list()
for k in range(N):
    tmp = list()
    x,y,h = map(int,input().split())
    if h == 0:
        continue
    if s:
        if len(s) == 1:
            break
        for i in s:
            if i[2] == h+abs(i[0]-x)+abs(i[1]-y):
                tmp.append(i)
        s = tmp
    else:
        for i in range(101):
            for j in range(101):
                if lis[i][j] == 0:
                    lis[i][j] = h+abs(i-x)+abs(j-y)
                elif lis[i][j] == h+abs(i-x)+abs(j-y):
                    s.append([i,j,lis[i][j]])
else:
    for i in range(101):
        for j in range(101):
            if lis[i][j] == 1:
                s.append([i,j,lis[i][j]])
print(s[0][0], s[0][1], int(s[0][2]))
import bisect

if 1:
    N,W = map(int, input().split(' '))
    w,v = [],[]
    for i in range(N):
        w_,v_ = map(int, input().split(' '))
        w.append(w_)
        v.append(v_)
else:
    N,W = 4,6
    w = [2,3,4,3]
    v = [1,4,10,4]

w0 = w[0]

idxs = set()
for i in range(N):
    for j in range(3*i+1):
        if i*w0+j <= W:
            idxs.add(i*w0+j)
idxs = list(idxs) 
idx_dict = {idx:i for i,idx in enumerate(idxs)}

dp = [[0 for j in range(len(idxs))] for i in range(N+1)]

for i in range(N):
    for j in range(len(idxs)):
        if idxs[j] < w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            k = bisect.bisect_left(idxs, idxs[j]-w[i])
            dp[i+1][j] = max([dp[i][j],dp[i][idx_dict[idxs[k]]]+v[i]])
                
print(dp[-1][-1])

### FIXED CODE ###


if 1:
    N,W = map(int, input().split(' '))
    w,v = [],[]
    for i in range(N):
        w_,v_ = map(int, input().split(' '))
        w.append(w_)
        v.append(v_)
else:
    N,W = 4,6
    w = [2,3,4,3]
    v = [1,4,10,4]

w0 = w[0]

idxs = set()
for i in range(N+1):
    for j in range(3*i+1):
        if i*w0+j <= W:
            idxs.add(i*w0+j)
idxs = sorted(list(idxs))
idx_dict = {idx:i for i,idx in enumerate(idxs)}

dp = [[0 for j in range(len(idxs))] for i in range(N+1)]

for i in range(N):
    for j in range(len(idxs)):
        if idxs[j] < w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            try:
                dp[i+1][j] = max([dp[i][j],dp[i][idx_dict[idxs[j]-w[i]]]+v[i]])
            except:
                dp[i+1][j] = dp[i][j]
        
print(max([max(dp_) for dp_ in dp]))
a = int(input())
b = int(input())
c = list(map(int,input().split()))
d = sum(c)

if (a-d) < 0:
    print(-1)
else:
    print(a-d)



    


### FIXED CODE ###

a,b = (map(int,input().split()))
c = list(map(int,input().split()))
d = sum(c)

if (a-d) < 0:
    print(-1)
else:
    print(a-d)
N, K = map(int, input().split())
print([0, 1][N % K])


### FIXED CODE ###

N, K = map(int, input().split())
print([0, 1][0<N % K])
import fractions, math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
import random

def is_prime3(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in xrange(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True
  
A, B = map(int, input().split()) 
ans = set(make_divisors(A)) &  set(make_divisors(B))
print(sum([is_prime3(i) for i in ans])+1)



### FIXED CODE ###

import fractions, math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
import random

def is_prime3(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True
  
A, B = map(int, input().split()) 
ans = set(make_divisors(A)) &  set(make_divisors(B))
print(sum([is_prime3(i) for i in ans])+1)
N = int(input())
NUM = list(map(int,input().split()))
MAX = max(NUM)
MIN = min(NUM)
COSTLIST = []
for i in range (MIN,MAX):
    COST = 0
    for j in NUM:
        COST += (j-i)**2
    COSTLIST.append(COST)
MINIMUM = min(COSTLIST)

print(MINIMUM)

### FIXED CODE ###

N = int(input())
NUM = list(map(int,input().split()))
MAX = max(NUM)
MIN = min(NUM)
COSTLIST = []
for i in range (MIN,MAX+1):
    COST = 0
    for j in NUM:
        COST += (j-i)**2
    COSTLIST.append(COST)
MINIMUM = min(COSTLIST)

print(MINIMUM)
while(True):

    a, b, c, x, y = list(map(int, input().split()))
    res = a * x + b * y
    for i in range(1, max(x, y) + 1):
        res = min(res, a * max(x - i, 0) + b * max(y - i, 0) + 2 * c * i)
    print(res)

### FIXED CODE ###

a, b, c, x, y = list(map(int, input().split()))
res = a * x + b * y
for i in range(1, max(x, y) + 1):
    res = min(res, a * max(x - i, 0) + b * max(y - i, 0) + 2 * c * i)
print(res)
N = int(input())
s = []
for i in range(N):
	s.append(input())
c = 0
for j in range(len(s)):
	c += s[j].count("AB")
a = 0
b = 0
for k in range(len(s)):
	if s[k][-1] == "A":
        a += 1
for l in range(len(s)):
	if s[l][0] == "B":
        b += 1
print(c+min(a,b))


### FIXED CODE ###

N = int(input())
S = [input() for _ in range(N)]
ans = 0
ba = b = a = 0
for s in S:
    ans += s.count('AB')
    if s[0] + s[-1] == 'BA':
        ba += 1
    if s[0] == 'B':
        b += 1
    if s[-1] == 'A':
        a += 1
ans += min(a, b)
if a == b == ba and b:
    ans -= 1
print(ans)
n, m = map(int, input().split())
digit = [[] for i in range(n)]
for i in range(m):
  s, c= map(str, input().split())
  digit[int(s)-1].append(c)

flag = True
for i in range(n):
  if len(digit[i]) > 1:
    digit[i] = list(set(digit[i]))
  if len(digit[i]) > 1:
    flag = False

if flag:
  ans = []
  for i in range(10**(n-1),10**n):
    tmp = 0
    count =10**(n-1)
    for j in range(len(digit)):
      if len(digit[j]) > 0:
        tmp+=count*int(digit[j][0])
      count/=10
    if i == tmp:
      ans.append(i)
  print(min(ans))  
else:
  print(-1)


### FIXED CODE ###

n, m = map(int, input().split())
digit = [list(map(int, input().split())) for _ in range(m)]

for i in range(10**n):
  tmp = str(i)
  if len(tmp) == n:
    flag = True
    for s, c in digit:
      if tmp[s-1] != str(c):
        flag = False
        break
    if flag:
      print(i)
      exit()
print(-1)
m,k=map(int,input().split())
if 0<=k<2**m:
    s=[i for i in range(2**m) if i!=k]
    print(*s,k,*s[::-1],k)
else:
    print(-1)

### FIXED CODE ###

m,k=map(int,input().split())
if 0<=k<2**m:
    if m==1:
        if k==1:print(-1)
        else:print(*[1,1,0,0])
    else:
        s=[str(i) for i in range(2**m) if i!=k]
        c=""
        for i in s:c+=i+" "
        c+=str(k)+" "
        for i in s[::-1]:c+=i+" "
        print(c+str(k))
else:
    print(-1)
n = int(input())

dp =[0]*40

if n ==0:
    print(0)

elif n >0:
    x = bin(n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==1 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))    

else:
    x = bin(n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==1 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))    

### FIXED CODE ###

n = int(input())

dp =[0]*40

if n ==0:
    print(0)

elif n >0:
    x = bin(n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==1 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))    

else:
    x = bin(-n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==0 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))
"""#自分で考えたやつ
N, M = map(int, input().split())
AB = []
for i in range(N):
    a, b =  (int(x) for x in input().split())
    AB.append([a, b])
AB.sort(key=lambda x: x[1])

dic = {}
for i in range(M):
"""

import heapd

N, M = map(int, input().split())

# 仕事の制約が厳しい順にリストに格納する
Blist = [[] for _ in range(M)]
for i in range(N):
    A, B = map(int, input().split())
    if A <= M: # AがMより大きいといつやっても間に合わない
        Blist[A-1].append(-B) # heapdを使うことを考慮して-倍しておく

ans = 0
q = [] # heapd.heapify(q)でリストのヒープ化ができるがここではlen(q)を使いたいためにしないでおく

# 可能な仕事をqに入れて扱う。その中でもBが最大(「-」倍しているのでここでは最小)のものを優先して取り出す。
for  i in range(M):
    for b in Blist[i]: # ヒープ化されたリストqに2次元のBlistのi番目のリストの要素を全て入れる
        heapd.heappush(q, b)
    if len(q) > 0: # qに要素があるならば、qから最小の要素を取り出して(「-」倍してあるので)それを引き算する
        ans -= heapd.heappop(q)

print(ans)


### FIXED CODE ###

A, B = map(int, input().split())

X = []
X.append(A+B)
X.append(A-B)
X.append(A*B)

X.sort()

print(X[2])
from math import log2
def main():
    N = int(input())
    A = list(map(int,input().split()))
    mod = 10**9+7
    
    digits_cnt1 = [0]*60
    for ai in A:
        if ai == 0:
            continue
        #2**60-1みたいな時にfloatの桁落ちが生じるが、ai>>dが必ずfalseになるのでlist index out of rangeは生じない
        for d in range(int(log2(ai))+1):
            if ai>>d & 1:
                digits_cnt1[d] += 1
    
    ans = 0
    for i in range(60):
        ans += digits_cnt1[i]*(N-digits_cnt1[i])*pow(2,i,mod)
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

from math import log
def main():
    N = int(input())
    A = list(map(int,input().split()))
    mod = 10**9+7
    
    digits_cnt1 = [0]*60
    for ai in A:
        if ai == 0:
            continue
        #2**60-1みたいな時にfloatの桁落ちが生じるが、元々の桁数を超えるとai>>dがfalseになるのでlist index out of rangeは生じない
        for d in range(int(log(ai)/log(2))+1):
            if ai>>d & 1:
                digits_cnt1[d] += 1
    
    ans = 0
    for i in range(60):
        ans += digits_cnt1[i]*(N-digits_cnt1[i])*pow(2,i,mod)
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()
A, B, K = map(int, input().split())
 
count = 0
index = 0

if A > B:
  for i in range(B):
    if A % i == 0 and B % i == 0:
      index = i
      count = count+1
      if count == K:
        break
elif A < B:
    for i in range(A):
      if A % i == 0 and B % i == 0:
        index = i
        count = count+1
        if count == K:
          break
  
print(index)  

### FIXED CODE ###

A, B, K = map(int, input().split())
 
count = 0
index = 0
 
if A >= B:
  for i in reversed(range(1, B+1)):
    if A % i == 0 and B % i == 0:
      index = i
      count = count+1
      if count == K:
        break
elif A < B:
    for i in reversed(range(1,A+1)):
      if A % (i) == 0 and B % (i) == 0:
        index = i
        count = count+1
        if count == K:
          break
  
print(index)
M, K = map(int, input().split())
if K >= 2**(M+1):
    print(-1)
elif M == 1:
    if K == 0:
        print("1 0")
    else:
        print(-1)
else:
    d = set()
    for i in range(2**(M+1)):
        p = tuple(sorted([i, i^K]))
        if p not in d:
            d.add(p)
    r = []
    while d:
        x,y = d.pop()
        z,w = d.pop()
        r += [x,y,z,w,y,x,w,z]
    print(*r)



### FIXED CODE ###

M, K = map(int, input().split())
if K >= 2**M:
    print(-1)
elif M == 0:
    print(0, 0)
elif M == 1:
    if K == 0:
        print("0 0 1 1")
    else:
        print(-1)
elif K==0:
    r = list(range(2**M))
    r += r[::-1]
    print(*r)
else:
    d = set()
    for i in range(2**M):
        p = tuple(sorted([i, i^K]))
        if p not in d:
            d.add(p)
    r = []
    while d:
        x,y = d.pop()
        z,w = d.pop()
        r += [x,y,z,w,y,x,w,z]
    print(*r)
question="C"
input=raw_input
if question=="A":
	t=input()
	t=t.replace("9","n")
	t=t.replace("1","o")
	t=t.replace("n","1")
	t=t.replace("o","9")
	print(t)
if question=="B":
	s=int(input())
	t=[111,222,333,444,555,666,777,888,999]
	t=filter(lambda x:x>=s,t)[0]
	print(t)
if question=="C":
	N=int(input())
	a=map(int,input().split())
	A=Amoto=a[0:][::2]
	B=Bmoto=a[1:][::2]
	def f(x):
		a=[(i, x.count(i)) for i in set(x)]
		a=sorted(a,key=lambda x:-x[1])
		return a
	A=f(A)
	B=f(B)
	if A[0][1]<B[0][1]:
		A,B=B,A
	A=A[0][0]
	B.append((0,0))
	B=filter(lambda x:(x[0]!=A),B)[0][0]
	print N-Amoto.count(A)-Bmoto.count(B)
if question=="D":
	pass
if question=="E":
	pass

### FIXED CODE ###

question="A"
input=raw_input
if question=="A":
	t=input()
	t=t.replace("9","n")
	t=t.replace("1","o")
	t=t.replace("n","1")
	t=t.replace("o","9")
	print(t)
if question=="B":
	pass
if question=="C":
	pass
if question=="D":
	pass
if question=="E":
	pass
lst = [1,2,3]
a,b=(int(x) for x in input().split())
lst.remove(a)
lst.remove(b)
print(lst)

### FIXED CODE ###

lst = [1,2,3]
l = [int(input()) for i in range(2)]
lst.remove(l[0])
lst.remove(l[1])
print(lst[0])
n, y = map(int, input().split())

# n, y = 1000, 1234000

flg = False
for i in range(y//10000 + 1):
    if flg:
        break
    for j in range(n-i):
        k = n - i - j
        if i*10000+j*5000+k*1000 == y:
            flg = True
            break
if flg:
    print(f'{i} {j} {k}')
else:
    print('-1 -1 -1')

### FIXED CODE ###

import sys

n, y = map(int, input().split())

# n, y = 1000, 1234000

flg = False
for i in range(y//10000 + 1):
    for j in range(n-i+1):
        k = n - i - j
        if i*10000+j*5000+k*1000 == y:
            print(i, j, k)
            sys.exit(0)
print('-1 -1 -1')
import sys

S = input()
center = len(S) // 2
b = S[center]

if len(S) % 2 == 1:
    for i in range(1, center + 1):
        if S[center + i] != b or S[center - i] != b:
            print(center + i)
            sys.exit()
else:
    for i in range(center + 1):
        if S[center - i] != b or S[center + 1 + i] != b:
            print(center)
            sys.exit()


### FIXED CODE ###

import sys

S = input()
center = len(S) // 2

if len(S) % 2 == 1:
    b = S[center]
    for i in range(1, center + 1):
        if S[center + i] != b or S[center - i] != b:
            print(center + i)
            sys.exit()
else:
    b = S[center - 1]
    for i in range(center):
        if S[center - 1 - i] != b or S[center + i] != b:
            print(center + i)
            sys.exit()
print(len(S))
a = int(input())
A = list(map(int,input().split()))

ch = [1]
t = 0
for e,i in enumerate(A):
    t+=i
    if t>=2**i:
        print(-1)
        exit()

cH = [1]
if A[0]>0:
    print(-1)
    exit()
for e,i in enumerate(A[1:]):
    cH.append(cH[-1]*2-i)
    # ch.append((cH[-1]*2)//(2**i))
# print(ch)
# print(cH)

# ch = ch[:-1]
# ch = ch[::-1]
# ch[0]*=2
# print(ch)
cH = cH[:-1]
cH.append(cH[-1]*2)
cH = cH[::-1]
# print(cH)

if cH[0] 

if 0 in cH:
    print(-1)
    exit()
A = A[::-1]

ans = 0
n = 0
for e,i in enumerate(A[:]):
    # print(n,ch[e],-1)
    if n//2+(n%2!=0)>cH[e]:
        print(-1)
        exit()
    if n  <= cH[e]:
        # print('ans:',ans,'n:',n)
        ans += n+i
        n+=i
    else:
        # print('ans:',ans,'ch:',cH[e],'i:',i)
        ans +=cH[e]+i
        n = cH[e]+i

    # print('ans:',ans,'n:',n)
print(ans)

### FIXED CODE ###



a = int(input())
A = list(map(int,input().split()))

if a == 0 and A[0] == 1:
    print(1)
    exit()
ch = [1]

cH = [1]
if A[0]>0:
    print(-1)
    exit()
for e,i in enumerate(A[1:]):
    cH.append(cH[-1]*2-i)
    # ch.append((cH[-1]*2)//(2**i))
# print(ch)
# print(cH)

# ch = ch[:-1]
# ch = ch[::-1]
# ch[0]*=2
# print(ch)
cH = cH[:-1]
cH.append(cH[-1]*2)
cH = cH[::-1]
# print(cH)
if 0 in cH:
    print(-1)
    exit()
A = A[::-1]

ans = 0
n = 0
for e,i in enumerate(A[:]):
    # print(n,ch[e],-1)
    if n//2+(n%2!=0)>cH[e]:
        print(-1)
        exit()
    if n  <= cH[e]:
        # print('ans:',ans,'n:',n)
        ans += n+i
        n+=i
    else:
        # print('ans:',ans,'ch:',cH[e],'i:',i)
        ans +=cH[e]+i
        n = cH[e]+i

    # print('ans:',ans,'n:',n)
print(ans)
N = int(input())
s = [input() for i in range(N)] 
for i in range(1, N):
  del s[i]
  print(max(s))
  

### FIXED CODE ###

n=int(input())
a=[int(input())for _ in range(n)]
b=sorted(a)
for a in a:print(b[(a<b[-1])-2])
import collections
s_str = input()
s = [int(s_str[i]) for i in range(len(s_str))] #リスト型に文字列を格納します
n = len(s_str)
s_block = []
for k in range(n):
    a = sum(s[i]*10**(n-i-1) for i in range(k,n)) % 2019
    s_block.append(a)
s_dict = list(dict(collections.Counter(s_block)).values())
ans = sum(s_dict[i]*(s_dict[i]-1)/2 for i in range(len(s_dict)))
print(int(ans))

### FIXED CODE ###

s,w = map(int,input().split())
print("safe" if s > w else "unsafe")
n = 
if n==1:
    print("Hello World")
else:
    int(input())
    int(input())
    print(a+b)


### FIXED CODE ###

n =int(input())
if n==1:
    print("Hello World")
else:
    a=int(input())
    b=int(input())
    print(a+b)
h,w=map(int,input().split())
a={}
for i in range(26):
  a[chr(i+97)]=0
for i in range(h):
  s=input()
  for j in s:
    a[j]+=1
if h%2==0 and w%2==0:
  for i in a.values():
    if i%4!=0:print("No");exit()
  print("Yes")
elif h%2==1 and w%2==0:
  cnt=0
  for i in a.values():
    if i%4!=2:cnt+=1
  if cnt>w//2:
    print("No")
  else:print("Yes")
elif h%2==0 and w%2==1:
   cnt=0
  for i in a.values():
    if i%4!=2:cnt+=1
  if cnt>h//2:
    print("No")
  else:print("Yes")
else:
  cnt2=0;cnt1=0
  for i in a.values():
    if i%4==1:cnt1+=1
    elif i%4==2:cnt2+=1
  if cnt1!=1:print("No")
  elif 2*cnt2>h+w-2:print("No")
  else:
    print("Yes")

### FIXED CODE ###

h,w=map(int,input().split())
a={}
for i in range(26):
  a[chr(i+97)]=0
for i in range(h):
  s=input()
  for j in s:
    a[j]+=1
if h==1 and w==1:print("Yes")
elif h%2==0 and w%2==0:
  for i in a.values():
    if i%4!=0:print("No");exit()
  print("Yes")
elif h%2==1 and w%2==0:
  cnt=0
  for i in a.values():
    if i%4==1 or i%4==3:
      print("No");exit()
    if i%4==2:cnt+=1
  if cnt>w//2:
    print("No")
  else:print("Yes")
elif h%2==0 and w%2==1:
  cnt=0
  for i in a.values():
    if i%4==1 or i%4==3:
      print("No");exit()
    if i%4==2:cnt+=1
  if cnt>h//2:
    print("No")
  else:print("Yes")
else:
  cnt3=0;cnt2=0;cnt1=0
  for i in a.values():
    if i%4==1:cnt1+=1
    elif i%4==2:cnt2+=1
    elif i%4==3:cnt3+=1
  if cnt1+cnt3!=1:print("No")
  elif cnt2+cnt3>(h-1)//2+(w-1)//2:print("No")
  else:
    print("Yes")