//#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 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;
  		}
  	ll add = 0;
	for (int j = 0; j < 17; j++) {
		if (vals[j] == 0) {
			par[j] = 0;
			continue;
		}
		add += vals[j];
		while (vals[j] >= 4) {
			vals[j] /= 4;
		}
		if (vals[j] == 1) par[j] = 1;
		else vals[j] /= 2, par[j] = 0;
	}	

	eprintf(LLD "\n", add);

  	int ans = 17;
	for (int mask = 0; mask < (1<<17); mask++) {
		int cnt = 0;
		for (int i = 0; i < 17; i++)
			if (vals[i] == 0 && (mask & (1<<i)))
				cnt += 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++;
					}
//				eprintf("%d%c", deg, " \n"[j==3]);
				cnt += deg % 2;
			}
//		eprintf("\n");
		if (cnt <= 2) {
			ans = min(ans, __builtin_popcount(mask));
		}
	}
	printf(LLD"\n", -ans + add);                                                                                
    return 0;
}