#include<iostream>
using namespace std;
int main(){
int arr[4] = { 0, 5, 3, 1 };
int a[7];
int cut = 0,sum=0;
while (1){
for (int i = 1; i < 7; i++)
{
cin >> a[i];
cut += a[i];
}
if (cut == 0) break;
//不能塞的零件进行打包
sum = a[6] + a[5] + a[4] + (a[3] + 4 - 1) /4;
//塞2*2
int wen = 5 * a[4] + arr[a[3] % 4];
if (wen < a[2]){
sum=sum+(a[2] - wen + 9 - 1) / 9;
//1*1
int wen1 = sum - a[6] * 36 - a[5] * 25 - a[4] * 16 - a[3] * 9 - a[2] * 4;
if (wen1 < a[1]){
sum = sum + (a[1] - wen1 + 36 - 1) / 36;
}
}
cout << sum << endl;
}
system("pause");
return 0;
}