import sys

from itertools import product



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

    N, *A = list(map(int, readline().split()))

    (*L,) = list(map(int, read().split()))



    ans = INF

    for p in product(list(range(4)), repeat=N):

        num = [0] * 3

        length = [0] * 3

        for i, j in enumerate(p):

            if j < 3:

                num[j] += 1

                length[j] += L[i]

        res = 0

        for j in range(3):

            if num[j] == 0:

                res = INF

                break

            else:

                res += (num[j] - 1) * 10 + abs(length[j] - A[j])

        if ans > res:

            ans = res



    print(ans)

    return





if __name__ == '__main__':

    main()

import sys

from itertools import product



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

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

    (*L,) = list(map(int, read().split()))



    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



        res0 = rec(i + 1, a, b, c)

        res1 = rec(i + 1, a + L[i], b, c) + 10

        res2 = rec(i + 1, a, b + L[i], c) + 10

        res3 = rec(i + 1, a, b, c + L[i]) + 10



        return min(res0, res1, res2, res3)



    print((rec(0, 0, 0, 0)))

    return





if __name__ == '__main__':

    main()

import sys
from itertools import product

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = list(map(int, readline().split()))
    (*L,) = list(map(int, read().split()))
    ans = INF
    for p in product(list(range(4)), repeat=N):
        num = [0] * 3
        length = [0] * 3
        for i, j in enumerate(p):
            if j < 3:
                num[j] += 1
                length[j] += L[i]
        res = 0
        for j in range(3):
            if num[j] == 0:
                res = INF
                break
            else:
                res += (num[j] - 1) * 10 + abs(length[j] - A[j])
        if ans > res:
            ans = res
    print(ans)
    return


if __name__ == "__main__":
    main()

import sys
from itertools import product

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, B, C = list(map(int, readline().split()))
    (*L,) = list(map(int, read().split()))

    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
            )
        res0 = rec(i + 1, a, b, c)
        res1 = rec(i + 1, a + L[i], b, c) + 10
        res2 = rec(i + 1, a, b + L[i], c) + 10
        res3 = rec(i + 1, a, b, c + L[i]) + 10
        return min(res0, res1, res2, res3)

    print((rec(0, 0, 0, 0)))
    return


if __name__ == "__main__":
    main()

-    N, *A = list(map(int, readline().split())) +    N, A, B, C = list(map(int, readline().split())) -    ans = INF -    for p in product(list(range(4)), repeat=N): -        num = [0] * 3 -        length = [0] * 3 -        for i, j in enumerate(p): -            if j < 3: -                num[j] += 1 -                length[j] += L[i] -        res = 0 -        for j in range(3): -            if num[j] == 0: -                res = INF -                break -            else: -                res += (num[j] - 1) * 10 + abs(length[j] - A[j]) -        if ans > res: -            ans = res -    print(ans) + +    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 +            ) +        res0 = rec(i + 1, a, b, c) +        res1 = rec(i + 1, a + L[i], b, c) + 10 +        res2 = rec(i + 1, a, b + L[i], c) + 10 +        res3 = rec(i + 1, a, b, c + L[i]) + 10 +        return min(res0, res1, res2, res3) + +    print((rec(0, 0, 0, 0)))