from functools import lru_cache
N, A, B, C, *L = map(int, open(0).read().split())


@lru_cache(None)
def popcnt(n):
    return bin(n).count('1')


@lru_cache(None)
def synth(bit):
    length = 0
    for i in range(N):
        if bit >> i & 1:
            length += L[i]
    return length


ans = 1 << 60
for bit1 in range(1, 1 << N):
    if popcnt(bit1) >= N-1:
        continue
    length1 = synth(bit1)

    for bit2 in range(1, 1 << N):
        if bit1 & bit2:
            continue
        if popcnt(bit1 | bit2) == N:
            continue
        length2 = synth(bit2)

        for bit3 in range(1, 1 << N):
            if bit1 & bit3 or bit2 & bit3:
                continue

            length3 = synth(bit3)
            c, b, a = sorted([length1, length2, length3])

            cost = 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a)
            if cost < ans:
                ans = cost

print(ans) from functools import lru_cache N, A, B, C, *L = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split A B C *L L def popcnt(n):
    return bin(n).count('1') popcnt return bin(n).count('1') bin(n).count('1') (n).count (n) bin n count '1' n n @lru_cache(None) popcnt None @lru_cache(None) lru_cache None popcnt def synth(bit):
    length = 0
    for i in range(N):
        if bit >> i & 1:
            length += L[i]
    return length synth length = 0 length 0 for i in range(N):
        if bit >> i & 1:
            length += L[i]
     i range(N) range N if bit >> i & 1:
            length += L[i]
     bit >> i & 1 bit >> i bit i 1 length += L[i] length L[i] L i return length length bit bit @lru_cache(None) synth None @lru_cache(None) lru_cache None synth ans = 1 << 60 ans 1 << 60 1 60 for bit1 in range(1, 1 << N):
    if popcnt(bit1) >= N-1:
        continue
    length1 = synth(bit1)

    for bit2 in range(1, 1 << N):
        if bit1 & bit2:
            continue
        if popcnt(bit1 | bit2) == N:
            continue
        length2 = synth(bit2)

        for bit3 in range(1, 1 << N):
            if bit1 & bit3 or bit2 & bit3:
                continue

            length3 = synth(bit3)
            c, b, a = sorted([length1, length2, length3])

            cost = 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a)
            if cost < ans:
                ans = cost bit1 range(1, 1 << N) range 1 1 << N 1 N if popcnt(bit1) >= N-1:
        continue
     popcnt(bit1) >= N-1 popcnt(bit1) popcnt bit1 N-1 N 1 continue length1 = synth(bit1) length1 synth(bit1) synth bit1 for bit2 in range(1, 1 << N):
        if bit1 & bit2:
            continue
        if popcnt(bit1 | bit2) == N:
            continue
        length2 = synth(bit2)

        for bit3 in range(1, 1 << N):
            if bit1 & bit3 or bit2 & bit3:
                continue

            length3 = synth(bit3)
            c, b, a = sorted([length1, length2, length3])

            cost = 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a)
            if cost < ans:
                ans = cost bit2 range(1, 1 << N) range 1 1 << N 1 N if bit1 & bit2:
            continue
         bit1 & bit2 bit1 bit2 continue if popcnt(bit1 | bit2) == N:
            continue
         popcnt(bit1 | bit2) == N popcnt(bit1 | bit2) popcnt bit1 | bit2 bit1 bit2 N continue length2 = synth(bit2) length2 synth(bit2) synth bit2 for bit3 in range(1, 1 << N):
            if bit1 & bit3 or bit2 & bit3:
                continue

            length3 = synth(bit3)
            c, b, a = sorted([length1, length2, length3])

            cost = 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a)
            if cost < ans:
                ans = cost bit3 range(1, 1 << N) range 1 1 << N 1 N if bit1 & bit3 or bit2 & bit3:
                continue

             bit1 & bit3 or bit2 & bit3 bit1 & bit3 bit1 bit3 bit2 & bit3 bit2 bit3 continue length3 = synth(bit3) length3 synth(bit3) synth bit3 c, b, a = sorted([length1, length2, length3]) c sorted([length1, length2, length3]) sorted [length1, length2, length3] length1 length2 length3 b a cost = 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a) cost 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a) 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) 10*(popcnt(bit1 | bit2 | bit3)-3) 10 popcnt(bit1 | bit2 | bit3)-3 popcnt(bit1 | bit2 | bit3) popcnt bit1 | bit2 | bit3 bit1 | bit2 bit1 bit2 bit3 3 abs(C-c) abs C-c C c abs(B-b) abs B-b B b abs(A-a) abs A-a A a if cost < ans:
                ans = cost cost < ans cost ans ans = cost ans cost print(ans) print ans length3 = synth(bit3) synth(bit3) length3 N, A, B, C, *L = map(int, open(0).read().split()) map(int, open(0).read().split()) N def synth(bit):
    length = 0
    for i in range(N):
        if bit >> i & 1:
            length += L[i]
    return length def synth(bit):
    length = 0
    for i in range(N):
        if bit >> i & 1:
            length += L[i]
    return length synth length1 = synth(bit1) synth(bit1) length1 cost = 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a) 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a) cost ans = 1 << 60 1 << 60 ans B, C, *L = map(int, open(0).read().split()) map(int, open(0).read().split()) B def popcnt(n):
    return bin(n).count('1') def popcnt(n):
    return bin(n).count('1') popcnt C, *L = map(int, open(0).read().split()) map(int, open(0).read().split()) C length2 = synth(bit2) synth(bit2) length2 b, a = sorted([length1, length2, length3]) sorted([length1, length2, length3]) b c, b, a = sorted([length1, length2, length3]) sorted([length1, length2, length3]) c ans = cost cost ans A, B, C, *L = map(int, open(0).read().split()) map(int, open(0).read().split()) A a = sorted([length1, length2, length3]) sorted([length1, length2, length3]) a
from functools import lru_cache
N, A, B, C, *L = map(int, open(0).read().split())


@lru_cache(None)
def popcnt(n):
    return bin(n).count('1')


@lru_cache(None)
def synth(bit):
    length = 0
    for i in range(N):
        if bit >> i & 1:
            length += L[i]
    return length


ans = 1 << 60
for bit1 in range(1, 1 << N):
    if popcnt(bit1) >= N-1:
        continue
    length1 = synth(bit1)

    for bit2 in range(1, 1 << N):
        if bit1 & bit2:
            continue
        if popcnt(bit1 | bit2) == N:
            continue
        length2 = synth(bit2)

        for bit3 in range(1, 1 << N):
            if bit1 & bit3 or bit2 & bit3:
                continue

            length3 = synth(bit3)
            c, b, a = sorted([length1, length2, length3])

            cost = 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a)
            if cost < ans:
                ans = cost

print(ans)
