def main():
    n, *target = map(int, input().split())
    l = [int(input()) for _ in range(n)]
    ans = float("inf")
    base = 4
    for i in range(pow(base, n)):
        now_l = [0] * base
        add = [0] * base
        now = i
        for j in range(n):
            now_l[now % base] += l[j]
            add[now % base] += 1
            now //= base
        if 0 in now_l[:base - 1]:
            continue
        now_ans = sum([abs(target[i] - now_l[i]) for i in range(3)]) + (sum(add[:3]) - 3) * 10
        ans = min(ans, now_ans)
    print(0 if all(t in l for t in target) else ans)


if __name__ == '__main__':
    main() def main():
    n, *target = map(int, input().split())
    l = [int(input()) for _ in range(n)]
    ans = float("inf")
    base = 4
    for i in range(pow(base, n)):
        now_l = [0] * base
        add = [0] * base
        now = i
        for j in range(n):
            now_l[now % base] += l[j]
            add[now % base] += 1
            now //= base
        if 0 in now_l[:base - 1]:
            continue
        now_ans = sum([abs(target[i] - now_l[i]) for i in range(3)]) + (sum(add[:3]) - 3) * 10
        ans = min(ans, now_ans)
    print(0 if all(t in l for t in target) else ans) main n, *target = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split *target target int(input()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) int(input()) int input() input l = [int(input()) for _ in range(n)] l [int(input()) for _ in range(n)] ans = float("inf") ans float("inf") float "inf" base = 4 base 4 for i in range(pow(base, n)):
        now_l = [0] * base
        add = [0] * base
        now = i
        for j in range(n):
            now_l[now % base] += l[j]
            add[now % base] += 1
            now //= base
        if 0 in now_l[:base - 1]:
            continue
        now_ans = sum([abs(target[i] - now_l[i]) for i in range(3)]) + (sum(add[:3]) - 3) * 10
        ans = min(ans, now_ans)
     i range(pow(base, n)) range pow(base, n) pow base n now_l = [0] * base now_l [0] * base [0] 0 base add = [0] * base add [0] * base [0] 0 base now = i now i for j in range(n):
            now_l[now % base] += l[j]
            add[now % base] += 1
            now //= base
         j range(n) range n now_l[now % base] += l[j] now_l[now % base] now_l now % base now base l[j] l j add[now % base] += 1 add[now % base] add now % base now base 1 now //= base now base if 0 in now_l[:base - 1]:
            continue
         0 in now_l[:base - 1] 0 now_l[:base - 1] now_l :base - 1 base - 1 base 1 continue abs(target[i] - now_l[i]) for i in range(3) for i in range(3) i range(3) range 3 for i in range(3) abs(target[i] - now_l[i]) abs target[i] - now_l[i] target[i] target i now_l[i] now_l i now_ans = sum([abs(target[i] - now_l[i]) for i in range(3)]) + (sum(add[:3]) - 3) * 10 now_ans sum([abs(target[i] - now_l[i]) for i in range(3)]) + (sum(add[:3]) - 3) * 10 sum([abs(target[i] - now_l[i]) for i in range(3)]) sum [abs(target[i] - now_l[i]) for i in range(3)] (sum(add[:3]) - 3) * 10 sum(add[:3]) - 3 sum(add[:3]) sum add[:3] add :3 3 3 10 ans = min(ans, now_ans) ans min(ans, now_ans) min ans now_ans print(0 if all(t in l for t in target) else ans) print 0 if all(t in l for t in target) else ans all(t in l for t in target) all t in l t l 0 ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, *target = map(int, input().split())
    l = [int(input()) for _ in range(n)]
    ans = float("inf")
    base = 4
    for i in range(pow(base, n)):
        now_l = [0] * base
        add = [0] * base
        now = i
        for j in range(n):
            now_l[now % base] += l[j]
            add[now % base] += 1
            now //= base
        if 0 in now_l[:base - 1]:
            continue
        now_ans = sum([abs(target[i] - now_l[i]) for i in range(3)]) + (sum(add[:3]) - 3) * 10
        ans = min(ans, now_ans)
    print(0 if all(t in l for t in target) else ans) def main():
    n, *target = map(int, input().split())
    l = [int(input()) for _ in range(n)]
    ans = float("inf")
    base = 4
    for i in range(pow(base, n)):
        now_l = [0] * base
        add = [0] * base
        now = i
        for j in range(n):
            now_l[now % base] += l[j]
            add[now % base] += 1
            now //= base
        if 0 in now_l[:base - 1]:
            continue
        now_ans = sum([abs(target[i] - now_l[i]) for i in range(3)]) + (sum(add[:3]) - 3) * 10
        ans = min(ans, now_ans)
    print(0 if all(t in l for t in target) else ans) main
def main():
    n, *target = map(int, input().split())
    l = [int(input()) for _ in range(n)]
    ans = float("inf")
    base = 4
    for i in range(pow(base, n)):
        now_l = [0] * base
        add = [0] * base
        now = i
        for j in range(n):
            now_l[now % base] += l[j]
            add[now % base] += 1
            now //= base
        if 0 in now_l[:base - 1]:
            continue
        now_ans = sum([abs(target[i] - now_l[i]) for i in range(3)]) + (sum(add[:3]) - 3) * 10
        ans = min(ans, now_ans)
    print(0 if all(t in l for t in target) else ans)


if __name__ == '__main__':
    main()
