N = list(map(int,input().split()))
l = [int(input()) for i in range(N)]

if N[1] in l:
    l.remove(A)
    del N[1]
if N[2] in l:
    l.remove(B)
    del N[2]
if N[3] in l:
    l.remove(C)
    del N[3]

MP=0

for i in N[1:]:
    P1 = min([abs(x-i) for x in l])
    P2 = min([abs(x+y-i) for x in l for y in l if index(x)!=index(y)])
    
    if P1>=P2:
        MP+=P1
        else:
            MP+=P2