import java.util.Scanner;
public class Main {
public static int u[]={0,5,3,1};
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n,a,b,c,d,e,f,x,y;
while(true){
String str=sc.nextLine();
String []split=str.split(" ");
a=Integer.parseInt(split[0]);
b=Integer.parseInt(split[1]);
c=Integer.parseInt(split[2]);
d=Integer.parseInt(split[3]);
e=Integer.parseInt(split[4]);
f=Integer.parseInt(split[5]);
if(a==0 && b==0 && c==0 && d==0 && e==0 && f==0){
break;
}
n=f+e+d+(c+3)/4;
y=5*d+u[c%4];
if(b>y){ n+=(b-y+8)/9; }
x=36*n-36*f-25*e-16*d-9*c-4*b;
if(a>x){ n+=(a-x+35)/36; }
System.out.println(n);
}
}
}