program main
Implicit None
	integer(8)::n,a,b,c,i,k=4,u(3),e,f,j
	integer(8),allocatable::l(:),t(:)
	
	read*,n,a,b,c
	allocate(l(n),t(n))
	read*,l
	f = 1000000
	
	do i = 1,k**n-1
		u = 0
		call nb(i,k,t,n)
		e = 0
		do j = 1,n
			if(t(j) /= 0)then
				if(u(t(j))/=0) e=e+10
				u(t(j)) = u(t(j))+l(j)
			endif
		enddo
		if(product(u)==0) cycle
		e = e+abs(u(1)-a)+abs(u(2)-b)+abs(u(3)-c)
		if(e<f) f = e
	enddo
	
	print"(i0)",f
end program main

subroutine nb(a1,n,b,k)
Implicit None
	integer(8)::a1,n,k,i,a
	integer(8)::b(k)
	b = 0
	a = a1
	
	do i = 1,k
		b(i) = mod(a,n)
		a = (a-b(i))/n
	enddo
end subroutine nb