def dfs(ls1,le,su,p,s,oe):
if (oe and s>=su//2) or ((not oe) and s>su//2):
return s
elif p==le:
return su
else:
return min(list(map(dfs,[ls1]*(le-p),[le]*(le-p),[su]*(le-p),range(p+1,le+1),list(map(lambda x:s+ls1[x],range(p,le))),[oe]*(le-p))))
t=0
sl=list(map(int,input().split()))
for i1 in range(4):
ll=list(map(int,input().split()))
t+=dfs(ll,len(ll),sum(ll),0,0,sum(ll)%2==0)
print(t)