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





initialSum = []
for i in range(2**N): 
    nowsum = 0
    nowbamboocnt = 0
    for j in range(N): 
        if i % (2**(j+1)) >= 2**j:
            nowbamboocnt += 1
            nowsum += L[j] 
    initialSum.append([nowsum, nowbamboocnt])




bambooset = {i for i in range(N)} 
min = 3000 

lestbamboo = bambooset.copy() 

for i, initSumA in enumerate(initialSum): 

    if initSumA[1] ==0 or N - initSumA[1] < 2: continue 
    lestbamboo = bambooset.copy() 
    for j in range(N): 
        if i % (2**(j+1)) >= 2**j: 
            lestbamboo.remove(j)
    necesMPforA = abs(A - initSumA[0]) + (initSumA[1]-1)*10 

    
    for b in range(len(lestbamboo)**2): 
    
        lestbambooList = list(lestbamboo) 
        
        bamboocntB = 0 
        nowsumB = 0
        lestbambooforC = lestbamboo.copy() 
        for k in range(len(lestbambooList)): 
            if b % (2**(k+1)) >= 2**k: 
                bamboocntB += 1
                nowsumB += lestbambooList[k] 
                lestbambooforC.remove(lestbambooList[k])
        if bamboocntB == 0: continue 

        for m in range(len(lestbambooforC)**2): 
        
        
            lestbambooforCList = list(lestbambooforC) 
            bamboocntC = 0
            nowsumC = 0
            for n in range(len(lestbambooforCList)):
                if m % (2**(n+1)) >= 2**n: 
                    bamboocntC += 1
                    nowsumC += lestbambooforCList[n] 
            if bamboocntC == 0: continue 

            nowTotalSum = necesMPforA + abs(B - nowsumB) + (bamboocntB-1)*10 + abs(C - nowsumC) + (bamboocntC-1)*10
            
            if nowTotalSum < min: min = nowTotalSum

print(min)

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



initialSum = []
for i in range(2**N): 
    nowsum = 0
    nowbamboocnt = 0
    for j in range(N): 
        if i % (2**(j+1)) >= 2**j:
            nowbamboocnt += 1
            nowsum += L[j] 
    initialSum.append([nowsum, nowbamboocnt])



bambooset = {i for i in range(N)} 
min = 3000 

lestbamboo = bambooset.copy() 

for i, initSumA in enumerate(initialSum): 

    if initSumA[1] ==0 or N - initSumA[1] < 2: continue 
    lestbamboo = bambooset.copy() 
    for j in range(N): 
        if i % (2**(j+1)) >= 2**j: 
            lestbamboo.remove(j)
    necesMPforA = abs(A - initSumA[0]) + (initSumA[1]-1)*10 

    
    for b in range(2**len(lestbamboo)): 
    
        lestbambooList = list(lestbamboo) 
        
        bamboocntB = 0 
        nowsumB = 0
        lestbambooforC = lestbamboo.copy() 
        for k in range(len(lestbambooList)): 
            if b % (2**(k+1)) >= 2**k: 
                bamboocntB += 1
                nowsumB += L[lestbambooList[k]] 
                lestbambooforC.remove(lestbambooList[k])
        if bamboocntB == 0: continue 

        for m in range(2**len(lestbambooforC)): 
        
        
            lestbambooforCList = list(lestbambooforC) 
            bamboocntC = 0
            nowsumC = 0
            for n in range(len(lestbambooforCList)):
                if m % (2**(n+1)) >= 2**n: 
                    bamboocntC += 1
                    nowsumC += L[lestbambooforCList[n]] 
            if bamboocntC == 0: continue 

            nowTotalSum = necesMPforA + abs(B - nowsumB) + (bamboocntB-1)*10 + abs(C - nowsumC) + (bamboocntC-1)*10
            
            if nowTotalSum < min: min = nowTotalSum

print(min)

Verdicts: Wrong Answer

Accepted