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):
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)
    re1 = 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)]
INF = 100000000
def rec(i,a,b,c):
    if(i==N):
        return(abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF)
    ret0 = rec(i+1,a,b,c)
    ret1 = rec(i+1,a+l[i],b,c)+10
    ret2 = rec(i+1,a,b+l[i],c)+10
    ret3 = rec(i+1,a,b,c+l[i])+10
    return min(ret0,ret1,ret2,ret3)
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):
# @hitstales 
n, *goals = list(map(int, input().split()))
bamboos = list(map(int, [input().rstrip() for _ in range(n)]))


def get_best(li, goal):
    bam_mp_lis = {0: (-10, tuple())}
    li = sorted(li)
    for i, v in enumerate(li):
        tmp = bam_mp_lis.copy()
        for bam, (mp, lis) in tmp.items():
            b0 = bam + v
            m0 = mp + 10
            l0 = lis + (i,)
            if b0 not in bam_mp_lis or m0 < bam_mp_lis[b0][0]:
                bam_mp_lis[b0] = (m0, l0)
    del bam_mp_lis[0]
    best = 10 ** 9
    for bam, (mp, lis) in bam_mp_lis.items():
        cost = mp + abs(goal - bam)
        if cost < best:
            best = cost
            beslis = lis
    return best, beslis


ans = 10 ** 9
from itertools import permutations

for junjo in permutations(goals):
    tmp = 0
    bambooo = bamboos.copy()
    for ju in junjo:
        if len(bambooo) == 0:
            tmp = 10 ** 9
            break
        be, beli = get_best(bambooo, ju)
        beli = sorted(beli, reverse=True)
        for beli0 in beli:
            del bambooo[beli0]
        tmp += be
    if tmp < ans:
        ans = tmp

print(ans)

# ABC119C - Synthetic Kadomatsu
import sys

sys.setrecursionlimit(10 ** 9)


def dfs(cur: int, x: int, y: int, z: int) -> int:
    if cur == N:
        if min(x, y, z):
            return abs(x - A) + abs(y - B) + abs(z - C) - 30
        else:
            return 1 << 60
    patterns = []
    patterns.append(dfs(cur + 1, x, y, z))
    patterns.append(dfs(cur + 1, x + L[cur], y, z) + 10)
    patterns.append(dfs(cur + 1, x, y + L[cur], z) + 10)
    patterns.append(dfs(cur + 1, x, y, z + L[cur]) + 10)
    return min(patterns)


def main():
    global N, A, B, C, L
    N, A, B, C, *L = map(int, open(0).read().split())
    ans = dfs(0, 0, 0, 0)
    print(ans)


if __name__ == "__main__":
    main()

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(i) for i in input()]
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 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):
def nsin(X,y):
    if(int(X/y)):
        return nsin(int(X/y),y)+str(X%y)
    return str(X%y)

cost=10000
for i in range(3**n):
    g=list(nsin(i,3).zfill(5))
    if len(set(g))!=3:
        continue
    la=[]
    lb=[]
    lc=[]
    for j in range(n):        
        if g[j]=="0":
            la.append(l[j])
        elif g[j]=="1":
            lb.append(l[j])
        elif g[j]=="2":
            lc.append(l[j])
    costa=10000
    costb=10000
    costc=10000
    for j in range(1,2**len(la)):
        ga=list(nsin(j,2).zfill(len(la)))
        A=0
        cont=-1
        for k in range(len(la)):
            if ga[k]=="1":
                A+=la[k]
                cont+=1
        tmp=cont*10+abs(A-a)
        if tmp<costa:
            costa=tmp
    for j in range(1,2**len(lb)):
        gb=list(nsin(j,2).zfill(len(lb)))
        B=0
        cont=-1
        for k in range(len(lb)):
            if gb[k]=="1":
                B+=lb[k]
                cont+=1
        tmp=cont*10+abs(B-b)
        if tmp<costb:
            costb=tmp
    for j in range(1,2**len(lc)):
        gc=list(nsin(j,2).zfill(len(lc)))
        C=0
        cont=-1
        for k in range(len(lc)):
            if gc[k]=="1":
                C+=lc[k]
                cont+=1
        tmp=cont*10+abs(C-c)
        if tmp<costc:
            costc=tmp
    if cost>(costa+costb+costc):
        cost=costa+costb+costc
print(cost)

# coding: utf-8
N,A,B,C=map(int,input().split())
L=[]
for i in range(N):
    L.append(int(input()))

def Base_10_to_n(X, base_n, len_N):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%base_n)+out
        X_dumy = int(X_dumy/base_n)
    return out.zfill(len_N)

ans=10**6

for i in range(4**N):
    bit=Base_10_to_n(i,4,N)
    group=[[] for j in range(4)]
    
    for j in range(N):
        group[int(bit[j])].append(L[j])
    
    if not(group[1]) or not(group[2]) or not(group[3]):
        continue
    
    costA = abs(A-sum(group[1])) + (len(group[1])-1)*10
    costB = abs(B-sum(group[2])) + (len(group[2])-1)*10
    costC = abs(C-sum(group[3])) + (len(group[3])-1)*10
    
    cost = costA + costB + costC
    
    ans=min(ans,cost)

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

# TLE   ac 


import heapq
from itertools import combinations
import sys
input = sys.stdin.readline  
N,A,B,C = (int(i) for i in input().split())
l =[0]*N
for i in range(N):
    l[i] = int(input())


mp=[]
for na in range(1,N-1):
    for ja in combinations(l,na):

        l_b =list(set(l) -set(ja))
        for nb in range(1,N):
            for jb in combinations(l_b ,nb):

                l_c =list(set(l_b) -set(jb) )
                for nc in range(1,N+1):
                    for jc in combinations(l_c ,nc):
                        
                        
                        AA =abs(A-sum(ja)) +10*(na-1)
                        BB =abs(B-sum(jb)) +10*(nb-1)
                        CC =abs(C-sum(jc)) +10*(nc-1)
                        mp.append(AA +BB +CC)

print(mp)


# RE 1   ac 19


import copy
from itertools import combinations
import sys
input = sys.stdin.readline  
N,A,B,C = (int(i) for i in input().split())
l =[0]*N
for i in range(N):
    l[i] = int(input())


mp=[]
for na in range(1,N-1):
    for ja in combinations(l,na):

        l_b =copy.copy(l)
        for i2 in ja:
            if i2 in l_b:
                l_b.remove(i2)
        for nb in range(1,N):
            for jb in combinations(l_b ,nb):

                l_c =copy.copy(l_b)
                for i3 in jb:
                    if i3 in l_c:
                        l_c.remove(i3)
                for nc in range(1,N+1):
                    for jc in combinations(l_c ,nc):
                        
                        
                        AA =abs(A-sum(ja)) +10*(na-1)
                        BB =abs(B-sum(jb)) +10*(nb-1)
                        CC =abs(C-sum(jc)) +10*(nc-1)
                        mp.append(AA +BB +CC)


print(min(mp))

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):
def ns(X, n):
    if (int(X/n)):
        return ns(int(X/n), n)+str(X%n)
    return str(X%n)

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

for i in range(4**n):
    tmp=ns(i,4)
    tmp="0"*(n-len(tmp))+tmp
    h=[0]*3
    p=0
    for j in range(n):
        if tmp[j]=="1":
            if h[0]!=0: p+=10
            h[0]+=l[j]

        elif tmp[j]=="2":
            if h[1]!=0: p+=10
            h[1]+=l[j]

        elif tmp[j]=="3":
            if h[2]!=0: p+=10
            h[2]+=l[j]

    if 0 in h:continue
    print(tmp,)
    for k in range(3):
        p+=abs(h[k]-t[k])
    if ans==-1: ans=p
    else: ans=min(ans,p)
print(ans)


#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

def ns(X, n):
    if (int(X/n)):
        return ns(int(X/n), n)+str(X%n)
    return str(X%n)

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

for i in range(4**n):
    tmp=ns(i,4)
    tmp="0"*(n-len(tmp))+tmp
    h=[0]*3
    p=0
    for j in range(n):
        if tmp[j]=="1":
            if h[0]!=0: p+=10
            h[0]+=l[j]

        elif tmp[j]=="2":
            if h[1]!=0: p+=10
            h[1]+=l[j]

        elif tmp[j]=="3":
            if h[2]!=0: p+=10
            h[2]+=l[j]

    if 0 in h:continue
    for k in range(3):
        p+=abs(h[k]-t[k])
    if ans==-1: ans=p
    else: ans=min(ans,p)
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):
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))

import sys
sys.setrecursionlimit(100000)
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))

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):
import collections
from copy import deepcopy

n,a,b,c=map(int,input().split())
arr=[int(input()) for _ in range(n)]
l=collections.deque()
l.append([[],[],[]])
cnt=0

while 1:
  if cnt==8:
    break
  base=l.popleft()
  if len(base[0])==0 and len(base[1])==0 and len(base[2])==0:
    l.append([[arr[cnt]],[],[]])
    l.append([[],[arr[cnt]],[]])
    l.append([[],[],[arr[cnt]]])
    l.append([[],[],[]])
    cnt+=1
  else:
    tmp1=deepcopy(base)
    tmp1[0].append(arr[cnt])
    l.append(tmp1)
    tmp2=deepcopy(base)
    tmp2[1].append(arr[cnt])
    l.append(tmp2)
    tmp3=deepcopy(base)
    tmp3[2].append(arr[cnt])
    l.append(tmp3)
    tmp4=deepcopy(base)
    l.append(tmp4)

mincost=10**9
for bl in l:
  if len(bl[0])==0 or len(bl[1])==0 or len(bl[2])==0:
    continue
  else:
    tmpcost=abs(sum(bl[0])-a)+abs(sum(bl[1])-b)+abs(sum(bl[2])-c)+10*(len(bl[0])-1+len(bl[1])-1+len(bl[2])-1)
    if mincost>tmpcost:
      mincost=tmpcost
print(mincost)

import collections
from copy import deepcopy

n,a,b,c=map(int,input().split())
arr=[int(input()) for _ in range(n)]
l=collections.deque()
l.append([[],[],[]])
cnt=0

while 1:
  if cnt==n:
    break
  base=l.popleft()
  if len(base[0])==0 and len(base[1])==0 and len(base[2])==0:
    l.append([[arr[cnt]],[],[]])
    l.append([[],[arr[cnt]],[]])
    l.append([[],[],[arr[cnt]]])
    l.append([[],[],[]])
    cnt+=1
  else:
    tmp1=deepcopy(base)
    tmp1[0].append(arr[cnt])
    l.append(tmp1)
    tmp2=deepcopy(base)
    tmp2[1].append(arr[cnt])
    l.append(tmp2)
    tmp3=deepcopy(base)
    tmp3[2].append(arr[cnt])
    l.append(tmp3)
    tmp4=deepcopy(base)
    l.append(tmp4)

mincost=10**9
for bl in l:
  if len(bl[0])==0 or len(bl[1])==0 or len(bl[2])==0:
    continue
  else:
    tmpcost=abs(sum(bl[0])-a)+abs(sum(bl[1])-b)+abs(sum(bl[2])-c)+10*(len(bl[0])-1+len(bl[1])-1+len(bl[2])-1)
    if mincost>tmpcost:
      mincost=tmpcost
print(mincost)


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=[]
for _ in range(N):
    l.append(int(input()))

def dfs(counter,a,b,c):
    if a==A and b==B and c==C:
            return counter
    ret1=dfs(counter+1,a+l[counter],b,c)+10
    ret2=dfs(counter+1,a,b+l[counter],c)+10
    ret3=dfs(counter+1,a,b,c+l[counter])+10
    ret4=dfs(counter+1,a+1,b,c)+1
    ret5=dfs(counter+1,a,b+1,c)+1
    ret6=dfs(counter+1,a,b,c+1)+1
    return min(ret1,ret2,ret3,ret4,ret5,ret6)

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

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

def dfs(counter,a,b,c):
    if counter==N:
        
        if a>0 and b>0 and c>0:
            offset=10*3
            return abs(A-a)+abs(B-b)+abs(C-c)-offset
        else:
            
            return 10**9
    
    
    
    ret0=dfs(counter+1,a,b,c)
    ret1=dfs(counter+1,a+l[counter],b,c)+10
    ret2=dfs(counter+1,a,b+l[counter],c)+10
    ret3=dfs(counter+1,a,b,c+l[counter])+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(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)]

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) &gt; 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))


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):
n,a,b,c=map(int,input().split())
l = [int(input()) for _ in range(n)]
ans = 100000000
for i in range(4**n):
  x,y,z=0,0,0
  s,t,u=0,0,0
  for j in range(n):
    t = i % 4
    if t == 0:
      x += l[j]
      s += 1
    elif t == 1:
      y += l[j]
      t += 1
    elif t == 2:
      z += l[j]
      u += 1
  if s == 0 or t == 0 or u == 0:
    continue
  k = (s + t + u - 3) * 10
  k += abs(a - x)
  k += abs(b - y)
  k += abs(c - z)
  ans = min(ans, k)
print(ans)

n,a,b,c=map(int,input().split())
l = [int(input()) for _ in range(n)]
ans = 100000000
for i in range(4**n):
  x,y,z=0,0,0
  s,t,u=0,0,0
  for j in range(n):
    if i % 4 == 0:
      x += l[j]
      s += 1
    elif i % 4 == 1:
      y += l[j]
      t += 1
    elif i % 4  == 2:
      z += l[j]
      u += 1
    i //= 4
  if s == 0 or t == 0 or u == 0:
    continue
  k = (s + t + u - 3) * 10
  k += abs(a - x)
  k += abs(b - y)
  k += abs(c - z)
  ans = min(ans, k)
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):
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)
    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 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 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)
    ret2 = dfs(cur+1,a+l[cur],b,c)+10
    ret3 = dfs(cur+1,a,b+l[cur],c)+10
    ret4 = 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)]
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):
from itertools import combinations
N, A, B, C = [int(i) for i in input().split()]
l_ls = list()
for i in range(N):
    l_ls.append(int(input()))
dis_ls = [(i,[i]) for i in l_ls]
for i in range(2,7):
    dis_ls += [(sum(i),i) for i in combinations(l_ls, i)]
_sum = 0
for target in [C, B, A]:
    min = 1e9
    for dis in dis_ls:
        sa = abs(dis[0] - target) + 10 * (len(dis[1]) - 1)
        if sa < min:
            min = sa
            min_combi = dis[1]
    _sum += min
    dis_ls = [i for i in dis_ls if len(set(min_combi).intersection(set(i[1]))) == 0]
print(_sum)

from itertools import combinations
N, A, B, C = [int(i) for i in input().split()]
l_ls = list()
for i in range(N):
    l_ls.append(int(input()))
dis_ls = [(i,[i]) for i in l_ls]
for i in range(2,7):
    dis_ls += [(sum(i),i) for i in combinations(l_ls, i)]
best = 1e9
for hoge in [[A, B, C], [A, C, B],[B, A, C],[B, C, A], [C,B,A],[C,A,B]]:
    _sum = 0
    for target in hoge:
        min = 1e9
        for dis in dis_ls:
            c_sa = abs(dis[0] - target) + 10 * (len(dis[1]) - 1)
            if sa < min:
                min = sa
                min_combi = dis[1]
        _sum += min
        dis_ls = [i for i in dis_ls if len(set(min_combi).intersection(set(i[1]))) == 0]
    if _sum < best:
        best = _sum
print(best)

from itertools import product
N, A, B, C = [int(i) for i in input().split()]
l_ls = list()
for i in range(N):
    l_ls.append(int(input()))
best = 1e9
for combi in product(range(4),repeat=N):
    a = [l for l, label in zip(l_ls, combi) if label == 1]
    b = [l for l, label in zip(l_ls, combi) if label == 2]
    c = [l for l, label in zip(l_ls, combi) if label == 3]
    dis = abs(A - sum(a)) + abs(B - sum(b)) + abs(C - sum(c)) \
          + (len(a) + len(b) + len(c) - 3) * 10
    if len(a) * len(b) * len(c) == 0:
        continue
    if best > dis:
        best = dis
print(best)

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):
import itertools
N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]
 
INF = 10 ** 18
answer = INF
for pattern in itertools.product(range(4), repeat = N):
  x = [0] * 4
  MP = 0
  for take, length in zip(pattern, L):
    if take == 3:
      continue
    if x[take] != 0:
      MP += 10
    x[take] += length
  if x[0] == 0 or x[1] == 0 or x[2] == 0:
    continue
  MP += abs(A-x[0])
  MP += abs(B-x[1])
  MP += abs(C-x[2])
  if answer > MP:
    answer = MP
print(answer

import itertools
N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]
 
INF = 10 ** 18
answer = INF
for pattern in itertools.product(range(4), repeat = N):
  x = [0] * 4
  MP = 0
  for take, length in zip(pattern, L):
    if take == 3:
      continue
    if x[take] != 0:
      MP += 10
    x[take] += length
  if x[0] == 0 or x[1] == 0 or x[2] == 0:
    continue
  MP += abs(A-x[0])
  MP += abs(B-x[1])
  MP += abs(C-x[2])
  if answer > MP:
    answer = MP
print(answer)

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 collections import deque

N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
minMP = 10**5

p = deque()
p.append([-1] * len(L))
while p:
    stats = p.pop()
    stats = list(stats)
    a, b, c = 0, 0, 0
    MP = 0
    cntA = 0; cntB = 0; cntC = 0
    for i in range(N):
        if stats[i] == 1:
            a += L[i]
            cntA += 1
        elif stats[i] == 2:
            b += L[i]
            cntB += 1
        elif stats[i] == 3:
            c += L[i]
            cntC += 1

    if cntA >= 1 and cntB >= 1 and cntC >= 1:
        MP += abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cntA+cntB+cntC-3)
        minMP = min(minMP, MP)

    if not -1 in stats:
        continue
    j = stats.index(-1)
    for k in range(4):
        stats[j] = k
        newStats = tuple(stats)
        p.append(newStats)
        print(newStats)
print(minMP)
input()


N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
INF = float('inf')

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

    no_compound = dfs(cursor+1, a, b, c)
    A_compound = dfs(cursor+1, a+L[cursor], b, c) + 10
    B_compound = dfs(cursor+1, a, b+L[cursor], c) + 10
    C_compound = dfs(cursor+1, a, b, c+L[cursor]) + 10
    return min(no_compound, A_compound, B_compound, C_compound)

print(dfs())


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

length = [0] * N

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

inf = 10 ** 9

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

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

length = [0] * N

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

inf = 10 ** 9

def dfs(pos, a, b, c):
    if pos == N:
        if min(a, b, c) > 0:
            
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return inf
    
    ret1 = dfs(pos + 1, a, b, c)
    ret2 = dfs(pos + 1, a + length[pos], b, c) + 10
    ret3 = dfs(pos + 1, a, b + length[pos], c) + 10
    ret4 = dfs(pos + 1, a, b, c + length[pos]) + 10
    return min(ret1, ret2, ret3, ret4)
    
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, *abc = [int(x) for x in input().split()]
l = [int(input()) for i in range(n)]
A = 0; B = 1; C = 2;

minmp = 10 ** 9
for k in range(2 ** (2 * n)):
    mat = [[], [], [], []]  
    
    
    
    
    
    for i in range(1, n):
        mat[k & (0b11)].append(l[i])
        k >>= 2

    if len(mat[0]) == 0 or len(mat[1]) == 0 or len(mat[2]) == 0:
        continue

    mp = 0
    for j in range(3):
        mp += 10 * (len(mat[j]) - 1)
        mp += 1 * abs(abc[j] - sum(mat[j]))

    minmp = min(minmp, mp)

print(minmp)

n, *abc = [int(x) for x in input().split()]
l = [int(input()) for i in range(n)]
A = 0; B = 1; C = 2;

minmp = 10 ** 9
for k in range(2 ** (2 * n)):
    mat = [[], [], [], []]  
    
    
    
    
    
    for i in range(n):
        mat[k & (0b11)].append(l[i])
        k >>= 2

    if len(mat[0]) == 0 or len(mat[1]) == 0 or len(mat[2]) == 0:
        continue

    mp = 0
    for j in range(3):
        mp += 10 * (len(mat[j]) - 1)
        mp += 1 * abs(abc[j] - sum(mat[j]))

    minmp = min(minmp, mp)

print(minmp)

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 = 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, 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: 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 = 10 ** 9

def dfs(i,a,b,c):
    if i == n:
        if min(a,b,c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return inf
    ret0 = dfs(i+1, a, b, c)
    ret1 = dfs(i+1, a + l[i], b, c) + 10
    ret2 = dfs(i+1, a, b + l[i], c) + 10
    ret3 = dfs(i+1, a, b, c + l[i]) + 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)]
inf = 10 ** 9

def dfs(i,a,b,c):
    if i == n:
        if min(a,b,c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return inf
    ret0 = dfs(i+1, a, b, c)
    ret1 = dfs(i+1, a + l[i], b, c) + 10
    ret2 = dfs(i+1, a, b + l[i], c) + 10
    ret3 = dfs(i+1, a, b, c + l[i]) + 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):
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

n,a,b,c=map(int,input().split())
L=[]
for _ in range(n):
    L.append(int(input()))
print(L)
at,bt,ct=[],[],[]
ans_list=[]
ans=999999999
for i in range(4**len(L)-1):
    i_4_list=list(Base_10_to_n(i, 4).zfill(len(L)))
    at,bt,ct=[],[],[]
    for num,i_4 in enumerate(i_4_list):
        if i_4=='0':
            at.append(L[num])
        elif i_4=='1':
            bt.append(L[num])
        elif i_4=='2':
            ct.append(L[num])
        else:
            continue
    if at!=[] and ct!=[] and ct!=[]:
        al=0
        al+=(len(at)+len(bt)+len(ct)-3)*10
        al+=(abs(sum(at)-a)+abs(sum(bt)-b)+abs(sum(ct)-c))
        if al < ans:
            ans=al
print(ans)




def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

n,a,b,c=map(int,input().split())
L=[]
for _ in range(n):
    L.append(int(input()))

ans=99999
for i in range(4**len(L)+1):
    i_4_list=list(Base_10_to_n(i, 4).zfill(len(L)))
    at,bt,ct=[],[],[]
    for num,i_4 in enumerate(i_4_list):
        if i_4=='0':
            at.append(L[num])
        elif i_4=='1':
            bt.append(L[num])
        elif i_4=='2':
            ct.append(L[num])
        else:
            continue
    if min(len(at),len(bt),len(ct))>0:
        al=0
        al+=(len(at)+len(bt)+len(ct)-3)*10
        al+=(abs(sum(at)-a)+abs(sum(bt)-b)+abs(sum(ct)-c))
        if al < ans:
            ans=al
print(ans)

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

def dfs(n,a,b,c):
    if n == N:
        if min(a,b,c)>0:
            return abs(A-a)+abs(B-b)+abs(C-c)-30
        else:
            return 10000
    root1=dfs(n+1,a+L[n],b,c)+10
    root2=dfs(n+1,a,b+L[n],c)+10
    root3=dfs(n+1,a,b,c+L[n])+10
    root4=dfs(n+1,a,b,c)
    return min(root1,root2,root3,root4)
    
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):
n,a,b,c=map(int,input().split())
l=[]
for i in range(n):
    l.append(int(input()))
op=[[0],[1],[2]]
for i in range(n-1):
    tmp=[]
    for j in op:
        tmp.append(j+[0])
        tmp.append(j+[1])
        tmp.append(j+[2])
    op=tmp
ans=1000000000
for i in op:
    ta=0
    tb=0
    tc=0
    for j in range(len(i)):
        if i[j]==0:
            ta+=l[j]
        elif i[j]==1:
            tb+=l[j]
        else:
            tc+=l[j]
    mp=abs(a-ta)+abs(b-tb)+abs(c-tc)
    if ta==0 or tb==0 or tc==0:
        mp=1000000000
    ans=min(ans,mp)
print(ans)

n,a,b,c=map(int,input().split())
l=[]
for i in range(n):
    l.append(int(input()))
op=[[0],[1],[2],[3]]
for i in range(n-1):
    tmp=[]
    for j in op:
        tmp.append(j+[0])
        tmp.append(j+[1])
        tmp.append(j+[2])
        tmp.append(j+[3])
    op=tmp
ans=1000000000
for i in op:
    ta=0
    tb=0
    tc=0
    mp=0
    for j in range(len(i)):
        if i[j]==0:
            if ta!=0:
                mp+=10
            ta+=l[j]        
        elif i[j]==1:
            if tb!=0:
                mp+=10
            tb+=l[j]
        elif i[j]==2:
            if tc!=0:
                mp+=10
            tc+=l[j]
    mp+=abs(a-ta)+abs(b-tb)+abs(c-tc)
    if ta==0 or tb==0 or tc==0:
        mp=1000000000
    ans=min(ans,mp)
print(ans)


Verdicts: Wrong Answer

Accepted