package work;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class A1017 {
static int sum;
static int[] box = new int[6];
public static void main(String[] args) throws FileNotFoundException {
/* Scanner sc=new Scanner(System.in); */
Scanner sc = new Scanner(new File("src/1017"));
while (true) {
for (int i = 0; i < 6; i++) {
box[i] = sc.nextInt();
}
if (box[0] == 0 && box[1] == 0 && box[2] == 0 && box[3] == 0
&& box[4] == 0 && box[5] == 0) {
break;
}
sum=0;
sum+=box[5]+box[4]+box[3]+(box[2]+3)/4;
int left22=box[3]*5;
if(box[2]%4==3){left22+=1;}
if(box[2]%4==2){left22+=3;}
if(box[2]%4==1){left22+=5;}
if(left22<box[1]){
sum+=(((box[1]-left22)+8)/9);
}
int left11=36*sum-36*box[5]-25*box[4]-16*box[3]-9*box[2]-4*box[1];
if(left11<box[0]){
sum+=(((box[0]-left11)+35)/36);
}
System.out.println(sum);
}
}
}