import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
patterns = []
def saiki(n, pat):
    if n == 0:
        patterns.append(pat)
        return
    for c in 'ABCX':
        pat += c
        saiki(n-1, pat)
        pat = pat[:-1]
def main():
    N, A, B, C = LI()
    L = []
    ans = inf
    for _ in range(N):
        L.append(I())

    saiki(len(L), '')
    for pat in patterns:
        if 'A' in pat and 'B' in pat and 'C' in pat:
            pass
        else:
            continue

        a, b, c = 0, 0, 0
        MP = 0
        for i, ch in enumerate(pat):
            if ch == 'X':
                continue

            if ch == 'A':
                if a > 0:
                    MP += 10
                a += L[i]
            if ch == 'B':
                if b > 0:
                    MP += 10
                b += L[i]
            if ch == 'C':
                if c > 0:
                    MP += 10
                c += L[i]
        tmp = min(
            abs(A-a) + abs(B-b) + abs(C-c),
            abs(A-a) + abs(B-c) + abs(C-b),
            abs(A-b) + abs(B-a) + abs(C-c),
            abs(A-b) + abs(B-c) + abs(C-a),
            abs(A-c) + abs(B-b) + abs(C-a),
            abs(A-c) + abs(B-a) + abs(C-b),
        )
        MP += tmp
        if MP < ans:
            ans_pat = pat
            ans = min(MP, ans)
    print(ans)

main()
 import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools math string itertools fractions heapq collections re array bisect sys random time copy functools from collections import deque sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 inf = 10**20 inf 10**20 10 20 mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 DR = [1, -1, 0, 0] DR [1, -1, 0, 0] 1 -1 0 0 DC = [0, 0, 1, -1] DC [0, 0, 1, -1] 0 0 1 -1 int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x def LI(): return [int(x) for x in sys.stdin.readline().split()] LI int(x)-1 for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x)-1 int(x) int x 1 def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] LI_ float(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() float(x) float x def LF(): return [float(x) for x in sys.stdin.readline().split()] LF def LS(): return sys.stdin.readline().split() LS def I(): return int(sys.stdin.readline()) I def F(): return float(sys.stdin.readline()) F def S(): return input()
      S patterns = [] patterns [] def saiki(n, pat):
    if n == 0:
        patterns.append(pat)
        return
    for c in 'ABCX':
        pat += c
        saiki(n-1, pat)
        pat = pat[:-1] saiki if n == 0:
        patterns.append(pat)
        return
     n == 0 n 0 patterns.append(pat) patterns.append patterns append pat return for c in 'ABCX':
        pat += c
        saiki(n-1, pat)
        pat = pat[:-1] c 'ABCX' pat += c pat c saiki(n-1, pat) saiki n-1 n 1 pat pat = pat[:-1] pat pat[:-1] pat :-1 -1 n n pat pat def main():
    N, A, B, C = LI()
    L = []
    ans = inf
    for _ in range(N):
        L.append(I())

    saiki(len(L), '')
    for pat in patterns:
        if 'A' in pat and 'B' in pat and 'C' in pat:
            pass
        else:
            continue

        a, b, c = 0, 0, 0
        MP = 0
        for i, ch in enumerate(pat):
            if ch == 'X':
                continue

            if ch == 'A':
                if a > 0:
                    MP += 10
                a += L[i]
            if ch == 'B':
                if b > 0:
                    MP += 10
                b += L[i]
            if ch == 'C':
                if c > 0:
                    MP += 10
                c += L[i]
        tmp = min(
            abs(A-a) + abs(B-b) + abs(C-c),
            abs(A-a) + abs(B-c) + abs(C-b),
            abs(A-b) + abs(B-a) + abs(C-c),
            abs(A-b) + abs(B-c) + abs(C-a),
            abs(A-c) + abs(B-b) + abs(C-a),
            abs(A-c) + abs(B-a) + abs(C-b),
        )
        MP += tmp
        if MP < ans:
            ans_pat = pat
            ans = min(MP, ans)
    print(ans) main N, A, B, C = LI() N LI() LI A B C L = [] L [] ans = inf ans inf for _ in range(N):
        L.append(I())

     _ range(N) range N L.append(I()) L.append L append I() I saiki(len(L), '') saiki len(L) len L '' for pat in patterns:
        if 'A' in pat and 'B' in pat and 'C' in pat:
            pass
        else:
            continue

        a, b, c = 0, 0, 0
        MP = 0
        for i, ch in enumerate(pat):
            if ch == 'X':
                continue

            if ch == 'A':
                if a > 0:
                    MP += 10
                a += L[i]
            if ch == 'B':
                if b > 0:
                    MP += 10
                b += L[i]
            if ch == 'C':
                if c > 0:
                    MP += 10
                c += L[i]
        tmp = min(
            abs(A-a) + abs(B-b) + abs(C-c),
            abs(A-a) + abs(B-c) + abs(C-b),
            abs(A-b) + abs(B-a) + abs(C-c),
            abs(A-b) + abs(B-c) + abs(C-a),
            abs(A-c) + abs(B-b) + abs(C-a),
            abs(A-c) + abs(B-a) + abs(C-b),
        )
        MP += tmp
        if MP < ans:
            ans_pat = pat
            ans = min(MP, ans)
     pat patterns if 'A' in pat and 'B' in pat and 'C' in pat:
            pass
        else:
            continue

         'A' in pat and 'B' in pat and 'C' in pat 'A' in pat and 'B' in pat 'A' in pat 'A' pat 'B' in pat 'B' pat 'C' in pat 'C' pat continue a, b, c = 0, 0, 0 a 0 b 0 c 0 MP = 0 MP 0 for i, ch in enumerate(pat):
            if ch == 'X':
                continue

            if ch == 'A':
                if a > 0:
                    MP += 10
                a += L[i]
            if ch == 'B':
                if b > 0:
                    MP += 10
                b += L[i]
            if ch == 'C':
                if c > 0:
                    MP += 10
                c += L[i]
         i ch enumerate(pat) enumerate pat if ch == 'X':
                continue

             ch == 'X' ch 'X' continue if ch == 'A':
                if a > 0:
                    MP += 10
                a += L[i]
             ch == 'A' ch 'A' if a > 0:
                    MP += 10
                 a > 0 a 0 MP += 10 MP 10 a += L[i] a L[i] L i if ch == 'B':
                if b > 0:
                    MP += 10
                b += L[i]
             ch == 'B' ch 'B' if b > 0:
                    MP += 10
                 b > 0 b 0 MP += 10 MP 10 b += L[i] b L[i] L i if ch == 'C':
                if c > 0:
                    MP += 10
                c += L[i]
         ch == 'C' ch 'C' if c > 0:
                    MP += 10
                 c > 0 c 0 MP += 10 MP 10 c += L[i] c L[i] L i tmp = min(
            abs(A-a) + abs(B-b) + abs(C-c),
            abs(A-a) + abs(B-c) + abs(C-b),
            abs(A-b) + abs(B-a) + abs(C-c),
            abs(A-b) + abs(B-c) + abs(C-a),
            abs(A-c) + abs(B-b) + abs(C-a),
            abs(A-c) + abs(B-a) + abs(C-b),
        ) tmp min(
            abs(A-a) + abs(B-b) + abs(C-c),
            abs(A-a) + abs(B-c) + abs(C-b),
            abs(A-b) + abs(B-a) + abs(C-c),
            abs(A-b) + abs(B-c) + abs(C-a),
            abs(A-c) + abs(B-b) + abs(C-a),
            abs(A-c) + abs(B-a) + abs(C-b),
        ) min abs(A-a) + abs(B-b) + abs(C-c) abs(A-a) + abs(B-b) abs(A-a) abs A-a A a abs(B-b) abs B-b B b abs(C-c) abs C-c C c abs(A-a) + abs(B-c) + abs(C-b) abs(A-a) + abs(B-c) abs(A-a) abs A-a A a abs(B-c) abs B-c B c abs(C-b) abs C-b C b abs(A-b) + abs(B-a) + abs(C-c) abs(A-b) + abs(B-a) abs(A-b) abs A-b A b abs(B-a) abs B-a B a abs(C-c) abs C-c C c abs(A-b) + abs(B-c) + abs(C-a) abs(A-b) + abs(B-c) abs(A-b) abs A-b A b abs(B-c) abs B-c B c abs(C-a) abs C-a C a abs(A-c) + abs(B-b) + abs(C-a) abs(A-c) + abs(B-b) abs(A-c) abs A-c A c abs(B-b) abs B-b B b abs(C-a) abs C-a C a abs(A-c) + abs(B-a) + abs(C-b) abs(A-c) + abs(B-a) abs(A-c) abs A-c A c abs(B-a) abs B-a B a abs(C-b) abs C-b C b MP += tmp MP tmp if MP < ans:
            ans_pat = pat
            ans = min(MP, ans)
     MP < ans MP ans ans_pat = pat ans_pat pat ans = min(MP, ans) ans min(MP, ans) min MP ans print(ans) print ans main() main DR = [1, -1, 0, 0] [1, -1, 0, 0] DR def main():
    N, A, B, C = LI()
    L = []
    ans = inf
    for _ in range(N):
        L.append(I())

    saiki(len(L), '')
    for pat in patterns:
        if 'A' in pat and 'B' in pat and 'C' in pat:
            pass
        else:
            continue

        a, b, c = 0, 0, 0
        MP = 0
        for i, ch in enumerate(pat):
            if ch == 'X':
                continue

            if ch == 'A':
                if a > 0:
                    MP += 10
                a += L[i]
            if ch == 'B':
                if b > 0:
                    MP += 10
                b += L[i]
            if ch == 'C':
                if c > 0:
                    MP += 10
                c += L[i]
        tmp = min(
            abs(A-a) + abs(B-b) + abs(C-c),
            abs(A-a) + abs(B-c) + abs(C-b),
            abs(A-b) + abs(B-a) + abs(C-c),
            abs(A-b) + abs(B-c) + abs(C-a),
            abs(A-c) + abs(B-b) + abs(C-a),
            abs(A-c) + abs(B-a) + abs(C-b),
        )
        MP += tmp
        if MP < ans:
            ans_pat = pat
            ans = min(MP, ans)
    print(ans) def main():
    N, A, B, C = LI()
    L = []
    ans = inf
    for _ in range(N):
        L.append(I())

    saiki(len(L), '')
    for pat in patterns:
        if 'A' in pat and 'B' in pat and 'C' in pat:
            pass
        else:
            continue

        a, b, c = 0, 0, 0
        MP = 0
        for i, ch in enumerate(pat):
            if ch == 'X':
                continue

            if ch == 'A':
                if a > 0:
                    MP += 10
                a += L[i]
            if ch == 'B':
                if b > 0:
                    MP += 10
                b += L[i]
            if ch == 'C':
                if c > 0:
                    MP += 10
                c += L[i]
        tmp = min(
            abs(A-a) + abs(B-b) + abs(C-c),
            abs(A-a) + abs(B-c) + abs(C-b),
            abs(A-b) + abs(B-a) + abs(C-c),
            abs(A-b) + abs(B-c) + abs(C-a),
            abs(A-c) + abs(B-b) + abs(C-a),
            abs(A-c) + abs(B-a) + abs(C-b),
        )
        MP += tmp
        if MP < ans:
            ans_pat = pat
            ans = min(MP, ans)
    print(ans) main patterns = [] [] patterns inf = 10**20 10**20 inf def S(): return input()
      def S(): return input()
      S mod = 10**9 + 7 10**9 + 7 mod def saiki(n, pat):
    if n == 0:
        patterns.append(pat)
        return
    for c in 'ABCX':
        pat += c
        saiki(n-1, pat)
        pat = pat[:-1] def saiki(n, pat):
    if n == 0:
        patterns.append(pat)
        return
    for c in 'ABCX':
        pat += c
        saiki(n-1, pat)
        pat = pat[:-1] saiki def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I def LF(): return [float(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] LF def F(): return float(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) F def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS DC = [0, 0, 1, -1] [0, 0, 1, -1] DC def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI(): return [int(x) for x in sys.stdin.readline().split()] LI def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] LI_
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
patterns = []
def saiki(n, pat):
    if n == 0:
        patterns.append(pat)
        return
    for c in 'ABCX':
        pat += c
        saiki(n-1, pat)
        pat = pat[:-1]
def main():
    N, A, B, C = LI()
    L = []
    ans = inf
    for _ in range(N):
        L.append(I())

    saiki(len(L), '')
    for pat in patterns:
        if 'A' in pat and 'B' in pat and 'C' in pat:
            pass
        else:
            continue

        a, b, c = 0, 0, 0
        MP = 0
        for i, ch in enumerate(pat):
            if ch == 'X':
                continue

            if ch == 'A':
                if a > 0:
                    MP += 10
                a += L[i]
            if ch == 'B':
                if b > 0:
                    MP += 10
                b += L[i]
            if ch == 'C':
                if c > 0:
                    MP += 10
                c += L[i]
        tmp = min(
            abs(A-a) + abs(B-b) + abs(C-c),
            abs(A-a) + abs(B-c) + abs(C-b),
            abs(A-b) + abs(B-a) + abs(C-c),
            abs(A-b) + abs(B-c) + abs(C-a),
            abs(A-c) + abs(B-b) + abs(C-a),
            abs(A-c) + abs(B-a) + abs(C-b),
        )
        MP += tmp
        if MP < ans:
            ans_pat = pat
            ans = min(MP, ans)
    print(ans)

main()

