Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. 

There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.

Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2i - 1)-th man in the line (for the current moment) talks with the (2i)-th one. 

Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.

We know that if students i and j talk, then the i-th student's happiness increases by g_{ij} and the j-th student's happiness increases by g_{ji}. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.


-----Input-----

The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows g_{ij} (0 ≤ g_{ij} ≤ 10^5). It is guaranteed that g_{ii} = 0 for all i.

Assume that the students are numbered from 1 to 5.


-----Output-----

Print a single integer — the maximum possible total happiness of the students.


-----Examples-----
Input
0 0 0 0 9
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
7 0 0 0 0

Output
32

Input
0 43 21 18 2
3 0 21 11 65
5 2 0 1 4
54 62 12 0 99
87 64 81 33 0

Output
620



-----Note-----

In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:

(g_23 + g_32 + g_15 + g_51) + (g_13 + g_31 + g_54 + g_45) + (g_15 + g_51) + (g_54 + g_45) = 32.

Difficulty: interview

Starter code:

Solutions:
from itertools import permutations

tab = []

for i in range(5):
  buf = input().split(" ")
  X = []
  for j in range(5):
    X.append(int(buf[j]))
  tab.append(X)

res = 0

for perm in permutations([0,1,2,3,4], 5):
  wyn = 0
  wyn += tab[perm[0]][perm[1]]
  wyn += tab[perm[1]][perm[0]]
  wyn += tab[perm[2]][perm[3]]
  wyn += tab[perm[3]][perm[2]]
  
  wyn += tab[perm[1]][perm[2]]
  wyn += tab[perm[3]][perm[4]]
  wyn += tab[perm[2]][perm[1]]
  wyn += tab[perm[4]][perm[3]]
  
  wyn += tab[perm[2]][perm[3]]
  wyn += tab[perm[3]][perm[2]]
  
  wyn += tab[perm[3]][perm[4]]
  wyn += tab[perm[4]][perm[3]]
  
  res = max(wyn, res)
  
print(res)

import random
import sys
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
a = [[0] * 5 for i in range(5)]
a[0] = list(map(int, input().split()))
a[1] = list(map(int, input().split()))
a[2] = list(map(int, input().split()))
a[3] = list(map(int, input().split()))
a[4] = list(map(int, input().split()))
ans = 0
for i in range(5):
    for j in range(5):
        for k in range(5):
            for l in range(5):
                for s in range(5):
                    if i == j or i == k or i == l or i == s or j == k or j == l or j == s or k == l or k == s or l == s:
                        continue
                    ans = max(ans, a[i][j] + a[j][i] + a[k][l] + a[l][k] + a[j][k] + a[k][j] + a[l][s] + a[s][l] + a[k][l] + a[l][k] + a[l][s] + a[s][l])
print(ans)

from sys import stdin

def generator(k):
    nonlocal generation
    nonlocal resnum
    nonlocal a
    if(k == 5):
        sm = a[generation[0]][generation[1]] + a[generation[1]][generation[0]] + 2 * a[generation[2]][generation[3]] + 2 * a[generation[3]][generation[2]] + a[generation[1]][generation[2]] + a[generation[2]][generation[1]] + 2 * a[generation[3]][generation[4]] + 2 * a[generation[4]][generation[3]]
        if(sm > resnum):
            resnum = sm
    else:
        for i in range(5):
            if not(i in generation):
                generation[k] = i
                generator(k + 1)
                generation[k] = -1


a = []
for i in range(5):
    a.append(list(map(int, stdin.readline().split())))
print()
generation = [-1 for i in range(5)]
resnum = -1
generator(0)
print(resnum)

from itertools import *
a=[]
for i in range(5):
    a.append(list(map(int,input().split())))
ans=[]
m=0
for p in permutations(range(5)):
    t=0
    for i in range(4):
        for j in range(i,5,2):
            if j!=4:
                t+=a[p[j]][p[j+1]]+a[p[j+1]][p[j]]
    if t>=m:
        m=t
print(m)

import itertools


def calc(comb):

    if len(comb) < 2:

        return 0

    s = 0
    for i in range(0, len(comb) // 2 * 2, 2):

        a, b = comb[i:i + 2]
        s += m[a, b] + m[b, a]

    return s + calc(comb[1:])

m = {}
for y in range(5):

    for x, v in enumerate(str.split(input())):

        m[x, y] = int(v)

print(max(list(map(calc, itertools.permutations(list(range(5)))))))




# 5 chel och
# pervii so vtorim etc, esli nechet lst stoit

radost = []
for i in range(5):
    radost.append(list(map(int, input().split())))

mr = 0

def cr(m):
    nonlocal radost
    return  radost[m[0]][m[1]] + \
            radost[m[1]][m[0]] + \
            radost[m[1]][m[2]] + \
            radost[m[2]][m[1]] + \
           (radost[m[2]][m[3]] + \
            radost[m[3]][m[2]]) * 2 + \
           (radost[m[3]][m[4]] + \
            radost[m[4]][m[3]]) * 2

for a in range(5):
    for b in range(5):
        for c in range(5):
            for d in range(5):
                for e in range(5):
                    m = [a, b, c, d, e]
                    if len(set(m))==5:
                        mr = max(mr, cr(m))

print(mr)


import sys, itertools

f = sys.stdin
g = []
for i in range(5):
    g.append( [int(u) for u in f.readline().strip().split()] )


p_all = itertools.permutations(list(range(5)))
max_S = 0
for p in p_all:
    S = g[p[0]][p[1]] + g[p[1]][p[0]] + g[p[2]][p[3]] + g[p[3]][p[2]] 
    S += g[p[1]][p[2]] + g[p[2]][p[1]] + g[p[3]][p[4]] + g[p[4]][p[3]]
    S += g[p[2]][p[3]] + g[p[3]][p[2]] + g[p[3]][p[4]] + g[p[4]][p[3]]
    max_S = max(S, max_S)

print(max_S)


def str(l, l1, l2, l3, l4):
    s = [l, l1, l2, l3, l4]
    return s
def count(u):
    sum = 0
    lim = 0
    while lim != 5:
        for i in range(0, len(u) - 1, 2):
            sum += a[u[i]-1][u[i+1]-1]
            sum += a[u[i+1]-1][u[i]-1]
        u = u[1:]
        lim += 1
    return sum
a = []
u = [1, 2, 3, 4 ,5]
for i in range(5):
    a.append(list(map(int, input().split())))
b = []
c = []
o = set()
for i in range(1, 6):
    for j in range(1, 6):
        for k in range(1, 6):
            for l in range(1, 6):
                for p in range(1, 6):
                    o.add(i)
                    o.add(j)
                    o.add(k)
                    o.add(l)
                    o.add(p)
                    if len(o) == 5:
                        b.append(str(i, j, k, l, p))
                    o = set()
for i in range(len(b)):
    c.append(count(b[i]))
c = sorted(c)
print(c[-1])

a = []
for i in range(5):
    a.append(list(map(int, input().split())))
    
used = [False] * 5
ans = 0
for i1 in range(5):
    used[i1] = True
    for i2 in range(5):
        if not used[i2]:
            used[i2] = True
            
            for i3 in range(5):
                if not used[i3]:
                    used[i3] = True
                    for i4 in range(5):
                        if not used[i4]:
                            used[i4] = True
                            for i5 in range(5):
                                if not used[i5]:
                                    m = 0
                                    used[i5] = True
                                    o = [i1, i2, i3, i4, i5]
                                    for j in range(5):
                                        for i in range(0, len(o) - 1, 2):
                                            m += a[o[i]][o[i + 1]] + a[o[i + 1]][o[i]]
                                        o = o[1:]
                                    if m > ans:
                                        ans = m
                                    used[i5] = False
                            used[i4] = False
                    used[i3] = False
            used[i2] = False
    used[i1] = False
print(ans)

g = []
for i in range(5):
    g.append(list(map(int,input().split())))
max = 0
for i in range(5):
    for j in range(5):
        if i!=j:
            for k in range(5):
                if i!=k and j!=k:
                    for l in range(5):
                        if i!=l and j!=l and k!=l:
                            m = 10 - i - j - k - l
                            sum = g[i][j]+g[j][i]+g[j][k]+g[k][j]
                            sum += 2*(g[k][l]+g[l][k]+g[l][m]+g[m][l])                          
                            if sum > max:
                                max = sum                           
print(max)
                


import sys
#sys.stdin = open('input.txt', 'r')
g = []
for i in range(5):
	g.append([])
	g[i] = list(map(int, input().split()))
from itertools import permutations
M = -1
for p in permutations(list(range(1,6))):
	M = max(M, g[p[0]-1][p[1]-1] + g[p[1]-1][p[0]-1] + g[p[1]-1][p[2]-1] + g[p[2]-1][p[1]-1] + 2*(g[p[2]-1][p[3]-1] + g[p[3]-1][p[2]-1] + g[p[3]-1][p[4]-1] + g[p[4]-1][p[3]-1]))
print(M)




from itertools import permutations
matrix, ans = [list(map(int, input().split())) + [0] for x in range(5)] + [[0] * 6], 0
for perm in permutations(list(range(5))):
    x = list(perm) + [5]
    temp = 0
    for i in range(5):
        for j in range(i, 5, 2):
            temp += matrix[x[j]][x[j + 1]] + matrix[x[j + 1]][x[j]]
    ans = max(ans, temp)
print(ans)


import itertools


g = [list(map(int, input().split())) for _ in range(5)]
maximum = 0

for p in itertools.permutations(list(range(5))):
    p = list(p)
    maximum = max(maximum, g[p[0]][p[1]] + g[p[1]][p[0]] + g[p[2]][p[3]]
            + g[p[3]][p[2]] + g[p[1]][p[2]] + g[p[2]][p[1]] + g[p[3]][p[4]]
            + g[p[4]][p[3]] + g[p[2]][p[3]] + g[p[3]][p[2]] + g[p[3]][p[4]]
            + g[p[4]][p[3]])

print(maximum)


#!/usr/bin/env python

import itertools

def main( ):
    g = list( )
    for i in range( 5 ):
        g.append( list( map( int, input( ).split( ) ) ) )

    print(( max( [ 
        g[ l[0] ][ l[1] ] + g[ l[1] ][ l[0] ] + 2 * g[ l[2] ][ l[3] ] + 2 * g[ l[3] ][ l[2] ] +
        g[ l[1] ][ l[2] ] + g[ l[2] ][ l[1] ] + 2 * g[ l[3] ][ l[4] ] + 2 * g[ l[4] ][ l[3] ]
        for l in itertools.permutations( list( range( 5 ) ) ) ] ) ))

def __starting_point():
    main( )


__starting_point()

def fun(mas, h):
    nonlocal ans,a
    
    if (h < 5):
        for i in range(5):
            if not(i in mas):
                fun(mas + [i], h+1)
        return 0

    res = 0
    for i in range(5):
        if (len(mas) > 1):
            res += a[mas[0]][mas[1]] 
            res += a[mas[1]][mas[0]] 
        if (len(mas) > 3):
            res += a[mas[2]][mas[3]] 
            res += a[mas[3]][mas[2]] 
        mas.pop(0)      
    
    if (res > ans): ans = res


a = [[0]*5]*5

for i in range(5):
    a[i] = [int(j) for j in input().split()]

ans = 0
for i in range(5):
    mas = [i]
    fun(mas,1)

print(ans)

3

import sys
import itertools

#Approach: Since there are only 5 students, we can brute force through all 5! (=120) lineups. Don't know if that will be fast enough, though, but let's see. We'll go through each lineup, and measure the happiness.

h_1 = list(map(int, input().split())) #i's happiness
h_2 = list(map(int, input().split()))
h_3 = list(map(int, input().split()))
h_4 = list(map(int, input().split()))
h_5 = list(map(int, input().split()))

all_hap = []
all_hap.append(h_1)
all_hap.append(h_2)
all_hap.append(h_3)
all_hap.append(h_4)
all_hap.append(h_5)

all_permutations = list(itertools.permutations([0, 1, 2, 3, 4], 5))
max_hap = 0

for perm in all_permutations:
	hap = 0
	hap = hap + all_hap[perm[0]][perm[1]] + all_hap[perm[1]][perm[0]] + all_hap[perm[2]][perm[3]] + all_hap[perm[3]][perm[2]]#When no one is showering.
	hap = hap + all_hap[perm[1]][perm[2]] + all_hap[perm[2]][perm[1]] + all_hap[perm[3]][perm[4]] + all_hap[perm[4]][perm[3]]#When first guy is in the shower
	hap = hap + all_hap[perm[2]][perm[3]] + all_hap[perm[3]][perm[2]]#When second guy is in the shower
	hap = hap +all_hap[perm[3]][perm[4]] + all_hap[perm[4]][perm[3]]#When third guy is in the shower
	if (hap > max_hap):
		max_hap = hap

print(max_hap)


from sys import stdin as cin
from itertools import permutations as p
a=[]*5
for i in range(5):
    a.append(list(map(int,cin.readline().split())))
b = list(p([0,1,2,3,4]))
sum = 0
max = 0
for x in b:
    sum =(a[x[0]][x[1]]+a[x[2]][x[3]]+a[x[1]][x[2]]+a[x[3]][x[4]]+a[x[2]][x[3]]+a[x[3]][x[4]])+ a[x[1]][x[0]]+a[x[3]][x[2]]+a[x[2]][x[1]]+a[x[4]][x[3]]+a[x[3]][x[2]]+a[x[4]][x[3]]
    if sum> max:
        max = sum
print(max)






g=[0]*5
for i in range(5):
    g[i]=[0]*5
    g[i]=list(map(int, input().split()))
max=0
for i in range(5):
    for j in range(5):
        if j!=i:
            for m in range(5):
                if m!=j and m!=i:
                    for n in range(5):
                        if n!=m and n!=j and n!=i:
                            s=10-n-m-j-i
                            if g[i][j]+g[j][i]+g[j][m]+g[m][j]+2*(g[m][n]+g[n][m])+2*(g[n][s]+g[s][n])>max:
                                max=g[i][j]+g[j][i]+g[j][m]+g[m][j]+2*(g[m][n]+g[n][m])+2*(g[n][s]+g[s][n])
print(max)

    


F=[]

def gen(T,X):
    if(len(X)==5):
        F.append(list(X))
        return
    for item in T:
        H=list(T)
        H.remove(item)
        X.append(item)
        gen(H,X)
        X.remove(item)
    return
G=[]
for i in range(5):
    G.append(list(map(int,input().split())))
gen([0,1,2,3,4],[])
ans=0
for item in F:
    X=item
    t=0
    for i in range(5):
        for j in range(i,5,2):
            if(j==4):
                continue
            t+=G[X[j]][X[j+1]]
            t+=G[X[j+1]][X[j]]
    ans=max(ans,t)
print(ans)

g = [list(map(int, input().split())) for i in range(5)]
ans = 0
for i1 in range(5):
    for i2 in range(5):
        for i3 in range(5):
            for i4 in range(5):
                for i5 in range(5):
                    if i1 != i2 and i3 != i1 and i3 != i2 and i4 != i1 and i4 != i2 and i4 != i3 and i5 != i1 and i5 != i2 and i5 != i3 and i5 != i4:
                        ans = max(ans, g[i1][i2] + g[i2][i1] + g[i3][i4] + g[i4][i3] + g[i2][i3] + g[i3][i2] + g[i4][i5] + g[i5][i4] + g[i3][i4] + g[i4][i3] + g[i4][i5] + g[i5][i4])
print(ans)

__author__ = 'Lipen'

def main():
	g = []
	for i in range(5):
		g.append(list(map(int, input().split())))

	already = []
	smax = 0
	for q1 in range(5):
		for q2 in range(5):
			if q2 not in [q1]:
				for q3 in range(5):
					if q3 not in [q1, q2]:
						for q4 in range(5):
							if q4 not in [q1, q2, q3]:
								for q5 in range(5):
									if q5 not in [q1, q2, q3, q4]:
										s = g[q1][q2]+g[q2][q1]+2*g[q3][q4]+2*g[q4][q3]+g[q2][q3]+g[q3][q2]+2*g[q4][q5]+2*g[q5][q4]
										if s > smax:
											smax = s
	print(smax)

main()

from itertools import permutations
q, t = 0, [list(map(int, input().split())) for i in range(5)]
for a, b, c, d, e in permutations([0, 1, 2, 3, 4]):
    s = t[a][b] + t[b][a] + t[b][c] + t[c][b] + 2 * (t[c][d] + t[d][c] + t[d][e] + t[e][d])
    if s > q: q = s
print(q)

def next (a):
    k = len(a) - 2

    while a[k] > a[k+1]:
        k -= 1;

    t = k + 1

    while t < len(a) - 1 and a[t+1] > a[k]:
        t += 1

    a[t], a[k] = a[k], a[t]

    sub = a[k+1:]
    sub.reverse()

    res = a[:k+1]+sub

    return res

def countCurrent (a,happiness):
    res = 0

    for i in range(len(a) // 2):
        f = a[2*i]
        n = a[2*i + 1]
        res += happiness[f][n] + happiness[n][f]

    return res

def count (a,happiness):
    res = 0
    tmp = a

    while len(tmp) > 1:
        res += countCurrent(tmp,happiness)
        tmp = tmp[1:]

    return res


happiness = []

for x in range(5):
    happiness.append([int(c) for c in input().split()])

test = [0,1,2,3,4]
k = 0

while True:
    c = count(test,happiness)
    if c > k:
        k = c
    if test != [4,3,2,1,0]:
        test = next(test)
    else:
        break

print(k)





from itertools import permutations
g = [list(map(int, input().split())) for i in range(5)]
j = lambda p: g[p[0]][p[1]] + g[p[1]][p[0]] + 2 * (g[p[2]][p[3]] + g[p[3]][p[2]]) + g[p[1]][p[2]] + g[p[2]][p[1]] + 2 * (g[p[3]][p[4]] + g[p[4]][p[3]])
print(max(j(p) for p in permutations(range(5))))