//#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#define mp make_pair
#define pb push_back

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

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

#define TASKNAME "coins"

#ifdef LOCAL
static struct __timestamper {
    string what;
    __timestamper(const char* what) : what(what){};
    __timestamper(const string& what) : what(what){};
	~__timestamper(){
        TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

int vals[20];
int par[20];
int id[3][4][4];
int deg[3][4];

const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int comp[3][4];

void dfs(int i, int j, int c) {
	if (i < 0 || i >= 3 || j < 0 || j >= 4 || comp[i][j] != -1) return;
	comp[i][j] = c;
	for (int k = 0; k < 4; k++)
		if (id[i][j][k] != -1 && vals[id[i][j][k]])
			dfs(i + dx[k], j + dy[k], c);
}


int main(){
    assert(freopen(TASKNAME".in","r",stdin));
    assert(freopen(TASKNAME".out","w",stdout));

  	for (int i = 0; i < 17; i++)
  		scanf("%d",&vals[i]);
  	memset(id, -1, sizeof(id));
  	for (int i = 0; i < 3; i++)
  		for (int j = 0; j < 4; j++) {
  			if (i != 0) id[i][j][0] = -4 + 7 * i + j;
  			if (j != 0) id[i][j][1] = -1 + 7 * i + j;
  			if (i != 2) id[i][j][2] = +3 + 7 * i + j;
  			if (j != 3) id[i][j][3] = +0 + 7 * i + j;
  		}
	for (int j = 0; j < 17; j++) {
		if (vals[j] == 0) {
			par[j] = 0;
			continue;
		}
		int tmp = vals[j];
		while (tmp >= 4) {
			tmp /= 4;
		}
		if (tmp == 1) par[j] = 1;
		else par[j] = 0;
	}	

	memset(comp, -1, sizeof(comp));
    int comps = 0;         
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 4; j++)
			if (comp[i][j] == -1)
				dfs(i, j, comps++);

  	ll ans = 0;
	for (int mask = 0; mask < (1<<17); mask++) {
		vector<int> cnt(comps);
		for (int i = 0; i < 17; i++)
			if (vals[i] == 0 && (mask & (1<<i)))
				cnt = vector<int>(comps, 3); 
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 4; j++) {
				int deg = 0;
				for (int dir = 0; dir < 4; dir++)
					if (id[i][j][dir] != -1 && (par[id[i][j][dir]] ^ !!(mask & (1<<id[i][j][dir])))) {
						deg++;
					}
				cnt[comp[i][j]] += deg % 2;
			}
		for (int i = 0; i < comps; i++)
			if (cnt[i] <= 2) {
				ll cur = 0;
				for (int x = 0; x < 3; x++)
					for (int y = 0; y < 4; y++)
					if (comp[x][y] == i)
						for (int j = 0; j < 4; j++)
						if (id[x][y][j] != -1)	
							cur += vals[id[x][y][j]] - !!(mask & (1<<id[x][y][j]));
				 assert(cur % 2 == 0);
				 ans = max(ans, cur / 2);
			}
	}
	printf(LLD"\n", ans);                                                                                
    return 0;
}