//
// main.cpp
// 1017
//
// Created by Jasmine wang on 05/11/2017.
// Copyright © 2017 Jasmine wang. All rights reserved.
//
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
int N, a, b, c, d, e, f, y, x;
int u[4] = {0, 5, 3, 1};//3*3的箱子分别多0,1,2,3个时2*2的空位个数
while(1){
cin >> a >> b >> c >> d >> e >> f;
if(a == 0 && b ==0 && c == 0 && d == 0 && e == 0 && f == 0) break;
N = f + d + e +(c + 3)/4;//先考虑6,5,4,3所用箱子个数,这些型号只能单独放置,不能互相合并
y = 5 * d + u[c % 4];//留给2*2的空位个数
if(b > y){
N += (b - y + 8)/9;
}
x = 36 * N - 36 * f - 25 * e - 16 * d - 9 * c - 4 * b;//留给1*1的空位个数
if(a > x){
N += (a - x + 35)/36;
}
printf("%d\n", N);
}
return 0;
}