while True:
lst1=list(map(int,input().split()))
if sum(lst1)==0:break
box_num=0#;remains=0
count=0
while count<6:
remains=0
if lst1[5]!=0:
box_num+=lst1[5]
lst1[5]=0
elif lst1[4]!=0:
box_num+=lst1[4]
remains+=lst1[4]*11#;print(remains)
lst1[0]-=remains#;print(lst1[0])
lst1[4]=0
elif lst1[3]!=0: #箱子裝4*4
box_num+=lst1[3]
remains+=lst1[3]*5
lst1[1]-=remains
lst1[3]=0
elif lst1[2]!=0:#箱子裝3*3
tmp=lst1[2]//4
box_num+=tmp
tmp2=lst1[2]%4
if tmp2!=0:
box_num+=1
if tmp2==1:
lst1[1]-=5
lst1[0]-=7
elif tmp2==2:
lst1[1]-=3
lst1[0]-=6
elif tmp2==3:
lst1[1]-=5
lst1[0]-=7
lst1[2]=0
elif lst1[1]!=0:#箱子裝2*2大小
tmp=lst1[1]//9
box_num+=tmp
tmp2=lst1[1]%9
if tmp2!=0:
box_num+=1
for tmp2 in range(1,9):
lst1[0]-=4*(9-tmp2)
lst1[0]=0
else:#裝1*1
if lst1[0]!=0:
box_num+=(lst1[0]//36)+1
lst1[0]=0
#更新箱子的狀況
for a in range(6):
if lst1[a]<0:lst1[a]=0
lst1=[lst1[0],lst1[1],lst1[2],lst1[3],lst1[4],lst1[5]]
#print(lst1,box_num)
if lst1==[0,0,0,0,0,0]:break;count+=1
#if box_num>5000:break
print(box_num)