#!/usr/bin/python3

N = 12

def root(x, par):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x], par)
        return par[x]

def getCnt(x):
    ret = 0
    while x > 0:
        ret += 1
        x //= 2
    return ret

def solve(edges, mask):
    global N
    par = [i for i in range(N)]
    size = len(edges)
    for i in range(size):
        if ((mask >> i) & 1) == 1:
            edges[i][2] -= 1
            edges[i][3] -= 1
    deg = [0] * N
    for (u, v, c, d) in edges:
        if d > 0:
            x, y = root(u, par), root(v, par)
            par[x] = y
            deg[u] += d
            deg[v] += d
    odds = [0] * N
    for i in range(N):
        if deg[i] % 2 == 1:
            odds[root(i, par)] += 1
    tot = [0] * N
    for (u, v, c, d) in edges:
        if d > 0:
            x = root(u, par)
            tot[x] += c
    ret = 0
    for i in range(N):
        if root(i, par) == i:
            if odds[i] <= 2 and ret < tot[i]:
                ret = tot[i]
    for i in range(size):
        if ((mask >> i) & 1) == 1:
            edges[i][2] += 1
            edges[i][3] += 1
    return ret

inf = open('coins.in', 'r')
edges = []
for i in range(5):
    data = [int(x) for x in inf.readline().strip().split()]
    ii = i // 2
    for j in range(len(data)):
        if i % 2 == 0:
            edges.append([4 * ii + j, 4 * ii + j + 1, data[j], getCnt(data[j])])
        else:
            edges.append([4 * ii + j, 4 * (ii + 1) + j, data[j], getCnt(data[j])])

CNT_MASKS = 2**len(edges)
answer = 0
for mask in range(CNT_MASKS):
    cur = solve(edges, mask)
    if cur > answer:
        answer = cur

ouf = open('coins.out', 'w')
ouf.write(str(answer) + '\n')
inf.close()
ouf.close()
