import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n, a, b, c = i_map()
    num_list = i_row(n)

    min_mp = INF
    for bin in list(product([0, 1, 2, 3], repeat=n)):
        ac = bin.count(1)
        bc = bin.count(2)
        cc = bin.count(3)
        if ac < 1 or bc < 1 or cc < 1:
            continue
        mp = 0
        if ac >= 2:
            mp += 10 * (ac-1)
        if bc >= 2:
            mp += 10 * (bc-1)
        if cc >= 2:
            mp += 10 * (cc-1)
        sum_a, sum_b, sum_c = 0, 0, 0
        for i in range(n):
            if bin[i] == 1:
                sum_a += num_list[i]
            elif bin[i] == 2:
                sum_b += num_list[i]
            elif bin[i] == 3:
                sum_c += num_list[i]
        mp += abs(a-sum_a)
        mp += abs(b-sum_b)
        mp += abs(c-sum_c)
        min_mp = min(min_mp, mp)
            
    print(min_mp)

if __name__ == '__main__':
    main() import sys, re sys re from math import ceil, floor, sqrt, pi, factorial from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left from functools import reduce def i_input(): return int(input()) i_input def i_map(): return map(int, input().split()) i_map def i_list(): return list(i_map()) i_list i_input() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) i_input() i_input def i_row(N): return [i_input() for _ in range(N)] i_row N N i_list() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) i_list() i_list def i_row_list(N): return [i_list() for _ in range(N)] i_row_list N N def s_input(): return input() s_input def s_map(): return input().split() s_map def s_list(): return list(s_map()) s_list s_input for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) s_input def s_row(N): return [s_input for _ in range(N)] s_row N N s_list() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) s_list() s_list def s_row_list(N): return [s_list() for _ in range(N)] s_row_list N N def Yes(): print('Yes') Yes def No(): print('No') No def YES(): print('YES') YES def NO(): print('NO') NO def lcm(a, b): return a * b // gcd(a, b) lcm a a b b sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 INF = float('inf') INF float('inf') float 'inf' MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 def main():
    n, a, b, c = i_map()
    num_list = i_row(n)

    min_mp = INF
    for bin in list(product([0, 1, 2, 3], repeat=n)):
        ac = bin.count(1)
        bc = bin.count(2)
        cc = bin.count(3)
        if ac < 1 or bc < 1 or cc < 1:
            continue
        mp = 0
        if ac >= 2:
            mp += 10 * (ac-1)
        if bc >= 2:
            mp += 10 * (bc-1)
        if cc >= 2:
            mp += 10 * (cc-1)
        sum_a, sum_b, sum_c = 0, 0, 0
        for i in range(n):
            if bin[i] == 1:
                sum_a += num_list[i]
            elif bin[i] == 2:
                sum_b += num_list[i]
            elif bin[i] == 3:
                sum_c += num_list[i]
        mp += abs(a-sum_a)
        mp += abs(b-sum_b)
        mp += abs(c-sum_c)
        min_mp = min(min_mp, mp)
            
    print(min_mp) main n, a, b, c = i_map() n i_map() i_map a b c num_list = i_row(n) num_list i_row(n) i_row n min_mp = INF min_mp INF for bin in list(product([0, 1, 2, 3], repeat=n)):
        ac = bin.count(1)
        bc = bin.count(2)
        cc = bin.count(3)
        if ac < 1 or bc < 1 or cc < 1:
            continue
        mp = 0
        if ac >= 2:
            mp += 10 * (ac-1)
        if bc >= 2:
            mp += 10 * (bc-1)
        if cc >= 2:
            mp += 10 * (cc-1)
        sum_a, sum_b, sum_c = 0, 0, 0
        for i in range(n):
            if bin[i] == 1:
                sum_a += num_list[i]
            elif bin[i] == 2:
                sum_b += num_list[i]
            elif bin[i] == 3:
                sum_c += num_list[i]
        mp += abs(a-sum_a)
        mp += abs(b-sum_b)
        mp += abs(c-sum_c)
        min_mp = min(min_mp, mp)
            
     bin list(product([0, 1, 2, 3], repeat=n)) list product([0, 1, 2, 3], repeat=n) product [0, 1, 2, 3] 0 1 2 3 repeat=n repeat n ac = bin.count(1) ac bin.count(1) bin.count bin count 1 bc = bin.count(2) bc bin.count(2) bin.count bin count 2 cc = bin.count(3) cc bin.count(3) bin.count bin count 3 if ac < 1 or bc < 1 or cc < 1:
            continue
         ac < 1 or bc < 1 or cc < 1 ac < 1 or bc < 1 ac < 1 ac 1 bc < 1 bc 1 cc < 1 cc 1 continue mp = 0 mp 0 if ac >= 2:
            mp += 10 * (ac-1)
         ac >= 2 ac 2 mp += 10 * (ac-1) mp 10 * (ac-1) 10 ac-1 ac 1 if bc >= 2:
            mp += 10 * (bc-1)
         bc >= 2 bc 2 mp += 10 * (bc-1) mp 10 * (bc-1) 10 bc-1 bc 1 if cc >= 2:
            mp += 10 * (cc-1)
         cc >= 2 cc 2 mp += 10 * (cc-1) mp 10 * (cc-1) 10 cc-1 cc 1 sum_a, sum_b, sum_c = 0, 0, 0 sum_a 0 sum_b 0 sum_c 0 for i in range(n):
            if bin[i] == 1:
                sum_a += num_list[i]
            elif bin[i] == 2:
                sum_b += num_list[i]
            elif bin[i] == 3:
                sum_c += num_list[i]
         i range(n) range n if bin[i] == 1:
                sum_a += num_list[i]
            elif bin[i] == 2:
                sum_b += num_list[i]
            elif bin[i] == 3:
                sum_c += num_list[i]
         bin[i] == 1 bin[i] bin i 1 sum_a += num_list[i] sum_a num_list[i] num_list i elif bin[i] == 2:
                sum_b += num_list[i]
             bin[i] == 2 bin[i] bin i 2 sum_b += num_list[i] sum_b num_list[i] num_list i elif bin[i] == 3:
                sum_c += num_list[i]
         bin[i] == 3 bin[i] bin i 3 sum_c += num_list[i] sum_c num_list[i] num_list i mp += abs(a-sum_a) mp abs(a-sum_a) abs a-sum_a a sum_a mp += abs(b-sum_b) mp abs(b-sum_b) abs b-sum_b b sum_b mp += abs(c-sum_c) mp abs(c-sum_c) abs c-sum_c c sum_c min_mp = min(min_mp, mp) min_mp min(min_mp, mp) min min_mp mp print(min_mp) print min_mp if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def s_input(): return input() def s_input(): return input() s_input def main():
    n, a, b, c = i_map()
    num_list = i_row(n)

    min_mp = INF
    for bin in list(product([0, 1, 2, 3], repeat=n)):
        ac = bin.count(1)
        bc = bin.count(2)
        cc = bin.count(3)
        if ac < 1 or bc < 1 or cc < 1:
            continue
        mp = 0
        if ac >= 2:
            mp += 10 * (ac-1)
        if bc >= 2:
            mp += 10 * (bc-1)
        if cc >= 2:
            mp += 10 * (cc-1)
        sum_a, sum_b, sum_c = 0, 0, 0
        for i in range(n):
            if bin[i] == 1:
                sum_a += num_list[i]
            elif bin[i] == 2:
                sum_b += num_list[i]
            elif bin[i] == 3:
                sum_c += num_list[i]
        mp += abs(a-sum_a)
        mp += abs(b-sum_b)
        mp += abs(c-sum_c)
        min_mp = min(min_mp, mp)
            
    print(min_mp) def main():
    n, a, b, c = i_map()
    num_list = i_row(n)

    min_mp = INF
    for bin in list(product([0, 1, 2, 3], repeat=n)):
        ac = bin.count(1)
        bc = bin.count(2)
        cc = bin.count(3)
        if ac < 1 or bc < 1 or cc < 1:
            continue
        mp = 0
        if ac >= 2:
            mp += 10 * (ac-1)
        if bc >= 2:
            mp += 10 * (bc-1)
        if cc >= 2:
            mp += 10 * (cc-1)
        sum_a, sum_b, sum_c = 0, 0, 0
        for i in range(n):
            if bin[i] == 1:
                sum_a += num_list[i]
            elif bin[i] == 2:
                sum_b += num_list[i]
            elif bin[i] == 3:
                sum_c += num_list[i]
        mp += abs(a-sum_a)
        mp += abs(b-sum_b)
        mp += abs(c-sum_c)
        min_mp = min(min_mp, mp)
            
    print(min_mp) main def s_list(): return list(s_map()) def s_list(): return list(s_map()) s_list def i_map(): return map(int, input().split()) def i_map(): return map(int, input().split()) i_map def i_list(): return list(i_map()) def i_list(): return list(i_map()) i_list def i_row(N): return [i_input() for _ in range(N)] def i_row(N): return [i_input() for _ in range(N)] i_row def No(): print('No') def No(): print('No') No def NO(): print('NO') def NO(): print('NO') NO def lcm(a, b): return a * b // gcd(a, b) def lcm(a, b): return a * b // gcd(a, b) lcm INF = float('inf') float('inf') INF def i_input(): return int(input()) def i_input(): return int(input()) i_input def s_map(): return input().split() def s_map(): return input().split() s_map MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD def s_row_list(N): return [s_list() for _ in range(N)] def s_row_list(N): return [s_list() for _ in range(N)] s_row_list def Yes(): print('Yes') def Yes(): print('Yes') Yes def YES(): print('YES') def YES(): print('YES') YES def s_row(N): return [s_input for _ in range(N)] def s_row(N): return [s_input for _ in range(N)] s_row def i_row_list(N): return [i_list() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] i_row_list
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n, a, b, c = i_map()
    num_list = i_row(n)

    min_mp = INF
    for bin in list(product([0, 1, 2, 3], repeat=n)):
        ac = bin.count(1)
        bc = bin.count(2)
        cc = bin.count(3)
        if ac < 1 or bc < 1 or cc < 1:
            continue
        mp = 0
        if ac >= 2:
            mp += 10 * (ac-1)
        if bc >= 2:
            mp += 10 * (bc-1)
        if cc >= 2:
            mp += 10 * (cc-1)
        sum_a, sum_b, sum_c = 0, 0, 0
        for i in range(n):
            if bin[i] == 1:
                sum_a += num_list[i]
            elif bin[i] == 2:
                sum_b += num_list[i]
            elif bin[i] == 3:
                sum_c += num_list[i]
        mp += abs(a-sum_a)
        mp += abs(b-sum_b)
        mp += abs(c-sum_c)
        min_mp = min(min_mp, mp)
            
    print(min_mp)

if __name__ == '__main__':
    main()
