# -*- coding: utf-8 -*-
import copy

# calc_sub_score
def search_min( target, LL ):
    # print( "search_min :", target, "LL", LL )
    if len( LL ) < 1 :
        return( -1 )
    t_min = LL[0]
    sub_score = abs( target - t_min )
    for tp in LL :
        sub_len = abs( target - tp )
        if sub_score > sub_len :
            sub_score = sub_len
            t_min = tp
    return( t_min )

# calc_sub_score
def sub_score( mp, target, sLL ):
    min_t = search_min( target, sLL )
    if min_t < 0 :
        return( target )
    sLL.remove( min_t )
    # print( "sub_score = ", target, ":", sLL , "mp = ", mp, "min_t=", min_t)
    nokori = abs( target - min_t )
    if nokori >= 10 :
        if target < min_t :
            return( target )
        if len(sLL) <1 :
            return( mp + min_t )
        mp = sub_score( 10, nokori, sLL )
    elif nokori > 0 and nokori  < 10 :
        mp = mp + nokori
    return( mp )

# calc_score
def score( mp, ANS, LL ):
    sub = copy.deepcopy( ANS )
    for target in ANS :
        sub.remove( target )
        n_mp = sub_score( 0, target, LL )
        # print( "score = ", target, ":",  sub, "mp=", mp, "n_mp=", n_mp )
        mp += n_mp
    return( mp )

# データ数の取込み
NN, AA, BB, CC =list(map(int, input().split()))
mp = 0
ANS = [[AA, BB, CC],[AA, CC, BB],[BB, AA, CC],[BB, CC, AA],[CC, AA, BB],[CC, BB, AA]]
LL = []
for ii in range( NN ) :
    LL.append( int( input() ) )
    # print( ii, LL )
# kumi = ANS[0]
# mp = score( mp, kumi, LL )

res = -1
for kumi in ANS :
    pipe = copy.deepcopy( LL )
    mp = score( 0, kumi, pipe )
    # print( "##### kumi=", kumi,"mp=", mp, "res=", res)
    if res == -1 or res > mp :
        res = mp

print( res )