Given a $6\times6$ 2D Array, $\textbf{arr}$: 

1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0

An hourglass in $\mbox{A}$ is a subset of values with indices falling in this pattern in $\textbf{arr}$'s graphical representation:

a b c
  d
e f g

There are $\mbox{16}$ hourglasses in $\textbf{arr}$. An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in $\textbf{arr}$, then print the maximum hourglass sum.  The array will always be $6\times6$.

Example  

$ar r=$

-9 -9 -9  1 1 1 
 0 -9  0  4 3 2
-9 -9 -9  1 2 3
 0  0  8  6 6 0
 0  0  0 -2 0 0
 0  0  1  2 4 0

The $\mbox{16}$ hourglass sums are:

-63, -34, -9, 12, 
-10,   0, 28, 23, 
-27, -11, -2, 10, 
  9,  17, 25, 18

The highest hourglass sum is $28$ from the hourglass beginning at row $1$, column $2$:

0 4 3
  1
8 6 6

Note: If you have already solved the Java domain's Java 2D Array challenge, you may wish to skip this challenge.

Function Description

Complete the function hourglassSum in the editor below.  

hourglassSum has the following parameter(s):

int arr[6][6]: an array of integers  

Returns  

int: the maximum hourglass sum

Input Format

Each of the $\boldsymbol{6}$ lines of inputs $arr\left[i\right]$ contains $\boldsymbol{6}$ space-separated integers $ar r[i][j]$.

Constraints

$-9\leq arr[i][j]\leq9$  
$0\leq i,j\leq5$

Output Format

Print the largest (maximum) hourglass sum found in $\textbf{arr}$.

Sample Input
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 2 4 4 0
0 0 0 2 0 0
0 0 1 2 4 0

Sample Output
19

Explanation

$\textbf{arr}$ contains the following hourglasses:

The hourglass with the maximum sum ($19$) is:

2 4 4
  2
1 2 4

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:

Solutions:
board = []
for i in range(6):
	board.append([int(x) for x in input().split()])
(i, j) = (0, 0)
m = sum([board[i][j], board[i][j + 1], board[i][j + 2], board[i + 1][j + 1], board[i + 2][j], board[i + 2][j + 1], board[i + 2][j + 2]])
for i in range(4):
	for j in range(4):
		acc = sum([board[i][j], board[i][j + 1], board[i][j + 2], board[i + 1][j + 1], board[i + 2][j], board[i + 2][j + 1], board[i + 2][j + 2]])
		m = max(m, acc)
print(m)


def read_input():
	arr = []
	for i in range(6):
		arr.append([int(x) for x in input().split()])
	return arr

def sum_hourglass(i, j, arr):
	cur_sum = 0
	cur_sum += sum(arr[i][j:j + 3])
	cur_sum += arr[i + 1][j + 1]
	cur_sum += sum(arr[i + 2][j:j + 3])
	return cur_sum
arr = read_input()
result_arr = [sum_hourglass(i, j, arr) for i in range(4) for j in range(4)]
print(max(result_arr))


__author__ = 'siddharth'
M = []
for _ in range(6):
	M.append(list(map(int, input().split())))
mask = ((0, 0), (0, 1), (0, 2), (1, 1), (2, 0), (2, 1), (2, 2))
T = -63
for r in range(4):
	for c in range(4):
		C = 0
		for m in mask:
			C += M[m[0] + r][m[1] + c]
		T = max(T, C)
print(T)


array = [list(map(int, input().split())) for _ in range(6)]

def hourglass(i, j):
	return sum((array[i + di][j + dj] for (di, dj) in ((0, 0), (0, 1), (0, 2), (1, 1), (2, 0), (2, 1), (2, 2))))
print(max((hourglass(i, j) for i in range(4) for j in range(4))))


__author__ = 'namii'

def calc_hourglass_sum(L, x, y):
	summa = L[x][y] + L[x][y + 1] + L[x][y + 2] + L[x + 1][y + 1] + L[x + 2][y] + L[x + 2][y + 1] + L[x + 2][y + 2]
	return summa
L = []
for i in range(6):
	L.append(list(map(int, input().split())))
print(max([calc_hourglass_sum(L, i, j) for i in range(4) for j in range(4)]))


arrayList = [input().split() for x in range(0, 6)]
intMatrix = [list(map(int, x)) for x in [list(x) for x in arrayList]]

def checkCoordinate(matrix, x, y):
	hourTop = matrix[y][x:x + 3]
	hourBottom = matrix[y + 2][x:x + 3]
	hourMiddle = matrix[y + 1][x + 1]
	hourglass = sum(hourTop) + hourMiddle + sum(hourBottom)
	return hourglass

def loopCoords(matrix):
	greatest = checkCoordinate(matrix, 0, 0)
	current = 0
	for i in range(4):
		for z in range(4):
			current = checkCoordinate(matrix, z, i)
			if current > greatest:
				greatest = current
			else:
				pass
	return greatest
print(loopCoords(intMatrix))


A = []
for _ in range(6):
	A.append(list(map(int, input().strip().split(' '))))
m = -100
for i in range(4):
	for j in range(4):
		val = A[i][j] + A[i][j + 1] + A[i][j + 2] + A[i + 1][j + 1] + A[i + 2][j] + A[i + 2][j + 1] + A[i + 2][j + 2]
		m = max(val, m)
print(m)


def sumHourglass(array, y, x):
	sum = array[y + 1][x + 1]
	for i in range(3):
		sum += array[y][x + i]
		sum += array[y + 2][x + i]
	return sum

def findMaxSum(array):
	n = len(array)
	largest = None
	for i in range(n):
		for j in range(n):
			l = i + 2
			w = j + 2
			if l >= n or w >= n:
				continue
			current = sumHourglass(array, i, j)
			if largest == None or current > largest:
				largest = current
	return largest
num_lines = 6
array = []
for i in range(num_lines):
	array.append([int(i) for i in input().split()])
result = findMaxSum(array)
print(result)


def gen_hourglasses(array=[]):
	start_of_hourglass_x = 0
	start_of_hourglass_y = 0
	while start_of_hourglass_x < len(array):
		hourglass = []
		try:
			hourglass.append(array[start_of_hourglass_x][start_of_hourglass_y])
			hourglass.append(array[start_of_hourglass_x][start_of_hourglass_y + 1])
			hourglass.append(array[start_of_hourglass_x][start_of_hourglass_y + 2])
			hourglass.append(array[start_of_hourglass_x + 1][start_of_hourglass_y + 1])
			hourglass.append(array[start_of_hourglass_x + 2][start_of_hourglass_y])
			hourglass.append(array[start_of_hourglass_x + 2][start_of_hourglass_y + 1])
			hourglass.append(array[start_of_hourglass_x + 2][start_of_hourglass_y + 2])
		except:
			start_of_hourglass_y += 1
			if start_of_hourglass_y >= len(array):
				start_of_hourglass_y = 0
				start_of_hourglass_x += 1
			yield None
			continue
		start_of_hourglass_y += 1
		if start_of_hourglass_y >= len(array):
			start_of_hourglass_y = 0
			start_of_hourglass_x += 1
		yield hourglass
arr = []
for _ in range(6):
	arr.append(list(map(int, input().split())))
MAX = -100
hourglasses = gen_hourglasses(arr)
for h in hourglasses:
	if h is None:
		continue
	MAX = max(sum(h), MAX)
print(MAX)


L = []
for _ in range(6):
	L.append(list(map(int, input().split())))
maxhg = None
sumhg = 0
for i in range(4):
	for j in range(4):
		if maxhg == None:
			maxhg = sum(L[i][j:j + 3]) + L[i + 1][j + 1] + sum(L[i + 2][j:j + 3])
		else:
			sumhg = sum(L[i][j:j + 3]) + L[i + 1][j + 1] + sum(L[i + 2][j:j + 3])
			if sumhg > maxhg:
				maxhg = sumhg
print(maxhg)


l = list()
l.append(input().split())
for x in range(len(l[0]) - 1):
	l.append(input().split())
for x in range(len(l)):
	l[x] = list(map(int, l[x]))
highestSum = float('-inf')
for y in range(len(l) - 2):
	for z in range(len(l) - 2):
		sum = l[y][z] + l[y][z + 1] + l[y][z + 2] + l[y + 1][z + 1] + l[y + 2][z] + l[y + 2][z + 1] + l[y + 2][z + 2]
		if sum > highestSum:
			highestSum = sum
print(highestSum)


def sum_hourglass(array, i, j):
	sum = 0
	sum += int(array[i][j]) + int(array[i][j + 1]) + int(array[i][j + 2]) + int(array[i + 1][j + 1]) + int(array[i + 2][j]) + int(array[i + 2][j + 1]) + int(array[i + 2][j + 2])
	return sum
array = []
for i in range(6):
	array.append(input().split())
max_sum = -100
for i in range(4):
	for j in range(4):
		sum = sum_hourglass(array, i, j)
		if sum > max_sum:
			max_sum = sum
print(max_sum)


def convert(x):
	res1 = []
	for i in range(len(x)):
		res1.append(int(x[i]))
	return res1

def cal_values(matrix):
	a0 = matrix[0]
	a1 = matrix[1]
	a2 = matrix[2]
	res3 = []
	for kk in range(4):
		temp1 = 0
		temp1 = sum(a0[kk:kk + 3])
		temp1 += a1[kk + 1]
		temp1 += sum(a2[kk:kk + 3])
		res3.append(temp1)
	return max(res3)
ss = []
result = []
for i in range(6):
	temp = input().split()
	res2 = convert(temp)
	ss.append(res2)
for j in range(4):
	ee = cal_values(ss[j:j + 3])
	result.append(ee)
print(max(result))


data = [[int(x) for x in input().strip().split(' ')] for _ in range(6)]
ng = [(-1, -1), (-1, 0), (-1, 1), (0, 0), (1, -1), (1, 0), (1, 1)]
print(max([sum([data[x + a][y + b] for (a, b) in ng]) for x in range(1, 5) for y in range(1, 5)]))


row0 = list(map(int, input().split(' ')))
row1 = list(map(int, input().split(' ')))
row2 = list(map(int, input().split(' ')))
row3 = list(map(int, input().split(' ')))
row4 = list(map(int, input().split(' ')))
row5 = list(map(int, input().split(' ')))
arr_2d = [row0, row1, row2, row3, row4, row5]
max_arr = []
for x in range(0, 4):
	for y in range(0, 4):
		total = 0
		total += arr_2d[x][y] + arr_2d[x][y + 1] + arr_2d[x][y + 2]
		total += arr_2d[x + 1][y + 1]
		total += arr_2d[x + 2][y] + arr_2d[x + 2][y + 1] + arr_2d[x + 2][y + 2]
		max_arr.append(total)
print(max(max_arr))


N = 6
Matrix = []
for i in range(N):
	Matrix.append(list(map(int, input().split())))
maxSum = -300
for i in range(1, 5):
	for j in range(1, 5):
		sum = Matrix[i][j] + Matrix[i - 1][j] + Matrix[i + 1][j]
		sum += Matrix[i - 1][j - 1] + Matrix[i - 1][j + 1]
		sum += Matrix[i + 1][j - 1] + Matrix[i + 1][j + 1]
		if sum > maxSum:
			maxSum = sum
print(maxSum)


import sys
data = []
for i in range(0, 6):
	line = sys.stdin.readline().split(' ')
	d = []
	for l in line:
		d.append(int(l))
	data.append(d)
largest = -10000000000000000000
for i in range(1, 5):
	for j in range(1, 5):
		s = 0
		s = data[i - 1][j - 1] + data[i - 1][j] + data[i - 1][j + 1] + data[i][j] + data[i + 1][j - 1] + data[i + 1][j] + data[i + 1][j + 1]
		if s > largest:
			largest = s
print(largest)


arr = []
for x in range(6):
	arr.insert(x, list(map(int, input().split())))
max = -99999999
center = []
for x in range(6):
	for y in range(6):
		if x == 0 or y == 0 or x == 5 or (y == 5):
			continue
		sum = arr[x][y] + arr[x - 1][y] + arr[x + 1][y] + arr[x - 1][y - 1] + arr[x - 1][y + 1] + arr[x + 1][y - 1] + arr[x + 1][y + 1]
		if sum > max:
			max = sum
print(max)


matrix = [[], [], [], [], [], []]
for i in range(6):
	matrix[i] = input().split()
	matrix[i] = [int(x) for x in matrix[i] if x != '']
max_sum = -9 * 7 + -1
for i in range(4):
	for j in range(4):
		sum = 0
		sum = matrix[i][j] + matrix[i][j + 1] + matrix[i][j + 2]
		sum += matrix[i + 1][j + 1]
		sum += matrix[i + 2][j] + matrix[i + 2][j + 1] + matrix[i + 2][j + 2]
		if sum > max_sum:
			max_sum = sum
			index = (i, j)
print(max_sum)


ints = []
for a in range(6):
	nums = input().split()
	ints.append(list())
	for b in range(6):
		ints[a].append(int(nums[b]))
max_sum = 0
for x in range(4):
	for y in range(4):
		s = sum(ints[x][y:y + 3]) + ints[x + 1][y + 1] + sum(ints[x + 2][y:y + 3])
		if x == 0 and y == 0:
			max_sum = s
		else:
			max_sum = max(max_sum, s)
print(max_sum)


import sys
import math

def calculateMax(matrix):
	maxSum = -float('inf')
	for i in range(4):
		for j in range(4):
			sum = int(matrix[i][j]) + int(matrix[i][j + 1]) + int(matrix[i][j + 2]) + int(matrix[i + 1][j + 1]) + int(matrix[i + 2][j]) + int(matrix[i + 2][j + 1]) + int(matrix[i + 2][j + 2])
			if sum > maxSum:
				maxSum = sum
	print(maxSum)

def main():
	input = sys.stdin.read().splitlines()
	matrix = []
	for i in input:
		list = i.split()
		matrix.append(list)
	calculateMax(matrix)
main()


from itertools import islice
n = []
matrix = []
HighestSum = -60
for test_input in range(0, 6):
	n.append(list(input().split('\n')))
for i in n:
	for x in i:
		if x:
			numbers = [int(z) for z in x.split()]
			matrix.append(numbers)
for (rowindex, rowvalue) in enumerate(islice(matrix, 1, 5)):
	for (columnindex, centrepoint) in enumerate(islice(rowvalue, 1, 5)):
		MatrixRowIndex = rowindex + 1
		MatrixColumn = columnindex + 1
		HourGlassSum = matrix[MatrixRowIndex][MatrixColumn] + matrix[MatrixRowIndex - 1][MatrixColumn - 1] + matrix[MatrixRowIndex - 1][MatrixColumn] + matrix[MatrixRowIndex - 1][MatrixColumn + 1] + matrix[MatrixRowIndex + 1][MatrixColumn - 1] + matrix[MatrixRowIndex + 1][MatrixColumn] + matrix[MatrixRowIndex + 1][MatrixColumn + 1]
		if HourGlassSum > HighestSum:
			HighestSum = HourGlassSum
print(HighestSum)


def hourglass(array, x, y):
	yield from array[x][y:y + 3]
	yield array[x + 1][y + 1]
	yield from array[x + 2][y:y + 3]

def list2dFromStdIn():
	return [[int(s) for s in input().strip().split(' ')] for i in range(6)]
array = list2dFromStdIn()
hourglasses = (hourglass(array, i, j) for i in range(len(array[0]) - 2) for j in range(len(array) - 2))
print(max((sum(glass) for glass in hourglasses)))


lst = []
res = []
for _ in range(6):
	lst.append([int(x) for x in input().split(' ')])
for i in range(4):
	for j in range(4):
		x = lst[i][j] + lst[i][j + 1] + lst[i][j + 2] + lst[i + 2][j] + lst[i + 2][j + 1] + lst[i + 2][j + 2] + lst[i + 1][j + 1]
		res.append(x)
print(max(res))


data = []
for i in range(6):
	t = input('').split(sep=' ')
	t = list(map(int, t))
	data.append(t)
hourglass_vals = []
k = 0
for i in range(4):
	for j in range(1, 5):
		hourglass_vals.append(data[i][j])
		hourglass_vals[k] += data[i][j - 1]
		hourglass_vals[k] += data[i][j + 1]
		hourglass_vals[k] += data[i + 1][j]
		hourglass_vals[k] += data[i + 2][j - 1]
		hourglass_vals[k] += data[i + 2][j]
		hourglass_vals[k] += data[i + 2][j + 1]
		k += 1
print(max(hourglass_vals))


arr = []
hg_sums = []
for i in range(6):
	arr.append([int(x) for x in input().replace('\r', '').split()])
for i in range(1, 5):
	for j in range(1, 5):
		local_sum = arr[j - 1][i] + arr[j - 1][i - 1] + arr[j - 1][i + 1]
		local_sum += arr[j + 1][i] + arr[j + 1][i - 1] + arr[j + 1][i + 1]
		local_sum += arr[j][i]
		hg_sums.append(local_sum)
print(max(hg_sums))


w = h = 6
data = []
for i in range(h):
	data.append(list(map(int, input().split()[:w])))
print(max((sum(data[i][j:j + 3]) + data[i + 1][j + 1] + sum(data[i + 2][j:j + 3]) for i in range(h - 2) for j in range(w - 2))))


tri_elem_sum_list = []
mid_elem_list = []
for row in range(6):
	input_row = input()
	input_row = input_row.split()
	input_row = list(map(int, input_row))
	tri_elem_row = []
	for col in range(4):
		left = input_row[col]
		center = input_row[col + 1]
		right = input_row[col + 2]
		tri_elem_row.append(left + center + right)
	tri_elem_sum_list.append(tri_elem_row)
	if row is not 0 and row is not 5:
		indexes = [1, 2, 3, 4]
		mid_elem_row = [input_row[i] for i in indexes]
		mid_elem_list.append(mid_elem_row)
largest_sum = None
for row in range(4):
	for col in range(4):
		hourglass_sum = tri_elem_sum_list[row][col] + tri_elem_sum_list[row + 2][col] + mid_elem_list[row][col]
		if largest_sum is None:
			largest_sum = hourglass_sum
		else:
			largest_sum = hourglass_sum if hourglass_sum > largest_sum else largest_sum
print(largest_sum)


def readInput():
	m = []
	for _ in range(6):
		nums = input().split(' ')
		for i in range(len(nums)):
			nums[i] = int(nums[i])
		m.append(nums)
	return m

def sumHourglass(m, x, y):
	return m[x][y] + m[x][y + 1] + m[x][y + 2] + m[x + 1][y + 1] + m[x + 2][y] + m[x + 2][y + 1] + m[x + 2][y + 2]

def findMaxSum(m):
	max = -9 * 7
	for i in range(4):
		for j in range(4):
			sum = sumHourglass(m, i, j)
			if sum > max:
				max = sum
	return max
print(findMaxSum(readInput()))


table = [[] for y in range(0, 6)]
for k in range(0, 6):
	for x in input().split():
		table[k].append(int(x))
s = -9 * 7
for x in range(1, 5):
	for y in range(1, 5):
		z = table[x - 1][y - 1] + table[x - 1][y] + table[x - 1][y + 1] + table[x][y] + table[x + 1][y - 1] + table[x + 1][y] + table[x + 1][y + 1]
		s = max(s, z)
print(s)


import sys
arr = []
for line in sys.stdin.readlines():
	numberString = line.split(' ')
	numbers = []
	for number in numberString:
		numbers += [int(number)]
	arr += [numbers]
maxHourglass = None
for i in range(0, 4):
	for j in range(0, 4):
		hourglassValue = arr[j][i] + arr[j][i + 1] + arr[j][i + 2] + arr[j + 1][i + 1]
		hourglassValue += arr[j + 2][i] + arr[j + 2][i + 1] + arr[j + 2][i + 2]
		if maxHourglass == None:
			maxHourglass = hourglassValue
		elif hourglassValue > maxHourglass:
			maxHourglass = hourglassValue
print(maxHourglass)


import sys
arr = [list(map(int, row.strip().split(' '))) for row in sys.stdin.readlines()]
sums = [sum(arr[r][c:c + 3]) + arr[r + 1][c + 1] + sum(arr[r + 2][c:c + 3]) for r in range(0, len(arr) - 2) for c in range(0, len(arr) - 2)]
print(max(sums))


import fileinput
import sys
twoDimMat = []
row = []
for line in fileinput.input():
	formattedLine = list(map(int, line.split(' ')))
	twoDimMat.append(formattedLine)
currSum = 0
for i in range(0, 4):
	for j in range(0, 4):
		if i == 0 and j == 0:
			maxSum = twoDimMat[i][j] + twoDimMat[i][j + 1] + twoDimMat[i][j + 2] + twoDimMat[i + 1][j + 1] + twoDimMat[i + 2][j] + twoDimMat[i + 2][j + 1] + twoDimMat[i + 2][j + 2]
		currSum = twoDimMat[i][j] + twoDimMat[i][j + 1] + twoDimMat[i][j + 2] + twoDimMat[i + 1][j + 1] + twoDimMat[i + 2][j] + twoDimMat[i + 2][j + 1] + twoDimMat[i + 2][j + 2]
		if currSum > maxSum:
			maxSum = currSum
print(maxSum)


arr = []
chk = [((-1, -1), (1, -1)), ((1, -1), (1, 1))]
comp = [(-1, -1), (-1, 0), (1, -1), (0, 0), (-1, 1), (1, 0), (1, 1)]
for l in range(6):
	arr.append(list(map(int, input().strip().split(' '))))
mx = -99999999999999999999
for x in range(1, 5):
	for y in range(1, 5):
		mx = max(mx, sum(list(map(lambda i: arr[x + i[0]][y + i[1]], comp))))
print(mx)


def hourg(arr, i, j):
	s = arr[i][j] + arr[i][j + 1] + arr[i][j + 2]
	s += arr[i + 1][j + 1]
	s += arr[i + 2][j] + arr[i + 2][j + 1] + arr[i + 2][j + 2]
	return s
arr = []
for i in range(0, 6):
	a = [int(s) for s in input().split()]
	arr.append(a)
m = -64
for i in range(0, 4):
	for j in range(0, 4):
		h = hourg(arr, i, j)
		if h > m:
			m = h
print(m)


arr = []
for _ in range(6):
	arr.append([int(x) for x in input().split()])
curr = -10000
for i in range(4):
	for j in range(4):
		total = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j] + arr[i + 2][j + 1] + arr[i + 2][j + 2]
		curr = max(curr, total)
print(curr)


grid = [[int(i) for i in input().split()] for _ in range(6)]
res = []
for i in range(4):
	for j in range(4):
		m = sum(grid[i][j:j + 3]) + grid[i + 1][j + 1] + sum(grid[i + 2][j:j + 3])
		res.append(m)
print(max(res))


import sys
A = []
for line in sys.stdin:
	nums = line.split(' ')
	A.append([int(num) for num in nums])
best = -sys.maxsize
for i in range(len(A) - 2):
	for j in range(len(A) - 2):
		now = A[i][j] + A[i][j + 1] + A[i][j + 2] + A[i + 1][j + 1] + A[i + 2][j] + A[i + 2][j + 1] + A[i + 2][j + 2]
		if now > best:
			best = now
print(best)


arr = []
finalSum = -100
for i in range(0, 6):
	row = input().split()
	row = list(map(int, row))
	arr.append(row)
for i in range(0, 4):
	for j in range(0, 4):
		tempSum = sum((arr[i][j], arr[i][j + 1], arr[i][j + 2], arr[i + 1][j + 1], arr[i + 2][j], arr[i + 2][j + 1], arr[i + 2][j + 2]))
		if finalSum < tempSum:
			finalSum = tempSum
print(finalSum)


cases = 6
l = [[], [], [], [], [], []]
while cases:
	l[6 - cases] = list(map(int, input().split()))
	cases -= 1
i = 1
max_i = 4
max_j = 4
max_sum = -99999
while i <= max_i:
	j = 1
	while j <= max_j:
		sum = l[i][j] + l[i - 1][j - 1] + l[i - 1][j] + l[i - 1][j + 1] + l[i + 1][j] + l[i + 1][j - 1] + l[i + 1][j + 1]
		if sum > max_sum:
			max_sum = sum
		j += 1
	i += 1
print(max_sum)


matrix = []
for i in range(6):
	row = [int(element) for element in input().split()]
	matrix.append(row)
max = -100
for i in range(4):
	for j in range(4):
		a = matrix[i][j]
		b = matrix[i][j + 1]
		c = matrix[i][j + 2]
		d = matrix[i + 1][j + 1]
		e = matrix[i + 2][j]
		f = matrix[i + 2][j + 1]
		g = matrix[i + 2][j + 2]
		sum = a + b + c + d + e + f + g
		if sum > max:
			max = sum
print(max)


line1 = list(map(int, input().split()))
line2 = list(map(int, input().split()))
line3 = list(map(int, input().split()))
line4 = list(map(int, input().split()))
line5 = list(map(int, input().split()))
line6 = list(map(int, input().split()))
lines = [line1, line2, line3, line4, line5, line6]
largestValue = None
for x in range(4):
	for y in range(4):
		value = sum(lines[y][x:x + 3]) + lines[y + 1][x + 1] + sum(lines[y + 2][x:x + 3])
		if largestValue is None:
			largestValue = value
		elif value > largestValue:
			largestValue = value
print(largestValue)


row_1 = [int(x) for x in input().split(' ')]
row_2 = [int(x) for x in input().split(' ')]
row_3 = [int(x) for x in input().split(' ')]
row_4 = [int(x) for x in input().split(' ')]
row_5 = [int(x) for x in input().split(' ')]
row_6 = [int(x) for x in input().split(' ')]
matrix = [row_1, row_2, row_3, row_4, row_5, row_6]
max_sum = -9999
for i in range(4):
	for j in range(4):
		hourglass_sum = sum(matrix[i][j:j + 3]) + matrix[i + 1][j + 1] + sum(matrix[i + 2][j:j + 3])
		if hourglass_sum > max_sum:
			max_sum = hourglass_sum
print(max_sum)


matrix = []
start_x = 0
start_y = 0

def calcSum(array, x, y):
	top = int(array[y - 1][x - 1]) + int(array[y - 1][x]) + int(array[y - 1][x + 1])
	middle = int(array[y][x])
	bottom = int(array[y + 1][x - 1]) + int(array[y + 1][x]) + int(array[y + 1][x + 1])
	return top + middle + bottom
for i in range(0, 6):
	matrix.append(input().split())
max_sum = calcSum(matrix, 3, 3)
for x in range(1, 5):
	for y in range(1, 5):
		cur_sum = calcSum(matrix, x, y)
		if max_sum < cur_sum:
			max_sum = cur_sum
print(max_sum)


inputs = []
for _ in range(6):
	inputs.append([int(x) for x in input().split()])
max_sum = float('-inf')
for row in range(1, 5):
	for col in range(1, 5):
		sum = inputs[row - 1][col - 1] + inputs[row - 1][col] + inputs[row - 1][col + 1] + inputs[row][col] + inputs[row + 1][col - 1] + inputs[row + 1][col] + inputs[row + 1][col + 1]
		max_sum = sum if sum > max_sum else max_sum
print(max_sum)


def get_hourglass_sum(arr, start_x, start_y):
	total = 0
	for i in range(3):
		total += arr[start_y][start_x + i]
		total += arr[start_y + 2][start_x + i]
	total += arr[start_y + 1][start_x + 1]
	return total
arr = []
N = 6
for i in range(N):
	row = list(map(lambda x: int(x), input().split()))
	arr.append(row)
max_sum = -63
for i in range(N - 2):
	for j in range(N - 2):
		curr_sum = get_hourglass_sum(arr, i, j)
		if curr_sum > max_sum:
			max_sum = curr_sum
print(max_sum)


m = []
for i in range(6):
	m.append([int(j) for j in input().strip().split()])

def h_sum(m, i, j):
	return sum(m[i - 1][j - 1:j + 2]) + m[i][j] + sum(m[i + 1][j - 1:j + 2])
max_sum = None
for i in range(1, 5):
	for j in range(1, 5):
		s = h_sum(m, i, j)
		if max_sum is None or s > max_sum:
			max_sum = s
print(max_sum)


a = []
for i in range(6):
	a.append([int(x) for x in input().split(' ')])
s = -float('inf')
for i in range(4):
	for j in range(4):
		sh = sum(a[i][j:j + 3]) + a[i + 1][j + 1] + sum(a[i + 2][j:j + 3])
		if sh > s:
			s = sh
print(s)


v = []
for i in range(0, 6):
	v.append([int(x) for x in input().split()])
m = -10000
for i in range(0, 4):
	for j in range(0, 4):
		s = v[i + 0][j + 0] + v[i + 0][j + 1] + v[i + 0][j + 2] + v[i + 1][j + 1] + v[i + 2][j + 0] + v[i + 2][j + 1] + v[i + 2][j + 2]
		m = max(m, s)
print(str(m))


board = []
for i in range(6):
	board.append([int(x) for x in input().split()])
(i, j) = (0, 0)
m = sum([board[i][j], board[i][j + 1], board[i][j + 2], board[i + 1][j + 1], board[i + 2][j], board[i + 2][j + 1], board[i + 2][j + 2]])
for i in range(4):
	for j in range(4):
		acc = sum([board[i][j], board[i][j + 1], board[i][j + 2], board[i + 1][j + 1], board[i + 2][j], board[i + 2][j + 1], board[i + 2][j + 2]])
		m = max(m, acc)
print(m)


import sys
COL_NUMBER = 6
ROW_NUMBER = 6
MATRIX = [[int(elt) for elt in input().split()] for row in range(6)]

def get_hourglass_value(row, col):
	res = MATRIX[row][col - 1]
	res += MATRIX[row][col]
	res += MATRIX[row][col + 1]
	res += MATRIX[row + 1][col]
	res += MATRIX[row + 2][col - 1]
	res += MATRIX[row + 2][col]
	res += MATRIX[row + 2][col + 1]
	return res
biggest_hourglass_value = -sys.maxsize - 1
for row in range(ROW_NUMBER - 2):
	for col in range(1, COL_NUMBER - 1):
		biggest_hourglass_value = max(biggest_hourglass_value, get_hourglass_value(row, col))
print(str(biggest_hourglass_value))


l = []
for i in range(6):
	l.append(list(map(int, input().split())))
m = -100
for i in range(1, 5):
	for j in range(1, 5):
		test = sum(l[j - 1][i - 1:i + 2]) + l[j][i] + sum(l[j + 1][i - 1:i + 2])
		if test > m:
			m = test
print(m)


mat = []
for i in range(6):
	mat.append(list(map(int, input().split())))
m = -100
for i in range(1, 5):
	for j in range(1, 5):
		s = mat[i][j] + mat[i - 1][j] + mat[i + 1][j] + mat[i + 1][j - 1] + mat[i + 1][j + 1] + mat[i - 1][j - 1] + mat[i - 1][j + 1]
		m = max(s, m)
print(m)


array_size = 6
a = []
for _ in range(array_size):
	a.append([int(i) for i in input().split()])
hour_glass_sums = []
for x in range(array_size - 2):
	for y in range(array_size - 2):
		hour_glass_sums.append(sum([a[y][x], a[y][x + 1], a[y][x + 2], a[y + 1][x + 1], a[y + 2][x], a[y + 2][x + 1], a[y + 2][x + 2]]))
print(max(hour_glass_sums))


n = 6
m = []
for i in range(n):
	m.append(list(map(int, input().split()[:n])))

def sum_glass(m, i, j):
	return sum(m[i][j:j + 3]) + m[i + 1][j + 1] + sum(m[i + 2][j:j + 3])
best = float('-inf')
for i in range(4):
	for j in range(4):
		s = sum_glass(m, i, j)
		if s > best:
			best = s
print(best)


hour_glass = [[0, 0], [0, 1], [0, 2], [1, 1], [2, 0], [2, 1], [2, 2]]

def extract_hourglass_at_index(offset_top, offset_left, array):
	try:
		values = []
		for h in hour_glass:
			new_top = h[0] + offset_top
			new_left = h[1] + offset_left
			values.append(int(array[new_top][new_left]))
		return sum(values)
	except Exception:
		return None

def get_input_arr():
	arr = []
	for i in range(0, 6):
		arr.append(input().split(' '))
	return arr
t = get_input_arr()
m = None
for top in range(0, 4):
	for left in range(0, 4):
		if m is None or extract_hourglass_at_index(top, left, t) > m:
			m = extract_hourglass_at_index(top, left, t)
if m is not None:
	print(m)


SIZE = 6
HOURGLASS_WIDTH = 3
HOURGLASS_HEIGHT = 3

def load_array():
	array = list()
	for _ in range(SIZE):
		line = list(map(int, input().split()))
		array.append(line)
	return array

def calculate_hourglass_sum(array, left_upper_row_index, left_upper_column_index):
	hourglass_sum = array[left_upper_row_index][left_upper_column_index] + array[left_upper_row_index][left_upper_column_index + 1] + array[left_upper_row_index][left_upper_column_index + 2] + array[left_upper_row_index + 1][left_upper_column_index + 1] + array[left_upper_row_index + 2][left_upper_column_index] + array[left_upper_row_index + 2][left_upper_column_index + 1] + array[left_upper_row_index + 2][left_upper_column_index + 2]
	return hourglass_sum

def max_hourglass_sum(array):
	max_sum = -float('inf')
	for i in range(SIZE + 1 - HOURGLASS_HEIGHT):
		for j in range(SIZE + 1 - HOURGLASS_WIDTH):
			hourglass_sum = calculate_hourglass_sum(array, i, j)
			if hourglass_sum > max_sum:
				max_sum = hourglass_sum
	return max_sum
array = load_array()
print(max_hourglass_sum(array))


A = [list(map(int, input().split())) for _ in range(6)]
m = -2 ** 63
for i in range(4):
	for j in range(4):
		s = sum((sum(A[i + k][j:j + 3]) for k in (0, 1, 2)))
		s -= A[i + 1][j]
		s -= A[i + 1][j + 2]
		m = max(m, s)
print(m)


grid = []
for i in range(6):
	grid.append([int(x) for x in input().split()])
totallist = []
for i in range(0, 4):
	for j in range(0, 4):
		total = 0
		array = [grid[i][j], grid[i][j + 1], grid[i][j + 2], grid[i + 1][j + 1], grid[i + 2][j], grid[i + 2][j + 1], grid[i + 2][j + 2]]
		for k in array:
			total = total + k
		totallist.append(total)
print(max(totallist))


def getArray():
	returnArray = []
	for i in range(0, 6):
		returnArray.append(input().split())
	return returnArray
mainArray = getArray()
maxSum = 0

def getSumOfHG(rowIndex, columnIndex):
	tempSum = 0
	tempSum += int(mainArray[rowIndex][columnIndex])
	tempSum += int(mainArray[rowIndex][columnIndex + 1])
	tempSum += int(mainArray[rowIndex][columnIndex + 2])
	tempSum += int(mainArray[rowIndex + 1][columnIndex + 1])
	tempSum += int(mainArray[rowIndex + 2][columnIndex])
	tempSum += int(mainArray[rowIndex + 2][columnIndex + 1])
	tempSum += int(mainArray[rowIndex + 2][columnIndex + 2])
	return tempSum
for i in range(0, 4):
	for j in range(0, 4):
		sumOfHg = getSumOfHG(i, j)
		if i == 0 and j == 0:
			maxSum = sumOfHg
		if maxSum < sumOfHg:
			maxSum = sumOfHg
print(maxSum)


A = [[int(i) for i in input().split()] for _ in range(6)]
smax = -9 * 7
for i in range(4):
	for j in range(4):
		t = sum(A[i][j:j + 3]) + A[i + 1][j + 1] + sum(A[i + 2][j:j + 3])
		if t > smax:
			smax = t
print(smax)


def hourglass(i, j):
	return m[i][j] + m[i][j + 1] + m[i][j + 2] + m[i + 1][j + 1] + m[i + 2][j] + m[i + 2][j + 1] + m[i + 2][j + 2]
n = 6
m = [[int(x) for x in input().split()] for _ in range(n)]
r = [hourglass(i, j) for i in range(n - 2) for j in range(n - 2)]
print(max(r))


__author__ = 'vaibhavgupta.v'
import sys
mat = 6
arr = [[0 for x in range(mat)] for x in range(mat)]
for i in range(mat):
	arr[i] = [int(x) for x in input().split()]

def possible(i, j):
	if j - 1 >= 0 and j + 1 < mat and (i >= 0) and (i + 2 < mat):
		return True
	else:
		return False

def hourGlassSum(i, j):
	return arr[i][j - 1] + arr[i][j] + arr[i][j + 1] + arr[i + 1][j] + arr[i + 2][j - 1] + arr[i + 2][j] + arr[i + 2][j + 1]
maximum = -100000
for i in range(mat):
	for j in range(mat):
		if possible(i, j):
			sum = hourGlassSum(i, j)
			if maximum < sum:
				maximum = sum
print(maximum)


hour_glass = [[0, 0], [0, 1], [0, 2], [1, 1], [2, 0], [2, 1], [2, 2]]

def extract_hourglass_at_index(offset_top, offset_left, array):
	try:
		values = []
		for h in hour_glass:
			new_top = h[0] + offset_top
			new_left = h[1] + offset_left
			values.append(int(array[new_top][new_left]))
		return sum(values)
	except Exception:
		return None

def get_input_arr():
	arr = []
	for i in range(0, 6):
		arr.append(input().split(' '))
	return arr
t = get_input_arr()
m = None
for top in range(0, 4):
	for left in range(0, 4):
		if m is None or extract_hourglass_at_index(top, left, t) > m:
			m = extract_hourglass_at_index(top, left, t)
if m is not None:
	print(m)


start = [[0, 0], [0, 1], [0, 2], [1, 1], [2, 0], [2, 1], [2, 2]]

def update_start(row, col, grid, sums, start):
	new_start = []
	if row + 3 == len(grid) and col + 3 == len(grid[0]):
		print(max(sums))
	elif col < len(grid[0]) - 3:
		for a in start:
			new_start.append([a[0], a[1] + 1])
		return new_start
	elif row < len(grid) - 3:
		y = [0, 1, 2, 1, 0, 1, 2]
		for (i, a) in enumerate(start):
			new_start.append([a[0] + 1, y[i]])
		return new_start
grid = []
for i in range(6):
	grid.append([int(a) for a in input().split()])
rows = len(grid) - 2
cols = len(grid[0]) - 2
sums = []
for row in range(rows):
	for col in range(cols):
		sum_i = []
		for idx in start:
			sum_i.append(grid[idx[0]][idx[1]])
		sums.append(sum(sum_i))
		this = update_start(row, col, grid, sums, start)
		start = this


lines = [[int(x) for x in input().split()] for _ in range(6)]
max_sum = -1000000
for i in range(4):
	for j in range(4):
		current_sum = sum(lines[i][j:j + 3]) + sum(lines[i + 2][j:j + 3]) + lines[i + 1][j + 1]
		max_sum = max(max_sum, current_sum)
print(max_sum)


l = 6
grid = []
for i in range(l):
	grid.append(list(map(int, input().strip().split())))
s = list()
for i in range(l // 2 + 1):
	for j in range(l // 2 + 1):
		s.append(sum(grid[i][j:j + 3]) + grid[i + 1][j + 1] + sum(grid[i + 2][j:j + 3]))
print(max(s))


def sum(X, midx, midy):
	theSum = X[midx][midy]
	theSum += X[midx - 1][midy - 1] + X[midx - 1][midy] + X[midx - 1][midy + 1]
	theSum += X[midx + 1][midy - 1] + X[midx + 1][midy] + X[midx + 1][midy + 1]
	return theSum

def getInput():
	lines = []
	for _ in range(6):
		strLine = input()
		aLine = strLine.rsplit()
		line = [int(x) for x in aLine]
		lines.append(line)
	return lines

def getLargestSum():
	linesH = getInput()
	maxH = -70
	for locX in range(1, 5):
		for locY in range(1, 5):
			currentSum = sum(linesH, locX, locY)
			if currentSum > maxH:
				maxH = currentSum
	print(maxH)
getLargestSum()


import sys
all_arr = [input().split(' ') for i in range(6)]
all_arr = [[int(j) for j in i] for i in all_arr]
highest_total = -100000000000
for i in range(4):
	for j in range(4):
		total = all_arr[i][j] + all_arr[i][j + 1] + all_arr[i][j + 2] + all_arr[i + 1][j + 1] + all_arr[i + 2][j] + all_arr[i + 2][j + 1] + all_arr[i + 2][j + 2]
		highest_total = max(highest_total, total)
print(highest_total)


L = []
for i in range(6):
	L.append(input().strip().split())
temp = -9 * 7
for i in range(4):
	for j in range(4):
		s = int(L[i][j]) + int(L[i][j + 1]) + int(L[i][j + 2]) + int(L[i + 1][j + 1]) + int(L[i + 2][j]) + int(L[i + 2][j + 1]) + int(L[i + 2][j + 2])
		if s > temp:
			temp = s
print(temp)


matrix = [[int(x) for x in input().split()] for _ in range(6)]
maxSum = None
for i in range(4):
	for j in range(4):
		tempSum = matrix[i][j] + matrix[i][j + 1] + matrix[i][j + 2] + matrix[i + 1][j + 1] + matrix[i + 2][j] + matrix[i + 2][j + 1] + matrix[i + 2][j + 2]
		if maxSum == None or maxSum < tempSum:
			maxSum = tempSum
print(maxSum)


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

def get_hg(x, y):
	hg = []
	xend = x + 3
	for i in range(y, y + 3):
		if i == y + 1:
			hg.append([0, ar[i][x + 1], 0])
		else:
			hg.append(ar[i][x:xend])
	return hg
hg = []
for x in range(3 + 1):
	for y in range(3 + 1):
		hg.append(get_hg(x, y))
hgsums = []
for h in hg:
	s = 0
	for j in h:
		s += sum(j)
	hgsums.append(s)
print(max(hgsums))


class Solution:

	def __init__(self, rows, columns):
		self.rows = rows
		self.columns = columns
		self.biggest_sum = None
		self.array = None

	@staticmethod
	def load_row():
		return [int(number) for number in input().split(' ')]

	def load_2d_array(self, rows, columns):
		return [self.load_row() for _ in range(rows)]

	def compute_hourglass_for_coordinates(self, x, y):
		hourglass_sum = self.array[y - 1][x - 1]
		hourglass_sum += self.array[y - 1][x]
		hourglass_sum += self.array[y - 1][x + 1]
		hourglass_sum += self.array[y][x]
		hourglass_sum += self.array[y + 1][x - 1]
		hourglass_sum += self.array[y + 1][x]
		hourglass_sum += self.array[y + 1][x + 1]
		return hourglass_sum

	def coordinates_are_valid_for_hourglass(self, x, y):
		if 0 < x < self.columns - 1:
			if 0 < y < self.rows - 1:
				return True
		return False

	def compare_sum_and_save_it(self, candidate_sum):
		if self.biggest_sum is None or self.biggest_sum < candidate_sum:
			self.biggest_sum = candidate_sum

	def find_biggest_sum(self):
		for y in range(self.rows):
			for x in range(self.columns):
				if self.coordinates_are_valid_for_hourglass(x, y):
					self.compare_sum_and_save_it(self.compute_hourglass_for_coordinates(x, y))

	def print_solution(self):
		print(self.biggest_sum)

	def solve(self):
		self.array = self.load_2d_array(self.rows, self.columns)
		self.find_biggest_sum()
		self.print_solution()

	def print_array(self):
		for row in self.array:
			self.print_row(row)

	@staticmethod
	def print_row(row):
		print(row)
solution = Solution(6, 6)
solution.solve()


def findGlassSum(A, B):
	if isWithinIndex(A, B):
		sum = array[A][B] + array[A][B + 1] + array[A][B + 2] + array[A + 1][B + 1] + array[A + 2][B] + array[A + 2][B + 1] + array[A + 2][B + 2]
		return sum
	return -999999

def isWithinIndex(A, B):
	if 6 - A < 3:
		return False
	if 6 - B < 3:
		return False
	return True
array = []
sum1 = -9999999
for i in range(0, 6):
	array.append([int(i) for i in input().split(' ')])
for i in range(0, 6):
	for j in range(0, 6):
		result = findGlassSum(i, j)
		sum1 = max(sum1, result)
print(sum1)


line1 = input()
line2 = input()
line3 = input()
line4 = input()
line5 = input()
line6 = input()
input_array = [line1, line2, line3, line4, line5, line6]
int_list = []
for line in input_array:
	line = line.split(' ')
	for number in line:
		int_list.append(int(number))
array_dimensions = 6

def get_hourglass_sum(start_pos):
	hourglass_sum = int_list[start_pos] + int_list[start_pos + 1] + int_list[start_pos + 2] + int_list[start_pos + array_dimensions + 1] + int_list[start_pos + array_dimensions * 2] + int_list[start_pos + array_dimensions * 2 + 1] + int_list[start_pos + array_dimensions * 2 + 2]
	return hourglass_sum
hourglass_sum = []
for i in range(0, 4):
	for k in range(0, 4):
		hourglass_sum.append(get_hourglass_sum(i * 6 + k))
print(max(hourglass_sum))


import sys

def hourPrint(ar):
	print(' '.join(map(str, ar[0:3])))
	print('  {0}  '.format(ar[4]))
	print(' '.join(map(str, ar[6:9])))

def getHours(ar):
	maxHour = -sys.maxsize - 1
	for i in range(0, len(ar) - 2):
		for j in range(0, len(ar[0]) - 2):
			hg = [x[j:j + 3] for x in ar[i:i + 3]]
			hg[1][0] = 0
			hg[1][2] = 0
			flat = [v for ls in hg for v in ls]
			s = sum(flat)
			if s > maxHour:
				maxHour = s
	return maxHour
n = 6
ar = []
for i in range(0, n):
	inp = [int(x) for x in input().strip().split(' ')]
	ar.append(inp)
hg = getHours(ar)
print(hg)


myArray = []
for i in range(6):
	myArray += [int(x) for x in input().strip().split(' ')]
greatestSum = None
for i in range(len(myArray)):
	if i % 6 < 4 and i < 23:
		newSum = sum(myArray[i:i + 3]) + myArray[i + 7] + sum(myArray[i + 12:i + 15])
		if greatestSum is None or newSum > greatestSum:
			greatestSum = newSum
print(str(greatestSum))


a = []
for a_i in range(6):
	a_t = [float(a_temp) for a_temp in input().strip().split(' ')]
	a.append(a_t)
high = -9 * 7 + 1
indexI = 0
indexJ = 0
for i in range(1, len(a) - 1):
	for j in range(1, len(a) - 1):
		sums = sum(a[i - 1][j - 1:j + 2]) + sum(a[i + 1][j - 1:j + 2]) + a[i][j]
		if sums > high:
			indexI = i
			indexJ = j
			high = sums
print(int(high))


import sys
matrix = []
for line in sys.stdin:
	matrix.append([int(n) for n in line.split()])
max_sum = -30
for y in range(0, len(matrix) - 2):
	for x in range(0, len(matrix[y]) - 2):
		hr_sum = matrix[y][x] + matrix[y][x + 1] + matrix[y][x + 2]
		hr_sum += matrix[y + 1][x + 1]
		hr_sum += matrix[y + 2][x] + matrix[y + 2][x + 1] + matrix[y + 2][x + 2]
		if hr_sum > max_sum:
			max_sum = hr_sum
print(str(max_sum))


array = []
for _ in range(6):
	array.append(list(map(int, input().split())))
max_sum = float('-inf')
for j in range(1, 5):
	for i in range(1, 5):
		sum_ = sum(array[j - 1][i - 1:i + 2]) + array[j][i] + sum(array[j + 1][i - 1:i + 2])
		if sum_ > max_sum:
			max_sum = sum_
print(max_sum)


N = 6
mat = list()
center16 = list()
for i in range(N):
	string = input()
	line = [int(char) for char in string.split()]
	mat.append(line)
	center16.append(line[1:N - 1])
center16 = center16[1:N - 1]
sumsOfThree = [[sum(line[i:i + 3]) for i in range(N - 2)] for line in mat]
for i in range(N - 2):
	for j in range(N - 2):
		center16[j][i] += sumsOfThree[j][i] + sumsOfThree[j + 2][i]
print(max([max(line) for line in center16]))


lines = []
maxm = -9 * 7
for r in range(6):
	lines.append([int(k) for k in input().split(' ')])
	if r >= 2:
		for i in range(4):
			sumall = sum(lines[r][i:i + 3])
			sumall += lines[r - 1][i + 1]
			sumall += sum(lines[r - 2][i:i + 3])
			maxm = sumall if sumall > maxm else maxm
print(maxm)


mat = []
for i in range(6):
	mat.append([int(x) for x in input().split()])
totals = []
tmp = 0
for i in range(4):
	for x in range(4):
		tmp = sum((mat[i + k][x + z] for k in range(3) for z in range(3) if not (k == 1 and z != 1)))
		totals.append(tmp)
print(max(totals))


def hourglass(arr, s, t):
	sum = 0
	sum += arr[s][t] + arr[s][t + 1] + arr[s][t + 2]
	sum += arr[s + 2][t] + arr[s + 2][t + 1] + arr[s + 2][t + 2]
	sum += arr[s + 1][t + 1]
	return sum
arr = []
for i in range(0, 6):
	x = input().split()
	x = [int(y) for y in x]
	arr.append(x)
max = -70
for i in range(0, 4):
	for j in range(0, 4):
		temp = hourglass(arr, i, j)
		if max < temp:
			max = temp
print(max)


mat = []
for i in range(6):
	nums = list(map(int, input().strip().split()))
	mat.append(nums)

def checkHG(mat, x, y):
	res = 0
	res += sum(mat[x][y:y + 3])
	res += mat[x + 1][y + 1]
	res += sum(mat[x + 2][y:y + 3])
	return res
maxHG = float('-inf')
for x in range(4):
	for y in range(4):
		maxHG = max(maxHG, checkHG(mat, x, y))
print(maxHG)


a = []
for a_i in range(6):
	a_t = [int(a_temp) for a_temp in input().strip().split(' ')]
	a.append(a_t)
sums = []
for i in range(4):
	for j in range(4):
		sums.append(a[i][j] + a[i][j + 1] + a[i][j + 2] + a[i + 1][j + 1] + a[i + 2][j] + a[i + 2][j + 1] + a[i + 2][j + 2])
print(max(sums))


import sys
m = []
for i in range(6):
	m.append([int(x) for x in input().split()])
maxhour = [-10, -10, -10, -10, -10, -10, -10]
for row in range(4):
	for col in range(4):
		suma = m[row][col] + m[row][col + 1] + m[row][col + 2] + m[row + 1][col + 1] + m[row + 2][col] + m[row + 2][col + 1] + m[row + 2][col + 2]
		if suma > sum(maxhour):
			maxhour = [m[row][col], m[row][col + 1], m[row][col + 2], m[row + 1][col + 1], m[row + 2][col], m[row + 2][col + 1], m[row + 2][col + 2]]
print(sum(maxhour))


a = [list(map(int, input().split())) for i in range(6)]
m = -9999999999
for i in range(4):
	for j in range(4):
		s = sum(a[i][j:j + 3]) + a[i + 1][j + 1] + sum(a[i + 2][j:j + 3])
		if s > m:
			m = s
print(m)


a = [[int(temp) for temp in input().strip().split()] for i in range(6)]
max = None
for i in range(len(a)):
	for j in range(len(a[i])):
		if i > 0 and i < len(a) - 1:
			if j > 0 and j < len(a[i]) - 1:
				temp = a[i][j] + a[i + 1][j] + a[i - 1][j] + a[i + 1][j + 1] + a[i - 1][j - 1] + a[i + 1][j - 1] + a[i - 1][j + 1]
				if max is None or temp > max:
					max = temp
print(max)


matrix = [list(map(int, input().split(' '))) for i in range(6)]

def hourglassSum(row, column):
	return sum(matrix[row][column:column + 3]) + matrix[row + 1][column + 1] + sum(matrix[row + 2][column:column + 3])
maxSum = -100
for i in range(4):
	for j in range(4):
		s = hourglassSum(i, j)
		maxSum = s if s > maxSum else maxSum
print(maxSum)


n = 6
arr = []
for i in range(n):
	arr.append([int(token) for token in input().strip().split(' ')])
res = []
for i in range(n - 2):
	for j in range(n - 2):
		c = sum(arr[i][j:j + 3]) + arr[i + 1][j + 1] + sum(arr[i + 2][j:j + 3])
		res.append(c)
print(max(res))


import fileinput

class Hourglass:

	def __init__(self, matrix):
		self.matrix = matrix

	def sum(self):
		return sum(self.matrix[0]) + self.matrix[1][1] + sum(self.matrix[2])
matrix = []
for l in fileinput.input():
	matrix.append([int(n) for n in l.strip().split()])
hourglasses = []
for y in range(len(matrix) - 2):
	for x in range(len(matrix[y]) - 2):
		submatrix = [row[x:x + 3] for row in matrix[y:y + 3]]
		hourglasses.append(Hourglass(submatrix).sum())
print(max(hourglasses))


array = []
for i in range(6):
	array.append(list(map(int, input().split())))
largest = -99999999999999
for line in range(0, 4):
	for pos in range(0, 4):
		current = 0
		current += sum(array[line][pos:pos + 3])
		current += array[line + 1][pos + 1]
		current += sum(array[line + 2][pos:pos + 3])
		if current > largest:
			largest = current
print(largest)


matrix = [[int(i) for i in input().split()] for j in range(6)]
sum = -99999
for i in range(4):
	for j in range(4):
		temp = matrix[i][j] + matrix[i][j + 1] + matrix[i][j + 2] + matrix[i + 1][j + 1] + matrix[i + 2][j] + matrix[i + 2][j + 1] + matrix[i + 2][j + 2]
		if temp > sum:
			sum = temp
print(sum)


grid = []
for i in range(6):
	grid.append([int(i) for i in input().split()])
largest = None
l = [0, 0]
for i in range(4):
	for a in range(1, 5):
		top = sum(grid[i][a - 1:a + 2])
		mid = grid[i + 1][a]
		bot = sum(grid[i + 2][a - 1:a + 2])
		total = top + mid + bot
		if largest == None or total > largest:
			largest = total
			l[0] = i
			l[1] = a
print(largest)


rays = []
for i in range(6):
	rays.append([int(i) for i in input().split(' ')])
n = float('-inf')
for x in range(2, 6):
	for y in range(6):
		total = sum([rays[y - 2][x - 2], rays[y - 2][x - 1], rays[y - 2][x], rays[y - 1][x - 1], rays[y][x - 2], rays[y][x - 1], rays[y][x]])
		if total > n:
			n = total
print(n)


array = []
for i in range(6):
	array.append(input().split(' '))
	for j in range(6):
		array[i][j] = int(array[i][j])
max = -63
for i in range(4):
	for j in range(4):
		sum = array[i][j] + array[i][j + 1] + array[i][j + 2] + array[i + 1][j + 1] + array[i + 2][j] + array[i + 2][j + 1] + array[i + 2][j + 2]
		if sum > max:
			max = sum
print(max)


matrix = [input().split() for i in range(6)]
for i in range(6):
	for j in range(6):
		matrix[i][j] = int(matrix[i][j])
largest_sum = -100
for j in range(4):
	for i in range(4):
		summa = sum(matrix[j][i:i + 3]) + matrix[j + 1][i + 1] + sum(matrix[j + 2][i:i + 3])
		if summa > largest_sum:
			largest_sum = summa
print(largest_sum)