#55336: c++


yp11451267@yphs.tp.edu.tw (705-43鄭丞博)


#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void solve() {
    // 使用 long long 預防任何潛在的溢位問題(雖然此題測資 5000 以內 int 就夠)
    vector<long long> count(7);
    
    while (cin >> count[0] && count[0] != -1) {
        for (int i = 1; i < 7; ++i) {
            cin >> count[i];
        }
        
        // 從邊長 1 (index 0) 一路推導到邊長 32 (index 5)
        // 每 4 個小正方形就需要 1 個大一號的正方形空間
        for (int i = 0; i < 6; ++i) {
            long long up = (count[i] + 3) / 4; // 無條件進位到下一階
            count[i + 1] += up;
        }
        
        // 最終 count[6] 代表我們需要多少個「邊長為 64」的格子
        long long final_needed = count[6];
        
        if (final_needed == 0) {
            cout << 0 << "\n";
            continue;
        }
        
        // 尋找最小的 K,使得 K * K >= final_needed
        long long K = 1;
        while (K * K < final_needed) {
            K++;
        }
        
        // 最終大箱子的最小邊長即為 64 * K
        cout << 64 * K << "\n";
    }
}

int main() {
    // 最佳化輸入輸出
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    solve();
    
    return 0;
}