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 = map(int, readline().split())
    (*L,) = map(int, read().split())

    ans = INF
    for p in product(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 sys from itertools import product read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline readlines = sys.stdin.readlines readlines sys.stdin.readlines sys.stdin sys stdin readlines sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = 1 << 60 INF 1 << 60 1 60 MOD = 1000000007 MOD 1000000007 def main():
    N, *A = map(int, readline().split())
    (*L,) = map(int, read().split())

    ans = INF
    for p in product(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 main N, *A = map(int, readline().split()) N map(int, readline().split()) map int readline().split() ().split () readline split *A A (*L,) = map(int, read().split()) *L L map(int, read().split()) map int read().split() ().split () read split ans = INF ans INF for p in product(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

     p product(range(4), repeat=N) product range(4) range 4 repeat=N repeat N num = [0] * 3 num [0] * 3 [0] 0 3 length = [0] * 3 length [0] * 3 [0] 0 3 for i, j in enumerate(p):
            if j < 3:
                num[j] += 1
                length[j] += L[i]
         i j enumerate(p) enumerate p if j < 3:
                num[j] += 1
                length[j] += L[i]
         j < 3 j 3 num[j] += 1 num[j] num j 1 length[j] += L[i] length[j] length j L[i] L i res = 0 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])
         j range(3) range 3 if num[j] == 0:
                res = INF
                break
            else:
                res += (num[j] - 1) * 10 + abs(length[j] - A[j])
         num[j] == 0 num[j] num j 0 res = INF res INF break res += (num[j] - 1) * 10 + abs(length[j] - A[j]) res (num[j] - 1) * 10 + abs(length[j] - A[j]) (num[j] - 1) * 10 num[j] - 1 num[j] num j 1 10 abs(length[j] - A[j]) abs length[j] - A[j] length[j] length j A[j] A j if ans > res:
            ans = res

     ans > res ans res ans = res ans res print(ans) print ans return if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main MOD = 1000000007 1000000007 MOD def main():
    N, *A = map(int, readline().split())
    (*L,) = map(int, read().split())

    ans = INF
    for p in product(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 def main():
    N, *A = map(int, readline().split())
    (*L,) = map(int, read().split())

    ans = INF
    for p in product(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 main INF = 1 << 60 1 << 60 INF readline = sys.stdin.readline sys.stdin.readline readline read = sys.stdin.read sys.stdin.read read readlines = sys.stdin.readlines sys.stdin.readlines readlines
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 = map(int, readline().split())
    (*L,) = map(int, read().split())

    ans = INF
    for p in product(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()
