#include <cstdio>
#include <cstdlib>
#include <memory.h>
#include <vector>
#include <cassert>
using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__);
#else
    #define eprintf(...) 42;
#endif

const int N = 12;

inline int calc(int x) {
    int ret = 0;
    while (x > 0) {
        ret++;
        x >>= 1;
    }
    return ret;
}

inline long long recalc(int fromc, int toc, int &value) {
    assert(fromc >= toc);
    long long ret = 0;
    while (fromc > toc) {
        ret += (value + 1) / 2;
        value /= 2;
        fromc--;
    }
    return ret;
}

int a[N][N];
int aa[N][N];
int ac[N][N];
long long best;

void brute(int v, long long cur) {
    if (cur > best) {
        best = cur;
    }
    for (int i = 0; i < N; i++) {
        if (ac[v][i] > 2) {
            int oldc = ac[v][i];
            int olda = aa[v][i];
            for (int nc = 0; nc <= 2; nc++) {
                int na = olda;
                long long toAdd = recalc(oldc, nc, na);
                aa[v][i] = na;
                ac[v][i] = nc;
                brute(v, cur + toAdd);
                aa[v][i] = olda;
                ac[v][i] = oldc;
            }
        } else if (ac[v][i] > 0) {
            int olda = aa[v][i];
            int oldc = ac[v][i];
            aa[v][i] /= 2;
            ac[v][i]--;
            brute(i, cur + (olda + 1) / 2);
            aa[v][i] = olda;
            ac[v][i] = oldc;
        }
    }
}

int main() {
    freopen("coins.in", "r", stdin);
    freopen("coins.out", "w", stdout);
    for (int i = 0; i < 5; i++) {
        int ii = i / 2;
        if (i & 1) {
            for (int j = 0; j < 4; j++) {
                scanf("%d", &a[4 * ii + j][4 * (ii + 1) + j]);
                a[4 * (ii + 1) + j][4 * ii + j] = a[4 * ii + j][4 * (ii + 1) + j];
            }
        } else {
            for (int j = 0; j < 3; j++) {
                scanf("%d", &a[4 * ii + j][4 * ii + j + 1]);
                a[4 * ii + j + 1][4 * ii + j] = a[4 * ii + j][4 * ii + j + 1];
            }
        }
    }
    best = 0;
    for (int start = 0; start < N; start++) {
        eprintf("start = %d\n", start);
        memcpy(aa, a, sizeof(a));
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                ac[i][j] = calc(aa[i][j]);
            }
        }
        eprintf("starting brute\n");
        brute(start, 0);
        eprintf("end start = %d\n", start);
    }
    printf("%lld\n", best);
    return 0;
}
