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: EASY

Solutions:
from itertools import permutations
f = lambda i, j: G[i][j] + G[j][i]
G = [[*map(int, input().split())] for _ in range(5)]
print(max((f(a, b) + f(b, c) + 2 * (f(c, d) + f(d, e)) for (a, b, c, d, e) in permutations(range(5)))))


import itertools

def queue_joy(g, p):
	return g[p[0]][p[1]] + g[p[1]][p[0]] + g[p[1]][p[2]] + g[p[2]][p[1]] + (g[p[2]][p[3]] + g[p[3]][p[2]]) * 2 + (g[p[3]][p[4]] + g[p[4]][p[3]]) * 2
g = list((list(map(int, input().split())) for _ in range(5)))
print(max([queue_joy(g, p) for p in list(itertools.permutations(range(5)))]))


import itertools
n = 5
g = []
for i in range(n):
	g.append(list(map(int, input().split())))
permutations = list(itertools.permutations(range(5)))
max_happiness = 0
for permutation in permutations:
	happiness = 0
	for t in range(n):
		for i in range(t, n - 1, 2):
			(a, b) = (permutation[i], permutation[i + 1])
			happiness += g[a][b] + g[b][a]
	if max_happiness < happiness:
		max_happiness = happiness
print(max_happiness)


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


def get_value(arr, permutation):
	val = 0
	adds = [(0, 1), (1, 0), (2, 3), (3, 2), (1, 2), (2, 1), (3, 4), (4, 3), (2, 3), (3, 2), (3, 4), (4, 3)]
	for a in adds:
		a0 = int(permutation[a[0]]) - 1
		a1 = int(permutation[a[1]]) - 1
		val += arr[a0][a1]
	return val

def get_input():
	lst = []
	for i in range(5):
		lst.append(list([int(x) for x in input().split(' ')]))
	return lst
g_ij = []
g_ij.append([0, 0, 0, 0, 9])
g_ij.append([0, 0, 0, 0, 0])
g_ij.append([0, 0, 0, 0, 0])
g_ij.append([0, 0, 0, 0, 0])
g_ij.append([7, 0, 0, 0, 0])
g_ij.clear()
g_ij.append([0, 43, 21, 18, 2])
g_ij.append([3, 0, 21, 11, 65])
g_ij.append([5, 2, 0, 1, 4])
g_ij.append([54, 62, 12, 0, 99])
g_ij.append([87, 64, 81, 33, 0])
g_ij = get_input()

def permute_string(str):
	if len(str) == 0:
		return ['']
	prev_list = permute_string(str[1:len(str)])
	next_list = []
	for i in range(0, len(prev_list)):
		for j in range(0, len(str)):
			new_str = prev_list[i][0:j] + str[0] + prev_list[i][j:len(str) - 1]
			if new_str not in next_list:
				next_list.append(new_str)
	return next_list
max_val = 0
d = dict()
for permutation in permute_string('12345'):
	val = get_value(g_ij, list(permutation))
	if val > max_val:
		max_val = val
print(max_val)


import itertools
g = [[int(i) for i in input().split()] for i in range(5)]
permutations = list(itertools.permutations([0, 1, 2, 3, 4], 5))
ans = -1
for per in permutations:
	tmp = (g[per[0]][per[1]] + g[per[1]][per[0]]) * 1 + (g[per[1]][per[2]] + g[per[2]][per[1]]) * 1 + (g[per[2]][per[3]] + g[per[3]][per[2]]) * 2 + (g[per[3]][per[4]] + g[per[4]][per[3]]) * 2
	if tmp > ans:
		ans = tmp
print(ans)


from itertools import permutations
(matrix, ans) = ([list(map(int, input().split())) + [0] for x in range(5)] + [[0] * 6], 0)
for perm in permutations(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)


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)


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 math
from itertools import permutations

def check(m, lst):
	t = 0
	for i in range(len(lst) - 1):
		j = i
		while j <= len(lst) - 2:
			t += m[lst[j] - 1][lst[j + 1] - 1]
			t += m[lst[j + 1] - 1][lst[j] - 1]
			j += 2
	return t

def main():
	m = []
	for _ in range(5):
		x = list(map(int, input().split()))
		m.append(x)
	p = list(permutations([1, 2, 3, 4, 5], 5))
	ans = 0
	for n in p:
		ans = max(check(m, n), ans)
	print(ans)
main()


from itertools import permutations
l = list(permutations(range(0, 5)))
p = []
m = []
for _ in range(5):
	m = list(map(int, input().split()))
	p.append(m)
res = 0
for i in range(len(l)):
	a = l[i][0]
	b = l[i][1]
	c = l[i][2]
	d = l[i][3]
	e = l[i][4]
	r = p[a][b] + p[b][a] + 2 * (p[c][d] + p[d][c]) + p[b][c] + p[c][b] + 2 * (p[d][e] + p[e][d])
	res = max(r, res)
print(res)


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

def permuB(A, l):
	if l == len(A) - 1:
		return B[A[1]][A[2]] + B[A[2]][A[1]] + B[A[0]][A[2]] + B[A[2]][A[0]] + 2 * (B[A[0]][A[4]] + B[A[4]][A[0]] + B[A[3]][A[4]] + B[A[4]][A[3]])
	ans = 0
	for i in range(l, len(A)):
		C = A[:]
		(C[l], C[i]) = (C[i], C[l])
		ans = max(ans, permuB(C, l + 1))
	return ans
print(permuB([0, 1, 2, 3, 4], 0))


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)))))))


from itertools import permutations
a = permutations('12345')
b = []
c = []
for i in range(5):
	b.append(list(map(int, input().split())))
for i in a:
	c.append(b[int(i[0]) - 1][int(i[1]) - 1] + b[int(i[1]) - 1][int(i[0]) - 1] + b[int(i[2]) - 1][int(i[3]) - 1] + b[int(i[3]) - 1][int(i[2]) - 1] + (b[int(i[1]) - 1][int(i[2]) - 1] + b[int(i[2]) - 1][int(i[1]) - 1] + b[int(i[3]) - 1][int(i[4]) - 1] + b[int(i[4]) - 1][int(i[3]) - 1]) + (b[int(i[2]) - 1][int(i[3]) - 1] + b[int(i[3]) - 1][int(i[2]) - 1]) + (b[int(i[3]) - 1][int(i[4]) - 1] + b[int(i[4]) - 1][int(i[3]) - 1]))
print(max(c))


from itertools import permutations
g = []
for _ in range(5):
	line = list(map(int, input().split()))
	g.append(line)

def calc_h(order):
	return g[order[0]][order[1]] + g[order[1]][order[0]] + g[order[2]][order[3]] + g[order[3]][order[2]] + +g[order[1]][order[2]] + g[order[2]][order[1]] + +g[order[3]][order[4]] + g[order[4]][order[3]] + g[order[2]][order[3]] + g[order[3]][order[2]] + g[order[3]][order[4]] + g[order[4]][order[3]]
mx = -999999999
com = permutations([0, 1, 2, 3, 4])
for i in com:
	v = calc_h(i)
	if v > mx:
		mx = v
print(mx)


import itertools

def main():
	lst = [list(map(int, input().split())) for _ in range(5)]
	lst = tuple((lst[i][j] + lst[j][i] for i in range(5) for j in range(5)))
	print(max((sum((lst[i * 5 + j] for s in range(4) for (i, j) in zip(p[s::2], p[s + 1::2]))) for p in itertools.permutations(range(5)))))
main()


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def def_value():
	return 0
a = []
for i in range(5):
	a.append(inlist())
P = permutations([0, 1, 2, 3, 4])
finalRes = 0
for b in P:
	res = 0
	for i in range(5):
		for j in range(i, 5 - 1, 2):
			res += a[b[i]][b[i + 1]] + a[b[i + 1]][b[i]]
	finalRes = max(res, finalRes)
print(finalRes)


from itertools import permutations
array = {}
for i in range(5):
	s = input().split()
	for j in range(5):
		if i is not j:
			array[i + 1, j + 1] = int(s[j])
pairs = {}
for i in range(5):
	for j in range(5):
		if i is not j:
			pairs[i + 1, j + 1] = array[i + 1, j + 1] + array[j + 1, i + 1]
l = list(permutations(range(1, 6)))
m = 0
for p in l:
	val = pairs[p[0], p[1]] + pairs[p[2], p[3]] + pairs[p[1], p[2]] + pairs[p[3], p[4]] + pairs[p[2], p[3]] + pairs[p[3], p[4]]
	if val > m:
		m = val
print(m)


import itertools

def main(arr):
	perms = itertools.permutations([0, 1, 2, 3, 4])
	add = -1
	for g in perms:
		a = 0
		for k in range(5):
			for i in range(k, 4, 2):
				a += arr[g[i]][g[i + 1]] + arr[g[i + 1]][g[i]]
		if a > add:
			add = a
	print(add)

def text():
	with open('input.txt', 'r') as f:
		t = int(f.readline().rstrip())
		while t:
			arr = []
			for _ in range(5):
				arr.append(list(map(int, f.readline().rstrip().split())))
			main(arr)
			t -= 1

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


N = 5
g = []
maxh = 0

def h(l):
	val = 0
	for i in range(N - 1):
		for j in range(i, N - 1, 2):
			(a, b) = (l[j], l[j + 1])
			val += g[a][b] + g[b][a]
	global maxh
	maxh = max(maxh, val)

def search(s, l):
	s2 = set(s)
	if not s:
		h(l)
	else:
		for e in s:
			s2.remove(e)
			l.append(e)
			search(s2, l)
			l.pop()
			s2.add(e)
for i in range(N):
	g.append([int(x) for x in input().split()])
search(set(range(N)), [])
print(maxh)


import os
import sys
from io import BytesIO, IOBase
from itertools import permutations

def happiness(arr, l):
	ans = 0
	while len(l) != 1:
		for i in range(0, len(l) - 1, 2):
			(x, y) = (l[i], l[i + 1])
			ans += arr[x - 1][y - 1] + arr[y - 1][x - 1]
		l.pop(0)
	return ans

def main():
	arr = []
	for _ in range(5):
		arr.append(list(map(int, input().split())))
	lst = list(permutations([1, 2, 3, 4, 5]))
	ans = 0
	for item in lst:
		ans = max(ans, happiness(arr, list(item)))
	print(ans)

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


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)))]))
main()


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List, Mapping
sys.setrecursionlimit(999999)
arr = []
for _ in range(5):
	arr.append(list(map(int, input().split())))
ans = 0
for ks in itertools.permutations(list(range(5)), 5):
	(a, b, c, d, e) = ks
	s = arr[a][b] + arr[b][a] + arr[b][c] + arr[c][b] + 2 * (arr[c][d] + arr[d][c] + arr[d][e] + arr[e][d])
	ans = max(ans, s)
print(ans)


a = []
for i in range(5):
	b = [int(i) for i in input().split()]
	a.append(b)
from itertools import permutations
b = permutations('12345')
b = list(b)
m = 0
for i in b:
	i = [int(j) - 1 for j in i]
	tot = 0
	(a1, a2, a3, a4, a5) = i
	tot = a[a1][a2] + a[a3][a4] + a[a2][a1] + a[a4][a3]
	tot += a[a2][a3] + a[a4][a5] + a[a3][a2] + a[a5][a4]
	tot += a[a3][a4] + a[a4][a3]
	tot += a[a4][a5] + a[a5][a4]
	if tot > m:
		m = tot
print(m)


from itertools import permutations
x = [1, 2, 3, 4, 5]
y = list(permutations(x, 5))
x = []
for i in range(5):
	a = list(map(int, input().split()))
	x.append(a)
m = 0
for i in y:
	(a, b) = (i[0] - 1, i[1] - 1)
	(c, d) = (i[2] - 1, i[3] - 1)
	e = i[4] - 1
	v = x[a][b] + x[b][a] + x[c][b] + x[b][c] + 2 * (x[d][e] + x[e][d] + x[c][d] + x[d][c])
	m = max(m, v)
print(m)


arr = []
for i in range(5):
	arr.append(list(map(int, input().split(' '))))
max_val = 0
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):
					if a != b and a != c and (a != d) and (a != e) and (b != c) and (b != d) and (b != e) and (c != d) and (c != e) and (d != e):
						temp_val = arr[a][b] + arr[b][a] + arr[b][c] + arr[c][b] + 2 * (arr[c][d] + arr[d][c]) + 2 * (arr[d][e] + arr[e][d])
						if temp_val > max_val:
							max_val = temp_val
print(max_val)


from itertools import permutations
li = []
for _ in range(5):
	li.append(list(map(int, input().split())))
t = list(permutations([1, 2, 3, 4, 5]))
res = 0
for permutation in t:
	(t, i) = (0, 0)
	while i < 5:
		j = i
		while j < 5:
			try:
				t += li[permutation[j] - 1][permutation[j + 1] - 1] + li[permutation[j + 1] - 1][permutation[j] - 1]
				j += 2
			except:
				j += 2
		i += 1
	res = max(res, t)
print(res)


def next_permutation(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()
	return a[:k + 1] + sub

def count_current(a, x):
	r = 0
	for i in range(len(a) // 2):
		f = a[2 * i]
		n = a[2 * i + 1]
		r += x[f][n] + x[n][f]
	return r

def count(a, x):
	(r, t) = (0, a)
	while len(t) > 1:
		r += count_current(t, x)
		t = t[1:]
	return r
arr = []
for i in range(5):
	arr.append([int(c) for c in input().split()])
p = [0, 1, 2, 3, 4]
k = 0
while p != [4, 3, 2, 1, 0]:
	k = max(k, count(p, arr))
	p = next_permutation(p)
print(max(k, count(p, arr)))


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)))))


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, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	tmp = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			cnt = 0
			while n % i == 0:
				n = n // i
				cnt += 1
			tmp.append((i, cnt))
	if n > 1:
		tmp.append((n, 1))
	return tmp

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def s(b):
	ans = []
	while b > 0:
		tmp = b % 10
		ans.append(tmp)
		b = b // 10
	return ans
my_list = ['12345', '12354', '12435', '12453', '12534', '12543', '13245', '13254', '13425', '13452', '13524', '13542', '14235', '14253', '14325', '14352', '14523', '14532', '15234', '15243', '15324', '15342', '15423', '15432', '21345', '21354', '21435', '21453', '21534', '21543', '23145', '23154', '23415', '23451', '23514', '23541', '24135', '24153', '24315', '24351', '24513', '24531', '25134', '25143', '25314', '25341', '25413', '25431', '31245', '31254', '31425', '31452', '31524', '31542', '32145', '32154', '32415', '32451', '32514', '32541', '34125', '34152', '34215', '34251', '34512', '34521', '35124', '35142', '35214', '35241', '35412', '35421', '41235', '41253', '41325', '41352', '41523', '41532', '42135', '42153', '42315', '42351', '42513', '42531', '43125', '43152', '43215', '43251', '43512', '43521', '45123', '45132', '45213', '45231', '45312', '45321', '51234', '51243', '51324', '51342', '51423', '51432', '52134', '52143', '52314', '52341', '52413', '52431', '53124', '53142', '53214', '53241', '53412', '53421', '54123', '54132', '54213', '54231', '54312', '54321']

def main():
	mat = []
	for i in range(5):
		mat.append(li())
	ans = 0
	for i in my_list:
		a = int(i[0]) - 1
		b = int(i[1]) - 1
		c = int(i[2]) - 1
		d = int(i[3]) - 1
		e = int(i[4]) - 1
		ans = max(ans, mat[a][b] + mat[b][a] + mat[c][d] + mat[d][c] + mat[b][c] + mat[c][b] + mat[d][e] + mat[e][d] + mat[c][d] + mat[d][c] + mat[d][e] + mat[e][d])
	print(ans)
main()


from itertools import permutations

def sumup(arr):
	su = 0
	for i in range(len(arr) - 1):
		for j in range(i, len(arr) - 1, 2):
			su += matrix[arr[j] - 1][arr[j + 1] - 1] + matrix[arr[j + 1] - 1][arr[j] - 1]
	return su
matrix = []
for i in range(5):
	row = list(map(int, input().split()))
	matrix.append(row)
mx = 0
perms = permutations([1, 2, 3, 4, 5])
for perm in list(perms):
	curr = sumup(perm)
	mx = max(curr, mx)
print(mx)


g = [[int(i) for i in input().split()] for i in range(5)]
s = 0
for i in range(5):
	for j in set(list(range(5))) - set([i]):
		for k in set(list(range(5))) - set([i, j]):
			for l in set(list(range(5))) - set([i, j, k]):
				for m in set(list(range(5))) - set([i, j, k, l]):
					s = max(s, g[i][j] + g[j][i] + g[k][l] + g[l][k] + g[j][k] + g[k][j] + g[l][m] + g[m][l] + g[k][l] + g[l][k] + g[l][m] + g[m][l])
print(s)


import itertools as it
arr = []
for i in range(5):
	arr.append([int(x) for x in input().split()])
ans = 0
for l in it.permutations(range(5)):
	cur = arr[l[0]][l[1]] + arr[l[1]][l[0]] + arr[l[2]][l[3]] + arr[l[3]][l[2]]
	cur += arr[l[1]][l[2]] + arr[l[2]][l[1]] + arr[l[3]][l[4]] + arr[l[4]][l[3]]
	cur += arr[l[2]][l[3]] + arr[l[3]][l[2]]
	cur += arr[l[3]][l[4]] + arr[l[4]][l[3]]
	ans = max(ans, cur)
print(ans)


from math import *
import itertools

def permutations(string):
	return list(set(list(map(lambda x: ''.join(x), list(itertools.permutations(string, len(string)))))))

def get(s, dp):
	s = list(s)
	z = 0
	while len(s) != 1:
		k = 0
		for i in range(len(s)):
			i += k
			if i < len(s) - 1:
				z += dp[int(s[i]) - 1][int(s[i + 1]) - 1] + dp[int(s[i + 1]) - 1][int(s[i]) - 1]
				k += 1
		s.pop(0)
	return z

def main():
	dp = []
	for i in range(5):
		dp.append(list(map(int, input().split())))
	res = map(lambda x: get(x, dp), permutations('12345'))
	print(max(res))
main()


x = 0
from itertools import permutations
z = [[int(j) for j in input().split()] for i in range(5)]
m = 0
for k in permutations([0, 1, 2, 3, 4]):
	s = 0
	for i in range(4):
		for j in range(i, 4, 2):
			s += z[k[j]][k[j + 1]] + z[k[j + 1]][k[j]]
	if s > m:
		m = s
print(m)


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)


from itertools import permutations
import math
a = []
for _ in range(5):
	a.append(list(map(int, input().split())))
perm = list(permutations([0, 1, 2, 3, 4], 5))
max = -math.inf
for p in perm:
	su = a[p[0]][p[1]]
	su += a[p[1]][p[0]]
	su += a[p[2]][p[3]]
	su += a[p[3]][p[2]]
	su += a[p[1]][p[2]]
	su += a[p[2]][p[1]]
	su += a[p[3]][p[4]]
	su += a[p[4]][p[3]]
	su += a[p[2]][p[3]]
	su += a[p[3]][p[2]]
	su += a[p[3]][p[4]]
	su += a[p[4]][p[3]]
	if su > max:
		max = su
print(max)


from itertools import permutations
g = [[int(i) for i in input().split()] for j in range(5)]
max_joy = -1
for p in permutations([0, 1, 2, 3, 4]):
	joy = g[p[0]][p[1]] + g[p[2]][p[3]] + g[p[1]][p[0]] + g[p[3]][p[2]] + (g[p[1]][p[2]] + g[p[3]][p[4]] + g[p[2]][p[1]] + 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]])
	if joy > max_joy:
		max_joy = joy
print(max_joy)


from itertools import permutations

class CodeforcesTask431BSolution:

	def __init__(self):
		self.result = ''
		self.incr = []

	def read_input(self):
		for x in range(5):
			self.incr.append([int(y) for y in input().split(' ')])

	def process_task(self):
		mx = 0
		for st in permutations([x for x in range(5)]):
			cr = 0
			cr += self.incr[st[0]][st[1]]
			cr += self.incr[st[1]][st[0]]
			cr += self.incr[st[2]][st[3]]
			cr += self.incr[st[3]][st[2]]
			cr += self.incr[st[1]][st[2]]
			cr += self.incr[st[2]][st[1]]
			cr += self.incr[st[3]][st[4]]
			cr += self.incr[st[4]][st[3]]
			cr += self.incr[st[2]][st[3]]
			cr += self.incr[st[3]][st[2]]
			cr += self.incr[st[3]][st[4]]
			cr += self.incr[st[4]][st[3]]
			mx = max(mx, cr)
		self.result = str(mx)

	def get_result(self):
		return self.result
Solution = CodeforcesTask431BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import itertools
g = [list(map(int, input().split())) for _ in range(5)]
maximum = 0
for p in itertools.permutations(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)


import math
import re
import sys
from itertools import permutations
from collections import Counter
MOD = 1000000007
inp = lambda : map(int, input().split(' '))
ninp = lambda : int(input())
g = []
for i in range(5):
	g.append(list(inp()))
a = [0, 1, 2, 3, 4]
perms = list(permutations(a))
ans = 0
for p in perms:
	temp = 0
	temp += g[p[0]][p[1]] + g[p[1]][p[0]]
	temp += g[p[2]][p[3]] + g[p[3]][p[2]]
	temp += g[p[1]][p[2]] + g[p[2]][p[1]]
	temp += g[p[3]][p[4]] + g[p[4]][p[3]]
	temp += g[p[2]][p[3]] + g[p[3]][p[2]]
	temp += g[p[3]][p[4]] + g[p[4]][p[3]]
	if temp >= ans:
		ans = temp
print(ans)


from itertools import permutations
g = []
for i in range(5):
	g.append(list(map(int, input().split())))
p = list(permutations('12345'))
highscore = 0
for perm in p:
	score = g[int(perm[0]) - 1][int(perm[1]) - 1] + g[int(perm[1]) - 1][int(perm[0]) - 1] + g[int(perm[2]) - 1][int(perm[3]) - 1] + g[int(perm[3]) - 1][int(perm[2]) - 1] + g[int(perm[1]) - 1][int(perm[2]) - 1] + g[int(perm[2]) - 1][int(perm[1]) - 1] + g[int(perm[3]) - 1][int(perm[4]) - 1] + g[int(perm[4]) - 1][int(perm[3]) - 1] + g[int(perm[2]) - 1][int(perm[3]) - 1] + g[int(perm[3]) - 1][int(perm[2]) - 1] + g[int(perm[3]) - 1][int(perm[4]) - 1] + g[int(perm[4]) - 1][int(perm[3]) - 1]
	if score > highscore:
		highscore = score
print(highscore)


from sys import stdin
from itertools import permutations
arr = []
for i in range(5):
	row = [int(i) for i in stdin.readline().split(' ')]
	arr.append(row)
val = {}
for i in range(5):
	for j in range(i + 1, 5):
		temp = arr[i][j] + arr[j][i]
		val[i + 1, j + 1] = temp
		val[j + 1, i + 1] = temp
permutation = permutations('12345')
m = 0
for i in permutation:
	temp = list(map(int, i))
	tempMax = val[temp[0], temp[1]] + val[temp[1], temp[2]] + 2 * (val[temp[2], temp[3]] + val[temp[3], temp[4]])
	if tempMax > m:
		m = tempMax
print(m)


import sys

def calculate(a, b, c, d, e):
	summ = g[a][b] + g[b][a] + g[b][c] + g[c][b] + 2 * (g[c][d] + g[d][c]) + 2 * (g[d][e] + g[e][d])
	return summ
g = []
maxx = 0
for _ in range(5):
	g.append(list(map(int, sys.stdin.readline().split())))
for i in range(5):
	for j in range(5):
		for k in range(5):
			for l in range(5):
				for m in range(5):
					if [i, j, k, l, m] == list(dict.fromkeys([i, j, k, l, m])):
						summ = calculate(i, j, k, l, m)
						if summ > maxx:
							maxx = summ
print(maxx)


import itertools
g = []
for i in range(5):
	g.append([int(i) for i in input().split()])
perm = [1, 2, 3, 4, 5]
m = 0
for i in list(itertools.permutations(perm)):
	(a, b, c, d, e) = i
	current = g[a - 1][b - 1] + g[b - 1][a - 1] + 2 * (g[c - 1][d - 1] + g[d - 1][c - 1]) + g[b - 1][c - 1] + g[c - 1][b - 1] + 2 * (g[d - 1][e - 1] + g[e - 1][d - 1])
	if current > m:
		m = current
print(m)


ans = 0

def rec(ind, l):
	global ans
	if ind == 5:
		res = 0
		for i in range(4):
			s = a[l[i]][l[i + 1]] + a[l[i + 1]][l[i]]
			res += s * (1 + i // 2)
		ans = max(ans, res)
		return
	else:
		for i in range(5):
			if i not in l:
				l.append(i)
				rec(ind + 1, l)
				l.pop()
a = []
for i in range(5):
	a.append(list(map(int, input().split())))
rec(0, [])
print(ans)


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

def utility_function(states, seq):
	score = states[seq[0]][seq[1]] + states[seq[1]][seq[0]] + states[seq[2]][seq[3]] + states[seq[3]][seq[2]] + (states[seq[1]][seq[2]] + states[seq[2]][seq[1]] + states[seq[3]][seq[4]] + states[seq[4]][seq[3]]) + (states[seq[2]][seq[3]] + states[seq[3]][seq[2]]) + (states[seq[3]][seq[4]] + states[seq[4]][seq[3]])
	return score

def permutation(seq):

	def backtrack(first=0):
		if first == n:
			if seq[:] not in combs:
				combs.append(seq[:])
		else:
			for i in range(first, n):
				(seq[first], seq[i]) = (seq[i], seq[first])
				backtrack(first + 1)
				(seq[first], seq[i]) = (seq[i], seq[first])
	n = len(seq)
	combs = []
	backtrack()
	return combs
seq = [0, 1, 2, 3, 4]
combs = permutation(seq)
max_score = 0
for seq in combs:
	max_score = max(max_score, utility_function(g_mat, seq))
print(max_score)


from itertools import permutations
matrix = []
for i in range(5):
	temp = [int(x) for x in input().split()]
	matrix.append(temp)
max_happiness = 0

def helper(arr):
	happiness = 0
	i = 0
	j = 1
	while i < len(arr) - 1:
		k = i
		l = i + 1
		while l < len(arr):
			happiness += matrix[arr[k] - 1][arr[l] - 1] + matrix[arr[l] - 1][arr[k] - 1]
			k += 2
			l += 2
		i += 1
	return happiness
permuList = permutations([1, 2, 3, 4, 5])
for per in permuList:
	current_happiness = helper(per)
	max_happiness = max(max_happiness, current_happiness)
print(max_happiness)


from itertools import permutations
a = []
for i in range(5):
	a.append(list(map(int, input().split())))
b = [j for j in permutations('12345')]
d = 0
for i in b:
	c = 0
	for j in range(1, 5):
		if j == 3 or j == 4:
			c += 2 * (a[int(i[j]) - 1][int(i[j - 1]) - 1] + a[int(i[j - 1]) - 1][int(i[j]) - 1])
		else:
			c += a[int(i[j]) - 1][int(i[j - 1]) - 1] + a[int(i[j - 1]) - 1][int(i[j]) - 1]
	if c > d:
		d = c
print(d)


arr = []
for i in range(5):
	arri = list(map(int, input().split()))
	arr.append(arri)
s = [0, 1, 2, 3, 4]
from itertools import permutations
perm = list(permutations(s))
mx = 0
sm = 0
for i in perm:
	s = list(i)
	sm = arr[s[0]][s[1]] + arr[s[1]][s[0]] + arr[s[2]][s[3]] + arr[s[3]][s[2]] + (arr[s[1]][s[2]] + arr[s[2]][s[1]] + arr[s[3]][s[4]] + arr[s[4]][s[3]]) + (arr[s[2]][s[3]] + arr[s[3]][s[2]]) + (arr[s[3]][s[4]] + arr[s[4]][s[3]])
	if mx < sm:
		mx = sm
print(mx)


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


from itertools import permutations
val2 = [(1, 2, 3, 4, 5), (1, 2, 3, 5, 4), (1, 2, 4, 3, 5), (1, 2, 4, 5, 3), (1, 2, 5, 3, 4), (1, 2, 5, 4, 3), (1, 3, 2, 4, 5), (1, 3, 2, 5, 4), (1, 3, 4, 2, 5), (1, 3, 4, 5, 2), (1, 3, 5, 2, 4), (1, 3, 5, 4, 2), (1, 4, 2, 3, 5), (1, 4, 2, 5, 3), (1, 4, 3, 2, 5), (1, 4, 3, 5, 2), (1, 4, 5, 2, 3), (1, 4, 5, 3, 2), (1, 5, 2, 3, 4), (1, 5, 2, 4, 3), (1, 5, 3, 2, 4), (1, 5, 3, 4, 2), (1, 5, 4, 2, 3), (1, 5, 4, 3, 2), (2, 1, 3, 4, 5), (2, 1, 3, 5, 4), (2, 1, 4, 3, 5), (2, 1, 4, 5, 3), (2, 1, 5, 3, 4), (2, 1, 5, 4, 3), (2, 3, 1, 4, 5), (2, 3, 1, 5, 4), (2, 3, 4, 1, 5), (2, 3, 4, 5, 1), (2, 3, 5, 1, 4), (2, 3, 5, 4, 1), (2, 4, 1, 3, 5), (2, 4, 1, 5, 3), (2, 4, 3, 1, 5), (2, 4, 3, 5, 1), (2, 4, 5, 1, 3), (2, 4, 5, 3, 1), (2, 5, 1, 3, 4), (2, 5, 1, 4, 3), (2, 5, 3, 1, 4), (2, 5, 3, 4, 1), (2, 5, 4, 1, 3), (2, 5, 4, 3, 1), (3, 1, 2, 4, 5), (3, 1, 2, 5, 4), (3, 1, 4, 2, 5), (3, 1, 4, 5, 2), (3, 1, 5, 2, 4), (3, 1, 5, 4, 2), (3, 2, 1, 4, 5), (3, 2, 1, 5, 4), (3, 2, 4, 1, 5), (3, 2, 4, 5, 1), (3, 2, 5, 1, 4), (3, 2, 5, 4, 1), (3, 4, 1, 2, 5), (3, 4, 1, 5, 2), (3, 4, 2, 1, 5), (3, 4, 2, 5, 1), (3, 4, 5, 1, 2), (3, 4, 5, 2, 1), (3, 5, 1, 2, 4), (3, 5, 1, 4, 2), (3, 5, 2, 1, 4), (3, 5, 2, 4, 1), (3, 5, 4, 1, 2), (3, 5, 4, 2, 1), (4, 1, 2, 3, 5), (4, 1, 2, 5, 3), (4, 1, 3, 2, 5), (4, 1, 3, 5, 2), (4, 1, 5, 2, 3), (4, 1, 5, 3, 2), (4, 2, 1, 3, 5), (4, 2, 1, 5, 3), (4, 2, 3, 1, 5), (4, 2, 3, 5, 1), (4, 2, 5, 1, 3), (4, 2, 5, 3, 1), (4, 3, 1, 2, 5), (4, 3, 1, 5, 2), (4, 3, 2, 1, 5), (4, 3, 2, 5, 1), (4, 3, 5, 1, 2), (4, 3, 5, 2, 1), (4, 5, 1, 2, 3), (4, 5, 1, 3, 2), (4, 5, 2, 1, 3), (4, 5, 2, 3, 1), (4, 5, 3, 1, 2), (4, 5, 3, 2, 1), (5, 1, 2, 3, 4), (5, 1, 2, 4, 3), (5, 1, 3, 2, 4), (5, 1, 3, 4, 2), (5, 1, 4, 2, 3), (5, 1, 4, 3, 2), (5, 2, 1, 3, 4), (5, 2, 1, 4, 3), (5, 2, 3, 1, 4), (5, 2, 3, 4, 1), (5, 2, 4, 1, 3), (5, 2, 4, 3, 1), (5, 3, 1, 2, 4), (5, 3, 1, 4, 2), (5, 3, 2, 1, 4), (5, 3, 2, 4, 1), (5, 3, 4, 1, 2), (5, 3, 4, 2, 1), (5, 4, 1, 2, 3), (5, 4, 1, 3, 2), (5, 4, 2, 1, 3), (5, 4, 2, 3, 1), (5, 4, 3, 1, 2), (5, 4, 3, 2, 1)]
arr = []
for i in range(5):
	temp = list(map(int, input().split()))
	arr.append(temp)
tot = 0
for i in val2:
	temp = list(i)
	tot_tm = 0
	for j in range(4):
		if not j & 1:
			lim = 4
		else:
			lim = 5
		for m in range(j, lim, 2):
			try:
				(p, q) = (temp[m] - 1, temp[m + 1] - 1)
				tot_tm += arr[p][q] + arr[q][p]
			except:
				pass
	tot = max(tot, tot_tm)
print(tot)


from itertools import permutations
M = []
for _ in range(5):
	row = list(map(int, input().split()))
	M.append(row)
permute = list(permutations([1, 2, 3, 4, 5]))
max_sum = 0
for (one, two, three, four, five) in permute:
	i0 = M[one - 1][two - 1] + M[two - 1][one - 1] + M[three - 1][four - 1] + M[four - 1][three - 1]
	i1 = M[two - 1][three - 1] + M[three - 1][two - 1] + M[four - 1][five - 1] + M[five - 1][four - 1]
	i2 = M[three - 1][four - 1] + M[four - 1][three - 1]
	i3 = M[four - 1][five - 1] + M[five - 1][four - 1]
	new_sum = i0 + i1 + i2 + i3
	if new_sum >= max_sum:
		max_sum = new_sum
print(max_sum)


A = []

def toString(List):
	return ''.join(List)

def permute(a, l, r):
	if l == r:
		A.append(toString(a))
	else:
		for i in range(l, r + 1):
			(a[l], a[i]) = (a[i], a[l])
			permute(a, l + 1, r)
			(a[l], a[i]) = (a[i], a[l])
s = list('12345')
permute(s, 0, 4)
B = [[0, 0, 0, 0, 0, 0]]
for i in range(5):
	p = [int(x) for x in input().split()]
	B.append([0] + p)
Ans = 0
for i in A:
	i = list(map(int, i))
	S = 0
	S += B[i[0]][i[1]] + B[i[1]][i[0]] + B[i[2]][i[3]] + B[i[3]][i[2]]
	S += B[i[1]][i[2]] + B[i[2]][i[1]] + B[i[3]][i[4]] + B[i[4]][i[3]]
	S += B[i[2]][i[3]] + B[i[3]][i[2]]
	S += B[i[3]][i[4]] + B[i[4]][i[3]]
	Ans = max(Ans, S)
print(Ans)


3
import sys
import itertools
h_1 = list(map(int, input().split()))
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]]
	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]]
	hap = hap + all_hap[perm[2]][perm[3]] + all_hap[perm[3]][perm[2]]
	hap = hap + all_hap[perm[3]][perm[4]] + all_hap[perm[4]][perm[3]]
	if hap > max_hap:
		max_hap = hap
print(max_hap)


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


from itertools import permutations
mat = [list(map(int, input().split())) for _ in range(5)]
q = list(range(5))
max_val = 0
for p in permutations(q, 5):
	tmp_val = mat[p[0]][p[1]] + mat[p[1]][p[0]] + mat[p[1]][p[2]] + mat[p[2]][p[1]]
	tmp_val += (mat[p[2]][p[3]] + mat[p[3]][p[2]]) * 2 + (mat[p[3]][p[4]] + mat[p[4]][p[3]]) * 2
	max_val = max(max_val, tmp_val)
print(max_val)


from itertools import permutations
gmatrix = []
for i in range(5):
	z = list(map(int, input().split()))
	gmatrix.append(z)
z = [0, 1, 2, 3, 4]
l = list(permutations(z, 5))
max_happiness = -1
for i in l:
	happiness = gmatrix[i[0]][i[1]] + gmatrix[i[1]][i[0]] + 2 * gmatrix[i[2]][i[3]] + 2 * gmatrix[i[3]][i[2]] + gmatrix[i[1]][i[2]] + gmatrix[i[2]][i[1]] + 2 * gmatrix[i[3]][i[4]] + 2 * gmatrix[i[4]][i[3]]
	max_happiness = max(max_happiness, happiness)
print(max_happiness)


matrix = [[0] * 6 for _ in range(6)]
for i in range(1, 6):
	matrix[i][1:] = list((int(j) for j in input().strip().split(' ')))
mainmx = 0

def ma(status=[False for _ in range(6)], p=[], i=0):
	global mainmx
	if i == 5:
		calmax = 0
		for k in range(5):
			j = k
			while j < 4:
				calmax += matrix[p[j]][p[j + 1]] + matrix[p[j + 1]][p[j]]
				j += 2
		mainmx = max(mainmx, calmax)
		return
	else:
		for j in range(1, 6):
			if status[j] == False:
				p.append(j)
				status[j] = True
				ma(status, p, i + 1)
				p.pop()
				status[j] = False
		return
ma()
print(mainmx)


from sys import *
from itertools import permutations
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)

def next_permutation(L):
	n = len(L)
	i = n - 2
	while i >= 0 and L[i] >= L[i + 1]:
		i -= 1
	if i == -1:
		return False
	j = i + 1
	while j < n and L[j] > L[i]:
		j += 1
	j -= 1
	(L[i], L[j]) = (L[j], L[i])
	left = i + 1
	right = n - 1
	while left < right:
		(L[left], L[right]) = (L[right], L[left])
		left += 1
		right -= 1
	return True
n = 5
mat = []
for i in range(n):
	mat.append(int_arr())
arr = [0, 1, 2, 3, 4]
mx = float('-inf')
arr = list(permutations(arr))
for i in range(len(arr)):
	val = mat[arr[i][0]][arr[i][1]] + mat[arr[i][1]][arr[i][0]] + mat[arr[i][2]][arr[i][3]] + mat[arr[i][3]][arr[i][2]] + mat[arr[i][1]][arr[i][2]] + mat[arr[i][2]][arr[i][1]] + mat[arr[i][3]][arr[i][4]] + mat[arr[i][4]][arr[i][3]] + mat[arr[i][2]][arr[i][3]] + mat[arr[i][3]][arr[i][2]] + mat[arr[i][3]][arr[i][4]] + mat[arr[i][4]][arr[i][3]]
	mx = max(mx, val)
print(mx)


from itertools import permutations as perm
mat = [[int(i) for i in input().split()] for j in range(5)]
ans = 0
for i in perm([0, 1, 2, 3, 4]):
	s = 0
	for k in range(4):
		for j in range(k, 4, 2):
			s += mat[i[j]][i[j + 1]] + mat[i[j + 1]][i[j]]
	if s > ans:
		ans = s
print(ans)


arr = []
for i in range(5):
	listt = list(map(int, input().split()))
	arr.append(listt)
maxx = 0
for i in range(5):
	for j in range(5):
		if i == j:
			continue
		for k in range(5):
			if k == j or k == i:
				continue
			for l in range(5):
				if l == k or l == j or l == i:
					continue
				for m in range(5):
					if m == l or m == k or m == j or (m == i):
						continue
					temp = arr[i][j] + arr[j][i] + arr[j][k] + 2 * arr[k][l] + arr[k][j] + 2 * arr[l][k] + 2 * arr[l][m] + 2 * arr[m][l]
					maxx = max(maxx, temp)
print(maxx)


from itertools import permutations as perm
l = [0, 1, 2, 3, 4]
arr = []
for i in range(5):
	arr.append([int(x) for x in input().split()])
ans = -1
for i in perm(l):
	curr = 0
	p = list(i)
	(a, b, c, d, e) = (p[0], p[1], p[2], p[3], p[4])
	curr += arr[a][b] + arr[b][a] + arr[c][d] + arr[d][c]
	curr += arr[b][c] + arr[c][b] + arr[d][e] + arr[e][d]
	curr += arr[c][d] + arr[d][c]
	curr += arr[d][e] + arr[e][d]
	ans = max(ans, curr)
print(ans)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
from itertools import permutations
l = [[]] * 5
n = [0, 1, 2, 3, 4]
for i in range(5):
	l[i] = li()
maxi = 0
for (a, b, c, d, e) in permutations(n, 5):
	s = l[a][b] + l[b][a] + l[b][c] + l[c][b] + 2 * (l[c][d] + l[d][c] + l[d][e] + l[e][d])
	maxi = max(maxi, s)
print(maxi)


from itertools import permutations
arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
l = [1, 2, 3, 4, 5]
perm = permutations(l)
ans = 0
for i in list(perm):
	count = 0
	loop = 4
	k1 = 0
	while k1 < loop:
		j = k1
		k = j + 1
		while k < 5:
			val = i[j]
			val1 = i[k]
			count += arr[val - 1][val1 - 1] + arr[val1 - 1][val - 1]
			j = k + 1
			k = j + 1
		if count > ans:
			ans = count
		k1 += 1
print(ans)


def fun(mas, h):
	global 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)


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)


from itertools import permutations

def perm(str):
	ans = []
	permList = permutations(str)
	for perm in list(permList):
		ans.append(''.join(perm))
	return ans
a = '01234'
arr = []
for _ in range(5):
	arr.append(list(map(int, input().split())))
ans = 0
p = perm(a)
for x in p:
	x = list(x)
	x = [int(i) for i in x]
	res = 0
	for i in range(0, 5):
		for j in range(i, 5, 2):
			if j + 1 < 5:
				res += arr[x[j]][x[j + 1]] + arr[x[j + 1]][x[j]]
		ans = max(ans, res)
print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict

def main(n, g):
	ans = -1
	best = 0
	perm = permutations(range(5), 5)
	for p in perm:
		h = g[p[1]][p[2]] + g[p[2]][p[1]] + g[p[0]][p[4]] + g[p[4]][p[0]] + (g[p[0]][p[2]] + g[p[2]][p[0]] + g[p[4]][p[3]] + g[p[3]][p[4]]) + (g[p[0]][p[4]] + g[p[4]][p[0]]) + (g[p[4]][p[3]] + g[p[3]][p[4]])
		if h > ans:
			ans = h
			best = ''.join([str(x + 1) for x in p])
	print(ans)

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


matrix = [[0, 0, 0, 0, 0, 0]]
for i in range(5):
	l = [0] + [int(i) for i in input().split(' ')]
	matrix.append(l)
mx = 0
for a_1 in range(1, 6):
	for a_2 in range(1, 6):
		for a_3 in range(1, 6):
			for a_4 in range(1, 6):
				for a_5 in range(1, 6):
					if not a_1 == a_2 and (not a_1 == a_3) and (not a_1 == a_4) and (not a_1 == a_5) and (not a_2 == a_3) and (not a_2 == a_4) and (not a_2 == a_5) and (not a_3 == a_4) and (not a_3 == a_5) and (not a_4 == a_5):
						m = matrix[a_1][a_2] + matrix[a_2][a_1] + matrix[a_3][a_4] + matrix[a_4][a_3] + (matrix[a_2][a_3] + matrix[a_3][a_2] + matrix[a_4][a_5] + matrix[a_5][a_4]) + (matrix[a_3][a_4] + matrix[a_4][a_3]) + (matrix[a_4][a_5] + matrix[a_5][a_4])
						if mx < m:
							mx = m
print(mx)


from itertools import permutations
gij = [[int(c) for c in input().split()] for _ in range(5)]
ans = -1
for comb in permutations(range(5)):
	cur = 2 * (gij[comb[2]][comb[3]] + gij[comb[3]][comb[4]]) + gij[comb[1]][comb[2]] + gij[comb[0]][comb[1]]
	cur += 2 * (gij[comb[3]][comb[2]] + gij[comb[4]][comb[3]]) + gij[comb[2]][comb[1]] + gij[comb[1]][comb[0]]
	ans = max(ans, cur)
print(ans)


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 = []
for i in range(5):
	temp = list(map(int, input().split()))
	g.append(temp)
maxi = 0
perm = ['12345', '12354', '12435', '12453', '12543', '12534', '13245', '13254', '13425', '13452', '13542', '13524', '14325', '14352', '14235', '14253', '14523', '14532', '15342', '15324', '15432', '15423', '15243', '15234', '21345', '21354', '21435', '21453', '21543', '21534', '23145', '23154', '23415', '23451', '23541', '23514', '24315', '24351', '24135', '24153', '24513', '24531', '25341', '25314', '25431', '25413', '25143', '25134', '32145', '32154', '32415', '32451', '32541', '32514', '31245', '31254', '31425', '31452', '31542', '31524', '34125', '34152', '34215', '34251', '34521', '34512', '35142', '35124', '35412', '35421', '35241', '35214', '42315', '42351', '42135', '42153', '42513', '42531', '43215', '43251', '43125', '43152', '43512', '43521', '41325', '41352', '41235', '41253', '41523', '41532', '45312', '45321', '45132', '45123', '45213', '45231', '52341', '52314', '52431', '52413', '52143', '52134', '53241', '53214', '53421', '53412', '53142', '53124', '54321', '54312', '54231', '54213', '54123', '54132', '51342', '51324', '51432', '51423', '51243', '51234']
for seq in perm:
	happy = g[int(seq[0]) - 1][int(seq[1]) - 1] + g[int(seq[1]) - 1][int(seq[0]) - 1] + g[int(seq[2]) - 1][int(seq[3]) - 1] + g[int(seq[3]) - 1][int(seq[2]) - 1] + (g[int(seq[1]) - 1][int(seq[2]) - 1] + g[int(seq[2]) - 1][int(seq[1]) - 1] + g[int(seq[3]) - 1][int(seq[4]) - 1] + g[int(seq[4]) - 1][int(seq[3]) - 1]) + (g[int(seq[2]) - 1][int(seq[3]) - 1] + g[int(seq[3]) - 1][int(seq[2]) - 1]) + (g[int(seq[3]) - 1][int(seq[4]) - 1] + g[int(seq[4]) - 1][int(seq[3]) - 1])
	if happy > maxi:
		maxi = happy
print(maxi)


import sys
import itertools
data = sys.stdin.readlines()
g = []
for i in data:
	g += [[int(x) for x in i.rstrip('\n').split(' ')]]
a = 0
perms = itertools.permutations('01234')
for perm in perms:
	perm = [int(x) for x in perm]
	tmp = g[perm[0]][perm[1]] + g[perm[1]][perm[0]]
	tmp += g[perm[2]][perm[3]] + g[perm[3]][perm[2]]
	tmp += g[perm[1]][perm[2]] + g[perm[2]][perm[1]]
	tmp += g[perm[3]][perm[4]] + g[perm[4]][perm[3]]
	tmp += g[perm[2]][perm[3]] + g[perm[3]][perm[2]]
	tmp += g[perm[3]][perm[4]] + g[perm[4]][perm[3]]
	if tmp > a:
		a = tmp
print(a)


rows = [list(map(int, input().split())) for x in range(5)]
values = []
for a in range(5):
	for b in range(4):
		for c in range(3):
			for d in range(2):
				numbers = [1, 2, 3, 4, 5]
				deleted = [a, b, c, d, 0]
				line = []
				for x in deleted:
					line.append(numbers[x])
					del numbers[x]
				h = 0
				for x in range(5, 1, -1):
					for y in range(x // 2):
						(p, q) = (line[y * 2] - 1, line[y * 2 + 1] - 1)
						h += rows[p][q] + rows[q][p]
					del line[0]
				values.append(h)
print(max(values))


from itertools import permutations
matrix = []
for i in range(5):
	matrix.append([int(x) for x in input().split(' ')])
max_s = 0
variables = list(permutations([1, 2, 3, 4, 5]))
for model in variables:
	now_s = matrix[model[0] - 1][model[1] - 1] + matrix[model[1] - 1][model[0] - 1]
	now_s += (matrix[model[3] - 1][model[4] - 1] + matrix[model[4] - 1][model[3] - 1]) * 2
	now_s += matrix[model[1] - 1][model[2] - 1] + matrix[model[2] - 1][model[1] - 1]
	now_s += (matrix[model[2] - 1][model[3] - 1] + matrix[model[3] - 1][model[2] - 1]) * 2
	if now_s > max_s:
		max_s = now_s
print(max_s)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
from itertools import permutations
l = [[]] * 5
n = [1, 2, 3, 4, 5]
for i in range(5):
	l[i] = li()
z = [0] * 120
for (i, p) in enumerate(permutations(n, 5)):
	(a, b, c, d, e) = [j - 1 for j in p]
	z[i] = l[a][b] + l[b][a] + 2 * l[c][d] + 2 * l[d][c] + l[b][c] + l[c][b] + 2 * l[d][e] + 2 * l[e][d]
print(max(z))


a = [list(map(int, input().split())) for i in range(5)]
b = []

def permutt():

	def toString(List):
		return ''.join(List)

	def permute(a, l, r):
		if l == r:
			b.append(toString(a))
		else:
			for i in range(l, r + 1):
				(a[l], a[i]) = (a[i], a[l])
				permute(a, l + 1, r)
				(a[l], a[i]) = (a[i], a[l])
	string = '01234'
	n = len(string)
	a = list(string)
	permute(a, 0, n - 1)
permutt()
max1 = 0
for i in b:
	k = [int(i[0]), int(i[1]), int(i[2]), int(i[3]), int(i[4])]
	c = a[k[0]][k[1]] + a[k[1]][k[0]] + a[k[2]][k[3]] + a[k[3]][k[2]] + (a[k[1]][k[2]] + a[k[2]][k[1]] + a[k[3]][k[4]] + a[k[4]][k[3]]) + (a[k[2]][k[3]] + a[k[3]][k[2]]) + (a[k[3]][k[4]] + a[k[4]][k[3]])
	max1 = max(c, max1)
print(max1)


from itertools import permutations

def calc_happiness(positions, g):
	s = g[positions[0]][positions[1]] + g[positions[1]][positions[0]]
	s += g[positions[2]][positions[3]] + g[positions[3]][positions[2]]
	s += g[positions[1]][positions[2]] + g[positions[2]][positions[1]]
	s += g[positions[3]][positions[4]] + g[positions[4]][positions[3]]
	s += g[positions[2]][positions[3]] + g[positions[3]][positions[2]]
	s += g[positions[3]][positions[4]] + g[positions[4]][positions[3]]
	return s
g = []
for i in range(5):
	g.append([int(k) for k in input().split()])
m = 0
perm = list(permutations([0, 1, 2, 3, 4]))
for p in perm:
	happiness = calc_happiness(p, g)
	if happiness > m:
		m = happiness
print(m)


from itertools import permutations

def main():
	m = []
	for i in range(5):
		row = [int(j) for j in input().split()]
		m.append(row)
	p = permutations(range(5))
	max = 0
	for j in list(p):
		acum = 0
		acum += m[j[0]][j[1]] + m[j[2]][j[3]] + m[j[1]][j[0]] + m[j[3]][j[2]]
		acum += m[j[1]][j[2]] + m[j[3]][j[4]] + m[j[2]][j[1]] + m[j[4]][j[3]]
		acum += m[j[2]][j[3]] + m[j[3]][j[2]]
		acum += m[j[3]][j[4]] + m[j[4]][j[3]]
		if acum > max:
			max = acum
	print(max)
	return
main()


from itertools import permutations
orders = permutations(list(range(5)))
happiness = [list(map(int, input().strip().split())) for i in range(5)]
max_h = 0
for tup in orders:
	hap = 0
	for i in range(5):
		for j in range(i, 5, 2):
			if j + 1 < 5:
				hap += happiness[tup[j]][tup[j + 1]] + happiness[tup[j + 1]][tup[j]]
	max_h = max(max_h, hap)
print(max_h)


from itertools import permutations
a = []
for _ in range(5):
	a.append(list(map(int, input().split())))
s = 0
for i in permutations('01234', 5):
	b = []
	for j in i:
		b.append(a[int(j)])
	b = list(zip(*b))
	c = []
	for j in i:
		c.append(b[int(j)])
	s = max(s, c[0][1] + c[1][0] + c[1][2] + c[2][1] + 2 * (c[2][3] + c[3][2] + c[3][4] + c[4][3]))
print(s)


import itertools
g = [[int(i) for i in input().split()] for j in range(5)]
p = list(itertools.permutations([0, 1, 2, 3, 4], 5))
ans = 0
for i in p:
	s = 0
	for k in range(4):
		while k < 4:
			s += g[i[k]][i[k + 1]] + g[i[k + 1]][i[k]]
			k += 2
	if s > ans:
		ans = s
print(ans)


def generate_permutations(n):
	if n == 1:
		return ['1']
	s_perms = generate_permutations(n - 1)
	perms = []
	for p in s_perms:
		p = list(map(lambda x: str(int(x) + 1), list(p)))
		for i in range(len(p) + 1):
			perms.append(''.join(p[:i]) + '1' + ''.join(p[i:]))
	return perms
perms = list(map(lambda x: list(map(lambda y: int(y) - 1, list(x))), generate_permutations(5)))
mtrx = []
for _ in range(5):
	mtrx.append(list(map(int, input().split())))
mh = 0
for p in perms:
	mh = max(mh, mtrx[p[0]][p[1]] + mtrx[p[1]][p[2]] + mtrx[p[1]][p[0]] + mtrx[p[2]][p[1]] + 2 * (mtrx[p[2]][p[3]] + mtrx[p[3]][p[4]] + mtrx[p[3]][p[2]] + mtrx[p[4]][p[3]]))
print(mh)


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
from heapq import heappop, heappush
from bisect import *
from collections import deque
from math import *
from itertools import permutations
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
g = []
for i in range(5):
	g.append(LIST())
ans = -1
for i in permutations(range(0, 5)):
	sm = g[i[0]][i[1]] + g[i[1]][i[0]]
	sm += g[i[2]][i[3]] + g[i[3]][i[2]]
	sm += g[i[1]][i[2]] + g[i[2]][i[1]]
	sm += g[i[3]][i[4]] + g[i[4]][i[3]]
	sm += g[i[2]][i[3]] + g[i[3]][i[2]]
	sm += g[i[3]][i[4]] + g[i[4]][i[3]]
	if sm > ans:
		ans = sm
print(ans)


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


import sys, threading, os.path
import collections, heapq, math, bisect
import string
from platform import python_version
import itertools
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('input.txt'):
		input = open('input.txt', 'r')
	else:
		input = sys.stdin
	studs = []
	for i in range(5):
		studs.append(list(map(int, input.readline().split())))
	allperm = list(itertools.permutations([1, 2, 3, 4, 5]))
	fineres = 0
	allres = []
	for lis in allperm:
		sum = 0
		sum += studs[lis[0] - 1][lis[1] - 1] + studs[lis[1] - 1][lis[0] - 1]
		sum += studs[lis[2] - 1][lis[3] - 1] + studs[lis[3] - 1][lis[2] - 1]
		sum += studs[lis[1] - 1][lis[2] - 1] + studs[lis[2] - 1][lis[1] - 1]
		sum += studs[lis[3] - 1][lis[4] - 1] + studs[lis[4] - 1][lis[3] - 1]
		sum += studs[lis[2] - 1][lis[3] - 1] + studs[lis[3] - 1][lis[2] - 1]
		sum += studs[lis[3] - 1][lis[4] - 1] + studs[lis[4] - 1][lis[3] - 1]
		allres.append(sum)
	output = max(allres)
	if os.path.exists('output.txt'):
		open('output.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


from itertools import permutations
from collections import deque

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

def cost(g, q):
	ret = 0
	while len(q) > 0:
		for i in range(0, len(q) - 1, 2):
			ret += g[q[i]][q[i + 1]]
			ret += g[q[i + 1]][q[i]]
		q.popleft()
	return ret

def main():
	g = inp()
	m = 0
	for lst in permutations(range(5)):
		m = max(m, cost(g, deque(lst)))
	return m
print(main())


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)


def getpermu(a, ans, res):
	if len(a) == 0:
		res.append(list(ans))
		return
	for i in range(len(a)):
		me = a[i]
		rest = a[:i] + a[i + 1:]
		getpermu(rest, ans + [me], res)
m = [[0 for x in range(5)] for x in range(5)]
for i in range(5):
	m[i] = [int(x) for x in input().split()]
maxi = -float('inf')
res = []
getpermu([x for x in range(1, 6)], [], res)
for permu in res:
	onetwo = 1 * (m[permu[0] - 1][permu[1] - 1] + m[permu[1] - 1][permu[0] - 1])
	threefour = 2 * (m[permu[2] - 1][permu[3] - 1] + m[permu[3] - 1][permu[2] - 1])
	twothree = 1 * (m[permu[1] - 1][permu[2] - 1] + m[permu[2] - 1][permu[1] - 1])
	fourfive = 2 * (m[permu[3] - 1][permu[4] - 1] + m[permu[4] - 1][permu[3] - 1])
	maxi = max(maxi, onetwo + threefour + twothree + fourfive)
print(maxi)


def get_total(order, g):
	happiness = 0
	while len(order) > 1:
		for i in range(0, len(order), 2):
			if i + 1 < len(order):
				(p1, p2) = (order[i] - 1, order[i + 1] - 1)
				happiness += g[p1][p2] + g[p2][p1]
		order.pop(0)
	return happiness

def generate(order, g):
	if len(order) == 5:
		return get_total(order, g)
	best = 0
	for j in range(1, 6):
		if j not in order:
			best = max(best, generate(order + [j], g))
	return best

def calc(g):
	return generate([], g)
g = []
for _ in range(5):
	g.append(list(map(int, input().split())))
print(calc(g))


g = []
for i in range(5):
	g.append([int(num) for num in input().split()])
lines = [[0, 1, 2, 3, 4], [0, 1, 2, 4, 3], [0, 1, 3, 2, 4], [0, 1, 3, 4, 2], [0, 1, 4, 2, 3], [0, 1, 4, 3, 2], [0, 2, 1, 3, 4], [0, 2, 1, 4, 3], [0, 2, 3, 1, 4], [0, 2, 3, 4, 1], [0, 2, 4, 1, 3], [0, 2, 4, 3, 1], [0, 3, 1, 2, 4], [0, 3, 1, 4, 2], [0, 3, 2, 1, 4], [0, 3, 2, 4, 1], [0, 3, 4, 1, 2], [0, 3, 4, 2, 1], [0, 4, 1, 2, 3], [0, 4, 1, 3, 2], [0, 4, 2, 1, 3], [0, 4, 2, 3, 1], [0, 4, 3, 1, 2], [0, 4, 3, 2, 1], [1, 0, 2, 3, 4], [1, 0, 2, 4, 3], [1, 0, 3, 2, 4], [1, 0, 3, 4, 2], [1, 0, 4, 2, 3], [1, 0, 4, 3, 2], [1, 2, 0, 3, 4], [1, 2, 0, 4, 3], [1, 2, 3, 0, 4], [1, 2, 3, 4, 0], [1, 2, 4, 0, 3], [1, 2, 4, 3, 0], [1, 3, 0, 2, 4], [1, 3, 0, 4, 2], [1, 3, 2, 0, 4], [1, 3, 2, 4, 0], [1, 3, 4, 0, 2], [1, 3, 4, 2, 0], [1, 4, 0, 2, 3], [1, 4, 0, 3, 2], [1, 4, 2, 0, 3], [1, 4, 2, 3, 0], [1, 4, 3, 0, 2], [1, 4, 3, 2, 0], [2, 0, 1, 3, 4], [2, 0, 1, 4, 3], [2, 0, 3, 1, 4], [2, 0, 3, 4, 1], [2, 0, 4, 1, 3], [2, 0, 4, 3, 1], [2, 1, 0, 3, 4], [2, 1, 0, 4, 3], [2, 1, 3, 0, 4], [2, 1, 3, 4, 0], [2, 1, 4, 0, 3], [2, 1, 4, 3, 0], [2, 3, 0, 1, 4], [2, 3, 0, 4, 1], [2, 3, 1, 0, 4], [2, 3, 1, 4, 0], [2, 3, 4, 0, 1], [2, 3, 4, 1, 0], [2, 4, 0, 1, 3], [2, 4, 0, 3, 1], [2, 4, 1, 0, 3], [2, 4, 1, 3, 0], [2, 4, 3, 0, 1], [2, 4, 3, 1, 0], [3, 0, 1, 2, 4], [3, 0, 1, 4, 2], [3, 0, 2, 1, 4], [3, 0, 2, 4, 1], [3, 0, 4, 1, 2], [3, 0, 4, 2, 1], [3, 1, 0, 2, 4], [3, 1, 0, 4, 2], [3, 1, 2, 0, 4], [3, 1, 2, 4, 0], [3, 1, 4, 0, 2], [3, 1, 4, 2, 0], [3, 2, 0, 1, 4], [3, 2, 0, 4, 1], [3, 2, 1, 0, 4], [3, 2, 1, 4, 0], [3, 2, 4, 0, 1], [3, 2, 4, 1, 0], [3, 4, 0, 1, 2], [3, 4, 0, 2, 1], [3, 4, 1, 0, 2], [3, 4, 1, 2, 0], [3, 4, 2, 0, 1], [3, 4, 2, 1, 0], [4, 0, 1, 2, 3], [4, 0, 1, 3, 2], [4, 0, 2, 1, 3], [4, 0, 2, 3, 1], [4, 0, 3, 1, 2], [4, 0, 3, 2, 1], [4, 1, 0, 2, 3], [4, 1, 0, 3, 2], [4, 1, 2, 0, 3], [4, 1, 2, 3, 0], [4, 1, 3, 0, 2], [4, 1, 3, 2, 0], [4, 2, 0, 1, 3], [4, 2, 0, 3, 1], [4, 2, 1, 0, 3], [4, 2, 1, 3, 0], [4, 2, 3, 0, 1], [4, 2, 3, 1, 0], [4, 3, 0, 1, 2], [4, 3, 0, 2, 1], [4, 3, 1, 0, 2], [4, 3, 1, 2, 0], [4, 3, 2, 0, 1], [4, 3, 2, 1, 0]]
components = [0, 0, 0, 0]

def calc_happ(line):
	for i in range(4):
		j = i + 1
		comp = g[line[i]][line[j]] + g[line[j]][line[i]]
		components[i] = comp
	return components[0] + components[1] + 2 * components[2] + 2 * components[3]

def main():
	max_happ = 0
	for line in lines:
		temp = calc_happ(line)
		if temp > max_happ:
			max_happ = temp
	print(max_happ)
main()


from itertools import permutations
x = permutations([1, 2, 3, 4, 5])
per = []
for i in x:
	n = i[0] * 10000 + i[1] * 1000 + i[2] * 100 + i[3] * 10 + i[4]
	per.append(n)
b = []
for i in range(5):
	b.append([int(i) for i in input().split()])
max_sum = 0
for i in per:
	i = str(i)
	s = b[int(i[0]) - 1][int(i[1]) - 1] + b[int(i[1]) - 1][int(i[0]) - 1] + (b[int(i[2]) - 1][int(i[3]) - 1] + b[int(i[3]) - 1][int(i[2]) - 1]) * 2 + b[int(i[1]) - 1][int(i[2]) - 1] + b[int(i[2]) - 1][int(i[1]) - 1] + (b[int(i[3]) - 1][int(i[4]) - 1] + b[int(i[4]) - 1][int(i[3]) - 1]) * 2
	if s > max_sum:
		max_sum = s
print(max_sum)


from itertools import permutations

def main(grid):
	return max((get_total_happiness(line, grid) for line in generate_lines()))

def get_total_happiness(line, grid):
	total = 0
	while line:
		for (a, b) in zip(line[::2], line[1::2]):
			total += grid[a][b] + grid[b][a]
		del line[0]
	return total

def generate_lines():
	for line in permutations(range(5)):
		yield list(line)
grid = [list(map(int, input().split())) for _ in range(5)]
print(main(grid))


import itertools
grid = []
for _ in range(5):
	grid.append(list(map(int, input().split())))
ans = -10 ** 9
for perm in itertools.permutations(range(5)):
	(a, b, c, d, e) = perm
	happiness = grid[a][b] + grid[b][a] + grid[b][c] + grid[c][b] + 2 * (grid[c][d] + grid[d][c] + grid[d][e] + grid[e][d])
	ans = max(ans, happiness)
print(ans)


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


x = [[int(j) for j in input().split()] for i in range(5)]
m = 0
for a in range(5):
	for b in range(5):
		if b == a:
			continue
		for c in range(5):
			if c == b or c == a:
				continue
			for d in range(5):
				if d == a or d == b or d == c:
					continue
				for e in range(5):
					if e == a or e == b or e == c or (e == d):
						continue
					s = x[a][b] + x[b][a] + x[b][c] + x[c][b] + 2 * (x[c][d] + x[d][c] + x[d][e] + x[e][d])
					if s > m:
						m = s
print(m)


from itertools import permutations

def main():
	l = [list(map(int, input().split())) for _ in range(5)]
	l = tuple((l[i][j] + l[j][i] for i in range(5) for j in range(5)))
	print(max((sum((l[i * 5 + j] for shift in range(4) for (i, j) in zip(pp[shift::2], pp[shift + 1::2]))) for pp in permutations(range(5)))))
main()


from itertools import permutations
arr = []
for _ in range(5):
	arr.append(list(map(int, input().split())))
permutation = list(permutations([1, 2, 3, 4, 5]))
maxsum = 0
sum = 0
for i in range(len(permutation)):
	first = permutation[i][0] - 1
	second = permutation[i][1] - 1
	third = permutation[i][2] - 1
	four = permutation[i][3] - 1
	five = permutation[i][4] - 1
	sum += arr[first][second]
	sum += arr[second][first]
	sum += arr[third][four] * 2
	sum += arr[four][third] * 2
	sum += arr[second][third]
	sum += arr[third][second]
	sum += arr[four][five] * 2
	sum += arr[five][four] * 2
	if sum > maxsum:
		maxsum = sum
	sum = 0
print(maxsum)


from itertools import permutations
obj = permutations([0, 1, 2, 3, 4])
l = list(obj)
g = []
for i in range(0, 5):
	g.append(list(map(int, input().strip().split())))
gl = 0
for i in l:
	res = 0
	res += g[i[0]][i[1]] + g[i[1]][i[0]]
	res += g[i[2]][i[3]] + g[i[3]][i[2]]
	res += g[i[1]][i[2]] + g[i[2]][i[1]]
	res += g[i[3]][i[4]] + g[i[4]][i[3]]
	res += g[i[2]][i[3]] + g[i[3]][i[2]]
	res += g[i[3]][i[4]] + g[i[4]][i[3]]
	gl = max(res, gl)
print(gl)


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


import itertools
one = [int(x) for x in input().split()]
two = [int(x) for x in input().split()]
three = [int(x) for x in input().split()]
four = [int(x) for x in input().split()]
five = [int(x) for x in input().split()]
test = [one, two, three, four, five]
letters = ['1', '2', '3', '4', '5']
max = 0
for c in itertools.permutations(letters, 5):
	first = test[int(c[0]) - 1][int(c[1]) - 1] + test[int(c[1]) - 1][int(c[0]) - 1] + test[int(c[2]) - 1][int(c[3]) - 1] + test[int(c[3]) - 1][int(c[2]) - 1]
	second = test[int(c[1]) - 1][int(c[2]) - 1] + test[int(c[2]) - 1][int(c[1]) - 1] + test[int(c[3]) - 1][int(c[4]) - 1] + test[int(c[4]) - 1][int(c[3]) - 1]
	third = test[int(c[2]) - 1][int(c[3]) - 1] + test[int(c[3]) - 1][int(c[2]) - 1] + test[int(c[4]) - 1][int(c[3]) - 1] + test[int(c[3]) - 1][int(c[4]) - 1]
	sum = first + second + third
	if sum > max:
		max = sum
print(max)


import itertools as repeater
list1 = [list(map(int, input().split(' '))) for _ in range(5)]
max_num = 0
for i in repeater.permutations(range(5)):
	i = list(i)
	max_num = max(max_num, list1[i[0]][i[1]] + list1[i[1]][i[0]] + list1[i[2]][i[3]] + list1[i[3]][i[2]] + list1[i[1]][i[2]] + list1[i[2]][i[1]] + list1[i[3]][i[4]] + list1[i[4]][i[3]] + list1[i[2]][i[3]] + list1[i[3]][i[2]] + list1[i[3]][i[4]] + list1[i[4]][i[3]])
print(max_num)


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
line = [0, 1, 2, 3, 4]
visit = set()
result = []

def dfs(combination):
	if len(combination) == len(line):
		result.append(combination[:])
		return
	for i in range(len(line)):
		if i not in visit:
			visit.add(i)
			combination.append(line[i])
			dfs(combination)
			visit.remove(i)
			combination.pop()
combination = []
dfs(combination)
maxx = -float('inf')
for line in result:
	val = matrix[line[0]][line[1]] + matrix[line[1]][line[0]] + 2 * (matrix[line[2]][line[3]] + matrix[line[3]][line[2]]) + matrix[line[1]][line[2]] + matrix[line[2]][line[1]] + 2 * (matrix[line[-1]][line[-2]] + matrix[line[-2]][line[-1]])
	maxx = max(val, maxx)
print(maxx)


from itertools import permutations
l = []
for _ in range(5):
	l.append(list(map(int, input().split())))
n = [0, 1, 2, 3, 4]
maxi = 0
for (a, b, c, d, e) in permutations(n, 5):
	s = l[a][b] + l[b][a] + l[c][d] + l[d][c] + l[b][c] + l[c][b] + l[d][e] + l[e][d] + l[c][d] + l[d][c] + l[d][e] + l[e][d]
	maxi = max(s, maxi)
print(maxi)


from itertools import permutations
l = list(permutations(range(1, 6)))
mat = []

def h(li, mat):
	ha = 0
	j = 0
	while j < 5:
		for i in range(j, len(li), 2):
			if i < len(li) - 1:
				ha += mat[li[i] - 1][li[i + 1] - 1] + mat[li[i + 1] - 1][li[i] - 1]
		j += 1
	return ha
ans = 0
for i in range(5):
	arr = [int(i) for i in input().split()]
	mat.append(arr)
for i in l:
	ans = max(ans, h(i, mat))
print(ans)


g = [[int(val) for val in input().split()] for _ in range(5)]
max = 0
for i1 in range(5):
	for i2 in range(5):
		if i1 != i2:
			for i3 in range(5):
				if i1 != i3 and i2 != i3:
					for i4 in range(5):
						if i1 != i4 and i2 != i4 and (i3 != i4):
							for i5 in range(5):
								if i1 != i5 and i2 != i5 and (i3 != i5) and (i4 != i5):
									sum = 0
									sum += g[i1][i2] + g[i2][i1] + g[i3][i4] + g[i4][i3]
									sum += g[i2][i3] + g[i3][i2] + g[i4][i5] + g[i5][i4]
									sum += g[i3][i4] + g[i4][i3]
									sum += g[i4][i5] + g[i5][i4]
									if sum > max:
										max = sum
print(max)


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)


l = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
e = list(map(int, input().split()))
l = [a, b, c, d, e]
ma = 0
for i in range(0, 5):
	for j in range(0, 5):
		for k in range(0, 5):
			for n in range(0, 5):
				for m in range(0, 5):
					if i == j or i == k or i == n or (i == m) or (j == k) or (j == n) or (j == m) or (k == n) or (k == m) or (m == n):
						continue
					else:
						t = l[i][j] + l[j][i] + l[j][k] + l[k][j] + 2 * (l[k][n] + l[n][k] + l[n][m] + l[m][n])
						ma = max(ma, t)
print(ma)


from itertools import permutations as p
z = []
r = [*range(5)]
ans = 0
for i in range(5):
	z += [list(map(int, input().split()))]
s = 0

def function(z, k):
	global s
	for i in range(0, len(k) - 1, 2):
		s += z[k[i]][k[i + 1]] + z[k[i + 1]][k[i]]
	k.pop(0)
	if len(k) == 1:
		return
	function(z, k)
for i in list(p(r, 5)):
	s = 0
	function(z, list(i))
	ans = max(ans, s)
print(ans)


import itertools
g = []
for i in range(5):
	g.append([int(i) for i in input().split(' ')])
max_happiness = 0
for i in itertools.permutations('01234', 5):
	seq = [int(j) for j in i]
	cur_happiness = 0
	cur_happiness += g[seq[0]][seq[1]] + g[seq[1]][seq[0]] + (g[seq[2]][seq[3]] + g[seq[3]][seq[2]]) * 2
	cur_happiness += g[seq[1]][seq[2]] + g[seq[2]][seq[1]] + (g[seq[3]][seq[4]] + g[seq[4]][seq[3]]) * 2
	if cur_happiness > max_happiness:
		max_happiness = cur_happiness
print(max_happiness)


a = [0] * 5
for i in range(5):
	a[i] = list(map(int, input().split()))
maxi = 0
for i1 in range(5):
	seq = [0] * 5
	mp = {}
	mp[i1] = 1
	seq[0] = i1
	for i2 in range(5):
		if i2 in mp:
			continue
		mp[i2] = 1
		seq[1] = i2
		for i3 in range(5):
			if i3 in mp:
				continue
			mp[i3] = 1
			seq[2] = i3
			for i4 in range(5):
				if i4 in mp:
					continue
				mp[i4] = 1
				seq[3] = i4
				for i5 in range(5):
					if i5 in mp:
						continue
					seq[4] = i5
					p = a[seq[0]][seq[1]] + a[seq[1]][seq[0]] + a[seq[2]][seq[3]] + a[seq[3]][seq[2]]
					q = a[seq[2]][seq[1]] + a[seq[1]][seq[2]] + a[seq[4]][seq[3]] + a[seq[3]][seq[4]]
					r = a[seq[2]][seq[3]] + a[seq[3]][seq[2]] + a[seq[4]][seq[3]] + a[seq[3]][seq[4]]
					maxi = max(maxi, p + q + r)
				del mp[i4]
			del mp[i3]
		del mp[i2]
	del mp[i1]
print(maxi)


from itertools import permutations

def solve(g):
	perm = list(permutations(range(0, 5)))
	sol = 0
	for p in perm:
		happ = 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]]
		sol = max(happ, sol)
	return sol
g = []
for _ in range(5):
	g.append(list(map(int, input().split())))
print(solve(g))


import itertools
arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
perms = list(itertools.permutations([0, 1, 2, 3, 4]))
maxhp = 0
for perm_tup in perms:
	perm = list(perm_tup)
	hp = 0
	while perm:
		for i in range(0, len(perm), 2):
			if i + 1 >= len(perm):
				break
			hp += arr[perm[i]][perm[i + 1]] + arr[perm[i + 1]][perm[i]]
		perm.pop(0)
	maxhp = max(maxhp, hp)
print(maxhp)


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 permutations

def caculate(array):
	ans = 0
	ans += g[array[0]][array[1]] + g[array[1]][array[0]]
	ans += g[array[2]][array[3]] + g[array[3]][array[2]]
	ans += g[array[1]][array[2]] + g[array[2]][array[1]]
	ans += g[array[3]][array[4]] + g[array[4]][array[3]]
	ans += g[array[2]][array[3]] + g[array[3]][array[2]]
	ans += g[array[3]][array[4]] + g[array[4]][array[3]]
	return ans
g = [list(map(int, input().split())) for i in range(5)]
result = 0
for i in permutations([0, 1, 2, 3, 4]):
	result = max(result, caculate(i))
print(result)


l = []
for i in range(5):
	li = list(map(int, input().split()))
	l.append(li)
from itertools import permutations
(a, ans) = (permutations([0, 1, 2, 3, 4], 5), -1)
for i in a:
	x = l[i[0]][i[1]] + l[i[1]][i[0]] + l[i[1]][i[2]] + l[i[2]][i[1]] + 2 * (l[i[2]][i[3]] + l[i[3]][i[2]] + l[i[3]][i[4]] + l[i[4]][i[3]])
	if x > ans:
		ans = x
print(ans)


import itertools
g = [[[] for _ in range(5)] for _ in range(5)]
for i in range(5):
	gi = [int(gij) for gij in input().split(' ')]
	for j in range(5):
		gij = gi[j]
		g[i][j] = gij
p = itertools.permutations([1, 2, 3, 4, 5])
ans = -1
for x in p:
	pi = list(x)
	pi = [pi - 1 for pi in pi]
	tmp = 0
	tmp += g[pi[0]][pi[1]]
	tmp += g[pi[1]][pi[0]]
	tmp += g[pi[1]][pi[2]]
	tmp += g[pi[2]][pi[1]]
	tmp += g[pi[2]][pi[3]]
	tmp += g[pi[3]][pi[2]]
	tmp += g[pi[2]][pi[3]]
	tmp += g[pi[3]][pi[2]]
	tmp += g[pi[3]][pi[4]]
	tmp += g[pi[4]][pi[3]]
	tmp += g[pi[3]][pi[4]]
	tmp += g[pi[4]][pi[3]]
	if tmp > ans:
		ans = tmp
print(ans)


from itertools import permutations

def main():
	a = [[int(j) for j in input().split()] for i in range(5)]
	(k, ans) = ([0, 1, 2, 3, 4], 0)
	for d in permutations(k):
		val = a[d[0]][d[1]] + a[d[1]][d[0]] + a[d[1]][d[2]] + a[d[2]][d[1]] + (a[d[2]][d[3]] + a[d[3]][d[2]]) * 2 + (a[d[3]][d[4]] + a[d[4]][d[3]]) * 2
		ans = max(ans, val)
	print(ans)
main()


def happy(l, h):
	s = 0
	while l:
		for i in range(0, len(l) - 1, 2):
			s += h[l[i]][l[i + 1]] + h[l[i + 1]][l[i]]
		l.pop(0)
	return s
import itertools
from itertools import permutations
h = []
for i in range(5):
	l = list(map(int, input().split()))
	h.append(l)
a = list(range(5))
s = list(itertools.permutations(a))
ans = 0
for i in range(len(s)):
	m = happy(list(s[i]), h)
	ans = max(ans, m)
print(ans)


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 = [list(map(int, input().split())) for _ in range(5)]
from itertools import permutations as P
mx = 0
for per in P([0, 1, 2, 3, 4]):
	(a, b, c, d, e) = per
	mx = max(mx, g[a][b] + g[b][a] + g[b][c] + g[c][b] + 2 * (g[e][d] + g[d][e] + g[d][c] + g[c][d]))
print(mx)


def gint():
	return int(input())

def gint_arr():
	return list(map(int, input().split()))

def gfloat():
	return float(input())

def gfloat_arr():
	return list(map(float, input().split()))

def pair_int():
	return map(int, input().split())
INF = 1 << 31
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
from itertools import permutations
g = []
for i in range(5):
	g.append(gint_arr())
res = -INF
for p in permutations(range(5)):
	res = max(res, g[p[0]][p[1]] + g[p[1]][p[0]] + g[p[1]][p[2]] + g[p[2]][p[1]] + 2 * (g[p[2]][p[3]] + g[p[3]][p[2]]) + 2 * (g[p[3]][p[4]] + g[p[4]][p[3]]))
print(res)


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


import itertools
mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
ans = 0
for p in itertools.permutations([0, 1, 2, 3, 4]):
	(a, b, c, d, e) = (p[0], p[1], p[2], p[3], p[4])
	happiness = mat[a][b] + mat[b][a] + mat[b][c] + mat[c][b] + 2 * (mat[c][d] + mat[d][c] + mat[d][e] + mat[e][d])
	ans = max(ans, happiness)
print(ans)


def arr_2d(n):
	return [[int(x) for x in stdin.readline().split()] for i in range(n)]
from sys import *
from itertools import *
(arr, perm, ans) = (arr_2d(5), list(permutations([x for x in range(5)], 5)), 0)
for i in perm:
	eq = arr[i[0]][i[1]] + arr[i[1]][i[0]] + arr[i[1]][i[2]] + arr[i[2]][i[1]] + (arr[i[3]][i[2]] + arr[i[2]][i[3]]) * 2 + (arr[i[4]][i[3]] + arr[i[3]][i[4]]) * 2
	ans = max(ans, eq)
print(ans)


from itertools import permutations

def calc_happiness(mat, arr):
	happiness = 0
	while len(arr) > 1:
		i = 0
		while i < len(arr) - 1:
			happiness += mat[arr[i]][arr[i + 1]] + mat[arr[i + 1]][arr[i]]
			i += 2
		del arr[0]
	return happiness
mat = []
for _ in range(5):
	mat.append(list(map(int, input().split())))
best = 0
for i in permutations([0, 1, 2, 3, 4]):
	happiness = calc_happiness(mat, list(i))
	if happiness > best:
		best = happiness
print(best)


from itertools import permutations
lines = []
for i in range(5):
	lines.append([int(x) for x in input().split(' ')])
max_thus_far = 0
pairs = []
perm = permutations([0, 1, 2, 3, 4])
for i in list(perm):
	s = lines[i[0]][i[1]] + lines[i[1]][i[0]] + 2 * (lines[i[2]][i[3]] + lines[i[3]][i[2]]) + lines[i[1]][i[2]] + lines[i[2]][i[1]] + 2 * (lines[i[4]][i[3]] + lines[i[3]][i[4]])
	if s > max_thus_far:
		max_thus_far = s
print(max_thus_far)


import sys
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(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)


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]
import itertools

def solve(lst):
	perm = list(itertools.permutations([1, 2, 3, 4, 5]))
	maxx = 0
	for i in perm:
		summ = 0
		for j in range(5):
			for k in range(0, 2 * (len(i) // 2), 2):
				summ += lst[i[k] - 1][i[k + 1] - 1]
				summ += lst[i[k + 1] - 1][i[k] - 1]
			i = i[1:]
		maxx = max(maxx, summ)
	return maxx
lst = []
for i in range(5):
	lst.append(list(map(int, input().split())))
print(solve(lst))


import sys
from itertools import permutations

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
l = list(permutations([0, 1, 2, 3, 4]))
g = []
for i in range(5):
	g.append(list(map(int, input().split())))
ans = -1
for item in l:
	item = list(item)
	(a, b, c, d, e) = (item[0], item[1], item[2], item[3], item[4])
	curr = g[a][b] + g[b][a] + g[c][d] + g[d][c] + (g[b][c] + g[c][b] + g[d][e] + g[e][d]) + (g[c][d] + g[d][c]) + (g[d][e] + g[e][d])
	ans = max(ans, curr)
print(ans)


import sys

def read_line(cast=None):
	if cast is not None:
		return cast(input().strip())
	else:
		return input().strip()

def read_list(cast=int):
	return list(map(cast, read_line().split()))
g = []
for _ in range(5):
	g.append(read_list())

def sumHappiness(a):
	global g
	h = 0
	for i in range(4):
		j = i
		while j + 1 < 5:
			h += g[a[j]][a[j + 1]] + g[a[j + 1]][a[j]]
			j += 2
	return h

def generateAllPerm(n):
	for i0 in range(5):
		s = set([i0])
		for i1 in range(5):
			if i1 not in s:
				s.add(i1)
				for i2 in range(5):
					if i2 not in s:
						s.add(i2)
						for i3 in range(5):
							if i3 not in s:
								s.add(i3)
								for i4 in range(5):
									if i4 not in s:
										yield [i0, i1, i2, i3, i4]
								s.remove(i3)
						s.remove(i2)
				s.remove(i1)
mh = 0
for a in generateAllPerm(5):
	h = sumHappiness(a)
	if h > mh:
		mh = h
print(mh)


from itertools import permutations as p
m = [list(map(int, input().split())) for _ in range(5)]
max_s = 0
for x in list(p(range(5))):
	s = m[x[0]][x[1]] + m[x[1]][x[0]] + m[x[1]][x[2]] + m[x[2]][x[1]] + 2 * (m[x[2]][x[3]] + m[x[3]][x[2]]) + 2 * (m[x[3]][x[4]] + m[x[4]][x[3]])
	max_s = max(max_s, s)
print(max_s)


from itertools import permutations
happiness = [list(map(int, input().split())) for _ in range(5)]

def get_total(order):
	total = 0
	length = 5
	while length > 1:
		for i in range(0, length, 2):
			if i + 1 < length:
				(x, y) = (order[i] - 1, order[i + 1] - 1)
				total += happiness[x][y] + happiness[y][x]
		order = order[1:]
		length -= 1
	return total
maximum = 0
for perm in permutations([1, 2, 3, 4, 5]):
	maximum = max(maximum, get_total(perm))
print(maximum)


import itertools
mat = []
for i in range(5):
	arr = [int(i) for i in input().split()]
	mat.append(arr)

def evaluate(perm):
	score = mat[perm[0]][perm[1]] + mat[perm[1]][perm[0]] + mat[perm[2]][perm[3]] + mat[perm[3]][perm[2]] + mat[perm[1]][perm[2]] + mat[perm[2]][perm[1]] + mat[perm[3]][perm[4]] + mat[perm[4]][perm[3]] + mat[perm[2]][perm[3]] + mat[perm[3]][perm[2]] + mat[perm[3]][perm[4]] + mat[perm[4]][perm[3]]
	return score
max_ = 0
for perm in itertools.permutations([0, 1, 2, 3, 4]):
	max_ = max(max_, evaluate(perm))
print(max_)


import sys

def minp():
	return sys.stdin.readline().strip()
talks = [(0, 1), (2, 3), (1, 2), (3, 4), (2, 3), (3, 4)]
g = []
for i in range(5):
	g.append(list(map(int, minp().split())))
M = 0
for i in range(5):
	for j in range(5):
		for k in range(5):
			for l in range(5):
				for m in range(5):
					s = [i, j, k, l, m]
					r = 0
					if len(set(s)) != 5:
						continue
					for z in talks:
						(x, y) = (s[z[0]], s[z[1]])
						r += g[x][y]
						r += g[y][x]
					M = max(M, r)
print(M)


from itertools import permutations
(a, mx) = ([], 0)
for i in range(5):
	a.append(list(map(int, input().split())))
for i in permutations([0, 1, 2, 3, 4]):
	new = a[i[0]][i[1]] + a[i[1]][i[0]] + a[i[2]][i[3]] + a[i[3]][i[2]]
	new += a[i[1]][i[2]] + a[i[2]][i[1]] + a[i[3]][i[4]] + a[i[4]][i[3]]
	new += a[i[2]][i[3]] + a[i[3]][i[2]]
	new += a[i[3]][i[4]] + a[i[4]][i[3]]
	mx = max(mx, new)
print(mx)


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)


from itertools import permutations
happy_increase = []
for i in range(5):
	happy_increase.append([int(x) for x in input().split()])
all_perm = list(permutations([0, 1, 2, 3, 4], 5))
ans = 0
for p in all_perm:
	p = [int(x) for x in p]
	summ = happy_increase[p[0]][p[1]] + happy_increase[p[1]][p[0]]
	summ += happy_increase[p[2]][p[3]] + happy_increase[p[3]][p[2]]
	summ += happy_increase[p[1]][p[2]] + happy_increase[p[2]][p[1]]
	summ += happy_increase[p[3]][p[4]] + happy_increase[p[4]][p[3]]
	summ += happy_increase[p[2]][p[3]] + happy_increase[p[3]][p[2]]
	summ += happy_increase[p[3]][p[4]] + happy_increase[p[4]][p[3]]
	if summ > ans:
		ans = summ
print(ans)


import collections, math, itertools, bisect, heapq, copy

class Solution:
	res = 0

	def solve(self):

		def findMax(arr):
			total = 0
			for i in range(5):
				for j in range(i, 4, 2):
					leftStud = arr[j]
					rightStud = arr[j + 1]
					total += A[leftStud - 1][rightStud - 1] + A[rightStud - 1][leftStud - 1]
			self.res = max(total, self.res)

		def generatePerm(arr):
			if len(arr) == 5:
				findMax(arr)
				return
			for i in range(1, 6):
				if chosen[i - 1]:
					continue
				chosen[i - 1] = True
				arr.append(i)
				generatePerm(arr)
				chosen[i - 1] = False
				arr.pop()
		chosen = [False for _ in range(5)]
		A = []
		for i in range(5):
			A.append(list(map(int, input().rstrip().split())))
		generatePerm([])
		print(self.res)
solution = Solution()
solution.solve()


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])


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)


matrix = []
for _ in range(5):
	matrix.append(list(map(int, input().split(' '))))

def compute_val(matrix, line):
	[one, two, three, four, five] = line
	first = matrix[one][two] + matrix[two][one] + matrix[three][four] + matrix[four][three]
	second = matrix[two][three] + matrix[three][two] + matrix[four][five] + matrix[five][four]
	third = matrix[three][four] + matrix[four][three]
	fourth = matrix[four][five] + matrix[five][four]
	return first + second + third + fourth

def backtrack(matrix, line):
	if len(line) == 5:
		res = compute_val(matrix, line)
		return res
	else:
		res = []
		for i in range(5):
			if i not in line:
				res.append(backtrack(matrix, line + [i]))
		return max(res)
print(backtrack(matrix, []))


mat = []
for i in range(5):
	mat.append([int(z) for z in input().split()])
m = 0
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):
					l = [a, b, c, d, e]
					if len(set(l)) == len(l):
						cnt = 0
						for i in range(5):
							for j in range(i, 4, 2):
								cnt += mat[l[j]][l[j + 1]]
								cnt += mat[l[j + 1]][l[j]]
						m = max(m, cnt)
print(m)


import random
import sys
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, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	arr = []
	for i in range(5):
		lis = L()
		arr.append(lis)
	perm = permutations([0, 1, 2, 3, 4])
	mx = 0
	val = 0
	for i in list(perm):
		lis = list(i)
		val = arr[lis[0]][lis[1]] + arr[lis[1]][lis[0]] + 2 * (arr[lis[2]][lis[3]] + arr[lis[3]][lis[2]]) + arr[lis[1]][lis[2]] + arr[lis[2]][lis[1]] + 2 * (arr[lis[3]][lis[4]] + arr[lis[4]][lis[3]])
		mx = max(mx, val)
	print(mx)
main()


import sys
from itertools import permutations

def Ni():
	return tuple(map(int, sys.stdin.readline().split()))

def Ns():
	return tuple(map(int, sys.stdin.readline().split()))
g = [Ni() for i in range(5)]
answer = 0
for p in permutations(range(5)):
	value = 0
	value += g[p[0]][p[1]] + g[p[2]][p[3]]
	value += g[p[1]][p[2]] + g[p[3]][p[4]]
	value += g[p[2]][p[3]]
	value += g[p[3]][p[4]]
	value += g[p[1]][p[0]] + g[p[3]][p[2]]
	value += g[p[2]][p[1]] + g[p[4]][p[3]]
	value += g[p[3]][p[2]]
	value += g[p[4]][p[3]]
	answer = max(answer, value)
print(answer)


def calculate(order):
	total = 0
	while len(order) > 1:
		for i in range(0, 3, 2):
			if i + 1 < len(order):
				total += arr[order[i] - 1][order[i + 1] - 1] + arr[order[i + 1] - 1][order[i] - 1]
		order.pop(0)
	return total
from itertools import permutations
arr = [[int(i) for i in input().split()] for j in range(5)]
l = [1, 2, 3, 4, 5]
m = 0
for permutation in permutations(l):
	c = calculate(list(permutation))
	if m < c:
		m = c
print(m)


__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()


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations

def solve():
	a = [list(map(int, input().split())) for i in range(5)]
	lis = list(permutations([1, 2, 3, 4, 5], 5))
	ans = 0
	for x in lis:
		val = a[x[0] - 1][x[1] - 1] + a[x[1] - 1][x[0] - 1] + a[x[2] - 1][x[3] - 1] + a[x[3] - 1][x[2] - 1] + a[x[1] - 1][x[2] - 1] + a[x[2] - 1][x[1] - 1] + a[x[3] - 1][x[4] - 1] + a[x[4] - 1][x[3] - 1] + a[x[2] - 1][x[3] - 1] + a[x[3] - 1][x[2] - 1] + a[x[3] - 1][x[4] - 1] + a[x[4] - 1][x[3] - 1]
		ans = max(val, ans)
	print(ans)
for _ in range(1):
	solve()


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)