CodeEff/ECCO huggingface dataset:
# Original solution

"""

貪欲か？
今いる地点から左のRと右のLの数を比較
多い方の最遠点に行く→そのような点が無くなったら終了

証明は…
まず右のR,左のLは無意味→区間を無駄にするだけ
少ない方に行く→多い方の区間が無駄になる
近い点に行く→　ここがむずい
遠い区間が無駄になるのを防ぐため？

実装は？
多い方の処理→BITで左にあるRの数と右にあるLの数をlogNで
優先度付きキューで最小のRと最大のLを検出
10^5+1 を足して1 ～ 2*10^5 + 1の区間として扱う
初期・終了地点は　10^5+1

"""
import heapq

def bitadd(a,w,bit): #aにwを加える(1-origin)
 
    x = a
    while x <= (len(bit)-1):
        bit[x] += w
        x += x & (-1 * x)
 
def bitsum(a,bit): #ind 1～aまでの和を求める
 
    ret = 0
    x = a
    while x > 0:
        ret += bit[x]
        x -= x & (-1 * x)
    return ret

N = int(eval(input()))

used = [False] * N
lq = []
rq = []
LR = []

LBIT = [0] * (2 * (10**5) + 10)
RBIT = [0] * (2 * (10**5) + 10)

for i in range(N):

    L,R = list(map(int,input().split()))

    L += 10**5+1
    R += 10**5+1

    LR.append([L,R])
    
    heapq.heappush(lq,[-1 * L,i])
    heapq.heappush(rq,[R,i])

    bitadd(L,1,LBIT)
    bitadd(R,1,RBIT)


ans = 0
now = 10**5+1

for i in range(N):

    R_in_left  = bitsum(now-1,RBIT)
    L_in_right = N - i - bitsum(now,LBIT)
    

    if R_in_left >= L_in_right: #左にあるRに移動

        while len(rq) > 0 and used[ rq[0][1] ]:
            heapq.heappop(rq)

        if len(rq) == 0:
            break

        nexp,nexind = heapq.heappop(rq)
        pair = LR[nexind][0]

        bitadd(nexp,-1,RBIT)
        bitadd(pair,-1,LBIT)
        used[nexind] = True

        if nexp >= now:
            break

        ans += now - nexp
        now = nexp

    else:

        while len(lq) > 0 and used[ lq[0][1] ]:
            heapq.heappop(lq)

        if len(lq) == 0:
            break

        nexp,nexind = heapq.heappop(lq)
        nexp *= -1
        pair = LR[nexind][1]

        bitadd(nexp,-1,LBIT)
        bitadd(pair,-1,RBIT)
        used[nexind] = True

        if nexp <= now:
            break

        ans += nexp - now
        now = nexp

ans += abs(10**5+1 - now)

print (ans)

        



# Optimized solution

N = int(eval(input()))

L = []
R = []

for i in range(N):
    l,r = list(map(int,input().split()))
    L.append(2 * l)
    R.append(-2 * r)

L.sort()
R.sort()
L.reverse()
R.reverse()

ans = 0

now = 0
for i in range(N):
    now += L[i]
    ans = max(ans,now)
    now += R[i]
    ans = max(ans,now)

now = 0
for i in range(N):
    now += R[i]
    ans = max(ans,now)
    now += L[i]
    ans = max(ans,now)

print (ans)
# Original solution
import sys
import heapq
import copy
input = sys.stdin.buffer.readline

N = int(eval(input()))
pq_L = []
pq_R = []
for i in range(N):
    L, R = list(map(int, input().split()))
    heapq.heappush(pq_L, (-L, i))
    heapq.heappush(pq_R, (R, i))
pq_L2 = copy.deepcopy(pq_L)
pq_R2 = copy.deepcopy(pq_R)

ans1 = 0
prev = 0
used = [0] * N
for i in range(N):
    if i % 2 == 0:
        while True:
            _x, j = heapq.heappop(pq_L)
            x = -_x
            if not used[j]:
                used[j] = 1
                break
        if prev < x:
            ans1 += x - prev
            prev = x
    else:
        while True:
            x, j = heapq.heappop(pq_R)
            if not used[j]:
                used[j] = 1
                break
        if prev > x:
            ans1 += prev - x
            prev = x

ans1 += abs(prev)

ans2 = 0
prev = 0
used = [0] * N
for i in range(N):
    if i % 2 == 1:
        while True:
            _x, j = heapq.heappop(pq_L2)
            x = -_x
            if not used[j]:
                used[j] = 1
                break
        if prev < x:
            ans2 += x - prev
            prev = x
    else:
        while True:
            x, j = heapq.heappop(pq_R2)
            if not used[j]:
                used[j] = 1
                break
        if prev > x:
            ans2 += prev - x
            prev = x

ans2 += abs(prev)

print((max(ans1, ans2)))


# Optimized solution
import sys
import heapq
import copy
input = sys.stdin.buffer.readline

def main():
    N = int(eval(input()))
    pq_L = []
    pq_R = []
    for i in range(N):
        L, R = list(map(int, input().split()))
        heapq.heappush(pq_L, (-L, i))
        heapq.heappush(pq_R, (R, i))
    pq_L2 = copy.deepcopy(pq_L)
    pq_R2 = copy.deepcopy(pq_R)

    ans1 = 0
    prev = 0
    used = [0] * N
    for i in range(N):
        if i % 2 == 0:
            while True:
                _x, j = heapq.heappop(pq_L)
                x = -_x
                if not used[j]:
                    used[j] = 1
                    break
            if prev < x:
                ans1 += x - prev
                prev = x
        else:
            while True:
                x, j = heapq.heappop(pq_R)
                if not used[j]:
                    used[j] = 1
                    break
            if prev > x:
                ans1 += prev - x
                prev = x

    ans1 += abs(prev)

    ans2 = 0
    prev = 0
    used = [0] * N
    for i in range(N):
        if i % 2 == 1:
            while True:
                _x, j = heapq.heappop(pq_L2)
                x = -_x
                if not used[j]:
                    used[j] = 1
                    break
            if prev < x:
                ans2 += x - prev
                prev = x
        else:
            while True:
                x, j = heapq.heappop(pq_R2)
                if not used[j]:
                    used[j] = 1
                    break
            if prev > x:
                ans2 += prev - x
                prev = x

    ans2 += abs(prev)

    print((max(ans1, ans2)))


if __name__ == '__main__':
    main()
# Original solution
from sys import stdin, stdout
from time import perf_counter

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


l = [int(item) for item in input().split()]

if (l[0]==5 and l[1] == 5 and l[2]==7) or (l[0]==5 and l[1] == 7 and l[2]==5) or (l[0]==7 and l[1] == 5 and l[2]==5):
    print("YES")
else:
    print("NO")

# Optimized solution
from sys import stdin, stdout
from time import perf_counter

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


l= sorted(map(int, input().split()))

print(("YES" if l == [5,5,7] else "NO"))
# Original solution
'''To count the number of occurrences of 
something in a programs

Use count fucntion of the list
'''


a=list(map(int,input().split()))
if a.count(5)==2 and a.count(7)==1:
	print("YES")
else:
	print("NO")


# Optimized solution
seq = [int(s) for s in input().split()]
if seq.count(5) == 2 and seq.count(7) == 1:
	print("YES")
else: print("NO")
# Original solution
L = [int(x) for x in input().split()]
L.sort()

if L == [5,5,7]:
    print("YES")
else:
    print("NO")


# Optimized solution
L = sorted(list(map(int, input().split())))
print(('YES' if L[0]==L[1]==5 and L[2]==7 else 'NO'))
# Original solution
L = sorted(list(map(int, input().split())))
if L == [5,5,7]:
 print("YES")
else:
 print("NO")

# Optimized solution
S = [int(i) for i in input().split()]
S.sort()
if S == [5,5,7]:
	print("YES")
else:
	print("NO")
# Original solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    ABC = list(map(int, input().split()))
    print(('YES' if ABC.count(5) == 2 and ABC.count(7) == 1 else 'NO'))


if __name__ == "__main__":
    main()


# Optimized solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    ABC = list(map(int, input().split()))
    ABC.sort()
    print(('YES' if [5, 5, 7] == ABC else 'NO'))


if __name__ == "__main__":
    main()
# Original solution
abc = list(map(int,input().split()))
print(("YES" if abc.count(5) == 2 and abc.count(7) == 1 else "NO"))

# Optimized solution
abc = list(map(int, input().split()))
if abc.count(5) == 2 and abc.count(7) == 1: print("YES")
else: print("NO")
# Original solution
ABC = list(map(int,input().split()))

print(("YES" if ABC.count(5)==2 and ABC.count(7)==1 else "NO"))

# Optimized solution
X = list(map(int,input().split()))
print(("YES" if X.count(5)==2 and X.count(7)==1 else "NO"))
# Original solution
a = list(map(int,input().split()))
b = sorted(a)
print(('YES' if b[0]==5 and b[1]==5 and b[2]==7 else 'NO'))

# Optimized solution
a = input().split()
b = sorted(a)
if b == ['5','5','7']:
    print('YES')
else:
    print('NO')
# Original solution
print((["NO","YES"][eval(input().replace(" ","*"))==175]))

# Optimized solution
a,b,c=list(map(str,input().split()))
s=a+b+c
if s.count("5")==2 and s.count("7")==1:
    print("YES")
else:
    print("NO")
# Original solution
a,b,c = list(map(int, input().split()))
print(('YES' if a+b+c==17 else 'NO'))

# Optimized solution
a = [int(_) for _ in input().split()]
a.sort()
print(('YES' if a[0]==a[1]==5 and a[2]==7 else 'NO'))
# Original solution
a,b,c=sorted(map(int,input().split()))
print((["NO","YES"][a==b==5 and c==7]))

# Optimized solution
a,b,c=sorted(input().split())
print((["NO","YES"][a==b=="5" and c=="7"]))
# Original solution
#ABC42 A
#リストで書いた場合
myList=[]
myList_int=[]
myList=input().split() #split()でリストに入力をstrで入れる
myList_int=[int(s) for s in myList] #intに変換

#print(myList)

if myList_int== [7,5,5]:
    print("YES")
elif myList_int== [5,7,5] :
    print("YES")
elif myList_int== [5,5,7] :
    print("YES")
else:
    print("NO")

# Optimized solution
myList=[]
myList_int=[]
myList=input().split() #split()でリストに入力をstrで入れる
myList_int=[int(s) for s in myList] #intに変換

#print(myList)

if myList_int== [7,5,5]:
    print("YES")
elif myList_int== [5,7,5] :
    print("YES")
elif myList_int== [5,5,7] :
    print("YES")
else:
    print("NO")
# Original solution
ABC=list(map(int,input().split()))
print(("YES" if ABC.count(5)==2 and ABC.count(7)==1 else "NO"))


# Optimized solution
ABC=input().split()
if ABC.count("5")==2 and ABC.count("7")==1:
  print("YES")
else:
  print("NO")
# Original solution
# -*- coding: utf-8 -*-

if __name__ == "__main__":
    # str_list = [map(int, input().split())]
    # if str_list.count(5) == 2 and str_list.count(7) == 1:
    #     print('YES')
    # else:
    #     print('NO')
    str_list = list(map(int, input().split()))
    if sum(str_list) == 17:
        print('YES')
    else:
        print('NO')







# Optimized solution
# -*- coding: utf-8 -*-

if __name__ == "__main__":
    str_list = list(map(int, input().split()))
    if sum(str_list) == 17:
        print('YES')
    else:
        print('NO')
# Original solution
# ABC158 A

def main():
    list = input().split()
    list.sort()
    if ''.join(list) == '557':
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    list = input().split()
    list.sort()
    if ''.join(list) == '557':
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()
# Original solution
List=list(map(int,input().split()))
print(('YES' if List.count(7)==1 and List.count(5)==2 else 'NO'))

# Optimized solution
l=list(input().split()) 
print(('YES' if l.count('5')==2 and l.count('7')==1 else 'NO'))
# Original solution
l = list(input().split())
five = 0
seven = 0
for i in l:
  if i == '5':
    five += 1
  elif i == '7':
    seven += 1
  else:
    pass

if five == 2 and seven == 1:
  print('YES')
else:
  print('NO')

# Optimized solution
l = list(map(int, input().split()))
print((['NO', 'YES'][l.count(5) == 2 and l.count(7) == 1]))
# Original solution
import sys
a=list(map(int,input().split()))
s=0
f=0

for i in range(3):
  s+=a[i]
  
if s!=17:
  print('NO')
  sys.exit()
  
else:
  for t in range(3):
    if a[t]==5:
      f+=1
      
if f==2:
  print('YES')
  

else:
  print('NO')
  

# Optimized solution
a=list(map(int,input().split()))

b=a[0]+a[1]+a[2]
c=a[2]-a[1]-a[0]

if b==17 and (c==-7 or c==-3):
  
  print('YES')

else:
  print('NO')
# Original solution
def slove():
    import sys, collections
    input = sys.stdin.readline
    a = dict(collections.Counter(list(map(int, input().rstrip('\n').split()))).most_common())
    print(("YES" if a[5] == 2 and a[7] == 1 else "NO"))


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    input = sys.stdin.readline
    a = "".join(sorted(list(map(str, str(input().rstrip('\n')).split()))))
    print(("YES" if a == "557" else "NO"))


if __name__ == '__main__':
    slove()
# Original solution
S = list(map(int, input().split()))

S.sort()

if S[0] == 5 and S[1] == 5 and S[2] == 7:
  print("YES")
else:
  print("NO")

# Optimized solution
L = list(map(int, input().split()))
L.sort()
if L[0]==5 and L[1]==5 and L[2] == 7:
  print("YES")
else:
  print("NO")
# Original solution
ABC = list(map(int, input().split()))
if ABC.count(5) == 2 and ABC.count(7):
    print('YES')
else:
    print('NO')

# Optimized solution
ABC = list(map(int, input().split()))
if ABC.count(5) == 2 and ABC.count(7) == 1:
    print('YES')
else:
    print('NO')
# Original solution
l = list(map(int, input().split()))
l.sort(reverse=True)
if l[0] == 7 and l[1] == 5 and l[2] == 5:
  print('YES')
else:
  print('NO')

# Optimized solution
a = list(map(int, input().split()))
cnt_5 = 0
cnt_7 = 0

for i in a:
  if i == 5:
    cnt_5 += 1
  if i == 7:
    cnt_7 += 1
      
if cnt_5 == 2 and cnt_7 == 1:
  print('YES')
else:
  print('NO')
# Original solution
go=0
nana=0
num = input().split()
for i in num:
  if i == "5":
    go+=1
  if i == "7":
    nana+=1
if (go==2) and (nana==1):
  print("YES")
else:
  print("NO")

# Optimized solution
num = input().split()
go = 0
nana = 0
for i in num:
    if i == "5":
        go+=1
    if i == "7":
        nana+=1
if (go==2) and (nana==1):
    print("YES")
else:
    print("NO")
# Original solution
input1 = list(map(int,input().split()))
A = input1[0]
B = input1[1]
C = input1[2]
if A == 5:
  if B == 5 and C == 7:
    print("YES")
  elif B == 7 and C == 5:
    print("YES")
  else:
    print("NO")
elif A == 7:
  if B == 5 and C == 5:
    print("YES")
  else:
    print("NO")
else:
  print("NO")

# Optimized solution
a,b,c=list(map(int,input().split()))
print(("YES" if a*b*c==175 else "NO"))
# Original solution
a,b,c=list(map(int, input().split()))
if a==5 and b==5 and c==7:
  print('YES')
elif a==5 and b==7 and c==5:
  print('YES')
elif a==7 and b==5 and c==5:
  print('YES')
else:
  print('NO')

# Optimized solution
myList = list(map(int, input().split()))
if myList.count(5)==2 and myList.count(7)==1:
  print('YES')
else:
  print('NO')
# Original solution
A = sorted([int(i) for i in input().split()])
print(('YES' if A == [5, 5, 7] else 'NO'))

# Optimized solution
A = sorted(input().split())
print(('YES' if A == ['5', '5', '7'] else 'NO'))
# Original solution
l = input().split()
print(("YES" if sorted(l) == ['5', '5', '7'] else "NO"))

# Optimized solution
l = list(map(int, input().split()))
print(("YES" if sorted(l) == [5, 5, 7] else "NO"))
# Original solution
N,A,B,C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]

ans = float('inf')
for i in range(1<<N):
    for j in range(1<<N):
        a,b,c = [],[],[]
        cost = 0
        for keta in range(N):
            bit_i = i&(1<<keta)
            bit_j = j&(1<<keta)
            if bit_i==0 and bit_j==0:
                a.append(keta)
            elif bit_i==0 and bit_j>0:
                b.append(keta)
            elif bit_i>0 and bit_j==0:
                c.append(keta)
            else:
                pass
        if a==[] or b==[] or c==[]:
            continue
        cost += 10*(len(a)+len(b)+len(c)-3)
        for l,val in zip([a,b,c],
                         [A,B,C]):
            s = sum([L[li] for li in l])
            cost += abs(s-val)
        ans = min(ans, cost)

print(ans)
                

# Optimized solution
from itertools import product
N,A,B,C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = float('inf')
for p in product(list(range(4)), repeat=N): # 4^Nループ
    take = [[] for _ in range(4)] # [A,B,C,使わない]
    for i in range(N):
        take[p[i]].append(L[i])
    a,b,c = take[0],take[1],take[2]
    if len(a)*len(b)*len(c)==0:
        continue 
    cost = (len(a)+len(b)+len(c)-3)*10
    cost += abs(sum(a)-A)+abs(sum(b)-B)+abs(sum(c)-C)
    ans = min(ans, cost)
print(ans)
# Original solution
# 8重for
# N,A,B,C = 5,100,90,80
# L = [98,40,30,21,80]
N,A,B,C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = float('inf')
for i1 in range(4):
    for i2 in range(4):
        for i3 in range(4):
            for i4 in range(4):
                for i5 in range(4):
                    for i6 in range(4):
                        for i7 in range(4):
                            for i8 in range(4):
                                p = [i1,i2,i3,i4,i5,i6,i7,i8]
                                take = [[] for _ in range(4)] # [A,B,C,使わない]
                                for i in range(N):
                                    take[p[i]].append(L[i])
                                a,b,c = take[0],take[1],take[2]
                                if len(a)*len(b)*len(c)==0:
                                    continue 
                                cost = (len(a)+len(b)+len(c)-3)*10
                                cost += abs(sum(a)-A)+abs(sum(b)-B)+abs(sum(c)-C)
                                ans = min(ans, cost)
print(ans)

# Optimized solution
# DFS
# N,A,B,C = 5,100,90,80
# L = [98,40,30,21,80]
N,A,B,C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = float('inf')

def dfs(cur,a,b,c)->int:
    if cur==N:
        if min(a,b,c)>0: return abs(a-A)+abs(b-B)+abs(c-C)-30
        else:            return float('inf')
        
    ret0 = dfs(cur+1, a,       b,       c)
    ret1 = dfs(cur+1, a+L[cur],b,       c) + 10
    ret2 = dfs(cur+1, a,       b+L[cur],c) + 10
    ret3 = dfs(cur+1, a,       b,       c+L[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print((dfs(0,0,0,0)))
# Original solution
n, a, b, c = list(map(int, input().split()))
l = []
for _ in range(n):
    l.append(int(eval(input())))

def dfs(depth, t, ans):
    if depth == n:
        sum = calc(t)
        if sum < ans:
            return sum
        else:
            return ans

    for j in range(4):
        tt = t.copy()
        tt.append(j)
        ans = dfs(depth + 1, tt, ans)

    return ans

def calc(t):
    ttt = [ [0, 0] ] * 3

    for i, v in enumerate(t):
        if v < 3:
            ttt[v] = [ttt[v][0] + 1, ttt[v][1] + l[i]]

    if ttt[0][0] == 0 or ttt[1][0] == 0 or ttt[2][0] == 0:
        return 1000000000

    sum = 0
    abc = [a, b, c, 0]
    for i, v in enumerate(ttt):
        sum += ((v[0] - 1) * 10) + abs(v[1] - abc[i])

    return sum


ans = dfs(0, [], 1000000000)
print(ans)

# Optimized solution
N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(N)]
INF = 10**12

def dfs(depth, a, b, c):
    if depth == N:
        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF

    res1 = dfs(depth + 1, a, b, c)
    res2 = dfs(depth + 1, a + l[depth], b, c) + 10
    res3 = dfs(depth + 1, a, b + l[depth], c) + 10
    res4 = dfs(depth + 1, a, b, c + l[depth]) + 10

    return min(res1, res2, res3, res4)

print((dfs(0, 0, 0, 0)))
# Original solution
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]


def solve(X):
    if not ("1" in X and "2" in X and "3" in X):
        return 1e10

    MS = [[L[i] for i in range(N) if X[i] == j] for j in "123"]
    ret = 1e10
    ret = min(ret, solve2(MS[0], A) + solve2(MS[1], B) + solve2(MS[2], C))
    ret = min(ret, solve2(MS[0], A) + solve2(MS[2], B) + solve2(MS[1], C))
    ret = min(ret, solve2(MS[1], A) + solve2(MS[0], B) + solve2(MS[2], C))
    ret = min(ret, solve2(MS[1], A) + solve2(MS[2], B) + solve2(MS[0], C))
    ret = min(ret, solve2(MS[2], A) + solve2(MS[0], B) + solve2(MS[1], C))
    ret = min(ret, solve2(MS[2], A) + solve2(MS[1], B) + solve2(MS[0], C))
    return ret


def solve2(M, target):
    def rec(Y, target):
        # Y: [1, 0, 0]
        if len(Y) == len(M):
            if len(set(Y)) == 1 and Y[0] == 0:
                return 1e10
            sum_M = sum([M[i] for i in range(len(M)) if Y[i] == 1])
            return abs(target - sum_M) + 10 * (Y.count(1) - 1)
        return min(rec(Y + [0], target), rec(Y + [1], target))
    ret = rec([], target)
    return ret


ans = 1e10


def rec(X):
    global ans
    if len(X) == N:
        ans = min(ans, solve(X))
        return
    rec(X + "1")
    rec(X + "2")
    rec(X + "3")


rec("")

print(ans)


# Optimized solution
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]


def solve(X):
    if not ("1" in X and "2" in X and "3" in X):
        return 1e10

    MS = [[L[i] for i in range(N) if X[i] == j] for j in "123"]
    ret = 1e10
    A_ans = []
    B_ans = []
    C_ans = []
    for i in range(3):
        A_ans.append(solve2(MS[i], A))
        B_ans.append(solve2(MS[i], B))
        C_ans.append(solve2(MS[i], C))
    ret = min(ret, A_ans[0] + B_ans[1] + C_ans[2])
    ret = min(ret, A_ans[0] + B_ans[2] + C_ans[1])
    ret = min(ret, A_ans[1] + B_ans[0] + C_ans[2])
    ret = min(ret, A_ans[1] + B_ans[2] + C_ans[0])
    ret = min(ret, A_ans[2] + B_ans[0] + C_ans[1])
    ret = min(ret, A_ans[2] + B_ans[1] + C_ans[0])
    return ret


def solve2(M, target):
    def rec(Y, target):
        # Y: [1, 0, 0]
        if len(Y) == len(M):
            if len(set(Y)) == 1 and Y[0] == 0:
                return 1e10
            sum_M = sum([M[i] for i in range(len(M)) if Y[i] == 1])
            return abs(target - sum_M) + 10 * (Y.count(1) - 1)
        return min(rec(Y + [0], target), rec(Y + [1], target))
    ret = rec([], target)
    return ret


ans = 1e10


def rec(X):
    global ans
    if len(X) == N:
        ans = min(ans, solve(X))
        return
    rec(X + "1")
    rec(X + "2")
    rec(X + "3")


rec("")

print(ans)
# Original solution
n,a,b,c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
answer = a+b+c
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
  
for i in range(1, 4**n):
  aa = []
  bb = []
  cc = []
  four = list(str(Base_10_to_n(i,4).zfill(n)))
  
  if four.count("1")==0 or four.count("2")==0 or four.count("3") ==0:
    continue
  for index,f in enumerate(four) :
    if f == "0": #使わない
      continue
    elif f == "1":
      aa.append(l[index])
    elif f == "2":
      bb.append(l[index])
    elif f == "3":
      cc.append(l[index])
    else:
      break
  cur = (len(aa)-1)*10+abs(a-sum(aa))+(len(bb)-1)*10+abs(b-sum(bb))+(len(cc)-1)*10+abs(c-sum(cc))
  answer = min(answer, cur)


  
print(answer)
    
  

# Optimized solution
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, A: int, B: int, C: int, l: "List[int]"):
    # 0: 使わない 1:A 2:B 3:C
    all = list(itertools.product([0,1,2,3], repeat=N))
    answer = 10**9
    for a in all:
        a_sum = 0
        a_count = 0
        b_sum = 0
        b_count = 0
        c_sum = 0
        c_count = 0

        for i in range(len(a)):
            if a[i] == 0:
                continue
            elif a[i] == 1:
                a_sum += l[i]
                a_count +=1
            elif a[i] == 2:
                b_sum += l[i]
                b_count +=1
            elif a[i] == 3:
                c_sum += l[i]
                c_count +=1
        
        if a_count == 0 or b_count == 0 or c_count==0 :
            continue

        MP = (a_count-1)*10+(b_count-1)*10+(c_count-1)*10+abs(A-a_sum)+abs(B-b_sum)+abs(C-c_sum)

        answer = min(MP,answer)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    l = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C, l)

if __name__ == '__main__':
    main()