TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
from collections import defaultdict
from operator import itemgetter

n, a, b, c, *L = map(int, open(0).read().split())
L.sort()
A = [a, b, c]
dicts = [defaultdict(lambda: 10**5) for _ in range(3)]
for i in range(n-2):
    for x in combinations(enumerate(L), i+1):
        k = tuple(i for i, l in x)
        v = sum(l for i, l in x)
        for d, x in zip(dicts, A):
            d[k] = min(d[k], abs(x-v) + 10*i)
scores = [sorted(d.items(), key=itemgetter(1)) for d in dicts]

ans = 10**5
for p1, p2, p3 in permutations(range(3)):
    k1, v1 = scores[p1][0]
    k1 = set(k1)
    for k2, v2 in scores[p2]:
        k2 = set(k2)
        if len(k1 & k2) == 0:
            break
    for k3, v3 in scores[p3]:
        k3 = set(k3)
        if len(k1 & k3) + len(k2 & k3) == 0:
            break
    ans = min(ans, sum([v1, v2, v3]))
print(ans)

from collections import defaultdict
from itertools import combinations, permutations
from operator import itemgetter
n, a, b, c, *L = map(int, open(0).read().split())
L.sort()
A = [a, b, c]
dicts = [defaultdict(lambda: 10**5) for _ in range(3)]
for i in range(n-2):
    for x in combinations(enumerate(L), i+1):
        k = tuple(i for i, l in x)
        v = sum(l for i, l in x)
        for d, x in zip(dicts, A):
            d[k] = min(d[k], abs(x-v) + 10*i)
scores = [sorted(d.items(), key=itemgetter(1)) for d in dicts]

ans = 10**5
for p1, p2, p3 in permutations(range(3)):
    k1, v1 = scores[p1][0]
    k1 = set(k1)
    for k2, v2 in scores[p2]:
        k2 = set(k2)
        if len(k1 & k2) == 0:
            break
    for k3, v3 in scores[p3]:
        k3 = set(k3)
        if len(k1 & k3) + len(k2 & k3) == 0:
            break
    ans = min(ans, sum([v1, v2, v3]))
print(ans)

Verdicts: Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
from itertools import product

import numpy as np

N, A, B, C = (int(i) for i in input().split())
l = []

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

l = np.array(l)

###########



min_cost = 1e10

for i in product(np.arange(4), repeat=N):
    i = np.array(i)

    if(len(np.unique(i)) != 4):
        continue

    for_a = l[i == 0]
    for_b = l[i == 1]
    for_c = l[i == 2]

    A_diff = np.abs(np.sum(for_a) - A) + (len(for_a) - 1) * 10
    B_diff = np.abs(np.sum(for_b) - B) + (len(for_b) - 1) * 10
    C_diff = np.abs(np.sum(for_c) - C) + (len(for_c) - 1) * 10

    cost = A_diff + B_diff + C_diff

    if(cost < min_cost):
        min_cost = cost

print(min_cost)

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))


Verdicts: Wrong Answer

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
N,A,B,C = map(int,input().split())
l = [input() for i in range(N)]
INF = 10 ** 9

def ans(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 = ans(cur + 1,a,b,c) 
    ret1 = ans(cur + 1,a + l[cur],b,c) + 10
    ret2 = ans(cur + 1,a,b + l[cur],c) + 10
    ret3 = ans(cur + 1,a,b,c + l[cur]) + 10

    return min(ret0,ret1,ret2,ret3)

print(ans(0,0,0,0))







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

def ans(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 = ans(cur + 1,a,b,c) 
    ret1 = ans(cur + 1,a + l[cur],b,c) + 10
    ret2 = ans(cur + 1,a,b + l[cur],c) + 10
    ret3 = ans(cur + 1,a,b,c + l[cur]) + 10

    return min(ret0,ret1,ret2,ret3)

print(ans(0,0,0,0))







Verdicts: Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
N, A, B, C = map(int, input().split())
l = [int(input()) for _ 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))

N, A, B, C = map(int, input().split())
l = [int(input()) for _ 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(defs(0, 0, 0, 0))

N, A, B, C = map(int, input().split())
l = [int(input()) for _ 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))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
def rec (i,a,b,c):
    if i==N:
        if a==0 and b==0 and c==0:
            return INF
        else:
            return abs(a-A)+abs(b-B)+abs(c-C)
    res = rec(i+1,a,b,c)
    
    res = min(res,rec(i+1,a+L[i],b,c)+(10 if a>0 else 0))
    res = min(res,rec(i+1,a,b+L[i],c)+(10 if b>0 else 0))
    res = min(res,rec(i+1,a,b,c+L[i])+(10 if c>0 else 0))
    
    return res
N,A,B,C = list(map(int,input().split()))
L = [int(input()) for _ in range(N)]
print(rec(0,0,0,0))

def rec (i,a,b,c):
    if i==N:
        if a==0 or b==0 or c==0:
            return INF
        else:
            return abs(a-A)+abs(b-B)+abs(c-C)
    res = rec(i+1,a,b,c)
    
    res = min(res,rec(i+1,a+L[i],b,c)+(10 if a>0 else 0))
    res = min(res,rec(i+1,a,b+L[i],c)+(10 if b>0 else 0))
    res = min(res,rec(i+1,a,b,c+L[i])+(10 if c>0 else 0))
    
    return res
N,A,B,C = list(map(int,input().split()))
INF=10**8
L = [int(input()) for _ in range(N)]
print(rec(0,0,0,0))

Verdicts: Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
from itertools import combinations
N,A,B,C=map(int,input().split())
l = []
for i in range(N):
    l.append(int(input()))
input_l = list(map(list,combinations(l,3)))
except_l = [l[:] for _ in range(len(input_l))]
for i in range(len(input_l)):
    except_l[i].remove(input_l[i][0])
    except_l[i].remove(input_l[i][1])
    except_l[i].remove(input_l[i][2])
print(input_l)
print(except_l)

n,a,b,c = list(map(int,input().split()))
l = []
ans = []
for i in range(n):
    l.append(int(input()))

def f(x,y,z,arr,cnt):
    global a
    global b
    global c
    global ans
    if arr:
        f(x + arr[0], y, z, arr[1:],cnt+1)
        f(x, y + arr[0], z, arr[1:],cnt+1)
        f(x, y, z + arr[0], arr[1:],cnt+1)
        f(x, y, z, arr[1:],cnt)
    else:
        if x > 0 and y > 0 and z > 0:
            ans.append(abs(a-x) + abs(b-y) + abs(c-z) + 10 * (cnt - 3))
f(0,0,0,l,0)
print(min(ans))

Verdicts: Wrong Answer

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
N, A, B, C = map(int, input().split())
ls = [int(input()) for i in range(N)]

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 10**9
  ret0 = dfs(cur+1, a+ls[cur], b, c)
  ret1 = dfs(cur+1, a, b+ls[cur], c)
  ret2 = dfs(cur+1, a, b, c+ls[cur])
  ret3 = dfs(cur+1, a, b, c)
  return min(ret0, ret1, ret2, ret3)
print(dfs(0,0,0,0))

N, A, B, C = map(int, input().split())
ls = [int(input) for i in range(N)]

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 10**9
  ret0 = dfs(cur+1, a+ls[cur], b, c)
  ret1 = dfs(cur+1, a, b+ls[cur], c)
  ret2 = dfs(cur+1, a, b, c+ls[cur])
  ret3 = dfs(cur+1, a, b, c)
  return min(ret0, ret1, ret2, ret3)
print(dfs(0,0,0,0))

N, A, B, C, *L = map(int, open('0').read().split())
ans = float('inf')
for i in range(4**N):
  a = 0
  b = 0
  c = 0
  m = 0
  for j in range(N):
    if i%4==0:
      if a!=0:
        m += 10
      a += L[j]
    elif i%4==1:
      if b!=0:
        m += 10
      b += L[j]
    elif i%4==2:
      if c!=0:
        m += 10
      c += L[j]
    i //= 4
  if a==0 or b==0 or c==0:
    continue
  ans = min(ans, m+abs(A-a)+abs(B-b)+abs(C-c))
print(ans)

N, A, B, C, *L = map(int, open(0).read().split())
ans = float('inf')
for i in range(4**N):
  a = 0
  b = 0
  c = 0
  m = 0
  for j in range(N):
    if i%4==0:
      if a!=0:
        m += 10
      a += L[j]
    elif i%4==1:
      if b!=0:
        m += 10
      b += L[j]
    elif i%4==2:
      if c!=0:
        m += 10
      c += L[j]
    i //= 4
  if a==0 or b==0 or c==0:
    continue
  ans = min(ans, m+abs(A-a)+abs(B-b)+abs(C-c))
print(ans)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):

N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]

INF = 10 ** 9


def dfs(cursor, a, b, c):  
    if cursor == N:  
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    
    # dfs(0,0,0)
    
    
    
    

    
    
    no_compound_pattern = dfs(cursor, a, b, c)
    compound_a_pattern = dfs(cursor, a + L[cursor], b, c)
    compound_b_pattern = dfs(cursor, a, b + L[cursor], c)
    compound_c_pattern = dfs(cursor, a, b, c + L[cursor])

    
    
    return min(no_compound_pattern, compound_a_pattern, compound_b_pattern, compound_c_pattern)


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



N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]

INF = 10 ** 9


def dfs(cursor, a, b, c):  
    if cursor == N:  
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    
    # dfs(0,0,0)
    
    
    
    

    
    
    no_compound_pattern = dfs(cursor, a, b, c)
    compound_a_pattern = dfs(cursor, a+L[cursor], b, c)
    compound_b_pattern = dfs(cursor, a, b+L[cursor], c)
    compound_c_pattern = dfs(cursor, a, b, c+L[cursor])

    
    
    return min(no_compound_pattern,compound_a_pattern,compound_b_pattern,compound_c_pattern)





N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]

INF = 10 ** 9


def dfs(cursor, a, b, c):  
    if cursor == N:  
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    
    # dfs(0,0,0)
    
    
    
    

    
    
    no_compound_pattern = dfs(cursor+1, a, b, c)
    compound_a_pattern = dfs(cursor+1, a + L[cursor], b, c)+10
    compound_b_pattern = dfs(cursor+1, a, b + L[cursor], c)+10
    compound_c_pattern = dfs(cursor+1, a, b, c + L[cursor])+10

    
    
    return min(no_compound_pattern, compound_a_pattern, compound_b_pattern, compound_c_pattern)


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


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
N,A,B,C = map(int,input().split())
l = [int(input()) for _ in range(N)]

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 10**9
    ret0 = dfs(cur+1,a,b,c)
    ret1 = dfs(cur+1,a+l[cur],b,c)
    ret2 = dfs(cur+1,a,b+l[cur],c)
    ret3 = dfs(cur+1,a,b,c+l[cur])
    return min(ret0,ret1,ret2,ret3)
print(dfs(0,0,0,0))

N,A,B,C = map(int,input().split())
l = [int(input()) for _ in range(N)]

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 10**9
    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))

Verdicts: Wrong Answer

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
N,A,B,C=map(int,input().split())

l=[int(input()) for i in range(N)]

INF=3000

def mp(co,a,b,c):
    if co==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF

    ret0=mp(co+1,a,b,c)
    ret1=mp(co+1,a+1,b,c)+10
    ret2=mp(co+1,a,b+1,c)+10
    ret3=mp(co+1,a,b,c+1)+10

    return min(ret0,ret1,ret2,ret3)

print(mp(0,0,0,0))
N,A,B,C=map(int,input().split())

l=[int(input()) for i in range(N)]

INF=3000

def mp(co,a,b,c):
    if co==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF

    ret0=mp(co+1,a,b,c)
    ret1=mp(co+1,a+1,b,c)+10
    ret2=mp(co+1,a,b+1,c)+10
    ret3=mp(co+1,a,b,c+1)+10

    return min(ret0,ret1,ret2,ret3)

print(mp(0,0,0,0))


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

l=[int(input()) for i in range(N)]

INF=3000

def mp(c,a,b,c):
    return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF

    ret0=mp(c+1,a,b,c)
    ret1=mp(c+1,a+1,b,c)+10
    ret2=mp(c+1,a,b+1,c)+10
    ret3=mp(c+1,a,b,c+1)+10

    return min(ret0,ret1,ret2,ret3)

print(mp(0,0,0,0))


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

l=[int(input()) for i in range(N)]

INF=3000

def mp(c,a,b,c):
    if c==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF

    ret0=mp(c+1,a,b,c)
    ret1=mp(c+1,a+1,b,c)+10
    ret2=mp(c+1,a,b+1,c)+10
    ret3=mp(c+1,a,b,c+1)+10

    return min(ret0,ret1,ret2,ret3)

print(mp(0,0,0,0))


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

l=[int(input()) for i in range(N)]

inf=3000

def mp(g,a,b,c,):
    if g==N:
        return abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c)>0 else inf

    l0=mp(g+1,a+l[g],b,c)+10
    l1=mp(g+1,a,b+l[g],c)+10
    l2=mp(g+1,a,b,c+l[g])+10
    l3=mp(g+1,a,b,c)
    
    return min(l0,l1,l2,l3)

print(mp(0,0,0,0))



Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C = I()
l = [i() for _ in range(N)]
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))

import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,A,B,C = I()
l = [i() for _ in range(N)]
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))

Verdicts: Wrong Answer

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
n,a,b,c=map(int,input().split())
l=[]
for i in range(n):
  l.append(int(input()))
list2=[]
s=0
for i in range(4):
  list=[0,0,0,0]
  list[i]+=l[0]
  if i!=3:
    s+=10
  for j in range(4):
    list[j]+=l[1]
    if j!=3:
      s+=10
      for o in range(4):
        list[o]+=l[2]
        if o!=3:
          s+=10
          for p in range(4):
            list[p]+=l[3]
            if p!=3:
              s+=10
              for u in range(4):
                list[u]+=l[4]
                if u!=3:
                  s+=10                 
                  for t in range(4):
                    list[t]+=l[5]
                    if t!=3:
                      s+=10
                      for r in range(4):
                        list[r]+=l[6]
                        if r!=3:
                          s+=10
                          for q in range(4):
                            list[q]+=l[7]
                            if q!=3:
                              s+=10
                            if list[0]==0 or list[1]==0 or list[2]==0:
                              pass
                            else:
                              list2.append(abs(a-list[0])+abs(b-list[1])+abs(c-list[2]))
print(min(list2))
                        
                      

  

  
  


           

n,a,b,c=map(int,input().split())
l=[]
for i in range(n):
  l.append(int(input()))
bit=[]
for i in range(1,4**n):
  bl=[]
  num=i
  while num!=0:
    bl.append(num%4)
    num=num//4
  while len(bl)<n:
    bl.append(0)
  bit.append(bl)
min=10**10
for i in bit:
  bit1=i
  l1=0
  l2=0
  l3=0
  c1,c2,c3=0,0,0
  for j in range(n):
    if bit1[j]==0:
      l1+=l[j]
      c1+=1
    elif bit1[j]==1:
      l2+=l[j]
      c2+=1
    elif bit1[j]==2: 
      l3+=l[j]
      c3+=1
  if l1==0 or l2==0 or l3==0:
    pass
  else:
    ans=0
    ans+=(c1+c2+c3-3)*10
    ans+=abs(a-l1)+abs(b-l2)+abs(c-l3)
    if min>ans:
      min=ans
print(min)

Verdicts: Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

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

def magic(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
    
    ret0 = magic(cur+1, a, b, c)
    ret1 = magic(cur+1, a+l[cur], b, c) + 10
    ret2 = magic(cur+1, a, b+l[cur], c) + 10
    ret3 = magic(cur+1, a, b, c+l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(magic(ret0, ret1, ret2, ret3)

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))

Verdicts: Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]
cnt = 0
for k in [a,b,c]:
    ans = 0
    for i in range(1, 257):
        s = 0
        for j in range(n):
            if i & 2**j:
                if s > 0:
                    s += 10
                s += l[j]
        v = abs(k - s)
        if v < ans:
            ans = v
            x = i
    cnt += ans
    for j in range(n):
        if x & 2**j:
            l[j] = 0
print(cnt)

n,a,b,c = map(int, input().split())
l = [int(input()) for _ in range(n)]
def dfs(k,p,q,r):
  if k == n:
    if min(a,b,c) > 0:
      return abs(p-a)+abs(q-b)+abs(r-c)-30
    else:
      return 10**5
  t1 = dfs(k+1,p,q,r)
  t2 = dfs(k+1,p+l[k],q,r)+10
  t3 = dfs(k+1,p,q+l[k],r)+10
  t2 = dfs(k+1,p,q,r+l[k])+10
  return min(t1,t2,t3,t4)

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

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]
cnt = 0
for k in [a,b,c]:
    ans = 100000
    for i in range(1, 2**n+1):
        s = 0
        for j in range(n):
            if i & 2**j:
                if s > 0:
                    s += 10
                s += l[j]
        v = abs(k - s)
        if v < ans:
            ans = v
            mast = i
    cnt += ans
    for j in range(n):
        if mast & 2**j:
            l[j] = 0
print(cnt)

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]
cnt = 0
for k in [a,b,c]:
    ans = 0
    for i in range(1, 257):
        s = 0
        for j in range(7):
            if i & 2**j:
                if s > 0:
                    s += 10
                s += l[j]
        v = abs(k - s)
        if v < ans:
            ans = v
            x = i
    cnt += ans
    for j in range(7):
        if x & 2**j:
            l[j] = 0
print(cnt)

n,a,b,c = map(int, input().split())
l = [int(input()) for _ in range(n)]
def dfs(k,p,q,r):
  if k == n:
    if min(p,q,r) > 0:
      return abs(p-a)+abs(q-b)+abs(r-c)-30
    else:
      return 10**7
  t1 = dfs(k+1,p,q,r)
  t2 = dfs(k+1,p+l[k],q,r)+10
  t3 = dfs(k+1,p,q+l[k],r)+10
  t4 = dfs(k+1,p,q,r+l[k])+10
  return min(t1,t2,t3,t4)

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


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
n,A,B,C=map(int,input().split())
bam=[]
for i in range(n):
    bam.append(int(input()))
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == n: 
        print(str(cur)+" "+str(a)+" "+str(b)+" "+str(c))
        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 + bam[cur], b, c) + 10 
    ret2 = dfs(cur + 1, a, b + bam[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + bam[cur]) + 10
    print(min(ret0, ret1, ret2, ret3))
    return min(ret0, ret1, ret2, ret3)

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

n,A,B,C=map(int,input().split())
bam=[]
for i in range(n):
    bam.append(int(input()))
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == n: 
        #print(str(cur)+" "+str(a)+" "+str(b)+" "+str(c))
        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 + bam[cur], b, c) + 10 
    ret2 = dfs(cur + 1, a, b + bam[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + bam[cur]) + 10
    #print(min(ret0, ret1, ret2, ret3))
    return min(ret0, ret1, ret2, ret3)

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

Verdicts: Wrong Answer

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
N,A,B,C = map(int, input().split())
l = list(map(int, input().split()))
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 10**9
    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))

N,A,B,C = map(int, input().split())
l = [int(input()) for i in range(N) ]
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 10**9
    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))

Verdicts: Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
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(rest0, ret1, ret2, ret3)

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

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(rest0, ret1, ret2, ret3)

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

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))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
many, A, B, C = map(int, input().split())
bamboos = [int(input()) for i in range(many)]







infinity = 1e10

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

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


many, A, B, C = map(int, input().split())
bamboos = [int(input()) for i in range(many)]







infinity = 1e10

def dfs(depth, a, b, c):
    if depth == many:
        
        if min(a, b, c) > 0:
            
            
            
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return infinity
    else:
        ret0 = dfs(depth+1, a, b, c)
        ret1 = dfs(depth+1, a+bamboos[depth], b, c) + 10
        ret2 = dfs(depth+1, a, b+bamboos[depth], c) + 10
        ret3 = dfs(depth+1, a, b, c+bamboos[depth]) + 10
        return min(ret0, ret1, ret2, ret3)

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


Verdicts: Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
N,a,b,c=map(int,input().split())
L=[int(input()) for i in range(N)]
import itertools 
ans=300000
for i in itertools.product('ABCD',repeat=N):
  cst=0
  A=[]
  B=[]
  C=[]
  for j in range(N):
    if i[j]=='A':
      A.append(L[j])
    elif i[j]=='B':
      B.append(L[j]) 
    elif i[j]=='C':
      C.append(L[j])
  if len(A)>0 and len(B)>0 and len(C)>0:
    if len(A)>1:
      cst+=len(A)-1
    cst+=abs(sum(A)-a)
    if len(B)>1:
      cst+=len(B)-1
    cst+=abs(sum(B)-b)
    if len(C)>1:
      cst+=len(C)-1
    cst+=abs(sum(C)-c)
    ans=min(ans,cst)
 
print(ans)
   

N,a,b,c=map(int,input().split())
L=[int(input()) for i in range(N)]
import itertools 
ans=300000
for i in itertools.product('ABCD',repeat=N):
  cst=0
  A=[]
  B=[]
  C=[]
  for j in range(N):
    if i[j]=='A':
      A.append(L[j])
    elif i[j]=='B':
      B.append(L[j]) 
    elif i[j]=='C':
      C.append(L[j])
  if len(A)>0 and len(B)>0 and len(C)>0:
    if len(A)>1:
      cst+=(len(A)-1)*10
    cst+=abs(sum(A)-a)
    if len(B)>1:
      cst+=(len(B)-1)*10
    cst+=abs(sum(B)-b)
    if len(C)>1:
      cst+=(len(C)-1)*10
    cst+=abs(sum(C)-c)
    ans=min(ans,cst)
 
print(ans)
   

Verdicts: Wrong Answer

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
l=[]

def detain(n,a,b,c,l):
    
    n,a,b,c=map(int,input().split())
    for i in range(n):
        li=int(input())
        l.append(li)
    return


detain(n,a,b,c,l)
d=[a,b,c]
d.sort()

mpmin=sum(l)*4+len(l)*10
for i in range(4**n):
    k=[]
    kj=i%4
    k.append(kj)
    b=int((i-kj)/4)
    l0=[]
    l1=[]
    l2=[]
    l3=[]
    if kj==0:
        l0.append(l[0])
    elif kj==1:
        l1.append(l[0])
    elif kj==2:
        l2.append(l[0])
    elif kj==3:
        l3.append(l[0])
        
    for j in range(n-1):
        kj=b%4
        k.append(kj)
        b=int((b-kj)/4)
        if kj==0:
            l0.append(l[j+1])
        elif kj==1:
            l1.append(l[j+1])
        elif kj==2:
            l2.append(l[j+1])
        elif kj==3:
            l3.append(l[j+1])
    mp=0
    if len(l0)>=1:
        mp=mp+(len(l0)-1)*10
    if len(l1)>=1:
        mp=mp+(len(l1)-1)*10
    if len(l2)>=1:
        mp=mp+(len(l2)-1)*10
    ls=[]
    ls=[sum(l0),sum(l1),sum(l2)]
    ls.sort()
    mp=mp+abs(d[0]-ls[0])+abs(d[1]-ls[1])+abs(d[2]-ls[2])    
    if mpmin>mp and len(l0)>=1 and len(l1)>=1 and len(l2)>=1:
        mpmin=mp
print(mpmin)        
        


n,a,b,c=map(int,input().split())
l=[0]*n
for i in range(n):
    l[i]=int(input())

inf=10**9

def dfs(cur,aa,bb,cc):
    if cur==n:
        if min(aa,bb,cc)>0:
            return abs(a-aa)+abs(b-bb)+abs(c-cc)-30
        else:
            return inf
    ret0=dfs(cur+1,aa,bb,cc)
    ret1=dfs(cur+1,aa+l[cur],bb,cc)+10
    ret2=dfs(cur+1,aa,bb+l[cur],cc)+10
    ret3=dfs(cur+1,aa,bb,cc+l[cur])+10
#    print(cur,l[cur],aa,bb,cc,ret0,ret1,ret2,ret3)
    return min(ret0,ret1,ret2,ret3)

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

Verdicts: Runtime Error

Accepted
Problem: You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.  Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:    * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1.   * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.   * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)  At least how much MP is needed to achieve the objective?

Submission attempts (in order):
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(depth, l):
        if depth == 0:
            calc(l)
            return
        for i in range(4):
            dfs( depth - 1, l + str(i) )

    def calc(l):
        res = 0
        if not '1' in l or not '2' in l or not '3' in l:
            return
        aa = [[] for i in range(3)]
        for i,x in enumerate(list(l)):
            x = int(x)
            if x == 3:
                continue
            take = NLIST[i]
            aa[x].append(take)
        for i, a in enumerate(aa):
            if len(a) > 1:
                res += 10 * (len(a) - 1)
            res += abs(ABC[i] - sum(a))
        RESULT.append(res)




    RESULT = []
    N,A,B,C = map(int, lines.pop(0).split(' '))
    ABC = [A,B,C]
    NLIST = []
    for i in range(N):
        NLIST.append(int(lines.pop(0)))
    dfs(N, "")
    print(min(RESULT))

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(depth, l):
        if depth == 0:
            calc(l)
            return
        for i in range(4):
            dfs( depth - 1, l + str(i) )

    def calc(l):
        res = 0
        if not '0' in l or not '1' in l or not '2' in l:
            return
        aa = [[] for i in range(3)]
        for i,x in enumerate(list(l)):
            x = int(x)
            if x == 3:
                continue
            take = NLIST[i]
            aa[x].append(take)
        for i, a in enumerate(aa):
            if len(a) > 1:
                res += 10 * (len(a) - 1)
            res += abs(ABC[i] - sum(a))
        RESULT.append(res)




    RESULT = []
    N,A,B,C = map(int, lines.pop(0).split(' '))
    ABC = [A,B,C]
    NLIST = []
    for i in range(N):
        NLIST.append(int(lines.pop(0)))
    dfs(N, "")
    print(min(RESULT))
    
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Verdicts: Wrong Answer

Accepted