Harryxun/stf_run huggingface dataset:
# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 9 + 1000000) // 2

while True:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""


### FIXED CODE ###

# (d1+d2)/2 == n1, (d2+d3)/2 == n2... が矛盾なくなるようにする
# にぶたんを使う
# なんかしらんけど3問駄目だな...

n = int(input())
dum = list(map(int, input().split()))
count = 0
l, r = 0, (10 ** 10) // 2

while l < r:
    mid = (l + r) // 2
    # print(l, r, mid)
    rain = [0 for _ in range(n)]
    rain[0] += mid * 2
    for i in range(1, n):
        next_amount = (dum[i - 1] - (rain[i - 1] // 2)) * 2
        rain[i] += next_amount
    # print(rain)

    if dum[-1] == (rain[-1] + rain[0]) // 2:
        rain = list(map(str, rain))
        print(" ".join(rain))
        exit()
    if (rain[0] + rain[-1]) // 2 < dum[-1]:
        # 最初に決めたやつが小さすぎた
        # print("{} は小さすぎた".format(rain[0]))
        l = mid + 1
    else:
        # 最初に決めたやつが大きすぎた
        # print("{} は大きすぎた".format(rain[0]))
        r = mid

    # セーフティネット 必要ないけど
    if count > 50:
        t = 5 / 0
        break
    count += 1

"""
7
110 50 53 50 11 36 88

11
38 7 15 15 9 31 23 1 5 55 81
"""
n, q = list(map(int, input().split(' ')))
inf = [[] for _ in range(n)]
p_list = [0 for _ in range(n)]

for i in range(n-1):
    a, b = list(map(int, input().split(' ')))
    inf[a-1].append(b-1)
    inf[b-1].append(a-1)

for i in range(q):
    p, x = list(map(int, input().split(' ')))
    p_list[p-1] += x

def add_p(num):
    if len(inf[num]) == 0:
        return 0
    for k in inf[num]:
        inf[k].remove(num)
        p_list[k] += p_list[num]
        add_p(k)
    return 0

add_p(0)
print(*p_list)

### FIXED CODE ###

def main():
    n, q = map(int, input().split(' '))
    import sys
    from collections import deque
    sys.setrecursionlimit(10**7)

    visit = [True for _ in range(n)]
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = deque()
    next_visit.append(0)
    visit[0] = False
    counter = 1
    while counter < n:
        t = next_visit.pop()
        for s in dic[t]:
            if visit[s]:
                point[s] += point[t]
                visit[s] = False
                counter += 1
                next_visit.append(s)
    print(*point)
if __name__ == '__main__':
    main()
x = int(input())
y = int(input())
z = int(input())
k = int(input())
a = list(map(int,[input() for i in range(x)]))
b = list(map(int,[input() for i in range(y)]))
c = list(map(int,[input() for i in range(z)]))
d = []
for i in a:
  for j in b:
    for k in c:
      d.append(a+b+c)
d.sort(reverse=True)
for i in range(k):
  print(d[i])

### FIXED CODE ###

import heapq
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
q = []
heapq.heapify(q)
heapq.heappush(q,(-(A[0] + B[0] + C[0]),0,0,0))
for _ in range(K):
    m, i, j, k = heapq.heappop(q) #mに和、ijkにインデックス
    print(-m) #親から取り出すが、親は子よりも小さい、大きい順にするために-を入れている
    if i + 1 < X: #最初にiには０が挿入されている,pythonではインデックスが０から始まるから<xでいい
        s = (-(A[i+1] + B[j] + C[k]), i+1, j, k)
        if s not in q:
            heapq.heappush(q,s)
    if j + 1 < Y:
        s = (-(A[i] + B[j+1] + C[k]), i, j+1, k)
        if s not in q:
            heapq.heappush(q, s)
    if k + 1 < Z:
        s = (-(A[i] + B[j] + C[k+1]), i, j, k+1)
        if s not in q:
            heapq.heappush(q,s)
n,d = map(int, input().split())
X = []
for _ in range(n):
    _x = list(map(int, input().split()))
    X.append(_x)

from itertools import combinations
import numpy as np

ans = 0
for (x1, x2) in combinations(X, 2):
    a = 0
    for i in range(d):
        a += (x1[i]-x2[i])**2 
    a = np.sqrt(a)
    if a.is_integer():
        ans += 1

print(ans)


### FIXED CODE ###

n,d = map(int, input().split())
X = []
for _ in range(n):
    _x = list(map(int, input().split()))
    X.append(_x)

from itertools import combinations
import numpy as np

ans = 0
for (x1, x2) in combinations(X, 2):
    a = 0
    for i in range(d):
        a += (x1[i]-x2[i])**2 
    a = np.sqrt(a)
    if a.is_integer():
        ans += 1

print(ans)
N, M = map(int, input().split())
friends = dict()
for i in range(M):
    a, b = map(int, input().split())
    if friends.get(a) is None:
        friends[a] = set([b])
    else:
        friends[a].add(b)
    if friends.get(b) is None:
        friends[b] = set([a])
    else:
        friends[b].add(a)
ans = max([len(a) for a in friends.values()]) + 1
#print(friends)
print(ans)


### FIXED CODE ###

from collections import deque

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

neighbor = [[] for _ in range(n)]
for edge in edges:
    neighbor[edge[0] - 1].append(edge[1] - 1)  # 1- → 0-index
    neighbor[edge[1] - 1].append(edge[0] - 1)

#print(neighbor)
visited = [-1] * n
ans = 1
for idx in range(n):
    if visited[idx] == -1:
        queue = deque()
        queue.append(idx)
        group_population = 1
        visited[idx] = 0
        while len(queue) > 0:
            vertex = queue.popleft()
            for nei in neighbor[vertex]:
                if visited[nei] == -1:
                    visited[nei] = 0
                    queue.append(nei)
                    group_population += 1

    ans = max(ans, group_population)

print(ans)
import copy
n, m = map( int, input().split() )
connect = []

for _ in range( n+1 ):
    connect.append( [ 0 ] * ( n+1 ) )

for _ in range( m ):
    a, b = map( int, input().split() )
    connect[ a ][ b ] = 1
    connect[ b ][ a ] = 1

guide = [ 0 ] * ( n+1 )
path = [ 0, 0 ] + [ m+1 ] * ( n-1 )
unvisited = [ a for a in range( 1, n+1 ) ]

def solve( a, unvisited ): # aに隣接したやつのguideをaにする．またそれのpathをpath[a]+1にする．
    # print( "calc " + str(a) )
    # print( "unvisited " + str(unvisited) )
    for b in unvisited:
        if connect[a][b] == 1 and path[a] + 1 < path[b]:
            # print( "update " + str(b) )
            path[b] = path[a] + 1
            guide[b] = a
            next_unvisited = copy.deepcopy( unvisited )
            next_unvisited.remove( a )
            # print( next_unvisited )
            solve( b, list( next_unvisited)  )

solve( 1, list( unvisited ) )

# print( guide, path )
if 0 not in guide[2:]:
    print( "Yes" )
    for i in range( 2, n+1 ):
        print( guide[i] )
else:
    print( "No" )

### FIXED CODE ###

####以下カンニング####
n, m = map( int, input().split() )
connect = {}

for _ in range( m ):
    a, b = map( int, input().split() )
    try:
        connect[ a ].append( b )
    except KeyError:
        connect[ a ] = [ b ]
    try:
        connect[ b ].append( a )
    except KeyError:
        connect[ b ] = [ a ]

queue = [ 1 ]
guide = [ -1 ] * ( n+1 )
visited = [ False ] * ( n+1 )

while queue:
    x = queue.pop(0)
    for y in connect[ x ]:
        if visited[ y ] == False:
            queue.append( y )
            guide[ y ] = x
            visited[ y ] = True

print( "Yes" )
for x in range( 2, n+1 ):
    print( guide[x] )
N = int(input())
An = list(map(int, input().split()))
count = 0
while all(an % 2 == 0 for an in nA):
    count += 1
    An = [an/2 for an in An]
    
print(count)

### FIXED CODE ###

a, b = map(int, input().split())
print('Odd' if a*b % 2 else 'Even')
#ABC166
N,M=map(int,input().split())
H =list(map(int,input().split()))  #展望台の標高
A = list(range(1,N+1))
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        A[b] = 0
    elif H[a-1] < H[b-1]:
        A[a] = 0
    else:
        A[a] = 0
        A[b] = 0
print(N-A.count(0))

### FIXED CODE ###

#ABC166
N,M=map(int,input().split())
H =list(map(int,input().split()))  #展望台の標高
A = list(range(1,N+1))
for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        A[b-1] = 0
    elif H[a-1] < H[b-1]:
        A[a-1] = 0
    else:
        A[a-1] = 0
        A[b-1] = 0
print(N-A.count(0))
# -*- coding: utf-8 -*-

def input_converter(key_string):
    key_string = key_string.replace('A', '1')
    key_string = key_string.replace('T', '2')
    key_string = key_string.replace('C', '3')
    key_string = key_string.replace('G', '4')
    return int(key_string)


class HashTable(object):
    def __init__(self, hash_size = 2 ** 30):
        self.hash_size = hash_size
        self.hash_array = [None] * self.hash_size

    def insert_value(self, data, key):
        collision_number = 0
        next_index = self.hash_function(key, collision_number)
        while self.hash_array[next_index] is not None:
            collision_number += 1
            next_index = self.hash_function(key, collision_number)
        # print self.hash_array[next_index]
        self.hash_array[next_index] = data

    def search_value(self, data, key):
        collision_number = 0
        next_index = self.hash_function(key, collision_number)
        next_data = self.hash_array[next_index]
        while True:
            if (next_data is None) or (collision_number > self.hash_size):
                return False
            elif next_data == data:
                return True
            else:            
                collision_number +=1
                next_index = self.hash_function(key, collision_number)
                next_data = self.hash_array[next_index]

    def hash_function(self, key, collision_number):
        def h1(key):
            return key % self.hash_size
    
        def h2(key):
            return key % (self.hash_size - 1)

        return (h1(key) + collision_number * h2(key)) % self.hash_size


def main():
    input_size = int(raw_input())
    hash_table = HashTable()
    counter = 0
    while counter < input_size:
        command, key = raw_input().split(' ')
        if command == 'insert':
            hash_table.insert_value(key, input_converter(key))
        else:
            if hash_table.search_value(key, input_converter(key)):
                print 'yes'
            else:
                print 'no'
        counter += 1


if __name__ == '__main__':
    main()

### FIXED CODE ###

# -*- coding: utf-8 -*-

dictionary = {}
input_num = int(raw_input())
counter = 0
while counter < input_num:
    command, key = raw_input().split(' ')
    if command == 'insert':
        dictionary[key] = None
    else:
        if key in dictionary:
            print 'yes'
        else:
            print 'no'

    counter += 1
import numpy as np
N=input()
if N%2==0:
  answer = 1.0/2
else:
  answer = ((N-1)/2 + 1) /(N-1)/2
print(answer) 
 

### FIXED CODE ###

N=int(input())
if N%2==0:
  answer = 1.0/2
else:
  answer = ((N-1)/2 + 1) /N
print(answer)
s = list(input())
a = {'1': '0', '0': '1'}
if len(s) == 1:
    print(0)
else:
    r = 0
    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            r += 1
            s[i+1] = a[s[i]]
print(r)


### FIXED CODE ###

s = list(input())
a = {'1': '0', '0': '1'}
if len(s) == 1:
    print(0)
else:
    r = 0
    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            r += 1
            s[i+1] = a[s[i]]
    print(r)
import heapq
from collections import defaultdict
cnt = defaultdict(int)
N = int(input())
A = list(map(int, input().split()))
# A = []
# for i in range(N):
#     A.append(int(input()))
ans = 0
_ans = []
buff = [0 for i in range(N)]
for i in range(N-1, -1, -1):
    if i > N//2:
        buff[i] = A[i]
    else:
        _m = 0
        # for j in range(i, N, max(1, i)):
        #     _m += buff[j]
        # _m = sum(buff[i:N])
        for j in range(i*2, N, max(1, i)):
            _m += buff[j]
        if _m % 2 != A[i]:
            buff[i] = 1
            ans += 1
            _ans.append(i+1)

mm = 0
for i in range(ans):
    if buff[i] == 1:
        mm = i

print(sum(buff))
print(*_ans)

### FIXED CODE ###

N = int(input())
A = []

for i in range(N):
    A.append(int(input()))

buff = A.copy()
buff.sort()
buff = buff[::-1]

for i in range(N):
    if A[i] == buff[0]:
        print(buff[1])
    else:
        print(buff[0])
Length = int(input())
inputString = input()
SpecialIndex = int(input())

for i in inputString:
  if i != inputString[SpecialIndex-1]:
    inputString[i] = "*"
print(inputString)

### FIXED CODE ###

Length = int(input())
inputString = input()
SpecialIndex = int(input())
SpecialChar = inputString[SpecialIndex-1]
answer = ""
for i in inputString:
  if i != SpecialChar:
    answer += "*"
  else:
    answer += i
print(answer)
T = str(input())
T=list(T)
if not T[0]=='?':
    for i in range(1,len(T)-1):
        if T[i]=='?':
            if T[i-1]=='D' and T[i+1]=='D':
                T[i]='P'
            else:
                T[i]='D'
    if T[len(T)-1]=='?':
        T[len(T)-1]='D'
else:
    T[0]='D'
    for i in range(1,len(T)-1):
        if T[i]=='?':
            if T[i-1]=='D' and T[i+1]=='D':
                T[i]='P'
            else:
                T[i]='D'
    if T[len(T)]=='?':
        T[len(T)]='D'

print(''.join(T))

### FIXED CODE ###

T = str(input())
T=list(T)
if not T[0]=='?':
    for i in range(1,len(T)-1):
        if T[i]=='?':
            if T[i-1]=='D' and T[i+1]=='D':
                T[i]='P'
            else:
                T[i]='D'
    if T[len(T)-1]=='?':
        T[len(T)-1]='D'
else:
    T[0]='D'
    for i in range(1,len(T)-1):
        if T[i]=='?':
            if T[i-1]=='D' and T[i+1]=='D':
                T[i]='P'
            else:
                T[i]='D'
    if T[len(T)-1]=='?':
        T[len(T)-1]='D'

print(''.join(T))
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
itta2 = set([])
mati = 1
i = 0
itta = []
t0 = time.time()
while True:
    if mati in itta2:
        saisyo = mati
        break
    else:
        itta2.add(mati)
        itta.append(mati)
        mati = c[mati-1]
        i += 1
print(time.time()-t0)
risuto2 = set([])
risuto = []
t0 = time.time()

while True:
    if mati in risuto2:
        break
    else:
        risuto2.add(mati)
        risuto.append(mati)
        mati = c[mati-1]
print(time.time()-t0)
if b <= i-1:
    print(itta[b])
else:
    print(risuto[(b-i) % len(risuto)])

### FIXED CODE ###

a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
itta2 = set([])
mati = 1
i = 0
itta = []
while True:
    if mati in itta2:
        saisyo = mati
        break
    else:
        itta2.add(mati)
        itta.append(mati)
        mati = c[mati-1]
        i += 1
risuto2 = set([])
risuto = []

while True:
    if mati in risuto2:
        break
    else:
        risuto2.add(mati)
        risuto.append(mati)
        mati = c[mati-1]
if b <= i-1:
    print(itta[b])
else:
    print(risuto[(b-i) % len(risuto)])
s = list(input())
k = int(input())
number = 0
count = 0
for i in range(k):
    if s[i] == "1":
        count += 1
        if count == k - 1:
            number = 1
    elif s[i] != "1" and number == 0:
        number = s[i]
print(number)


### FIXED CODE ###

s = list(input())
k = int(input())
for i in range(min(len(s), k)):
    if s[i] != "1":
        print(s[i])
        exit()
print(1)
import math
N,T  = list(map(int,input().split()))
#d = int(T / N)
m = 1
def ans():
    for i in range(1,int(math.sqrt(T))):    
            if T % i ==0:
                m = max(1,i)
    print (m)
if T % N == 0:
    print (d)
else:
    ans()
    

### FIXED CODE ###

N,T  = list(map(int,input().split()))
d = int(T / N)
def ans():
    for i in range(d+1,0,-1):    
            if T % i ==0:
                print(i)
                break
if T % N == 0:
    print (d)
else:
    ans()
S=[]
for char in input():
  S.append(char)
  
#route 1
C1=0
for i in range(len(S)):
  if i%2==0:
    if S[i]==1:
      S[i]=0
      C1+=1
  else:
    if S[i]==0:
      S[i]=1
      C1+=1

S=[]
for char in input():
  S.append(char)
#route 2
C2=0
for n in range(len(S)):
  if n%2==0:
    if S[n]==0:
      S[n]=1
      C2+=1
  else:
    if S[n]==1:
      S[n]=0
      C2+=1

if C1>=C2:
  print(C1)
else:
  print(C2)

### FIXED CODE ###

S=[]
for char in input():
  S.append(char)
#route 1
C1=0
for i in range(len(S)):
  if i%2==0:
    if S[i]=='1':
      C1+=1
  else:
    if S[i]=='0':
      C1+=1

#route 2
C2=0
for n in range(len(S)):
  if n%2==0:
    if S[n]=='0':
      C2+=1
  else:
    if S[n]=='1':
      C2+=1

if C2>=C1:
  print(C1)
else:
  print(C2)
kazu = input()
nums = list(map(int, input().split()))
count = 0
flg = True
while flg:
  for i in range(kazu):
    if nums[i] % 2 == 1:
      flg = False
      break
    else:
      nums[i] /= 2
      count += 1
print(count)
      

### FIXED CODE ###

kazu = int(input())
nums = list(map(int, input().split()))
count = 0
flg = True
while flg:
  for i in range(kazu):
    if nums[i] % 2 == 1:
      flg = False
      break
    else:
      nums[i] /= 2
  count += 1
count -= 1
print(count)
def readint():
    for line in sys.stdin:
        yield map(int,line.split())

def gcd(x,y):
    [x,y] = [max(x,y),min(x,y)]
    z = x % y
    while z > 0:
        [x,y,z] = [y,z,x % y]
    return y

for [x,y] in readint():
    GCD = gcd(x,y)
    mx = x/GCD
    print GCD,mx*y

### FIXED CODE ###

import sys

def readint():
    for line in sys.stdin:
        yield map(int,line.split())

def gcd(x,y):
    [x,y] = [max(x,y),min(x,y)]
    while 1:
        z = x % y
        if z == 0:
            break
        [x,y] = [y,z]
    return y

for [x,y] in readint():
    GCD = gcd(x,y)
    mx = x/GCD
    print GCD,mx*y
N,D = map(int,input(),split()))
a = (N-1)/(2*D)
if (N-1)%(2*D)==0:
	print(a)
else :
 	print((N-1)//2*D+1)

### FIXED CODE ###

N,D = map(int,input().split())
a = N//(2*D+1)
if N%(2*D+1) == 0:
	print(a)
else:
 	print(a+1)
import math

n = int(input())
balls = [tuple(map(int, input().split())) for _ in range(n)]


def katamuki(balla, ballb):
    xa, ya = balla
    xb, yb = ballb
    x, y = (xa - xb), (ya - yb)
    dir = math.sqrt(y ** 2 + x ** 2)
    if x == 0:
        return 1.0, dir
    if y == 0:
        return 0.0, dir
    if y / x == -1.0:
        return 1.0, dir
    return y / x, dir


a = []
for i in range(0, n - 1):
    for j in range(i + 1, n):
        a.append(katamuki(balls[i], balls[j]))

a.sort()
tmp = a[0]
cnt = 0
ans = []
a.append(10000000)
for i in range(len(a)):
    if a[i] == tmp:
        cnt += 1
    else:
        ans.append(cnt)
        tmp = a[i]
        cnt = 1

print(n - max(ans))


### FIXED CODE ###

import collections


def calc(balla, ballb):
    xa, ya = balla
    xb, yb = ballb
    return xa - xb, ya - yb


n = int(input())
balls = [tuple(map(int, input().split())) for _ in range(n)]

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

a = []
for i in range(0, n - 1):
    for j in range(i + 1, n):
        tmp = calc(balls[i], balls[j])
        a += [tmp, tuple(-i for i in tmp)]
counts = collections.Counter(a)

print(n - max(counts.values()))
N, K=map(int,input().split())
S=list(input())
S[K] = S[K].lower()
print(''.join(S))

### FIXED CODE ###

N, K=map(int,input().split())
S=list(input())
S[K-1] = S[K-1].lower()
print(''.join(S))
n = int(input())
t, a = map(int, input().split())
list = [int(i) for i in input().split()]

dif_list = []
answer = 0

for i in range(n):
    t_i = t - list(i) * 0.006
    t_i_dif = abs(a - t_i)
    dif_list.append(t_i_dif)
    if min(dif_list) == t_i_dif:
        answer = i + 1

print(answer)


### FIXED CODE ###

n = int(input())
t, a = map(int, input().split())
list = [int(i) for i in input().split()]

dif_list = []
answer = 0

for i in range(n):
    t_i = t - list[i] * 0.006
    t_i_dif = abs(a - t_i)
    dif_list.append(t_i_dif)
    if min(dif_list) == t_i_dif:
        answer = i + 1

print(answer)
#include <iostream>
#include <vector>
#include <string>
#include <functional>
using namespace std;
using ll = long long;

int N, M;
int dp[10001] = {};
vector<ll> A;
ll cost[] = {0,2,5,5,4,5,6,3,7,6};
string ans = "";
int tmp;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;

    for (int m = 0; m < M; ++m) {
        cin >> tmp;
        A.push_back(tmp);  
    }
    sort(A.begin(), A.end(), greater<int>());

    for (int n = 2; n <= N; ++n) {
        for (auto e : A) {
            if (n >= cost[e])
                dp[n] = max(dp[n], dp[n - cost[e]] + 1);
        }
    }

    int remained = N;
    while (remained > 0) {
        for (auto e : A) {
            if (dp[remained - cost[e]] == dp[remained] - 1) {
                if (remained < cost[e]) continue;
                if (1 == dp[remained])
                    if (remained != cost[e]) continue;
                ans += to_string(e); 
                remained -= cost[e]; 
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
dp = [0]
cost = [0,2,5,5,4,5,6,3,7,6]
for i in range(1, N+1):
    dp.append(-(2<<10))
    for a in A:
        if i >= cost[a]: 
            dp[i] = max(dp[i - cost[a]] + 1, dp[i])
ans = ""
while N > 0:
    for e in A:
        if N >= cost[e] and dp[N] - 1 == dp[N - cost[e]]:
            if dp[N] == 1:
                if N != cost[e]: continue
            N -= cost[e]
            ans += str(e)
            break
print(ans)
import numpy as np
S = input()

MOD = 10 ** 9 + 7
mod_change_table = [(i * 10) % 13 for i in range(13)]
dp = np.array([[0] * 13] * (len(S)))
if S[0] == '?':
    dp[0][:10] = 1
else:
    dp[0][int(S[0])] = 1

for i in range(1, len(S)):
    for j in range(13):
        if S[i] == '?':
            for k in range(10):
                dp[i][(mod_change_table[j] + k) % 13] += dp[i - 1][j]
        else:
            dp[i][(mod_change_table[j] + c) % 13] += dp[i - 1][j]
    dp[i] %= MOD
print(dp[len(S) - 1][5])

### FIXED CODE ###

r = [[(j - k) * 9 % 13 for j in range(10)] for k in range(13)]
d = [1] + [0] * 12
M = 10 ** 9 + 7
for c in input():
    if c == '?':
        d = [sum(d[j] for j in k) % M for k in r]
    else:
        d = [d[(int(c) - k) * 9 % 13] for k in range(13)]
    #print(d)
print(d[5])
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
if cur == N:
  return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))


### FIXED CODE ###

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
inf = 10 ** 9

def dfs(cur, a, b, c):
  if cur == N:
    if min(a, b, c) > 0:
      return abs(a - A) + abs(b - B) + abs(c - C) - 30 
    else:
      return inf
  else:  
    ret0 = dfs(cur + 1, a, b, c) 
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))