You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:  Swap two neighboring matrix rows, that is, rows with indexes i and i + 1 for some integer i (1 ≤ i < 5).  Swap two neighboring matrix columns, that is, columns with indexes j and j + 1 for some integer j (1 ≤ j < 5). 

You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.


-----Input-----

The input consists of five lines, each line contains five integers: the j-th integer in the i-th line of the input represents the element of the matrix that is located on the intersection of the i-th row and the j-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.


-----Output-----

Print a single integer — the minimum number of moves needed to make the matrix beautiful.


-----Examples-----
Input
0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

Output
3

Input
0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0

Output
1

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
a = [[] * 5] * 5
for i in range(5):
	a[i] = list(map(int, input().split()))
x_one = 0
y_one = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x_one = j
			y_one = i
			break
print(abs(x_one - 2) + abs(y_one - 2))


for i in range(5):
	data = [j for j in input().split()]
	if '1' in data:
		pos = abs(i - 2) + abs(data.index('1') - 2)
		break
print(pos)


n = 5
for i in range(n):
	row = [int(x) for x in input().split()]
	if row[0] + row[1] + row[2] + row[3] + row[4] > 0:
		a = i + 1
		for y in range(n):
			if row[y] > 0:
				b = y + 1
A = abs(a - 3)
B = abs(b - 3)
print(A + B)


import math
r1 = input().split()
r1.extend(input().split())
r1.extend(input().split())
r1.extend(input().split())
r1.extend(input().split())
pos = r1.index('1') + 1
row_diff = 3 - math.ceil(pos / 5)
print(abs(row_diff) + abs(pos + row_diff * 5 - 13))


for i in range(5):
	g = input()
	if '1' in g:
		n = i + 1
		m = g.index('1') // 2 + 1
print(abs(3 - n) + abs(3 - m))


matrix = [2, 1, 0, 1, 2]
for i in matrix:
	s = input()
	if '1' in s:
		print(i + matrix[s.find('1') // 2])


l = [2, 1, 0, 1, 2]
for i in l:
	s = input()
	if '1' in s:
		print(l[s.find('1') // 2] + i)


for i in range(5):
	l = [int(x) for x in input().split()]
	for j in range(5):
		if l[j] == 1:
			c1 = i
			c2 = j
print(abs(2 - c1) + abs(2 - c2))


count = 0
for a in range(5):
	y = [int(i) for i in input().split()]
	for z in y:
		if z == 1:
			i = a + 1
			j = y.index(z) + 1
if i != 3:
	while i < 3:
		i += 1
		count += 1
	while i > 3:
		i -= 1
		count += 1
if j != 3:
	while j < 3:
		j += 1
		count += 1
	while j > 3:
		j -= 1
		count += 1
print(count)


M = []
for i in range(0, 5):
	M.append(input().split())
for i in range(0, 5):
	for j in range(0, 5):
		if M[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))
			break


tablica = []
for i in range(5):
	a = input().split(' ')
	tablica.append(a)
for i in range(len(tablica)):
	for j in range(len(tablica)):
		punkt = tablica[i][j]
		if punkt == '1':
			wynik = abs(int(i) - 2) + abs(int(j) - 2)
			print(int(wynik))


(r, w) = (0, 0)
flag = False
for i in range(5):
	x = map(int, input().split())
	if not flag:
		for z in enumerate(x):
			(a, b) = z
			if b == 1:
				(r, w) = (i, a)
				flag = True
(r, w) = (r - 2, w - 2)
print(abs(r) + abs(w))


for i in range(5):
	a = input().split()
	if '1' in a:
		break
print(abs(2 - i) + abs(2 - a.index('1')))


l = [[0 for j in range(5)] for i in range(5)]
for f1 in range(5):
	(l[f1][0], l[f1][1], l[f1][2], l[f1][3], l[f1][4]) = map(int, input().split())
for f1 in range(5):
	for f2 in range(5):
		if l[f1][f2] == 1:
			print(abs(f2 - 2) + abs(f1 - 2))


from math import floor, ceil
from sys import stdin, stdout

def main(status=int(0), const_matix_size=5):

	def fte(array, elm, const_matix_size=5):
		for line in range(const_matix_size):
			for pos in range(const_matix_size):
				if array[line][pos] == elm:
					return (line, pos)
		return (None, None)
	matix = [input().split() for _ in range(const_matix_size)]
	(x_pos, y_pos) = fte(array=matix, elm='1')
	print(abs(2 - x_pos) + abs(2 - y_pos))
main()


m = list()
for i in range(5):
	m.append(input().split(' '))
(x, y) = (0, 0)
for i in range(5):
	for j in range(5):
		if m[i][j] == '1':
			x = i + 1
			y = j + 1
			break
d = abs(x - 3) + abs(y - 3)
print(d)


s = []
i1 = 0
j1 = 0
for i in range(5):
	s.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if s[i][j] == 1:
			i1 = i
			j1 = j
print(abs(i1 - 2) + abs(j1 - 2))


for i in range(5):
	arr = [int(x) for x in input().split()]
	for j in range(5):
		if arr[j] == 1:
			print(abs(2 - i) + abs(2 - j))
			break


found = False
for i in range(5):
	line = list(map(int, input().split()))
	if not found:
		for j in range(len(line)):
			if line[j] == 1:
				found = True
				res = abs(2 - i) + abs(2 - j)
print(res)


a = []
for i in range(5):
	s = list(map(int, input().split()))
	a.append(s)
	t = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			t = 1
			break
	if t == 1:
		break
print(abs(2 - i) + abs(2 - j))


def beautimatrix(matrix):
	for i in range(5):
		for y in range(5):
			if matrix[i][y] == 1:
				return abs(i - 2) + abs(y - 2)
matrix = []
for i in range(5):
	row = list(map(int, input().split()))
	matrix.append(row)
print(beautimatrix(matrix))


def get_values():
	grid = []
	for i in range(5):
		row = list(map(int, input().split()))
		grid.append(row)
	result = check(grid)
	return print(result)

def check(m):
	moves = 0
	new_grid = []
	center_row = m[2]
	center_value = m[2][2]
	for row in range(len(m)):
		for col in range(len(m[row])):
			if m[row][col] == 1:
				new_center = m[row]
				moves += abs(row - 2)
				moves += abs(col - 2)
	return moves
get_values()


arr2d = [[j for j in list(map(int, input().split()))] for i in range(5)]
for i in range(5):
	for j in range(5):
		if arr2d[i][j] == 1:
			location = [i + 1, j + 1]
ideal = [3, 3]
m = abs(ideal[0] - location[0])
n = abs(ideal[1] - location[1])
print(abs(m + n))


a = []
for i in range(5):
	c = list(map(int, input().split()))
	if 1 in c:
		x = i
		y = c.index(1)
	a.append(c)
print(abs(2 - x) + abs(2 - y))


l = []
for _ in range(5):
	n_l = list(map(int, input().split()))
	l.append(n_l)
(g_i, g_j) = (0, 0)
for i in range(len(l)):
	for j in range(len(l[i])):
		if l[i][j] == 1:
			(g_i, g_j) = (i, j)
print(abs(2 - g_i) + abs(2 - g_j))


a = [[int(x) for x in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


import math
li = []
x = 0
y = 0
for i in range(5):
	a = input().split()
	li.append(a)
for j in range(5):
	for k in range(5):
		if li[j][k] == '1':
			j += 1
			k += 1
			if j > 3:
				x = j - 3
			elif j == 3:
				x = 0
			else:
				x = math.fabs(j - 3)
			if k > 3:
				y = k - 3
			elif k == 3:
				y = 0
			else:
				y = math.fabs(k - 3)
			break
print(int(x + y))


def cf_263a():
	(x, y) = (0, 0)
	for i in range(5):
		try:
			x = input().split().index('1')
			y = i
			print(abs(x + 1 - 3) + abs(y + 1 - 3))
		except:
			pass
cf_263a()


__author__ = 'Utena'
l = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


n = 0
l = []
x = 0
y = 0
while n < 5:
	l.append(list(map(int, input().split())))
	n += 1
for i in range(0, 5):
	for j in range(0, 5):
		if l[i][j] == 1:
			x = i + 1
			y = j + 1
print(abs(3 - x) + abs(3 - y))


q = 0
w = 0
a = input().split()
if '1' in a:
	q = 2
	w = ((a.index('1') - 2) ** 2) ** 0.5
b = input().split()
if '1' in b:
	q = 1
	w = ((b.index('1') - 2) ** 2) ** 0.5
c = input().split()
if '1' in c:
	q = 0
	w = ((c.index('1') - 2) ** 2) ** 0.5
d = input().split()
if '1' in d:
	q = 1
	w = ((d.index('1') - 2) ** 2) ** 0.5
e = input().split()
if '1' in e:
	q = 2
	w = ((e.index('1') - 2) ** 2) ** 0.5
print(int(w + q))


for i in range(5):
	t = input()
	if '1' in t:
		x = t.find('1') // 2 + 1
		y = i + 1
		break
	else:
		pass
print(abs(x - 3) + abs(y - 3))


from math import *
arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
(x, y) = (0, 0)
for (i, val1) in enumerate(arr):
	for (j, val2) in enumerate(val1):
		if val2 == 1:
			(x, y) = (i, j)
print(int(fabs(x - 2) + fabs(y - 2)))


i = 0
j = 0
for line_num in range(1, 6):
	line = input()
	if i != 0 or j != 0:
		continue
	if '1' in line:
		i = line_num
		j = line.split().index('1') + 1
print(abs(3 - i) + abs(3 - j))


l = []
for i in range(5):
	inner = list(map(int, input().split()))
	if 1 in inner:
		y = inner.index(1)
		x = i
	l.append(inner)
print(sum((abs(2 - x), abs(2 - y))))


l1 = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
l3 = [int(x) for x in input().split()]
l4 = [int(x) for x in input().split()]
l5 = [int(x) for x in input().split()]
if 1 in l1:
	x = l1.index(1) + 1
	y = 1
if 1 in l2:
	x = l2.index(1) + 1
	y = 2
if 1 in l3:
	x = l3.index(1) + 1
	y = 3
if 1 in l4:
	x = l4.index(1) + 1
	y = 4
if 1 in l5:
	x = l5.index(1) + 1
	y = 5
d = abs(x - 3)
f = abs(y - 3)
print(d + f)


n = 5
(x, y) = (None, None)
for i in range(n):
	lame = list(map(int, input().split()))
	if 1 in lame:
		x = i + 1
		y = lame.index(1) + 1
		break
print(abs(x - 3) + abs(y - 3))


for i in range(5):
	c = [int(x) for x in input().split()]
	for j in range(5):
		if c[j] == 1:
			m = abs(i - 2) + abs(j - 2)
			print(m)


matrix = [input().split() for _ in range(5)]
for (i, line) in enumerate(matrix):
	for (j, n) in enumerate(line):
		if n == '1':
			pos = (i + 1, j + 1)
			break
	else:
		continue
	break
print(abs(pos[0] - 3) + abs(pos[1] - 3))


Matrix = list()
for i in range(5):
	Matrix.append(list(map(int, input().split())))
x = 0
y = 0
for i in range(5):
	for j in range(5):
		if Matrix[i][j] == 1:
			x = i
			y = j
			break
print(abs(2 - x) + abs(2 - y))


a = list(input().split(' '))
b = list(input().split(' '))
c = list(input().split(' '))
d = list(input().split(' '))
e = list(input().split(' '))
i = 0
for j in a:
	i = 1
	if j == '1':
		k = a.index(j)
		f = k + 1 - 3
		g = i - 3
		if f < 0:
			f = -f
		if g < 0:
			g = -g
		print(f + g)
		break
for j in b:
	i = 2
	if j == '1':
		k = b.index(j)
		f = k + 1 - 3
		g = i - 3
		if f < 0:
			f = -f
		if g < 0:
			g = -g
		print(f + g)
		break
for j in c:
	i = 3
	if j == '1':
		k = c.index(j)
		f = k + 1 - 3
		g = i - 3
		if f < 0:
			f = -f
		if g < 0:
			g = -g
		print(f + g)
		break
for j in d:
	i = 4
	if j == '1':
		k = d.index(j)
		f = k + 1 - 3
		g = i - 3
		if f < 0:
			f = -f
		if g < 0:
			g = -g
		print(f + g)
		break
for j in e:
	i = 5
	if j == '1':
		k = e.index(j)
		f = k + 1 - 3
		g = i - 3
		if f < 0:
			f = -f
		if g < 0:
			g = -g
		print(f + g)
		break


(a, b, c, d, e) = map(int, input().split())
(f, g, h, i, j) = map(int, input().split())
(k, l, m, n, o) = map(int, input().split())
(p, r, s, t, w) = map(int, input().split())
(u, y, z, x, q) = map(int, input().split())
if h == 1 or n == 1 or s == 1 or (l == 1):
	print(1)
elif g == 1 or i == 1 or r == 1 or (t == 1):
	print(2)
elif o == 1 or k == 1 or z == 1 or (c == 1):
	print(2)
elif y == 1 or x == 1 or w == 1 or (j == 1) or (d == 1) or (b == 1) or (f == 1) or (p == 1):
	print(3)
elif u == 1 or q == 1 or e == 1 or (a == 1):
	print(4)
elif m == 1:
	print(0)


for i in range(5):
	x = input().split()
	if '1' in x:
		fi = i
		fj = x.index('1')
(t1, t2) = (abs(fi - 2), abs(fj - 2))
print(t1 + t2)


i = 1
while i <= 5:
	lines = list(input().split())
	if '1' in lines:
		column = int(lines.index('1')) + 1
		row = i
	i += 1
c = abs(column - 3)
r = abs(row - 3)
print(c + r)


for i in range(5):
	row = input()
	index = row.find('1')
	if index >= 0:
		index = int(index / 2)
		print(abs(index - 2) + abs(i - 2))
		break


row = 0
column = 0
for i in range(5):
	row += 1
	l = input().split()
	if '1' in l:
		column = l.index('1')
		break
print(abs(row - 3) + abs(column - 2))


r1 = list(map(int, input().split(' ')))
r2 = list(map(int, input().split(' ')))
r3 = list(map(int, input().split(' ')))
r4 = list(map(int, input().split(' ')))
r5 = list(map(int, input().split(' ')))
if 1 in r1:
	pos = (1, r1.index(1) + 1)
elif 1 in r2:
	pos = (2, r2.index(1) + 1)
elif 1 in r3:
	pos = (3, r3.index(1) + 1)
elif 1 in r4:
	pos = (4, r4.index(1) + 1)
elif 1 in r5:
	pos = (5, r5.index(1) + 1)
x = 3 - pos[0] if pos[0] <= 3 else pos[0] - 3
y = 3 - pos[1] if pos[1] <= 3 else pos[1] - 3
print(x + y)


l = []
for i in range(5):
	l.append(list(map(int, input().split())))
for i in range(len(l)):
	for j in range(len(l[i])):
		if l[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))


a = list(map(int, input('').split(' ')))
if 1 in a:
	x = 0
	y = a.index(1)
b = list(map(int, input('').split(' ')))
if 1 in b:
	x = 1
	y = b.index(1)
c = list(map(int, input('').split(' ')))
if 1 in c:
	x = 2
	y = c.index(1)
d = list(map(int, input('').split(' ')))
if 1 in d:
	x = 3
	y = d.index(1)
e = list(map(int, input('').split(' ')))
if 1 in e:
	x = 4
	y = e.index(1)
print(abs(x - 2) + abs(y - 2))


arr = []
for i in range(5):
	num = input().split()
	arr.append(num)
	for j in range(5):
		if arr[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))


matrix = list()
location = list()
for i in range(5):
	inp = list(map(int, input().split()))
	if 1 in inp:
		location.append(i + 1)
		location.append(inp.index(1) + 1)
	matrix.append(inp)
count = abs(location[0] - 3) + abs(location[1] - 3)
print(count)


__author__ = 'myduomilia'
(x, y) = (0, 0)
for i in range(5):
	l = list(map(int, input().split()))
	for j in range(5):
		if l[j] == 1:
			x = i
			y = j
print(abs(x - 2) + abs(y - 2))


t = []
for i in range(1, 6):
	a = input()
	b = a.split()
	t.append(b)
r = 0
for i in range(0, 5):
	for j in range(0, 5):
		if t[i][j] == '1':
			r = i
			c = j
r1 = 0
if r <= 2:
	r1 += 2 - r
else:
	r1 += r - 2
if c <= 2:
	r1 += 2 - c
else:
	r1 += c - 2
print(r1)


from math import sqrt
matrix = []
count = 0
for _ in range(5):
	matrix.append(input().split())
(n, m) = (-1, -1)
for i in range(5):
	for j in range(5):
		if int(matrix[i][j]) == 1:
			(n, m) = (i, j)
x = sqrt((2 - n) ** 2)
y = sqrt((2 - m) ** 2)
print(int(x + y))


import math as mt

class solution:

	def __init__(self):
		self.list1 = []
		self.i = 0
		self.j = 0
		self.z = 0

	def read_input(self):
		for i in range(5):
			str1 = input()
			self.list1.append(str1.split())

	def read_matrix(self):
		for a in range(5):
			for b in range(5):
				if self.list1[a][b] == '1':
					self.i = a
					self.j = b

	def no_moves(self):
		x = mt.fabs(2 - self.i)
		y = mt.fabs(2 - self.j)
		self.z = x + y

	def show_res(self):
		print(int(self.z))

	def execute(self):
		self.read_input()
		self.read_matrix()
		self.no_moves()
		self.show_res()

def main():
	s1 = solution()
	s1.execute()
main()


row_1 = input().split()
row_2 = input().split()
row_3 = input().split()
row_4 = input().split()
row_5 = input().split()
matrix = [row_1, row_2, row_3, row_4, row_5]
steps = 0
row_with_1 = 0
column_with_1 = 0
for row in range(0, 5):
	for column in range(0, 5):
		if int(matrix[row][column]) == 1:
			row_with_1 = row + 1
			column_with_1 = column + 1
			break
steps += abs(row_with_1 - 3)
steps += abs(column_with_1 - 3)
print(steps)


a = []
for i in range(5):
	l = list(map(int, input().split()))
	a.append(l)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			b = (i, j)
ans = abs(2 - b[0]) + abs(2 - b[1])
print(ans)


for row in range(5):
	row_list = [int(i) for i in input().split(' ')]
	if 1 in row_list:
		one_pos = (row, row_list.index(1))
print(abs(one_pos[0] - 2) + abs(one_pos[1] - 2))


matrix = [list(map(int, input().split())) for y in range(5)]
(x, y) = (-3, -3)
for i in range(2, -3, -1):
	for j in range(-2, 3):
		if matrix[i + 2][j + 2] == 1:
			(x, y) = (i, j)
			break
print(abs(x) + abs(y))


for i in range(5):
	row = list(map(int, input().split()))
	for j in range(5):
		if row[j] == 1:
			index_x = i
			index_y = j
			break
print(abs(2 - index_x) + abs(2 - index_y))


def matrixCount(listM):
	count = 0
	for x in range(len(listM)):
		if listM[x] == 1:
			if x == 0 or x == 4:
				count += 2
			elif x == 1 or x == 3:
				count += 1
			else:
				count += 0
	return count
x = 5
count = 0
for y in range(x):
	s = list(map(int, input().split()))
	if 1 in s:
		if y == 0 or y == 4:
			count += 2
		elif y == 1 or y == 3:
			count += 1
		else:
			count += 0
	count += matrixCount(s)
print(count)


L = []
for i in range(1, 6):
	L.append(list(map(int, input().split())))
for i in range(0, 5):
	for j in range(0, 5):
		if L[i][j] == 1:
			x = i + 1
			y = j + 1
			break
print(abs(x - 3) + abs(y - 3))


def func(s):
	for i in range(5):
		for j in range(5):
			if s[i][j] == 1:
				return (i, j)
s = []
for i in range(5):
	s.append(list(map(int, input().rstrip().split())))
(x, y) = func(s)
x = abs(x - 2)
y = abs(y - 2)
print(x + y)


def convert(arr):
	arr = arr.split(' ')
	loc = 0
	for i in range(len(arr)):
		arr[i] = int(arr[i])
		if arr[i] != 0:
			loc = i + 1
	return [loc, arr]
matrix = []
cord = {'x': 0, 'y': 0}
for i in range(5):
	line = input()
	lineList = convert(line)
	if lineList[0] != 0:
		cord['x'] = lineList[0]
		cord['y'] = i + 1
		matrix.insert(i, lineList[1])
	else:
		matrix.insert(i, lineList[1])
print(abs(cord['x'] - 3) + abs(cord['y'] - 3))


lst = []
for i in range(5):
	lst.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if lst[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
			break


a = []
c = 0
for x in range(0, 5):
	n1 = list(map(int, input().split(' ')))
	a.append(n1)
for (y, z) in enumerate(a):
	if 1 in z:
		k = y
		j = z.index(1)
if k != 2:
	c = c + abs(2 - k)
if j != 2:
	c = c + abs(2 - j)
print(c)


n = 1
while n <= 5:
	a = list(map(int, input().split()))
	for i in range(len(a)):
		if a[i] == 1:
			r = n
			c = i + 1
	n += 1
result = abs(r - 3) + abs(c - 3)
print(result)


board = sum([[int(x) for x in input().split()] for _ in range(5)], [])
index = sum([x * y for (x, y) in zip(board, range(25))])
print(abs(int(index / 5) - 2) + abs(index % 5 - 2))


r = []
for i in range(5):
	n = input().split()
	r.append(n)
total = 0
for i in range(len(r)):
	if '1' in r[i]:
		if i == 0:
			total += 2
		if i == 1:
			total += 1
		if i == 2:
			total += 0
		if i == 3:
			total += 1
		if i == 4:
			total += 2
for j in r:
	for i in range(len(j)):
		if j[i] == '1':
			if i == 0:
				total += 2
			if i == 1:
				total += 1
			if i == 2:
				total += 0
			if i == 3:
				total += 1
			if i == 4:
				total += 2
print(total)


a1 = input().split()
a2 = input().split()
a3 = input().split()
a4 = input().split()
a5 = input().split()
if '1' in a1:
	print(2 + abs(a1.index('1') - 2))
if '1' in a2:
	print(1 + abs(a2.index('1') - 2))
if '1' in a3:
	print(abs(a3.index('1') - 2))
if '1' in a4:
	print(1 + abs(a4.index('1') - 2))
if '1' in a5:
	print(2 + abs(a5.index('1') - 2))


matrix = []
counter = 0
position_i = 0
position_j = 0
for i in range(5):
	matrix.append([int(j) for j in input().split()])
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			position_i = i
			position_j = j
if position_i > 2:
	counter = position_i - 2
elif position_i < 2:
	counter = 2 - position_i
if position_j > 2:
	counter = counter + position_j - 2
elif position_j < 2:
	counter = counter + (2 - position_j)
print(counter)


lst = []
for z in range(5):
	lst.append([int(j) for j in input('').split(' ')])
m = 0
for i in range(5):
	if 1 in lst[i]:
		j = lst[i].index(1)
		break
if j != 2:
	m += j - 2 if j > 2 else 2 - j
if i != 2:
	m += i - 2 if i > 2 else 2 - i
print(m)


def find_coord(m):
	i = 1
	j = 1
	for row in m:
		i = 1
		for column in row:
			if column == 1:
				return (i, j)
			i += 1
		j += 1
	return -1
m = []
for _ in range(5):
	m.append(list(map(int, input().split())))
(i, j) = find_coord(m)
final = (3, 3)
s = 0
if i != 3:
	s += abs(3 - i)
if j != 3:
	s += abs(3 - j)
print(s)


m = []
a = []
for i in range(5):
	m.append(input().split())
for i in m:
	if '1' in i:
		x = 3 - (m.index(i) + 1)
		y = 3 - (i.index('1') + 1)
		print(abs(x) + abs(y))


(x, y) = (0, 0)
for k in range(5):
	s = input()
	if '1' in s:
		(x, y) = (k, s.index('1') // 2)
print(abs(x - 2) + abs(y - 2))


b = []
for k in range(5):
	a = input().split(' ')
	a = [int(a[i]) for i in range(len(a))]
	b.append(a)
count = 0
for i in range(len(b)):
	if 1 in b[i]:
		c = i
		a = b[i].index(1)
		break
while True:
	if c < 2:
		c = c + 1
		count += 1
		continue
	if c > 2:
		c = c - 1
		count += 1
		continue
	if c == 2:
		while True:
			if a > 2:
				a = a - 1
				count += 1
				continue
			if a < 2:
				a = a + 1
				count += 1
				continue
			if a == 2:
				break
	if c == 2 and a == 2:
		print(count)
		break


for i in range(5):
	li = list(map(int, input().split()))
	if 1 in li:
		m = li.index(1)
		print(abs(2 - i) + abs(2 - m))
		break


ls = [list(map(int, input().split())) for _ in range(5)]
for i in range(5):
	for j in range(5):
		if ls[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


for i in range(5):
	rolls = input()
	if '1' in rolls:
		t = i
		j = rolls.find('1')
print(int(abs(t - 2) + abs(j - 4) / 2))


r = []
for t in range(5):
	r1 = [int(x) for x in input().split()]
	r.append(r1)
a = 0
for i in range(5):
	for j in range(5):
		if r[i][j] == 1:
			a = abs(2 - i) + abs(2 - j)
			print(a)
			break


lst = []
for i in range(5):
	(a, b, c, d, e) = [int(x) for x in input().split()]
	lst.append(a)
	lst.append(b)
	lst.append(c)
	lst.append(d)
	lst.append(e)
pos = int(lst.index(1))
if pos == 7 or pos == 11 or pos == 13 or (pos == 17):
	print('1')
elif pos == 6 or pos == 8 or pos == 16 or (pos == 18) or (pos == 2) or (pos == 10) or (pos == 14) or (pos == 22):
	print('2')
elif pos == 1 or pos == 3 or pos == 5 or (pos == 9) or (pos == 15) or (pos == 19) or (pos == 21) or (pos == 23):
	print('3')
elif pos == 0 or pos == 4 or pos == 20 or (pos == 24):
	print('4')
elif pos == 12:
	print('0')


for i in range(5):
	row = list(map(int, input().split()))
	for j in range(5):
		if row[j] == 1:
			(x, y) = (i, j)
ans = abs(x - 2) + abs(y - 2)
print(ans)


m = [input().split(), input().split(), input().split(), input().split(), input().split()]
slon = 0
for j in range(5):
	for i in range(5):
		if m[j][i] == '1':
			slon = abs(i - 2) + abs(j - 2)
print(slon)


pos = 0
matrix = []
for i in range(0, 5):
	i = input().split()
	matrix.append(i)
for i in range(0, len(matrix)):
	if '1' in matrix[i]:
		row_pos = i + 1
		column_pos = matrix[i].index('1') + 1
row_step = 0
column_step = 0
if row_pos > 3:
	row_step = row_pos - 3
elif row_pos < 3:
	row_step = 3 - row_pos
elif row_pos == 3:
	row_step = row_step + 0
if column_pos > 3:
	column_step = column_pos - 3
elif column_pos < 3:
	column_step = 3 - column_pos
elif column_pos == 3:
	column_step = column_step + 0
print(column_step + row_step)


import math
matrix = []
for i in range(5):
	line = input()
	matrix.append(list(map(int, line.split(' '))))
val1 = 0
val2 = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			val1 = i
			val2 = j
moves = abs(val1 - 2) + abs(val2 - 2)
print(moves)


for x in range(5):
	r = input().split()
	for y in range(5):
		if r[y] == '1':
			i = x
			j = y
print(abs(2 - i) + abs(2 - j))


a = []
for i in range(5):
	temp = list(map(int, input().split()))
	a.append(temp)
(x, y) = (0, 0)
flag = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			(x, y) = (i, j)
			flag = 1
			break
	if flag == 1:
		break
ans = abs(x - 2) + abs(y - 2)
print(ans)


mat = [list(map(int, input().split())) for x in range(5)]
pos = (0, 0)
mid = (2, 2)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			pos = (i, j)
res = (abs(mid[0] - pos[0]), abs(mid[1] - pos[1]))
print(sum(res))


s = input()
s1 = input()
s2 = input()
s3 = input()
s4 = input()
s5 = s + s1 + s2 + s3 + s4
s6 = s5.replace(' ', '')
if s6.find('1') in (0, 4, 20, 24):
	print(4)
elif s6.find('1') in (1, 3, 5, 9, 15, 19, 21, 23):
	print(3)
elif s6.find('1') in (2, 6, 8, 10, 14, 16, 18, 22):
	print(2)
elif s6.find('1') in (7, 11, 13, 17):
	print(1)
else:
	print(0)


moves = 0
for i in range(5):
	row = list(map(int, input().split()))
	for j in range(5):
		if row[j] == 1:
			moves = abs(2 - j) + abs(2 - i)
			break
print(moves)


sum = 0
for i in range(0, 5):
	a = [int(x) for x in input().split(' ')]
	for j in range(0, 5):
		if a[j] == 1 and j == 2 and (i == 2):
			sum = 0
		elif a[j] == 1 and j == 2 and (i != 2):
			sum = abs(2 - i)
		elif a[j] == 1 and j != 2 and (i == 2):
			sum = abs(2 - j)
		elif a[j] == 1 and j != 2 and (i != 2):
			sum = abs(2 - j)
			y = abs(2 - i)
			sum = sum + y
print(sum)


answer = 0
for i in range(5):
	input_user = input()
	if '1' in input_user:
		answer = abs(i - 2) + abs(input_user.index('1') / 2 - 2)
print(int(answer))


a1 = list(map(int, input().split(' ')))
a2 = list(map(int, input().split(' ')))
a3 = list(map(int, input().split(' ')))
a4 = list(map(int, input().split(' ')))
a5 = list(map(int, input().split(' ')))
aa = [a1, a2, a3, a4, a5]
pos = [0, 0]
for i in range(len(aa)):
	try:
		pos[1] = aa[i].index(1)
		pos[0] = i
		break
	except:
		continue
print(abs(2 - pos[0]) + abs(2 - pos[1]))


def check(arr):
	if arr[2][2] != 1:
		return 0
	return 1
arr = []
for i in range(5):
	row = list(map(int, input().split()))
	arr.append(row)
c = 0
while check(arr) != 1:
	flag = 0
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				(i_n, j_n) = (i, j)
				if i > 2:
					i_n = i - 1
				elif i < 2:
					i_n = i + 1
				elif j > 2:
					j_n = j - 1
				elif j < 2:
					j_n = j + 1
				arr[i][j] = 0
				arr[i_n][j_n] = 1
				if i != i_n or j != j_n:
					flag = 1
					break
		if flag == 1:
			break
	c += 1
print(c)


l = []
row = 0
col = 0
moves = 0
for i in range(5):
	l.append([int(j) for j in input().split()])
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			row = i
			col = j
moves += abs(row - 2)
moves += abs(col - 2)
print(moves)


m = [[None] * 5 for i in range(5)]
for i in range(5):
	a = list(map(int, input().rstrip().split()))
	m[i] = a
item_index = 0
matrix_dim = 5
for row in m:
	for col in row:
		if col == 1:
			break
		item_index += 1
	if col == 1:
		break
(r, c) = (item_index // matrix_dim, item_index % matrix_dim)
r += 1
c += 1
print(abs(3 - r) + abs(3 - c))


(x, y) = (0, 0)
for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			(x, y) = (i, j)
print(abs(2 - x) + abs(2 - y))


import math
a = []
pos_x = 0
pos_y = 0
for i in range(0, 5):
	arr = list(map(int, input().split(' ')))
	a.append(arr)
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == 1:
			pos_x = i
			pos_y = j
print(abs(pos_x - 2) + abs(pos_y - 2))


a = []
for k in range(5):
	l = [int(i) for i in input().split()]
	a.append(l)
c = 1
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			c = 0
			break
	if c == 0:
		break
print(abs(j - 2) + abs(i - 2))


matrix = []
for i in range(5):
	matrix.append([int(x) for x in input().split()])
for i in matrix:
	if sum(i) == 1:
		X1 = matrix.index(i) + 1
		Y1 = matrix[matrix.index(i)].index(1) + 1
print(abs(X1 - 3) + abs(Y1 - 3))


matrix = []
for i in range(5):
	line = input().split()
	matrix.append(line)
pos = ()
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			pos = (i, j)
if pos == (2, 2):
	print(0)
else:
	print(abs(3 - (pos[0] + 1)) + abs(3 - (pos[1] + 1)))


row1 = 0
col1 = 0
for i in range(1, 6):
	s = input().split(' ')
	if '1' in s:
		row1 = i
		col1 = s.index('1') + 1
		break
r = abs(3 - row1)
c = abs(3 - col1)
print(r + c)


a = []
for i in range(5):
	s = [int(x) for x in input().split()]
	if sum(s) != 0:
		z = [i, s.index(1)]
print(abs(2 - z[0]) + abs(2 - z[1]))


matrix = []
for _ in range(5):
	numbers = list(map(int, input().split()))
	matrix.append(numbers)
for (index, data) in enumerate(matrix):
	for (in_index, value) in enumerate(data):
		if value == 1:
			output = abs(2 - index) + abs(in_index - 2)
			print(output)


for i in range(0, 5):
	lst = [int(x) for x in input().split(' ')]
	if 1 in lst:
		hr = lst.index(1)
		vr = i
print(str(abs(2 - hr) + abs(2 - vr)))


array = []
result = 0
for i in range(5):
	array.append(list(map(int, input().split())))
x = array.index(max(array))
y = array[x].index(max(array[x]))
while x != 2:
	if x > 2:
		x -= 1
		result += 1
	elif x < 2:
		x += 1
		result += 1
while y != 2:
	if y > 2:
		y -= 1
		result += 1
	elif y < 2:
		y += 1
		result += 1
print(result)


matrix = []
for i in range(5):
	entries = list(map(int, input().split()))
	matrix.append(entries)
for i in range(len(matrix)):
	if matrix[i].count(1) == 1:
		c = [i, matrix[i].index(1)]
print(abs(2 - c[0]) + abs(2 - c[1]))


i = j = 0
for a in range(5):
	x = input().split(' ')
	for b in range(5):
		if x[b] == '1':
			i = a
			j = b
print(abs(2 - i) + abs(2 - j))


import sys
L = []
for i in range(0, 5):
	L1 = [int(x) for x in input().split()]
	L.append(L1)
for i in range(0, 5):
	if 1 in L[i]:
		j = L[i].index(1)
		ans = abs(i - 2) + abs(j - 2)
		print(ans)
		sys.exit()


bigMatrix = []
for i in range(0, 5):
	matrixIn = str(input())
	splitted = matrixIn.split()
	bigMatrix.append(splitted)
biggerMatrix = []
for i in bigMatrix:
	biggerMatrix.append(int(i[0]))
	biggerMatrix.append(int(i[1]))
	biggerMatrix.append(int(i[2]))
	biggerMatrix.append(int(i[3]))
	biggerMatrix.append(int(i[4]))
for i in biggerMatrix:
	if i == 1:
		currPlace = biggerMatrix.index(i)
numberMoves = 0
while currPlace != 12:
	if currPlace > 12 and currPlace - 12 >= 5:
		currPlace -= 5
		numberMoves += 1
	elif currPlace > 12 and currPlace - 12 < 5 and (currPlace - 12 != 4):
		currPlace -= 1
		numberMoves += 1
	elif currPlace > 12 and currPlace - 12 == 4:
		currPlace -= 5
		numberMoves += 1
	elif currPlace < 12 and 12 - currPlace >= 5:
		currPlace += 5
		numberMoves += 1
	elif currPlace < 12 and 12 - currPlace < 5 and (12 - currPlace != 4):
		currPlace += 1
		numberMoves += 1
	elif currPlace < 12 and 12 - currPlace == 4:
		currPlace += 5
		numberMoves += 1
print(numberMoves)


mat = []
r = 5
c = 5
for i in range(r):
	a = [int(x) for x in input().split()]
	mat.append(a)
for i in range(r):
	for j in range(c):
		if mat[i][j] > 0:
			x = i - 2
			y = j - 2
if x < 0:
	x = -x
if y < 0:
	y = -y
print(x + y)


count = 0
for z in '     ':
	x = input().replace(' ', '')
	count = count + 1
	if '1' in x:
		print(abs(3 - count) + abs(3 - x.find('1') - 1))


for row in range(5):
	n = input().split()
	for col in range(5):
		if n[col] == '1':
			x = abs(row - 2) + abs(col - 2)
			break
print(x)


(a, b) = [0, 0]
lines = list()
for i in range(5):
	lines.append([int(i) for i in input().split(' ')])
	for j in range(len(lines[i])):
		if lines[i][j] == 1:
			(a, b) = (i, j)
			break
print(abs(a - 2) + abs(b - 2))


s = ''
for i in range(5):
	n = input()
	s = s + ' ' + n
a = 1 / 2 + s.find('1') / 2
b = (a - 1) // 5 + 1
c = (a - 1) % 5 + 1
print(int(abs(b - 3) + abs(c - 3)))


cnt = 5
L = []
seq1 = None
seq2 = None
for i in range(0, cnt):
	L.append([int(x) for x in input().split(' ')])
	if seq1 == None and seq2 == None:
		for j in range(0, cnt):
			if L[i][j] == 1:
				seq1 = i
				seq2 = j
print(abs(seq1 - 2) + abs(seq2 - 2))


from itertools import groupby
import sys
a = {}
row = 0
column = 0
for i in range(1, 6):
	a[i] = list(map(int, input().split()))
for i in range(1, 6):
	if 1 in a[i]:
		row = i
		b = a[i]
counter = 0
for i in b:
	counter += 1
	if i == 1:
		column = counter
result = abs(3 - row) + abs(3 - column)
print(result)


line_count = 0
for i in range(5):
	line_count += 1
	line = input().split()
	for j in range(len(line)):
		if line[j] == '1':
			x = j + 1
			y = line_count
			break
l = []
l.append(x)
l.append(y)
mid = [3, 3]
moves = abs(mid[0] - l[0]) + abs(mid[1] - l[1])
print(moves)


v = h = 0
for i in range(5):
	a = list(map(int, input().split()))
	if a.count(1):
		v = i
		h = a.index(1)
		break
print(abs(2 - v) + abs(2 - h))


d = {}
for i in range(5):
	d[i] = input().split(' ')
for i in range(5):
	for j in range(5):
		if d[i][j] == '1':
			x = i
			y = j
if x >= 2:
	x = x - 2
else:
	x = 2 - x
if y >= 2:
	y = y - 2
else:
	y = 2 - y
print(x + y)


s = [[x for x in input().split()] for _ in range(5)]
for (i, row) in enumerate(s):
	if '1' in row:
		print(abs(2 - i) + abs(2 - row.index('1')))


def solve(matrix):

	def index(matrix):
		for (x, y) in enumerate(matrix):
			if 1 in y:
				return [x + 1, y.index(1) + 1]
	idx = index(matrix)
	print(abs(3 - idx[0]) + abs(3 - idx[1]))
matrix = []
for i in range(5):
	row = list(map(int, input().split()))
	matrix.append(row)
solve(matrix)


import math as m
matrix = []
for _ in range(0, 5):
	row = []
	row = input().split()
	matrix.append(row)
counter = 0
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == '1':
			counter = abs(i - 2) + abs(j - 2)
			print(counter)


matrix = []
for i in range(0, 5):
	matrix.append(input().split(' '))
x = 0
y = 0
ans = -1
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == '1':
			ans = abs(i - 2) + abs(j - 2)
			break
	if ans != -1:
		break
print(ans)


l = []
for i in range(5):
	l1 = list(map(int, input().split()))
	if 1 in l1:
		row = i
		col = l1.index(1)
print(abs(row - 2) + abs(col - 2))


post = []
for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		post.append(i + 1)
		post.append(l.index(1) + 1)
print(abs(3 - post[0]) + abs(3 - post[1]))


ai = []
(r, c) = (None, None)
for i in range(5):
	s = list(map(int, input().split()))
	ai.append(s)
	if 1 in s:
		r = i + 1
		c = s.index(1) + 1
print(abs(3 - r) + abs(3 - c))


for i in range(5):
	arr = list(map(int, input().split()))
	for j in range(5):
		if arr[j] == 1:
			(x, y) = (i, j)
x += 1
y += 1
moves = abs(x - 3) + abs(y - 3)
print(moves)


for i in range(5):
	line = list(map(int, input().split()))
	for j in range(5):
		if line[j]:
			print(abs(i - 2) + abs(j - 2))


matrix = []
main_index = []
overall = 0
for i in range(5):
	row = [int(x) for x in input().split()]
	if 1 in row:
		main_index.append(i)
		main_index.append(row.index(1))
	matrix.append(row)
x = main_index[0]
y = main_index[1]
while x != 2 or y != 2:
	if x > 2:
		x -= 1
	elif x < 2:
		x += 1
	elif y > 2:
		y -= 1
	else:
		y += 1
	overall += 1
print(overall)


from sys import stdin, stdout

def distance_to_5(x):
	if x <= 3:
		return 3 - x
	return x - 3
i = 1
movement = 0
while i <= 5:
	row = stdin.readline().split()
	if row.count('1'):
		x = row.index('1') + 1
		y = i
		break
	i += 1
stdout.write(str(distance_to_5(x) + distance_to_5(y)) + '\n')


for i in range(5):
	temp = [int(x) for x in input().split()]
	if sum(temp) == 1:
		n_index = temp.index(1) + 1
		n_range = i + 1
print(abs(3 - n_index) + abs(3 - n_range))


matrix = [[int(x) for x in input().split()] for y in range(5)]
moves = -1
for row in range(5):
	for col in range(5):
		if matrix[row][col] == 1:
			moves = abs(2 - row) + abs(2 - col)
			break
	if moves != -1:
		break
print(moves)


m = 0
for i in range(5):
	s = input().split()
	for j in range(5):
		if int(s[j]) == 1:
			m = abs(i - 2) + abs(j - 2)
print(m)


for i in range(5):
	row = input().split()
	for j in range(5):
		if row[j] == '1':
			print(abs(i - 2) + abs(j - 2))


m = 0
for u in range(1, 6):
	k = list(map(int, input().split()))
	if 1 in k:
		for (i, c) in enumerate(k):
			if c == 1:
				c = i + 1
				r = u
				break
if c > 3 or c < 3:
	if c > 3:
		while c != 3:
			c -= 1
			m += 1
	else:
		while c != 3:
			c += 1
			m += 1
if r > 3 or r < 3:
	if r > 3:
		while r != 3:
			r -= 1
			m += 1
	else:
		while r != 3:
			r += 1
			m += 1
print(m)


for i in range(5):
	a = input().split()
	if '1' in a:
		(x, y) = (i, a.index('1'))
print(abs(x - 2) + abs(y - 2))


row1 = input().split()
row2 = input().split()
row3 = input().split()
row4 = input().split()
row5 = input().split()
col1 = [row1[0], row2[0], row3[0], row4[0], row5[0]]
col2 = [row1[1], row2[1], row3[1], row4[1], row5[1]]
col3 = [row1[2], row2[2], row3[2], row4[2], row5[2]]
col4 = [row1[3], row2[3], row3[3], row4[3], row5[3]]
col5 = [row1[4], row2[4], row3[4], row4[4], row5[4]]
if '1' in row1:
	a = row1.index('1') - 2
elif '1' in row2:
	a = row2.index('1') - 2
elif '1' in row3:
	a = row3.index('1') - 2
elif '1' in row4:
	a = row4.index('1') - 2
elif '1' in row5:
	a = row5.index('1') - 2
a = abs(a)
if '1' in col1:
	b = col1.index('1') - 2
elif '1' in col2:
	b = col2.index('1') - 2
elif '1' in col3:
	b = col3.index('1') - 2
elif '1' in col4:
	b = col4.index('1') - 2
elif '1' in col5:
	b = col5.index('1') - 2
b = abs(b)
print(a + b)


for i in range(1, 6):
	s = list(map(int, input().split()))
	for k in range(1, 6):
		if s[k - 1] == 1:
			print(abs(i - 3) + abs(k - 3))
			break


matrix = []
for i in range(5):
	line = input()
	line1 = line.split()
	if '1' in line1:
		lugar = [line1.index('1'), i]
	matrix.append(line1)
total = 0
while matrix[2][2] != '1':
	if lugar[0] < 2:
		matrix[lugar[0]][lugar[1]] = '0'
		lugar[0] += 1
		matrix[lugar[0]][lugar[1]] = '1'
		total += 1
	elif lugar[0] > 2:
		matrix[lugar[0]][lugar[1]] = '0'
		lugar[0] -= 1
		matrix[lugar[0]][lugar[1]] = '1'
		total += 1
	elif lugar[1] < 2:
		matrix[lugar[0]][lugar[1]] = '0'
		lugar[1] += 1
		matrix[lugar[0]][lugar[1]] = '1'
		total += 1
	elif lugar[1] > 2:
		matrix[lugar[0]][lugar[1]] = '0'
		lugar[1] -= 1
		matrix[lugar[0]][lugar[1]] = '1'
		total += 1
print(total)


matrix = []
steps = 0
for i in range(5):
	matrix.append(list(input().strip().split()))
ind = [(index, row.index('1')) for (index, row) in enumerate(matrix) if '1' in row]
if ind[0][0] < 2:
	steps += 2 - ind[0][0]
else:
	steps += ind[0][0] - 2
if ind[0][1] < 2:
	steps += 2 - ind[0][1]
else:
	steps += ind[0][1] - 2
print(steps)


row = 1
col = 1
for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		col = l.index(1) + 1
		break
	else:
		row += 1
		continue
r = abs(row - 3) + abs(col - 3)
print(abs(row - 3) + abs(col - 3))


import math
(l, ll) = ([], [])
for i in range(5):
	s = input().split()
	ll = []
	for c in s:
		ll.append(int(c))
	l.append(ll)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			(ic, jc) = (i, j)
ans = math.fabs(2 - ic) + math.fabs(2 - jc)
print(int(ans))


x1 = input().split()
x2 = input().split()
x3 = input().split()
x4 = input().split()
x5 = input().split()
lst = ['0', '0', '0', '0', '0']
i = 0
for i in range(5):
	if x1[i] != lst[i] or x5[i] != lst[i]:
		if i == 0 or i == 4:
			z = 4
		elif i == 1 or i == 3:
			z = 3
		else:
			z = 2
	elif x2[i] != lst[i] or x4[i] != lst[i]:
		if i == 0 or i == 4:
			z = 3
		elif i == 1 or i == 3:
			z = 2
		else:
			z = 1
	elif x3[i] != lst[i]:
		if i == 0 or i == 4:
			z = 2
		elif i == 1 or i == 3:
			z = 1
		else:
			z = 0
	i += 1
print(z)


a = []
for _ in range(5):
	a.append(list(map(int, input().split())))
I = 1
J = 1
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			I = i + 1
			J = j + 1
print(abs(3 - I) + abs(3 - J))


(x, y) = (0, 0)
for i in range(5):
	a = list(input().replace(' ', ''))
	for j in range(5):
		if a[j] == '1':
			(x, y) = (i, j)
print(abs(x - 2) + abs(y - 2))


from sys import stdin

def main():
	for x in range(5):
		cad = stdin.readline().strip().split()
		if '1' in cad:
			a = x
			b = cad.index('1')
	a = abs(a - 2)
	b = abs(b - 2)
	print(a + b)
main()


n = 5
res = [input().split()[:n] for i in range(n)]
for i in range(n):
	for j in range(n):
		if res[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))


(a1, a2) = (0, 0)
for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		a1 = i + 1
		a2 = l.index(1) + 1
print(abs(3 - a1) + abs(3 - a2))


def find_1():
	(h, w) = (0, 0)
	stop = False
	for i in range(5):
		arr = input().split()
		for j in range(len(arr)):
			if arr[j] == '1':
				return (i, j)
(h, w) = find_1()
print(abs(h - 2) + abs(w - 2))


index_i = 0
index_j = 0
matrix = []
for i in range(5):
	matrix = input('').split(' ')
	if '1' in matrix:
		index_i = i
		for x in range(5):
			if matrix[x] == '1':
				index_j = x
answer = abs(index_i - 2) + abs(index_j - 2)
print(answer)


i = int(0)
j = int(0)
while i < 5:
	s = input()
	j = int(0)
	ans = 0
	while j < 10:
		if s[j] == '1':
			ans = 1
			break
		j = j + 2
	if ans == 1:
		print(abs(2 - i) + abs(2 - int(j / 2)))
		exit(0)
	i = i + 1


for matrix in range(5):
	row = [int(x) for x in input().split()]
	if 1 in row:
		store = [matrix, row.index(1)]
print(abs(store[0] - 2) + abs(store[1] - 2))


List = []
Row = 1
Column = 1
for i in range(5):
	row = input()
	row_int = row.split(' ')
	row_int = [int(x) for x in row_int]
	List.append(row_int)
	Sum = sum(row_int)
	if Sum == 1:
		Row = i + 1
for i in range(5):
	if List[Row - 1][i] == 1:
		Column = i + 1
		break
print(abs(Row - 3) + abs(Column - 3))


for i in range(5):
	(*s,) = map(int, input().split())
	if 1 in s:
		print(abs(2 - s.index(1)) + abs(2 - i))


matrix = []
for _ in range(5):
	matrix.append(list(map(int, input().rstrip().split())))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			x = j
			y = i
ans = abs(x - 2) + abs(y - 2)
print(ans)


n = 0
x1 = [input()]
while n <= 3:
	x2 = [input()]
	x1 += x2
	n += 1
for i in range(len(x1)):
	if x1[i] != '0 0 0 0 0':
		row = i + 1
		a = x1[row - 1]
	if x1[i] == '0 0 0 0 0':
		b = x1[i]
for j in range(9):
	if a[j] == '1':
		column = j / 2 + 1
	if a[j] != 1:
		nothing = 1
step = abs(row - 3) + abs(column - 3)
print(int(step))


matrix = []
x = 0
y = 0
for i in range(5):
	matrix.append(input().split())
	if '1' in matrix[i]:
		y = i + 1
for j in range(5):
	if matrix[y - 1][j] == '1':
		x = j + 1
print(abs(x - 3) + abs(y - 3))


a = []
for i in range(5):
	a.append([int(x) for x in input().split()])
flag = False
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))
			flag = True
			break
	if flag:
		break


import math
for i in range(5):
	S = [int(x) for x in input().split()]
	if S.count(1) != 0:
		print(int(math.fabs(2 - i) + math.fabs(2 - S.index(1))))


lst = []
for i in range(1, 6):
	x = input().split()
	for j in range(1, 6):
		if x[j - 1] == '1':
			active = (i, j)
			break
print(abs(active[0] - 3) + abs(active[1] - 3))


a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a4 = list(map(int, input().split()))
a5 = list(map(int, input().split()))
if 1 in a1:
	x = a1.index(1)
	if x == 0 or x == 4:
		print(4)
	elif x == 1 or x == 3:
		print(3)
	else:
		print(2)
elif 1 in a5:
	x = a5.index(1)
	if x == 0 or x == 4:
		print(4)
	elif x == 1 or x == 3:
		print(3)
	else:
		print(2)
elif 1 in a2:
	x = a2.index(1)
	if x == 0 or x == 4:
		print(3)
	elif x == 1 or x == 3:
		print(2)
	else:
		print(1)
elif 1 in a4:
	x = a4.index(1)
	if x == 0 or x == 4:
		print(3)
	elif x == 1 or x == 3:
		print(2)
	else:
		print(1)
else:
	x = a3.index(1)
	if x == 0 or x == 4:
		print(2)
	elif x == 1 or x == 3:
		print(1)
	else:
		print(0)


l1 = list(map(int, input().split(' ')))
l2 = list(map(int, input().split(' ')))
l3 = list(map(int, input().split(' ')))
l4 = list(map(int, input().split(' ')))
l5 = list(map(int, input().split(' ')))
li = [l1, l2, l3, l4, l5]
k = -1
for i in li:
	try:
		k = k + 1
		a = i.index(1)
		break
	except:
		continue
moves = abs(2 - a) + abs(2 - k)
print(moves)


def inp():
	row = 0
	for i in range(5):
		arr = input().split()
		row += 1
		if '1' in arr:
			return [arr.index('1') + 1, row]
(col, row) = inp()
diff = abs(3 - row) + abs(3 - col)
print(diff)
exit(0)


matrix = []
for i in range(0, 5):
	T = input().split(' ')
	matrix.append(T)
for i in range(0, 5):
	for j in range(0, 5):
		if int(matrix[i][j]) == 1:
			leastnumber = abs(i - 2) + abs(j - 2)
print(leastnumber)


matrix = [tuple(map(int, input().split())) for _ in range(5)]
for i in matrix:
	if 1 in i:
		x = i.index(1)
		y = matrix.index(i)
		break
print(abs(2 - x) + abs(2 - y))


a = [0] * 5
for i in range(5):
	a[i] = input()
	if '1' in a[i]:
		row = i + 1
c = a[row - 1].split(' ')
for i in range(5):
	if c[i] == '1':
		col = i + 1
print(abs(3 - int(row)) + abs(3 - int(col)))


l = []
for i in range(0, 5):
	n = list(map(int, input().split()))
	l.append(n)
for i in range(0, 5):
	if sum(l[i]) == 1:
		a = i
for j in range(0, 5):
	if l[a][j] == 1:
		b = j + 1
a = a + 1
c = abs(a - 3)
d = abs(b - 3)
print(c + d)


m = []
x = 0
y = 0
pos = 0
for i in range(5):
	X = [int(i) for i in input().split()]
	m.append(X)
	if 1 in X:
		x = pos
		y = X.index(1)
	pos += 1
print(abs(2 - x) + abs(2 - y))


a = []
h = 0
for i in range(5):
	k = input().split()
	if k.count('1') > 0:
		h += abs(i - 3 + 1) + abs(k.index('1') - 3 + 1)
print(h)


row1 = input().split(' ')
row2 = input().split(' ')
row3 = input().split(' ')
row4 = input().split(' ')
row5 = input().split(' ')
matrix = [row1, row2, row3, row4, row5]
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))


n = 1
x = 1
y = 0
while n <= 5:
	(a, b, c, d, e) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	d = int(d)
	e = int(e)
	if a == 1:
		y = 1
		x = n
	elif b == 1:
		y = 2
		x = n
	elif c == 1:
		y = 3
		x = n
	elif d == 1:
		y = 4
		x = n
	elif e == 1:
		y = 5
		x = n
	n = n + 1
print(abs(y - 3) + abs(x - 3))


for i in range(1, 6):
	line = input()
	(a, b, c, d, e) = line.split()
	if int(a) == 1:
		y = i
		x = 1
	if int(b) == 1:
		y = i
		x = 2
	if int(c) == 1:
		y = i
		x = 3
	if int(d) == 1:
		y = i
		x = 4
	if int(e) == 1:
		y = i
		x = 5
output = abs(3 - int(x)) + abs(3 - int(y))
print(output)


count = 0
for j in range(5):
	row = input().split()
	for i in range(len(row)):
		row[i] = int(row[i])
		if row[i] == 1:
			count = abs(2 - j) + abs(i - 2)
			break
print(count)


l = []
for _ in range(5):
	ll = list(map(int, input().split()))
	l.append(ll)
for (ix, row) in enumerate(l):
	for (iy, i) in enumerate(row):
		if i == 1:
			r = ix
			c = iy
print(abs(r - 2) + abs(c - 2))


matrix = []
for i in range(5):
	temp = []
	for j in range(5):
		temp.append('')
	matrix.append(temp)
for i in range(5):
	matrix[i] = list(map(int, input().split()))
x = 0
y = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] != 0:
			x = i
			y = j
print(abs(2 - y) + abs(2 - x))


n = 5
pozice_x = 0
pozice_y = 0
for i in range(n):
	values = [int(n) for n in input().split()]
	for j in range(n):
		if values[j] == 1:
			pozice_x = i + 1
			pozice_y = j + 1
print(abs(pozice_x - 3) + abs(pozice_y - 3))


arr = []
for i in range(0, 5):
	arrInput = list(map(int, input().split()))
	for j in range(0, 5):
		arr.append(arrInput[j])
pos = arr.index(1) + 1
if pos % 5 == 0:
	x = 5
	y = pos / 5
else:
	x = pos % 5
	y = pos // 5 + 1
print(int(abs(x - 3) + abs(y - 3)))


arr = []
for z in range(5):
	arr.append([int(i) for i in input().split()])
x = 0
y = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			x = i + 1
			y = j + 1
			break
ans = abs(x - 3) + abs(y - 3)
print(ans)


x = y = 0
for i in range(5):
	inp = list(map(int, input().split()))
	if 1 in inp:
		(x, y) = (i, inp.index(1))
print(abs(x - 2) + abs(y - 2))


a = list(str(input()).replace(' ', ''))
b = list(str(input()).replace(' ', ''))
c = list(str(input()).replace(' ', ''))
d = list(str(input()).replace(' ', ''))
e = list(str(input()).replace(' ', ''))
x = [a, b, c, d, e]
r = 0
k = True
i = 0
while k:
	if str(1) in x[i]:
		k = False
		break
	else:
		i = i + 1
n = i
k = True
i = 0
while k:
	if str(1) in x[n][i]:
		k = False
		break
	elif i < 5:
		i = i + 1
n += 1
i += 1
n = abs(3 - n)
i = abs(3 - i)
r = i + n
print(r)


a = [i for i in input().split()]
b = [i for i in input().split()]
c = [i for i in input().split()]
d = [i for i in input().split()]
e = [i for i in input().split()]
w = [a, b, c, d, e]
for i in w:
	if '1' in i:
		g = w.index(i)
		z = i.index('1')
		moves = abs(g - 2) + abs(z - 2)
		print(moves)


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def solve(pos):
	return abs(pos[0] - 2) + abs(pos[1] - 2)
pos = None
for i in range(5):
	r = invr()
	if 1 in r:
		for (j, c) in enumerate(r):
			if c == 1:
				pos = (i, j)
print(solve(pos))


m = []
for i in range(5):
	l = list(map(int, input().split()))
	m.append(l)
ri = 0
rj = 0
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			ri = i
			rj = j
print(abs(2 - ri) + abs(2 - rj))


matrix = [input().split(' '), input().split(' '), input().split(' '), input().split(' '), input().split(' ')]
(x, y) = (1, 1)
(ox, oy) = (x, y)
for row in matrix:
	x = 1
	for n in row:
		if n == '1':
			(ox, oy) = (x, y)
		x += 1
	y += 1
steps = 0
if ox != 3:
	steps += abs(3 - ox)
if oy != 3:
	steps += abs(3 - oy)
print(steps)


def main():
	r = c = 0
	j = 2
	for i in range(5):
		p = input().find('1')
		if p != -1:
			r = i
			c = p // 2
			break
	return abs(r - 2) + abs(c - 2)
print(main())


mat = list((list(map(int, input().strip().split())) for i in range(5)))
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


(line, col) = (0, 0)
for i in range(0, 5):
	pts = input().split(sep=' ')
	if '1' in pts:
		col = pts.index('1') + 1
		line = i + 1
		break
moves = abs(3 - line) + abs(3 - col)
print(moves)


for i in range(5):
	a = input().split()
	for j in range(5):
		if a[j] == '1':
			ans = abs(i - 2) + abs(j - 2)
print(ans)


p = []
for i in range(5):
	p.append(list(map(int, input().split())))
a = -1
b = -1
for i in range(5):
	for j in range(5):
		if p[i][j] == 1:
			a = i
			b = j
print(abs(a - 2) + abs(b - 2))


lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
lst3 = list(map(int, input().split()))
lst4 = list(map(int, input().split()))
lst5 = list(map(int, input().split()))
r = 0
y = 0
x = 0
if 1 in lst1:
	x = 2
	r = lst1.index(1)
	y = abs(2 - r)
if 1 in lst2:
	x = 1
	r = lst2.index(1)
	y = abs(2 - r)
if 1 in lst3:
	x = 0
	r = lst3.index(1)
	y = abs(2 - r)
if 1 in lst4:
	x = 1
	r = lst4.index(1)
	y = abs(2 - r)
if 1 in lst5:
	x = 2
	r = lst5.index(1)
	y = abs(2 - r)
print(y + x)


for a in range(5):
	row = input().split()
	for b in range(5):
		if row[b] == '1':
			print(abs(2 - a) + abs(2 - b))


mat = [1, 2, 3, 4, 5]
for i in range(5):
	arr = input().split()
	mat[i] = list(map(int, arr))
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


a = []
for _ in range(5):
	a.append(list(map(int, input().split())))
c = 0
r = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			c = j
			r = i
			break
print(abs(c - 2) + abs(r - 2))


row_idx = 0
col_idx = 0
for i in range(5):
	row = list(map(int, input().split()))
	try:
		idx = row.index(1)
	except:
		idx = -1
	if idx >= 0:
		row_idx = i
		col_idx = idx
		break
result = abs(2 - row_idx) + abs(2 - col_idx)
print(result)


g = 0
for t in range(5):
	row = list(map(int, input().split()))
	if max(row) == 1:
		g = t + 1
		pos = row.index(1) + 1
rmov = abs(3 - g)
cmov = abs(3 - pos)
print(rmov + cmov)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	S = Scanner.int_list_list(5)
	for x in range(5):
		for y in range(5):
			if S[y][x] == 1:
				print(abs(y - 2) + abs(x - 2))
main()


x = -1
for i in range(5):
	l = input().split()
	if x == -1 and '1' in l:
		(x, y) = (l.index('1'), i)
print(abs(x - 2) + abs(y - 2))


l = []
for c in range(5):
	n = list(map(int, input().split()))
	for (i, k) in enumerate(n):
		if k == 1:
			(r, c_) = (i, c)
print(abs(c_ - 2) + abs(r - 2))


m = []
for i in range(5):
	m.append([int(x) for x in input().split(' ')])
r = 0
while 1 not in m[r]:
	r += 1
c = 0
while 1 != m[r][c]:
	c += 1
print(abs(r - 2) + abs(c - 2))


for i in range(5):
	r = input()
	if '1' in r:
		print(abs(i - 2) + abs(r.index('1') // 2 - 2))


line = 1
while line < 6:
	col = input().replace(' ', '').find('1')
	if col != -1:
		break
	line += 1
col += 1
print(abs(line - 3) + abs(col - 3))


n = []
for i in range(5):
	n.append([int(x) for x in input().split()])
for i in range(5):
	for j in range(5):
		if n[i][j] == 1:
			x = int(i)
			y = int(j)
			break
print(abs(x - 2) + abs(y - 2))


m = 0
for i in range(5):
	a = list(map(int, input().split()))
	for m in range(5):
		if a[m] == 1:
			k = m + 1
			p = i + 1
		m += 1
print(abs(3 - k) + abs(3 - p))


ans = 0
for i in range(5):
	row = input().split()
	if str(1) in row:
		print(abs(row.index(str(1)) - 2) + abs(i - 2))


ans = None
for i in range(5):
	row = list(map(int, input().split()))
	if not ans and 1 in row:
		ans = abs(row.index(1) - 2) + abs(i - 2)
print(ans)


for i in range(5):
	a = input('')
	if '1' in a:
		print(int(abs(2 - i) + abs(2 - a.index('1') / 2)))


for i in range(5):
	list1 = input().split()
	for j in range(5):
		if int(list1[j]) == 1:
			x = j
			y = i
print(abs(2 - x) + abs(2 - y))


M = []
for i in range(5):
	R = [int(x) for x in input().split(' ')]
	M.append(R)
for i in range(5):
	for j in range(5):
		if M[i][j]:
			print(abs(2 - i) + abs(2 - j))
			break
	else:
		continue
	break


a = []
list1 = []
b = []
for i in range(5):
	list1.append(input())
	a.append(list1)
	list1 = []
for i in range(len(a)):
	for j in range(0, len(a[i][0]), 2):
		b.append(int(a[i][0][j:j + 1]))
	a[i] = b
	b = []
for i in range(len(a)):
	for j in range(len(a[0])):
		if a[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


v = []
t = 0
n = 0
s = 0
f = 0
h = 0
l = 0
w = 0
for c in range(5):
	x = [int(z) for z in input().split()]
	for q in x:
		if q == 0 or q == 1:
			if q == 1:
				w = w + 1
		else:
			x.remove(q)
	if len(x) != 5:
		break
	v.append(x)
	l += 1
if l == 5 and w == 1:
	for b in v:
		n = n + 1
		for m in b:
			if m == 1:
				t = n - 1
				s = b.index(m)
	for d in range(2):
		if t < 2:
			t = t + 1
			f = f + 1
		elif t > 2:
			t = t - 1
			f = f + 1
	for g in range(2):
		if s < 2:
			s = s + 1
			h = h + 1
		elif s > 2:
			s = s - 1
			h = h + 1
	print(f + h)


def solve(mat):
	row_mid = 2
	col_mid = 2
	for i in range(5):
		for j in range(5):
			if mat[i][j] == 1:
				row_ind = i
				col_ind = j
	min_mov = abs(row_ind - row_mid) + abs(col_ind - col_mid)
	print(min_mov)
mat = []
for i in range(5):
	l = list(map(int, input().split()))
	mat.append(l)
solve(mat)


import math
a = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(int(math.fabs(j - 2) + math.fabs(i - 2)))
			break


a = input()
b = input()
c = input()
d = input()
e = input()
f = ''
part1 = 0
part2 = 0

def haso(s):
	c = 0
	for i in s.split(' '):
		ii = int(i)
		c += ii
	if c == 1:
		global f
		f = s
	return c
if haso(a) == 1 or haso(e) == 1:
	part1 = 2
elif haso(b) == 1 or haso(d) == 1:
	part1 = 1
haso(c)
if f.split(' ')[0] == '1' or f.split(' ')[4] == '1':
	part2 = 2
elif f.split(' ')[1] == '1' or f.split(' ')[3] == '1':
	part2 = 1
print(str(part1 + part2))


mat = list()
for x in range(5):
	mat.append(input())
for i in range(len(mat)):
	j = mat[i].split(' ')
	if '1' in j:
		print(abs(i + 1 - 3) + abs(j.index('1') + 1 - 3))
		break


(a11, a12, a13, a14, a15) = map(int, input().split(' '))
(a21, a22, a23, a24, a25) = map(int, input().split(' '))
(a31, a32, a33, a34, a35) = map(int, input().split(' '))
(a41, a42, a43, a44, a45) = map(int, input().split(' '))
(a51, a52, a53, a54, a55) = map(int, input().split(' '))
if a33 == 1:
	print('0')
if a23 == 1 or a32 == 1 or a34 == 1 or (a43 == 1):
	print('1')
if a22 + a24 + a42 + a44 + a31 + a53 + a35 + a13 != 0:
	print('2')
if a12 + a14 + a21 + a25 + a41 + a45 + a52 + a54 != 0:
	print('3')
if a11 + a15 + a51 + a55 != 0:
	print('4')


k = 0
m = 0
for i in range(0, 5):
	s = input().split(' ')
	if max(s) == '1':
		k = i + 1
		m = s.index('1') + 1
ans = abs(k - 3) + abs(m - 3)
print(ans)


n = 0
for i in range(5):
	str1 = input()
	str_list = str1.split(' ')
	if '1' in str_list:
		x = str_list.index('1')
		n = abs(x - 2) + abs(i - 2)
print(n)


sqr = []
(o_row, o_col) = (0, 0)
for i in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		o_row = i
		o_col = row.index(1)
	sqr.append(row)
(m_row, m_col) = (2, 2)
r_dis = abs(m_row - o_row)
c_dis = abs(m_col - o_col)
print(r_dis + c_dis)


import math
l1 = input()
l2 = input()
l3 = input()
l4 = input()
l5 = input()
x = 0
y = 1
count = 1
for a in range(9):
	if l1[a] == '1':
		x = count
	if l1[a] != ' ':
		count += 1
if x == 0:
	y += 1
count = 1
for a in range(9):
	if l2[a] == '1':
		x = count
	if l2[a] != ' ':
		count += 1
if x == 0:
	y += 1
count = 1
for a in range(9):
	if l3[a] == '1':
		x = count
	if l3[a] != ' ':
		count += 1
if x == 0:
	y += 1
count = 1
for a in range(9):
	if l4[a] == '1':
		x = count
	if l4[a] != ' ':
		count += 1
if x == 0:
	y += 1
count = 1
for a in range(9):
	if l5[a] == '1':
		x = count
	if l5[a] != ' ':
		count += 1
if x == 0:
	y += 1
print(abs(y - 3) + abs(x - 3))


l = []
for x in range(0, 5):
	w = input().split()
	l.append(w)
for i in range(0, 5):
	for c in range(0, 5):
		if l[i][c] == '1':
			x = i + 1
			y = c + 1
			break
if x == 3:
	x = 0
else:
	x = abs(x - 3)
if y == 3:
	y = 0
else:
	y = abs(y - 3)
print(x + y)


a = []
for i in range(5):
	a.append(list(map(int, input().rstrip().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i
			y = j
			break
diff1 = abs(x - 2)
diff2 = abs(y - 2)
print(diff1 + diff2)


row = 0
col = 0
for i in range(5):
	matrix = input('')
	if '1' in matrix:
		row = i
		col = matrix.replace(' ', '').index('1') % 5
moves = abs(row - 2) + abs(col - 2)
print(moves)


a = []
count = 0
for i in range(5):
	l = list(input().split())
	a.append(l)
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			m = i
			n = j
(i, j) = (m, n)
while True:
	if i == 2 and j == 2:
		break
	elif i < 2:
		i += 1
		count += 1
	elif i > 2:
		i -= 1
		count += 1
	elif j < 2:
		j += 1
		count += 1
	elif j > 2:
		j -= 1
		count += 1
print(count)


for i in range(5):
	t = input()
	if '1' in t:
		print(abs(i + 1 - 3) + abs(t.index('1') // 2 - 2))


def find_one(matrix):
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == '1':
				return abs(i - 2) + abs(j - 2)
matrix = [''] * 5
for i in range(5):
	matrix[i] = input().split()
print(find_one(matrix))


import math
a = []
ind = []
moveUp = False
moveRight = False
x = y = 0
for _ in range(5):
	n = input().split()
	a.append(n)
	if '1' in n:
		ind.append(_)
		ind.append(n.index('1'))
if ind != [2, 2]:
	y = abs(2 - ind[0])
	x = abs(2 - ind[1])
print(x + y)


dist = [2, 1, 0, 1, 2]
for i in range(5):
	s = input()
	if '1' in s:
		print(dist[i] + dist[s.find('1') // 2])


import math
matrix_row = []
row = 0
column = 0
for i in range(5):
	matrix_row.append(input().replace(' ', ''))
for i in range(5):
	for j in matrix_row[i]:
		if j == '1':
			row = i
			column = matrix_row[i].find(j)
			break
print(abs(row - 2) + abs(column - 2))


a = [x for x in input().split()]
b = [x for x in input().split()]
c = [x for x in input().split()]
d = [x for x in input().split()]
e = [x for x in input().split()]
j = 0
k = 0
for i in range(5):
	if a[i] == '1':
		j = 1
		k = i
		break
	elif b[i] == '1':
		j = 2
		k = i
		break
	elif c[i] == '1':
		j = 3
		k = i
		break
	elif d[i] == '1':
		j = 4
		k = i
		break
	elif e[i] == '1':
		j = 5
		k = i
		break
x = abs(3 - j) + abs(2 - k)
print(x)


c = 0
r = 0
for i in range(5):
	l = list(map(int, input().split()))
	for j in range(5):
		if l[j] is 1:
			r = i + 1
			c = j + 1
			break
print(abs(3 - c) + abs(3 - r))


for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		c = l.index(1) + 1
		r = i + 1
		break
print(abs(3 - r) + abs(3 - c))


a = []
x = 0
for i in range(5):
	l = list(map(int, input().split()))
	a.append(l)
	if 1 in l:
		y = 0
		for j in range(len(l)):
			if l[j] == 1:
				y = j
				break
		x = i
		break
print(abs(x - 2) + abs(y - 2))


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

def findit():
	global row, column
	for row in range(0, len(matrix)):
		for column in range(0, len(matrix[row])):
			if matrix[row][column] == 1:
				break
		if matrix[row][column] == 1:
			break
findit()
print(abs(column - 2) + abs(row - 2))


n = 5
a = []
for i in range(n):
	b = []
	for j in range(n):
		c = map(int, input().split())
		b += c
		break
	a.append(b)
s = 0
for i in range(n):
	for j in range(n):
		if a[i][j] == 1:
			a[i][j] = a[i][j] - 1
			a[i][2] += 1
			s += abs(j - 2)
			s += abs(i - 2)
			break
print(s)


b = []

def search(a):
	check = 0
	position = 0
	for j in range(5):
		for i in range(5):
			if b[j][i] == 0:
				check += 1
			else:
				position = check
				break
	return position
for i in range(5):
	a = list(map(int, input().strip().split()))
	b.append(a)
position = search(b)
center = 12
if position == 0:
	print('4')
elif position == 1:
	print('3')
elif position == 2:
	print('2')
elif position == 3:
	print('3')
elif position == 4:
	print('4')
elif position == 5:
	print('3')
elif position == 6:
	print('2')
elif position == 7:
	print('1')
elif position == 8:
	print('2')
elif position == 9:
	print('3')
elif position == 10:
	print('2')
elif position == 11:
	print('1')
elif position == 12:
	print('0')
elif position == 13:
	print('1')
elif position == 14:
	print('2')
elif position == 15:
	print('3')
elif position == 16:
	print('2')
elif position == 17:
	print('1')
elif position == 18:
	print('2')
elif position == 19:
	print('3')
elif position == 20:
	print('4')
elif position == 21:
	print('3')
elif position == 22:
	print('2')
elif position == 23:
	print('3')
elif position == 24:
	print('4')


_2d = []
for i in range(5):
	array = list(map(int, input().split()))
	_2d.append(array)
for i in range(5):
	for j in range(5):
		if _2d[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))


for i in range(5):
	row = input().split()
	if '1' in row:
		index = row.index('1') + 1
		index1 = i + 1
print(abs(3 - index) + abs(3 - index1))


numbers = []
n1 = list(map(int, input().split()))
numbers.extend(n1)
n2 = list(map(int, input().split()))
numbers.extend(n2)
n3 = list(map(int, input().split()))
numbers.extend(n3)
n4 = list(map(int, input().split()))
numbers.extend(n4)
n5 = list(map(int, input().split()))
numbers.extend(n5)
p = numbers.index(1) + 1
if p == 13:
	print('0')
elif p == 8 or p == 12 or p == 14 or (p == 18):
	print('1')
elif p == 3 or p == 7 or p == 11 or (p == 17) or (p == 23) or (p == 19) or (p == 15) or (p == 9):
	print('2')
elif p == 2 or p == 6 or p == 4 or (p == 10) or (p == 22) or (p == 16) or (p == 20) or (p == 24):
	print('3')
else:
	print('4')


M = []
t = 0
for i in range(0, 5):
	s = [int(x) for x in input().split()]
	M.append(s)
	if 1 in s:
		t += abs(i - 2)
	for i in range(0, 5):
		if s[i] == 1:
			t += abs(i - 2)
print(t)


(i, j) = (0, 0)
for y in range(5):
	x = input().split()
	if '1' in x:
		(i, j) = (y, x.index('1'))
print(abs(2 - i) + abs(2 - j))


num = 0
for i in range(5):
	m = map(int, input().split())
	x = 0
	for (j, element) in enumerate(m):
		if element:
			num = abs(j - 2)
			num += abs(i - 2)
print(num)


a = []
for i in range(5):
	b = list(map(int, input().split()))
	a.append(b)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			(c, d) = (i, j)
			break
if c != 2:
	x = abs(2 - c)
else:
	x = 0
if d != 2:
	y = abs(2 - d)
else:
	y = 0
print(x + y)


matrix = []
t_matrix = []
current_row = 0
current_column = 0
for row in range(5):
	matrix.append([])
	matrix[row].extend(list(map(int, input().split())))
	if sum(matrix[row]) == 1:
		current_row = row + 1
t_matrix = [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]
for column in range(5):
	if sum(t_matrix[column]) == 1:
		current_column = column + 1
output = abs(current_row - 3) + abs(current_column - 3)
print(output)


for i in range(5):
	s = input()
	if '1' in s:
		print(abs(i - 2) + abs(s.find('1') // 2 - 2))


l = []
for i in range(5):
	a = input().split(' ')
	l.append(a)
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))


for i in range(5):
	x = list(map(int, input().split()))
	if 1 in x:
		(a, b) = (i, x.index(1))
c = 0
if a == 2 and b == 2:
	print(0)
else:
	while 1:
		if a != 2:
			if a > 2:
				a = a - 1
			else:
				a = a + 1
			c += 1
		if b != 2:
			if b > 2:
				b = b - 1
			else:
				b = b + 1
			c += 1
		if a == 2 and b == 2:
			print(c)
			break


a = []
for i in range(5):
	b = [int(j) for j in input().split()]
	a.append(b)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			temp = abs(i - 2) + abs(j - 2)
			break
print(temp)


a = [[], [], [], [], []]
for i in range(5):
	a[i].extend(map(int, input().split()))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			r = i
			c = j
print(abs(r - 2) + abs(c - 2))


m = []
n = 1
while n < 6:
	a = [int(i) for i in input().split()]
	for i in range(5):
		if a[i] == 1:
			x = i + 1
			y = n
			break
	m.append(a)
	n += 1
print(abs(x - 3) + abs(y - 3))


matrix = []
for i in range(0, 5):
	matrix.append(input())
for m in range(0, 5):
	n = matrix[m].find('1')
	if n != -1:
		print(abs(m - 2) + abs(int(n / 2) - 2))


row = 0
col = 0
for i in range(5):
	num = list(map(int, input().split()))
	for j in range(5):
		if num[j]:
			row = abs(2 - i)
			col = abs(2 - j)
print(row + col)


ans = 0
for i in range(5):
	a = ''.join(input().split())
	if a.find('1') > -1:
		ans = abs(i - 2) + abs(a.find('1') - 2)
print(ans)


a = []
ans = None
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			ans = abs(i - 2) + abs(j - 2)
			break
	if ans:
		break
print(ans)


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))

def findIndex(rowNum, row):
	for value in rowNum:
		if value == 1:
			colm = rowNum.index(1) + 1
			rw = row
			return (colm, rw)
	return ('None', row)
(c1, row1) = findIndex(r1, 1)
(c2, row2) = findIndex(r2, 2)
(c3, row3) = findIndex(r3, 3)
(c4, row4) = findIndex(r4, 4)
(c5, row5) = findIndex(r5, 5)
if c1 != 'None':
	print(abs(3 - row1) + abs(c1 - 3))
if c2 != 'None':
	print(abs(3 - row2) + abs(c2 - 3))
if c3 != 'None':
	print(abs(3 - row3) + abs(c3 - 3))
if c4 != 'None':
	print(abs(3 - row4) + abs(c4 - 3))
if c5 != 'None':
	print(abs(3 - row5) + abs(c5 - 3))


import math
import os
import sys
import re
import itertools
import functools
import operator
A = [[None] * 5 for _ in range(5)]
for i in range(5):
	A[i] = map(int, input().split())
for (i, s) in enumerate(A):
	for (j, el) in enumerate(s):
		if el == 1:
			print(abs(i - 2) + abs(j - 2))
			quit()


m = 5
n = 5
matrix = []
b = 0
c = 0
for i in range(n):
	a = input().split()
	matrix.append(a)
for i in range(n):
	for j in range(m):
		if matrix[i][j] == '1':
			b = b + abs(2 - i)
			c = c + abs(2 - j)
print(b + c)


l = []
for i in range(5):
	l.append(input().split())
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			a = i + 1
			b = j + 1
			break
if a > 3:
	a = a - 3
else:
	a = 3 - a
if b > 3:
	b = b - 3
else:
	b = 3 - b
print(a + b)


matrix = []
char = '1'
count = 0
i = 0
j = 0
for k in range(0, 5):
	row = input().split()
	matrix.append(row)
for sub_list in matrix:
	if char in sub_list:
		i = matrix.index(sub_list)
		j = sub_list.index(char)
if i in range(2):
	count = 2 - i
else:
	count = i - 2
if j in range(2):
	count = count + (2 - j)
else:
	count = count + (j - 2)
print(count)


x = 0
y = 0
flag = False
for i in range(0, 5):
	row = input().split(sep=' ')
	for j in range(0, 5):
		if row[j] == '1':
			x = i + 1
			y = j + 1
			break
		pass
	pass
res = abs(3 - x) + abs(3 - y)
print(res)


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
if c[2] == 1:
	print(0)
elif b[2] or c[1] or c[3] or (d[2] == 1):
	print(1)
elif a[2] or b[1] or b[3] or c[0] or c[4] or d[1] or d[3] or (e[2] == 1):
	print(2)
elif a[1] or a[3] or b[0] or b[4] or d[0] or d[4] or e[1] or (e[3] == 1):
	print(3)
elif a[0] or a[4] or e[0] or (e[4] == 1):
	print(4)


r1 = [int(x) for x in input().split()]
r2 = [int(x) for x in input().split()]
r3 = [int(x) for x in input().split()]
r4 = [int(x) for x in input().split()]
r5 = [int(x) for x in input().split()]
m = [r1, r2, r3, r4, r5]
for i in range(0, 5):
	if sum(m[i]) == 1:
		for j in range(0, 5):
			if m[i][j] == 1:
				print(abs(i - 2) + abs(j - 2))
				break


a = [0, 0, 0, 0, 0]
for i in range(5):
	a[i] = list(map(int, input().split()))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			(m, n) = (i, j)
			break
print(abs(2 - m) + abs(2 - n))


for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			print(abs(2 - j) + abs(2 - i))
			import sys
			sys.exit()


n = 5
m = 5
l = []
xo = 0
yo = 0
for i in range(n):
	row = [int(x) for x in input().split(' ')]
	l.append(row)
for row in range(n):
	for colomn in range(m):
		if l[row][colomn] == 1:
			yo = row
			xo = colomn
print(abs(xo - 2) + abs(yo - 2))


def findOne():
	for i in range(5):
		in_str = input().split()
		for j in range(5):
			if int(in_str[j]):
				return (abs(i - 2), abs(j - 2))
print(sum(findOne()))


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
for i in range(5):
	for j in matrix[i]:
		if j == 1:
			if i == 2:
				if matrix[i].index(j) == 2:
					print(0)
				elif matrix[i].index(j) == 1 or matrix[i].index(j) == 3:
					print(1)
				else:
					print(2)
			elif i == 1 or i == 3:
				if matrix[i].index(j) == 2:
					print(1)
				elif matrix[i].index(j) == 1 or matrix[i].index(j) == 3:
					print(2)
				else:
					print(3)
			elif matrix[i].index(j) == 2:
				print(2)
			elif matrix[i].index(j) == 1 or matrix[i].index(j) == 3:
				print(3)
			else:
				print(4)


done = False
for i in range(5):
	a = list(input().split())
	a = [int(x) for x in a]
	for j in range(len(a)):
		if a[j] == 1:
			print(abs(i - 2) + abs(j - 2))
			done = True
			break
	if done == True:
		break


i = 0
j = 0
for u in range(1, 6):
	n = [int(_) for _ in input().split()]
	if 1 in n:
		i = u
		j = n.index(1) + 1
		break
print(abs(3 - i) + abs(3 - j))


i = 0
l = []
for _ in range(5):
	l1 = []
	for x in input().split():
		l1.append(int(x))
		if x == '1':
			i = _
	l.append(l1)
j = l[i].index(1)
c = 0
c += abs(3 - (j + 1))
c += abs(3 - (i + 1))
print(c)


for n in range(0, 5):
	row = input().split()
	for i in range(0, 5):
		if row[i] == '1':
			columna = i
			fila = n
moves = abs(columna - 2) + abs(fila - 2)
print(moves)


M = [[int(j) for j in input().split()] for i in range(5)]
for i in range(len(M)):
	for j in range(len(M[i])):
		if M[i][j] == 1:
			one = [i, j]
print(abs(2 - one[0]) + abs(2 - one[1]))


mat = [input().strip().split(' ') for _ in range(5)]
r = -1
c = -1
for (i, row) in enumerate(mat):
	if '1' in row:
		r = i
		c = row.index('1')
		break
print(abs(r - 2) + abs(c - 2))


op = 1
for i in range(5):
	r = input()
	j = r.find('1')
	if j == -1:
		continue
	j //= 2
	op = abs(i - 2) + abs(j - 2)
print(op)


a = []
b = []
c = [3, 3]
for i in range(5):
	for i in [input().split()]:
		a.append(i)
	print()
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			b = b + [i + 1, j + 1]
if c[0] - b[0] >= 0:
	z = c[0] - b[0]
else:
	z = b[0] - c[0]
if c[1] - b[1] >= 0:
	x = c[1] - b[1]
else:
	x = b[1] - c[1]
print(x + z)


(l, pos, row) = ([], None, 0)

def custom_int(x: str):
	global row, col, pos
	if x == '1':
		pos = [row, col]
	col += 1
	return int(x)
for i in range(5):
	col = 0
	l.append(list(map(custom_int, input().split(' '))))
	row += 1
print(abs(pos[0] - 2) + abs(pos[1] - 2))


def main():
	(pos_r, pos_c) = (2, 2)
	for i in range(5):
		a = input().split()
		for j in range(len(a)):
			if i == 2 and j == 2:
				continue
			if a[j] == '1':
				pos_c = j
				pos_r = i
				break
	distance = abs(2 - pos_c) + abs(2 - pos_r)
	print(distance)
main()


matrix = []
for i in range(5):
	matrix += [[int(n) for n in input().strip().split()]]
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			row = i
			column = j
			break
		else:
			pass
moves = 0
while row != 2:
	if row < 2:
		row += 1
		moves += 1
	elif row > 2:
		row -= 1
		moves += 1
while column != 2:
	if column < 2:
		column += 1
		moves += 1
	elif column > 2:
		column -= 1
		moves += 1
print(moves)


mat = []
for i in range(5):
	tmp = input().split()
	mat.append([int(j) for j in tmp])
mid = 3
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			print(abs(i + 1 - mid) + abs(j + 1 - mid))


for i in range(1, 6):
	m = list(map(int, input().split(' ')))
	if 1 in m:
		moves = abs(i - 3) + abs(m.index(1) + 1 - 3)
		print(moves)
		break


import math
matrix = []
for _ in range(5):
	matrix.extend(input().split(' '))
if (matrix.index('1') + 1) % 5 == 0:
	print(abs(math.ceil((matrix.index('1') + 1) / 5) - 3) + 2)
else:
	print(abs(math.ceil((matrix.index('1') + 1) / 5) - 3) + abs((matrix.index('1') + 1) % 5 - 3))


(a, b) = (0, 0)
for i in range(5):
	s = input().split()
	if '1' in s:
		a = i
		b = s.index('1')
print(abs(2 - a) + abs(2 - b))


ans = 0
for i in range(5):
	line = input().split()
	if '1' in line:
		ans = abs(i - 2) + abs(line.index('1') - 2)
print(ans)


l = []
for i in range(5):
	m = list(map(int, input().split()))
	l.append(m)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			row = i + 1
			col = j + 1
rowcount = 0
colcount = 0
while row != 3:
	if row < 3:
		row += 1
		rowcount += 1
	else:
		row -= 1
		rowcount += 1
while col != 3:
	if col < 3:
		col += 1
		colcount += 1
	else:
		col -= 1
		colcount += 1
print(rowcount + colcount)


a = []
l = 0
m = 0
for i in range(5):
	b = input()
	a.append(b)
	b = b.split()
	if '1' in b:
		l = i + 1
		m = b.index('1') + 1
print(abs(l - 3) + abs(m - 3))


arr = []
x = None
y = None
for i in range(5):
	arr.append([x for x in input().split()])
	if '1' in arr[i]:
		x = i
		y = arr[i].index('1')
print(abs(int(x) - 2) + abs(int(y) - 2))


ans = 0
for row in range(1, 6):
	columns = input().split(' ')
	for (indx, col) in enumerate(columns):
		if col == '1':
			ans = abs(3 - (indx + 1)) + abs(3 - row)
print(ans)


for i in range(5):
	ar = list(map(int, input().split()))
	for j in range(5):
		if ar[j] == 1:
			print(abs(2 - i) + abs(2 - j))
			exit


m = []
for i in range(5):
	l = list(input().split())
	m.append(l)
j = 0
for count in m:
	try:
		i = count.index('1')
		break
	except:
		pass
	j += 1
print(abs(2 - i) + abs(2 - j))


a = []
l = 0
m = 0
for i in range(5):
	a.append(list(map(int, input().split())))
	if 1 in a[i]:
		l = i
		m = a[i].index(1)
print(abs(l - 2) + abs(m - 2))


for i in range(5):
	inp = input().split(' ')
	if '1' in inp:
		ind = inp.index('1')
		answer = abs(2 - i) + abs(2 - ind)
		print(answer)
		break


(a, b) = (0, 0)
for i in range(5):
	(c1, c2, c3, c4, c5) = map(int, input().split(' '))
	lst = [c1, c2, c3, c4, c5]
	if sum(lst) == 1:
		a = i + 1
		b = lst.index(1) + 1
print(abs(a - 3) + abs(b - 3))


def isBeautiful(arr):
	for (i, num) in enumerate(arr):
		for (j, nums) in enumerate(num):
			if arr[i][j] == 1:
				val = abs(3 - (i + 1)) + abs(3 - (j + 1))
				return val
arr = []
for i in range(5):
	arr.append(list(map(int, input().rstrip().split())))
print(isBeautiful(arr))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
x = 0
y = 0
erg = 0
if a.count('1') == 1:
	y = a.index('1') + 1
	erg = abs(3 - y) + 2
elif b.count('1') == 1:
	y = b.index('1') + 1
	erg = abs(3 - y) + 1
elif c.count('1') == 1:
	y = c.index('1') + 1
	erg = abs(3 - y) + 0
elif d.count('1') == 1:
	y = d.index('1') + 1
	erg = abs(3 - y) + 1
elif e.count('1') == 1:
	y = e.index('1') + 1
	erg = abs(3 - y) + 2
print(erg)


list = [2, 1, 0, 1, 2]
for i in list:
	a = input()
	if '1' in a:
		print(i + list[a.find('1') // 2])


for i in range(5):
	row = input().replace(' ', '')
	col = row.find('1')
	if col != -1:
		print(abs(2 - i) + abs(2 - col))
		break


for i in range(5):
	row = list(map(int, input().split()))
	if sum(row):
		position = (i, row.index(1))
print(abs(position[0] - 2) + abs(position[1] - 2))


for i in range(5):
	try:
		print(abs(2 - i) + abs(2 - input().split().index('1')))
	except:
		pass


import math as m
(b1, b2) = (0, 0)
for i in range(5):
	a = list(input().split())
	for j in range(5):
		if a[j] == '1':
			b1 = i
			b2 = j
			break
	if b1 != 0:
		break
print(int(m.fabs(2 - b1) + m.fabs(2 - b2)))


def Find_1(X, Y, Arrays):
	for R in range(Y):
		for C in range(X):
			if Arrays[R][C]:
				return (C + 1, R + 1)
X = 5
Y = 5
Lists = [[0] * X] * Y
for I in range(Y):
	Lists[I] = list(map(int, input().split()))
(X_1, Y_1) = Find_1(X, Y, Lists)
Key = (X + Y) // 4 + (X + Y) // 2 % 2
print(abs(max(Key, X_1) - min(Key, X_1) + max(Key, Y_1) - min(Key, Y_1)))


arr = [list(map(int, input().split())) for i in range(5)]
for i in range(len(arr)):
	for j in range(len(arr[i])):
		if arr[i][j]:
			(a, b) = (i + 1, j + 1)
			break
step = 0
while not (a == 3 and b == 3):
	if a > 3:
		a -= 1
		step += 1
	elif a < 3:
		a += 1
		step += 1
	if b > 3:
		b -= 1
		step += 1
	elif b < 3:
		b += 1
		step += 1
print(step)


M = []
for i in range(0, 5):
	M.append(list(map(int, input().split())))
H = 0
W = 0
for i in range(0, 5):
	for j in range(0, 5):
		if M[i][j] == 1:
			H = i
			W = j
			break
print(abs(H - 2) + abs(W - 2))


a = [[int(j) for j in input().split()] for i in range(5)]
ind = 0
for i in range(len(a)):
	if 1 in a[i]:
		ind = a[i].index(1)
		break
print(abs(i - 2) + abs(ind - 2))


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().rstrip().split())))
swaps = 0
if 1 in matrix[0] or 1 in matrix[4]:
	swaps += 2
elif 1 in matrix[1] or 1 in matrix[3]:
	swaps += 1
for i in matrix:
	if i[0] == 1 or i[4] == 1:
		swaps += 2
	elif i[1] == 1 or i[3] == 1:
		swaps += 1
print(swaps)


def getInput():
	for i in range(1, 5 + 1):
		row = [int(x) for x in input().split()]
		for j in range(len(row)):
			if row[j] == 1:
				return (i, j + 1)

def solve():
	loc = getInput()
	print(abs(loc[0] - 3) + abs(loc[1] - 3))
	return
solve()


mat = []
count = 0
for i in range(5):
	mat.append(list(map(int, input().strip().split()))[:5])
current_row = current_col = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			current_col = j
			current_row = i
move_row = abs(2 - current_row)
move_col = abs(2 - current_col)
print(move_col + move_row)


row = 0
ins = []
col = 0
for i in range(5):
	temp_row = list(map(int, input().split()))
	if sum(temp_row) == 1:
		row = i
		for j in range(5):
			if temp_row[j] == 1:
				col = j
	ins.append(temp_row)
move = abs(col - 2) + abs(row - 2)
print(move)


lst = list()
for j in range(5):
	data = input()
	for i in data.split():
		lst.append(int(i))
z = lst.index(1) + 1
y = z % 5
if z <= 5:
	ver = 2
elif z > 5 and z <= 10:
	ver = 1
elif z > 10 and z <= 15:
	ver = 0
elif z > 15 and z <= 20:
	ver = 1
elif z > 20:
	ver = 2
if y == 0 or y == 1:
	hor = 2
elif y == 2 or y == 4:
	hor = 1
elif y == 3:
	hor = 0
print(hor + ver)


c = []
n = ''
for i in range(5):
	x = input()
	x = x.replace(' ', '')
	c.append(x)
	if '1' in x:
		n += '1'
	else:
		n += '0'
row = int(n.find('1'))
col = int(c[row].find('1'))
print(abs(3 - col - 1) + abs(3 - row - 1))


import math
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()))
M = A + B + C + D + E
l = [M.index(1) + 1 - (M.index(1) + 1 - 0.01) // 5 * 5, math.ceil((M.index(1) + 1) / 5)]
print(int(abs(l[0] - 3)) + abs(l[1] - 3))


(cx, cy) = (0, 0)
for i in range(5):
	line = ''.join(input().split())
	for j in range(5):
		if line[j] == '1':
			(cy, cx) = (i, j)
print(abs(cx - 2) + abs(cy - 2))


d = 0
for i in range(5):
	inputs = input().split(' ')
	for j in range(len(inputs)):
		inputs[j] = int(inputs[j])
		if inputs[j] == 1:
			d = abs(3 - (i + 1)) + abs(3 - (j + 1))
print(d)


i1 = list(map(int, input().split()))
i2 = list(map(int, input().split()))
i3 = list(map(int, input().split()))
i4 = list(map(int, input().split()))
i5 = list(map(int, input().split()))
c = 0
for i in i1:
	if i == 1:
		r = 1
		col = c
	c = c + 1
c = 0
for i in i2:
	if i == 1:
		r = 2
		col = c
	c = c + 1
c = 0
for i in i3:
	if i == 1:
		r = 3
		col = c
	c = c + 1
c = 0
for i in i4:
	if i == 1:
		r = 4
		col = c
	c = c + 1
c = 0
for i in i5:
	if i == 1:
		r = 5
		col = c
	c = c + 1
col = col + 1
print(abs(col - 3) + abs(r - 3))


def solution(i, j):
	return abs(3 - j) + abs(3 - i)
for k in range(5):
	line = input().split(' ')
	if '1' in line:
		j = -1
		for v in line:
			j += 1
			if v == '1':
				break
		print(solution(k + 1, j + 1))
		break


a = []
for i in range(5):
	t = list(map(int, input().split(' ')))
	a.append(t)
	t = []
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i + 1
			y = j + 1
x = 3 - x
y = 3 - y
s = abs(x) + abs(y)
print(s)


i = 5
while i > 0:
	matrixLine = [int(x) for x in input().split(' ')]
	if 1 in matrixLine:
		oneX = matrixLine.index(1) + 1
		oneY = i
		xDiff = abs(3 - oneX)
		yDiff = abs(3 - oneY)
		print(xDiff + yDiff)
		break
	i = i - 1


a = input()
b = input()
c = input()
d = input()
e = input()
list = [a, b, c, d, e]
for i in range(5):
	for j in range(9):
		if list[i][j] == '1':
			print(abs(i - 2) + abs((j + 2) // 2 - 3))


count_prob = 5
lst = []
for i in range(count_prob):
	lst.append([int(a) for a in input().split()])
for i in range(5):
	for j in range(5):
		if lst[i][j] == 1:
			moves = abs(i - 2) + abs(j - 2)
			break
print(moves)


l = list()
l1 = [int(x) for x in input().split()]
l.append(l1)
l1 = [int(x) for x in input().split()]
l.append(l1)
l1 = [int(x) for x in input().split()]
l.append(l1)
l1 = [int(x) for x in input().split()]
l.append(l1)
l1 = [int(x) for x in input().split()]
l.append(l1)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
			break


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
if 1 in l1:
	if l1.index(1) >= 2:
		print(l1.index(1))
	else:
		print(4 - l1.index(1))
elif 1 in l2:
	if l2.index(1) >= 2:
		print(l2.index(1) - 1)
	else:
		print(3 - l2.index(1))
elif 1 in l3:
	if l3.index(1) >= 2:
		print(l3.index(1) - 2)
	else:
		print(2 - l3.index(1))
elif 1 in l4:
	if l4.index(1) >= 2:
		print(l4.index(1) - 1)
	else:
		print(3 - l4.index(1))
elif 1 in l5:
	if l5.index(1) >= 2:
		print(l5.index(1))
	else:
		print(4 - l5.index(1))


l = []
for _ in range(5):
	l.append(list(map(int, input().split())))
(a, b) = (0, 0)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			(a, b) = (i, j)
			break
s = 0
s += abs(a - 2) + abs(b - 2)
print(s)


t = 5
l1 = []
c = r = b = 0
for i in range(t):
	l = list(map(int, input().split()))
	if 1 in l:
		c = l.index(1)
		r = i
	l1.append(l)
b = abs(c - 2) + abs(r - 2)
print(b)


def solve(mat):
	min_dist = 100
	for i in range(5):
		for j in range(5):
			if mat[i][j] == 1:
				dist = abs(i - 2) + abs(j - 2)
				min_dist = min(min_dist, dist)
	return min_dist
mat = []
for i in range(5):
	vect = list(map(int, input().rstrip().split()))
	mat.append(vect)
res = solve(mat)
print(res)


flag = False
for i in range(5):
	line = list(map(int, input().split(' ')))
	for j in range(5):
		if line[j] == 1:
			col = j + 1
			row = i + 1
print(abs(3 - row) + abs(3 - col))


matrix = []
for i in range(5):
	arr = input().split()
	matrix.append(arr)
row = 0
column = 0
for i in range(0, 5):
	for j in range(0, 5):
		if int(matrix[i][j]) == 1:
			column = j
			row = i
			break
	else:
		row = row + 1
		continue
	break
res = abs(row - 2) + abs(column - 2)
print(res)


import math
(row, col) = (0, 0)
for i in range(5):
	ss = input().find('1')
	if ss != -1:
		row = i + 1
		col = ss / 2 + 1
print(int(abs(row - 3) + abs(col - 3)))


for i in range(1, 6):
	l = [int(i) for i in input().split()]
	if 1 in l:
		k = l.index(1) + 1
		ind = i
		break
print(abs(3 - k) + abs(3 - ind))


table = []
for i in range(5):
	k = input().split()
	for j in range(5):
		if int(k[j]) == 1:
			ans = [i + 1, j + 1]
print(abs(ans[0] - 3) + abs(ans[1] - 3))


c = 5
while c:
	p = input().replace(' ', '')
	p = p.find('1')
	if p != -1:
		print(abs(c - 3) + abs(p - 2))
	c = c - 1


def solve():
	(r, c, flag) = (0, 0, 0)
	matrix = []
	for i in range(5):
		a = list(map(int, input().split()))
		matrix.append(a)
	for i in range(5):
		if flag == 0:
			for j in range(5):
				if matrix[i][j] == 1:
					r = i + 1
					c = j + 1
					flag = 1
					break
	print(abs(r - 3) + abs(c - 3))
solve()


(a, b) = (0, 0)
for x in range(5):
	s = input().split()
	for y in range(5):
		if s[y] == '1':
			a = x + 1
			b = y + 1
			break
print(abs(a - 3) + abs(b - 3))


matrix = []
flag = 0
for i in range(5):
	matrix.append([int(j) for j in input().split()])
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			flag = 1
			break
	if flag == 1:
		break
print(abs(i - 2) + abs(j - 2))


for i in range(5):
	x = input()
	if '1' in x:
		print(abs(2 - i) + int(abs(4 - x.find('1')) / 2))
		break


row_1 = input().split()
row_2 = input().split()
row_3 = input().split()
row_4 = input().split()
row_5 = input().split()
if '1' in row_1:
	if row_1.index('1') == 0 or row_1.index('1') == 4:
		count = 4
	elif row_1.index('1') == 2:
		count = 2
	else:
		count = 3
if '1' in row_2:
	if row_2.index('1') == 0 or row_2.index('1') == 4:
		count = 3
	elif row_2.index('1') == 2:
		count = 1
	else:
		count = 2
if '1' in row_3:
	if row_3.index('1') == 0 or row_3.index('1') == 4:
		count = 2
	elif row_3.index('1') == 2:
		count = 0
	else:
		count = 1
if '1' in row_4:
	if row_4.index('1') == 0 or row_4.index('1') == 4:
		count = 3
	elif row_4.index('1') == 2:
		count = 1
	else:
		count = 2
if '1' in row_5:
	if row_5.index('1') == 0 or row_5.index('1') == 4:
		count = 4
	elif row_5.index('1') == 2:
		count = 2
	else:
		count = 3
print(count)


import sys
from copy import copy
x = y = 0
for i in range(5):
	a = input().split()
	if '1' in a:
		x = a.index('1') + 1
		y = i + 1
		break
print(abs(3 - x) + abs(3 - y))


import sys
icount = 0
l1 = sys.stdin.readline().replace(' ', '')
l2 = sys.stdin.readline().replace(' ', '')
l3 = sys.stdin.readline().replace(' ', '')
l4 = sys.stdin.readline().replace(' ', '')
l5 = sys.stdin.readline().replace(' ', '')
if '1' in l1:
	icount = 1
	jcount = l1.index('1')
elif '1' in l2:
	icount = 2
	jcount = l2.index('1')
elif '1' in l3:
	icount = 3
	jcount = l3.index('1')
elif '1' in l4:
	icount = 4
	jcount = l4.index('1')
elif '1' in l5:
	icount = 5
	jcount = l5.index('1')
jcount += 1
minMoves = abs(jcount - 3) + abs(icount - 3)
print(minMoves)


for i in range(1, 6):
	n = input().replace(' ', '')
	if '1' in n:
		k = abs(3 - i) + abs(2 - n.find('1'))
print(k)


k1 = input()
k2 = input()
k3 = input()
k4 = input()
k5 = input()
k1 = k1.split()
k2 = k2.split()
k3 = k3.split()
k4 = k4.split()
k5 = k5.split()
a = 0
b = 0

def nice(a, b):
	if a == 1:
		if b == 1 or b == 5:
			print(4)
		elif b == 2 or b == 4:
			print(3)
		else:
			print(2)
	elif a == 2:
		if b == 1 or b == 5:
			print(3)
		elif b == 2 or b == 4:
			print(2)
		else:
			print(1)
	elif b == 1 or b == 5:
		print(2)
	elif b == 2 or b == 4:
		print(1)
	else:
		print(0)
for element in range(5):
	if k1[element] == '1':
		a = 1
		b = element + 1
for element in range(5):
	if k2[element] == '1':
		a = 2
		b = element + 1
for element in range(5):
	if k3[element] == '1':
		a = 3
		b = element + 1
for element in range(5):
	if k4[element] == '1':
		a = 2
		b = element + 1
for element in range(5):
	if k5[element] == '1':
		a = 1
		b = element + 1
nice(a, b)


class CodeforcesTask263ASolution:

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

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

	def process_task(self):
		x = 1
		posx = 0
		posy = 0
		for row in self.matrix:
			if 1 in row:
				posy = x
				posx = row.index(1) + 1
			x += 1
		self.result = str(abs(3 - posx) + abs(3 - posy))

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


for i in range(5):
	s = input().split()
	if '1' in s:
		t = s.index('1')
		t = abs(t - 2) + abs(i - 2)
print(t)


for i in range(5):
	l = [int(x) for x in input().split()]
	for j in range(5):
		if l[j] == 1:
			pos = [i, j]
print(abs(pos[0] - 2) + abs(pos[1] - 2))


import string, re
for i in range(5):
	list1 = input().split()
	if '1' in list1:
		print(abs(2 - i) + abs(2 - list1.index('1')))


ls = list()
for i in range(5):
	ls.append(input())
for i in range(5):
	if '1' in ls[i]:
		c = abs(2 - i)
		l = ls[i].find('1') // 2
		r = abs(2 - l)
print(c + r)


import math
from collections import *
import sys
from functools import reduce

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

def get_list():
	return list(get_ints())

def getlistofstring():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
matr = []
for i in range(5):
	matr.append(get_list())
for i in range(5):
	for j in range(5):
		if matr[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))
			break


for i in range(5):
	j = list(input().split())
	if '1' in j:
		k = j.index('1')
		a = max(i - 2, 2 - i)
		b = max(k - 2, 2 - k)
		print(a + b)


matrix = []
for i in range(5):
	l = list(map(int, input().strip().split(' ')))
	matrix.append(l)
(x, y) = (0, 0)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			x = i
			y = j
			break
print(abs(2 - x) + abs(2 - y))


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()))
if a[0] == 1 or a[4] == 1 or e[0] == 1 or (e[4] == 1):
	print(4)
if a[1] == 1 or a[3] == 1 or b[0] == 1 or (d[0] == 1) or (e[1] == 1) or (e[3] == 1) or (b[4] == 1) or (d[4] == 1):
	print(3)
if a[2] == 1 or b[1] == 1 or b[3] == 1 or (d[1] == 1) or (d[3] == 1) or (e[2] == 1) or (c[0] == 1) or (c[4] == 1):
	print(2)
if b[2] == 1 or d[2] == 1 or c[1] == 1 or (c[3] == 1):
	print(1)
if c[2] == 1:
	print(0)


(n, m) = (0, 0)
for i in range(5):
	line = list(map(int, input().split()))
	if 1 in line:
		(n, m) = (i, line.index(1))
		break
print(abs(2 - m) + abs(2 - n))


(uno_i, uno_j) = (0, 0)
output = 0
for i in range(5):
	v = list(map(int, input().split()))
	for j in range(5):
		if v[j] == 1:
			uno_i = i
			uno_j = j
print(abs(uno_i - 2) + abs(uno_j - 2))


for i in range(0, 5):
	l = list(map(int, input().split()))
	for j in range(0, 5):
		if l[j] == 1:
			result = abs(2 - i) + abs(2 - j)
print(result)


x = 0
y = 0
for s in range(1, 6):
	arr = [int(i) for i in input().split()]
	for j in range(5):
		if arr[j] == 1:
			x = s
			y = j + 1
print(abs(3 - x) + abs(3 - y))


j = 0
i = 0
for k in range(5):
	x = input()
	x = list(map(int, x.split()))
	if 1 in x:
		i = k
		j = x.index(1)
print(abs(2 - j) + abs(2 - i))


(l, i, j) = ([], 0, 0)
for i in range(5):
	l.append(input('').split(' '))
for r in l:
	if '1' in r:
		(i, j) = (l.index(r) + 1, r.index('1') + 1)
print(abs(3 - j) + abs(3 - i))


z = []
for _ in range(5):
	z.append(list(map(int, input().split())))
for i in z:
	if 1 in i:
		count = abs(2 - i.index(1)) + abs(2 - z.index(i))
print(count)


a = [[]]
for j in range(1, 6):
	(a1, a2, a3, a4, a5) = input().split()
	a.append([0, int(a1), int(a2), int(a3), int(a4), int(a5)])
for j in range(1, 6):
	for i in range(1, 6):
		if a[j][i] == 1:
			(J, I) = (j, i)
print(abs(J - 3) + abs(I - 3))


array = []
for i in range(5):
	row = input().split()
	array.append(row)
for i in range(5):
	for j in range(5):
		if array[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))
			break


a = b = 0
for i in range(5):
	s = list(map(int, input().split()))
	for j in range(5):
		if s[j]:
			a = i
			b = j
print(abs(2 - a) + abs(2 - b))


z = []
x = 0
y = 0
p = 0
q = 0
for i in range(5):
	a = list(map(int, input().split()))
	z.append(a)
while z[p][q] != 1:
	x += 1
	q += 1
	if q % 5 == 0:
		p += 1
		q = 0
t = x + 1
while t < 11:
	t += 5
	y += 1
while t > 15:
	t -= 5
	y += 1
while t < 13:
	t += 1
	y += 1
while t > 13:
	t -= 1
	y += 1
print(y)


moves = 0
r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))
col1 = [r1[0], r2[0], r3[0], r4[0], r5[0], r1[4], r2[4], r3[4], r4[4], r5[4]]
col2 = [r1[1], r2[1], r3[1], r4[1], r5[1], r1[3], r2[3], r3[3], r4[3], r5[3]]
if 1 in r1 or 1 in r5:
	moves += 2
if 1 in r2 or 1 in r4:
	moves += 1
if 1 in col1:
	moves += 2
if 1 in col2:
	moves += 1
print(moves)


x = input().split()
y = input().split()
z = input().split()
p = input().split()
q = input().split()
if ('1' in x or '1' in q) and (x[2] == '1' or q[2] == '1'):
	print('2')
elif ('1' in y or '1' in p) and (y[2] == '1' or p[2] == '1'):
	print('1')
elif '1' in z and z[2] == '1':
	print('0')
elif '1' in x and (x[0] == '1' or x[4] == '1'):
	print('4')
elif '1' in x and (x[1] == '1' or x[3] == '1'):
	print('3')
elif '1' in y and (y[0] == '1' or y[4] == '1'):
	print('3')
elif '1' in y and (y[1] == '1' or y[3] == '1'):
	print('2')
elif '1' in z and (z[0] == '1' or z[4] == '1'):
	print('2')
elif '1' in z and (z[1] == '1' or z[3] == '1'):
	print('1')
elif '1' in q and (q[0] == '1' or q[4] == '1'):
	print('4')
elif '1' in q and (q[1] == '1' or q[3] == '1'):
	print('3')
elif '1' in p and (p[0] == '1' or p[4] == '1'):
	print('3')
elif '1' in p and (p[1] == '1' or p[3] == '1'):
	print('2')


matrix = []
for _ in range(5):
	row = input().split(' ')
	row = [int(i) for i in row]
	matrix.append(row)
count = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j]:
			count = abs(i + 1 - 3) + abs(j + 1 - 3)
			print(count)
			break


M = N = 5
(i0, j0) = (0, 0)
matrix = []
for i in range(M):
	inp = list(map(int, input().split()))
	if 1 in inp:
		i0 = i
		j0 = inp.index(1)
	matrix.append(inp)
c = 0
while not i0 == j0 == 2:
	if i0 > 2:
		i0 = i0 - 1
	elif i0 < 2:
		i0 = i0 + 1
	elif j0 > 2:
		j0 = j0 - 1
	elif j0 < 2:
		j0 = j0 + 1
	c = c + 1
print(c)


a = []
row = 0
colunm = 0
for i in range(5):
	p = list(map(int, input().split()))
	for j in range(0, len(p)):
		if p[j] == 1:
			row = i
			column = j
	a.append(p)
ans = 0
ans += abs(row - 2)
ans += abs(column - 2)
print(ans)


c = 0
i = 0
j = 0
j_1 = 1
i_1 = 0
n_1 = ''
while j_1 < 6:
	n = input()
	if n != '0 0 0 0 0':
		j = j_1
		n_1 = n
	j_1 += 1
while i_1 < len(n):
	if n_1[i_1] == '1':
		break
	else:
		i_1 += 1
if j >= 3:
	c += j - 3
else:
	c += 3 - j
i = i_1 / 2 + 1
if i >= 3:
	c += i - 3
else:
	c += 3 - i
print(int(c))


count = []
for i in range(5):
	a = list(map(int, input().strip().split()))[:5]
	count.append(a)
for i in range(5):
	for j in range(5):
		if count[i][j] == 1:
			total = abs(i - 2) + abs(j - 2)
			print(total)


mat = []
for i in range(5):
	mat.append(input().split(' '))
moves = 0
for (ind, i) in enumerate(mat):
	if '1' in i:
		moves += abs(2 - ind)
		for (index, j) in enumerate(i):
			if j == '1':
				moves += abs(2 - index)
print(moves)


s = []
for i in range(5):
	s.extend(map(int, input().split()))
i = s.index(1) % 5
j = int(s.index(1) / 5)
move = abs(i - 2) + abs(j - 2)
print(move)


for i in range(1, 6):
	x = list(map(int, input().split()))
	if 1 in x:
		b = x.index(1) + 1
		a = i
print(abs(a - 3) + abs(b - 3))


rows = []
rowPos = None
colPos = None
for i in range(5):
	rows.append(input())
for (j, row) in enumerate(rows):
	ref = 1
	for char in row:
		if char == '1':
			colPos = ref
			rowPos = j + 1
			break
		elif char == ' ':
			continue
		else:
			ref = ref + 1
			continue
numberOfSwaps = abs(3 - rowPos) + abs(3 - colPos)
print(numberOfSwaps)


for t in range(5):
	l = list(map(int, input().split()))
	for j in range(5):
		if l[j] == 1:
			x = j + 1
			y = t + 1
r = abs(3 - x)
f = abs(3 - y)
print(r + f)


a = [input().find('1') for i in range(5)]
print(abs(max(a) // 2 - 2) + abs(a.index(max(a)) - 2))


matrix = [[int(j) for j in input().split()] for i in range(5)]
boo = False
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			boo = True
			break
	if boo:
		break
print(abs(i - 2) + abs(j - 2))


for i in range(5):
	a = list(map(int, input().split()))
	if 1 in a:
		print(abs(i - 2) + abs(a.index(1) - 2))


import sys
from os import path
if path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')

def ri():
	return int(input())

def ria():
	return [int(x) for x in input().split()]
mat = []
row = 0
col = 0
for i in range(5):
	mat.append(ria())
	if 1 in mat[i]:
		row = i
		col = mat[i].index(1)
print(abs(2 - row) + abs(2 - col))


matrix = []
for i in range(5):
	word = input().strip().split(' ')
	matrix.append(list(word))
for row in range(5):
	check = False
	for column in range(5):
		if matrix[row][column] == '1':
			check = True
			break
	if check:
		column += 1
		row += 1
		break
count = abs(column - 3) + abs(row - 3)
print(count)


ls = '0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0'.splitlines()
for row in range(5):
	t = input().find('1')
	if t != -1:
		RowIndex = row
		ColIndex = t
print(abs(ColIndex - 4) // 2 + abs(RowIndex - 2))


a = []
for i in range(5):
	x = input().strip().split()
	x = [int(x[j]) for j in range(5)]
	a.append(x)
	if 1 in x:
		for j in range(5):
			if x[j] == 1:
				loc = [i, j]
print(abs(loc[0] - 2) + abs(loc[1] - 2))


for i in range(1, 6):
	s = list(input().split())
	if '1' in s:
		j = s.index('1') + 1
		print(abs(3 - i) + abs(3 - j))


(desired_i, desired_j) = (2, 2)
for i in range(5):
	row_line = input()
	row_lst = row_line.split()
	if '1' in row_lst:
		j = row_lst.index('1')
		minimal_moves = abs(i - desired_i) + abs(j - desired_j)
		print(minimal_moves)
		break


(l, c, m) = (0, 0, 0)
for i in range(5):
	linha = [int(x) for x in input().split()]
	if 1 in linha:
		(l, c) = (i + 1, linha.index(1) + 1)
m = abs(l - 3) + abs(c - 3)
print(m)


M = [list(map(int, input().split())) for _ in range(5)]
for i in range(5):
	if 1 in M[i]:
		j = M[i].index(1)
		print(abs(i - 2) + abs(j - 2))
		break


def beautiful_matrix():
	matrix = []
	for i in range(5):
		temp = list(map(int, input().split()))
		for j in range(5):
			if temp[j] == 1:
				x = [i, j]
	return abs(x[0] - 2) + abs(x[1] - 2)
print(beautiful_matrix())


b = 0
for i in range(1, 6):
	a = list(map(str, input().split()))
	u = a.count('1')
	if u == 1:
		b += abs(3 - int(i))
		c = a.index('1')
		b += abs(2 - int(c))
print(b)


f = []
for i in range(5):
	x = input().split(' ')
	if '1' in x:
		f = [i, x.index('1')]
		break
print(abs(2 - f[0]) + abs(2 - f[1]))


m = []
for i in range(5):
	m.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			r = abs(i - 2) + abs(j - 2)
print(r)


n = 0
for i in range(5):
	str_0 = input()
	list_0 = str_0.split()
	for j in range(len(list_0)):
		if list_0[j] == '1':
			print(abs(2 - i) + abs(2 - int(j)))


for i in range(5):
	row = list(input().split())
	if '1' in row:
		c = row.index('1')
		r = i
		ans = abs(2 - i) + abs(2 - c)
print(ans)


import math
a = 0
b = 0
inp = [[], [], [], [], []]
for i in range(5):
	inp[i] = list(input().split())
for i in range(5):
	a = i
	k = 0
	for j in range(5):
		b = j
		if inp[i][j] == '1':
			k = 1
			break
	if k == 1:
		break
c = int(math.fabs(a - 2) + math.fabs(b - 2))
print(c)


rows = [list(map(int, input().split())) for x in range(5)]
for x in range(5):
	if 1 in rows[x]:
		print(abs(x - 2) + abs(rows[x].index(1) - 2))
		break


step = 0
for row in range(5):
	rowlist = [int(num) for num in input().split()]
	if 1 in rowlist:
		if row == 0 or row == 4:
			step += 2
		elif row == 1 or row == 3:
			step += 1
		position = rowlist.index(1)
		if position == 0 or position == 4:
			step += 2
		elif position == 1 or position == 3:
			step += 1
print(step)


matrix = [[int(x) for x in input().split()] for i in range(5)]
for i in range(5):
	if 1 in matrix[i]:
		j = matrix[i].index(1)
		print(abs(i - 2) + abs(j - 2))


d = []
for i in range(1, 6):
	d.append(list(map(int, input().split())))
for j in range(5):
	for k in range(5):
		if d[j][k] != 0:
			c = j
			e = k
print(abs(c - 2) + abs(e - 2))


raw = []
for i in range(5):
	raw.append(input())
for i in range(5):
	aux2 = 0
	for j in raw[i]:
		if j is not ' ':
			aux2 += 1
			j = int(j)
			if j == 1:
				aux1 = i + 1
				final = abs(3 - aux1) + abs(3 - aux2)
				print(final)


def do(a):
	index_i = 0
	index_j = 0
	ii = 0
	for i in a:
		for j in range(len(i)):
			if i[j] == 1:
				index_i = ii
				index_j = j
		ii += 1
	return abs(2 - index_i) + abs(2 - index_j)
a = []
for i in range(5):
	a.append(list(map(int, input().split())))
print(do(a))


matrix = []
for i in range(5):
	mat = list(map(int, input().split()))
	matrix.append(mat)
posi = -1
posj = -1
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			(posi, posj) = (i + 1, j + 1)
print(abs(posi - 3) + abs(posj - 3))


m = []
for i in range(5):
	l = [int(x) for x in input().split()]
	m.append(l)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


for num in range(5):
	x = input()
	y = x.split(' ')
	if '1' in y:
		num1 = y.index('1') + 1
		count = num + 1
		break
num1 = abs(num1 - 3)
count = abs(count - 3)
print(num1 + count)


m = [input().split() for i in range(5)]
for i in range(len(m)):
	for j in range(len(m)):
		if m[i][j] == '1':
			coords = (j, i)
			break
print(abs(2 - coords[1]) + abs(2 - coords[0]))


a = []
(mr, mc) = (2, 2)
(oR, oC) = (-1, -1)
for i in range(5):
	row = list(map(lambda x: int(x), input().strip().split()))
	if 1 in row:
		oC = row.index(1)
		oR = i
print(abs(oR - mr) + abs(oC - mc))


i = 0
y = 0
while y == 0:
	i = i + 1
	j = 1
	a = input().split()
	a = list(map(int, a))
	for x in a:
		if x == 0:
			j = j + 1
		elif x == 1:
			y = 1
			break
ans = abs(3 - i) + abs(3 - j)
print(ans)


for i in range(5):
	gh = input()
	a = gh[::2]
	if '1' in a:
		b = a.find('1')
		itog = abs(b - 2)
		g = abs(i - 2)
		itog += g
		print(itog)


list1 = []
nor = 0
for i in range(5):
	list1.append([int(data) for data in input().split(' ')])
for i in range(5):
	noc = 0
	for j in range(5):
		if list1[i][j] == 1:
			break
		else:
			noc += 1
	if list1[i][j] == 1:
		break
	else:
		nor += 1
noc = abs(noc - 2)
nor = abs(nor - 2)
print(noc + nor)


for i in range(5):
	r = input()
	one = r.find('1')
	if one != -1:
		loc = [i, one // 2]
		break
print(abs(2 - loc[0]) + abs(2 - loc[1]))


lista = []
soma = 0
for i in range(5):
	lista.append(list(map(str, input().split())))
	if str(lista[i]).find('1') >= 0:
		soma += abs(3 - (i + 1))
		soma += abs(2 - lista[i].index('1'))
print(soma)


m = []
a = 13
for i in range(5):
	l = [int(i) for i in input().split()]
	m.append(l)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			a = abs(i - 2)
			b = abs(j - 2)
print(abs(a + b))


import sys
i = 0
for line in sys.stdin:
	i += 1
	row = map(int, line.split())
	j = 1
	for m in row:
		if m:
			break
		j += 1
	else:
		continue
	break
print(abs(3 - i) + abs(3 - j))


mat = [input().split(), input().split(), input().split(), input().split(), input().split()]
m = 2
for (x, a) in enumerate(mat):
	if '1' in a:
		for (y, b) in enumerate(a):
			if b == '1':
				print(abs(x - m) + abs(y - m))


d1 = 0
d2 = 0
for i in range(0, 5):
	l = input().replace(' ', '')
	if '1' in l:
		d1 = abs(i - 2)
		d2 = abs(l.index('1') - 2)
print(d1 + d2)


for i in range(5):
	row = list(map(int, input().split()))
	try:
		j = row.index(1)
		print(abs(i - 2) + abs(j - 2))
		break
	except ValueError:
		continue


matrix = []
for i in range(5):
	value = list(map(int, input().split()))
	matrix.append(value)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			i = 2 - i
			i = abs(i)
			j = 2 - j
			j = abs(j)
			answer = i + j
print(answer)


l = []
for i in range(5):
	x = input().split(' ')
	temp = [int(i) for i in x]
	l.append(temp)
index = [(index, index2) for (index, item) in enumerate(l) for (index2, item2) in enumerate(item) if item2 == 1]
x = index[0][0]
y = index[0][1]
x = abs(abs(x) - 2)
y = abs(abs(y) - 2)
print(x + y)


N = 5
lst = []
m = None
for i in range(N):
	temp = input().split()
	for j in range(N):
		if temp[j] == '1':
			(m, n) = (i + 1, j + 1)
			break
	if m != None:
		break
count = 0
if m > 3:
	count += m - 3
else:
	count += 3 - m
if n > 3:
	count += n - 3
else:
	count += 3 - n
print(count)


a = []
for i in range(5):
	a.append(list(map(int, input().strip().split()))[:5])
x = [x for x in a if 1 in x][0]
print(abs(a.index(x) - 2) + abs(x.index(1) - 2))


a = []
for i in range(5):
	a.append([])
	s = input()
	a[i] = s.split()
i = 0
b = False
while not b:
	j = 0
	while not b and j < 5:
		if a[i][j] == '1':
			b = True
		j += 1
	i += 1
print(abs(3 - j) + abs(3 - i))


for y in range(5):
	line = list(map(int, input().split(' ')))
	try:
		x = line.index(1)
		break
	except ValueError:
		continue
print(abs(2 - y) + abs(2 - x))


a = []
b = []
c = [3, 3]
for _ in range(5):
	a.append(input().split())
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			b = b + [i + 1] + [j + 1]
if b[0] - c[0] >= 0:
	d = b[0] - c[0]
else:
	d = c[0] - b[0]
if b[1] - c[1] >= 0:
	print(d + b[1] - c[1])
else:
	print(d + c[1] - b[1])


x = ''
for i in range(5):
	z = input()
	x += z
x = x.split()
s = ''
x = s.join(x)
one = str(x.index('1'))
val = 0
if one == '0' or one == '5' or one == '10' or (one == '15') or (one == '20') or (one == '4') or (one == '9') or (one == '14') or (one == '19') or (one == '24'):
	val += 2
elif one == '1' or one == '6' or one == '11' or (one == '16') or (one == '21') or (one == '3') or (one == '8') or (one == '13') or (one == '18') or (one == '23'):
	val += 1
elif one == '2' or one == '7' or one == '12' or (one == '17') or (one == '22'):
	val += 0
if one == '0' or one == '1' or one == '2' or (one == '3') or (one == '4') or (one == '20') or (one == '21') or (one == '22') or (one == '23') or (one == '24'):
	val += 2
elif one == '5' or one == '6' or one == '7' or (one == '8') or (one == '9') or (one == '15') or (one == '16') or (one == '17') or (one == '18') or (one == '19'):
	val += 1
elif one == '10' or one == '11' or one == '12' or (one == '13') or (one == '14'):
	val += 0
print(val)


m = [[int(i) for i in input().split()] for j in range(5)]
for i in range(len(m)):
	for j in range(len(m[i])):
		if m[i][j] == 1:
			if i == 2 and j == 2:
				hasil = 0
			elif i <= 2 and j <= 2:
				hasil = 2 - i + (2 - j)
			elif i >= 2 and j >= 2:
				hasil = i - 2 + (j - 2)
			elif i <= 2 and j >= 2:
				hasil = 2 - i + (j - 2)
			elif i >= 2 and j <= 2:
				hasil = i - 2 + (2 - j)
print(hasil)


l = []
for i in range(5):
	l.append([int(x) for x in input().split()])
for j in range(5):
	for k in range(5):
		if l[j][k] != 0:
			x = abs(k - 2) + abs(j - 2)
			print(x)


the_matrix = list()
row_index = 0
column_index = 0
for i in range(5):
	item = input().split()
	the_matrix.append(item)
	if '1' in the_matrix[i]:
		row_index = i
		column_index = the_matrix[i].index('1')
print(abs(2 - row_index) + abs(2 - column_index))


for i in range(1, 6):
	(a, b, c, d, e) = map(int, input().split())
	if a == 1:
		x = i
		y = 1
	elif b == 1:
		x = i
		y = 2
	elif c == 1:
		x = i
		y = 3
	elif d == 1:
		x = i
		y = 4
	elif e == 1:
		x = i
		y = 5
A = abs(3 - x)
B = abs(3 - y)
print(A + B)


for i in range(5):
	s = input()
	x = s.find('1')
	if x != -1:
		c = x // 2 + 1
		r = i + 1
c = 3 - c
r = 3 - r
if c < 0:
	c = -c
if r < 0:
	r = -r
print(r + c)


matriz = []
for i in range(5):
	matriz.append(str(input()).split(' '))
k = 0
j = 0
for i in range(5):
	if matriz[i].count('1') > 0:
		k = matriz[i].index('1')
		j = i
		break
print(abs(k - 2) + abs(j - 2))


for i in range(5):
	numbers = input('').split(' ')
	if '1' in numbers:
		n = i + 1
		m = numbers.index('1') + 1
print(abs(m - 3) + abs(n - 3))


mat = []
for k in range(5):
	mat.append(list(map(int, input().split())))
flag = 0
ct = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] != 0:
			i += 1
			j += 1
			flag = 1
			break
	if flag == 1:
		break
ct = abs(3 - i) + abs(3 - j)
print(ct)


z = 0
a = 0
br = 0
for y in range(5):
	z = z + 1
	a = 0
	for x in input().split():
		a = a + 1
		if x == '1':
			br = 1
			break
	if br == 1:
		break
print(abs(3 - a) + abs(3 - z))


n1 = 1
while n1 <= 5:
	n = list(map(int, input().split()))
	if 1 in n:
		x = n.index(1) + 1
		y = n1
	n1 += 1
print(abs(x - 3) + abs(y - 3))


x = 5
t = 0
while x != 0:
	y = input()
	y = y.replace(' ', '')
	t = t + 1
	if t == 1:
		s = 2
	elif t == 2:
		s = 1
	elif t == 3:
		s = 0
	elif t == 4:
		s = 1
	elif t == 5:
		s = 2
	if '1' in y:
		d = y.index('1')
		if d < 2:
			a = 2 - d + s
		elif d > 2:
			a = d - 2 + s
		else:
			a = 0 + s
	x = x - 1
print(a)


s = []
cr = 0
cc = 0
for k in range(5):
	s.append([0, 0, 0, 0, 0])
for i in range(5):
	s[i] = str(input()).split()
for n in range(5):
	for m in range(5):
		if s[n][m] == '1':
			cr = n
			cc = m
			a = abs(2 - cr) + abs(2 - cc)
			print(a)


m = [[int(i) for i in input().split()] for j in range(5)]
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
			break


from sys import stdin, stdout

def read_line():
	return stdin.readline().strip()

def print(value):
	stdout.write(str(value))

def main():
	for i in range(5):
		row_lst = read_line().split()
		if '1' in row_lst:
			print(abs(i - 2) + abs(row_lst.index('1') - 2))
			return
main()


I = 0
J = 0
for i in range(0, 5):
	a = list(map(int, input().split()))
	for j in range(0, 5):
		if a[j]:
			(I, J) = (i, j)
print(abs(I - 2) + abs(J - 2))


c = 0
r = 0
for i in range(5):
	inp = input().split()
	try:
		c = inp.index('1')
		r = i
		break
	except ValueError:
		c = -1
c = int(c)
r = int(r)
s = abs(2 - c) + abs(2 - r)
print(s)


n = []
for i in range(5):
	a = [int(c) for c in input().split()]
	n.append(a)
for i in range(len(n)):
	if 1 in n[i]:
		print(abs(n[i].index(1) - 2) + abs(i - 2))
		break


n = 5
matrix = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	matrix[i] = input().split()
for i in range(n):
	for j in range(n):
		if matrix[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))


x = 2
y = 2
arr = []
for i in range(5):
	a = list(map(int, input().split()))
	if a.count(1) > 0:
		(x1, y2) = (a.index(1), i)
ans = abs(x - x1) + abs(y - y2)
print(ans)


indexes = []
j = 0
for n in range(5):
	j = j + 1
	s = list(input().split(' '))
	if '1' in s:
		indexes.append(j)
		indexes.append(s.index('1') + 1)
print(abs(3 - indexes[0]) + abs(3 - indexes[1]))


a = [[0 for i in range(5)] for j in range(5)]
x = 0
y = 0
for i in range(5):
	temp = input()
	a[i] = [int(y) for y in temp.split()]
	for j in range(5):
		if a[i][j] == 1:
			x = i + 1
			y = j + 1
if x == 3 and y == 3:
	print(0)
else:
	ans = abs(3 - x) + abs(3 - y)
	print(ans)


mat = []

def solve():
	result = 0
	for i in range(5):
		t = list(map(int, input().split()))
		for j in range(len(t)):
			if t[j] == 1:
				result = abs(j - 2) + abs(i - 2)
	print(result)
solve()


x = []
k = []
strss = ''
for i in range(5):
	k = input().split(' ')
	x.extend(k)
x_1 = [7, 11, 13, 17]
x_2 = [6, 8, 16, 18, 2, 22, 10, 14]
x_3 = [1, 3, 5, 9, 15, 19, 21, 23]
x_4 = [0, 4, 20, 24]
ks = x.index('1')
if ks in x_1:
	print('1')
elif ks in x_2:
	print('2')
elif ks in x_3:
	print('3')
elif ks in x_4:
	print('4')
else:
	print('0')


ans = 0
k = []
for i in range(5):
	l = list(map(int, input().split()))
	k.append(l)
for i in range(5):
	for j in range(5):
		if k[i][j] == 1:
			if i < 2:
				ans += 2 - i
			else:
				ans += i - 2
			if j < 2:
				ans += 2 - j
			else:
				ans += j - 2
			break
print(ans)


Rows = [[int(s) for s in input().split()], [int(s) for s in input().split()], [int(s) for s in input().split()], [int(s) for s in input().split()], [int(s) for s in input().split()]]
(X, Y) = (None, None)
Sum = 0
for y in range(5):
	for x in range(5):
		if Rows[y][x] != 0:
			X = x
			Y = y
			break
while X != 2 or Y != 2:
	if X > 2:
		Sum += 1
		X -= 1
	elif X < 2:
		Sum += 1
		X += 1
	elif Y > 2:
		Sum += 1
		Y -= 1
	elif Y < 2:
		Sum += 1
		Y += 1
	elif X == 2 and Y == 2:
		break
print(Sum)


for i in range(5):
	a = input().split()
	a = ''.join(a)
	ac = a.rfind('1')
	if ac != -1:
		x = ac
		y = i
x = 2 - x
y = 2 - y
sum = abs(x) + abs(y)
print(sum)


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i
			column = j
count = 0
while row != 2:
	if row < 2:
		row += 1
	else:
		row -= 1
	count += 1
while column != 2:
	if column < 2:
		column += 1
	else:
		column -= 1
	count += 1
print(count)


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
for l in range(5):
	for s in range(5):
		if arr[l][s] == 1:
			print(abs(l - 2) + abs(s - 2))
			quit()


arr2d = [[j for j in map(int, input().strip().split())] for i in range(5)]
k = 0
l = 0
for i in range(5):
	for j in range(5):
		if arr2d[i][j] == 1:
			k = i
			l = j
(tar_i, tar_j) = (2, 2)
print(abs(k - tar_i) + abs(l - tar_j))


a = []
for i in range(5):
	p = list(map(int, input().split(' ')))
	if sum(p) == 1:
		c = i
	a.append(p)
for i in range(5):
	if a[c][i] == 1:
		q = i
u = abs(q - 2) + abs(c - 2)
print(u)


x = []
for i in range(5):
	x.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if x[i][j] == 1:
			c = i + 1
			d = j + 1
			print(abs(3 - c) + abs(3 - d))


import math
for i in range(5):
	a = input()
	if a.find('1') != -1:
		print(abs((4 - a.find('1')) // 2) + abs(i - 2))
		break


matrix = []
for i in range(5):
	row = input()
	row = row.split()
	row = [int(k) for k in row]
	matrix.append(row)
for i in matrix:
	if 1 in i:
		n = []
		n.append(matrix.index(i))
		n.append(i.index(1))
moves = abs(2 - n[1]) + abs(2 - n[0])
print(moves)


mid = 2
matrix = []
minimum = 0
for x in range(5):
	matrix = list(input().split())
	for z in range(5):
		if matrix[z] == '1':
			minimum = abs(int(x) - mid) + abs(int(z) - mid)
print(minimum)


(row, col) = (1, 1)
for i in range(1, 6):
	line = list(map(int, input().split()))
	if 1 in line:
		col = line.index(1) + 1
		row = i
(mid_col, mid_row) = (3, 3)
print(abs(mid_row - row) + abs(mid_col - col))


nofind = True
for i in range(5):
	s = input().split()
	t = 0
	while nofind and t <= 4:
		if s[t] == '1':
			ans = abs(2 - t) + abs(2 - i)
			nofind = False
		t += 1
print(ans)


i = 5
result = []
while i > 0:
	result.append([int(x) for x in input().split()])
	i -= 1
vi = -1
hi = -1
for i in range(len(result)):
	for j in range(len(result[i])):
		if result[i][j] == 1:
			vi = i
			hi = j
			break
	if vi > -1 and hi > -1:
		break
print(abs(vi - 2) + abs(hi - 2))


l = [2, 1, 0, 1, 2]
for i in l:
	row = input()
	if '1' in row:
		print(i + l[row.find('1') // 2])


row = [[], [], [], [], []]
row_num = 0
col_num = 0
for i in range(5):
	r = input().split()
	row[i] = [int(j) for j in r]
	if 1 in row[i]:
		row_num = i
		col_num = row[i].index(1)
steps = abs(2 - row_num) + abs(2 - col_num)
print(steps)


A = []
for i in range(5):
	A.append(input().split())

def f(x):
	for i in range(5):
		for t in range(5):
			if x[i][t] == '1':
				k = abs(i - 2) + abs(t - 2)
				return k
print(f(A))


n = 5
a = []
rowNum = 0
colNum = 0
for i in range(n):
	row = input().split()
	for i in range(len(row)):
		row[i] = int(row[i])
	a.append(row)
for i in range(n):
	row = a[i]
	for j in range(n):
		if row[j] == 1:
			rowNum = i + 1
			colNum = j + 1
			break
	else:
		continue
	break
print(abs(3 - rowNum) + abs(3 - colNum))


def read2DIntArray(row, col):
	arr = []
	for i in range(0, row):
		temp = list(map(int, input().strip().split()))
		arr.append(temp)
	return arr
a = read2DIntArray(5, 5)
x = 0
y = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i + 1
			y = j + 1
			break
	if x or y:
		break
n = abs(3 - x) + abs(3 - y)
print(n)


(x, y) = (-1, -1)
for i in range(5):
	t = input().strip().split()
	if '1' in t:
		x = i
		y = t.index('1')
print(abs(x - 2) + abs(y - 2))


a = []
for i in range(5):
	a.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			b = [i + 1, j + 1]
print(abs(b[0] - 3) + abs(b[1] - 3))


(r, c) = (-1, -1)
for i in range(5):
	st = input().replace(' ', '')
	col = st.find('1')
	if col != -1:
		r = i
		c = col
print(abs(r - 2) + abs(c - 2))


point = []
for i in range(1, 6):
	a = input().split(' ')
	if '1' in a:
		point.append([i, a.index('1') + 1])
print(abs(point[0][0] - 3) + abs(point[0][1] - 3))


n = 5
r = -1
c = -1
for _ in range(n):
	s = list(input().split())
	for i in range(n):
		if s[i] == '1':
			r = _
			c = i
print(abs(2 - r) + abs(2 - c))


a = [int(a) for a in input().split()]
b = [int(b) for b in input().split()]
c = [int(c) for c in input().split()]
d = [int(d) for d in input().split()]
e = [int(e) for e in input().split()]
index1 = 0
if 1 in a:
	index1 = a.index(1) + 1
	index2 = 1
elif 1 in b:
	index1 = b.index(1) + 1
	index2 = 2
elif 1 in c:
	index1 = c.index(1) + 1
	index2 = 3
elif 1 in d:
	index1 = d.index(1) + 1
	index2 = 4
elif 1 in e:
	index1 = e.index(1) + 1
	index2 = 5
print(abs(3 - index1) + abs(3 - index2))


mat = []
for x in range(0, 5):
	a = list(map(int, input().split()))
	mat.append(a)
	for i in a:
		if i == 1:
			row = a.index(1)
			col = mat.index(a)
print(abs(row - 2) + abs(col - 2))


result = 0
x = -1
y = -1
fl = False
for i in range(5):
	t = input()
	t = list(map(int, t.strip().split()))
	for j in range(len(t)):
		if t[j] == 1:
			fl = True
			x = i
			y = j
			break
	if fl:
		break
result = abs(x - 2) + abs(y - 2)
print(result)


mat = []
for i in range(5):
	a = input().split(' ')
	row = [int(element) for element in a]
	mat.append(row)
entry = {}
for i in range(len(mat)):
	for j in range(len(mat)):
		if mat[i][j] == 1:
			entry['row'] = i
			entry['col'] = j
num_of_move = abs(entry['row'] - 2) + abs(entry['col'] - 2)
print(num_of_move)


(r, c) = (0, 0)
for i in range(1, 6):
	a = list(map(int, input().split()))
	for j in a:
		if j == 1:
			r = i
			c = a.index(j) + 1
print(abs(3 - r) + abs(3 - c))


a = []
for i in range(5):
	a.append(input())
n = 0
co = 0
if '1' in a[0]:
	b = a[0].count(' ', 0, a[0].index('1'))
	n = a[0].index('1') + 1 - b
	co = 1
if '1' in a[1]:
	b = a[0].count(' ', 0, a[1].index('1'))
	n = a[1].index('1') + 1 - b
	co = 2
if '1' in a[2]:
	b = a[2].count(' ', 0, a[2].index('1'))
	n = a[2].index('1') + 1 - b
	co = 3
if '1' in a[3]:
	b = a[3].count(' ', 0, a[3].index('1'))
	n = a[3].index('1') + 1 - b
	co = 4
if '1' in a[4]:
	b = a[0].count(' ', 0, a[4].index('1'))
	n = a[4].index('1') + 1 - b
	co = 5
print(abs(3 - n) + abs(3 - co))


list2 = []
for i in range(0, 5, 1):
	list1 = [int(i) for i in input().split()]
	list2.append(list1)
for i in range(0, 5, 1):
	for j in range(0, 5, 1):
		if list2[i][j] == 1:
			if i <= 2:
				a = 2 - i
			else:
				a = i - 2
			if j <= 2:
				b = 2 - j
			else:
				b = j - 2
print(a + b)


from sys import stdin
arr = []
for i in range(5):
	arr.append(list(map(int, stdin.readline().split())))
coordsList = [[x, y] for (x, li) in enumerate(arr) for (y, val) in enumerate(li) if val == 1]
print(abs(2 - coordsList[0][0]) + abs(2 - coordsList[0][1]))


def distance():
	for i in range(5):
		arr = [int(x) for x in input().split()]
		for j in range(5):
			if arr[j] == 1:
				print(abs(2 - i) + abs(2 - j))
				exit

def main():
	distance()
main()


lst = []
for i in range(5):
	lst1 = list(map(int, input().split()[:5]))
	lst.append(lst1)
for i in range(5):
	for j in range(5):
		if lst[i][j] != 0:
			m = i
			t = j
print(abs(m - 2) + abs(t - 2))


from sys import stdin

def main():
	matrix = []
	a = 0
	while a < 6:
		b = [int(x) for x in stdin.readline().strip().split()]
		matrix.append(b)
		a = a + 1
	for i in range(len(matrix)):
		for j in range(len(matrix[i])):
			if matrix[i][j] > 0:
				contador1 = 2 - i
				contador2 = 2 - j
	if contador1 < 0:
		contador1 = -contador1
	if contador2 < 0:
		contador2 = -contador2
	contador = contador1 + contador2
	print(contador)
main()


pos = 2
matrix = []
for _ in range(5):
	matrix.append(list(map(int, input().split())))
(a, b) = (0, 0)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			(a, b) = (i, j)
ans = abs(pos - a) + abs(pos - b)
print(ans)


a = ''
for i in range(5):
	a += input('')
	a += '\n'
rows = a.split('\n')
for i in rows:
	if '1' in i:
		(ix, iy) = (rows.index(i) + 1, i.index('1') - i[0:i.index('1') + 1].count('0') + 1)
print(abs(3 - ix) + abs(3 - iy))


for i in range(5):
	tmp = [int(x) for x in input().split(' ')]
	for j in range(5):
		if tmp[j] == 1:
			distance = abs(2 - i) + abs(2 - j)
			print(distance)
			break


x = 1
y = 1
for i in range(5):
	line = list(map(int, input().split(' ')))
	try:
		y = line.index(1) + 1
		break
	except:
		pass
	x += 1
print(abs(3 - y) + abs(3 - x))


matrix = []
x = 0
y = 0
for i in range(5):
	l = [int(i) for i in input().split()]
	if 1 in l:
		x = i
		y = l.index(1)
	matrix.append(l)
c = 0
if x < 2:
	c += 2 - x
if x > 2:
	c += x - 2
if y < 2:
	c += 2 - y
if y > 2:
	c += y - 2
print(c)


a = []
for i in range(5):
	a = a + [int(x) for x in input().split()]
ai = a.index(1)
print(abs(2 - ai // 5) + abs(2 - ai % 5))


for i in range(5):
	x = [int(x) for x in input().split()]
	if 1 in x:
		print(abs(2 - i) + abs(2 - x.index(1)))
		quit()


row = 0
column = 0
for i in range(5):
	inputRow = input().split()
	for j in range(5):
		if inputRow[j] == '1':
			row = i
			column = j
			break
print(abs(2 - row) + abs(2 - column))


mat = []
for i in range(5):
	mat.append([int(x) for x in input().split()])
ind1 = None
z = None
for i in range(len(mat)):
	if 1 in mat[i]:
		ind1 = mat[i].index(1)
		z = i
		break
step = 0
if z > 2:
	step = z - 2
else:
	step = 2 - z
if ind1 > 2:
	step += ind1 - 2
else:
	step += 2 - ind1
print(step)


def solve():
	for i in range(1, 6):
		row = input().split()
		position_1 = [(i, j) for j in range(1, 6) if row[j - 1] == '1']
		if len(position_1) == 1:
			return abs(position_1[0][0] - 3) + abs(position_1[0][1] - 3)
res = solve()
print(res)


l1 = input().split(' ')
l2 = input().split(' ')
l3 = input().split(' ')
l4 = input().split(' ')
l5 = input().split(' ')
for i in range(5):
	if l1[i] == '1':
		print(2 + abs(2 - l1.index('1')))
	elif l2[i] == '1':
		print(1 + abs(2 - l2.index('1')))
	elif l3[i] == '1':
		print(0 + abs(2 - l3.index('1')))
	elif l4[i] == '1':
		print(1 + abs(2 - l4.index('1')))
	elif l5[i] == '1':
		print(2 + abs(2 - l5.index('1')))


lst = []
row = 0
column = 0
for i in range(0, 5):
	lst.append(input())
for x in range(0, 5):
	lst[x] = lst[x].replace(' ', '')
	if '1' in lst[x]:
		row = x
for y in range(0, 5):
	if lst[row][y] == '1':
		column = y
horz_move = abs(2 - row)
vert_move = abs(2 - column)
print(horz_move + vert_move)


arr = []
for i in range(5):
	arr.append(input().split())
for i in range(len(arr)):
	if arr[i].count('1') == 1:
		k = arr[i].index('1')
		print(abs(i - 2) + abs(k - 2))


import math
matrix = [[0] * 5 for i in range(5)]
for i in range(5):
	row = list(input().split(' '))
	matrix[i] = row
res = 100
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if ord(matrix[i][j]) - ord('0') == 1:
			res = min(abs(i - 2) + abs(j - 2), res)
print(res)


for i in range(5):
	ls = list(map(int, input().split()))
	try:
		ind = ls.index(1)
		print(abs(i - 2) + abs(ind - 2))
		break
	except:
		pass


a = [input().split() for item in range(5)]
for item in a:
	if '1' in item:
		print(abs(2 - item.index('1')) + abs(2 - a.index(item)))


done = False
for i in range(5):
	if done:
		input()
		continue
	nums = list(map(int, input().split(' ')))
	for j in range(5):
		if nums[j] == 1:
			res = abs(2 - i) + abs(2 - j)
print(res)


import sys
minSteps = 0
loopCounter = 1
for line in sys.stdin:
	row = line.rstrip()
	if row.find('1') != -1:
		if loopCounter == 1 or loopCounter == 5:
			minSteps += 2
		elif loopCounter == 2 or loopCounter == 4:
			minSteps += 1
		if row.find('1') == 0 or row.find('1') == 8:
			minSteps += 2
		elif row.find('1') == 2 or row.find('1') == 6:
			minSteps += 1
	loopCounter += 1
	if loopCounter == 6:
		print(minSteps)
		break


def mutlak_deger(number):
	if number < 0:
		return -number
	else:
		return number

def int_input_spliter_and_reciever():
	liste = []
	for i in input().strip().split():
		liste.append(int(i))
	return liste
x = []
l1 = int_input_spliter_and_reciever()
l2 = int_input_spliter_and_reciever()
l3 = int_input_spliter_and_reciever()
l4 = int_input_spliter_and_reciever()
l5 = int_input_spliter_and_reciever()
x.append(l1)
x.append(l2)
x.append(l3)
x.append(l4)
x.append(l5)
l = 1
for i in x:
	s = 1
	for t in i:
		if t == 1:
			result = mutlak_deger(l - 3) + mutlak_deger(s - 3)
		s += 1
	l += 1
print(result)


for x in range(5):
	l = input().split()
	if '1' in l:
		j = l.index('1')
		print(abs(j - 2) + abs(x - 2))
		break


array_1 = input().split()
array_2 = input().split()
array_3 = input().split()
array_4 = input().split()
array_5 = input().split()
output = 0
array = [array_1, array_2, array_3, array_4, array_5]
for i in range(1, 6):
	r = array[i - 1]
	for j in range(1, 6):
		c = r[j - 1]
		if c == '1':
			output = abs(3 - int(i)) + abs(3 - int(j))
print(output)


A = []
(a, b, c, d, e) = map(int, input().split())
A.append([a, b, c, d, e])
(a, b, c, d, e) = map(int, input().split())
A.append([a, b, c, d, e])
(a, b, c, d, e) = map(int, input().split())
A.append([a, b, c, d, e])
(a, b, c, d, e) = map(int, input().split())
A.append([a, b, c, d, e])
(a, b, c, d, e) = map(int, input().split())
A.append([a, b, c, d, e])
z = 0
n = 0
for i in range(5):
	for x in range(5):
		if A[i][x] == 1:
			z = i + 1
			n = x + 1
			break
z = 3 - z
n = 3 - n
if z <= 0 and n <= 0:
	print(z * -1 + n * -1)
elif z <= 0 and n >= 0:
	print(z * -1 + n)
elif z >= 0 and n <= 0:
	print(z + n * -1)
else:
	print(z + n)


a = []
b = []
c = []
d = []
for x in range(0, 5):
	n = [int(x) for x in input().split(' ')]
	a.append(n)
	for i in n:
		if i == 1:
			b.append(n.index(1) + 1)
			c.append(x + 1)
for x in (c, b):
	d.append(x)
print(abs(3 - d[0][0]) + abs(3 - d[1][0]))


k = 0
cnt = 0
for _ in range(0, 5):
	cnt = cnt + 1
	m = list(map(int, input().split()))
	if 1 in m:
		k = m.index(1)
		break
print(abs(3 - cnt) + abs(2 - k))


import sys
lines = sys.stdin.readlines()
x = -1
y = -1
for i in range(5):
	line = lines[i]
	if '1' in line:
		x = i + 1
		y = line.find('1') // 2 + 1
		break
print(abs(x - 3) + abs(y - 3))


for i in range(1, 6):
	x = input().split()
	if '1' in x:
		r = i
		c = x.index('1') + 1
print(abs(r - 3) + abs(c - 3))


l = []
count = 0
for i in range(5):
	a = list(map(int, input().split()))
	for items in a:
		if items == 1:
			r = count
			c = a.index(items)
	count += 1
	l.append(a)
req = 0
while r != 2:
	if r > 2:
		r -= 1
		req += 1
	elif r < 2:
		r += 1
		req += 1
while c != 2:
	if c > 2:
		c -= 1
		req += 1
	elif c < 2:
		c += 1
		req += 1
print(req)


mat = []
x = 0
y = 0
for r in range(5):
	(a, b, c, d, e) = map(str, input().split())
	mat.append(a + b + c + d + e)
for i in range(len(mat)):
	a = mat[i]
	for j in range(5):
		if a[j] == '1':
			y = i
			x = j
goal = abs(x - 2) + abs(y - 2)
print(goal)


for i in range(5):
	s = list(map(int, input().split()))
	if 1 in s:
		r = i
		c = s.index(1)
print(abs(r - 2) + abs(c - 2))


masukan1 = input()
masukan2 = input()
masukan3 = input()
masukan4 = input()
masukan5 = input()
x = 0
y = 0
n = 0
for i in masukan1.split():
	n = n + 1
	if int(i) == 1:
		x = n
		y = 1
n = 0
for i in masukan2.split():
	n = n + 1
	if int(i) == 1:
		x = n
		y = 2
n = 0
for i in masukan3.split():
	n = n + 1
	if int(i) == 1:
		x = n
		y = 3
n = 0
for i in masukan4.split():
	n = n + 1
	if int(i) == 1:
		x = n
		y = 4
n = 0
for i in masukan5.split():
	n = n + 1
	if int(i) == 1:
		x = n
		y = 5
print(abs(3 - x) + abs(3 - y))


def solve():
	matrix = []
	for _ in range(5):
		matrix.append(list(map(int, input().split())))
	start_row = 0
	start_col = 0
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				start_row = i
				start_col = j
	print(abs(start_row + 1 - 3) + abs(start_col + 1 - 3))
solve()


arr = [list(map(int, input().split())) for i in range(5)]
flag = 0
for i in range(len(arr)):
	part = arr[i]
	if flag == 1:
		break
	for j in range(len(part)):
		if part[j] == 1:
			pos = (i, j)
			flag = 1
			break
moves = abs(pos[0] - 2) + abs(pos[1] - 2)
print(moves)


str1 = [0] * 5
for i in range(0, 5):
	str1[i] = [int(x) for x in input().split()]
	for j in range(0, len(str1[i])):
		if str1[i][j] == 1:
			temp1 = i
			temp2 = j
print(abs(temp1 - 2) + abs(temp2 - 2))


A = [list(map(int, input().split())) for _ in range(5)]
one_loc = [[i, A[i].index(1)] for i in range(len(A)) if 1 in A[i]]
moves = abs(2 - one_loc[0][0]) + abs(2 - one_loc[0][1])
print(moves)


for i in range(5):
	k = input()
	if '1' in k:
		ans = abs(i - 2) + abs(2 - k.index('1') // 2)
		print(ans)
		break


N = 5
for i in range(N):
	fila = [int(d) for d in input().split(' ')]
	if 1 not in fila:
		continue
	for j in range(N):
		if fila[j] == 1:
			z = abs(i - 2) + abs(j - 2)
			break
	print(z)
	break


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()))
f = a + b + c + d + e
x = f.index(1) + 1
if x <= 5:
	i = 1
	j = x
	print(abs(i - 3) + abs(j - 3))
elif x <= 10:
	i = 2
	j = x - 5
	print(abs(i - 3) + abs(j - 3))
elif x <= 15:
	i = 3
	j = x - 10
	print(abs(i - 3) + abs(j - 3))
elif x <= 20:
	i = 4
	j = x - 15
	print(abs(i - 3) + abs(j - 3))
elif x <= 25:
	i = 5
	j = x - 20
	print(abs(i - 3) + abs(j - 3))


matrix = []
for i in range(5):
	a = []
	a = [int(x) for x in input().split()]
	matrix.append(a)
flag = False
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			(x, y) = (i, j)
			flag = True
			break
	if flag:
		break
moves = abs(3 - (x + 1)) + abs(3 - (y + 1))
print(moves)


for i in range(5):
	w = [int(x) for x in input().split()]
	if w.count(1):
		for j in range(5):
			if w[j] == 1:
				print(abs(2 - i) + abs(2 - j))


def main():
	A = [[int(i) for i in input().strip().split()] for i in range(5)]
	for i in range(5):
		for j in range(5):
			if A[i][j] == 1:
				x = abs(i - 2)
				y = abs(j - 2)
				print(x + y)
main()


for i in range(1, 6):
	x = list(map(int, input().rstrip().split()))
	if 1 in x:
		if i == 1 or i == 5:
			c = 2
		elif i == 2 or i == 4:
			c = 1
		else:
			c = 0
		if x.index(1) == 1 or x.index(1) == 3:
			c = c + 1
		elif x.index(1) == 0 or x.index(1) == 4:
			c = c + 2
print(c)


import sys
input = sys.stdin.readline
matrix = [input().split() for _ in range(5)]
for row in range(5):
	if '1' in matrix[row]:
		x = matrix[row].index('1')
		y = row
		break
print(abs(x - 2) + abs(y - 2))


for i in range(5):
	list1 = list(map(int, input().split()))
	for x in range(5):
		if list1[x] == 1:
			print(abs(i - 2) + abs(x - 2))
			break


matrix = []
for i in range(5):
	s = input().split()
	matrix.append(s)
ptra = 0
ptrb = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			ptra = i
			ptrb = j
			break
if ptra >= 2 and ptrb >= 2:
	print(ptra + ptrb - 4)
elif ptra <= 2 and ptrb >= 2:
	print(ptrb - ptra)
elif ptra <= 2 and ptrb <= 2:
	print(4 - ptra - ptrb)
else:
	print(ptra - ptrb)


for i in range(5):
	s = list(map(int, input().split()))
	for j in range(5):
		if s[j] == 1:
			indi = i
			indj = j
print(abs(2 - indi) + abs(2 - indj))


matrix = [[x1 for x1 in input().split()], [x2 for x2 in input().split()], [x3 for x3 in input().split()], [x4 for x4 in input().split()], [x5 for x5 in input().split()]]
for i in range(5):
	for j in range(5):
		if '1' in matrix[i][j]:
			a = i + 1
			b = j + 1
print(abs(a - 3) + abs(b - 3))


filas = []
columnas = []
for i in range(5):
	filas.append(input())
for j in filas:
	columnas.append(j.split())

def centro(columnas):
	contFilas = 0
	contCol = 0
	for arr in columnas:
		for i in arr:
			if i != '1':
				contFilas += 1
			else:
				contFilasFinal = contFilas
				contColFinal = contCol
		contCol += 1
		contFilas = 0
	if contFilasFinal > 2:
		trF = contFilasFinal - 2
	else:
		trF = 2 - contFilasFinal
	if contColFinal > 2:
		trC = contColFinal - 2
	else:
		trC = 2 - contColFinal
	if contFilasFinal == contColFinal == 2:
		return print(0)
	else:
		return print(trF + trC)
centro(columnas)


x = 0
y = 0
for i in range(5):
	line = input().split()
	if '1' in line:
		x = i + 1
		y = line.index('1') + 1
print(abs(x - 3) + abs(y - 3))


matrix = []
for i in range(5):
	s = input().split()
	if '1' in s:
		r = i + 1
		c = s.index('1') + 1
		break
print(abs(r - 3) + abs(c - 3))


for r in range(5):
	num = input().split()
	for c in range(5):
		if num[c] == '1':
			move = abs(r - 2) + abs(c - 2)
			print(move)


matrix = []
xco = yco = 0
for i in range(5):
	matrix.append(list(input().split()))
	try:
		yco = matrix[-1].index('1')
		xco = i
	except ValueError:
		pass
print(abs(xco - 2) + abs(yco - 2))


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split(' '))))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			pos = [i + 1, j + 1]
			break
print(abs(3 - pos[0]) + abs(3 - pos[1]))


a = [0] * 5
for i in range(5):
	a = list(map(int, input().split(' ')))
	if sum(a) == 1:
		n = i + 1
		for j in range(5):
			if a[j] == 1:
				m = j + 1
print(abs(m - 3) + abs(n - 3))


import sys
y = 0
x = 0
for i in range(5):
	in_str = sys.stdin.readline().split()
	for j in range(5):
		if in_str[j] == '1':
			x = j
			y = i
			print(abs(2 - x) + abs(2 - y))
			return


def main():
	for i in range(5):
		s = list(map(int, input().split()))
		if sum(s) == 1:
			pos = s.index(1)
			print(abs(pos - 2) + abs(i - 2))
			return
main()


matrix = [[0]] * 5
for i in range(5):
	matrix[i] = input().split()
for i in range(5):
	for j in range(5):
		if '1' in matrix[i][j]:
			a = i + 1
			b = j + 1
			break
moves = abs(a - 3) + abs(b - 3)
print(moves)


def find_one(array):
	for i in range(5):
		for j in range(5):
			if array[i][j] == 1:
				return (i, j)
array = []
for i in range(5):
	ip = input()
	row = [int(x) for x in ip.split(' ')]
	array.append(row)
(i, j) = find_one(array)
print(abs(2 - i) + abs(2 - j))


from math import *
import sys, random

def nextInt():
	return int(input())

def nextStrs():
	return input().split()

def nextInts():
	return list(map(int, nextStrs()))

def main():
	arr = [0] * 5
	for i in range(5):
		arr[i] = nextInts()
	x = -1
	y = -1
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				x = i
				y = j
	print(abs(x - 2) + abs(y - 2))
exit(main())


for i in range(5):
	line = input().split()
	for j in range(5):
		if line[j] == '1':
			number = abs(i - 2) + abs(j - 2)
			print(number)


matrix = []
for i in range(5):
	X = list(map(int, input().split()))
	matrix.append(X)
currentx = 0
currenty = 0
for i in range(5):
	try:
		c = matrix[i].index(1)
		currentx = i + 1
		currenty = c + 1
	except ValueError:
		continue
print(abs(3 - currentx) + abs(3 - currenty))


from sys import stdin

def move(x):
	a = 0
	b = 0
	for i in range(len(x)):
		for j in range(len(x)):
			if x[i][j] == 1:
				a = i
				b = j
	d = abs(a - 2) + abs(b - 2)
	print(d)

def main():
	a = 5
	l = []
	while a != 0:
		x = [int(i) for i in stdin.readline().strip().split()]
		l.append(x)
		a -= 1
	move(l)
main()


for i in range(5):
	j = input().find('1') // 2
	if j >= 0:
		print(str(abs(2 - i) + abs(2 - j)))


A = list()
for i in range(5):
	A.append(list(map(int, input().split(' '))))
for i in range(5):
	if 1 in A[i]:
		col = A[i].index(1)
		row = i
		break
print(abs(2 - row) + abs(2 - col))


result = 0
for i in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		x = i
		y = row.index(1)
k = x - 2
if k < 0:
	result -= k
else:
	result += k
k = y - 2
if k < 0:
	result -= k
else:
	result += k
print(result)


l = []
for i in range(5):
	l += [list(map(int, input().split()))]
for i in l:
	if sum(i) == 1:
		for j in i:
			if j == 1:
				(f, t) = (l.index(i) + 1, i.index(j) + 1)
				break
print(abs(3 - f) + abs(3 - t))


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
f = a + b + c + d + e
h = f.index(1)
row = h // 5
row = row - 2
row = abs(row)
column = h % 5
column = column - 2
column = abs(column)
print(row + column)


list1 = [[0] * 5] * 5
for i in range(5):
	list1[i] = input().split()
for a in range(5):
	for k in range(5):
		if list1[a][k] == '1':
			row = a
			col = k
swaps = abs(row - 2) + abs(col - 2)
print(swaps, end='')


(x, y) = (0, 0)
for i in range(5):
	s = input()
	if '1' in s:
		y = i
		x = s.find('1') // 2
dist = abs(x - 2) + abs(y - 2)
print(dist)


matrix = []
for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	matrix.append([a, b, c, d, e])

def get_coordinates(matrix):
	row_index = 0
	for row in matrix:
		col_index = 0
		for i in range(5):
			if row[col_index] == 1:
				return (row_index + 1, col_index + 1)
			col_index += 1
		row_index += 1
(row_index, col_index) = get_coordinates(matrix)
min_moves = abs(3 - row_index) + abs(3 - col_index)
print(min_moves)


m = [[int(j) for j in input().split()] for i in range(5)]
movs = 0
while m[2][2] != 1:
	for i in range(5):
		for j in range(5):
			if m[i][j] == 1 and i != 2:
				if i > 2:
					m[i][j] = 0
					m[i - 1][j] = 1
					movs += 1
				elif i < 2:
					m[i][j] = 0
					m[i + 1][j] = 1
					movs += 1
			if m[i][j] == 1 and j != 2:
				if j > 2:
					m[i][j] = 0
					m[i][j - 1] = 1
					movs += 1
				elif j < 2:
					m[i][j] = 0
					m[i][j + 1] = 1
					movs += 1
print(movs)


mat = []
for i in range(5):
	mat.append(input().split())
for i in range(5):
	for j in range(5):
		if mat[i][j] == '1':
			rl = abs(2 - i)
			cl = abs(2 - j)
			res = rl + cl
			print(res)


for i in range(5):
	inp = input().split()
	for j in range(5):
		if inp[j] == '1':
			(y, x) = (i + 1, j + 1)
print(abs(x - 3) + abs(y - 3))


ch = 0
for i in range(5):
	d = list(map(int, input().split()))
	if ch == 1:
		continue
	for j in range(5):
		if d[j] == 1:
			r = i
			c = j
			ch = 1
			break
print(abs(r - 2) + abs(c - 2))


row = 0
column = 0
for i in range(5):
	s = input().split()
	for j in range(5):
		if int(s[j]) == 1:
			row = i + 1
			column = j + 1
print(abs(row - 3) + abs(column - 3))


point = (None, None)
for i in range(5):
	r = input().split()
	for (j, v) in enumerate(r):
		if v == '1':
			point = (i, j)
			break
print(abs(point[0] - 2) + abs(point[1] - 2))


a = []
for i in range(5):
	a.append([int(j) for j in input().split()])
for i in range(5):
	if 1 in a[i]:
		n = i
		m = a[i].index(1)
print(abs(n - 2) + abs(m - 2))


row = 0
col = 0
for i in range(5):
	r = list(map(int, input().split()))
	if 1 in r:
		col = r.index(1)
		row = i
print(abs(2 - row) + abs(2 - col))


a = []
x = 0
y = 0
for i in range(0, 5):
	c = input()
	a.append(c.split())
for i in range(0, 5):
	for j in range(0, 5):
		a[i][j] = int(a[i][j])
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == 1:
			x = i + 1
			y = j + 1
ans = abs(x - 3) + abs(y - 3)
print(ans)


def find(ans):
	if ans[2][2] == 1:
		return 0
	(n, m) = (0, 0)
	for i in range(5):
		for j in range(5):
			if ans[i][j] == 1:
				n = i
				m = j
				break
	return abs(n - 2) + abs(m - 2)
ans = []
for _ in range(5):
	li = list(map(int, input().rstrip().split()))
	ans.append(li)
print(find(ans))


l = [[int(j) for j in input().strip().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			n = abs(2 - i) + abs(2 - j)
			break
print(n)


arr = []
for i in range(5):
	arr.append(input().split())
for i in range(5):
	if '1' in arr[i]:
		print(abs(arr[i].index('1') - 2) + abs(i - 2))


transformations = 0
matrix = []
for m in range(5):
	m = [int(x) for x in input().split()]
	matrix.append(m)
s = [(index, row.index(1)) for (index, row) in enumerate(matrix) if 1 in row]
for x in s:
	(ix, iy) = x
while ix < 2 and ix != 2:
	transformations += 1
	ix += 1
while ix > 2 and ix != 2:
	transformations += 1
	ix -= 1
while iy < 2 and iy != 2:
	transformations += 1
	iy += 1
while iy > 2 and iy != 2:
	transformations += 1
	iy -= 1
print(transformations)


L = list(range(5))
for i in range(5):
	L[i] = input().split()
for j in range(5):
	for k in range(5):
		s = L[j][k]
		if s == '1':
			x = j
			y = k
			break
n = abs(2 - x) + abs(2 - y)
print(n)


for row in range(5):
	line = list(map(int, input().strip().split()))
	for (col, n) in enumerate(line):
		if n == 1:
			(one_x, one_y) = (row, col)
(origin_x, origin_y) = (2, 2)
print(abs(origin_x - one_x) + abs(origin_y - one_y))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
(x, y) = (0, 0)
for i in range(25):
	if i < 5:
		curr = a[i]
		y = 1
		x = i + 1
	elif i < 10:
		y = 2
		x = i + 1 - 5
		curr = b[i - 5]
	elif i < 15:
		y = 3
		x = i + 1 - 10
		curr = c[i - 10]
	elif i < 20:
		y = 4
		x = i + 1 - 15
		curr = d[i - 15]
	else:
		y = 5
		x = i + 1 - 20
		curr = e[i - 20]
	if curr == '1':
		if x != 3 or y != 3:
			print(abs(x - 3) + abs(y - 3))
			break
		else:
			print(0)


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
l = [[0 for i in range(5)] for j in range(5)]
l[0] = l1
l[1] = l2
l[2] = l3
l[3] = l4
l[4] = l5
index = [-1, -1]
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			index = [i, j]
if index != [-1, -1]:
	print(abs(index[0] - 2) + abs(index[1] - 2))


l1 = []
steps = 0
for i in range(5):
	l = list(map(int, input().split()))
	l1.append(l)
index_x = 0
index_y = 0
for i in range(len(l1)):
	for j in range(len(l1[i])):
		if l1[i][j] == 1:
			index_x = i + 1
			index_y = j + 1
if index_x < 3:
	steps = 3 - index_x
else:
	steps = index_x - 3
if index_y < 3:
	steps += 3 - index_y
else:
	steps += index_y - 3
print(steps)


l = []
for n in range(5):
	l.append(list(map(int, input().strip().split()))[:5])
(x, y) = (0, 0)
for i in l:
	if 1 in i:
		(x, y) = (l.index(i), i.index(1))
		break
if x == 2 and y == 2:
	print(0)
else:
	print(abs(x - 2) + abs(y - 2))


cr = 0
for r in range(5):
	rows = input().split(' ')
	cr = cr + 1
	for c in range(5):
		if rows[c] == '1':
			r1 = cr
			c1 = c + 1
print(abs(r1 - 3) + abs(c1 - 3))


nol = 5
lines = ''
for i in range(nol):
	lines += input() + '\n'
one_line = lines.split()
n = one_line.index('1')
if n == 0 or n == 4 or n == 20 or (n == 24):
	print('4')
elif n == 1 or n == 3 or n == 5 or (n == 9) or (n == 15) or (n == 19) or (n == 21) or (n == 23):
	print('3')
elif n == 2 or n == 6 or n == 8 or (n == 10) or (n == 14) or (n == 16) or (n == 18) or (n == 22):
	print('2')
elif n == 12:
	print('0')
else:
	print('1')


def main():
	beautiful_row = 3
	beautiful_col = 3
	row = 0
	col = 0
	current_row = 0
	is_found = False
	for current_row in range(5):
		s = input().split()
		if is_found:
			continue
		for current_col in range(len(s)):
			if s[current_col] == '1':
				is_found = True
				row = current_row + 1
				col = current_col + 1
				break
	print(abs(beautiful_row - row) + abs(beautiful_col - col))
main()


import math

def beau_mat():
	for r in range(5):
		matrix = list(map(int, input().split()))
		if sum(matrix) == 1:
			c = matrix.index(1)
			num = math.fabs(2 - r) + math.fabs(2 - c)
			break
	return int(num)
print(beau_mat())


import re
p = re.compile('0|1')
try:
	matrix = []
	(row, col) = (0, 0)
	summer = 0
	counter = 0
	for i in range(5):
		a = []
		(col1, col2, col3, col4, col5) = input().split(' ')
		if bool(p.match(col1)) and bool(p.match(col2)) and bool(p.match(col3)) and bool(p.match(col4)) and bool(p.match(col5)):
			a = [col1, col2, col3, col4, col5]
			if col1 == '1' or col2 == '1' or col3 == '1' or (col4 == '1') or (col5 == '1'):
				counter += 1
				if counter == 1:
					if col1 == '1':
						(row, col) = (i, 0)
					elif col2 == '1':
						(row, col) = (i, 1)
					elif col3 == '1':
						(row, col) = (i, 2)
					elif col4 == '1':
						(row, col) = (i, 3)
					elif col5 == '1':
						(row, col) = (i, 4)
			matrix.append(a)
	if counter == 1:
		summer = abs(2 - row) + abs(2 - col)
		print(summer)
except Exception as e:
	print(e)


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()))
if sum(a) == 1:
	x = 1
	y = a.index(1) + 1
elif sum(b) == 1:
	x = 2
	y = b.index(1) + 1
elif sum(c) == 1:
	x = 3
	y = c.index(1) + 1
elif sum(d) == 1:
	x = 4
	y = d.index(1) + 1
elif sum(e) == 1:
	x = 5
	y = e.index(1) + 1
minx = max([x, 3]) - min([x, 3])
miny = max([y, 3]) - min([y, 3])
print(minx + miny)


(x, y) = (-1, -1)
for i in range(5):
	a = [int(x) for x in input().split()]
	if a.count(1) == 1:
		for j in range(5):
			if a[j] == 1:
				x = i
				y = j
t = abs(2 - x) + abs(2 - y)
print(t)


G = [[0 for i in range(5)] for i in range(5)]
for i in range(0, 5):
	G[i] = list(map(int, input().split(' ')))
for i in range(0, 5):
	for j in range(0, 5):
		if G[i][j]:
			print(abs(j - 2) + abs(i - 2))
			break


n = [2, 1, 0, 1, 2]
for i in n:
	m = input()
	if '1' in m:
		print(i + n[m.find('1') // 2])


for i in range(1, 6):
	a = list(map(int, input().split()))
	if sum(a) == 1:
		c = a.index(1) + 1
		break
print(abs(3 - i) + abs(3 - c))


m = [input().split() for i in range(5)]
i = m.index([x for x in m if '1' in x][0])
r = abs(2 - i)
j = m[i].index('1')
r += abs(2 - j)
print(r)


(x, y) = (0, 0)
for k in range(5):
	l = list(map(int, input().split()))
	for i in range(5):
		if l[i] == 1:
			(x, y) = (k, i)
print(abs(y - 2) + abs(x - 2))


arr = []
for i in range(5):
	n = list(map(int, input().split()))
	arr.append(n)
for mat in arr:
	for num in mat:
		if num == 1:
			hi = arr.index(mat)
			hel = mat.index(num)
		else:
			continue
print(abs(hi - 2) + abs(hel - 2))


def index_nested_list(my_list, element):
	for sub_list in my_list:
		if element in sub_list:
			return (my_list.index(sub_list), sub_list.index(element))
l = []
for _ in range(5):
	l.append(list(map(int, input().split())))
k = index_nested_list(l, 1)
print(abs(2 - k[0]) + abs(2 - k[1]))


import math
for i in range(5):
	line = input().split()
	if '1' in line:
		y = line.index('1')
		x = i
print(abs(2 - x) + abs(2 - y))


matrix = []
for i in range(5):
	temp = input('').replace(' ', '')
	matrix.append(list(temp))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			x = j
			y = i
print(abs(2 - x) + abs(2 - y))


mat = []
for i in range(5):
	t = list(map(int, input().split()))
	mat.append(t)
(x, y) = (0, 0)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			x = i + 1
			y = j + 1
			break
print(abs(3 - x) + abs(3 - y))


def count(i, j):
	return abs(2 - j) + abs(2 - i)

def find(arr):
	for i in range(len(arr)):
		for j in range(len(arr[0])):
			if arr[i][j] == 1:
				return (i, j)

def main():
	arr = []
	t = 5
	while t:
		ar = [int(i) for i in input().split(' ') if i != '']
		arr.append(ar)
		t -= 1
	print(count(*find(arr)))
main()


n = []
steps = 0
for inputval in range(0, 5):
	newinput = input().split()
	n.extend(newinput)
oneindex = n.index('1')
while abs(oneindex - 12) > 2:
	if oneindex < 12:
		oneindex += 5
		steps += 1
	elif oneindex > 12:
		oneindex -= 5
		steps += 1
while abs(oneindex - 12) <= 2 and abs(oneindex - 12) != 0:
	if oneindex < 12:
		oneindex += 1
		steps += 1
	elif oneindex > 12:
		oneindex -= 1
		steps += 1
print(steps)


result = 0
for i in range(0, 5):
	(j, k, l, m, n) = (int(x) for x in input().split())
	if max(j, k, l, m, n) == 1:
		if j == 1:
			result = 2 + abs(3 - i - 1)
		elif k == 1:
			result = 1 + abs(3 - i - 1)
		elif l == 1:
			result = 0 + abs(3 - i - 1)
		elif m == 1:
			result = 1 + abs(3 - i - 1)
		elif n == 1:
			result = 2 + abs(3 - i - 1)
print(result)


for i in range(1, 6):
	l = list(map(int, input().split()))
	for a in l:
		if a == 1:
			x = l.index(a) + 1
			y = i
		else:
			pass
if x == 1 or x == 5:
	s = 2
elif x == 2 or x == 4:
	s = 1
elif x == 3:
	s = 0
if y == 1 or y == 5:
	d = 2
elif y == 2 or y == 4:
	d = 1
elif y == 3:
	d = 0
print(s + d)


from math import fabs
a = [[int(j) for j in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			rem_i = i + 1
			rem_j = j + 1
			break
print(int(fabs(3 - rem_i) + fabs(3 - rem_j)))


matrix = [input().split() for _ in range(5)]

def find_element(matrix):
	for (index, sub_list) in enumerate(matrix):
		for (sub_index, element) in enumerate(sub_list):
			if element != '0':
				return (index, sub_index)
print(sum((abs(index1 - index2) for (index1, index2) in zip(find_element(matrix), (2, 2)))))


count = 0
for i in range(5):
	r = list(map(int, input().split()))
	if len(r) != 5:
		raise ValueError
	if r[0] == 1 or r[4] == 1:
		count += 2
	elif r[1] == 1 or r[3] == 1:
		count += 1
	if 1 in r:
		if i == 0 or i == 4:
			count += 2
		elif i == 1 or i == 3:
			count += 1
print(count)


lis = []
row = col = 10
for _ in range(5):
	lis.append(input().split())
for i in range(5):
	if '1' in lis[i]:
		row = i + 1
		for j in range(5):
			if lis[i][j] == '1':
				col = j + 1
print(abs(3 - row) + abs(3 - col))


m = 5
mat = [[int(j) for j in input().split()[:m]] for i in range(m)]
for i in range(m):
	for j in range(m):
		if mat[i][j]:
			print(abs(i - 2) + abs(j - 2))


arr = []
row_no = 0
col_no = 0
for i in range(5):
	brr = list(map(int, input().split()))
	if 1 in brr:
		row_no = i
		col_no = brr.index(1)
	arr.append(brr)
(t_x, t_y) = (2, 2)
ans = abs(t_x - row_no) + abs(t_y - col_no)
print(ans)


a = [0, 0, 0, 0, 0]
for i in range(5):
	a[i] = list(map(int, input().split()))
x = 0
o = 0
for i in a:
	if o == 1:
		break
	y = 1
	x += 1
	for j in i:
		if j == 0:
			y += 1
			continue
		else:
			o = 1
			break
print(abs(y - 3) + abs(x - 3))


lis = []
for i in range(5):
	lis1 = list(map(int, input().split()))
	lis.append(lis1)
for (i, x) in enumerate(lis):
	if 1 in x:
		posx = i
		posy = x.index(1)
		break
res = abs(posx - 2) + abs(posy - 2)
print(res)


for r in range(5):
	l = input().split()
	if '1' in l:
		c = l.index('1')
		print(abs(2 - r) + abs(2 - c))
		break


from sys import stdin
real_number = [int(x) for x in stdin.read().split()]
c = 1
for x in real_number[0:]:
	if x == 0:
		c += 1
	if x == 1:
		break
if 1 <= c <= 5:
	row = 1
if 6 <= c <= 10:
	row = 2
if 11 <= c <= 15 and c != 13:
	row = 3
if 16 <= c <= 20:
	row = 4
if 21 <= c <= 25:
	row = 5
if c == 1 or c == 6 or c == 11 or (c == 16) or (c == 21):
	column = 1
if c == 2 or c == 7 or c == 12 or (c == 17) or (c == 22):
	column = 2
if c == 3 or c == 8 or c == 18 or (c == 23):
	column = 3
if c == 4 or c == 9 or c == 14 or (c == 19) or (c == 24):
	column = 4
if c == 5 or c == 10 or c == 15 or (c == 20) or (c == 25):
	column = 5
if c == 13:
	print('0')
elif row >= 3 and column >= 3 and (c != 13):
	print(row - 3 + (column - 3))
elif row <= 3 and column >= 3 and (c != 13):
	print(3 - row + (column - 3))
elif row >= 3 and column <= 3 and (c != 13):
	print(row - 3 + (3 - column))
elif row < 3 and column < 3 and (c != 13):
	print(3 - row + (3 - column))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().strip().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().strip().split()]

def LS():
	return sys.stdin.readline().strip().split()

def I():
	return int(sys.stdin.readline().strip())

def F():
	return float(sys.stdin.readline().strip())

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

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))
from math import factorial, gcd
from random import choice, randint
from sys import stdin, stdout
inp = stdin.readline
out = stdout.write

def main():
	s = [LI() for i in range(5)]
	for i in range(5):
		for j in range(5):
			if s[i][j] == 1:
				print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
				break
main()


matrix = []
st = ''
s = 0
for i in range(5):
	for j in range(1):
		st = st + input()
	matrix.append(st.split(' '))
	st = ''
for i in range(5):
	for j in range(5):
		if int(matrix[i][j]) == 1:
			if 1 != matrix[2][2]:
				if j != 2 and i != 2:
					s = abs(2 - j) + abs(2 - i)
				elif j != 2 and i == 2:
					s = abs(2 - j)
				else:
					s = abs(2 - i)
			else:
				s = 0
print(s)


op = 1
r = 0
key = 1
while op:
	list1 = [int(i) for i in input().split()]
	for j in range(0, 5):
		if list1[j] == key:
			print(abs(2 - j) + abs(2 - r))
			op = 0
	r = r + 1


(linea, columna) = (0, 0)
for i in range(5):
	l = input().split()
	for j in range(5):
		if int(l[j]) == 1:
			linea = j
			columna = i
print(abs(linea - 2) + abs(columna - 2))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
qwer = [a, b, c, d, e]
for i in qwer:
	if '1' in i:
		k = qwer.index(i)
		f = i
r = f.index('1')
k += 1
r += 1
if k == 1:
	u = 2
elif k == 2:
	u = 1
elif k == 3:
	u = 0
elif k == 4:
	u = 1
elif k == 5:
	u = 2
if r == 1:
	u += 2
elif r == 2:
	u += 1
elif r == 3:
	pass
elif r == 4:
	u += 1
elif r == 5:
	u += 2
print(u)


for i in range(5):
	lst = list(map(int, input().split()))
	if 1 in lst:
		col = lst.index(1)
		print(abs(col - 2) + abs(i - 2))
		break


for ri in range(5):
	row = input().split(' ')
	if '1' in row:
		print(abs(2 - ri) + abs(2 - row.index('1')))


a = [[int(x) for x in input().strip().split(' ')] for y in range(0, 5)]
for i in range(0, len(a)):
	for j in range(0, 5):
		if a[i][j] == 1:
			b = i
			c = j
			break
if b == 0 and c == 0 or (b == 4 and c == 0) or (b == 4 and c == 4) or (b == 0 and c == 4):
	print(4)
elif b == 4 and c == 1 or (b == 0 and c == 1) or (b == 0 and c == 3) or (b == 4 and c == 3):
	print(3)
elif b == 1 and c == 0 or (b == 3 and c == 0) or (b == 1 and c == 4) or (b == 3 and c == 4):
	print(3)
elif b == 1 and c == 1 or (b == 3 and c == 1) or (b == 1 and c == 3) or (b == 3 and c == 3):
	print(2)
elif b == 1 and c == 1 or (b == 3 and c == 1) or (b == 3 and c == 3) or (b == 1 and c == 3):
	print(2)
elif b == 1 and c == 2 or (b == 2 and c == 1) or (b == 2 and c == 3) or (b == 3 and c == 2):
	print(1)
elif b == 0 and c == 2 or (b == 4 and c == 2):
	print(2)
elif b == 2 and c == 0 or (b == 2 and c == 4):
	print(2)
else:
	print(0)


i = 0
word = input('').replace(' ', '')
while word.find('1') < 0:
	word = input('').replace(' ', '')
	i += 1
print(abs(2 - i) + abs(2 - word.find('1')))


(i, j) = (0, 0)
for x in range(1, 6):
	l = list(input().split())
	if '1' in l:
		(i, j) = (x, l.index('1') + 1)
print(abs(i - 3) + abs(j - 3))


row = 0
col = 0
for i in range(5):
	line = str(input())
	if '1' in line:
		row = i
		col = int(line.index('1') / 2)
		break
print(abs(row - 2) + abs(col - 2))


for i in range(0, 5):
	p = input().split()
	if '1' in p:
		z = abs(i - 2) + abs(p.index('1') - 2)
print(z)


a = list(input().split(' '))
b = list(input().split(' '))
c = list(input().split(' '))
d = list(input().split(' '))
e = list(input().split(' '))
if '1' in a:
	if a[0] == '1':
		print(4)
	if a[1] == '1':
		print(3)
	if a[2] == '1':
		print(2)
	if a[3] == '1':
		print(3)
	if a[4] == '1':
		print(4)
if '1' in b:
	if b[0] == '1':
		print(3)
	if b[1] == '1':
		print(2)
	if b[2] == '1':
		print(1)
	if b[3] == '1':
		print(2)
	if b[4] == '1':
		print(3)
if '1' in c:
	if c[0] == '1':
		print(2)
	if c[1] == '1':
		print(1)
	if c[2] == '1':
		print(0)
	if c[3] == '1':
		print(1)
	if c[4] == '1':
		print(2)
if '1' in d:
	if d[0] == '1':
		print(3)
	if d[1] == '1':
		print(2)
	if d[2] == '1':
		print(1)
	if d[3] == '1':
		print(2)
	if d[4] == '1':
		print(3)
if '1' in e:
	if e[0] == '1':
		print(4)
	if e[1] == '1':
		print(3)
	if e[2] == '1':
		print(2)
	if e[3] == '1':
		print(3)
	if e[4] == '1':
		print(4)


lst = []
for n in range(5):
	a = list(map(int, input().strip().split()))[:5]
	lst.append(a)
flag = 0
for n in range(5):
	for m in range(5):
		if lst[n][m] is not 0:
			flag = 100
			break
		if flag is 100:
			break
	if flag is 100:
		break
print(abs(2 - n) + abs(2 - m))


lst = []
for i in range(5):
	inp = input().split()
	lst.append(inp)
for sublist in lst:
	if '1' in sublist:
		print(abs(lst.index(sublist) - 2) + abs(sublist.index('1') - 2))


for i in range(0, 5):
	s = input().split()
	if '1' in s:
		print(abs(2 - s.index('1')) + abs(2 - i))
		break


import math
a = []
for i in range(5):
	column = input()
	temp = column.find('1')
	if temp != -1:
		(x, y) = (i, math.floor(temp / 2))
print(abs(x - 2) + abs(y - 2))


st1 = [int(i) for i in input().split()]
st2 = [int(i) for i in input().split()]
st3 = [int(i) for i in input().split()]
st4 = [int(i) for i in input().split()]
st5 = [int(i) for i in input().split()]
a = 0
b = 0
if sum(st1) == 1 or sum(st5) == 1:
	a = 2
elif sum(st2) == 1 or sum(st4) == 1:
	a = 1
for st in [st1, st2, st3, st4, st5]:
	if st[0] == 1 or st[-1] == 1:
		b = 2
	elif st[1] == 1 or st[-2] == 1:
		b = 1
print(a + b)


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
for i in range(5):
	if 1 in mat[i]:
		x = i
		y = mat[i].index(1)
s = 0
s += abs(2 - x)
s += abs(2 - y)
print(s)


rows = [0, 0, 0, 0, 0]
r = -1
c = -1
for i in range(5):
	row = input().split()
	rows[i] = row
	for j in range(5):
		if row[j] == '1':
			r = i
			c = j
			break
	if r != -1:
		break
print(abs(2 - r) + abs(2 - c))


from math import *
parameters = ['j k', 'kdsj', 'jnhf', 'rjfh', 'jf']
moves = 0
for i in range(0, 5):
	parameters[i] = str(input())
	for j in range(0, 10, 2):
		if parameters[i][j] == '1':
			if j == 0 or j == 8:
				moves += 2
			elif j == 2 or j == 6:
				moves += 1
			if i == 0 or i == 4:
				moves += 2
			elif i == 1 or i == 3:
				moves += 1
print(moves)


l = list()
for _ in range(5):
	l.append(list(map(int, input().split())))
flag = False
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			flag = True
			break
	if flag == True:
		break
print(abs(2 - i) + abs(2 - j))


import sys

def read_lines(n):
	return [sys.stdin.readline().strip() for _ in range(n)]
lines = read_lines(5)
positions = [(index, row.index('1')) for (index, row) in enumerate([x.split() for x in lines]) if '1' in row]
print(abs(2 - positions[0][0]) + abs(2 - positions[0][1]))


matrix = []
for _ in range(5):
	matrix.append([int(x) for x in input().split()])
(row, col) = (-1, -1)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i + 1
			col = j + 1
			break
print(abs(3 - row) + abs(3 - col))


import math
counter = 0
for i in range(0, 5):
	s = input().split()
	counter += 1
	if '1' in s:
		break
counter = math.fabs(3 - counter)
counter2 = 0
for i in range(0, 5):
	counter2 += 1
	if s[i] == '1':
		break
counter2 = math.fabs(3 - counter2)
print(int(counter + counter2))


import sys
for i in range(5):
	vals = sys.stdin.readline()[:-1]
	if '1' in vals:
		y = vals.split(' ').index('1') + 1
		x = i + 1
		break
print(abs(x - 3) + abs(y - 3))


mat = [[0 for i in range(5)] for j in range(5)]
(idx, idy) = (0, 0)
for i in range(5):
	mat[i] = [int(k) for k in input().split()]
	for j in range(5):
		if mat[i][j] == 1:
			(idx, idy) = (i, j)
num_mods = abs(idx - 2) + abs(idy - 2)
print(num_mods)


arr = []
for i in range(5):
	arr.append(input().split(' '))
one_i = -1
one_j = -1
for i in range(5):
	for j in range(5):
		if arr[i][j] == '1':
			one_i = i
			one_j = j
print(abs(one_i - 2) + abs(one_j - 2))


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
b = True
i = 0
c = [0, 0]
while b:
	if 1 in a[i]:
		c[0] = i
		c[1] = a[i].index(1)
		b = False
	i += 1
print(abs(c[0] - 2) + abs(c[1] - 2))


k = 0
l = 0
for i in range(5):
	x = [int(x) for x in input().split()]
	for j in range(5):
		if x[j] == 1:
			k = abs(2 - j)
			l = abs(2 - i)
			break
print(k + l)
end = ' '


one = input().split(' ')
two = input().split(' ')
three = input().split(' ')
four = input().split(' ')
five = input().split(' ')
if '1' in one:
	if one.index('1') == 0 or one.index('1') == 4:
		print('4')
	elif one.index('1') == 2:
		print('2')
	else:
		print('3')
elif '1' in two:
	if two.index('1') == 0 or two.index('1') == 4:
		print('3')
	elif two.index('1') == 2:
		print('1')
	else:
		print(2)
elif '1' in three:
	if three.index('1') == 0 or three.index('1') == 4:
		print('2')
	elif three.index('1') == 2:
		print('0')
	else:
		print('1')
elif '1' in four:
	if four.index('1') == 0 or four.index('1') == 4:
		print('3')
	elif four.index('1') == 2:
		print('1')
	else:
		print('2')
elif '1' in five:
	if five.index('1') == 0 or five.index('1') == 4:
		print('4')
	elif five.index('1') == 2:
		print('2')
	else:
		print('3')


c = None
for r in range(5):
	col = input().split()
	try:
		c = col.index('1')
	except ValueError:
		continue
	else:
		print(abs(2 - r) + abs(2 - c))
		exit()


a = 0
b = 0
for i in range(5):
	l = [int(x) for x in input().split()]
	for j in range(5):
		if l[j]:
			a = i
			b = j
			break
print(abs(2 - a) + abs(2 - b))


from math import fabs
mass = []
for i in range(5):
	(a, b, c, d, e) = input().split()
	mass.append(int(a))
	mass.append(int(b))
	mass.append(int(c))
	mass.append(int(d))
	mass.append(int(e))
iD = 0
for i in mass:
	if i == 1:
		break
	iD += 1
y = fabs(2 - iD // 5)
x = fabs(2 - iD % 5)
ans = x + y
print(int(ans))


def matrix():
	y = 0
	counter = 0
	found = 0
	for a in range(5):
		n = list(map(int, input().split()))
		i = 0
		for b in range(5):
			if n[i] != 1:
				i += 1
			else:
				if i != 2:
					move = abs(i - 2)
					counter += move
					found += 1
					i += 1
				elif i == 2:
					found += 1
					i += 1
				if found != 0:
					move = abs(y - 2)
					counter += move
		y += 1
	print(counter)
matrix()


def matrix_check_1(matrix):
	i = 0
	while i != 5:
		j = 0
		while j != 5:
			if matrix[i][j] == '1':
				return [i, j]
			else:
				j += 1
		i += 1
matrix1 = []
for _ in range(5):
	matrix1.append(input().split(' '))
n = matrix_check_1(matrix1)
res = 0
res += abs(2 - n[0])
res += abs(2 - n[1])
print(res)


index = 0
count = 0
mid = 2
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()))
if 1 in b:
	for i in range(len(b)):
		if b[i] < 1:
			count += 1
		if b[i] == 1:
			break
	if count >= mid:
		index = count - mid
	else:
		index = mid - count
	print(index + 1)
if 1 in a:
	for i in range(len(a)):
		if a[i] < 1:
			count += 1
		if a[i] == 1:
			break
	if count >= mid:
		index = count - mid
	else:
		index = mid - count
	print(index + 2)
if 1 in c:
	for i in range(len(c)):
		if c[i] < 1:
			count += 1
		if c[i] == 1:
			break
	if count >= mid:
		index = count - mid
	else:
		index = mid - count
	print(index)
if 1 in d:
	for i in range(len(d)):
		if d[i] < 1:
			count += 1
		if d[i] == 1:
			break
	if count >= mid:
		index = count - mid
	else:
		index = mid - count
	print(index + 1)
if 1 in e:
	for i in range(len(e)):
		if e[i] < 1:
			count += 1
		if e[i] == 1:
			break
	if count >= mid:
		index = count - mid
	else:
		index = mid - count
	print(index + 2)


l = []
for i in range(5):
	e = input()
	l.append(e)
moves = 0
x = ''.join(l)
x = x.replace(' ', '')
ll = list(x)
for i in ll:
	if i == '1':
		row = int((ll.index(i) + 1) / 5)
		rown = int((ll.index(i) + 1) % 5)
		if rown == 0:
			row -= 1
			if row == 0 or row == 4:
				moves += 2
			elif row == 1 or row == 3:
				moves += 1
			else:
				continue
		elif row == 0 or row == 4:
			moves += 2
		elif row == 1 or row == 3:
			moves += 1
		else:
			continue
	else:
		continue
for i in ll:
	if i == '1':
		col = int((ll.index(i) + 1) % 5)
		if col == 0:
			moves += 2
		elif col == 1:
			moves += 2
		elif col == 2 or col == 4:
			moves += 1
		else:
			continue
	else:
		continue
print(moves)


for k in range(5):
	a = list(input().split(' '))
	for l in range(5):
		if int(a[l]) == 1:
			c = abs(l - 2) + abs(k - 2)
print(c)


matrix = []
ko = 0
sw1 = []
ke = int
for i in range(5):
	s = list(map(int, input().split(maxsplit=4)))
	matrix.append(s)
numbers = [1, 2, 3, 4, 5]
matrix = dict(zip(numbers, matrix))
for i in matrix.values():
	if 1 in i:
		sw1 = i
if sw1.index(1) == 4:
	ko += 2
if sw1.index(1) == 0:
	ko += 2
if sw1.index(1) == 1:
	ko += 1
if sw1.index(1) == 3:
	ko += 1
for (k, v) in matrix.items():
	if 1 in v:
		ke = k
		break
if ke == 1:
	ko += 2
if ke == 5:
	ko += 2
if ke == 2:
	ko += 1
if ke == 4:
	ko += 1
print(ko)


c = 1
r = 1
row = 0
col = 0
for t in range(5):
	s = input()
	c = 1
	for i in s:
		if i is '0':
			c += 1
		elif i is '1':
			col = c
			row = r
			break
	r += 1
print(abs(row - 3) + abs(col - 3))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
x = 0
y = 0
for k in range(0, 5):
	if '1' == a[k]:
		x = 2
		y = k + 1
	if '1' == b[k]:
		x = 1
		y = k + 1
	if '1' == c[k]:
		x = 0
		y = k + 1
	if '1' == d[k]:
		x = 1
		y = k + 1
	if '1' == e[k]:
		x = 2
		y = k + 1
print(x + abs(y - 3))


for i in range(5):
	lst = input().split()
	if '1' in lst:
		x = i + 1
		y = lst.index('1') + 1
print(abs(x - 3) + abs(y - 3))


for i in range(5):
	arr = list(map(int, input().strip().split()))
	if 1 in arr:
		row = i + 1
		col = arr.index(1) + 1
res = abs(row - 3) + abs(col - 3)
print(res)


i = 0
s = list()
t = list()
r = 0
while i < 5:
	n = input()
	s.append(n)
	i = i + 1
for f in s:
	t = f.split()
	r = r + 1
	c = 0
	for q in t:
		c = c + 1
		q = int(q)
		if q == 1:
			a = 3 - r
			b = 3 - c
			a = abs(a)
			b = abs(b)
			print(a + b)


l = []
c = 0
for i in range(5):
	n = input().split()
	l.append(n)
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			c = abs(3 - i - 1) + abs(3 - j - 1)
			break
	if c:
		break
print(c)


answer = 0
for i in range(5):
	a = [int(elem) for elem in input().split()]
	if 1 in a:
		for j in range(5):
			if a[j] == 1:
				answer = abs(3 - i - 1) + abs(3 - j - 1)
print(answer)


for i in range(5):
	row = input().split()
	if '1' in row:
		temp = row.index('1')
		col_pos = temp
		row_pos = i
print(abs(col_pos - 2) + abs(row_pos - 2))


from math import fabs
a = []
for i in range(5):
	a += [list(map(int, input().split()))]
b = sum(map(lambda x: sum(a[x]) * x, range(5)))
c = a[b].index(1)
print(int(fabs(b - 2) + fabs(c - 2)))


arr = []
for _ in range(5):
	arr.append(input().split())
s = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == '1':
			s = abs(2 - i) + abs(2 - j)
			break
print(s)


import sys
matrix = sys.stdin.readlines()
input_matrix = []
for line in matrix:
	line = line.strip()
	input_matrix.append(line.split())

def beautiful_matrix(input_matrix):
	(target_i, target_j) = (2, 2)
	(current_i, current_j) = (-1, -1)
	for i in range(5):
		for j in range(5):
			if input_matrix[i][j] == '1':
				(current_i, current_j) = (i, j)
	print(abs(current_i - target_i) + abs(current_j - target_j))
beautiful_matrix(input_matrix)


text1 = input('')
text2 = input('')
text3 = input('')
text4 = input('')
text5 = input('')
satir1 = ''
satir2 = ''
satir3 = ''
satir4 = ''
satir5 = ''
for i in text1:
	if i != ' ':
		satir1 += i
for i in text2:
	if i != ' ':
		satir2 += i
for i in text3:
	if i != ' ':
		satir3 += i
for i in text4:
	if i != ' ':
		satir4 += i
for i in text5:
	if i != ' ':
		satir5 += i
for i in satir1:
	if i == '1':
		dikey = 2
		yatay = 2 - satir1.index('1')
		if yatay < 0:
			yatay *= -1
for i in satir2:
	if i == '1':
		dikey = 1
		yatay = 2 - satir2.index('1')
		if yatay < 0:
			yatay *= -1
for i in satir3:
	if i == '1':
		dikey = 0
		yatay = 2 - satir3.index('1')
		if yatay < 0:
			yatay *= -1
for i in satir4:
	if i == '1':
		dikey = 1
		yatay = 2 - satir4.index('1')
		if yatay < 0:
			yatay *= -1
for i in satir5:
	if i == '1':
		dikey = 2
		yatay = 2 - satir5.index('1')
		if yatay < 0:
			yatay *= -1
print(dikey + yatay)


for i in range(5):
	mat = list(map(int, input().split()))
	if 1 in mat:
		(r, l) = (i, mat.index(1))
print(abs(2 - r) + abs(2 - l))


for j in range(5):
	row = [int(x) for x in input().split(' ')]
	if 1 in row:
		i = row.index(1)
		if j >= 2:
			j -= 2
		else:
			j = 2 - j
		if i >= 2:
			i -= 2
		else:
			i = 2 - i
		print(j + i)


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(' ')))
col = int('0')
row = int('0')
if 1 in row1:
	col = int('1')
	row = row1.index(1)
if 1 in row2:
	col = int('2')
	row = row2.index(1)
if 1 in row3:
	col = int('3')
	row = row3.index(1)
if 1 in row4:
	col = int('4')
	row = row4.index(1)
if 1 in row5:
	col = int('5')
	row = row5.index(1)
row += 1
print(abs(3 - row) + abs(3 - col))


WKtorymWierszu = NaKtorejKolumnie = 0
for i in range(5):
	TablicaZKlawiatury = input().split(' ')
	for J in range(5):
		if TablicaZKlawiatury[J] == '1':
			NaKtorejKolumnie = J
			WKtorymWierszu = i
			break
OIleWierszy = abs(2 - WKtorymWierszu)
OLieKolumn = abs(2 - NaKtorejKolumnie)
print(OLieKolumn + OIleWierszy)


count = 0
rows = []
while count < 5:
	rows.append(input())
	count += 1
for (index, row) in enumerate(rows):
	if '1' in row:
		for (i, col) in enumerate(rows[index].replace(' ', '')):
			if '1' in col:
				output = abs(2 - index) + abs(i - 2)
				print(output)


l = []
for i in range(5):
	l.append(list(map(int, input().split())))
	if 1 in l[i]:
		y = i
x = l[y].index(1)
print(abs(3 - (y + 1)) + abs(3 - (x + 1)))


listagenetal = []
linea1 = input().split()
listagenetal.append(linea1)
linea2 = input().split()
listagenetal.append(linea2)
linea3 = input().split()
listagenetal.append(linea3)
linea4 = input().split()
listagenetal.append(linea4)
linea5 = input().split()
listagenetal.append(linea5)
for i in range(len(listagenetal)):
	if '1' in listagenetal[i]:
		a = abs(2 - i)
for x in listagenetal:
	for y in range(len(x)):
		if x[y] == '1':
			b = abs(2 - y)
print(a + b)


(a1, a2, a3, a4, a5) = [int(i) for i in input().split()]
(b1, b2, b3, b4, b5) = [int(i) for i in input().split()]
(c1, c2, c3, c4, c5) = [int(i) for i in input().split()]
(d1, d2, d3, d4, d5) = [int(i) for i in input().split()]
(e1, e2, e3, e4, e5) = [int(i) for i in input().split()]
x = 0
if (a1 or a2 or a3 or a4 or a5 or e1 or e2 or e3 or e4 or e5) != 0:
	x += 2
elif (b1 or b2 or b3 or b4 or b5 or d1 or d2 or d3 or d4 or d5) != 0:
	x += 1
else:
	x += 0
if (a1 or b1 or c1 or d1 or e1 or a5 or b5 or c5 or d5 or e5) != 0:
	x += 2
elif (a2 or b2 or c2 or d2 or e2 or a4 or b4 or c4 or d4 or e4) != 0:
	x += 1
else:
	x += 0
print(x)


for i in range(1, 6):
	num = list(map(int, input().split()))
	if num.count(1):
		print(abs(3 - (num.index(1) + 1)) + abs(3 - i))


matrix = []
for i in range(5):
	li = list(map(int, input().split(' ')))
	matrix.append(li)
exact_a = 2
exact_b = 2
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			dest_a = i
			dest_b = j
			break
res_a = abs(dest_a - exact_a)
res_b = abs(dest_b - exact_b)
print(res_a + res_b)


import math
grid = []
for i in range(5):
	string = input()
	row = string.split(' ')
	grid.append(row)
if '1' in grid[0]:
	a = [1, grid[0].index('1') + 1]
elif '1' in grid[1]:
	a = [2, grid[1].index('1') + 1]
elif '1' in grid[2]:
	a = [3, grid[2].index('1') + 1]
elif '1' in grid[3]:
	a = [4, grid[3].index('1') + 1]
elif '1' in grid[4]:
	a = [5, grid[4].index('1') + 1]
move = abs(a[0] - 3) + abs(a[1] - 3)
print(move)


def minSteps(matrix):
	prow = 0
	pcol = 0
	for row in range(5):
		for col in range(5):
			if matrix[row][col] == 1:
				prow = row
				pcol = col
	return abs(prow - 2) + abs(pcol - 2)
matrix = [[int(ele) for ele in input().split()] for i in range(5)]
print(minSteps(matrix))


list = [2, 1, 0, 1, 2]
for i in range(0, 5):
	s = input()
	if '1' in s:
		a = list[i] + abs(int(s.find('1') / 2) - 2)
print(a)


a = input().split(' ')
b = input().split(' ')
c = input().split(' ')
d = input().split(' ')
e = input().split(' ')
count = 0
if '1' in a:
	count += 2
	v = a.index('1')
	if v != 2:
		count += abs(v - 2)
elif '1' in e:
	count += 2
	v = e.index('1')
	if v != 2:
		count += abs(v - 2)
elif '1' in b:
	count += 1
	v = b.index('1')
	if v != 2:
		count += abs(v - 2)
elif '1' in d:
	count += 1
	v = d.index('1')
	if v != 2:
		count += abs(v - 2)
elif '1' in c:
	v = c.index('1')
	if v != 2:
		count += abs(v - 2)
print(count)


row = 0
column = 0
for i in range(1, 6):
	test = [int(i) for i in input().split()]
	if 1 in test:
		column = test.index(1) + 1
		row = i
result = abs(3 - row) + abs(3 - column)
print(result)


for i in range(5):
	t = input().split()
	for j in range(len(t)):
		if t[j] == '1':
			print(abs(2 - int(j)) + abs(2 - i))


def main():
	for i in range(5):
		col_of_one = input().find('1')
		if col_of_one != -1:
			col_of_one //= 2
			transformations_x = abs(2 - col_of_one)
			transformations_y = abs(2 - i)
			print(transformations_x + transformations_y)
main()


n = 5
matrix = [] * n
middle_row = 2
middle_col = 2
moves = 0
for i in range(n):
	matrix.append(list(map(int, input().split())))
for i in range(n):
	for j in range(n):
		if matrix[i][j] == 1:
			print(abs(middle_row - i) + abs(middle_col - j))


(i1, i2, i3, i4, i5) = list(map(int, input().strip().split()))
(i6, i7, i8, i9, i10) = list(map(int, input().strip().split()))
(i11, i12, i13, i14, i15) = list(map(int, input().strip().split()))
(i16, i17, i18, i19, i20) = list(map(int, input().strip().split()))
(i21, i22, i23, i24, i25) = list(map(int, input().strip().split()))
if i1 or i5 or i25 or (i21 == 1):
	print(4)
if i2 or i4 or i10 or i20 or i24 or i22 or i16 or (i6 == 1):
	print(3)
if i13 == 1:
	print(0)
if i8 or i14 or i18 or (i12 == 1):
	print(1)
if i3 or i9 or i15 or i19 or i23 or i17 or i11 or (i7 == 1):
	print(2)


imt = [list(map(int, input().strip().split())) for i in range(5)]
for i in range(1, 6):
	for j in range(1, 6):
		if imt[i - 1][j - 1] == 1:
			print(abs(i - 3) + abs(j - 3))


data = []
for x in range(0, 5):
	data.append(input().split(' '))
row = 0
column = 0
for i in range(0, 5):
	for j in range(0, 5):
		if data[i][j] == '1':
			row = i
			column = j
rr = abs(row - 2)
rc = abs(column - 2)
print(rr + rc)


arr = [x[:] for x in [[0] * 5] * 5]
arr = []
for k in range(0, 5):
	lst = input().split()
	arr.append(lst)
for i in range(5):
	for j in range(5):
		if arr[i][j] == '1':
			result = abs(2 - i) + abs(2 - j)
print(result)


res = []
for i in range(5):
	res.append(list(map(int, input().split())))
(res_i, res_j) = (0, 0)
for i in range(5):
	for j in range(5):
		if res[i][j] == 1:
			(res_i, res_j) = (i + 1, j + 1)
			break
print(abs(res_i - 3) + abs(res_j - 3))


from sys import stdin
input = stdin.readline
graph = [list(map(int, input().split())) for _ in range(5)]
for i in range(5):
	for j in range(5):
		if graph[i][j]:
			a = max(3, i + 1) - min(3, i + 1)
			b = max(3, j + 1) - min(3, j + 1)
			print(a + b)
			break


m = []
(_x, _y) = (0, 0)
(bx, by) = (3, 3)
for i in range(1, 6):
	r = [int(x) for x in input().split(' ')]
	for x in enumerate(r, start=1):
		(j, v) = x
		if v == 1:
			(_x, _y) = (i, j)
			break
moves = abs(bx - _x) + abs(by - _y)
print(moves)


M = [list(map(int, input().split())) for _ in range(5)]
r = [1 in x for x in M].index(True)
c = M[r].index(1)
d = abs(r - 2) + abs(c - 2)
print(d)


mat = []
for i in range(5):
	mat.append(list(map(int, input().rstrip().split())))
(row, col) = (None, None)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			(row, col) = (i + 1, j + 1)
			break
print(abs(row - 3) + abs(col - 3))


from sys import stdin
matrix = [[s for s in stdin.readline().strip().split(' ')] for _ in range(0, 5)]
row_idx = next((idx for (idx, row) in enumerate(matrix) if '1' in row))
col_idx = matrix[row_idx].index('1')
result = abs(2 - row_idx) + abs(2 - col_idx)
print(result)


c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))
c4 = list(map(int, input().split()))
c5 = list(map(int, input().split()))
n = 1
s = 0
if n in c1:
	s += 2
	if c1.index(n) == 0 or c1.index(n) == 4:
		s += 2
	elif c1.index(n) == 1 or c1.index(n) == 3:
		s += 1
elif n in c2:
	s += 1
	if c2.index(n) == 0 or c2.index(n) == 4:
		s += 2
	elif c2.index(n) == 1 or c2.index(n) == 3:
		s += 1
elif n in c3:
	if c3.index(n) == 0 or c3.index(n) == 4:
		s += 2
	elif c3.index(n) == 1 or c3.index(n) == 3:
		s += 1
elif n in c4:
	s += 1
	if c4.index(n) == 0 or c4.index(n) == 4:
		s += 2
	elif c4.index(n) == 1 or c4.index(n) == 3:
		s += 1
elif n in c5:
	s += 2
	if c5.index(n) == 0 or c5.index(n) == 4:
		s += 2
	elif c5.index(n) == 1 or c5.index(n) == 3:
		s += 1
print(s)


n = 0
for i in range(1, 6):
	l = list(map(int, input().split()))
	if 1 in l:
		n += abs(3 - i)
		j = l.index(1) + 1
		n += abs(3 - j)
print(n)


for r in range(5):
	row = input().split()
	for c in range(5):
		if row[c] == '1':
			moves = abs(r - 2) + abs(c - 2)
			print(moves)


matrixRow = []
indexRow = 0
indexCol = 0
turn = 0
for row in range(5):
	matrixRow = input().split()
	if '1' in matrixRow:
		indexRow = row + 1
		indexCol = matrixRow.index('1') + 1
if indexRow > 3:
	turn = turn + (indexRow - 3)
else:
	turn = turn + (3 - indexRow)
if indexCol > 3:
	turn = turn + (indexCol - 3)
else:
	turn = turn + (3 - indexCol)
print(turn)


f = []
x = []
n = 0
m = 0
for i in range(5):
	x = input().split()
	f.append(x)
for i in range(5):
	for j in range(5):
		if f[i][j] == '1':
			m = i - 2
			n = j - 2
print(abs(m) + abs(n))


mx = [[0 for x in range(5)] for y in range(5)]
ax = 0
ay = 0
for y in range(5):
	mx[y] = list(map(int, input().split()))
	for x in range(5):
		if mx[y][x] == 1:
			ax = x
			ay = y
print(abs(ax - 2) + abs(ay - 2))


for indexRow in range(1, 6):
	row = input().split(' ')
	indexColum = -1 if not '1' in row else row.index('1') + 1
	if indexColum >= 0:
		print(abs(indexRow - 3) + abs(indexColum - 3))
		break


columns = []
moves = 0
for x in [0] * 5:
	columns.append(input().split())
for (index, row) in enumerate(columns):
	if '1' in row:
		moves += abs(2 - row.index('1'))
		moves += abs(2 - index)
print(moves)


def moves(i, j):
	m = abs(i - 3) + abs(j - 3)
	print(m)
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()))
if 1 in a:
	moves(1, a.index(1) + 1)
elif 1 in b:
	moves(2, b.index(1) + 1)
elif 1 in c:
	moves(3, c.index(1) + 1)
elif 1 in d:
	moves(4, d.index(1) + 1)
else:
	moves(5, e.index(1) + 1)


steps = 0
sor = 0
oszlop = 0
for i in range(1, 6):
	a = [int(i) for i in input().split()[:5]]
	for j in range(5):
		if a[j] == 1:
			sor = i
			oszlop = j + 1
			steps = abs(3 - sor) + abs(3 - oszlop)
print(steps)


for i in range(5):
	s = input().split()
	if '1' in s:
		break
for j in range(5):
	if s[j] == '1':
		break
print(abs(j - 2) + abs(i - 2))


one = input().split()
two = input().split()
three = input().split()
four = input().split()
five = input().split()
xcord = 0
ycord = 0
moves = 0
for i in range(0, 5):
	if one[i] == '1':
		xcord = i + 1
		ycord = 1
	elif two[i] == '1':
		xcord = i + 1
		ycord = 2
	elif three[i] == '1':
		xcord = i + 1
		ycord = 3
	elif four[i] == '1':
		xcord = i + 1
		ycord = 4
	elif five[i] == '1':
		xcord = i + 1
		ycord = 5
if xcord > 3:
	moves += xcord - 3
elif xcord == 3:
	moves += 0
elif xcord < 3:
	moves += 3 - xcord
if ycord > 3:
	moves += ycord - 3
elif ycord == 3:
	moves += 0
elif ycord < 3:
	moves += 3 - ycord
print(moves)


(a1, a2, a3, a4, a5) = map(int, input().split())
(b1, b2, b3, b4, b5) = map(int, input().split())
(c1, c2, c3, c4, c5) = map(int, input().split())
(d1, d2, d3, d4, d5) = map(int, input().split())
(e1, e2, e3, e4, e5) = map(int, input().split())
if a1 == 1 or a5 == 1 or e1 == 1 or (e5 == 1):
	print(4)
elif a2 == 1 or a4 == 1 or b1 == 1 or (b5 == 1) or (d1 == 1) or (d5 == 1) or (e2 == 1) or (e4 == 1):
	print(3)
elif a3 == 1 or b2 == 1 or b4 == 1 or (c1 == 1) or (c5 == 1) or (d2 == 1) or (d4 == 1) or (e3 == 1):
	print(2)
elif b3 == 1 or c2 == 1 or c4 == 1 or (d3 == 1):
	print(1)
else:
	print(0)


for i in range(5):
	a = input().split()
	for j in range(5):
		if a[j] == '1':
			print(abs(i - 2) + abs(j - 2))
			exit(0)


rpos = 0
cpos = 0
for x in range(0, 5):
	s = input()
	l = s.split(' ')
	for p in range(0, len(l)):
		if l[p] == '1':
			cpos = p + 1
			rpos = x + 1
			break
print(abs(rpos - 3) + abs(cpos - 3))


A = [2, 1, 0, 1, 2]
for i in A:
	N = input()
	if '1' in N:
		print(i + A[N.find('1') // 2])


matrix = []
pos = [0, 0]
moves = 0
for i in range(5):
	row = input()
	matrix.append(row.split())
	if row.count('1') > 0:
		pos[0] = matrix[len(matrix) - 1].index('1')
		pos[1] = i
if pos[0] > 2:
	moves += abs(pos[0] - 2)
elif pos[0] < 2:
	moves += 2 - pos[0]
if pos[1] > 2:
	moves += abs(pos[1] - 2)
elif pos[1] < 2:
	moves += 2 - pos[1]
print(moves)


a = list(input())
b = list(input())
c = list(input())
d = list(input())
e = list(input())
t = 0
if '1' in a:
	t = t + 2
	d = a
elif '1' in b:
	t = t + 1
	d = b
elif '1' in d:
	t = t + 1
	d = d
elif '1' in e:
	t = t + 2
	d = e
elif '1' in c:
	t = 0
	d = c
while ' ' in d:
	d.remove(' ')
i = d.index('1') + 1
t = t + abs(3 - i)
print(t)


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
matrix = [a, b, c, d, e]
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))


line = 0
col = 0
for i in range(5):
	t = input()
	t = t.split()
	if '1' in t:
		for j in range(5):
			if t[j] == '1':
				col = j
				break
		break
	else:
		line += 1
print(abs(2 - line) + abs(2 - col))


matrix = list()
for i in range(5):
	row = input().split()
	if '1' in row:
		x = i
		y = row.index('1')
print(abs(x - 2) + abs(y - 2))


def solve(arr):
	if arr[2][2] == 1:
		return 0
	else:
		for i in range(5):
			for j in range(5):
				if arr[i][j] == 1:
					return abs(i - 2) + abs(j - 2)
cases = 5
arr = []
for x in range(cases):
	a = list(map(int, input().split(' ')))
	arr.append(a)
print(solve(arr))


a = 0
b = 0
for i in range(0, 5):
	ro = input().split(' ')
	for j in range(0, len(ro)):
		if ro[j] == '1':
			print(abs(i - 2) + abs(j - 2))
			break


m = [[0 for i in range(5)] for i in range(5)]
x = 0
y = 0
for i in range(5):
	m[i] = list(map(int, input().split(' ')))
	for j in range(len(m[i])):
		if m[i][j] == 1:
			(x, y) = (i + 1, j + 1)
print(abs(x - 3) + abs(y - 3))


loc = [0, 0]
for i in range(5):
	foo = [int(x) for x in input().split()]
	if 1 in foo:
		loc = [i, foo.index(1)]
		break
print(abs(loc[0] - 2) + abs(loc[1] - 2))


v = 0
f = 0
for i in range(5):
	for j in range(5):
		(a, b, c, d, e) = map(int, input().split())
		if a != 1:
			v = v + 1
		else:
			f = 1
			break
		if b != 1:
			v = v + 1
		else:
			f = 1
			break
		if c != 1:
			v = v + 1
		else:
			f = 1
			break
		if d != 1:
			v = v + 1
		else:
			f = 1
			break
		if e != 1:
			v = v + 1
		else:
			f = 1
			break
	if f == 1:
		break
l = [4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4]
print(l[v])


my_list = []
x_index = 0
y_index = 0
for i in range(0, 5):
	lst = list(map(int, input().split()))
	my_list += [lst]
	for j in range(0, 5):
		if my_list[i][j] == 1:
			x_index = i
			y_index = j
print(abs(2 - x_index) + abs(2 - y_index))


n = 5
a = [[] for i in range(n)]
for i in range(n):
	a[i].extend(map(int, input().split()))
tgt_row = 2
tgt_col = 2
one_row = 0
one_col = 0
for i in range(len(a)):
	if 1 in a[i]:
		one_row = i
		one_col = a[i].index(1)
		break
print(abs(tgt_col - one_col) + abs(tgt_row - one_row))


for x in range(1, 6):
	n = list(map(int, input().split()))
	if 1 in n:
		a = n.index(1)
		print(abs(3 - x) + abs(2 - a))


x = []
for i in range(0, 5, 1):
	x.append([])
	x[i] = list(map(int, input().split()))
for i in range(0, 5, 1):
	for j in range(0, 5, 1):
		if x[i][j] == 1:
			m = i
			n = j
print(abs(m - 2) + abs(n - 2))


for i in range(1, 6):
	(n1, n2, n3, n4, n5) = map(int, input().split())
	if n1 == 1:
		r = abs(3 - i) + 2
	if n2 == 1:
		r = abs(3 - i) + 1
	if n3 == 1:
		r = abs(3 - i) + 0
	if n4 == 1:
		r = abs(3 - i) + 1
	if n5 == 1:
		r = abs(3 - i) + 2
print(r)


mat = [[]] * 5
for i in range(5):
	mat[i] = list(map(int, input().split()))
for (i, j) in enumerate(mat):
	for (k, l) in enumerate(j):
		if l == 1:
			print(abs(i - 2) + abs(k - 2))
			break


arr = []
for _ in range(5):
	arr.append(list(map(int, input().split())))
flag = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			flag = 1
			break
	if flag:
		break
print(abs(2 - i) + abs(2 - j))


q = lambda : map(int, input().split())
qs = lambda : input().split()
a = [[int(j) for j in q()] for i in range(5)]
for i in a:
	if 1 in i:
		print(abs(a.index(i) - 2) + abs(i.index(1) - 2))
		exit()


my_list = []
for _ in range(5):
	a = str(input())
	b = a.split()
	my_list.append(b)
for i in range(5):
	for j in range(5):
		if int(my_list[i][j]) == 1:
			print(abs(int(i) - 2) + abs(int(j) - 2))
			break


i1 = 0
j1 = 0
for i in range(5):
	x = input().split()
	for j in range(5):
		if x[j] == '1':
			i1 = i
			j1 = j
print(abs(i1 - 2) + abs(j1 - 2))


def printsol(l):
	for i in range(5):
		for j in range(5):
			if l[i][j] == 1:
				x = abs(2 - i)
				y = abs(2 - j)
				return x + y
l = []
for i in range(5):
	q = []
	q.extend(list(map(int, input().split())))
	l.append(q)
t = printsol(l)
print(t)


for i in range(5):
	a = input().split()
	if '1' in a:
		b = i
		c = a.index('1')
print(abs(2 - b) + abs(2 - c))


m = list((input().split() for _ in range(5)))
for i in range(5):
	for j in range(5):
		if m[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))


lst = []
for i in range(5):
	n = input().split()
	lst.append(n)
for i in range(5):
	for j in range(5):
		if lst[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))


flag = 0
count = 0
a = 0
sum = 0
for i in range(0, 5):
	count = count + 1
	w = list(map(int, input().split()))
	for j in range(0, 5):
		if w[j] == 1:
			flag = flag + 1
			a = 1
			break
		else:
			flag = flag + 1
	if a == 1:
		break
	else:
		flag = 0
sum = abs(count - 3) + abs(flag - 3)
print(sum)


ans = 0
getAns = False
for i in range(5):
	row = input('').split()
	for e in range(5):
		if int(row[e]) == 1:
			rowMove = abs(2 - i)
			colMove = abs(2 - e)
			ans = rowMove + colMove
			getAns = True
		if getAns == True:
			break
	if getAns == True:
		break
print(ans)


found = []
for i in range(5):
	row = list(map(int, input().split()))
	if len(found) == 0:
		for j in range(5):
			if row[j] == 1:
				found = [i, j]
print(abs(2 - int(found[0])) + abs(2 - int(found[1])))


moves = 0
i = 0
line = 0
for i in range(5):
	inp = input()
	lst = inp.split(' ')
	if lst.count('1') == 1:
		index = lst.index('1')
		moves += abs(2 - index)
		line = i
moves += abs(2 - line)
print(moves)


n = 5
pos = [input().find('1') // 2 + 1 for i in range(n)]
print([abs(n // 2 + 1 - i) + abs(n // 2 - idx) for (idx, i) in enumerate(pos) if i][0])


import math
mattrix = [list(map(int, input().split())) for i in range(5)]
coordinates = list()
for i in range(5):
	for j in range(5):
		if mattrix[i][j] == 1:
			coordinates.append(i)
			coordinates.append(j)
print(math.ceil(math.copysign(coordinates[0] - 2, 1) + math.copysign(coordinates[1] - 2, 1)))


mat = []
for i in range(5):
	li = list(map(int, input().split()))
	mat.append(li)
flag = 2
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			r = i
			c = j
			flag = 0
			break
	if flag == 0:
		break
print(abs(2 - r) + abs(2 - c))


j = 0
i = 0
for k in range(1, 6):
	n = input().split()
	if '1' in n:
		i = k
		j = n.index('1') + 1
		break
print(abs(3 - i) + abs(3 - j))


s = 0
number_a = 0
for i in range(5):
	(a1, a2, a3, a4, a5) = map(int, input().split())
	number = max(a1, a2, a3, a4, a5)
	if number == 1:
		if a1 == 1:
			number_a = 1
		if a2 == 1:
			number_a = 2
		if a3 == 1:
			number_a = 3
		if a4 == 1:
			number_a = 4
		if a5 == 1:
			number_a = 5
		s = abs(3 - (i + 1)) + abs(number_a - 3)
		break
print(s)


a = [[int(j) for j in input().split()] for i in range(5)]
r = 0
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == 1:
			r = 1
			break
	if r == 1:
		break
print(abs(i - 2) + abs(j - 2))


from math import *
mat = []
for i in range(0, 5):
	mat.append(list(map(int, input().split())))
c = 0
for i in range(0, 5):
	for j in range(0, 5):
		if mat[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))
			c = 1
			break
		else:
			continue
	if c == 1:
		break


for _ in range(5):
	X = [int(_) for _ in input().split()]
	if 1 in X:
		print(abs(2 - _) + abs(2 - X.index(1)))


from sys import stdin, stdout
i = 1
j = 1
count = 0
for row in stdin:
	if '1' in row.rstrip().split():
		j += row.rstrip().split().index('1')
		break
	i += 1
if i in (1, 5):
	count += 2
if j in (1, 5):
	count += 2
if i in (2, 4):
	count += 1
if j in (2, 4):
	count += 1
stdout.write(str(count))


for i in range(5):
	strng = input().split()
	if '1' in strng:
		j = strng.index('1')
		print(abs(2 - i) + abs(2 - j))


p = q = 0
for i in range(5):
	m = input().split()
	for j in range(5):
		if m[j] == '1':
			p = i
			q = j
print(abs(p - 2) + abs(q - 2))


def main():
	n = 6
	ans = 0
	for i in range(1, n):
		(a, b, c, d, e) = map(int, input().split())
		if a == 1:
			ans = abs(3 - i) + 2
			break
		if b == 1:
			ans = abs(3 - i) + 1
			break
		if c == 1:
			ans = abs(3 - i)
			break
		if d == 1:
			ans = abs(3 - i) + 1
			break
		if e == 1:
			ans = abs(3 - i) + 2
			break
	print(ans)
main()


n = 5
matrix = []
for i in range(n):
	lst = list(map(int, input().split(' ')))
	matrix.append(lst)
for i in range(n):
	for j in range(n):
		if matrix[i][j] == 1:
			ans = max(i, 2) - min(i, 2) + max(j, 2) - min(j, 2)
			print(ans)
			break


matrix = [0] * 5
ans = 0
for i in range(0, 5):
	matrix[i] = [int(x) for x in input().split(' ')]
	for j in range(0, 5):
		if matrix[i][j] == 1:
			ans = abs(2 - i) + abs(2 - j)
print(ans)


L = []
for i in range(0, 5):
	s = str(input())
	L.append(list(map(int, s.split())))
for i in range(0, 5):
	for j in range(0, 5):
		if L[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


for i in range(5):
	matr = input()
	zn = matr.find('1')
	if zn != -1:
		break
print(abs(zn // 2 - 2) + abs(i - 2))


mo = []
x = 0
cntrx = 0
cntry = 0
y = 0
for i in range(5):
	m = input().split()
	mo.append(m)
for elem in mo:
	cntrx += 1
	if '1' in elem:
		x += cntrx
		for num in elem:
			cntry += 1
			if num == '1':
				y += cntry
print(abs(x - 3) + abs(y - 3))


from sys import stdin, stdout

def read_line():
	return stdin.readline().strip()

def print(value):
	stdout.write(str(value))

def main():
	(desired_i, desired_j) = (2, 2)
	for i in range(5):
		row_line = read_line()
		row_lst = row_line.split(' ')
		try:
			j = row_lst.index('1')
			minimal_moves = abs(i - desired_i) + abs(j - desired_j)
			print(minimal_moves)
			break
		except:
			continue
main()


num = []
answ = 0
for q in range(5):
	num.append(input().split())
for i in range(5):
	for z in range(5):
		if '1' in num[i][z]:
			a = i + 1
			b = z + 1
while a != 3:
	if a > 3:
		a -= 1
		answ += 1
	elif a < 3:
		a += 1
		answ += 1
	else:
		pass
while b != 3:
	if b > 3:
		b -= 1
		answ += 1
	elif b < 3:
		b += 1
		answ += 1
	else:
		pass
print(answ)


m = []
posX = 0
posY = 0
for i in range(5):
	m.append(list(map(int, input().split())))
	for j in range(len(m[i])):
		if m[i][j] == 1:
			posX = i + 1
			posY = j + 1
pasos = abs(3 - posX)
pasos = pasos + abs(3 - posY)
print(pasos)


import math
matrix = ''
for i in range(5):
	matrix += input() + '\n'
position = 0
for i in range(0, 50, 2):
	position = math.ceil((i + 1) / 2)
	if matrix[i] == '1':
		break
row = math.ceil(position / 5)
if position % 5 == 0:
	col = 5
else:
	col = position % 5
print(abs(3 - row) + abs(3 - col))


matrix = []
for i in range(5):
	matrix.append(input().split(' '))
for (row_number, rows) in enumerate(matrix):
	for (column_number, elements) in enumerate(rows):
		if elements == '1':
			print(abs(column_number - 2) + abs(row_number - 2))
			break


for i in range(5):
	matrix = list((int(x) for x in input().split()))
	pos = []
	if 1 in matrix:
		pos = [i, matrix.index(1)]
		ans = abs(pos[0] - 2) + abs(pos[1] - 2)
print(ans)


matrix = []
for i in range(5):
	matrix.append([int(x) for x in input().split()])
place = ''
flag = False
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			place += '%d%d' % (i, j)
			flag = True
			break
	if flag:
		break
result = 0
place = int(place)
if place != 22:
	while place != 22:
		if place < 15:
			place += 10
			result += 1
		elif 19 < place < 23:
			place += 1
			result += 1
		elif 21 < place < 25:
			place -= 1
			result += 1
		elif place > 29:
			place -= 10
			result += 1
print(result)


m = []
for i in range(5):
	m.append(input().split())
(r, c) = (0, 0)
for i in range(5):
	for j in range(5):
		if m[i][j] == '1':
			r = i
			c = j
			break
print(abs(r - 2) + abs(c - 2))


li = []
li.append(input().split())
li.append(input().split())
li.append(input().split())
li.append(input().split())
li.append(input().split())
for i in range(5):
	for j in range(5):
		if li[i][j] == '1':
			nu = abs(2 - i) + abs(j - 2)
			print(nu)


one = list(map(int, input().split()))
two = list(map(int, input().split()))
three = list(map(int, input().split()))
four = list(map(int, input().split()))
five = list(map(int, input().split()))
matrix = [one, two, three, four, five]
for rows in range(5):
	for cols in range(5):
		if matrix[rows][cols] == 1:
			(r, c) = (rows + 1, cols + 1)
answer = abs(3 - r) + abs(3 - c)
print(answer)


arr = [[0 for j in range(5)] for i in range(5)]
arr[0] = input().split(' ')
arr[1] = input().split(' ')
arr[2] = input().split(' ')
arr[3] = input().split(' ')
arr[4] = input().split(' ')
for i in range(5):
	for j in range(5):
		arr[i][j] = int(arr[i][j])
		if arr[i][j] == 1:
			x = i
			y = j
x = 2 - x
y = 2 - y
if x < 0:
	x = x * -1
if y < 0:
	y = y * -1
print(x + y)


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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
x = []
g = 0
for i in range(5):
	a = inlt()
	if 1 in a:
		x = a
		g = i
print(abs(x.index(1) - 2) + abs(g - 2))


import sys
m = []
for i in range(5):
	m.append([int(x) for x in sys.stdin.readline().strip().split()])
one = None
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			one = (i, j)
print(abs(one[0] - 2) + abs(one[1] - 2))


n1 = input().split()
n2 = input().split()
n3 = input().split()
n4 = input().split()
n5 = input().split()
if '1' in n1:
	y = n1.index('1')
	x = 2
	if y >= 0:
		if y >= 2:
			x += y - 2
		elif y == 0:
			x += 2
		else:
			x += y
elif '1' in n2:
	y = n2.index('1')
	x = 1
	if y >= 0:
		if y >= 2:
			x += y - 2
		elif y == 0:
			x += 2
		else:
			x += y
elif '1' in n3:
	y = n3.index('1')
	x = 0
	if y >= 0:
		if y >= 2:
			x += y - 2
		elif y == 0:
			x += 2
		else:
			x += y
elif '1' in n4:
	y = n4.index('1')
	x = 1
	if y >= 0:
		if y >= 2:
			x += y - 2
		elif y == 0:
			x += 2
		else:
			x += y
elif '1' in n5:
	y = n5.index('1')
	x = 2
	if y >= 0:
		if y >= 2:
			x += y - 2
		elif y == 0:
			x += 2
		else:
			x += y
print(x)


mat = [[] * 5 for i in range(5)]
row = 0
col = 0
for i in range(5):
	mat[i] = input().split()
	if mat[i] != ['0', '0', '0', '0', '0']:
		row = i
		col = mat[i].index('1')
print(abs(2 - row) + abs(2 - col))


for k in range(5):
	a = list(map(int, input().split()))
	if 1 in a:
		y = k
		x = a.index(1)
count = 0
if x != 2:
	count += abs(x - 2)
if y != 2:
	count += abs(y - 2)
print(count)


size = 5
arr = []
x = 0
y = 0
index = -1
for x in range(size):
	arr.append([int(y) for y in input().split()])
for i in arr:
	index = index + 1
	index2 = -1
	for j in i:
		index2 = index2 + 1
		if j == 1:
			x = index
			y = index2
n = 0
if x > 2:
	n = n + (x - 2)
else:
	n = n + (2 - x)
if y > 2:
	n = n + (y - 2)
else:
	n = n + (2 - y)
print(n)


b = list()
c = 0
for i in range(5):
	a = input().split(' ')
	b = b + [a]
for i in range(5):
	for j in range(5):
		if b[i][j] == '1':
			c = c + abs(i - 2) + abs(j - 2)
			break
		else:
			continue
print(c)


import sys
for i in range(5):
	n = list(map(int, sys.stdin.readline().split()))
	if 1 in n:
		b = n.index(1) + 1
		dis = abs(i + 1 - 3) + abs(b - 3)
		print(dis)
		break


mat = [[None for i in range(5)] for i in range(5)]
for i in range(5):
	mat[i] = list(map(int, input().split()))
for i in range(5):
	if 1 in mat[i]:
		(m, n) = (i, mat[i].index(1))
		break
print(abs(2 - m) + abs(2 - n))


m = []
for i in range(5):
	n = list(map(int, input().split()))
	m.append(n)
for j in range(5):
	for l in range(5):
		if m[j][l] == 1:
			n = l
			k = j
s = 0
if n >= 2:
	s = s + (n - 2)
else:
	s = s + (2 - n)
if k >= 2:
	s = s + (k - 2)
else:
	s = s + (2 - k)
print(s)


n = []
for i in range(5):
	n.append([])
	line = input().split()
	for j in range(5):
		n[i].append(line[j])
		if n[i][j] == '1':
			a = i
			b = j
print(abs(a - 2) + abs(b - 2))


for i in range(-2, 3):
	row = list(map(int, input().split(' ')))
	for j in range(-2, 3):
		num = row[j + 2]
		if num == 1:
			d = abs(i) + abs(j)
			print(d)
			exit(0)


from collections import *
a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


n = 1
row_index = 0
column_index = 0
while n <= 5:
	string1 = str(input())
	i = 0
	j = 1
	while i <= 8:
		if int(string1[i]) == 1:
			row_index = n
			column_index = j
		i = i + 2
		j = j + 1
	n = n + 1
print(abs(row_index - 3) + abs(column_index - 3))


l = []
for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		r = i + 1
		c = l.index(1) + 1
		break
ans = 0
if c > 3:
	ans += c - 3
elif c < 3:
	ans += 3 - c
if r > 3:
	ans += r - 3
elif r < 3:
	ans += 3 - r
print(ans)


arr = [[0] * 5] * 5
(ir, jr) = (0, 0)
for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			ir = i
			jr = j
			break
print(abs(ir - 2) + abs(jr - 2))


list = []
for i in range(5):
	(a, b, c, d, e) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	d = int(d)
	e = int(e)
	list.append([a, b, c, d, e])
for y in range(len(list)):
	for x in range(len(list)):
		if list[y][x] == 1:
			sy = y + 1
			sx = x + 1
print(abs(3 - sy) + abs(3 - sx))


matrix = []
for _ in range(5):
	matrix.append(list(map(int, input().split())))
pos = []
for row in range(len(matrix)):
	found = 0
	for column in range(len(matrix[0])):
		if matrix[row][column] == 1:
			pos.append(row + 1)
			pos.append(column + 1)
			found = 1
	if found:
		break
print(str(abs(3 - pos[0]) + abs(3 - pos[1])))


i = []
for j in range(5):
	i.append(list(map(int, input().split(' '))))
	try:
		(m, n) = (j, i[j].index(1))
	except:
		pass
print(str(abs(m - 2) + abs(n - 2)))


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
f = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			f = 1
			break
	if f == 1:
		break
print(abs(i - 2) + abs(j - 2))


l = []
for i in range(5):
	s = str(input(''))
	l.append(s.split(' '))
i = 0
j = 0
t = True
while i < 5 and t:
	while j < 5:
		if l[i][j] == '1':
			t = False
			break
		else:
			j += 1
	if t:
		j = 0
		i += 1
print(abs(2 - i) + abs(2 - j))


matrix = []
at_pos = [-1, -1]
swap_counts = 0

def swap_row(at_pos, swap_counts):
	if at_pos[0] < 2:
		at_pos[0] += 1
		swap_counts += 1
	elif at_pos[0] > 2:
		at_pos[0] -= 1
		swap_counts += 1
	return (at_pos, swap_counts)

def swap_column(at_pos, swap_counts):
	if at_pos[1] < 2:
		at_pos[1] += 1
		swap_counts += 1
	elif at_pos[1] > 2:
		at_pos[1] -= 1
		swap_counts += 1
	return (at_pos, swap_counts)
for i in range(5):
	inp = list(map(int, input().split()))
	matrix.append(inp)
for row in range(5):
	for column in range(5):
		if matrix[row][column] == 1:
			at_pos = [row, column]
for row in range(5):
	for column in range(5):
		if matrix[2][2] == 1:
			pass
		elif row < 3 or row > 3:
			(at_pos, swap_counts) = swap_row(at_pos, swap_counts)
		elif column > 3 or column < 3:
			(at_pos, swap_counts) = swap_column(at_pos, swap_counts)
print(swap_counts)


l = []
i = 0
j = 0
isnotFound = True
for k in range(5):
	l.append(list(map(int, input().split())))
	if isnotFound:
		if 1 in l[k]:
			isnotFound = False
			i = k
			j = l[i].index(1)
			break
print(abs(3 - (j + 1)) + abs(3 - (i + 1)))


def index(m):
	for i in range(len(m)):
		for j in range(len(m)):
			if m[i][j] == 1:
				return (i, j)
m = []
for _ in range(5):
	m.append(list(map(int, input().split())))
(i, j) = index(m)
print(abs(i - 2) + abs(j - 2))


a = []
x = 0
y = 0
for i in range(5):
	b = input().split()
	a.append(b)
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			x = i
			y = j
if (x < 2) & (y < 2):
	print(2 - x + (2 - y))
elif (x > 2) & (y > 2):
	print(x - 2 + (y - 2))
elif (x > 2) & (y < 2):
	print(x - 2 + (2 - y))
elif (x < 2) & (y > 2):
	print(2 - x + (y - 2))
elif (x == 2) & (y > 2):
	print(y - 2)
elif (x == 2) & (y < 2):
	print(2 - y)
elif (x > 2) & (y == 2):
	print(x - 2)
elif (x < 2) & (y == 2):
	print(2 - x)
elif (x == 2) & (y == 2):
	print(0)


line_1 = input().split(' ')
line_2 = input().split(' ')
line_3 = input().split(' ')
line_4 = input().split(' ')
line_5 = input().split(' ')
switch = 0
count = 0
answer = 0
for i in range(0, 5):
	if int(line_1[i]) == 1:
		switch = 1
		count += 1
		break
	elif int(line_2[i]) == 1:
		switch = 2
		count += 1
		break
	elif int(line_3[i]) == 1:
		switch = 3
		count += 1
		break
	elif int(line_4[i]) == 1:
		switch = 4
		count += 1
		break
	elif int(line_5[i]) == 1:
		switch = 5
		count += 1
		break
	else:
		count += 1
answer = abs(switch - 3) + abs(count - 3)
print(answer)


from typing import Tuple, List
BEAUTIFUL_MATRIX = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]

def swap_x(_matrix, y, x_a, x_b) -> List:
	tmp = _matrix[y][x_a]
	_matrix[y][x_a] = _matrix[y][x_b]
	_matrix[y][x_b] = tmp
	return _matrix

def swap_y(_matrix, x, y_a, y_b) -> List:
	tmp = _matrix[y_a][x]
	_matrix[y_a][x] = _matrix[y_b][x]
	_matrix[y_b][x] = tmp
	return _matrix

def check_state(_matrix) -> Tuple[List, int]:
	for (y, row) in enumerate(_matrix, 1):
		for (x, column) in enumerate(row, 1):
			if column == 1:
				_moves_used = 0
				if x > 3:
					_matrix = swap_x(_matrix, y - 1, x - 1, x - 2)
					_moves_used += 1
					return (_matrix, _moves_used)
				elif x < 3:
					_matrix = swap_x(_matrix, y - 1, x - 1, x)
					_moves_used += 1
					return (_matrix, _moves_used)
				if y > 3:
					_matrix = swap_y(_matrix, x - 1, y - 1, y - 2)
					_moves_used += 1
					return (_matrix, _moves_used)
				elif y < 3:
					_matrix = swap_y(_matrix, x - 1, y - 1, y)
					_moves_used += 1
					return (_matrix, _moves_used)
matrix = []
for _ in range(5):
	matrix.append([int(x) for x in input().split()])
total_moves = 0
while matrix != BEAUTIFUL_MATRIX:
	(matrix, moves_used) = check_state(matrix)
	total_moves += moves_used
print(total_moves)


l = [[int(i) for i in input().split()] for _ in range(5)]
(x, y) = (-1, -1)
for i in range(5):
	for j in range(5):
		if l[i][j]:
			(x, y) = (i, j)
print(abs(x - 2) + abs(y - 2))


d = []
for i in range(5):
	d.append(list(map(int, input().split())))
for (indx, i) in enumerate(d):
	if i.count(1) > 0:
		print(abs(indx - 2) + abs(i.index(1) - 2))


a = 2
b = 2
flag = False
for i in range(5):
	n = list(map(int, input().split()))
	for j in range(5):
		if n[j] == 1:
			x = i
			y = j
			flag = True
			break
	if flag == True:
		break
l = abs(x - a) + abs(y - b)
print(l)


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
summ = 0
totalL = int(a[0]) + int(b[0]) + int(c[0]) + int(d[0]) + int(e[0])
totalR = int(a[4]) + int(b[4]) + int(c[4]) + int(d[4]) + int(e[4])
if totalR == 1 or totalL == 1:
	summ += 2
tl = int(a[1]) + int(b[1]) + int(c[1]) + int(d[1]) + int(e[1])
tr = int(a[3]) + int(b[3]) + int(c[3]) + int(d[3]) + int(e[3])
if tr == 1 or tl == 1:
	summ += 1
totL = int(a[0]) + int(a[1]) + int(a[2]) + int(a[3]) + int(a[4])
totR = int(e[0]) + int(e[1]) + int(e[2]) + int(e[3]) + int(e[4])
if totL == 1 or totR == 1:
	summ += 2
toL = int(b[0]) + int(b[1]) + int(b[2]) + int(b[3]) + int(b[4])
toR = int(d[0]) + int(d[1]) + int(d[2]) + int(d[3]) + int(d[4])
if toL == 1 or toR == 1:
	summ += 1
print(summ)


(tr, tc) = (2, 2)
for i in range(5):
	k = list(map(int, input().split()))
	if 1 in k:
		row = i
		col = k.index(1)
		break
ans = abs(tr - row) + abs(tc - col)
print(ans)


for s in range(5):
	N = [int(x) for x in input().split()]
	if sum(N) > 0:
		X = [i for (i, x) in enumerate(N) if x == 1]
		l = abs(X[0] - 2) + abs(s - 2)
print(l)


numberOneCell = None
for i in range(5):
	row = input().split()
	if '1' in row:
		numberOneCell = [i, row.index('1')]
if numberOneCell[0] == 2 and numberOneCell[1] != 2:
	print(abs(numberOneCell[1] - 2))
elif numberOneCell[0] != 2 and numberOneCell[1] == 2:
	print(abs(numberOneCell[0] - 2))
elif numberOneCell[0] != 2 and numberOneCell[1] != 2:
	print(abs(numberOneCell[0] - 2) + abs(numberOneCell[1] - 2))
else:
	print(0)


moves = 0
for i in range(5):
	line = input().split()
	for j in range(5):
		if line[j] == '1':
			moves = abs(2 - j) + abs(2 - i)
print(moves)


count = 0
matrix = list(map(int, input().split()))
if 1 in matrix:
	count = count + 2
	atrix = list(map(str, matrix))
	if atrix[0] == '1':
		count = count + 2
	elif atrix[1] == '1':
		count = count + 1
	elif atrix[2] == '1':
		count = count
	elif atrix[3] == '1':
		count = count + 1
	elif atrix[4] == '1':
		count = count + 2
natrix = list(map(int, input().split()))
if 1 in natrix:
	count = count + 1
	batrix = list(map(str, natrix))
	if batrix[0] == '1':
		count = count + 2
	elif batrix[1] == '1':
		count = count + 1
	elif batrix[2] == '1':
		count = count
	elif batrix[3] == '1':
		count = count + 1
	elif batrix[4] == '1':
		count = count + 2
oatrix = list(map(int, input().split()))
if 1 in oatrix:
	count = count
	catrix = list(map(str, oatrix))
	if catrix[0] == '1':
		count = count + 2
	elif catrix[1] == '1':
		count = count + 1
	elif catrix[2] == '1':
		count = count
	elif catrix[3] == '1':
		count = count + 1
	elif catrix[4] == '1':
		count = count + 2
patrix = list(map(int, input().split()))
if 1 in patrix:
	count = count + 1
	datrix = list(map(str, patrix))
	if datrix[0] == '1':
		count = count + 2
	elif datrix[1] == '1':
		count = count + 1
	elif datrix[2] == '1':
		count = count
	elif datrix[3] == '1':
		count = count + 1
	elif datrix[4] == '1':
		count = count + 2
qatrix = list(map(int, input().split()))
if 1 in qatrix:
	count = count + 2
	eatrix = list(map(str, qatrix))
	if eatrix[0] == '1':
		count = count + 2
	elif eatrix[1] == '1':
		count = count + 1
	elif eatrix[2] == '1':
		count = count
	elif eatrix[3] == '1':
		count = count + 1
	elif eatrix[4] == '1':
		count = count + 2
print(count)


def move_num_to_center_of_matrix():
	num_lines = 0
	row_num = 1
	while num_lines < 5:
		line_list = list(map(int, input().split(' ')))
		col_num = 1
		for num in line_list:
			if num != 0:
				int_row = row_num
				int_col = col_num
			col_num += 1
		row_num += 1
		num_lines += 1
	print(abs(int_row - 3) + abs(int_col - 3))
move_num_to_center_of_matrix()


m = []
for i in range(5):
	h = input().split()
	m.append(h)
for i in range(5):
	for j in range(5):
		if m[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))


count = 0
i = 0
x = 0
y = 0
while i < 5:
	string = input().split(' ')
	for (index, c) in enumerate(string):
		if c == '1':
			x = index + 1
			y = i + 1
			break
	i += 1
if y > 3:
	count += y - 3
elif y < 3:
	count += 3 - y
if x > 3:
	count += x - 3
elif x < 3:
	count += 3 - x
print(count)


z1 = list(map(int, input().split()))
z2 = list(map(int, input().split()))
z3 = list(map(int, input().split()))
z4 = list(map(int, input().split()))
z5 = list(map(int, input().split()))
x = 0
y = 0
for i in range(5):
	if z1[i] == 1:
		x = 1
		y = i + 1
for i in range(5):
	if z2[i] == 1:
		x = 2
		y = i + 1
for i in range(5):
	if z3[i] == 1:
		x = 3
		y = i + 1
for i in range(5):
	if z4[i] == 1:
		x = 4
		y = i + 1
for i in range(5):
	if z5[i] == 1:
		x = 5
		y = i + 1
print(int(((x - 3) ** 2) ** 0.5 + ((y - 3) ** 2) ** 0.5))


ar = []
for i in range(5):
	ar.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if ar[i][j] == 1:
			x = i
			y = j
			break
s = abs(x - 2) + abs(y - 2)
print(s)


def main():
	m = []
	idx = 0
	for i in range(5):
		m.append([int(j) for j in input().split(' ')])
		if 1 in m[i]:
			idx = (i + 1, m[i].index(1) + 1)
	ans = abs(3 - idx[0]) + abs(3 - idx[1])
	print(ans)
main()


matrix = [[]]
moves = 0
for x in range(5):
	matrix.append(input().split())
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == '1':
			moves = abs(j - 2) + abs(i - 3)
print(moves)


import math
Line = [0] * 5
for i in range(5):
	Line[i] = [i for i in map(int, input().split())]
for i in range(5):
	for j in range(5):
		if Line[i][j] == 1:
			print(int(math.fabs(2 - i) + math.fabs(2 - j)))


l = []
b = []
for i in range(0, 5):
	l = list(map(int, input().split()))
	b.append(l)
for i in range(0, 5):
	for j in range(0, 5):
		if b[i][j] == 1:
			u = i
			v = j
			break
print(abs(2 - v) + abs(2 - u))


n = 5
A = []
row = 0
column = 0
counter = 0
for i in range(n):
	A.append(input().split(' '))
	for a in range(n):
		A[i][a] = int(A[i][a])
for i in range(len(A)):
	for a in range(len(A)):
		if A[i][a] == 1:
			row = i
			column = a
while row < 2 or row > 2:
	counter += 1
	if row < 2:
		row += 1
	else:
		row -= 1
while column < 2 or column > 2:
	counter += 1
	if column < 2:
		column += 1
	else:
		column -= 1
print(counter)


for i in range(5):
	line = [s for s in input().split(' ')]
	if '1' in line:
		l = i
		c = line.index('1')
moves = abs(l - 2) + abs(c - 2)
print(moves)


matrx = []
for i in range(5):
	matrx = list(map(int, input().split()))
	for j in range(len(matrx)):
		if matrx[j] == 1:
			x = j
			y = i
print(abs(x - 2) + abs(y - 2))


A = input().split()
B = input().split()
C = input().split()
D = input().split()
E = input().split()
i = 0
j = 0
for k in range(5):
	if A[k] == '1':
		i = 1
		j = k + 1
for k in range(5):
	if B[k] == '1':
		i = 2
		j = k + 1
for k in range(5):
	if C[k] == '1':
		i = 3
		j = k + 1
for k in range(5):
	if D[k] == '1':
		i = 4
		j = k + 1
for k in range(5):
	if E[k] == '1':
		i = 5
		j = k + 1
print(abs(i - 3) + abs(j - 3))


matrix = list()
for i in range(5):
	inp = input()
	matrix.append(inp)
row = -1
flag = 0
for string in matrix:
	ls = string.split()
	row = row + 1
	col = -1
	for num in ls:
		col = col + 1
		if num == '1':
			flag = 1
			break
	if flag == 1:
		break
result = abs(row - 2) + abs(col - 2)
print(result)


x = 0
y = 0
for j in range(5):
	row = [int(i) for i in input().split(' ')]
	for (k_idx, k) in enumerate(row):
		if k == 1:
			x = k_idx
			y = j
print(abs(2 - x) + abs(2 - y))


import math
rows = []
for i in range(0, 5):
	rows.append(list(input()))
row = 0
column = 0
for i in range(0, 5):
	for j in range(0, 9):
		if rows[i][j] == '1':
			row = i
			column = j / 2
print(int(abs(2 - row) + abs(2 - column)))


a = []
for i in range(5):
	a.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			z = i
			d = j
print(abs(z - 2) + abs(d - 2))


import re
list = []
for i in range(5):
	list.append(input())
w = 1
q = 1
while True:
	s = list[w - 1]
	if s[2 * q - 2] == '0':
		q = q + 1
		if q == 6:
			q = 1
			w = w + 1
	else:
		print(abs(w - 3) + abs(q - 3))
		break


ts = True
s = []
for i in range(5):
	s.append(list(input().split()))
for a in range(5):
	for b in range(5):
		if s[a][b] == '1':
			print(abs(2 - a) + abs(2 - b))
			ts = False
			break
	if ts == False:
		break


def nice_matrix(lst):
	t = tuple()
	for elem in lst:
		if '1' in elem:
			t += (lst.index(elem), elem.index('1'))
	return abs(2 - t[0]) + abs(2 - t[1])
b = list()
for z in range(5):
	s = input()
	b.append(list(s.replace(' ', '')))
print(nice_matrix(b))


matrix = [[int(i) for i in input().split()] for _ in range(5)]
for i in range(len(matrix)):
	if any(matrix[i]):
		index = [i, matrix[i].index(1)]
print(abs(index[0] - 2) + abs(index[1] - 2))


s = []
for i in range(5):
	s.append(input().split())
for i in s:
	if '1' in i:
		x = i.index('1')
		y = s.index(i)
	else:
		continue
print(abs(x - 2) + abs(y - 2))


r = 0
c = 0
for row in range(5):
	line = [i for i in input().split()]
	for item in range(0, 5):
		if line[item] == '1':
			r = row + 1
			c = item + 1
			break
print(abs(r - 3) + abs(c - 3))


MATRIX_SIZE = 5
matrix = [input().split(' ') for i in range(MATRIX_SIZE)]
for i in range(MATRIX_SIZE):
	for j in range(MATRIX_SIZE):
		if matrix[i][j] == str(1):
			print(abs(i - 2) + abs(j - 2))
			break


seq = []
for i in range(5):
	row = input().split()
	for i in range(len(row)):
		row[i] = int(row[i])
	seq.append(row)
steps = 0
for i in range(5):
	for j in range(5):
		if seq[i][j] == 1:
			steps = abs(2 - i) + abs(2 - j)
print(steps)


lines = []
position_of_one = (0, 0)
for i in range(5):
	line_strings = input().split(' ')
	for j in range(len(line_strings)):
		string = line_strings[j]
		if string == '1':
			position_of_one = (i, j)
			print(abs(2 - i) + abs(2 - j))


list1 = []
i = 0
j = 0
for num in range(5):
	(A, B, C, D, E) = map(int, input().split())
	list1.append(list((A, B, C, D, E)))
for loop1 in range(5):
	for loop2 in range(5):
		if list1[loop1][loop2] == 1:
			i = loop1 + 1
			j = loop2 + 1
count = abs(i - 3) + abs(j - 3)
print(count)


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()))
if 1 in row1:
	column = row1.index(1)
	row = 0
elif 1 in row2:
	column = row2.index(1)
	row = 1
elif 1 in row3:
	column = row3.index(1)
	row = 2
elif 1 in row4:
	column = row4.index(1)
	row = 3
else:
	column = row5.index(1)
	row = 4
resultado = 0
if column > 2:
	resultado = column - 2
elif column < 2:
	resultado = 2 - column
if row > 2:
	resultado += row - 2
elif row < 2:
	resultado += 2 - row
print(resultado)


mat = []
for r in range(5):
	row = [int(n) for n in input().split()]
	mat.append(row)
elementFound = False
for r in range(5):
	for c in range(5):
		if mat[r][c] == 1:
			elementFound = True
			break
	if elementFound:
		break
print(abs(r - 2) + abs(c - 2))


col = 0
row = 0
for i_str in range(0, 5):
	i_input_string = input()
	if '1' in i_input_string:
		row = i_str
		col = i_input_string.find('1')
		break
count_actions = 0
MIDDLE = 2
CENTER = 4
while row != MIDDLE:
	if row > MIDDLE:
		row -= 1
		count_actions += 1
	else:
		row += 1
		count_actions += 1
while col != CENTER:
	if col > CENTER:
		col -= 2
		count_actions += 1
	else:
		col += 2
		count_actions += 1
print(count_actions)


a = 5 * [0]
for i in range(5):
	a[i] = input().split()
for i in range(5):
	for t in range(5):
		if a[i][t] == '1':
			v = abs(i - 2) + abs(t - 2)
			print(v)
			exit()


r = []
for i in range(0, 5):
	a = input().split()
	for i in range(0, 101):
		a[i] = int(a[i])
		if a[i] == a[-1]:
			break
	r.append(a)
	a = []
cont = 0
cont1 = 0
yes = 0
for i in r:
	if yes == 1:
		break
	cont1 = cont1 + 1
	cont = 0
	for j in i:
		cont = cont + 1
		if j == 1:
			yes = yes + 1
			break
result = 0
if cont1 >= 3:
	result = result + (cont1 - 3)
if cont >= 3:
	result = result + (cont - 3)
if cont1 < 3:
	result = result + (3 - cont1)
if cont < 3:
	result = result + (3 - cont)
print(result)


D = {}
for i in range(1, 6):
	a = list(map(int, input().split()))
	D[i] = a
for i in D:
	if D[i] != [0, 0, 0, 0, 0]:
		b = i
		break
	else:
		pass
c = D[b]
c = c.index(1)
swaps = abs(3 - b) + abs(2 - c)
print(swaps)


matrix = []
for _ in range(5):
	hor = input().split()
	matrix.append(hor)
for line in matrix:
	if line.count('1') > 0:
		coord1 = [matrix.index(line) + 1, line.index('1') + 1]
	else:
		continue
print(abs(3 - coord1[0]) + abs(3 - coord1[1]))


a = []
for i in range(5):
	inpt = list(map(int, input().split()))
	if 1 in inpt:
		row = i
		col = inpt.index(1)
	a.append(inpt)
print(abs(2 - row) + abs(2 - col))


i = 0
j = 0
l = 1
while l <= 5:
	s = input()
	if '1' in s:
		i = l
		(a, b, c, d, e) = s.split(' ')
		if a is '1':
			j = 1
		elif b is '1':
			j = 2
		elif c is '1':
			j = 3
		elif d is '1':
			j = 4
		else:
			j = 5
	l += 1
moves = 0
while not i is 3 or not j is 3:
	if i > 3:
		moves += 1
		i -= 1
	elif i < 3:
		moves += 1
		i += 1
	if j > 3:
		moves += 1
		j -= 1
	elif j < 3:
		moves += 1
		j += 1
print(moves)


import sys
input = sys.stdin.readline

def main():
	arr = [0] * 5
	for i in range(5):
		arr[i] = inlt()
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				print(abs(2 - i) + abs(2 - j))

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

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

def instr():
	return ''.join(insr())

def insr():
	s = input()
	return list(s[:len(s) - 1])

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


for i in range(5):
	inputs = input().split()
	for j in range(5):
		if inputs[j] == '1':
			(x, y) = (i, j)
			break
print(abs(x - 2) + abs(y - 2))


main = []
for i in range(5):
	c = [x for x in map(int, input().split())]
	main.append(c)
for i in range(5):
	for j in range(5):
		if main[i][j] == 1:
			row = i
			column = j
mr = abs(2 - row)
cl = abs(2 - column)
print(mr + cl)


def matrix(bb):
	a = 0
	b = 0
	for i in range(len(bb)):
		if bb[i] == 1:
			if i >= 0 and i <= 2:
				a = 2 - i
				b = 2
			if i > 2 and i <= 4:
				a = i - 2
				b = 2
			if i >= 5 and i <= 7:
				a = 7 - i
				b = 1
			if i > 7 and i <= 9:
				a = i - 7
				b = 1
			if i >= 10 and i <= 12:
				a = 12 - i
				b = 0
			if i > 12 and i <= 14:
				a = i - 12
				b = 0
			if i >= 15 and i <= 17:
				a = 17 - i
				b = 1
			if i > 17 and i <= 19:
				a = i - 17
				b = 1
			if i >= 20 and i <= 22:
				a = 22 - i
				b = 2
			if i > 22 and i <= 24:
				a = i - 22
				b = 2
	print(a + b)
i = 1
bb = []
while i <= 5:
	numbers = list(map(int, input().split()))
	for j in range(len(numbers)):
		bb.append(numbers[j])
	i += 1
matrix(bb)


r = 0
c = 0
for i in range(5):
	s = [int(p) for p in input().split()]
	for j in range(5):
		if s[j] == 1:
			r = i + 1
			c = j + 1
h = abs(r - 3) + abs(c - 3)
print(h)


lis = []
for i in range(5):
	a = list(map(int, input().rstrip().split()))
	lis.append(a)
for j in range(5):
	for k in range(5):
		if lis[j][k] == 1:
			print(abs(j - 2) + abs(k - 2))


a = []
for i in range(5):
	a.append([int(j) for j in input().split()])
for i in range(len(a)):
	for j in range(len(a)):
		if a[i][j] == 1:
			result = abs(3 - (i + 1)) + abs(3 - (j + 1))
			print(result)


try:
	l = []
	(r, c) = (0, 0)
	for _ in range(5):
		li = list(map(int, input().split()))
		if 1 in li:
			c = li.index(1)
			r = _
		l.append(li)
	print(abs(r - 5 // 2) + abs(len(l[0]) // 2 - c))
except EOFError:
	pass


x = input().split()
y = input().split()
z = input().split()
w = input().split()
s = input().split()
count = 0
col = 0

def col_distance(r):
	for (index, xs) in enumerate(r):
		if xs == '1':
			if index < 2:
				return 2 - index
			else:
				return index - 2
if '1' in x:
	count = 2
	col = col_distance(x)
if '1' in y:
	count = 1
	col = col_distance(y)
if '1' in z:
	count = 0
	col = col_distance(z)
if '1' in w:
	count = 1
	col = col_distance(w)
if '1' in s:
	count = 2
	col = col_distance(s)
print(col + count)


def numMoves(zeroPoint):
	rise = abs(2 - zeroPoint[0])
	run = abs(2 - zeroPoint[1])
	return rise + run
for i in range(0, 5):
	row = input().split(' ')
	for a in range(0, len(row)):
		if int(row[a]) == 1:
			print(numMoves([i, a]))


for i in range(5):
	curR = input().split()
	if '1' in curR:
		ans = abs(i - 2)
		ans += abs(curR.index('1') - 2)
		print(ans)
		break


moves = -1
for i in range(5):
	lt = input().replace(' ', '')
	a = lt.find('1')
	if a > -1:
		moves = abs(a - 2) + abs(i - 2)
print(moves)


s3 = []
for c in range(5):
	s = input()
	s1 = s.split()
	s3.append(s1)
for i in range(5):
	for j in range(5):
		if s3[i][j] == '1':
			(a, b) = (i, j)
a = abs(a - 2)
b = abs(b - 2)
print(a + b)


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
f = 0
for i in range(5):
	if int(a[i]) == 1:
		print(abs(int(i) - 3 + 1) + 2)
	elif int(b[i]) == 1:
		print(abs(int(i) - 3 + 1) + 1)
	elif int(c[i]) == 1:
		print(abs(int(i) - 3 + 1) + 0)
	elif int(d[i]) == 1:
		print(abs(int(i) - 3 + 1) + 1)
	elif int(e[i]) == 1:
		print(abs(int(i) - 3 + 1) + 2)


hold = []
moves = 0
for ___ in range(5):
	hold.append([int(a) for a in input().split()])
for matrix in hold:
	if 1 in matrix:
		if matrix[2] != 1:
			a = matrix.index(1)
			if a - 2 > 0:
				moves += a - 2
			else:
				moves += 2 - a
			matrix.remove(1)
			matrix.insert(2, 1)
		if hold.index(matrix) != 2:
			if hold.index(matrix) - 2 > 0:
				moves += hold.index(matrix) - 2
			else:
				moves += 2 - hold.index(matrix)
			hold.insert(2, hold.pop(hold.index(matrix)))
print(moves)


r = 0
for _ in range(5):
	a = list(map(int, input().split()))
	r += 1
	if 1 in a:
		c = a.index(1)
		c += 1
		ans = abs(3 - r) + abs(3 - c)
		break
print(ans)


for y in range(5):
	r = input().split()
	if '1' in r:
		print(abs(2 - r.index('1')) + abs(2 - y))
		break


def inputMatrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def getSteps():
	matrix = inputMatrix(5)
	for r in range(1, 6):
		for c in range(1, 6):
			if matrix[r - 1][c - 1] == 1:
				movies = r - 3 if r > 3 else 3 - r
				movies += c - 3 if c > 3 else 3 - c
				return movies
print(getSteps())


s1 = str(input())
s2 = str(input())
s3 = str(input())
s4 = str(input())
s5 = str(input())
d1 = s1.split()
d2 = s2.split()
d3 = s3.split()
d4 = s4.split()
d5 = s5.split()
xc = 0
yc = 0
ans = 0
if '1' in d1:
	xc = 1
	yc = d1.index('1')
elif '1' in d2:
	xc = 2
	yc = d2.index('1')
elif '1' in d3:
	xc = 3
	yc = d3.index('1')
elif '1' in d4:
	xc = 4
	yc = d4.index('1')
elif '1' in d5:
	xc = 5
	yc = d5.index('1')
if xc > 3:
	ans += xc - 3
elif xc < 3:
	ans += 3 - xc
if yc > 2:
	ans += yc - 2
elif yc < 2:
	ans += 2 - yc
print(ans)


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
f = a + b + c + d + e
g = [4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4]
for x in range(25):
	if f[x] == '1':
		print(g[x])


for i in range(5):
	x = input().split()
	for j in range(5):
		if int(x[j]) == 1:
			row = i + 1
			col = j + 1
print(abs(row - 3) + abs(col - 3))


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
for i in range(5):
	if a[i] != 0 or e[i] != 0:
		print(abs(2 - i) + 2)
	elif b[i] != 0 or d[i] != 0:
		print(abs(2 - i) + 1)
	elif c[i] != 0:
		print(abs(2 - i))


index = 2
done = False
while not done:
	line = input().split()
	if '1' in line:
		print(abs(index) + abs(2 - line.index('1')))
		done = True
	index -= 1
	if index == -3:
		done = True


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
arr = []
for _ in range(5):
	arr.append(inlt())
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			ans = abs(i - 2) + abs(j - 2)
			print(ans)
			exit()
print('Something went wrong')


a = [list(map(int, input().split())) for i in range(5)]
(k, p) = (0, 0)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			(k, p) = (i, j)
			break
print(abs(2 - k) + abs(2 - p))


nos = 0
for n in range(5):
	m = list(map(int, input().split()))
	if m.count(1) == 1:
		nos += abs(2 - m.index(1))
		nos += abs(2 - n)
print(nos)


def getMinimumStep():
	matrix = []
	foundPos = -1
	for i in range(5):
		rowMatrix = [int(x) for x in input().split(' ')]
		matrix.append(rowMatrix)
	for rows in range(5):
		for col in range(5):
			elem = matrix[rows][col]
			if elem == 1:
				return abs(2 - rows) + abs(2 - col)
print(getMinimumStep())


mylist = [2, 1, 0, 1, 2]
for row in mylist:
	s = input()
	if '1' in s:
		print(row + mylist[s.find('1') // 2])


mat = [[int(x) for x in input().split()] for i in range(5)]
m = 0
n = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			m = i
			n = j
print(abs(m - 2) + abs(n - 2))


l = []
for _ in range(5):
	a = list(map(int, input().rstrip().split()))
	l.append(a)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


t = []
m = 0
for i in range(5):
	t.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if t[i][j] == 1:
			a = (i, j)
m = abs(a[1] - 2) + abs(a[0] - 2)
print(m)


(n, f) = ([], [])
for i in range(5):
	n = input().split()
	if '1' in n:
		x = i
		y = n.index('1')
if x != 2 and y != 2:
	print(2 - x % 2 + (2 - y % 2))
elif x != 2 and y == 2:
	print(2 - x % 2)
elif x == 2 and y != 2:
	print(2 - y % 2)
else:
	print(0)


def physicist():
	mat = [[int(i) for i in input().split()] for _ in range(5)]
	for i in range(5):
		for j in range(5):
			if mat[i][j] == 1:
				print(abs(2 - i) + abs(2 - j))
				exit(0)
physicist()


input_list = []
num = 0
while True:
	if num == 5:
		break
	line = input().split()
	line = list(map(int, line))
	input_list.append(line)
	num += 1
x = 0
y = 0
for item in input_list:
	if 1 in item:
		x = item.index(1)
		break
	y += 1
print(abs(x - 2) + abs(y - 2))


def solve(matrix):
	(n, m) = (5, 5)
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 1:
				(a, b) = (i + 1, j + 1)
				return abs(3 - a) + abs(3 - b)
matrix = []
for i in range(5):
	row = [int(x) for x in input().split()]
	matrix.append(row)
print(solve(matrix))


def main():
	(m, n) = (0, 0)
	for i in range(0, 5):
		inputs = [int(x) for x in input().split()]
		for q in range(0, 5):
			if inputs[q] == 1:
				(m, n) = (i, q)
	print(abs(m - 2) + abs(n - 2))
main()


s = []
for i in range(5):
	tmp = list(map(int, input().split()))
	for j in range(5):
		if tmp[j] == 1:
			ans = abs(2 - i) + abs(2 - j)
print(ans)


l = []
for _ in range(5):
	l.append(list(map(int, input().split())))
i = 0
for e in l:
	i += 1
	if 1 in e:
		idx = e.index(1) + 1
		break
print(abs(3 - i) + abs(idx - 3))


for i in range(5):
	a = input('').split()
	if '1' in a:
		n = i
		m = a.index('1')
		n = abs(2 - n)
		m = abs(2 - m)
		print(n + m)


a = []
sum = 0
for i in range(5):
	l = [int(m) for m in input().split()]
	a.append(l)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i
			y = j
if x < 2:
	sum += 2 - x
else:
	sum += x - 2
if y < 2:
	sum += 2 - y
else:
	sum += y - 2
print(sum)


c = 0
for _ in range(5):
	l = input().split()
	for i in range(5):
		if l[i] == '1':
			c = abs(_ - 2) + abs(i - 2)
print(c)


M = []
Count = 0
for i in range(0, 5):
	M.append(list(map(int, input().split())))
while M[2][2] != 1:
	if 1 in M[0]:
		Count += 2
		M[2][M[0].index(1)] = 1
		M[0][M[0].index(1)] = 0
	elif 1 in M[1]:
		Count += 1
		M[2][M[1].index(1)] = 1
		M[1][M[1].index(1)] = 0
	elif 1 in M[3]:
		Count += 1
		M[2][M[3].index(1)] = 1
		M[3][M[3].index(1)] = 0
	elif 1 in M[4]:
		Count += 2
		M[2][M[4].index(1)] = 1
		M[4][M[4].index(1)] = 0
	elif 1 in M[2]:
		Count += abs(2 - M[2].index(1))
		M[2][M[2].index(1)] = 0
		M[2][2] = 1
print(Count)


from sys import stdin, stdout
mat = []
row_index = -1
col_index = -1
for tt in range(5):
	row = list(map(int, stdin.readline().split()))
	if 1 in row:
		row_index = tt
		col_index = row.index(1)
	mat.append(row)
print(abs(2 - row_index) + abs(2 - col_index))


r = []
for i in range(5):
	l = map(int, input().split())
	r += l
j = r.index(1)
moves = 0
while j != 12:
	if j <= 4:
		moves += 2
		j += 10
	elif j <= 9:
		j += 5
		moves += 1
	elif j > 14 and j <= 19:
		moves += 1
		j -= 5
	elif j > 19:
		moves += 2
		j -= 10
	elif j == 10:
		j += 2
		moves += 2
	elif j == 11:
		moves += 1
		j += 1
	elif j == 13:
		j -= 1
		moves += 1
	elif j == 14:
		j -= 2
		moves += 2
print(moves)


for i in range(5):
	L = input().split()
	for j in range(5):
		if L[j] == '1':
			minmoves = abs(2 - i) + abs(2 - j)
print(minmoves)


for row in range(5):
	s = input().split()
	for col in range(5):
		if s[col] == '1':
			print(abs(row - 2) + abs(col - 2))


flag = 0
for i in range(5):
	br = list(map(int, input().split()))
	if flag == 0 and 1 in br:
		x = i + 1
		y = br.index(1) + 1
		flag = 1
c = abs(3 - x) + abs(3 - y)
print(c)


mat = []
ans = 0
flag = 0
for i in range(5):
	a = list(map(int, input().split()))
	mat.append(a)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			ans = abs(i - 2) + abs(j - 2)
			flag = 1
			break
	if flag == 1:
		break
print(ans)


class Code:

	def __init__(self):
		self.horizontal = -1
		self.vertical = -1
		self.matrix = []

	def process(self):
		for i in range(5):
			row = list(map(int, input().split()))
			if 1 in row:
				self.horizontal = row.index(1)
				self.vertical = i
			self.matrix.append(row)
		print(abs(self.horizontal - 2) + abs(self.vertical - 2))
code = Code()
code.process()


a = input()
a = a.split()
b = input()
b = b.split()
c = input()
c = c.split()
d = input()
d = d.split()
e = input()
e = e.split()
for i in range(0, 5):
	a[i] = int(a[i])
	b[i] = int(b[i])
	c[i] = int(c[i])
	d[i] = int(d[i])
	e[i] = int(e[i])
A = [a, b, c, d, e]
count = 0
for i in range(0, 5):
	for j in range(0, 5):
		if A[i][j] == 1:
			if j != 2:
				count = count + abs(j - 2)
			if i != 2:
				count = count + abs(i - 2)
				break
print(count)


for i in range(1, 6):
	s = input()
	k = s.find('1')
	if k == -1:
		continue
	m = k // 2 + 1
	n = i
print(abs(3 - n) + abs(3 - m))


idxrow = 0
idxcol = 0
for i in range(1, 6):
	a = [int(x) for x in input().split()]
	for j in range(5):
		if a[j] == 1:
			idxrow = i
			idxcol = j + 1
print(abs(3 - idxrow) + abs(3 - idxcol))


ls = []
for i in range(5):
	ls.append(input().split())
for j in ls:
	if '1' in j:
		print(abs(ls.index(j) - 2) + abs(j.index('1') - 2))


for i in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		nrow = i
		ncol = row.index(1)
		break
transforms = 0
if nrow != 2:
	transforms += abs(2 - nrow)
if ncol != 2:
	transforms += abs(2 - ncol)
print(transforms)


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
c = [(index, row.index(1)) for (index, row) in enumerate(a) if 1 in row]
res = abs(2 - c[0][0]) + abs(2 - c[0][1])
print(res)


a = []
x = -2
y = 0
for i in range(5):
	a = input().split()
	if '1' in a:
		y = -2 + a.index('1')
		break
	else:
		x += 1
print(abs(x) + abs(y))


import math
mat = [[5] * 5] * 5
for f in range(5):
	m = [int(i) for i in input().split()]
	mat[f] = m
s = 0
for t in mat:
	if 1 in t:
		x = t.index(1) + 1
		y = s + 1
	else:
		s += 1
d = int(sum([math.fabs(x - 3), math.fabs(y - 3)]))
print(d)


ans = int(0)
a = [2, 1, 0, 1, 2]
for i in range(5):
	x = input()
	b = int(x.find('1'))
	if b != -1:
		ans = a[i] + a[b // 2]
print(ans)


import sys

def solve():
	r = -1
	c = -1
	for i in range(5):
		line = [int(j) for j in input().split()]
		if 1 in line:
			r = i
			c = line.index(1)
	ans = abs(r - 2) + abs(c - 2)
	print(ans)
solve()


from sys import stdin
r = [x.rstrip().find('1') for (i, x) in enumerate(stdin.readlines())]
for (i, x) in enumerate(r):
	if x >= 0:
		print(abs(2 - i) + abs(x - 4) // 2)
		break


for i in range(5):
	current_row = list(map(int, input().split()))
	try:
		col = current_row.index(1) + 1
		row = i + 1
	except ValueError:
		pass
print(abs(row - 3) + abs(col - 3))


for i in range(5):
	s = input().split()
	if '1' in s:
		k = i + 1
		ind = s.index('1') + 1
print(abs(3 - k) + abs(3 - ind))


def calcArr(m):
	val1 = 0
	val2 = 0
	for i in range(0, len(m)):
		for j in range(len(m[i])):
			if m[i][j] == '1':
				val1 = abs(2 - i)
				val2 = abs(2 - j)
	return val1 + val2
m1 = input().split(' ')
m2 = input().split(' ')
m3 = input().split(' ')
m4 = input().split(' ')
m5 = input().split(' ')
matrixAll = [m1, m2, m3, m4, m5]
print(calcArr(matrixAll))


pos = None
for i in range(5):
	row = list(map(int, input().split()))
	for (j, x) in enumerate(row):
		if x:
			pos = (i, j)
print(abs(2 - pos[0]) + abs(2 - pos[1]))


def index_2d(b, v):
	for (i, x) in enumerate(b):
		if v in x:
			return (i, x.index(v))
arr = []
b = []
c = []
for i in range(0, 5):
	arr = list(map(int, input().split()))
	b.append(arr)
c.append(index_2d(b, 1))
a = c[0][0]
b = c[0][1]
a = a - 2
if a < 0:
	a = -1 * a
b = b - 2
if b < 0:
	b = -1 * b
res = a + b
print(res)


a = []
for i in range(0, 5):
	a.append(input())
b = a
for i in range(0, 5):
	b[i] = a[i].split()
p = 0
q = 0
for i in range(0, 5):
	for j in range(0, 5):
		if b[i][j] == '1':
			p = i
			q = j
		else:
			pass
x = 2 - p
y = 2 - q
if x < 0:
	x = x * -1
else:
	pass
if y < 0:
	y = y * -1
else:
	pass
z = x + y
print(z)


x1 = input().replace(' ', '')
x2 = input().replace(' ', '')
x3 = input().replace(' ', '')
x4 = input().replace(' ', '')
x5 = input().replace(' ', '')
y = x1 + x2 + x3 + x4 + x5
number = y.find('1') + 1
i = int(int(number / 5 - 0.001))
j = number - i * 5
a = 0
if i != 2:
	a = abs(2 - i)
b = 0
if j != 3:
	b = abs(3 - j)
print(a + b)


u = []
for i in range(1, 6):
	l = list(map(int, input().split()))
	u.append(l)
for i in u:
	k = 1
	if k in i:
		print(abs(i.index(k) - 2) + abs(u.index(i) - 2))


matrix = []
pos = 0
for i in range(5):
	matrix.append([])
	n = list(map(int, input().split()))
	for j in range(5):
		matrix[i].append(n[j])
		if n[j] == 1:
			pos = (i, j)
ans = abs(2 - pos[0]) + abs(2 - pos[1])
print(ans)


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
row = 0
col = 0
if 1 in a:
	row = 1
	col = a.index(1) + 1
elif 1 in b:
	row = 2
	col = b.index(1) + 1
elif 1 in c:
	row = 3
	col = c.index(1) + 1
elif 1 in d:
	row = 4
	col = d.index(1) + 1
elif 1 in e:
	row = 5
	col = e.index(1) + 1
result = abs(3 - row) + abs(3 - col)
print(result)


l = []
for i in range(5):
	l1 = [int(i) for i in input().split()[:5]]
	l.append(l1)
for i in range(len(l)):
	if 1 in l[i]:
		position = l[i].index(1) + 1
		print(abs(i + 1 - 3) + abs(position - 3))
		break


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
ll = []
(x, y) = (-1, -1)
for i in range(5):
	l = list(map(int, input().split()))
	for j in range(5):
		if l[j] == 1:
			x = i
			y = j
			break
print(abs(2 - x) + abs(2 - y))


n = [[], [], [], [], []]
for i in range(5):
	n[i] = input().split()
for i in range(5):
	for j in range(5):
		if n[i][j] == '1':
			row_steps = abs(i + 1 - 3)
			col_steps = abs(j + 1 - 3)
			print(row_steps + col_steps)
			break


for a in range(1, 6):
	x = list(map(int, input().split()))
	for b in range(0, 5):
		if x[b] != 0:
			i = b + 1
			j = a
print(abs(i - 3) + abs(j - 3))


n = 5
m = 5
a = [[0] * m for i in range(n)]
for i in range(5):
	a[i] = [int(x) for x in input().split()]
	if sum(a[i]) == 1:
		for j in range(5):
			if a[i][j] == 1:
				counter_j = j
				break
		counter_i = i
distance = abs(counter_i - 2) + abs(counter_j - 2)
print(distance)


for z in range(5):
	n = input()
	n = [int(s) for s in n.split() if s.isdigit()]
	for x in range(len(n)):
		if n[x] == 1:
			pos_column = x + 1
			pos_row = z + 1
			break
	if n[x] == 1:
		break
print(abs(pos_column - 3) + abs(pos_row - 3))


g = []
for i in range(5):
	g += list(map(int, input().split()))
y = ((g.index(1) // 5 + 1 - 3) ** 2) ** 0.5
x = ((g.index(1) % 5 + 1 - 3) ** 2) ** 0.5
print(int(y + x))


counteri = 0
counterj = 0
for i in range(5):
	x = input().split()
	y = int(x[0]) + int(x[1]) + int(x[2]) + int(x[3]) + int(x[4])
	if y == 1:
		counteri = abs(i - 2)
		for j in range(5):
			if int(x[int(j)]) == 1:
				counterj = abs(j - 2)
print(counteri + counterj)


import math
for i in range(5):
	l = list(map(int, input().split()))
	for j in range(len(l)):
		if l[j] == 1:
			x = i + 1
			y = j + 1
			break
x = abs(x - 3)
y = abs(y - 3)
print(x + y)


a = [[int(j) for j in input().split()] for i in range(5)]
ss = int(0)
y = int(0)
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == 1:
			ss = i + 1
			y = j + 1
print(abs(ss - 3) + abs(y - 3))


ll = []
for i in range(5):
	l = list(map(int, input().split()))
	ll.append(l)
	if 1 in l:
		r = i
		c = l.index(1)
print(abs(r - 2) + abs(c - 2))


for i in range(5):
	s = str(input()).split()
	if '1' in s:
		c = abs(2 - i) + abs(2 - s.index('1'))
print(c)


b = []
for _ in range(5):
	a = [int(i) for i in input().split()]
	b.append(a)
for i in range(5):
	if b[i].count(1) == 1:
		bb = abs(2 - i)
		for j in range(5):
			if b[i][j] == 1:
				nn = abs(2 - j)
				break
print(nn + bb)


x = 0
i = 0
j = 0
while x < 5:
	a = list(map(int, input().split()))
	k = -1
	for b in a:
		k += 1
		if b == 1:
			i = k
			j = x
	x += 1
print(abs(i - 2) + abs(j - 2))


M = []
b = 0
for i in range(5):
	j = input().split()
	c = list(j)
	M.append(c)
for i in range(5):
	for j in range(5):
		if M[i][j] == '1':
			b = abs(i - 2) + abs(j - 2)
			print(b)


for i in range(5):
	ip = input()
	if ip != '0 0 0 0 0':
		raw = i
		myList = list(ip.split())
for i in range(len(myList)):
	if myList[i] == '1':
		col = i
print(abs(2 - raw) + abs(2 - col))


from pprint import pprint
a = [[int(i) for i in input().split()] for j in range(1, 6)]
for i in a:
	for j in i:
		if j == 1:
			row = a.index(i)
			column = i.index(j)
			position = a[row][column]
row = row + 1
column = column + 1
pos = row + column
if pos > 6 or pos < 6:
	adjusted_pos = abs(row - 3) + abs(column - 3)
	print(adjusted_pos)
elif row - column == 0:
	print(0)
else:
	adjusted_pos = abs(row - 3) + abs(column - 3)
	print(adjusted_pos)


import sys
import math
mata = []
for i in range(1, 6):
	x = [int(x) for x in input().strip().split()]
	mata.append(x)
for i in range(5):
	for j in range(5):
		if mata[i][j] == 1:
			(ax, ay) = (i, j)
print(abs(ax - 2) + abs(ay - 2))


a = []
for k in range(1, 6):
	a.append(input())
	if a[k - 1].find('1') + 1:
		y = k
		x = a[k - 1].find('1') + 1
x = int((x + 1) / 2)
print(abs(y - 3) + abs(x - 3))


a = []
for i in range(5):
	a.append(input().split())
(m1, m2) = (2, 2)
for row in range(5):
	for col in range(5):
		if a[row][col] == '1':
			(l1, l2) = (row, col)
			break
d = abs(m1 - l1) + abs(m2 - l2)
print(d)


mat = []
for i in range(5):
	mat.append(list(map(int, input().split(' '))))
for x in mat:
	if 1 in x:
		coo = [mat.index(x) + 1, x.index(1) + 1]
		break
print(abs(coo[1] - 3) + abs(coo[0] - 3))


matrix = []
for item in range(5):
	matrix.append(list(map(int, input().split())))
	if 1 in matrix[item]:
		i = item
		j = matrix[item].index(1)
op_number = 0
while i != 2:
	if i > 2:
		i = i - 1
		op_number += 1
	elif i < 2:
		i = i + 1
		op_number += 1
while j != 2:
	if j > 2:
		j = j - 1
		op_number += 1
	elif j < 2:
		j = j + 1
		op_number += 1
print(int(op_number))


mat = []
loc = 0
for i in range(5):
	row = list(map(int, input().split()))
	for (j, num) in enumerate(row):
		if num == 1:
			loc = abs(2 - i) + abs(2 - j)
print(loc)


def add(n):
	l = []
	for i in n:
		l.append(i)
	return l
rows = []
for j in range(0, 5):
	f = map(int, input().split())
	rows.append(add(f))
for k in range(0, 5):
	for o in range(0, 5):
		if rows[k][o] == 1:
			cr = abs(3 - (k + 1))
			cc = abs(3 - (o + 1))
print(cr + cc)


sa = [int(x) for x in input().split()]
sb = [int(x) for x in input().split()]
sc = [int(x) for x in input().split()]
sd = [int(x) for x in input().split()]
se = [int(x) for x in input().split()]
if 1 == sc[2]:
	print('0')
elif 1 == sb[2] or 1 == sc[1] or 1 == sc[3] or (1 == sd[2]):
	print('1')
elif 1 == sa[2] or 1 == se[2] or 1 == sc[0] or (1 == sc[4]) or (1 == sb[1]) or (1 == sb[3]) or (1 == sd[1]) or (1 == sd[3]):
	print('2')
elif 1 == sa[1] or 1 == sa[3] or 1 == sb[0] or (1 == sb[4]) or (1 == sd[0]) or (1 == sd[4]) or (1 == se[1]) or (1 == se[3]):
	print('3')
elif 1 == sa[0] or 1 == sa[4] or 1 == se[0] or (1 == se[4]):
	print('4')


temp = []
k = 0
m = 0
for i in range(5):
	temp.append(input().split())
for i in range(5):
	for j in range(5):
		if temp[i][j] == '1':
			k = i
			m = j
k = abs(k - 2)
m = abs(m - 2)
print(k + m)


counter = 0
for i in range(5):
	row = input().split(' ')
	for j in range(len(row)):
		if row[j] == '1':
			if i >= 2:
				counter += i - 2
			else:
				counter += 2 - i
			if j >= 2:
				counter += j - 2
			else:
				counter += 2 - j
		else:
			continue
print(counter)


c = 1
count = 0
amnt = 0

def is1(ask):
	val = 0
	for i in ask:
		if i == '1':
			val += 1
	return val
while c <= 5:
	s = input()
	if c == 1 or c == 5:
		amnt = is1(s)
		if amnt == 1:
			count += 2
	elif c == 2 or c == 4:
		amnt = is1(s)
		if amnt == 1:
			count += 1
	pos = 0
	row = s.split()
	for i in row:
		pos = row.index(i)
		if i == '1':
			count = count + abs(pos - 2)
	c += 1
print(count)


no_lines = 0
row_and_column_dict = {}
while no_lines < 5:
	row_and_column_dict.update({no_lines: input().split(' ')})
	no_lines += 1
for items in row_and_column_dict.values():
	for elements in items:
		if '1' in elements:
			i = abs(items.index('1') - 2)
			j = abs(list(row_and_column_dict.keys())[list(row_and_column_dict.values()).index(items)] - 2)
			print(i + j)


(fila_1, fila_2, fila_3, fila_4, fila_5) = ([], [], [], [], [])
one = '1'
fila = int
columna = int
fila_1 = input().split(' ')
fila_2 = input().split(' ')
fila_3 = input().split(' ')
fila_4 = input().split(' ')
fila_5 = input().split(' ')
if one in fila_1:
	fila = 0
	for i in range(0, len(fila_1)):
		if fila_1[i] == '1':
			columna = i
elif one in fila_2:
	fila = 1
	for i in range(0, len(fila_2)):
		if fila_2[i] == '1':
			columna = i
elif one in fila_3:
	fila = 2
	for i in range(0, len(fila_3)):
		if fila_3[i] == '1':
			columna = i
elif one in fila_4:
	fila = 3
	for i in range(0, len(fila_4)):
		if fila_4[i] == '1':
			columna = i
elif one in fila_5:
	fila = 4
	for i in range(0, len(fila_5)):
		if fila_5[i] == '1':
			columna = i
if fila <= 2 and columna <= 2:
	ultimate = 2 - fila + (2 - columna)
elif fila <= 2 and columna > 2:
	ultimate = 2 - fila + (columna - 2)
elif fila > 2 and columna <= 2:
	ultimate = fila - 2 + (2 - columna)
elif fila > 2 and columna > 2:
	ultimate = fila - 2 + (columna - 2)
print(ultimate)


lis = []
for i in range(5):
	li = list((int(num) for num in input().strip().split()))[:5]
	if 1 in li:
		k = abs(li.index(1) - 2) + abs(i - 2)
	lis.append(li)
del li
del lis
print(k)


for i in range(5):
	row = input().split()
	if '1' in row:
		answer = abs(row.index('1') - 2) + abs(i - 2)
print(answer)


for i in range(0, 5):
	value = str(input())
	myList = value.split(' ')
	for j in range(0, 5):
		if myList[j] == '1':
			x = i + 1
			y = j + 1
			break
print(abs(x - 3) + abs(y - 3))


from sys import stdin, stdout

def get_int():
	return int(stdin.readline().strip())

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

def get_string():
	return stdin.readline().strip()

def get_list():
	return list(map(int, stdin.readline().strip().split()))
x = 1
y = 1
solved = False
getOut = 5
for _ in range(5):
	list = get_ints()
	getOut -= 1
	for pos in list:
		if pos == 1:
			solved = True
			break
		x += 1
	if solved:
		break
	x = 1
	y += 1
for _ in range(getOut):
	list = get_ints()
stdout.write(str(abs(3 - x) + abs(3 - y)))


Matrix = [[0] * 5] * 5
for i in range(5):
	Matrix[i] = input().split()
for k in range(0, 5):
	for p in range(0, 5):
		if int(Matrix[k][p]) == 1:
			a = int(k)
			b = int(p)
			print(abs(2 - a) + abs(2 - b))
			break


for i in range(5):
	row = [int(x) for x in input().split()]
	for j in range(5):
		if row[j] == 1:
			a = i
			b = j
d = abs(2 - a) + abs(2 - b)
print(d)


def bmatrix(m):
	i = j = 0
	for i in range(len(m)):
		if 1 in m[i]:
			j = m[i].index(1)
			break
	return abs(i - 2) + abs(j - 2)
mat = list()
for i in range(5):
	mat.append(list(map(int, input().strip().split())))
print(bmatrix(mat))


r1 = input()
r1 = r1.split(' ')
r2 = input()
r2 = r2.split(' ')
r3 = input()
import math
r3 = r3.split(' ')
r4 = input()
r4 = r4.split(' ')
r5 = input()
r5 = r5.split(' ')
if '1' in r1:
	for x in range(5):
		if int(r1[x]) == 1:
			m = 1
			n = x + 1
elif '1' in r2:
	for x in range(5):
		if int(r2[x]) == 1:
			m = 2
			n = x + 1
elif '1' in r3:
	for x in range(5):
		if int(r3[x]) == 1:
			m = 3
			n = x + 1
elif '1' in r4:
	for x in range(5):
		if int(r4[x]) == 1:
			m = 4
			n = x + 1
elif '1' in r5:
	for x in range(5):
		if int(r5[x]) == 1:
			m = 5
			n = x + 1
move = int(math.fabs(m - 3) + math.fabs(n - 3))
print(move)


for i in range(5):
	temp = list(map(int, input().split()))
	if 1 in temp:
		print(abs(3 - i - 1) + abs(3 - temp.index(1) - 1))


a0 = input()
a0 = a0.split()
a1 = input()
a1 = a1.split()
a2 = input()
a2 = a2.split()
a3 = input()
a3 = a3.split()
a4 = input()
a4 = a4.split()
b0 = [a0[0], a1[0], a2[0], a3[0], a4[0]]
b1 = [a0[1], a1[1], a2[1], a3[1], a4[1]]
b2 = [a0[2], a1[2], a2[2], a3[2], a4[2]]
b3 = [a0[3], a1[3], a2[3], a3[3], a4[3]]
b4 = [a0[4], a1[4], a2[4], a3[4], a4[4]]
ena = []
for i in a0:
	if i == '1':
		k = a0.index(i)
		ena.append(k)
for y in a1:
	if y == '1':
		k = a1.index(y)
		ena.append(k)
for z in a2:
	if z == '1':
		k = a2.index(z)
		ena.append(k)
for x in a3:
	if x == '1':
		k = a3.index(x)
		ena.append(k)
for n in a4:
	if n == '1':
		k = a4.index(n)
		ena.append(k)
for q in b0:
	if q == '1':
		k = b0.index(q)
		ena.append(k)
for w in b1:
	if w == '1':
		k = b1.index(w)
		ena.append(k)
for e in b2:
	if e == '1':
		k = b2.index(e)
		ena.append(k)
for r in b3:
	if r == '1':
		k = b3.index(r)
		ena.append(k)
for t in b4:
	if t == '1':
		k = b4.index(t)
		ena.append(k)
d = int(ena[0])
o = int(ena[1])
korakiv = abs(d - 2)
korakin = abs(o - 2)
stevilo = korakiv + korakin
print(stevilo)


n = 0
k = 0
for i in range(5):
	s = input().split()
	if '1' in s:
		n = i
		k = s.index('1')
		break
m = abs(2 - n) + abs(2 - k)
print(m)


matrix = []
for i in range(5):
	inp = input()
	x = inp.split(' ')
	matrix.append(x)
r = 0
c = 0
for i in range(5):
	for j in range(5):
		if int(matrix[i][j]) == 1:
			r = i
			c = j
r = abs(r - 2)
c = abs(c - 2)
print(r + c)


for _ in range(5):
	n = [int(i) for i in input().split()]
	if n.count(1) > 0:
		r = _
		c = n.index(1)
	else:
		pass
print(abs(2 - r) + abs(2 - c))


l = []
for _ in range(5):
	l.append(list(input().split()))
for i in range(5):
	if '1' in l[i]:
		print(abs(i - 2) + abs(l[i].index('1') - 2))


mat = list()
for i in range(5):
	lst = list(map(int, input().split()))
	mat.append(lst)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			one_rowLoc = i + 1
			one_columnLoc = j + 1
ans = abs(3 - one_rowLoc) + abs(3 - one_columnLoc)
print(ans)


from math import ceil
for i in range(1, 6):
	a = input()
	if a.count('1') != 0:
		s = ceil(a.index('1') / 2 + 1)
		p = abs(i - 3) + abs(s - 3)
print(abs(p))


x = 0
pos = None
for r in range(5):
	i = input()
	if '1' in i:
		pos = (x, i.split().index('1'))
	x += 1
count = 0
count += abs(2 - pos[0])
count += abs(2 - pos[1])
print(count)


matrix = []
locationRow = 0
locationColumn = 0
for x in range(5):
	inputs = input().split()
	y = [int(x) for x in inputs]
	matrix.append(y)
for row in range(5):
	for column in range(5):
		if matrix[row][column] == 1:
			locationRow = row
			locationColumn = column
print(abs(2 - locationRow) + abs(2 - locationColumn))


arr = []
for i in range(5):
	temp = [int(x) for x in input().split()]
	arr.append(temp)
for (i, j) in enumerate(arr):
	for (k, l) in enumerate(j):
		if l == 1:
			value = k
			arrya = i
			break
print(abs(2 - arrya) + abs(2 - value))


def findRow(array):
	for arr in array:
		if '1' in arr:
			currentRow = array.index(arr)
	return currentRow

def findCol(array):
	currentRow = findRow(array)
	currentCol = array[currentRow].index('1')
	return currentCol

def getCurrentArray(array):
	return array[findRow(array)]

def moveCol(array, moveR):
	currentArray = getCurrentArray(array)
	currentIndex = currentArray.index('1')
	if moveR:
		currentArray[currentIndex] = '0'
		currentArray[currentIndex + 1] = '1'
	else:
		currentArray[currentIndex] = '0'
		currentArray[currentIndex - 1] = '1'

def moveRow(array, moveU):
	currentArray = getCurrentArray(array)
	currentIndex = currentArray.index('1')
	rowIndex = findRow(array)
	if moveU:
		currentArray[currentIndex] = '0'
		array[rowIndex - 1][currentIndex] = '1'
	else:
		currentArray[currentIndex] = '0'
		array[rowIndex + 1][currentIndex] = '1'
row1 = input()
row2 = input()
row3 = input()
row4 = input()
row5 = input()
array1 = row1.split(' ')
array2 = row2.split(' ')
array3 = row3.split(' ')
array4 = row4.split(' ')
array5 = row5.split(' ')
mainArray = [array1, array2, array3, array4, array5]
numOfSwaps = 0
isInMiddle = False
while not isInMiddle:
	rowIndex = findRow(mainArray)
	colIndex = findCol(mainArray)
	if rowIndex == 2 and colIndex == 2:
		isInMiddle = True
		break
	if rowIndex > 2:
		moveRow(mainArray, True)
		numOfSwaps = numOfSwaps + 1
	elif rowIndex < 2:
		moveRow(mainArray, False)
		numOfSwaps = numOfSwaps + 1
	elif colIndex > 2:
		moveCol(mainArray, False)
		numOfSwaps = numOfSwaps + 1
	elif colIndex < 2:
		moveCol(mainArray, True)
		numOfSwaps = numOfSwaps + 1
print(numOfSwaps)


a = input()
b = input()
c = input()
d = input()
e = input()
x1 = a.find('1')
x2 = b.find('1')
x3 = c.find('1')
x4 = d.find('1')
x5 = e.find('1')
if x1 == 0 or x1 == 8:
	print('4')
elif x1 == 2 or x1 == 6:
	print('3')
elif x1 == 4:
	print('2')
elif x2 == 0 or x2 == 8:
	print('3')
elif x2 == 2 or x2 == 6:
	print('2')
elif x2 == 4:
	print('1')
elif x3 == 0 or x3 == 8:
	print('2')
elif x3 == 2 or x3 == 6:
	print('1')
elif x3 == 4:
	print('0')
elif x4 == 0 or x4 == 8:
	print('3')
elif x4 == 2 or x4 == 6:
	print('2')
elif x4 == 4:
	print('1')
elif x5 == 0 or x5 == 8:
	print('4')
elif x5 == 2 or x5 == 6:
	print('3')
elif x5 == 4:
	print('2')


for i in range(5):
	input_string = input()
	v = input_string.split()
	for j in range(5):
		if int(v[j]) == 1:
			y = j + 1
			x = i + 1
d = abs(x - 3) + abs(y - 3)
print(d)


matrix = [[int(x) for x in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			moves_v = abs(i - 2)
			moves_h = abs(j - 2)
print(moves_v + moves_h)


mat = []
for i in range(5):
	inp = list(map(int, input().split()))
	if sum(inp) == 1:
		r = i + 1
		c = inp.index(1) + 1
	mat.append(inp)
count = abs(3 - r) + abs(3 - c)
print(count)


move = 0
y = 0
for g in range(0, 5):
	v = [int(i) for i in input().split()]
	y += 1
	x = 0
	for g in range(0, 5):
		x += 1
		if v[g] == 1:
			c = y
			n = x
c = c - 3
n -= 3
n = abs(n)
c = abs(c)
move = move + c + n
print(move)


x = 0
for i in range(5):
	lst = list(map(int, input().split()))
	if 1 in lst and x == 0:
		n = lst.index(1)
		c = abs(2 - n) + abs(2 - i)
		x = 1
print(c)


c = []
p = 0
for i in range(5):
	a = input().split(' ')
	c.append(a)
for i in range(5):
	for j in range(5):
		if c[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))


s = []
r = -1
c = -1
for i in range(5):
	s.append(list(map(int, input().rstrip().split())))
for i in range(5):
	if 1 in s[i]:
		r = i
		break
for j in range(5):
	if 1 == s[r][j]:
		c = j
		break
print(abs(c - 2) + abs(r - 2))


b = []
for i in range(5):
	a = [int(i) for i in input().split()]
	b.append(a)
for i in range(5):
	for j in range(5):
		if b[i][j] == 1:
			c = b[i].index(1)
			d = i
			print(max(2, c) - min(2, c) + (max(2, d) - min(2, d)))


import math
mat_list = []
position = 0
cco = 0
final = 0
for i in range(0, 5):
	gg = input()
	gg = gg.replace(' ', '')
	mat_list.extend(gg)
for i in mat_list:
	if i == '1':
		position = cco
	cco += 1
xc = position % 5 + 1
pos = math.floor(position / 5) + 1
bb = 3 - xc
ll = 3 - pos
final = abs(bb) + abs(ll)
print(final)


from sys import stdin, stdout, stderr, setrecursionlimit
setrecursionlimit(100000)

def debug(*e):
	if not __debug__:
		print(*e, file=stderr)

def dd(*vals):
	import inspect, re
	frame = inspect.getframeinfo(inspect.stack()[1][0])
	vs = re.search('dd\\((.+)\\)', frame.code_context[0]).group(1).split(',')
	if vs:
		debug(','.join(('{0} = {1}'.format(vs[i], v) for (i, v) in enumerate(vals))))

def trace(f):

	def traced(*args, **kw):
		debug('calling {} with args {}, {}'.format(f.__name__, args, kw))
		return f(*args, **kw)
	return traced

def read():
	return stdin.readline().rstrip()

def readarr(sep=None, maxsplit=-1):
	return read().split(sep, maxsplit)

def readint():
	return int(read())

def readintarr(sep=None, maxsplit=-1):
	return [int(a) for a in readarr(sep, maxsplit)]

def write(*args, **kwargs):
	sep = kwargs.get('sep', ' ')
	end = kwargs.get('end', '\n')
	stdout.write(sep.join((str(a) for a in args)) + end)

def writearr(arr, sep=' ', end='\n'):
	stdout.write(sep.join((str(a) for a in arr)) + end)
for i in range(5):
	x = read().replace(' ', '').find('1')
	if x >= 0:
		write(abs(2 - x) + abs(2 - i))
		exit()


import math
a = 5
n = 5
num = 0
for q in range(a):
	m = [int(x) for x in input().split()]
	for i in range(n):
		c = m[i]
		if c == 1:
			num = int(num + math.fabs(2 - i) + math.fabs(2 - q))
print(num)


pos = []
for i in range(5):
	n = input().split()
	for it in n:
		pos.append(int(it))
posi = pos.index(1) + 1
if posi == 13:
	print(0)
	exit()
elif posi == 25 or posi == 5:
	print(4)
	exit()
rem = posi % 5
if rem == 0 or rem == 1:
	r = 2
elif rem == 4 or rem == 2:
	r = 1
elif rem == 3:
	r = 0
div = posi // 5
if div == 0 or div == 4:
	c = 2
elif div == 1 or div == 3:
	c = 1
elif div == 2:
	c = 0
if rem == 0:
	c -= 1
print(abs(r) + abs(c))


ans = 0
for i in range(0, 5):
	row = input().split(' ')
	if row.__contains__('1'):
		ans = abs(i + 1 - 3) + abs(3 - (row.index('1') + 1))
print(ans)


for i in range(1, 6):
	lst = list(map(int, input().split()))
	if 1 in lst:
		for j in range(5):
			if lst[j] == 1:
				x = i
				y = j + 1
				break
(ori_x, ori_y) = (3, 3)
count = 0
if x < ori_x:
	count += ori_x - x
elif x > ori_x:
	count += x - ori_x
if y < ori_y:
	count += ori_y - y
elif y > ori_y:
	count += y - ori_y
print(count)


for i in range(5):
	pos = input().find('1')
	if pos != -1:
		ans = abs(i - 2) + abs(pos // 2 - 2)
print(ans)


l = []
ans = 0
xx = 0
yy = 0
for i in range(5):
	x = input().split()
	c = []
	for j in range(5):
		c.append(int(x[j]))
	l.append(c)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			xx = abs(3 - (i + 1))
			yy = abs(3 - (j + 1))
			ans = xx + yy
			break
print(ans)


count_i = 0
while count_i < 5:
	groups = [int(a) for a in input().split(' ')]
	count_j = 0
	while count_j < len(groups):
		k = groups[count_j]
		if k == 1:
			j = count_j
			i = count_i
		count_j += 1
	count_i += 1
j0 = 2
i0 = 2
if i - i0 > 0:
	vertical = i - i0
else:
	vertical = i0 - i
if j - j0 > 0:
	horizontal = j - j0
else:
	horizontal = j0 - j
ans = vertical + horizontal
print(ans)


arr = []
for i in range(5):
	arr.append(input().split())
for r in range(5):
	for c in range(5):
		if int(arr[r][c]) == 1:
			print(max(r - 2, 2 - r) + max(c - 2, 2 - c))


for i in range(5):
	row = input().split()
	if '1' in row:
		ind = row.index('1')
		print(abs(i - 2) + abs(ind - 2))
		break


for i in range(5):
	n = list(map(int, input().split(' ')))
	if 1 in n:
		s = n.index(1)
		print(abs(3 - (i + 1)) + abs(3 - (s + 1)))


flag = True
for i in range(5):
	a = list(map(int, input().split()))
	if flag:
		for j in range(5):
			if a[j] == 1:
				r = i + 1
				c = j + 1
				flag = False
print(abs(3 - r) + abs(3 - c))


row = 0
col = 0
for x in range(0, 5):
	persons = list(map(int, input().split()))
	if 1 in persons:
		row = x
		col = persons.index(1)
print(abs(row - 2) + abs(col - 2))


count = 0
list1 = []
list2 = []
for i in range(5):
	list1 = list(map(int, input().split()))
	list2.append(list1)
for i in list2:
	if i.count(1) == 1:
		count = count + abs(2 - list2.index(i))
		if i.index(1) == 0 or i.index(1) == 4:
			count += 2
		elif i.index(1) == 1 or i.index(1) == 3:
			count += 1
print(count)


def readmat():
	t = list(range(5))
	for i in range(5):
		t[i] = str(input())
	return t

def readcor(a):
	for i in range(5):
		if a[i].find('1') >= 0:
			row = a[i].find('1') // 2 + 1
			col = i + 1
			break
	return [row, col]

def counta(a):
	return abs(a[0] - 3) + abs(a[1] - 3)
print(counta(readcor(readmat())))


c = 0
l = []
while c < 5:
	n = input()
	m = ''
	for i in n:
		if not i.isspace():
			m += i
	l.append(m)
	c += 1
x = 0
for i in l:
	x += 1
	if i.count('1') == 1:
		y = i.find('1') + 1
		break
if x != 3:
	if x > 3:
		a = x - 3
	elif x < 3:
		a = 3 - x
elif x == 3:
	a = 0
if y != 3:
	if y > 3:
		b = y - 3
	elif y < 3:
		b = 3 - y
elif y == 3:
	b = 0
print(a + b)


origin = (2, 2)
find = (0, 0)
for j in range(5):
	t = list(map(int, input().split()))
	for (_, i) in enumerate(t):
		if i == 1:
			find = (j, _)
			break
print(abs(origin[0] - find[0]) + abs(origin[1] - find[1]))


array_input = []
for x in range(5):
	array_input.append([int(y) for y in input().split()])
index_row = [array_input.index(row) for row in array_input if 1 in row]
index_column = [row.index(1) for row in array_input if 1 in row]
x = abs(index_row[0] - 2) + abs(index_column[0] - 2)
print(x)


def main():
	(r, c) = (-1, -1)
	for i in range(5):
		z = [int(x) for x in input().split()]
		for j in range(5):
			if z[j] == 1:
				(r, c) = (i, j)
	ans = abs(r - 2) + abs(c - 2)
	print(ans)
main()


def mod(a, b):
	if a - b < 0:
		return -(a - b)
	else:
		return a - b
a = []
for i in range(5):
	lst = list(map(int, input().split()))
	a.append(lst)
for i in a:
	for j in i:
		if j == 1:
			(x, y) = (a.index(i), i.index(j))
print(mod(x, 2) + mod(y, 2))


matrix = []
for i in range(5):
	x = input().split()
	matrix.append(x)
c = 0
for i in range(5):
	x = matrix[i]
	for j in range(5):
		z = matrix[i][j]
		if z == '1':
			c += abs(i - 2)
			c += abs(j - 2)
print(c)


complete = False
answer = 0
for a in range(5):
	c = input()
	for b in range(5):
		if c[b * 2] == '1':
			answer = str(abs(2 - a) + abs(2 - b))
			complete = True
			break
	if complete:
		break
print(answer)


gri = []
for i in range(5):
	s = [int(i) for i in input().split()]
	gri.append(s)
for i in range(5):
	for j in range(5):
		if gri[i][j] == 1:
			print(abs(i + 1 - 3) + abs(j + 1 - 3))


k = []
for i in range(5):
	k.append(''.join(input().split(' ')))
	if '1' in k[i]:
		a = k[i].index('1')
		print(abs(3 - (a + 1)) + abs(3 - (i + 1)))


MATRIX_SIZE = 5
row_position = 0
column_position = 0
for i in range(MATRIX_SIZE):
	entrada = str(input())
	entrada = entrada.split()
	for j in range(MATRIX_SIZE):
		if entrada[j] == '1':
			row_position = i + 1
			column_position = j + 1
result = abs(3 - row_position) + abs(3 - column_position)
print(result)


column1 = input().split()
column2 = input().split()
column3 = input().split()
column4 = input().split()
column5 = input().split()
moves = 0
if '1' in column1:
	while column1[2] != '1':
		x = column1.index('1')
		if x < 2:
			column1[x + 1] = '1'
			column1[x] = '0'
			moves += 1
		elif x > 2:
			column1[x - 1] = '1'
			column1[x] = '0'
			moves += 1
elif '1' in column2:
	while column2[2] != '1':
		x = column2.index('1')
		if x < 2:
			column2[x + 1] = '1'
			column2[x] = '0'
			moves += 1
		elif x > 2:
			column2[x - 1] = '1'
			column2[x] = '0'
			moves += 1
elif '1' in column3:
	while column3[2] != '1':
		x = column3.index('1')
		if x < 2:
			column3[x + 1] = '1'
			column3[x] = '0'
			moves += 1
		elif x > 2:
			column3[x - 1] = '1'
			column3[x] = '0'
			moves += 1
elif '1' in column4:
	while column4[2] != '1':
		x = column4.index('1')
		if x < 2:
			column4[x + 1] = '1'
			column4[x] = '0'
			moves += 1
		elif x > 2:
			column4[x - 1] = '1'
			column4[x] = '0'
			moves += 1
elif '1' in column5:
	while column5[2] != '1':
		x = column5.index('1')
		if x < 2:
			column5[x + 1] = '1'
			column5[x] = '0'
			moves += 1
		elif x > 2:
			column5[x - 1] = '1'
			column5[x] = '0'
			moves += 1
row1 = [column1[0], column2[0], column3[0], column4[0], column5[0]]
row2 = [column1[1], column2[1], column3[1], column4[1], column5[1]]
row3 = [column1[2], column2[2], column3[2], column4[2], column5[2]]
row4 = [column1[3], column2[3], column3[3], column4[3], column5[3]]
row5 = [column1[4], column2[4], column3[4], column4[4], column5[4]]
while row3[2] != '1':
	if '1' in row1:
		while row1[2] != '1':
			x = row1.index('1')
			if x < 2:
				row1[x + 1] = '1'
				row1[x] = '0'
				moves += 1
			elif x > 2:
				row1[x - 1] = '1'
				row1[x] = '0'
				moves += 1
	elif '1' in row2:
		while row2[2] != '1':
			x = row2.index('1')
			if x < 2:
				row2[x + 1] = '1'
				row2[x] = '0'
				moves += 1
			elif x > 2:
				row2[x - 1] = '1'
				row2[x] = '0'
				moves += 1
	elif '1' in row3:
		while row3[2] != '1':
			x = row3.index('1')
			if x < 2:
				row3[x + 1] = '1'
				row3[x] = '0'
				moves += 1
			elif x > 2:
				row3[x - 1] = '1'
				row3[x] = '0'
				moves += 1
	elif '1' in row4:
		while row1[2] != '1':
			x = row4.index('1')
			if x < 2:
				row4[x + 1] = '1'
				row4[x] = '0'
				moves += 1
			elif x > 2:
				row4[x - 1] = '1'
				row4[x] = '0'
				moves += 1
	elif '1' in row5:
		while row5[2] != '1':
			x = row5.index('1')
			if x < 2:
				row5[x + 1] = '1'
				row5[x] = '0'
				moves += 1
			elif x > 2:
				row5[x - 1] = '1'
				row5[x] = '0'
				moves += 1
print(moves)


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
x = inlt()
y = inlt()
z = inlt()
a = inlt()
b = inlt()
if sum(x) == 1:
	it = abs(x.index(1) - 2) + 2
if sum(y) == 1:
	it = abs(y.index(1) - 2) + 1
if sum(z) == 1:
	it = abs(z.index(1) - 2)
if sum(a) == 1:
	it = abs(a.index(1) - 2) + 1
if sum(b) == 1:
	it = abs(b.index(1) - 2) + 2
print(it)


array = []
for i in range(0, 5):
	array.append(list(map(str, input().split(' '))))
for x in range(0, 5):
	for y in range(0, 5):
		if int(array[x][y]) == 1:
			post_x = x + 1
			post_y = y + 1
total = 0
for i in (post_x, post_y):
	if i > 3:
		total = total + (i - 3)
	else:
		total = total + (3 - i)
print(total)


for i in range(5):
	column = input().split()
	for j in range(5):
		if column[j] == '1':
			moves = abs(i - 2) + abs(j - 2)
			print(moves)


l = []
for _ in range(5):
	l1 = list(map(int, input().split()))
	l.append(l1)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			(r, c) = (i, j)
print(abs(2 - r) + abs(2 - c))


l = []
(r, c) = (0, 0)
for x in range(5):
	l.append(input().split())
	if '1' in l[x]:
		r = x
		c = l[x].index('1')
print(abs(r - 2) + abs(c - 2))


m = []
for i in range(5):
	m.append(list(map(int, input().split())))
	try:
		j = m[i].index(1)
		if m[i].index:
			c = abs(j - 2) + abs(i - 2)
			print(c)
	except:
		c = 0


case = ['0 0 0 0 0', '0 0 0 0 1', '0 0 0 0 0', '0 0 0 0 0', '0 0 0 0 0']
matrix = []
count = 0
for i in range(5):
	matrix.append(list(map(int, input().rstrip().split())))
(row, col) = (0, 0)
for i in range(5):
	found = False
	for j in range(5):
		if matrix[i][j] == 1:
			row = i
			col = j
			found = True
			break
	if found:
		count = abs(row - 2) + abs(col - 2)
		break
print(count)


def find_one():
	for i in range(5):
		row = [int(x) for x in input().split()]
		if sum(row) == 1:
			num = abs(i - 2)
			for j in range(len(row)):
				if row[j] == 1:
					num += abs(j - 2)
					return num
print(find_one())


mat = [list(map(int, input().split())) for i in range(5)]
row = 0
col = 0
flag = False
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			row = i
			col = j
			flag = True
			break
	if flag:
		break
row = abs(row - 2)
col = abs(col - 2)
print(row + col)


for i in range(5):
	a = [int(_) for _ in input().split()]
	if 1 in a:
		ans = abs(a.index(1) - 2) + abs(i - 2)
print(ans)


for i in range(5):
	z = input().find('1')
	if z != -1:
		x = z // 2
		y = i
print(abs(x - 2) + abs(y - 2))


arr = []
for _ in range(5):
	items = list(map(int, input().split()))
	arr.append(items)
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			a = i
			b = j
			break
print(abs(a - 2) + abs(b - 2))


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd, log10, atan, tan

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

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

def input():
	return sys.stdin.readline().strip()
mat = []
for i in range(5):
	mat.append(get_array())
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			index = (i, j)
			break
need = abs(index[0] - 2) + abs(index[1] - 2)
print(need)


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
			break
	else:
		continue
	break


(x, y) = (0, 0)
for i in range(1, 6):
	row = input().split()
	r = -1
	try:
		r = row.index('1')
	except ValueError:
		r = -1
	if r != -1:
		x = r + 1
		y = i
print(abs(x - 3) + abs(y - 3))


for i in range(5):
	row = [int(x) for x in input().split()]
	if 1 in row:
		x = row.index(1)
		y = i
		break
answer = abs(2 - x) + abs(2 - y)
print(answer)


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

def index_2d(myList, v):
	for (j, x) in enumerate(myList):
		if v in x:
			return abs(3 - (j + 1)) + abs(3 - (x.index(v) + 1))
print(index_2d(matrix, 1))


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
a = 0
b = 0
if l1.count(1) == 1:
	a = 2
	b = 2 - l1.index(1)
if l2.count(1) == 1:
	a = 1
	b = 2 - l2.index(1)
if l3.count(1) == 1:
	a = 0
	b = 2 - l3.index(1)
if l4.count(1) == 1:
	a = 1
	b = 2 - l4.index(1)
if l5.count(1) == 1:
	a = 2
	b = 2 - l5.index(1)
if b < 0:
	b = -b
print(a + b)


a = input().split(' ')
b = input().split(' ')
c = input().split(' ')
d = input().split(' ')
e = input().split(' ')
y = 0
if '1' in a:
	n = a.index('1')
	m = 0
elif '1' in b:
	n = b.index('1')
	m = 1
elif '1' in c:
	n = c.index('1')
	m = 2
elif '1' in d:
	n = d.index('1')
	m = 3
elif '1' in e:
	n = e.index('1')
	m = 4
if n > 2:
	while n != 2:
		n -= 1
		y += 1
if n < 2:
	while n != 2:
		n += 1
		y += 1
if m > 2:
	while m != 2:
		m -= 1
		y += 1
if m < 2:
	while m != 2:
		m += 1
		y += 1
print(y)


linha = 0
coluna = 0
matrix = []
for _ in range(5):
	linhaa = input().split()
	matrix.append(linhaa)
	if linhaa.count('1') == 1:
		linha = _ + 1
		coluna = linhaa.index('1') + 1
moves = 0
moves += abs(linha - 3) + abs(coluna - 3)
print(moves)


ans = 0
for i in range(1, 6):
	m = list(input().split())
	if '1' in m:
		a = i
		for j in range(len(m)):
			if m[j] == '0':
				ans += 1
			else:
				break
j = abs(ans - 2)
i = abs(a - 3)
if a != 3:
	k = j + i
else:
	k = j
if k > 0:
	print(k)
else:
	print(-k)


import math
input_string = input()
input_string += input()
input_string += input()
input_string += input()
input_string += input()
input_string = input_string.replace(' ', '')
find_num = input_string.find('1') + 1
num_x = math.ceil(find_num / 5)
num_y = find_num - (num_x - 1) * 5
print(abs(num_x - 3) + abs(num_y - 3))


for i in range(5):
	r = list(map(int, input().split()))
	if r.count(1) > 0:
		rn = i
		p = r.index(1)
rs = abs(2 - rn)
cs = abs(2 - p)
print(rs + cs)


row = -1
for i in range(1, 6):
	a = input().split()
	for k in range(5):
		if a[k] == '1':
			row = i
			column = k + 1
			break
print(abs(3 - row) + abs(3 - column))


LENGTH = 5
matrix = []
while True:
	for _ in range(5):
		x = input()
		matrix.append([int(i) for i in x.split(' ')])
	break
result = 0
for i in range(LENGTH):
	for j in range(LENGTH):
		if matrix[i][j] == 1:
			result = abs(i - 2) + abs(j - 2)
			break
print(result)


b = 0
c = []
d = 0
while b < 5:
	c.append(list(map(int, input().split())))
	b += 1
b = 0
while b < 5:
	if c[b].count(1) == 1:
		d = c[b].index(1) + 1
		b += 1
		break
	b += 1
print(abs(d - 3) + abs(b - 3))


for i in range(5):
	s = input().replace(' ', '')
	if '1' in s:
		(y, x) = (i, s.index('1'))
print(abs(y - 2) + abs(x - 2))


for row in range(5):
	column = list(map(int, input().split()))
	count = column.count(1)
	if count == 1:
		j = column.index(1)
		i = row
steps = 0
while j != 2:
	if j < 2:
		j = j + 1
	elif j > 2:
		j = j - 1
	steps = steps + 1
while i != 2:
	if i < 2:
		i = i + 1
	elif i > 2:
		i = i - 1
	steps = steps + 1
print(steps)


a = [2, 1, 0, 1, 2]
y = 0
x = 0
for i in a:
	s = input().split(' ')
	if '1' in s:
		y += i
		if s[0] == '1' or s[4] == '1':
			x += 2
		elif s[1] == '1' or s[3] == '1':
			x += 1
print(str(x + y))


def find_beautiful_matrix(lst):
	for i in range(len(lst)):
		for j in range(len(lst)):
			if lst[i][j] == 1:
				x = i
				y = j
	result = abs(x - 2) + abs(y - 2)
	return result
data = []
for i in range(0, 5):
	data.append(list(map(int, input().split(' '))))
print(find_beautiful_matrix(data))


s1 = list(map(int, input().strip().split()))
s2 = list(map(int, input().strip().split()))
s3 = list(map(int, input().strip().split()))
s4 = list(map(int, input().strip().split()))
s5 = list(map(int, input().strip().split()))
l = []
l.append(s1)
l.append(s2)
l.append(s3)
l.append(s4)
l.append(s5)
for i in range(5):
	count = 0
	a = l[i]
	if 1 in a:
		b = a.index(1)
		count = count + abs(2 - b) + abs(2 - i)
		print(count)
		break


def main():
	a = []
	for i in range(5):
		k = input()
		k = k.split()
		for j in range(5):
			if int(k[j]) == 1:
				print(abs(i - 2) + abs(j - 2))
				return
main()


x = 0
y = 0
for i in range(0, 5):
	line = input()
	if line.find('1') != -1:
		x = line.find('1')
		y = i
n = abs(x / 2 - 2) + abs(y - 2)
print(int(n))


li = []
for _ in range(5):
	li.append(input().split())
r = -1
for i in li:
	r += 1
	if '1' in i:
		print(abs(r - 2) + abs(i.index('1') - 2))
		break


for i in range(5):
	l = input()
	ind = l.find('1') // 2
	if ind >= 0:
		print(abs(2 - i) + abs(2 - ind))


moves_needed = 0
for i in range(5):
	row = input().split()
	for j in range(5):
		if row[j] == '1':
			moves_needed += abs(3 - (i + 1))
			moves_needed += abs(3 - (j + 1))
print(moves_needed)


array_1 = input().split()
array_2 = input().split()
array_3 = input().split()
array_4 = input().split()
array_5 = input().split()
array_all = [array_1, array_2, array_3, array_4, array_5]
count = 0
for check in range(len(array_all)):
	if '1' in array_all[check]:
		answer_index = array_all[check].index('1')
		while answer_index != 2:
			if answer_index > 2:
				answer_index -= 1
				count += 1
			else:
				answer_index += 1
				count += 1
		while check != 2:
			if check > 2:
				check -= 1
				count += 1
			else:
				check += 1
				count += 1
print(count)


for row in range(5):
	string = input().split()
	for (col, n) in enumerate(string):
		if n == '1':
			print(abs(col - 2) + abs(row - 2))
			exit(0)


for row in range(5):
	col = [int(x) for x in input().split()]
	if 1 in col:
		idx = col.index(1)
		print(abs(row - 2) + abs(idx - 2))
		break


data = [list(map(int, input().split())) for i in range(5)]
sum = 0
for i in range(5):
	for j in range(5):
		if data[i][j] == 1:
			if i >= 2:
				sum = sum + i - 2
			else:
				sum = sum + 2 - i
			if j >= 2:
				sum = sum + j - 2
			else:
				sum = sum + 2 - j
print(sum)


matriz = []
for x in range(5):
	fila = list(map(int, input().split()))
	if 1 in fila:
		loc_column = fila.index(1)
		loc_fila = x
	matriz.append(fila)
moves_fila = abs(2 - loc_fila)
moves_columna = abs(2 - loc_column)
moves = moves_fila + moves_columna
print(moves)


matrix = [[int(j) for j in input().split()] for i in range(5)]
list_contained_1 = [x for x in matrix if 1 in x][0]
row = matrix.index(list_contained_1) + 1
column = list_contained_1.index(1) + 1
move = abs(row - 3) + abs(column - 3)
print(move)


m1 = input().split(' ')
m2 = input().split(' ')
m3 = input().split(' ')
m4 = input().split(' ')
m5 = input().split(' ')
m = [m1, m2, m3, m4, m5]
mat = ['']
for i in m:
	if i.count('1') == 1:
		mat = i
		break
	else:
		pass
n = abs(2 - m.index(mat))
num = abs(2 - mat.index('1'))
print(n + num)


a = []
for _ in range(5):
	a.append(input().split())
flag = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			x = i
			y = j
			flag = 1
			break
	if flag == 1:
		break
print(abs(x - 2) + abs(y - 2))


for i in range(1, 6):
	v = list(map(int, input().split()))
	if any(v):
		x = i
		y = v.index(1) + 1
print(abs(3 - x) + abs(3 - y))


for i in range(5):
	row = input()
	try:
		index = row.index('1')
		index = index / 2
		index += 1
		row_index = i + 1
	except ValueError:
		pass
print(int(abs(row_index - 3) + abs(index - 3)))


l1 = []
i = 0
for k in range(5):
	i += 1
	l = [int(x) for x in input().split()]
	if 1 in l:
		l1 = l[:]
		break
j = l1.index(1) + 1
ans = abs(3 - i) + abs(3 - j)
print(ans)


map = []
for i in range(5):
	map.append([int(x) for x in input().split()])
	if 1 in map[i]:
		index = (i, map[i].index(1))
steps = 0
if index[0] != 2:
	steps = abs(2 - index[0])
if index[1] != 2:
	steps += abs(2 - index[1])
print(steps)


l1 = input().split()
l2 = input().split()
l3 = input().split()
l4 = input().split()
l5 = input().split()
for i in range(5):
	l1[i] = int(l1[i])
	l2[i] = int(l2[i])
	l3[i] = int(l3[i])
	l4[i] = int(l4[i])
	l5[i] = int(l5[i])
e = 0
for i in range(6):
	if i != 2 and i < 5:
		if l1[i] == 1:
			l1[2] = 1
			l1[i] = 0
			if i < 2:
				e += 2 - i
			else:
				e += i - 2
		if l2[i] == 1:
			l2[2] = 1
			l2[i] = 0
			if i < 2:
				e += 2 - i
			else:
				e += i - 2
		if l4[i] == 1:
			l4[2] = 1
			l4[i] = 0
			if i < 2:
				e += 2 - i
			else:
				e += i - 2
		if l3[i] == 1:
			l3[2] = 1
			l3[i] = 0
			if i < 2:
				e += 2 - i
			else:
				e += i - 2
		if l5[i] == 1:
			l5[2] = 1
			l5[i] = 0
			if i < 2:
				e += 2 - i
			else:
				e += i - 2
	if i == 5:
		if l1[2] == 1 or l5[2] == 1:
			e += 2
			l3[2] = 1
			break
		if l2[2] == 1 or l4[2] == 1:
			e += 1
			l3[2] = 1
			break
print(e)


for ix in range(1, 6):
	row = input()
	if '1' in row:
		row = row.split()
		ind1 = row.index('1') + 1
		nmoves = abs(ix - 3) + abs(ind1 - 3)
print(nmoves)


y = []
xi = 0
xj = 0
for i in range(0, 5):
	x = [int(x) for x in input().split()]
	y.append(x)
for i in range(len(y)):
	for j in range(len(y[i])):
		if y[i][j] == 1:
			xi = i
			xj = j
print(abs(xi - 2) + abs(xj - 2))


full = list()
for _ in range(5):
	n = list(map(int, input().split(' ')))
	full.append(n)
for i in full:
	for j in i:
		if j == 1:
			(x, y) = (full.index(i), i.index(j))
			break
print(abs(2 - x) + abs(2 - y))


matrix = []
for i in range(5):
	inputs = list(map(int, input().split()))
	matrix.append(inputs)
matrixsz = 5
moves = 0
for i in range(matrixsz):
	for j in range(matrixsz):
		if matrix[i][j] == 1:
			if i > 2:
				moves += 2 - i
			else:
				moves += i - 2
			if j > 2:
				moves += 2 - j
			else:
				moves += j - 2
print(abs(moves))


massiv = []
for i in range(5):
	mass = input().split()
	massiv.append(mass)
for i in range(5):
	for j in range(5):
		if massiv[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
			break


l = []
m = 5
while m > 0:
	m -= 1
	l.append(input().split())
for i in range(5):
	if l[i] != ['0'] * 5:
		break
	i += 1
b = l[i].index('1')
print(abs(i - 2) + abs(b - 2))


count = 0
moves = 0
for i in range(1, 6):
	li = list(map(int, input().split(' ')))
	count += 1
	for i in range(len(li)):
		if li[i] == 1:
			moves += abs(3 - count) + abs(2 - i)
print(moves)


l = []
(x, y) = (0, 0)
for i in range(5):
	a = list(input().split())
	s = ''.join(a)
	j = s.find('1')
	if j != -1:
		x = j + 1
		y = i + 1
print(abs(3 - x) + abs(3 - y))


N = 5
a = []
while N:
	N -= 1
	b = [int(i) for i in input().split()]
	a.append(b)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			pos = [i, j]
			break
print(abs(pos[0] - 2) + abs(pos[1] - 2))


a = [list(map(int, input().split())) for i in range(5)]
flag = False
ans = 0
for i in range(5):
	if flag:
		break
	for j in range(5):
		if a[i][j] == 1:
			ans = abs(i + 1 - 3) + abs(j + 1 - 3)
			flag = True
			break
print(ans)


def run():
	for i in range(0, 5):
		line = list(map(int, input().split()))
		for j in range(0, len(line)):
			if line[j] == 1:
				print(abs(i - 2) + abs(j - 2))
				return
run()


mat = []
for i in range(5):
	row = list(map(int, input().split(' ')))
	mat.append(row)
c = 0
r = 0
for i in range(len(mat)):
	for j in range(len(mat[i])):
		if mat[i][j] == 1:
			r = i
			c = j
colch = abs(r - 2)
rowch = abs(c - 2)
print(colch + rowch)


a = []
for i in range(5):
	a.append([int(i) for i in input().split()])
b = []
for i in range(5):
	c = []
	for j in range(5):
		c.append(a[j][i])
	b.append(c)
s = 0
for i in a:
	if 1 in i:
		index1 = a.index(i)
s = abs(2 - index1)
for i in b:
	if 1 in i:
		index1 = b.index(i)
s = s + abs(2 - index1)
print(s)


m = []
for k in range(5):
	a = [int(n) for n in input().split()]
	m.append(a)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			s = i
			t = j
			break
result = abs(s - 2) + abs(t - 2)
print(result)


ans = 0
for x in range(-2, 3):
	INPUT = input().split(' ')
	if '1' in INPUT:
		INDEX = INPUT.index('1')
		if INDEX == 0 or INDEX == 4:
			ans += 2
		if INDEX == 1 or INDEX == 3:
			ans += 1
		ans += abs(x)
		print(ans)
		break


d = 0
for i in range(5):
	R = [int(x) for x in input().split()]
	for j in range(5):
		d += R[j] and abs(j - 2) + abs(i - 2)
print(d)


list_1 = list(map(int, input().split()))
list_2 = list(map(int, input().split()))
list_3 = list(map(int, input().split()))
list_4 = list(map(int, input().split()))
list_5 = list(map(int, input().split()))
list_of_all = [list_1, list_2, list_3, list_4, list_5]
c = 0
c1 = 0
for i in range(len(list_of_all)):
	for j in range(5):
		if list_of_all[i][j] == 1:
			c += i
			c1 += j
			break
if c == 2:
	c = 0
else:
	for i in range(1, 6):
		if c - i == 2 or c + i == 2:
			c = i
			break
if c1 == 2:
	c1 = 0
else:
	for i in range(1, 6):
		if c1 - i == 2 or c1 + i == 2:
			c1 = i
			break
print(c + c1)


data = []
for a in range(5):
	data.extend(map(int, input().split()))
ans = data.index(1)
print(abs(ans // 5 - 2) + abs(ans % 5 - 2))


liste = []
for i in range(5):
	temp = input()
	liste.append(temp)
for i in range(len(liste)):
	if '1' in liste[i]:
		row = i + 1
		break
columns = liste[row - 1].split(' ')
for i in range(len(columns)):
	if '1' == columns[i]:
		column = i + 1
		break
value = abs(row - 3) + abs(column - 3)
print(value)


m0 = input().split()
m1 = input().split()
m2 = input().split()
m3 = input().split()
m4 = input().split()
matrix = [m0, m1, m2, m3, m4]
for i in range(0, 5):
	if '1' in matrix[i]:
		y = i
		x = matrix[i].index('1')
		break
xmove = abs(x - 2)
ymove = abs(y - 2)
move = xmove + ymove
print(move)


for k in range(5):
	curr = [int(i) for i in input().split()]
	for l in range(5):
		if curr[l] == 1:
			(i, j) = (k, l)
print(abs(2 - i) + abs(2 - j))


lst = [[0] * 5 for i in range(5)]
for i in range(5):
	l1 = input().strip().split()
	lst[i] = l1
(m, n) = (-1, -1)
for i in range(5):
	for j in range(5):
		if lst[i][j] == '1':
			(m, n) = (int(i), int(j))
print(abs(m + 1 - 3) + abs(n + 1 - 3))


Input = []
for i in range(5):
	line = input()
	Input.append(line.split())
for i in range(5):
	for j in range(5):
		if Input[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))


matrix = [list(map(int, input().split())) for i in range(5)]
ones_digit = []
for (i, row) in enumerate(matrix):
	try:
		ones_digit = [i, row.index(1)]
	except ValueError:
		continue
for i in range(2):
	ones_digit[i] -= 2
	ones_digit[i] = abs(ones_digit[i])
print(sum(ones_digit))


row1 = input().split()
row2 = input().split()
row3 = input().split()
row4 = input().split()
row5 = input().split()
matrix = [row1, row2, row3, row4, row5]
for item in matrix:
	if '1' in item:
		x = item.index('1') + 1
		y = matrix.index(item) + 1
step = abs(x - 3) + abs(y - 3)
print(step)


def read_mat():
	mat = []
	for i in range(5):
		row = list(map(int, input().split()))
		mat.append(row)
	return mat

def find_index(mat):
	for i in range(5):
		for j in range(5):
			if mat[i][j] == 1:
				return (i, j)

def main():
	mat = read_mat()
	(ii, jj) = find_index(mat)
	print(abs(2 - ii) + abs(2 - jj))
main()


mat = []
for i in range(0, 5):
	arr = input().split()
	mat.append(arr)
for i in range(0, 5):
	for j in range(0, 5):
		if mat[i][j] == '1':
			row = i
			col = j
print(abs(row - 2) + abs(col - 2))


bm = []
for i in range(5):
	bm.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if bm[i][j] == 1:
			a = i
			b = j
			break
c = 0
if a >= 2:
	c += a - 2
else:
	c += 2 - a
if b >= 2:
	c += b - 2
else:
	c += 2 - b
print(str(c))


a = []
(b, c) = (0, 0)
for i in range(5):
	a.append(input().replace(' ', ''))
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			b = i + 1
			c = j + 1
print(abs(3 - b) + abs(3 - c))


matrix = []
count = 0
for i in range(5):
	matrix.append(input().strip().split())
for i in matrix:
	if '1' in i:
		count += abs(int(i.index('1')) - 2)
		count += abs(int(matrix.index(i)) - 2)
print(count)


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()))
X = 0
Y = 0
for i in range(5):
	if row1[i] == 1:
		X = 1
		Y = i + 1
		break
for i in range(5):
	if row2[i] == 1:
		X = 2
		Y = i + 1
		break
for i in range(5):
	if row3[i] == 1:
		X = 3
		Y = i + 1
		break
for i in range(5):
	if row4[i] == 1:
		X = 4
		Y = i + 1
		break
for i in range(5):
	if row5[i] == 1:
		X = 5
		Y = i + 1
		break
move = abs(X - 3) + abs(Y - 3)
print(move)


n = 5
k = 0
for i in range(n):
	a = input().split()
	for j in range(5):
		if a[j] == '1':
			k = abs(2 - i) + abs(2 - j)
print(k)


list1 = []
list2 = []
list3 = []
list4 = []
list5 = []
for i in range(5):
	(a, b, c, d, e) = input().split()
	list1.append(int(a))
	list2.append(int(b))
	list3.append(int(c))
	list4.append(int(d))
	list5.append(int(e))
tanho = [list1, list2, list3, list4, list5]

def check(list):
	if int(1) in list:
		return True
	else:
		return False
for j in tanho:
	if check(j):
		m = tanho.index(j)
		n = j.index(1)
if (m == 0 or m == 4) and (n == 0 or n == 4):
	print(4)
elif (m == 0 or m == 4) and (n == 1 or n == 3):
	print(3)
elif (m == 0 or m == 4) and n == 2:
	print(2)
elif (m == 1 or m == 3) and (n == 0 or n == 4):
	print(3)
elif (m == 1 or m == 3) and (n == 1 or n == 3):
	print(2)
elif (m == 1 or m == 3) and n == 2:
	print(1)
elif m == 2 and (n == 0 or n == 4):
	print(2)
elif m == 2 and (n == 1 or n == 3):
	print(1)
elif m == 2 and n == 2:
	print(0)


mat = []
for i in range(5):
	mat.append(input().split())
for r in range(5):
	for c in range(5):
		if mat[r][c] == '1':
			(l1, l2) = (r, c)
			break
print(abs(2 - l1) + abs(2 - l2))


def main():
	row = col = -1
	for _ in range(5):
		row += 1
		a = list(map(int, input().split()))
		if a.count(1):
			col = a.index(1)
			break
	num_cols = abs(2 - col)
	num_rows = abs(2 - row)
	print(num_cols + num_rows)
	pass
main()


n = 5
m = 5
a = [0] * n
for i in range(n):
	a[i] = [0] * m
for i in range(5):
	(a[i][0], a[i][1], a[i][2], a[i][3], a[i][4]) = input().split()
	for k in range(5):
		if '1' in a[i][k]:
			x = i
			y = k
x = int(x)
y = int(y)
c = 0
d = 0
if x == 2:
	c = 0
elif x > 2:
	c = x - 2
elif x < 2:
	c = 2 - x
if y == 2:
	d = 0
elif y > 2:
	d = y - 2
elif y < 2:
	d = 2 - y
s = c + d
print(s)


matrix = [input().split() for i in range(5)]
for (row_n, row) in enumerate(matrix):
	if '1' in row:
		col_n = row.index('1')
		print(abs(2 - row_n) + abs(2 - col_n))


def beautifulMatrix(matrix):
	(x, y) = (0, 0)
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == '1':
				(x, y) = (i, j)
	return abs(2 - x) + abs(2 - y)
matrix = []
for i in range(5):
	matrix.append(input().split())
print(beautifulMatrix(matrix))


matrix = []
for i in range(5):
	l = input().split()
	initArr = [int(x) for x in l]
	matrix.append(initArr)
for i in range(5):
	for j in range(5):
		if matrix[i][j]:
			xOne = i
			yOne = j
print(abs(2 - xOne) + abs(2 - yOne))


z = k = 0
lst = []
for i in range(5):
	ls = list(map(int, input().split()))
	if ls.count(1) == 1:
		for j in range(5):
			if ls[j] == 1:
				z = j
				k = i
				break
print(abs(z - 2) + abs(k - 2))


a = list(map(int, input().split()))[:5]
b = list(map(int, input().split()))[:5]
c = list(map(int, input().split()))[:5]
d = list(map(int, input().split()))[:5]
e = list(map(int, input().split()))[:5]
for i in range(5):
	if a[i] == 1:
		row = 1
		column = i + 1
	elif b[i] == 1:
		row = 2
		column = i + 1
	elif c[i] == 1:
		row = 3
		column = i + 1
	elif d[i] == 1:
		row = 4
		column = i + 1
	elif e[i] == 1:
		row = 5
		column = i + 1
if row >= 3 and column >= 3:
	print(row - 3 + (column - 3))
elif row < 3 and column < 3:
	print(3 - row + (3 - column))
elif row >= 3 and column < 3:
	print(row - 3 + (3 - column))
elif row < 3 and column >= 3:
	print(3 - row + (column - 3))


for i in range(5):
	x = input()
	if '1' in x:
		pos = (i + 1, x.split().index('1') + 1)
		break
print(abs(pos[0] - 3) + abs(pos[1] - 3))


a_list = []
for i in range(5):
	lines = input()
	lines = lines.split()
	if '1' in lines:
		row = i + 1
		column = lines.index('1') + 1
	a_list.append(lines)
moves = abs(row - 3) + abs(column - 3)
print(moves)


cst = [2, 1, 0, 1, 2]
for i in cst:
	l = input()
	if '1' in l:
		print(i + cst[l.find('1') // 2])


l = []
for i in range(5):
	l.append(list(map(int, input().split())))
c = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			u = i
			v = j
			while u != 2 or v != 2:
				if u > 2:
					c += 1
					u -= 1
				if u < 2:
					c += 1
					u += 1
				if v > 2:
					c += 1
					v -= 1
				if v < 2:
					c += 1
					v += 1
			print(c)
			break
	if l[i][j] == 1:
		break


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
n = 1
if n in l1:
	i = l1.index(n)
	r = abs(i - 2)
	ans = 2 + r
elif n in l2:
	i = l2.index(n)
	r = abs(i - 2)
	ans = 1 + r
elif n in l3:
	i = l3.index(n)
	r = abs(i - 2)
	ans = r
elif n in l4:
	i = l4.index(n)
	r = abs(i - 2)
	ans = 1 + r
elif n in l5:
	i = l5.index(n)
	r = abs(i - 2)
	ans = 2 + r
print(ans)


arr = []
for _ in range(5):
	arr.append([int(x) for x in input().split()])
for x in range(5):
	for y in range(5):
		if arr[x][y] == 1:
			xPos = x
			yPos = y
			break
print(abs(xPos - 2) + abs(yPos - 2))


s = []
for i in range(5):
	l = list(map(int, input().split()))
	s.append(l)
p = 1
for i in range(5):
	if p in s[i]:
		k = s[i].index(1)
		z = i
		break
print(abs(z - 2) + abs(k - 2))


i = 0
while i < 5:
	l = [int(x) for x in input().split()]
	if 1 in l:
		a = abs(2 - l.index(1)) + abs(2 - i)
	i += 1
print(a)


for i in range(1, 6):
	(a1, a2, a3, a4, a5) = map(int, input().split())
	loc = a1 * 1 + a2 * 2 + a3 * 3 + a4 * 4 + a5 * 5
	if loc > 0:
		res = abs(i - 3) + abs(loc - 3)
print(res)


lineOne = [int(x) for x in input().split()]
lineTwo = [int(x) for x in input().split()]
lineThree = [int(x) for x in input().split()]
lineFour = [int(x) for x in input().split()]
lineFive = [int(x) for x in input().split()]
if 1 in lineOne:
	upDown = 2
if 1 in lineTwo:
	upDown = 1
if 1 in lineThree:
	upDown = 0
if 1 in lineFour:
	upDown = 1
if 1 in lineFive:
	upDown = 2
foundLR = False
while not foundLR:
	if lineOne[0] or lineTwo[0] or lineThree[0] or lineFour[0] or (lineFive[0] == 1):
		leftRight = 2
	if lineOne[1] or lineTwo[1] or lineThree[1] or lineFour[1] or (lineFive[1] == 1):
		leftRight = 1
	if lineOne[2] or lineTwo[2] or lineThree[2] or lineFour[2] or (lineFive[2] == 1):
		leftRight = 0
	if lineOne[3] or lineTwo[3] or lineThree[3] or lineFour[3] or (lineFive[3] == 1):
		leftRight = 1
	if lineOne[4] or lineTwo[4] or lineThree[4] or lineFour[4] or (lineFive[4] == 1):
		leftRight = 2
	foundLR = True
print(upDown + leftRight)


from math import sqrt
array = [list(map(int, input().split())) for _ in range(5)]
for (i, j) in enumerate(array):
	if 1 in j:
		coords = (i, j.index(1))
		break
print(abs(coords[0] - 2) + abs(coords[1] - 2))


count = -2
missing = True
answer = 0
while missing:
	a = list(map(int, input().split()))
	for x in range(5):
		if a[x] == 1:
			answer = abs(x - 2) + abs(count)
			missing = False
	count = count + 1
print(answer)


L = []
for i in range(5):
	temp = list(map(int, input().split()))
	L.append(temp)
flag = 0
for i in range(5):
	for j in range(5):
		if L[i][j] == 1:
			flag = 1
			break
	if flag:
		break
ans = abs(i - 2) + abs(j - 2)
print(ans)


r = 0
n = -1
i = 1
while i < 6:
	a = list(map(int, input().split()))
	if 1 in a:
		r = i
		n = a.index(1)
		n += 1
	i += 1
move = 0
if n <= 3:
	move += 3 - n
else:
	move += n - 3
if r <= 3:
	move += 3 - r
else:
	move += r - 3
print(move)


arr = []
col = 0
rows = 0
cnt = 0
ans = 0
for i in range(5):
	arr.append(input().split(' '))
for i in range(5):
	for j in range(5):
		if int(arr[i][j]) == 1:
			rows = i
			col = j
if col < 2:
	cnt = 0
	for i in range(int(2 - int(col))):
		cnt += 1
elif col > 2:
	cnt = 0
	for i in range(int(col), 2, -1):
		cnt += 1
else:
	cnt = 0
if rows < 2:
	for i in range(int(2 - int(rows))):
		cnt += 1
elif rows > 2:
	for i in range(int(rows), 2, -1):
		cnt += 1
print(cnt)


import math
a = [[0] * 5 for i in range(5)]
for i in range(5):
	l = []
	l = list(map(int, input().split()))
	for (idx, e) in enumerate(l):
		if e == 1:
			ans = int(math.fabs(i - 2) + math.fabs(idx - 2))
print(ans)


row_1 = [int(i) for i in input().split()]
row_2 = [int(i) for i in input().split()]
row_3 = [int(i) for i in input().split()]
row_4 = [int(i) for i in input().split()]
row_5 = [int(i) for i in input().split()]
row = 0
column = 0
if 1 in row_1:
	row = 1
	column = row_1.index(1) + 1
if 1 in row_2:
	row = 2
	column = row_2.index(1) + 1
if 1 in row_3:
	row = 3
	column = row_3.index(1) + 1
if 1 in row_4:
	row = 4
	column = row_4.index(1) + 1
if 1 in row_5:
	row = 5
	column = row_5.index(1) + 1
score = 0
score += abs(row - 3)
score += abs(column - 3)
print(score)


matrix = []
for i in range(5):
	a = []
	a = list(map(int, input().split()))
	if 1 in a:
		x = i
		for i in range(5):
			if a[i] == 1:
				y = i
	matrix.append(a)
count = 0
while x != 2:
	if x > 2:
		x -= 1
		count += 1
	elif x < 2:
		x += 1
		count += 1
while y != 2:
	if y > 2:
		y -= 1
		count += 1
	elif y < 2:
		y += 1
		count += 1
print(count)


isFound = False
totalMoves = 0
for i in range(5):
	row = input().split(' ')
	for j in range(5):
		if int(row[j]) == 1 and isFound == False:
			totalMoves = abs(j - 2)
			totalMoves = totalMoves + abs(i - 2)
			isFound = True
print(totalMoves)


a = [[0] * 5 for _ in range(5)]
for i in range(5):
	a[i] = [int(j) for j in input().strip().split(' ')]
	if 1 in a[i]:
		print('\n', abs(i - 2) + abs(a[i].index(1) - 2))
		break


i = 0
while i < 5:
	a = list(map(int, input().split()))
	j = 0
	while j < 5:
		if a[j] == 1:
			p = i + 1
			h = j + 1
		j += 1
	i += 1
p = ((3 - p) ** 2) ** 0.5
h = ((3 - h) ** 2) ** 0.5
print(int(h + p))


matrix = []
i = 0
row = 0
col = 0
while i < 5:
	row_list = list(map(int, input().split()))
	matrix.append(row)
	if 1 in row_list:
		row = i
		col = row_list.index(1)
	i += 1
print(abs(row - 2) + abs(col - 2))


(a11, a12, a13, a14, a15) = [int(x) for x in input().split()]
(b21, b22, b23, b24, b25) = [int(x) for x in input().split()]
(c31, c32, c33, c34, c35) = [int(x) for x in input().split()]
(d41, d42, d43, d44, d45) = [int(x) for x in input().split()]
(e51, e52, e53, e54, e55) = [int(x) for x in input().split()]
if 1 in [a11, a12, a13, a14, a15]:
	i = 1
elif 1 in [b21, b22, b23, b24, b25]:
	i = 2
elif 1 in [c31, c32, c33, c34, c35]:
	i = 3
elif 1 in [d41, d42, d43, d44, d45]:
	i = 4
else:
	i = 5
if 1 in [a11, b21, c31, d41, e51]:
	j = 1
elif 1 in [a12, b22, c32, d42, e52]:
	j = 2
elif 1 in [a13, b23, c33, d43, e53]:
	j = 3
elif 1 in [a14, b24, c34, d44, e54]:
	j = 4
else:
	j = 5
print(abs(i - 3) + abs(j - 3))


import math
a = []
for i in range(5):
	a.append([int(x) for x in input().split()])
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = int(i)
			y = int(j)
c = abs(2 - x) + abs(y - 2)
print(c)


def answer():
	i = 0
	a = []
	while i < 5:
		b = input().split()
		a.append(b)
		i += 1
	i = 0
	while i < 5:
		if '1' in a[i]:
			col = abs(i - 2)
			row = abs(a[i].index('1') - 2)
		i += 1
	return col + row
print(answer())


while True:
	try:
		grid = []
		for i in range(5):
			row = input().split()
			grid.append(row)
		coord = None
		for row in range(5):
			for col in range(5):
				cell = grid[row][col]
				if cell == '1':
					coord = (row + 1, col + 1)
		min_moves = abs(3 - coord[0]) + abs(3 - coord[1])
		print(min_moves)
	except EOFError:
		break


for i in range(5):
	a = list(map(int, input().split()))
	if sum(a) == 1:
		for j in range(5):
			if a[j] == 1:
				break
		print(abs(i - 2) + abs(j - 2))
		break


m = [[int(i) for i in input().split()] for j in range(5)]
coords = []
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			coords.append(i + 1)
			coords.append(j + 1)
print(abs(3 - coords[0]) + abs(3 - coords[1]))


a = []
l = 0
k = 0
for i in range(5):
	a.append(0)
	a[i] = input()
for i in range(5):
	while l < 10:
		if a[i][l] == '1':
			k = k + abs(i - 2)
			k = k + abs(l - 4) // 2
		l = l + 2
	l = 0
print(k)


import math
a = []
sum = 0
for i in range(5):
	row = input().split()
	for i in range(len(row)):
		row[i] = int(row[i])
	a.append(row)
(i1, j1) = (0, 0)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			(i1, j1) = (i, j)
print(int(math.fabs(i1 - 2) + math.fabs(j1 - 2)))


inp = []
inp1 = []
for i in range(5):
	inp.append(input().split())
for i in inp:
	for x in i:
		inp1.append(x)
indexpos = inp1.index('1')
xpos = indexpos % 5 - 2
ypos = int(indexpos / 5) - 2
vzdialenost = abs(xpos) + abs(ypos)
print(vzdialenost)


matrix = []
(x, y) = (2, 2)
(mx, my) = (0, 0)
for i in range(5):
	arr = input().split(' ')
	arr = list(map(int, arr))
	for j in range(5):
		if arr[j] == 1:
			(mx, my) = (i, j)
			break
print(abs(x - mx) + abs(y - my))


import math
line_number = 0
line = list()
while True:
	line = input()
	line = list(map(int, line.split()))
	line_number += 1
	if 1 in line:
		break
horizontal_moves = int(math.fabs(3 - line_number))
vertical_location = line.index(1) + 1
vertical_moves = int(math.fabs(3 - vertical_location))
print(horizontal_moves + vertical_moves)


for i in range(5):
	arr = [int(num) for num in input().split(' ')]
	if 1 in arr:
		idx_row = i
		idx_col = arr.index(1)
ans = abs(2 - idx_row) + abs(2 - idx_col)
print(ans)


k = 5
s = 1
j = 0
x = [[], [], [], [], []]
for i in range(k):
	x[i] = list(map(int, input().split()))
	if 1 in x[i]:
		s = i
for i in range(k):
	if x[s][i] == 1:
		j = i
s += 1
j += 1
s = 3 - s
j = 3 - j
if s < 0:
	s *= -1
if j < 0:
	j *= -1
print(s + j)


arr = [input().split() for i in range(5)]
for i in range(5):
	for j in range(5):
		if arr[i][j] == '1':
			print(f'{abs(i - 2) + abs(j - 2)}')


matriz = []
primero = 0
segundo = 0
for j in range(5):
	lista = list(str(input()).split())
	for i in range(len(lista)):
		lista[i] = int(lista[i])
	matriz.append(lista)
for j in range(len(matriz)):
	for i in range(len(matriz[j])):
		if matriz[j][i] == 1:
			if j < 2:
				primero = 2 - j
			else:
				primero = j - 2
			if i < 2:
				segundo = 2 - i
			else:
				segundo = i - 2
movimientos = primero + segundo
print(movimientos)


for i in range(5):
	l = list(input().split())
	for j in range(5):
		if l[j] == '1':
			print(abs(2 - j) + abs(2 - i))


import math
firstline = input().split()
secondline = input().split()
thirdline = input().split()
fourthline = input().split()
fifthline = input().split()
all_lists = [firstline, secondline, thirdline, fourthline, fifthline]
for i in range(5):
	for j in range(5):
		if all_lists[i][j] == '1':
			(x_axis, y_axis) = (i, j)
diff = abs(x_axis - 2) + abs(y_axis - 2)
print(diff)


(r, c) = (0, 0)
for i in range(5):
	t = tuple(map(int, input().strip().split()))
	for j in range(5):
		if t[j] == 1:
			(r, c) = (i + 1, j + 1)
print(abs(3 - r) + abs(3 - c))


a = [input().split() for _ in range(5)]
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			res = abs(2 - i) + abs(2 - j)
print(res)


from math import *
l = []
for i in range(5):
	k = list(map(int, input().split()))
	l.append(k)

def pos1(l):
	for i in range(5):
		for j in range(5):
			if l[i][j] == 1:
				return [i, j]
				break
pos = pos1(l)
i = pos[0]
j = pos[1]
x = abs(i - 2)
y = abs(j - 2)
print(x + y)


for i in range(5):
	c = 0
	for j in input().split():
		if j == '1':
			print(abs(i - 2) + abs(c - 2))
			break
		c += 1


a = 0
for i in range(5):
	d = input().split()
	try:
		print(abs(2 - d.index('1')) + abs(2 - a))
	except:
		a += 1


a = []
ans = 0
ans1 = 0
for i in range(5):
	a = list(map(int, input().split()))
	for k in range(5):
		if a[k] == 1:
			ans = i + 1 - 3
			ans1 = k + 1 - 3
			break
if ans <= 0:
	ans = ans * -1
	if ans1 < 0:
		ans1 = ans1 * -1
	print(ans + ans1)
elif ans1 <= 0:
	ans1 = ans1 * -1
	if ans < 0:
		ans = ans * -1
	print(ans + ans1)
else:
	print(ans + ans1)


m = [input().split() for x in range(5)]
m = [int(x) for y in m for x in y]
ind = m.index(1)
a = int(ind / 5) + 1
b = ind % 5
count = abs(3 - a) + abs(2 - b)
print(count)


pos_x = 0
pos_y = 0
for i in range(5):
	s = list(map(int, input().split(' ')))
	for j in range(5):
		if s[j] == 1:
			pos_x = j
			pos_y = i
dif = abs(2 - pos_x) + abs(2 - pos_y)
print(dif)


import math
arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
for i in range(len(arr)):
	for j in range(len(arr[i])):
		if arr[i][j] == 1:
			break
	if arr[i][j] == 1:
		break
print(abs(j - 2) + abs(i - 2))


r = 0
for i in range(5):
	x = [int(i) for i in input().split()]
	for j in range(len(x)):
		if x[j] == 1:
			r += abs(j - 2) + abs(i - 2)
print(r)


n = 5
s = []
(ypos, xpos) = (0, 0)
(ymid, xmid) = (2, 2)
for i in range(n):
	row = input().split(' ')
	if '1' in row:
		ypos = i
		xpos = row.index('1')
nop = abs(ymid - ypos) + abs(xmid - xpos)
print(nop)


p1 = input()
p1 = p1.split()
p2 = input()
p2 = p2.split()
p3 = input()
p3 = p3.split()
p4 = input()
p4 = p4.split()
p5 = input()
p5 = p5.split()
for i in range(5):
	if p1[i] == '1':
		c = 2 + abs(2 - i)
		break
	if p2[i] == '1':
		c = 1 + abs(2 - i)
		break
	if p3[i] == '1':
		c = abs(2 - i)
		break
	if p4[i] == '1':
		c = 1 + abs(2 - i)
		break
	if p5[i] == '1':
		c = 2 + abs(2 - i)
		break
print(c)


def matrix(mat):
	(r, c) = (0, 0)
	for i in range(5):
		for j in range(5):
			if mat[i][j] == 1:
				(r, c) = (i, j)
				break
	print(abs(r - 2) + abs(c - 2))
mat = []
for i in range(5):
	row = []
	row = list(map(int, input().split()))
	mat.append(row)
matrix(mat)


(row, col) = (5, 5)
sum = 0
data = [input().split() for i in range(5)]
for row in range(5):
	for col in range(5):
		if data[row][col] == '1':
			b = row
			c = col
			break
sum = abs(2 - b) + abs(2 - c)
print(sum)


import os
import sys
import math
import ast
from itertools import *
from io import BytesIO, IOBase
from collections import *
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))
MOD = 10 ** 9 + 7
PI = 3.141592653589793

def i1():
	return int(sys.stdin.readline())

def sf():
	return sys.stdin.readline()

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

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

def pf(ans):
	return sys.stdout.write(str(ans) + '\n')

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

def lcm(a, b):
	return a * b // gcd(a, b)

def LogN(a, b):
	return math.log(a) / math.log(b)

def fpow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a
		a = a * a
		b >>= 1
	return res

def sieve(n):
	m = (n - 1) // 2
	b = [True] * m
	(i, p, ps) = (0, 3, [2])
	while p * p < n:
		if b[i]:
			ps.append(p)
			j = 2 * i * i + 6 * i + 3
			while j < m:
				b[j] = False
				j = j + 2 * i + 3
		i += 1
		p += 2
	while i < m:
		if b[i]:
			ps.append(p)
		i += 1
		p += 2
	return ps

def solve():
	mtx = []
	for i in range(5):
		mtx.append(list(map(int, input().split())))
	x = [(j, i) for j in range(5) for i in range(5) if mtx[j][i] == 1]
	ans = abs(2 - x[0][0]) + abs(2 - x[0][1])
	print(ans)
solve()


import math
matrix = []
for i in range(0, 5):
	matrix.append([int(x) for x in input().split()])
	for j in range(0, 5):
		if matrix[i][j] == 1:
			print(int(math.fabs(2 - i) + math.fabs(2 - j)))


a = 0
b = 0
for x in range(5):
	s = input().split(' ')
	for y in range(5):
		if s[y] == '1':
			a = x
			b = y
			break
		else:
			pass
c = abs(a - 2) + abs(b - 2)
print(c)


arr = []
for _ in range(5):
	arr.append(list(map(int, input().split())))
for i in range(5):
	if 1 in arr[i]:
		x = [i, arr[i].index(1)]
		break
print(abs(x[0] - 2) + abs(x[1] - 2))


l = list()
for i in range(5):
	ll = list(map(int, input().rstrip().split()))
	if sum(ll) == 1:
		(a, b) = (i + 1, ll.index(1) + 1)
print(abs(3 - a) + abs(3 - b))


def moves(mat):
	index1 = 0
	index2 = 0
	for i in mat:
		index1 = index1 + 1
		if '1' in i:
			index2 = i.index('1')
			break
	index2 = index2 + 1
	res = abs(3 - index1) + abs(3 - index2)
	return res
a = []
for i in range(5):
	inp = input().split()
	a.append(inp)
x = moves(a)
print(x)


a = []
for i in range(5):
	s = ''.join(input().split(' '))
	a.append(s)
for i in range(5):
	if '1' in a[i]:
		xxx = a[i]
		c = xxx.find('1')
		r = i
r = r + 1
c = c + 1
if r >= 3:
	r = r - 3
elif r == 1:
	r = 2
elif r == 2:
	r = 1
if c >= 3:
	c = c - 3
elif c == 2:
	c = 1
elif c == 1:
	c = 2
print(r + c)


m = []
for i in range(0, 5):
	m.append(input().split())
while m[2][2] == '0':
	for i in range(0, 5):
		for j in range(0, 5):
			if m[i][j] != '0':
				if i + 1 < 5 and m[i + 1][j] == '0':
					m[i + 1][j] = str(int(m[i][j]) + 1)
				if i - 1 > -1 and m[i - 1][j] == '0':
					m[i - 1][j] = str(int(m[i][j]) + 1)
				if j + 1 < 5 and m[i][j + 1] == '0':
					m[i][j + 1] = str(int(m[i][j]) + 1)
				if j - 1 > -1 and m[i][j - 1] == '0':
					m[i][j - 1] = str(int(m[i][j]) + 1)
print(int(m[2][2]) - 1)


(i, j) = divmod(''.join((input().replace(' ', '') for i in range(5))).index('1'), 5)
print(abs(i - 2) + abs(j - 2))


row_d = 0
col_d = 0
ans = 0
for i in range(5):
	s = list(input().split())
	for j in range(5):
		c = s[j]
		if c == '1':
			row_d = abs(i - 2)
			col_d = abs(j - 2)
			ans = row_d + col_d
print(ans)


m = []
n = int()
l = int()
for i in range(5):
	a = []
	k = input()
	a = k.split()
	m.append(a)
for i in range(5):
	for j in range(5):
		if m[i][j] == '1':
			n = i
			l = j
			break
sum = abs(n - 2) + abs(l - 2)
print(sum)


mat = []
for i in range(5):
	lst = list(map(int, input().split()))
	mat.append(lst)
flag = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			x = i
			y = j
			flag = 1
			break
	if flag == 1:
		break
x = x - 2
if x < 0:
	x *= -1
y = y - 2
if y < 0:
	y *= -1
print(x + y)


from math import fabs
array = []
n = 0
count = 0
array_1 = map(str, input().split())
array_2 = map(str, input().split())
array_3 = map(str, input().split())
array_4 = map(str, input().split())
array_5 = map(str, input().split())
array = list(array_1) + list(array_2) + list(array_3) + list(array_4) + list(array_5)
while n < 25:
	if int(array[n]) == 1:
		if fabs(n - 12) == 8 or fabs(n - 12) == 12:
			count = 4
			print(count)
			break
		elif fabs(n - 12) == 0:
			print(count)
			break
		elif fabs(n - 12) % 2 == 0:
			count = 2
			print(count)
			break
		elif fabs(n - 12) == 5 or fabs(n - 12) == 1:
			count = 1
			print(count)
			break
		elif fabs(n - 12) == 3 or fabs(n - 12) == 7 or fabs(n - 12) == 11 or (fabs(n - 12) == 9):
			count = 3
			print(count)
			break
	else:
		n += 1


def beautify(matrix):
	for i in range(len(matrix)):
		if any(matrix[i]):
			j = matrix[i].index(1)
			return abs(i - 2) + abs(j - 2)
matrix = []
for i in range(5):
	matrix.append(list(map(int, input().rstrip().split())))
print(beautify(matrix))


(c, r) = (2, 2)
l = []
for i in range(5):
	user = input().split()
	l.append(user)
for row in l:
	if '1' in row:
		R = l.index(row)
		C = row.index('1')
h = abs(r - R)
v = abs(c - C)
print(h + v)


for i in range(5):
	line = list(map(int, input().split()))
	if 1 in line:
		from_top = i
		from_left = line.index(1)
print(abs(2 - from_top) + abs(2 - from_left))


a = 0
b = 0
l = []
for i in range(0, 5):
	s = [int(x) for x in input().split(' ')]
	v = []
	for j in range(0, 5):
		v.append(s[j])
		if s[j] == 1:
			a = i
			b = j
	l.append(v)
x = abs(2 - a) + abs(2 - b)
print(x)


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
if '1' in a:
	print(2 + abs(2 - int(a.index('1'))))
if '1' in b:
	print(1 + abs(2 - int(b.index('1'))))
if '1' in c:
	print(0 + abs(2 - int(c.index('1'))))
if '1' in d:
	print(1 + abs(2 - int(d.index('1'))))
if '1' in e:
	print(2 + abs(2 - int(e.index('1'))))


numbers = list()
for i in range(5):
	n = list(map(int, input().split()))
	numbers.append(n)
for j in range(0, 5):
	for k in range(0, 5):
		if numbers[j][k] == 1:
			c = abs(j - 2) + abs(k - 2)
print(c)


mtrx = []
for i in range(5):
	mtrx.append(list(map(int, input().split())))
for k in range(5):
	if 1 in mtrx[k]:
		print(abs(k - 2) + abs(mtrx[k].index(1) - 2))
		break


n = [2, 1, 0, 1, 2]
for i in n:
	a = input()
	if '1' in a:
		print(i + n[a.find('1') // 2])


matrix = []
x = 0
for i in range(5):
	row = input()
	row = row.split()
	matrix.append(row)
for i in range(5):
	if matrix[i].count('1') > 0:
		x += abs(2 - i)
		y = matrix[i].index('1')
		x += abs(2 - y)
print(x)


i = j = 0
while True:
	row = list(map(int, input().split()))
	try:
		j = row.index(1)
		break
	except:
		pass
	i += 1
print(abs(i - 2) + abs(j - 2))


list1 = []
n = 0
while n < 5:
	n += 1
	list1.append(input().split(' '))
for n1 in range(5):
	for n2 in range(5):
		if list1[n1][n2] == '1':
			(get1, get2) = (n1, n2)
ans = abs(get1 - 2) + abs(get2 - 2)
print(ans)


for i in range(5):
	n = ''.join(input().split())
	p = n.find('1') + 1
	if p:
		print(abs(3 - p) + abs(2 - i))
		break


mat = []
for _ in range(5):
	rows = list(map(int, input().split()))
	mat.append(rows)
ans = False
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			ans = True
			print(abs(2 - i) + abs(2 - j))
			break
	if ans:
		break


for i in range(5):
	string = input().split()
	for j in range(5):
		if string[j] is '1':
			print(abs(2 - i) + abs(2 - j))


n = 5
a = []
for i in range(n):
	w = input()
	a = a + [w]
a = ' '.join(a)
a = a.replace(' ', '')
x = a.index('1')
if x % 2 == 0:
	if x == 0 or x == 4 or x == 20 or (x == 24):
		print(4)
	elif x == 12:
		print(0)
	else:
		print(2)
elif x == 7 or x == 11 or x == 13 or (x == 17):
	print(1)
else:
	print(3)


a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
e = [int(i) for i in input().split()]
for i in range(len(a)):
	if a[i] == 1:
		print(abs(3 - (i + 1)) + 2)
for i in range(len(a)):
	if b[i] == 1:
		print(abs(3 - (i + 1)) + 1)
for i in range(len(a)):
	if c[i] == 1:
		print(abs(3 - (i + 1)))
for i in range(len(a)):
	if d[i] == 1:
		print(abs(3 - (i + 1)) + 1)
for i in range(len(a)):
	if e[i] == 1:
		print(abs(3 - (i + 1)) + 2)


m = 0
n = []
o = 0
u = 0
w = 0
while o < 5:
	p = [int(x) for x in input().split()]
	n += p
	o += 1
for i in n:
	if i == 1:
		u = w
	w += 1
while u != 12:
	while u < 10 and u < 14:
		u += 5
		m += 1
	while u > 14 and u > 10:
		u -= 5
		m += 1
	while u < 12:
		u += 1
		m += 1
	while u > 12:
		u -= 1
		m += 1
print(m)


import sys
flag = 0
for i in range(5):
	if flag == 1:
		break
	listt = list(map(int, sys.stdin.readline().split()))
	for j in range(5):
		if listt[j] == 1:
			(idx, jdx) = (i, j)
			flag = 1
			break
print(abs(2 - idx) + abs(2 - jdx))


for i in range(5):
	col = 0
	for j in map(int, input().split()):
		col += 1
		if j == 1:
			print(abs(2 - i) + abs(3 - col))


arr = [int(j) for i in range(5) for j in input().split()]
k = arr.index(1)
print(abs(2 - k // 5) + abs(2 - k % 5))


matrix = []
for i in range(5):
	matrix.append([])
	matrix[i] = [int(j) for j in input().split()]
for i in range(5):
	if 1 in matrix[i]:
		x_coord = i
		y_coord = matrix[i].index(1)
dop_matrix = [[4, 3, 2, 3, 4], [3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3], [4, 3, 2, 3, 4]]
print(dop_matrix[x_coord][y_coord])


import math
a = []
for i in range(5):
	a.append(input().split())
for i in range(5):
	if '1' in a[i]:
		x = i
		y = a[i].index('1')
		break
print(int(math.fabs(y - 2) + math.fabs(x - 2)))


A = []
one_i = 0
one_j = 0
one = 1
for i in range(5):
	a = list(map(int, input().split()))
	for j in a:
		if j == one:
			one_i = i
			one_j = a.index(j)
	A.append(a)
k = 0
while one_j != 2:
	if one_j > 2:
		one_j -= 1
		k += 1
	elif one_j < 2:
		one_j += 1
		k += 1
while one_i != 2:
	if one_i > 2:
		one_i -= 1
		k += 1
	elif one_i < 2:
		one_i += 1
		k += 1
print(k)


a = []
jj = 0
ii = 0
for i in range(5):
	a = input().split()
	if '1' in a:
		jj = a.index('1')
		ii = i
print(abs(2 - jj) + abs(2 - ii))


n = 5
center = [2, 2]
a = list(map(int, input().split()))
i = 0
while sum(a) == 0:
	a = list(map(int, input().split()))
	i += 1
j = a.index(1)
print(abs(center[0] - i) + abs(center[1] - j))


for i in range(5):
	row = list(input().split())
	if '1' in row:
		cnum = row.index('1')
		rnum = i
tot = 0
if rnum == 0 or rnum == 4:
	tot += 2
elif rnum == 1 or rnum == 3:
	tot += 1
if cnum == 0 or cnum == 4:
	tot += 2
elif cnum == 1 or cnum == 3:
	tot += 1
print(tot)


n = 0
for i in range(5):
	h = str(input()).replace(' ', '')
	if '1' in h:
		n += abs(i - 2)
		n += abs(h.index('1') - 2)
print(n)


for i in range(5):
	s = [int(x) for x in input().split()]
	for k in range(5):
		if s[k] == 1:
			print(abs(k - 2) + abs(i - 2))
			break


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))
x = 0
y = 0
for cont in range(0, 5):
	if r1[cont] == 1:
		x = cont
		y = 0
		break
	if r2[cont] == 1:
		x = cont
		y = 1
		break
	if r3[cont] == 1:
		x = cont
		y = 2
		break
	if r4[cont] == 1:
		x = cont
		y = 3
		break
	if r5[cont] == 1:
		x = cont
		y = 4
		break
ris = abs(y - 2) + abs(x - 2)
print(ris)


l = []
for i in range(5):
	l.append(list(map(int, input().strip().split())))
for j in range(5):
	for k in range(5):
		if l[j][k] == 1:
			r = j + 1
			c = k + 1
print(abs(3 - r) + abs(3 - c))


x = [0, 0]
for n in range(5):
	y = input().split()
	if '1' in y:
		x[0] = n + 1
		x[1] = y.index('1') + 1
print(abs(x[0] - 3) + abs(x[1] - 3))


matrix = []
for i in range(5):
	a = [int(i) for i in input().split()][:5]
	matrix.append(a)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			x = i
			y = j
			break
move = abs(x - 2) + abs(y - 2)
print(move)


row = 0
column = 0
matrix = []
for i in range(5):
	a = list(map(int, input().split()))
	matrix.append(a)
for i in range(5):
	flag = 0
	for j in range(5):
		if matrix[i][j] == 1:
			row = i + 1
			column = j + 1
			flag = 1
			break
	if flag == 1:
		break
print(abs(row - 3) + abs(column - 3))


import sys

def solution():
	matrix = []
	size = 5
	for i in range(size):
		line = list(map(int, sys.stdin.readline().split()))
		matrix.append(line)
	for (h, row) in enumerate(matrix):
		for (g, elem) in enumerate(row):
			if elem == 1:
				pos = (h + 1, g + 1)
	steps = abs(pos[0] - 3) + abs(pos[1] - 3)
	print(steps)
solution()


for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		x = i
		y = l.index(1)
		break
c = abs(x - 2) + abs(y - 2)
print(c)


import math
a = []
for i in range(5):
	a.append(list(map(int, input().split())))
position = []
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			position.append(i)
			position.append(j)
print(int(math.sqrt(abs(2 - position[0]) ** 2) + math.sqrt(abs(2 - position[1]) ** 2)))


(x, y) = (-1, -1)
matrix = []
for i in range(5):
	temp = [int(x) for x in input().split()]
	if 1 in temp:
		x = i
		y = temp.index(1)
	matrix.append(temp)
result = abs(2 - x) + abs(2 - y)
print(result)


for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			ans = abs(3 - (i + 1)) + abs(3 - (j + 1))
print(ans)


a = 0
for i in range(5):
	linha = input()
	if len(set(linha)) >= 3 or (len(set(linha)) >= 2 and i == 4):
		a = abs(i - 2) + abs(int(linha.index('1') / 2) - 2)
		print(a)
		exit(0)
print(int(a))


matrix = []
for i in range(5):
	zeile = input().split()
	matrix.append(zeile)
	if '1' in zeile:
		index_y = i
index_x = matrix[index_y].index('1')
abstand = abs(2 - index_x) + abs(2 - index_y)
print(abstand)


x = 0
y = 0
onerow = []
for i in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		x = i
		onerow = row
for (i, j) in enumerate(onerow):
	if j == 1:
		y = i
		break
print(abs(x - 2) + abs(y - 2))


count = 0
for i in range(5):
	s = list(map(int, input().split()))
	for j in range(5):
		if s[j] == 1:
			count = abs(i - 2) + abs(j - 2)
print(count)


list1 = []
for i in range(5):
	list1.append(list(map(int, input().split(' '))))
row = 0
col = 0
for i in range(1, 6):
	if 1 in list1[i - 1]:
		row = i
		break
for j in range(1, 6):
	if list1[row - 1][j - 1] == 1:
		col = j
		break
print(abs(row - 3) + abs(col - 3))


row = -1
col = -1
for i in range(5):
	c = input().split(' ')
	if c.count('1'):
		row = i
		col = c.index('1')
ans = abs(2 - row) + abs(2 - col)
print(ans)


l = []
for a in range(5):
	x = input()
	l.append(x.split())
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			s = i
			v = j
n = abs(s - 2) + abs(v - 2)
print(n)


list1 = input().split()
list2 = input().split()
list3 = input().split()
list4 = input().split()
list5 = input().split()
list6 = [list1, list2, list3, list4, list5]
k = -1
for i in list6:
	k = k + 1
	l = -1
	for j in i:
		l = l + 1
		if j == '1':
			c = 2 - k
			d = 2 - l
			if c < 0 and d < 0:
				c = c * -1
				d = d * -1
				b = c + d
				print(b)
			elif c < 0:
				c = c * -1
				b = c + d
				print(b)
			elif d < 0:
				d = d * -1
				b = c + d
				print(b)
			else:
				b = c + d
				print(b)


row = []
for i in range(5):
	row.append(list(map(int, input().split())))
for k in range(5):
	for j in range(5):
		if row[k][j] == 1:
			print(abs(2 - k) + abs(2 - j))
			break
		else:
			pass


a = []
for i in range(5):
	a.append(input().split())
for i in range(5):
	if a[i].count('1') == 1:
		k = i
		h = a[i].index('1')
		break
print(abs(2 - k) + abs(2 - h))


import sys
for row in range(5):
	s = list(sys.stdin.readline().split())
	if '1' in s:
		i = row
		j = s.index('1')
total = abs(2 - i) + abs(2 - j)
sys.stdout.write(str(total) + '\n')


lista = [['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e']]
for i in range(5):
	texto = input('')
	lista[i] = texto.split(' ')
for j in range(5):
	if lista[0][j] == '1':
		if j == 0 or j == 4:
			print('4')
		if j == 1 or j == 3:
			print('3')
		if j == 2:
			print('2')
for j in range(5):
	if lista[1][j] == '1':
		if j == 0 or j == 4:
			print('3')
		if j == 1 or j == 3:
			print('2')
		if j == 2:
			print('1')
for j in range(5):
	if lista[2][j] == '1':
		if j == 0 or j == 4:
			print('2')
		if j == 1 or j == 3:
			print('1')
		if j == 2:
			print('0')
for j in range(5):
	if lista[3][j] == '1':
		if j == 0 or j == 4:
			print('3')
		if j == 1 or j == 3:
			print('2')
		if j == 2:
			print('1')
for j in range(5):
	if lista[4][j] == '1':
		if j == 0 or j == 4:
			print('4')
		if j == 1 or j == 3:
			print('3')
		if j == 2:
			print('2')


matrix = []
for i in range(0, 5):
	a = []
	inp = input().split()
	for j in range(5):
		a.append(int(inp[j]))
	matrix.append(a)
c = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			if i > 2:
				while i != 2:
					matrix[i][j] = 0
					matrix[i - 1][j] = 1
					i -= 1
					c += 1
			if i < 2:
				while i != 2:
					matrix[i][j] = 0
					matrix[i + 1][j] = 1
					i += 1
					c += 1
			if j > 2:
				while j != 2:
					matrix[i][j] = 0
					matrix[i][j - 1] = 1
					j -= 1
					c += 1
			if j < 2:
				while j != 2:
					matrix[i][j] = 0
					matrix[i][j + 1] = 1
					j += 1
					c += 1
print(c)


for i in range(5):
	inp = list(map(int, input().split()))
	if sum(inp) == 1:
		ix = i
		jx = inp.index(1)
print(abs(ix - 2) + abs(jx - 2))


row = None
col = None
for i in range(1, 5 + 1):
	inp = input()
	if '1' in inp:
		row = i
		col = inp.split(' ').index('1') + 1
print(abs(3 - row) + abs(3 - col))


import math
tool = 0
arz = 0
for i in range(5):
	x = input().split()
	for j in range(5):
		if int(x[j]) == 1:
			tool += i + 1
			arz += j + 1
print(abs(3 - tool) + abs(3 - arz))


a = [0] * 5
for i in range(5):
	b = [int(j) for j in input().split()]
	a[i] = b
for k in range(5):
	if 1 in a[k]:
		x = a[k].index(1)
		y = k
		break
print(abs(x - 2) + abs(y - 2))


q = []
for i in range(5):
	temp = list(map(int, input().split()))
	if 1 in temp:
		pos = [i, temp.index(1)]
	q.append(temp)
c = abs(pos[0] - 2) + abs(pos[1] - 2)
print(c)


for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			q = i
			w = j
print(abs(2 - q) + abs(2 - w))


target_i = 2
target_j = 2
output = 0
matrix = [input().split() for i in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			output = abs(target_i - i) + abs(target_j - j)
print(output)


mat = []
for i in range(5):
	a = input().split()
	a = [int(x) for x in a]
	mat.append(a)
	d = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			d = 1
			break
	if d == 1:
		break
x = abs(2 - i) + abs(2 - j)
print(x)


l = []
for i in range(5):
	temp = list(map(int, input().split()))
	l.append(temp)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			row = i
			col = j
			break
print(abs(row - 2) + abs(col - 2))


rix = []
for i in range(5):
	mat = input().split()
	rix.append(mat)
for i in range(5):
	if '1' in rix[i]:
		x = i
		y = rix[i].index('1')
result = abs(2 - x) + abs(2 - y)
print(result)


for i in range(5):
	m = input().split()
	if m.count('1'):
		j = m.index('1')
		break
print(abs(i - 2) + abs(j - 2))


for i in range(5):
	row = [int(x) for x in input().split()]
	if sum(row) == 1:
		res = abs(row.index(1) - 2) + abs(i - 2)
print(res)


y = []
flag = 0
for j in range(5):
	y = input().split()
	for i in range(5):
		if y[i] == '1':
			flag = 1
			break
	if flag == 1:
		break
print(abs(i - 2) + abs(j - 2))


s = 0
for i in range(0, 5):
	st = input()
	if st[0] == '1' or st[2] == '1' or st[4] == '1' or (st[6] == '1') or (st[8] == '1'):
		if i == 0 or i == 4:
			if st[0] == '1' or st[8] == '1':
				s += 2
			if st[2] == '1' or st[6] == '1':
				s += 1
			s += 2
		if i == 1 or i == 3:
			if st[0] == '1' or st[8] == '1':
				s += 2
			if st[2] == '1' or st[6] == '1':
				s += 1
			s += 1
		if i == 2:
			if st[0] == '1' or st[8] == '1':
				s += 2
			if st[2] == '1' or st[6] == '1':
				s += 1
print(s)


for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		a = l.index(1)
		dist = abs(i + 1 - 3) + abs(a + 1 - 3)
print(dist)


a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a4 = list(map(int, input().split()))
a5 = list(map(int, input().split()))
if 1 in a1:
	y = a1.index(1)
	t = y - 2
	if t < 0:
		t *= -1
	print(2 + t)
if 1 in a2:
	y = a2.index(1)
	t = y - 2
	if t < 0:
		t *= -1
	print(1 + t)
if 1 in a3:
	y = a3.index(1)
	t = y - 2
	if t < 0:
		t *= -1
	print(t)
if 1 in a4:
	y = a4.index(1)
	t = y - 2
	if t < 0:
		t *= -1
	print(1 + t)
if 1 in a5:
	y = a5.index(1)
	t = y - 2
	if t < 0:
		t *= -1
	print(2 + t)


n = 5
a = [list(map(int, input().split()))]
for x in range(len(a[0]) - 1):
	a.append(list(map(int, input().split())))
for i in range(n):
	for j in range(n):
		if a[i][j] == 1:
			u = i
			v = j
print(abs(u - 2) + abs(v - 2))


for i in range(5):
	r = [int(i) for i in input().split()]
	if 1 in r:
		row = i + 1
		col = r.index(1) + 1
print(abs(row - 3) + abs(col - 3))


index = 0
arr = [list(map(int, input().split())) for i in range(5)]
for i in range(len(arr)):
	if 1 in arr[i]:
		index = (i, arr[i].index(1))
		break
print(abs(2 - index[0]) + abs(2 - index[1]))


l = []
for i in range(5):
	ch = input()
	for x in ch:
		if x != ' ':
			l.append(x)
n = l.index('1') + 1
a = 0
b = 0
if n <= 10:
	a = 2 - (n - 1) // 5
elif 15 <= n:
	a = (n - 1) // 5 - 2
if n % 5 == 1 or n % 5 == 0:
	b = 2
elif n % 5 == 2 or n % 5 == 4:
	b = 1
print(a + b)


arr = 0
for i in range(1, 5 + 1):
	lst = list(map(int, input().split()))
	if 1 in lst:
		arr = abs(3 - i) + abs(3 - (lst.index(1) + 1))
		break
print(arr)


a = 5 * [5 * [0]]
for i in range(5):
	arr = input()
	a[i] = [int(n) for n in arr.split()]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


list = [2, 1, 0, 1, 2]
for i in list:
	matrix = input()
	if '1' in matrix:
		print(i + list[matrix.find('1') // 2])


arr = []
for i in range(0, 5):
	n = [int(x) for x in input('').split()]
	arr.append(n)
loc = 0
center = 13
for j in range(0, len(arr)):
	for k in range(0, len(arr[i])):
		loc += 1
		if arr[j][k] == 1:
			print(abs(j - 2) + abs(k - 2))


m = 5
while m > 0:
	i = input()
	if '1' in i:
		(a1, b1, c1, d1, e1) = i.split()
		a = int(a1)
		b = int(b1)
		c = int(c1)
		d = int(d1)
		e = int(e1)
		if a == 1:
			p = abs(m - 3) + 2
		elif b == 1:
			p = abs(m - 3) + 1
		elif c == 1:
			p = abs(m - 3)
		elif d == 1:
			p = abs(m - 3) + 1
		elif e == 1:
			p = abs(m - 3) + 2
		print(p)
		break
	else:
		m = m - 1


def get_moves(x, y):
	return abs(x - 3) + abs(y - 3)

def get_x(row):
	return row.index('1') // 2 + 1
for y in range(5, 0, -1):
	row = input()
	if '1' in row:
		solution = get_moves(get_x(row), y)
print(solution)


x = y = 0
for i in range(5):
	row = [int(i) for i in str(input()).split(' ')]
	if sum(row) == 1:
		x = i
		y = row.index(1)
print(abs(2 - x) + abs(2 - y))


matrx = []
for i in range(5):
	matrx.append(list(map(int, input().split())))
for i in matrx:
	try:
		i.index(1)
		row_indx = matrx.index(i)
	except ValueError:
		pass
count_rswap = 0
while row_indx != 2:
	if row_indx > 2:
		row_indx -= 1
		count_rswap += 1
	else:
		row_indx += 1
		count_rswap += 1
for i in matrx:
	try:
		col_indx = i.index(1)
	except ValueError:
		pass
count_cswap = 0
while col_indx != 2:
	if col_indx > 2:
		col_indx -= 1
		count_cswap += 1
	else:
		col_indx += 1
		count_cswap += 1
total_swap = count_cswap + count_rswap
print(total_swap)


arr = []
count = 0
for i in range(5):
	arr.append([int(i) for i in input().rstrip().split()])
	if 1 in arr[i]:
		r_n = i
		c_n = arr[i].index(1)
while r_n != 2 or c_n != 2:
	if r_n != 2:
		if r_n > 2:
			(arr[r_n], arr[r_n - 1]) = (arr[r_n - 1], arr[r_n])
			count += 1
			r_n = r_n - 1
			continue
		else:
			(arr[r_n], arr[r_n + 1]) = (arr[r_n + 1], arr[r_n])
			count += 1
			r_n = r_n + 1
			continue
	if c_n != 2:
		if c_n > 2:
			(arr[r_n][c_n], arr[r_n][c_n - 1]) = (arr[r_n][c_n - 1], arr[r_n][c_n - 1])
			count += 1
			c_n = c_n - 1
			continue
		else:
			(arr[r_n][c_n], arr[r_n][c_n + 1]) = (arr[r_n][c_n + 1], arr[r_n][c_n])
			count += 1
			c_n = c_n + 1
			continue
print(count)


from sys import stdin, stdout
matrix = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


for i in range(5):
	a = list(map(int, input().split()))
	res = 0
	for j in range(len(a)):
		if a[j] == 1:
			cols = abs(j - 3 + 1)
			rows = abs(i - 3 + 1)
			print(cols + rows)
			break


a = [2, 1, 0, 1, 2]
for i in a:
	s = input()
	if '1' in s:
		print(i + a[s.find('1') // 2])


m = []
stepcount = 0
for i in range(5):
	m.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			pos = [i, j]
if pos[0] < 2:
	stepcount += 2 - pos[0]
else:
	stepcount += pos[0] - 2
if pos[1] < 2:
	stepcount += 2 - pos[1]
else:
	stepcount += pos[1] - 2
print(stepcount)


matrix = []
row_index = -1
column_index = -1

def remove_space(n):
	return [value for value in n if value != ' ']
for i in range(5):
	matrix.append(remove_space(list(input())))
for i in range(5):
	for x in range(5):
		if matrix[x][i] == '1':
			row_index = i
			column_index = x
			break
		else:
			pass
if row_index <= 2:
	row_steps = 2 - row_index
else:
	row_steps = row_index - 2
if column_index <= 2:
	column_steps = 2 - column_index
else:
	column_steps = column_index - 2
print(row_steps + column_steps)


li = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if li[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))
			quit()


s = ''
for x in range(5):
	s = s + input().replace(' ', '')
p = s.find('1')
print(abs(p // 5 - 2) + abs(p % 5 - 2))


l = []
for x in range(5):
	a = input().split()
	l.append(a)
for x in l:
	if '1' in x:
		a = l.index(x) + 1
		b = x.index('1') + 1
x = max(a - 3, 3 - a)
y = max(b - 3, 3 - b)
print(x + y)


def solve(list):
	for i in range(5):
		if '1' in list[i]:
			for j in range(0, 9, 2):
				if list[i][j] == '1':
					return abs(j // 2 - 2) + abs(i - 2)
list = [0] * 5
for i in range(5):
	list[i] = input()
print(solve(list))


n = 5
matrix = []
for i in range(5):
	matrix.append([int(c) for c in input().split()])
row = col = -1
for r in range(5):
	for c in range(5):
		if matrix[r][c] == 1:
			(row, col) = (r, c)
swaps = abs(col - 2) + abs(row - 2)
print(swaps)


def get_coord():
	for i in range(5):
		jr = input().split()
		for (j, v) in enumerate(jr):
			if v == '1':
				return (i, j)
(i, j) = get_coord()
print(abs(2 - i) + abs(2 - j))


mtrx = []
for i in range(5):
	s = input()
	row = []
	for j in range(5):
		row.append(int(s.split()[j]))
	mtrx.append(row)
for x in range(5):
	for y in range(5):
		if int(mtrx[x][y]) == 1:
			print(abs(x - 2) + abs(y - 2))


x = 0
y = 0
for i in range(5):
	l = map(int, input().split())
	for (j, n) in enumerate(l):
		if n == 1:
			x = i
			y = j
			break
print(abs(2 - x) + abs(2 - y))


matrix = []
for i in range(5):
	matrix.append(list(map(int, str(input()).split(' '))))
one = (0, 0)
for i in range(len(matrix)):
	row = matrix[i]
	for j in range(len(row)):
		if row[j] == 1:
			one = (i + 1, j + 1)
print(sum(map(lambda x: abs(x - 3), list(one))))


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
for i in range(len(arr)):
	for j in range(len(arr[0])):
		if arr[i][j] == 1:
			row = i
			col = j
print(str(abs(row - 2) + abs(col - 2)))


a = []
for i in range(5):
	l = list(map(int, input().split()))
	a.append(l)
originX = 2
originY = 2
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			targetX = i
			targetY = j
print(abs(originX - targetX) + abs(originY - targetY))


import math
l = []
for i in range(1, 6):
	l.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			v = i
			v1 = j
print(int(math.fabs(v - 2) + math.fabs(v1 - 2)))


indexInLine = -1
movs = 0
for i in range(-2, 3):
	indexInLine = input().find('1')
	if indexInLine != -1:
		movs = abs(i) + abs(indexInLine / 2 - 2)
print(int(movs))


moves = 0
row = 0
column = 0
for i in range(5):
	line = input().split()
	for j in range(5):
		line[j] = int(line[j])
	if sum(line) == 1:
		column = line.index(1) + 1
		row = i + 1
moves = abs(column - 3) + abs(row - 3)
print(moves)


count = 0
row = None
column = None
for i in range(5):
	ip = list(map(int, input().split()))
	if 1 in ip:
		row = i
		for j in ip:
			if j == 1:
				column = ip.index(j)
	else:
		count += 1
answer = abs(row - 2) + abs(2 - column)
print(answer)


contents = []
while True:
	try:
		contents.append(input().split())
	except:
		break
num_row = one_num_column = one_num_row = steps = 0
for line in contents:
	num_column = 0
	for num in line:
		if int(num) == 1:
			one_num_row = num_row
			one_num_column = num_column
		num_column += 1
	num_row += 1
if one_num_row != 2:
	steps += abs(2 - one_num_row)
if one_num_column != 2:
	steps += abs(2 - one_num_column)
print(steps)


def main():
	L = []
	c = 0
	for i in range(5):
		L.append(input().split())
		if '1' in L[i]:
			c += i - 2 if i > 2 else 2 - i
			c += L[i].index('1') - 2 if L[i].index('1') > 2 else 2 - L[i].index('1')
	print(c)
main()


(ai, aj) = (0, 0)
for i in range(5):
	a = input().split()
	if '1' in a:
		ai = i
		aj = a.index('1')
print(abs(ai - 2) + abs(aj - 2))


M = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if M[i][j] == 1:
			k = i
			l = j
kr = abs(2 - k) + abs(2 - l)
print(kr)


x = -1
while x <= 4:
	list = input().split(' ')
	x = x + 1
	if '1' in list:
		a = list.index('1')
		break
print(abs(2 - x) + abs(a - 2))


l = list()
(m, n) = (-1, -1)
for m in range(5):
	i = input().split()
	try:
		n = i.index('1')
		if n != -1:
			print(abs(2 - m) + abs(2 - n))
	except:
		pass


m = []
num = ''
steps = 0
for i in range(5):
	row = input().split(' ')
	l = []
	for j in range(len(row)):
		if row[j] != '0':
			num = (i, j)
		l.append(row[j])
	m.append(l)
if num[0] > 2:
	steps += num[0] - 2
elif num[0] < 2:
	steps += 2 - num[0]
if num[1] > 2:
	steps += num[1] - 2
elif num[1] < 2:
	steps += 2 - num[1]
print(steps)


n = 5
for i in range(5):
	h = list(map(int, input().split(' ')))
	for j in range(5):
		if h[j] == 1:
			a = j
			b = i
			c = abs(i - 2) + abs(j - 2)
			print(c)


for i in range(5):
	A = list(map(int, input().split()))
	if 1 in A:
		row = i + 1
		column = A.index(1) + 1
print(abs(3 - row) + abs(3 - column))


h = list(map(int, input().split())) + list(map(int, input().split())) + list(map(int, input().split())) + list(map(int, input().split())) + list(map(int, input().split()))
g = [4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4]
s = 0
for i in range(25):
	s += g[i] * h[i]
print(s)


for row_item in range(5):
	row = input().split(' ')
	if row.count('1') > 0:
		column_item = row.index('1')
		print(abs(3 - (int(column_item) + 1)) + abs(3 - (row_item + 1)))


row = 0
respuesta = ''
for i in range(1, 6):
	respuesta = input()
	if '1' in respuesta:
		row = i
		break
column = respuesta.split().index('1') + 1
print(abs(3 - row) + abs(3 - column))


l = []
for _ in range(5):
	l.append(''.join(input().split()))
for i in range(len(l)):
	if '1' in l[i]:
		x = i
y = l[x].index('1')
count = 0
x = x + 1
y = y + 1
while x != 3:
	if x < 3:
		x += 1
	else:
		x -= 1
	count += 1
while y != 3:
	if y < 3:
		y += 1
	else:
		y -= 1
	count += 1
print(count)


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			str = i
			col = j
print(abs(2 - str) + abs(2 - col))


import sys
for i in range(5):
	inputs = sys.stdin.readline()
	if '1' in inputs:
		inputs = inputs.split()
		for j in range(5):
			if inputs[j] == '1':
				(x, y) = (i, j)
				break
print(abs(x - 2) + abs(y - 2))


for i in range(5):
	row = [int(x) for x in input().split(' ')]
	if 1 in row:
		p = row.index(1)
		if p > -1:
			pos = [p, i]
print(abs(2 - pos[0]) + abs(2 - pos[1]))


def main():
	matrix = []
	for i in range(5):
		line = list(map(int, input().split()))
		for j in range(5):
			if line[j] == 1:
				row = i
				col = j
				break
		matrix.append(line)
	answer = abs(2 - row) + abs(2 - col)
	print(answer)
main()


def tup(st):
	lt = st.split()
	tp = tuple(lt)
	return tp
s1 = input()
t1 = tup(s1)
s2 = input()
t2 = tup(s2)
s3 = input()
t3 = tup(s3)
s4 = input()
t4 = tup(s4)
s5 = input()
t5 = tup(s5)
lst = []
lst.append(t1)
lst.append(t2)
lst.append(t3)
lst.append(t4)
lst.append(t5)
count = 0
passer = 0
for (N, x) in enumerate(lst):
	for (n, y) in enumerate(x):
		if y == '1':
			passer = 1
			if n < 2:
				count = count + (2 - n)
			else:
				count = count + (n - 2)
			if N < 2:
				count = count + (2 - N)
			else:
				count = count + (N - 2)
			break
		else:
			pass
print(count)


matrix = []
for i in range(5):
	l = input().split()
	matrix.append(l)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
			break


l = []
for i in range(5):
	l.append([int(x) for x in input().split()])
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			x = i
			y = j
			break
if x > 2:
	c = x - 2
else:
	c = 2 - x
if y > 2:
	c += y - 2
else:
	c += 2 - y
print(c)


matr = []
for i in range(5):
	matr.append(input().split())
for j in range(5):
	for q in range(5):
		if matr[j][q] == '1':
			print(abs(2 - j) + abs(2 - q))


matrix = [list(map(int, input().split())) for _ in range(5)]
row = 0
for (idx, r) in enumerate(matrix):
	if 1 in r:
		row = idx + 1
		break
col = 0
for (idx, c) in enumerate(matrix[row - 1]):
	if 1 == c:
		col = idx + 1
		break
print(abs(3 - row) + abs(3 - col))


mat = []
for x in range(5):
	t = [int(x) for x in input().split()]
	mat.append(t)
for (i, x) in enumerate(mat):
	if 1 in x:
		j = x.index(1)
		print(abs(i - 2) + abs(j - 2))
		break


matrix = list()
for i in range(0, 5):
	(a, b, c, d, e) = input().split()
	matrix.extend((a, b, c, d, e))
uno = matrix.index('1') + 1
if uno % 5 == 0:
	row = uno / 5
	col = 5
else:
	row = uno // 5 + 1
	col = uno % 5
print(int(abs(3 - row) + abs(3 - col)))


for i in range(1, 6):
	inp = input()
	if '1' in inp:
		y_ = inp[::2].find('1') + 1
		x_ = i
print(abs(x_ - 3) + abs(y_ - 3))


c = []
b = []
t_p = 0
for i in range(5):
	x = map(int, input().split())
	a = list(x)
	b.append(a)
for i in range(len(b)):
	for j in range(len(b[0])):
		if b[i][j] == 1:
			c.append((i, j))
d = [item for t in c for item in t]
for i in d:
	while i != 2:
		if i > 2:
			i -= 1
			t_p += 1
		elif i < 2:
			i += 1
			t_p += 1
		else:
			pass
print(t_p)


inp = []
for i in range(5):
	inp.append(input())
dim = (0, 0)
for i in range(len(inp)):
	s = inp[i].split()
	for j in range(len(s)):
		if int(s[j]) == 1:
			dim = (i + 1, int(j) + 1)
print(abs(dim[0] - 3) + abs(dim[1] - 3))


N = 5
while N > 0:
	N -= 1
	A = input()
	B = A.find(str(1))
	if B < 0:
		pass
	else:
		print(str(int(abs(N - 2) + abs(B / 2 - 2))))


def solution(li):
	row = 0
	col = 0
	n = len(li)
	for i in range(n):
		for j in range(n):
			if li[i][j] == 1:
				row = i
				col = j
				break
	return abs(row - 2) + abs(col - 2)
li = [[int(j) for j in input().split()] for i in range(5)]
print(solution(li))


a = list(input().split())
b = list(input().split())
c = list(input().split())
d = list(input().split())
e = list(input().split())
m = 0
if '1' in a or '1' in e:
	m += 2
	for i in range(5):
		if a[i] == '1' or e[i] == '1':
			if i < 3:
				m += 2 - i
			else:
				m += i - 2
if '1' in b or '1' in d:
	m += 1
	for i in range(5):
		if b[i] == '1' or d[i] == '1':
			if i < 3:
				m += 2 - i
			else:
				m += i - 2
for i in range(5):
	if c[i] == '1':
		if i < 3:
			m += 2 - i
		elif i > 2:
			m += i - 2
print(m)


import math
row1s = input()
row2s = input()
row3s = input()
row4s = input()
row5s = input()
a = row1s.find('1')
b = row2s.find('1')
c = row3s.find('1')
d = row4s.find('1')
e = row5s.find('1')
row = 0
i = -1
alist = [a, b, c, d, e]
while i == -1:
	i = alist[row]
	row = row + 1
line = i / 2 + 1
answer = math.fabs(line - 3) + math.fabs(row - 3)
print(int(answer))


matrix = []
for _ in range(5):
	r = input().split(' ')
	matrix.append([])
	for v in r:
		matrix[-1].append(int(v))
(loc_y, loc_x) = (0, 0)
for j in range(len(matrix)):
	for i in range(len(matrix[0])):
		if matrix[j][i] == 1:
			print(abs(j - 2) + abs(i - 2))
			exit()


l = []
for i in range(5):
	s = input()
	s = s.split(' ')
	l.append(s)
for i in l:
	if '1' in i:
		(a, b) = (l.index(i), i.index('1'))
		break
	else:
		continue
print(abs(a - 2) + abs(b - 2))


a = list(input())
b = list(input())
c = list(input())
d = list(input())
e = list(input())
j = 0
n = 1
for i in a + b + c + d + e:
	if i == '0':
		j += 1
		if j == 5:
			j = 0
			n += 1
	if i == '1':
		j += 1
		break
print(abs(n - 3) + abs(j - 3))


for r in range(5):
	for (c, i) in enumerate(input().split()):
		if i == '1':
			print(abs(r - 2) + abs(c - 2))


for i in range(1, 6):
	j = input().replace(' ', '').find('1') + 1
	if j:
		print(abs(3 - i) + abs(3 - j))


(x, y) = (0, 0)
(m, n) = (3, 3)
for i in range(1, 6):
	a = list(map(int, input().split()))
	if 1 in a:
		x = i
		y = a.index(1) + 1
print(abs(m - x) + abs(n - y))


rows = (input().replace(' ', '') for _ in range(5))
for (row, cols) in enumerate(rows):
	col = cols.find('1')
	if col != -1:
		print(abs(2 - row) + abs(2 - col))
		break


a = []
for i in range(5):
	n = input().split()
	for i in range(len(n)):
		a.append(n[i])
index = a.index('1')
if 0 <= index <= 4:
	D = abs(index - 2) + 2
if 5 <= index <= 9:
	D = abs(index - 5 - 2) + 1
if 10 <= index <= 14:
	D = abs(index - 10 - 2)
if 15 <= index <= 19:
	D = abs(index - 15 - 2) + 1
if 20 <= index <= 24:
	D = abs(index - 20 - 2) + 2
print(D)


arr = []
raw = 0
column = 0
counter = 0
for i in range(5):
	x = input()
	z = x.split(' ')
	try:
		raw = raw + z.index('1')
		column = column + counter
	except:
		pass
	arr.append(z)
	counter = counter + 1
moves = abs(column - 2) + abs(raw - 2)
print(moves)


x = [[int(i) for i in input().split()] for j in range(5)]
p = 0
for i in range(5):
	for j in range(5):
		if x[i][j] == 1:
			row = i
			column = j
swap = abs(row - 2)
swap += abs(column - 2)
print(swap)


l = [2, 1, 0, 1, 2]
for i in l:
	x = input()
	if '1' in x:
		print(i + l[x.find('1') // 2])


y = []
for i in range(5):
	y.append([int(x) for x in input().split()])
for k in range(5):
	z = len(y[k])
	for n in range(z):
		if y[k][n] == 1:
			print(f'{abs(2 - k) + abs(2 - n)}')


ar = []
for i in range(5):
	temp = input().split()
	temp[:] = [int(i) for i in temp]
	ar.append(temp)
for i in range(len(ar)):
	for j in range(len(ar)):
		if ar[i][j] == 1:
			x = i + 1
			y = j + 1
			break
print(abs(x - 3) + abs(y - 3))


(x, y) = (2, 2)
for x2 in range(5):
	nums = ''.join(input().rstrip().split())
	y2 = nums.find('1')
	if y2 > -1:
		print(abs(x2 - x) + abs(y2 - y))
		break


a = []
for i in range(5):
	a.append(input().split())
i = 0
while i < len(a):
	j = 0
	while j < len(a[i]):
		if a[i][j] == '1':
			coord = [i, j]
		j += 1
	i += 1
print(abs(2 - coord[0]) + abs(2 - coord[1]))


for i in range(1, 6):
	s = str(input().replace(' ', ''))
	if s.count('1') == 1:
		index = s.index('1')
		print(abs(index - 2) + abs(i - 3))


import math
table = []
a = 1
for i in range(5):
	x = list(map(int, input().split()))
	if a in x:
		row_in = i + 1
		col_in = x.index(a) + 1
	table.append(x)
steps = math.fabs(3 - row_in) + math.fabs(3 - col_in)
print(int(steps))


def solve() -> int:
	for row_index in range(5):
		row_list = list(map(int, input().split(' ')))
		if 1 in row_list:
			col_index = row_list.index(1)
			return abs(row_index - 2) + abs(col_index - 2)
	raise RuntimeError('Invalid matrix !')
result = solve()
print(result)


import math
matrix = []
n = 5
i = 1
j = 0
one = 0
index1 = 0
index2 = 0
while n > 0:
	matrix.append([int(x) for x in input().split(' ')])
	n -= 1
for rows in matrix:
	j = 1
	for column in rows:
		if column == 1:
			index1 = i
			index2 = j
		j += 1
	i += 1
result = int(math.fabs(index1 - 3) + math.fabs(index2 - 3))
print(result)


r = c = -1
for i in range(5):
	row = list(map(int, input().split()))
	for (j, val) in enumerate(row):
		if val:
			print(max(i - 2, 2 - i) + max(j - 2, 2 - j))


x = 0
y = 0
for i in range(1, 6):
	sp = list(map(int, input().split()))
	for j in range(1, 6):
		if sp[j - 1] == 1:
			x = i
			y = j
print(abs(3 - x) + abs(3 - y))


c = 3
for i in range(5):
	st = input()
	if '1' in st:
		s = st
		break
	c += 5
s = s.split()
s = ''.join(s)
idx = s.index('1')
if c == 3:
	p = s.index('1') + 1
elif idx < 2:
	p = c - idx
else:
	p = c + idx - 2
m1 = max(c, p) - min(c, p)
if c >= 13:
	m2 = (c - 13) / 5
else:
	m2 = (13 - c) / 5
m = m1 + m2
if idx == 0 and c > 3:
	print(int(m + 2))
	exit()
print(int(m))


r = 0
for i in range(1, 5 + 1):
	row = list(map(int, input().split()))
	try:
		index = row.index(1)
		r = abs(i - 3) + abs(index + 1 - 3)
	except ValueError:
		pass
print(r)


def index_2d(myList):
	for (i, x) in enumerate(myList):
		if 1 in x:
			return (i, x.index(1))
matrix = []
for _ in range(5):
	values = list(map(int, input().split()))
	matrix.append(values)
(x, y) = index_2d(matrix)
print(abs(x - 2) + abs(y - 2))


for i in range(1, 6):
	line = input().split()
	for j in range(1, 6):
		if line[j - 1] == '1':
			print(abs(i - 3) + abs(j - 3))
			break


rows = []
for i in range(5):
	rows.append(list((int(num) for num in input().split())))
for i in range(1, 6):
	if 1 in rows[i - 1]:
		one_row = i
		one_col = rows[i - 1].index(1) + 1
		break
print(abs(3 - one_row) + abs(3 - one_col))


r = 0
c = 0
for i in range(0, 5):
	x = input().split()
	for j in range(0, 5):
		if x[j] == '1':
			r = i
			c = j
sum = abs(r - 2) + abs(c - 2)
print(sum)


l = []
for i in range(5):
	l.append(list(map(int, input().split())))
for i in range(len(l)):
	if 1 in l[i]:
		col = i
		row = l[i].index(1)
		break
if abs(col - 2) == 1 and abs(row - 2) == 1:
	print(2)
else:
	print(abs(col - 2) + abs(row - 2))


ma = []
for i in range(5):
	ma.append(input().split())
r = 0
c = 0
for row in range(len(ma)):
	for col in range(len(ma[0])):
		if ma[row][col] == '1':
			r = row
			c = col
ans = abs(r - 2) + abs(c - 2)
print(ans)


count = 0
for i in range(5):
	line = str(input()).split()
	for j in range(5):
		if int(line[j]) == 1:
			count = count + abs(3 - j - 1) + abs(3 - i - 1)
print(count)


Matrix = []
for _ in range(5):
	Matrix.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if Matrix[i][j] == 1:
			moves_needed = abs(i - 2) + abs(j - 2)
			print(moves_needed)


data = []
for q in range(5):
	data.append([int(x) for x in input().split()])
posx = 0
posy = 0
for q in range(len(data)):
	for w in range(len(data[0])):
		if data[q][w] == 1:
			posx = q
			posy = w
			break
print(abs(2 - posx) + abs(2 - posy))


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

def index2D(matrix, number):
	for (i, x) in enumerate(matrix):
		if number in x:
			a = i + 1
			b = x.index(number) + 1
			k = abs(3 - a) + abs(3 - b)
			return abs(3 - a) + abs(3 - b)
			if k == 0:
				print(0)
print(index2D(matrix, 1))


co_ordinate = ()
for i in range(5):
	f = input().split(' ')
	for j in range(len(f)):
		if f[j] == '1':
			co_ordinate = (i, int(j))
mid_co = (2, 2)
dis = (abs(mid_co[0] - co_ordinate[0]), abs(mid_co[1] - co_ordinate[1]))
print(sum(dis))


def abs(n):
	return -n if n < 0 else n
mat = []
for i in range(5):
	temp = [int(i) for i in input().split(' ')]
	mat.append(temp)
cl = []
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			cl = [i, j]
			break
op = 0
op = abs(cl[0] - 2) + abs(cl[1] - 2)
print(op)


mat = list()
for i in range(5):
	mat.append(input().split())
for i in range(5):
	for j in range(5):
		if mat[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
			break


mat = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if mat[i][j] != 0:
			steps = abs(3 - (i + 1)) + abs(3 - (j + 1))
			break
print(steps)


def read_line():
	return [int(i) for i in input().split(' ')]
mid = 2
for i in range(5):
	line = read_line()
	ones = [(i, x) for (i, x) in enumerate(line) if x == 1]
	if len(ones) > 0:
		row = i
		col = ones[0][0]
		print(abs(mid - row) + abs(mid - col))


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()))
from math import fabs
for i in range(1, 6):
	if a[i - 1] == 1:
		print(int(2 + fabs(3 - i)))
	if b[i - 1] == 1:
		print(int(1 + fabs(3 - i)))
	if c[i - 1] == 1:
		print(int(fabs(3 - i)))
	if d[i - 1] == 1:
		print(int(1 + fabs(3 - i)))
	if e[i - 1] == 1:
		print(int(2 + fabs(3 - i)))


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
move = 0
check = 0
for j in range(5):
	if a[j] == 1:
		check += 1
		break
	elif b[j] == 1:
		check += 2
		break
	elif c[j] == 1:
		check += 3
		break
	elif d[j] == 1:
		check += 4
		break
	elif e[j] == 1:
		check += 5
		break
if j == 0 or j == 4:
	move += 2
elif j == 1 or j == 3:
	move += 1
if check == 1 or check == 5:
	move += 2
elif check == 2 or check == 4:
	move += 1
print(move)


mat = []
for i in range(5):
	mat.append([int(_) for _ in input().split()])
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			(xi, xj) = (i, j)
print(abs(xi - 2) + abs(xj - 2))


row = 0
coloum = 0
move = 0
a = abs
for i in range(5):
	y = input()
	mat = y.strip().split()
	row += 1
	for i in mat:
		coloum += 1
		if coloum > 5:
			coloum = 1
		if i == '1':
			moves = a(3 - row) + a(3 - coloum)
print(moves)


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(number_of_variables):
	if number_of_variables == 1:
		return int(sys.stdin.readline())
	if number_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
mod = 100000007
mat = []
for i in range(5):
	mat.append([i for i in input().split()])
for i in range(5):
	for j in range(5):
		if mat[i][j] == '1':
			(r, c) = (i, j)
			break
print(abs(r - 3 + 1) + abs(c - 3 + 1))


matrix = []
for i in range(5):
	matrix.append(input().split())
(row, col) = (float('inf'), float('inf'))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			row = i
			col = j
print(abs(row - 2) + abs(col - 2))


m = []
for i in range(5):
	l = list(map(int, input().split()))[:5]
	m.append(l)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			k = i + 1
			o = j + 1
			break
count1 = abs(k - 3)
count2 = abs(o - 3)
print(count1 + count2)


(col, row) = (0, 0)
lst = []
for _ in range(5):
	r = list(map(int, input().split()))
	lst.append(r)
for _ in range(5):
	try:
		if 1 in lst[_]:
			row = _
			col = lst[_].index(1)
			break
	except:
		continue
print(abs(row - 2) + abs(col - 2))


from math import ceil
import sys, bisect, copyreg, copy, statistics, os

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

def IIX():
	return (int(x) for x in sys.stdin.readline().split())

def II():
	return int(inp())

def LI():
	return list(map(int, inp().split()))

def L(x):
	return list(x)

def out(var):
	return sys.stdout.write(str(var))
arr = []
for i in range(5):
	arr.append(L(IIX()))
for i in range(5):
	for j in range(5):
		ch = arr[i][j]
		if ch == 1:
			idx = [i, j]
out(abs(2 - idx[0]) + abs(2 - idx[1]))


mat = [0] * 5
j = 0
i = 0
for x in range(5):
	mat[x] = list(map(int, input().split()))
while j < 5:
	while i < 5:
		if mat[j][i] == 1:
			moves = abs(j - 2) + abs(i - 2)
			print(moves)
			break
		else:
			i = i + 1
	i = 0
	j = j + 1


one_cell = [0, 0]
for i in range(5):
	x = input().split()
	for j in range(5):
		if x[j] == '1':
			(one_cell[0], one_cell[1]) = (i, j)
print(abs(2 - one_cell[0]) + abs(2 - one_cell[1]))


def calculate(i, j):
	return abs(2 - i) + abs(2 - j)

def h():
	for i in range(5):
		x = [int(x) for x in input().split()]
		num = max(x)
		if num == 1:
			j = x.index(num)
			return calculate(i, j)
print(h())


a = []
for i in range(5):
	b = [int(x) for x in input().split()]
	a.append(b)
ind = None
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			ind = (i, j)
			break
	if ind:
		break
print(abs(ind[0] - 2) + abs(ind[1] - 2))


import sys
m = sys.stdin.read().splitlines()
c = int(0)
while c < len(m):
	m[c] = m[c].replace(' ', '')
	c = c + 1
i = int(0)
j = int(0)
while i < len(m):
	while j < len(m):
		if m[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
		j = j + 1
	i = i + 1
	j = 0


a = []
for i in range(5):
	a.append(input().split())
(x, y) = (1, 1)
for row in a:
	for column in row:
		if column == '1':
			print(abs(x - 3) + abs(y - 3))
			break
		x += 1
	x -= 5
	y += 1


for i in range(5):
	abc = list(input().split())
	if '1' in abc:
		x = i
		y = abc.index('1')
print(abs(2 - x) + abs(2 - y))


d = []
for i in range(0, 5):
	a = [int(x) for x in input().split()]
	d = d + a
for j in range(0, 25):
	if d[j] == 1:
		c = j + 1
if c == 1 or c == 21 or c == 5 or (c == 25):
	print(4)
if c == 2 or c == 4 or c == 6 or (c == 10) or (c == 16) or (c == 20) or (c == 22) or (c == 24):
	print(3)
if c == 3 or c == 7 or c == 9 or (c == 11) or (c == 15) or (c == 17) or (c == 19) or (c == 23):
	print(2)
if c == 8 or c == 14 or c == 12 or (c == 18):
	print(1)
if c == 13:
	print(0)


l = []
for x in range(5):
	m = input().split()
	for y in m:
		l.append(int(y))
for z in range(25):
	if l[z] == 0:
		pass
	else:
		a = z
		break
c = a // 5 + 1
b = (a + 1) % 5
if b == 0:
	b = 5
print(abs(b - 3) + abs(c - 3))


d = {}
for i in range(5):
	d[i] = input()
(x, y) = (0, 0)
for m in d:
	if d[m].find('1') >= 0:
		x += m
		y += d[m].find('1')
print(int(abs(x - 2) + abs((y - 4) / 2)))


matrix = []
for i in range(5):
	matrix.append(input())
i = 0
while matrix[i].find('1') == -1:
	i += 1
line = i + 1
col = matrix[i].find('1') // 2 + 1
print(abs(line - 3) + abs(col - 3))


xAxis = 0
yAxis = 0
for i in range(5):
	idx = input().split()
	idx = [int(x) for x in idx]
	if 1 in idx:
		(y, x) = (yAxis, idx.index(1))
		break
	yAxis += 1
print(abs(y - 2) + abs(x - 2))


matrix = []
for i in range(5):
	n = input().split()
	matrix.append(n)
pos = []
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			pos.append((i, j))
			break
print(abs(pos[0][0] - 2) + abs(pos[0][1] - 2))


count = 0
for i in range(5):
	line = input()
	if '1' in line:
		column = line.find('1')
		if i == 0 or i == 4:
			count = count + 2
		if i == 1 or i == 3:
			count = count + 1
		if column == 0 or column == 8:
			count = count + 2
		if column == 2 or column == 6:
			count = count + 1
print(count)


__author__ = 'runekri3'
for i in range(5):
	nums = list(map(int, input().split()))
	if 1 in nums:
		print(abs(2 - i) + abs(2 - nums.index(1)))


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
mi = 2
mj = 2
if 1 in l1:
	i = 1
	j = l1.index(1)
elif 1 in l2:
	i = 2
	j = l2.index(1)
elif 1 in l3:
	i = 3
	j = l3.index(1)
elif 1 in l4:
	i = 4
	j = l4.index(1)
else:
	i = 5
	j = l5.index(1)
moves = 0
if i <= 3 and j <= 2:
	moves += 3 - i + (2 - j)
elif i <= 3 and j > 2:
	moves += 3 - i + (j - 2)
elif i >= 3 and j <= 2:
	moves += i - 3 + (2 - j)
else:
	moves += i - 3 + (j - 2)
print(moves)


arr = [[int(i) for i in input().split(' ')] for j in range(5)]
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			x = i
			y = j
			pass
print(abs(x - 2) + abs(y - 2))


import math
list = []
while True:
	try:
		list.append(input())
		continue
	except:
		break
line_with_1 = 0
where_is_1 = 0
for i in list:
	if '1' in i:
		line_with_1 += list.index(i)
		i = i.replace(' ', '')
		where_is_1 += i.index('1')
	else:
		line_with_1 += 0
row = math.fabs(2 - line_with_1)
column = math.fabs(2 - where_is_1)
print(math.ceil(row + column))


s = []
for i in range(5):
	r = input()
	s.append(r.split())
for i in range(5):
	for j in range(5):
		if '1' in s[i][j]:
			f = (i + 1, j + 1)
			break

def g(a):
	if a < 0:
		return -a
	return a
print(g(f[0] - 3) + g(f[1] - 3))


c = 0
d = 0
x = 0
for i in range(1, 6):
	a = list(map(int, input().split(' ')))
	c = 0
	for j in range(len(a)):
		if a[j] == 1:
			d = i
			x = c + 1
			break
		else:
			c += 1
print(abs(3 - d) + abs(3 - x))


a = []
import math
for i in range(0, 5):
	b = list(map(int, input().split()))
	a.append(b)
r = int(0)
c = int(0)
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == 1:
			r = i + 1
			c = j + 1
m = abs(3 - r) + abs(3 - c)
print(m)


l = []
for i in range(5):
	l.append(list(map(int, input().strip().split())))
for i in range(5):
	if 1 in l[i]:
		ind1 = i
		ind2 = l[i].index(1)
		break
a = abs(2 - ind1)
b = abs(2 - ind2)
print(a + b)


x1 = input()
x2 = input()
x3 = input()
x4 = input()
x5 = input()
if x1[0] == '1' or x1[8] == '1' or x5[0] == '1' or (x5[8] == '1'):
	moves = 4
elif x1[2] == '1' or x1[6] == '1' or x5[2] == '1' or (x5[6] == '1') or (x2[0] == '1') or (x2[8] == '1') or (x4[0] == '1') or (x4[8] == '1'):
	moves = 3
elif x1[4] == '1' or x5[4] == '1' or x2[2] == '1' or (x2[6] == '1') or (x4[2] == '1') or (x4[6] == '1') or (x3[0] == '1') or (x3[8] == '1'):
	moves = 2
elif x3[4] == '1':
	moves = 0
else:
	moves = 1
print(moves)


lst = [2, 1, 0, 1, 2]
for i in lst:
	line = input()
	if line.count('1') > 0:
		print(i + abs(line.split().index('1') - 2))


n = 5
for i in range(n):
	row = input().strip().split(' ')
	try:
		j = row.index('1')
		break
	except:
		pass
ib = 2
jb = 2
print(abs(ib - i) + abs(jb - j))


l = []
for a in range(5):
	s = list(input().split())
	l.append(s)
for i in range(5):
	for j in range(5):
		if int(l[i][j]) == 1:
			result = abs(2 - i) + abs(2 - j)
			print(result)
			break


for a in range(0, 5):
	i = list(map(int, input().split()))
	for x in range(0, 5):
		if i[x] == 1:
			row = a + 1
			column = x + 1
total = abs(3 - row) + abs(3 - column)
print(total)


for i in range(5):
	n = input().find('1') // 2
	if n > -1:
		print(abs(2 - i) + abs(2 - n))
		break


for i in range(5):
	s = list(map(int, input().split()))
	for j in range(len(s)):
		if s[j] == 1:
			if i == 0 or i == 4:
				if j == 0 or j == 4:
					moves = 4
				elif j == 1 or j == 3:
					moves = 3
				else:
					moves = 2
			elif i == 1 or i == 3:
				if j == 0 or j == 4:
					moves = 3
				elif j == 1 or j == 3:
					moves = 2
				else:
					moves = 1
			elif j == 0 or j == 4:
				moves = 2
			elif j == 1 or j == 3:
				moves = 1
			else:
				moves = 0
print(moves)


def resolve(matrix):
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				return abs(3 - (i + 1)) + abs(3 - (j + 1))
matrix = []
for i in range(5):
	matrix.append([int(v) for v in input().split(' ')])
print(resolve(matrix))


x = 1
for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	if a + b + c + d + e == 1:
		r = i + 1
		for i in (a, b, c, d, e):
			if i == 1:
				break
			else:
				x = x + 1
				continue
	else:
		continue
if r >= 3:
	h = r - 3
else:
	h = 3 - r
if x >= 3:
	v = x - 3
else:
	v = 3 - x
print(h + v)


m = list()
(i, j) = (None, None)
for l in range(5):
	line = input().split()
	if '1' in line:
		i = l
		j = line.index('1')
	m.append(line)
c = 0
while i != 2 or j != 2:
	if i < 2:
		(m[i][j], m[i + 1][j]) = (m[i + 1][j], m[i][j])
		i += 1
		c += 1
	elif i > 2:
		(m[i][j], m[i - 1][j]) = (m[i - 1][j], m[i][j])
		i -= 1
		c += 1
	if j < 2:
		(m[i][j], m[i][j + 1]) = (m[i][j + 1], m[i][j])
		j += 1
		c += 1
	elif j > 2:
		(m[i][j], m[i][j - 1]) = (m[i][j - 1], m[i][j])
		j -= 1
		c += 1
print(c)


a = []
for i in range(5):
	a.append([*map(int, input().split())])
pos = []
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			pos.append((i, j))
			break
print(abs(pos[0][0] - 2) + abs(pos[0][1] - 2))


n = 5
for i in range(1, 6):
	s = input()
	s = s.split()
	if '1' in s:
		x = i
		y = s.index('1') + 1
print(abs(x - 3) + abs(y - 3))


(l, store) = ([], [])
for i in range(5):
	temp = list(map(int, input().split()))
	l.append(temp)
	if 1 in temp:
		store.append(i)
		store.append(temp.index(1))
print(abs(store[0] - 2) + abs(store[1] - 2))


a = []
count = 0
for _ in range(5):
	b = list(map(int, input().split(' ')))
	a.append(b)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			(m, n) = (i, j)
			break
while m != 2 or n != 2:
	if m > 2:
		m -= 1
		count += 1
	elif m < 2:
		m += 1
		count += 1
	elif n < 2:
		n += 1
		count += 1
	elif n > 2:
		n -= 1
		count += 1
print(count)


for i in range(5):
	string = [int(a) for a in input().split()]
	for j in range(5):
		a = string[j]
		if a == 1:
			i1 = i
			j1 = j
print(abs(i1 - 2) + abs(j1 - 2))


ii = 0
jj = 0
for i in range(5):
	arr = list(map(int, input().split()))
	if 1 in arr:
		ii = i
		jj = arr.index(1)
print(abs(2 - ii) + abs(2 - jj))


x = []
for i in range(5):
	x.append(input())
	x[i] = x[i].split(' ')
for i in range(5):
	for j in range(5):
		if x[i][j] == '1':
			p = i + 1
			q = j + 1
p = abs(p - 3)
q = abs(q - 3)
print(p + q)


r = []
for i in range(5):
	l = []
	l = [int(x) for x in input().split()]
	for k in range(len(l)):
		if l[k] == 1:
			a = i
			b = k
		r.append(l)
z = abs(a - 2)
k = abs(b - 2)
print(z + k)


pos1 = 0
pos2 = 0
for i in range(5):
	l = input().split()
	if '1' in l:
		pos1 = l.index('1')
		pos2 = i
print(abs(pos1 - 2) + abs(pos2 - 2))


mat = [[0 for i in range(5)] for j in range(5)]
for i in range(5):
	mat[i] = list(map(int, input().split()))
for i in range(len(mat)):
	if 1 in mat[i]:
		ind = mat[i].index(1)
		row = i
		break
res = [row, ind]
count = 0
if res[1] > 2 and res[0] < 2:
	for i in range(res[1], 2, -1):
		count = count + 1
	for j in range(res[0], 2):
		count = count + 1
if res[1] > 2 and res[0] > 2:
	for i in range(res[1], 2, -1):
		count = count + 1
	for j in range(res[0], 2, -1):
		count = count + 1
if res[1] < 2 and res[0] < 2:
	for i in range(res[1], 2):
		count = count + 1
	for j in range(res[0], 2):
		count = count + 1
if res[1] < 2 and res[0] > 2:
	for i in range(res[1], 2):
		count = count + 1
	for j in range(res[0], 2, -1):
		count = count + 1
if res[1] == 2 and res[0] != 2:
	if res[0] < 2:
		for i in range(res[0], 2):
			count = count + 1
	if res[0] > 2:
		for i in range(res[0], 2, -1):
			count = count + 1
if res[0] == 2 and res[1] != 2:
	if res[1] < 2:
		for i in range(res[1], 2):
			count = count + 1
	if res[1] > 2:
		for i in range(res[1], 2, -1):
			count = count + 1
print(count)


my_list = []
for i in range(5):
	my_list.append([int(x) for x in input().split()])
for i in range(5):
	for j in range(5):
		if my_list[i][j] == 1:
			ans = abs(2 - i) + abs(2 - j)
			print(ans)
			break


arr = [input().split() for i in range(5)]
ans = ()
for i in range(5):
	for j in range(5):
		if arr[i][j] == '1':
			ans = (i + 1, j + 1)
print(abs(3 - ans[0]) + abs(3 - ans[1]))


matrix = []
for x in range(5):
	r = list(map(int, input().split()))
	matrix.append(r)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			(z, w) = (i, j)
counter = 0
while z != 2 or w != 2:
	if z < 2:
		z += 1
		counter += 1
	elif z > 2:
		z -= 1
		counter += 1
	elif w < 2:
		w += 1
		counter += 1
	elif w > 2:
		w -= 1
		counter += 1
print(counter)


a = input().strip().split(' ')
b = input().strip().split(' ')
c = input().strip().split(' ')
d = input().strip().split(' ')
e = input().strip().split(' ')
if '1' in a:
	x = abs(a.index('1') + 1 - 3)
	y = 2
if '1' in b:
	x = abs(b.index('1') + 1 - 3)
	y = 1
if '1' in c:
	x = abs(c.index('1') + 1 - 3)
	y = 0
if '1' in d:
	x = abs(d.index('1') + 1 - 3)
	y = 1
if '1' in e:
	x = abs(e.index('1') + 1 - 3)
	y = 2
print(x + y)


from collections import deque
base = []
dq = deque([])
count = 0
used = [[0 for _ in range(5)] for _ in range(5)]
for idx in range(5):
	temps = list(map(int, input().split()))
	if 1 in temps:
		dq.append((idx, temps.index(1)))
while dq:
	for _ in range(len(dq)):
		(x, y) = dq.popleft()
		if (x, y) == (2, 2):
			print(count)
			break
		else:
			for (dx, dy) in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
				(next_x, next_y) = (x + dx, y + dy)
				if 0 <= next_x < 5 and 0 <= next_y < 5:
					if not used[next_x][next_y]:
						used[next_x][next_y] = 1
						dq.append((next_x, next_y))
	count += 1


out = 0
for x in range(1, 6):
	l = list(map(int, input().split()))
	if 1 in l:
		out = abs(x - 3) + abs(l.index(1) - 2)
print(out)


import math
for row in range(1, 6):
	s = input()
	if '1' in s:
		col = math.ceil(s.find('1') / 2) + 1
		print(abs(row - 3) + abs(col - 3))


o = 0
for i in range(5):
	n = input()
	if '1' in n:
		o = abs(i - 2) + abs(n.index('1') // 2 - 2)
print(o)


a = list(input().split())
b = list(input().split())
c = list(input().split())
d = list(input().split())
e = list(input().split())
if '1' in a:
	one = a.index('1')
	if one == 0 or one == 4:
		print('4')
	elif one == 1 or one == 3:
		print('3')
	else:
		print('2')
elif '1' in b:
	one = b.index('1')
	if one == 0 or one == 4:
		print('3')
	elif one == 1 or one == 3:
		print('2')
	else:
		print('1')
elif '1' in c:
	one = c.index('1')
	if one == 0 or one == 4:
		print('2')
	elif one == 1 or one == 3:
		print('1')
	else:
		print('0')
elif '1' in d:
	one = d.index('1')
	if one == 0 or one == 4:
		print('3')
	elif one == 1 or one == 3:
		print('2')
	else:
		print('1')
elif '1' in e:
	one = e.index('1')
	if one == 0 or one == 4:
		print('4')
	elif one == 1 or one == 3:
		print('3')
	else:
		print('2')


for i in range(1, 6):
	a = list(map(int, input().split()))
	if 1 in a:
		w = a.index(1) + 1
		break
e = abs(w - 3)
r = abs(i - 3)
n = e + r
print(n)


matrix = []
for i in range(5):
	row = input().split()
	ok = False
	for j in range(5):
		if row[j] == '1':
			ok = True
			print(abs(2 - i) + abs(2 - j))
			break
	if ok:
		break


matrix = []
for i in range(5):
	matrix.append([])
	matrix[i] = list(map(int, input().split()))
	if 1 in matrix[i]:
		indx = matrix[i].index(1)
		c = i
print(abs(indx - 2) + abs(c - 2))


def solve(matrix):
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				return abs(i - 2) + abs(j - 2)

def main():
	matrix = list()
	for _ in range(5):
		matrix.append(list(map(int, input().split())))
	print(solve(matrix))
main()


def fun(w):
	for i in range(5):
		try:
			r = li[i].index(1)
			print(abs(2 - i) + abs(2 - r))
		except:
			pass
li = list()
for i in range(5):
	li.append(list(map(lambda x: int(x), input().split())))
fun(li)


no_of_lines = 5
i_of_1 = 0
j_of_1 = 0
lines = ''
for i in range(no_of_lines):
	x = input()
	if '1' in x:
		i_of_1 = i
		j_of_1 = x.index('1')
	lines += x + '\n'
print(abs(i_of_1 - 2) + abs(int((j_of_1 - 4) / 2)))


i = 0
j = 0
for index in range(5):
	string = str(input())
	if '1' in string:
		i = string.replace(' ', '').index('1')
		j = index
if i >= 3:
	i = 4 - i
if j >= 3:
	j = 4 - j
print(2 - j + (2 - i))


arr = list()
for _ in range(5):
	n = list(map(int, input().split()))
	arr.append(n)
for row in range(5):
	for column in range(5):
		if arr[row][column] == 1:
			index = [row + 1, column + 1]
print(abs(3 - index[0]) + abs(3 - index[1]))


inp = []
for i in range(5):
	x = list(map(int, input().split()))
	inp.append(x)
for i in range(5):
	for j in range(5):
		if inp[i][j] == 1:
			(m, n) = tuple((i, j))
			break
ans = 0
for i in range(3):
	if m < 2:
		ans += 2 - m
		break
	elif m > 2:
		ans += m - 2
		break
	else:
		break
for k in range(3):
	if n < 2:
		ans += 2 - n
		break
	elif n > 2:
		ans += n - 2
		break
	else:
		break
print(ans)


a = []

def ret_pos(mylist, val_to_find, x, y):
	for i in range(x):
		for j in range(y):
			if mylist[i][j] == val_to_find:
				postn = [i, j]
	return postn
for i in range(5):
	a.append([int(x) for x in input().split()])
(x, r) = ret_pos(a, 1, 5, 5)
op = abs(2 - x) + abs(2 - r)
print(op)


i = 0
while i < 5:
	i = i + 1
	a = list(map(int, input().split()))
	try:
		if a.index(1) >= 0:
			index1 = a.index(1)
			movementHorizontal = abs(2 - index1)
			movementVertical = abs(3 - i)
			print(movementHorizontal + movementVertical)
	except:
		x = 1


i = 1
u = 1
s = 0
a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
r = 0
flag = False
for u in range(len(a)):
	for i in range(5):
		if (int(a[i]) == 1 and s == 0 or (int(b[i]) == 1 and s == 5) or (int(c[i]) == 1 and s == 10) or (int(d[i]) == 1 and s == 15) or (int(e[i]) == 1 and s == 20)) and flag == False:
			r = s + i + 1
			flag = True
	i = 0
	s += 5
if r == 2 or r == 4 or r == 6 or (r == 10) or (r == 16) or (r == 20) or (r == 22) or (r == 24):
	print(3)
elif r == 3 or r == 7 or r == 9 or (r == 11) or (r == 15) or (r == 17) or (r == 19) or (r == 23):
	print(2)
elif r == 1 or r == 5 or r == 21 or (r == 25):
	print(4)
elif r == 8 or r == 12 or r == 14 or (r == 18):
	print(1)
else:
	print(0)


def zxc(ls):
	x = 0
	while x < 5:
		if ls[x] == 1:
			return x + 1
		x = x + 1
for j in range(5):
	ls = list(map(int, input().split()))
	if 1 in ls:
		h = j + 1
		w = zxc(ls)
k = abs(3 - h) + abs(3 - w)
print(k)


m = 5
n = 5
myList = []
myList1 = []
for i in range(0, m):
	myList.append([])
for i in range(0, m):
	for j in range(0, n):
		myList[i].append(j)
		myList[i][j] = 0
for i in myList:
	i = list(map(int, input().split()))
	myList1.append(i)
tempList = []
for i in range(0, 5):
	for j in range(0, 5):
		if myList1[i][j] == 1:
			tempList.append(i)
			tempList.append(j)
r = 2 - tempList[0]
r = abs(r)
c = 2 - tempList[1]
c = abs(c)
print(r + c)


i = 0
flag = True
while True:
	try:
		x = input().split()
		j = 0
		for a in x:
			if a == '1':
				flag = False
				break
			j += 1
		if not flag:
			break
		i += 1
	except:
		break
print(abs(i - 2) + abs(j - 2))


matrix = []
column = 0
row = 0
for i in range(5):
	list = [int(i) for i in input().split()]
	if 1 in list:
		row = i
		column = list.index(1)
	matrix.append(list)
print(abs(row - 2) + abs(column - 2))


from sys import stdin
n1 = [int(y) for y in stdin.readline().split()]
n2 = [int(y) for y in stdin.readline().split()]
n3 = [int(y) for y in stdin.readline().split()]
n4 = [int(y) for y in stdin.readline().split()]
n5 = [int(y) for y in stdin.readline().split()]
row = 0
pos = 0
for (i, x) in enumerate(n1):
	if x == 1:
		row = 1
		pos = i
for (i, x) in enumerate(n2):
	if x == 1:
		row = 2
		pos = i
for (i, x) in enumerate(n3):
	if x == 1:
		row = 3
		pos = i
for (i, x) in enumerate(n4):
	if x == 1:
		row = 4
		pos = i
for (i, x) in enumerate(n5):
	if x == 1:
		row = 5
		pos = i
print(abs(row - 3) + abs(pos - 2))


import sys
values = list(map(int, input().split(' ')))
t = 1
for k in values:
	if k == 1:
		print(2 + abs(t - 3))
		sys.exit(0)
	t = t + 1
values = list(map(int, input().split(' ')))
t = 1
for k in values:
	if k == 1:
		print(1 + abs(t - 3))
		sys.exit(0)
	t = t + 1
values = list(map(int, input().split(' ')))
t = 1
for k in values:
	if k == 1:
		print(0 + abs(t - 3))
		sys.exit(0)
	t = t + 1
values = list(map(int, input().split(' ')))
t = 1
for k in values:
	if k == 1:
		print(1 + abs(t - 3))
		sys.exit(0)
	t = t + 1
values = list(map(int, input().split(' ')))
t = 1
for k in values:
	if k == 1:
		print(2 + abs(t - 3))
		sys.exit(0)
	t = t + 1


i = 0
for i in range(0, 5):
	a = list(map(int, input().split()))
	for b in range(0, 5):
		if a[b] == 1:
			c = abs(3 - (i + 1)) + abs(3 - (b + 1))
		b += 1
print(c)


for i in range(5):
	newl = [int(x) for x in input('').split()]
	if 1 in newl:
		row = abs(i + 1 - 3)
		column = abs(newl.index(1) + 1 - 3)
print(column + row)


matrix = [list(map(int, input().split())) for _ in range(5)]
index = (0, 0)
for i in range(5):
	try:
		index = (i, matrix[i].index(1))
	except ValueError:
		continue
result = abs(index[0] - 2) + abs(index[1] - 2)
print(result)


m = 0
n = 0
for i in range(5):
	eles = input().split()
	if '1' in eles:
		n = eles.index('1')
		m = i
		break
n += 1
m += 1
print(abs(m - 3) + abs(n - 3))


import math
i = 0
matrix = []
while i < 5:
	row = input()
	i += 1
	matrix.append(list(map(int, row.split())))
for i in range(5):
	for k in range(5):
		if matrix[i][k] == 1:
			ans = abs(i - 2) + abs(k - 2)
			print(ans)


list_ = []
for num in range(5):
	a = list(map(int, input().split()))
	list_.append(a)
for num in list_:
	for nu in num:
		if nu == 1:
			i = list_.index(num)
			j = num.index(nu)
if i >= 2 and j >= 2:
	print(i - 2 + (j - 2))
elif i >= 2 and j <= 2:
	print(i - 2 + (2 - j))
elif i <= 2 and j >= 2:
	print(2 - i + (j - 2))
elif i <= 2 and j <= 2:
	print(2 - i + (2 - j))


lst = list()
rowWithOne = -1
columnWithOne = -1
for i in range(5):
	rowStr = input()
	row = [int(ch) for ch in rowStr.split()]
	lst.append(row)
	if rowStr.find('1') != -1:
		for j in range(5):
			if row[j] == 1:
				rowWithOne = i
				columnWithOne = j
dist = abs(rowWithOne - 2) + abs(columnWithOne - 2)
print(dist)


val = 0
for i in range(5):
	n = list(map(int, input().split()))
	if 1 in n:
		val += abs(n.index(1) - 2)
		val += abs(i - 2)
print(val)


a = []
for i in range(5):
	a.append([])
	a[i] = [int(j) for j in input().split()]
	if 1 in a[i]:
		row = i
		col = a[i].index(1)
print(abs(1 + row - 3) + abs(1 + col - 3))


from sys import stdin, stdout
import math

def main():
	matrix = []
	for n in range(0, 5):
		matrix.append(list(map(int, stdin.readline().rstrip().split())))
	middlex = 2
	middley = 2
	myY = 0
	myX = 0
	for y in range(0, 5):
		for x in range(0, 5):
			if matrix[y][x] == 1:
				myX = x
				myY = y
	moves = abs(myX - middlex) + abs(myY - middley)
	stdout.write(str(moves) + '\n')
main()


a = []
k = r = 0
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			k = j
			r = i
print(abs(k + 1 - 3) + abs(r + 1 - 3))


(row, col) = (-1, -1)
for i in range(5):
	a = [el for el in map(int, input().split(' '))]
	if 1 in a:
		row = i
		col = a.index(1)
print(abs(row - 2) + abs(col - 2))


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()))
count = 0
if 1 in a:
	if a.index(1) == 0 or a.index(1) == 4:
		count += 4
	elif a.index(1) == 1 or a.index(1) == 3:
		count += 3
	else:
		count += 2
elif 1 in b:
	if b.index(1) == 0 or b.index(1) == 4:
		count += 3
	elif b.index(1) == 1 or b.index(1) == 3:
		count += 2
	else:
		count += 1
elif 1 in c:
	if c.index(1) == 0 or c.index(1) == 4:
		count += 2
	elif c.index(1) == 1 or c.index(1) == 3:
		count += 1
	else:
		count += 0
elif 1 in d:
	if d.index(1) == 0 or d.index(1) == 4:
		count += 3
	elif d.index(1) == 1 or d.index(1) == 3:
		count += 2
	else:
		count += 1
elif 1 in e:
	if e.index(1) == 0 or e.index(1) == 4:
		count += 4
	elif e.index(1) == 1 or e.index(1) == 3:
		count += 3
	else:
		count += 2
print(count)


c = 0
for i in range(5):
	exec('a%s=list(input().split())' % i)
for i in range(5):
	for o in range(5):
		exec('c=(a%s[o])' % i)
		if c == '1':
			print(abs(i - 2) + abs(o - 2))


matrix = []
tag = 0
for i in range(5):
	colume = input().split()
	matrix.append(colume)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			tag = 1
			print(abs(i - 2) + abs(j - 2))
			break
	if tag == 1:
		break


def get_one_index(row):
	counter = 0
	for item in row:
		if item == 1:
			return counter + 1
		else:
			counter += 1
col_no = 0
row_no = 0
for i in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		col_no = get_one_index(row)
		row_no = i + 1
		break
print(abs(3 - row_no) + abs(3 - col_no))


y = 1
x = 0
found = False
for u in range(5):
	i = input().split()
	for z in range(len(i)):
		if i[z] == '1':
			x = z + 1
			found = True
			break
	else:
		if not found:
			y += 1
r = abs(y - 3) + abs(x - 3)
print(r)


R = lambda : [*map(int, input().split())]
matrix = [R() for i in range(5)]
ans = 0
for i in range(5):
	if 1 in matrix[i]:
		y = i
		x = matrix[i].index(1)
while x != 2 or y != 2:
	if x < 2:
		ans += 1
		x += 1
	elif x > 2:
		x -= 1
		ans += 1
	if y < 2:
		ans += 1
		y += 1
	elif y > 2:
		y -= 1
		ans += 1
print(ans)


from sys import stdin

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

def solve(vs):
	for r in range(5):
		for c in range(5):
			if vs[r][c] == 1:
				return (r, c)
	return None

def run():
	m = []
	for _ in range(5):
		vs = readInts()
		m.append(list(vs))
	(r, c) = solve(m)
	print(abs(2 - r) + abs(2 - c))
run()


x = []
for i in range(5):
	x.append(list(map(int, input().split())))
(a, b) = (0, 0)
for i in range(5):
	for j in range(5):
		if x[i][j] == 1:
			a = i
			b = j
			break
print(max(2, a) - min(2, a) + (max(2, b) - min(2, b)))


for i in range(0, 5):
	n = list(input().strip().replace(' ', ''))
	for ni in n:
		if int(ni) == 1:
			r = n.index(ni) + 1
			c = i + 1
			break
r = abs(r - 3) + abs(c - 3)
print(r)


column = 0
row = 0
for i in range(1, 6):
	temp = input().split()
	if '1' in temp:
		column = temp.index('1') + 1
		row = i
shifts = 0
if column != 3:
	if column % 2 == 1:
		shifts += 2
	else:
		shifts += 1
if row != 3:
	if row % 2 == 1:
		shifts += 2
	else:
		shifts += 1
print(shifts)


import sys
for line_index in range(5):
	line = sys.stdin.readline().strip().split(' ')
	index = [i for (i, x) in enumerate(line) if x == '1']
	if index:
		print(abs(line_index - 2) + abs(index[0] - 2))
		exit()


for i in range(5):
	x = input().split()
	for j in range(5):
		if x[j] == '1':
			(a, b) = (i + 1, j + 1)
print(abs(3 - a) + abs(3 - b))


matrix = []
x = None
y = None
center_pos = [2, 2]
for i in range(0, 5):
	elements = input().split()
	row = list(map(int, elements))
	if 1 in row:
		x = i
		y = row.index(1)
	matrix.append(row)
stepsX = None
stepsY = None
if x > 2:
	stepsX = x - 2
else:
	stepsX = 2 - x
if y > 2:
	stepsY = y - 2
else:
	stepsY = 2 - y
print(stepsX + stepsY)


index = None
for y in range(5):
	row = input()
	if '1' in row:
		index = [y, row.find('1') / 2]
print(int(abs(index[0] - 2) + abs(index[1] - 2)))


lst = []
for i in range(5):
	lst.append(list(map(int, input().split())))
for i in range(5):
	if 1 in lst[i]:
		k = lst[i].index(1)
		break
a = 2 - i
b = 2 - k
if a < 0:
	a = a * -1
if b < 0:
	b = b * -1
print(a + b)


import sys
it = iter(sys.stdin.read().splitlines())
s = []
for i in range(5):
	row = next(it).split()
	if '1' in row:
		index = row.index('1')
		index2 = i
f = abs(index - 2) + abs(index2 - 2)
print(f)


l = [list(map(int, input().split())) for i in range(5)]
x = 0
y = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			(x, y) = (i + 1, j + 1)
			break
print(abs(3 - x) + abs(3 - y))


l = []
for i in range(5):
	l1 = list(map(int, input().split()))
	l.append(l1)
for j in range(5):
	for k in range(5):
		if l[j][k] == 1:
			(a, b) = (j, k)
			break
print(abs(a - 2) + abs(b - 2))


from sys import stdin, stdout

def sin():
	return stdin.readline().rstrip()

def listInput():
	return list(map(int, sin().split()))

def printBS(li):
	if not li:
		return
	for i in range(len(li) - 1):
		stdout.write('%d ' % li[i])
	stdout.write('%d\n' % li[-1])
li = []
for i in range(5):
	li.append(listInput())
(x, y) = (0, 0)
for i in range(5):
	for j in range(5):
		if li[i][j] == 1:
			(x, y) = (i, j)
print(abs(2 - x) + abs(2 - y))


n = 5
l = list()
while n:
	l.append(map(int, input().split()))
	n = n - 1
r = 1
s = 0
for i in l:
	c = 1
	for j in i:
		if j == 1:
			s = abs(r - 3) + abs(c - 3)
			print(s)
		c = c + 1
	r = r + 1


x_axis = 0
y_axis = 0
for i in range(5):
	line = [int(i) for i in input().split()]
	if 1 in line:
		y_axis = i
		x_axis = line.index(1)
print(abs(x_axis - 2) + abs(y_axis - 2))


arr = []
s = 0
for i in range(5):
	ar = input().split()
	if '1' in ar:
		col = ar.index('1')
		row = i
if col > 2:
	s = col - 2
elif col < 2:
	s = 2 - col
if row > 2:
	s += row - 2
elif row < 2:
	s += 2 - row
print(s)


matrix = [input().split() for i in range(5)]
moves = 0
for i in matrix:
	if '1' in i:
		moves += abs(matrix.index(i) + 1 - 3)
		moves += abs(i.index('1') + 1 - 3)
		break
print(moves)


matrix = []
y_pos = 0
x_pos = 0
for i in range(5):
	x = str(input())
	matrix.append(''.join(x.split()))
for y in matrix:
	if '1' in y:
		break
	else:
		y_pos += 1
x_pos = matrix[y_pos].find('1') + 1
y_pos = y_pos + 1
if x_pos > 3:
	x_dis = x_pos - 3
else:
	x_dis = 3 - x_pos
if y_pos > 3:
	y_dis = y_pos - 3
else:
	y_dis = 3 - y_pos
total = x_dis + y_dis
print(total)


row = 0
for row in range(5):
	row += 1
	(a1, a2, a3, a4, a5) = map(int, input().split())
	if a1 == 1:
		j = 1
		i = row
	elif a2 == 1:
		j = 2
		i = row
	elif a3 == 1:
		j = 3
		i = row
	elif a4 == 1:
		j = 4
		i = row
	elif a5 == 1:
		j = 5
		i = row
print(abs(3 - i) + abs(3 - j))


a = []
for i in range(5):
	a.append(input().split())
for i in range(5):
	f = 0
	for j in range(5):
		if a[i][j] == '1':
			f = 1
			break
	if f == 1:
		break
print(abs(i - 2) + abs(j - 2))


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
row = -1
col = -1
flag = False
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			row = i
			col = j
			flag = True
			break
	if flag:
		break
ans = abs(row - 2) + abs(col - 2)
print(ans)


a = []
y = 0

def modul(x):
	if x < 0:
		x *= -1
	return x
for i in range(5):
	a.append([int(j) for j in input().split()])
for i in a:
	y += 1
	x = 0
	for j in i:
		x += 1
		if j == 1:
			print(modul(y - 3) + modul(x - 3))
			break


def locate_one(matrix):
	for i in range(5):
		for k in range(5):
			if matrix[i][k] == '1':
				return (i + 1, k + 1)
adj_matrix = []
for i in range(5):
	adj_matrix.append(input().strip().split(' '))
(i, k) = locate_one(adj_matrix)
row_Moves = abs(int(i) - 3)
col_Moves = abs(int(k) - 3)
print(row_Moves + col_Moves)


for i in range(5):
	a = [int(j) for j in input().split()]
	for j in range(5):
		if a[j] == 1:
			t = abs(2 - i) + abs(2 - j)
			break
print(t)


list0 = []
list1 = []
list2 = []
list3 = []
list4 = []
x = input().split()
list0 = list(x)
x = input().split()
list1 = list(x)
x = input().split()
list2 = list(x)
x = input().split()
list3 = list(x)
x = input().split()
list4 = list(x)
list5 = [list0, list1, list2, list3, list4]
for i in range(5):
	for j in range(5):
		if int(list5[i][j]) == 1:
			if i > 2:
				a = i - 2
			else:
				a = 2 - i
			if j > 2:
				b = j - 2
			else:
				b = 2 - j
			print(a + b)
			break


x = 0
y = 0
for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			x = i + 1
			y = j + 1
if y >= 3:
	ans = y - 3
else:
	ans = 3 - y
if x >= 3:
	ans += x - 3
else:
	ans += 3 - x
print(ans)


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
d = 0
for i in arr:
	if 1 in i:
		c = i.index(1)
		break
	d += 1
k = abs(d + 1 - 3) + abs(c + 1 - 3)
print(k)


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().rstrip().split())))
for m in range(5):
	if 1 in matrix[m]:
		col = matrix[m].index(1)
		row = m
moves_col = abs(col - 2)
moves_row = abs(row - 2)
print(moves_row + moves_col)


mat = []
arr = []
for _ in range(5):
	arr = list(map(int, input().split()))
	mat.append(arr)
c = -1
r = -1
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			c = j
			r = i
			break
if c > 2:
	c = c - 2
else:
	c = 2 - c
if r > 2:
	r = r - 2
else:
	r = 2 - r
print(str(r + c))


matriz = []
for i in range(0, 5):
	matriz.append(input().split())
i = 0
salir = False
for linea in matriz:
	j = 0
	for numero in linea:
		if numero == '1':
			salir = True
			break
		j = j + 1
	if salir:
		break
	i = i + 1
numero_saltos = abs(2 - i)
numero_saltos += abs(2 - j)
print(numero_saltos)


s = [input().split() for i in range(5)]
for i in range(5):
	for j in range(5):
		if s[i][j] == '0':
			continue
		else:
			print(abs(2 - i) + abs(2 - j))
			break


r = list()
for i in range(5):
	n = list(map(int, input().split()))
	r.append(n)
x = 0
y = 0
for i in range(5):
	for j in range(5):
		if r[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
	pass


matrix = []
f = 1
for i in range(5):
	a = list(input().split())
	matrix.append(a)
	if f:
		for j in range(5):
			if a[j] == '1':
				c = j
				r = i
				f = 0
				break
print(abs(2 - c) + abs(2 - r))


ans = 0
for i in range(5):
	arr = [int(x) for x in input('').split()]
	if 1 in arr:
		index = arr.index(1)
		ans = abs(i - 2) + abs(index - 2)
print(ans)


matrix = [[int(x) for x in input().split()] for i in range(5)]
moves = 0
for i in range(5):
	for n in range(5):
		if matrix[i][n] == 1:
			if i != n:
				moves = abs(i - 2) + abs(n - 2)
			elif i == n:
				if n == 2:
					moves = 0
				elif i == n:
					moves = abs(i - 2) + abs(n - 2)
print(moves)


mat = []
mid = (2, 2)
for _ in range(5):
	mat.append([int(__) for __ in input().strip().split()])
given = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			given = (i, j)
			break
print(abs(mid[0] - given[0]) + abs(mid[1] - given[1]))


import sys
for i in range(1, 6):
	line = sys.stdin.readline().strip('\n').split(' ')
	if '1' in line:
		index = line.index('1')
		final_target = abs(i - 3) + abs(index + 1 - 3)
		print(final_target)
		break


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

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

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

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
m = []
for i in range(5):
	arr = LIST()
	if 1 in arr:
		x = i
		y = arr.index(1)
print(abs(x + 1 - 3) + abs(y - 3 + 1))


rows = 5
position = [0, 0]
for i in range(0, rows):
	cols = input().split(' ')
	if '1' in cols:
		position = [i, cols.index('1')]
if position == [2, 2]:
	print(0)
elif position == [1, 2] or position == [3, 2] or position == [2, 1] or (position == [2, 3]):
	print(1)
elif position == [1, 1] or position == [1, 3] or position == [3, 1] or (position == [3, 3]) or (position == [0, 2]) or (position == [4, 2]) or (position == [2, 0]) or (position == [2, 4]):
	print(2)
elif position == [0, 0] or position == [4, 4] or position == [0, 4] or (position == [4, 0]):
	print(4)
else:
	print(3)


x = 0
y = 0
for i in range(5):
	sp2 = list(map(int, input().split()))
	for j in range(len(sp2)):
		if sp2[j] == 1:
			x = i
			y = j
			break
print(abs(2 - x) + abs(2 - y))


a = []
for i in range(5):
	a.append(list(map(int, input().strip().split()))[:5])
for j in range(5):
	if 1 in a[j]:
		for k in range(5):
			if a[j][k] == 1:
				c = abs(j + 1 - 3) + abs(k + 1 - 3)
				break
		break
print(c)


ans = []
for i in range(5):
	n = input().split()
	if '1' in n:
		k = n.index('1')
		r = i
	ans.append(n)
print(abs(2 - k) + abs(2 - r))


arr = []
for i in range(5):
	t = [int(x) for x in input().strip().split()]
	arr.append(t)
f = False
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			ind1 = i
			ind2 = j
			f = True
			break
	if f:
		break
moves = abs(ind1 - 2)
moves += abs(ind2 - 2)
print(moves)


a = []
b = []
m = 0
n = 0
for i in range(1, 6):
	inp = input()
	for j in inp.split(' '):
		b.append(j)
	a.append(b)
	b = []
for k in range(0, 5):
	for l in range(0, 5):
		if a[k][l] == '1':
			m = k - 2
			if m < 0:
				m = -m
			n = l - 2
			if n < 0:
				n = -n
			break
print(m + n)


n = 0
while n <= 4:
	a = [x for x in input().split()]
	for m in range(len(a)):
		if a[m] == '1':
			i = n
			j = m
	n = n + 1
o = abs(i - 2) + abs(j - 2)
print(o)


def main():
	lines = 0
	matrix = []
	target_index = 2
	while lines < 5:
		matrix.append(input().split(' '))
		lines += 1
	line = 0
	while line < len(matrix):
		if '1' in matrix[line]:
			break
		line += 1
	moves = abs(line - target_index)
	pos = 0
	while pos < len(matrix[line]):
		if matrix[line][pos] == '1':
			moves += abs(pos - target_index)
			break
		pos += 1
	print(moves)
main()


s = [[i for i in input().split()] for x in range(5)]
sum = 0
for i in range(1, 6):
	for j in range(1, 6):
		if s[i - 1][j - 1] == '1':
			sum = abs(i - 3) + abs(j - 3)
			break
print(sum)


l = []
for i in range(5):
	x = input().split()
	l.append(list(x))
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			r = i
			c = j
p = abs(r - 2) + abs(c - 2)
print(p)


for i in range(5):
	row = input().split()
	if '1' in row:
		x = i + 1
		y = row.index('1') + 1
		break
move = abs(x - 3) + abs(y - 3)
print(move)


a = []
x = 0
y = 0
x1 = 2
y1 = 2
for i in range(5):
	a.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i
			y = j
			break
if x1 - x < 0:
	x = (x1 - x) * -1
else:
	x = x1 - x
if y1 - y < 0:
	y = (y1 - y) * -1
else:
	y = y1 - y
print(x + y)


M = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if M[i][j] == 1:
			r = i
			S = j
print(abs(2 - r) + abs(2 - S))


for i in range(5):
	a = input()
	if '1' in a:
		(x, y) = (i + 1, a.split().index('1') + 1)
print(abs(3 - x) % 6 + abs(3 - y % 6))


l = []
for i in range(0, 5):
	a = []
	s = input()
	a = list(s.split(' '))
	l.append(a)
for i in range(0, 5):
	for j in range(0, 5):
		if l[i][j] == '1':
			x = i
			y = j
count = 0
for a in range(0, 5):
	if x == 2:
		break
	elif x > 2:
		x = x - 1
	elif x < 2:
		x = x + 1
	count = count + 1
for b in range(0, 5):
	if y == 2:
		break
	elif y > 2:
		y = y - 1
	elif y < 2:
		y = y + 1
	count = count + 1
print(count)


Spalte = 0
Zeile = 0
Spalte2 = 0
Zeile2 = 0
for i in range(5):
	Spalte = 0
	Zeile += 1
	inp = str(input()).replace(' ', '')
	for j in range(5):
		Spalte += 1
		if inp[j] == '1':
			Spalte2 = Spalte
			Zeile2 = Zeile
print(abs(Spalte2 - 3) + abs(Zeile2 - 3))


a = []
y = 0
for i in range(0, 5):
	y += 1
	a = list(map(int, str(input()).split()))
	if 1 in a:
		x = a.index(1) + 1
		print(abs(x - 3) + abs(y - 3))
		break


done = False
row = -1
while not done:
	row += 1
	col = 0
	for ch in input():
		if ch == ' ':
			col += 1
		if ch == '1':
			done = True
			break
print(abs(row - 2) + abs(col - 2))


def main():
	res = 0
	matrix = []
	for i in range(0, 5):
		entries = list(map(int, input().split()))
		matrix.append(entries)
	target_row = -1
	target_col = -1
	for i in range(0, 5):
		if 1 in matrix[i]:
			target_row = i
			target_col = matrix[i].index(1)
	target_row = abs(2 - target_row)
	target_col = abs(2 - target_col)
	res = target_col + target_row
	print(res)
main()


def td_list():
	n = 0
	list1 = list()
	while n < 5:
		a = input()
		list1.extend(a.split(' '))
		n += 1
	else:
		return list1
lit1 = td_list()
a = lit1.index('1')
if a == 12:
	print('0')
elif a == 0 or a == 4 or a == 20 or (a == 24):
	print('4')
elif a == 7 or a == 11 or a == 13 or (a == 17):
	print('1')
elif a == 1 or a == 3 or a == 5 or (a == 9) or (a == 15) or (a == 19) or (a == 21) or (a == 23):
	print('3')
else:
	print('2')


grid = []
for i in range(5):
	rows = [int(j) for j in input().split()]
	grid.append(rows)
	if 1 in rows:
		y_axis = i
		x_axis = rows.index(1)
print(abs(2 - y_axis) + abs(2 - x_axis))


for i in range(5):
	r = input().split()
	for l in range(5):
		if r[l] == '1':
			n = abs(l - 2) + abs(i - 2)
print(n)


r1 = input().split()
r2 = input().split()
r3 = input().split()
r4 = input().split()
r5 = input().split()
n = 0
for i in r1:
	n += 1
	if int(i) == 1:
		i = 1
		j = n
		print(abs(i - 3) + abs(j - 3))
		exit(0)
n = 0
for i in r2:
	n += 1
	if int(i) == 1:
		i = 2
		j = n
		print(abs(i - 3) + abs(j - 3))
		exit(0)
n = 0
for i in r3:
	n += 1
	if int(i) == 1:
		i = 3
		j = n
		print(abs(i - 3) + abs(j - 3))
		exit(0)
n = 0
for i in r4:
	n += 1
	if int(i) == 1:
		i = 4
		j = n
		print(abs(i - 3) + abs(j - 3))
		exit(0)
n = 0
for i in r5:
	n += 1
	if int(i) == 1:
		i = 5
		j = n
		print(abs(i - 3) + abs(j - 3))
		exit(0)


l = []
while not l or len(l) < len(l[0]):
	l.append(list(map(int, input().split())))
for i in range(len(l)):
	for j in range(len(l[i])):
		if l[i][j] == 1:
			k = i + 1
			o = j + 1
			break
print(abs(3 - k) + abs(3 - o))


res = 0
for row in range(1, 6):
	line = input().split()
	try:
		col = line.index('1') + 1
		res = abs(col - 3) + abs(row - 3)
	except ValueError:
		pass
print(res)


x = 0
y = 0
j = 0
for m in range(5):
	n = input().split()
	if '1' in n:
		x = m
		for s in range(5):
			if n[s] == '1':
				y = s
if x <= 2:
	j = j + 2 - x
else:
	j = j + x - 2
if y <= 2:
	j = j + 2 - y
else:
	j = j + y - 2
print(j)


ar = []
for i in range(5):
	a = list(map(int, input().split()))
	ar.append(a)
(left, right) = (0, 0)
for i in range(5):
	for j in range(5):
		if ar[i][j] == 1:
			left = i + 1
			right = j + 1
			break
left = left - 3
left = left if left >= 0 else left * -1
right = right - 3
right = right if right >= 0 else right * -1
print(left + right)


a = []
for i in range(5):
	k = list(map(int, input().split(' ')))
	if 1 in k:
		x = i
		y = k.index(1)
		p = abs(2 - x) + abs(2 - y)
		print(p)
		break


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
kolona = 0
red = 0
if 1 in l1:
	kolona = 1
	for i in range(5):
		if l1[i] == 1:
			red = i + 1
			break
elif 1 in l2:
	kolona = 2
	for i in range(5):
		if l2[i] == 1:
			red = i + 1
			break
elif 1 in l3:
	kolona = 3
	for i in range(5):
		if l3[i] == 1:
			red = i + 1
			break
elif 1 in l4:
	kolona = 4
	for i in range(5):
		if l4[i] == 1:
			red = i + 1
			break
else:
	kolona = 5
	for i in range(5):
		if l5[i] == 1:
			red = i + 1
			break
print(abs(3 - kolona) + abs(3 - red))


import math
s = ''
for x in range(0, 5):
	s = s + input().replace(' ', '')
p = int(math.log10(int(s)))
print(abs(p // 5 - 2) + abs(p % 5 - 2))


a = []
for i in range(0, 5):
	a.append([int(x) for x in input().split()])
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == 1:
			print(0 if i == 2 and j == 2 else abs(2 - i) + abs(2 - j))
			break


tmp = []
cmp = [0] * 5
(x, y) = (0, 0)
from math import fabs
for i in range(5):
	tmp = list(map(int, input().split()))
	if tmp != cmp:
		for j in range(5):
			if tmp[j] != cmp[j]:
				(x, y) = (i, j)

def minOperation(x, y):
	return int(fabs(x - 2) + fabs(y - 2))
print(minOperation(x, y))


y = 5
sum = 0
while y:
	n = input()
	x = int(n.find('1') / 2) + 1
	if n.count('1'):
		sum = abs(y - 3) + abs(x - 3)
	y -= 1
print(sum)


for i in range(5):
	colomn = input().split()
	for j in range(5):
		if colomn[j] == '1':
			move = abs(i - 2) + abs(j - 2)
			print(move)


one_coord = -1
for i in range(5):
	row = [j for j in input().split()]
	if '1' in row:
		one_coord = (i, row.index('1'))
print(abs(one_coord[0] - 2) + abs(one_coord[1] - 2))


A = [None] * 5

def VA(x):
	if x < 0:
		return x * -1
	elif x > 0:
		return x
	else:
		return 0
for i in range(5):
	A[i] = input()
	A[i] = A[i].split()
for i in range(5):
	for j in range(5):
		if A[i][j] == str(1):
			f = i
			c = j
F = f - 2
F = VA(F)
C = c - 2
C = VA(C)
print(F + C)


t = 0
for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		t += abs(2 - l.index(1)) + abs(i - 2)
print(t)


for i in range(5):
	row = input().split()
	if '1' in row:
		loc = [i + 1, row.index('1') + 1]
print(abs(loc[0] - 3) + abs(loc[1] - 3))


line = ''
done = False
for i in range(5):
	if done == True:
		break
	line = input().split()
	for j in range(len(line)):
		if line[j] == '1':
			if i == 2 and j == 2:
				print(0)
			else:
				print(abs(i - 2) + abs(j - 2))
			done = True
			break


import sys

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

def get():
	return int(sys.stdin.readline().strip())

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

def getli():
	return list(map(int, sys.stdin.readline().strip().split()))
A = []
(r, c) = (0, 0)
for i in range(5):
	a = getli()
	for j in range(5):
		if a[j]:
			r = i
			c = j
print(abs(r - 2) + abs(c - 2))


n = 5
krok = 0
jeden = 0
while True:
	var = [int(x) for x in input().split(' ')]
	if 1 in var:
		jeden = var.index(1)
		break
	krok += 1
print(abs(krok - 2) + abs(jeden - 2))


def main():
	for i in range(5):
		row = input().split()
		if '1' in row:
			print(abs(row.index('1') - 2) + abs(i - 2))
			exit()
main()


I = 0
J = 0
for k in range(5):
	T = input('')
	if '1' in T:
		T = T.split(' ')
		I = T.index('1')
		J = k
J += 1
I += 1
mov = abs(3 - J) + abs(3 - I)
print(mov)


a = []
for i in range(1, 6):
	a.append(input().split())
for i in range(1, 6):
	for j in range(1, 6):
		if int(a[i - 1][j - 1]) == 1:
			print(abs(3 - i) + abs(3 - j))


a = []
for i in range(5):
	a.append(input().split())
for i in range(5):
	try:
		jth = a[i].index('1') + 1
		ith = i + 1
		break
	except:
		...
print(abs(ith - 3) + abs(jth - 3))


(a1, b1, c1, d1, e1) = input('').split()
(a2, b2, c2, d2, e2) = input('').split()
(a3, b3, c3, d3, e3) = input('').split()
(a4, b4, c4, d4, e4) = input('').split()
(a5, b5, c5, d5, e5) = input('').split()
l1 = []
l2 = []
l3 = []
l4 = []
l5 = []
l1.extend([a1, b1, c1, d1, e1])
l2.extend([a2, b2, c2, d2, e2])
l3.extend([a3, b3, c3, d3, e3])
l4.extend([a4, b4, c4, d4, e4])
l5.extend([a5, b5, c5, d5, e5])
l6 = [a1, a2, a3, a4, a5]
l7 = [b1, b2, b3, b4, b5]
l8 = [c1, c2, c3, c4, c5]
l9 = [d1, d2, d3, d4, d5]
l10 = [e1, e2, e3, e4, e5]
index1 = []
if '1' in l1:
	index1.append(l1.index('1'))
elif '1' in l2:
	index1.append(l2.index('1'))
elif '1' in l3:
	index1.append(l3.index('1'))
elif '1' in l4:
	index1.append(l4.index('1'))
elif '1' in l5:
	index1.append(l5.index('1'))
if '1' in l6:
	index1.append(l6.index('1'))
elif '1' in l7:
	index1.append(l7.index('1'))
elif '1' in l8:
	index1.append(l8.index('1'))
elif '1' in l9:
	index1.append(l9.index('1'))
elif '1' in l10:
	index1.append(l10.index('1'))
pos = []
for i in index1:
	pos.append(abs(2 - i))
print(sum(pos))


l = []
for i in range(5):
	l2 = [int(x) for x in input().split()]
	l.append(l2)
for i in l:
	if 1 in i:
		m = l.index(i)
		n = i.index(1)
		break
c = abs(m - 2) + abs(n - 2)
print(c)


a = []
z = 0
v = 0
for k in range(5):
	a.append(list(map(int, input().split())))
for i in a:
	for j in i:
		if j == 1:
			z = a.index(i) + 1
			v = i.index(j) + 1
print(abs(3 - z) + abs(3 - v))


(r, c) = (0, 0)
for i in range(1, 6):
	matrix = input()
	if '1' in matrix:
		r = i
		c = matrix.split().index('1')
r = abs(3 - r)
c = abs(2 - c)
print(r + c)


for i in range(5):
	line = [int(val) for val in input().split(' ')]
	if 1 in line:
		print(abs(2 - i) + abs(2 - line.index(1)))
		break


m_a = input().split()
m_b = input().split()
m_c = input().split()
m_d = input().split()
m_e = input().split()
num_matrix = [m_a, m_b, m_c, m_d, m_e]
for i in range(0, 5):
	if '1' in num_matrix[i]:
		a = i
		b = num_matrix[i].index('1')
		break
disa = abs(a - 2)
disb = abs(b - 2)
dis = disa + disb
print(dis)


first_line = input().split()
second_line = input().split()
third_line = input().split()
fourth_line = input().split()
fifth_line = input().split()
main_row = 3
main_column = 2
row_with_one = 0
column_with_one = 0
one = '1'
result = 0
for i in range(len(first_line)):
	if first_line[i] == one:
		row_with_one = 1
		column_with_one = i
for i in range(len(second_line)):
	if second_line[i] == one:
		row_with_one = 2
		column_with_one = i
for i in range(len(third_line)):
	if third_line[i] == one:
		row_with_one = 3
		column_with_one = i
for i in range(len(fourth_line)):
	if fourth_line[i] == one:
		row_with_one = 4
		column_with_one = i
for i in range(len(fifth_line)):
	if fifth_line[i] == one:
		row_with_one = 5
		column_with_one = i
if row_with_one < 3:
	result = main_row - row_with_one
elif row_with_one > 3:
	result = row_with_one - main_row
elif row_with_one == 3:
	result = 0
if column_with_one < 2:
	result = result + (main_column - column_with_one)
elif column_with_one > 2:
	result = result + (column_with_one - main_column)
elif column_with_one == 2:
	result = result + 0
print(result)


l1 = list()
l2 = list()
l3 = list()
l4 = list()
l5 = list()
for t in range(5):
	(a, y, z, u, v) = [int(k) for k in input().split()]
	l1.append(a)
	l2.append(y)
	l3.append(z)
	l4.append(u)
	l5.append(v)
if (l1[0] == l1[4] == l5[0] == l5[4]) == 0:
	print(4)
elif (l1[1] == l1[3] == l2[0] == l2[4] == l4[0] == l4[4] == l5[1] == l5[3]) == 0:
	print(3)
elif (l1[2] == l5[2] == l2[1] == l2[3] == l3[0] == l3[4] == l4[1] == l4[3]) == 0:
	print(2)
elif (l2[2] == l4[2] == l3[1] == l3[3]) == 0:
	print(1)
else:
	print(0)


(m, n) = (0, 0)
for i in range(5):
	string = input().split()
	if string.count('1'):
		m = i
		n = string.index('1')
print(abs(2 - n) + abs(2 - m))


matrix = [[int(x) for x in input().strip().split()] for _ in range(5)]
row = col = 0
for (i, r) in enumerate(matrix):
	if 1 in r:
		(row, col) = (i, r.index(1))
		break
print(abs(row - 2) + abs(col - 2))


for i in range(5):
	l = [int(x) for x in input().split()]
	if 1 in l:
		print(abs(2 - i) + abs(2 - l.index(1)))
		break


i = 0
mat = []
while i < 5:
	now = [int(x) for x in input().split()]
	mat.append(now)
	i += 1
(a, count) = (0, 0)
for row in mat:
	if 1 not in row:
		a += 1
		del row
	else:
		index = row.index(1)
		count += abs(2 - index)
		count += abs(2 - a)
		break
print(count)


a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a4 = list(map(int, input().split()))
a5 = list(map(int, input().split()))
count = 0
if 1 in a1:
	count = 2
	c = abs(a1.index(1) - 2)
	print(count + c)
elif 1 in a2:
	count = 1
	c = abs(a2.index(1) - 2)
	print(count + c)
elif 1 in a3:
	count = 0
	c = abs(a3.index(1) - 2)
	print(count + c)
elif 1 in a4:
	count = 1
	c = abs(a4.index(1) - 2)
	print(count + c)
elif 1 in a5:
	count = 2
	c = abs(a5.index(1) - 2)
	print(count + c)


matrix = []
(r, c) = (0, 0)
for i in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		r = i
	matrix.append(row)
for i in range(5):
	if matrix[r][i] == 1:
		c = i
		break
rr = abs(r - 2)
cc = abs(c - 2)
print(rr + cc)


for r in range(5):
	new = input().split()
	if '1' in new:
		col = new.index('1')
		row = r
print(abs(2 - row) + abs(2 - col))


for r in range(0, 5):
	k = 0
	for y in input().split():
		x = int(y)
		if x == 1:
			print(abs(k - 2) + abs(r - 2))
		k = k + 1


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))
t = 0
if 1 in r1 or 1 in r5:
	t += 2
	if 1 in r1:
		t += abs(r1.index(1) - 2)
	else:
		t += abs(r5.index(1) - 2)
if 1 in r2 or 1 in r4:
	t += 1
	if 1 in r2:
		t += abs(r2.index(1) - 2)
	else:
		t += abs(r4.index(1) - 2)
if 1 in r3:
	t += abs(r3.index(1) - 2)
print(t)


l = list()
for i in range(5):
	l.append(list(map(int, input().split())))
	if 1 in l[i]:
		g = l[i].index(1)
		r = i
print(abs(g + 1 - 3) + abs(r + 1 - 3))


count = 0
rows = 0
for i in range(5):
	qwerty = input().replace(' ', '')
	if qwerty.count('1') > 0:
		count = i + 1
		rows = qwerty.index('1') + 1
print(abs(count - 3) + abs(rows - 3))


v = [[abs(2 - i) + abs(2 - j) for (j, x) in enumerate(input().split()) if x == '1'] for i in range(5)]
print(*[x[0] for x in v if len(x)])


def main():
	move_number_map = {0: {0: 4, 1: 3, 2: 2, 3: 3, 4: 4}, 1: {0: 3, 1: 2, 2: 1, 3: 2, 4: 3}, 2: {0: 2, 1: 1, 2: 0, 3: 1, 4: 2}, 3: {0: 3, 1: 2, 2: 1, 3: 2, 4: 3}, 4: {0: 4, 1: 3, 2: 2, 3: 3, 4: 4}}
	for i in range(5):
		row = input().split()
		try:
			j = row.index('1')
			print(move_number_map[i][j])
			break
		except ValueError:
			continue
main()


counter = 0
matrix = []
while counter < 5:
	string = input().split()
	matrix.append(string)
	if string.__contains__('1'):
		(x, y) = (string.index('1') + 1, counter + 1)
	counter += 1
print(abs(3 - x) + abs(3 - y))


a = []
s = 0
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			if i + 1 >= 3:
				s = i + 1 - 3
			else:
				s = 3 - (i + 1)
			if j + 1 >= 3:
				s = s + (j + 1 - 3)
			else:
				s = s + (3 - (j + 1))
print(s)


res = 0
for r in range(5):
	s = input().split()
	for column in range(5):
		if s[column] == '1':
			res = abs(r - 2) + abs(column - 2)
print(res)


matrix = []
for _ in range(5):
	matrix.append(input().split(' '))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			moves = abs(2 - i) + abs(2 - j)
			print(moves)
			break


def solve(matrix):
	i = r = c = 0
	isOneFound = False
	while i < 5 and (not isOneFound):
		j = 0
		while j < 5 and (not isOneFound):
			if matrix[i][j] == '1':
				c = i
				r = j
				isOneFound = False
			j += 1
		i += 1
	return abs(c - 2) + abs(r - 2)
matrix = list()
for _ in range(0, 5):
	matrix.append(input().split(' '))
print(solve(matrix))


a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a4 = list(map(int, input().split()))
a5 = list(map(int, input().split()))
r = 0
c = 0
f = False
for i in range(5):
	if a1[i] == 1:
		f = True
		r = 1
		c = i + 1
if not f:
	for i in range(5):
		if a2[i] == 1:
			f = True
			r = 2
			c = i + 1
if not f:
	for i in range(5):
		if a3[i] == 1:
			f = True
			r = 3
			c = i + 1
if not f:
	for i in range(5):
		if a4[i] == 1:
			f = True
			r = 4
			c = i + 1
if not f:
	for i in range(5):
		if a5[i] == 1:
			f = True
			r = 5
			c = i + 1
r1 = abs(3 - r)
c1 = abs(3 - c)
print(r1 + c1)


lst = []
for k in range(5):
	x = list(map(int, input().strip().split()))
	lst.append(x)
for i in range(5):
	for j in range(5):
		if lst[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


k = [0, 1, 2, 3, 4]
s = 0
t = 0
for i in k:
	vec = [int(x) for x in input().split(' ')]
	for j in k:
		if vec[j] == 1:
			s = i
			t = j
total_movements = abs(s - 2) + abs(t - 2)
print(total_movements)


n = 1
while n != 6:
	a = input().split()
	a = [int(i) for i in a]
	if 1 in a:
		l = a.index(1) + 1
		k = n
		break
	n += 1
print(abs(k - 3) + abs(l - 3))


for i in range(1, 6):
	m = list(map(int, input().rstrip().split()))[:5]
	if 1 in m:
		(a, b) = (i, m.index(1) + 1)
c = abs(a - 3) + abs(b - 3)
print(c)


for row in range(5):
	column = input().split()
	for num in range(5):
		if column[num] == '1':
			print(abs(row - 2) + abs(num - 2))


mass = []
for i in range(5):
	mass.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if mass[i][j] == 1:
			stroka = i
			stolb = j
print(abs(2 - stroka) + abs(2 - stolb))


ii = 0
while True:
	row = [int(item) for item in input().split(' ')]
	n = len(row)
	mid = (n - 1) / 2
	if 1 in row:
		print(int(abs(mid - row.index(1)) + abs(mid - ii)))
		break
	ii += 1


l = []
for i in range(5):
	l.append(list(map(int, input().split())))
p = 0
k = 0
m = 0
for i in range(5):
	p = sum(l[i])
	if p == 1:
		k = i
		for j in range(5):
			if l[i][j] == 1:
				m = j
				break
		break
print(abs(k - 2) + abs(m - 2))


n = [input().split() for i in range(5)]
b = 0
c = 0
while '1' not in n[b]:
	b += 1
while n[b][c] != '1':
	c += 1
print(abs(b - 2) + abs(c - 2))


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

def index_2d(myList, v):
	for (i, x) in enumerate(myList):
		if v in x:
			return (i + 1, x.index(v) + 1)
one_index = index_2d(matrix, 1)
res = tuple(map(operator.sub, centre, one_index))
res = list(map(abs, res))
print(sum(res))


import sys
import math as mt
t = 1

def dfs(i, j, m, n, arr, d, k):
	if i < n and i >= 0 and (j < m) and (j >= 0):
		if arr[i][j] != 0 or d[i][j] == '.':
			return
		else:
			arr[i][j] = k
			dfs(i + 1, j, m, n, arr, d, k)
			dfs(i, j + 1, m, n, arr, d, k)
			dfs(i - 1, j, m, n, arr, d, k)
			dfs(i, j - 1, m, n, arr, d, k)
	else:
		return
for __ in range(t):
	(n, m) = (5, 5)
	d = {}
	j = 0
	for i in range(n):
		l = list(map(int, input().split()))
		for k in range(5):
			if l[k] == 1:
				ans = abs(2 - i) + abs(2 - k)
	print(ans)


def Sol(arr):
	found = False
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				found = True
				break
		if found:
			break
	moves = i - 2
	if moves < 0:
		moves = -moves
	if j - 2 >= 0:
		moves += j - 2
	else:
		moves += -(j - 2)
	print(moves)
	return
arr = []
for t in range(5):
	test = list(map(int, input().split()))
	arr.append(test)
Sol(arr)


done = False
for i in range(5):
	m = [int(x) for x in input().split()]
	for x in m:
		if x == 1:
			y = m.index(1)
			print(abs(i - 2) + abs(y - 2))
			done = True
			break
	if done == True:
		break


matrix_arr = []
for i in range(5):
	matrix_arr += str(input()).split()
pos = matrix_arr.index('1')
s = abs(pos % 5 - 2)
s += abs(pos // 5 - 2)
print(s)


l = []
for i in range(5):
	l.append(list(input().split()[:5]))
for i in range(len(l)):
	if '1' in l[i]:
		r = i
		for n in range(len(l[i])):
			if l[i][n] == '1':
				c = n
steps = 0
while r != 2:
	if r > 2:
		r -= 1
	elif r < 2:
		r += 1
	steps += 1
while c != 2:
	if c > 2:
		c -= 1
	elif c < 2:
		c += 1
	steps += 1
print(steps)


counter = 0
for i in range(5):
	row = input().split()
	if '1' in row:
		nRow = i
		theRow = row
for j in range(5):
	if theRow[j] == '1':
		nColumn = j
		break
if nRow == 0 or nRow == 4:
	counter += 2
elif nRow == 1 or nRow == 3:
	counter += 1
if nColumn == 0 or nColumn == 4:
	counter += 2
if nColumn == 1 or nColumn == 3:
	counter += 1
print(counter)


for i in range(5):
	row = input().split()
	c_value = 0
	ans = False
	for c in range(5):
		if row[c] == '1':
			c_value = c
			ans = True
			break
	if ans:
		print(abs(2 - c_value) + abs(2 - i))
		break


l1 = list(map(int, input().split(' ')))
l2 = list(map(int, input().split(' ')))
l3 = list(map(int, input().split(' ')))
l4 = list(map(int, input().split(' ')))
l5 = list(map(int, input().split(' ')))
i = 0
if 1 in l1:
	ind = l1.index(1)
	pos = (1, ind + 1)
elif 1 in l2:
	ind = l2.index(1)
	pos = (2, ind + 1)
elif 1 in l3:
	ind = l3.index(1)
	pos = (3, ind + 1)
elif 1 in l4:
	ind = l4.index(1)
	pos = (4, ind + 1)
elif 1 in l5:
	ind = l5.index(1)
	pos = (5, ind + 1)
ans = abs(pos[0] - 3) + abs(pos[1] - 3)
print(ans)


import sys
for i in range(5):
	(a, b, c, d, e) = map(int, sys.stdin.readline().split())
	if a == 1 or e == 1:
		print(2 + abs(2 - i))
		break
	elif b == 1 or d == 1:
		print(1 + abs(2 - i))
		break
	elif c == 1:
		print(abs(2 - i))
		break


mylist = []
for i in range(5):
	mylist.append(list(map(int, input().split())))
for x in range(5):
	for y in range(5):
		if mylist[x][y] == 1:
			r = x
			c = y
count = 0
if r == 2 and c == 2:
	print(count)
	exit()
if r < 2:
	while r != 2:
		temp = mylist[r][c]
		mylist[r][c] = mylist[r + 1][c]
		mylist[r + 1][c] = temp
		r += 1
		count += 1
else:
	while r != 2:
		temp = mylist[r][c]
		mylist[r][c] = mylist[r - 1][c]
		mylist[r - 1][c] = temp
		r -= 1
		count += 1
if c < 2:
	while c != 2:
		temp = mylist[r][c]
		mylist[r][c] = mylist[r][c + 1]
		mylist[r][c + 1] = temp
		c += 1
		count += 1
else:
	while c != 2:
		temp = mylist[r][c]
		mylist[r][c] = mylist[r][c - 1]
		mylist[r][c - 1] = temp
		c -= 1
		count += 1
print(count)


line1 = input().split(' ')
line2 = input().split(' ')
line3 = input().split(' ')
line4 = input().split(' ')
line5 = input().split(' ')
total = 0
if '1' in line1:
	dst = line1.index('1') + 1
	dif = abs(3 - dst)
	total = 2 + dif
elif '1' in line2:
	dst = line2.index('1') + 1
	dif = abs(3 - dst)
	total = 1 + dif
elif '1' in line3:
	dst = line3.index('1') + 1
	dif = abs(3 - dst)
	total = 0 + dif
elif '1' in line4:
	dst = line4.index('1') + 1
	dif = abs(3 - dst)
	total = 1 + dif
elif '1' in line5:
	dst = line5.index('1') + 1
	dif = abs(3 - dst)
	total = 2 + dif
print(total)


coordinates = []
for i in range(1, 6):
	x = list(map(int, input().split()))
	if x.count(1) == 1:
		coordinates.append(i)
		coordinates.append(x.index(1) + 1)
print(abs(3 - coordinates[0]) + abs(3 - coordinates[1]))


A = []
for i in range(5):
	A.append(input().split())
for i in range(5):
	for j in range(5):
		if A[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))


arr = []
for i in range(5):
	x = list(map(int, input().split()))
	arr.append(x)
x = 0
y = 0
f = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			x = i
			y = j
			f = 1
			break
	if f == 1:
		break
z = abs(x - 2) + abs(y - 2)
print(z)


for i in range(1, 6):
	lst = list(map(int, input().split()))
	if 1 in lst:
		idx = lst.index(1) + 1
		print(abs(i - 3) + abs(idx - 3))
		break


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))
m = [r1, r2, r3, r4, r5]
flag = 0
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			pos = [i, j]
			flag = 1
			break
	if flag == 1:
		break
desti = [2, 2]
print(abs(pos[0] - desti[0]) + abs(pos[1] - desti[1]))


(i, j) = divmod((input() + input() + input() + input() + input()).replace(' ', '').index('1'), 5)
print(abs(i - 2) + abs(j - 2))


import os
import sys
from io import BytesIO, IOBase

def main():
	matrix = []
	for _ in range(5):
		row = list(map(int, input().split()))
		matrix.append(row)
	for (row_idx, row) in enumerate(matrix):
		for (col_idx, cell) in enumerate(row):
			if cell == 1:
				sys.stdout.write(str(abs(2 - row_idx) + abs(2 - col_idx)))
				break
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')
main()


table = [[0 for i in range(5)] for j in range(5)]
for row in range(5):
	line = [int(i) for i in input().split()]
	if max(line) == 1:
		for column in range(len(line)):
			if line[column] == 1:
				table[row][column] = 1
				break
		print(abs(row - 2) + abs(column - 2))
		break


import math
(i, j) = (0, 0)
for r in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		i = l.index(1)
		j = r
print(int(math.fabs(i - 2) + math.fabs(j - 2)))


for i in range(5):
	arr = [int(x) for x in input().split()]
	for j in range(len(arr)):
		if arr[j] == 1:
			print(abs(2 - i) + abs(2 - j))
			exit


n = 5
ar = []
for i in range(n):
	ar2 = [int(i) for i in input().split()]
	ar.append(ar2)
for i in range(len(ar)):
	for j in range(len(ar)):
		if ar[i][j] == 1:
			x = i
			y = j
print(abs(2 - x) + abs(2 - y))


import sys
m = 0
n = 0
for i in range(5):
	k = [int(a) for a in sys.stdin.readline().split()]
	if 1 in k:
		m = k.index(1) + 1
		n = i + 1
		break
print(abs(3 - m) + abs(3 - n))


x = 0
y = 0
for g in range(5):
	f = list(map(int, input().split()))
	for i in range(5):
		if f[i] == 1:
			y = g + 1
			x = i + 1
if x == 3 and y == 3:
	print(0)
else:
	print(abs(x - 3) + abs(y - 3))


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
(i, j) = (0, 0)
for row in range(len(mat)):
	if 1 in mat[row]:
		(i, j) = (row, mat[row].index(1))
print(abs(i - 2) + abs(j - 2))


pos = None
for r in range(1, 6):
	line = input().strip()
	a = line.split(' ')
	for c in range(1, 6):
		if a[c - 1] == '1':
			pos = (r, c)
			break
	if pos:
		break
print(abs(3 - pos[0]) + abs(3 - pos[1]))


import sys
break_val = False
for i in range(5):
	n = sys.stdin.readline().split()
	for (j, val) in enumerate(n):
		if val == '1':
			break_val = True
			index = abs(j - 2) + abs(i - 2)
			break
	if break_val:
		break
print(index)


m = []
c = 0
r = 0
for _ in range(5):
	n = list(map(int, input().split()))
	m.append(n)
	if 1 in n:
		c = n.index(1)
		r = _
temp = abs(c - 2) + abs(r - 2)
print(temp)


x = []
for i in range(5):
	x.append(list(input().split()))

def fun(x, count=0):
	for i in x:
		for j in i:
			if j == '1':
				count = count + abs(2 - x.index(i))
				x[2][i.index(j)] = '1'
				return count
z = fun(x)
j = abs(2 - x[2].index('1'))
print(z + j)


mat = []
for i in range(5):
	temp = [int(i) for i in input().split()]
	mat.append(temp)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			row = i + 1
			column = j + 1
print(abs(row - 3) + abs(column - 3))


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]

def pos(l):
	for i in range(5):
		for j in range(5):
			if l[i][j] == 1:
				return [i, j]
print(abs(pos(l)[0] - 2) + abs(pos(l)[1] - 2))


arr = [[0 for _ in range(5)] for _ in range(5)]
for i in range(5):
	arr[i] = list(map(int, input().split()))
	if 1 in arr[i]:
		for j in range(5):
			if arr[i][j] == 1:
				posI = i
				posJ = j
print(abs(posI - 2) + abs(posJ - 2))


co = -1
to = -1
for i in range(5):
	x = list(map(int, input().split()))
	for r in range(5):
		if x[r] == 1:
			co = r
			to = i
print(abs(2 - co) + abs(2 - to))


for i in range(5):
	s = input().replace(' ', '')
	id = s.find('1')
	if id != -1:
		print(abs(i - 2) + abs(id - 2))
		exit()


matrix = [[int(i) for i in list(input().split(' '))] for j in range(5)]
for (i, j) in enumerate(matrix):
	for (k, l) in enumerate(j):
		if l == 1:
			print(abs(2 - i) + abs(2 - k))


a = [i for i in input().split()]
b = [i for i in input().split()]
c = [i for i in input().split()]
d = [i for i in input().split()]
e = [i for i in input().split()]
l = [a, b, c, d, e]
for i in l:
	if '1' in i:
		f = l.index(i)
		f = max(2 - int(f), int(f) - 2)
		g = i.index('1')
		g = max(2 - int(g), int(g) - 2)
print(f + g)


for i in range(5):
	t = [int(k) for k in input().split()]
	if 1 in t:
		print(abs(t.index(1) - 2) + abs(i - 2))
		break


for i in range(5):
	l = list(map(int, input().split(' ')))
	for (j, k) in enumerate(l):
		if k == 1:
			r = i + 1
			c = j + 1
m = abs(3 - r) + abs(3 - c)
print(m)


ar = []
for i in range(0, 5):
	row = input()
	ar.append(row.split())
k = 0
l = 0
for i in range(5):
	for j in range(5):
		if ar[i][j] == '1':
			k = i
			l = j
			break
final = abs(k - 2) + abs(l - 2)
print(final)


matrix = []
for i in range(5):
	line = list(input().split())
	matrix.append(line)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			line = i
			col = j
			break
print(abs(line - 2) + abs(col - 2))


l = []
for _ in range(5):
	l.append(input().split())
m = 0
n = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			m = i
			n = j
			break
print(abs(m - 2) + abs(n - 2))


x = None
y = None
for i in range(5):
	row = map(int, input().split())
	if not x:
		for (idx, number) in enumerate(row):
			if number == 1:
				x = idx + 1
				y = i + 1
				break
print(abs(3 - x) + abs(3 - y))


s = [0, 1, 0, 0, 0]
s[0] = input().split()
s[1] = input().split()
s[2] = input().split()
s[3] = input().split()
s[4] = input().split()
line1 = 0
line2 = 0
for i in range(5):
	if '1' in s[i]:
		m = i
		line1 = abs(i + 1 - 3)
for x in range(5):
	if s[m][x] == '1':
		line2 = abs(x + 1 - 3)
print(line1 + line2)


w = (2, 1, 0, 1, 2)
score = 0
for i in w:
	s = tuple(map(int, input().split(' ')))
	for j in range(0, 5):
		score += w[j] * s[j] + i * s[j]
print(score)


l1 = list(map(int, input('').split()))
l2 = list(map(int, input('').split()))
l3 = list(map(int, input('').split()))
l4 = list(map(int, input('').split()))
l5 = list(map(int, input('').split()))
if 1 in l1:
	x = 1
	y = l1.index(1) + 1
elif 1 in l2:
	x = 2
	y = l2.index(1) + 1
elif 1 in l3:
	x = 3
	y = l3.index(1) + 1
elif 1 in l4:
	x = 4
	y = l4.index(1) + 1
else:
	x = 5
	y = l5.index(1) + 1
print(abs(3 - x) + abs(3 - y))


spis = []
for i in range(5):
	matrix = [int(f) for f in input().split()]
	spis.append(matrix)
for elem in spis:
	if 1 in elem:
		num_stolb = elem.index(1) + 1
		num_stroka = spis.index(elem) + 1
		s_stroka = abs(num_stroka - 3)
		s_stolb = abs(num_stolb - 3)
		print(s_stolb + s_stroka)


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

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

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def createMatrix(rowCount, colCount, dataList):
	mat = []
	for i in range(rowCount):
		rowList = []
		for j in range(colCount):
			if dataList[j] not in mat:
				rowList.append(dataList[j])
		mat.append(rowList)
	return mat
b = []
c = 0
d = 0
e = 0
for i in range(5):
	a = list(map(int, input().split()))
	b.append(a)
for i in range(5):
	for j in range(5):
		if b[i][j] == 1:
			c = i
			d = j
while c != 2 or d != 2:
	if c < 2:
		c += 1
		e += 1
	if c > 2:
		c -= 1
		e += 1
	if d < 2:
		d += 1
		e += 1
	if d > 2:
		d -= 1
		e += 1
print(e)


matrix = []
for i in range(0, 5):
	matrix.append(input().split(' '))
i = r = c = 0
res = False
while i < 5 and (not res):
	j = 0
	while j < 5 and (not res):
		if matrix[i][j] == '1':
			r = i
			c = j
			res = True
		j += 1
	i += 1
print(abs(r - 2) + abs(c - 2))


i = 0
x = []
for i in range(5):
	a = input().split()
	x.append(a)
n1 = 0
n2 = 0
for v in range(5):
	for j in range(5):
		if x[v][j] == '1':
			(n1, n2) = (v, j)
			break
print(abs(n1 - 2) + abs(n2 - 2))


import sys
one_row = -1
one_col = -1
for i in range(5):
	row = sys.stdin.readline()[:-1].split()
	for j in range(5):
		if row[j] == '1':
			one_row = i
			one_col = j
			break
print(abs(one_row - 2) + abs(one_col - 2))


lst = [list(map(int, input().split())) for i in range(5)]
(row, column) = (0, 0)
for row in range(5):
	if 1 in lst[row]:
		column = lst[row].index(1)
		break
print(abs(row - 2) + abs(column - 2))


x = 0
y = 0
for i in range(5):
	f = input().find('1')
	if f >= 0:
		x = i + 1
		y = f // 2 + 1
print(abs(3 - x) + abs(3 - y))


for i in range(5):
	listi = input()
	numi = listi.find('1')
	if numi != -1:
		num1 = i
		num2 = numi / 2
print(int(abs(num1 - 2) + abs(num2 - 2)))


for i in range(1, 6):
	l = input()
	if l.find('1') >= 0:
		col = l.split(' ').index('1') + 1
		diff = abs(col - 3) + abs(i - 3)
		print(diff)
		break


from sys import stdin
matrix = list()
for i in range(5):
	matrix_elements = ''.join(stdin.readline().rstrip().split())
	one_pos = matrix_elements.find('1')
	if one_pos >= 0:
		min_moves = abs(3 - (i + 1)) + abs(3 - (one_pos + 1))
print(min_moves)


summ = 0
for i in range(5):
	line = str(input(''))
	line = line.split(' ')
	for l in range(5):
		if int(line[l]) == 1:
			summ = abs(3 - (i + 1)) + abs(3 - (l + 1))
			break
	if summ != 0:
		break
print(summ)


for i in range(0, 5):
	ar = list(map(int, input().split()))
	for j in range(0, 5):
		if ar[j] == 1:
			print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
			quit()


row1 = input()
row2 = input()
row3 = input()
row4 = input()
row5 = input()
if row1.find('1') != -1:
	row = 1
	column = row1.find('1') // 2 + 1
if row2.find('1') != -1:
	row = 2
	column = row2.find('1') // 2 + 1
if row3.find('1') != -1:
	row = 3
	column = row3.find('1') // 2 + 1
if row4.find('1') != -1:
	row = 4
	column = row4.find('1') // 2 + 1
if row5.find('1') != -1:
	row = 5
	column = row5.find('1') // 2 + 1
print(abs(row - 3) + abs(column - 3))


mtx = []
for i in range(5):
	mtx.append(input().split())
location = [(i, j) for i in range(5) for j in range(5) if mtx[i][j] == '1']
moves = abs(location[0][0] - 2) + abs(location[0][1] - 2)
print(moves)


row = []
for i in range(0, 5):
	row.append(input())
column = 0
roww = 0
for i in range(0, 5):
	if '1' in row[i]:
		roww = i
		column = row[i].index('1') / 2
print(int(abs(roww - 2) + abs(column - 2)))


def beautiful_matrix():
	global position
	for i in range(5):
		row = input().split(' ')
		for (j, num) in enumerate(row):
			if num == '1':
				return abs(i - 2) + abs(j - 2)
print(beautiful_matrix())


for i in range(5):
	s = input()
	if '1' in s:
		print(abs(3 - (s.index('1') // 2 + 1)) + abs(3 - (i + 1)))
		break


matrix = [[4, 3, 2, 3, 4], [3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3], [4, 3, 2, 3, 4]]
for a in range(5):
	x = [int(c) for c in input().split()]
	for b in range(5):
		if x[b]:
			print(matrix[a][b])
			break


row = 0
asd = ''
for i in range(5):
	row += 1
	line = input()
	if '1' in line:
		for x in range(9):
			if line[x] != ' ':
				asd += line[x]
		for j in range(5):
			if asd[j] == '1':
				print(abs(i - 2) + abs(j - 2))


box = [[list(input())], [list(input())], [list(input())], [list(input())], [list(input())]]
for i in range(5):
	for j in range(4):
		box[i][0].remove(' ')
	if '1' in box[i][0]:
		if i < 2:
			if box[i][0].index('1') < 2:
				print(2 - i + 2 - box[i][0].index('1'))
			else:
				print(2 - i + box[i][0].index('1') - 2)
		elif box[i][0].index('1') < 2:
			print(i - 2 + 2 - box[i][0].index('1'))
		else:
			print(i - 2 + box[i][0].index('1') - 2)


import sys
data = [sub.split() for sub in sys.stdin.readlines()]
(n, m) = (0, 0)
for i in range(len(data)):
	if sum([int(x) for x in data[i]]):
		n = i
		m = data[i].index('1')
		break
sys.stdout.write(str(abs(2 - n) + abs(2 - m)))


matrix = []
for i in range(5):
	matrix.append(input().strip().split(' '))
	if '1' in matrix[i]:
		c = matrix[i].index('1')
		r = i
print(abs(2 - c) + abs(2 - r))


col = 0
for i in range(5):
	row = list(map(int, input().split()))
	try:
		col = row.index(1) + 1
		break
	except ValueError:
		continue
for _ in range(4 - i):
	input()
print(abs(col - 3) + abs(i + 1 - 3))


for i in range(5):
	a = input().split()
	for j in range(len(a)):
		if a[j] == '1':
			ia = i
			ja = j
			break
print(abs(2 - ia) + abs(2 - ja))


def solve(arr):
	req = 0
	for i in range(5):
		for j in range(5):
			if arr[j][i] == 1:
				req = abs(j - 2) + abs(i - 2)
	print(req)
x = []
for i in range(5):
	y = list(map(int, input().split()))
	x.append(y)
solve(x)


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
px = 0
py = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			px = i
			py = j
print(abs(2 - px) + abs(2 - py))


def main():
	l1 = map(int, input().split(' '))
	l2 = map(int, input().split(' '))
	l3 = map(int, input().split(' '))
	l4 = map(int, input().split(' '))
	l5 = map(int, input().split(' '))
	m0 = [list(l1), list(l2), list(l3), list(l4), list(l5)]
	posi = 0
	posj = 0
	restai = 0
	restaj = 0
	for i in range(len(m0)):
		for j in range(len(m0[i])):
			if m0[i][j] == 1:
				posi = i + 1
				posj = j + 1
	restai = abs(posi - 3)
	restaj = abs(posj - 3)
	mov = restai + restaj
	print(mov)
main()


m = []
n = 5
for i in range(n):
	t = input()
	m.append(t.split(' '))
(x, y) = (0, 0)
for i in range(n):
	for j in range(n):
		if m[i][j] == '1':
			(x, y) = (i, j)
			break
ans = abs(x - 2) + abs(y - 2)
print(ans)


import sys
input = sys.stdin.readline
matrix = []
for i in range(5):
	matrix.append(list(input().split()))
pos_x = [x for x in matrix if '1' in x]
x = matrix.index(pos_x[0])
y = pos_x[0].index('1')
res = abs(2 - x) + abs(2 - y)
print(res)


import math
list = []
for i in range(5):
	list.append(input().split())
x = 0
y = 0
for i in range(5):
	for j in range(5):
		if int(list[i][j]) == 1:
			x = i
			y = j
			print(abs(x - 2) + abs(y - 2))


(w, h) = (5, 5)
matrix = [[0 for xx in range(w)] for y in range(h)]
for i in range(0, 5):
	row = input('')
	cols = row.split(' ')
	for j in range(0, len(cols)):
		matrix[i][j] = int(cols[j])

def mod(num):
	return num if num >= 0 else num * -1

def to_make_beautiful(in_matrix):
	start_x = 0
	start_y = 0
	for i in range(0, len(in_matrix)):
		row = in_matrix[i]
		for j in range(0, len(in_matrix)):
			if in_matrix[i][j] != 0:
				start_x = i
				start_y = j
				break
	x_required = mod(start_x - 2)
	y_required = mod(start_y - 2)
	return x_required + y_required
output = to_make_beautiful(matrix)
print(output)


list = []
for i in range(5):
	list.append(input().split())
for i in range(5):
	for j in range(5):
		if int(list[i][j]) == 1:
			print(abs(i - 2) + abs(j - 2))


for i in range(5):
	a = input().split()
	if '1' in a:
		print(abs(3 - a.index('1') - 1) + abs(3 - i - 1))
		exit()


a = []
b = []
for i in range(5):
	c = input().split(' ')
	b = list(c)
	a.append(b)
f = 0
for i in range(5):
	p = i
	for j in range(5):
		q = j
		if a[i][j] == '1':
			f = 1
			break
	if f == 1:
		break
i = p
j = q
c = 0
if i == 2 and j == 2:
	print(0)
	quit()
else:
	while i != 2:
		if i < 2:
			i = i + 1
		elif i > 2:
			i = i - 1
		c = c + 1
	while j != 2:
		if j < 2:
			j = j + 1
		elif j > 2:
			j = j - 1
		c = c + 1
print(c)


n = 5
matrix = []
for i in range(n):
	all = [int(i) for i in input().split()]
	matrix.append(all)
for i in range(n):
	for j in range(n):
		if matrix[i][j] == 1:
			if (i != 2) | (j != 2):
				print(int(abs(i - 2)) + int(abs(j - 2)))
			else:
				print(0)


x = 0
y = 0
while True:
	y += 1
	line = str(input())
	if line.find('1') >= 0:
		x = line.find('1') / 2 + 1
		break
x = abs(x - 3)
y = abs(y - 3)
print(int(x + y))


a = []
b = []
for i in range(5):
	for j in range(5):
		a.append((i, j))
for i in range(5):
	b += map(int, input().split())
pos_do_um = b.index(1)
par_correspondente = a[pos_do_um]
par_central = [2, 2]
dist = abs(par_correspondente[0] - par_central[0]) + abs(par_correspondente[1] - par_central[1])
print(dist)


import math
a = []
for i in range(5):
	a.append(input().split())
for j in range(5):
	if '1' in a[j]:
		(l, k) = (j, a[j].index('1'))
print(abs(l - 2) + abs(k - 2))


matrix = []
for i in range(5):
	row = list(map(int, input().split(' ')))
	matrix.append(row)
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			(row, col) = (i, j)
print(abs(row - 2) + abs(col - 2))


arr = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
for i in range(5):
	lis = [int(x) for x in input().split()]
	for j in range(5):
		if lis[j] == 1:
			r = i + 1
			c = j + 1
		arr[i][j] = lis[j]
print(abs(3 - r) + abs(3 - c))


import sys
data = [i for i in sys.stdin.read()].index('1') // 2
print(sum(map(abs, [data % 5 - 2, data // 5 - 2])))


T = []
n = 5
sum = 0
while n > 0:
	T.append(list(map(int, input().strip().split())))
	for (index, item) in enumerate(T):
		if 1 in item:
			row = abs(index - 2)
			cols = abs(item.index(1) - 2)
			sum = row + cols
	n -= 1
print(sum)


L = []
for i in range(5):
	L.append(input().split(' '))
ind1 = 0
ind2 = 0
for i in range(5):
	for j in range(5):
		if L[i][j] == '1':
			ind1 = i
			ind2 = j
			break
print(abs(ind1 - 2) + abs(ind2 - 2))


p = []
for i in range(0, 5):
	a = input()
	a = a.split(' ')
	p.append(a)
q = 0
for i in range(0, 5):
	if '1' in p[i]:
		if i == 0 or i == 4:
			q = q + 2
		elif i == 1 or i == 3:
			q = q + 1
		for j in range(0, 5):
			if p[i][j] == '1':
				if j == 0 or j == 4:
					q = q + 2
				elif j == 1 or j == 3:
					q = q + 1
print(q)


m = []
for i in range(5):
	a = list(map(int, input().split()))
	m.append(a)
	loc = None
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			loc = (i, j)
			break
c = abs(loc[0] - 2) + abs(loc[1] - 2)
print(c)


a = []
pos = []
for x in range(0, 5):
	b = input()
	b = a.append(list(map(int, b.split())))
for x in range(0, 5):
	for y in range(0, 5):
		if a[x][y] == 1:
			pos.extend([x + 1, y + 1])
print(abs(3 - pos[0]) + abs(3 - pos[1]))


m = []
for i in range(5):
	r = [int(x) for x in input().split()]
	m.append(r)
rindex = 0
cindex = 0
for i in range(len(m)):
	for j in range(len(m[0])):
		if m[i][j] == 1:
			rindex = i
			cindex = j
			break
print(abs(2 - rindex) + abs(2 - cindex))


mat = []
for i in range(5):
	l = list(map(int, input().split(' ')))
	mat.append(l)
for i in range(len(mat)):
	for j in range(len(mat[i])):
		if mat[i][j] == 1:
			a = i + 1
			b = j + 1
			break
print(abs(a - 3) + abs(b - 3))


A = [list(map(int, input().split())) for i in range(5)]
x = 0
y = 0
for i in range(len(A)):
	for j in A[i]:
		if j == 1:
			x = A[i].index(j)
			y = i
			break
s = abs(2 - x) + abs(2 - y)
print(s)


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
m12 = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			m12 = abs(2 - i) + abs(j - 2)
print(m12)


from sys import stdin
a = [[0] * 5 for i in range(5)]
for i in range(5):
	b = list(map(int, stdin.readline().rstrip().split()))
	for j in range(5):
		a[i][j] = b[j]
		if b[j] == 1:
			myindex = [i + 1, j + 1]
			break
print(abs(myindex[0] - 3) + abs(myindex[1] - 3))


n = input()
up = 1
while '1' not in n:
	up += 1
	n = input()
bush = [int(a) for a in n.split()]
print(abs(bush.index(1) - 3 + 1) + abs(up - 3))


rows = []
for i in range(0, 5):
	rows.append(input())
moves_to_line_mid = 0
moves_to_row_mid = 0
for (row_id, row) in enumerate(rows):
	row_numbers = row.split(' ')
	for (number_id, number) in enumerate(row_numbers):
		if number == '1':
			if row_id == 0 or row_id == 4:
				moves_to_row_mid = 2
			elif row_id == 1 or row_id == 3:
				moves_to_row_mid = 1
			else:
				moves_to_row_mid = 0
			if number_id == 0 or number_id == 4:
				moves_to_line_mid = 2
			elif number_id == 1 or number_id == 3:
				moves_to_line_mid = 1
			else:
				moves_to_line_mid = 0
print(moves_to_line_mid + moves_to_row_mid)


l = 5
for i in range(l):
	colume = input().split()
	for j in range(l):
		if colume[j] == '1':
			moves = abs(j - 2) + abs(i - 2)
			print(moves)


n = 5
m = n // 2
cnt = 0
for j in range(n):
	ints = [int(x) for x in input().split()]
	for i in range(n):
		v = ints[i]
		if v == 1:
			cnt += abs(i - m) + abs(j - m)
print(cnt)


import sys
s = sys.stdin.read()
S = s.split()
d = S.index('1')
x = d % 5
y = d // 5
dx = abs(x - 2)
dy = abs(y - 2)
print(dx + dy)


matrix = []
for _ in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		one = l.index(1)
		ind = _
	matrix.append(l)
count = abs(ind - 2) + abs(one - 2)
print(count)


i = -1
while True:
	i += 1
	a = input().split()
	try:
		j = a.index('1')
		print(abs(2 - i) + abs(2 - j))
		break
	except ValueError:
		continue


from time import process_time
from sys import argv

def solve():
	a = [[int(n) for n in input().split()] for _ in range(5)]
	s = list(map(sum, a))
	x = s.index(1)
	y = a[x].index(1)
	print(abs(x - 2) + abs(y - 2))
if len(argv) > 1:
	startTime = process_time()
	solve()
	print('Elapsed Time:', process_time() - startTime)
else:
	solve()


def moves(matrix):
	for row in range(5):
		for col in range(5):
			if matrix[row][col] == 1:
				return abs(row - 2) + abs(col - 2)
matrix = []
for i in range(5):
	r = list(map(int, input().split()))
	matrix.append(r)
print(moves(matrix))


r = []
one_id = 0
row_of_one = 0
for i in range(5):
	row = [int(i) for i in input().split()][:5]
	r.append(row)
	for k in range(len(row)):
		if row[k] == 1:
			row_of_one = i
			one_id = k
hor_moves = abs(one_id - 2)
vert_moves = abs(row_of_one - 2)
print(hor_moves + vert_moves)


import math as m
list = []
for i in range(0, 5):
	a = input()
	b = a.split()
	list.append(b)
for i in range(0, 5):
	for j in range(0, 5):
		if list[i][j] == '1':
			c = m.fabs(i - 2) + m.fabs(j - 2)
			print(int(c))


mat = [(x, input().find('1') // 2) for x in range(5)]
ans = [abs(x - 2) + abs(y - 2) for (x, y) in mat if y >= 0]
print(ans[0])


import sys
input = sys.stdin.readline()
matrix = []
size = 5
while input:
	matrix.append(input.split())
	input = sys.stdin.readline()
id_i = 0
id_j = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			id_i = i
			id_j = j
			break
moves_rows = abs(id_i - 2)
moves_cols = abs(id_j - 2)
tot_moves = moves_cols + moves_rows
print(tot_moves)


temp = input().replace(' ', '')
if temp.find('1') != -1:
	print(abs(int(temp.find('1')) - 2) + 2)
temp = input().replace(' ', '')
if temp.find('1') != -1:
	print(abs(int(temp.find('1')) - 2) + 1)
temp = input().replace(' ', '')
if temp.find('1') != -1:
	print(abs(int(temp.find('1')) - 2))
temp = input().replace(' ', '')
if temp.find('1') != -1:
	print(abs(int(temp.find('1')) - 2) + 1)
temp = input().replace(' ', '')
if temp.find('1') != -1:
	print(abs(int(temp.find('1')) - 2) + 2)


for i in range(5):
	s = input().replace(' ', '')
	if '1' in s:
		c = s.index('1') + 1
		r = i + 1
		print(abs(3 - r) + abs(3 - c))
		break


c = []
for i in range(5):
	row = input().split()
	r = [int(n) for n in row]
	c.append(r)
for i in range(5):
	for j in range(5):
		if c[i][j] == 1:
			if i > 2:
				x = i - 5 // 2
			else:
				x = 5 // 2 - i
			if j > 2:
				y = j - 5 // 2
			else:
				y = 5 // 2 - j
print(x + y)


def find_1(matrix):
	row = 0
	col = 0
	while matrix[row][col] != 1:
		if col == 4:
			row += 1
			col = 0
		else:
			col += 1
	return (row, col)
matrix = []
for i in range(5):
	row = input()
	matrix += [[*map(int, row.split())]]
(row, col) = find_1(matrix)
turns = abs(2 - row) + abs(2 - col)
print(turns)


a1 = input().split()
a2 = input().split()
a3 = input().split()
a4 = input().split()
a5 = input().split()
x = 0
for i in range(0, 5):
	if a1[i] == '1':
		x = 2 + abs(2 - i)
		print(x)
		break
	elif a2[i] == '1':
		x = 1 + abs(2 - i)
		print(x)
		break
	elif a3[i] == '1':
		x = abs(2 - i)
		print(x)
		break
	elif a4[i] == '1':
		x = 1 + abs(2 - i)
		print(x)
		break
	elif a5[i] == '1':
		x = 2 + abs(2 - i)
		print(x)
		break


M = [input()[::2] for i in range(5)]
for y in range(5):
	if '1' in M[y]:
		print(abs(y - 2) + abs(M[y].index('1') - 2))


listy = [input() for _ in range(5)]
for (i, j) in enumerate(listy):
	j = j.split(' ')
	for (k, l) in enumerate(j):
		if l == '1':
			row = i
			column = k
			print(abs(row - 2) + abs(column - 2))


m = []
for i in range(5):
	m.append([int(s) for s in input().split(' ')])

def findOne(m):
	for i in m:
		for j in i:
			if j == 1:
				return [m.index(i), i.index(j)]

def disToCenter(pos):
	return abs(pos[0] - 2) + abs(pos[1] - 2)
print(disToCenter(findOne(m)))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
c1 = [a[0], b[0], c[0], d[0], e[0]]
c2 = [a[1], b[1], c[1], d[1], e[1]]
c3 = [a[2], b[2], c[2], d[2], e[2]]
c4 = [a[3], b[3], c[3], d[3], e[3]]
c5 = [a[4], b[4], c[4], d[4], e[4]]
x = 0
y = 0
if '1' in a:
	while x < 5:
		if a[x] == '1':
			y = abs(x - 2)
		x = x + 1
elif '1' in b:
	while x < 5:
		if b[x] == '1':
			y = abs(x - 2)
		x = x + 1
elif '1' in c:
	while x < 5:
		if c[x] == '1':
			y = abs(x - 2)
		x = x + 1
elif '1' in d:
	while x < 5:
		if d[x] == '1':
			y = abs(x - 2)
		x = x + 1
elif '1' in e:
	while x < 5:
		if e[x] == '1':
			y = abs(x - 2)
		x = x + 1
q = 0
w = 0
if '1' in c1:
	while q < 5:
		if c1[q] == '1':
			w = abs(q - 2)
		q = q + 1
elif '1' in c2:
	while q < 5:
		if c2[q] == '1':
			w = abs(q - 2)
		q = q + 1
elif '1' in c3:
	while q < 5:
		if c3[q] == '1':
			w = abs(q - 2)
		q = q + 1
elif '1' in c4:
	while q < 5:
		if c4[q] == '1':
			w = abs(q - 2)
		q = q + 1
elif '1' in c5:
	while q < 5:
		if c5[q] == '1':
			w = abs(q - 2)
		q = q + 1
print(y + w)


m = [[print(abs(2 - int(i)) + abs(3 - int(j))) for (i, c) in enumerate(input().split(' ')) if int(c)] for j in range(1, 6)]


for i in range(5):
	a = input().replace(' ', '')
	a = list(a)
	if '1' in a:
		b = i + 1
		c = int(a.index('1')) + 1
a = 0
if b < 3:
	while b != 3:
		b += 1
		a += 1
if b > 3:
	while b != 3:
		b -= 1
		a += 1
if c < 3:
	while c != 3:
		c += 1
		a += 1
if c > 3:
	while c != 3:
		c -= 1
		a += 1
print(a)


a = input()
b = input()
c = input()
d = input()
e = input()
for v in a:
	if v == '1':
		p = a.index('1')
		if p > 4:
			print((p - 4) // 2 + 2)
		else:
			print(2 + (4 - p) // 2)
		break
for v in b:
	if v == '1':
		q = b.index('1')
		if q > 4:
			print((q - 4) // 2 + 1)
		else:
			print(1 + (4 - q) // 2)
		break
for v in c:
	if v == '1':
		r = c.index('1')
		if r > 4:
			print((r - 4) // 2)
		else:
			print((4 - r) // 2)
		break
for v in d:
	if v == '1':
		s = d.index('1')
		if s > 4:
			print((s - 4) // 2 + 1)
		else:
			print(1 + (4 - s) // 2)
		break
for v in e:
	if v == '1':
		t = e.index('1')
		if t > 4:
			print((t - 4) // 2 + 2)
		else:
			print(2 + (4 - t) // 2)
		break


zr = '0 '
zrl = (zr * 5)[:-1]

def dc(x):
	return abs(x - 2)

def vc(s):
	v = s.split()
	for (x, t) in enumerate(v):
		if t != zr[0]:
			return dc(x)

def hc(v):
	for (x, t) in enumerate(v):
		if t != zrl:
			return dc(x) + vc(t)
v = []
for x in range(5):
	v.append(input())
print(hc(v))


ls = [2, 1, 0, 1, 2]
for l in ls:
	val = input()
	if '1' in val:
		print(l + ls[val.find('1') // 2])


matrix = []
for i in range(5):
	a = list(map(int, input().split()))
	matrix.append(a)
ind_stroka = 0
ind_stolb = 0
for stroka in range(5):
	for stolb in range(5):
		if matrix[stroka][stolb] == 1:
			ind_stroka = stroka + 1
			ind_stolb = stolb + 1
count = abs(ind_stroka - 3) + abs(ind_stolb - 3)
print(count)


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
(x, y) = (0, 0)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			x = i
			y = j
ans = abs(x - 2) + abs(y - 2)
print(ans)


matrix = []
for i in range(5):
	l = list(map(int, input().split()))
	matrix.append(l)
one_pos = [0, 0]
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] == 1:
			one_pos = [i + 1, j + 1]
			break
if one_pos == [3, 3]:
	print(0)
else:
	moves = abs(3 - one_pos[0])
	moves += abs(3 - abs(one_pos[1]))
	print(moves)


mtr = [input().split() for i in range(5)]
for i in range(5):
	for j in range(5):
		if mtr[i][j] == '1':
			break
	else:
		continue
	break
print(abs(i - 2) + abs(j - 2))


def go():
	matrix = []
	for i in range(5):
		matrix.append(input().split(' '))
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == '1':
				return abs(2 - i) + abs(2 - j)
print(go())


l = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			r = i
			s = j
v = abs(2 - r) + abs(2 - s)
print(v)


(row, col) = (0, 0)
for i in range(5):
	for (j, element) in enumerate(input().split(' ')):
		if element == '1':
			(row, col) = (i, j)
answer = int(abs(row - 2)) + int(abs(col - 2))
print(answer)


from math import *
a1 = []
b1 = []
c1 = []
d1 = []
e1 = []
for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	a1.append(a)
	b1.append(b)
	c1.append(c)
	d1.append(d)
	e1.append(e)
all = a1 + b1 + c1 + d1 + e1
x = len(all)
for i in range(x):
	if all[i] == 1:
		index = i + 1
row_num = index % 5
if row_num == 0:
	row_num += 5
col_num = ceil(index / 5)
p = 3 - row_num
q = 3 - col_num
if q < 0:
	q = q * -1
if p < 0:
	p = p * -1
ans = p + q
print(ans)


l = []
a = 2
b = 2
for i in range(5):
	k = list(map(int, input().split()))
	l.append(k)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			c = i
			d = j
print(abs(a - c) + abs(b - d))


for i in range(5):
	s = list(map(int, input().split()))
	for j in range(5):
		if s[j] == 1:
			mrow = i + 1
			mcol = j + 1
move = abs(3 - mrow) + abs(3 - mcol)
print(move)


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(len(a)):
	for j in range(len(a)):
		if a[i][j] == 1:
			firstmove = i + 1
			secondmove = j + 1
			break
x = abs(firstmove - 3)
y = abs(secondmove - 3)
print(x + y)


(x, y) = (0, 0)
for r in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		x = row.index(1)
		y = r
print(abs(x - 2) + abs(y - 2))


matrix = []
for i in range(5):
	arr = list(map(int, input().split()))
	matrix.append(arr)
flag = False
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			print(abs(i - 3 + 1) + abs(j - 3 + 1))
			flag = True
			break
	if flag:
		break


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()))
mainrow = row1 + row2 + row3 + row4 + row5
n = mainrow.index(1)
i = n // 5
j = n % 5
first = 2 - i
second = 2 - j
print(abs(first) + abs(second))


for i in range(1, 6):
	row = input()
	int_row = list(map(int, row.split(' ')))
	if 1 in int_row:
		y_index = int_row.index(1) + 1
		print(abs(3 - i) + abs(3 - y_index))


row = 0
col = 0
for i in range(5):
	n = input().split()
	if n.count('1') == 1:
		row = i + 1
		col = n.index('1') + 1
print(abs(col - 3) + abs(row - 3))


m = []
for i in range(5):
	(s1, s2, s3, s4, s5) = map(int, input().split())
	m.append([s1, s2, s3, s4, s5])
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			x = i
			y = j
if x > 2:
	m1 = x - 2
elif x < 2:
	m1 = 2 - x
else:
	m1 = 0
if y > 2:
	m2 = y - 2
elif y < 2:
	m2 = 2 - y
else:
	m2 = 0
print(m1 + m2)


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()))
A = [a, b, c, d, e]
k = 0
for i in range(0, 5):
	for j in range(0, 5):
		if A[i][j] == 1:
			k += 2 - i if i <= 2 else i - 2
			k += 2 - j if j <= 2 else j - 2
print(k)


steps = 0
l1 = input().split()
l2 = input().split()
l3 = input().split()
l4 = input().split()
l5 = input().split()
for x in range(0, 5):
	l1[x] = int(l1[x])
	l2[x] = int(l2[x])
	l3[x] = int(l3[x])
	l4[x] = int(l4[x])
	l5[x] = int(l5[x])
l = [l1, l2, l3, l4, l5]
for i in range(5):
	for j in range(5):
		if int(l[i][j]) == 1:
			steps = steps + abs(i - 2) + abs(j - 2)
print(steps)


for i in range(5):
	line = input()
	if '1' in line:
		line = line.split()
		(x, y) = (i, line.index('1'))
c = 0
while (x, y) != (2, 2):
	if x > 2:
		x -= 1
		c += 1
	elif x < 2:
		x += 1
		c += 1
	elif y > 2:
		y -= 1
		c += 1
	elif y < 2:
		y += 1
		c += 1
print(c)


t = 0
r = 0
for _ in range(5):
	m = list(map(int, input().split()))
	for i in range(int(len(m))):
		if m[i] == 1:
			r = t * 10 + i
	t += 1
print(abs(r // 10 - 2) + abs(r % 10 - 2))


for r in range(5):
	for (c, v) in enumerate(input().split()):
		if int(v):
			print(abs(2 - r) + abs(2 - c))


matrix = [list(map(int, input().split())) for _ in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] != 0:
			column = j
			row = i
			break
print(abs(2 - column) + abs(2 - row))


def main():
	manhattan_distance = 0
	for i in range(5):
		row = [int(x) for x in input().split(' ')]
		for j in range(5):
			if row[j] == 1:
				manhattan_x = j + 1 - 3 if j + 1 > 3 else 3 - (j + 1)
				manhattan_y = i + 1 - 3 if i + 1 > 3 else 3 - (i + 1)
				manhattan_distance = manhattan_x + manhattan_y
			else:
				continue
	print(manhattan_distance)
main()


import sys
if False:
	input = open('matrix.txt', 'r')
else:
	input = sys.stdin
matrix = input.readlines()
rows = []
for row in matrix:
	row = row.strip()
	cols = row.split()
	rows.append(cols)
Steps = 0
currentrow = 0
currentcol = 0
requiredrow = 2
requiredcol = 2
for x in range(5):
	for y in range(5):
		if rows[x][y] == '1':
			currentrow = x
			currentcol = y
			break
Steps = abs(currentcol - requiredcol) + abs(currentrow - requiredrow)
print(Steps)


import math
import os
import random
import re
import sys

def init_matrix():
	matrix = []
	MATRIX_WIDTH = 5
	for index in range(MATRIX_WIDTH):
		matrix.append(list(map(int, input().split())))
	return matrix

def find_one(matrix):
	for i in range(len(matrix)):
		for j in range(len(matrix[i])):
			if matrix[i][j] == 1:
				return (i, j)

def solve():
	matrix = init_matrix()
	(beautiful_row, beautiful_col) = (2, 2)
	(x, y) = find_one(matrix)
	return sum([abs(beautiful_row - x), abs(beautiful_col - y)])
result = solve()
print(result)


import sys
a = sys.stdin.read().split()
i = a.index('1')
print(abs(i // 5 - 2) + abs(i % 5 - 2))


mat = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
coord = [0, 0]
for i in range(0, 5):
	mat[i] = input().split(' ')
	if '1' in mat[i]:
		coord[0] = i + 1
		coord[1] = mat[i].index('1') + 1
print(abs(3 - coord[0]) + abs(3 - coord[1]))


def get_num_of_moves(matrix):
	for row in range(len(matrix)):
		for col in range(len(matrix[row])):
			if matrix[row][col] != 0:
				return abs(row - 2) + abs(col - 2)
	return -1
rows = 5
matrix = []
for i in range(rows):
	matrix.append([int(x) for x in input().split()])
print(get_num_of_moves(matrix))


x = []
for i in range(5):
	r = list(map(int, input().split(' ')))
	x.append(r)
a = 0
b = 0
for i in range(5):
	for j in range(5):
		if x[i][j] == 1:
			a = i
			b = j
print(abs(2 - a) + abs(2 - b))


def jue(a):
	if a >= 0:
		return a
	if a < 0:
		return -a
a = list(input().split())
b = list(input().split())
c = list(input().split())
d = list(input().split())
e = list(input().split())
s = 0
for l in (a, b, c, d, e):
	s += 1
	if l.count('1') == 0:
		continue
	if l.count('1') == 1:
		row = l.index('1') + 1
		col = s
x = jue(row - 3)
y = jue(col - 3)
print(x + y)


num = 0
element = [input().split() for i in range(5)]
for x in range(5):
	if '1' in element[x]:
		y = element[x].index('1')
		break
if x >= 2:
	num += x - 2
else:
	num += 2 - x
if y >= 2:
	num += y - 2
else:
	num += 2 - y
print(num)


m = []
for i in range(0, 5):
	m.append([int(x) for x in input().strip().split(' ')])
ans = 0
for i in range(0, 5):
	for j in range(0, 5):
		if m[i][j] == 1:
			ans = abs(i - 2) + abs(j - 2)
			break
print(ans)


def input_func():
	matrix_list = []
	for i in range(5):
		row = input().split()
		matrix_list.append(row)
	return matrix_list

def solve(matrix_list):
	row_num = -1
	col_num = -1
	for row in matrix_list:
		try:
			col_num = row.index('1')
			row_num += 1
			break
		except ValueError:
			row_num += 1
			continue
	steps = abs(row_num - 2) + abs(col_num - 2)
	print(steps)
matrix_list = input_func()
solve(matrix_list)


mtrx = [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']]
for i in range(5):
	inp = input()
	inplst = inp.split(' ')
	cntr = 0
	for member in inplst:
		mtrx[i][cntr] = member
		cntr += 1
bigin = 0
smlin = 0
for bigm in mtrx:
	if '1' in bigm:
		bigin = mtrx.index(bigm)
		for smlm in bigm:
			if smlm == '1':
				smlin = bigm.index('1')
print(abs(bigin - 2) + abs(smlin - 2))


mx = [[0] * 5 for row in range(5)]
for row in range(5):
	line = [int(j) for j in input().split()]
	if max(line) == 1:
		for column in range(5):
			if line[column] == 1:
				mx[row][column] = 1
				break
		print(abs(row - 2) + abs(column - 2))
		break


for i in range(5):
	row = input(' ')
	index = row.find('1')
	if index > -1:
		x = index / 2
		y = i
print(int(abs(x - 2) + abs(y - 2)))


for i in range(5):
	s = input()
	j = s.find('1')
	if j >= 0:
		r = i
		c = j // 2
print(abs(r - 2) + abs(c - 2))


from sys import stdin

def main():
	li = [list(stdin.readline().rstrip().split()) for i in range(5)]
	for i in range(5):
		try:
			y = li[i].index('1')
			x = i
			break
		except:
			continue
	print(abs(x - 2) + abs(y - 2))
main()


def beautify(matrix):
	res = 0
	req_row = 0
	req_col = 0
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				req_row = i
				req_col = j
				break
	res = abs(5 // 2 - req_row)
	res += abs(5 // 2 - req_col)
	return res
matrix = []
matrix.append(list(map(int, input().strip().split(' '))))
for i in range(len(matrix[0]) - 1):
	matrix.append(list(map(int, input().strip().split(' '))))
res = beautify(matrix)
print(res)


mat = [[int(i) for i in input().split()] for x in range(5)]
for i in range(0, 5):
	for j in range(0, 5):
		if mat[i][j] == 1:
			print(abs(i + 1 - 3) + abs(j + 1 - 3))


matrix = []
for i in range(5):
	a = input()
	a = a.replace(' ', '')
	a = list(a)
	if '1' in a:
		rowIndex = a.index('1')
		columnIndex = i
	matrix.append(a)
differenceInRows = rowIndex - 2
differenceInColumns = columnIndex - 2
if differenceInRows < 0:
	differenceInRows *= -1
if differenceInColumns < 0:
	differenceInColumns *= -1
moves = differenceInRows + differenceInColumns
if moves < 0:
	moves *= -1
print(moves)


lst = []
for n in range(5):
	lst.append(input().split())
	if '1' in lst[n]:
		col = lst[n].index('1')
		row = n
print(abs(2 - row) + abs(2 - col))


n = 5
num = 0
mid_num = 3
row_counter = 0
column_counter = 1
y = 0
old_str = []
for x in range(n):
	input1 = input().split()
	old_str += input1
for u in range(len(old_str)):
	row_counter += 1
	if old_str[u] == '1':
		if row_counter == 6:
			row_counter = 1
			column_counter += 1
		y += abs(3 - row_counter)
		break
	if row_counter == 6:
		row_counter = 1
		column_counter += 1
z = abs(3 - column_counter)
print(y + z)


i1 = input().split()
i2 = input().split()
i3 = input().split()
i4 = input().split()
i5 = input().split()
if i1.count('1') == 1:
	q = 1
	p = i1.index('1') + 1
elif i2.count('1') == 1:
	q = 2
	p = i2.index('1') + 1
elif i3.count('1') == 1:
	q = 3
	p = i3.index('1') + 1
elif i4.count('1') == 1:
	q = 4
	p = i4.index('1') + 1
elif i5.count('1') == 1:
	q = 5
	p = i5.index('1') + 1
s = abs(3 - q)
t = abs(3 - p)
print(s + t)


for each in range(5):
	a = list(map(int, input().split(' ')))
	if sum(a) == 1:
		ind1 = each
		ind2 = a.index(1)
print(abs(ind1 - 2) + abs(ind2 - 2))


for i in range(5):
	a = input().split()
	try:
		j = a.index('1')
		break
	except:
		j = -1
print(abs(i - 2) + abs(j - 2))


matx = []
for i in range(5):
	matx.append([int(j) for j in input().split()])
row = 0
column = 0
for i in range(5):
	for j in range(5):
		if matx[i][j] == 1:
			row = i
			column = j
moves = 0
if row >= 2:
	moves += row - 2
else:
	moves += 2 - row
if column >= 2:
	moves += column - 2
else:
	moves += 2 - column
print(moves)


a1 = input()
a2 = input()
a3 = input()
a4 = input()
a5 = input()
a1 = a1.split()
a2 = a2.split()
a3 = a3.split()
a4 = a4.split()
a5 = a5.split()
a1 = [int(x) for x in a1]
a2 = [int(x) for x in a2]
a3 = [int(x) for x in a3]
a4 = [int(x) for x in a4]
a5 = [int(x) for x in a5]
a = [a1, a2, a3, a4, a5]
for j in range(5):
	for i in range(5):
		if a[i][j] == 1:
			n = abs(2 - i) + abs(2 - j)
			print(n)


for i in range(5):
	line = list(map(int, input().split()))
	for a in range(5):
		if line[a] == 1:
			steps = abs(2 - i) + abs(2 - a)
			break
print(steps)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def main():
	n = 5
	a = []
	for i in range(n):
		a.append(ria())
	for i in range(n):
		for j in range(n):
			if a[i][j] == 1:
				wi(abs(i - 2) + abs(j - 2))
main()


a = [0 for x in range(5)]
for i in range(5):
	a[i] = [int(x) for x in input().split()]
for i in range(5):
	for j in range(5):
		if a[i][j] != 0:
			(x, y) = (i, j)
			break
if x > 2:
	x = x - 2
else:
	x = 2 - x
if y > 2:
	y = y - 2
else:
	y = 2 - y
print(x + y)


a = []
for i in range(0, 5):
	b = list(map(int, input().split()))
	a.append(b)
	if sum(b) == 1:
		a1 = i
		for m in range(0, 5):
			if b[m] == 1:
				a2 = m
c = abs(a1 - 2) + abs(a2 - 2)
print(c)


arr = []
for i in range(1, 6):
	arr.append(list(map(int, input().rstrip().split())))
z = []
z = [(ix + 1, iy + 1) for (ix, row) in enumerate(arr) for (iy, i) in enumerate(row) if i == 1]
l = []
n = z[0][0]
m = z[0][1]
a = 0
b = 0
if n < 3:
	a = 3 - n
elif n > 3:
	a = n - 3
elif n == 3:
	a = a
if m <= 3:
	b = 3 - m
elif m > 3:
	b = m - 3
s = a + b
print(s)


l = []
for i in range(5):
	h = list(map(int, input().split()))
	l.extend([h])
(a, b, c) = (0, 0, 0)
for i in l:
	if 1 in i:
		a = l.index(i)
		b = i.index(1)
		break
while a != 2:
	if a < 2:
		a = a + 1
		c = c + 1
	elif a > 2:
		a = a - 1
		c = c + 1
while b != 2:
	if b < 2:
		b = b + 1
		c = c + 1
	elif b > 2:
		b = b - 1
		c = c + 1
print(c)


d = 0
for i in range(5):
	x = input().split()
	if '1' in x:
		h = i
		k = x.index('1')
if h == k and h == 2:
	print(0)
else:
	if h > 2:
		d = d + (h - 2)
	else:
		d = d + (2 - h)
	if k > 2:
		d = d + (k - 2)
	else:
		d = d + (2 - k)
	print(d)


a = []
for i in range(5):
	a.append([int(i) for i in input().split()])
count = 0
for i in range(5):
	for j in range(5):
		if a[i][j]:
			count = abs(i - 2) + abs(j - 2)
			break
print(count)


mat = []
for i in range(5):
	mat.append(list(map(int, input().split(' '))))
	if 1 in mat[i]:
		idx = mat[i].index(1)
		print(abs(2 - i) + abs(2 - idx))


a = []
b = []
c = []
d = []
e = []
i = 0
j = 0
k = 0
l = 0
m = 0
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()))
for x in a:
	i += 1
	if x == 1:
		if i == 1:
			print(4)
		elif i == 2:
			print(3)
		elif i == 3:
			print(2)
		elif i == 4:
			print(3)
		elif i == 5:
			print(4)
for x in b:
	j += 1
	if x == 1:
		if j == 1:
			print(3)
		elif j == 2:
			print(2)
		elif j == 3:
			print(1)
		elif j == 4:
			print(2)
		elif j == 5:
			print(3)
for x in c:
	k += 1
	if x == 1:
		if k == 1:
			print(2)
		elif k == 2:
			print(1)
		elif k == 3:
			print(0)
		elif k == 4:
			print(1)
		elif k == 5:
			print(2)
for x in d:
	l += 1
	if x == 1:
		if l == 1:
			print(3)
		elif l == 2:
			print(2)
		elif l == 3:
			print(1)
		elif l == 4:
			print(2)
		elif l == 5:
			print(3)
for x in e:
	m += 1
	if x == 1:
		if m == 1:
			print(4)
		elif m == 2:
			print(3)
		elif m == 3:
			print(2)
		elif m == 4:
			print(3)
		elif m == 5:
			print(4)


l = []
for i in range(5):
	l1 = list(map(int, input().split()))
	l.append(l1)
count = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			r = 2 - i
			k = 2 - j
			if k >= 0:
				k = k
			else:
				k = -k
			if r >= 0:
				r = r
			else:
				r = -r
			count = count + r + k
print(count)


import sys
width = 0
height = 0
for line in sys.stdin:
	ln_copy = None
	if '1' in line:
		ln_copy = line.strip()
		ln_copy = ln_copy.replace(' ', '')
		height = ln_copy.index('1')
		break
	width += 1
print(abs(width - 2) + abs(height - 2))


k = ['0', '0', '0', '0', '0']
i = 0
l = []
for i in range(5):
	l = input().split(' ')
	if k != l:
		break
j = l.index('1')
print(abs(2 - i) + abs(2 - j))


for x in range(6):
	arr = list(map(int, input().split()))
	if 1 in arr:
		break
y = arr.index(1)
x = x + 1
y = y + 1
steps = abs(3 - x) + abs(y - 3)
if steps > 0:
	print(steps)
else:
	print(-1 * steps)


arr = []
for _ in range(0, 5):
	ar = [int(num) for num in input().split()]
	arr.append(ar)
for i in range(0, 5):
	if 1 in arr[i]:
		a = i
		b = arr[i].index(1)
print(abs(2 - a) + abs(2 - b))


ls = []
for i in range(5):
	tmp = list(map(int, input().split()))
	ls.append(tmp)
for i in range(len(ls)):
	for j in range(len(ls[i])):
		if 1 in ls[i]:
			idx = [i, ls[i].index(1)]
			break
ans = abs(2 - idx[0]) + abs(2 - idx[1])
print(ans)


(index_i, index_j) = (None, None)
for i in range(5):
	row = input().split()
	if '1' in row:
		(index_i, index_j) = (i + 1, row.index('1') + 1)
print(abs(index_i - 3) + abs(index_j - 3))


matrix = []
a = 0
b = 0
m = 0
for i in range(5):
	row = list(map(int, input().split()))
	matrix.append(row)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			a = i
			b = j
if a > 2:
	m1 = a - 2
if a <= 2:
	m1 = 2 - a
if b > 2:
	m2 = b - 2
if b <= 2:
	m2 = 2 - b
m = m1 + m2
print(m)


a = []
counter = 0
y = []
for i in range(5):
	a.append([int(j) for j in input().split()])
for i in range(len(a)):
	if a[i].count(1) == 1:
		counter += abs(2 - i)
for m in range(5):
	y.append([row[m] for row in a])
for j in range(len(y)):
	if y[j].count(1) == 1:
		counter += abs(2 - j)
print(counter)


for i in range(5):
	row = list(map(int, input().split(' ')))
	if 1 in row:
		s = abs(2 - i) + abs(2 - row.index(1))
		print(s)
		break


a = []
for i in range(0, 5):
	a = list(map(int, input().split()))
	for j in range(0, 5):
		if a[j] == 1:
			x1 = i
			y1 = j
	a[:] = []
print(abs(x1 - 2) + abs(y1 - 2))


row1 = list(input().split())
row2 = list(input().split())
row3 = list(input().split())
row4 = list(input().split())
row5 = list(input().split())
count = 0
r = -1
j = -1
for i in range(5):
	if row1[i] == '1':
		r = 0
		j = i
	if row2[i] == '1':
		r = 1
		j = i
	if row3[i] == '1':
		r = 2
		j = i
	if row4[i] == '1':
		r = 3
		j = i
	if row5[i] == '1':
		r = 4
		j = i
if r == 0 or r == 4:
	count = count + 2
elif r == 1 or r == 3:
	count = count + 1
if j == 0 or j == 4:
	count = count + 2
elif j == 1 or j == 3:
	count = count + 1
print(count)


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
for i in range(5):
	try:
		ind = arr[i].index(1)
		break
	except:
		pass
cx = 2
cy = 2
print(abs(cx - i) + abs(cy - ind))


r = -1
c = -1
for i in range(1, 6):
	l = input().split(' ')
	for j in range(5):
		if l[j] == '1':
			r = i
			c = j + 1
ans = 0
ans += abs(r - 3)
ans += abs(c - 3)
print(ans)


l1 = []
for i in range(5):
	l2 = [int(x) for x in input().split()]
	l1.append(l2)
m = 0
n = 0
for i in range(5):
	if l1[i].count(1) == 1:
		m = i + 1
		n = l1[i].index(1) + 1
p = abs(m - 3) + abs(n - 3)
print(p)


import math
from typing import List, Any

def _read_row(sep=' ', converters=None) -> List[Any]:
	if not converters:
		converters = [str]
	return list(map(lambda x: converters[x[0] % len(converters)](x[1]), enumerate(input().split(sep=sep))))

def _read_matrix(rows_count=1, sep=' ', converters=None) -> List[List[Any]]:
	if not converters:
		converters = [[str]]
	matrix = []
	for i in range(0, rows_count):
		matrix.append(_read_row(sep=sep, converters=converters[i % len(converters)]))
	return matrix

def _find_element_in_row(row, element):
	for j in range(0, len(row)):
		if row[j] == element:
			return j
	return None

def _find_element_in_matrix(matrix, element):
	for i in range(0, len(matrix)):
		row = matrix[i]
		j = _find_element_in_row(row, element)
		if j is not None:
			return (i, j)
	return None

def main():
	matrix: List[List[int]] = _read_matrix(5, converters=[[int]])
	(i, j) = _find_element_in_matrix(matrix, 1)
	middle = 5 / 2 - 1
	result = abs(math.ceil(middle - i)) + abs(math.ceil(middle - j))
	return result
print(main())


for i in range(5):
	row = input().split(' ')
	if '1' in row:
		column_index = i + 1
		row_index = row.index('1') + 1
		break
print(abs(column_index - 3) + abs(row_index - 3))


i = 0
while i <= 4:
	(a, b, c, d, e) = input('').split(' ')
	p = int(a)
	q = int(b)
	r = int(c)
	s = int(d)
	t = int(e)
	f = (p, q, r, s, t)
	if any(f) == 1 and (i == 0 or i == 4):
		if p == 1 or t == 1:
			k = 4
		elif q == 1 or s == 1:
			k = 3
		else:
			k = 2
	elif any(f) == 1 and (i == 1 or i == 3):
		if p == 1 or t == 1:
			k = 3
		elif q == 1 or s == 1:
			k = 2
		else:
			k = 1
	elif any(f) == 1 and i == 2:
		if p == 1 or t == 1:
			k = 2
		elif q == 1 or s == 1:
			k = 1
		else:
			k = 0
	i += 1
print(k)


import math
n = 0
i = 0
k = 0
m = 0
pg = 0
pv = 0
for n in range(5):
	a = [int(i) for i in input().split(' ')]
	for i in range(5):
		if a[i] == 1:
			k = i + 1
			m = n + 1
pg = abs(3 - k)
pv = abs(3 - m)
print(pg + pv)


def main():
	ans = 0
	for i in range(5):
		row = input().split()
		for j in range(5):
			if row[j] == '1':
				ans = abs(2 - i) + abs(2 - j)
	print(ans)
main()


V = 0
for i in range(5):
	L = input().split()
	if L.count('1') == 1:
		v = abs(2 - i)
		v += abs(L.index('1') - 2)
print(int(v))


col = 0
row = 0
mylist = []
for i in range(5):
	x = []
	(a, b, c, d, e) = map(int, input().split())
	x.append(a)
	x.append(b)
	x.append(c)
	x.append(d)
	x.append(e)
	mylist.append(x)
for j in range(len(mylist)):
	y = mylist[j]
	add = 0
	for k in range(len(y)):
		add = add + y[k]
	if add > 0:
		if j >= 2:
			col = j - 2
			if y[3] > y[2] or y[1] > y[2]:
				row = 1
			elif y[4] > y[2] or y[0] > y[2]:
				row = 2
			else:
				row = 0
		else:
			col = 2 - j
			if y[3] > y[2] or y[1] > y[2]:
				row = 1
			elif y[4] > y[2] or y[0] > y[2]:
				row = 2
			else:
				row = 0
		print(row + col)


l = []
for i in range(0, 5):
	(w1, w2, w3, w4, w5) = input('').split()
	w = w1 + w2 + w3 + w4 + w5
	l.append(w)
	x = w.find('1')
	if x != -1:
		y = x
		j = i
print(abs(y - 2) + abs(j - 2))


x = 5
matrix = []
while x > 0:
	matrix.append(input().replace(' ', ''))
	x = x - 1
for i in range(0, 5):
	if matrix[i].find('1') >= 0:
		ind = matrix[i].find('1') + 1
		ind2 = i + 1
		print(abs(3 - ind) + abs(3 - ind2))
		break


matrix = []
for x in range(0, 5):
	matrix.append(list(map(int, input().split(' '))))
posOfOne = (0, 0)
for x in range(0, 5):
	for y in range(0, 5):
		if matrix[x][y] == 1:
			posOfOne = (x, y)
counter = 0
offset = [0, 0]
while offset[0] + posOfOne[0] != 2:
	if posOfOne[0] > 2:
		offset[0] -= 1
		counter += 1
	elif posOfOne[0] < 2:
		offset[0] += 1
		counter += 1
	else:
		print('error')
while offset[1] + posOfOne[1] != 2:
	if posOfOne[1] > 2:
		offset[1] -= 1
		counter += 1
	elif posOfOne[1] < 2:
		offset[1] += 1
		counter += 1
	else:
		print('error')
print(counter)


def main():
	moves = 0
	matrix = list()
	x = 0
	y = 0
	for x in range(5):
		nums = input()
		matrix.append(nums)
	for i in range(len(matrix)):
		s = matrix[i].replace(' ', '')
		if '1' in s:
			x = s.index('1')
			y = i
			break
	print(abs(y - 2) + abs(x - 2))
main()


import sys
from math import *
stdin = sys.stdin
stdout = sys.stdout
mat = [[int(_) for _ in stdin.readline().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			(ii, ij) = (i, j)
stdout.write(f'{abs(2 - ii) + abs(2 - ij)}')


row = 3
column = 3
for i in range(1, 5 + 1):
	string = list(map(int, input().split(' ')))
	for j in range(5):
		if string[j] == 1:
			result = abs(i - 3) + abs(j + 1 - 3)
			print(result)


lst = []
for i in range(5):
	a = [int(item) for item in input().split()]
	lst.append(a)
for i in range(5):
	for j in range(5):
		if lst[i][j] == 1:
			break
		else:
			continue
	if lst[i][j] == 1:
		break
	else:
		continue
count = abs(2 - i) + abs(2 - j)
print(count)


(row, column) = (0, 0)
for i in range(5):
	l = input().split()
	for j in range(5):
		if l[j] == '1':
			(row, column) = (i, j)
print(abs(row - 2) + abs(column - 2))


for i in range(5):
	s = [int(k) for k in input().split()]
	for j in range(5):
		if s[j] == 1:
			print(abs(2 - i) + abs(2 - j))


from typing import List

def solve(*, _input: List[List[int]], current_index: int=0) -> int:
	return abs(_input[current_index].index(1) - 2) + abs(current_index - 2) if 1 in _input[current_index] else solve(_input=_input, current_index=current_index + 1)
solution = solve(_input=[list(map(int, input().split())) for _ in range(5)])
print(solution)


matrix = [[int(j) for j in input().split()] for i in range(5)]
for row in matrix:
	if row.count(1) == 1:
		n = row.index(1)
		m = matrix.index(row)
		print(abs(m - 2) + abs(n - 2))
	else:
		pass


matrix = []
(i, k, d, h) = (0, 0, 0, 0)
(col, roww) = (0, 0)
c = False
while i < 5:
	row = list(map(str, input().split()))
	matrix.append(row)
	i = i + 1
while k < 5:
	h = 0
	while h < 5:
		if matrix[k][h] == '1':
			roww = k
			col = h
			c = True
			break
		else:
			h = h + 1
	k = k + 1
	if c == True:
		break
if roww > 2:
	while roww != 2:
		roww = roww - 1
		d = d + 1
elif roww < 2:
	while roww != 2:
		roww = roww + 1
		d = d + 1
if col > 2:
	while col != 2:
		col = col - 1
		d = d + 1
elif col < 2:
	while col != 2:
		col = col + 1
		d = d + 1
print(d)


a1 = list((int(x) for x in input().split()))
a2 = list((int(x) for x in input().split()))
a3 = list((int(x) for x in input().split()))
a4 = list((int(x) for x in input().split()))
a5 = list((int(x) for x in input().split()))
col = 0
row = 0
if 1 in a1:
	col = a1.index(1)
	row = 1
if 1 in a2:
	col = a2.index(1)
	row = 2
elif 1 in a3:
	col = a3.index(1)
	row = 3
elif 1 in a4:
	col = a4.index(1)
	row = 4
elif 1 in a5:
	col = a5.index(1)
	row = 5
print(abs(3 - row) + abs(3 - (col + 1)))


matrix = []
for i in range(5):
	matrix = [int(i) for i in input().split()]
	if 1 in matrix:
		line = i
		column = matrix.index(1)
x = abs(line + 1 - 3)
y = abs(column + 1 - 3)
sum = x + y
print(sum)


flag = 0
for i in range(0, 5):
	array = list(map(int, input().split()))
	for j in range(0, 5):
		if array[j] == 1:
			row = 3 - i - 1
			col = 3 - j - 1
			flag = 1
			break
	if flag == 1:
		break
print(abs(row) + abs(col))


import sys
try:
	sys.stdin = open('inputs.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
finally:
	input = sys.stdin.readline
	print = sys.stdout.write
for row in range(1, 6):
	this_row = input().split()
	try:
		col = this_row.index('1')
		out = abs(row - 3) + abs(col - 2)
		print(str(out))
		break
	except:
		pass


numrows = 5
bmposition = (2, 2)
matrix = []

def minmoves(targetpostion):
	rowbest = abs(bmposition[0] - targetpostion[0])
	colbest = abs(bmposition[1] - targetpostion[1])
	minmovesresult = rowbest + colbest
	return minmovesresult
for i in range(numrows):
	row = list(map(int, input().split()))
	matrix.append(row)
for (index1, item) in enumerate(matrix):
	for (index2, item2) in enumerate(item):
		if item2 == 1:
			targetpostion = (index1, index2)
			finalresult = minmoves(targetpostion)
			print(finalresult)
			break


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
for j in range(5):
	for k in range(5):
		if arr[j][k] == 1:
			r = abs(j - 2) + abs(k - 2)
			break
print(r)


a = [list(map(int, input().split())) for i in range(5)]
g = a[2][2]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			break
	if a[i][j] == 1:
		break
c = a[i][j]
s = 0
if i == 0 or i == 4:
	s += 2
if i == 1 or i == 3:
	s += 1
s += abs(3 - (j + 1))
print(s)


p = 0
x = 0
while x < 5:
	x = x + 1
	ALL = input()
	(a, b, c, d, e) = ALL.split(' ')
	if a == '1' or e == '1':
		p = p + 2
	elif b == '1' or d == '1':
		p = p + 1
	if a == '1' or b == '1' or c == '1' or (d == '1') or (e == '1'):
		if x == 1 or x == 5:
			p = p + 2
		elif x == 2 or x == 4:
			p = p + 1
print(p)


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

def index_2d(myList, v):
	for (i, x) in enumerate(myList):
		if v in x:
			return [i, x.index(v)]
ind = index_2d(l, 1)
ans = abs(ind[0] - 2) + abs(ind[1] - 2)
print(ans)


def find(a):
	b = []
	for i in range(5):
		for j in range(5):
			if a[i][j] == 1:
				b.append(i)
				b.append(j)
				return b
a = []
for i in range(5):
	a.append(list(map(int, input().split())))
b = find(a)
print(abs(b[0] - 2) + abs(b[1] - 2))


m = []
for i in range(5):
	l = list(map(int, input().strip().split()[:5]))
	m.append(l)
(r, c) = (0, 0)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			r = i + 1
			c = j + 1
			break
r1 = abs(r - 3)
r2 = abs(c - 3)
print(r1 + r2)


import math
b = []
for i in range(5):
	a = input().split()
	b.append(a)
for i in range(5):
	for j in range(5):
		if b[i][j] == '1':
			g = abs(i - 2)
			h = abs(j - 2)
			k = g + h
print(k)


for i in range(5):
	arr = input().split()
	if '1' in arr:
		j = arr.index('1')
		ans = abs(i - 2) + abs(j - 2)
		break
print(ans)


arr = []
for i in range(1, 6):
	temp = list(map(int, input().split()))
	if sum(temp) == 1:
		rows = i
		cols = temp.index(1) + 1
print(abs(rows - 3) + abs(cols - 3))


lis = []
j = 0
for i in range(1, 6):
	lis = list(map(int, input().split()))
	if lis.__contains__(1):
		j = lis.index(1) + 1
		break
print(abs(3 - i) + abs(3 - j))


matrix = []
for i in range(5):
	lr = list(map(int, input().split()))
	matrix.append(lr)
c = 0
for column in matrix:
	if 1 in column:
		alpha = matrix.index(column)
		while alpha != len(matrix) // 2:
			if alpha > len(matrix) // 2:
				alpha -= 1
				(matrix[alpha + 1], matrix[alpha]) = (matrix[alpha], matrix[alpha + 1])
			elif alpha < len(matrix) // 2:
				alpha += 1
				(matrix[alpha - 1], matrix[alpha]) = (matrix[alpha], matrix[alpha - 1])
			c += 1
		for i in range(len(matrix[alpha])):
			if matrix[alpha][i] == 1:
				beta = i
		while beta != len(matrix[alpha]) // 2:
			if beta > len(matrix[alpha]) // 2:
				beta -= 1
				(matrix[alpha][beta + 1], matrix[alpha][beta]) = (matrix[alpha][beta], matrix[alpha][beta + 1])
			elif beta < len(matrix[alpha]) // 2:
				beta += 1
				(matrix[alpha][beta - 1], matrix[alpha][beta]) = (matrix[alpha][beta], matrix[alpha][beta - 1])
			c += 1
print(c)


a = 0
for _ in range(0, 5):
	l = list(map(int, input().split()))
	if 1 in l:
		a = abs(_ - 2) + abs(l.index(1) - 2)
print(a)


n = []
for i in range(5):
	n.append(input().strip().split())
for i in range(5):
	for j in range(5):
		if n[i][j] == '1':
			print(abs(i + 1 - 3) + abs(j + 1 - 3))


for i in range(5):
	s = input().split()
	for j in range(len(s)):
		if s[j] == '1':
			print(abs(2 - i) + abs(2 - j))
			exit()


def main():
	(x, y) = (-1, -1)
	for i in range(5):
		s = input().split()
		if s.count('1'):
			x = s.index('1') + 1
			y = i + 1
	print(abs(x - 3) + abs(y - 3))
main()


n = [[], [], [], [], []]
for i in range(5):
	n[i] = input().split()
for l in range(5):
	for k in range(5):
		if n[l][k] == '1':
			ans = (l, k)
			break
print(abs(2 - ans[0]) + abs(2 - ans[1]))


matrix = [[int(i) for i in input().split()], [int(i) for i in input().split()], [int(i) for i in input().split()], [int(i) for i in input().split()], [int(i) for i in input().split()]]
need_column = 0
need_row = 0
for row in range(5):
	for col in range(5):
		if matrix[row][col] == 1:
			need_column = col + 1
			need_row = row + 1
print(abs(3 - need_row) + abs(3 - need_column))


def beautiful():
	list1 = input().split()
	list2 = input().split()
	list3 = input().split()
	list4 = input().split()
	list5 = input().split()
	if '1' in list1:
		x = list1.index('1')
		y = 2
		xmovement = abs(x - 2)
		print(y + xmovement)
	elif '1' in list2:
		x = list2.index('1')
		y = 1
		xmovement = abs(x - 2)
		print(y + xmovement)
	elif '1' in list3:
		x = list3.index('1')
		xmovement = abs(x - 2)
		print(xmovement)
	elif '1' in list4:
		x = list4.index('1')
		y = 1
		xmovement = abs(x - 2)
		print(y + xmovement)
	elif '1' in list5:
		x = list5.index('1')
		y = 2
		xmovement = abs(x - 2)
		print(y + xmovement)
beautiful()


(row_index, col_index) = (0, 0)
for i in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		(row_index, col_index) = (i + 1, row.index(1) + 1)
print(abs(row_index - 3) + abs(col_index - 3))


indexRow = 0
indexColumn = 0
for i in range(0, 5):
	line = input().split(' ')
	try:
		indexColumn = line.index('1')
		indexRow = i
	except:
		pass
movement = abs(indexRow - 2) + abs(indexColumn - 2)
print(movement)


for i in range(1, 6):
	l = list(map(int, input().split()))
	if 1 in l:
		x = i
		y = l.index(1)
ans = abs(x - 3) + abs(y - 2)
print(ans)


for i in range(5):
	inpuT = input()
	booL = '1' in inpuT
	if booL:
		x = 1 + inpuT.index('1') // 2
		y = i + 1
		break
print(abs(x - 3) + abs(y - 3))


row1 = input().split()
row2 = input().split()
row3 = input().split()
row4 = input().split()
row5 = input().split()
moves = 0
if '1' in row1:
	moves += 2
	x = row1.index('1')
	if x == 0 or x == 4:
		moves += 2
	elif x == 1 or x == 3:
		moves += 1
elif '1' in row2:
	moves += 1
	x = row2.index('1')
	if x == 0 or x == 4:
		moves += 2
	elif x == 1 or x == 3:
		moves += 1
elif '1' in row4:
	moves += 1
	x = row4.index('1')
	if x == 0 or x == 4:
		moves += 2
	elif x == 1 or x == 3:
		moves += 1
elif '1' in row5:
	moves += 2
	x = row5.index('1')
	if x == 0 or x == 4:
		moves += 2
	elif x == 1 or x == 3:
		moves += 1
else:
	print()
	x = row3.index('1')
	if x == 0 or x == 4:
		moves += 2
	elif x == 1 or x == 3:
		moves += 1
print(moves)


arr = [[0 for x in range(5)] for y in range(5)]
for i in range(5):
	str = input()
	list = str.split(' ')
	for j in range(5):
		arr[i][j] = int(list[j])
targetX = 2
targetY = 2
weAreX = 0
weAreY = 0
sumMoves = 0
for x in range(5):
	if arr[x].count(1) != 0:
		weAreX = x
		weAreY = arr[x].index(1)
		sumMoves += abs(weAreX - targetX)
		sumMoves += abs(weAreY - targetY)
		print(sumMoves)


m = [[]]
m = [[int(i) for i in input().split(' ')] for j in range(5)]

def get_val(m):
	for i in range(5):
		for j in range(5):
			if m[i][j] == 1:
				return abs(3 - (i + 1)) + abs(3 - (j + 1))
print(get_val(m))


i = 3
j = 3
nums = ''
n = 1
row = 0
column = 0
while n < 6:
	nums = input().replace(' ', '')
	if nums.__contains__('1'):
		row = n
		column = nums.index('1') + 1
		break
	n += 1
print(abs(j - row) + abs(i - column))


a = []
for i in range(5):
	b = list(input().split())
	a.append(b)
flag = 0
(x, y) = (0, 0)
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == '1':
			(x, y) = (i, j)
			flag = 1
			break
	if flag == 1:
		break
c = abs(2 - x) + abs(2 - y)
print(c)


def list_turning(x: object) -> object:
	z = ['none'] * len(x)
	for i in range(len(x)):
		z[i] = x[i]
	return z

def position(x):
	y = 100
	for i in range(len(x)):
		if x[i] == '1':
			y = i
	return y
fi = input()
sec = input()
th = input()
fo = input()
fif = input()
fil = list_turning(fi)
secl = list_turning(sec)
thl = list_turning(th)
fol = list_turning(fo)
fifl = list_turning(fif)
filp = position(fil)
seclp = position(secl)
thlp = position(thl)
folp = position(fol)
fiflp = position(fifl)
turns = 0
if filp == 0 or filp == 8:
	turns = 2
elif filp == 2 or filp == 6:
	turns = 1
elif filp == 4:
	turns = 0
if seclp == 0 or seclp == 8:
	turns = 2
elif seclp == 2 or seclp == 6:
	turns = 1
elif seclp == 4:
	turns = 0
if thlp == 0 or thlp == 8:
	turns = 2
elif thlp == 2 or thlp == 6:
	turns = 1
elif thlp == 4:
	turns = 0
if folp == 0 or folp == 8:
	turns = 2
elif folp == 2 or folp == 6:
	turns = 1
elif folp == 4:
	turns = 0
if fiflp == 0 or fiflp == 8:
	turns = 2
elif fiflp == 2 or fiflp == 6:
	turns = 1
elif fiflp == 4:
	turns = 0
if filp != 100 or fiflp != 100:
	turns += 2
elif seclp != 100 or folp != 100:
	turns += 1
print(turns)


vac = []
for i in range(5):
	vac.append(input())
	a = list(map(int, vac[i].split()))
	if sum(a) == 1:
		for j in range(5):
			if a[j] == 1:
				d = abs(i - 2) + abs(j - 2)
			else:
				continue
	else:
		continue
print(d)


count = 0
for i in range(5):
	a = list(map(int, input().strip().split()))[:5]
	if 1 in a:
		row = i + 1
		for i in range(5):
			if a[i] == 1:
				col = i + 1
		break
if row == 1 or row == 5:
	count += 2
elif row == 2 or row == 4:
	count += 1
if col == 1 or col == 5:
	count += 2
elif col == 2 or col == 4:
	count += 1
print(count)


posr = 0
posc = 0
for i in range(1, 6):
	row = input()
	if '1' in row:
		posr = i
		posc = list(map(lambda x: int(x), row.split())).index(1) + 1
		break
print(abs(3 - posr) + abs(3 - posc))


import sys

class MyReader:

	def __init__(self):
		filename = 'file.in'
		if self.isLocal():
			self.file = open(filename)
		self.str = ['']
		self.ind = 1

	def isLocal(self):
		return len(sys.argv) > 1 and sys.argv[1] == 'SCHULLZ'

	def nextString(self):
		if self.isLocal():
			return self.file.read()
		else:
			return input()

	def nextInt(self):
		return int(self.nextToken())

	def nextToken(self):
		if self.ind >= len(self.str):
			self.ind = 0
			self.str = self.nextString().split()
		self.ind += 1
		return self.str[self.ind - 1]
rdr = MyReader()
x = -1
y = -1
for i in range(0, 5):
	for j in range(0, 5):
		a = rdr.nextInt()
		if a == 1:
			x = i
			y = j
print(abs(x - 2) + abs(y - 2))


for x in range(5):
	arr = [int(n) for n in input().split()]
	for i in range(5):
		if arr[i] == 1:
			print(abs(2 - x) + abs(2 - i))
			exit


from sys import stdin, stdout

def stdinhack():
	for line in stdin:
		yield line
next_line = lambda : next(stdinhack()).split()
write = lambda x: stdout.write(x)

def solve():
	a = []
	for _ in range(5):
		a.append(list(map(int, next_line())))
	(i, j) = (-1, -1)
	for ii in range(5):
		for jj in range(5):
			if a[ii][jj] == 1:
				(i, j) = (ii, jj)
	ans = abs(i - 2) + abs(j - 2)
	print(ans)
	return
solve()


ans = 0
for i in range(5):
	l = [int(x) for x in input().split()]
	for j in range(5):
		ans += l[j] * (abs(i - 2) + abs(j - 2))
print(ans)


n = 5
lst = []
while n > 0:
	row = input().split()
	lst.append(row)
	n -= 1
for sub in lst:
	if '1' in sub:
		tup = (lst.index(sub), sub.index('1'))
print(abs(2 - tup[0]) + abs(2 - tup[1]))


matrix = []
rOne = 0
cOne = 0
for i in range(5):
	temp = input()
	temp = temp.split(' ')
	if '1' in temp:
		rOne = i
		cOne = temp.index('1')
	matrix.append(temp)
counter = 0
while rOne != 2:
	if rOne > 2:
		rOne -= 1
	else:
		rOne += 1
	counter += 1
while cOne != 2:
	if cOne > 2:
		cOne -= 1
	else:
		cOne += 1
	counter += 1
print(counter)


d = []
for i in range(5):
	d.append(input().split())
for i in range(len(d)):
	for j in range(len(d)):
		d[i][j] = int(d[i][j])
x = 0
y = 0
for i in range(len(d)):
	for j in range(len(d)):
		if d[i][j] == 1:
			(x, y) = (i, j)
k = 0
while not (x == 2 and y == 2):
	if x < 2:
		x = x + 1
		k = k + 1
		if y < 2:
			y = y + 1
			k = k + 1
		elif y > 2:
			y = y - 1
			k = k + 1
	elif x > 2:
		x = x - 1
		k = k + 1
		if y > 2:
			y = y - 1
			k = k + 1
		elif y < 2:
			y = y + 1
			k = k + 1
	elif x == 2:
		if y < 2:
			y = y + 1
			k = k + 1
		elif y > 2:
			y = y - 1
			k = k + 1
else:
	print(k)


for i in range(5):
	x = list(map(int, input().split()))
	for j in range(5):
		if x[j] == 1:
			(ax, ay) = (i + 1, j + 1)
	x.clear()
print(abs(3 - ax) + abs(3 - ay))


t_a = [list(map(int, input().split())) for i in range(5)]
for r in range(1, len(t_a) + 1):
	for c in range(1, len(t_a) + 1):
		if t_a[r - 1][c - 1] == 1:
			print(abs(r - 3) + abs(c - 3))
			break
		else:
			continue
		break


for i in range(5):
	x = input()[::2]
	if '1' in x:
		a = x.find('1')
		break
print(abs(2 - a) + abs(2 - i))


matrix = []
row_1 = 0
col_1 = 0
for i in range(1, 6):
	row = input()
	if '1' in row:
		row_1 = i
		col_1 = row.find('1') / 2 + 1
	matrix.append(row)
swaps = 0
if row_1 >= 3:
	swaps = swaps + row_1 - 3
else:
	swaps = swaps + 3 - row_1
if col_1 >= 3:
	swaps = swaps + col_1 - 3
else:
	swaps = swaps + 3 - col_1
print(int(swaps))


a = []
b = 5
for i in range(b):
	a.append(list(input().split()[:b]))
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == '1':
			break
	if a[i][j] == '1':
		break
c = abs(3 - (i + 1))
d = abs(3 - (j + 1))
print(c + d)


NUMLINES = 5
NUMCOLS = 5

def main():
	middlerow = NUMLINES // 2 + 1
	middlecol = NUMCOLS // 2 + 1
	for line in range(NUMLINES):
		input_ = input().replace(' ', '')
		if '1' in input_:
			row = line
			col = input_.find('1')
	numop = abs(row + 1 - middlerow) + abs(col + 1 - middlecol)
	print(numop)
	return numop
main()


r = 0
c = -1
for _ in range(5):
	a = list(map(int, input().split()))
	if max(a) == 1:
		c = a.index(1)
		break
	else:
		r += 1
print(abs(r - 2) + abs(c - 2))


def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())
l = ['a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'O', 'I', 'U', 'Y']
n = 5
a = [[int(j) for j in input().split()] for i in range(n)]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			c = i
			d = j
			break
ans = abs(2 - c) + abs(2 - d)
print(ans)


l = []
for i in range(5):
	a = input().split()
	l.extend(a)
l = ''.join(l)
n = l.find('1')
row = n // 5
coloumn = n % 5
counter = abs(coloumn - 2) + abs(row - 2)
print(counter)


for i in range(5):
	l = [int(n) for n in input().split()]
	if 1 in l:
		l.index(1)
		ans = abs(2 - i) + abs(2 - l.index(1))
print(ans)


mat = []
for i in range(5):
	l = list(map(int, input().split()))
	mat.append(l)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			row = i
			col = j
ans1 = abs(row - 2) + abs(col - 2)
print(ans1)


matrix = []
for i in range(5):
	row = list(map(int, input().split()))
	matrix.append(row)
xpos = 0
ypos = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			xpos = i
			ypos = j
moves = abs(ypos - 2)
moves += abs(xpos - 2)
print(moves)


a = []
for i in range(5):
	row = input().split()
	for i in range(len(row)):
		row[i] = int(row[i])
	a.append(row)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			i = i - 2
			j = j - 2
			z = abs(i) + abs(j)
			print(z)
			break


a = []
(z, s) = (0, 0)
(zl, sl) = (0, 0)
zuege = 0
for _ in range(5):
	a.append(list(map(int, input().split())))
for i in a:
	z += 1
	for j in i:
		if j == 1:
			s += 1
			(zl, sl) = (z, s)
		else:
			s += 1
	s = 0
if zl < 3:
	zuege += 3 - zl
elif zl > 3:
	zuege += zl - 3
if sl < 3:
	zuege += 3 - sl
elif sl > 3:
	zuege += sl - 3
print(zuege)


def searchmat(a):
	for i in range(5):
		for j in range(5):
			if a[i][j] == 1:
				return (i, j)
	pass
a = []
moves = 0
for i in range(5):
	a.append(list(map(int, input().split(' '))))
(i, j) = searchmat(a)
moves = abs(i - 2) + abs(j - 2)
print(moves)


a = []
for i in range(5):
	a.append(input().split())
for i in range(5):
	for j in range(5):
		if int(a[i][j]) == 1:
			c = i + 1
			d = j + 1
print(abs(3 - c) + abs(3 - d))


from sys import stdin

def indices(matriz):
	for i in range(len(matriz)):
		if '1' in matriz[i]:
			return (i + 1, matriz[i].index('1') + 1)
matriz = []
for i in range(5):
	matriz.append([x for x in stdin.readline().split()])
(i, j) = indices(matriz)
print(abs(i - 3) + abs(j - 3))


a1 = [[int(i) for i in input().split()]]
a1.append([int(i) for i in input().split()])
a1.append([int(i) for i in input().split()])
a1.append([int(i) for i in input().split()])
a1.append([int(i) for i in input().split()])
for (c, i) in enumerate(a1):
	if 1 in i:
		x = c
	for z in i:
		if z == 1:
			y = i.index(z)
print(abs(y - 2) + abs(x - 2))


a = [[0 for i in range(0, 5)] for j in range(0, 5)]
x = 0
y = 0
for i in range(5):
	n = input().split(' ')
	for j in range(5):
		a[i][j] = int(n[j])
		if a[i][j] == 1:
			x = i
			y = j
l = abs(x - 2) + abs(y - 2)
print(l)


r = 0
for i in range(1, 6):
	s = input()
	if '1' in s:
		r = abs(2 - s.split().index('1')) + abs(3 - i)
print(r)


for i in range(5):
	n = [int(n) for n in input().split()]
	for j in n:
		if j == 1:
			y = n.index(1) + 1
			x = i + 1
			break
	n.clear()
a = x - 3
b = y - 3
if a > 0 and b > 0:
	n = a + b
elif a < 0 and b > 0:
	n = -a + b
elif a > 0 and b < 0:
	n = a + -b
elif a == 0 and b > 0:
	n = b
elif a == 0 and b < 0:
	n = -b
elif a > 0 and b == 0:
	n = a
elif a == 0 and b < 0:
	n = -b
else:
	n = -a + -b
print(n)


lst = []
for i in range(5):
	lst = [int(x) for x in input().split()]
	if 1 in lst:
		col = lst.index(1)
		row = i
print(abs(row - 2) + abs(col - 2))


(a, b) = (-1, -1)
for i in range(1, 6):
	c = input().split()
	for j in range(1, 6):
		if c[j - 1] == '1':
			a = i
			b = j
print(abs(a - 3) + abs(b - 3))


mat = []
for i in range(5):
	s = [int(x) for x in input().split()]
	mat.append(s)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))


line1 = [int(x) for x in input().split()]
line2 = [int(x) for x in input().split()]
line3 = [int(x) for x in input().split()]
line4 = [int(x) for x in input().split()]
line5 = [int(x) for x in input().split()]
for col in range(5):
	v = abs(col - 2)
	if line1[col] == 1:
		print(v + 2)
		break
	if line2[col] == 1:
		print(v + 1)
		break
	if line3[col] == 1:
		print(v)
		break
	if line4[col] == 1:
		print(v + 1)
		break
	if line5[col] == 1:
		print(v + 2)
		break


import sys
for i in range(1, 6):
	a = input()
	for j in range(0, 9, 2):
		if a[j] == '1':
			print(abs(i - 3) + abs(j // 2 + 1 - 3))
			sys.exit()


a = []
for i in range(5):
	b = input('').split()
	a.append(b)
(x, y) = (0, 0)
for j in range(5):
	for k in range(5):
		if a[j][k] == '1':
			x = j
			y = k
(ans1, ans2) = (abs(x - 2), abs(y - 2))
print(ans1 + ans2)


x = 0
y = 0
for row in range(1, 6):
	_input = input().split()
	for col in range(1, 6):
		no = _input[col - 1]
		if no == '1':
			x = row
			y = col
print(abs(3 - x) + abs(3 - y))


l = []
for i in range(5):
	l.append([int(i) for i in input().split()])
	if 1 in l[-1]:
		m = i + 1
		n = l[-1].index(1) + 1
if m < 3:
	m = 3 - m
else:
	m = m - 3
if n < 3:
	n = 3 - n
else:
	n = n - 3
print(m + n)


One = True
k = 0
j = 0
while One:
	l = list(map(int, input('').split()))
	k += 1
	if 1 in l:
		One = False
		j = l.index(1) + 1
steps = abs(k - 3) + abs(j - 3)
print(steps)


place = ()
for i in range(5):
	line = input().split(' ')
	for (j, ch) in enumerate(line):
		if ch == '1':
			place = (i, j)
print(abs(place[0] - 2) + abs(place[1] - 2))


a = [0, 0, 0, 0, 0]
for i in range(5):
	a[i] = list(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			g = i
			h = j
c = 0

def gg(c):
	if g == 0:
		c = c + 2
	elif g == 1:
		c = c + 1
	elif g == 2:
		c += 0
	elif g == 3:
		c = c + 1
	elif g == 4:
		c = c + 2
	return hh(c)

def hh(c):
	if h == 0:
		c += 2
	elif h == 1:
		c += 1
	elif h == 2:
		c += 0
	elif h == 3:
		c += 1
	elif h == 4:
		c += 2
	return c
d = gg(c)
print(d)


matrix = [input().split() for i in range(5)]
print(''.join((str(abs(2 - i) + abs(2 - matrix[i].index('1'))) for i in range(5) if matrix[i].count('1'))))


def main():
	for i in range(5):
		line = list(map(int, input().split()))
		if 1 in line:
			iind = i
			jind = line.index(1)
	print(abs(2 - iind) + abs(2 - jind))
main()


import math
for i in range(5):
	a = list(map(int, input().split()))
	for x in range(5):
		if a[x] == 1:
			b = x + 1
			c = i + 1
print(int(math.fabs(3 - b) + math.fabs(3 - c)))


count_x = 0
count_y = 0
list1 = list()
for i in range(1, 6):
	inp = input().split(' ')
	inp2 = [int(a) for a in inp]
	if inp2[0] == 1 or inp2[4] == 1:
		if i == 1 or i == 5:
			count_x += 2
			count_y += 2
		elif i == 2 or i == 4:
			count_x += 2
			count_y += 1
		else:
			count_x += 2
			count_y += 0
	elif inp2[1] == 1 or inp2[3] == 1:
		if i == 1 or i == 5:
			count_x += 1
			count_y += 2
		elif i == 2 or i == 4:
			count_x += 1
			count_y += 1
		else:
			count_x += 1
			count_y += 0
	elif inp2[2] == 1:
		if i == 1 or i == 5:
			count_x += 0
			count_y += 2
		elif i == 2 or i == 4:
			count_x += 0
			count_y += 1
		else:
			count_x += 0
			count_y += 0
print(int(count_x + count_y))


z = [[0 for i in range(5)] for j in range(5)]
for i in range(5):
	x = list(map(int, input().split()))
	for j in range(5):
		z[i][j] = x[j]
for i in range(5):
	for j in range(5):
		if z[i][j] == 1:
			f = i
			k = j
left = abs(2 - f)
right = abs(2 - k)
ans = left + right
print(ans)


arr_matrix = []
for i in range(5):
	arr_matrix.append(input().split())
x_axis = 0
y_axis = 0
for i in range(5):
	for j in range(5):
		if arr_matrix[i][j] == '1':
			x_axis = 2 - i
			y_axis = 2 - j
if y_axis < 0:
	y_axis *= -1
if x_axis < 0:
	x_axis *= -1
print(f'{x_axis + y_axis}')


ONE = 1
I_TARGET = 2
J_TARGET = 2

def main():
	matrix = []
	for i in range(0, 5):
		string = list(map(int, input().split()))
		matrix.append(string)
	i_one = 0
	j_one = 0
	for i in range(0, 5):
		if ONE in matrix[i]:
			i_one = i
			j_one = matrix[i].index(ONE)
	motions = abs(I_TARGET - i_one) + abs(J_TARGET - j_one)
	print(motions)
main()


n = 5
x = []
t = 0
for i in range(n):
	q = map(int, input().split())
	q = list(q)
	x.append(q)
for i in range(n):
	for j in range(n):
		if x[i][j] == 1:
			t = abs(3 - (i + 1)) + abs(3 - (j + 1))
		else:
			t = t
print(t)


a = []
t = 5
while t > 0:
	b = list(map(int, input().split()))
	a.append(b)
	t = t - 1
for i in range(len(a)):
	if 1 in a[i]:
		b = abs(i - 2)
		c = a[i].index(1)
		d = abs(c - 2)
		final = b + d
		print(final)
		break


for i in range(5):
	w = list(input())
	if '1' in w:
		v = abs(i - 2) + abs(w.index('1') // 2 + 1 - 3)
	else:
		pass
print(v)


l = []
for i in range(5):
	l1 = [int(x) for x in input().split()]
	l.append(l1)
x = 0
y = 0
for i in range(5):
	if l[i].count(1) == 1:
		x = i + 1
		y = l[i].index(1) + 1
print(abs(x - 3) + abs(y - 3))


def main():
	for i in range(1, 6):
		a = input().split()
		for j in range(1, 6):
			if a[j - 1] == '1':
				print(abs(3 - i) + abs(3 - j))
				return
main()


co = [0, 0]
for i in range(5):
	s = input().split()
	if '1' in s:
		co[0] = i + 1
		co[1] = s.index('1') + 1
print(abs(3 - co[0]) + abs(3 - co[1]))


for i in range(5):
	s = input()
	if '1' in s:
		x = i
		sp = s.split(' ')
		y = sp.index('1')
print(abs(x - 2) + abs(y - 2))


(r, c) = (-1, -1)
for irow in range(5):
	row = []
	while len(row) == 0:
		row = input().split()
	for (icol, val) in enumerate(row):
		if val == '1':
			print(abs(irow - 2) + abs(icol - 2))


def indices(mat, element):
	for (i, row) in enumerate(mat):
		if element in row:
			return (i, row.index(element))
matrix = [list(map(int, input().split())) for row in range(5)]
indices_of_one = indices(matrix, 1)
no_moves = abs(2 - indices_of_one[0]) + abs(2 - indices_of_one[1])
print(no_moves)


matrix = list()
for i in range(0, 5):
	matrix.append(input().split())

def find(matrix):
	i = r = c = 0
	OneFind = False
	while i < 5 and (not OneFind):
		j = 0
		while j < 5 and (not OneFind):
			if matrix[i][j] == '1':
				r = i
				c = j
				OneFind = True
			j += 1
		i += 1
	return abs(r - 2) + abs(c - 2)
print(find(matrix))


row1 = input()
row2 = input()
row3 = input()
row4 = input()
row5 = input()

def one_row(row):
	row = row.replace(' ', '')
	return abs(2 - row.find('1'))
if '1' in row1:
	ones = one_row(row1)
	ones2 = 2
if '1' in row2:
	ones = one_row(row2)
	ones2 = 1
if '1' in row3:
	ones = one_row(row3)
	ones2 = 0
if '1' in row4:
	ones = one_row(row4)
	ones2 = 1
if '1' in row5:
	ones = one_row(row5)
	ones2 = 2
result = ones + ones2
print(result)


import math
for x in range(1, 6):
	s = str(input())
	if '1' in s:
		y = s.split(' ').index('1') + 1
		coor = (x, y)
print(int(math.fabs(coor[0] - 3) + math.fabs(coor[1] - 3)))


row1 = [int(i) for i in input().split()]
row2 = [int(i) for i in input().split()]
row3 = [int(i) for i in input().split()]
row4 = [int(i) for i in input().split()]
row5 = [int(i) for i in input().split()]
count = 0
column15 = row1[0] + row2[0] + row3[0] + row4[0] + row5[0] + row1[4] + row2[4] + row3[4] + row4[4] + row5[4]
column24 = row1[1] + row2[1] + row3[1] + row4[1] + row5[1] + row1[3] + row2[3] + row3[3] + row4[3] + row5[3]
if column15 == 1:
	count += 2
if column24 == 1:
	count += 1
if sum(row1) == 1:
	count += 2
if sum(row2) == 1:
	count += 1
if sum(row3) == 1:
	count += 0
if sum(row4) == 1:
	count += 1
if sum(row5) == 1:
	count += 2
print(count)


stroki = []
for i in range(5):
	n = input().split()
	stroki.append(n)
for k in stroki:
	counter = k.count('1')
	if counter == 1:
		a = stroki.index(k) + 1
		b = k.index('1') + 1
		ans = abs(3 - a) + abs(3 - b)
		break
print(ans)


import sys

def make_row(line):
	return list(map(int, line.split(' ')))

def steps_to_make_beautiful(matrix):
	done = False
	r = 0
	for row in matrix:
		c = 0
		for item in row:
			if item == 1:
				done = True
				break
			c = c + 1
		if done:
			break
		r = r + 1
	return abs(2 - r) + abs(2 - c)

def main(args):
	lines = sys.stdin.readlines()
	matrix = map(make_row, lines)
	num_steps = steps_to_make_beautiful(matrix)
	print(num_steps)
main(sys.argv)


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
step = 0
if '1' in a:
	step = step + 2 + abs(a.index('1') - 2)
elif '1' in b:
	step = step + 1 + abs(b.index('1') - 2)
elif '1' in c:
	step = step + abs(c.index('1') - 2)
elif '1' in d:
	step = step + 1 + abs(d.index('1') - 2)
else:
	step = step + 2 + abs(e.index('1') - 2)
print(step)


a = 0
for i in range(5):
	y = input()
	z = y.split()
	for j in range(5):
		if z[j] == '1':
			a += abs(i - 2) + abs(j - 2)
print(a)


n = 5
s = []
for i in range(0, n):
	s.append(list(map(int, input().split())))
for i in range(0, n):
	for j in range(0, n):
		if s[i][j] == 1:
			left = abs(i - 2)
			right = abs(j - 2)
			print(right + left)


a = [[int(x) for x in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			res = abs(3 - (i + 1)) + abs(3 - (j + 1))
			print(res)
			break


mat = []
for i in range(5):
	arr = list(map(int, input().split()))
	mat.append(arr)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			x = abs(i - 2)
			y = abs(j - 2)
			break
print(x + y)


a = []
row = 0
col = 0
for i in range(5):
	a.append(input().split())
for i in range(5):
	for j in range(5):
		a[i][j] = int(a[i][j])
		if a[i][j] == 1:
			row = i
			col = j
row_movement = abs(row - 2)
col_movement = abs(col - 2)
print(row_movement + col_movement)


for row in range(5):
	r = input().split()
	for col in range(len(r)):
		if r[col] == '1':
			cord = (row, col)
			break
rowdiff = abs(2 - cord[0]) + abs(2 - cord[1])
print(rowdiff)


max_raw = 5
max_coulum = 5
row = coulum = 1
k = 0
while row <= max_raw:
	i = input()
	i = i.split()
	i = ''.join(i)
	index = i.find('1')
	if index != -1:
		index += 1
		postion_r = row
		postion_c = index
		if postion_r != 3:
			if postion_r < 3:
				while postion_r != 3:
					postion_r += 1
					k += 1
			else:
				while postion_r != 3:
					postion_r -= 1
					k += 1
		if postion_c != 3:
			if postion_c < 3:
				while postion_c != 3:
					postion_c += 1
					k += 1
			else:
				while postion_c != 3:
					postion_c -= 1
					k += 1
	row += 1
print(k)


a = []
for _ in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j]:
			print(abs(i - 2) + abs(j - 2))
			break


import math
lst1 = [int(a) for a in input().split()]
lst2 = [int(b) for b in input().split()]
lst3 = [int(c) for c in input().split()]
lst4 = [int(d) for d in input().split()]
lst5 = [int(e) for e in input().split()]
lst = lst1 + lst2 + lst3 + lst4 + lst5
k = lst.index(1) + 1
if k % 5 == 0:
	row = int(k / 5)
	col = 5
else:
	row = math.ceil(k / 5)
	col = k % 5
ans = abs(3 - row) + abs(3 - col)
print(ans)


line = ''
for i in range(5):
	line = input().split()
	for j in range(len(line)):
		if line[j] == '1':
			if i == 2 and j == 2:
				print(0)
			else:
				print(abs(i - 2) + abs(j - 2))


def krasivaya_matrica():
	str1 = [int(i) for i in input().split()]
	str2 = [int(i) for i in input().split()]
	str3 = [int(i) for i in input().split()]
	str4 = [int(i) for i in input().split()]
	str5 = [int(i) for i in input().split()]
	strs = [str1, str2, str3, str4, str5]
	for strn in range(len(strs)):
		for n in range(len(strs[strn])):
			if strs[strn][n] == 1:
				coordinate = [strn + 1, n + 1]
	target = [3, 3]
	print(abs(target[0] - coordinate[0]) + abs(target[1] - coordinate[1]))
krasivaya_matrica()


data = []
(x, y) = (-1, -1)
for i in range(5):
	data.append(list(map(int, input().split())))
	if data[i].__contains__(1):
		(x, y) = (i, data[i].index(1))
print(abs(2 - x) + abs(2 - y))


count = 0
for x in range(5):
	data = input().split(' ')
	for y in range(len(data)):
		if data[y] == '1':
			if y >= 2:
				count = count + (y - 2)
			else:
				count = count + (2 - y)
			if x >= 2:
				count = count + (x - 2)
			else:
				count = count + (2 - x)
			break
print(count)


matrix = [input().replace('\n', '').split() for _ in range(5)]
r = c = None
for row in range(5):
	for col in range(5):
		if matrix[col][row] == '1':
			(r, c) = (row + 1, col + 1)
			break
	if r is not None and c is not None:
		break
print(abs(3 - r) + abs(3 - c))


res = 0
for i in range(5):
	cmd = input().split()
	for j in range(5):
		if cmd[j] == '1':
			res = abs(2 - i) + abs(2 - j)
print(res)


a = [[int(i) for i in input().split()] for j in range(5)]
for i in range(1, 6):
	for j in range(1, 6):
		if a[i - 1][j - 1] == 1:
			ix = i
			jx = j
print(abs(3 - ix) + abs(3 - jx))


def main(lst):
	(x, y) = (0, 0)
	for i in range(5):
		if sum(lst[i]) == 1:
			y = i + 1
			break
	for i in range(5):
		if lst[y - 1][i] == 1:
			x = i + 1
			break
	return abs(3 - x) + abs(3 - y)
lst = []
for j in range(5):
	lst.append(list(map(int, input().split())))
print(main(lst))


array = []
one = [0, 0]
for i in range(5):
	row = input()
	row = row.split()
	row = [int(i) for i in row]
	array.append(row)
for y in range(5):
	for x in range(5):
		if array[y][x] == 1:
			print(abs(y - 2) + abs(x - 2))


L = []
for i in range(5):
	s = list(map(int, input().split()))
	L.append(s)
for i in L:
	if 1 in i:
		a = i.index(1)
		b = L.index(i)
		break
c = abs(a - 2) + abs(b - 2)
print(c)


f = False
for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			print(abs(i - 2) + abs(j - 2))
			f = True
			break
	if f:
		break


a1 = [int(x) for x in input().split()]
a2 = [int(x) for x in input().split()]
a3 = [int(x) for x in input().split()]
a4 = [int(x) for x in input().split()]
a5 = [int(x) for x in input().split()]
if 1 in a1:
	m = 2
	for i in range(len(a1)):
		if a1[i] == 1:
			n = abs(i - 2)
if 1 in a2:
	m = 1
	for i in range(len(a2)):
		if a2[i] == 1:
			n = abs(i - 2)
if 1 in a3:
	m = 0
	for i in range(len(a3)):
		if a3[i] == 1:
			n = abs(i - 2)
if 1 in a4:
	m = 1
	for i in range(len(a4)):
		if a4[i] == 1:
			n = abs(i - 2)
if 1 in a5:
	m = 2
	for i in range(len(a5)):
		if a5[i] == 1:
			n = abs(i - 2)
print(m + n)


(x, y) = (0, 0)
for i in range(5):
	s = str(input())
	s = s.split(' ')
	if '1' in s:
		y = s.index('1')
		x = i
x = max(x - 2, 2 - x)
y = max(y - 2, 2 - y)
print(x + y)


for i in range(1, 6):
	a = input().split(' ')
	try:
		y = a.index('1')
		x = i
	except:
		pass
print(abs(x - 3) + abs(y - 2))


A = []
for _ in range(5):
	a = list(map(int, input().split()))
	A.append(a)
for i in range(5):
	for j in range(5):
		if A[i][j] == 1:
			x = i
			y = j
			break
print(abs(x - 2) + abs(y - 2))


matrix = []
for i in range(5):
	matrix.append([i for i in map(int, input().split())])
found1 = False
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			found1 = True
			break
	if found1:
		break
moves = abs(2 - i) + abs(2 - j)
print(moves)


for i in range(1, 6):
	row = input()
	rowList = row.split()
	rowList = [int(i) for i in rowList]
	if 1 in rowList:
		index = rowList.index(1)
		out = abs(3 - (index + 1)) + abs(3 - i)
print(out)


A = [4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4]
x = []
for i in range(5):
	p = list(map(int, input().rstrip().split()))
	x += p
z = x.index(1)
print(A[z])


m = []
for _ in range(5):
	m += map(int, input().split())
print(abs(2 - m.index(1) // 5) + abs(2 - m.index(1) % 5))


i = 0
j = 0
c1 = 0
c2 = 0
for m in range(5):
	x = list(map(int, input().split()))
	c1 += 1
	c2 = 0
	for k in x:
		c2 += 1
		if k == 1:
			i = c1
			j = c2
print(abs(3 - i) + abs(3 - j))


alist = []
(r, c) = (0, 0)
flag = 0
for i in range(5):
	xlist = [int(x) for x in input().split()]
	for j in range(5):
		if xlist[j] == 1:
			(r, c) = (i, j)
print(abs(r - 2) + abs(c - 2))


matrix = []
s = ''
for i in range(5):
	n = map(int, input().split())
	comp = list(n)
	for j in range(5):
		if comp[j] == 1:
			colum = j
			row = i
if row < 2:
	if row % 2 == 1:
		row = 1
	else:
		row = 2
elif row > 2:
	if row % 2 == 0:
		row = 2
	else:
		row = 1
elif row == 2:
	row = 0
if colum < 2:
	if colum % 2 == 1:
		colum = 1
	else:
		colum = 2
elif colum > 2:
	if colum % 2 == 0:
		colum = 2
	else:
		colum = 1
elif colum == 2:
	colum = 0
print(row + colum)


for i in range(5):
	alist = list(input().split())
	aset = set(alist)
	if len(aset) > 1:
		r = i + 1
		c = alist.index('1') + 1
		break
print(abs(r - 3) + abs(c - 3))


def main():
	(r, c) = (0, 0)
	for _ in range(5):
		arr = list(map(int, input().strip().split()))
		if arr.count(1) != 0:
			r = _ + 1
			c = arr.index(1) + 1
	print(abs(r - 3) + abs(c - 3))
main()


matrix = []
for i in range(1, 6):
	x = list(map(int, input().strip().split()))
	matrix.append(x)
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == 1:
			row = i
			column = j
			break
		else:
			continue
roww = abs(row - 2)
columnn = abs(column - 2)
print(roww + columnn)


a = []
for i in range(5):
	a.extend(map(int, input().split()))
n = a.index(1)
print(abs(n % 5 - 2) + abs(n // 5 - 2))


def mod():
	x = []
	n = 2
	for k in range(5):
		f = list(map(int, input().split()))
		x.append(f)
	for i in range(len(x)):
		for j in range(5):
			if x[i][j] == 1:
				c = i
				d = j
				break
	print(abs(n - c) + abs(n - d))
mod()


def row(number):
	if number % 5 != 0:
		return int(number / 5) + 1
	else:
		return int(number / 5)

def column(number):
	if number % 5 != 0:
		return number % 5
	else:
		return 5

def moves(row, column):
	return abs(row - 3) + abs(column - 3)
matrix = ''
for i in range(5):
	matrix = matrix + input()
newMatrix = ''
for i in matrix:
	if i != ' ':
		newMatrix = newMatrix + i
count = 0
for i in range(len(newMatrix)):
	if 1 * int(newMatrix[i]) == 1:
		count = count + 1
		break
	else:
		count = count + 1
print(moves(row(count), column(count)))


a = None
b = None
for i in range(5):
	s = input().split()
	if '1' in s:
		a = i + 1
		b = s.index('1') + 1
		break
print(abs(3 - a) + abs(3 - b))


for i in range(5):
	currentlist = input().split()
	if '1' in currentlist:
		break
for j in range(len(currentlist)):
	if currentlist[j] == '1':
		break
m = abs(2 - i)
n = abs(2 - j)
print(m + n)


arr = [[0 for i in range(5)] for j in range(5)]
x = 0
y = 0
for i in range(5):
	l = list(map(int, input().split()))
	for j in range(5):
		arr[i][j] = l[j]
		if arr[i][j] == 1:
			x = i
			y = j
			break
c = 0
c = c + abs(x - 2)
c = c + abs(y - 2)
print(c)


l = [[i for i in input().split()] for t in range(5)]
for a in range(5):
	for b in range(5):
		if l[a][b] == '1':
			print(abs(a - 2) + abs(b - 2))
			exit()


l = []
for i in range(5):
	a = input().split()
	l.append(a)
d = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			p = i
			q = j
			d = 1
			break
	if d == 1:
		break
print(abs(3 - (p + 1)) + abs(3 - (q + 1)))


n_rows = 5
for i in range(n_rows):
	line = list(map(int, input().split()))
	if 1 in line:
		row = i
		col = line.index(1)
print(abs(row - 2) + abs(col - 2))


import math
for i in range(5):
	a = input().replace(' ', '')
	a = list(a)
	if '1' in a:
		b = i + 1
		c = int(a.index('1')) + 1
a = math.fabs(b - 3) + math.fabs(c - 3)
print(math.trunc(a))


def move_count():
	for i in range(5):
		row = [int(x) for x in input().split()]
		for j in range(5):
			if row[j] == 1:
				return abs(2 - i) + abs(2 - j)
print(move_count())


col = 0
row = 0
for i in range(1, 6):
	w = list(input().split())
	if '1' in w:
		col = w.index('1') + 1
		row = i
		break
print(abs(3 - row) + abs(3 - col))


b = []
for i in range(0, 5):
	a = list(map(int, input('').split()))
	b.append(a)
for j in range(5):
	for k in range(5):
		if b[j][k] == 1:
			row = j + 1
			col = k + 1
moves = abs(row - 3) + abs(col - 3)
print(moves)


l = []
for i in range(0, 5):
	j = []
	j = list(map(int, input().split()))
	l.append(j)
x = 0
y = 0
flag = 0
for row in range(0, 5):
	for col in range(0, 5):
		if l[row][col] == 1:
			x = row
			y = col
			flag = 1
			break
	if flag == 1:
		break
moves = 0
moves = abs(2 - x) + abs(2 - y)
print(int(moves))


import math
l = []
for i in range(5):
	s = input()
	l.append(s.split())
(a, b) = (0, 0)
for i in range(len(l)):
	for j in range(len(l[i])):
		if l[i][j] == '1':
			a = i
			b = j
			break
print(abs(2 - a) + abs(2 - b))


ar = []
for i in range(5):
	a = list(map(int, input().split()))
	ar.append(a)
for i in range(5):
	for j in range(5):
		if ar[i][j] == 1:
			x = i + 1
			y = j + 1
			break
print(abs(x - 3) + abs(y - 3))


import math
li = []
for i in range(5):
	a = [int(j) for j in input().split()]
	li.append(a)
row = -1
col = -1
for i in range(5):
	for j in range(5):
		if li[i][j] == 1:
			row = i
			col = j
			break
sum = abs(2 - row) + abs(2 - col)
print(sum)


matrix = []
t = 0
h = 0
g = 0
for m in range(5):
	a = list(map(int, input('').split(' ')))
	matrix.append(a)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			g = i
			h = j
			break
if g > 2:
	for o in range(g, 1, -1):
		if o > 2:
			t += 1
	if h > 2:
		for l in range(h, 1, -1):
			if l > 2:
				t += 1
	elif h < 2:
		for p in range(h, 3):
			if p < 2:
				t += 1
elif g < 2:
	for d in range(g, 3):
		if d < 2:
			t += 1
	if h > 2:
		for x in range(h, 1, -1):
			if x > 2:
				t += 1
	elif h < 2:
		for z in range(h, 3):
			if z < 2:
				t += 1
elif h > 2:
	for n in range(h, 1, -1):
		if n > 2:
			t += 1
elif h < 2:
	for w in range(h, 3):
		if w < 2:
			t += 1
print(t)


for i in range(5):
	row = input()
	if '1' in row:
		moves = abs(row.find('1') / 2 - 2) + abs(i - 2)
		print(int(moves))
		break


matrix = []
for i in range(5):
	l = list(map(int, input().split()))
	matrix.append(l)
for j in range(5):
	for k in range(5):
		if matrix[j][k] == 1:
			print(abs(j - 2) + abs(k - 2))
			break


result = -1
for i in range(5):
	for (j, item) in enumerate(list(map(int, input().split()))):
		if item == 1:
			result = abs(i - 2) + abs(j - 2)
print(result)


row = 0
col = 0
for i in range(5):
	s = input()
	if s != '0 0 0 0 0':
		row = i + 1
		for x in range(0, 9, 2):
			if s[x] == '1':
				col = x / 2 + 1
				break
print(int(abs(row - 3) + abs(col - 3)))


mat = [list(map(int, input().split())) for _ in range(5)]
(row, col) = (2, 2)
for (i, lst) in enumerate(mat):
	if 1 in lst:
		(row, col) = (abs(row - i), abs(col - lst.index(1)))
print(row + col)


def pelnyIndex(matrix):
	indexJ = 0
	indexI = 0
	for i in matrix:
		indexI += 1
		for j in i:
			indexJ += 1
			if j == 1:
				return [indexI, indexJ]

def konkretnyIndex(x):
	x[0] = x[0] - 1
	x[1] = x[1] - x[0] * 5
	return x

def nareszcie(x):
	if x >= 3:
		return x - 3
	elif x < 3:
		return 3 - x
matrix = []
for x in range(5):
	matrix.append([int(y) for y in input().split()])
x = pelnyIndex(matrix)
x = konkretnyIndex(x)
x[0] = x[0] + 1
print(nareszcie(x[0]) + nareszcie(x[1]))


N = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if N[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


def beautiful_matrix():
	count = 55
	matrix = []
	for _ in range(5):
		matrix.append(input().split())
	if '1' in matrix[0] or '1' in matrix[4]:
		if '1' in matrix[0]:
			if matrix[0][0] == '1' or matrix[0][4] == '1':
				count = 4
			elif matrix[0][1] == '1' or matrix[0][3] == '1':
				count = 3
			elif matrix[0][2] == '1':
				count = 2
		elif '1' in matrix[4]:
			if matrix[4][0] == '1' or matrix[4][4] == '1':
				count = 4
			elif matrix[4][1] == '1' or matrix[4][3] == '1':
				count = 3
			elif matrix[4][2] == '1':
				count = 2
	elif '1' in matrix[1] or '1' in matrix[3]:
		if '1' in matrix[1]:
			if matrix[1][0] == '1' or matrix[1][4] == '1':
				count = 3
			elif matrix[1][1] == '1' or matrix[1][3] == '1':
				count = 2
			elif matrix[1][2] == '1':
				count = 1
		elif '1' in matrix[3]:
			if matrix[3][0] == '1' or matrix[3][4] == '1':
				count = 3
			elif matrix[3][1] == '1' or matrix[3][3] == '1':
				count = 2
			elif matrix[3][2] == '1':
				count = 1
	elif '1' in matrix[2]:
		if matrix[2][0] == '1' or matrix[2][4] == '1':
			count = 2
		elif matrix[2][1] == '1' or matrix[2][3] == '1':
			count = 1
		elif matrix[2][2] == '1':
			count = 0
	print(count)
beautiful_matrix()


l = []
for i in range(0, 5):
	c = list(map(int, input().split()))
	l.append(c)
(x, y) = (0, 0)
b = False
for i in range(0, 5):
	for j in range(0, 5):
		if l[i][j] == 1:
			(x, y) = (i, j)
			b = True
			break
	if b:
		break
print(abs(x - 2) + abs(y - 2))


t = 5
m = []
c = 0

def mo(m):
	if m < 0:
		return -m
	else:
		return m
while t:
	l1 = list(map(int, input().split()))
	m.append(l1)
	t = t - 1
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			(a, b) = (i, j)
a = mo(a - 2)
b = mo(b - 2)
print(a + b)


for i in range(5):
	a = [int(x) for x in input().split(' ')]
	for j in range(5):
		if a[j] == 1:
			col = j
			row = i
res = abs(2 - row) + abs(2 - col)
print(res)


(n, m) = (5, 5)
a = [[0] * n for _ in range(m)]
for i in range(n):
	a[i] = [int(j) for j in input().strip().split(' ')]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i
			y = j
ans = abs(2 - x) + abs(2 - y)
print(ans)


matrix = []
m = 0
for _ in range(5):
	r = input().split()
	r = [int(i) for i in r]
	matrix.append(r)
for i in matrix:
	for j in range(5):
		if i[j] == 1:
			c = i.index(1)
			r = matrix.index(i)
			break
aux = None
if c > 2:
	count = c - 2
	while count != 0:
		aux = matrix[r][c - 1]
		matrix[r][c - 1] = matrix[r][c]
		matrix[r][c] = aux
		count -= 1
		c -= 1
		m += 1
if c < 2:
	count = c
	while count != 2:
		aux = matrix[r][c + 1]
		matrix[r][c + 1] = matrix[r][c]
		matrix[r][c] = aux
		count += 1
		c += 1
		m += 1
aux = None
if r > 2:
	count = r - 2
	while count != 0:
		aux = matrix[r - 1]
		matrix[r - 1] = matrix[r]
		matrix[r] = aux
		r -= 1
		count -= 1
		m += 1
if r < 2:
	count = r
	while count != 2:
		aux = matrix[r + 1]
		matrix[r + 1] = matrix[r]
		matrix[r] = aux
		r += 1
		count += 1
		m += 1
print(m)


l = []
for i in range(5):
	x = input().split()
	c = []
	for j in range(5):
		c.append(int(x[j]))
	l.append(c)
count = 0
for j in range(5):
	for i in range(5):
		if l[i][j] == 1:
			while i != 2:
				if i > 2:
					i = i - 1
					count = count + 1
				else:
					i = i + 1
					count = count + 1
			while j != 2:
				if j > 2:
					j = j - 1
					count = count + 1
				else:
					j = j + 1
					count = count + 1
print(count)


mylist = []
for i in range(5):
	mylist.append([int(i) for i in input().split()])
target_row = 2
target_col = 2
index = 0
for i in mylist:
	if 1 in i:
		temp_row = index
		for j in range(len(i)):
			if i[j] == 1:
				temp_col = j
	index += 1
moves = abs(target_row - temp_row) + abs(target_col - temp_col)
print(moves)


matrix = []
pos = []
moves = 0
for i in range(0, 5):
	input_array = list(map(int, input().split(' ')))
	matrix.append(input_array)
for i in range(0, len(matrix)):
	for j in range(0, len(matrix[i])):
		if matrix[i][j] == 1:
			pos.append(i)
			pos.append(j)
for i in pos:
	moves = moves + abs(i - 2)
print(moves)


matrix = []
noOfSwaps = 0
for i in range(0, 5):
	matrix.append(input().split(' '))
for (i, row) in enumerate(matrix):
	for (j, ele) in enumerate(row):
		if ele == '1':
			noOfSwaps = abs(i - 2) + abs(j - 2)
			print(noOfSwaps)
			break


l = []
x = 0
y = 0
for i in range(5):
	l = list(map(int, input().split()))
	y += 1
	if l.count(1) == 1:
		break
x = l.index(1)
print(abs(x - 2) + abs(y - 3))


a = list(input().split(' '))
b = list(input().split(' '))
c = list(input().split(' '))
d = list(input().split(' '))
e = list(input().split(' '))
li = [a, b, c, d, e]
vdis = 0
hdis = 0
for i in range(len(a)):
	if a[i] == '1' or e[i] == '1':
		vdis = 2
		hdis = abs(3 - (i + 1))
	if b[i] == '1' or d[i] == '1':
		vdis = 1
		hdis = abs(3 - (i + 1))
	if e[i] == '1':
		vdis = 2
		hdis = abs(3 - (i + 1))
	if c[i] == '1':
		hdis = abs(3 - (i + 1))
print(hdis + vdis)


A = []
for i in range(5):
	B = list(map(int, input().split()))
	A.append(B)
flag = 0
for i in range(5):
	for j in range(5):
		if A[i][j] == 1:
			flag += 1
			break
	if flag != 0:
		break
print(abs(i + 1 - 3) + abs(j + 1 - 3))


for i in range(5):
	col = input().split()
	for j in range(5):
		if col[j] == '1':
			m = abs(i - 2) + abs(j - 2)
			print(m)


for i in range(5):
	list = input().split()
	for j in range(5):
		if list[j] == '1':
			a = abs(i - 2)
			b = abs(j - 2)
print(a + b)


def matrix(m):
	locI = 0
	locJ = 0
	for i in range(0, 5):
		for j in range(0, 5):
			if m[i][j] == 1:
				locI = i
				locJ = j
	print(abs(2 - locI) + abs(2 - locJ))
ma = []
for _ in range(0, 5):
	ma.append(list(map(int, input().rstrip().split())))
matrix(ma)


import math
acts = 0
for k in range(6):
	row = list(map(int, input().split()))
	if 1 in row:
		acts += abs(k - 2)
		acts += abs(row.index(1) - 2)
		break
print(acts)


mtr = []
for a in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		bar = a
	mtr.append(row)
kol = mtr[bar].index(1)
total = abs(kol - 2) + abs(bar - 2)
print(total)


import sys
for row in range(5):
	r = [int(i) for i in input().split()]
	for c in range(5):
		if r[c] == 1:
			result = abs(2 - row) + abs(2 - c)
			for i in range(4 - row):
				input()
			print(result)
			exit()


import sys
import math
l = []
ind = []
mi = 2
mj = 2
t = 0
for i in range(5):
	nl = [int(x) for x in input().split()]
	if 1 in nl:
		ti = i
		tj = nl.index(1)
	l.append(nl)
c = abs(ti - mi) + abs(tj - mj)
print(c)


from sys import stdin
one_coords = None
for (index, line) in enumerate(stdin, start=1):
	if '1' in line:
		line = line.replace(' ', '')
		one_coords = (index, [pos + 1 for (pos, char) in enumerate(line) if char == '1'][0])
print(abs(3 - one_coords[0]) + abs(3 - one_coords[1]))


def findOne(x):
	column = 1
	for i in x:
		if i == 1:
			gotOne = True
			break
		else:
			gotOne = False
		column += 1
	return (gotOne, column)
row = 1
for j in range(5):
	rows = list(map(int, input().split()))
	(gotOne, column) = findOne(rows)
	if gotOne == True:
		break
	else:
		row += 1
if gotOne == True:
	for k in range(5 - row):
		misc = list(map(int, input().split()))
print(abs(row - 3) + abs(column - 3))


for i in range(5):
	a = list(map(str, input().split()))
	for n in range(len(a)):
		if a[n] > '0':
			x = i
			y = n
print(abs(x - 2) + abs(y - 2))


row_idx = -1
col_idx = -1
for i in range(5):
	row = input().split()
	if '1' in row:
		row_idx = i + 1
		col_idx = row.index('1') + 1
print(abs(3 - row_idx) + abs(3 - col_idx))


for row in range(5):
	x = list(map(int, input().split()))
	if sum(x) == 1:
		row1 = row + 1
		break
for i in range(len(x)):
	if x[i] == 1:
		col1 = i + 1
		break
print(abs(col1 - 3) + abs(row1 - 3))


Matrix = [[0 for _ in range(5)] for _ in range(5)]
num = 0
for i in range(5):
	a = input().split()
	for j in range(5):
		Matrix[i][j] = int(a[j])
for _ in range(10):
	for k in range(5):
		for m in range(5):
			if Matrix[k][m] == 1:
				if k < 2:
					(Matrix[k], Matrix[k + 1]) = (Matrix[k + 1], Matrix[k])
					num += 1
					if m < 2:
						(Matrix[k + 1][m], Matrix[k + 1][m + 1]) = (Matrix[k + 1][m + 1], Matrix[k + 1][m])
						num += 1
					if m > 2 and m <= 4:
						(Matrix[k + 1][m], Matrix[k + 1][m - 1]) = (Matrix[k + 1][m - 1], Matrix[k + 1][m])
						num += 1
					if m == 2:
						num = num
				if k > 2 and k <= 4:
					(Matrix[k], Matrix[k - 1]) = (Matrix[k - 1], Matrix[k])
					num += 1
					if m < 2:
						(Matrix[k - 1][m], Matrix[k - 1][m + 1]) = (Matrix[k - 1][m + 1], Matrix[k - 1][m])
						num += 1
					if m > 2 and m <= 4:
						(Matrix[k - 1][m], Matrix[k - 1][m - 1]) = (Matrix[k - 1][m - 1], Matrix[k - 1][m])
						num += 1
					if m == 2:
						num = num
				if k == 2:
					num = num
					if m < 2:
						(Matrix[k][m], Matrix[k][m + 1]) = (Matrix[k][m + 1], Matrix[k][m])
						num += 1
					if m > 2 and m <= 4:
						(Matrix[k][m], Matrix[k][m - 1]) = (Matrix[k][m - 1], Matrix[k][m])
						num += 1
					if m == 2:
						num = num
			else:
				num = num
print(num)


def pos(l):
	for i in range(5):
		for j in range(5):
			if l[i][j] == 1:
				return (i, j)
l = [list(map(int, input().split())) for i in range(5)]
(i, j) = pos(l)
print(abs(2 - i) + abs(2 - j))


matrix = list()
for i in range(5):
	num = list(map(int, input().split(' ')))
	matrix.append(num)
for r in range(5):
	for c in range(5):
		if matrix[r][c] == 1:
			count = abs(r - 2) + abs(c - 2)
print(count)


from sys import stdin
array = []
x = 0
y = 0
for i in range(5):
	array.append([int(i) for i in stdin.readline().split()])
	if 1 in array[i]:
		x = i
		y = array[x].index(1)
print(abs(2 - x) + abs(2 - y))


def resultx(c):
	if c == 0:
		print(4)
	if c == 1:
		print(3)
	if c == 2:
		print(2)
	if c == 3:
		print(3)
	if c == 4:
		print(4)

def resulty(c):
	if c == 0:
		print(3)
	if c == 1:
		print(2)
	if c == 2:
		print(1)
	if c == 3:
		print(2)
	if c == 4:
		print(3)

def resultz(c):
	if c == 0:
		print(2)
	if c == 1:
		print(1)
	if c == 2:
		print(0)
	if c == 3:
		print(1)
	if c == 4:
		print(2)
x = input('').split()
y = input('').split()
z = input('').split()
m = input('').split()
n = input('').split()
for c in range(5):
	if x[c] == '1':
		resultx(c)
	if y[c] == '1':
		resulty(c)
	if z[c] == '1':
		resultz(c)
	if m[c] == '1':
		resulty(c)
	if n[c] == '1':
		resultx(c)


mat = []
for i in range(5):
	list2 = list(map(int, input().strip().split()))[:5]
	mat.append(list2)
found = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			(l, r) = (i, j)
			found = 1
			break
	if found:
		break
res = abs(2 - l) + abs(2 - r)
print(res)


for i in range(5):
	line = input().split()
	for k in range(5):
		if line[k] == '1':
			print(abs(i - 2) + abs(k - 2))


m = []
for _ in range(5):
	k = list(map(int, input().split()))
	m.append(k)
f = 0
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			f = 1
			break
	if f == 1:
		break
print(abs(2 - i) + abs(2 - j))


matrix = []
for r in range(5):
	matrix.append(input().split(' '))
int_matrix = []
for i in range(5):
	int_matrix.append(matrix[i])
center = [2, 2]
pos = []
for rows in matrix:
	for val in rows:
		if int(val) == 1:
			pos.append(matrix.index(rows))
			pos.append(rows.index(val))
row_shuffle = abs(center[0] - pos[0])
col_shuffle = abs(center[1] - pos[1])
moves = row_shuffle + col_shuffle
print(moves)


list = [2, 1, 0, 1, 2]
for i in list:
	s = input()
	if '1' in s:
		print(i + list[s.find('1') // 2])


l = []
for i in range(5):
	x = list(map(int, input().split()))
	l.append(x)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			c = list([i, j])
if c[0] <= 2 and c[1] <= 2:
	res = 2 - c[0] + (2 - c[1])
elif c[0] > 2 and c[1] <= 2:
	res = c[0] - 2 + (2 - c[1])
elif c[0] <= 2 and c[1] > 2:
	res = 2 - c[0] + (c[1] - 2)
else:
	res = c[0] - 2 + (c[1] - 2)
print(res)


for a in range(5):
	line = input().split()
	for i in range(5):
		if int(line[i]) == 1:
			print(abs(a - 2) + abs(i - 2))


for i in range(1, 6):
	n = input().split()
	for (j, v) in enumerate(n):
		if v == '1':
			print(abs(3 - i) + abs(3 - (j + 1)))


m = []
for i in range(5):
	m.append(input().split())
for i in range(5):
	if m[i].count('1') == 1:
		row = i + 1
		col = m[i].index('1') + 1
		break
print(abs(row - 3) + abs(col - 3))


for i in range(5):
	s = list(map(int, input().split()))
	if 1 in s:
		col = i
		pos = s.index(1)
print(abs(col - 2) + abs(pos - 2))


import sys
matrix = sys.stdin.read().splitlines()
for i in range(5):
	if '1' in matrix[i]:
		lista = matrix[i].split(' ')
		column = lista.index('1')
		row = i
		break
result = abs(row - 2) + abs(column - 2)
print(result)


a = []
for i in range(5):
	a.append(input().split(' '))
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			tam = i
			tmp = j
print(abs(tam - 2) + abs(tmp - 2))


op = 0
for i in range(5):
	g = input().split()
	for j in range(5):
		if int(g[j]) == 1:
			op = abs(i - 2) + abs(j - 2)
print(op)


a = []
for i in range(5):
	x = list(map(int, input().split()))
	a.append(x)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			one = (i, j)
			break
print(abs(2 - one[0]) + abs(2 - one[1]))


matrix = []
for i in range(5):
	rows = list(map(int, input().split(' ')))
	matrix.append(rows)
count_c = 0
count_r = 0
for j in range(5):
	for k in range(5):
		if matrix[j][k] == 1:
			if k > 2 and j > 2:
				count_c = int(abs(k - 2))
				count_r = int(abs(j - 2))
			else:
				count_c = int(abs(2 - k))
				count_r = int(abs(2 - j))
		else:
			pass
count = count_c + count_r
print(count)


matrix = []
for i in range(5):
	row = input().split()
	matrix.append(row)
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == '1':
			ridx = i + 1
			cidx = j + 1
print(abs(3 - ridx) + abs(3 - cidx))


flag = 0
for i in range(1, 6):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			flag = 1
			break
	if flag == 1:
		break
print(abs(3 - i) + abs(2 - j))


for a in range(5):
	for (b, c) in zip(input().split(), range(5)):
		if b == '1':
			x = a
			y = c
print(abs(x - 2) + abs(y - 2))


x = 0
y = 0
for i in range(5):
	list = [int(x) for x in input().split()]
	if sum(list) == 1:
		x = i + 1
		for j in range(5):
			if list[j] == 1:
				y = j + 1
print(abs(x - 3) + abs(y - 3))


a = input()
b = input()
c = input()
d = input()
e = input()
a = a.split()
b = b.split()
c = c.split()
d = d.split()
e = e.split()
A = [a, b, c, d, e]
(f, g) = (0, 0)
resp = 0
for i in range(0, 5):
	for j in range(0, 5):
		if A[i][j] == '1':
			(f, g) = (i, j)
			break
		else:
			pass
(f, g) = (int(f), int(g))
if f > 2:
	resp += f - 2
elif f < 2:
	resp += 2 - f
if g > 2:
	resp += g - 2
elif g < 2:
	resp += 2 - g
print(resp)


for i in range(5):
	s = input()
	if s.find('1') != -1:
		x = i + 1
		y = s.find('1') // 2 + 1
print(abs(x - 3) + abs(y - 3))


for i in range(5):
	res = input()
	ans = 0
	if res == '0 0 0 0 0':
		continue
	else:
		for (j, x) in enumerate(res.split()):
			if x == '1':
				ans = abs(2 - j) + abs(2 - i)
	print(ans)


import sys
(x, y) = (0, 0)
for i in range(5):
	row = list(map(int, sys.stdin.readline().split()))
	for j in range(5):
		if row[j] == 1:
			(x, y) = (i + 1, j + 1)
moves = abs(x - 3) + abs(y - 3)
sys.stdout.write(str(moves))


(ind_c, ind_r) = (-1, -1)
for _ in range(5):
	k = list(map(int, input().split()))
	if 1 in k:
		ind_c = k.index(1)
		ind_r = _
print(abs(ind_r - 2) + abs(ind_c - 2))


arr = []
for i in range(5):
	line = input().split()
	if '1' in line:
		x = i
		y = line.index('1')
	arr += line
print(abs(2 - x) + abs(2 - y))


for i in range(5):
	row = input().strip().split()
	if '1' in row:
		j = row.index('1')
		print(abs(3 - i - 1) + abs(3 - j - 1))
		exit()


num = int(0)
for i in range(5):
	a = input().split()
	for j in range(5):
		if int(a[j]) == 1:
			num = abs(i - 2) + abs(j - 2)
print(num)


from sys import stdin

def main():
	fila0 = [int(x) for x in stdin.readline().strip().split()]
	fila1 = [int(x) for x in stdin.readline().strip().split()]
	fila2 = [int(x) for x in stdin.readline().strip().split()]
	fila3 = [int(x) for x in stdin.readline().strip().split()]
	fila4 = [int(x) for x in stdin.readline().strip().split()]
	mat = []
	mat.append(fila0)
	mat.append(fila1)
	mat.append(fila2)
	mat.append(fila3)
	mat.append(fila4)
	for i in range(5):
		for j in range(5):
			if mat[i][j] == 1:
				x = i
				y = j
				break
				break
	print(abs(2 - x) + abs(2 - y))
main()


r = 0
c = 0
for i in range(5):
	k = [int(i) for i in input().split()]
	for j in range(5):
		if k[j]:
			r = i
			c = j
L = abs(r - 2) + abs(c - 2)
print(L)


m = 0
n = 0
for i in range(0, 5):
	str = input()
	for j in range(0, len(str)):
		if str[j] == '1':
			m = i + 1
			n = j / 2 + 1
			break
t = abs(m - 3) + abs(n - 3)
print(int(t))


x1 = input().split()
x2 = input().split()
x3 = input().split()
x4 = input().split()
x5 = input().split()
if x1[0] == '1' or x1[4] == '1' or x5[0] == '1' or (x5[4] == '1'):
	print('4')
elif x1[1] == '1' or x1[3] == '1' or x2[0] == '1' or (x2[4] == '1') or (x4[0] == '1') or (x4[4] == '1') or (x5[1] == '1') or (x5[3] == '1'):
	print('3')
elif x1[2] == '1' or x2[1] == '1' or x2[3] == '1' or (x3[0] == '1') or (x3[4] == '1') or (x4[1] == '1') or (x4[3] == '1') or (x5[2] == '1'):
	print('2')
elif x2[2] == '1' or x3[1] == '1' or x3[3] == '1' or (x4[2] == '1'):
	print('1')
else:
	print('0')


l = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
r = []
for i in range(5):
	c = [int(x) for x in input().split()]
	r.append(c)
for i in range(5):
	for j in range(5):
		if r[i][j] == 1:
			a = i
			b = j
l[0][0] = l[4][0] = 4
l[0][1] = l[4][1] = 3
l[0][2] = l[4][2] = 2
l[0][3] = l[4][3] = 3
l[0][4] = l[4][4] = 4
l[1][0] = l[3][0] = 3
l[1][1] = l[3][1] = 2
l[1][2] = l[3][2] = 1
l[1][3] = l[3][3] = 2
l[1][4] = l[3][4] = 3
l[2][0] = 2
l[2][1] = 1
l[2][2] = 0
l[2][3] = 1
l[2][4] = 2
print(l[a][b])


matrix = []
while len(matrix) != 5:
	matrix.append(list(map(int, input().split())))
flag = 0
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			flag = 1
			break
	if flag == 1:
		break
i += 1
j += 1
steps = abs(3 - i) + abs(3 - j)
print(steps)


mat = []
lin = 0
col = 0
for i in range(5):
	mat.append(input().split())
for i in range(len(mat)):
	if '1' in mat[i]:
		col = mat[i].index('1')
		lin = i
steps = abs(2 - lin) + abs(2 - col)
print(steps)


c = 0
for i in range(5):
	n = input().split(' ')
	for j in n:
		if int(j) == 1:
			N = n
			I = i + 1
while I < 3:
	I += 1
	c += 1
while I > 3:
	I -= 1
	c += 1
for i in N:
	if int(i) == 1:
		x = N.index(i) + 1
while x < 3:
	x += 1
	c += 1
while x > 3:
	x -= 1
	c += 1
print(c)


s1 = []
list0 = [12]
list1 = [7, 11, 13, 17]
list2 = [2, 6, 8, 10, 14, 16, 18, 22]
list3 = [1, 3, 5, 9, 15, 19, 21, 23]
list4 = [0, 4, 20, 24]
for i in range(5):
	n = input().split()
	s1.extend(n)
for i in range(25):
	if s1[i] == '1':
		k = i
if k in list0:
	print('0')
elif k in list1:
	print('1')
elif k in list2:
	print('2')
elif k in list3:
	print('3')
elif k in list4:
	print('4')


for i in range(1, 6):
	row = [j for j in input().split()]
	for j in range(1, 6):
		if row[j - 1] == '1':
			x = i
			y = j
print(abs(x - 3) + abs(y - 3))


for i in range(1, 6):
	s = input()
	if '1' in s:
		index = s.index('1')
		row = abs(3 - i)
		col = abs(3 - (index // 2 + 1))
		print(str(row + col))


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

def main():
	for i in range(len(matrix)):
		for j in range(len(matrix[i])):
			if matrix[i][j] == 1:
				row = i
				col = j
				break
	steps = 0
	if row >= 2:
		steps += row - 2
	else:
		steps += 2 - row
	if col >= 2:
		steps += col - 2
	else:
		steps += 2 - col
	print(steps)
	return 0
main()


for i in range(5):
	temp = list(map(int, input().split()))
	if 1 in temp:
		r = i + 1
		break
for j in range(5):
	if temp[j] == 1:
		c = j + 1
		break
print(abs(c - 3) + abs(r - 3))


b = [[4, 3, 2, 3, 4], [3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3], [4, 3, 2, 3, 4]]
for i in range(5):
	l = [int(n) for n in input().split()]
	for j in range(5):
		if l[j] == 1:
			print(b[i][j])


def main():
	row = 0
	col = 0
	for i in range(5):
		zeros = input().split()
		if '1' in zeros:
			row = i
			col = zeros.index('1')
	print(abs(row - 2) + abs(col - 2))
main()


import sys
u = sys.stdin.read().split('\n')
mat = []
for line in u:
	mat.append([int(x) for x in line.split()])
i1 = -1
j1 = -1
for x in mat:
	i1 += 1
	if 1 in x:
		j1 = x.index(1)
		break
moves = abs(i1 - 2) + abs(j1 - 2)
print(moves)


for i in range(5):
	l = list(map(int, input().split()))
	for x in range(len(l)):
		if l[x] == 1:
			(glx, gly) = (i + 1, x + 1)
			print(abs(glx - 3) + abs(gly - 3))


i = 0
matrix = []
while i < 5:
	row = list(map(int, input().strip().split()))
	matrix.append(row)
	i += 1
for li in matrix:
	for l in li:
		if l == 1:
			idx_row = li.index(l) + 1
			idx_col = matrix.index(li) + 1
print(abs(3 - idx_row) + abs(3 - idx_col))


import sys
matrix = []
for i in range(5):
	matrix.append(input().split())
ans = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			ans = abs(i - 2) + abs(j - 2)
print(ans)


a = []
b = []
counti = 0
countj = 0
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(len(a)):
	for j in range(len(a)):
		if a[i][j] == 1:
			b.append(i)
			b.append(j)
if b[0] > 2:
	counti = b[0] - 2
elif b[0] < 2:
	counti = 2 - b[0]
if b[1] > 2:
	countj = b[1] - 2
elif b[1] < 2:
	countj = 2 - b[1]
print(counti + countj)


totaltransformations = 0
count = -1
newCount = -1
array = []
for i in range(0, 5):
	element = list(map(int, input().split()))
	array.insert(i, element)
for listelement in array:
	if 1 in listelement:
		count += 1
		break
	else:
		count += 1
for element in array[count]:
	if element == 1:
		newCount += 1
		break
	else:
		newCount += 1
print(abs(count - 2) + abs(newCount - 2))


for i in range(5):
	s = input()
	if '1' in s:
		lst = s.split()
		n = lst.index('1')
		print(abs(n - 2) + abs(i - 2))
		break


import math
b = []
for i in range(5):
	a = [x for x in input().split('\n')]
	b.append(a)
for i in range(5):
	if str(b[i]).count('1') == 1:
		x = i
		w = str(b[i])
		l = len(w)
		for j in range(l):
			if w[j] == '1':
				y = (j - 1) // 2
q = abs(x - 2) + abs(y - 2)
print(q)


def a():
	cs = list()
	for i in range(5):
		ss = list(map(int, input().split()))
		cs[len(cs):] = ss[:len(ss)]
	i = int(((cs.index(1) // 5 - 2) ** 2) ** 0.5)
	j = int(((cs.index(1) % 5 - 2) ** 2) ** 0.5)
	print(i + j)
a()


lisa = [''] * 5
for i in range(5):
	lisa[i] = input()
row = 0
for i in range(5):
	if '1' in lisa[i]:
		row = i
lisa[row] = lisa[row].replace(' ', '')
col = lisa[row].index('1')
ans = abs(2 - row) + abs(2 - col)
print(ans)


posx = posy = -1
for i in range(5):
	x = input().split(' ')
	try:
		y = x.index('1')
	except:
		y = -1
	if y != -1:
		posy = i
		posx = y
x = 2 - posx if posx < 2 else posx - 2
y = 2 - posy if posy < 2 else posy - 2
print(x + y)


a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a4 = list(map(int, input().split()))
a5 = list(map(int, input().split()))
A = [a1, a2, a3, a4, a5]
for i in range(len(A)):
	if 1 in A[i]:
		n = A[i].index(1) + 1
		if n > 3:
			n = n - 3
		elif n < 3:
			n = 3 - n
		else:
			n = 0
		if i > 2:
			i = i - 2
		elif i < 2:
			i = 2 - i
		else:
			i = 0
		print(i + n)
		break


for c in range(5):
	r = ''.join(input().split(' '))
	if '1' in r:
		print(abs(c - 2) + abs(r.find('1') - 2))
		break


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()))
s = [a, b, c, d, e]
for i in range(5):
	if 1 in s[i]:
		f = abs(i + 1 - 3)
		break
for j in range(5):
	if s[i][j] == 1:
		g = abs(j + 1 - 3)
		print(f + g)
		break


a = []
for i in range(5):
	b = list(map(int, input().split()))
	a.append(b)
s1 = 0
s2 = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			s1 = i + 1
			s2 = j + 1
print(abs(3 - s1) + abs(3 - s2))


matrix = []
for j in range(5):
	row = list(map(int, input().split()))
	matrix.append(row)
for i in range(5):
	for t in range(5):
		if matrix[i][t] == 1:
			sol = abs(i - 2) + abs(t - 2)
print(sol)


M = []
for _ in range(5):
	M.append([int(x) for x in input().split()])
one = None
for i in range(5):
	for j in range(5):
		if M[i][j] == 1:
			one = (i, j)
	if one is not None:
		break
print(abs(2 - one[0]) + abs(2 - one[1]))


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
	if sum(a[-1]) == 1:
		row = i
column = a[row].index(1)
ans = abs(row - 2) + abs(column - 2)
print(ans)


ii = 0
jj = 0
for i in range(5):
	line = list(map(int, input().split()))
	for j in range(5):
		temp = line[j]
		if temp == 1:
			ii = i
			jj = j
print(abs(jj - 2) + abs(ii - 2))


from sys import stdout
matrix = [input().replace(' ', ''), input().replace(' ', ''), input().replace(' ', ''), input().replace(' ', ''), input().replace(' ', '')]
out = ''
for i in range(0, len(matrix)):
	pos = matrix[i].find('1')
	if pos != -1:
		out = abs(pos - 2) + abs(i - 2)
		break
stdout.write(str(out))


res = 0
for i in range(0, 5):
	arr = list(map(int, input().split()))
	for j in range(0, 5):
		if arr[j] == 1:
			res = abs(2 - i) + abs(2 - j)
			break
print(res)


matrix = []
(c_y, c_x) = (2, 2)
(n_y, n_y) = (None, None)
for _ in range(5):
	matrix.append(list(map(int, input().split())))
for (i, row) in enumerate(matrix):
	for (j, num) in enumerate(row):
		if num == 1:
			(n_y, n_x) = (i, j)
			break
n_moves = abs(c_y - n_y) + abs(c_x - n_x)
print(n_moves)


mrx = [[None] * 5] * 5
for i in range(5):
	k = input().split()
	for j in range(5):
		if k[j] == '1':
			break
	else:
		continue
	break
print(abs(i - 2) + abs(j - 2))


n = []
for i in range(5):
	n.append([int(j) for j in input().split()])
for i in range(5):
	for j in range(5):
		if n[i][j] == 1:
			a = i
			b = j
			break
if a < 2:
	n = 2 - a
else:
	n = a - 2
if b < 2:
	m = 2 - b
else:
	m = b - 2
print(n + m)


for i in range(5):
	val = list(map(int, input().split()))
	try:
		col = val.index(1)
		row = i
	except:
		pass
print(abs(row - 2) + abs(col - 2))


for i in range(1, 6):
	lst = [int(x) for x in input().split(' ')]
	if 1 in lst:
		count = abs(3 - i) + abs(3 - lst.index(1) - 1)
print(count)


x = y = ans = 0
for i in range(5):
	c = list(map(int, input().split()))
	for j in range(5):
		if c[j] == 1:
			(x, y) = (i + 1, j + 1)
		ans = abs(x - 3) + abs(y - 3)
print(ans)


a = []
for i in range(5):
	a.append([int(x) for x in input().split()])
	try:
		ind = a[i].index(1) + 1
		k = i + 1
	except:
		pass
print(abs(ind - 3) + abs(k - 3))


for i in range(5):
	s = list(input().split())
	try:
		j = s.index('1')
		print(abs(i - 2) + abs(j - 2))
	except ValueError:
		continue


a = []
for element in range(1, 6):
	a.append(input().split(' '))
for i in range(5):
	if '1' in a[i]:
		(y1, x1) = (a[i].index('1') + 1, i + 1)
steps = 0
while not (x1 == 3 and y1 == 3):
	if x1 < 3:
		x1 += 1
		steps += 1
	elif x1 > 3:
		x1 -= 1
		steps += 1
	if y1 < 3:
		y1 += 1
		steps += 1
	elif y1 > 3:
		y1 -= 1
		steps += 1
print(steps)


n = 5
a = []
ci = -1
cj = -1
for i in range(n):
	a.append(list(map(int, input().split(' '))))
for i in range(n):
	for j in range(n):
		if a[i][j] == 1:
			ci = i
			cj = j
			break
	if ci != -1 and cj != -1:
		break
k = abs(2 - ci % 4) + abs(2 - cj % 4)
print(k)


arr = []
for i in range(5):
	for j in range(1):
		x = list(map(int, input().split()))
	arr.append(x)
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			p = i
			q = j
if p != 2 or q != 2:
	mi = p - 2
	m = abs(mi)
	ni = q - 2
	n = abs(ni)
	sw = m + n
	print(sw)
else:
	print('0')


n = 5
for i in range(n):
	line = input().split()
	if '1' in line:
		row = i + 1
		col = line.index('1') + 1
		break
operations_left = abs(row - 3) + abs(col - 3)
print(operations_left)


m = []
for i in range(0, 5):
	m.append(list(map(int, input().split())))
for i in range(0, 5):
	for j in range(0, 5):
		if m[i][j] == 1:
			(lat, lon) = (i, j)
count = 0
while lat != 2:
	if lat > 2:
		lat = lat - 1
	else:
		lat = lat + 1
	count = count + 1
while lon != 2:
	if lon > 2:
		lon = lon - 1
	else:
		lon = lon + 1
	count = count + 1
print(count)


matrix = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i
			coloum = j
print(abs(row - 2) + abs(coloum - 2))


n1 = input().split()
n2 = input().split()
n3 = input().split()
n4 = input().split()
n5 = input().split()
n = [n1, n2, n3, n4, n5]
(a, b) = (0, 0)
flag = True
for i in range(5):
	for j in range(5):
		if n[i][j] == '1':
			flag = False
			(a, b) = (i, j)
			break
	if flag == False:
		break
print(abs(a - 2) + abs(b - 2))


mat = []
for i in range(5):
	row = [int(x) for x in input().strip().split()]
	mat.append(row)
pos = None
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			pos = (i, j)
			break
print(abs(pos[0] - 2) + abs(pos[1] - 2))


mat = []
pos = (3, 3)
for i in range(1, 6):
	t = list(input().split())
	if '1' in t:
		pos = (i, t.index('1') + 1)
		break
if pos == (3, 3):
	print(0)
else:
	print(abs(3 - pos[0]) + abs(3 - pos[1]))


x = 0
y = 0
for idx in range(1, 6):
	temp = input().split()
	if '1' in temp:
		y = idx
		x = temp.index('1') + 1
print(abs(x - 3) + abs(y - 3))


list = []
for _ in range(5):
	list.append(input().split(' '))
for i in range(5):
	for j in range(5):
		if list[i][j] != '0':
			(x, y) = (i, j)
print(abs(x - 2) + abs(y - 2))


j = 0
k = 0
for i in range(0, 5):
	x = [int(x) for x in input().split()]
	for t in range(0, 5):
		if x[t] == 1:
			j = i + 1
			k = t + 1
print(abs(j - 3) + abs(k - 3))


posx = -1
posy = -1
for i in range(5):
	inp = input()
	inpL = inp.split(' ')
	for j in range(5):
		if inpL[j] == '1':
			posx = i
			posy = j
print(abs(posx - 2) + abs(posy - 2))


c = [2, 2]
c1 = []
for i in range(5):
	arr = list(map(int, input().split(' ')))
	if 1 in arr:
		c1 = [i, arr.index(1)]
n = 0
while c != c1:
	if c1[0] > c[0]:
		n += 1
		c1[0] -= 1
	elif c1[0] < c[0]:
		n += 1
		c1[0] += 1
	elif c1[1] > c[1]:
		n += 1
		c1[1] -= 1
	elif c1[1] < c[1]:
		n += 1
		c1[1] += 1
print(n)


movs = 0
for i in range(5):
	ins = list(map(int, input().split()))
	if 1 in ins:
		movs += abs(ins.index(1) - 2) + abs(i - 2)
print(movs)


for i in range(5):
	l = [int(a) for a in input().split()]
	x = sum(l)
	if x == 1:
		print(abs(l.index(1) - 2) + abs(i - 2))


m = []
c = 0
for i in range(5):
	stroka = [int(a) for a in input().split()]
	m.append(stroka)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			if i == 0 or i == 4:
				c += 2
			if i == 1 or i == 3:
				c += 1
			if j == 0 or j == 4:
				c += 2
			if j == 1 or j == 3:
				c += 1
print(c)


a = None
b = None
for i in range(5):
	l = list(map(int, input().split()))
	for j in range(5):
		if l[j] == 1:
			a = i
			b = j
			break
	if not a is None:
		break
moves = 0
moves = abs(a - 2) + abs(b - 2)
print(moves)


matrix = []
for i in range(5):
	matrix.append([int(x) for x in input().split()])
current_location = None
desired_location = [2, 2]
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] == 1:
			current_location = [i, j]
print(abs(desired_location[0] - current_location[0]) + abs(desired_location[1] - current_location[1]))


x = 5
matrix = []
middle = x // 2 + 1
for i in range(x):
	n = input().split()
	matrix.append(n)
for i in range(x):
	for j in range(x):
		line = matrix[i]
		line[j] = int(line[j])
		if line[j] != 0:
			linha = i + 1
			coluna = j + 1
res = abs(middle - linha) + abs(middle - coluna)
print(res)


x = []
for i in range(5):
	a = [int(num) for num in input().split()]
	x.append(a)
	if 1 in a:
		for j in range(5):
			if a[j] == 1:
				xcor = i
				ycor = j
k = abs(xcor - 2) + abs(ycor - 2)
print(k)


n = 5
m = 5
mat = []
for i in range(n):
	inputs = list(map(int, input().split(' ')))[:m]
	mat.append(inputs)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			row = i
			column = j
count = 0
while row != 2:
	if row > 2:
		row = row - 1
	else:
		row = row + 1
	count = count + 1
while column != 2:
	if column > 2:
		column = column - 1
	else:
		column = column + 1
	count += 1
print(count)


import math
import os
import random
import re
import sys

def solve(matrix):
	i = r = c = 0
	isOneFound = False
	while i < 5 and (not isOneFound):
		j = 0
		while j < 5 and (not isOneFound):
			if matrix[i][j] == '1':
				r = i
				c = j
				isOneFound = True
			j += 1
		i += 1
	return abs(r - 2) + abs(c - 2)
matrix = list()
for _ in range(0, 5):
	matrix.append(input().split(' '))
print(solve(matrix))


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
for i in range(5):
	if 1 in matrix[i]:
		I = i + 1
		line = matrix[i]
for f in range(5):
	if line[f] == 1:
		F = f + 1
print(str(abs(F - 3) + abs(I - 3)))


m = 0
n = 0
for i in range(0, 5):
	s = input()
	l = s.split(' ')
	for j in range(0, 5):
		if l[j] == '1':
			m = i + 1
			n = j + 1
			break
if m > 3:
	m = m - 3
else:
	m = 3 - m
if n > 3:
	n = n - 3
else:
	n = 3 - n
print(m + n)


matrix = []
for _ in range(5):
	line = input()
	matrix.append(line.split(' '))

def find_one(matrix):
	for r in range(5):
		for c in range(5):
			if matrix[r][c] == '1':
				return (r, c)
(r, c) = find_one(matrix)
print(abs(r - 2) + abs(c - 2))


arr = []
posx = 0
posy = 0
for i in range(5):
	inter = input()
	inter = inter.replace(' ', '')
	index = inter.find('1')
	if index != -1:
		posy = i + 1
		posx = index + 1
print(abs(posx - 3) + abs(posy - 3))


for x in range(5):
	line = list(map(int, input().split()))
	if 1 in line:
		location = [x + 1, line.index(1) + 1]
		break
moves = abs(x - 2) + abs(line.index(1) - 2)
print(moves)


arr = []
count = 0
for i in range(5):
	a = list(map(int, input().split()))
	arr.append(a)
for _ in range(5):
	try:
		if 1 in arr[_]:
			b = arr[_].index(1)
			i = _
			j = b
	except ValueError:
		pass
if i > 2:
	while i != 2:
		i -= 1
		count += 1
elif i < 2:
	while i != 2:
		i += 1
		count += 1
if j > 2:
	while j != 2:
		j -= 1
		count += 1
elif j < 2:
	while j != 2:
		j += 1
		count += 1
print(count)


n = 5
h = 1
while n > 0:
	x = list(map(int, input().split()))
	if x[0] == 1:
		v = 1
		break
	elif x[1] == 1:
		v = 2
		break
	elif x[2] == 1:
		v = 3
		break
	elif x[3] == 1:
		v = 4
		break
	elif x[4] == 1:
		v = 5
		break
	h += 1
	n -= 1
if h < 3:
	c = 3 - h
else:
	c = h - 3
if v < 3:
	a = 3 - v
else:
	a = v - 3
print(a + c)


l = [0] * 5
l[0] = list(map(int, input().split()))
l[1] = list(map(int, input().split()))
l[2] = list(map(int, input().split()))
l[3] = list(map(int, input().split()))
l[4] = list(map(int, input().split()))
for i in range(len(l)):
	if 1 in l[i]:
		r = i + 1
		break
c = l[r - 1].index(1) + 1
m = abs(c - 3) + abs(r - 3)
print(m)


answ = ''
for i in range(0, 5):
	a = input()
	for j in range(0, 9):
		if a[j] == '1':
			answ = abs(j - 4) // 2 + abs(i - 2)
print(answ)


steps = 0
matrix = []
a = input()
b = input()
c = input()
d = input()
e = input()
matrix.append(a.split(' '))
matrix.append(b.split(' '))
matrix.append(c.split(' '))
matrix.append(d.split(' '))
matrix.append(e.split(' '))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			if i >= 2 and j >= 2:
				steps = i - 2 + j - 2
			elif i >= 2 and j <= 2:
				steps = i - 2 + 2 - j
			elif i <= 2 and j >= 2:
				steps = 2 - i + j - 2
			elif i <= 2 and j <= 2:
				steps = 2 - i + 2 - j
print(steps)


for i in range(5):
	k = list(map(int, input().split()))
	if 1 in k:
		j = k.index(1)
		break
print(abs(i + 1 - 3) + abs(j + 1 - 3))


l = ''
row = -1
column = -1
for i in range(5):
	l = input()
	s = l.split()
	for e in range(len(s)):
		if int(s[e]) == 1:
			row = i + 1
			column = e + 1
count = abs(3 - row) + abs(3 - column)
print(count)


for i in range(1, 6):
	li = input()
	f = li.find('1')
	if f != -1:
		a = i
		b = f // 2 + 1
c = 0
while (a == 3 and b == 3) != 1:
	if a > 3:
		a = a - 1
		c += 1
	elif a < 3:
		a = a + 1
		c += 1
	elif b > 3:
		b = b - 1
		c += 1
	elif b < 3:
		b = b + 1
		c += 1
print(c)


l1 = []
l2 = []
l3 = []
for i in range(5):
	l2 = []
	inp = input()
	inp = inp.split(' ')
	for j in range(len(inp)):
		if int(inp[j]) == 1:
			l3.append(i)
			l3.append(j)
		l2.append(int(inp[j]))
	l1.append(l2)
rowmin = l3[0] - 2
if rowmin < 0:
	rowmin = -1 * rowmin
colmin = l3[1] - 2
if colmin < 0:
	colmin = -1 * colmin
print(rowmin + colmin)


def beautifulMatrix():
	a = []
	for i in range(5):
		s = [int(x) for x in input().split()]
		a.append(s)
	for i in range(5):
		for j in range(5):
			if a[i][j] == 1:
				(n, m) = (i, j)
	p = abs(n - 2)
	q = abs(m - 2)
	print(p + q)
beautifulMatrix()


array = []
number = 0
for i in range(5):
	line = input()
	temp = line.split(' ')
	for j in range(5):
		if temp[j] == '1':
			a = i
			b = j
	array.append(temp)
while a != 2 or b != 2:
	if a > 2:
		a -= 1
		number += 1
	if a < 2:
		a += 1
		number += 1
	if b > 2:
		b -= 1
		number += 1
	if b < 2:
		b += 1
		number += 1
print(number)


def main():
	(i, j) = (None, None)
	for i in range(1, 6):
		row = input()
		if '1' in row:
			j = row.find('1') // 2 + 1
			break
	min_moves = abs(3 - i) + abs(3 - j)
	print(min_moves)
main()


lst = list()
t = 0
r = -1
c = -1
while t < 5:
	lst1 = list(map(int, input().split(' ')))
	if lst1.count(1) != 0:
		r = t
		c = lst1.index(1)
	lst.append(lst1)
	t = t + 1
r = r + 1
c = c + 1
print(abs(r - 3) + abs(c - 3))


l = []
for i in range(5):
	l.append(input().split(' '))
count = 0
for y in range(5):
	for x in range(5):
		if l[y][x] == '1':
			count = abs(2 - y) + abs(2 - x)
print(count)


y = 0
for ty in range(5):
	k = list((int(a) for a in input().split()))
	if sum(k) == 0:
		continue
	x = k.index(1)
	y = ty
	break
print(abs(2 - x) + abs(2 - y))


n = 5
a = [[]] * n
(x, y) = (0, 0)
for i in range(n):
	a[i] = list(map(int, input().split()))
for i in range(n):
	if 1 in a[i]:
		x = i
		y = a[i].index(1)
		break
print(abs(2 - x) + abs(2 - y))


a = []
b = []
c = []
d = []
f = []
a = input().split()
b = input().split()
c = input().split()
d = input().split()
f = input().split()
aa = 0
k = 0
i = 0
bb = 0
cc = 0
ff = 0
dd = 0
for i in range(0, 5):
	if a[i] == '1':
		aa = i + 1
		break
for i in range(0, 5):
	if b[i] == '1':
		bb = i + 1
		break
for i in range(0, 5):
	if c[i] == '1':
		cc = i + 1
		break
for i in range(0, 5):
	if d[i] == '1':
		dd = i + 1
		break
for i in range(0, 5):
	if f[i] == '1':
		ff = i + 1
		break
if aa != 0:
	k = abs(aa - 3) + 2
if bb != 0:
	k = abs(bb - 3) + 1
if cc != 0:
	k = abs(cc - 3)
if dd != 0:
	k = abs(dd - 3) + 1
if ff != 0:
	k = abs(ff - 3) + 2
print(k)


row = 0
colum = 0
count = 0
for x in range(5):
	colum = 0
	a = list(map(int, input().split()))
	for y in a:
		if y == 1:
			count = abs(2 - row) + abs(2 - colum)
		else:
			colum += 1
	row += 1
print(count)


import sys
import math

def solve():
	ans = None
	for i in range(1, 6):
		row = [int(x) for x in input().split()]
		if 1 in row:
			ans = abs(i - 3) + abs(row.index(1) + 1 - 3)
	print(ans)
test_cases = 1
for _ in range(test_cases):
	solve()


matrix = []
x = 0
y = 0
for i in range(0, 5):
	tmp = [int(i) for i in input().split()]
	matrix.append(tmp)
	if 1 in matrix[i]:
		pos = tmp[:]
x = abs(pos.index(1) - 2)
y = abs(matrix.index(pos) - 2)
print(x + y)


a = 0
for i in range(5):
	s = input()
	s = s.split()
	for y in range(5):
		if int(s[y]) == 1:
			a = abs(y - 2) + abs(i - 2)
print(a)


n = 5
a = []
for i in range(n):
	c = list(map(int, input().split()))
	a.append(c)
s = 0
while a[2][2] == 0:
	for i in range(5):
		for j in range(5):
			if a[2][2] == 0 and a[i][j] == 1:
				if i < 2 and j > 2:
					a[i][j] = 0
					a[i][j - 1] = 1
					s += 1
				elif i > 2 and j > 2:
					a[i][j] = 0
					a[i][j - 1] = 1
					s += 1
				elif i > 2 and j < 2:
					a[i][j] = 0
					a[i][j + 1] = 1
					s += 1
				elif i < 2 and j < 2:
					a[i][j] = 0
					a[i][j + 1] = 1
					s += 1
				elif i < 2 and j == 2:
					a[i][j] = 0
					a[i + 1][j] = 1
					s += 1
				elif i > 2 and j == 2:
					a[i][j] = 0
					a[i - 1][j] = 1
					s += 1
				elif i == 2 and j < 2:
					a[i][j] = 0
					a[i][j + 1] = 1
					s += 1
				elif i == 2 and j > 2:
					a[i][j] = 0
					a[i][j - 1] = 1
					s += 1
print(s)


mat = []
row = 1
col = 1
for i in range(5):
	mat.append(input().split(' '))
	for j in range(5):
		mat[i][j] = int(mat[i][j])
		if mat[i][j] == 1:
			row += i
			col += j
row_b = abs(row - 3)
col_b = abs(col - 3)
print(row_b + col_b)


row = []
m = []
x = 0
y = 0
for i in range(5):
	row = list(map(int, input().split()))
	m.append(row)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			x = i + 1
			y = j + 1
ans = abs(x - 3) + abs(y - 3)
print(ans)


matrix = []
(i, j) = (0, 0)
for a in range(5):
	row = input().split()
	if '1' in row:
		i = a
		j = row.index('1')
	matrix.append(row)
print(abs(2 - i) + abs(2 - j))


zeile1 = input('')
zeile2 = input('')
zeile3 = input('')
zeile4 = input('')
zeile5 = input('')
zahl = 0
z1 = []
z2 = []
z3 = []
z4 = []
z5 = []
for i in range(len(zeile1)):
	if zeile1[i] == '1':
		x = 1
		y = i
	if zeile2[i] == '1':
		x = 2
		y = i
	if zeile3[i] == '1':
		x = 3
		y = i
	if zeile4[i] == '1':
		x = 4
		y = i
	if zeile5[i] == '1':
		x = 5
		y = i
y = int(y / 2 + 1)
anzahl = 0
if x < 3:
	anzahl += 3 - x
elif x > 3:
	anzahl += x - 3
if y < 3:
	anzahl += 3 - y
elif y > 3:
	anzahl += y - 3
print(anzahl)


b = []
for i in range(5):
	b.append(input().split())
for i in range(len(b)):
	if '1' in b[i]:
		row = i
		column = b[i].index('1')
print(abs(2 - column) + abs(2 - row))


r1 = input('')
r2 = input('')
r3 = input('')
r4 = input('')
r5 = input('')
r2 = r2.split()
r3 = r3.split()
r4 = r4.split()
r5 = r5.split()
r1 = r1.split()
move = 0
if '1' in r1:
	move = move + 2
	for i in range(0, 5):
		if r1[i] == '1':
			if i == 0 or i == 4:
				move = move + 2
				break
			elif i == 1 or i == 3:
				move = move + 1
			else:
				break
elif '1' in r2:
	move = move + 1
	for i in range(0, 5):
		if r2[i] == '1':
			if i == 0 or i == 4:
				move = move + 2
				break
			elif i == 1 or i == 3:
				move = move + 1
			else:
				break
elif '1' in r3:
	move = move + 0
	for i in range(0, 5):
		if r3[i] == '1':
			if i == 0 or i == 4:
				move = move + 2
				break
			elif i == 1 or i == 3:
				move = move + 1
			else:
				break
elif '1' in r4:
	move = move + 1
	for i in range(0, 5):
		if r4[i] == '1':
			if i == 0 or i == 4:
				move = move + 2
				break
			elif i == 1 or i == 3:
				move = move + 1
			else:
				break
elif '1' in r5:
	move = move + 2
	for i in range(0, 5):
		if r5[i] == '1':
			if i == 0 or i == 4:
				move = move + 2
				break
			elif i == 1 or i == 3:
				move = move + 1
			else:
				break
print(move)


a = []
y = []
d = 0
for i in range(5):
	x = list(map(int, input().split()))
	a.append(x)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			y.append(i)
			y.append(j)
			break
if y[0] > 2 and y[1] == 2:
	y[0] = y[0] - 2
	d = d + y[0]
elif y[0] == 2 and y[1] > 2:
	y[1] = y[1] - 2
	d = d + y[1]
elif y[0] == 2 and y[1] < 2:
	y[1] = 2 - y[1]
	d = d + y[1]
elif y[0] < 2 and y[1] == 2:
	y[0] = 2 - y[0]
	d = d + y[0]
elif y[0] > 2 and y[1] < 2:
	y[0] = y[0] - 2
	y[1] = 2 - y[1]
	d = d + y[0] + y[1]
elif y[0] < 2 and y[1] > 2:
	y[0] = 2 - y[0]
	y[1] = y[1] - 2
	d = d + y[0] + y[1]
elif y[0] > 2 and y[1] > 2:
	y[0] = y[0] - 2
	y[1] = y[1] - 2
	d = d + y[0] + y[1]
elif y[0] < 2 and y[1] < 2:
	y[0] = 2 - y[0]
	y[1] = 2 - y[1]
	d = d + y[0] + y[1]
print(d)


lis = [list(input().split()), list(input().split()), list(input().split()), list(input().split()), list(input().split())]
i = 0
j = 0
ok = True
for i in range(5):
	if ok == False:
		i -= 1
		break
	for j in range(5):
		if lis[i][j] == '1':
			ok = False
			break
print(abs(i - 2) + abs(j - 2))


(a, b, c, d, e) = input().split()
(f, g, h, i, j) = input().split()
(k, l, m, n, o) = input().split()
(p, q, r, s, t) = input().split()
(u, v, w, x, y) = input().split()
matrix = [[a, b, c, d, e], [f, g, h, i, j], [k, l, m, n, o], [p, q, r, s, t], [u, v, w, x, y]]
row = -1
for ko in matrix:
	row += 1
	col = 0
	for index in ko:
		if index == '1':
			print(abs(col - 2) + abs(2 - row))
		col += 1


input = [input().split(' ') for _ in range(5)]
count = 0
while True:
	for x in range(len(input)):
		if '1' in input[x]:
			row = x
	if row < 2:
		(input[row], input[row + 1]) = (input[row + 1], input[row])
		count += 1
	elif row > 2:
		(input[row], input[row - 1]) = (input[row - 1], input[row])
		count += 1
	else:
		break
while True:
	col = input[row].index('1')
	if col < 2:
		(input[row][col], input[row][col + 1]) = (input[row][col + 1], input[row][col])
		count += 1
	elif col > 2:
		(input[row][col], input[row][col - 1]) = (input[row][col - 1], input[row][col])
		count += 1
	else:
		break
print(count)


for row in range(5):
	for (col, x) in enumerate(input().split()):
		if x == '1':
			print(abs(2 - row) + abs(2 - col))


res = 0
for i in range(0, 5):
	x = input()
	x = x.split()
	for l in range(0, 5):
		if int(x[l]) == 1:
			if l < 2:
				res = res + (2 - l)
			if l > 2:
				res = res + (l - 2)
			if i < 2:
				res = res + (2 - i)
			if i > 2:
				res = res + (i - 2)
print(res)


arr = []
for i in range(0, 5):
	arr.append([int(i) for i in input().split(' ')])
for i in range(0, len(arr)):
	if 1 in arr[i]:
		print(abs(arr[i].index(1) - 2) + abs(i - 2))
		exit()


def BeautifulMatrix(matrix):
	(x, y) = FindPositionOfOne(matrix)
	noOfMoves = abs(y - 2) + abs(x - 2)
	print(noOfMoves)

def FindPositionOfOne(matrix):
	i = 0
	for row in matrix:
		j = 0
		for element in row:
			if element == '1':
				return (i, j)
			j += 1
		i += 1
matrix = []
temp = 0
while temp < 5:
	P = [x for x in input().split()]
	matrix.append(P)
	temp += 1
BeautifulMatrix(matrix)


(r, c) = (-1, -1)
for i in range(5):
	rw = list(map(int, input().split()))
	for j in range(0, 5):
		if rw[j] == 1:
			(r, c) = (i, j)
			break
if r != -1:
	print(abs(r - 2) + abs(c - 2))


ap = []
c = 0
for i in range(5):
	s = list(map(int, input().split()))
	ap.append(s)
	if 1 in s:
		r = s.index(1)
		g = i
while 1 not in ap[2]:
	while g > 2:
		z = ap[g - 1]
		ap[g - 1] = ap[g]
		ap[g] = z
		g -= 1
		c += 1
	while g < 2:
		z = ap[g + 1]
		ap[g + 1] = ap[g]
		ap[g] = z
		g += 1
		c += 1
while ap[2][2] != 1:
	while r > 2:
		z = ap[2][r]
		ap[2][r] = ap[2][r - 1]
		ap[2][r - 1] = z
		r -= 1
		c += 1
	while r < 2:
		z = ap[2][r]
		ap[2][r] = ap[2][r + 1]
		ap[2][r + 1] = z
		r += 1
		c += 1
print(c)


a1 = input('')
a2 = input('')
a3 = input('')
a4 = input('')
a5 = input('')
if a1.find('1') != -1:
	vert_moves = 2
	hor_moves = abs(a1.find('1') / 2 + 1 - 3)
elif a2.find('1') != -1:
	vert_moves = 1
	hor_moves = abs(a2.find('1') / 2 + 1 - 3)
elif a3.find('1') != -1:
	vert_moves = 0
	hor_moves = abs(a3.find('1') / 2 + 1 - 3)
elif a4.find('1') != -1:
	vert_moves = 1
	hor_moves = abs(a4.find('1') / 2 + 1 - 3)
elif a5.find('1') != -1:
	vert_moves = 2
	hor_moves = abs(a5.find('1') / 2 + 1 - 3)
tot_moves = vert_moves + hor_moves
print(int(tot_moves))


matrix = []
for i in range(5):
	matrix.append(input().split())
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			print(abs(i + 1 - 3) + abs(j + 1 - 3))
			break


l = []
while not l or len(l) < len(l[0]):
	l.append(list(map(int, input().split())))
for x in l:
	if 1 in x:
		y = [l.index(x) + 1, x.index(1) + 1]
print(int(abs((len(l) + 1) / 2 - y[0]) + abs((len(l) + 1) / 2 - y[1])))


matrix = []
for i in range(5):
	a = list(map(int, input().split()))
	matrix.append(a)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			s1 = abs(2 - i)
			s2 = abs(2 - j)
print(s1 + s2)


matrix = [[0] * 5] * 5
for i in range(0, 5):
	matrix[i] = input().split()
	if '1' in matrix[i]:
		(row_idx_counter, col_idx_counter) = (i, matrix[i].index('1'))
min_counter = 0
while True:
	if row_idx_counter == 2 and col_idx_counter == 2:
		break
	if row_idx_counter > 2:
		row_idx_counter -= 1
		min_counter += 1
	elif row_idx_counter < 2:
		row_idx_counter += 1
		min_counter += 1
	if col_idx_counter > 2:
		col_idx_counter -= 1
		min_counter += 1
	elif col_idx_counter < 2:
		col_idx_counter += 1
		min_counter += 1
print(min_counter)


n = 5
lst = []
for i in range(n):
	c = []
	s = input().split()
	for m in s:
		c.append(int(m))
	lst.append(c)
a = 0
b = 0
for i in range(len(lst)):
	for z in range(len(lst)):
		if lst[i][z] == 1:
			a = i
			b = z
print(abs(a - 2) + abs(b - 2))


import math
for i in range(0, 5):
	i1 = input().split(' ')
	if '1' in i1:
		a = abs(2 - i) + abs(2 - i1.index('1'))
		break
print(a)


for i in range(0, 5):
	for (j, a) in enumerate(map(int, input().split())):
		if a == 1:
			print(abs(i - 2) + abs(j - 2))


l1 = input()
l2 = input()
l3 = input()
l4 = input()
l5 = input()
matrix = [l1, l2, l3, l4, l5]
line = 0
col = 0
for i in range(5):
	if '1' in matrix[i]:
		line = i + 1
		col = matrix[i].split(' ').index('1') + 1
print(abs(3 - line) + abs(3 - col))


s = 0
a = []
for i in range(5):
	a.append([int(j) for j in input().split()])
	if 1 in a[i]:
		if i == 0 or i == 4:
			s += 2
		elif i == 1 or i == 3:
			s += 1
	if '1' in str(a[i][0]) or '1' in str(a[i][4]):
		s += 2
	elif '1' in str(a[i][1]) or '1' in str(a[i][3]):
		s += 1
print(s)


x = 1
for i in range(5):
	b = list(map(int, input().strip().split()))
	if x in b:
		y = b.index(x)
		break
print(abs(2 - i) + abs(2 - y))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = 5
	a = [LI() for _ in range(n)]
	r = 0
	for i in range(n):
		if 1 in a[i]:
			r += abs(2 - i)
			j = a[i].index(1)
			r += abs(2 - j)
	return r
print(main())


row = []
for i in range(5):
	col = list(map(int, input().split()))
	for j in range(len(col)):
		if col[j] == 1:
			print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
			break
	row.append(col)


a = []
s = 0
for x in range(5):
	t = []
	t = list(map(int, input().split()))
	a.append(t)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			if j == 3 or j == 1:
				s = 1
				a[i][2] = 1
			elif j == 0 or j == 4:
				s = 2
				a[i][2] = 1
for i in range(5):
	if a[i][2] == 1:
		if i == 0 or i == 4:
			s += 2
		elif i == 1 or i == 3:
			s += 1
print(s)


o = (2, 2)
s = (0, 0)

def get_index(a, n):
	try:
		index_value = a.index(n)
	except ValueError:
		index_value = -1
	return index_value
for j in range(5):
	row = input().split(' ')
	i = get_index(row, '1')
	if i > -1:
		s = (i, j)
		break
print(abs(s[0] - o[0]) + abs(s[1] - o[1]))


def main():
	for i in range(5):
		row = input().split()
		try:
			j = row.index('1')
			print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
			break
		except ValueError:
			continue
main()


import math
for i in range(5):
	value = input()
	num = value.split()
	for j in range(len(num)):
		if num[j] == '1':
			values = abs(j - 2) + abs(i - 2)
print(values)


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))
if r1[0] == 1:
	print('4')
elif r1[1] == 1:
	print('3')
elif r1[2] == 1:
	print('2')
elif r1[3] == 1:
	print('3')
elif r1[4] == 1:
	print('4')
elif r2[0] == 1:
	print('3')
elif r2[1] == 1:
	print('2')
elif r2[2] == 1:
	print('1')
elif r2[3] == 1:
	print('2')
elif r2[4] == 1:
	print('3')
elif r3[0] == 1:
	print('2')
elif r3[1] == 1:
	print('1')
elif r3[2] == 1:
	print('0')
elif r3[3] == 1:
	print('1')
elif r3[4] == 1:
	print('2')
elif r4[0] == 1:
	print('3')
elif r4[1] == 1:
	print('2')
elif r4[2] == 1:
	print('1')
elif r4[3] == 1:
	print('2')
elif r4[4] == 1:
	print('3')
elif r5[0] == 1:
	print('4')
elif r5[1] == 1:
	print('3')
elif r5[2] == 1:
	print('2')
elif r5[3] == 1:
	print('3')
elif r5[4] == 1:
	print('4')


i = 1
while i <= 5:
	(a, b, c, d, e) = input().split()
	(a, b, c, d, e) = (int(a), int(b), int(c), int(d), int(e))
	if a == 1:
		x = 1
		y = i
	if b == 1:
		x = 2
		y = i
	if c == 1:
		x = 3
		y = i
	if d == 1:
		x = 4
		y = i
	if e == 1:
		x = 5
		y = i
	i = i + 1
z = x - 3
z = abs(z)
l = y - 3
l = abs(l)
print(z + l)


def BM():
	for i in range(5):
		a = input().split(' ')
		if '1' in a:
			b = a.index('1') + 1
			sol = abs(3 - i - 1) + abs(3 - b)
			return sol
			break
print(BM())


rownum = 0
moves = 0
for i in range(5):
	row = input().split()
	for column in range(5):
		if row[column] == '1':
			moves = abs(2 - rownum) + abs(2 - column)
	rownum += 1
print(moves)


import math
matrix = []
for i in range(5):
	z = input().split(' ')
	if '1' in z:
		y = i
		x = z.index('1')
print(int(math.fabs(x - 2) + math.fabs(y - 2)))


for k in range(1, 6):
	string = input().split()
	if '1' in string:
		x_coor = string.index('1') + 1
		y_coor = k
		print(abs(3 - x_coor) + abs(3 - y_coor))
		break


i = 0
while i < 5:
	n = [int(x) for x in input().split(' ')]
	if 1 in n:
		print(abs(i - 2) + abs(n.index(1) - 2))
		break
	i = i + 1


import sys
matrix = [[0 for x in range(5)] for y in range(5)]
row = 0
for line in sys.stdin:
	column = 0
	for word in line.split():
		matrix[row][column] = int(word)
		column += 1
	row += 1
actions = 0
row = 0
for line in matrix:
	column = 0
	for col in line:
		if matrix[row][column] == 1:
			if column < 2:
				actions += 2 - column
			elif column > 2:
				actions += column - 2
			if row < 2:
				actions += 2 - row
			elif row > 2:
				actions += row - 2
		column += 1
	row += 1
print(actions)


for i in range(5):
	s = input().split()
	if '1' in s:
		a = abs(s.index('1') + 1 - 3) + abs(i - 2)
print(a)


lst = []
for i in range(5):
	inputted_value = [int(x) for x in input().split()]
	lst.append(inputted_value)
moves = 0
index = 0
while index < len(lst):
	if 1 in lst[index]:
		lst_index = index
		break
	index += 1
if lst_index == 0 or lst_index == 4:
	moves += 2
elif lst_index == 1 or lst_index == 3:
	moves += 1
index_second = lst[lst_index].index(1)
if index_second == 0 or index_second == 4:
	moves += 2
elif index_second == 1 or index_second == 3:
	moves += 1
print(moves)


one_index = []
for row in range(5):
	line = input().split(' ')
	for col in range(5):
		if line[col] == '1':
			one_index = [row, col]
			break
	if len(one_index) > 0:
		break
print(abs(one_index[0] - 2) + abs(one_index[1] - 2))


l = []
for _ in range(5):
	l.append([int(i) for i in input().split()])
(x, y) = (0, 0)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			x = i
			y = j
			break
if x < 2:
	x = abs(2 - x)
else:
	x = abs(x - 2)
if y < 2:
	y = abs(2 - y)
else:
	y = abs(y - 2)
print(x + y)


lst = [[int(x) for x in input().split()] for x in range(5)]
k = max(lst)
print(abs(lst.index(k) - 2) + abs(k.index(1) - 2))


matrix = []
one_i = 0
one_j = 0
for i in range(0, 5):
	row = input().split()
	row = [int(i) for i in row]
	if 1 in row:
		one_i = i
		one_j = row.index(1)
	matrix.append(row)
print(abs(2 - one_i) + abs(2 - one_j))


def remove(string):
	return string.replace(' ', '')
row = 1
for i in range(5):
	line = input()
	line = remove(line)
	result = line.find('1') + 1
	if result == 0:
		row += 1
	else:
		break
if result == 1 or result == 5:
	col = 2
elif result == 2 or result == 4:
	col = 1
else:
	col = 0
if row == 1 or row == 5:
	rc = 2
elif row == 2 or row == 4:
	rc = 1
else:
	rc = 0
print(rc + col)


def BeautifulMatrix():
	matrix = [[], [], [], [], []]
	moves = []
	bPos = [2, 2]
	oPos = []
	for i in range(5):
		matrix[i] = list(map(int, input().strip().split()))[:5]
	for r in range(5):
		for c in range(5):
			if matrix[r][c] == 1:
				oPos = [r, c]
				break
	moves = [abs(oPos[0] - bPos[0]), abs(oPos[1] - bPos[1])]
	print(moves[0] + moves[1])
BeautifulMatrix()


for x in range(5):
	tem = list(input().split())
	if '1' in tem:
		a = x
		b = tem.index('1')
print(abs(a - 2) + abs(b - 2))


try:
	l = [2, 1, 0, 1, 2]
	for i in l:
		s = input()
		if '1' in s:
			print(i + l[s.find('1') // 2])
except:
	pass


i = 1
t = 5
br = 0
while t > 0:
	j = 1
	a = input().split()
	for k in a:
		if k == '1':
			br = 1
			break
		j += 1
	if br == 1:
		break
	i += 1
	t -= 1
c = abs(3 - i)
d = abs(3 - j)
print(c + d)


for i in range(5):
	n = input().split()
	for j in range(5):
		if n[j] == '1':
			k = j + 1
			m = i + 1
print(abs(3 - k) + abs(3 - m))


m = []
x = 0
y = 0
for i in range(5):
	x = [int(x) for x in input().split()]
	m.append(x)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			x = i
			y = j
			break
if x < 2:
	x = 2 - x
else:
	x = x - 2
if y < 2:
	y = 2 - y
else:
	y = y - 2
print(x + y)


arr = []
for _ in range(5):
	arr.append(list(map(int, input().split())))
steps = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			ith = abs(2 - i)
			jth = abs(2 - j)
			steps = ith + jth
			break
print(steps)


matrix = list()
counter_i = 0
counter_j = 0
flag = 0
for i in range(5):
	matrix.append(input().split())
for i in matrix:
	counter_i += 1
	counter_j = 0
	for j in i:
		counter_j += 1
		if int(j) == 1:
			flag = 1
			break
	if flag == 1:
		break
print(abs(counter_i - 3) + abs(counter_j - 3))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
mass = [a, b, c, d, e]
x = 0
y = 0
for i in range(5):
	for j in range(5):
		if mass[i][j] == '1':
			x = i
			y = j
print(abs(x - 2) + abs(y - 2))


(row, col) = (0, 0)
for i in range(5):
	li = list(map(int, input().split()))
	try:
		r = li.index(1)
		col = r + 1
		row = i + 1
	except:
		pass
ans = abs(3 - row) + abs(3 - col)
print(ans)


matrix = [None, None, None, None, None]
matrix[0] = input().split()
matrix[1] = input().split()
matrix[2] = input().split()
matrix[3] = input().split()
matrix[4] = input().split()
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			a = i
			b = j
print(abs(a - 2) + abs(b - 2))


l = []
for i in range(5):
	l.append([int(x) for x in input().strip().split(' ')])
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			(u, v) = (i, j)
print(abs(u - 2) + abs(v - 2))


row_one_matrix = list(map(int, input().split(' ')))
row_two_matrix = list(map(int, input().split(' ')))
row_three_matrix = list(map(int, input().split(' ')))
row_four_matrix = list(map(int, input().split(' ')))
row_five_matrix = list(map(int, input().split(' ')))
matrix = [row_one_matrix, row_two_matrix, row_three_matrix, row_four_matrix, row_five_matrix]
rowIndex = columnIndex = 0
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			rowIndex = i
			columnIndex = j
			break
moves = 0
moves += abs(2 - rowIndex)
moves += abs(2 - columnIndex)
print(moves)


a = [[int(x) for x in input().split()] for i in range(5)]
for i in range(5):
	for ii in range(5):
		if a[i][ii] == 1:
			x = i
			y = ii
print(abs(x - 2) + abs(y - 2))


matrix = []
flag = 0
for i in range(5):
	matrix.append(list(map(int, input().split()))[:5])
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			jVal = j
			iVal = i
			flag = 1
			break
	if flag == 1:
		break
print(abs(iVal - 2) + abs(jVal - 2))


i = 0
while i < 5:
	fila = input()
	fila = fila.split(' ')
	if '1' in fila:
		for k in range(5):
			if fila[k] == '1':
				x = k - 2
				y = i - 2
				break
	i += 1
print(abs(x) + abs(y))


mlist = []
ii = 0
jj = 0
for i in range(5):
	listm = list(map(int, input().split()))
	mlist.append(listm)
for i in range(5):
	for j in range(5):
		if mlist[i][j] == 1:
			ii = i
			jj = j
			break
if jj >= 2 and ii <= 2:
	print(jj - ii)
elif jj >= 2 and ii > 2:
	print(abs(abs(4 - ii) - jj))
elif ii <= 2 and jj < 2:
	print(abs(abs(4 - jj) - ii))
elif jj < 2 and ii > 2:
	print(abs(abs(4 - jj) - abs(4 - ii)))


kv = list((list(map(int, input().split())) for i in range(5)))
for i in range(5):
	if 1 in kv[i]:
		y1 = kv[i].index(1) + 1
		x1 = i + 1
		break
print(max(3, y1) - min(3, y1) + max(3, x1) - min(3, x1))


row_1 = input().split()
row_2 = input().split()
row_3 = input().split()
row_4 = input().split()
row_5 = input().split()
if '1' in row_1:
	column = row_1.index('1')
	row = 1
elif '1' in row_2:
	column = row_2.index('1')
	row = 2
elif '1' in row_3:
	column = row_3.index('1')
	row = 3
elif '1' in row_4:
	column = row_4.index('1')
	row = 4
elif '1' in row_5:
	column = row_5.index('1')
	row = 5
print(abs(column - 2) + abs(row - 3))


a = []
for i in range(0, 5):
	n = input().split()
	a.append(n)
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == '1':
			x = i
			y = j
pos = abs(2 - x) + abs(2 - y)
print(pos)


def Print():
	print('Current Matrix')
	for i in range(5):
		print(matrix[i])

def FindOne():
	for r in range(5):
		for c in range(5):
			if matrix[r][c] == '1':
				return (r, c)

def Calculate(coord):
	(r, c) = coord
	mid = 2
	moveRow = mid - r
	moveCol = mid - c
	return (moveRow, moveCol)

def main():
	(mr, mc) = Calculate(FindOne())
	print(abs(mr) + abs(mc))
matrix = [input().split() for i in range(5)]
main()


for i in range(1, 6):
	n = [int(x) for x in input().split()]
	for e in n:
		if e == 1:
			r = 0
			c = 0
			nc = 0
			nr = 0
			row = i
			col = n.index(1) + 1
			if row != 3:
				r = row - 3
				nr = abs(r)
			if col != 3:
				c = col - 3
				nc = abs(c)
			if r == 3:
				result = abs(nc)
			if c == 3:
				result = abs(nr)
			if c and r == 3:
				result = 0
			result = abs(nr) + abs(nc)
			print(result)


idx = [0, 0]
for _ in range(5):
	row = input().split()
	if '1' in row:
		idx[0] = _
		idx[1] = row.index('1')
print(abs(2 - idx[0]) + abs(2 - idx[1]))


c = 0
for i in range(5):
	c += 1
	j = input()
	if '1' in j:
		x = j.split()
		d = x.index('1') + 1
		break
print(abs(3 - c) + abs(3 - d))


b = []
for i in range(5):
	a = []
	a = list(map(int, input().split()))
	b.append(a)
	if 1 in a:
		ind = a.index(1)
		x = ind
		y = i
an = abs(2 - x) + abs(2 - y)
print(an)


lst = []
for i in range(5):
	a = list(map(int, input().split()))
	lst.append(a)
for j in range(5):
	for k in range(5):
		if lst[j][k] == 1:
			m = [j, k]
			break
res = abs(2 - m[0]) + abs(2 - m[1])
print(res)


def f():
	for i in range(5):
		row = list(input().split())
		for j in range(5):
			if row[j] == '1':
				print(abs(2 - i) + abs(2 - j))
				return
f()


lists = []
for i in range(5):
	lis = input().split()
	lists.append(lis)
for i in range(0, 5):
	for j in range(0, 5):
		if lists[i][j] == '1':
			bar = i
			kol = j
print(abs(bar - 2) + abs(kol - 2))


j = 0
cur = 0
for i in range(5):
	j += 1
	s = input()
	if '1' in s:
		cur = j
		a = s.find('1') // 2 + 1
else:
	print(abs(a - 3) + abs(cur - 3))


arr = [[] for i in range(5)]
for i in range(5):
	arr[i] = input().split()
if arr[2][2] == 1:
	print(0)
else:
	for n in range(0, 5):
		for o in range(0, 5):
			if arr[n][o] == '1':
				x = n
				y = o
				sol = abs(2 - x) + abs(2 - y)
			else:
				pass
print(sol)


matrix = []
for i in range(5):
	aRow = input().split()
	matrix.append(aRow)
flag = True
counter = 0
while flag:
	if '1' in matrix[counter]:
		flag = False
	else:
		counter += 1
i = matrix[counter].index('1')
final = ((2 - i) ** 2) ** (1 / 2) + ((2 - counter) ** 2) ** (1 / 2)
print(int(final))


for i in range(0, 5):
	x1 = input().split()
	for j in range(0, 5):
		if x1[j] == '1':
			print(abs(2 - i) + abs(2 - j))


mat = []
moves = 0
for i in range(5):
	a = list(map(int, input().split()))
	mat.append(a)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			r = i
			c = j
			break
if r > 2:
	moves += r - 2
else:
	moves += 2 - r
if c > 2:
	moves += c - 2
else:
	moves += 2 - c
print(moves)


li = []
pos1 = 0
pos2 = 0
for i in range(5):
	matrix = input().split(' ')
	li.append(matrix)
for i in range(5):
	for j in range(5):
		if li[i][j] == '1':
			pos1 = i
			pos2 = j
			break
pos1 += 1
pos2 += 1
count = 0
if pos1 == 3 and pos2 == 3:
	print('0')
	count += 1
elif count == 0 and (pos1 == 3 or pos2 == 3):
	if pos1 % 2 != 0 and pos2 % 2 == 0 or (pos1 % 2 == 0 and pos2 % 2 != 0):
		print('1')
	elif pos1 % 2 != 0 and pos2 % 2 != 0:
		print('2')
elif pos1 % 2 != 0 and pos2 % 2 != 0:
	print('4')
elif count == 0 and pos1 % 2 != 0 and (pos2 % 2 != 0):
	print('2')
elif pos1 % 2 != 0 and pos2 % 2 == 0 or (pos1 % 2 == 0 and pos2 % 2 != 0):
	print('3')
elif pos2 % 2 == 0 and pos1 % 2 == 0:
	print('2')


tempPos = (0, 0)
temp = []
forces = []
for i in range(0, 5):
	temp = input().split()
	for p in range(len(temp)):
		temp[p] = int(temp[p])
	forces.append(temp)
for i in range(0, 5):
	for j in range(0, 5):
		if forces[i][j] == 1:
			tempPos = (i, j)
count = abs(2 - tempPos[0]) + abs(2 - tempPos[1])
print(count)


a = []
for i in range(5):
	v = list(map(int, input().split()))
	a.append(v)
for j in range(5):
	for k in range(5):
		if a[j][k] == 1:
			m = j
			n = k
count = abs(m - 2) + abs(n - 2)
print(count)


m = []
for _ in range(5):
	row = list(map(int, input().split()))
	m.append(row)
pos = 0
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			pos = (i, j)
steps = abs(pos[0] - 2) + abs(pos[1] - 2)
print(steps)


for i in range(1, 6):
	row = list(map(int, input().split()))
	try:
		j = row.index(1) + 1
		print(abs(i - 3) + abs(j - 3))
		break
	except:
		continue


a = str(input()).split()
b = str(input()).split()
c = str(input()).split()
d = str(input()).split()
e = str(input()).split()
letak = []
for i in range(5):
	if a[i] == '1':
		letak.append('a')
		letak.append(i)
		break
	elif b[i] == '1':
		letak.append('b')
		letak.append(i)
		break
	elif c[i] == '1':
		letak.append('c')
		letak.append(i)
		break
	elif d[i] == '1':
		letak.append('d')
		letak.append(i)
		break
	elif e[i] == '1':
		letak.append('e')
		letak.append(i)
		break
gerak = abs(letak[1] - 2)
if letak[0] == 'a':
	gerak += 2
elif letak[0] == 'b':
	gerak += 1
elif letak[0] == 'd':
	gerak += 1
elif letak[0] == 'e':
	gerak += 2
print(gerak)


lst = []
for i in range(0, 5):
	lst.append(input().split(' '))
	if i == 0:
		list1 = [j for j in lst[0]]
	if i == 1:
		list2 = [j2 for j2 in lst[1]]
	if i == 2:
		list3 = [j3 for j3 in lst[2]]
	if i == 3:
		list4 = [j4 for j4 in lst[3]]
	if i == 4:
		list5 = [j5 for j5 in lst[4]]
count = -1
for k1 in list1:
	count += 1
	if int(k1) == 1:
		print(abs(2 - count) + 2)
		break
count = -1
for k2 in list2:
	count += 1
	if int(k2) == 1:
		print(abs(2 - count) + 1)
		break
count = -1
for k3 in list3:
	count += 1
	if int(k3) == 1:
		print(abs(2 - count))
		break
count = -1
for k4 in list4:
	count += 1
	if int(k4) == 1:
		print(abs(2 - count) + 1)
		break
count = -1
for k5 in list5:
	count += 1
	if int(k5) == 1:
		print(abs(2 - count) + 2)
		break


import io
import os
matrix = [[int(j) for j in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))


t = 0
for j in range(5):
	s = input().replace(' ', '')
	pos = s.find('1')
	if pos >= 0:
		t += abs(3 - (pos + 1))
		t += abs(3 - (j + 1))
print(t)


def beautiful_matrix():
	for i in range(5):
		for j in range(5):
			if a[i][j] == 1:
				return abs(i - 2) + abs(j - 2)
a = [[] for i in range(5)]
for i in range(5):
	a[i].extend(map(int, input().split()))
result = beautiful_matrix()
print(result)


inp = []
cor = []
for i in range(5):
	temp = list(map(int, input().split(' ')))
	try:
		cor.append(temp.index(1) + 1)
		cor.append(i + 1)
		inp.append(temp)
	except:
		inp.append(temp)
		continue
ans = abs(cor[0] - 3) + abs(cor[1] - 3)
print(ans)


for x in range(5):
	try:
		y = input().split().index('1')
		print(abs(x - 2) + abs(y - 2))
		break
	except ValueError:
		continue


def r(n):
	if n > 0:
		return n
	if n < 0:
		return -n
	if n == 0:
		return 0
b = []
for i in range(1, 6):
	a = [int(i) for i in input().split()]
	b.append(a)
	if 1 in a:
		s = i
		k = a.index(1) + 1
print(r(s - 3) + r(k - 3))


def findSolution(arr):
	for i in arr:
		for j in i:
			if j == 1:
				return abs(2 - arr.index(i)) + abs(2 - i.index(j))
arr = []
for i in range(5):
	arr.append(list(map(int, input().strip().split())))
print(findSolution(arr))


(rows, cols) = (5, 5)
x = [[0 for i in range(cols)] for j in range(rows)]
for i in range(0, 5):
	y = list(map(int, input().split()))
	for j in range(0, 5):
		x[i][j] = y[j]
for i in range(5):
	for j in range(5):
		if x[i][j] == 1:
			(index_row, index_col) = (i, j)
			break
c = 0
while True:
	if index_row == 2 and index_col == 2:
		print(c)
		break
	if index_row != 2:
		c += 1
		if index_row < 2:
			index_row += 1
		else:
			index_row -= 1
	if index_col != 2:
		c += 1
		if index_col < 2:
			index_col += 1
		else:
			index_col -= 1


mat = [input().split() for i in range(5)]
i = 0
j = 0
for red in mat:
	i += 1
	j = 0
	for stup in red:
		j += 1
		if stup == '1':
			a = int(i)
			b = int(j)
n = abs(3 - a) + abs(3 - b)
print(n)


import math

def bb():
	(a, b) = list(map(int, input().split()))
	i = 0
	while a <= b:
		a *= 3
		b *= 2
		i += 1
	print(i)

def beatiful_matrix():
	middle = 2
	matrix = []
	for i in range(5):
		a = list(map(int, input().split()))
		for j in range(5):
			if a[j] == 1:
				middle = math.fabs(middle - i) + math.fabs(middle - j)
	print(int(middle))
beatiful_matrix()


mat = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	try:
		print(abs(2 - mat[i].index(1)) + abs(2 - i))
	except:
		pass


l = []
for i in range(5):
	a = list(map(int, input().split()))
	l.append(a)
for i in range(5):
	if l[i].count(1) == 1:
		ind = l[i].index(1)
		break
x = abs(2 - i) + abs(2 - ind)
print(x)


a = input().split(' ')
b = input().split(' ')
c = input().split(' ')
d = input().split(' ')
e = input().split(' ')
main = []
main.append(a)
main.append(b)
main.append(c)
main.append(d)
main.append(e)
check = 0
x = 0
y = 0
while x < 5:
	while y < 5:
		if main[x][y] == '1':
			check = True
			break
		y += 1
	if check:
		break
	x += 1
	y = 0
space = abs(2 - x) + abs(2 - y)
print(space)


loop = [2, 1, 0, 1, 2]
for i in loop:
	s = input()
	if '1' in s:
		print(i + loop[s.find('1') // 2])


row = 0
col = 0
for i in range(5):
	row = row + 1
	s = input()
	s = s.split()
	col = 0
	sledge = 0
	for j in range(5):
		col = col + 1
		if s[j] == '1':
			sledge = 1
			break
	if sledge == 1:
		break
print(abs(3 - row) + abs(3 - col))


import sys
m = [[int(i) for i in input().split()] for _ in range(5)]
rowMov = 0
colMov = 0
for i in range(5):
	for j in range(5):
		if m[i][j]:
			if (i, j) == (2, 2):
				print(0)
				sys.exit(0)
			rowMov = abs(i - 2)
			colMov = abs(j - 2)
			break
print(rowMov + colMov)


grid = []
for line in range(5):
	grid.append(input().split(' '))
(ix, iy) = (-1, -1)
for i in range(5):
	for j in range(5):
		if grid[i][j] == '1':
			ix = i
			iy = j
			break
print(abs(2 - ix) + abs(2 - iy))


n = 5
arr = []
for i in range(0, 5):
	arr.append(input().split())
x = -1
y = -1
flag = False
for i in range(0, 5):
	for j in range(0, 5):
		if arr[i][j] == '1':
			x = i + 1
			y = j + 1
sol = abs(x - 3) + abs(y - 3)
print(sol)


x = 0
y = 0
for col in range(5):
	row = list(map(int, input().split()))
	try:
		x = row.index(1)
		y = col
		break
	except:
		pass
print(abs(2 - x) + abs(2 - y))


class BeautifulMatrix:

	@staticmethod
	def solve(matrix):
		target = '1'
		for row in range(len(matrix)):
			if target in matrix[row]:
				col_index = matrix[row].index(target)
				return abs(row - 2) + abs(col_index - 2)

def main():
	matrix = list()
	for _ in range(0, 5):
		matrix.append(input().split(' '))
	bm = BeautifulMatrix()
	print(bm.solve(matrix))
main()


def findMovements(matrix):
	x = 0
	y = 0
	for i in range(len(matrix)):
		row = matrix[i]
		for j in range(len(row)):
			if int(row[j]) == 1:
				x = j + 1
				y = i + 1
	numberOfMovements = abs(x - 3) + abs(y - 3)
	return numberOfMovements
numberRows = 5
matrix = []
for i in range(numberRows):
	row = input().split(' ')
	matrix.append(row)
result = findMovements(matrix)
print(result)


l = []
for i in range(5):
	l.append(input().split())
for i in range(5):
	try:
		x = (l[i].index('1'), i)
		break
	except:
		pass
print(str(abs(x[0] - 2) + abs(x[1] - 2)))


matrix = [[0] * 5 for _ in range(5)]
for i in range(5):
	matrix[i] = [int(j) for j in input().split()]
flagx = 0
flagy = 0
moves = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			flagx = i
			flagy = j
			break
if flagx == 0 or flagx == 4:
	moves += 2
if flagy == 0 or flagy == 4:
	moves += 2
if flagx == 1 or flagx == 3:
	moves += 1
if flagy == 1 or flagy == 3:
	moves += 1
print(moves)


x = []
for i in range(5):
	n = list(map(str, input().split()))
	x = x + n
s = ''.join(x)
b = s.find('1')
a = b + 1
if a == 13:
	print('0')
elif a == 2 or a == 6 or a == 4 or (a == 10) or (a == 16) or (a == 20) or (a == 22) or (a == 24):
	print('3')
elif a == 1 or a == 5 or a == 21 or (a == 25):
	print('4')
elif a == 8 or a == 12 or a == 14 or (a == 18):
	print('1')
else:
	print('2')


A = []
for i in range(5):
	B = list(map(int, input().split()))
	A.append(B)
t = [(ix, iy) for (ix, row) in enumerate(A) for (iy, i) in enumerate(row) if i == 1]
print(abs(t[0][0] - 2) + abs(t[0][1] - 2))


c = 0
for i in range(5):
	n = input()
	l = n.split()
	if l.count('1') == 1:
		j = l.index('1')
		h = c
	c = c + 1
print(abs(h - 2) + abs(j - 2))


for i in range(1, 6):
	a = 0
	b = []
	b = list(map(int, input().split()))
	for j in b:
		a = a + 1
		if j == 1:
			i1 = i
			j1 = a
print(abs(i1 - 3) + abs(j1 - 3))


def contain(st):
	for i in range(1, 6):
		if st[i - 1] == '1':
			return i
	return 0
st1 = input().split()
st2 = input().split()
st3 = input().split()
st4 = input().split()
st5 = input().split()
if contain(st1) != 0:
	print(abs(contain(st1) - 3) + 2)
if contain(st2) != 0:
	print(abs(contain(st2) - 3) + 1)
if contain(st3) != 0:
	print(abs(contain(st3) - 3))
if contain(st4) != 0:
	print(abs(contain(st4) - 3) + 1)
if contain(st5) != 0:
	print(abs(contain(st5) - 3) + 2)


l = []
for e in range(5):
	a = input().split()
	l.append(a)
x = -3
y = 3
for e in l:
	y -= 1
	if '1' in e:
		for i in e:
			x += 1
			if i == '1':
				print(abs(x) + abs(y))


for i in range(1, 6):
	s = list(input().split())
	if '1' in s:
		x = i
		y = s.index('1') + 1
print(abs(3 - x) + abs(3 - y))


l = []
for i in range(5):
	l.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			rowNumber = i + 1
			columnNumber = j + 1
print(abs(rowNumber - 3) + abs(columnNumber - 3))


r = 0
c = 0
for i in range(0, 5):
	k = input()
	count = 0
	for j in range(0, len(k), 2):
		if k[j] == '1':
			r = i + 1
			c = count + 1
		count += 1
d1 = abs(r - 3)
d2 = abs(c - 3)
print(d1 + d2)


for i in range(1, 6):
	l = list(map(int, input().split()))
	if 1 in l:
		c = l.index(1)
		res = sum([abs(3 - i), abs(3 - (c + 1))])
print(res)


a = [0, 0, 0, 0, 0]
for i in range(5):
	a[i] = input()
	if '1' in a[i]:
		n = a[i].find('1') / 2
		m = i
x = int(abs(n - 2) + abs(m - 2))
print(x)


m = []
for i in range(5):
	m.append(list(map(int, input().split())))
for (i, lst) in enumerate(m):
	for (j, x) in enumerate(lst):
		if x == 1:
			pos = (i, j)
			break
print(abs(pos[0] - 2) + abs(pos[1] - 2))


s = [0] * 5
for x in range(5):
	s = input().split()
	if '1' in s:
		a = s.index('1')
		print(max(x - 2, 2 - x) + max(a - 2, 2 - a))


matrix_1 = [int(i) for i in input().split()]
matrix_2 = [int(i) for i in input().split()]
matrix_3 = [int(i) for i in input().split()]
matrix_4 = [int(i) for i in input().split()]
matrix_5 = [int(i) for i in input().split()]
if 1 in matrix_1:
	a = matrix_1.index(1)
	result = 2 + abs(a - 2)
elif 1 in matrix_2:
	a = matrix_2.index(1)
	result = 1 + abs(a - 2)
elif 1 in matrix_3:
	a = matrix_3.index(1)
	result = 0 + abs(a - 2)
elif 1 in matrix_4:
	a = matrix_4.index(1)
	result = 1 + abs(a - 2)
elif 1 in matrix_5:
	a = matrix_5.index(1)
	result = 2 + abs(a - 2)
print(result)


cor1 = 0
cor2 = 0
for j in range(5):
	x = input().split()
	for i in range(5):
		if x[i] == '1':
			cor1 = j
			cor2 = i
print(abs(2 - cor1) + abs(2 - cor2))


l1 = [int(j) for j in input().split()][:5]
l2 = [int(j) for j in input().split()][:5]
l3 = [int(j) for j in input().split()][:5]
l4 = [int(j) for j in input().split()][:5]
l5 = [int(j) for j in input().split()][:5]
if l1.count(1) == 1:
	print(2 + abs(3 - (l1.index(1) + 1)))
elif l2.count(1) == 1:
	print(1 + abs(3 - (l2.index(1) + 1)))
elif l3.count(1) == 1:
	print(0 + abs(3 - (l3.index(1) + 1)))
elif l4.count(1) == 1:
	print(1 + abs(3 - (l4.index(1) + 1)))
elif l5.count(1) == 1:
	print(2 + abs(3 - (l5.index(1) + 1)))


for i in range(5):
	temparr = input().split(' ')
	if '1' in temparr:
		row_number = i + 1
		column_number = temparr.index('1') + 1
print(abs(3 - row_number) + abs(3 - column_number))


print(sum(*[[abs(i + 1 - 3), abs(j - 3)] for (i, j) in enumerate([input().find('1') // 2 + 1 for r in ' ' * 5]) if j > 0]))


lastmas = []
ind = 0
jnd = 0
for i in range(5):
	mas = [int(i) for i in input().split()]
	lastmas.append(mas)
for i in range(5):
	for j in range(5):
		if lastmas[i][j] == 1:
			ind = i + 1
			jnd = j + 1
print(abs(3 - ind) + abs(3 - jnd))


x = 0
y = 0
ans = 0
for i in range(5):
	lst = []
	lst = input()
	lst = lst.split()
	for j in range(len(lst)):
		if int(lst[j]) == 1:
			x = i + 1
			if x < 3:
				ans = 3 - x
			else:
				ans = x - 3
			y = j + 1
			if y < 3:
				ans += 3 - y
			else:
				ans += y - 3
print(ans)


i = 1
while i <= 5:
	a = input().split()
	j = 1
	while j <= 5:
		if a[j - 1] == '1':
			result = abs(3 - j) + abs(3 - i)
		j += 1
	i += 1
print(result)


a = []
for i in range(5):
	l = [int(j) for j in input().split()]
	a += [l]
y = 0
for g in range(5):
	if max(a[g]) == 1:
		y = g
x = a[y].index(1)
print(abs(x - 2) + abs(y - 2))


A = []
n = 0
m = 0
for i in range(0, 5):
	a = input()
	A.append(a.split())
for j in range(0, 5):
	for k in range(0, 5):
		if A[j][k] == '1':
			n = j + 1
			m = k + 1
			break
sum = abs(n - 3) + abs(m - 3)
print(sum)


for i in range(5):
	for (j, k) in enumerate(input()[::2]):
		if int(k) == 1:
			print(abs(i - 2) + abs(j - 2))


matrix = []
for i in range(0, 5):
	input_row = input()
	matrix.append(input_row.split())
x = 0
y = 0
for row in matrix:
	y += 1
	if '1' in row:
		for i in range(0, 5):
			if row[i] == '1':
				x = i + 1
				break
		break
print(abs(3 - x) + abs(3 - y))


row1 = input().split(' ')
row2 = input().split(' ')
row3 = input().split(' ')
row4 = input().split(' ')
row5 = input().split(' ')
matrix = []
matrix.extend([row1, row2, row3, row4, row5])
for (rowIndex, row) in enumerate(matrix):
	for (colIndex, col) in enumerate(row):
		if matrix[rowIndex][colIndex] == '1':
			print(str(abs(2 - rowIndex) + abs(2 - colIndex)))


answer = 0

def determine():
	row = 0
	for i in range(5):
		current_row = input()
		current_row = current_row.split(' ')
		if '1' in current_row:
			row = i
			column = 0
			for index in range(len(current_row)):
				if current_row[index] == '1':
					column = index
					answer = abs(2 - row) + abs(2 - column)
					print(answer)
		else:
			current_row = ''
determine()


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

def main():
	j = 0
	for line in mat:
		i = 0
		for n in line:
			if n == 1:
				print(abs(2 - i) + abs(2 - j))
				return
			i += 1
		j += 1
main()


rows = 0
for i in range(5):
	ar = list(map(int, input().split()))
	if 1 not in ar:
		rows += 1
	else:
		turns = abs(2 - rows) + abs(2 - int(ar.index(1)))
else:
	print(turns)


a = []
row = []
col = []
for i in range(5):
	i = input().split(' ')
	a.append(i)
i = 0
n = 0
while i < 6:
	if a[i][n] == '1':
		col = a[i].index('1')
	i += 1
	if i == 5:
		i = 0
		n += 1
		if n == 5:
			break
for i in range(5):
	if '1' in a[i]:
		row = i
		break
count = 0
while col != 2:
	if col >= 3:
		col -= 1
		count += 1
	else:
		col += 1
		count += 1
while i != 2:
	if i >= 3:
		i -= 1
		count += 1
	else:
		i += 1
		count += 1
print(count)


(a_i, a_j) = (0, 0)
(b_i, b_j) = (2, 2)
m = []
for i in range(5):
	s = list(map(int, input().split(' ')))
	m.append(s)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			(a_i, a_j) = (i, j)
			break
moves = 0
while 1:
	if a_i > b_i:
		m[a_i][a_j] = 0
		a_i -= 1
		m[a_i][a_j] = 1
		moves += 1
	if a_i < b_i:
		m[a_i][a_j] = 0
		a_i += 1
		m[a_i][a_j] = 1
		moves += 1
	if a_j > b_j:
		m[a_i][a_j] = 0
		a_j -= 1
		m[a_i][a_j] = 1
		moves += 1
	if a_j < b_j:
		m[a_i][a_j] = 0
		a_j += 1
		m[a_i][a_j] = 1
		moves += 1
	if a_i == b_i and a_j == b_j:
		break
print(moves)


a = []
for i in range(5):
	a.extend(input().split(' '))
for i in range(len(a)):
	if a[i] == '1':
		print(abs(i // 5 - 2) + abs(i % 5 - 2))
		exit()


a = []
sum = 0
for i in range(5):
	a.append([int(y) for y in input().split()])
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
			break


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
	if 1 in arr[i]:
		oposition = [i, arr[i].index(1)]
print(abs(oposition[0] - 2) + abs(oposition[1] - 2))


import sys
matrix = []
n = 5
x = 0
centerPoint = [2, 2]
one_coordinates = []
while n > 0:
	matrix_line = input()
	matrix_line = matrix_line.split()
	matrix_line = [int(f) for f in matrix_line]
	if 1 in matrix_line:
		one_coordinates.append(x)
		one_coordinates.append(matrix_line.index(1))
	x += 1
	n -= 1
numberOfMoves = 0
if one_coordinates[0] == centerPoint[0]:
	pass
else:
	numberOfMoves += abs(one_coordinates[0] - centerPoint[0])
if one_coordinates[1] == centerPoint[1]:
	pass
else:
	numberOfMoves += abs(one_coordinates[1] - centerPoint[1])
print(numberOfMoves)


listA = []
for i in range(5):
	listA.append(input())
	if '1' in listA[i]:
		print(int(abs((listA[i].find('1') - 4) / 2) + abs(i - 2)))


n = 5
l = []
while n > 0:
	a = input().split()
	a = list(a)
	l.append(a)
	n -= 1
n = 0
while n <= 4:
	list1 = l[n]
	m = 0
	while m <= 4:
		num = list1[m]
		if num == '1':
			ans = [n, m]
		m += 1
	n += 1
print(abs(ans[0] - 2) + abs(ans[1] - 2))


x = [[0] * 5] * 5
for i in range(5):
	x1 = list(map(int, input().split()))
	if 1 in x1:
		temp = i
		t = x1.index(1)
		x[i] = x1
t1 = abs(2 - temp) + abs(2 - t)
print(t1)


result = 0
for i in range(5):
	row = input().split(' ')
	try:
		indexOfOne = row.index('1')
		result = abs(i - 2) + abs(indexOfOne - 2)
	except ValueError:
		continue
print(result)


import math
y_shift = 0
x_shift = 0
for i in range(5):
	row = input().replace(' ', '')
	if row.find('1') != -1:
		y_shift = int(math.fabs(3 - (i + 1)))
		x_shift = int(math.fabs(3 - (row.find('1') + 1)))
print(y_shift + x_shift)


matrix = []
for _ in range(5):
	a = list(map(int, input().split()))
	matrix.append(a)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			c1 = abs(2 - i)
			c2 = abs(2 - j)
			count = c1 + c2
			break
print(count)


s = [[0] * 5 for _ in range(5)]
for i in range(5):
	s[i] = [int(j) for j in input().strip().split()]
for i in range(5):
	for j in range(5):
		if s[i][j] == 1:
			break
	if s[i][j] == 1:
		break
i += 1
j += 1
x = abs(3 - i) + abs(3 - j)
print(x)


import math
ctr_r = 0
result = False
for i in range(5):
	ctr_c = 0
	s = input().split()
	ctr_r += 1
	for j in range(5):
		ctr_c += 1
		if s[j] == '1':
			result = True
			break
	if result:
		break
print(int(math.fabs(ctr_c - 3)) + int(math.fabs(ctr_r - 3)))


r1 = str(input()).replace(' ', '')
r2 = str(input()).replace(' ', '')
r3 = str(input()).replace(' ', '')
r4 = str(input()).replace(' ', '')
r5 = str(input()).replace(' ', '')
p = [r1, r2, r3, r4, r5]
for i in range(0, 5, 1):
	if '1' in p[i]:
		nr = i + 1
		r = p[i]
for i in range(0, 5, 1):
	if '1' in r[i]:
		nc = i + 1
print(abs(3 - nr) + abs(3 - nc))


lst = []
for i in range(5):
	lst.append(list(map(int, input().split())))
	if 1 in lst[i]:
		c = lst[i].index(1) + 1
		r = lst.index(lst[i]) + 1
print(abs(3 - c) + abs(3 - r))


answer = []
x = 0
y = 0
for i in range(5):
	r = str(input())
	e = r.split(' ')
	for j in range(5):
		if e[j] == '1':
			x = i
			y = j
	answer.append(e)
print(abs(2 - x) + abs(2 - y))


(pos_1, pos_2) = (0, 0)
for i in range(1, 6):
	string = input()
	if '1' in string:
		pos = string.find('1') + 1
		pos_1 = i
		pos_2 = pos // 2 + 1
moves = abs(3 - pos_1) + abs(3 - pos_2)
print(moves)


width = place = 0
for i in range(5):
	array = list(map(int, input().split()))
	if 1 in array:
		for j in range(5):
			if array[j] == 1:
				place = j
				break
		break
	width += 1
print(abs(2 - width) + abs(2 - place))


matrix = ''
i = 0
while i < 5:
	matrix += str(input())
	i += 1
n = 0
for i in matrix:
	if i == '0':
		n += 1
	elif i == '1':
		break
print(abs(2 - n % 5) + abs(2 - n // 5))


array = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if array[i][j] == 1:
			row = i
			column = j
print(abs(2 - row) + abs(2 - column))


found = False
for i in range(1, 6):
	a = [int(r) for r in input().split()]
	if found == False:
		for j in range(5):
			if a[j] == 1:
				found = True
				sar = i
				col = j + 1
print(abs(3 - sar) + abs(3 - col))


l = []
for i in range(5):
	c = list(map(int, input().strip().split()))
	l.append(c)
c = [[i, j] for i in range(5) for j in range(5) if l[i][j] == 1]
print(abs(c[0][0] - 2) + abs(c[0][1] - 2))


a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a4 = list(map(int, input().split()))
a5 = list(map(int, input().split()))
c = 0
if 1 in a1:
	c = 1
	b = a1.index(1) + 1
if 1 in a2:
	c = 2
	b = a2.index(1) + 1
if 1 in a3:
	c = 3
	b = a3.index(1) + 1
if 1 in a4:
	c = 4
	b = a4.index(1) + 1
if 1 in a5:
	c = 5
	b = a5.index(1) + 1
moves = int(3 - c)
if moves < 0:
	moves *= -1
move2 = 3 - b
if move2 < 0:
	move2 *= -1
print(move2 + moves)


from math import *
k = 0
sum = 0
for i in range(1, 6):
	(c1, c2, c3, c4, c5) = map(int, input().split())
	if c1 == 1:
		sum += abs(3 - 1)
		sum += abs(3 - i)
	if c2 == 1:
		sum += abs(3 - 2)
		sum += abs(3 - i)
	if c3 == 1:
		sum += abs(3 - 3)
		sum += abs(3 - i)
	if c4 == 1:
		sum += abs(4 - 3)
		sum += abs(3 - i)
	if c5 == 1:
		sum += abs(5 - 3)
		sum += abs(3 - i)
print(sum)


mat = []
for a in range(5):
	strok = list(map(int, input().split()))
	if 1 in strok:
		strokS1 = strok
		aS1 = a
print(abs(strokS1.index(1) - 2) + abs(aS1 - 2))


def matrix():
	rows = []
	for i in range(5):
		row = str(input())
		rows.append(row.split(' '))
	x = 0
	y = 0
	given_coor = [0, 0]
	expected_coor = [2, 2]
	for y in range(5):
		for x in range(5):
			val = rows[y][x]
			if val == '1':
				given_coor[0] = x
				given_coor[1] = y
	result = abs(expected_coor[0] - given_coor[0]) + abs(expected_coor[1] - given_coor[1])
	print(result)
matrix()


r = input
i = 0
while i < 5:
	j = r().find('1')
	if j != -1:
		break
	i = i + 1
i = i + 1
j = j // 2 + 1
c = abs(3 - i) + abs(3 - j)
print(c)


element_position = []
for row in range(5):
	matrix = input().split()
	if '1' in matrix:
		element_position.append(row)
		element_position.append(matrix.index('1'))
minimum_moves = 0
if not (element_position[0] == 2 and element_position[1] == 2):
	while element_position:
		for (i, _) in enumerate(element_position):
			minimum_moves += abs(element_position[i] - 2)
			element_position.pop(i)
print(minimum_moves)


def matrixSearch():
	for r in range(5):
		row = list(map(int, input().split()))
		for c in range(len(row)):
			if row[c] == 1:
				ans = (r, c)
	return ans
(r, c) = matrixSearch()
print(abs(r - 2) + abs(c - 2))


n1 = [int(a) for a in input().split()]
n2 = [int(b) for b in input().split()]
n3 = [int(c) for c in input().split()]
n4 = [int(d) for d in input().split()]
n5 = [int(e) for e in input().split()]
if 1 in n1:
	print(abs(n1.index(1) - 2) + 2)
elif 1 in n2:
	print(abs(n2.index(1) - 2) + 1)
elif 1 in n3:
	print(abs(n3.index(1) - 2))
elif 1 in n4:
	print(abs(n4.index(1) - 2) + 1)
else:
	print(abs(n5.index(1) - 2) + 2)


import math as m
n = 5
arr = [[int(j) for j in input().split(' ')] for i in range(n)]
for i in range(n):
	for j in range(n):
		if arr[i][j] == 1:
			(line, column) = (i, j)
count = int(m.fabs(2 - line) + m.fabs(2 - column))
print(count)


matrix = []
r = None
c = None
for row in range(1, 6):
	current_row = [int(i) for i in input().split(' ')]
	if r == None and c == None:
		for (idx, num) in enumerate(current_row, start=1):
			if num == 1:
				r = row
				c = idx
				break
print(abs(3 - r) + abs(3 - c))


for i in range(5):
	mat = list(map(int, input().split()))
	for j in range(5):
		if mat[j] == 1:
			row = i + 1
			col = j + 1
print(abs(row - 3) + abs(col - 3))


def ans():
	for a in range(5):
		found = 0
		lis = input().split(' ')
		for i in range(len(lis)):
			if lis[i] == '1' and found == 0:
				column = i + 1
				row = a + 1
				found = 1
	return abs(column - 3) + abs(row - 3)
print(ans())


a = []
for k in range(5):
	b = list(map(int, input().split()))
	a.append(b)
	if 1 in b:
		i = k + 1
		j = b.index(1) + 1
print(abs(i - 3) + abs(j - 3))


for i in range(5):
	s = list(map(str, input().split()))
	if '1' in s:
		k = i
		n = s
i = 0
while n[i] != '1':
	i += 1
print(abs(k - 2) + abs(i - 2))


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
b = []
for i in range(5):
	for j in range(5):
		c = 0
		if a[i][j] == 1:
			c = abs(2 - i) + abs(2 - j)
			b.append(c)
print(min(b))


ar = [[int(x) for x in input().strip().split()] for i in range(5)]
l = [(index, row.index(1)) for (index, row) in enumerate(ar) if 1 in row]
val = list(l[0])
(m, n) = (int(val[0]), int(val[1]))
a = abs(2 - m)
b = abs(2 - n)
r = int(a + b)
print(r)


a = []
for i in range(5):
	s = input().split()
	s = [int(x) for x in s]
	a.append(s)
raw = [0, 0, 0, 0, 0]
n = 0
for i in a:
	if i == raw:
		pass
	else:
		if a.index(i) == 0 or a.index(i) == 4:
			n += 2
		elif a.index(i) == 1 or a.index(i) == 3:
			n += 1
		else:
			pass
		if i.index(1) == 0 or i.index(1) == 4:
			n += 2
		elif i.index(1) == 1 or i.index(1) == 3:
			n += 1
		else:
			pass
print(n)


for i in range(1, 6):
	l1 = list(map(int, input().split()))
	l = sum(l1)
	if l == 1:
		x = l1.index(1)
		t = abs(3 - i)
		y = abs(3 - (x + 1))
		print(t + y)


arr = []
for i in range(5):
	array = list(map(int, input().strip().split()))
	arr.append(array)
c = 0
for i in arr:
	if 1 in i:
		ind1 = arr.index(i)
		ind1 += 1
		ind2 = i.index(1)
		ind2 += 1
		break
if ind1 != 3:
	ind1 = abs(3 - ind1)
	c += ind1
if ind2 != 3:
	ind2 = abs(3 - ind2)
	c += ind2
print(c)


(a1, b1, c1, d1, f1) = input().split(' ', 4)
(a2, b2, c2, d2, f2) = input().split(' ', 4)
(a3, b3, c3, d3, f3) = input().split(' ', 4)
(a4, b4, c4, d4, f4) = input().split(' ', 4)
(a5, b5, c5, d5, f5) = input().split(' ', 4)
if a1 == '1' or a5 == '1' or f1 == '1' or (f5 == '1'):
	print(4)
if a2 == '1' or b1 == '1' or a4 == '1' or (b5 == '1') or (d5 == '1') or (f4 == '1') or (f2 == '1') or (d1 == '1'):
	print(3)
if c1 == '1' or b2 == '1' or a3 == '1' or (b4 == '1') or (c5 == '1') or (d4 == '1') or (f3 == '1') or (d2 == '1'):
	print(2)
if c2 == '1' or b3 == '1' or c4 == '1' or (d3 == '1'):
	print(1)
if c3 == '1':
	print(0)


arr = []
i = 0
while i < 5:
	temp = [int(i) for i in input().split()]
	if 1 in temp:
		index = [i, temp.index(1)]
	arr.append(temp)
	i += 1
moves = abs(index[0] - 2) + abs(index[1] - 2)
print(moves)


import math
for i in range(5):
	s = list(map(int, input().split()))
	if 1 in s:
		print(int(math.fabs(2 - i) + math.fabs(2 - s.index(1))))
		break


x = 0
y = 0
for i in range(1, 6):
	a = input().split(' ')
	for j in range(1, 6):
		d = a[j - 1]
		if d == '1':
			y = i
			x = j
print(abs(3 - x) + abs(3 - y))


p = 1
c = 0
for i in range(5):
	a = list(map(int, input().split()))
	if 1 in a:
		pc = a.index(1) + 1
		for i in range(1, 6):
			if p + i == 3 or p - i == 3:
				c += i
			if pc + i == 3 or pc - i == 3:
				c += i
		break
	p += 1
print(c)


a_list = []
for i in range(5):
	s = [int(x) for x in input().split()]
	a_list.extend(s)
k = 0
for q in range(25):
	if a_list[q] == 1:
		k = q
print(str(abs(2 - k // 5) + abs(2 - k % 5)))


n = 5
mat = []
for i in range(n):
	rr = list(map(int, input().strip().split()))[:n]
	mat.append(rr)
(row, col) = (0, 0)
for rr in mat:
	row = row + 1
	if 1 in rr:
		col = rr.index(1) + 1
		break
print(abs(3 - row) + abs(3 - col))


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()))
if 1 in a:
	f = abs(a.index(1) - 2)
	print(f + 2)
elif 1 in b:
	f = abs(b.index(1) - 2)
	print(f + 1)
elif 1 in c:
	f = abs(c.index(1) - 2)
	print(f)
elif 1 in d:
	f = abs(d.index(1) - 2)
	print(f + 1)
elif 1 in e:
	f = abs(e.index(1) - 2)
	print(f + 2)


mat = [list(map(int, input().split())) for i in range(5)]
for (i, row) in enumerate(mat):
	if sum(row) == 1:
		R = i + 1
		for (j, col) in enumerate(row):
			if col == 1:
				C = j + 1
				break
		break
print(abs(3 - R) + abs(3 - C))


s = []
for i in range(5):
	m = list(map(int, input().split()))
	s.append(m)
n = 0
k = 0
for i in range(len(s)):
	for j in range(len(s)):
		if s[i][j] == 1:
			n = i
			k = j
n = abs(n - 2)
k = abs(k - 2)
print(n + k)


l = []
for x in range(5):
	l.append(list(map(int, input().strip().split()[:5])))
for x in l:
	if any(x) == True:
		lno = l.index(x)
		break
for x in l[lno]:
	if x == 1:
		no = l[lno].index(1)
print(abs(lno - 2) + abs(no - 2))


m = []
res = 0
for i in range(5):
	m.append(list(map(int, input().split())))
for i in m:
	if 1 in i:
		lis = m.index(i)
		res += abs(3 - (i.index(1) + 1))
		break
res += abs(3 - (lis + 1))
print(res)


x = 0
y = 0
for i in range(5):
	t = list(map(int, input().split()))
	if 1 in t:
		x = i + 1
		y = t.index(1) + 1
ans = abs(3 - x) + abs(3 - y)
print(ans)


def getInitailPosition(matrix):
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				pos = [i, j]
				return pos

def getResult(initialPosition):
	result = abs(2 - initialPosition[0]) + abs(2 - initialPosition[1])
	return result
matrix = []
for i in range(5):
	a = list(map(int, input().split()))
	matrix.append(a)
initialPosition = getInitailPosition(matrix)
print(getResult(initialPosition))


(a, b) = ([list(input().split()) for i in range(5)], 0)
for i in range(5):
	if '1' in a[i]:
		b = abs(2 - i) + abs(2 - a[i].index('1'))
		print(b)
		break


for x in range(5):
	y = str(input().replace(' ', '')).find('1')
	if y != -1:
		print(abs(2 - x) + abs(2 - y))


i = 0
onesposx = 0
onesposy = 0
while i < 5:
	a = input().find('1')
	if a > -1:
		onesposx = i
		onesposy = a // 2
	i += 1
steps = abs(onesposx - 2) + abs(onesposy - 2)
print(steps)


pos = (2, 2)
for i in range(5):
	cur = list(map(int, input().split(' ')))
	for j in range(len(cur)):
		if cur[j] == 1:
			pos = (i, j)
print(abs(2 - pos[0]) + abs(2 - pos[1]))


for i in range(5):
	s = list(map(int, input().split()))
	if sum(s) == 1:
		y = s.index(1)
		x = i
print(abs(2 - x) + abs(2 - y))


matrix = []
row = 0
column = 0
for _ in range(5):
	matrix.append(input().split())
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			row = i
			column = j
			break
print(abs(2 - row) + abs(2 - column))


def ans(arr):
	(i, j) = (0, 0)
	for x in range(5):
		if 1 in arr[x]:
			i = x
			for y in range(5):
				if arr[i][y] == 1:
					j = y
					break
			break
	return abs(i - 2) + abs(j - 2)
t = 5
temp = []
for _ in range(t):
	temp.append(list(map(int, input().strip().split())))
print(ans(temp))


import sys
matrix = []
for i in range(5):
	temp = [int(x) for x in sys.stdin.readline().split()]
	matrix.append(temp)
a = 0
b = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			a = i
			b = j
counter = 0
while a != 2:
	if a > 2:
		a -= 1
	else:
		a += 1
	counter += 1
while b != 2:
	if b > 2:
		b -= 1
	else:
		b += 1
	counter += 1
print(counter)


a = {}
d = 0
for i in range(5):
	c = input()
	a[i] = c.split()
for i in range(5):
	for j in range(5):
		if int(a[i][j]) == 1:
			if j > 2:
				if j == 3:
					d += 1
				else:
					d += 2
			else:
				if j == 0:
					d += 2
				if j == 1:
					d += 1
			if i > 2:
				if i == 3:
					d += 1
				else:
					d += 2
			else:
				if i == 0:
					d += 2
				if i == 1:
					d += 1
print(d)


n = 5
a1 = a2 = None
b1 = b2 = n // 2
for i in range(n):
	row = input().split()
	if '1' in row:
		a1 = i
		a2 = row.index('1')
c = abs(a1 - b1) + abs(a2 - b2)
print(c)


row1 = str(input())
row2 = str(input())
row3 = str(input())
row4 = str(input())
row5 = str(input())
fcolumn1 = -1
frow1 = -1
mymatrix = [row1.split(), row2.split(), row3.split(), row4.split(), row5.split()]
for (i, j) in enumerate(mymatrix):
	for (k, l) in enumerate(j):
		if l == '1':
			fcolumn1 = k
			frow1 = i
print(abs(fcolumn1 - 2) + abs(frow1 - 2))


n = [[int(i) for i in input().split()] for j in range(5)]
for k in range(5):
	try:
		x = n[k].index(1)
		z = k
	except ValueError:
		pass
print(abs(z - 2) + abs(x - 2))


for i in range(1, 6):
	lest = map(int, input().split())
	lest = list(lest)
	for j in range(len(lest)):
		if lest[j] == 1:
			y = j + 1
			x = i
			break
z = abs(x - 3) + abs(y - 3)
print(z)


ml = []
x = 0
y = 0
for i in range(5):
	ml.append(input().split(' '))
	if ml[i].count('1') == 1:
		x = i + 1
		y = ml[i].index('1') + 1
print(abs(3 - x) + abs(3 - y))


for i in range(1, 6):
	(a, b, c, d, e) = [int(i) for i in input().split()]
	if a + b + c + d + e == 1:
		if a == 1:
			j = 2
		elif b == 1:
			j = 1
		elif c == 1:
			j = 0
		elif d == 1:
			j = 1
		elif e == 1:
			j = 2
		if i <= 3:
			k = j + (3 - i)
		else:
			k = j + (i - 3)
print(k)


l = []
for i in range(0, 5):
	a = list(map(int, input().split(' ')))
	l.append(a)
mov = 0
for i in range(0, 5):
	for j in range(0, 5):
		if l[i][j] == 1:
			row = i
			col = j
			break
k = abs(row - 2) + abs(col - 2)
print(mov + k)


index_of_one = [0, 0]
centre = [2, 2]
for x in range(5):
	i = ''.join(input().split(' '))
	if '1' in i:
		index_of_one = [x, i.index('1')]
print(abs(centre[0] - index_of_one[0]) + abs(centre[1] - index_of_one[1]))


(row, column) = (0, 0)
for i in range(5):
	lis = list(map(int, input().split()))
	for j in range(len(lis)):
		if lis[j] == 1:
			(row, column) = (i + 1, j + 1)
			break
print(abs(row - 3) + abs(column - 3))


for row in range(5):
	for (column, value) in enumerate(input().split()):
		if value == '1':
			print(abs(row - 2) + abs(column - 2))
			quit()


matrix = []
for _ in range(5):
	temp = list(map(int, input().split()))
	matrix.append(temp)
a = -1
b = -1
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] == 1:
			a = i
			b = j
			break
print(abs(a - 2) + abs(b - 2))


j = []
for i in range(5):
	j.append(list(map(int, input().split(' '))))
for i in range(5):
	for k in range(5):
		if j[i][k] == 1:
			o = i
			u = k
			break
cout = 0
t = 0
if o == 0 or o == 4:
	cout += 2
	t = cout
elif o == 1 or o == 3:
	cout += 1
	t = cout
if u == 0 or u == 4:
	t += 2
elif u == 1 or u == 3:
	t += 1
print(t)


matrix = []
for i in range(5):
	matrix = list(map(int, input().split()))
	for j in range(5):
		if matrix[j] == 1:
			if j >= 2:
				cntcol = j - 2
			else:
				cntcol = 2 - j
			if i >= 2:
				cntrow = i - 2
			else:
				cntrow = 2 - i
			break
print(cntcol + cntrow)


a = [list(map(int, input().split())) for i in range(5)]
s = -1
for i in range(5):
	if a[i].count(1) == 1:
		z = a[i].index(1)
		x = i
print(abs(x - 2) + abs(z - 2))


def main():
	ct = 0
	lines = []
	while ct < 5:
		line = [i for i in input().split()]
		if line:
			lines.append(line)
			ct += 1
	pos = []
	for i in lines:
		for j in i:
			if j == '1':
				pos.append(lines.index(i) + 1)
				pos.append(i.index(j) + 1)
	res = abs(pos[0] - 3) + abs(pos[1] - 3)
	print(res)
main()


n = 0
for i in range(5):
	x = input().split()
	for j in range(len(x)):
		if x[j] == '1':
			n = abs(2 - i) + abs(2 - j)
print(n)


for i in range(1, 6):
	A = list((int(x) for x in input().split()))
	for j in range(5):
		if A[j] == 1:
			x = i
			y = j + 1
print(abs(x - 3) + abs(y - 3))


matrix = []
for i in range(5):
	a = []
	a = list(map(str, input().split()))
	matrix.append(a)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			print(abs(3 - i - 1) + abs(3 - j - 1))
			break


counter = 0
for i in range(5):
	row = input().split()
	if '1' in row:
		nRow = i
		nColumn = row.index('1')
if nRow == 0 or nRow == 4:
	counter += 2
elif nRow == 1 or nRow == 3:
	counter += 1
if nColumn == 0 or nColumn == 4:
	counter += 2
if nColumn == 1 or nColumn == 3:
	counter += 1
print(counter)


m = []
for i in range(5):
	t = [int(i) for i in input().split()]
	if 1 in t:
		x = i + 1
		y = t.index(1) + 1
print(abs(3 - x) + abs(3 - y))


for i in range(5):
	r = [int(x) for x in input().split()]
	for j in range(5):
		if r[j] == 1:
			ans = abs(i - 2) + abs(j - 2)
print(ans)


def main():
	n = 5
	for i in range(n):
		a = list(map(int, input().split()))
		for j in range(n):
			if a[j] == 1:
				ans = abs(i - 2) + abs(j - 2)
	print(ans)
main()


list = [2, 1, 0, 1, 2]
for i in list:
	m = input()
	if '1' in m:
		print(i + list[m.find('1') // 2])


s = []
for i in range(5):
	inp = list(map(int, input().split(' ')))
	if inp.count(1) > 0:
		ind = inp.index(1)
		s.append(i)
		s.append(ind)
steps = abs(s[0] - 2) + abs(s[1] - 2)
print(steps)


i = 0j
for row in range(5):
	r = [int(a) for a in input().strip().split()]
	for column in range(len(r)):
		if r[column] == 1:
			i = row + column * 1j
print(abs(2 - int(i.real)) + abs(2 - int(i.imag)))


rowIndex = 0
colIndex = 0
for i in range(0, 5):
	row = input()
	if '1' in row:
		rowList = row.split(' ')
		colIndex = rowList.index('1') + 1
		rowIndex = i + 1
rowSol = abs(rowIndex - 3)
colSol = abs(colIndex - 3)
print(rowSol + colSol)


i = 0
while i < 5:
	j = 0
	a = input()
	while j < 9:
		if a[j] == '1':
			print(abs(2 - i) + abs(2 - int(j / 2)))
		j += 1
	i += 1


inp = input
li = list
iinp = lambda : int(inp())
ent = lambda : map(int, inp().split())
lient = lambda : li(ent())
s = sum
ab = abs
mat = []
ind = 0
for i in range(5):
	a = lient()
	if s(a):
		ind = i
	mat.append(a)
res = ab(3 - (ind + 1))
for i in range(5):
	if mat[ind][i]:
		res += ab(3 - (i + 1))
print(res)


def procura(matrix):
	a = 0
	b = 0
	ach = False
	for i in range(len(matrix)):
		for j in range(len(matrix[i])):
			if matrix[i][j] == '1':
				a = i
				b = j
				ach = True
				break
		if ach:
			break
	return [a, b]
l1 = input().split()
l2 = input().split()
l3 = input().split()
l4 = input().split()
l5 = input().split()
matrix = [l1, l2, l3, l4, l5]
cont = 0
resp = procura(matrix)
fin = abs(2 - resp[0]) + abs(2 - resp[1])
print(fin)


a = [[], [], [], [], []]
for i in range(5):
	a[i] = list(map(int, input().strip().split(' ')))
for i in a:
	if 1 in i:
		L = a.index(i)
		c = i.index(1)
n = abs(2 - L) + abs(2 - c)
print(n)


ans = 0
(rr, cc) = (0, 0)
mat = []
for i in range(5):
	l = list(map(int, input().split()))
	mat.append(l)
(r, c) = (-1, -1)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			(r, c) = (i, j)
			break
rr = rr + (r - 2)
rr = abs(rr)
cc = cc + (c - 2)
cc = abs(cc)
print(rr + cc)


matrix = [[int(e) for e in input().split()] for y in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] > 0:
			print(abs(i - 2) + abs(j - 2))
			break


index_i = 0
index_j = 0
for i in range(0, 5):
	li = list(map(int, input().split()))
	if 1 in li:
		index_j = li.index(1)
		index_i = i
print(abs(index_i - 2) + abs(index_j - 2))


(a1, a2, a3, a4, a5, nul) = (input(), input(), input(), input(), input(), 0)
a = a1 + a2 + a3 + a4 + a5
a = a.replace(' ', '')
for i in range(25):
	if a[i] == '1':
		nul = i + 1
		break
if nul % 5 == 0:
	dei = 2 + abs(3 - nul // 5)
else:
	dei = abs(3 - nul % 5)
	dei += abs(2 - nul // 5)
print(dei)


matrix_list = []
for i in range(5):
	row = input().split()
	for j in range(5):
		row[j] = int(row[j])
	matrix_list.append(row)
moves = 0
for i in range(5):
	for j in range(5):
		if matrix_list[i][j] == 1:
			moves = abs(i - 2) + abs(j - 2)
			break
print(moves)


gi = 0
gj = 0
for i in range(5):
	x = input().split(' ')
	if '1' in x:
		gi = i
		gj = x.index('1')
print(abs(gi - 2) + abs(gj - 2))


def NumberMoves(Array):
	Moves = 0
	for i in range(5):
		for j in range(5):
			if Array[i][j] == 1:
				if i == 2 and j == 2:
					return 0
				if i != 2:
					Moves += abs(i - 2)
				if j != 2:
					Moves += abs(j - 2)
	return Moves
Array = [[int(j) for j in input().split()] for i in range(5)]
print(NumberMoves(Array))


def newFunction():
	for i in range(5):
		input1 = input().split()
		for j in range(5):
			if input1[j] == '1':
				row = i
				col = j
	print(abs(row - 2) + abs(col - 2))
newFunction()


def main():
	y = 0
	rowf = None
	for i in range(5):
		row = input()
		if '1' in row:
			y = i
			rowf = row
	x = rowf.index('1') // 2
	print(abs(2 - x) + abs(2 - y))
main()


i = 0
mat = []
counter = 0
one = 0
while i < 5:
	i += 1
	row = list(map(int, input().split()))
	mat.append(row)
for i in range(5):
	if 1 in mat[i]:
		one += i
		row = mat[i]
		a = row.index(1)
		if a > 2:
			counter += a - 2
		if a < 2:
			counter += 2 - a
if one > 2:
	counter += one - 2
if one < 2:
	counter += 2 - one
print(counter)


m = [list(map(int, input().split())) for i in range(5)]
for (i, row) in enumerate(m, 1):
	for (j, col) in enumerate(row, 1):
		if col == 1:
			moves = 0
			if i == 1 or i == 5:
				moves += 2
			elif i == 2 or i == 4:
				moves += 1
			if j == 1 or j == 5:
				moves += 2
			elif j == 2 or j == 4:
				moves += 1
			print(moves)
			break


x = []
x.append(input().split())
x.append(input().split())
x.append(input().split())
x.append(input().split())
x.append(input().split())
count = 0
for i in range(len(x)):
	for j in range(len(x)):
		if x[i][j] == '1':
			if abs(i - 2) + abs(j - 2) == 0:
				count = 0
			elif abs(i - 2) + abs(j - 2) == 1:
				count = 1
			elif abs(i - 2) + abs(j - 2) == 2:
				count = 2
			elif abs(i - 2) + abs(j - 2) == 3:
				count = 3
			else:
				count = 4
print(count)


l = [2, 1, 0, 1, 2]
for j in l:
	s = input()
	if '1' in s:
		print(j + l[s.find('1') // 2])


for i in range(1, 6):
	ls = list(map(int, input().split()))
	if 1 in ls:
		c = ls.index(1) + 1
		r = i
print(abs(c - 3) + abs(r - 3))


while True:
	try:

		def soln(r, c):
			r = abs(r - 3)
			c = abs(c - 3)
			print(r + c)

		def inputt():
			r = c = 0
			for i in range(5):
				mtrx = list(map(int, input().split()))
				for j in range(5):
					if mtrx[j] == 1:
						(r, c) = (i + 1, j + 1)
				del mtrx
			soln(r, c)
		if __name__ == '__main__':
			inputt()
	except EOFError:
		break


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
for i in range(5):
	s = input().split(' ')
	if '1' in s:
		k = s.index('1')
		print(abs(2 - i) + abs(2 - k))
		exit()


for i in range(5):
	str = input().split()
	for j in range(5):
		if str[j] == '1':
			x = j + 1
			y = i + 1
if x >= 3:
	actions = x - 3
else:
	actions = 3 - x
if y >= 3:
	actions += y - 3
else:
	actions += 3 - y
print(actions)


import math
x = 0
y = 0
a = []
for i in range(5):
	m = input().split()
	a.append(m)
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			x = i
			y = j
x1 = 2
y1 = 2
result = abs(x - x1) + abs(y - y1)
print(result)


a = [None] * 5
idx = 0
for x in range(5):
	a[x] = [int(x) for x in input().split()]
for x in range(5):
	for y in range(5):
		if a[x][y] == 1:
			idx = abs(x - 2) + abs(y - 2)
			break
print(idx)


def steps_to_beauty(matrix):
	the_i = -1
	the_j = -1
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == '1':
				(the_i, the_j) = (i, j)
				break
	return abs(the_i - 2) + abs(the_j - 2)
matrix = []
for i in range(5):
	matrix.append(input().split())
print(steps_to_beauty(matrix))


for i in range(5):
	line = input().split()
	if '1' in line:
		column = line.index('1')
		row = i
		print(abs(column - 2) + abs(row - 2))


lit = []
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()))
lit.append(a)
lit.append(b)
lit.append(c)
lit.append(d)
lit.append(e)
for i in range(0, 5):
	for j in range(0, 5):
		if lit[i][j] == 1:
			k = i
			l = j
			x = abs(k - 2) + abs(l - 2)
			break
print(x)


def beautify(n, matrix):
	i = 0
	j = 0
	for i in range(n):
		for j in range(n):
			if matrix[i][j] == 1:
				if i > n // 2:
					i = i % 2
				if j > n // 2:
					j = j % 2
				return abs(i - n // 2) + abs(j - n // 2)
n = 5
matrix = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	matrix[i] = [int(x) for x in input().split()]
print(beautify(n, matrix))


main_arr = []
for i in range(5):
	column_arr = list(map(int, input().split()))
	if 1 in column_arr:
		x = i
		y = column_arr.index(1)
	else:
		continue
final_answer = abs(2 - x) + abs(2 - y)
print(final_answer)


a = []
for i in range(5):
	inp = input().split()
	inp = [int(x) for x in inp]
	a.append(inp)
r = 0
c = 0
for i in range(len(a)):
	for j in range(len(a)):
		if a[i][j] == 1:
			r = i
			c = j
			break
print(abs(2 - r) + abs(2 - c))


a = []
for i in range(5):
	a += list(map(int, input().split()))
b = a.index(1, 0, 25)
if b == 0 or b == 4 or b == 20 or (b == 24):
	print(4)
elif b == 1 or b == 5 or b == 3 or (b == 9) or (b == 15) or (b == 21) or (b == 23) or (b == 19):
	print(3)
elif b == 2 or b == 6 or b == 10 or (b == 16) or (b == 22) or (b == 18) or (b == 14) or (b == 8):
	print(2)
elif b == 7 or b == 11 or b == 17 or (b == 13):
	print(1)
elif b == 12:
	print(0)


arr = []
count = 0
for i in range(5):
	arr.append(list(map(int, input().split(' '))))
mid = (2, 2)
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			tuple = (i, j)
if tuple[0] < mid[0]:
	for i in range(tuple[0], mid[0]):
		swap = arr[i]
		arr[i] = arr[i + 1]
		arr[i + 1] = swap
		count += 1
elif tuple[0] > mid[0]:
	for i in range(tuple[0], mid[0], -1):
		swap = arr[i]
		arr[i] = arr[i - 1]
		arr[i - 1] = swap
		count += 1
if tuple[1] < mid[1]:
	for j in range(tuple[1], mid[1]):
		new = []
		temp = []
		for i in range(5):
			temp.append(arr[i][j])
		new.append(temp)
		temp = []
		for i in range(5):
			temp.append(arr[i][j + 1])
		new.append(temp)
		swap = new[0]
		new[0] = new[1]
		new[1] = swap
		for k in range(0, 2):
			for i in range(5):
				arr[i][k + j] = new[k][i]
		count += 1
elif tuple[1] > mid[1]:
	for j in range(tuple[1], mid[1], -1):
		new = []
		temp = []
		for i in range(5):
			temp.append(arr[i][j])
		new.append(temp)
		temp = []
		for i in range(5):
			temp.append(arr[i][j - 1])
		new.append(temp)
		swap = new[0]
		new[0] = new[1]
		new[1] = swap
		for k in range(0, 2):
			for i in range(5):
				arr[i][j - k] = new[k][i]
		count += 1
print(count)


str1 = input()
str2 = input()
str3 = input()
str4 = input()
str5 = input()
strfull = str1 + ' ' + str2 + ' ' + str3 + ' ' + str4 + ' ' + str5
listfull = strfull.split()
n = listfull.index('1') + 1
if n == 1 or n == 5 or n == 21 or (n == 25):
	print('4')
elif n == 2 or n == 4 or n == 6 or (n == 10) or (n == 16) or (n == 20) or (n == 22) or (n == 24):
	print('3')
elif n == 8 or n == 12 or n == 14 or (n == 18):
	print('1')
elif n == 13:
	print('0')
else:
	print('2')


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
moves = 0
matrix = [[0 for i in range(5)] for j in range(5)]
matrix[0][0] = int(a[0])
matrix[0][1] = int(a[1])
matrix[0][2] = int(a[2])
matrix[0][3] = int(a[3])
matrix[0][4] = int(a[4])
matrix[1][0] = int(b[0])
matrix[1][1] = int(b[1])
matrix[1][2] = int(b[2])
matrix[1][3] = int(b[3])
matrix[1][4] = int(b[4])
matrix[2][0] = int(c[0])
matrix[2][1] = int(c[1])
matrix[2][2] = int(c[2])
matrix[2][3] = int(c[3])
matrix[2][4] = int(c[4])
matrix[3][0] = int(d[0])
matrix[3][1] = int(d[1])
matrix[3][2] = int(d[2])
matrix[3][3] = int(d[3])
matrix[3][4] = int(d[4])
matrix[4][0] = int(e[0])
matrix[4][1] = int(e[1])
matrix[4][2] = int(e[2])
matrix[4][3] = int(e[3])
matrix[4][4] = int(e[4])
if matrix[0][0] or matrix[0][4] or matrix[4][4] or (matrix[4][0] == 1):
	print(4)
elif matrix[0][1] or matrix[0][3] or matrix[1][0] or (matrix[3][0] == 1):
	print(3)
elif matrix[4][1] or matrix[4][3] or matrix[1][4] or (matrix[3][4] == 1):
	print(3)
elif matrix[0][2] or matrix[2][0] or matrix[4][2] or (matrix[2][4] == 1):
	print(2)
elif matrix[1][1] or matrix[1][3] or matrix[3][1] or (matrix[3][3] == 1):
	print(2)
elif matrix[2][2] == 1:
	print(0)
else:
	print(1)


m = 5
n = 5
ar = [[int(j) for j in input().split()] for i in range(n)]
k = 0
counter = 0
while k < n:
	j = 0
	while j < m:
		if ar[k][j] == 1:
			print(abs(2 - k) + abs(2 - j))
			counter = 1
			break
		j += 1
	if counter:
		break
	k += 1


x = input()
y = input()
z = input()
m = input()
n = input()
if '1' in x:
	print(int(2 + abs(x.index('1') / 2 - 2)))
if '1' in y:
	print(int(1 + abs(y.index('1') / 2 - 2)))
if '1' in z:
	print(int(abs(z.index('1') / 2 - 2)))
if '1' in m:
	print(int(1 + abs(m.index('1') / 2 - 2)))
if '1' in n:
	print(int(2 + abs(n.index('1') / 2 - 2)))


l = []
for _ in range(5):
	l.append(input().split())
for i in range(5):
	if '1' in l[i]:
		row = l[i].index('1')
		col = i
print(abs(2 - row) + abs(2 - col))


matrix = []
for i in range(5):
	line = [int(i) for i in input().split()]
	matrix.append(line)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			x = i
			y = j
output = abs(x - 2) + abs(y - 2)
print(output)


import math
import sys
inf = sys.stdin
row = 0
col = 0
for i in range(5):
	temp = inf.readline()
	line = [int(i) for i in temp.split(' ')]
	if 1 in line:
		row = i
		col = line.index(1)
print(int(math.fabs(2 - row) + math.fabs(2 - col)))


m = 1
while m <= 5:
	a = list(input().split())
	if '1' in a:
		x = a
		i = m
	else:
		pass
	m = m + 1
j = x.index('1') + 1
d = [i, j]
if d in [[2, 3], [3, 2], [4, 3], [3, 4]]:
	print(1)
elif [i, j] in [[3, 3]]:
	print(0)
elif [i, j] in [[1, 1], [1, 5], [5, 1], [5, 5]]:
	print(4)
elif [i, j] in [[1, 2], [2, 1], [1, 4], [2, 5], [5, 4], [4, 5], [5, 2], [4, 1]]:
	print(3)
else:
	print(2)


matrix = []
matrixSize = 5
centreValue = (matrixSize - 1) / 2
count = -1
for n in range(matrixSize):
	count += 1
	matrix.insert(count, list(input().split()))
rowCount = -1
rowFound = False
for n in matrix:
	columnCount = -1
	rowCount += 1
	for x in n:
		columnCount += 1
		if x == '1':
			finalColumnCount = columnCount
			rowFound = True
	if rowFound == True:
		finalRowCount = rowCount
		rowFound = False
rowDifference = abs(centreValue - finalRowCount)
columnDifference = abs(centreValue - finalColumnCount)
finalDifference = rowDifference + columnDifference
print(int(finalDifference))


ls = [input().split(), input().split(), input().split(), input().split(), input().split()]
for i in range(5):
	for j in range(5):
		if ls[i][j] is '1':
			print(abs(int(i) - 2) + abs(int(j) - 2))


s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s3 = list(map(int, input().split()))
s4 = list(map(int, input().split()))
s5 = list(map(int, input().split()))
if s1[0] == 1 or s1[4] == 1 or s5[0] == 1 or (s5[4] == 1):
	print(4)
elif s1[1] == 1 or s1[3] == 1 or s2[0] == 1 or (s2[4] == 1) or (s5[1] == 1) or (s5[3] == 1) or (s4[0] == 1) or (s4[4] == 1):
	print(3)
elif s1[2] == 1 or s3[0] == 1 or s3[4] == 1 or (s5[2] == 1) or (s2[1] == 1) or (s2[3] == 1) or (s4[1] == 1) or (s4[3] == 1):
	print(2)
elif s2[2] == 1 or s4[2] == 1 or s3[1] == 1 or (s3[3] == 1):
	print(1)
else:
	print(0)


def solve(m):
	for (i, row) in enumerate(m):
		for (j, n) in enumerate(row):
			if n == 1:
				return abs(i - 2) + abs(j - 2)
	return 4
m = []
for i in range(5):
	inp = [int(x) for x in input().split(' ')]
	m.append(inp)
print(solve(m))


s1 = [int(a) for a in input().split()]
s2 = [int(a) for a in input().split()]
s3 = [int(a) for a in input().split()]
s4 = [int(a) for a in input().split()]
s5 = [int(a) for a in input().split()]
S = 0
if s1.count(1) == 1:
	S += 2
	if s1.index(1) > 2:
		S += s1.index(1) - 2
	if s1.index(1) < 2:
		S += 2 - s1.index(1)
if s2.count(1) == 1:
	S += 1
	if s2.index(1) > 2:
		S += s2.index(1) - 2
	if s2.index(1) < 2:
		S += 2 - s2.index(1)
if s3.count(1) == 1:
	S += 0
	if s3.index(1) > 2:
		S += s3.index(1) - 2
	if s3.index(1) < 2:
		S += 2 - s3.index(1)
if s4.count(1) == 1:
	S += 1
	if s4.index(1) > 2:
		S += s4.index(1) - 2
	if s4.index(1) < 2:
		S += 2 - s4.index(1)
if s5.count(1) == 1:
	S += 2
	if s5.index(1) > 2:
		S += s5.index(1) - 2
	if s5.index(1) < 2:
		S += 2 - s5.index(1)
print(S)


(h, w) = (0, 0)
for i in range(5):
	l = input().split(' ')
	if '1' in l:
		h = i
		w = l.index('1')
print(abs(h - 2) + abs(w - 2))


for i in range(5):
	inputbyrow = input().split()
	if '1' in inputbyrow:
		row = i
		column = inputbyrow.index('1')
rowmove = abs(2 - row)
colmove = abs(2 - column)
totalmoves = rowmove + colmove
print(totalmoves)


j = 1
p = 0
while j <= 5:
	c = [int(i) for i in input().split(' ')]
	if c[0] == 1 or c[4] == 1:
		p += 2
		p += abs(3 - j)
		break
	elif c[1] == 1 or c[3] == 1:
		p += 1
		p += abs(3 - j)
		break
	elif c[2] == 1:
		p += abs(3 - j)
		break
	else:
		p += 0
	j += 1
print(p)


(x, y) = (2, 2)
ind = 0
for i in range(5):
	r = list(map(int, input().split()))
	if 1 in r:
		ind = r.index(1)
		c = i
		break
print(abs(x - ind) + abs(y - c))


n = 5
a = []
for i in range(5):
	a.append(list(map(int, input().split())))
x = 2
y = 2
res = 0
res1 = 0
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == 1:
			res += abs(j - y)
			res1 += abs(i - x)
			break
print(res + res1)


r_num = 1
c_num = None
moves = None
for _ in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		c_num = row.index(1) + 1
		moves = abs(r_num - 3) + abs(c_num - 3)
	r_num += 1
print(moves)


from sys import stdin

def main():
	super_matriz = []
	cont = 0
	for i in range(5):
		m1 = [int(x) for x in stdin.readline().strip().split()]
		super_matriz.append(m1)
	for j in range(len(super_matriz)):
		for k in range(len(super_matriz[0])):
			if super_matriz[j][k] == 1:
				cont = abs(2 - j) + abs(2 - k)
	print(cont)
main()


import sys
import math
from sys import stdin, stdout
n = 5
for i in range(n):
	a = list(map(int, stdin.readline().split()))
	if sum(a) == 1:
		y = a.index(1) + 1
		x = i + 1
		break
print(abs(x - 3) + abs(y - 3))


mas = []
for i in range(5):
	mas.append(list(map(int, input().split())))
	for j in range(5):
		if mas[i][j] == 1:
			x = i
			y = j
print(abs(x - 2) + abs(y - 2))


pos_y = 0
pos_x = 0
for i in range(1, 6):
	lst = list(map(int, input().split(' ')))
	if 1 in lst:
		pos_x = lst.index(1)
		pos_y = i - 1
print(abs(2 - pos_x) + abs(2 - pos_y))


l = [2, 1, 0, 1, 2]
for i in l:
	r = input()
	if '1' in r:
		print(i + l[r.find('1') // 2])


a = []
for i in range(5):
	a += list(map(str, input().split()))
print(abs(2 - a.index('1') % 5) + abs((12 - a.index('1') - (2 - a.index('1') % 5)) // 5))


def search(mat):
	global row
	global coloum
	for i in range(5):
		for j in range(5):
			if mat[i][j] == 1:
				row = i
				coloum = j
ans = 0
mat = []
for i in range(5):
	a = list(map(int, input().split()))
	mat.append(a)
search(mat)
print(abs(2 - row) + abs(2 - coloum))


for i in range(5):
	value = [int(x) for x in input().split()]
	for inp in range(len(value)):
		if value[inp] == 1:
			z = abs(inp - 2)
			l = abs(i - 2)
print(z + l)


n = [input().split() for i in range(5)]
for j in range(5):
	if '1' in n[j]:
		print(max(j + 1, 3) - min(j + 1, 3) + (max(3, n[j].index('1') + 1) - min(3, n[j].index('1') + 1)))


import sys
matrix = [[0 for x in range(5)] for y in range(5)]
row = 0
for line in sys.stdin:
	column = 0
	for word in line.split():
		matrix[row][column] = int(word)
		column += 1
	row += 1
row = 0
actions = 0
for i in matrix:
	column = 0
	for j in i:
		if matrix[row][column] == 1:
			if row < 2:
				actions += 2 - row
			if row > 2:
				actions += row - 2
			if column < 2:
				actions += 2 - column
			if column > 2:
				actions += column - 2
		column += 1
	row += 1
print(actions)


matrix = [input().strip().split() for i in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] != '0':
			(row, col) = (i, j)
print(abs(2 - row) + abs(2 - col))


moves = 0
matriz = []
for i in range(5):
	matriz.append([])
	matriz[i] = input().split(' ')
	for j in range(5):
		if matriz[i][j] == '1':
			x = i + 1
			y = j + 1
			moves = abs(3 - x) + abs(3 - y)
			break
print(moves)


for b in range(0, 5):
	p = str(input(''))
	xlist = p.split()
	for a in range(0, 5):
		if xlist[a] == '1':
			x = a
			y = b
print(abs(x - 2) + abs(y - 2))


def diff(p, q):
	if p > q:
		return p - q
	else:
		return q - p
for i in range(0, 5):
	(a, b, c, d, e) = map(int, input().split())
	if a or b or c or d or (e == 1):
		x = i + 1
		break
l = [a, b, c, d, e]
for i in range(0, 5):
	if l[i] == 1:
		y = i + 1
		break
sum = diff(3, x) + diff(3, y)
print(sum)


def prog():
	s = 0
	for i in range(5):
		q = map(int, input().split())
		for (j, x) in enumerate(q):
			if x == 1:
				s = 1
				break
		if s == 1:
			break
	a = 3 - i - 1
	b = 3 - j - 1
	if a < 0:
		a = a * -1
	if b < 0:
		b = b * -1
	print(a + b)
prog()


count = 5
steps = 0
string_one = 0
column_one = 0
while count != 0:
	line = list(map(int, input().split()))
	for i in line:
		if i == 1:
			string_one = 6 - count
			column_one = line.index(i) + 1
	count = count - 1
if string_one != 3 or column_one != 3:
	steps = abs(3 - string_one) + abs(3 - column_one)
print(steps)


def main():
	a = []
	for i in range(5):
		x = list(map(int, input().split()))
		a.append(x)
	for i in range(5):
		for j in range(5):
			if a[i][j] == 1:
				return abs(2 - i) + abs(2 - j)
print(main())


(x, res) = ([], [])
for i in range(5):
	x.append(''.join(input().split()))
for i in range(5):
	if '1' in x[i]:
		res.append(i + 1)
		res.append(x[i].find('1') + 1)
print(abs(res[0] - 3) + abs(res[1] - 3))


i = 0
while i in range(5):
	list0 = list(map(int, input().split()))
	if list0.count(1) != 0:
		a = list0.index(1)
		b = i
	i = i + 1
dst = abs(a - 2) + abs(b - 2)
print(dst)


a = []
for i in range(0, 5):
	a.extend(list(map(int, input().split())))
p = a.index(1) + 1
y = -(-p // 5)
x = p - 5 * y + 5
print(abs(x - 3) + abs(y - 3))


found1 = 0
y = 0
while found1 == 0:
	s = input()
	if '1' in s:
		found1 = 1
	else:
		y += 1
l = s.split()
x = l.index('1')
print(abs(x - 2) + abs(y - 2))


for i in range(5):
	n = input()
	l = list(n.split())
	m = ''.join(l)
	for j in range(5):
		l[j] = int(l[j])
	s = sum(l)
	if s != 0:
		a = abs(2 - i)
		f = m.find('1')
		b = abs(f - 2)
print(a + b)


poxX = 0
posY = 0
for i in range(0, 5):
	line = input().split()
	if '1' in line:
		posY = line.index('1')
		posX = i
		break
print(abs(posX - 2) + abs(posY - 2))


import re
x = None
y = None
for i in range(1, 6):
	s = input()
	if '1' in s:
		y = i
		s = s.replace(' ', '')
		x = s.find('1') + 1
print(abs(3 - x) + abs(3 - y))


dest = [2, 2]
matrix = [list(map(int, input().split(' '))) for i in range(0, 5)]
loc = [[x, y] for x in range(0, 5) for y in range(0, 5) if matrix[x][y] == 1]
loc = loc[0]
print(abs(loc[0] - dest[0]) + abs(loc[1] - dest[1]))


def mi():
	return map(int, input().split())
for i in range(5):
	t = list(mi())
	for j in range(5):
		if t[j] == 1:
			print(abs(2 - i) + abs(2 - j))


res = 0
for i in range(5):
	l1 = input().split()
	for j in range(5):
		if l1[j] == '1':
			res = abs(2 - i) + abs(2 - j)
			break
print(res)


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
xInd = 0
yInd = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			xInd = i
			yInd = j
print(abs(2 - xInd) + abs(2 - yInd))


for p in range(1, 6):
	b = input().split()
	if '1' in b:
		print(abs(3 - p) + abs(2 - b.index('1')))
		break
	else:
		continue


i = 0
(ox, oy) = (0, 0)
while i < 5:
	row_elems = input().split()
	for j in range(5):
		if row_elems[j] == '1':
			ox = i
			oy = j
			i += 10
			break
	i += 1
n = abs(ox - 2) + abs(oy - 2)
print(n)


l = [input().split() for i in range(5)]
(col, row) = (-1, -1)
for (i, j) in enumerate(l):
	for k in range(5):
		if j[k] == '1':
			row = i
			col = k
			break
	if col != -1 and row != -1:
		break
steps = abs(row + 1 - 3) + abs(col + 1 - 3)
print(steps)


n = 0
while n < 5:
	s = input().split()
	if '1' not in s:
		n += 1
	else:
		m = s.index('1')
		break
print(abs(n - 2) + abs(m - 2))


a = input()
b = input()
c = input()
d = input()
e = input()
total = a + b + c + d + e
total = total.replace(' ', '')
t = len(total.split('1')[0])
row = int(t / 5 + 1)
col = t % 5 + 1
print(abs(row - 3) + abs(col - 3))


arr = [[int(j) for j in input().strip(' ').split(' ')] for i in range(5)]
count = 0
for i in range(1, 6):
	for j in range(1, 6):
		if arr[i - 1][j - 1] == 1:
			count = abs(i - 3) + abs(j - 3)
			break
print(count)


(Row, Column) = (5, 5)
(goalI, goalK) = (2, 2)
a = []
matriz = []
answer = 0
for i in range(int(Row)):
	a = input()
	a = a.split(' ')
	matriz.append(list(a))
for i in range(Row):
	for k in range(Column):
		if matriz[i][k] == '1':
			gotI = i
			gotK = k
while gotI != goalI:
	if gotI < goalI:
		gotI += 1
		answer += 1
	else:
		gotI -= 1
		answer += 1
while gotK != goalK:
	if gotK < goalK:
		gotK += 1
		answer += 1
	else:
		gotK -= 1
		answer += 1
print(answer)


l = []
for i in range(5):
	li = list(map(int, input().split()))
	l.append(li)
for row in range(5):
	for col in range(5):
		if l[row][col] == 1:
			print(abs(2 - row) + abs(2 - col))
			break
		else:
			continue


ll = [list(map(int, input().split())) for j in range(5)]
done = False
for i in range(5):
	for j in range(5):
		if ll[i][j] == 1:
			(a, b) = (i, j)
			done = True
			break
		if done:
			break
if a == 2:
	print(abs(b - 2))
elif b == 2:
	print(abs(a - 2))
else:
	print(abs(a - 2) + abs(b - 2))


for i in range(5):
	line = input()
	if '1' in line:
		for (j, c) in enumerate(map(int, line.split())):
			if c == 1:
				row = i + 1
				col = j + 1
				print(abs(row - 3) + abs(col - 3))
				exit(0)


list1 = []
for i in range(5):
	ll = list(map(int, input().split()))
	list1.append(ll)
ii = 0
jj = 0
for i in range(5):
	for j in range(5):
		if list1[i][j] == 1:
			ii = i
			jj = j
i = ii
j = jj
i += 1
j += 1
r = abs(3 - i)
c = abs(3 - j)
print(r + c)


n = 5
a = []
count = 0
for i in range(n):
	b = []
	b = list(map(int, input().split()))
	a.append(b)
for i in range(n):
	for j in range(n):
		if a[i][j] == 1:
			k = i
			l = j
			break
if k > 2:
	while k != 2:
		k -= 1
		count += 1
else:
	while k != 2:
		k += 1
		count += 1
if l > 2:
	while l != 2:
		l -= 1
		count += 1
else:
	while l != 2:
		l += 1
		count += 1
print(count)


x = [2, 1, 0, 1, 2]
for i in x:
	s = input()
	if '1' in s:
		print(i + x[s.find('1') // 2])


import math
lineIndex = rowIndex = 0
for i in range(5):
	line = list(map(int, input().split(' ')))
	if 1 in line:
		lineIndex = i
		rowIndex = line.index(1)
count = math.fabs(lineIndex - 2) + math.fabs(rowIndex - 2)
print(int(count))


for t in range(5):
	num = list(map(int, input().rstrip().split()))
	if 1 in num:
		b = [idx for (idx, vals) in enumerate(num) if vals == 1]
		a = abs(3 - (t + 1)) + abs(3 - (b[0] + 1))
		print(a)
		break


s = []
f = 0
g = 0
for i in range(1, 6):
	(a, b, c, d, e) = map(int, input().split())
	s = []
	s.append(a)
	s.append(b)
	s.append(c)
	s.append(d)
	s.append(e)
	for j in range(1, 6):
		if s[j - 1] > 0:
			f += 3 - i
		if s[j - 1] > 0:
			g += 3 - j
if f < 0:
	f = f * -1
if g < 0:
	g = g * -1
print(f + g)


i = 0
matrix = []
row = col = 0
dist1 = dist2 = 0
for a in range(5):
	n = input()
	l = n.split(' ')
	j = 0
	matrix.append(l)
	i += 1
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			row = int(i) + 1
			col = int(j) + 1
			break
if row > 3:
	dist1 = row - 3
else:
	dist1 = 3 - row
if col > 3:
	dist2 = col - 3
else:
	dist2 = 3 - col
print(dist1 + dist2)


x = 0
for i in range(0, 5, 1):
	x = [int(x) for x in input().split()]
	for j in range(0, 5, 1):
		if x[j] == 1:
			z = abs(i - 2) + abs(j - 2)
print(z)


a = []
x = 0
y = 0
for i in range(5):
	row = input().split()
	for j in range(5):
		row[j] = int(row[j])
		if row[j] == 1:
			x = i
			y = j
	a.append(row)
print(abs(x - 2) + abs(y - 2))


stroka = []
stolb = ['', '', '', '', '']
cood = [0, 0]
mid_cood = [3, 3]
nc = []
for i in range(5):
	a = input()
	stroka.append(a)
	if '1' in a:
		cood[0] = i + 1
		a = a.split()
		cood[1] = a.index('1') + 1
if cood[0] > mid_cood[0]:
	nc.append(cood[0] - mid_cood[0])
else:
	nc.append(-cood[0] + mid_cood[0])
if cood[1] > mid_cood[1]:
	nc.append(cood[1] - mid_cood[1])
else:
	nc.append(-cood[1] + mid_cood[1])
print(sum(nc))


import math
mat = []
(i, j) = (0, 0)
for _ in range(5):
	m = input().split()
	mat.append(m)
	if '1' in m:
		i = _
		j = m.index('1')
print(abs(2 - i) + abs(2 - j))


st0 = input()
st1 = input()
st2 = input()
st3 = input()
st4 = input()

def find1(st0, st1, st2, st3, st4):
	i = 0
	for st in [st0, st1, st2, st3, st4]:
		i = i + 1
		for j in range(5):
			if '1' == st[2 * j]:
				return (i, j + 1)
(m, n) = find1(st0, st1, st2, st3, st4)
if m >= 3:
	s = m - 3
else:
	s = 3 - m
if n >= 3:
	s = s + n - 3
else:
	s = s + 3 - n
print(s)


mat = []
for i in range(5):
	row = input().split()
	mat.append(row)
for i in range(5):
	if '1' in mat[i]:
		for k in range(5):
			if mat[i][k] == '1':
				step = abs(i - 2) + abs(k - 2)
print(step)


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

def countMoves(m):
	for i in range(5):
		for j in range(5):
			if m[i][j] == 1:
				return abs(i + 1 - 3) + abs(j + 1 - 3)
print(countMoves(m))


matrix = []
for x in range(0, 5):
	row = input().split(' ')
	matrix.append(row)
number_x_pos = 0
number_y_pos = 0
for x in range(0, 5):
	for y in range(0, 5):
		if matrix[x][y] == '1':
			number_x_pos = x
			number_y_pos = y
			break
num_row_switches = number_x_pos - 2 if number_x_pos - 2 >= 0 else -(number_x_pos - 2)
num_column_switches = number_y_pos - 2 if number_y_pos - 2 >= 0 else -(number_y_pos - 2)
print(num_row_switches + num_column_switches)


matrix = []
for i in range(0, 5):
	l = list(map(int, input().split()))
	matrix.append(l)
for x in range(0, 5):
	for y in range(0, 5):
		if matrix[x][y] == 1:
			a = x
			b = y
		else:
			pass
result = abs(a - 2) + abs(b - 2)
print(result)


for i in range(1, 6):
	row = input().split()
	if '1' in row:
		j = row.index('1') + 1
		dist = abs(i - 3) + abs(j - 3)
		print(dist)
		break


for i in range(5):
	a = input().split(' ')
	for j in range(len(a)):
		if a[j] == '1':
			x = i
			y = j
			break
print(abs(int(x) - 2) + abs(int(y) - 2))


def load():
	matrix = []
	for i in range(0, 5):
		inp = list(input().rstrip().split())
		matrix.append(inp)
	return matrix

def locate(matrix):
	f = False
	location = ()
	for string in matrix:
		if f != True:
			if '1' in string:
				location = (string.index('1'), matrix.index(string))
	return location

def moves(tup):
	counter = 0
	counter += abs(2 - tup[0])
	counter += abs(2 - tup[1])
	return counter
print(moves(locate(load())))


import sys
row = 0
col = 0
cnt = 0
for line in sys.stdin:
	cnt += 1
	if '1' in line:
		row = cnt
		col = line.strip().split().index('1') + 1
		moves = abs(row - 3) + abs(col - 3)
		print(moves)
		break


a = []
for i in range(5):
	a += [list(input().split())]
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			print(abs(i + 1 - 3) + abs(j + 1 - 3))


A = [[int(j) for j in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if A[i][j] == 1:
			print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
			break


n = 5
A = [[int(j) for j in input().split()] for i in range(n)]
k = 0
q = 0
n = 0
for i in range(len(A)):
	for j in range(len(A[i])):
		if A[i][j] == int('1'):
			q = i
			n = j
while q > 2:
	(A[q], A[q - 1]) = (A[q - 1], A[q])
	q -= 1
	k += 1
while q < 2:
	(A[q], A[q + 1]) = (A[q + 1], A[q])
	q += 1
	k += 1
while n > 2:
	(A[q][n], A[q][n - 1]) = (A[q][n - 1], A[q][n])
	n -= 1
	k += 1
while n < 2:
	(A[q][n], A[q][n + 1]) = (A[q][n + 1], A[q][n])
	n += 1
	k += 1
print(k)


for i in range(1, 6):
	l = input().split()
	if '1' in l:
		print(abs(i - 3) + abs(l.index('1') - 2), end='')
		exit()


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()))
matrix = [a, b, c, d, e]
s = 0
for i in matrix:
	if 1 in i:
		s += abs(matrix.index(i) - 2) + abs(i.index(1) - 2)
print(s)


position = (input() + '\n' + input() + '\n' + input() + '\n' + input() + '\n' + input()).split().index('1')
print(abs(2 - position // 5) + abs(2 - position % 5))


for i in range(5):
	l = input().split()
	if '1' in l:
		k = l.index('1')
		print(abs(3 - k - 1) + abs(3 - i - 1))


MAX_ROWS = 5
MAX_COLS = 5

def main():
	matrix = [list(map(int, input().strip().split())) for row in range(MAX_ROWS)]
	one_loc = tuple()
	for row in range(MAX_ROWS):
		for col in range(MAX_COLS):
			if matrix[row][col]:
				one_loc = (row, col)
	print(f'{abs(2 - one_loc[0]) + abs(2 - one_loc[1])}')
main()


column = 0
str = 0
for i in range(5):
	s = input()
	if s.find('1') != -1:
		str = i
		column = s.find('1') // 2
print(abs(str - 2) + abs(column - 2))


a = [0, 0, 0, 0, 0]
for i in range(5):
	s = input()
	s = s.split(' ')
	a[i] = s
moves = 0
for i in range(5):
	if not a[i] == ['0', '0', '0', '0', '0']:
		row = i
		moves = moves + abs(3 - (i + 1))
for k in range(i + 1):
	if a[row][k] == '1':
		col = k
		moves = moves + abs(3 - (k + 1))
print(moves)


for i in range(5):
	x = list(input().split())
	if '1' in x:
		m = x.index('1')
		print(abs(2 - i) + abs(2 - m))
		break


mat = []
for i in range(5):
	arr = [int(i) for i in input().split()]
	mat.append(arr)
src = []
ans = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			src = [i + 1, j + 1]
			ans = abs(3 - i - 1) + abs(3 - j - 1)
print(ans)


mat = []
for i in range(5):
	mat.append(list(map(int, input().split(' '))))
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			(row, col) = (i, j)
			break
if row == col == 2:
	nop = 0
elif col == 2:
	nop = abs(2 - row)
else:
	nop = abs(2 - row) + abs(2 - col)
print(nop)


x = []
for i in range(5):
	num = input()
	x.append(num.replace(' ', ''))
for i in range(5):
	for j in range(5):
		if x[i][j] == '1':
			a = abs(i - 2)
			b = abs(j - 2)
			steps = a + b
			print(steps)
			break


matrix = []
index = 0
total = 0
for i in range(5):
	matrix.append(list(map(int, input().split(' '))))
for j in matrix:
	try:
		if j.count(1) == 1:
			temp = j
			indexOfArr = matrix.index(temp)
			index = j.index(1)
			if index != 2:
				total = abs(3 - (index + 1))
			if indexOfArr != 2:
				total += abs(3 - (indexOfArr + 1))
			break
	except:
		pass
print(total)


a = []
for i in range(5):
	b = input()
	c = b.split(' ')
	a.append(c)
x = 0
for j in range(5):
	for k in range(5):
		if a[j][k] == '1':
			if j <= 2 and k <= 2:
				x = x + 2 - j + 2 - k
			elif j <= 2 and k > 2:
				x = x + 2 - j + k - 2
			elif j > 2 and k <= 2:
				x = x + j - 2 + 2 - k
			else:
				x = x + j - 2 + k - 2
		else:
			pass
print(x)


i = 0
for i in range(0, 5):
	str = input()
	list = str.split()
	j = 0
	for j in range(0, 5):
		if list[j] == '1':
			num = abs(i - 2) + abs(j - 2)
print(num)


a = []
for i in range(5):
	b = list(map(int, input().split()))
	a.append(b)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i
			y = j
sum = 0
if x > 2:
	sum = sum + (x - 2)
else:
	sum = sum + (2 - x)
if y > 2:
	sum = sum + (y - 2)
else:
	sum = sum + (2 - y)
print(sum)


res = 0
for y in range(5):
	line = list(map(int, input().split()))
	if 1 in line:
		res += abs(2 - y)
		res += abs(2 - line.index(1))
print(res)


matrix = []
for i in range(0, 5):
	matrix.append([])
	(x1, x2, x3, x4, x5) = map(int, input().split())
	matrix[i].append(x1)
	matrix[i].append(x2)
	matrix[i].append(x3)
	matrix[i].append(x4)
	matrix[i].append(x5)
for k in range(0, 5):
	if 1 in matrix[k]:
		c = matrix[k].index(1)
		r = k
swaps = abs(c - 2) + abs(r - 2)
print(swaps)


mat1 = []
for _ in range(5):
	list1 = list(map(int, input().split()))
	mat1.append(list1)
for i in range(len(mat1)):
	for j in range(len(mat1)):
		if mat1[i][j] == 1:
			g = i + 1
			h = j + 1
x = 3
y = 3
print(abs(g - x) + abs(h - y))


a = []
ai = 0
aj = 0
count = 0
count2 = 0
for i in range(5):
	a.append([int(j) for j in input().split()])
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			ai = i
			aj = j
if ai < 2:
	count = 2 - ai
if ai > 2:
	count = ai - 2
if ai == 2:
	count = 0
if aj < 2:
	count2 = 2 - aj
if aj > 2:
	count2 = aj - 2
if aj == 2:
	count2 = 0
print(count + count2)


x = 0
y = 0
for i in range(5):
	a = list(map(int, input().split()))
	for j in a:
		if j == 1:
			x = i + 1
			y = a.index(j) + 1
b = 3 - x
c = 3 - y
if b < 0:
	b *= -1
if c < 0:
	c *= -1
print(b + c)


a = input()
b = input()
c = input()
d = input()
e = input()
r1 = a.split()
r2 = b.split()
r3 = c.split()
r4 = d.split()
r5 = e.split()
bar = 0
kol = 0
for i in range(0, 5):
	if r1[i] == '1':
		bar = 1
		kol = i + 1
for i in range(0, 5):
	if r2[i] == '1':
		bar = 2
		kol = i + 1
for i in range(0, 5):
	if r3[i] == '1':
		bar = 3
		kol = i + 1
for i in range(0, 5):
	if r4[i] == '1':
		bar = 4
		kol = i + 1
for i in range(0, 5):
	if r5[i] == '1':
		bar = 5
		kol = i + 1
jar = abs(bar - 3) + abs(kol - 3)
print(jar)


a = []
b = -1
c = -1
for x in range(5):
	a.append(input().split(' '))
	if a[x].count('1') > 0:
		b = x + 1
		c = a[x].index('1') + 1
		break
d = abs(b - 3) + abs(c - 3)
print(d)


for i in range(5):
	l = input().split()
	if '1' in l:
		print(abs(l.index('1') - 2) + abs(2 - i))


arr = []
for i in range(5):
	mat_i = list(map(int, input().split()))
	arr.append(mat_i)
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
			break


import sys
input = sys.stdin.readline
one_col = 0
one_row = 0
for i in range(5):
	row = input().split()
	if '1' in row:
		one_col = row.index('1')
		one_row = i
		if i == 2 and one_col == 2:
			print(0)
			exit()
steps = abs(one_row - 2) + abs(one_col - 2)
print(steps)


a1 = input().split()
a2 = input().split()
a3 = input().split()
a4 = input().split()
a5 = input().split()
answ = 0
if '1' in a1:
	answ += 2
	answ += abs(a1.index('1') - 2)
elif '1' in a5:
	answ += 2
	answ += abs(a5.index('1') - 2)
elif '1' in a2:
	answ += 1
	answ += abs(a2.index('1') - 2)
elif '1' in a4:
	answ += 1
	answ += abs(a4.index('1') - 2)
else:
	answ += abs(a3.index('1') - 2)
print(answ)


d = [[] * 5] * 5
r_check = 0
c_check = 0
for i in range(5):
	n = list(map(int, input().split(' ')))
	d[i].append(n)
	if 1 in n:
		r_check = i
		c_check = n.index(1)
moves = abs(2 - r_check) + abs(2 - c_check)
print(moves)


p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
if p.count(1):
	print(abs(p.index(1) + 1 - 3) + 2)
elif q.count(1):
	print(abs(q.index(1) + 1 - 3) + 1)
elif s.count(1):
	print(abs(s.index(1) - 2))
elif r.count(1):
	print(abs(r.index(1) + 1 - 3) + 1)
elif t.count(1):
	print(abs(t.index(1) + 1 - 3) + 2)


for i in range(5):
	line = list(input().split())
	if '1' in line:
		print(abs(2 - i) + abs(2 - int(line.index('1'))))


t = 5
y = []
while t > 0:
	x = []
	x = [int(x) for x in input().split()]
	y.append(x)
	t -= 1
row = 0
for i in range(5):
	if y[i].count(1) == 1:
		row = i + 1
	else:
		continue
place = 0
col = 0
for item in y[row - 1]:
	if item == 1:
		place += 1
		col = place
	else:
		place += 1
if row > 3:
	s1 = row - 3
elif row == 3:
	s1 = 0
else:
	s1 = 3 - row
if col > 3:
	s2 = col - 3
elif col == 3:
	s2 = 0
else:
	s2 = 3 - col
print(s1 + s2)


br_flag = 0
for i in range(0, 5):
	a = list(input().split(' '))
	for j in range(0, 5):
		if int(a[j]):
			br_flag = 1
			break
	if br_flag:
		break
res = abs(i - 2) + abs(j - 2)
print(res)


import sys
input = sys.stdin.readline

def int_array():
	return list(map(int, input().split()))
a = []
for _ in range(5):
	a.append(int_array())
for i in a:
	if 1 in i:
		row = a.index(i) + 1
		cell = i.index(1) + 1
middleRow = 3
middleCell = 3
print(abs(middleRow - row) + abs(middleCell - cell))


l1 = []
for i in range(5):
	l = list(map(int, input().split()))
	l1.append(l)
for i in range(5):
	for j in range(5):
		if l1[i][j] == 1:
			c = j + 1
			r = i + 1
			break
if r > 3:
	r = r - 3
else:
	r = 3 - r
if c > 3:
	c = c - 3
else:
	c = 3 - c
print(c + r)


matrix = []

def swap(x, y, mat):
	steps = 0
	while x != 2 or y != 2:
		if x > 2:
			x -= 1
			steps += 1
		elif x < 2:
			x += 1
			steps += 1
		if y > 2:
			y -= 1
			steps += 1
		elif y < 2:
			y += 1
			steps += 1
	return steps
for i in range(5):
	matrix.append(list(map(int, input().split())))
for i in range(5):
	if 1 in matrix[i]:
		x = i
		y = matrix[i].index(1)
n = swap(x, y, matrix)
print(n)


mylist = input().split()
mylist = mylist + input().split()
mylist = mylist + input().split()
mylist = mylist + input().split()
mylist = mylist + input().split()
i = mylist.index('1') + 1
if i % 5 == 0:
	d = 5
else:
	d = i % 5
import math
e = math.ceil(i / 5)
a = abs(d - 3)
b = abs(e - 3)
c = a + b
print(c)


def find_element():
	for i in range(5):
		row = input()
		j = 0
		for e in row.split():
			if int(e) == 1:
				return (i + 1, j + 1)
			j += 1

def main():
	(i, j) = find_element()
	x = abs(i - 3)
	y = abs(j - 3)
	moves = str(x + y)
	print(moves)
main()


A = []
for i in range(5):
	line = list(map(int, input().split()))
	A = A + line
pos = A.index(1)
row = pos // 5
col = pos % 5
moves = abs(2 - row) + abs(2 - col)
print(moves)


k = []
for i in range(5):
	x = list(map(int, input().split()))
	k.append(x)
for i in range(5):
	for j in range(5):
		if k[i][j] == 1:
			n = i
			o = j
			break
z = abs(n - 2) + abs(o - 2)
print(z)


for i in range(5):
	a = list(map(int, input().split()))
	if 1 in a:
		w = a.index(1)
		print(abs(3 - (i + 1)) + abs(3 - (w + 1)))
		break


for f1 in range(5):
	s = input().split(' ')
	for f2 in range(5):
		if s[f2] == '1':
			print(abs(2 - f1) + abs(2 - f2))


mat = []
for i in range(5):
	x = input().split(' ')
	mat.append(x)
r = 1
w = 1
for i in mat:
	if '1' in i:
		w = i.index('1') + 1
		c = r - 3
		y = w - 3
		if c < 0:
			c = -c
		if y < 0:
			y = -y
		print(c + y)
		break
	r += 1


(n, r) = (0, 0)
for i in range(5):
	m = list(map(int, input().split(' ')))
	r += 1
	if 1 in m:
		i = m.index(1) + 1
		if i == 1 or i == 5:
			n += 2
		elif i == 2 or i == 4:
			n += 1
		if r == 1 or r == 5:
			n += 2
		elif r == 2 or r == 4:
			n += 1
print(n)


def main():
	matrix = [list(map(int, input().split())) for i in range(5)]
	done = False
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				print(abs(i - 2) + abs(j - 2))
				done = True
				break
		if done:
			break
main()


l = []
i = 0
for k in range(1, 6):
	ch = input()
	lst = ch.split()
	if '1' in lst:
		i = k
	l.append(lst)
j = l[i - 1].index('1') + 1
nombre = 0
if i <= 3:
	nombre += 3 - i
else:
	nombre += i - 3
if j <= 3:
	nombre += 3 - j
else:
	nombre += j - 3
print(nombre)


r = 5
matrix = [input().split() for i in range(r)]
for i in range(r):
	for j in range(r):
		if matrix[i][j] == '1':
			(x, y) = (2 - i, 2 - j)
			z = abs(x) + abs(y)
			print(z)
			exit()


ans = 0
for i in range(1, 6):
	t = input().split(' ')
	if '1' in t:
		ans += abs(i - 3)
		l = t.index('1')
		ans += abs(l - 2)
print(ans)


(row, col) = (0, 0)
for i in range(1, 6):
	line = input().split()
	for j in range(1, 6):
		if line[j - 1] == '1':
			row = i
			col = j
print(abs(row - 3) + abs(col - 3))


arr = []
arr.append(list(input()))
arr.append(list(input()))
arr.append(list(input()))
arr.append(list(input()))
arr.append(list(input()))
for row in arr:
	for e in row:
		if e == ' ':
			row.remove(e)
x = 1
y = 1
for row in arr:
	for e in row:
		if e == '1':
			posx = x
			posy = y
			break
		y += 1
	x += 1
	y = 1
print(abs(posx - 3) + abs(posy - 3))


n = 5
matrix = []
for _ in range(n):
	matrix.append(list(map(int, input().split())))
for i in range(n):
	if 1 in matrix[i]:
		con = (i, matrix[i].index(1))
print(abs(2 - con[0]) + abs(2 - con[1]))


arr = [[int(j) for j in input().split()] for x in range(5)]
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			ind = (i, j)
print(abs(2 - ind[0]) + abs(2 - ind[1]))


import math
m = []
for i in range(5):
	m.append(list(map(int, input().rstrip().split())))
i = 0
j = 0
f = True
while i < 5 and f == True:
	while j < 5 and f:
		if m[i][j] == 1:
			f = False
			n = j
			s = i
			break
		j += 1
	j = 0
	i += 1
print(abs(2 - s) + abs(2 - n))


swaps = 0
for i in range(5):
	arr = list(map(int, input().split()))
	for j in range(len(arr)):
		if arr[j] == 1:
			swaps = abs(i + 1 - 3) + abs(j + 1 - 3)
			flag = 1
print(swaps)


num_lines = 5
for i in range(int(num_lines)):
	row = input().split()
	if '1' in row:
		col_ind = row.index('1') + 1
		row_ind = i + 1
		break
print(abs(col_ind - 3) + abs(row_ind - 3))


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
(r, c) = (len(mat), len(mat[0]))
for i in range(r):
	for j in range(c):
		if mat[i][j]:
			(x, y) = (i + 1, j + 1)
			break
print(abs(x - 3) + abs(y - 3))


a = [2, 1, 0, 1, 2]
for i in a:
	l = input()
	if '1' in l:
		print(i + a[l.find('1') // 2])


def beautiful_matrix(matrix):
	for row in range(5):
		for colu in range(5):
			if matrix[row][colu] is '1':
				return abs(2 - row) + abs(2 - colu)
matrix = [input().split() for i in range(5)]
print(beautiful_matrix(matrix))


matrix = []
rowIndex = 0
columnIndex = 0
for i in range(5):
	row = [int(x) for x in input().split()]
	if 1 in row:
		rowIndex = i
		columnIndex = row.index(1)
	matrix.append(row)
print(abs(rowIndex - 2) + abs(columnIndex - 2))


arr = []
for i in range(0, 5):
	arr.append(input().split())
for i in range(0, 5):
	for j in range(0, 5):
		if arr[i][j] == '1':
			print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
			break


from math import *
m = 0
for i in range(1, 6):
	x = input()
	j = x.find('1')
	if j >= 0:
		m = abs(j / 2 - 2) + abs(i - 3)
print(int(m))


(ii, jj) = (1, 1)
for i in range(1, 6):
	l = input().split()
	if '1' in l:
		ii = i
		jj = l.index('1') + 1
print(abs(3 - ii) + abs(3 - jj))


mat = []
(row, col) = (0, 0)
for _ in range(5):
	mat.append(input().split())
for (k, i) in enumerate(mat):
	if '1' in i:
		row = k
		for (q, u) in enumerate(i):
			if u == '1':
				col = q
ans_row = abs(int(row) - 2)
ans_col = abs(int(col) - 2)
print(ans_col + ans_row)


i = 0
j = 0
mat = []
for i in range(5):
	x = input().split()
	c = []
	for j in range(5):
		c.append(int(x[j]))
	mat.append(c)
r = 0
c = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			r = i
			c = j
ind = 0
if r != 2:
	while r < 2:
		r = r + 1
		ind = ind + 1
	while r > 2:
		r = r - 1
		ind = ind + 1
if c != 2:
	while c < 2:
		c = c + 1
		ind = ind + 1
	while c > 2:
		c = c - 1
		ind = ind + 1
print(ind)


mtrx = []
cnt = 0
for i in range(5):
	a = list(map(int, input().split()))
	mtrx.append(a)
for i in range(5):
	for j in range(5):
		if mtrx[i][j] == 1:
			if i == 0 or i == 4:
				cnt += 2
			elif i == 1 or i == 3:
				cnt += 1
			if j == 0 or j == 4:
				cnt += 2
			elif j == 1 or j == 3:
				cnt += 1
			break
print(cnt)


x = []
a = 0
b = 0
for i in range(5):
	x.append(list(map(int, input().split())))
for i in range(len(x)):
	if sum(x[i]) == 1:
		a = i + 1
b = x[a - 1].index(1) + 1
print(abs(a - 3) + abs(b - 3))


x = 0
y = 0
for i in range(5):
	s = tuple(map(int, input().split()))
	for j in range(5):
		if s[j] == 1:
			x = i
			y = j
z = int(abs(x - 2) + abs(y - 2))
print(z)


co = 0
matrix = []
for i in range(5):
	ab = list(map(int, input().split()))
	matrix.append(ab)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			a = i
			b = j
			break
co += abs(2 - a)
co += abs(2 - b)
print(co)


lines = []
while True:
	try:
		lines.append(input())
	except EOFError:
		break
reference_x = 3
reference_y = 3
x_value = 0
y_value = 0
for x in range(0, 5):
	cur_line = lines[x]
	values = cur_line.split(' ')
	if '1' in values:
		y_value = values.index('1')
		y_value = y_value + 1
		x_value = x + 1
		break
	else:
		continue
total_moves = abs(reference_x - x_value) + abs(reference_y - y_value)
print(total_moves)


for i in range(5):
	s = input()
	for j in range(len(s)):
		if s[j] == '1':
			xx = i
			yy = j // 2
print(abs(xx - 2) + abs(yy - 2))


import math

def findOne(matrix):
	for i in range(len(matrix)):
		for j in range(len(matrix[i])):
			if matrix[i][j] == 1:
				return (i, j)
matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
onePos = findOne(matrix)
print((2 - onePos[0]).__abs__() + (2 - onePos[1]).__abs__())


n = 5
m = 5
data = []
langkah = 0
for i in range(n):
	data += [[0] * m]
for i in range(n):
	a = input().split(' ')
	for j in range(m):
		data[i][j] += int(a[j])
for i in range(n):
	for j in range(m):
		if data[i][j] == 1:
			cek1 = i
			cek2 = j
if cek1 <= 2 and cek2 <= 2:
	while cek1 != 2:
		cek1 += 1
		langkah += 1
	while cek2 != 2:
		cek2 += 1
		langkah += 1
elif cek1 >= 2 and cek2 >= 2:
	while cek1 != 2:
		cek1 -= 1
		langkah += 1
	while cek2 != 2:
		cek2 -= 1
		langkah += 1
elif cek1 >= 2 and cek2 <= 2:
	while cek1 != 2:
		cek1 -= 1
		langkah += 1
	while cek2 != 2:
		cek2 += 1
		langkah += 1
else:
	while cek1 != 2:
		cek1 += 1
		langkah += 1
	while cek2 != 2:
		cek2 -= 1
		langkah += 1
print(langkah)


matrix = []
for i in range(5):
	x = list(map(int, input().split()))
	matrix.append(x)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			x_inp = i
			y_inp = j
			break
print(abs(x_inp - 2) + abs(y_inp - 2))


one = 0
for i in range(1, 6):
	l = input().split()
	for j in range(0, len(l)):
		if '1' == l[j]:
			one = abs(i - 3) + abs(j + 1 - 3)
print(one)


A = input().split()
B = input().split()
C = input().split()
D = input().split()
E = input().split()
x = 0
y = 0
s0 = '0'
s1 = '0'
s2 = '0'
s3 = '0'
s4 = '0'
for i in range(6):
	if (s0 == '0') & (s1 == '0') & (s2 == '0') & (s3 == '0') & (s4 == '0'):
		s0 = A[i]
		s1 = B[i]
		s2 = C[i]
		s3 = D[i]
		s4 = E[i]
	elif s0 == '1':
		x = 1
		y = i
		break
	elif s1 == '1':
		x = 2
		y = i
		break
	elif s2 == '1':
		x = 3
		y = i
		break
	elif s3 == '1':
		x = 4
		y = i
		break
	elif s4 == '1':
		x = 5
		y = i
		break
print(abs(x - 3) + abs(y - 3))


def count(m):
	for i in range(5):
		for j in range(5):
			if m[i][j] == '1':
				return abs(i - 2) + abs(j - 2)
m = []
for i in range(5):
	m.append(input().split(' '))
print(count(m))


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
tf = False
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i
			y = j
			tf = True
			break
	if tf:
		break
print(abs(x - 2) + abs(y - 2))


L = []
for i in range(1, 6):
	arr = input().split()
	a = arr.count('1')
	if a is 1:
		b = arr.index('1') + 1
		print(abs(i - 3) + abs(b - 3))


l = []
for i in range(5):
	a = input()
	l = a.split(' ')
	for j in range(5):
		if l[j] == '1':
			x = i
			y = j
print(str(abs(x - 2) + abs(y - 2)))


mas1 = input()
x = 0
y = 0
for i in range(0, 9):
	if mas1[i] == '1':
		x = i
		y = 1
i = 0
mas2 = input()
for i in range(0, 9):
	if mas2[i] == '1':
		x = i
		y = 2
i = 0
mas3 = input()
for i in range(0, 9):
	if mas3[i] == '1':
		x = i
		y = 3
i = 0
mas4 = input()
for i in range(0, 9):
	if mas4[i] == '1':
		x = i
		y = 4
i = 0
mas5 = input()
for i in range(0, 9):
	if mas5[i] == '1':
		x = i
		y = 5
a = abs((x - 4) // 2)
b = abs(y - 3)
print(a + b)


b = []
for _ in range(5):
	a = input().split(' ')
	b.append(a)
for i in range(0, 5, 1):
	for j in range(0, 5, 1):
		if b[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))


import sys

def solution():
	result = 0
	matrix = []
	m = 5
	n = 5
	for _ in range(m):
		cols = list(map(int, input().split(' ')))
		matrix.append(cols)
	r = 0
	c = 0
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 1:
				r = i
				c = j
				break
	result = abs(2 - r) + abs(2 - c)
	print(result)
solution()


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
f = [a, b, c, d, e]
for i in range(5):
	for n in range(5):
		if f[i][n] in ['1']:
			h = i - 2
			q = n - 2
			h = abs(h)
			q = abs(q)
			print(h + q)
		else:
			continue


for i in range(5):
	l = list(map(int, input().split()))
	try:
		j = l.index(1)
		c = i
	except:
		pass
print(abs(2 - c) + abs(2 - j))


(x, y) = (0, 0)
for j in range(0, 5):
	lst = [int(i) for i in input().split()]
	for i in range(0, 5):
		if lst[i] == 1:
			x = j
			y = i
x = x - 2
y = y - 2
if x < 0:
	x = -x
if y < 0:
	y = -y
print(x + y)


l = []
for _ in range(5):
	p = [i for i in input().split()]
	l.append(p)
for i in range(5):
	p = l[i]
	if '1' in p:
		o = p.index('1')
		print(abs(i - 2) + abs(o - 2))
		break


matrix = []
n = 5
while n > 0:
	matrix.append([int(x) for x in input().split(' ')])
	n -= 1
row_i = 0
row_j = 0
mid_row = 3
mid_col = 3
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			row_i = i + 1
			row_j = j + 1
dist = abs(mid_row - row_i) + abs(mid_col - row_j)
print(dist)


import math as m
p = []
for _ in range(1, 6):
	l = list(map(int, input().split()))
	if 1 in l:
		y = l.index(1)
		x = _
	p.append(l)
print(int(m.fabs(x - 3) + m.fabs(2 - y)))


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	if a[i].count(1):
		for j in range(5):
			if a[i][j] == 1:
				row = 2 - i
				col = 2 - j
				total = abs(row) + abs(col)
				break
print(total)


import math
n = 5
for i in range(n):
	a = input().split()
	for j in range(n):
		if a[j] == '1':
			print(abs(2 - i) + abs(2 - j))


for i in range(1, 6):
	str = input()
	if '1' in str:
		str = str.split()
		ycoord = i
		xcoord = str.index('1') + 1
print(abs(ycoord - 3) + abs(xcoord - 3))


(mx, my) = (2, 2)
l = list()
l1 = list()
x = 0
y = 0
for i in range(5):
	l1 = list(map(int, input().split()))
	if 1 in l1:
		x = i
		y = l1.index(1)
		break
print(abs(mx - x) + abs(my - y))


a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
e = [int(i) for i in input().split()]
if 1 in a:
	t = (1, a.index(1) + 1)
elif 1 in b:
	t = (2, b.index(1) + 1)
elif 1 in c:
	t = (3, c.index(1) + 1)
elif 1 in d:
	t = (4, d.index(1) + 1)
elif 1 in e:
	t = (5, e.index(1) + 1)
print(abs(3 - t[0]) + abs(3 - t[1]))


class Solution:

	def solve(self, grid):
		n = 2
		m = 2
		(oneN, oneM) = (-1, -1)
		for i in range(5):
			for j in range(5):
				if grid[i][j] == 1:
					(oneN, oneM) = (i, j)
		return abs(oneN - n) + abs(oneM - m)
sol = Solution()
grid = []
for i in range(5):
	row = list(map(int, input().strip().split()))
	grid.append(row)
print(sol.solve(grid))


(m, n) = (-1, -1)
for i in range(5):
	s = list(input().split())
	for j in range(5):
		if s[j] == '1':
			(m, n) = (i, j)
print(abs(m - 2) + abs(n - 2))


l = []
for i in range(1, 6):
	x = [int(x) for x in input().split()]
	if sum(x) == 1:
		a = x.index(1) + 1
		l.append(a)
		l.append(i)
print(abs(3 - l[0]) + abs(3 - l[1]))


a = tuple((tuple(map(int, input().split())) for i in range(5)))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


l = []
stroka = 0
pos = 0
res = 0
for i in range(5):
	l.append(list(map(int, input().split())))
for s in range(len(l)):
	if 1 in l[s]:
		stroka = s + 1
		for i in range(len(l[s])):
			if l[s][i] == 1:
				pos = i + 1
if stroka == 1 or stroka == 5:
	res += 2
if pos == 1 or pos == 5:
	res += 2
if stroka == 2 or stroka == 4:
	res += 1
if pos == 2 or pos == 4:
	res += 1
print(res)


for i in range(5):
	num = input().split()
	ans = 0
	for j in range(5):
		if num[j] == '1':
			print(max(i - 2, 2 - i) + max(j - 2, 2 - j))
			ans = 1
			break
	if ans == 1:
		break


ans = 0
for i in range(5):
	s = input().split()
	for j in range(5):
		if s[j] == '1':
			ans = ans + abs(j - 2) + abs(i - 2)
print(ans)


m = [[0] * 5] * 5
for i in range(0, 5):
	m[i] = input().split()
for k in range(0, 5):
	for j in range(0, 5):
		a = int(k)
		b = int(j)
		if int(m[a][b]) == 1:
			print(abs(a - 2) + abs(b - 2))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
for i in range(9):
	if a[0] == '1' or a[4] == '1' or e[0] == '1' or (e[4] == '1'):
		output = 4
	elif a[1] == '1' or a[3] == '1' or e[1] == '1' or (e[3] == '1') or (b[0] == '1') or (b[4] == '1') or (d[0] == '1') or (d[4] == '1'):
		output = 3
	elif a[2] == '1' or b[1] == '1' or b[3] == '1' or (c[0] == '1') or (c[4] == '1') or (d[1] == '1') or (d[3] == '1') or (e[2] == '1'):
		output = 2
	elif c[2] == '1':
		output = 0
	else:
		output = 1
print(output)


(row_id, col_id) = (-1, -1)
for i in range(5):
	row = input().split()
	for (j, _) in enumerate(row):
		if _ == '1':
			row_id = i
			col_id = j
print(abs(2 - row_id) + abs(2 - col_id))


for i in range(5):
	list = input().split()
	if '1' in list:
		hang = i + 1
		lie = list.index('1') + 1
print(abs(hang - 3) + abs(lie - 3))


from sys import stdin, stdout
for i in range(5):
	row = [int(x) for x in stdin.readline().rstrip().split()]
	for (j, n) in enumerate(row):
		if n == 1:
			x = i
			y = j
			break
dist = abs(x - 2) + abs(y - 2)
stdout.write(str(dist))


an = []
an2 = 0
d = []
n = input
for i in range(1, 6):
	d = n().split()
	if '1' in d:
		an = d
		an2 = i
print(abs(3 - (an.index('1') + 1)) + abs(3 - an2))


def find_cord(index_number, number):
	for (index, Value) in enumerate(index_number):
		if number in Value:
			return (index, Value.index(number))

def solver(problem):
	steps = 0
	X_Coord = problem[0]
	Y_Coord = problem[1]
	while X_Coord != 2:
		if X_Coord == 2:
			break
		elif X_Coord > 2:
			X_Coord -= 1
			steps += 1
		elif X_Coord < 2:
			X_Coord += 1
			steps += 1
	while Y_Coord != 2:
		if Y_Coord == 2:
			break
		elif Y_Coord > 2:
			Y_Coord -= 1
			steps += 1
		elif Y_Coord < 2:
			Y_Coord += 1
			steps += 1
	return steps
a = list()
val = 1
sentinel = []
for i in range(5):
	a.append([int(j) for j in input().split()])
Coordinates = find_cord(a, val)
print(solver(Coordinates))


r = [2, 1, 0, 1, 2]
for i in r:
	string = input().split()
	if '1' in string:
		print(i + r[string.index('1')])


lst = [2, 1, 0, 1, 2]
for i in lst:
	s = input().split()
	if '1' in s:
		print(i + lst[s.index('1')])
		break


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return list(map(int, input().split()))
for i in range(5):
	dum = invr()
	try:
		idx = dum.index(1)
		print(abs(idx - 2) + abs(i - 2))
	except:
		continue


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))
a = 0
b = 0
c = 0
d = 0
e = 0
try:
	if r1.index(1) or 0 == 0:
		a = r1.index(1) + 1
except:
	pass
try:
	if r2.index(1) or 0 == 0:
		b = r2.index(1) + 1
except:
	pass
try:
	if r3.index(1) or 0 == 0:
		c = r3.index(1) + 1
except:
	pass
try:
	if r4.index(1) or 0 == 0:
		d = r4.index(1) + 1
except:
	pass
try:
	if r5.index(1) or 0 == 0:
		e = r5.index(1) + 1
except:
	pass
if a:
	x = abs(3 - 1) + abs(3 - a)
	print(x)
if b:
	x = abs(3 - 2) + abs(3 - b)
	print(x)
if c:
	x = abs(3 - c)
	print(x)
if d:
	x = abs(3 - 4) + abs(3 - d)
	print(x)
if e:
	x = abs(3 - 5) + abs(3 - e)
	print(x)


def fixMatrix(m):
	row = 0
	col = 0
	for i in range(5):
		for j in range(5):
			if m[i][j] == 1:
				row = i
				col = j
	total = 0
	if row > 2:
		total += row - 2
	else:
		total += 2 - row
	if col > 2:
		total += col - 2
	else:
		total += 2 - col
	return total

def llenarMatriz():
	m = []
	l = []
	for i in range(5):
		l = input().split()
		l = list(map(int, l))
		m.append(l)
	return m
print(fixMatrix(llenarMatriz()))


import re

def main():
	res = 0
	for i in range(5):
		arr = list(map(int, input().split()))
		if sum(arr) == 1:
			for j in range(5):
				if arr[j] == 1:
					res = abs(2 - i) + abs(2 - j)
	print(res)
main()


ans = 0
for i in range(5):
	tmp = input().split()
	if '1' in tmp:
		if i == 0 or i == 4:
			ans += 2
		elif i == 1 or i == 3:
			ans += 1
		if tmp.index('1') == 0 or tmp.index('1') == 4:
			ans += 2
		if tmp.index('1') == 1 or tmp.index('1') == 3:
			ans += 1
print(ans)


for i in range(5):
	row = [int(s) for s in input().split()]
	if 1 in row:
		x = i + 1
		y = row.index(1) + 1
print(abs(x - 3) + abs(y - 3))


list1 = list(map(int, input().split()))
list1.extend(list(map(int, input().split())))
list1.extend(list(map(int, input().split())))
list1.extend(list(map(int, input().split())))
list1.extend(list(map(int, input().split())))
x = list1.index(1)
a = min(x % 5, 4 - x % 5) + 1
b = min(x // 5, 4 - x // 5) + 1
print(6 - a - b)


import os
row = 1
col = 1
found = False
for _ in range(5):
	line = list(map(int, input().rstrip().split()))
	i = 1
	for j in line:
		if j == 1:
			found = True
			col = i
			break
		i += 1
	if found:
		break
	row += 1
print(abs(3 - row) + abs(3 - col))


num = 0
for m in range(5):
	line = input()
	if line != '0 0 0 0 0':
		num += abs(m - 2)
		line = line.split()
		for n in range(5):
			if line[n] == '1':
				num += abs(n - 2)
print(num)


import math
m = []
for i in range(5):
	m.append([int(i) for i in input().split()])
for j in range(5):
	for k in range(5):
		if m[j][k] == 1:
			r = j
			c = k
b = abs(2 - r) + abs(2 - c)
print(b)


matrix = []
for i in range(5):
	a = [None] * 5
	(a[0], a[1], a[2], a[3], a[4]) = map(int, input().split())
	matrix.append(a)
step = 0
if matrix[2][2] == 1:
	print(step)
else:
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				if i >= 2:
					r = i - 2
				if j >= 2:
					c = j - 2
				if i < 2:
					r = 2 - i
				if j < 2:
					c = 2 - j
				print(r + c)
				break


arr = []
ans = 0
for i in range(5):
	inner = []
	inner = list(map(int, input().split()))
	arr.append(inner)
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			r = i
			c = j
ans = abs(r - 2) + abs(c - 2)
print(ans)


r = -1
c = -1
count = 0
for i in range(5):
	l = list(map(int, input().split()))
	if sum(l) == 1:
		r = i
		for j in range(5):
			if l[j] == 1:
				c = j
if r == 0 or r == 4:
	count += 2
elif r == 1 or r == 3:
	count += 1
if c == 0 or c == 4:
	count += 2
elif c == 1 or c == 3:
	count += 1
print(count)


mymatriz = []
for i in range(5):
	(a, b, c, d, e) = input().split()
	mymatriz.append([a, b, c, d, e])
for i in range(5):
	for j in range(5):
		if mymatriz[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
			break


n = 5
a = []
s = 0
z = 5
for i in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	for j in range(n):
		if a[i][j] == 1:
			z = abs(2 - i) + abs(2 - j)
	s = 0
print(z)


l = [2, 1, 0, 1, 2]
for i in l:
	s = input().split()
	if '1' in s:
		print(i + l[s.index('1')])


x1 = input().split(' ')
x2 = input().split(' ')
x3 = input().split(' ')
x4 = input().split(' ')
x5 = input().split(' ')
y = list()
y.append(x1)
y.append(x2)
y.append(x3)
y.append(x4)
y.append(x5)
a = 0
b = 0
for i in range(0, 5):
	for j in range(0, 5):
		if y[i][j] == '1':
			a = i
			b = j
cnt = 0
if a > 2:
	cnt += a - 2
elif a <= 2:
	cnt += 2 - a
if b > 2:
	cnt += b - 2
elif b <= 2:
	cnt += 2 - b
print(cnt)


_1 = ''
o = 0
count = 0
l = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			if i > 2:
				count += i - 2
			elif i < 2:
				count += 2 - i
			if j > 2:
				count += j - 2
			elif j < 2:
				count += 2 - j
print(count)


ar = [2, 1, 0, 1, 2]
for i in ar:
	m = input()
	if '1' in m:
		print(i + ar[m.find('1') // 2])


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			idx = abs(i + 1 - 3)
			idy = abs(j + 1 - 3)
			print(idx + idy)
			break


arr = [None] * 5
for i in range(5):
	arr[i] = list(map(int, input().split()))
	for j in range(5):
		if arr[i][j] == 1:
			x = i
			y = j
count = abs(x - 2) + abs(y - 2)
print(count)


matrix = []
for x in range(1, 6):
	row = [int(y) for y in input().split()]
	row.append(x)
	if row[:5].count(1) == 1:
		row_number = row[5]
		i = 1
		for elem in row[:5]:
			if elem == 1:
				break
			i += 1
		column_number = i
	matrix.append(row)
row_moves = row_number - 3
column_moves = column_number - 3
if row_moves < 0 and row_moves != 0:
	row_moves *= -1
if column_moves < 0 and column_moves != 0:
	column_moves *= -1
print(row_moves + column_moves)


t = [[0 for i in range(5)] for j in range(5)]
for i in range(5):
	t[i] = [int(e) for e in input().split()]
a = ()
for i in range(5):
	for j in range(5):
		if t[i][j] == 1:
			a = (i + 1, j + 1)
			i = 5
			break
print(abs(a[0] - 3) + abs(a[1] - 3))


import math
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
if 1 in l1:
	print(2 + abs(2 - l1.index(1)))
elif 1 in l2:
	print(1 + abs(2 - l2.index(1)))
elif 1 in l3:
	print(abs(2 - l3.index(1)))
elif 1 in l4:
	print(1 + abs(2 - l4.index(1)))
elif 1 in l5:
	print(2 + abs(2 - l5.index(1)))


L = []
for i in range(5):
	L.append(input().split())
index_x = 0
index_y = 0
for i in range(5):
	for j in range(5):
		if int(L[i][j]) == 1:
			index_x = i + 1
			index_y = j + 1
		L[i][j] = int(L[i][j])
ans = abs(3 - index_x)
ans = ans + abs(3 - index_y)
print(ans)


for r in range(1, 6):
	values = input().split()
	for i in range(1, 6):
		if values[i - 1] == '1':
			ans = abs(i - 3) + abs(r - 3)
			break
print(ans)


for i in range(5):
	row = input().split()
	for j in range(5):
		if row[j] == '1':
			m = i
			n = j
		else:
			continue
print(abs(m - 2) + abs(n - 2))


lt = []
for n in range(0, 5):
	lt.append(input().split())
for i in range(0, 5):
	if '1' in lt[i]:
		x = int(i)
		y = lt[i].index('1')
s = abs(x - 2) + abs(y - 2)
print(s)


(m, n) = (0, 0)
for i in range(1, 6):
	a = [int(x) for x in input().split()]
	for j in range(1, 6):
		if a[j - 1] == 1:
			m = i
			n = j
print(abs(3 - m) + abs(3 - n))


import math
n = [[int(x) for x in input().split()] for i in range(5)]

def first():
	for i in range(5):
		for j in range(5):
			if n[i][j] == 1:
				return (i, j)
(i, j) = first()
m = 2
l = 2
k = abs(m - i)
h = abs(j - l)
b = k + h
print(b)


l = []
row = 0
col = 0
count = 0
for i in range(5):
	l.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			row = i
			col = j
if row == 0 or row == 4:
	count += 2
if row == 1 or row == 3:
	count += 1
if col == 0 or col == 4:
	count += 2
if col == 1 or col == 3:
	count += 1
print(count)


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().strip().split())))
for i in range(5):
	if 1 in matrix[i]:
		r = abs(i - 2) + abs(matrix[i].index(1) - 2)
		print(r)
		break


import math

def main():
	lst = [input().split()[:5] for x in range(5)]
	(xPos, yPos) = (0, 0)
	check = False
	for x in range(5):
		for y in range(5):
			if lst[x][y] == '1':
				xPos = x
				yPos = y
				check = True
				break
		if check == True:
			break
	print(int(math.fabs(2 - xPos) + math.fabs(2 - yPos)))
main()


matrix = []
loop = 0
moves = 0
while loop < 5:
	usr = input('')
	usr = usr.split(' ')
	usr = [int(n) for n in usr]
	matrix.append(usr)
	loop += 1
for items in matrix:
	if 1 in items:
		row_index = matrix.index(items)
		one_index = items.index(1)
		if row_index == 2:
			if one_index == 2:
				print(0)
				break
			else:
				if one_index > 2:
					print(one_index - 2)
				else:
					print(2 - one_index)
				break
		elif one_index == 2:
			if row_index > 2:
				print(row_index - 2)
			else:
				print(2 - row_index)
		else:
			if row_index > 2:
				moves += row_index - 2
			else:
				moves += 2 - row_index
			if one_index > 2:
				moves += one_index - 2
			else:
				moves += 2 - one_index
			print(moves)


total = 0
arr = []
for _ in range(5):
	arr.append(list(map(int, input().split())))
for (n, row) in enumerate(arr):
	try:
		col = row.index(1)
	except ValueError:
		continue
	if col > 2:
		total += col - 2
	elif col < 2:
		total += 2 - col
	if n > 2:
		total += n - 2
	elif n < 2:
		total += 2 - n
	print(total)
	break


for i in range(1, 6):
	l = list(map(int, input().split()))
	if 1 in l:
		m = i
		n = l.index(1)
s = abs(3 - m) + abs(n - 2)
print(s)


import math
matrix = []
place = 0
move = 0
for i in range(5):
	matrix.append(list(map(int, input().split())))
for i in range(5):
	if 1 in matrix[i]:
		place = i
		move += int(math.fabs(i - 2))
		break
move += int(math.fabs(matrix[place].index(1) - 2))
print(move)


l = []
for _ in range(5):
	p = list(map(int, input().split()))
	l.append(p)
col = -1
for i in range(5):
	try:
		col = l[i].index(1)
	except ValueError:
		continue
	if col > -1:
		row = i
print(abs(row - 2) + abs(col - 2))


l = []
for _ in range(5):
	l.append([int(i) for i in input().split()])
for i in range(len(l)):
	if 1 in l[i]:
		y = l[i].index(1)
		break
i += 1
y += 1
count = 0
if i != 3:
	count += abs(3 - i)
if y != 3:
	count += abs(3 - y)
print(count)


m = []
for i in range(5):
	x = input().split()
	m.append(x)
for i in range(5):
	if '1' in m[i]:
		a = i
		b = m[i].index('1')
		break
print(abs(a - 2) + abs(b - 2))


a = []
for i in range(5):
	b = list(map(int, input().split()))
	try:
		n = b.index(1)
		m = i
	except:
		continue
print(abs(m - 2) + abs(n - 2))


a = []
b = 0
while b < 5:
	a.append(input('').split(' '))
	b = b + 1
i = 0
while i < 5:
	j = 0
	while j < 5:
		if int(a[i][j]) != 0:
			p = i + 1
			q = j + 1
			break
		else:
			j = j + 1
			continue
	i = i + 1
if p >= 3:
	x = p - 3
else:
	x = 3 - p
if q >= 3:
	y = q - 3
else:
	y = 3 - q
print(x + y)


def matrix(array):
	for i in range(5):
		for j in range(5):
			if array[i][j] == 1:
				return abs(2 - i) + abs(2 - j)
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
print(matrix([a, b, c, d, e]))


b = []
for i in range(5):
	b.append(list(map(int, input().rstrip().split())))
l = 0
r = 0
for i in range(5):
	for j in range(5):
		if b[i][j] == 1:
			l = i + 1
			r = j + 1
			break
if l == 3 and r == 3:
	print(0)
else:
	print(abs(3 - l) + abs(3 - r))


a = [[int(j) for j in input().split()] for k in range(5)]
for k in range(5):
	for s in range(5):
		if a[k][s] == 1:
			n = k
			m = s
print(abs(n - 2) + abs(m - 2))


a = []
while True:
	try:
		a.append(input().replace(' ', ''))
	except:
		break
for i in range(int(len(a))):
	for j in range(int(len(a[i]))):
		if a[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))


mass = [[]]
mass.clear()
one_i = 0
one_j = 0
for i in range(5):
	mass.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if mass[i][j] == 1:
			one_i = i
			one_j = j
print(abs(2 - one_i) + abs(2 - one_j))


mat = []
for _ in range(5):
	mat.append(list(map(int, input().split())))
for i in range(5):
	for k in range(5):
		if mat[i][k] == 1:
			row = i
			col = k
print(abs(2 - row) + abs(2 - col))


for i in range(5):
	row = input().split(' ')
	if '1' in row:
		rownum = i
		column = row.index('1')
		print(abs(2 - rownum) + abs(2 - column))
		break


mat = []
i = 0
while i < 5:
	fila = input()
	lista = fila.split(' ')
	for num in lista:
		mat.append(int(num))
	i += 1
pos1 = 0
for i in mat:
	pos1 += 1
	if i == 1:
		break
pos1 -= 1
i = pos1 % 5 + 1
j = int(pos1 / 5) + 1
i = i - 3
j = j - 3
i = abs(i)
j = abs(j)
print(i + j)


from sys import stdin, stdout
inp = stdin.readline
out = stdout.write
idx = []
for i in range(5):
	l = list(map(int, inp().strip().split()))
	if 1 in l:
		idx.append(i)
		idx.append(l.index(1))
m = abs(2 - idx[0]) + abs(2 - idx[1])
out(str(m))


def differenceBetweenTwoNumbers(x, y):
	if x > y:
		return x - y
	elif x < y:
		return y - x
	else:
		return 0
rowOne = list(map(int, input().split()))
rowTwo = list(map(int, input().split()))
rowThree = list(map(int, input().split()))
rowFour = list(map(int, input().split()))
rowFive = list(map(int, input().split()))
for number in rowOne:
	if number == 0:
		continue
	else:
		row = 1
for number in rowTwo:
	if number == 0:
		continue
	else:
		row = 2
for number in rowThree:
	if number == 0:
		continue
	else:
		row = 3
for number in rowFour:
	if number == 0:
		continue
	else:
		row = 4
for number in rowFive:
	if number == 0:
		continue
	else:
		row = 5
movesInRows = differenceBetweenTwoNumbers(row, 3)
if row == 1:
	column = rowOne.index(1) + 1
if row == 2:
	column = rowTwo.index(1) + 1
if row == 3:
	column = rowThree.index(1) + 1
if row == 4:
	column = rowFour.index(1) + 1
if row == 5:
	column = rowFive.index(1) + 1
movesInColumns = differenceBetweenTwoNumbers(column, 3)
answer = int(movesInRows + movesInColumns)
print(answer)


matrix = [[0 for x in range(5)] for j in range(5)]
for i in range(5):
	matrix[i] = list(map(int, input().split()))
row = 0
col = 0
flag = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i
			col = j
			flag = 1
			break
	if flag == 1:
		break
print(abs(row - 2) + abs(col - 2))


a = []
r = 0
c = 0
for i in range(5):
	a.append(list(map(int, input().split())))
for x in range(len(a)):
	for y in range(len(a[x])):
		if a[x][y] == 1:
			r = x
			c = y
			break
if r > 2:
	if c > 2:
		m = r - 2 + (c - 2)
	else:
		m = r - 2 + (2 - c)
elif c > 2:
	m = 2 - r + (c - 2)
else:
	m = 2 - r + (2 - c)
print(m)


li = [[int(i) for i in input().split()] for j in range(5)]
for i in range(5):
	for j in range(5):
		if li[i][j] == 1:
			a = i + 1
			b = j + 1
print(abs(a - 3) + abs(b - 3))


for i in range(0, 5):
	ar = list(map(int, input('').split()))
	for x in range(0, 5):
		if ar[x] == 1:
			l = i + 1
			k = x + 1
l = 3 - l
k = 3 - k
print(abs(l) + abs(k))


i = 0
while i < 5:
	s = list(map(int, input().split()))
	for t in range(0, 5):
		if s[t] == 1:
			m = abs(2 - i) + abs(2 - t)
		else:
			pass
	i = i + 1
print(m)


from sys import stdin
x = [[i for i in stdin.readline().rstrip().split()] for j in range(5)]
foundOne = [(index, row.index('1')) for (index, row) in enumerate(x) if '1' in row]
foundOne = foundOne[0]
print(abs(foundOne[0] - 2) + abs(foundOne[1] - 2))


b = 0
a = []
for x in range(5):
	c = list(map(int, input().split()))
	a.append(c)
for x in range(len(a)):
	for y in range(len(a)):
		if a[2][2] == 1:
			break
		elif 1 in a[0]:
			(a[0], a[1]) = (a[1], a[0])
			b += 1
		elif 1 in a[1]:
			(a[1], a[2]) = (a[2], a[1])
			b += 1
		elif 1 in a[3]:
			(a[3], a[2]) = (a[2], a[3])
			b += 1
		elif 1 in a[4]:
			(a[4], a[3]) = (a[3], a[4])
			b += 1
while a[2][2] != 1:
	if 1 is a[2][0]:
		b += 1
		for x in range(len(a)):
			(a[x][0], a[x][1]) = (a[x][1], a[x][0])
	elif 1 is a[2][1]:
		b += 1
		for x in range(len(a)):
			(a[x][1], a[x][2]) = (a[x][2], a[x][1])
	elif 1 is a[2][3]:
		b += 1
		for x in range(len(a)):
			(a[x][2], a[x][3]) = (a[x][3], a[x][2])
	elif 1 is a[2][4]:
		b += 1
		for x in range(len(a)):
			(a[x][4], a[x][3]) = (a[x][3], a[x][4])
print(b)


Matrix = [list(map(int, input().split())) for lines in range(5)]
for i in range(5):
	for j in range(5):
		if Matrix[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


from math import fabs
n = 2
for _ in 'qqqqq':
	a = list(map(int, input().split()))
	if 1 in a:
		n = fabs(n)
		m = 2
		for i in a:
			if i == 1:
				m = fabs(m)
				print(str(n + m)[:-2])
			else:
				m -= 1
	else:
		n -= 1


x = [list(map(int, input().split())) for _ in range(5)]
k = 1
for y in range(5):
	if k in x[y]:
		(a, b) = (y, x[y].index(k))
		print(abs(a - 2) + abs(b - 2))
	else:
		pass


input_list = []
for i in range(5):
	input_list.append(list(map(int, input().split(' '))))
row_1 = 0
col_1 = 0
for i in range(len(input_list)):
	if 1 in input_list[i]:
		row_1 = i
		col_1 = input_list[i].index(1)
number_of_moves = abs(2 - row_1) + abs(2 - col_1)
print(number_of_moves)


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i
			coloumn = j
			break
print(abs(row - 2) + abs(coloumn - 2))


from math import fabs
mas = []
summa = 0
for i in range(5):
	mas.append(input().split(' '))
for i in range(5):
	l = mas[i]
	for j in range(5):
		if l[j] == '1':
			summa = fabs(2 - i) + fabs(2 - j)
			print(int(summa))


pos = []
for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			pos.append(i)
			pos.append(j)
		else:
			continue
(i, j) = (2, 2)
move = abs(pos[0] - i) + abs(pos[1] - j)
print(abs(move))


g = 0
v = 0
for x in range(1, 6):
	lst = input().split()
	if '1' in lst:
		g = x
		v = lst.index('1')
print(abs(3 - g) + abs(2 - v))


x = []
lonelyrow = 0
lonelycolumn = 0
disttocenterRow = 0
disttocenterCol = 0
moves = 0
for i in range(0, 5):
	monkey = str(input())
	monkey = monkey.replace(' ', '')
	x.append(monkey)
	if x[i].__contains__('1'):
		lonelyrow = i
		lonelycolumn = x[i].find('1')
disttocenterRow = abs(2 - lonelyrow)
disttocenterCol = abs(2 - lonelycolumn)
moves = disttocenterCol + disttocenterRow
print(moves)


import math
l = []
a = 0
b = 0
f = 0
for i in range(5):
	s = input()
	l = s.split()
	if '1' in l:
		b = l.index('1')
		f = 1
	elif f == 0:
		a += 1
print(abs(2 - a) + abs(2 - b))


a = 0
b = 0
j = 1
c = []
for x in range(1, 6):
	t = input()
	j = 0
	for y in t.split():
		j = j + 1
		c.append(y)
		if int(y) == 1:
			a = x
			b = j
a = abs(3 - a)
b = abs(3 - b)
print(a + b)


import sys
arr = []
for i in range(5):
	arr.append(input().strip().split(' '))
i1 = 0
j1 = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == '1':
			i1 = i
			j1 = j
			break
print(abs(i1 - 2) + abs(j1 - 2))


row = col = -1

def problem_input() -> None:
	global row, col
	for i in range(5):
		index = input().find('1')
		if index >= 0:
			row = i
			col = index // 2

def count_moves(row_index: int, col_index: int) -> int:
	return abs(row_index - 2) + abs(col_index - 2)
problem_input()
print(count_moves(row, col))


k = 0
x = 0
y = 0
for i in range(5):
	b = list(map(int, input().split()))
	if 1 in b:
		y = b.index(1)
		k = 1
	elif k != 1:
		x += 1
print(abs(x - 2) + abs(y - 2))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
(x, y, p, q) = (0, 0, 2, 2)
for i in range(5):
	a[i] = int(a[i])
	b[i] = int(b[i])
	c[i] = int(c[i])
	d[i] = int(d[i])
	e[i] = int(e[i])
	if a[i] == 1:
		x = 0
		y = i
	elif b[i] == 1:
		x = 1
		y = i
	elif c[i] == 1:
		x = 2
		y = i
	elif d[i] == 1:
		x = 3
		y = i
	elif e[i] == 1:
		x = 4
		y = i
print(abs(p - x) + abs(q - y))


import math
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()))
for i in range(5):
	if a[i] == 1:
		r = 1
		c = i + 1
		break
	if b[i] == 1:
		r = 2
		c = i + 1
		break
	if c[i] == 1:
		r = 3
		c = i + 1
		break
	if d[i] == 1:
		r = 4
		c = i + 1
		break
	if e[i] == 1:
		r = 5
		c = i + 1
		break
rd = 3 - r
if rd < 0:
	rd = -rd
cd = 3 - c
if cd < 0:
	cd = -cd
ans = rd + cd
print(ans)


l = [list(map(int, input().split())) for i in range(0, 5)]
count = 0
for i in range(0, len(l)):
	for j in range(0, len(l[i])):
		if l[i][j] == 1:
			if i == 2 and j == 2:
				count == 0
				break
			else:
				count = abs(2 - j)
				count += abs(2 - i)
				break
print(count)


a1 = [int(a) for a in input().split(' ')]
a2 = [int(a) for a in input().split(' ')]
a3 = [int(a) for a in input().split(' ')]
a4 = [int(a) for a in input().split(' ')]
a5 = [int(a) for a in input().split(' ')]
for e in range(5):
	if a1[e] == 1:
		num_row = 1
		num_col = e + 1
	elif a2[e] == 1:
		num_row = 2
		num_col = e + 1
	elif a3[e] == 1:
		num_row = 3
		num_col = e + 1
	elif a4[e] == 1:
		num_row = 4
		num_col = e + 1
	elif a5[e] == 1:
		num_row = 5
		num_col = e + 1
print(abs(3 - num_row) + abs(3 - num_col))


matrix = list()
for _ in range(5):
	matrix.append(input().split())
(target_row, target_col) = (3, 3)
(found_row, found_col) = (0, 0)
for rows in range(len(matrix)):
	for cols in range(len(matrix)):
		if matrix[rows][cols] == '1':
			(found_row, found_col) = (rows + 1, cols + 1)
result = abs(target_row - found_row) + abs(target_col - found_col)
print(result)


m = []
for i in range(5):
	mat = list(map(int, input().split()))
	m.append(mat)
c = 0
c1 = 4
c2 = 3
c3 = 2
for i in m:
	if i[0] == 1 or i[4] == 1:
		print(c1)
	elif i[1] == 1 or i[3] == 1:
		print(c2)
	elif i[2] == 1:
		print(c3)
	c = c + 1
	if c == 3 or c == 4:
		c1 = c1 + 1
		c2 = c2 + 1
		c3 = c3 + 1
	else:
		c1 = c1 - 1
		c2 = c2 - 1
		c3 = c3 - 1


r = 0
c = 0
for i in range(5):
	t = input().split()
	for j in range(5):
		if int(t[j]) == 1:
			r = i + 1
			c = j + 1
toR = abs(r - 3)
toC = abs(c - 3)
print(toR + toC)


import math
matrix = []
for i in range(5):
	inp = input().split()
	for j in range(5):
		if inp[j] == '1':
			row = j
			col = i
print(abs(row - 2) + abs(col - 2))


x = [input().split() for i in range(5)]
y = int([x.index(i) for i in x if '1' in i][0])
z = int([i.index('1') for i in [i for i in x if '1' in i]][0])
it = sum([abs(z - 2), abs(y - 2)])
print(it)


st = [[int(j) for j in input().split()] for i in range(0, 5)]
for i in range(0, 5):
	if 1 in st[i]:
		a = st[i].index(1)
		print(abs(i - 2) + abs(a - 2))


for i in range(5):
	a = [int(x) for x in input().split()]
	if 1 in a:
		r = i + 1
		c = a.index(1) + 1
ans = abs(r - 3) + abs(c - 3)
print(ans)


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
x = 0
y = 0
for i in range(5):
	A = inlt()
	for j in range(5):
		if A[j] == 1:
			x = j
			y = i
print(abs(x - 2) + abs(y - 2))


x = y = 0
m = []
for i in range(5):
	m.append([s for s in input().split(' ')])
for (n, i) in enumerate(m):
	if '1' in i:
		y = n
		x = i.index('1')
print(abs(2 - x) + abs(2 - y))


for i in range(5):
	row = list(map(int, input().split(' ')))
	if 1 in row:
		x = i
		y = row.index(1)
diff = abs(2 - x) + abs(2 - y)
print(diff)


for i in range(5):
	e = input()
	li = e.split()
	if '1' in li:
		mov = abs(2 - i) + abs(2 - li.index('1'))
print(mov)


m = []
r = 0
c = 0
moves = 0
for i in range(0, 5):
	ilist = map(int, input().split())
	m.append(list(ilist))
for i in m:
	if sum(i) > 0:
		break
	r += 1
for i in m[r]:
	if i > 0:
		break
	c += 1
while c != 2:
	if c < 2:
		c += 1
		moves += 1
	if c > 2:
		c -= 1
		moves += 1
while r != 2:
	if r < 2:
		r += 1
		moves += 1
	if r > 2:
		r -= 1
		moves += 1
print(moves)


a = 2
b = 2
c = 0
d = 0
for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		c = l.index(1)
		d = i
print(abs(a - d) + abs(b - c))


matrixRow = []
for i in range(5):
	temp = list(map(int, input().split()))
	matrixRow.append(temp)
row = -1
column = -1
for i in range(5):
	for j in range(5):
		if int(matrixRow[i][j]) == 1:
			row = i + 1
			column = j + 1
result = 0
if row >= 0 and column >= 0:
	rowCount = abs(row - 3)
	columnCount = abs(column - 3)
	result = rowCount + columnCount
print(result)


cont = 0
for i in range(5):
	inp = input()
	clean_inp = inp.replace(' ', '')
	if '1' in clean_inp:
		index = clean_inp.find('1')
		col = cont
	cont += 1
print(abs(index - 2) + abs(col - 2))


l = [input().split() for i in range(5)]
x = 0
i = 0
while i < 5 and x == 0:
	if '1' in l[i]:
		x = 1
	i += 1
row = i - 1
column = l[row].index('1')
ans = abs(row - 2) + abs(column - 2)
print(ans)


inp = []
for i in range(5):
	inp.append(input().replace(' ', ''))
for i in range(1, 6):
	temp = inp[i - 1].find('1')
	if temp != -1:
		print(abs(3 - i) + abs(temp - 2))
		break


mat = []
n = 5
for i in range(n):
	arr = list(map(int, input().split()))
	mat.append(arr)
for i in range(n):
	for j in range(n):
		if mat[i][j] == 1:
			a = i
			a = a + 1
			b = j
			b = b + 1
			if a > 3 and b > 3:
				print(a - 3 + b - 3)
			elif a > 3 and b <= 3:
				print(a - b)
			elif a <= 3 and b > 3:
				print(b - a)
			else:
				print(3 - a + 3 - b)


x = input()
y = input()
z = input()
q = input()
r = input()
if '1' in x:
	t = x.find('1')
	if t == 0 or t == 8:
		print(4)
	elif t == 2 or t == 6:
		print(3)
	elif t == 4:
		print(2)
if '1' in y:
	t = y.find('1')
	if t == 0 or t == 8:
		print(3)
	elif t == 2 or t == 6:
		print(2)
	elif t == 4:
		print(1)
if '1' in z:
	t = z.find('1')
	if t == 0 or t == 8:
		print(2)
	elif t == 2 or t == 6:
		print(1)
	elif t == 4:
		print(0)
if '1' in q:
	t = q.find('1')
	if t == 0 or t == 8:
		print(3)
	elif t == 2 or t == 6:
		print(2)
	elif t == 4:
		print(1)
if '1' in r:
	t = r.find('1')
	if t == 0 or t == 8:
		print(4)
	elif t == 2 or t == 6:
		print(3)
	elif t == 4:
		print(2)


row = col = 0
for i in range(5):
	for (k, j) in enumerate(map(int, input().split())):
		if j == 1:
			row = i
			col = k
			break
print(abs(2 - row) + abs(2 - col))


for y in range(0, 5):
	row = [int(i) for i in list(input().split())]
	for x in range(0, 5):
		if row[x] == 1:
			onex = x
			oney = y
ans = abs(onex - 2) + abs(oney - 2)
print(ans)


l = []
for i in range(5):
	k = list(map(int, input().split()))
	l.append(k)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			first = i
			second = j
print(abs(first - 2) + abs(second - 2))


z = []
for i in range(5):
	a = list(map(int, input().split()))
	z.append(a)
for j in range(5):
	for k in range(5):
		if z[j][k] == 1:
			if j - 2 >= 0 and k - 2 >= 0:
				print(j - 2 + (k - 2))
			elif j - 2 <= 0 and k - 2 >= 0:
				print(2 - j + (k - 2))
			elif j - 2 >= 0 and k - 2 <= 0:
				print(j - 2 + (2 - k))
			elif j - 2 <= 0 and k - 2 <= 0:
				print(2 - j + (2 - k))
			break


for i in range(0, 5):
	ss = [int(x) for x in input().split()]
	for j in range(0, 5):
		if ss[j] == 1:
			ii = i
			jj = j
print(abs(2 - ii) + abs(2 - jj))


m = []
p = q = 7
for i in range(5):
	a = list(map(int, input().split()))
	m.append(a)
for l in range(len(m)):
	for k in range(len(m[l])):
		if m[l][k] == 1:
			p = l
			q = k
			break
print(abs(2 - p) + abs(2 - q))


l = []
for i in range(5):
	l.append(list(map(int, input().split())))
t = []
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			t = [i, j]
			break
d = abs(t[0] - 2) + abs(t[1] - 2)
print(d)


import sys
i = 0
j = 0
for line in sys.stdin:
	size = len(line.split())
	i = 0
	for e in line.split():
		if e == '1':
			ei = i
			ej = j
		i += 1
	j += 1
print(abs(ei - size // 2) + abs(ej - size // 2))


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
	if sum(mat[i]) > 0:
		y = i
for i in range(len(mat)):
	for j in range(len(mat[i])):
		try:
			x = mat[i].index(1)
		except:
			pass
print(abs(3 - (y + 1)) + abs(3 - (x + 1)))


l = []
c = 0
k = 0
for i in range(5):
	l.append(list(map(int, input().split())))
	if 1 in l[i]:
		c = l[i].index(1)
		k = i
print(abs(k - 2) + abs(c - 2))


for i in range(5):
	one_index = input().find('1')
	if one_index != -1:
		print(abs(i - 2) + abs(one_index // 2 + 1 - 3))


list1 = [int(x) for x in input().split()]
list2 = [int(y) for y in input().split()]
list3 = [int(z) for z in input().split()]
list4 = [int(a) for a in input().split()]
list5 = [int(b) for b in input().split()]
final_list = list1 + list2 + list3 + list4 + list5
print()
index = final_list.index(1)
if index == 12:
	print('0')
elif index == 0 or index == 4 or index == 20 or (index == 24):
	print('4')
elif index == 1 or index == 3 or index == 5 or (index == 9) or (index == 15) or (index == 19) or (index == 21) or (index == 23):
	print('3')
elif index == 2 or index == 6 or index == 8 or (index == 10) or (index == 14) or (index == 16) or (index == 18) or (index == 22):
	print('2')
else:
	print('1')


count = 0
matrix = []
for i in range(0, 5):
	row = input().split(' ')
	if '1' in row:
		row_num = count
		column_num = row.index('1')
	matrix.append(row)
	count += 1
moves = abs(row_num - 2) + abs(column_num - 2)
print(moves)


import math
matrix = []
center = [2, 2]
first = []
for i in range(5):
	matrix.append([int(i) for i in input().split(' ')])
	if 1 in matrix[i]:
		first = [i, matrix[i].index(1)]
print(abs(center[0] - first[0]) + abs(center[1] - first[1]))


for i in range(5):
	lst = list(map(int, input().split()))
	if 1 in lst:
		r = i + 1
		c = lst.index(1) + 1
mr = 3 - r
if mr < 0:
	mr = mr * -1
mc = 3 - c
if mc < 0:
	mc = mc * -1
print(mr + mc)


from sys import stdin
matrix = []
for i in range(5):
	lst = list(map(int, stdin.readline().strip().split()))
	if 1 in lst:
		col = lst.index(1)
		print(abs(col - 2) + abs(i - 2))
		break


lst = []
one = 0
for i in range(5):
	line = list(map(int, input().split()))
	if 1 in line:
		one = (i, line.index(1))
	lst.append(line)
print(abs(one[0] - 2) + abs(one[1] - 2))


matrix = list()
i = 0
position_of_row = 0
position_of_col = 0
while i < 5:
	x = list(map(int, input().split()))
	matrix.append(x)
	i += 1
row = 0
while row <= 4:
	col = 0
	while col <= 4:
		if matrix[row][col] == 1:
			position_of_row = position_of_row + row
			position_of_col = position_of_col + col
		col += 1
	row += 1
num_of_row_moves = position_of_row - 2
num_of_col_moves = position_of_col - 2
if num_of_row_moves < 0:
	num_of_row_moves = num_of_row_moves * -1
if num_of_col_moves < 0:
	num_of_col_moves = num_of_col_moves * -1
number_of_minmum_moves = num_of_row_moves + num_of_col_moves
print(number_of_minmum_moves)


matrix = []
for i in range(5):
	a = []
	a.append(input().split(' '))
	matrix.append(a)
row = 0
col = 0
for j in range(5):
	for k in range(5):
		if matrix[j][0][k] == '1':
			row = j + 1
			col = k + 1
steps = 0
steps = abs(row - 3) + abs(col - 3)
print(steps)


def main():
	for row in range(0, 6):
		(col1, col2, col3, col4, col5) = map(int, input().split())
		if col1 == 1:
			print(2 + abs(2 - row))
			break
		elif col2 == 1:
			print(1 + abs(2 - row))
			break
		elif col3 == 1:
			print(abs(2 - row))
			break
		elif col4 == 1:
			print(1 + abs(2 - row))
			break
		elif col5 == 1:
			print(2 + abs(2 - row))
			break
		else:
			continue
main()


out = 0
i = -2
while i <= 2:
	j = -2
	temp = input().split()
	while j <= 2:
		if temp[j + 2] == '1':
			ii = i
			jj = j
			if i < 0:
				ii = -1 * i
			if j < 0:
				jj = -1 * j
			out = ii + jj
		j += 1
	i += 1
print(out)


col = 0
row = 0
for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		row = i + 1
		col = l.index(1) + 1
ans = abs(3 - row) + abs(3 - col)
print(ans)


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

def get_location(matrix=[]):
	for (idx, arr) in enumerate(matrix):
		for (idx2, i) in enumerate(arr):
			if i == 1:
				return [idx, idx2]
location = get_location(matrix)
rows_swaps = abs(location[0] - 2)
columns_swaps = abs(location[1] - 2)
swapes = rows_swaps + columns_swaps
print(swapes)


def matrix():
	main_list = [list(map(int, i)) for i in [input().split(' ') for _ in range(5)]]
	temp = main_list[0] + main_list[1] + main_list[2] + main_list[3] + main_list[4]
	ind = temp.index(1)
	row = ind // 5 + 1
	col = ind % 5 + 1
	return abs(row - 3) + abs(col - 3)
print(matrix())


x = []
s = 0
for i in range(5):
	a = list(map(int, input().split()))
	if 1 in a:
		r = i
		c = a.index(1)
		if (r == 1) | (r == 3):
			s += 1
		elif (r == 0) | (r == 4):
			s += 2
		if (c == 1) | (c == 3):
			s += 1
		elif (c == 0) | (c == 4):
			s += 2
print(s)


import sys
import math
for i in range(5):
	s = input()
	if '1' in s:
		s2 = s
		ans = abs(i - 2)
l = [int(h) for h in s2.split()]
ans += abs(l.index(1) - 2)
print(ans)


matrix = []
for i in range(5):
	row = input().split(' ')
	matrix.append(row)
output = None
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			output = abs(2 - i) + abs(2 - j)
print(output)


tot_mov = 0
f1 = 3
f2 = 3
li = []
for i in range(5):
	l = list(map(int, input().strip().split()))
	li.append(l)
for i in range(5):
	for j in range(5):
		if li[i][j] == 1:
			tot_mov = abs(f1 - (i + 1)) + abs(f2 - (j + 1))
print(tot_mov)


matrice = []
for i in range(5):
	ligne = input().split()
	matrice.append(ligne)
for i in range(5):
	for j in range(5):
		if matrice[i][j] == '1':
			k = abs(i - 2) + abs(j - 2)
print(k)


import math
(row, col) = (None, None)
for i in range(5):
	l = input().split()
	if '1' in l:
		(row, col) = (i, l.index('1'))
print(abs(col - 2) + abs(row - 2))


i = 1
while i < 6:
	s = tuple(map(int, input().split()))
	if 1 in s:
		x = s.index(1) + 1
		y = i
		break
	i = i + 1
ans = abs(3 - x) + abs(3 - y)
print(ans)


mat = []
for i in range(5):
	mat.append(''.join(input().split()))
for i in range(5):
	j = mat[i].find('1')
	if j != -1:
		print(abs(2 - i) + abs(2 - j))
		break


(r, w, e) = (0, 0, 0)
for i in range(5):
	r += 1
	a = input().split(' ')
	if '1' in a:
		e = r
		w = a.index('1')
		w += 1
a1 = abs(3 - w)
a2 = abs(3 - e)
a = a1 + a2
print(str(a))


l = [2, 1, 0, 1, 2]
for i in l:
	m = input()
	if '1' in m:
		print(i + l[m.find('1') // 2])


matrix = []
for i in range(5):
	matrix.append(input())
(row, col) = (0, 0)
for i in range(5):
	if matrix[i].find('1') != -1:
		col = matrix[i].find('1') // 2
		row = i
print('%d' % (abs(row - 2) + abs(col - 2)))


matrix = []
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(' ')))
x = 0
y = 0
for i in range(5):
	if row1[i] == 1:
		x = 1
		y = i + 1
	elif row2[i] == 1:
		x = 2
		y = i + 1
	elif row3[i] == 1:
		x = 3
		y = i + 1
	elif row4[i] == 1:
		x = 4
		y = i + 1
	elif row5[i] == 1:
		x = 5
		y = i + 1
swaps = abs(3 - x) + abs(3 - y)
print(swaps)


def location(arr):
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				return [i + 1, j + 1]

def beautify(arr):
	count = 0
	if arr[0] < 3:
		count = count + (3 - arr[0])
	elif arr[0] > 3:
		count = count + (arr[0] - 3)
	if arr[1] < 3:
		count = count + (3 - arr[1])
	elif arr[1] > 3:
		count = count + (arr[1] - 3)
	return count
arr = []
for i in range(5):
	row = [int(x) for x in input().split()]
	arr.append(row)
location = location(arr)
print(beautify(location))


a = 0
b = 0
for i in range(5):
	l = list(map(int, input().split()))
	for j in range(len(l)):
		if l[j] == 1:
			a = j + 1
			b = i + 1
print(abs(3 - a) + abs(3 - b))


one = []
for i in range(5):
	rows = str(input())
	rows_list = rows.split(' ')
	for i in range(0, len(rows_list)):
		rows_list[i] = int(rows_list[i])
	one.append(rows_list)
column = 0
row = 0
for i in range(0, len(one)):
	if one[i].count(1) == 1:
		column = one[i].index(1) + 1
		row = i + 1
column = column - 3
row = row - 3
print(abs(column) + abs(row))


m = [list(map(int, input().split())) for i in range(5)]
c = 0
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			c = abs(2 - i) + abs(2 - j)
print(c)


import math
matrix = [0] * 5
k = 0
for i in range(5):
	matrix[i] = list(map(int, input().split()))
	if 1 in matrix[i]:
		j = k
		i2 = matrix[i].index(1)
	k += 1
x = abs(i2 - 2)
y = abs(j - 2)
print(x + y)


m = 0
while True:
	m = m + 1
	(a, b, c, d, e) = input().split()
	if '1' in [a, b, c, d, e]:
		break
t = [a, b, c, d, e]
n = t.index('1') + 1
x = m - 3
y = n - 3
if x < 0:
	x = -x
if y < 0:
	y = -y
print(x + y)


matrix = []
for i in range(0, 5):
	a = list(map(int, input().split()))
	matrix.append(a)
for l in range(0, 5):
	for k in range(0, 5):
		if matrix[l][k] == 1:
			a = abs(l + 1 - 3)
			b = abs(k + 1 - 3)
print(a + b)


arr = []
notFound = False
for i in range(5):
	res = list(map(int, input().split()))
	arr.append(res)
	if not notFound:
		if 1 in res:
			(x, y) = (i, res.index(1))
			notFound = True
print(abs(x - 2) + abs(y - 2))


def Main():
	matr = [0] * 5
	matr[0] = [0] * 5
	matr[0] = list(map(int, input().split()))
	matr[1] = [0] * 5
	matr[1] = list(map(int, input().split()))
	matr[2] = [0] * 5
	matr[2] = list(map(int, input().split()))
	matr[3] = [0] * 5
	matr[3] = list(map(int, input().split()))
	matr[4] = [0] * 5
	matr[4] = list(map(int, input().split()))
	for i in range(5):
		for j in range(5):
			if matr[i][j] == 1:
				x = i + 1
				y = j + 1
	print(abs(x - 3) + abs(y - 3))
Main()


matrix = []
for _ in range(5):
	l = list(map(int, input().split(' ')))
	matrix.append(l)
for i in range(5):
	x = 0
	for j in range(5):
		if matrix[i][j] == 1:
			x = 1
			ans = [i, j]
			break
	if x == 1:
		break
res = abs(ans[0] - 2) + abs(ans[1] - 2)
print(res)


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()))
i = 0
j = 0
s = 0
while i < 5 and j == 0:
	if a[i] == 1:
		j = 1
	elif b[i] == 1:
		j = 2
	elif c[i] == 1:
		j = 3
	elif d[i] == 1:
		j = 4
	elif e[i] == 1:
		j = 5
	else:
		i += 1
if i > 2:
	while i != 2:
		i -= 1
		s += 1
else:
	while i != 2:
		i += 1
		s += 1
if j > 3:
	while j != 3:
		j -= 1
		s += 1
else:
	while j != 3:
		j += 1
		s += 1
print(s)


import sys
input = sys.stdin.readline
print = sys.stdout.write
mat = [list(map(int, input().split())) for _ in range(5)]
for i in range(5):
	if 1 in mat[i]:
		col = mat[i].index(1)
		print(str(abs(i - 2) + abs(col - 2)))


t = True
b = 0
while t:
	a = input().split()
	if a != '':
		b += 1
		if '1' in a:
			c = a.index('1') + 1
			t = False
print(abs(b - 3) + abs(c - 3))


matrix = []
res = 0
for i in range(1, 6):
	a = list(map(int, input().split()))
	if 1 in a:
		strok = i
		stolb = a.index(1) + 1
res = abs(3 - strok) + abs(3 - stolb)
print(res)


(i, j) = (-1, -1)
for row_num in range(5):
	row = [int(x) for x in input().split()]
	if 1 in row:
		i = row_num
		j = row.index(1)
print(abs(i - 2) + abs(j - 2))


k = 0
for x in range(5):
	s = input().split()
	if '1' in s:
		p = s.index('1')
		k += abs(p - 2)
		k += abs(x - 2)
print(k)


l = []
for i in range(5):
	l.append(list(map(int, input().split())))
for i in range(5):
	if 1 in l[i]:
		ind = l[i].index(1)
		break
res = abs(2 - i) + abs(2 - ind)
print(res)


string1 = [int(i) for i in input().split()]
string2 = [int(i) for i in input().split()]
string3 = [int(i) for i in input().split()]
string4 = [int(i) for i in input().split()]
string5 = [int(i) for i in input().split()]
needMoves = 0
if 1 in string1:
	needMoves += abs(3 - (string1.index(1) + 1))
	needMoves += 2
elif 1 in string2:
	needMoves += abs(3 - (string2.index(1) + 1))
	needMoves += 1
elif 1 in string3:
	needMoves += abs(3 - (string3.index(1) + 1))
	needMoves += 0
elif 1 in string4:
	needMoves += abs(3 - (string4.index(1) + 1))
	needMoves += 1
elif 1 in string5:
	needMoves += abs(3 - (string5.index(1) + 1))
	needMoves += 2
print(needMoves)


list1 = []
list2 = []
for i in range(5):
	list1.insert(i, input().split(' '))
for i in range(5):
	if '1' in list1[i]:
		list2.append(1)
	else:
		list2.append(0)
row = int(list2.index(1))
col = int(list1[row].index('1'))
print(abs(2 - row) + abs(2 - col))


i = 0
j = 0
ic = 3
jc = 3
j1 = 0
i1 = 0
a = list()
while i < 5:
	a.append(list(map(int, input().split(' '))))
	i = i + 1
i = 0
for i in range(0, len(a)):
	for j in range(0, len(a[i])):
		if a[i][j] == 1:
			j1 = j + 1
			i1 = i + 1
			print(abs(ic - i1) + abs(jc - j1))


matrix = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
for i in range(5):
	matrix[i] = input().split(' ')
	for j in range(5):
		if matrix[i][j] == '1':
			r = i
			c = j
print(abs(r - 2) + abs(c - 2))


matrix = []
for j in range(0, 5):
	el = str(input())
	matrix.append(el)
number_str = 0
number_el = 0
if matrix[2] == '0 0 1 0 0':
	print('0')
else:
	for i in matrix:
		if '1' in i:
			number_str = matrix.index(i)
			number_el = i.replace(' ', '').index('1')
			matrix[number_str] = i.replace('1', '0')
			if number_el >= 2 and number_str <= 2 or (number_el <= 2 and number_str >= 2):
				count_move_str = len(matrix) - number_str
				count_move_kol = len(i.replace(' ', '')) - number_el
			else:
				count_move_str = len(matrix) - number_str
				count_move_kol = number_el + 1
			count_move = abs(count_move_kol) - abs(count_move_str)
			print(abs(count_move))


n = 5
l = []
for i in range(0, 5):
	s = list(map(int, input().strip().split()))
	l.append(s)
for i in range(len(l)):
	for j in range(len(l[i])):
		if l[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


nice = (3, 3)
current = [0, 0]
for i in range(1, 6):
	line = list(map(int, input().split()))
	if 1 in line:
		current[0] = i
		current[1] = line.index(1) + 1
answer = abs(nice[0] - current[0]) + abs(nice[1] - current[1])
print(answer)


def BeautifulMatrix(matrix):
	rowscenter = int(5 / 2)
	colcenter = int(5 / 2)
	step = 0
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				step = abs(i - rowscenter) + abs(j - colcenter)
	return step
matrix = []
for j in range(5):
	a = [int(i) for i in input().split()]
	matrix.append(a)
res = BeautifulMatrix(matrix)
print(res)


arr = list()
for i in range(5):
	arr.append(str(input()).split())
for i in range(1, 6):
	for j in range(1, 6):
		if arr[i - 1][j - 1] == '1':
			ip = i
			jp = j
			break
print(abs(ip - 3) + abs(jp - 3))


l = []
for i in range(5):
	lis1 = list(map(int, input().split()))
	l.append(lis1)
for i in range(5):
	if 1 in l[i]:
		print(abs(i - 3 + 1) + abs(l[i].index(1) - 3 + 1))
		break


a1 = input().split()
a2 = input().split()
a3 = input().split()
a4 = input().split()
a5 = input().split()
lst = [a1, a2, a3, a4, a5]
count = 0
for i in range(0, len(lst)):
	if '1' in lst[i]:
		j = lst[i].index('1')
		while j != 2:
			if j > 2:
				j -= 1
				count += 1
			if j < 2:
				j += 1
				count += 1
		while i != 2:
			if i > 2:
				i -= 1
				count += 1
			if i < 2:
				i += 1
				count += 1
print(count)


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
m = [l1, l2, l3, l4, l5]
for (i, n) in enumerate(m):
	if sum(n) != 0:
		for (x, y) in enumerate(n):
			if y != 0:
				x1 = i
				y1 = x
print(abs(2 - x1) + abs(2 - y1))


matrix = [list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split()))]
for i in range(5):
	if max(matrix[i]):
		ii = matrix[i].index(1)
		print(abs(i - 2) + abs(int(ii - 2)))
		break


matrix = []
for i in range(5):
	matrix.append(input().split(' '))
for j in range(len(matrix)):
	if '1' in matrix[j]:
		(row, col) = (j, matrix[j].index('1'))
print(abs(row - 2) + abs(col - 2))


array = []
for x in range(5):
	userInput = input()
	array.append(userInput)
row_needs = 0
cols_needs = 0
r = 0
for row in array:
	r += 1
	if '1' in row:
		row_needs = abs(3 - r)
		cols = row.split(' ').index('1')
		cols_needs = abs(cols + 1 - 3)
		print(row_needs + cols_needs)
		break


s1 = input()
s2 = input()
s3 = input()
s4 = input()
s5 = input()
l = 0
if '1' in s1 or '1' in s5:
	if '1' in s1:
		(a, b, c, d, e) = map(int, s1.split())
	else:
		(a, b, c, d, e) = map(int, s5.split())
	l = 2
elif '1' in s2 or '1' in s4:
	if '1' in s2:
		(a, b, c, d, e) = map(int, s2.split())
	else:
		(a, b, c, d, e) = map(int, s4.split())
	l = 1
else:
	(a, b, c, d, e) = map(int, s3.split())
	l = 0
if a == 1 or e == 1:
	l = l + 2
elif b == 1 or d == 1:
	l = l + 1
else:
	l = l + 0
print(l)


for i in range(5):
	a = input()
	arr = [y for y in a.split()]
	if '1' in arr:
		column = i
		row = arr.index('1')
min_swaps = abs(2 - column) + abs(2 - row)
print(min_swaps)


l = []
s = []
for _ in range(5):
	s = input().split()
	s1 = [int(char) for char in s]
	l.append(s1)
res = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			while True:
				if i > 2:
					i -= 1
					res += 1
				elif i < 2:
					i += 1
					res += 1
				if j > 2:
					j -= 1
					res += 1
				elif j < 2:
					j += 1
					res += 1
				if j == 2 and i == 2:
					print(res)
					break


for i in range(1, 6):
	a = input().split(' ')
	if a.count('1') == 1:
		x = i
		y = a.index('1') + 1
n = 0
if x != 3:
	if x > 3:
		n += x - 3
	else:
		n += 3 - x
if y != 3:
	if y > 3:
		n += y - 3
	else:
		n += 3 - y
print(n)


N = 5
table = []
for i in range(N):
	table.append(input().split())
for i in range(N):
	for j in range(N):
		if table[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
			exit()


m = []
for i in range(5):
	l = [int(x) for x in input().split()]
	m.append(l)
f = 0
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			f = 1
			break
	if f == 1:
		break
mid = [2, 2]
print(abs(mid[0] - i) + abs(mid[1] - j))


l = []
for i in range(5):
	a = list(map(int, input().split()))
	l.append(a)
	if 1 in a:
		idx = [i + 1, a.index(1) + 1]
v = abs(3 - idx[0]) + abs(3 - idx[1])
print(v)


answer = 0
for i in range(5):
	s_i = input()
	s_i = s_i.split()
	for k in range(5):
		if s_i[k] == '1':
			answer = abs(i - 2) + abs(k - 2)
print(answer)


ROW = 3
COLUMN = 3
move_needed = 0
for row in range(1, 6, 1):
	line = input()
	line_list = line.split()
	if '1' in line_list:
		row_move = row - ROW
		if row_move < 0:
			row_move *= -1
		col_move = line_list.index('1') + 1 - COLUMN
		if col_move < 0:
			col_move *= -1
		move_needed += row_move + col_move
print(move_needed)


from math import fabs
a = []
for i in range(0, 5):
	a += [list(map(int, input().split()))]
for i in range(0, 5):
	if 1 in a[i]:
		p = i
		q = a[i].index(1)
		break
print(int(fabs(2 - p)) + int(fabs(2 - q)))


my = []
row = 0
indexpos = 0
for x in range(5):
	tm = list(map(int, input().split()))
	for i in range(len(tm)):
		if tm[i] == 1:
			row = x
			indexpos = i
			break
print(abs(2 - row) + abs(2 - indexpos))


a = []
count = 0
for i in range(5):
	l = list(map(int, input().split()))
	try:
		index = l.index(1)
		a = i
	except:
		count += 1
count1 = abs(2 - index) + abs(2 - a)
print(count1)


def read_array():
	x = []
	x1 = []
	x = input()
	x = x.split(' ')
	for r in range(len(x)):
		x1.append(int(x[r]))
	return x1
matrix = []
for r in range(5):
	x = read_array()
	matrix.append(x)
(i_f, j_f) = (0, 0)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			i_f = i
			j_f = j
		else:
			pass
print(abs(i_f - 2) + abs(j_f - 2))


(lst, one_count, line, ryad) = ([], 0, 0, 0)
for i in range(5):
	lst.append(list(map(int, input().split())))
for j in lst:
	for one in j:
		if one == 1:
			one_count += 1
			ryad = j.index(one) + 1
			break
	line += 1
	if one_count == 1:
		break
if ryad == 3:
	if line == 1 or line == 5:
		print(2)
	elif line == 2 or line == 4:
		print(1)
	elif line == 3:
		print(0)
elif ryad == 1 or ryad == 5:
	if line == 1 or line == 5:
		print(4)
	elif line == 2 or line == 4:
		print(3)
	elif line == 3:
		print(2)
elif ryad == 2 or ryad == 4:
	if line == 1 or line == 5:
		print(3)
	elif line == 2 or line == 4:
		print(2)
	elif line == 3:
		print(1)


from sys import stdin
m = [line.split() for line in stdin.readlines()]
try:
	for i in range(5):
		for j in range(5):
			if m[i][j] == '1':
				raise Exception
except:
	pass
print(abs(i - 2) + abs(j - 2))


s = []
for i in range(5):
	a = list(map(int, input().rstrip().split()))
	s.append(a)
row = 0
column = 0
for i in range(len(s)):
	if 1 in s[i]:
		row = i + 1
		b = s[row - 1].index(1)
		column = b + 1
		print(abs(3 - row) + abs(3 - column))


a = []
s = 0
for i in range(5):
	a.append(list(map(int, input().split())))
for g in range(5):
	for i in range(5):
		if sum(a[i]) == 1:
			for j in range(5):
				if a[i][j] == 1:
					if 1 in a[i][:2]:
						(a[i][j], a[i][j + 1]) = (a[i][j + 1], a[i][j])
					elif 1 in a[i][3:]:
						(a[i][j], a[i][j - 1]) = (a[i][j - 1], a[i][j])
					else:
						break
					s += 1
for g in range(5):
	for i in range(5):
		if sum(a[i]) == 1:
			if a[i] in a[:2]:
				(a[i], a[i + 1]) = (a[i + 1], a[i])
			elif a[i] in a[3:]:
				(a[i], a[i - 1]) = (a[i - 1], a[i])
			else:
				break
			s += 1
print(s)


n = 5
l = []
for i in range(n):
	l.append(list(map(int, input().rstrip().split())))
h = -2
for i in range(5):
	try:
		h = l[i].index(1)
	except:
		pass
	if h != -2:
		x = i
		y = h
		break
ans = abs(x - 2) + abs(y - 2)
print(ans)


row = 0
column = 0
for i in range(5):
	LIST = [int(s) for s in input().split()]
	if 1 in LIST:
		column = LIST.index(1)
		row = i
		break
print(abs(2 - column) + abs(2 - row))


a = []
count = 0
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			if i > 2:
				count += i - 2
			if i < 2:
				count += 2 - i
			if j > 2:
				count += j - 2
			if j < 2:
				count += 2 - j
			if i == 2 and j == 2:
				count += 0
print(count)


list = [[0] * 5] * 5
for i in range(5):
	list[i] = input().split()
(x, y) = (0, 0)
for i in range(5):
	for j in range(5):
		if list[i][j] == '1':
			(x, y) = (i, j)
			break
		else:
			continue
print(abs(x - 2) + abs(y - 2))


arr = []
for i in range(5):
	z = input().split()
	y = [int(x) for x in z]
	arr.append(y)
x = 0
y = 0
dx = 0
dy = 0
while y <= len(arr) - 1:
	while x <= len(arr[0]) - 1:
		if arr[y][x] != 0:
			dx = x
			dy = y
			break
		x += 1
	x = 0
	y += 1
	if dy != 0:
		break
distance = abs(dx - 2) + abs(dy - 2)
print(distance)


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))
if 1 in r1:
	c = r1.index(1)
	r = 1
elif 1 in r2:
	c = r2.index(1)
	r = 2
elif 1 in r3:
	c = r3.index(1)
	r = 3
elif 1 in r4:
	c = r4.index(1)
	r = 4
elif 1 in r5:
	c = r5.index(1)
	r = 5
d1 = abs(c + 1 - 3)
d2 = abs(r - 3)
print(d1 + d2)


c = []
t = 0
x = 0
y = 0
for i in range(5):
	b = [int(b) for b in input().split()]
	c.append(b)
for i in range(5):
	for j in range(5):
		if c[i][j] == 1:
			x = i
			y = j
			t = 1
			break
		if t == 1:
			break
if x > 2:
	m = x - 2
if x <= 2:
	m = 2 - x
if y > 2:
	r = y - 2
if y <= 2:
	r = 2 - y
sum = m + r
print(sum)


n = 0
m = 0
input_str = []
out_put = ''
while n < 5:
	n += 1
	input_str = input()
	if '1' in input_str:
		for j in input_str.split():
			m += 1
			if '1' == j:
				out_put = abs(int(m) - 3) + abs(n - 3)
				break
print(out_put)


l = []
center = 3
row_pos = 0
col_pos = 0
ans = 0
for i in range(5):
	a = list(map(int, input().split()))
	l.append(a)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			row_pos = j + 1
			col_pos = i + 1
if row_pos >= center:
	ans += row_pos - center
else:
	ans += center - row_pos
if col_pos >= center:
	ans += col_pos - center
else:
	ans += center - col_pos
print(ans)


for i in range(5):
	line = input().split(' ')
	for j in range(len(line)):
		line[j] = int(line[j])
		if line[j] == 1:
			x = i
			y = j
move = abs(x - 2) + abs(y - 2)
print(move)


def makeMatrixBeautiful(matrix):
	for i in range(len(matrix)):
		if '1' in matrix[i]:
			j = matrix[i].index('1')
			(row, col) = (i, j)
			break
		else:
			continue
	return abs(row - 2) + abs(col - 2)
matrix = [[x for x in input().split()] for i in range(5)]
print(makeMatrixBeautiful(matrix))


mat = [input() for _ in range(5)]
y = [i for i in range(5) if '1' in mat[i]][0]
print(abs(2 - y) + abs(2 - mat[y].split().index('1')))


a = [[0] * 5 for i in range(5)]
(x, y) = (0, 0)
for i in range(5):
	a[i] = input().split()
	for j in range(5):
		if a[i][j] == '1':
			(x, y) = (i, j)
if x > 2:
	x = x - 2
else:
	x = 2 - x
if y > 2:
	y = y - 2
else:
	y = 2 - y
print(x + y)


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
k = 0
j = 0
if a.count('1') == 1:
	k = a.index('1') + 1
	j = 1
elif b.count('1') == 1:
	k = b.index('1') + 1
	j = 2
elif c.count('1') == 1:
	k = c.index('1') + 1
	j = 3
elif d.count('1') == 1:
	k = d.index('1') + 1
	j = 4
elif e.count('1') == 1:
	k = e.index('1') + 1
	j = 5
print(abs(3 - j) + abs(3 - k))


import math
index = (0, 0)
for i in range(1, 6):
	temp_list = list(map(int, input().strip().split()))
	if 1 in temp_list:
		index = (i, temp_list.index(1) + 1)
print(abs(3 - index[0]) + abs(3 - index[1]))


row = int()
matrix = []
col = int()
for x in range(5):
	Find1 = str(input())
	matrix.append(Find1)
for y in matrix:
	col = col + 1
	row = y.find('1')
	if row != -1:
		break
print(abs(col - 3) + abs(int((row + 2) / 2) - 3))


grid = ''
for i in range(5):
	grid += input()
grid = grid.replace(' ', '')
columns_away = abs(2 - grid.index('1') % 5)
rows_away = abs(2 - grid.index('1') // 5)
turns = columns_away + rows_away
print(turns)


matrix = []
tag = {}
for i in range(5):
	line = list(input())
	line = [element for element in line if element != ' ']
	if '1' in line:
		tag['row'] = i
		tag['col'] = line.index('1')
	matrix.append(line)
print(abs(2 - tag['row']) + abs(2 - tag['col']))


y = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
uzaklik = 0
for i in range(5):
	x = input()
	x = x.split()
	y[i][0] = int(x[0])
	y[i][1] = int(x[1])
	y[i][2] = int(x[2])
	y[i][3] = int(x[3])
	y[i][4] = int(x[4])
for i in range(5):
	for i2 in range(5):
		a = y[i][i2]
		if a == 1:
			uzaklik += abs(2 - i)
			uzaklik += abs(2 - i2)
print(uzaklik)


mat = []
for i in range(5):
	t = list(map(int, input().split()))
	mat.append(t)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			(u, v) = (i + 1, j + 1)
count = abs(u - 3) + abs(v - 3)
print(count)


result = 0
for i in range(5):
	a = input().replace(' ', '')
	t = a.find('1')
	if t != -1:
		result = abs(i - 2) + abs(t - 2)
		break
print(result)


for i in range(5):
	a = [int(k) for k in input().split()]
	if a.count(1) == 0:
		continue
	else:
		y = a.index(1)
		x = i + 1
		break
print(abs(x - 3) + abs(y + 1 - 3))


from math import floor
arr = []
for i in range(5):
	line = input().split(' ')
	arr.append(line)
pos = []
count = 0
row = floor(len(arr) / 2)
col = floor(len(arr[0]) / 2)
for i in range(len(arr)):
	for j in range(len(arr[i])):
		if arr[i][j] == '1':
			pos = [i, j]
			break
if pos[1] > col:
	while pos[1] > col:
		pos[1] -= 1
		count += 1
elif pos[1] < col:
	while pos[1] < col:
		pos[1] += 1
		count += 1
if pos[0] > row:
	while pos[0] > row:
		pos[0] -= 1
		count += 1
elif pos[0] < row:
	while pos[0] < row:
		pos[0] += 1
		count += 1
print(count)


arr = []
for _ in range(5):
	arr.append(list(map(int, input().rstrip().split())))
res = 0
for i in range(len(arr)):
	for j in range(len(arr[i])):
		if arr[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
			break


a = []
for _ in range(5):
	a.append(list(map(int, input().split())))
for i in range(len(a)):
	if a[i].count(1) == 0:
		continue
	else:
		c = i + 1
		b = a[i].index(1) + 1
		print(abs(3 - c) + abs(3 - b))


def index_2d(myList, v):
	for (i, x) in enumerate(myList):
		if v in x:
			return (i, x.index(v))
matrix = []
for i in range(5):
	matrix_row = [k for k in input().split()]
	matrix.append(matrix_row)
coord = index_2d(matrix, '1')
print(abs(coord[0] - 2) + abs(coord[1] - 2))


cur = []
ret = 0
for i in range(5):
	cur.append(list(map(int, input().split())))
for (index, i) in enumerate(cur, start=1):
	for (inj, j) in enumerate(i, start=1):
		if j == 1:
			if index == 3:
				ret = abs(inj - 3)
				break
			elif inj == 3:
				ret = abs(index - 3)
				break
			else:
				ret = abs(index - 3) + abs(inj - 3)
				break
	if ret > 0:
		break
print(ret)


matrix = []
n = 5
center_pos = 2
count = 0
for _ in range(n):
	matrix.append(list(map(int, input().split())))
for i in range(n):
	if 1 in matrix[i]:
		count += abs(center_pos - i)
		for (index, j) in enumerate(matrix[i]):
			if j == 1:
				count += abs(center_pos - index)
print(count)


def sele(x1, x2, x3, x4, x5):
	if x1 == 1:
		return 2
	elif x2 == 1:
		return 1
	elif x3 == 1:
		return 0
	elif x4 == 1:
		return 1
	elif x5 == 1:
		return 2
	else:
		return 55
swap = 0
for i in range(5):
	(a1, a2, a3, a4, a5) = (int(x) for x in input().split())
	if sele(a1, a2, a3, a4, a5) != 55:
		swap += abs(i + 1 - 3) + sele(a1, a2, a3, a4, a5)
print(swap)


x = 0
for i in range(5):
	arr = input().split(' ')
	x += 1
	if arr.count('1') > 0:
		A = abs(3 - x) + abs(2 - arr.index('1'))
print(A)


import math
s1 = input()
s2 = input()
s3 = input()
s4 = input()
s5 = input()
res = 0
x = 0
y = 0

def check_col(s, num):
	global x, y
	i = 0
	for n in s:
		if n == ' ':
			continue
		i += 1
		if n == '1':
			x = num
			y = i
			break
check_col(s1, 1)
check_col(s2, 2)
check_col(s3, 3)
check_col(s4, 4)
check_col(s5, 5)
print(int(math.fabs(x - 3) + math.fabs(y - 3)))


counter = 1
for i in range(5):
	a = input().split()
	counter2 = 1
	for i in a:
		if i == '1':
			break
		counter2 += 1
	if i == '1':
		break
	counter += 1
ans1 = 3 - counter
if ans1 < 0:
	ans1 = -1 * ans1
ans2 = 3 - counter2
if ans2 < 0:
	ans2 = -1 * ans2
print(int(ans2 + ans1))


a1 = input().split()
a2 = input().split()
a3 = input().split()
a4 = input().split()
a5 = input().split()
a = [a1, a2, a3, a4, a5]
for i in range(5):
	for t in range(5):
		if a[i][t] == '1':
			print(abs(i - 2) + abs(t - 2))


n = 0
while n < 5:
	string = str(input())
	s = string.split()
	a = s[0] + s[1] + s[2] + s[3] + s[4]
	if int(a) != 0:
		i = n
		n = n + 1
		j = 0
		while int(s[j]) == 0:
			j = j + 1
	else:
		n = n + 1
import math
print(str(int(math.sqrt((j - 2) ** 2) + math.sqrt((i - 2) ** 2))))


check = []
arr = []
for i in range(0, 5):
	take_arr = input().split()
	arr = arr + [take_arr]
	if '1' in arr[i]:
		check = [arr[i].index('1'), i]
print(abs(2 - check[0]) + abs(2 - check[1]))


list1 = list(input().split())
list2 = list(input().split())
list3 = list(input().split())
list4 = list(input().split())
list5 = list(input().split())
filas = 0
columnas = 0
if '1' in list1:
	filas += 2
	if 4 == list1.index('1') or 0 == list1.index('1'):
		columnas += 2
	elif 3 == list1.index('1') or 1 == list1.index('1'):
		columnas += 1
	else:
		pass
if '1' in list5:
	filas += 2
	if 4 == list5.index('1') or 0 == list5.index('1'):
		columnas += 2
	elif 3 == list5.index('1') or 1 == list5.index('1'):
		columnas += 1
	else:
		pass
if '1' in list2:
	filas += 1
	if 3 == list2.index('1') or 1 == list2.index('1'):
		columnas += 1
	elif 4 == list2.index('1') or 0 == list2.index('1'):
		columnas += 2
	else:
		pass
if '1' in list4:
	filas += 1
	if 3 == list4.index('1') or 1 == list4.index('1'):
		columnas += 1
	elif 4 == list4.index('1') or 0 == list4.index('1'):
		columnas += 2
	else:
		pass
if '1' in list3:
	if 3 == list3.index('1') or 1 == list3.index('1'):
		columnas += 1
	elif 4 == list3.index('1') or 0 == list3.index('1'):
		columnas += 2
	else:
		pass
print(filas + columnas)


p = 0
for i in range(5):
	t = input()
	l = list(map(int, t.split(' ')))
	if l.count(1) == 1:
		p = l.index(1)
		c = abs(3 - (i + 1)) + abs(3 - (p + 1))
print(c)


t = 5
l = []
sl = []
for i in range(t):
	sl = list(input().split())
	l.append(sl)
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			x = i
			y = j
x = abs(x - 2)
y = abs(y - 2)
print(x + y)


matrix = []
(row, col) = (None, None)
for i in range(5):
	curr_row = list(map(int, input().split()))
	try:
		col = curr_row.index(1) + 1
		row = i + 1
	except ValueError:
		pass
	if col is not None:
		print(str(abs(3 - row) + abs(3 - col)))
		break


l = []
row = 0
col = 0
for i in range(0, 5):
	N = input()
	N = list(map(int, N.split()))
	l.append(N)
for x in range(0, 5):
	for y in range(0, 5):
		if l[x][y] == 1:
			(row, col) = (x, y)
s = abs(row - 2) + abs(col - 2)
print(s)


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			i1 = i
			j1 = j
print(abs(2 - j1) + abs(2 - i1))


import math
for i in range(0, 5):
	r = input()
	if '1' in r:
		r = r.split(' ')
		for j in range(0, 5):
			r[j] = int(r[j])
		raw = i
		colum = r.index(1)
		continue
	else:
		continue
x = math.fabs(colum - 2)
y = math.fabs(raw - 2)
print(int(x + y))


mat = []
for _ in range(5):
	mat.append(list(map(int, input().split())))
ans = 0
idx = 0
for i in range(5):
	if 1 in mat[i]:
		idx = i
		ans = abs(2 - mat[i].index(1))
		break
ans += abs(2 - i)
print(ans)


matrix = []
for i in range(5):
	matrix.insert(i, input())
for i in range(5):
	for j in range(9):
		if matrix[i][j] == '1':
			locJ = j - j / 2
			locI = i
posJ = abs(locJ - 2)
posI = abs(locI - 2)
totPos = posJ + posI
print(int(totPos), end='')


mtrx = []
for i in range(5):
	lst = list(map(int, input().split(' ')))
	mtrx.append(lst)
stp = 0
for j in range(5):
	if sum(mtrx[j]) == 1:
		stp += abs(2 - j)
		for k in range(5):
			if mtrx[j][k] == 1:
				stp += abs(2 - k)
print(stp)


from math import *
matrix = [[int(i) for i in input().split(' ')] for j in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] != 0:
			row = i + 1
			column = j + 1
print(abs(row - 3) + abs(column - 3))


a = []
for i in range(5):
	n = input().split()
	a.append(n)
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			k = i + 1
			s = j + 1
if abs(k - 3) == 2 and abs(s - 3) == 2:
	print(4)
elif abs(k - 3) == 2 and abs(s - 3) == 1 or (abs(k - 3) == 1 and abs(s - 3) == 2):
	print(3)
elif abs(k - 3) == 2 and abs(s - 3) == 0 or (abs(k - 3) == 0 and abs(s - 3) == 2) or (abs(k - 3) == 1 and abs(s - 3) == 1):
	print(2)
elif k - 3 == 0 and s - 3 == 0:
	print(0)
else:
	print(1)


for i in range(5):
	arr = list(map(int, input().split(' ')))
	for k in range(5):
		if arr[k] == 1:
			print(abs(k - 2) + abs(i - 2))


def find(list):
	for x in range(5):
		if list[x] == '1':
			return int(x)
arr = []
m = 0
n = 0
for i in range(5):
	arr.append(input().split(' '))
	if arr[i].__contains__('1'):
		m = i
		n = find(arr[i])
print(abs(m - 2) + abs(n - 2))


matrix = []
for i in range(5):
	matrixRow = [int(x) for x in input().split(' ')]
	matrix.append(matrixRow)
pos = 0
for row in range(len(matrix)):
	for col in range(len(matrix)):
		if matrix[row][col] == 1:
			pos = abs(row - 2) + abs(col - 2)
			break
print(pos)


li = []
wanted = 0
for i in range(5):
	li.append([int(x) for x in input().split()])
	for (j, val) in enumerate(li[-1]):
		if val == 1:
			wanted = (i, j)
ans = abs(wanted[0] - 2) + abs(wanted[1] - 2)
print(ans)


import math
array = []
i = 0
j = -1
a = input()
b = input()
c = input()
d = input()
e = input()
if '1' in a:
	string = a
elif '1' in b:
	string = b
	i = 1
elif '1' in c:
	string = c
	i = 2
elif '1' in d:
	string = d
	i = 3
elif '1' in e:
	string = e
	i = 4
for k in range(0, len(string)):
	if string[k] == '0':
		j += 1
	elif string[k] == '1':
		j += 1
		break
print(int(math.fabs(2 - j) + math.fabs(2 - i)))


n = 0
L = []
while n < 5:
	lis = input().split(' ')
	lis1 = [int(x) for x in lis]
	if 1 in lis1:
		x = lis1.index(1)
		y = n
	n += 1
print(abs(2 - x) + abs(2 - y))


for y in range(5):
	ar = [int(i) for i in input().split()]
	if ar.count(1) == 1:
		print(abs(y + 1 - 3) + abs(ar.index(1) + 1 - 3))
		break
	else:
		pass


m = [input().split() for _ in range(5)]
(r, c) = (0, 0)
for i in range(5):
	for j in range(5):
		if m[i][j] == '1':
			(r, c) = map(abs, [2 - i, 2 - j])
print(r + c)


for i in range(5):
	a = input()[::2].find('1')
	if a >= 0:
		x = i
		y = a
print(abs(x - 2) + abs(y - 2))


indices = [-1, -1, -1, -1, -1]

def swap(l, i, j):
	temp = l[i]
	l[i] = l[j]
	l[j] = temp
	return l
for i in range(5):
	row = [int(x) for x in input().split(' ')]
	try:
		print(abs(2 - row.index(1)) + abs(2 - i))
		break
	except ValueError:
		continue


for i in range(5):
	m = input().split(' ')
	m = ''.join((i for i in m))
	n = m.find('1')
	if n != -1:
		print(abs(2 - i) + abs(2 - n))


k = 0
for i in range(5):
	l = list(map(int, input().split()))
	for j in range(5):
		if l[j] == 1:
			k1 = j + 1
			k2 = i + 1
if k1 > 3:
	k = k + k1 - 3
else:
	k = k + 3 - k1
if k2 > 3:
	k = k + k2 - 3
else:
	k = k + 3 - k2
print(k)


lines = []
j = 0
i = 0
n = 0
j_new = 0
for x in range(5):
	var = input().split(' ')
	j = 0
	for char in var:
		if char == '1':
			n = i
			j_new = j
			break
		else:
			j += 1
	i += 1
column = abs(n - 2)
row = abs(j_new - 2)
print(column + row)


def main():
	for i in range(5):
		row = input().split()
		if '1' in row:
			j = row.index('1')
			return abs(j - 2) + abs(i - 2)
print(main())


lst = list()
for i in range(5):
	lst.append(input())
for j in range(5):
	if '1' in lst[j]:
		x = lst[j].find('1')
		break
if j == 0 or j == 4:
	if x / 2 == 0 or x / 2 == 4:
		out = 4
	elif x / 2 == 1 or x / 2 == 3:
		out = 3
	else:
		out = 2
elif j == 1 or j == 3:
	if x / 2 == 0 or x / 2 == 4:
		out = 3
	elif x / 2 == 1 or x / 2 == 3:
		out = 2
	else:
		out = 1
elif x / 2 == 0 or x / 2 == 4:
	out = 2
elif x / 2 == 1 or x / 2 == 3:
	out = 1
else:
	out = 0
print(out)


a = []
for i in range(5):
	(a1, a2, a3, a4, a5) = map(int, input().split())
	a.extend(list((a1, a2, a3, a4, a5)))
n = a.index(1) + 1
x = n % 5
if x == 0:
	x = 5
y = -(-n // 5)
if y > 3:
	y = y - 3
else:
	y = 3 - y
if x > 3:
	x = x - 3
else:
	x = 3 - x
print(x + y)


TN = 1

def solution():
	(x, y) = (0, 0)
	for i in range(5):
		l = list(map(int, input().split()))
		if 1 in l:
			x = l.index(1) + 1
			y = i + 1
	print(abs(3 - x) + abs(3 - y))
while TN != 0:
	solution()
	TN -= 1


def abs(a):
	if a < 0:
		return a * -1
	else:
		return a
l = []
for i in range(5):
	l.append(list(map(int, input().split())))
for i in range(len(l)):
	for j in range(len(l)):
		if l[i][j] == 1:
			a = i
			b = j
			break
print(abs(a - 2) + abs(b - 2))


matrix = []
while len(matrix) != 5:
	matrix.append(input().split())
for line in matrix:
	for things in line:
		if things == '1':
			(line_no, idx) = (matrix.index(line), line.index(things))
			print(abs(2 - line_no) + abs(2 - idx))


lst = []
for i in range(5):
	lst.append(input().split())
strnum = 0
colnum = 0
for i in lst:
	for j in i:
		if j != '1':
			continue
		if j == '1':
			colnum = i.index(j)
			strnum = lst.index(i)
print(abs(colnum - 2) + abs(strnum - 2))


from math import *
mat = []
for i in range(5):
	ip = [int(i) for i in input().split()]
	mat.append(ip)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			x = i + 1
			y = j + 1
res = abs(3 - x) + abs(3 - y)
print(res)


r1 = input().split(' ')
r2 = input().split(' ')
r3 = input().split(' ')
r4 = input().split(' ')
r5 = input().split(' ')
if r1.count('1') != 0:
	print(str(2 + abs(r1.index('1') - 3 + 1)))
elif r2.count('1') != 0:
	print(str(1 + abs(r2.index('1') - 3 + 1)))
elif r3.count('1') != 0:
	print(str(0 + abs(r3.index('1') - 3 + 1)))
elif r4.count('1') != 0:
	print(str(1 + abs(r4.index('1') - 3 + 1)))
else:
	print(str(2 + abs(r5.index('1') - 3 + 1)))


import sys
index = 0
indexI = 0
list = []
for i in range(0, 5):
	row = []
	row = input()
	list.append(row)
for i in list:
	myIndex = i.find('1')
	myIndexI = list.index(i)
	if myIndex >= 0:
		index = myIndex
		indexI = myIndexI
		break
if index != 0:
	index = index / 2
sum = abs(index - 2) + abs(indexI - 2)
print(int(sum))


mat = []
for i in range(5):
	arr = list(map(int, input().split()))
	mat.append(arr)
	for y in range(5):
		if mat[i][y] == 1:
			u = i
			j = y
			break
if u == 1 and j == 2 or (u == 2 and j == 1) or (j == 3 and u == 2) or (j == 2 and u == 3):
	moves = 1
else:
	moves = abs(2 - u) + abs(2 - j)
print(moves)


from math import *
string1 = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
i = int(0)
j = int(0)
count_i = int(5)
count_j = int(5)
imp_i = int(0)
imp_j = int(0)
while count_i != 0:
	string1[i] = input().split()
	j = 0
	count_j = 5
	while count_j != 0:
		if string1[i][j] == '1':
			imp_i = i
			imp_j = j
		j += 1
		count_j -= 1
	i += 1
	count_i -= 1
new_i = 2 - imp_i
new_j = 2 - imp_j
print(abs(new_i) + abs(new_j))


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
row = 1
for i in range(5):
	a = get_ints()
	if 1 in a:
		col = a.index(1) + 1
		result = abs(3 - row) + abs(3 - col)
	row += 1
print(result)


x_pos = 0
y_pos = 0
for i in range(5):
	line = input().split()
	for j in range(5):
		if line[j] == '1':
			x_pos = i
			y_pos = j
print(abs(2 - x_pos) + abs(2 - y_pos))


for i in range(5):
	s = input()[::2]
	pos = s.find('1')
	if pos != -1:
		posx = i + 1
		posy = pos + 1
print(abs(3 - posx) + abs(3 - posy))


for i in range(1, 6):
	row = input()
	for e in range(0, 9, 2):
		if row[e] == '1':
			print(abs(e // 2 + 1 - 3) + abs(i - 3))


(k, l) = (0, 0)
for i in range(5):
	j = input().replace(' ', '').find('1')
	if j >= 0:
		print(abs(2 - i) + abs(2 - j))


m = []
R = 0
C = 0
for i in range(0, 5):
	row = list(map(int, input().split(' ')))
	if 1 in row:
		R = i
		for n in range(0, 5):
			if row[n] == 1:
				C = n
				break
	m.append(row)
print(abs(R - 2) + abs(C - 2))


def BeautifulMatrix():
	matrix = [list(map(int, input().split(' '))) for i in range(5)]
	posrow = [i for i in range(5) if 1 in matrix[i]]
	poscol = [j for j in range(5) if matrix[posrow[0]][j] == 1]
	position = (posrow[0], poscol[0])
	mid = (2, 2)
	minMoves = abs(mid[0] - position[0]) + abs(mid[1] - position[1])
	print(minMoves)
	return None

def main():
	BeautifulMatrix()
main()


l = []
for i in range(1, 6):
	x = list(map(int, input().split()))
	l.append(x)
for i in range(5):
	if 1 in l[i]:
		r = i + 1
		c = l[i].index(1) + 1
print(abs(3 - r) + abs(3 - c))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
if a.count('1') == 1:
	print(abs(a.index('1') - 2) + 2)
if b.count('1') == 1:
	print(abs(b.index('1') - 2) + 1)
if c.count('1') == 1:
	print(abs(c.index('1') - 2) + 0)
if d.count('1') == 1:
	print(abs(d.index('1') - 2) + 1)
if e.count('1') == 1:
	print(abs(e.index('1') - 2) + 2)


n = 5
g = []
l = []
k = 1
for i in range(n):
	l += [list(map(int, input().split()))]
for i in range(n):
	for j in range(n):
		if l[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
			k = 1


for i in range(1, 6):
	try:
		index = input().index('1') // 2 + 1
		break
	except:
		pass
print(abs(i - 3) + abs(index - 3))


matrix = []
rowOne = 0
colOne = 0
for i in range(5):
	row = input().split(' ')
	if '1' in row:
		colOne = row.index('1')
		rowOne = int(i)
	matrix.append(row)
print(abs(2 - int(rowOne)) + abs(2 - int(colOne)))


r = 0
c = 0
s = input()
while not '1' in s:
	r += 1
	s = input()
c = s.split(' ').index('1')
print(abs(2 - r) + abs(2 - c))


(rows, cols) = (5, 5)
arr = [[0 for i in range(cols)] for j in range(rows)]
(r, c) = (0, 0)
for i in range(5):
	arr[i] = list(map(int, input().split()))
	if 1 in arr[i]:
		r = i + 1
		c = arr[i].index(1) + 1
print(abs(r - 3) + abs(c - 3))


def input_matrix():
	row_no = 0
	while True:
		line = input()
		if line:
			row_ = line.split(' ')
			for i in range(len(row_)):
				if int(row_[i]) == 1:
					col_no = i
					return abs(col_no - 2) + abs(row_no - 2)
			row_no += 1
		else:
			break
	return 'no 1 found'
print(input_matrix())


matrix = [[int(i) for i in input().split()] for _ in range(5)]
for (idx, row) in enumerate(matrix):
	try:
		print(abs(idx - 2) + abs(row.index(1) - 2))
	except ValueError:
		pass


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
r = 0
col = 0
if '1' in a:
	r = 1
	col = a.index('1') + 1
if '1' in b:
	r = 2
	col = b.index('1') + 1
if '1' in c:
	r = 3
	col = c.index('1') + 1
if '1' in d:
	r = 4
	col = d.index('1') + 1
if '1' in e:
	r = 5
	col = e.index('1') + 1
fin = 0
if r == 3 and col == 3:
	print(0)
else:
	fin = abs(3 - r) + abs(3 - col)
	print(fin)


row1 = input().split()
row2 = input().split()
row3 = input().split()
row4 = input().split()
row5 = input().split()
x = 0
y = 0
for i in range(5):
	try:
		if i == 0:
			y = row1.index('1') + 1
			x = 1
			break
		elif i == 1:
			y = row2.index('1') + 1
			x = 2
			break
		elif i == 2:
			y = row3.index('1') + 1
			x = 3
			break
		elif i == 3:
			y = row4.index('1') + 1
			x = 4
			break
		elif i == 4:
			y = row5.index('1') + 1
			x = 5
			break
	except ValueError as e:
		pass
xdiff = abs(3 - x)
ydiff = abs(3 - y)
moves = xdiff + ydiff
print(moves)


for i in range(5):
	a = input()
	if '1' in a:
		m = i + 1
		n = a.find('1') / 2 + 1
print(int(abs(m - 3) + abs(n - 3)))


lst = []
c = -1
x = -1
for i in range(5):
	l = list(map(int, input().split()))
	lst.append(l)
	if 1 in l:
		c = i
		x = l.index(1)
print(abs(c - 2) + abs(x - 2))


mat = []
l = 1
for i in range(5):
	k = list(map(int, input().split()))
	mat.append(k)
for b in range(5):
	for j in range(5):
		if mat[b][j] == 1:
			m = b
			n = j
			l = 0
			break
	if l == 0:
		break
if m == 2 and n == 2:
	print(0)
elif m < 2 and n < 2:
	print(2 - m + 2 - n)
elif m < 2 and n > 2:
	print(2 - m + n - 2)
elif m > 2 and n < 2:
	print(m - 2 + 2 - n)
elif m > 2 and n > 2:
	print(m - 2 + n - 2)
elif m == 2 and n < 2:
	print(2 - n)
elif m == 2 and n > 2:
	print(n - 2)
elif m < 2 and n == 2:
	print(2 - m)
elif m > 2 and n == 2:
	print(m - 2)


N = 5
M = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
	for j in range(N):
		if M[i][j] == 1:
			a = (i + 1, j + 1)
print(abs(a[0] - 3) + abs(a[1] - 3))


flag = 0
for i in range(5):
	n = input().split()
	for j in range(5):
		if n[j] == '1':
			if j == 1 or j == 3:
				flag += 1
			elif j == 0 or j == 4:
				flag += 2
			if i == 0 or i == 4:
				flag += 2
			elif i == 1 or i == 3:
				flag += 1
print(flag)


import sys
args = sys.stdin.read().splitlines()
(x, y) = (None, None)
for (i, arg) in enumerate(args):
	row = [int(x) for x in arg.split(' ')]
	for (j, val) in enumerate(row):
		if val == 1:
			(x, y) = (i, j)
steps = abs(2 - x) + abs(2 - y)
print(steps)


import math
row = 0
col = 0
for i in range(5):
	s = input()
	ind = s.find('1')
	if ind != -1:
		row = i
		col = ind - ind // 2
print(abs(row - 2) + abs(col - 2))


for i in range(5):
	n = list(map(int, input().split(' ')))
	if 1 in n:
		L = n.index(1) + 1
		K = abs(3 - L)
		J = K + abs(2 - i)
print(J)


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
if c.count(1) == 1:
	print(abs(c.index(1) - 2))
elif d.count(1) == 1:
	print(abs(d.index(1) - 2) + 1)
elif b.count(1) == 1:
	print(abs(b.index(1) - 2) + 1)
elif a.count(1) == 1:
	print(abs(a.index(1) - 2) + 2)
elif p.count(1) == 1:
	print(abs(p.index(1) - 2) + 2)


n1 = input()
n2 = input()
n3 = input()
n4 = input()
n5 = input()
n1 = [int(x) for x in n1.split()]
n2 = [int(x) for x in n2.split()]
n3 = [int(x) for x in n3.split()]
n4 = [int(x) for x in n4.split()]
n5 = [int(x) for x in n5.split()]
r = 0
if 1 in n1:
	r += 2
	r = r + int(((n1.index(1) + 1 - 3) ** 2) ** 0.5)
elif 1 in n2:
	r += 1
	r = r + int(((n2.index(1) + 1 - 3) ** 2) ** 0.5)
elif 1 in n3:
	r = r + int(((n3.index(1) + 1 - 3) ** 2) ** 0.5)
elif 1 in n4:
	r += 1
	r = r + int(((n4.index(1) + 1 - 3) ** 2) ** 0.5)
elif 1 in n5:
	r += 2
	r = r + int(((n5.index(1) + 1 - 3) ** 2) ** 0.5)
print(r)


x = 10
a = input().split()
b = input().split()
c = input().split()
d = input().split()
f = input().split()
if '1' in a:
	if a[0] == '1' or a[-1] == '1':
		x = 4
	elif a[1] == '1' or a[-2] == '1':
		x = 3
	else:
		x = 2
if '1' in b:
	if b[0] == '1' or b[-1] == '1':
		x = 3
	elif b[1] == '1' or b[-2] == '1':
		x = 2
	else:
		x = 1
if '1' in c:
	if c[0] == '1' or c[-1] == '1':
		x = 2
	elif c[1] == '1' or c[-2] == '1':
		x = 1
	else:
		x = 0
if '1' in d:
	if d[0] == '1' or d[-1] == '1':
		x = 3
	elif d[1] == '1' or d[-2] == '1':
		x = 2
	else:
		x = 1
if '1' in f:
	if f[0] == '1' or f[-1] == '1':
		x = 4
	elif f[1] == '1' or f[-2] == '1':
		x = 3
	else:
		x = 2
print(x)


def index2d(m, v):
	for (i, j) in enumerate(m):
		if v in j:
			return (i, j.index(v))
m = [[int(j) for j in input().split()] for i in range(5)]
index = index2d(m, 1)
print(abs(index[0] - 2) + abs(index[1] - 2))


import math
A = input()
A = A.split()
B = input()
B = B.split()
C = input()
C = C.split()
D = input()
D = D.split()
E = input()
E = E.split()
Mov = 0
for k in range(5):
	if int(A[k]) == 1:
		Mov = 2 + abs(3 - (k + 1))
	if int(B[k]) == 1:
		Mov = 1 + abs(3 - (k + 1))
	if int(C[k]) == 1:
		Mov = abs(3 - (k + 1))
	if int(D[k]) == 1:
		Mov = 1 + abs(3 - (k + 1))
	if int(E[k]) == 1:
		Mov = 2 + abs(3 - (k + 1))
print(Mov)


dl = list(range(5))
l = list(range(5))
k = z = 0
for i in range(5):
	str = input()
	k = 0
	dl = str.split()
	for a in dl:
		dl[k] = int(a)
		k += 1
	l[z] = dl
	z += 1
z = 0
for i in l:
	if (1 in i) == True:
		ind = i.index(1)
		break
	else:
		z += 1
mov = abs(2 - z) + abs(2 - ind)
print(mov)


import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda : list(map(int, input().split()))

def main():
	n = 5
	arr = []
	for _ in range(n):
		arr.append(ARR())
	for i in range(n):
		for j in range(n):
			if arr[i][j]:
				print(abs(i - 2) + abs(j - 2))
				return
main()


for i in range(1, 6):
	a = list(input().split())
	if '1' in a:
		break
print(abs(a.index('1') + 1 - 3) + abs(i - 3))


import sys

def beauty(matrix):
	(i, j) = (0, 0)
	for (idxi, row) in enumerate(matrix):
		for (idxj, val) in enumerate(row):
			if val == 1:
				i = idxi + 1
				j = idxj + 1
				break
		if i > 0:
			break
	return abs(3 - i) + abs(3 - j)
for line in sys.stdin:
	matrix = []
	row = [int(val) for val in line.split()]
	matrix.append(row)
	for i in range(4):
		line2 = sys.stdin.readline()
		row = [int(val) for val in line2.split()]
		matrix.append(row)
	answer = beauty(matrix)
	print(answer)


import sys
n = sys.stdin.readline()
while n:
	if '1' in n:
		movements = abs(2) + abs(n.split().index('1') - 2)
	for i in range(4):
		n = sys.stdin.readline()
		if '1' in n:
			movements = abs(i - 1) + abs(n.split().index('1') - 2)
	print(movements)
	n = sys.stdin.readline()


l = []
l.append(input().split())
l.append(input().split())
l.append(input().split())
l.append(input().split())
l.append(input().split())
if l[2][2] == '1':
	print(0)
if l[0][0] == '1':
	print(4)
i = 2
if l[i][1] == '1' or l[i][3] == '1':
	print(1)
if l[i][0] == '1' or l[i][4] == '1':
	print(2)
a = 3
if l[a][1] == '1' or l[a][3] == '1':
	print(2)
if l[a][0] == '1' or l[a][4] == '1':
	print(3)
if l[a][2] == '1':
	print(1)
b = 4
if l[b][2] == '1':
	print(2)
if l[b][1] == '1' or l[b][3] == '1':
	print(3)
if l[b][0] == '1' or l[b][4] == '1':
	print(4)
d = 0
if l[d][1] == '1' or l[d][3] == '1':
	print(3)
if l[d][2] == '1':
	print(2)
if l[d][4] == '1':
	print(4)
e = 1
if l[e][0] == '1' or l[e][4] == '1':
	print(3)
if l[e][1] == '1' or l[e][3] == '1':
	print(2)
if l[e][2] == '1':
	print(1)


i = 0
j = 0
for line_num in range(1, 6):
	line = input()
	if j > 0 or i > 0:
		continue
	idx = line.find('1')
	if idx != -1:
		j = int(idx / 2) + 1
		i = line_num
print(abs(3 - i) + abs(3 - j))


x = inx = int(5)
a = int(0)
b = int(0)
for i in range(x):
	z = input()
	for j in range(len(z)):
		if z[j] == '1':
			a = i
			b = int(j / 2)
print(abs(2 - a) + abs(2 - b))


matrix = []
i = 0
while i < 5:
	line = input()
	values = line.split()
	row = [int(value) for value in values]
	matrix.append(row)
	i = i + 1
for i in range(0, 5):
	for j in range(0, 5):
		a = matrix[i][j]
		if a == 1:
			c = abs(2 - i) + abs(2 - j)
			print(c)


mat = []

def proA(mat):
	for i in range(len(mat)):
		for j in range(len(mat[0])):
			if mat[i][j] == 1:
				return (i, j)
for i in range(5):
	arr = list(map(int, input().split()))
	mat.append(arr)
(i, j) = proA(mat)
print(abs(2 - i) + abs(2 - j))


(x, y) = (0, 0)
for i in range(5):
	b = input('').split()
	for j in range(5):
		if b[j] == '1':
			x = i + 1
			y = j + 1
x = x - 3
y = y - 3
if x < 0:
	x = -x
if y < 0:
	y = -y
print(x + y)


import math
matrix = []
o = 0
b = 0
for i in range(5):
	row = list(map(int, input().split()))
	matrix.append(row)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			o = i + 1
			b = j + 1
print(int(math.sqrt(pow(3 - o, 2)) + math.sqrt(pow(b - 3, 2))))


arr = []
for i in range(5):
	arr.append([int(j) for j in input().split()])
(x, y) = (0, 0)
for (i, lst) in enumerate(arr):
	for (j, ele) in enumerate(lst):
		if ele == 1:
			(x, y) = (i, j)
if x == 2 and y == 2:
	print('0')
else:
	print(abs(x - 2) + abs(y - 2))


matrix = []
m = 0
for i in range(5):
	n = 0
	m += 1
	a = input().split()
	for entity in a:
		n += 1
		if int(a[n - 1]) == 1:
			c = m
			b = n
	matrix.append(a)
count = abs(3 - c)
count += abs(3 - b)
print(count)


arr = []
for i in range(5):
	a = [int(x) for x in input().split()]
	arr.append(a)
	if 1 in a:
		y = i
		x = a.index(1)
x_diff = abs(x - 2)
y_diff = abs(y - 2)
print(x_diff + y_diff)


a = []
for i in range(5):
	arr = list(map(int, input().split()))
	a.append(arr)
ax = 1
ay = 1
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			ax += i
			ay += j
			break
ans = abs(ax - 3) + abs(ay - 3)
print(ans)


x = input().split()
y = input().split()
z = input().split()
a = input().split()
b = input().split()
note = list()
X = 0
Y = 1
Z = 2
A = 3
B = 4
for i in range(5):
	if x[i] == '1':
		column = i
		row = X
	elif y[i] == '1':
		column = i
		row = Y
	elif z[i] == '1':
		column = i
		row = Z
	elif a[i] == '1':
		column = i
		row = A
	elif b[i] == '1':
		column = i
		row = B
t = abs(2 - row)
s = abs(2 - column)
d = t + s
print(d)


a = [[int(x) for x in input().split()] for y in range(0, 5, 1)]
for i in range(0, 5, 1):
	for j in range(0, 5, 1):
		if a[i][j] == 1:
			k = i
			l = j
			break
m = abs(2 - k) + abs(2 - l)
print(m)


matrix = {}
moves = 0
for x in range(1, 6):
	matrix[x] = list(map(int, input().split()))
if 1 == matrix[3][2]:
	print(moves)
else:
	for (x, y) in matrix.items():
		if 1 in y:
			moves = abs(3 - (y.index(1) + 1)) + abs(3 - x)
	print(moves)


spisok = []
count = 0
for i in range(5):
	spisok.append(list(map(int, input().split())))
point = []
for i in range(5):
	if spisok[i].count(1) == 1:
		point.append(i + 1)
		point.append(spisok[i].index(1) + 1)
		break
for i in point:
	count += abs(3 - i)
print(count)


arr_matrix = []
number_of_min_swaps = 0
for e in range(5):
	arr_matrix.append([int(x) for x in input().split()])
for j in range(len(arr_matrix)):
	for i in range(len(arr_matrix[j])):
		if arr_matrix[j][i] == 1:
			number_of_min_swaps += abs(2 - i)
			if not j == 2:
				number_of_min_swaps += abs(2 - j)
print(number_of_min_swaps)


i = 0
array = []
while i < 5:
	row = input().split()
	array.append(row)
	i = i + 1
x = [x for x in array if '1' in x][0]
x_dif = abs(2 - array.index(x))
y_dif = abs(2 - x.index('1'))
moves = x_dif + y_dif
print(moves)


matrix = []
for i in range(0, 5):
	l = list(map(int, input().split()))
	matrix.append(l)
ti = 0
tj = 0
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == 1:
			ti = i
			tj = j
print(abs(ti - 2) + abs(tj - 2))


for i in range(1, 6):
	d = [int(_) for _ in input().split()]
	if 1 in d:
		print(abs(3 - (d.index(1) + 1)) + abs(3 - i))


ind = 0
while ind < 5:
	temp = list(map(int, input().split(' ')))
	if 1 in temp:
		(i, j) = [ind, temp.index(1)]
		break
	ind += 1
i = abs(i - 2)
j = abs(j - 2)
print(i + j)


m = [[int(i) for i in input().split()] for j in range(5)]
h = 0
g = 0
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			h = i
			g = j
			break
otv = 0
if h != 2:
	if h > 2:
		n = h - 2
		otv += n
		h = h - n
	elif h < 2:
		n = 2 - h
		otv += n
		h = h + n
if g != 2:
	if g > 2:
		n = g - 2
		otv += n
		g = g - n
	elif g < 2:
		n = 2 - g
		otv += n
		g = g + n
print(otv)


for i in range(5):
	riadok = input().split()
	for j in range(5):
		if riadok[j] == '1':
			print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
			exit()


l = []
for i in range(5):
	l1 = input().split()
	if '1' in l1:
		j = 0
		while j < 5:
			if l1[j] == '1':
				i_ = i
				j_ = j
				break
			j += 1
	l.append(l1)

def mod(i):
	if i >= 0:
		return i
	else:
		return -i
print(mod(j_ - 2) + mod(i_ - 2))


for i in range(5):
	total = 0
	num = input().split()
	for m in range(5):
		total += int(num[m])
	if total == 1:
		for j in range(5):
			if num[j] == '1':
				j1 = j
				break
		i1 = i
print(abs(i1 - 2) + abs(j1 - 2))


import sys

class Scanner:

	def __init__(self):
		self.current_tokens = []

	def remaining_tokens(self):
		return len(self.current_tokens)

	def nextline(self):
		assert self.remaining_tokens() == 0, 'Reading next line with remaining tokens'
		return input()

	def nexttokens(self):
		return self.nextline().split()

	def nexttoken(self):
		if len(self.current_tokens) == 0:
			self.current_tokens = self.nexttokens()
		assert self.remaining_tokens() > 0, 'Not enough tokens to parse.'
		return self.current_tokens.pop(0)

	def nextints(self, n=-1):
		if n == -1:
			return list(map(int, self.nexttokens()))
		else:
			return (self.nextint() for i in range(n))

	def nextint(self):
		return int(self.nexttoken())

def quit():
	sys.exit(0)
stdin = Scanner()
nextint = stdin.nextint
nextints = stdin.nextints
nextline = stdin.nextline
m = []
for i in range(5):
	m.append(nextints())
(ix, iy) = (-1, -1)
for x in range(5):
	for y in range(5):
		if m[x][y] == 1:
			(ix, iy) = (x, y)
			break
	if ix > 0:
		break
print(abs(ix - 2) + abs(iy - 2))


matrix = []
for i in range(5):
	rows = list(map(int, input().split()))
	matrix.append(rows)
row = 0
column = 0
beautifulNumber = 3
for i in range(len(matrix)):
	for j in range(len(matrix)):
		if matrix[i][j] == 1:
			row = i + 1
			column = j + 1
			break
if beautifulNumber > row:
	row = beautifulNumber - row
else:
	row = row - beautifulNumber
if beautifulNumber > column:
	column = beautifulNumber - column
else:
	column = column - beautifulNumber
print(row + column)


for i in range(0, 5):
	arr = list(map(int, input().strip().split()))
	for l in range(0, 5):
		if arr[l] != 0:
			r = i + 1
			c = l + 1
if r >= 3:
	if c >= 3:
		ans = r + c - 6
	elif c < 3:
		ans = r - c
elif r < 3:
	if c >= 3:
		ans = c - r
	elif c < 3:
		ans = 6 - r - c
print(ans)


i = 0
j = 0
a = [0 * 5] * 5
for i in range(5):
	a[i] = input().split()
	for j in range(5):
		if a[i][j] == '1':
			q = abs(i - 2) + abs(j - 2)
			break
print(q)


matrix = []
for i in range(5):
	a = list(map(int, input().split()))
	matrix.append(a)
for k in range(5):
	for l in range(5):
		if matrix[k][l] == 1:
			break
	if matrix[k][l] == 1:
		break
s = k - 2
if s < 0:
	s = -s
t = l - 2
if t < 0:
	t = -t
print(s + t)


a = [0] * 5
for i in range(5):
	a[i] = list(map(int, input().split()))
for i in range(1, 6):
	for j in range(1, 6):
		if a[i - 1][j - 1] == 1:
			m = i
			n = j
			break
ans = abs(m - 3) + abs(n - 3)
print(ans)


(row, col) = (None, None)
for i in range(5):
	s = [int(j) for j in input().strip().replace(' ', '')]
	if 1 in s:
		(row, col) = (i, s.index(1))
print(abs(row - 2) + abs(col - 2))


import math
matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			print(abs(i + 1 - 3) + abs(j + 1 - 3))


k = 0
while True:
	s = input().split()
	k += 1
	if '1' in s:
		break
print(abs(3 - (s.index('1') + 1)) + abs(3 - k))


import math
string = ''
for i in range(5):
	string += input()
	string += ' '
matrix = string.split(' ')
for pos in range(25):
	if matrix[pos] == '1':
		break
i = pos // 5
j = pos - 5 * i
print(int(math.fabs(i - 2) + math.fabs(j - 2)))


for i in range(5):
	s = list(map(str, input().split()))
	if '1' in s:
		x = s.index('1') + 1
		y = i + 1
print(abs(3 - x) + abs(3 - y))


r = 0
for i in range(0, 5):
	x = input().split()
	for b in range(0, 5):
		if int(x[b]) == 1:
			if b < 2:
				r = r + (2 - b)
			if b > 2:
				r = r + (b - 2)
			if i < 2:
				r = r + (2 - i)
			if i > 2:
				r = r + (i - 2)
print(r)


a = []
for i in range(5):
	a.append([int(i) for i in input().split()])
for i in range(5):
	for k in range(5):
		if a[i][k] == 1:
			print(abs(3 - (i + 1)) + abs(3 - (k + 1)))


arr = [[int(s) for s in input().split(' ')] for i in range(5)]
for i in range(len(arr)):
	for j in range(len(arr[i])):
		if arr[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))
			break


def centerOne(mat: list) -> int:
	for i in range(0, len(mat)):
		for j in range(0, len(mat[0])):
			if mat[i][j] == 1:
				return abs(i - len(mat) // 2) + abs(j - len(mat) // 2)
	return -1

def main():
	mat = []
	for _ in range(5):
		subMat = list(map(int, input().strip().split()))
		mat.append(subMat)
	print(centerOne(mat))
main()


from math import fabs
m = []
a = 0
b = 0
rez = 0
for x in range(5):
	p = input().split()
	if '1' in p:
		a = fabs(3 - (p.index('1') + 1))
		b = fabs(3 - (x + 1))
	t = m.append(p)
print(int(a + b))


try:
	m = [input().split(' ') for i in range(5)]
	(v, no, nz, ro, co) = (True, 0, 0, 0, 0)
	for i in m:
		if len(i) == 5:
			if '0' in i or '1' in i:
				if i.count('1') == 1:
					(ro, co) = (m.index(i), i.index('1'))
					no += 1
					nz += 4
				elif i.count('0') == 5:
					nz += 5
				else:
					v = False
					break
		else:
			v = False
			break
	del i
	if no != 1 or nz != 24:
		v = False
	if v == True:
		m = 0
		if ro == co == 2:
			m = 0
		else:
			m += abs(2 - ro)
			m += abs(2 - co)
		print(m)
except:
	pass


i = 0
for _ in range(5):
	i += 1
	a = list(map(int, input().split()))
	if 1 in a:
		break
j = a.index(1)
print(abs(j + 1 - 3) + abs(i - 3))


from sys import stdin, stdout
matrix = []
for i in range(5):
	l = list(map(int, stdin.readline().split()))
	l.append(1)
	matrix.append(l)
result = []
for i in range(5):
	ind = matrix[i].index(1)
	if ind >= 5:
		continue
	elif ind < 5:
		index1 = i
		index2 = ind
		break
stdout.write(str(abs(index1 - 2) + abs(index2 - 2)) + '\n')


i = 0
j = 0
k = 0
while k < 5:
	col = list(map(int, input().split()))
	if 1 in col:
		j = col.index(1)
		i = k
	k += 1
print(abs(3 - (i + 1)) + abs(3 - (j + 1)))


import sys
import math
matrix = sys.stdin.readlines()
j = 0
for row in matrix:
	row = row.split()
	for i in range(5):
		if row[i] == '1':
			print(abs(2 - i) + abs(2 - j))
	j += 1


import sys
row = 0
col = 0
i = 0
for line in map(str.rstrip, sys.stdin):
	nums = map(int, line.split())
	j = 0
	for n in nums:
		if n == 1:
			row = i
			col = j
			break
		j += 1
	i += 1
print(str(abs(row - 2) + abs(col - 2)))


main_lst = []
count = 0
for i in range(5):
	a = input()
	lst = a.split(' ')
	main_lst.append(lst)
for i in range(5):
	for j in range(5):
		if main_lst[i][j] == '1':
			position = str(i) + ' ' + str(j)
			break
(x, y) = position.split(' ')
(x, y) = (int(x), int(y))
distance_x = 2 - x
distance_y = 2 - y
if distance_y < 0:
	distance_y = -distance_y
if distance_x < 0:
	distance_x = -distance_x
print(distance_x + distance_y)


def countSwap(mat):
	for i in range(5):
		for j in range(5):
			if mat[i][j] == 1:
				return abs(2 - i) + abs(2 - j)
mat = []
for _ in range(5):
	temp = list(map(int, input().strip().split()))
	mat.append(temp)
print(countSwap(mat))


t = []
for i in range(5):
	t.append(input().split())
for i in t:
	if '1' in i:
		a = i.index('1') + 1
		b = t.index(i) + 1
print(abs(a - 3) + abs(b - 3))


mat = [0 for i in range(5)]
for i in range(5):
	mat[i] = input('').split()
	mat[i] = [int(mat[i][j]) for j in range(5)]
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			break
	if mat[i][j] == 1:
		break
row = i - 2 if i >= 2 else 2 - i
col = j - 2 if j >= 2 else 2 - j
print(row + col, end='')


def test():
	m = 0
	n = 0
	for i in range(5):
		pos = input().split()
		for j in range(5):
			if pos[j] == '1':
				m = i
				n = j
	print(abs(2 - n) + abs(2 - m))
test()


a = [list(map(int, input().split())) for i in range(5)]
t = 0
p = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			t = i + 1
			p = j + 1
print(abs(3 - t) + abs(3 - p))


for row in range(5):
	str1 = input().replace(' ', '')
	col = str1.find('1')
	if col != -1:
		print(abs(row - 2) + abs(col - 2))
		exit()


a = []
for i in range(5):
	a.append([int(j) for j in input().split()])
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			q = i + 1
			w = j + 1
print(abs(q - 3) + abs(w - 3))


row = 1
col = 1
while True:
	line = input()
	line = line.replace(' ', '')
	if '1' in line:
		col = line.find('1') + 1
		break
	row += 1
	if row == 6:
		break
print(abs(row - 3) + abs(col - 3))


coord = tuple()
for i in range(5):
	entrada = input().split(' ')
	if '1' in entrada:
		coord = (i + 1, entrada.index('1') + 1)
x = abs(3 - coord[0])
y = abs(3 - coord[1])
print(x + y)


matrix = []
for _ in range(5):
	matrix.append(list(input().split(' ')))
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
			break


column_count = 1
row_count = 0
found = False
for index in range(5):
	str_value = str(input())
	row_values = [int(s) for s in str_value.split(' ')]
	column_count = 1
	for value in row_values:
		if value == 1:
			found = True
			break
		column_count += 1
	row_count += 1
	if found:
		break
row_swap_count = 3 - row_count
column_swap_count = 3 - column_count
print(abs(row_swap_count) + abs(column_swap_count))


arra = []
for i in range(0, 5):
	arr = list(map(int, input().split()))
	arra.append(arr)
ans = [(ix + 1, iy + 1) for (ix, row) in enumerate(arra) for (iy, i) in enumerate(row) if i == 1]
print(abs(ans[0][0] - 3) + abs(ans[0][1] - 3))


ar = []
p = 0
q = 0
for i in range(5):
	a = list(map(int, input().split()))
	ar.append(a)
for i in range(5):
	for j in range(5):
		if ar[i][j] == 1:
			p = i
			q = j
			break
	if p != 0:
		break
print(abs(2 - p) + abs(2 - q))


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
A = [l1, l2, l3, l4, l5]
t = 2
count = 0
p = next(((i, a.index(1)) for (i, a) in enumerate(A) if 1 in a), None)
(a, b) = p
while a != t or b != t:
	if a > t and a != t:
		a = a - 1
		count += 1
	elif a < t and a != t:
		a = a + 1
		count += 1
	if b > t and b != t:
		b = b - 1
		count += 1
	elif b < t and b != t:
		b = b + 1
		count += 1
print(count)


for i in range(5):
	x = input()
	x = x.split()
	for j in range(len(x)):
		if x[j] == '1':
			ro = i
			co = j
print(abs(ro - 2) + abs(co - 2))


for i in range(5):
	li = input().split()
	if '1' in li:
		n = abs(i + 1 - 3) + abs(li.index('1') - 2)
print(n)


mat = [input().replace(' ', ''), input().replace(' ', ''), input().replace(' ', ''), input().replace(' ', ''), input().replace(' ', '')]
for x in range(len(mat)):
	if '1' in mat[x]:
		print(abs(2 - x) + abs(2 - mat[x].find('1')))


k = 0
j = 0
for i in range(5):
	s = list(map(int, input().split(' ')))
	for e in range(5):
		if s[e] == 1:
			j = e
			k = i
			break
ans = abs(2 - k) + abs(2 - j)
print(ans)


result = []
b = 0
c = 0
for x in range(5):
	a = list(map(int, input().split()))
	result.append(a)
	if 1 in a:
		b = x
		c = a.index(1)
print(abs(2 - b) + abs(2 - c))


row1 = []
row2 = []
row3 = []
row4 = []
row5 = []
temp = input()
row1 = list(map(int, temp.strip().split()))
temp = input()
row2 = list(map(int, temp.strip().split()))
temp = input()
row3 = list(map(int, temp.strip().split()))
temp = input()
row4 = list(map(int, temp.strip().split()))
temp = input()
row5 = list(map(int, temp.strip().split()))
matrix = [row1, row2, row3, row4, row5]
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i
			col = j
print(abs(row - 2) + abs(col - 2))


index = 0
count = 0
for i in range(5):
	nums = input().split()
	if index == 0:
		count += 1
		for j in range(5):
			if nums[j] == '1':
				index = j + 1
print(abs(index - 3) + abs(count - 3))


mat = []
for i in range(5):
	line = input().split()
	if '1' in line:
		print(abs(i - 2) + abs(line.index('1') - 2))


indices = []
for i in range(5):
	array = list(map(int, input().strip().split()))
	for j in range(len(array)):
		if array[j] == 1:
			indices.append(i)
			indices.append(j)
answer = abs(indices[0] - 2) + abs(indices[1] - 2)
print(answer)


row = 0
while row < 5:
	l = []
	l = input()
	if '1' in l:
		i = row
		j = l.index('1')
	row += 1
num = int(abs(i - 2) + abs(j - 4) / 2)
print(num)


flag = True
x_coordinate = 0
y_coordinate = 0
for i in range(5):
	row = input().split()
	if flag and '1' in row:
		y_coordinate = row.index('1')
		x_coordinate = i
		flag = False
print(abs(x_coordinate - 2) + abs(y_coordinate - 2))


for i in range(1, 6):
	x = input().split()
	if '1' in x:
		for j in range(len(x)):
			if x[j] == '1':
				y = i
				l = j + 1
a = int(y) - 3
b = int(l) - 3
if a < 0:
	a *= -1
if b < 0:
	b *= -1
print(a + b)


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()))
k = [a, b, c, d, e]
p = 0
q = 0
for i in range(5):
	for j in range(5):
		if k[i][j] == 1:
			p = i
			q = j
p = abs(p - 2)
q = abs(q - 2)
print(p + q)


for i in range(1, 6):
	a = input()
	if '1' in a:
		print(abs(3 - i) + abs(a.index('1') // 2 - 2))


(i, j) = (0, 0)
found = False
for p in range(5):
	user = list(map(int, input().split()))
	if found == False:
		if sum(user) != 0:
			i += 1
			j = user.index(1) + 1
			found = True
		else:
			i += 1
	else:
		pass
if i <= 3:
	i = 3 - i
else:
	i -= 3
if j <= 3:
	j = 3 - j
else:
	j -= 3
print(i + j)


print(sum(map(lambda x: abs(x - 2), divmod(' '.join((input() for i in range(5))).index('1') // 2, 5))))


(x, y) = (0, 0)
for i in range(5):
	a = [int(x) for x in input().split()]
	if 1 in a:
		x = a.index(1) + 1
		y = i + 1
print(abs(3 - x) + abs(3 - y))


A = []
for i in range(5):
	A.append([int(i) for i in input().split(' ')])
pos_x = -1
pos_y = -1
for i in range(5):
	for j in range(5):
		if A[i][j] == 1:
			pos_x = i
			pos_y = j
			break
print(abs(pos_x - 2) + abs(pos_y - 2))


x1 = input()
x1 = x1.split()
x2 = input()
x2 = x2.split()
x3 = input()
x3 = x3.split()
x4 = input()
x4 = x4.split()
x5 = input()
x5 = x5.split()
a = None
b = None
for i in [x1, x2, x3, x4, x5]:
	for j in range(5):
		if i[j] == '1':
			a = i
			b = j
			break
if a == x1:
	a = 1
elif a == x2:
	a = 2
elif a == x3:
	a = 3
elif a == x4:
	a = 4
elif a == x5:
	a = 5
b = b + 1
p = abs(3 - a) + abs(3 - b)
print(p)


p = 0
q = 0
flag = 0
b = []
for i in range(5):
	a = list(map(int, input().split()))
	b.append(a)
for i in range(5):
	if flag == 0:
		for j in range(5):
			if b[i][j] == 1:
				p = i + 1
				q = j + 1
				flag = 1
				break
print(abs(p - 3) + abs(q - 3))


(x, y) = (0, 0)
for i in range(5):
	A = list(map(int, input().split()))
	if A.count(1) != 0:
		x = A.index(1) + 1
		y = i + 1
print(abs(x - 3) + abs(y - 3))


def row_finder(mat, n):
	count = 0
	for i in range(n):
		count = sum(mat[i])
		if count == 1:
			break
		pass
	return abs(2 - i)

def column_finder(mat, n):
	count = 0
	for i in range(n):
		count = sum(mat[i])
		if count == 1:
			for j in range(n):
				if mat[i][j] == 1:
					break
				pass
		pass
	return abs(2 - j)
n = 5
mat = []
for i in range(0, n):
	mat.append([int(j) for j in input().split()])
row_steps = row_finder(mat, n)
column_steps = column_finder(mat, n)
out = row_steps + column_steps
print(out)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
r = 0
for _ in range(5):
	a = list(map(int, input().split()))
	r += 1
	if 1 in a:
		c = a.index(1)
		c += 1
		ans = abs(3 - r) + abs(3 - c)
		break
print(ans)


a = input()
b = input()
c = input()
d = input()
e = input()
l = []
x = 0
y = 0
l.append(list(a))
l.append(list(b))
l.append(list(c))
l.append(list(d))
l.append(list(e))
for i in range(0, 5):
	for k in range(0, len(l[i]), 2):
		if l[i][k] == '1':
			x = i + 1
			y = k // 2 + 1
countx = 0
while x != 3:
	if x > 3:
		countx = countx + 1
		x = x - 1
	else:
		countx = countx + 1
		x = x + 1
county = 0
while y != 3:
	if y > 3:
		county = county + 1
		y = y - 1
	else:
		county = county + 1
		y = y + 1
print(countx + county)


import math
row = 0
for i in range(0, 5):
	inp = input().replace(' ', '')
	if '1' in inp:
		row = i
		col = inp.find('1')
		break
ans = math.fabs(2 - row) + math.fabs(2 - col)
print(int(ans))


m = []
for k in range(0, 5):
	C = [int(x) for x in input().split()]
	if 1 in C:
		a = C.index(1) + 1
		b = k + 1
	m.append(C)
suma = abs(a - 3) + abs(b - 3)
print(suma)


l = []
for i in range(5):
	n = input()
	f = n.split()
	for c in f:
		l.append(c)
		if c == '1':
			j = len(l) - 1
m = 0
while j != 12:
	if j < 12:
		if j % 5 >= 0:
			if 12 - j >= 3:
				j += 5
			else:
				j += 1
	elif j % 5 >= 0:
		if j - 17 >= -2:
			j -= 5
		else:
			j -= 1
	m += 1
print(m)


a = input()
b = input()
c = input()
d = input()
e = input()
result = 0
if '1' in a:
	result = result + 2
	n = a.find('1')
	n = int(abs(n - 4) // 2)
	result = result + n
elif '1' in e:
	result = result + 2
	n = e.find('1')
	n = int(abs(n - 4) // 2)
	result = result + n
elif '1' in b:
	result = result + 1
	n = b.find('1')
	n = int(abs(n - 4) // 2)
	result = result + n
elif '1' in d:
	result = result + 1
	n = d.find('1')
	n = int(abs(n - 4) // 2)
	result = result + n
else:
	n = c.find('1')
	n = int(abs(n - 4) // 2)
	result = result + n
print(result)


ls = [2, 1, 0, 1, 2]
for i in range(5):
	s = input()
	if '1' in s:
		print(ls[i] + ls[s.index('1') // 2])


b = []
x = 0
y = 0
for i in range(5):
	b.append(list(map(int, input().split())))
	if b[i].count(0) != 5:
		x = b[i].index(1)
		y = i
		break
print(abs(2 - x) + abs(2 - y))


matrix = []
for i in range(5):
	temp = [int(x) for x in input().split()]
	matrix.append(temp)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


matrix = []
a = 0
b = 0
for i in range(5):
	arr = list(map(int, input().split()))
	matrix.append(arr)
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			a = i + 1
			b = j + 1
	ans = abs(a - 3) + abs(b - 3)
print(ans)


lst = []
for i in range(5):
	(a, b, c, d, e) = [int(x) for x in input().split()]
	lst.append(a)
	lst.append(b)
	lst.append(c)
	lst.append(d)
	lst.append(e)
pos = int(lst.index(1))
mid_range = [2, 7, 12, 17, 22]

def m(pos, mid, s, e):
	for i in range(s, e):
		if lst[i] == 1:
			if pos < mid:
				count = mid - pos
			else:
				count = pos - mid
			if mid < 12:
				loc = int(mid_range.index(12)) - int(mid_range.index(mid))
			else:
				loc = int(mid_range.index(mid)) - int(mid_range.index(12))
			count += loc
			print(count)
if pos < 5:
	m(pos=pos, mid=2, s=0, e=5)
elif pos >= 5 and pos < 10:
	m(pos, 7, 5, 10)
elif pos < 15:
	m(pos, 12, 10, 15)
elif pos < 20:
	m(pos, 17, 15, 20)
elif pos < 25:
	m(pos, 22, 20, 25)
else:
	print('idk')


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
m = 0
n = 0
for x in range(5):
	if int(a[x]) + int(e[x]) > 0:
		m = 2
		n = abs(x - 2)
	elif int(b[x]) + int(d[x]) > 0:
		m = 1
		n = abs(x - 2)
	elif int(c[x]) > 0:
		m = 0
		n = abs(x - 2)
print(m + n)


matrix = []
row = 1
column = 1
exit_now = 0
for i in range(5):
	matrix.append(input().split())
for j in range(5):
	for k in range(5):
		if matrix[j][k] == '1':
			exit_now = 1
			break
		column += 1
	if exit_now == 1:
		break
	column = 1
	row += 1
print(abs(3 - row) + abs(3 - column))


m = []
for i in range(5):
	l = list(map(int, input().split()))
	m.append(l)
cnt = 0
for i in m:
	cnt += 1
	if 1 in i:
		x = i.index(1)
		break
ct = 0
i = cnt - 1
j = x
while i != 2 or j != 2:
	if i < 2:
		i += 1
		ct += 1
	elif i > 2:
		i -= 1
		ct += 1
	elif j < 2:
		j += 1
		ct += 1
	elif j > 2:
		j -= 1
		ct += 1
else:
	print(ct)


res = 0
for i in range(5):
	x = [int(i) for i in input().split(' ')]
	if 1 in x:
		res = abs(3 - (i + 1))
		for (j, c) in enumerate(x):
			if c == 1:
				res += abs(j + 1 - 3)
print(res)


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
a = a + b + c + d + e
f = 1
for i in a:
	if i == '0':
		f += 1
	else:
		break
if f % 5 == 0:
	print(int(abs(f / 5 - 3) + 2))
else:
	print(int(abs(f // 5 - 2) + abs(f % 5 - 3)))


import math
matrix = []
for i in range(5):
	matrix.append(input())
xdif = 0
ydif = 0

def find1():
	global xdif, ydif
	for row in matrix:
		for col in row.split(' '):
			if col == '1':
				xdif = matrix.index(row) + 1
				ydif = row.split(' ').index(col) + 1

def calculateMove():
	return int(math.fabs(xdif - 3) + math.fabs(ydif - 3))
find1()
print(calculateMove())


k = [2, 1, 0, 1, 2]
for i in k:
	data = input().split()
	for j in range(len(data)):
		if data[j] == '1':
			j = k[j]
			print(i + j)


j = 1
for i in range(5):
	(a, b, c, d, e) = (int(x) for x in input().split())
	if a == 1:
		a1 = 1
		rs = abs(j - 3) + abs(a1 - 3)
	elif b == 1:
		a2 = 2
		rs = abs(j - 3) + abs(a2 - 3)
	elif c == 1:
		a3 = 3
		rs = abs(j - 3) + abs(a3 - 3)
	elif d == 1:
		a4 = 4
		rs = abs(j - 3) + abs(a4 - 3)
	elif e == 1:
		a5 = 1
		rs = abs(j - 3) + abs(a5 - 3)
	j += 1
print(rs)


b = []
v = 0
for i in range(5):
	b.append([])
	b[i] = [int(s) for s in input().split()]
for c in range(5):
	if b[c].count(1) == 1:
		s = b[c].index(1)
		v = abs(2 - c) + abs(2 - s)
		print(v)
		break


c = 0
d = 0
for i in range(1, 6):
	k = list(map(int, input().split()))
	if 1 in k:
		c = k.index(1) + 1
		d = i
print(abs(3 - c) + abs(3 - d))


matrix = []
for i in range(0, 5):
	a = list(map(int, input().split(' ')))
	matrix.extend(a)
matrix = [matrix[i:i + 5] for i in range(0, len(matrix), 5)]
for x in range(0, 5):
	for y in range(0, 5):
		if matrix[x][y] == 1:
			a = x
			b = y
print(abs(a - 2) + abs(b - 2))


from typing import List

def solve(a: List[List[int]]) -> int:
	for i in range(5):
		for j in range(5):
			if a[i][j] == 1:
				return abs(i - 2) + abs(j - 2)
print(solve([list(map(int, input().split())) for i in range(5)]))


def main1(a):
	(x, y) = (0, 0)
	for i in range(len(a)):
		for j in range(len(a[0])):
			if a[i][j] == 1:
				x = i + 1
				y = j + 1
	print(abs(x - 3) + abs(y - 3))
list_of_lists = []
for line in range(5):
	new_list = list(map(int, input().rstrip().split()))
	list_of_lists.append(new_list)
main1(list_of_lists)


matrix = []
for r in range(5):
	matrix.append(input().split())
for row in range(5):
	for col in range(5):
		if matrix[row][col] == '1':
			linha = row
			coluna = col
dist1 = abs(linha - 2)
dist2 = abs(coluna - 2)
total = dist1 + dist2
print(total)


import math
b = [input(), input(), input(), input(), input()]
x = 0
y = 0
for i in range(len(b)):
	if '1' in b[i]:
		y = i + 1
		x = b[i].find('1')
		if x > 0:
			x = x / 2 + 1
		else:
			x += 1

def d(x, y):
	m = math.sqrt((3 - x) ** 2 + (3 - y) ** 2)
	return m
m = 0
run = True
while run:
	if d(x, y) == 0:
		print(m)
		run = False
	else:
		m += 1
		if d(x + 1, y) < d(x - 1, y) and d(x + 1, y) < d(x, y + 1) and (d(x + 1, y) < d(x, y - 1)):
			x += 1
		elif d(x - 1, y) < d(x, y + 1) and d(x - 1, y) < d(x, y - 1):
			x -= 1
		elif d(x, y + 1) < d(x, y - 1):
			y += 1
		else:
			y -= 1


jd = -1
id = 0
while jd == -1:
	s = input()
	s = s.replace(' ', '')
	if '1' in s:
		jd = s.index('1')
	id += 1
print(abs(jd - 2) + abs(id - 3))


a = []
s = 0
for i in range(5):
	n = list(map(int, input().split()))
	a.append(n)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			break
		else:
			s = s + 1
	if a[i][j] == 1:
		break
if s == 7 or s == 11 or s == 13 or (s == 17):
	print(1)
elif s == 12:
	print(0)
elif s == 0 or s == 4 or s == 20 or (s == 24):
	print(4)
elif s % 2 == 0:
	print(2)
else:
	print(3)


import math
arr = []
for i in range(5):
	l = list(map(int, input().split()))
	arr.append(l)
x = 0
y = 0
for i in range(len(arr)):
	for j in range(len(arr[i])):
		if arr[i][j] == 1:
			x = i
			y = j
print(abs(x - 2) + abs(y - 2))


import sys
import collections
import math
import functools
import itertools
import bisect
import operator
import heapq
import random
true = True
false = False
null = None
tcid = 0

def ceil(a, b):
	ans = a // b
	if a % b != 0:
		ans += 1
	return ans

def perr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def line():
	ln = sys.stdin.readline().strip()
	if ln == '':
		sys.exit()
	return ln

def lines(n):
	return [line() for i in range(n)]

def split(ln=None):
	return (ln or line()).split()

def parse(*parsers):
	return list(map(lambda p, w: p(w), parsers, split()))

def nums(o=None):
	if o is not None:
		if isinstance(o, int):
			o = lines(o)
		elif isinstance(o, str):
			o = split(o)
	return list(map(int, o or split()))

def num():
	return int(line())

def solve(tcid=1):

	def find():
		a = [nums() for zz in range(5)]
		for rr in range(5):
			for cc in range(5):
				if a[rr][cc] == 1:
					return abs(rr - 2) + abs(cc - 2)
	print(find())
while true:
	tcid += 1
	solve(tcid)


for i in range(1, 6):
	s = input().split(' ')
	for j in range(0, 5):
		if 1 == int(s[j]):
			k = i
			l = j + 1
print(abs(3 - k) + abs(3 - l))


for i in range(5):
	values = [int(e) for e in input().split()]
	if 1 in values:
		xcol = values.index(1)
		xrow = i
moves = abs(2 - xcol) + abs(2 - xrow)
print(moves)


import sys
lines = sys.stdin.readlines()

def mid(x):
	moves = abs(x[0] - 2) + abs(x[1] - 2)
	print(moves)
l1 = []
x = ()
count = 0
for line in lines:
	if '1' in line:
		x = (count, line.split().index('1'))
	l1.append(line.split())
	count += 1
mid(x)


l = []
x = 0
y = 0
for i in range(5):
	t = list(map(int, input().split()))
	for j in range(len(t)):
		if t[j] == 1:
			x = i
			y = j
	l.append(x)
ans = abs(2 - x) + abs(2 - y)
print(ans)


grid = []
for x in range(5):
	grid.append(input().split())
for i in range(5):
	for j in range(5):
		if grid[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))


for rindex in range(5):
	r = input().split(' ')
	for (cindex, value) in enumerate(r):
		if value == '1':
			rone = rindex + 1
			cone = cindex + 1
			break
n_moves = abs(rone - 3) + abs(cone - 3)
print(n_moves)


a = []
kolvo = 0
row = 0
collumn = 0
for i in range(5):
	k = input().split()
	for i in range(len(k)):
		k[i] = int(k[i])
	a.append(k)
for i in range(5):
	for k in range(5):
		if a[i][k] == 1:
			break
		elif a[i][k] == 0:
			continue
	if a[i][k] == 1:
		row = i
		collumn = k
		break
	else:
		continue
while row != 2:
	if row < 2:
		row += 1
		kolvo += 1
	elif row > 2:
		row -= 1
		kolvo += 1
while collumn != 2:
	if collumn < 2:
		collumn += 1
		kolvo += 1
	elif collumn > 2:
		collumn -= 1
		kolvo += 1
print(kolvo)


l = []
(x, y) = (0, 0)
for u in range(5):
	l.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			x = i
			y = j
			break
s = abs(x - 2) + abs(y - 2)
print(s)


c = 0
r = 0
for i in range(5):
	x = input().replace(' ', '')
	if x.count('1') > 0:
		c = i + 1
		r = x.index('1') + 1
print(abs(c - 3) + abs(r - 3))


line1 = input()
line2 = input()
line3 = input()
line4 = input()
line5 = input()
row1 = line1.split(' ')
row2 = line2.split(' ')
row3 = line3.split(' ')
row4 = line4.split(' ')
row5 = line5.split(' ')
n = len(row1)
steps = 0
if '1' in row1 or '1' in row5:
	steps = 2
	for i in range(0, n):
		if row1[i] == '1' or row5[i] == '1':
			additional_steps = abs(i - 2)
			steps = steps + additional_steps
elif '1' in row2 or '1' in row4:
	steps = 1
	for i in range(0, n):
		if row2[i] == '1' or row4[i] == '1':
			additional_steps = abs(i - 2)
			steps = steps + additional_steps
else:
	steps = 0
	for i in range(0, n):
		if row3[i] == '1':
			additional_steps = abs(i - 2)
			steps = steps + additional_steps
print(steps)


for i in range(5):
	s = input()
	if '1' in s:
		counter = 0
		for j in s:
			if j == ' ':
				continue
			if j == '1':
				break
			counter += 1
		print(abs(2 - i) + abs(counter - 2))


s = []
for i in range(5):
	line = [int(i) for i in input().split()]
	s.append(line)
for i in range(5):
	for k in range(5):
		if s[i][k] == 1:
			out = abs(i - 2) + abs(k - 2)
print(out)


m = [[int(j) for j in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			p = i
			q = j
			break
a = abs(2 - p)
b = abs(2 - q)
print(a + b)


data = [0] * 5
for i in range(5):
	masukan = input().split()
	for j in range(len(masukan)):
		if masukan[j] == '1':
			if j >= 3:
				var = j - 1
			else:
				var = j - 3
				if var < 0:
					var = -var
			data[i] = var
			break
for j in range(len(data)):
	if data[j] != 0:
		if j >= 3:
			hasil = j - 2 + data[j] - 1
		else:
			hasil = (j - 2) * -1 + data[j] - 1
		break
print(hasil)


for i in range(1, 6):
	line = [int(j) for j in str(input()).split()]
	if 1 in line:
		column = line.index(1) + 1
		row = i
print(abs(column - 3) + abs(row - 3))


(x, y) = (0, 0)
for m in range(5):
	data = input().replace(' ', '')
	if '1' in data:
		(x, y) = (data.index('1'), m)
	data = ''
print(abs(x - 2) + abs(y - 2))


a = []
cnt = 0
for i in range(5):
	b = list(map(int, input().split()))
	if 1 in b:
		ind = b.index(1) + 1
		cnt += abs(ind - 3)
		cnt += abs(i + 1 - 3)
		print(cnt)
		break


for i in range(5):
	a = input().split()
	for j in range(5):
		if int(a[j]) != 0:
			print(str(abs(i - 2) + abs(j - 2)))


s = None
x = 0
y = 0
for i in range(1, 6):
	s = input()
	s = s.split()
	if '1' in s:
		x += i
		for j in range(0, 5):
			if s[j] == '1':
				y += j + 1
if 5 - x >= 3:
	if 5 - y >= 3:
		print(3 - y + (3 - x))
	elif 5 - y < 2:
		print(y - 3 + (3 - x))
	else:
		print(3 - x)
elif 5 - x == 2:
	if 5 - y >= 3:
		print(3 - y)
	elif 5 - y < 2:
		print(y - 3)
	else:
		print(0)
elif 5 - y >= 3:
	print(3 - y + x - 3)
elif 5 - y < 2:
	print(y - 3 + x - 3)
else:
	print(x - 3)


matrix = []
x = 0
y = 0
for i in range(5):
	row = list(map(int, input().split()))
	for j in range(5):
		if row[j] == 1:
			x = j
			y = i
steps = abs(2 - x) + abs(2 - y)
print(steps)


from math import fabs
x_counter = 0
y_counter = 0
for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	if a == 1:
		x_counter = 1
		y_counter = i + 1
	if b == 1:
		x_counter = 2
		y_counter = i + 1
	if c == 1:
		x_counter = 3
		y_counter = i + 1
	if d == 1:
		x_counter = 4
		y_counter = i + 1
	if e == 1:
		x_counter = 5
		y_counter = i + 1
print(int(fabs(3 - x_counter) + fabs(3 - y_counter)))


a = ''
for i in range(5):
	b = input()
	a += b + '\n'
a = [i for i in a.split('\n') if len(i) > 1]
for i in range(len(a)):
	if '1' in a[i]:
		y = i
ligne = a[y]
x = int(ligne.find('1') / 2)
xx = abs(x - 2)
yy = abs(y - 2)
print(xx + yy)


n = 5
s = []
for i in range(n):
	row = input().split()
	for i in range(len(row)):
		row[i] = int(row[i])
	s.append(row)
x = 0
y = 0
count = 0
for raw in s:
	for i in raw:
		if i == 1:
			x = s.index(raw) + 1
			y = raw.index(i) + 1
			break
if x < 3 and x != 0:
	u = 3 - x
	for i in range(u):
		temp = s[x + 2]
		s[x + 2] = s[x]
		s[x] = temp
		count += 1
		x = x + 1
elif x > 3 and x != 0:
	u = x - 3
	for i in range(u):
		temp = s[x - 2]
		s[x - 2] = s[x - 1]
		s[x - 1] = temp
		count += 1
		x = x - 2
if y > 3 and y != 0:
	u = y - 3
	for i in range(u):
		temp = s[x - 1][y - 2]
		s[x - 1][y - 2] = s[x - 1][y - 1]
		s[x - 1][y - 1] = temp
		count += 1
		y = y - 2
elif y < 3 and y != 0:
	u = 3 - y
	for i in range(u):
		temp = s[x - 1][y]
		s[x - 1][y] = s[x][y - 1]
		s[x - 1][y - 1] = temp
		count += 1
		y = y + 1
print(count)


n = 5
x = []
for i in range(n):
	x.append(input().split())
pos = []
for i in range(n):
	if '1' in x[i]:
		pos.append(i)
		pos.append(x[i].index('1'))
		break
print(abs(2 - pos[0]) + abs(2 - pos[1]))


i = t = n = 0
while i < 5:
	(a, b, c, d, e) = map(int, input().split())
	if a == 1:
		t += 2
		n = i
	if b == 1:
		t += 1
		n = i
	if c == 1:
		t += 0
		n = i
	if d == 1:
		t += 1
		n = i
	if e == 1:
		t += 2
		n = i
	i += 1
if n == 0 or n == 4:
	t += 2
elif n == 1 or n == 3:
	t += 1
print(t)


i = 0
a = []
while i < 5:
	x = input()
	a.append([int(i) for i in x.split()])
	i += 1
o = 0
u = 0
for k in a:
	if 1 in k:
		o += a.index(k)
		u += k.index(1)
		break
print(abs(2 - o) + abs(2 - u))


M = []
R = 0
A = '1'
for i in range(5):
	L = []
	L = input().split()
	if A in L:
		R += abs(L.index(A) - 2) + abs(2 - i)
print(R)


x = 3
y = 3
for y in range(1, 6):
	line = input()
	if '1' in line:
		x = line.index('1') // 2 + 1
		break
print(abs(x - 3) + abs(y - 3))


matrix = []
moves = 0
for i in range(5):
	matrix.append([int(x) for x in input().split()])
for i in range(len(matrix)):
	for x in range(len(matrix[i])):
		if matrix[i][x] == 1:
			starting_x = x
			starting_y = i
moves = abs(2 - starting_x) + abs(2 - starting_y)
print(abs(moves))


from sys import stdin
matrix = stdin.read().split('\n')
one_row = 0
one_column = 0
for row in range(0, 5):
	actual_row = matrix[row].replace(' ', '')
	one_column = actual_row.find('1')
	if one_column >= 0:
		one_row = row
		break
print(abs(2 - one_column) + abs(2 - one_row))


matrix = list([input().split(), input().split(), input().split(), input().split(), input().split()])

def pos_counter(matrix):
	row_count = 0
	for row in matrix:
		row_count += 1
		column_count = 0
		for i in row:
			column_count += 1
			if i == '1':
				return (row_count, column_count)
(a, b) = pos_counter(matrix)
print(abs(a - 3) + abs(b - 3))


for sth in range(5):
	j = input().split()
	j = [int(i) for i in j]
	for sb in range(5):
		if j[sb] == 1:
			move = abs(sb + 1 - 3)
	if sum(j) == 1:
		move += abs(sth + 1 - 3)
print(move)


l1 = []
for i in range(5):
	x = list(input().split())
	l1.append(x)
row = 0
col = 0
step = 0
for i in range(5):
	for j in range(5):
		if l1[i][j] == '1':
			row = i
			col = j
			break
if row > 2:
	step += row - 2
else:
	step += 2 - row
if col > 2:
	step += col - 2
else:
	step += 2 - col
print(step)


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()))
matrix = [line1, line2, line3, line4, line5]
currentpos = (0, 0)
for line in matrix:
	for num in line:
		if num == 1:
			currentpos = (matrix.index(line), line.index(num))
print(abs(currentpos[0] - 2) + abs(currentpos[1] - 2))


x = []
for n in range(5):
	x.append(list(input().split()))
for i in range(5):
	for j in range(5):
		if x[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))


arr = []
arr.append(input().split())
for x in range(4):
	arr.append(input().split())
for i in range(5):
	for j in range(5):
		if arr[i][j] == '1':
			rows = abs(2 - i)
			colums = abs(2 - j)
			break
print(rows + colums)


matrix = []
for i in range(5):
	row = list(map(int, input().split()))
	matrix.append(row)
	if 1 in row:
		x_coord = row.index(1)
		y_coord = i
print(abs(x_coord - 2) + abs(y_coord - 2))


inputs = []
for i in range(5):
	inputs.append([x for x in input().split()])
i1 = -1
j1 = -1
for i in range(5):
	found = False
	for j in range(5):
		if inputs[i][j] == '1':
			i1 = i
			j1 = j
			found = True
			break
	if found:
		break
print(abs(i1 - 2) + abs(j1 - 2))


n = 5
r = 0
c = 0
x = [[], [], [], [], []]
for i in range(n):
	x[i] = list(map(int, input().split()))
	if 1 in x[i]:
		r = i
for k in range(n):
	if x[r][k] == 1:
		c = k
r += 1
c += 1
r = r - 3
c = c - 3
if r < 0:
	r *= -1
if c < 0:
	c *= -1
print(r + c)


arr = []
for i in range(5):
	s = list(map(int, input().split()))
	for j in range(len(s)):
		if s[j] == 1:
			(a, b) = (i, j)
print(abs(a - 2) + abs(b - 2))


arr = []
for i in range(5):
	row = list(map(int, input().split()))
	arr.append(row)
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			index_i = i
			index_j = j
store = abs(index_j - 2) + abs(index_i - 2)
print(store)


k = 0
index = 0
for i in range(5):
	s1 = input()
	s2 = s1.split()
	if '1' in s2:
		index = s2.index('1')
		k = i + 1
if k > 3:
	l = k - 3
else:
	l = 3 - k
if index + 1 > 3:
	j = index - 3 + 1
else:
	j = 3 - index - 1
print(l + j)


arr = []
one_row = 0
one_column = 0
for i in range(5):
	arr.append(input().split())
	if '1' in arr[i]:
		one_row = i + 1
		one_column = arr[i].index('1') + 1
print(abs(3 - one_column) + abs(3 - one_row))


answer = 0
for i in range(5):
	A = input().split()
	if A.count('1'):
		answer = abs(i - 2) + abs(A.index('1') - 2)
print(answer)


num = []
for row in range(5):
	num.append(list(map(int, input().split())))
index_x = 0
index_y = 0
for i in range(5):
	for j in range(5):
		if num[i][j]:
			index_x = i
			index_y = j
count = 0
while index_x != 2:
	if index_x > 2:
		index_x -= 1
		count += 1
	else:
		index_x += 1
		count += 1
while index_y != 2:
	if index_y > 2:
		index_y -= 1
		count += 1
	else:
		index_y += 1
		count += 1
print(count)


def main():
	n = 5
	matrix = []
	for i in range(n):
		matrix.append([int(x) for x in input().split(' ')])
	flag = False
	for i in range(n):
		for j in range(n):
			if matrix[i][j] == 1:
				print(abs(i - 2) + abs(j - 2))
				flag = True
				break
		if flag:
			break
	return 0
main()


g = []
total = 0
for i in range(0, 5):
	g.append(list(map(int, input().split())))
	for j in range(0, 5):
		if g[i][j] == 1:
			if i == 2 and j == 2:
				total = 0
			if i < 2:
				total += 2 - i
			if j < 2:
				total += 2 - j
			if i > 2:
				total += i - 2
			if j > 2:
				total += j - 2
print(total)


for x in range(5):
	S = input().split()
	for y in range(5):
		if S[y] == '1':
			ans = abs(x - 2) + abs(y - 2)
print(ans)


arr = []
for i in range(5):
	arr.append(list(map(int, input().split(' '))))
mid = (2, 2)
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			tuple = (i, j)
result = abs(tuple[0] - mid[0]) + abs(tuple[1] - mid[1])
print(result)


a = []
for i in range(5):
	a.append([int(x) for x in input().split()])
row = 0
for i in a:
	row += 1
	if 1 in i:
		r = row - 1
		c = i.index(1)
(mr, mc) = (2, 2)
print(abs(r - mr) + abs(c - mc))


pos = (0, 0)
for i in range(0, 5):
	temp = [int(i) for i in input('').split()]
	if sum(temp) >= 1:
		pos = (i, temp.index(1))
		break
print(abs(2 - pos[0]) + abs(2 - pos[1]))


from sys import stdin

def index_of(lis, e):
	for i in range(len(lis)):
		if e == lis[i]:
			return i
	return -1

def manhattan_dist(c1, c2):
	return abs(c1[0] - c2[0]) + abs(c1[1] - c2[1])
for i in range(5):
	row = stdin.readline().strip().split(' ')
	col_idx = index_of(row, '1')
	if col_idx != -1:
		row_idx = i
		break
beautiful_coord = (2, 2)
print(manhattan_dist((col_idx, row_idx), beautiful_coord))


for i in range(5):
	string = input().split()
	if '1' in string:
		posr = i
		posc = string.index('1')
print(abs(posr - 2) + abs(posc - 2))


arr = []
for i in range(5):
	inp = str(input()).split(' ')
	arr.append(inp)
	if '1' in inp:
		row = i + 1
		col = inp.index('1') + 1
print(abs(3 - row) + abs(3 - col))


for i in range(5):
	arr = input().split()
	if '1' in arr:
		x = arr.index('1') + 1
		y = i + 1
		break
print(abs(3 - int(x)) + abs(3 - int(y)))


li = []
r = 0
col = 0
mov = 0
for i in range(5):
	li.append(list(map(int, input().strip().split())))
	for j in range(5):
		if li[i][j] == 1:
			r = i + 1
			col = j + 1
if r > 3:
	mov += r - 3
elif r < 3:
	mov += 3 - r
if col > 3:
	mov += col - 3
elif col < 3:
	mov += 3 - col
print(mov)


n = 1
matrix = []
while n < 6:
	list = input()
	row = list.split(' ', 4)
	matrix.append(row)
	n += 1
n = 0
encontrado = False
while n < 5 and encontrado == False:
	i = 0
	while i < 5 and encontrado == False:
		if matrix[n][i] == '1':
			encontrado = True
		i += 1
	n += 1
if n < 3:
	movLat = 3 - n
else:
	movLat = n - 3
if i < 3:
	movHor = 3 - i
else:
	movHor = i - 3
print(movHor + movLat)


from sys import stdin, stdout

def main():
	for i in range(5):
		_input = stdin.readline()
		if '1' in _input:
			ans = 0
			pos = _input.index('1') // 2
			while pos != 2:
				ans += 1
				if pos < 2:
					pos += 1
				else:
					pos -= 1
			while i != 2:
				ans += 1
				if i > 2:
					i -= 1
				else:
					i += 1
			stdout.write(repr(ans))
			return None
main()


for i in range(5):
	nl = input().split()
	if '1' in nl:
		pos_i = i
		pos_j = nl.index('1')
print(abs(pos_i - 2) + abs(pos_j - 2))


q = list(map(int, input().split()))
r = list(map(int, input().split()))
s = list(map(int, input().split()))
t = list(map(int, input().split()))
u = list(map(int, input().split()))
for i in range(5):
	if q[i] == 1:
		m = i
		j = 1
	elif r[i] == 1:
		m = i
		j = 2
	elif s[i] == 1:
		m = i
		j = 3
	elif t[i] == 1:
		m = i
		j = 4
	elif u[i] == 1:
		m = i
		j = 5
	else:
		continue
f = abs(m - 2)
s = abs(j - 3)
print(f + s)


def find():
	for row in range(5):
		t = input().split(' ')
		if t.count('1') != 0:
			column = t.index('1')
			return (row + 1, column + 1)

def countSteps():
	rc = find()
	r = rc[0]
	c = rc[1]
	return abs(3 - r) + abs(3 - c)
print(countSteps())


x = []
(m, n) = (0, 0)
for i in range(5):
	s = input().split()
	if '1' in s:
		m = s.index('1')
		n = i
	x.append(s)
j = 2 - m
k = 2 - n
if j < 0:
	j *= -1
if k < 0:
	k *= -1
print(j + k)


a = [[int(s) for s in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
			break
	else:
		continue
	break


(lambda a: print([abs(a.index(x) - 2) + abs(x.index(1) - 2) for x in a if 1 in x][0]))([list(map(int, input().split())) for x in range(5)])


arr = list()
for i in range(5):
	temp = list(input().split())
	arr.append(temp)
for i in range(5):
	for j in range(5):
		if arr[i][j] == '1':
			temp = [i, j]
			break
print(abs(temp[0] - 2) + abs(temp[1] - 2))


m = []
for i in range(5):
	arr = [int(i) for i in input().split()]
	for (j, elem) in enumerate(arr):
		if elem == 1:
			num = abs(i - 2) + abs(j - 2)
print(num)


a = [[i for i in range(5)] for j in range(5)]
for j in range(5):
	s = [k for k in range(5)]
	s = input().split()
	for i in range(5):
		a[j][i] = s[i]
		if s[i] == '1':
			print(max(2, j) - min(2, j) + max(2, i) - min(2, i))


grid = [input().split() for _ in range(5)]
for i in range(5):
	for j in range(5):
		if grid[i][j] == '1':
			loc = (i + 1, j + 1)
			break
print(abs(3 - loc[0]) + abs(3 - loc[1]))


xPos = -1
yPos = -1
for i in range(5):
	ithLine = input().split()
	if '1' in ithLine:
		yPos = i
		for j in range(5):
			if ithLine[j] == '1':
				xPos = j
				break
print(abs(xPos - 2) + abs(yPos - 2))


arry = [[0] * 5] * 5
for i in range(5):
	arry[i] = input().split()
for j in range(5):
	for k in range(5):
		if arry[j][k] == '1':
			a = j + 1
			b = k + 1
minsteps = abs(a - 3) + abs(b - 3)
print(minsteps)


matrix = [list(input().split()) for i in range(5)]
one_location_column_cell = [0, 0]
count = 0
for i in matrix:
	if '1' not in i:
		one_location_column_cell[0] += 1
	else:
		one_location_column_cell[1] += matrix[matrix.index(i)].index('1')
		break
while one_location_column_cell[0] != 2 or one_location_column_cell[1] != 2:
	count += 1
	if one_location_column_cell[0] < 2:
		one_location_column_cell[0] += 1
	elif one_location_column_cell[0] > 2:
		one_location_column_cell[0] -= 1
	elif one_location_column_cell[1] < 2:
		one_location_column_cell[1] += 1
	elif one_location_column_cell[1] > 2:
		one_location_column_cell[1] -= 1
print(count)


arr = list()
for i in range(5):
	ar = list(map(int, input().split()))
	arr.append(ar)
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
			exit()
		else:
			continue


m = [input().split(' '), input().split(' '), input().split(' '), input().split(' '), input().split(' ')]
m = [i for s in m for i in s]
i = m.index('1')
l = i // 5
c = i % 5
print(abs(2 - l) + abs(2 - c))


import math
matrix = []
pos_one = [0, 0]
for i in range(5):
	line = [int(x) for x in input().split()]
	matrix.append(line)
	if 1 in line:
		pos_one = (line.index(1), len(matrix) - 1)
min_step = abs(pos_one[0] - 2) + abs(pos_one[1] - 2)
print(min_step)


a = list(map(int, input().split()))
if 1 in a:
	col = a.index(1)
	r = 0
b = list(map(int, input().split()))
if 1 in b:
	col = b.index(1)
	r = 1
c = list(map(int, input().split()))
if 1 in c:
	col = c.index(1)
	r = 2
d = list(map(int, input().split()))
if 1 in d:
	col = d.index(1)
	r = 3
e = list(map(int, input().split()))
if 1 in e:
	col = e.index(1)
	r = 4
count = abs(2 - r) + abs(2 - col)
print(count)


def find_one(array):
	for i in range(5):
		if array[i] == '1':
			return True
	return False
line = 0
row = 0
line_answer = 0
row_answer = 0
line_1 = input().split()
line_2 = input().split()
line_3 = input().split()
line_4 = input().split()
line_5 = input().split()
array = [line_1, line_2, line_3, line_4, line_5]
for i in range(5):
	if find_one(array[i]):
		line = int(i)
needed_line = array[line]
for i in range(5):
	if needed_line[i] == '1':
		row = int(i)
line += 1
row += 1
if line > 3:
	line_answer = line - 3
else:
	line_answer = 3 - line
if row > 3:
	row_answer = row - 3
else:
	row_answer = 3 - row
print(row_answer + line_answer)


ponto = [0, 0]
matriz = []
for i in range(1, 6):
	linha = list(map(int, input().split()))
	for v in range(1, len(linha) + 1):
		if linha[v - 1] == 1:
			ponto[0] = v
			ponto[1] = i
diff = abs(3 - ponto[0]) + abs(3 - ponto[1])
print(diff)


entrada = []
for k in range(5):
	numeros = list(map(int, input().split()))
	entrada.append(numeros)
for i in entrada:
	for j in i:
		if j == 1:
			indice = (i.index(j), entrada.index(i))
(x, y) = indice
diferenca = 0
diferenca += abs(2 - x)
diferenca += abs(2 - y)
print(diferenca)


(row, column) = (0, 0)
for i in range(5):
	o = input().split()
	if o.count('1') == 1:
		(row, column) = (i + 1, o.index('1') + 1)
print(abs(3 - row) + abs(3 - column))


(r, c) = (0, 0)
s = None
while True:
	s = input()
	if '1' in s:
		break
	r += 1
s = s.split()
for a in s:
	if a == '1':
		break
	c += 1
print(abs(c - 2) + abs(r - 2))


answer = 0
row = 0
col = 0
l = [1, 2]
c = 0
last = 0
for i in range(5):
	a = list(map(int, input().split()))
	c += 1
	if 1 in a:
		row = a.index(1) - len(a) // 2
		last = c
if last == 3:
	col = 0
elif last == 1 or last == 5:
	col = 2
elif last == 2 or last == 4:
	col = 1
answer = abs(row) + abs(col)
print(answer)


i = 0
j = 0
for i in range(5):
	row = input()
	i += 1
	if '1' in row:
		j = row.split().index('1') + 1
		break
moves = abs(3 - i) + abs(3 - j)
print(moves)


count = 0
row = 0
column = 0
for i in range(5):
	r = input()
	x = r.split()
	for j in range(5):
		if int(x[j]) == 1:
			row = i + 1
			column = j + 1
count = abs(row - 3) + abs(column - 3)
print(count)


matrix = [[], [], [], [], []]
for i in range(5):
	user_input = input()
	arr = user_input.split(' ')
	matrix[i] = arr
output = 0
for r in range(5):
	for c in range(5):
		if int(matrix[r][c]) == 1:
			if c > 2:
				output += c - 2
			elif c < 2:
				output += 2 - c
			if r > 2:
				output += r - 2
			elif r < 2:
				output += 2 - r
print(output)


s = []
for i in range(0, 5):
	s.append(input().split())
for (row, lst) in enumerate(s):
	if '1' in lst:
		col = lst.index('1')
		break
fin_row = abs(row - 2)
fin_col = abs(col - 2)
print(fin_col + fin_row)


m = []
for i in range(5):
	nums = [int(i) for i in input().split()]
	if 1 in nums:
		cell = (nums.index(1), i)
	m.append(nums)
spot = (2, 2)
ans = abs(spot[0] - cell[0]) + abs(spot[1] - cell[1])
print(ans)


size = 5
for i in range(size):
	s = input().split()
	for j in range(size):
		if s[j] == '1':
			x = i
			y = j
sum = abs(x - 2) + abs(y - 2)
print(sum)


moves = 0
x = True
row1 = input()
row2 = input()
row3 = input()
row4 = input()
row5 = input()
row1 = list(''.join(row1.split()))
row2 = list(''.join(row2.split()))
row3 = list(''.join(row3.split()))
row4 = list(''.join(row4.split()))
row5 = list(''.join(row5.split()))

def setColumn():
	col1 = list(row1[0] + row2[0] + row3[0] + row4[0] + row5[0])
	col2 = list(row1[1] + row2[1] + row3[1] + row4[1] + row5[1])
	col3 = list(row1[2] + row2[2] + row3[2] + row4[2] + row5[2])
	col4 = list(row1[3] + row2[3] + row3[3] + row4[3] + row5[3])
	col5 = list(row1[4] + row2[4] + row3[4] + row4[4] + row5[4])
	return (col1, col2, col3, col4, col5)
(col1, col2, col3, col4, col5) = setColumn()
while True:
	if '1' in row3 and '1' in col3:
		break
	elif '1' not in row3:
		moves += 1
		if '1' in row1:
			_index = row1.index('1')
			row1[_index] = '0'
			row2[_index] = '1'
		elif '1' in row2:
			_index = row2.index('1')
			row2[_index] = '0'
			row3[_index] = '1'
		elif '1' in row4:
			_index = row4.index('1')
			row4[_index] = '0'
			row3[_index] = '1'
		elif '1' in row5:
			_index = row5.index('1')
			row5[_index] = '0'
			row4[_index] = '1'
	else:
		if x:
			(col1, col2, col3, col4, col5) = setColumn()
			x = False
		moves += 1
		if '1' in col1:
			_index = col1.index('1')
			col1[_index] = '0'
			col2[_index] = '1'
		elif '1' in col2:
			_index = col2.index('1')
			col2[_index] = '0'
			col3[_index] = '1'
		elif '1' in col4:
			_index = col4.index('1')
			col4[_index] = '0'
			col3[_index] = '1'
		elif '1' in col5:
			_index = col5.index('1')
			col5[_index] = '0'
			col4[_index] = '1'
print(moves)


m = []
for i in range(5):
	m.append(list(map(int, input().split())))
d = [(ix + 1, iy + 1) for (ix, row) in enumerate(m) for (iy, i) in enumerate(row) if i == 1]
print(abs(d[0][0] - 3) + abs(d[0][1] - 3))


s = ''
for lines in range(5):
	s += input()
s = s.replace(' ', '')
index = s.find('1') + 1
if index % 5 == 0:
	x = index // 5
	y = 5
else:
	x = index // 5 + 1
	y = index % 5
print(int(abs(x - 3) + abs(y - 3)))


for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			ii = i
			jj = j
print(abs(ii - 2) + abs(jj - 2))


position = []
a = []
for i in range(5):
	row = input().split()
	for i in range(len(row)):
		row[i] = int(row[i])
	a.append(row)
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == 1:
			row = i
			column = j
total = abs(row - 2) + abs(column - 2)
print(total)


lst = []
cor = []
for x in range(5):
	a = list(map(int, input().split()))
	lst.append(a)
for x in range(5):
	try:
		row = x
		st = lst[x].index(1)
		break
	except ValueError:
		continue
do = 0
while row != 2:
	if row > 2:
		row -= 1
		do += 1
	else:
		row += 1
		do += 1
while st != 2:
	if st > 2:
		st -= 1
		do += 1
	else:
		st += 1
		do += 1
print(do)


for i in range(5):
	p = [int(i) for i in input().split()]
	for j in range(5):
		if p[j] == 1:
			print(abs(i - 2) + abs(j - 2))


def main():
	n = 5
	pos_x = -1
	pos_y = -1
	for i in range(0, n):
		line = [int(it) for it in input().split(' ')]
		if 1 in line:
			pos_x = line.index(1)
			pos_y = i
	print(abs(pos_x - 2) + abs(pos_y - 2))
main()


matrix = []
differentNumberLocation = (-1, -1)
for i in range(5):
	line = list(map(int, input().split()))
	matrix.append(line)
	if 1 in line:
		differentNumberLocation = (i, line.index(1))
print(abs(differentNumberLocation[0] - 2) + abs(differentNumberLocation[1] - 2))


a = []
for i in range(5):
	n = input().split()
	for j in range(5):
		n[j] = int(n[j])
	a.append(n)
x = 0
y = 0
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == 1:
			y = i
			x = j
			continue
print(abs(2 - x) + abs(2 - y))


a = [2, 1, 0, 1, 2]
for i in a:
	b = input()
	if '1' in b:
		print(i + a[b.find('1') // 2])


mat = []
d = 0
for i in range(5):
	mat.append(input().split())
for i in range(5):
	if '1' in mat[i]:
		d = abs(i + 1 - 3) + abs(mat[i].index('1') + 1 - 3)
print(d)


for i in range(5):
	try:
		j = input().split().index('1')
		print(sum([abs(2 - x) for x in (i, j)]))
	except ValueError:
		continue


(r, c) = (-1, -1)
for i in range(5):
	arr = [int(i) for i in input().split(' ')]
	for j in range(5):
		if arr[j] == 1:
			(r, c) = (i, j)
print(abs(2 - r) + abs(2 - c))


for y in range(5):
	arr = input().split()
	if '1' not in arr:
		continue
	x = arr.index('1')
	if x > -1:
		print(abs(2 - x) + abs(2 - y))
		break


a = []
n = [[4, 3, 2, 3, 4], [3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3], [4, 3, 2, 3, 4]]
ans = 0
for i in range(5):
	a = input().split(' ')
	for j in range(5):
		ans += int(a[j]) * n[i][j]
print(ans)


X = []
for I in range(0, 5):
	A = input().split(' ')
	if '1' in A:
		X = [I, A.index('1')]
		break
print(abs(2 - X[0]) + abs(2 - X[1]))


an = 0
for i in range(5):
	v = [int(x) for x in input().split()]
	for j in range(5):
		if v[j] == 1:
			x = i
			y = j
an = abs(x - 2) + abs(y - 2)
print(an)


import math
from collections import defaultdict
from collections import Counter
import itertools

def solve(m):
	c = None
	for i in range(5):
		for j in range(5):
			if m[i][j] == 1:
				c = [i, j]
	return abs(c[0] - 2) + abs(c[1] - 2)
n = 5
m = 5
res = []
for i in range(n):
	t = []
	in_ = input().split(' ')
	for x in in_:
		t.append(int(x))
	res.append(t)
print(solve(res))


mat = []
for row in range(5):
	mat.append(list(map(int, input().split())))
	if 1 in mat[-1]:
		one_row = len(mat)
		one_col = mat[-1].index(1) + 1
num_moves = abs(3 - one_row) + abs(3 - one_col)
print(num_moves)


l = [0, 0]
c = 0
for i in range(5):
	s = input().split()
	if '1' in s:
		l[0] = s.index('1')
		l[1] = c
	c += 1
print(abs(l[0] - 2) + abs(l[1] - 2))


data = []
(row, col) = (0, 0)
for i in range(5):
	data.append(input().split())
for rowv in range(len(data)):
	if '1' in data[rowv]:
		row = rowv
for colv in range(len(data[row])):
	if '1' in data[row][colv]:
		col = colv
moves = 0
if row > 2:
	moves += row - 2
elif row < 2:
	moves += 2 - row
if col > 2:
	moves += col - 2
elif col < 2:
	moves += 2 - col
print(moves)


matrix = []
position = [0, 0]
for i in range(5):
	matrix.append(input())
	if matrix[i].__contains__('1'):
		position = [i, int(matrix[i].index('1') / 2)]
result = abs(position[0] - 2) + abs(position[1] - 2)
print(result)


lists = []
for i in range(5):
	list = input().split(' ')
	lists.append(list)
for a in range(5):
	for b in range(5):
		if lists[a][b] == '1':
			c = abs(a - 2) + abs(b - 2)
			print(c)
			break


hcount = 0
vcount = 0
for x in range(5):
	line = input()
	data = line.split()
	for k in range(5):
		if data[k] == '1':
			if k <= 2:
				hcount = 2 - k
			else:
				hcount = k - 2
			if x <= 2:
				vcount = 2 - x
			else:
				vcount = x - 2
		else:
			continue
answer = hcount + vcount
print(answer)


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))
for i in range(5):
	a = to_list(input())
	if 1 in a:
		print(str(abs(2 - i) + abs(a.index(1) - 2)))


a = 0
for _ in range(0, 5):
	l = input().split()
	if '1' in l:
		a = abs(_ - 2) + abs(l.index('1') - 2)
print(a)


matrix = [5 * [0] for x in range(5)]
for i in range(0, 5):
	matrix[i] = list(map(int, input().split()))
(save_i, save_j) = (-1, -1)
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == 1:
			save_i = i + 1
			save_j = j + 1
			break
moves = 0
if save_j > 3:
	moves = moves + save_j - 3
else:
	moves = moves + 3 - save_j
if save_i > 3:
	moves = moves + save_i - 3
else:
	moves = moves + 3 - save_i
print(moves)


i = j = None
for (row, num) in enumerate([[input().split()] for x in range(5)]):
	if '1' in num[0]:
		i = row
		j = num[0].index('1')
print(abs(i - 2) + abs(j - 2))


e = []
for i in range(5):
	e = input()
	if e.find('1') != -1:
		j = e.find('1') // 2
		o = i
print(abs(2 - o) + abs(2 - j))


ls = []
m1 = list(map(int, input().split()))
m2 = list(map(int, input().split()))
m3 = list(map(int, input().split()))
m4 = list(map(int, input().split()))
m5 = list(map(int, input().split()))
ls.append(m1)
ls.append(m2)
ls.append(m3)
ls.append(m4)
ls.append(m5)
c = 0
while 1 not in ls[2]:
	if 1 in ls[0]:
		(ls[1], ls[0]) = (ls[0], ls[1])
		c += 1
		(ls[2], ls[1]) = (ls[1], ls[2])
		c += 1
	elif 1 in ls[1]:
		(ls[2], ls[1]) = (ls[1], ls[2])
		c += 1
	elif 1 in ls[3]:
		(ls[2], ls[3]) = (ls[3], ls[2])
		c += 1
	elif 1 in ls[4]:
		(ls[3], ls[4]) = (ls[4], ls[3])
		c += 1
		(ls[2], ls[3]) = (ls[3], ls[2])
		c += 1
	c = c
else:
	while ls[2][2] != 1:
		if ls[2][0] == 1:
			(ls[2][1], ls[2][0]) = (ls[2][0], ls[2][1])
			c += 1
			(ls[2][2], ls[2][1]) = (ls[2][1], ls[2][2])
			c += 1
		elif ls[2][1] == 1:
			(ls[2][2], ls[2][1]) = (ls[2][1], ls[2][2])
			c += 1
		elif ls[2][3] == 1:
			(ls[2][2], ls[2][3]) = (ls[2][3], ls[2][2])
			c += 1
		else:
			(ls[2][3], ls[2][4]) = (ls[2][4], ls[2][3])
			c += 1
			(ls[2][2], ls[2][3]) = (ls[2][3], ls[2][2])
			c += 1
	else:
		print(c)


import math

def beautifulmatrix(l):
	(r, c) = (0, 0)
	for i in range(0, 5):
		for j in range(0, 5):
			if l[i][j] == 1:
				(r, c) = (i, j)
				break
	return int(math.fabs(r - 2) + math.fabs(c - 2))
m = []
for x in range(5):
	k = list(map(int, input().split()))
	m.append(k)
print(beautifulmatrix(m))


ll = []
for j in range(5):
	mat = list(map(int, input().split()))
	col = [mat.index(i) for i in mat if i == 1]
	if len(col) != 0:
		rec = j
		col_fin = col
	ll.append(mat)
print(abs(int(rec) - 2) + abs(col_fin[0] - 2))


matrix = []
for i in range(5):
	baris = list(map(int, input().split()))
	matrix.append(baris)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			a = i + 1
			b = j + 1
			break
moves = abs(a - 3) + abs(b - 3)
print(moves)


list1 = [int(x) for x in input().split()]
list2 = [int(x) for x in input().split()]
list3 = [int(x) for x in input().split()]
list4 = [int(x) for x in input().split()]
list5 = [int(x) for x in input().split()]
matrix = [list1, list2, list3, list4, list5]
n = int(0)
m = int(0)
for n in range(0, 5):
	for m in range(0, 5):
		if matrix[n][m] == 1:
			print(abs(n - 2) + abs(m - 2))
			break
	else:
		continue
	break


k = 1
res = 0
while k < 6:
	n = input().split()
	if '1' in n:
		index = n.index('1')
		index = index + 1
		rows = 3 - k
		columns = 3 - index
		if rows < 0:
			rows = rows * -1
		if columns < 0:
			columns = columns * -1
		res = res + rows + columns
	k = k + 1
print(res)


c = 0
f = 0
x = list()
for i in range(5):
	l = list(map(int, input().split()))
	x.append(l)
	if 1 in l:
		c = i + 1
		f = l.index(1) + 1
print(abs(3 - f) + abs(3 - c))


flag = 0
for i in range(5):
	current_row = [int(x) for x in input().split()]
	for j in range(5):
		if current_row[j] > 0:
			flag = 1
			break
	if flag > 0:
		break
print(abs(i - 2) + abs(j - 2))


matrix = []
for i in range(5):
	permanent_not = input().split()
	if '1' in permanent_not:
		result = abs(2 - i) + abs(2 - permanent_not.index('1'))
print(result)


t = 1
i = 0
j = 0
x = -1
y = -1
while t:
	(a, b, c, d, e) = input().split()
	if a == '1':
		x = i
		y = j
	if b == '1':
		x = i
		y = j + 1
	else:
		j += 1
	if c == '1':
		x = i
		y = j + 1
	else:
		j += 1
	if d == '1':
		x = i
		y = j + 1
	else:
		j += 1
	if e == '1':
		x = i
		y = j + 1
	else:
		j += 1
	j = 0
	if i < 4:
		i += 1
	else:
		t = 0
print(abs(2 - x) + abs(2 - y))


for i in range(5):
	for (j, x) in enumerate(map(int, input().split())):
		if x == 1:
			print(abs(i - 2) + abs(j - 2))


M = {}
r = 0
c = 0
for i in range(1, 6):
	M[i] = list(map(int, input().split()))
for i in range(1, 6):
	if 1 in M[i]:
		r = i
		cn = 0
		for j in M[i]:
			cn += 1
			if j == 1:
				c = cn
print(abs(3 - r) + abs(3 - c))


mat = []
move = 0
for i in range(5):
	mat.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			if i < 2:
				move = move + (2 - i)
				i = 2
			elif i > 2:
				move = move + (i - 2)
				i = 2
			if j < 2:
				move = move + (2 - j)
				j = 2
			elif j > 2:
				move = move + (j - 2)
				j = 2
print(move)


line1 = input()
line2 = input()
line3 = input()
line4 = input()
line5 = input()
one = line1.split()
two = line2.split()
three = line3.split()
four = line4.split()
five = line5.split()
y = 0
x = 0
line = one
if '1' in one:
	line = one
	x = 2
if '1' in two:
	line = two
	x = 1
if '1' in three:
	line = three
if '1' in four:
	line = four
	x = 1
if '1' in five:
	line = five
	x = 2
z = 0
while '1' != line[z]:
	z = z + 1
z = z + 1
y = abs(3 - z)
print(y + x)


def main():
	row = 0
	col = 0
	for i in range(5):
		s = input()
		if '1' in s:
			row = i
			l = s
	c = 0
	for i in l:
		if i == '1':
			col = c
		c += 1
	res = abs(row - 2) + abs(int(col / 2) - 2)
	print(res)
main()


num = []
for i in range(5):
	temp = input()
	num.append(temp.split(' '))
(row, column) = (None, None)
for i in range(5):
	for j in range(5):
		if num[i][j] == '1':
			row = i + 1
			column = j + 1
			break
result = abs(row - 3) + abs(column - 3)
print(result)


mat = []
row = []
for _ in range(5):
	row = input().split(' ')
	mat.append(row)
for i in range(5):
	for j in range(5):
		x = mat[i][j]
		if x == '1':
			print(abs(i - 2) + abs(j - 2))
			break


import math
t = []
for i in range(0, 5):
	a = list(map(int, input().split()))
	t.append(a)
for i in range(0, 5):
	for j in range(0, 5):
		if t[i][j] == 1:
			a = i + 1
			b = j + 1
			break
print(int(math.fabs(a - 3) + math.fabs(b - 3)))


for i in range(5):
	l = str(input())
	if '1' in l:
		y = i + 1
		l = l.split()
		z = l.index('1')
		z = z + 1
print(abs(3 - y) + abs(3 - z))


pos_i = pos_j = 0
for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			pos_i = i + 1
			pos_j = j + 1
print(abs(3 - pos_i) + abs(3 - pos_j))


(k, l) = (0, 0)
while True:
	k = k + 1
	try:
		n = list(map(int, input().strip().split(' ')))
		if sum(n) == 1:
			l = n.index(1) + 1
			break
	except EOFError:
		break
print(abs(3 - k) + abs(3 - l))


mat = []
(rows, cols) = (5, 5)
for _ in range(rows):
	row = list(map(int, input().split()))
	mat.append(row)
mid = (2, 2)
temp = ()
for (id1, i) in enumerate(mat):
	for (id2, j) in enumerate(i):
		if j == 1:
			temp = (id1, id2)
a = abs(mid[0] - temp[0])
b = abs(mid[1] - temp[1])
print(a + b)


m = [[j for j in input().split()] for i in range(5)]
(x, y) = (0, 0)
for i in range(5):
	for j in range(5):
		if m[i][j] == '1':
			y = i + 1
			x = j + 1
print(abs(3 - x) + abs(3 - y))


a = [2, 1, 0, 1, 2]
for i in a:
	x = input()
	if '1' in x:
		print(i + a[x.find('1') // 2])


l1 = list(map(str, input().rstrip().split()))
l2 = list(map(str, input().rstrip().split()))
l3 = list(map(str, input().rstrip().split()))
l4 = list(map(str, input().rstrip().split()))
l5 = list(map(str, input().rstrip().split()))
count = 0
if l1.count('1') == 1:
	count += 2
	a = l1.index('1')
if l2.count('1') == 1:
	count += 1
	a = l2.index('1')
if l3.count('1') == 1:
	a = l3.index('1')
if l4.count('1') == 1:
	count += 1
	a = l4.index('1')
if l5.count('1') == 1:
	count += 2
	a = l5.index('1')
if a == 4 or a == 0:
	count += 2
if a == 3 or a == 1:
	count += 1
print(count)


matrix = []
pos_1 = False
for i in range(5):
	T = [int(x) for x in input().split()]
	if not pos_1:
		if 1 in T:
			pos_1 = [T.index(1) + 1, i + 1]
count = 0
while pos_1 != [3, 3]:
	if pos_1[0] > 3:
		pos_1[0] -= 1
	elif pos_1[0] < 3:
		pos_1[0] += 1
	elif pos_1[1] > 3:
		pos_1[1] -= 1
	elif pos_1[1] < 3:
		pos_1[1] += 1
	count += 1
else:
	print(count)


def search(x):
	if '1' in x:
		sdvStroka = abs(2 - x.index('1'))
		return 1
	else:
		return 0
str1 = input().split()
str2 = input().split()
str3 = input().split()
str4 = input().split()
str5 = input().split()
(sdvStroka, sdvStolb) = (0, 0)
m = [str1, str2, str3, str4, str5]
res = 0
for i in range(5):
	if search(m[i]) == 1:
		sdvStroka = abs(2 - m[i].index('1'))
		res = i
		break
sdvStolb = abs(2 - res)
print(sdvStolb + sdvStroka)


moves = 0
for i in range(0, 5):
	line = input()
	for num in line:
		if num == '1':
			if i - 2 > 0:
				moves += i - 2
			elif i - 2 < 0:
				moves -= i - 2
			else:
				moves += 0
			for num1 in range(len(line)):
				if line[num1] == '1':
					pos = int(num1 / 2)
					moves += abs(int(pos - 2))
print(moves)


n = 5
x1 = 0
x2 = 0
for i in range(5):
	line = list(map(int, input().split()))
	if 1 in line:
		x1 = i
		x2 = line.index(1)
print(abs(3 - x1 - 1) + abs(3 - x2 - 1))


import sys
matrix = []
for _ in range(5):
	matrix.append(list(map(int, input().split())))
if matrix[2][2] == 1:
	print(0)
	sys.exit(0)
row_no = None
column_no = None
moves = 0
row_needed = column_needed = 3
for (idx, row) in enumerate(matrix):
	if 1 in row:
		row_no = idx + 1
		column_no = row.index(1) + 1
		break
moves += abs(row_no - row_needed)
moves += abs(column_no - column_needed)
print(moves)


import math
for i in range(5):
	s = input().replace(' ', '')
	x = s.find('1')
	if x != -1:
		print(abs(2 - x) + abs(2 - i))
		break


liste = []
for y in range(5):
	liste = list(map(int, input().split()))
	for x in range(5):
		if liste[x] == 1:
			x = abs(2 - x)
			y = abs(2 - y)
			print(x + y)


row1 = input().replace(' ', '')
row2 = input().replace(' ', '')
row3 = input().replace(' ', '')
row4 = input().replace(' ', '')
row5 = input().replace(' ', '')
matrix = []
matrix.append(row1)
matrix.append(row2)
matrix.append(row3)
matrix.append(row4)
matrix.append(row5)
for row in matrix:
	if '1' in row:
		has_one = row
		break
moves = 0
row_num = matrix.index(has_one)
hor_moves = abs(2 - row_num)
moves += hor_moves
column_num = has_one.index('1')
vert_moves = abs(2 - column_num)
moves += vert_moves
print(moves)


for i in range(5):
	a = [int(x) for x in input().split()]
	for j in range(5):
		if a[j] == 1:
			x = i + 1
			y = j + 1
print(abs(x - 3) + abs(y - 3))


ch = [[0] * 5]
ch = input().split()
i = 0
j = 0
c = 0
while ch[j] != '1':
	j += 1
	if j == 5:
		i += 1
		j = 0
		ch = input().split()
if i <= 2:
	c = c + (2 - i)
else:
	c = c + abs(2 - i)
if j <= 2:
	c = c + (2 - j)
else:
	c = c + abs(2 - j)
print(c)


for i in range(5):
	x = input().split()
	temp = -1
	for j in x:
		temp += 1
		if int(j) == 1:
			ngang = i
			doc = temp
			break
print(abs(2 - ngang) + abs(2 - doc))


matrix = [[], [], [], [], []]
for i in range(5):
	matrix[i] = input().split()
r = 0
c = 0
for j in range(5):
	for k in range(5):
		if matrix[j][k] == '1':
			r = j + 1
			c = k + 1
answer = abs(3 - r) + abs(3 - c)
print(str(answer))


a = []
counter = 0
for i in range(5):
	a.append([int(x) for x in input().split()])
	if 1 in a[i]:
		index = i
if index < 2:
	while index != 2:
		(a[index + 1], a[index]) = (a[index], a[index + 1])
		index += 1
		counter += 1
else:
	while index != 2:
		(a[index - 1], a[index]) = (a[index], a[index - 1])
		index -= 1
		counter += 1
for i in range(5):
	if 1 == a[2][i]:
		ind = i
if ind < 2:
	while ind != 2:
		(a[ind + 1], a[ind]) = (a[ind], a[ind + 1])
		ind += 1
		counter += 1
else:
	while ind != 2:
		(a[ind - 1], a[ind]) = (a[ind], a[ind - 1])
		ind -= 1
		counter += 1
print(counter)


flis = []
for i in range(5):
	lis = list(map(int, input().split()))
	flis.append(lis)
for i in range(5):
	for j in range(5):
		if flis[i][j] == 1:
			res1 = i
			res2 = j
			break
ans = abs(2 - res1) + abs(2 - res2)
print(ans)


def find_distance():
	(x, y) = (0, 0)
	for i in range(5):
		line = [int(i) for i in input().split()]
		for j in range(5):
			if line[j] > 0:
				(x, y) = (i, j)
	return abs(2 - x) + abs(2 - y)
print(find_distance())


(r, c) = (0, 0)
for i in range(0, 5):
	matrix_row = input().split(' ')
	for j in range(0, 5):
		if matrix_row[j] == '1':
			c = int(j)
			r = int(i)
r += 1
c += 1
moves = abs(3 - r) + abs(3 - c)
print(moves)


x = ''.join([''.join(input().split()) for i in range(5)]).index('1')
print(abs(2 - x % 5) + abs(2 - x // 5))


A = input().split()
B = input().split()
C = input().split()
D = input().split()
E = input().split()
listlist = [A, B, C, D, E]
a = 0
for list in listlist:
	a = a + 1
	if '1' in list:
		break
AA = listlist[a - 1]
b = AA.index('1') + 1
c = abs(a - 3) + abs(b - 3)
print(c)


i1 = list(map(int, input().split()))
i2 = list(map(int, input().split()))
i3 = list(map(int, input().split()))
i4 = list(map(int, input().split()))
i5 = list(map(int, input().split()))
M = [i1, i2, i3, i4, i5]
moves = 0
row_num = 1
for row in M:
	if 1 in row:
		col_num = row.index(1) + 1
		moves = moves + abs(row_num - 3) + abs(col_num - 3)
		print(moves)
		break
	row_num = row_num + 1


a = 5
for i in range(5):
	arr = list(map(int, input().split()))
	c = 0
	if max(arr) == 1:
		r = i
		x = arr.index(1)
		if r != 2:
			c += abs(2 - r)
		if x != 2:
			c += abs(2 - x)
		print(c)
	else:
		pass


s = ''
for i in range(5):
	for i in input().split():
		s += str(i)
j = s.find('1') // 5
i = s.find('1') % 5
print(abs(i - 2) + abs(j - 2))


n = [[int(x) for x in input().split()] for line in range(5)]
for i in range(5):
	for j in range(5):
		if str(n[i][j]) == '1':
			(m1, m2) = (i + 1, j + 1)
print(abs(3 - m1) + abs(3 - m2))


t = lambda : map(int, input().split())
for i in range(5):
	l = list(t())
	if 1 in l:
		break
column = l.index(1) + 1
row = i + 1
result = abs(3 - column) + abs(3 - row)
print(result)


r0 = [int(x) for x in input().split()]
r1 = [int(x) for x in input().split()]
r2 = [int(x) for x in input().split()]
r3 = [int(x) for x in input().split()]
r4 = [int(x) for x in input().split()]
if r2[2] != 0:
	print('0')
elif r1[2] != 0 or r2[1] != 0 or r2[3] != 0 or (r3[2] != 0):
	print('1')
elif r1[1] != 0 or r1[3] != 0 or r3[1] != 0 or (r3[3] != 0) or (r0[2] != 0) or (r2[0] != 0) or (r2[4] != 0) or (r4[2] != 0):
	print('2')
elif r0[0] != 0 or r4[0] != 0 or r0[4] != 0 or (r4[4] != 0):
	print('4')
else:
	print('3')


matrix = []
numberOfMoves = 0
for i in range(0, 5):
	row = input().split()
	matrix.append(row)
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == '1':
			if i % 2 != 0:
				numberOfMoves += 1
			if i % 2 == 0 and i != 2:
				numberOfMoves += 2
			if j % 2 == 0 and j != 2:
				numberOfMoves += 2
			if j % 2 != 0:
				numberOfMoves += 1
print(numberOfMoves)


from math import fabs
res = 0
for i in range(5):
	s = input().split()
	for j in range(5):
		if s[j] == '1':
			res = fabs(2 - i) + fabs(2 - j)
			break
print(int(res))


arr = list()
shag = 0
for _ in range(5):
	arr.append(list(map(int, input().split())))
for i in range(5):
	try:
		if arr[i].index(1) >= 0:
			if i >= 2:
				shag += i + 1 - 3
			else:
				shag += 3 - (i + 1)
			if arr[i].index(1) >= 2:
				shag += arr[i].index(1) + 1 - 3
			else:
				shag += 3 - (arr[i].index(1) + 1)
			break
	except Exception:
		pass
print(shag)


def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())
for i in range(5):
	a = li()
	f = 0
	for j in range(5):
		if a[j]:
			f = 1
			break
	if f == 1:
		break
x = abs(2 - i)
x += abs(2 - j)
print(x)


for i in range(5):
	mat = list(map(int, input().split()))
	for j in range(5):
		if mat[j] == 1:
			print('\n' + str(abs(i + 1 - 3) + abs(j + 1 - 3)))
			break


row = 0
column = 0
for i in range(5):
	inMatrix = input()
	if '1' in inMatrix:
		row = i
		column = inMatrix.split(' ').index('1')
rescol = abs(column - 2)
relrow = abs(row - 2)
print(rescol + relrow)


posr = posc = 0
f = 0
for _ in range(5):
	temp = input()
	posr += 1
	if '1' in temp:
		t = temp.split()
		posc = t.index('1')
		break
print(abs(posr - 3) + abs(posc - 2))


num = 0
for j in range(5):
	seq = [int(x) for x in input().split()]
	for i in range(0, 5):
		if seq[i] == 0:
			num += 0
		elif seq[i] != 0:
			num = abs(j - 2) + abs(i - 2)
print(num)


import math
(x, y) = (0, 0)
(X, Y) = (2, 2)
flag = False
for i in range(5):
	ls = list(map(int, input().strip().split(' ')))
	if ls.count(1):
		x = i
		y = ls.index(1)
		break
print(int(math.fabs(X - x) + math.fabs(Y - y)))


posr = 0
posc = 0
for i in range(1, 6):
	row = input()
	if '1' in row:
		posr = i
		posc = row.split().index('1') + 1
		break
print(abs(3 - posr) + abs(3 - posc))


for i in range(5):
	n = input().split()
	if '1' in n:
		print(abs(i - 2) + abs(n.index('1') - 2))
		exit()


import sys
import math

def leastMoves(matrix):
	cnt = 0
	for x in range(0, len(matrix) + 1):
		row = matrix[x]
		if 1 in row:
			return int(math.fabs(2 - x) + math.fabs(2 - row.index(1)))
	return 0
beautiful_matrix = []
for x in range(0, 5):
	row = list(map(int, input().split(' ')))
	beautiful_matrix.append(row)
result = leastMoves(beautiful_matrix)
print(result)


l0 = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l = [l0, l1, l2, l3, l4]
(x, y) = (0, 0)
for i in range(5):
	if 1 in l[i]:
		x = i
		y = l[i].index(1)
		break
print(abs(x - 2) + abs(y - 2))


li = [[], [], [], [], []]
b_li = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
for i in range(5):
	li[i] = list(map(int, input().split()))
c = 0
r = 0
count = 0
for i in range(5):
	for j in range(5):
		if li[i][j] == 1:
			r = i
			c = j
while li != b_li:
	if r > 2:
		li[r][c] = 0
		r -= 1
		li[r][c] = 1
		count += 1
	elif r < 2:
		li[r][c] = 0
		r += 1
		li[r][c] = 1
		count += 1
	if c > 2:
		li[r][c] = 0
		c -= 1
		li[r][c] = 1
		count += 1
	elif c < 2:
		li[r][c] = 0
		c += 1
		li[r][c] = 1
		count += 1
print(count)


a = []
for i in range(5):
	b = input().split()
	if '1' in b:
		p = b.index('1')
		j = i
print(abs(2 - j) + abs(2 - p))


from math import *
matrix = []
for i in range(5):
	a = []
	a = [int(i) for i in input().split()][:5]
	matrix.append(a)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			p = abs(2 - i)
			q = abs(2 - j)
			break
if p == 0 and q == 0:
	print(0)
elif p == 0:
	if q == 1:
		print(1)
	elif q == 2:
		print(2)
elif p == 1:
	if q == 0:
		print(1)
	elif q == 1:
		print(2)
	else:
		print(3)
elif q == 0:
	print(2)
elif q == 1:
	print(3)
else:
	print(4)


w = 5
h = 5
matrix = [[0 for x in range(w)] for y in range(h)]
l = []
for i in range(0, 5):
	raw = str(input(''))
	raw = raw.split(' ')
	counter = 0
	for items in raw:
		if int(items) == 1:
			l.insert(len(l), i)
			l.insert(len(l), counter)
		matrix[i][counter] = int(items)
		counter = counter + 1
step = abs(l[0] - 2) + abs(l[1] - 2)
print(step, end='')


mat = []
flag = 0
for i in range(5):
	l = list(map(int, input().split()))
	if not flag:
		if 1 in l:
			flag = 1
			x = i
			y = l.index(1)
if flag:
	print(abs(x - 2) + abs(y - 2))
else:
	print(0)


x = []
for i in range(5):
	x.append(list(map(int, input().split())))
for i in range(5):
	if 1 in x[i]:
		row = i
		column = x[i].index(1)
		break
row += 1
column += 1
row -= 3
column -= 3
moves = abs(row) + abs(column)
print(moves)


r1 = input()
r2 = input()
r3 = input()
r4 = input()
r5 = input()
r1 = r1.split()
r2 = r2.split()
r3 = r3.split()
r4 = r4.split()
r5 = r5.split()
count = 0
c = 0
for i in range(5):
	c = i
	if r1[i] == '1' or r5[i] == '1':
		count += 2
		break
	elif r2[i] == '1' or r4[i] == '1':
		count += 1
		break
	elif r3[i] == '1':
		break
if i == 0 or i == 4:
	count += 2
elif i == 1 or i == 3:
	count += 1
print(count)


matrix = []
one_pos = None
for _ in range(5):
	matrix.append([int(i) for i in input().split()])
for i in range(len(matrix)):
	for j in range(len(matrix)):
		if matrix[i][j] == 1:
			one_pos = [i, j]
moves = abs(2 - one_pos[0]) + abs(2 - one_pos[1])
print(moves)


l1_string = input()
l2_string = input()
l3_string = input()
l4_string = input()
l5_string = input()
moves = 0
l1 = l1_string.split()
l2 = l2_string.split()
l3 = l3_string.split()
l4 = l4_string.split()
l5 = l5_string.split()
for i in range(5):
	if l1[i] == '1':
		moves = abs(i - 2) + 2
	elif l2[i] == '1':
		moves = abs(i - 2) + 1
	elif l3[i] == '1':
		moves = abs(i - 2)
	elif l4[i] == '1':
		moves = abs(i - 2) + 1
	elif l5[i] == '1':
		moves = abs(i - 2) + 2
	else:
		continue
print(moves)


import sys
for i in range(5):
	s1 = sys.stdin.readline().rstrip()
	if '1' in s1:
		xi = i + 1
		xj = s1.split(' ').index('1') + 1
ss = abs(3 - xi) + abs(3 - xj)
print(ss)


arr = []
for i in range(5):
	lsj = []
	ls = []
	ls = input().split()
	for x in range(len(ls)):
		lsj.append(int(ls[x]))
	arr.append(lsj)
cti = 0
ctj = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			cti = abs(i - 2)
			ctj = abs(j - 2)
print(cti + ctj)


l = [[], [], [], [], []]
x = y = 0
for i in range(5):
	l[i] = [int(x) for x in input().split()]
for i in range(5):
	if 1 in l[i]:
		x = i + 1
		for j in range(5):
			if l[i][j] == 1:
				y = j + 1
				break
	else:
		continue
print(abs(x - 3) + abs(y - 3))


t = [input().replace(' ', '') for _ in range(5)]
for i in range(5):
	for j in range(5):
		if t[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))


m = []
px = 0
py = 0
for i in range(0, 5):
	aux = input().split(' ')
	for j in range(0, 5):
		if aux[j] == '1':
			py = i + 1
			px = j + 1
	m.append(aux)
d = abs(px - 3) + abs(py - 3)
print(d)


arr = []
for i in range(0, 5):
	arr.append([int(x) for x in input().split(' ')])
numberOneIndex = None
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			numberOneIndex = [i, j]
print(sum([abs(2 - numberOneIndex[0]), abs(2 - numberOneIndex[1])]))


line1 = input()
line2 = input()
line3 = input()
line4 = input()
line5 = input()
line1 = line1.split()
line2 = line2.split()
line3 = line3.split()
line4 = line4.split()
line5 = line5.split()
perfect = [2, 2]
i = 0
j = 0
while j < len(line1):
	if line1[j] == '1':
		i = abs(i - 2)
		j = abs(j - 2)
		print(i + j)
		break
	j += 1
j = 0
i += 1
while j < len(line2):
	if line2[j] == '1':
		i = abs(i - 2)
		j = abs(j - 2)
		print(i + j)
		break
	j += 1
j = 0
i += 1
while j < len(line3):
	if line3[j] == '1':
		i = abs(i - 2)
		j = abs(j - 2)
		print(i + j)
		break
	j += 1
j = 0
i += 1
while j < len(line4):
	if line4[j] == '1':
		i = abs(i - 2)
		j = abs(j - 2)
		print(i + j)
		break
	j += 1
j = 0
i += 1
while j < len(line5):
	if line5[j] == '1':
		i = abs(i - 2)
		j = abs(j - 2)
		print(i + j)
		break
	j += 1


mat = []
for row in range(5):
	mat.append(list(map(int, input().split())))
for row in range(5):
	for col in range(5):
		if mat[row][col] == 1:
			break
	if mat[row][col] == 1:
		break
print(abs(row - 2) + abs(col - 2))


l = []
for i in range(5):
	l.append([int(j) for j in input().split()])
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			r = i
			c = j
m = r - 2
n = c - 2
print(abs(m) + abs(n))


for i in range(5):
	t = list(map(str, input().split(' ')))
	if '1' in t:
		print(abs(t.index('1') - 2) + abs(i - 2))
		break


matrix = []
for i in range(0, 5):
	st = input('')
	s = list(st.split(' '))
	lis = [int(x) for x in s]
	matrix.append(lis)
for k in range(0, 5):
	for j in range(0, 5):
		if matrix[k][j] == 1:
			total = abs(k - 2) + abs(j - 2)
		else:
			continue
print(total)


a = 2
na = input().split(' ')
nb = input().split(' ')
nc = input().split(' ')
nd = input().split(' ')
ne = input().split(' ')
pa = []
pb = []
pc = []
pd = []
pe = []
for i in range(5):
	pa.append(int(na[i]))
	pb.append(int(nb[i]))
	pc.append(int(nc[i]))
	pd.append(int(nd[i]))
	pe.append(int(ne[i]))
if 1 in pa:
	m = pa.index(1)
	print(abs(m - 2) + 2)
if 1 in pb:
	m = pb.index(1)
	print(abs(m - 2) + 1)
if 1 in pc:
	m = pc.index(1)
	print(abs(m - 2))
if 1 in pd:
	m = pd.index(1)
	print(abs(m - 2) + 1)
if 1 in pe:
	m = pe.index(1)
	print(abs(m - 2) + 2)


l = list()
for i in range(1, 6):
	temp = list(map(int, input().split(' ')))
	l = l + temp
a = l.index(1) + 1
if a % 5 == 0:
	row = a // 5
else:
	row = a // 5 + 1
column = a % 5
if column == 0:
	column = 5
diff = abs(3 - row) + abs(3 - column)
print(diff)


for i in range(5):
	x = list(map(int, input().split()))
	if 1 in x:
		c = x.index(1)
		r = i
		break
s = lambda x: x if x > 0 else -x
x = s(2 - c)
y = s(2 - r)
print(x + y)


ans = []
for i in range(5):
	arr = []
	arr = list(map(int, input().strip().split()))
	ans.append(arr)
for i in range(5):
	for j in range(5):
		if ans[i][j] == 1:
			x = i
			y = j
suma = abs(x - 2) + abs(y - 2)
print(suma)


lista = []
contador = 0
for i in range(0, 5):
	a = input()
	lista.append(a.split(' '))
for j in range(0, 5):
	for k in range(0, 5):
		if lista[j][k] == '1':
			contador = str(j) + ' ' + str(k)
operacion = 0
if int(contador[0]) >= 2 and int(contador[-1]) < 2:
	operacion = int(contador[0]) - 2 + int(contador[-1])
	if int(contador[-1]) == 0:
		operacion += 2
elif int(contador[-1]) >= 2 and int(contador[0]) < 2:
	operacion = int(contador[-1]) - 2 + int(contador[0])
	if int(contador[0]) == 0:
		operacion += 2
elif int(contador[-1]) >= 2 and int(contador[0]) >= 2:
	operacion = int(contador[-1]) - 2 + (int(contador[0]) - 2)
elif int(contador[0]) == 0 and int(contador[-1]) == 0:
	operacion = 4
elif int(contador[-1]) < 2 and int(contador[0]) < 2:
	operacion = int(contador[0]) + int(contador[-1])
	if int(contador[-1]) == 0:
		operacion += 2
	elif int(contador[0]) == 0:
		operacion += 2
print(operacion)


mat = [input().split() for _ in range(5)]
for i in range(5):
	for j in range(5):
		if mat[i][j] == '1':
			(a, b) = [i, j]
			break
print(abs(2 - a) + abs(2 - b))


for i in range(5):
	row = [int(num) for num in str.split(input())]
	if 1 in row:
		r = i
		c = row.index(1)
print(abs(r - 2) + abs(c - 2))


matrix = list()
for _ in range(5):
	matrix.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			cr = i + 1
			cc = j + 1
tot = 0
if cr != 3:
	tot += abs(3 - cr)
if cc != 3:
	tot += abs(3 - cc)
print(tot)


a = []
g = 0
for i in range(5):
	a.append(list(map(int, input().split())))
if 1 in a[0]:
	g = a[0].index(1)
	if g == 0 or g == 4:
		print(4)
	if g == 1 or g == 3:
		print(3)
	if g == 2:
		print(2)
if 1 in a[1]:
	g = a[1].index(1)
	if g == 0 or g == 4:
		print(3)
	if g == 1 or g == 3:
		print(2)
	if g == 2:
		print(1)
if 1 in a[2]:
	g = a[2].index(1)
	if g == 0 or g == 4:
		print(2)
	if g == 1 or g == 3:
		print(1)
	if g == 2:
		print(0)
if 1 in a[3]:
	g = a[3].index(1)
	if g == 0 or g == 4:
		print(3)
	if g == 1 or g == 3:
		print(2)
	if g == 2:
		print(1)
if 1 in a[4]:
	g = a[4].index(1)
	if g == 0 or g == 4:
		print(4)
	if g == 1 or g == 3:
		print(3)
	if g == 2:
		print(2)


arr = []
row = 0
answer = 0
for rows in range(1, 6):
	row = [int(a) for a in input().split()]
	arr.append(row)
	if 1 in row:
		answer = abs(3 - (row.index(1) + 1)) + abs(3 - rows)
print(answer)


k = []
for i in range(5):
	k.append(list(map(int, input().strip().split(' '))))
	if k[i].count(1) == 1:
		r = i
		c = k[i].index(1)
print(abs(r - 2) + abs(c - 2))


matrix = []
for i in range(5):
	temp = input()
	a = temp.split()
	matrix.append(a)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			x = i
			y = j
			break
_x = abs(2 - x) + abs(2 - y)
print(_x)


l1 = input().split()
l2 = input().split()
l3 = input().split()
l4 = input().split()
l5 = input().split()
if l1[0] == '1':
	print(4)
elif l1[1] == '1':
	print(3)
elif l1[2] == '1':
	print(2)
elif l1[3] == '1':
	print(3)
elif l1[4] == '1':
	print(4)
elif l2[0] == '1':
	print(3)
elif l2[1] == '1':
	print(2)
elif l2[2] == '1':
	print(1)
elif l2[3] == '1':
	print(2)
elif l2[4] == '1':
	print(3)
elif l3[0] == '1':
	print(2)
elif l3[1] == '1':
	print(1)
elif l3[2] == '1':
	print(0)
elif l3[3] == '1':
	print(1)
elif l3[4] == '1':
	print(2)
elif l4[0] == '1':
	print(3)
elif l4[1] == '1':
	print(2)
elif l4[2] == '1':
	print(1)
elif l4[3] == '1':
	print(2)
elif l4[4] == '1':
	print(3)
elif l5[0] == '1':
	print(4)
elif l5[1] == '1':
	print(3)
elif l5[2] == '1':
	print(2)
elif l5[3] == '1':
	print(3)
elif l5[4] == '1':
	print(4)


def solve(arr):
	s = 0
	p = 0
	for i in range(0, 5):
		for j in range(0, 5):
			if arr[i][j] == 1:
				s = i
				p = j
	x = abs(p + 1 - 3) + abs(s + 1 - 3)
	return x
arr = []
for i in range(0, 5):
	arr1 = list(map(int, input().split()))
	arr.append(arr1)
print(solve(arr))


matrix = []
mosse = 0
for i in range(5):
	matrix.append(input().replace(' ', ''))
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if int(matrix[i][j]) == 1:
			break
	if int(matrix[i][j]) == 1:
		break
if int(matrix[i][j]) == 1 and i == 3 and (j == 3):
	mosse += 0
if int(matrix[i][j]) == 1 and i != 2:
	mosse += abs(2 - i)
if int(matrix[i][j]) == 1 and j != 2:
	mosse += abs(2 - j)
print(mosse)


for i in range(5):
	x = tuple(map(int, input().split()))
	if 1 in x:
		ans = abs(2 - i) + abs(2 - x.index(1))
print(ans)


a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a4 = list(map(int, input().split()))
a5 = list(map(int, input().split()))
array = list((a1, a2, a3, a4, a5))
haha = []
count = 0
for i in array:
	for j in i:
		if j == 1:
			haha.append(array.index(i))
			haha.append(i.index(1))
count += abs(2 - haha[0])
count += abs(2 - haha[1])
print(count)


import math
flag = '1'
for i in range(0, 5):
	row = input().split()
	j = row.index(flag) if flag in row else None
	if j is not None:
		break
print(int(math.fabs(2 - i) + math.fabs(2 - j)))


for i in range(5):
	vec = [int(i) for i in input().split(' ')]
	try:
		c = vec.index(1) + 1
		r = i + 1
	except:
		continue
print(abs(3 - r) + abs(3 - c))


p = []
s = []
for i in range(5):
	p.append(list(map(int, input().split())))
	if 1 in p[i]:
		s = [i, p[i].index(1)]
print(str(abs(s[0] - 2) + abs(s[1] - 2)))


import math
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
countr = [0] * 6
countc = [0] * 6
i = 0
f = False
while i < len(l1) and (not f):
	if l1[i] == 1:
		countr[1] += 1
		countc[i + 1] += 1
		f = True
		break
	i += 1
i = 0
while i < len(l2) and (not f):
	if l2[i] == 1:
		countr[2] += 1
		countc[i + 1] += 1
		f = True
		break
	i += 1
i = 0
while i < len(l3) and (not f):
	if l3[i] == 1:
		countr[3] += 1
		countc[i + 1] += 1
		f = True
		break
	i += 1
i = 0
while i < len(l4) and (not f):
	if l4[i] == 1:
		countr[4] += 1
		countc[i + 1] += 1
		f = True
		break
	i += 1
i = 0
while i < len(l5) and (not f):
	if l5[i] == 1:
		countr[5] += 1
		countc[i + 1] += 1
		f = True
		break
	i += 1
r = 0
c = 0
i = 1
while i < len(countc):
	if countc[i] == 1:
		c = i
		break
	i += 1
i = 1
while i < len(countr):
	if countr[i] == 1:
		r = i
		break
	i += 1
n = abs(c - 3) + abs(r - 3)
print(n)


mtx = []
for i in range(5):
	temp = list(map(int, input().split()))
	mtx.append(temp)
r = 0
c = 0
for i in range(5):
	for j in range(5):
		if mtx[i][j] == 1:
			r = i
			c = j
ans = abs(r - 2) + abs(c - 2)
print(ans)


row = 5
col = 5
arr = []
count = 0
for i in range(row):
	ar = list(map(int, input().rstrip().split()))
	arr.append(ar)
while True:
	for i in range(row):
		for j in range(row):
			if arr[2][2] == 1:
				print(count)
				quit()
			elif 1 in arr[i]:
				x = arr[i].index(1)
				if x > 2:
					t = arr[i][x]
					arr[i][x] = arr[i][x - 1]
					arr[i][x - 1] = t
					count += 1
					if t == arr[i][2]:
						if i == 2:
							print(count)
							quit()
						elif i < 2:
							p = arr[i][2]
							arr[i][2] = arr[i + 1][2]
							arr[i + 1][2] = p
							count += 1
						else:
							p = arr[i][2]
							arr[i][2] = arr[i - 1][2]
							arr[i - 1][2] = p
							count += 1
				elif x < 2:
					t = arr[i][x]
					arr[i][x] = arr[i][x + 1]
					arr[i][x + 1] = t
					count += 1
					if t == arr[i][2]:
						if i == 2:
							print(count)
							quit()
						elif i < 2:
							p = arr[i][2]
							arr[i][2] = arr[i + 1][2]
							arr[i + 1][2] = p
							count += 1
						else:
							p = arr[i][2]
							arr[i][2] = arr[i - 1][2]
							arr[i - 1][2] = p
							count += 1
				elif x == 2:
					if i == 2:
						print(count)
						quit()
					elif i < 2:
						p = arr[i][2]
						arr[i][2] = arr[i + 1][2]
						arr[i + 1][2] = p
						count += 1
					else:
						p = arr[i][2]
						arr[i][2] = arr[i - 1][2]
						arr[i - 1][2] = p
						count += 1
				else:
					continue
			else:
				continue


for i in range(5):
	row = input()
	for j in range(5):
		arr = row.split()
		if arr[j] == '1':
			storei = i
			storej = j
print(abs(storei - 2) + abs(storej - 2))


list1 = []
for i in range(5):
	list2 = [int(x) for x in input().split()]
	list1.append(list2)
for i in range(5):
	for j in range(5):
		if list1[i][j] == 1:
			c = i
			d = j
print(abs(c - 2) + abs(d - 2))


def findColumn(arr):
	for i in range(1, 6):
		if arr[i - 1] == '1':
			return i
line1 = input().split()
line2 = input().split()
line3 = input().split()
line4 = input().split()
line5 = input().split()
oneRow = 0
oneColumn = 0
if '1' in line1:
	oneRow = 1
	oneColumn = findColumn(line1)
elif '1' in line2:
	oneRow = 2
	oneColumn = findColumn(line2)
elif '1' in line3:
	oneRow = 3
	oneColumn = findColumn(line3)
elif '1' in line4:
	oneRow = 4
	oneColumn = findColumn(line4)
elif '1' in line5:
	oneRow = 5
	oneColumn = findColumn(line5)
print(abs(oneRow - 3) + abs(oneColumn - 3))


row = 0
col = 0
for i in range(5):
	x = input()
	l = x.split()
	for j in range(5):
		num = l[j]
		if num == '1':
			row = i
			col = j
print(abs(row - 2) + abs(col - 2))


a = b = c = d = e = []
a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
lst = [a, b, c, d, e]
z = 0
for i in range(0, 5):
	for j in range(0, 5):
		if lst[i][j] == '1':
			z = abs(i - 2) + abs(j - 2)
print(z)


a = [[int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()]]
for ind in range(5):
	if sum(a[ind]) > 0:
		row = ind
		column = a[ind].index(1)
print(abs(row - 2) + abs(column - 2))


mass = []
for i in range(5):
	mass.append([int(s) for s in input().split()])
for i in range(5):
	for j in range(5):
		if mass[i][j] == 1:
			x = i
			y = j
our_coord = [3, 3]
print(abs(2 - x) + abs(2 - y))


rows = []
for i in range(1, 6):
	row = input().split(' ')
	if '1' in row:
		X = i
	rows.append(row)
print(abs(X - 3) + abs(rows[X - 1].index('1') + 1 - 3))


global a, d
for i in range(5):
	a = list(map(int, input().split(' ')))
	b = a.count(1)
	if b == 1:
		d = i
		break
c = a.index(1)
print(abs(2 - c) + abs(2 - d))


for x in range(5):
	cur_tab = list(map(int, input().split()))
	for y in range(5):
		if cur_tab[y] == 1:
			print(abs(3 - (x + 1)) + abs(3 - (y + 1)))
			break


matrix = [input().strip().split() for i in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			(x, y) = (i, j)
print(abs(2 - x) + abs(2 - y))


count = 0
for i in range(1, 6):
	nums = list(map(int, input().split()))
	if 1 in nums:
		count += abs(2 - nums.index(1)) + abs(3 - i)
	else:
		continue
print(count)


input_list = []
for i in range(5):
	input_list += [input().split()]
coordinates = []
for i in range(5):
	if '1' in input_list[i]:
		coordinates = [input_list[i].index('1') + 1, i + 1]
moves = abs(coordinates[0] - 3) + abs(coordinates[1] - 3)
print(moves)


(x, y) = (0, 0)
for x in range(5):
	s = input().split()
	for y in range(5):
		if s[y] == '1':
			print(abs(x - 2) + abs(y - 2))


for i in range(5):
	s = input()
	if '1' in s:
		ans = abs(i - 2) + abs((s.index('1') - 4) // 2)
print(ans)


line1 = input()
line2 = input()
line3 = input()
line4 = input()
line5 = input()
dataLine1 = []
dataLine1 = line1.split(' ')
dataLine2 = []
dataLine2 = line2.split(' ')
dataLine3 = []
dataLine3 = line3.split(' ')
dataLine4 = []
dataLine4 = line4.split(' ')
dataLine5 = []
dataLine5 = line5.split(' ')
count = 0
for i in range(0, 5):
	if dataLine1[i] == '1' or dataLine5[i] == '1':
		count = count + 2
		dataLine3[i] = '1'
		if i > 2:
			add = i - 2
			count = count + add
		elif i < 2:
			add = 2 - i
			count = count + add
	elif dataLine2[i] == '1' or dataLine4[i] == '1':
		count = count + 1
		dataLine3[i] = '1'
		if i > 2:
			add = i - 2
			count = count + add
		elif i < 2:
			add = 2 - i
			count = count + add
	elif dataLine3[i] == '1':
		count = 0
		if i == 2:
			add = 0
			count = count + add
		if i > 2:
			add = i - 2
			count = count + add
		elif i < 2:
			add = 2 - i
			count = count + add
print(count)


def mod(a, b):
	if a >= b:
		return a - b
	else:
		return b - a
m = []
ans = 0
for i in range(5):
	m.append(list(map(int, input().split())))
for (r, v) in enumerate(m):
	if 1 in v:
		ans += mod(r, 2)
		ans += mod(v.index(1), 2)
print(ans)


arr = []
for i in range(5):
	arr.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			ans = abs(i + 1 - 3) + abs(j + 1 - 3)
			break
print(ans)


v = []
for i in range(5):
	v.append([int(x) for x in input().split()])
	for j in range(5):
		if v[i][j] == 1:
			pozi = i
			pozj = j
nr = 0
if pozi > 2:
	nr += pozi - 2
else:
	nr += 2 - pozi
if pozj > 2:
	nr += pozj - 2
else:
	nr += 2 - pozj
print(nr)


matrix = []
arr = []
flag = 0
for i in range(0, 5):
	arr = list(map(int, input().split()))
	matrix.append(arr)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			x = i
			y = j
			flag = 1
			break
	if flag == 1:
		break
diff1 = 2 - x
if diff1 < 0:
	diff1 *= -1
diff2 = 2 - y
if diff2 < 0:
	diff2 *= -1
ans = diff1 + diff2
print(ans)


def solve():
	ans = 0
	for i in range(5):
		row = input().split(' ')
		if '1' in row:
			ans += abs(2 - i)
			ans += abs(2 - row.index('1'))
	print(ans)
solve()


board = []
for index in range(5):
	board.append([int(x) for x in input().split()])
save = []
for x in range(5):
	for y in range(5):
		if board[x][y] == 1:
			save = [x, y]
ans = abs(save[0] - 2) + abs(save[1] - 2)
print(ans)


n = 5
cnt = 0
i = 0
j = 0
while cnt < n:
	cnt += 1
	l = list(map(int, input().split()))
	if sum(l) == 1:
		i = cnt
		j = l.index(1) + 1
	l = []
print(abs(i - 3) + abs(j - 3))


i = 0
j = 0
centre = 2
n = 5
for k in range(n):
	tmp = ''.join(input().split())
	found = tmp.find('1')
	if found != -1:
		i = k
		j = found
print(abs(centre - i) + abs(centre - j))


ANS = -1
Arr = []
for i in range(0, 5):
	ip = input().split()
	Arr.append(ip)
for i in range(0, 5):
	for j in range(0, 5):
		if Arr[i][j] == '1':
			ANS = abs(i - 2) + abs(j - 2)
print(ANS)


for i in range(5):
	a = list(map(int, input().split()))
	if 1 in a:
		c = a.index(1)
		r = i
m = 0
while r != 2:
	if r > 2:
		r -= 1
		m += 1
	else:
		r += 1
		m += 1
while c != 2:
	if c > 2:
		c -= 1
		m += 1
	else:
		c += 1
		m += 1
print(m)


import math
import cmath
from decimal import *
from fractions import *
for _ in range(5):
	a = input().split()
	for i in range(5):
		if a[i] == '1':
			print(abs(2 - _) + abs(2 - i))


l = []
for i in range(5):
	a = list(map(int, input().split()))
	l.append(a)
for i in range(5):
	f = l[i]
	if 1 in f:
		(x, y) = (i, f.index(1))
		break
print(abs(x - 2) + abs(y - 2))


l = []
c = 0
for _ in range(5):
	l += [list(map(int, input().split()))]
for i in range(5):
	if 1 in l[i]:
		j = l[i].index(1)
		break
if i < 2:
	if j <= 2:
		c += 2 - j
		j += 2 - j
	else:
		c += j - 2
		j += 2 - j
	c += 2 - i
else:
	if j <= 2:
		c += 2 - j
		j += 2 - j
	else:
		c += j - 2
		j += 2 - j
	c += i - 2
print(c)


s = [input().split() for i in range(5)]
for i in range(5):
	for j in range(5):
		if s[i][j] == '1':
			print(abs(i + 1 - 3) + abs(j + 1 - 3))
			raise SystemExit


def solve(m):
	moves = 0
	for i in range(len(m)):
		for j in range(len(m)):
			if m[i][j] == 1:
				moves = abs(i - 2) + abs(j - 2)
	return moves
matrix = []
for k in range(5):
	cols = []
	(c1, c2, c3, c4, c5) = input().split()
	cols.append(int(c1))
	cols.append(int(c2))
	cols.append(int(c3))
	cols.append(int(c4))
	cols.append(int(c5))
	matrix.append(cols)
print(solve(matrix))


matrix = list((list(map(int, input().split())) for _ in range(5)))
i = j = 0
while sum(matrix[i]) == 0:
	i += 1
while matrix[i][j] == 0:
	j += 1
print(abs(i - 2) + abs(j - 2))


m = [[None] * 5] * 5
posx = 0
posy = 0
found = False
for i in range(5):
	m[i] = input().split(' ')
	if not found:
		for x in range(5):
			if m[i][x] == '1':
				posx = x
				posy = i
				found = True
				break
print(abs(posx - 2) + abs(posy - 2))


print([abs(i - 2) + abs(j - 2) for i in range(5) for (j, val) in enumerate(input().split()) if int(val)][0])


import sys
x = y = 0
for l in sys.stdin:
	y += 1
	x = 0
	for e in l.split():
		x += 1
		if e == '1':
			ans = abs(x - 3) + abs(y - 3)
print(ans)


(x, y) = (5, 5)
matrix = [list(map(int, input().split(None, 5)[:5])) for j in range(y)]
column = [2, 1, 0, 1, 2]
row = [2, 1, 0, 1, 2]
for i in range(0, x):
	for j in range(0, y):
		if matrix[i][j] == 1:
			print(row[i] + column[j])


(m, n) = (0, 0)
for i in range(1, 6):
	s = input().split()
	for j in range(5):
		if s[j] != '0':
			m = i
			n = j + 1
print(abs(3 - m) + abs(3 - n))


s1 = input().split(' ')
s2 = input().split(' ')
s3 = input().split(' ')
s4 = input().split(' ')
s5 = input().split(' ')
(l1, l2, l3, l4, l5) = ([], [], [], [], [])
r = 0
for a in s1:
	l1.append(int(a))
for a in s2:
	l2.append(int(a))
for a in s3:
	l3.append(int(a))
for a in s4:
	l4.append(int(a))
for a in s5:
	l5.append(int(a))
x = 0
z = 1
for a in l1:
	if a == 1:
		y = 1
		x = z
	else:
		z += 1
z = 1
for a in l2:
	if a == 1:
		y = 2
		x = z
	else:
		z += 1
z = 1
for a in l3:
	if a == 1:
		y = 3
		x = z
	else:
		z += 1
z = 1
for a in l4:
	if a == 1:
		y = 4
		x = z
	else:
		z += 1
z = 1
for a in l5:
	if a == 1:
		y = 5
		x = z
	else:
		z += 1
while x < 3:
	r += 1
	x += 1
while x > 3:
	r += 1
	x -= 1
while y < 3:
	r += 1
	y += 1
while y > 3:
	r += 1
	y -= 1
print(r)


a = []
for i in range(5):
	row = list(map(int, input().split()))
	a.append(row)
	for j in range(5):
		if a[i][j] == 1:
			I = i
			J = j
print(abs(I - 2) + abs(J - 2))


mat = [tuple(map(int, input().split())) for i in range(5)]
x1 = 0
for row in mat:
	x1 += 1
	if any(row):
		y1 = row.index(1)
		break
ind1 = (x1, y1 + 1)
ind2 = (3, 3)
print(abs(ind1[0] - ind2[0]) + abs(ind1[1] - ind2[1]))


def movefinder(x):
	switcher = {0: 2, 4: 2, 1: 1, 3: 1, 2: 0}
	return switcher[x]
mat = []
onein = ()
moves = 0
for i in range(5):
	tup = tuple(input().split())
	if '1' in tup:
		onein = (i, tup.index('1'))
	mat.append(tup)
moves += movefinder(onein[0])
moves += movefinder(onein[1])
print(moves)


n = 5
mat = []
for i in range(n):
	mat.append([int(x) for x in input().split()])
for i in range(n):
	found = False
	for j in range(n):
		if mat[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))
			found = True
			break
	if found == True:
		break


l = []
for i in range(5):
	l.append(input().split())
x = 0
y = 0
k = 0
for i in range(5):
	for b in range(5):
		if l[i][b] == '1':
			str = i + 1
			stol = b + 1
			break
if stol > 3:
	k += stol - 3
elif stol < 3:
	k += 3 - stol
if str < 3:
	k += 3 - str
elif str > 3:
	k += str - 3
print(k)


total = 0
for i in range(1, 6):
	array = list(input().replace(' ', ''))
	if array.count('1'):
		x = array.index('1') + 1
		y = i
		break
total += abs(y - 3)
total += abs(x - 3)
print(total)


from math import fabs
arr = [list(map(int, input().split())) for _ in range(5)]
total = 0
for (i, a) in enumerate(arr):
	if sum(a) == 1:
		total += fabs(2 - i)
		for (j, b) in enumerate(a):
			if b == 1:
				total += fabs(2 - j)
print(int(total))


import math
matrix = [[None] * 5] * 5
for i in range(5):
	matrix[i] = [int(num) for num in input().split()]
	if 1 in matrix[i]:
		r = i + 1
		for j in range(5):
			if matrix[i][j] == 1:
				c = j + 1
print(abs(c - 3) + abs(r - 3))


data = []
for i in range(5):
	data.append(input())
	if data[-1].find('1') != -1:
		row = i
		col = data[-1].find('1') // 2
print(abs(row - 2) + abs(col - 2))


row1 = [int(i) for i in input().split()]
row2 = [int(i) for i in input().split()]
row3 = [int(i) for i in input().split()]
row4 = [int(i) for i in input().split()]
row5 = [int(i) for i in input().split()]
rows = [row1, row2, row3, row4, row5]
cols = []
for i in range(5):
	col = []
	for j in range(5):
		col.append(rows[j][i])
	cols.append(col)
count = 0
for k in range(5):
	if 1 in rows[k]:
		count += abs(2 - rows[k].index(1))
for l in range(5):
	if 1 in cols[l]:
		count += abs(2 - cols[l].index(1))
print(count)


matrix = []
for i in range(5):
	matrix.append(input().split())
ind = 0
for i in range(5):
	c = matrix[i]
	for j in range(len(c)):
		if c[j] == '1':
			ind = [i, j]
c = 0
while ind != [2, 2]:
	if ind[0] > 2:
		ind[0] -= 1
		c += 1
	elif ind[0] < 2:
		ind[0] += 1
		c += 1
	if ind[1] > 2:
		ind[1] -= 1
		c += 1
	elif ind[1] < 2:
		ind[1] += 1
		c += 1
print(c)


matrix = [input(), input(), input(), input(), input()]
row = []
vertical_cost = 0
for i in range(5):
	if '1' in matrix[i]:
		vertical_cost = abs(2 - i)
		row = matrix[i].split()
for i in range(5):
	if row[i] == '1':
		horizontal_cost = abs(2 - i)
print(horizontal_cost + vertical_cost)


j = 0
for i in range(5):
	x = input().split()
	if '1' in x:
		z = i
		while j < 5:
			if x[j] != '1':
				j += 1
			else:
				break
if z != 2:
	z = 2 - z
	if z < 0:
		z = -z
else:
	z = 0
if j != 2:
	j = 2 - j
	if j < 0:
		j = -j
else:
	j = 0
print(z + j)


def matrix():
	lovely = []
	for i in range(5):
		beauty = list(map(int, input().split()))
		lovely.append(beauty)
	move = 0
	for i in range(5):
		if sum(lovely[i]) == 1:
			if i < 2:
				(lovely[i], lovely[i + 1]) = (lovely[i + 1], lovely[i])
				move += 1
			elif i > 2:
				j = i
				while j != 2:
					(lovely[j], lovely[j - 1]) = (lovely[j - 1], lovely[j])
					move += 1
					j -= 1
			else:
				break
		else:
			continue
	for j in range(len(lovely[2])):
		if lovely[2][j] == 1:
			if j < 2:
				(lovely[2][j], lovely[2][j + 1]) = (lovely[2][j + 1], lovely[2][j])
				move += 1
			elif j > 2:
				k = j
				while k != 2:
					(lovely[2][k], lovely[2][k - 1]) = (lovely[2][k - 1], lovely[2][k])
					move += 1
					k -= 1
		else:
			continue
	print(move)
matrix()


a = input()
b = input()
c = input()
d = input()
e = input()
if '1' in a or '1' in e:
	x = 2
elif '1' in b or '1' in d:
	x = 1
elif '1' in c:
	x = 0
if '1' in a:
	y = a.find('1')
	if y == 0 or y == 8:
		p = 2
	elif y == 2 or y == 6:
		p = 1
	elif y == 4:
		p = 0
elif '1' in b:
	y = b.find('1')
	if y == 0 or y == 8:
		p = 2
	elif y == 2 or y == 6:
		p = 1
	elif y == 4:
		p = 0
elif '1' in c:
	y = c.find('1')
	if y == 0 or y == 8:
		p = 2
	elif y == 2 or y == 6:
		p = 1
	elif y == 4:
		p = 0
elif '1' in d:
	y = d.find('1')
	if y == 0 or y == 8:
		p = 2
	elif y == 2 or y == 6:
		p = 1
	elif y == 4:
		p = 0
if '1' in e:
	y = e.find('1')
	if y == 0 or y == 8:
		p = 2
	elif y == 2 or y == 6:
		p = 1
	elif y == 4:
		p = 0
print(x + p)


import sys
for i in range(1, 6):
	line = sys.stdin.readline().strip().split()
	if '1' in line:
		for j in range(0, 5):
			if line[j] == '1':
				print(abs(j - 2) + abs(i - 3))


a = list()
for i in range(5):
	s = input()
	a.append(s.split(' '))
conti = 0
for i in a:
	conti += 1
	contj = 0
	for j in i:
		contj += 1
		if j == '1':
			print(abs(3 - conti) + abs(3 - contj))


matrix = []
for i in range(5):
	matrix.append(input())
for j in range(5):
	if matrix[j] == '0 0 0 0 0':
		continue
	else:
		if j <= 2:
			x = 2 - j
		else:
			x = j - 2
		if matrix[j] == '0 0 1 0 0':
			y = 0
		elif matrix[j] == '0 0 0 0 1' or matrix[j] == '1 0 0 0 0':
			y = 2
		else:
			y = 1
print(x + y)


(rowContainingOne, columnContainingOne) = (0, 0)
for i in range(5):
	row = list(map(int, input().split()))
	for j in range(5):
		if row[j] == 1:
			columnContainingOne = j + 1
			rowContainingOne = i + 1
print(abs(3 - rowContainingOne) + abs(3 - columnContainingOne))


matrix = []
for i in range(5):
	matrix.append([int(i) for i in input().split()])
for i in range(5):
	if 1 in matrix[i]:
		x = matrix[i].index(1)
		print(abs(2 - x) + abs(2 - i))
		break


def findXY():
	for x in range(5):
		l = [int(k) for k in input().split(' ')]
		for y in range(5):
			if l[y] == 1:
				return (x, y)
(x, y) = findXY()
print(abs(2 - x) + abs(2 - y))


for i in range(5):
	temp = [int(j) for j in input().split()]
	if 1 in temp:
		col = temp.index(1)
		row = i
print(abs(2 - row) + abs(2 - col))


from math import *

def vind_pos():
	for rij_num in range(1, 6):
		rij = [int(cel) for cel in input().split()]
		for kolom_num in range(1, 6):
			if rij[kolom_num - 1] == 1:
				return (rij_num, kolom_num)
(rij, kolom) = vind_pos()
print(abs(rij - 3) + abs(kolom - 3))


l = [[0] * 5] * 5
flag = False
for i in range(5):
	l[i] = list(map(int, input().split()))
for i in range(5):
	for j in range(5):
		if l[i][j] is 1:
			flag = True
			break
	if flag:
		break
print(abs(2 - i) + abs(2 - j))


line = []
for x in range(1, 6):
	line += input().split()
for i in range(len(line)):
	if '1' == line[i]:
		print(abs(i % 5 - 2) + abs(i // 5 - 2))


for i in range(5):
	st = input()
	if '1' in st:
		print(abs(st.replace(' ', '').index('1') - 2) + abs(i - 2))
		exit()


M = [0]
flag = 0
count = 0
for i in range(5):
	R = input()
	r = R.split()
	M.append(r)
for i in range(1, 6):
	for a in range(5):
		if M[i][a] == '1':
			row = i
			col = a + 1
			flag = 1
			break
	if flag == 1:
		break
count += abs(row - 3)
count += abs(col - 3)
print(count)


s = [2, 1, 0, 1, 2]
for j in s:
	x = input()
	if '1' in x:
		print(j + s[x.find('1') // 2])


def main():
	matrix = []
	index = [0, 0]
	for j in range(5):
		row = input().split()
		row = [int(i) for i in row]
		matrix.append(row)
		if 1 in row:
			index[0] = j + 1
			index[1] = row.index(1) + 1
	print(abs(index[0] - 3) + abs(index[1] - 3))
main()


s1 = input()
list1 = s1.split()
for i in range(len(list1)):
	list1[i] = int(list1[i])
if list1.count(0) == 4:
	a = 1
	b = list1.index(1) + 1
s2 = input()
list2 = s2.split()
for i in range(len(list2)):
	list2[i] = int(list2[i])
if list2.count(0) == 4:
	a = 2
	b = list2.index(1) + 1
s3 = input()
list3 = s3.split()
for i in range(len(list3)):
	list3[i] = int(list3[i])
if list3.count(0) == 4:
	a = 3
	b = list3.index(1) + 1
s4 = input()
list4 = s4.split()
for i in range(len(list4)):
	list4[i] = int(list4[i])
if list4.count(0) == 4:
	a = 4
	b = list4.index(1) + 1
s5 = input()
list5 = s5.split()
for i in range(len(list5)):
	list5[i] = int(list5[i])
if list5.count(0) == 4:
	a = 5
	b = list5.index(1) + 1
s = abs(3 - a) + abs(3 - b)
print(s)


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
l = 0
if 1 in a:
	l = l + 2
	k = a
if 1 in b:
	l = l + 1
	k = b
if 1 in c:
	l = l
	k = c
if 1 in d:
	l = l + 1
	k = d
if 1 in e:
	l = l + 2
	k = e
for i in range(5):
	if k[i] == 1:
		m = i
if m <= 2:
	m = 2 - m
if m > 2:
	m = m - 2
print(m + l)


matrix = []
row_num = 0
count = 0
for i in range(5):
	matrix = input()
	if '1' in matrix:
		row_num = i + 1
		break
	else:
		row_num = row_num + 1
if '1' in matrix:
	colum_num = matrix.find('1')
	if row_num == 1 or row_num == 5:
		count = count + 2
	if row_num == 2 or row_num == 4:
		count = count + 1
	if colum_num == 0 or colum_num == 8:
		count = count + 2
	if colum_num == 2 or colum_num == 6:
		count = count + 1
print(count)


for i in range(5):
	l = [s for s in input().split(' ')]
	if '1' in l:
		row = i
		column = l.index('1')
print(abs(row - 2) + abs(column - 2))


a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a4 = list(map(int, input().split()))
a5 = list(map(int, input().split()))
for i in a1:
	if i == 1:
		x = 2 - a1.index(1)
		y = 2
		if x >= 0:
			print(x + y)
		else:
			print(-x + y)
for i in a2:
	if i == 1:
		x = 2 - a2.index(1)
		y = 1
		if x >= 0:
			print(x + y)
		else:
			print(-x + y)
for i in a3:
	if i == 1:
		x = 2 - a3.index(1)
		if x >= 0:
			print(x)
		else:
			print(-x)
for i in a4:
	if i == 1:
		x = 2 - a4.index(1)
		y = 1
		if x >= 0:
			print(x + y)
		else:
			print(-x + y)
for i in a5:
	if i == 1:
		x = 2 - a5.index(1)
		y = 2
		if x >= 0:
			print(x + y)
		else:
			print(-x + y)


for l in range(5):
	x = list(map(int, input().split()))
	for c in range(5):
		if x[c] == 1:
			x1 = abs(c - 2)
			y1 = abs(l - 2)
print(x1 + y1)


from sys import stdin, setrecursionlimit
from collections import deque
input = stdin.readline
setrecursionlimit(int(200000.0))

def getstr():
	return input()[:-1]

def getint():
	return int(input())

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

def getint1():
	return list(map(lambda x: int(x) - 1, input().split()))
jn = lambda x, l: x.join(map(str, l))
MOD = 10 ** 9 + 7
(y, n) = ('YES', 'NO')

def solve():
	l = []
	row = 0
	col = 0
	for i in range(5):
		x = list(map(int, input().strip().split(' ')))
		if 1 in x:
			row = i
			col = x.index(1)
		l.append(x)
	print(abs(2 - row) + abs(2 - col))
solve()


testes = []
linhas = []
beauty = [2, 2]
for i in range(5):
	testes.append(input())
for i in range(len(testes)):
	linhas.append(testes[i].split())
for i in range(5):
	if str(1) in linhas[i]:
		suba = [str(linhas[i].index(str(1))), str(i)]
x = int(suba[0]) - beauty[0]
y = int(suba[1]) - beauty[1]
moves = abs(x) + abs(y)
print(moves)


x = 2
y = 2
for i in range(5):
	for (j, val) in enumerate(input().split()):
		if val == '1':
			(x, y) = (i, j)
print(abs(x - 2) + abs(y - 2))


c = 0
list1 = []
a = 0
z = 0
b = 0
while c <= 4:
	f = input()
	f = f.split(' ')
	c += 1
	if '1' in f:
		for p in f:
			b += 1
			if p == '1':
				s = abs(c - 3)
				m = abs(b - 3)
				z = s + m
print(z)


def max_n():
	x = 0
	y = 0
	n = 0
	while n < 5:
		lst = list(map(int, input().split()))
		if 1 in lst:
			temp = lst.index(1)
			x = abs(2 - temp)
			y = abs(2 - n)
		n += 1
	print(x + y)
max_n()


a = [input().split(), input().split(), input().split(), input().split(), input().split()]
done = False
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			x = [i + 1, j + 1]
			done = True
			break
	if done:
		break
print(abs(3 - x[0]) + abs(3 - x[1]))


arr = []
for i in range(5):
	arr.append([int(x) for x in input().split()])
for (i, row) in enumerate(arr):
	for (j, element) in enumerate(row):
		if element == 1:
			print(abs(i - 2) + abs(j - 2))


mtx = []
crdX = 0
crdY = 0
for i in range(5):
	mtx.append(input().split(' '))
	if mtx[i].count('1'):
		crdX = mtx[i].index('1')
		crdY = i
res = abs(crdX - 2) + abs(crdY - 2)
print(res)


from pprint import pprint
a = [[int(i) for i in input().split()] for j in range(1, 6)]
for i in a:
	for j in i:
		if j == 1:
			row = a.index(i)
			column = i.index(j)
			position = a[row][column]
			break
row = row + 1
column = column + 1
adj = abs(row - 3) + abs(column - 3)
print(adj)


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()))
k = c[0] + c[1] + c[2] + c[3] + c[4]
x = 0
while k < 1:
	for i in range(5):
		if a[i] == 1:
			a[i] = 0
			b[i] = 1
			x = x + 1
		if b[i] == 1:
			b[i] = 0
			c[i] = 1
			x = x + 1
		if d[i] == 1:
			d[i] = 0
			c[i] = 1
			x = x + 1
		if e[i] == 1:
			e[i] = 0
			d[i] = 1
			x = x + 1
		k = c[0] + c[1] + c[2] + c[3] + c[4]
while c[2] != 1:
	for i in range(len(c)):
		if c[i] == 1:
			if i < 2:
				c[i] = 0
				c[i + 1] = 1
				x = x + 1
			if i > 2:
				c[i] = 0
				c[i - 1] = 1
				x = x + 1
print(x)


graph = []
for _ in range(5):
	str_arr = input().split(' ')
	graph.append(str_arr)
i_index = 0
j_index = 0
for i in range(5):
	for j in range(5):
		if graph[i][j] == '1':
			i_index = i
			j_index = j
print(abs(i_index - 2) + abs(j_index - 2))


r = []
c = [0, 0, 0, 0, 0]
for i in range(5):
	i = input().strip()
	i_ = list(map(int, i.split()))
	for i in range(5):
		c[i] = c[i] + i_[i]
	r.append(sum(i_))
res = abs(2 - r.index(1)) + abs(2 - c.index(1))
print(res)


r = 0
mid = 2
while r < 5:
	row = list(map(int, input().split()))
	if 1 in row:
		col = row.index(1)
		break
	r += 1
ans = abs(r - mid) + abs(col - mid)
print(ans)


g = 0
for k in range(1, 6):
	g += 1
	s = input().split(' ')
	if '1' in s:
		s1 = s
		i = g
j = s1.index('1') + 1
id = abs(i - 3)
jd = abs(j - 3)
print(id + jd)


for i in range(5):
	row = input().split()
	if '1' in row:
		y_move = abs(i - 2)
		x_move = abs(row.index('1') - 2)
		print(y_move + x_move)
		break


(i, j) = (0, 0)
for row in range(5):
	x = list(map(int, input().split(' ')))
	for (col, a) in enumerate(x):
		if a:
			j = col
			i = row
print(abs(i - 2) + abs(j - 2))


print(sum((abs(x - 2) + abs(y - 2) for x in range(5) for (y, v) in enumerate(input().split()) if int(v))))


l = [0] * 25
for a in [0, 5, 10, 15, 20]:
	(l[a], l[a + 1], l[a + 2], l[a + 3], l[a + 4]) = input().split()
index = l.index('1')
for i in range(1, 6):
	for j in range(1, 6):
		if 5 * (i - 1) + (j - 1) == index:
			sum = abs(3 - i) + abs(3 - j)
			print(sum)


flag = False
pos_col = None
pos_row = None
for i in range(5):
	n = list(map(int, input().rstrip().split()))
	for j in range(5):
		if n[j] == 1:
			pos_col = j
			flag = True
			break
	if flag:
		pos_row = i
		break
goal_row = 2
goal_col = 2
result = abs(goal_row - pos_row) + abs(goal_col - pos_col)
print(result)


one = list(input())
two = list(input())
three = list(input())
four = list(input())
five = list(input())
t = 0
while True:
	if one[t] != '1':
		t = t + 1
		if t == 9:
			break
	else:
		num = abs((4 - t) / 2) + 2
		break
t = 0
while True:
	if two[t] != '1':
		t = t + 1
		if t == 9:
			break
	else:
		num = abs((4 - t) / 2) + 1
		break
t = 0
while True:
	if three[t] != '1':
		t = t + 1
		if t == 9:
			break
	else:
		num = abs((4 - t) / 2)
		break
t = 0
while True:
	if four[t] != '1':
		t = t + 1
		if t == 9:
			break
	else:
		num = abs((4 - t) / 2) + 1
		break
t = 0
while True:
	if five[t] != '1':
		t = t + 1
		if t == 9:
			break
	else:
		num = abs((4 - t) / 2) + 2
		break
print(int(num))


matrix = []
matrix.append(list(map(int, input().split())))
matrix.append(list(map(int, input().split())))
matrix.append(list(map(int, input().split())))
matrix.append(list(map(int, input().split())))
matrix.append(list(map(int, input().split())))
for mat in matrix:
	if mat.count(1) != 0:
		(i, j) = (matrix.index(mat), mat.index(1))
BESTI = 2
BESTJ = 2
k = 0
if i > BESTI:
	k += i - BESTI
else:
	k += BESTI - i
if j > BESTJ:
	k += j - BESTI
else:
	k += BESTJ - j
print(k)


a = list()
for i in range(5):
	x = list(map(int, input().split()))
	a.append(x)
for i in range(len(a)):
	for j in range(len(a)):
		if a[i][j] == 1:
			x = i
			y = j
count1 = 0
for i in range(len(a)):
	if x > 2:
		count1 += 1
		x -= 1
	elif x < 2:
		count1 += 1
		x += 1
	elif x == 2:
		break
count2 = 0
for i in range(len(a)):
	if y > 2:
		count2 += 1
		y -= 1
	elif y < 2:
		count2 += 1
		y += 1
	elif y == 2:
		break
count = count2 + count1
print(count)


a = []
for i in range(5):
	b = []
	b = input().split(' ')
	a.append(b)
pos = []
p = 0
for i in a:
	if '1' in i:
		p1 = 0
		for j in i:
			if j == '1':
				pos.append(p)
				pos.append(p1)
			p1 += 1
	p += 1
pos[0] = int(pos[0]) + 1
pos[1] = int(pos[1]) + 1
y = abs(3 - pos[1])
x = abs(3 - pos[0])
print(x + y)


l = []
for i in range(5):
	l.append(list(map(int, input().split())))
m = 0
n = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			m = i + 1
			n = j + 1
			break
print(abs(m - 3) + abs(n - 3))


m = []
for i in range(5):
	m.append(list(map(int, input().split())))
door = False
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			door = True
			break
	if door:
		break
print(abs(i - 2) + abs(j - 2))


r_1 = input().split()
r_2 = input().split()
r_3 = input().split()
r_4 = input().split()
r_5 = input().split()
for i in r_1:
	if i == '1':
		a = r_1.index(i) + 1
		if a == 1 or a == 5:
			print(4)
		if a == 2 or a == 4:
			print(3)
		if a == 3:
			print(2)
for i in r_2:
	if i == '1':
		a = r_2.index(i) + 1
		if a == 1 or a == 5:
			print(3)
		if a == 2 or a == 4:
			print(2)
		if a == 3:
			print(1)
for i in r_3:
	if i == '1':
		a = r_3.index(i) + 1
		if a == 1 or a == 5:
			print(2)
		if a == 2 or a == 4:
			print(1)
		if a == 3:
			print(0)
for i in r_4:
	if i == '1':
		a = r_4.index(i) + 1
		if a == 1 or a == 5:
			print(3)
		if a == 2 or a == 4:
			print(2)
		if a == 3:
			print(1)
for i in r_5:
	if i == '1':
		a = r_5.index(i) + 1
		if a == 1 or a == 5:
			print(4)
		if a == 2 or a == 4:
			print(3)
		if a == 3:
			print(2)


l = []
f = False
i = j = 0
for k in range(5):
	arr = list(map(int, input().split()))
	l.append(arr)
while i < 5:
	j = 0
	while j < 5:
		if l[i][j] == 1:
			f = True
			break
		j += 1
	if f:
		break
	i += 1
print(abs(3 - (i + 1)) + abs(3 - (j + 1)))


def main():
	x: int = 0
	y: int = 0
	for i in range(5):
		aux = input().split()
		if '1' in aux:
			y = i
			x = aux.index('1')
	print(abs(y - 2) + abs(x - 2))
main()


a = input()
b = input()
c = input()
d = input()
e = input()
if '1' in a:
	row = 1
	column = ''.join(a.split()).find('1') + 1
elif '1' in b:
	row = 2
	column = ''.join(b.split()).find('1') + 1
elif '1' in c:
	row = 3
	column = ''.join(c.split()).find('1') + 1
elif '1' in d:
	row = 4
	column = ''.join(d.split()).find('1') + 1
else:
	row = 5
	column = ''.join(e.split()).find('1') + 1
print(int(abs(row - 3) + abs(column - 3)))


import math
str1 = input().split()
str2 = input().split()
str3 = input().split()
str4 = input().split()
str5 = input().split()
if '1' in str1:
	x = 2
	n = str1.index('1') + 1
if '1' in str2:
	x = 1
	n = str2.index('1') + 1
if '1' in str3:
	x = 0
	n = str3.index('1') + 1
if '1' in str4:
	x = 1
	n = str4.index('1') + 1
if '1' in str5:
	x = 2
	n = str5.index('1') + 1
c = math.fabs(n - 3)
x += c
print('{0:.0f}'.format(x))


(i, j) = (0, 0)
for i in range(5):
	try:
		j = input().split().index('1')
	except ValueError:
		j = -1
	if j > -1:
		break
print(abs(j - 2) + abs(i - 2))


a = []
d = [[4, 3, 2, 3, 4], [3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3], [4, 3, 2, 3, 4]]
for i in range(5):
	b = list(map(int, input().split()))
	a.append(b)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(d[i][j])
			break


def seperateints(x):
	k = ''
	l = []
	for i in x:
		if i == ' ':
			l.append(int(k))
			k = ''
			continue
		k = k + i
	l.append(int(k))
	return l
l = []
for i in range(5):
	l.append(seperateints(input()))
r = 0
for i in range(len(l)):
	for k in range(len(l[i])):
		if l[i][k] == 1:
			r = i + 1
			c = k + 1
			break
	if r > 0:
		break
if r > 3:
	nn = r - 3
else:
	nn = 3 - r
if c > 3:
	nn += c - 3
else:
	nn += 3 - c
print(nn)


def count():
	index = [0, 0]
	arr = list()
	for i in range(5):
		temp = list(map(int, input().rstrip().split()))
		if 1 in temp:
			index[0] = i
			index[1] = temp.index(1)
	print(abs(index[0] - 2) + abs(index[1] - 2))
count()


line1 = list(input().split(' '))
line2 = list(input().split(' '))
line3 = list(input().split(' '))
line4 = list(input().split(' '))
line5 = list(input().split(' '))
col1 = [line1[0], line2[0], line3[0], line4[0], line5[0]]
col2 = [line1[1], line2[1], line3[1], line4[1], line5[1]]
col3 = [line1[2], line2[2], line3[2], line4[2], line5[2]]
col4 = [line1[3], line2[3], line3[3], line4[3], line5[3]]
col5 = [line1[4], line2[4], line3[4], line4[4], line5[4]]
lines = [line1, line2, line3, line4, line5]
cols = [col1, col2, col3, col4, col5]
li = None
ci = None
for l in lines:
	if '1' in l:
		ci = l.index('1') + 1
for c in cols:
	if '1' in c:
		li = c.index('1') + 1
s1 = abs(3 - li)
s2 = abs(3 - ci)
print(s1 + s2)


(a1, a2, a3, a4, a5) = ([int(s) for s in input().split()], [int(s) for s in input().split()], [int(s) for s in input().split()], [int(s) for s in input().split()], [int(s) for s in input().split()])
a = [a1, a2, a3, a4, a5]
k = 0
ni = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			ni = i
if ni > 2:
	k += ni - 2
else:
	k += 2 - ni
nj = 0
for i in range(5):
	if a[ni][i] == 1:
		nj = i
if nj > 2:
	k += nj - 2
else:
	k += 2 - nj
print(k)


listt = []
t = 0
for i in range(5):
	lis = list(map(int, input().split()))
	listt.append(t)
	if 1 in lis and t == 0:
		col = lis.index(1)
		row = i
		t = 1
print(abs(2 - col) + abs(2 - row))


import sys
matrix = [list(map(int, input().split())) for _ in range(5)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
			sys.exit(0)


i = 0
j = 0
for k1 in range(5):
	a = list(map(int, input().split()))
	for k2 in range(5):
		if a[k2] == 1:
			i = k1
			j = k2
print(abs(i - 2) + abs(j - 2))


where_is_1 = []
for i in range(5):
	a = input()
	a = a.split()
	for j in range(5):
		if a[j] == '1':
			where_is_1.append(j)
			where_is_1.append(i)
print(abs(where_is_1[0] - 2) + abs(where_is_1[1] - 2))


matrix = []
for i in range(5):
	ar = list(map(int, input().split()))
	matrix.append(ar)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			a = i
			b = j
			break
s = abs(2 - a) + abs(2 - b)
print(s)


row = 0
col = 0
for i in range(5):
	each = input().strip().split(' ')
	for j in range(5):
		if each[j] == '1':
			(row, col) = (i, j)
			break
ans = abs(row - 2) + abs(col - 2)
print(ans)


matrix = []
for i in range(5):
	a = list(map(int, input().split()))
	matrix.append(a)
for j in range(5):
	for k in range(5):
		if matrix[j][k] == 1:
			break
	if matrix[j][k] == 1:
		break
move = abs(3 - j - 1) + abs(3 - k - 1)
print(move)


l1 = input().split()
l2 = input().split()
l3 = input().split()
l4 = input().split()
l5 = input().split()
if '1' in l1:
	i = 0
	j = l1.index('1')
if '1' in l2:
	i = 1
	j = l2.index('1')
if '1' in l3:
	i = 2
	j = l3.index('1')
if '1' in l4:
	i = 3
	j = l4.index('1')
if '1' in l5:
	i = 4
	j = l5.index('1')
print(abs(2 - int(i)) + abs(2 - int(j)))


for i in range(5):
	row = input().split()
	if '1' in row:
		num_row = i + 1
		real_row = row
add_1 = abs(num_row - 3)
num_column = real_row.index('1') + 1
add_2 = abs(num_column - 3)
print(add_1 + add_2)


M = []
M1 = list(map(int, input().split()))
M.append(M1)
M2 = list(map(int, input().split()))
M.append(M2)
M3 = list(map(int, input().split()))
M.append(M3)
M4 = list(map(int, input().split()))
M.append(M4)
M5 = list(map(int, input().split()))
M.append(M5)
if M3[2] == 1:
	print('0')
else:
	count = 0
	for i in range(5):
		for j in range(5):
			if M[i][j] == 1:
				count += abs(2 - i) + abs(2 - j)
	print(count)


matriks = [[0 for i in range(5)] for j in range(5)]
px = 0
py = 0
for i in range(5):
	matriks[i] = list(map(int, input().split()))
for i in range(5):
	for j in range(5):
		if matriks[i][j] == 1:
			py = i + 1
			px = j + 1
			break
hasil = abs(3 - py) + abs(3 - px)
print(hasil)


y = 0
xx = 0
for z in range(5):
	x = list(map(int, input().split()))
	if 1 in x:
		y = z + 1
		xx = x.index(1) + 1
total = abs(3 - y) + abs(3 - xx)
print(total)


import itertools as it
matrix = [[int(x) for x in input().split()] for _ in range(5)]
for (i, j) in it.product(range(5), repeat=2):
	if matrix[i][j] == 1:
		break
print(abs(i - 2) + abs(j - 2))


t = 0
for i in range(5):
	a = input().split()
	if a[0] == '1':
		t = t + 2
		m = 3 - i - 1
		if m < 0:
			m = m * -1
		t = t + m
	elif a[1] == '1':
		t = t + 1
		m = 3 - i - 1
		if m < 0:
			m = m * -1
		t = t + m
	if a[2] == '1':
		m = 3 - i - 1
		if m < 0:
			m = m * -1
		t = t + m
	if a[3] == '1':
		t = t + 1
		m = 3 - i - 1
		if m < 0:
			m = m * -1
		t = t + m
	if a[4] == '1':
		t = t + 2
		m = 3 - i - 1
		if m < 0:
			m = m * -1
		t = t + m
print(t)


arr = []
one_arr = []
one_i_index = 0
one_j_index = 0
numOfMoves = 0
for n in range(5):
	(a, b, c, d, e) = map(int, input().split())
	arr.append([a, b, c, d, e])
for i in range(len(arr)):
	if sum(arr[i]) == 1:
		one_i_index = i
		one_arr = arr[i]
for j in range(len(one_arr)):
	if one_arr[j] == 1:
		one_j_index = j
numOfMoves = abs(one_i_index - 2) + abs(one_j_index - 2)
print(numOfMoves)


List = []
x = 0
y = 0
for i in range(5):
	row = list(map(int, input().split()))
	List.append(row)
for i in range(5):
	for j in range(5):
		if List[i][j] == 1:
			x = j
			y = i
			break
counterX = abs(x - 2)
counterY = abs(y - 2)
print(counterX + counterY)


from array import array
from sys import stdin
import bisect

def scan_gen():
	for line in stdin:
		yield from iter(line.split())
scan = scan_gen()

def nint():
	return int(next(scan))

def nintk(k):
	return tuple((nint() for _ in range(k)))

def nfloat():
	return float(next(scan))

def intar_init(size):
	return array('i', [0]) * size

def intar(size=None):
	if size == None:
		size = nint()
	arr = intar_init(size)
	for x in range(size):
		arr[x] = nint()
	return arr
m = [intar(5) for _ in range(5)]
for i in range(5):
	for j in range(5):
		if m[i][j]:
			print(abs(2 - i) + abs(2 - j))


n = 5
for i in range(1, n + 1):
	j = input().split(' ')
	if '1' in j:
		j = j.index('1') + 1
		break
if i >= 3:
	i = i - 3
else:
	i = 3 - i
if j >= 3:
	j = j - 3
else:
	j = 3 - j
print(i + j)


def beautiful_matrix():
	for idx in range(5):
		row_input = list(map(int, input().split()))
		if 1 in row_input:
			row = idx + 1
			for (idx1, elem) in enumerate(row_input):
				if elem == 1:
					column = idx1 + 1
	output = abs(3 - row) + abs(3 - column)
	print(output)
	return
beautiful_matrix()


import math
line = 0
while line < 5:
	line += 1
	lin = input().split()
	if '1' in lin:
		o = math.fabs(line - 3) + math.fabs(lin.index('1') - 2)
print(int(o))


for i in range(1, 6):
	list_list = list(input().split())
	if '1' in list_list:
		row = i
		colume = list_list.index('1') + 1
print(abs(row - 3) + abs(colume - 3))


res = 0
for i in range(5):
	l = list(map(int, input().split()))
	j = 0
	while j < len(l):
		if l[j] == 1:
			res = abs(j - 2) + abs(i - 2)
		j = j + 1
print(res)


mat = []
found = 0
for i in range(5):
	a = []
	a = list(map(int, input().split()))[:5]
	mat.append(a)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			u = i
			d = j
			found = 1
			break
	if found == 1:
		break
k = 0
print(abs(u - 2) + abs(d - 2))


n = list()
i = 0
while i < 5:
	s = str(input())
	m = list(s.split(' '))
	n.append(m)
	i += 1
for i in range(0, 5):
	for j in range(0, 5):
		if n[i][j] == '1':
			print(abs(2 - j) + abs(2 - i))


mat = []
for i in range(5):
	l = list(map(int, input().split()))
	mat.append(l)
for i in range(5):
	if 1 in mat[i]:
		ith = i
		jth = mat[i].index(1)
print(abs(2 - ith) + abs(2 - jth))


a = input()
b = input()
c = input()
d = input()
e = input()
if '1' in a:
	x = 2
	w = a
if '1' in b:
	x = 1
	w = b
if '1' in d:
	x = 1
	w = d
if '1' in c:
	w = c
	x = 0
if '1' in e:
	x = 2
	w = e
n = 0
for q in w.split():
	n = n + 1
	if q == '1':
		break
print(x + abs(3 - n))


class Main:
	rows = []
	for i in range(0, 5):
		rows.append(input())
	(r, c) = (0, 0)
	for i in range(0, 5):
		if '1' in rows[i]:
			r = i + 1
	row_1 = rows[r - 1].split(' ')
	c = row_1.index('1') + 1
	moves = abs(3 - r) + abs(3 - c)
	print(moves)
Main()


l = [[4, 3, 2, 3, 4], [3, 2, 1, 2, 3], [2, 1, 0, 1, 2]]
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
e = list(map(int, input().split()))
f = list(map(int, input().split()))
if 1 in b:
	a = b.index(1)
	print(l[0][a])
elif 1 in c:
	a = c.index(1)
	print(l[1][a])
elif 1 in d:
	a = d.index(1)
	print(l[2][a])
if 1 in e:
	a = e.index(1)
	print(l[1][a])
if 1 in f:
	a = f.index(1)
	print(l[0][a])


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			r = i + 1
			c = j + 1
			break
res = abs(3 - r) + abs(3 - c)
print(res)


l = list()
for i in range(5):
	k = [int(x) for x in input('').split()]
	l.append(k)
flag = 0
for i in range(len(l)):
	count = 0
	for k in l[i]:
		if k == 1:
			w = i
			c = count
			flag = 1
			break
		count += 1
	if flag == 1:
		break
a = abs(2 - w)
b = abs(2 - c)
print(a + b)


def main():
	row1 = input().split()
	row2 = input().split()
	row3 = input().split()
	row4 = input().split()
	row5 = input().split()
	matrix = [row1, row2, row3, row4, row5]
	for i in range(5):
		for j in range(5):
			if int(matrix[i][j]) == 1:
				print(abs(i - 2) + abs(j - 2))
main()


row = 1
for i in range(1, 6):
	r = input().split()
	if '1' in r:
		print(abs(3 - row) + abs(3 - (r.index('1') + 1)))
		break
	row += 1


import math

def getcoord(matrix):
	coord = [-1, -1]
	i = 1
	j = 1
	for rows in matrix:
		j = 1
		for columns in rows:
			if columns == 1:
				coord[0] = i
				coord[1] = j
				return coord
			j += 1
		i += 1
i = 0
matrix = []
while i < 5:
	matrix.append([int(x) for x in input().split(' ')])
	i += 1
coord = getcoord(matrix)
print(int(math.fabs(coord[0] - 3) + math.fabs(coord[1] - 3)))


for i in range(5):
	row = input().split()
	try:
		ind = row.index('1')
		print(abs(i - 2) + abs(ind - 2))
	except ValueError:
		continue


li = []
for i in range(5):
	li.append([int(x) for x in input().split()])
for (i, temp) in enumerate(li):
	for (j, value) in enumerate(temp):
		if value == 1:
			print(abs(3 - (j + 1)) + abs(3 - (i + 1)))
			break


matrix = []
moves = 0
for i in range(5):
	row = input()
	if '1' in row:
		req = i
		moves = abs(2 - i)
	matrix.append(row)
moves += abs(2 - matrix[req].split().index('1'))
print(moves)


def f(x):
	if x >= 0:
		return x
	else:
		return -x
a = []
for i in range(0, 5):
	a.append(input())
for m in range(0, 5):
	b = a[m].split()
	for n in range(0, 5):
		c = int(b[n])
		if c == 1:
			print(f(m - 2) + f(n - 2))


for i in range(1, 6):
	row = input()
	for j in range(0, 9, 2):
		if row[j] == '1':
			print(int(abs(i - 3) + abs(j / 2 + 1 - 3)))


mat = [0, 0, 0, 0, 0]
c1 = 0
c2 = 0
for i in range(5):
	mat[i] = input().split()
for i in range(5):
	for j in range(5):
		if mat[i][j] == '1':
			c1 = i
			c2 = j
print(abs(2 - c1) + abs(2 - c2))


def main():
	for k in range(5):
		lis = list(input().split())
		if '1' in lis:
			k += 1
			break
	j = 0
	for l in lis:
		j += 1
		if l == '1':
			break
	out = abs(j - 3) + abs(k - 3)
	print(out)
main()


from sys import stdin
the_matrix = []
x = 0
y = 0
for i in range(5):
	matrix_row = stdin.readline().strip().split()
	if '1' in matrix_row:
		x = i
		y = int(matrix_row.index('1'))
	the_matrix.append(matrix_row)
print(abs(2 - x) + abs(2 - y))


print([abs(n - 2) + abs(i - 2) for (i, n) in [(input().replace(' ', '').find('1'), n) for n in range(5)] if i != -1][0])


num = 0
for i in range(5):
	t = list(input())
	for a in range(4):
		t.remove(' ')
	if '1' in t:
		b = int(t.index('1'))
		c = b - 2
		z = i - 2
		num = abs(c) + abs(z)
print(num)


def solve():
	one = list(map(int, input().split()))
	two = list(map(int, input().split()))
	three = list(map(int, input().split()))
	four = list(map(int, input().split()))
	five = list(map(int, input().split()))
	if 1 in one:
		row_num = 1
		idx = one.index(1)
	elif 1 in two:
		row_num = 2
		idx = two.index(1)
	elif 1 in three:
		row_num = 3
		idx = three.index(1)
	elif 1 in four:
		row_num = 4
		idx = four.index(1)
	else:
		row_num = 5
		idx = five.index(1)
	ans = abs(row_num - 3)
	if idx == 0:
		print(ans + 2)
	elif idx == 1:
		print(ans + 1)
	elif idx == 2:
		print(ans)
	elif idx == 3:
		print(ans + 1)
	elif idx == 4:
		print(ans + 2)
solve()


stopY = int(0)
stopX = int(0)
moveY = int(0)
matrix = []
for i in range(5):
	col = input().split()
	col = ''.join(col)
	if col != '00000':
		stopY = i + 1
		string = col
stringList = list(string)
for i in range(5):
	if stringList[i] == '1':
		stopX = i + 1
moveX = abs(3 - stopX)
moveY = abs(3 - stopY)
s = moveX + moveY
print(s)


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

def getIndex(matrix: list):
	index = (0, 0)
	for x in range(len(matrix)):
		if matrix[x].__contains__(1):
			index = (x, matrix[x].index(1))
	return index
index = getIndex(matrix)
while matrix[2][2] != 1:
	if index[0] > 2:
		(matrix[index[0]][index[1]], matrix[index[0] - 1][index[1]]) = (matrix[index[0] - 1][index[1]], matrix[index[0]][index[1]])
		index = (index[0] - 1, index[1])
		moves += 1
	elif index[0] < 2:
		(matrix[index[0]][index[1]], matrix[index[0] + 1][index[1]]) = (matrix[index[0] + 1][index[1]], matrix[index[0]][index[1]])
		index = (index[0] + 1, index[1])
		moves += 1
	if index[1] > 2:
		(matrix[index[0]][index[1]], matrix[index[0]][index[1] - 1]) = (matrix[index[0]][index[1] - 1], matrix[index[0]][index[1]])
		index = (index[0], index[1] - 1)
		moves += 1
	elif index[1] < 2:
		(matrix[index[0]][index[1]], matrix[index[0]][index[1] + 1]) = (matrix[index[0]][index[1] + 1], matrix[index[0]][index[1]])
		index = (index[0], index[1] + 1)
		moves += 1
print(moves)


def matrix():
	lista = []
	for i in range(5):
		lista.append(list(map(int, input().split())))
	wynik = 0
	for x in range(5):
		for y in range(5):
			if lista[x][y] == 1:
				if x + 1 != 3:
					wynik += max(x + 1, 3) - min(x + 1, 3)
				if y + 1 != 3:
					wynik += max(y + 1, 3) - min(y + 1, 3)
	return wynik
print(matrix())


import math
a = []
c = 0
b = 0
i = 0
j = 0
f = 3
n = 5
for i in range(n):
	a.append([int(j) for j in input().split()])
i = 0
j = 0
for i in range(n):
	for j in range(len(a[i])):
		if a[i][j] == 1:
			c = i + 1
			b = j + 1
i = 0
j = 0
if c < 3:
	while c < 3:
		i += 1
		c += 1
elif c > 3:
	while c > 3:
		i += 1
		c -= 1
if b < 3:
	while b < 3:
		j += 1
		b += 1
elif b > 3:
	while b > 3:
		j += 1
		b -= 1
print(i + j)


count = 0
mat = [[], [], [], [], []]
for i in range(0, 5):
	mat[i] = input().split(' ')
	if '1' in mat[i]:
		posi = i
		posj = mat[i].index('1')
while posi != 2:
	if posi < 2:
		posi += 1
	elif posi > 2:
		posi -= 1
	count += 1
while posj != 2:
	if posj < 2:
		posj += 1
	elif posj > 2:
		posj -= 1
	count += 1
print(count)


from math import fabs
n = 5
l = []
result = 0
for i in range(n):
	l.append(list(map(int, input().split())))
for i in range(n):
	for j in range(n):
		if l[i][j] == 1:
			result += fabs(2 - i)
			result += fabs(2 - j)
print(int(result))


A = []
count = 0
for i in range(5):
	B = [int(i) for i in input().split()]
	A.append(B)
for i in range(5):
	for j in range(5):
		if A[i][j] == 1:
			count = abs(i - 2) + abs(j - 2)
print(count)


matrix: list = []
for i in range(5):
	matrix.append([int(bin) for bin in input().split()])
rowPos: int = int()
for i in range(5):
	if 1 in matrix[i]:
		rowPos = i + 1
		break
colPos = matrix[rowPos - 1].index(1) + 1
displacement = abs(rowPos - 3) + abs(colPos - 3)
print(displacement)


i = 0
j = 0
for ii in range(5):
	jj = 0
	for e in input().split():
		if int(e) == 1:
			break
		jj = jj + 1
	else:
		continue
	i = ii
	j = jj
	break
n = 0
while i != 2:
	if i < 2:
		i = i + 1
	else:
		i = i - 1
	n = n + 1
while j != 2:
	if j < 2:
		j = j + 1
	else:
		j = j - 1
	n = n + 1
print(n)


from typing import List
LOCAL = False
if LOCAL:
	import os
	import sys
	import time
	start = time.time()
	letter = 'A'
	sys.stdin = open(f'{letter}in.txt', 'r')
	sys.stdout = open(f'{letter}out.txt', 'w')
from collections import deque

def bfs(matrix: List[List[int]], memo, queue, target):
	moves = -1
	while queue:
		size = len(queue)
		moves += 1
		for _ in range(size):
			pos = queue.popleft()
			if pos[0] == target[0] and pos[1] == target[1]:
				return moves
			(row, col) = pos
			distance = (target[0] - row) ** 2 + (target[0] - col) ** 2
			for new_pos in [(row + 1, col), (row - 1, col), (row, col + 1), (row, col - 1)]:
				(nr, nc) = new_pos
				if nr >= 0 and nr < len(matrix) and (nc >= 0) and (nc < len(matrix[0])) and (new_pos not in memo):
					nd = (target[0] - nr) ** 2 + (target[0] - nc) ** 2
					if nd <= distance:
						queue.append(new_pos)
						memo[new_pos] = True
	return moves
matrix = []
pos = None
for i in range(5):
	row = map(int, input().split())
	row = list(row)
	if 1 in row:
		pos = (i, row.index(1))
	matrix.append(list(row))
queue = deque([pos])
queue.append(pos)
memo = {}
target = (2, 2)
print(bfs(matrix, memo, queue, target))
if LOCAL:
	print('TIME:', time.time() - start, 'sec.')


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
for i in range(0, 5):
	if l1[i] == 1:
		print(3 - 1 + (max(3, i + 1) - min(3, i + 1)))
	elif l2[i] == 1:
		print(3 - 2 + (max(3, i + 1) - min(3, i + 1)))
	elif l3[i] == 1:
		print(3 - 3 + (max(3, i + 1) - min(3, i + 1)))
	elif l4[i] == 1:
		print(4 - 3 + (max(3, i + 1) - min(3, i + 1)))
	elif l5[i] == 1:
		print(5 - 3 + (max(3, i + 1) - min(3, i + 1)))


result = 0
for i in range(1, 6):
	num = [int(x) for x in input().split()]
	for j in range(1, 6):
		if num[j - 1] == 1:
			result = abs(i - 3) + abs(j - 3)
print(result)


for i in range(5):
	ai = [int(x) for x in input().split()]
	for j in range(5):
		if ai[j] == 1:
			m = i + 1
			n = j + 1
l = abs(m - 3) + abs(n - 3)
print(l)


R = 5
C = 5
my_matrix = []
for i in range(R):
	(a, b, c, d, e) = list(map(int, input().split(' ')))
	my_matrix.extend([[a, b, c, d, e]])
steps = 0
if my_matrix[2][2] == 1:
	print('0')
	exit(0)
else:
	for row in my_matrix:
		if 1 in row:
			if 1 == row[-1]:
				steps += 2
				(row[2], row[-1]) = (row[-1], row[2])
			elif 1 == row[0]:
				steps += 2
				(row[2], row[0]) = (row[0], row[2])
			elif 1 == row[-2]:
				steps += 1
				(row[2], row[-2]) = (row[-2], row[2])
			elif 1 == row[1]:
				steps += 1
				(row[2], row[1]) = (row[1], row[2])
for row in my_matrix:
	if 1 in row:
		if 1 == my_matrix[0][2]:
			steps += 2
			(my_matrix[0][2], my_matrix[2][2]) = (my_matrix[2][2], my_matrix[0][2])
		elif 1 == my_matrix[1][2]:
			steps += 1
			(my_matrix[1][2], my_matrix[2][2]) = (my_matrix[2][2], my_matrix[1][2])
		elif 1 == my_matrix[-1][2]:
			steps += 2
			(my_matrix[-1][2], my_matrix[2][2]) = (my_matrix[2][2], my_matrix[-1][2])
		elif 1 == my_matrix[-2][2]:
			steps += 1
			(my_matrix[-2][2], my_matrix[2][2]) = (my_matrix[2][2], my_matrix[-2][2])
print(steps)


import math

def find(str, char):
	for i in range(0, len(str)):
		if str[i] == char:
			return i
	return -1
j = ''
xpos = -1
ypos = -1
for i in range(0, 5):
	j = input()
	if xpos != -1:
		continue
	xpos = find(j, '1')
	ypos = i
xpos = int(xpos / 2)
center_position_x = int((5 - 1) / 2)
center_position_y = center_position_x
shortest_path = abs(center_position_x - xpos) + abs(center_position_y - ypos)
print(int(shortest_path))


for i in range(5):
	line = list(map(int, input().split()))
	try:
		if line.index(1) is not None:
			x_y = [i, line.index(1)]
	except:
		None
print(abs(x_y[0] - 2) + abs(x_y[1] - 2))


a = [list(map(int, input().split())) for _ in range(5)]
(row, column) = (0, 0)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			(row, column) = (i, j)
print(abs(row - 2) + abs(column - 2))


moves = 0
for row in range(1, 6):
	matrix = list(map(int, input().split()))
	for col in range(1, 6):
		if matrix[col - 1] == 1:
			moves += abs(col - 3) + abs(row - 3)
print(moves)


a = []
for i in range(5):
	a.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if a[i][j]:
			print(abs(2 - i) + abs(2 - j))


fl = input()
sl = input()
tl = input()
fourthl = input()
fifthl = input()
fl_s = fl.split()
sl_s = sl.split()
tl_s = tl.split()
fourthl_s = fourthl.split()
fifthl_s = fifthl.split()
fc = [fl_s[0], sl_s[0], tl_s[0], fourthl_s[0], fifthl_s[0]]
sc = [fl_s[1], sl_s[1], tl_s[1], fourthl_s[1], fifthl_s[1]]
tc = [fl_s[2], sl_s[2], tl_s[2], fourthl_s[2], fifthl_s[2]]
fourthc = [fl_s[3], sl_s[3], tl_s[3], fourthl_s[3], fifthl_s[3]]
fifthc = [fl_s[4], sl_s[4], tl_s[4], fourthl_s[4], fifthl_s[4]]
answer = 0
if fl_s.count('1') > 0:
	answer += 2
elif sl_s.count('1') > 0:
	answer += 1
elif tl_s.count('1') > 0:
	answer += 0
elif fourthl_s.count('1') > 0:
	answer += 1
else:
	answer += 2
if fc.count('1') > 0:
	answer += 2
elif sc.count('1') > 0:
	answer += 1
elif tc.count('1') > 0:
	answer += 0
elif fourthc.count('1') > 0:
	answer += 1
else:
	answer += 2
print(answer)


Matrix_list = []
row = 0
col = 0
for i in range(5):
	s = input().split()
	Matrix_list.append(list(s))
for x in range(5):
	for y in range(5):
		if Matrix_list[x][y] == '1':
			(row, col) = (x, y)
print(abs(row - 2) + abs(col - 2))


a = [[0] * 10] * 10
for i in range(5):
	b = input().split()
	for j in range(len(b)):
		if b[j] == '1':
			ans = abs(2 - i) + abs(2 - int(j))
print(ans)


matrix = []
for i in range(5):
	line = input().split(' ')
	matrix.append(line)
for l in matrix:
	for n in l:
		if n == '1':
			pos = [l.index(n), matrix.index(l)]
move_x = abs(2 - pos[0])
move_y = abs(2 - pos[1])
print(move_x + move_y)


(i1, j2) = (0, 0)
for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		i1 = i + 1
		j2 = l.index(1) + 1
print(abs(3 - i1) + abs(3 - j2))


def get_moves(n=0):
	row = input().split(' ')
	if '1' in row:
		return abs(2 - row.index('1')) + abs(2 - n)
	return get_moves(n=n + 1)
print(get_moves())


Matrix = []
OneLocation = [0, 0]
for i in range(0, 5):
	Line = input()
	Matrix.append(Line)
	if '1' in Line:
		y = 0
		for n in Line.split(' '):
			if 1 == int(n):
				OneLocation = [i, y]
				break
			y += 1
print(abs(2 - OneLocation[0]) + abs(2 - OneLocation[1]))


import sys
input = sys.stdin.readline
mat = [input().strip().split() for _ in range(5)]
x = y = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
			break
	else:
		continue


A = []
for i in range(5):
	N = [int(x) for x in input().split()]
	A.append(N)
	N = []
for i in range(5):
	for j in range(5):
		if A[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))
			break


m = []
for i in range(5):
	m.append(input().split())
	if '1' in m[i]:
		one_row = i
		one_col = m[i].index('1')
row_moves = abs(one_row - 2)
col_moves = abs(one_col - 2)
print(row_moves + col_moves)


for i in range(5):
	matrix = input().split()
	if '1' in matrix:
		distance_row = abs(i - 2)
		distance_column = abs(matrix.index('1') - 2)
print(distance_row + distance_column)


import sys
import math

def matrix():
	rows = 0
	matrix = []
	for i in range(5):
		matrix.append(input().split())
	for i in matrix:
		rows += 1
		if '1' in i:
			columns = i.index('1') + 1
			break
	print(abs(3 - rows) + abs(3 - columns))
matrix()


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
xloc = 0
yloc = 0
count = 0
try:
	xloc = a.index('1')
	yloc = 0
except:
	pass
try:
	xloc = b.index('1')
	yloc = 1
except:
	pass
try:
	xloc = c.index('1')
	yloc = 2
except:
	pass
try:
	xloc = d.index('1')
	yloc = 3
except:
	pass
try:
	xloc = e.index('1')
	yloc = 4
except:
	pass
if int(xloc) <= 2:
	count += 2 - int(xloc)
elif 2 < int(xloc):
	count += int(xloc) - 2
if yloc <= 2:
	count += 2 - int(yloc)
elif 2 < int(yloc):
	count += int(yloc) - 2
print(count)


for i in range(0, 5):
	a = list(map(int, input().split(' ')))
	if 1 in a:
		r = i
		for j in range(0, 5):
			if a[j] == 1:
				c = j
outcome = abs(r - 2) + abs(c - 2)
print(outcome)


mat = []
for i in range(0, 5):
	b = input().split()
	mat.append(b)
for x in range(0, 5):
	for y in range(0, 5):
		if mat[x][y] == '1':
			m = x
			n = y
print(abs(m - 2) + abs(n - 2))


import math
(r, c) = (-1, -1)
for k in range(5):
	s = input()
	xs = [int(i) for i in s.split()]
	if xs.count(1) > 0:
		r = k
		c = xs.index(1)
		break
print(abs(2 - r) + abs(2 - c))


moves = 0
for i in range(5):
	row = input().split()
	if '1' in row:
		moves = abs(i - 2) + abs(row.index('1') - 2)
print(moves)


num = 0
for i in range(5):
	m = map(int, input().split())
	x = 0
	for element in m:
		x += 1
		if element:
			num = abs(x - 3)
			num += abs(i - 2)
print(num)


matrix = [[0 for j in range(5)] for i in range(5)]
for i in range(5):
	s = list(map(int, input().split()))
	matrix[i] = s
(r, c) = (0, 0)
key = False
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			r = i
			c = j
			key = True
			break
	if key == True:
		break
print(abs(2 - r) + abs(2 - c))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
flag = 0
hit = 0
v = 0
for i in range(len(a)):
	if a[i] == '1':
		flag = 1
		hit = 2
		if i == 0:
			v = 2
		if i == 1:
			v = 1
		if i == 2:
			v = 0
		if i == 3:
			v = 1
		if i == 4:
			v = 2
		break
if flag == 0:
	for i in range(len(b)):
		if b[i] == '1':
			flag = 1
			hit = 1
			if i == 0:
				v = 2
			if i == 1:
				v = 1
			if i == 2:
				v = 0
			if i == 3:
				v = 1
			if i == 4:
				v = 2
			break
if flag == 0:
	for i in range(len(c)):
		if c[i] == '1':
			flag = 1
			hit = 0
			if i == 0:
				v = 2
			if i == 1:
				v = 1
			if i == 2:
				v = 0
			if i == 3:
				v = 1
			if i == 4:
				v = 2
			break
if flag == 0:
	for i in range(len(d)):
		if d[i] == '1':
			flag = 1
			hit = 1
			if i == 0:
				v = 2
			if i == 1:
				v = 1
			if i == 2:
				v = 0
			if i == 3:
				v = 1
			if i == 4:
				v = 2
			break
if flag == 0:
	for i in range(len(e)):
		if e[i] == '1':
			flag = 1
			hit = 2
			if i == 0:
				v = 2
			if i == 1:
				v = 1
			if i == 2:
				v = 0
			if i == 3:
				v = 1
			if i == 4:
				v = 2
			break
print(hit + v)


arr = [list(map(int, input().split(' '))) for i in range(5)]
for i in range(5):
	try:
		ind2 = arr[i].index(1)
		ind1 = i
		break
	except:
		continue
print(abs(2 - ind2) + abs(2 - ind1))


Mat = []
for i in range(0, 5):
	Mat.append(list(map(int, input().split())))
	for j in range(0, 5):
		if Mat[i][j] == 1:
			R = abs(i - 2) + abs(j - 2)
print(R)


(i1, j1, m) = (0, 0, 0)
a = []
for i in range(5):
	a.append(input())
	a[i] = a[i].split(' ')
	for j in range(5):
		a[i][j] = int(a[i][j])
		if a[i][j] == 1:
			(i1, j1) = (i, j)
while i1 != 2 or j1 != 2:
	if i1 < 2:
		a[i1][j1] = 0
		a[i1 + 1][j1] = 1
		i1 += 1
		m += 1
	elif i1 > 2:
		a[i1][j1] = 0
		a[i1 - 1][j1] = 1
		i1 -= 1
		m += 1
	if j1 < 2:
		a[i1][j1] = 0
		a[i1][j1 + 1] = 1
		j1 += 1
		m += 1
	elif j1 > 2:
		a[i1][j1] = 0
		a[i1][j1 - 1] = 1
		j1 -= 1
		m += 1
print(m)


def beautifulmMatrix(li):
	i = 0
	while i < 5:
		j = 0
		while j < 5:
			if li[i][j] == 1:
				return abs(2 - i) + abs(2 - j)
			j += 1
		i += 1
li = []
for i in range(5):
	a = [int(x) for x in input().split()]
	li += [a]
print(beautifulmMatrix(li))


def excu():
	for i in range(5):
		arr = [int(n) for n in input().split()]
		for j in range(5):
			if arr[j] == 1:
				print(abs(j - 2) + abs(i - 2))
				return 0
excu()


print(sum((sum((abs(x - 2) * z + abs(y - 2) * z for (z, x) in zip(list(map(int, input().split())), range(5)))) for y in range(5))))


for i in range(5):
	lst = [int(i) for i in input().split()]
	if 1 in lst:
		c = lst.index(1)
		r = i
print(abs(c - 2) + abs(r - 2))


integer = int
string = str
length = len

def main():
	a = []
	for _ in range(5):
		a.append(input().split())
	for i in range(5):
		if '1' in a[i]:
			j = a[i].index('1')
			print(abs(i - 2) + abs(j - 2))
			break
main()


s = []
for i in range(5):
	a = list(input())
	while ' ' in a:
		a.remove(' ')
	if '1' in a:
		s.append(i + 1)
		s.append(a.index('1') + 1)
print(abs(s[1] - 3) + abs(s[0] - 3))


s = []
for i in range(5):
	n = list(input().split())
	s.append(n)
for i in range(5):
	for j in range(5):
		if s[i][j] > str(0):
			val = abs(i - 2) + abs(j - 2)
print(val)


b = []
for i in range(5):
	l = list(map(int, input().split()))
	b.append(l)
x = []
for i in range(len(b)):
	if 1 in b[i]:
		r = i + 1
		x = b[i]
		break
for i in range(len(x)):
	if x[i] == 1:
		c = i + 1
		break
print(abs(r - 3) + abs(c - 3))


def solve():

	def read():
		(row, col) = (None, None)
		cnt = 0
		for _ in range(5):
			items = list(map(int, input().split()))
			for (i, num) in enumerate(items):
				if num == 1:
					(row, col) = (cnt, i)
			cnt += 1
		return (row, col)
	(row, col) = read()
	print(abs(2 - row) + abs(2 - col))
solve()


(Y, X) = (0, 0)
for y in range(-2, 3):
	s = input().split()
	if '1' in s:
		X = s.index('1') - 2
		Y = y
print(int((X ** 2) ** 0.5 + (Y ** 2) ** 0.5))


F = input().split()
S = input().split()
T = input().split()
FO = input().split()
FI = input().split()
c = 0
v = 0
p = 1
for i in [F, S, T, FO, FI]:
	c += 1
	if i.count('1') == 1:
		v = c
		p += i.index('1')
c = 0
if v < 3:
	c += 3 - v
else:
	c += v - 3
if p < 3:
	c += 3 - p
else:
	c += p - 3
print(c)


a = input().split(' ')
b = input().split(' ')
v = input().split(' ')
c = input().split(' ')
k = input().split(' ')
if a[0] == '1':
	print(4)
if a[1] == '1':
	print(3)
if a[2] == '1':
	print(2)
if a[3] == '1':
	print(3)
if a[4] == '1':
	print(4)
if b[0] == '1':
	print(3)
if b[1] == '1':
	print(2)
if b[2] == '1':
	print(1)
if b[3] == '1':
	print(2)
if b[4] == '1':
	print(3)
if v[0] == '1':
	print(2)
if v[1] == '1':
	print(1)
if v[2] == '1':
	print(0)
if v[3] == '1':
	print(1)
if v[4] == '1':
	print(2)
if c[0] == '1':
	print(3)
if c[1] == '1':
	print(2)
if c[2] == '1':
	print(1)
if c[3] == '1':
	print(2)
if c[4] == '1':
	print(3)
if k[0] == '1':
	print(4)
if k[1] == '1':
	print(3)
if k[2] == '1':
	print(2)
if k[3] == '1':
	print(3)
if k[4] == '1':
	print(4)


import sys
from math import *
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
import heapq
infinite = float('inf')
n = 5
l = [0] * 5
for i in range(n):
	l[i] = RI()
for i in range(n):
	for j in range(n):
		if l[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))


a = []
for i in range(5):
	newElement = input()
	a.append(newElement)
	if a[i].find('1') >= 0:
		row = i + 1
		z = a[i].split()
		couloum = z.index('1') + 1
print(abs(row - 3) + abs(couloum - 3))


x1 = input().split()
x2 = input().split()
x3 = input().split()
x4 = input().split()
x5 = input().split()
x = [x1, x2, x3, x4, x5]
res = 0
for i in range(0, len(x)):
	if '1' in x[i]:
		y = x[i].index('1')
		while y != 2:
			if y > 2:
				y -= 1
				res += 1
			else:
				y += 1
				res += 1
		while i != 2:
			if i > 2:
				i -= 1
				res += 1
			else:
				i += 1
				res += 1
print(res)


a = [[int(x) for x in input().split()] for i in range(5)]
c = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			if i != 2:
				while i != 2:
					if i > 2:
						i = i - 1
						c = c + 1
					elif i < 2:
						i = i + 1
						c = c + 1
			if j != 2:
				while j != 2:
					if j > 2:
						j = j - 1
						c = c + 1
					elif j < 2:
						j = j + 1
						c = c + 1
print(c)


def index(l):
	for k in range(len(l)):
		if int(l[k]) == 1:
			return k
	return -1
for k in range(5):
	l = input().split(' ')
	a = index(l)
	if a > -1:
		print(abs(k - 2) + abs(a - 2))


l1 = []
row = 0
col = 0
for i in range(5):
	l2 = [int(k) for k in input().split(' ')]
	l1.append(l2)
	for j in range(5):
		if l2[j] == 1:
			row = i
			col = j
temp = abs(row - 2)
temp2 = abs(col - 2)
print(temp + temp2)


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()))
supreme = [a, b, c, d, e]
i = 0
while i < len(supreme):
	if 1 in supreme[i]:
		k = 0
		while k < len(supreme[i]):
			if supreme[i][k] == 1:
				print(abs(i - 2) + abs(k - 2))
				break
			else:
				k = k + 1
		break
	else:
		i = i + 1


l = [[]] * 5
(r, c) = (0, 0)
for i in range(5):
	l[i] = [int(x) for x in input().split()]
	if 1 in l[i]:
		r = i
		c = l[i].index(1)
ans = abs(2 - r) + abs(2 - c)
print(ans)


def main():
	for row in range(5):
		line = input().split()
		if '1' in line:
			row += 1
			break
	for (col, elem) in enumerate(line):
		if elem is '1':
			col += 1
			break
	rowMove = abs(3 - row)
	colMove = abs(3 - col)
	print(rowMove + colMove)
main()


a = [list(map(int, input().strip().split()))[:5] for i in range(5)]
one = []
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			one = [i, j]
print(abs(one[0] - 2) + abs(one[1] - 2))


i = j = 2
arr = []
for _ in range(5):
	arr.append(list(map(int, input().rstrip().split())))
flag = False
for x in range(0, 5):
	for y in range(0, 5):
		if arr[x][y] == 1:
			flag = True
			break
	if flag is True:
		break
print(abs(x - i) + abs(y - j))


for i in range(1, 6):
	line = input().split()
	if '1' in line:
		for (index, item) in enumerate(line):
			if item == '1':
				row = i
				column = index + 1
print(abs(row - 3) + abs(column - 3))


def solve(matrix):
	(i, r, c) = (0, 0, 0)
	flag = False
	while i < 5 and (not flag):
		j = 0
		while j < 5 and (not flag):
			if matrix[i][j] == '1':
				r = i
				c = j
				flag = True
			j += 1
		i += 1
	return abs(r - 2) + abs(c - 2)
a = list()
for i in range(0, 5):
	a.append(input().split())
print(solve(a))


def solve():
	matrix = []
	for _ in range(5):
		row = list(map(int, input().split()))
		matrix.append(row)
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				(x, y) = (i, j)
	res = abs(2 - x) + abs(2 - y)
	print(res)
	return
solve()


a = 0
b = 0
for i in range(5):
	s = input().split()
	for j in range(5):
		if s[j] == '1':
			a = i + 1
			b = j + 1
print(abs(a - 3) + abs(b - 3))


list1 = input().split()
list2 = input().split()
list3 = input().split()
list4 = input().split()
list5 = input().split()
ls = list1 + list2 + list3 + list4 + list5
a = ls.index('1')
tuple = (a - a // 5 * 5, a // 5)
print(abs(tuple[0] - 2) + abs(tuple[1] - 2))


q = 0
w = 0
k = 0
for i in range(5):
	A = [int(i) for i in input().split()]
	for b in range(len(A)):
		if A[b] == 1:
			q = b
			w = i
while q != 2:
	if q < 2:
		q += 1
		k += 1
	else:
		q -= 1
		k += 1
while w != 2:
	if w < 2:
		w += 1
		k += 1
	else:
		w -= 1
		k += 1
print(k)


for row in range(1, 5 + 1):
	each_row = list(map(int, input().split()))
	for col in range(1, 5 + 1):
		if each_row[col - 1] == 1:
			print(abs(row - 3) + abs(col - 3))
			exit(0)


matrix = []
x = -1
y = -1
for i in range(5):
	matrix.append(input().split())
	for j in range(5):
		if matrix[i][j] == '1':
			x = i
			y = j
moves = 0
if x > 2:
	moves += x - 2
elif x < 2:
	moves += 2 - x
if y > 2:
	moves += y - 2
elif y < 2:
	moves += 2 - y
print(moves)


arr = []
for n in range(5):
	x = str(input())
	x = x.split(' ')
	x = [int(i) for i in x]
	arr.append(x)
xout = -2
for x in arr:
	xin = -2
	for b in x:
		if b == 1:
			print(abs(xin) + abs(xout))
		xin = xin + 1
	xout = xout + 1


coordinates = (0, 0)
for rowIndex in range(0, 5):
	row = input().split(' ')
	for columnIndex in range(0, 5):
		if row[columnIndex] == '1':
			coordinates = (rowIndex + 1, columnIndex + 1)
rowMoves = abs(coordinates[0] - 3)
columnMoves = abs(coordinates[1] - 3)
print(rowMoves + columnMoves)


def solve(matrix):
	found = 0
	for row in range(5):
		for column in range(5):
			if int(matrix[row][column]) == 1:
				found = 1
				break
			if found == 1:
				break
		if found == 1:
			return abs(row - 2) + abs(column - 2)
matrix = list()
for x in range(0, 5):
	matrix.append(input().split(' '))
print(solve(matrix))


l = []
for x in range(5):
	(x, y, w, v, z) = map(int, input().split())
	l.append([x, y, w, v, z])
for elt in l:
	if 1 in elt:
		r = l.index(elt) + 1
		c = elt.index(1) + 1
min_move = abs(3 - r) + abs(3 - c)
print(min_move)


elements = [input().split() for _ in range(5)]
for (idx, row) in enumerate(elements):
	if '1' in row:
		print(abs(idx - 2) + abs(row.index('1') - 2))


L1 = map(int, input().split())
L1 = list(L1)
L2 = map(int, input().split())
L2 = list(L2)
L3 = map(int, input().split())
L3 = list(L3)
L4 = map(int, input().split())
L4 = list(L4)
L5 = map(int, input().split())
L5 = list(L5)
c = 0
if 1 in L1:
	c = c + 2
	for i in range(5):
		if L1[i] == 1:
			c = c + abs(3 - (i + 1))
elif 1 in L2:
	c = c + 1
	for i in range(5):
		if L2[i] == 1:
			c = c + abs(3 - (i + 1))
elif 1 in L3:
	for i in range(5):
		if L3[i] == 1:
			c = c + abs(3 - (i + 1))
elif 1 in L4:
	c = c + 1
	for i in range(5):
		if L4[i] == 1:
			c = c + abs(3 - (i + 1))
else:
	c = c + 2
	for i in range(5):
		if L5[i] == 1:
			c = c + abs(3 - (i + 1))
print(c)


for i in range(1, 6):
	rawstr = input().split()
	for k in range(len(rawstr)):
		rawstr[k] = int(rawstr[k])
	for j in range(1, 6):
		if rawstr[j - 1] == 1:
			print(abs(j - 3) + abs(i - 3))


lst = []
for i in range(5):
	lst += [list(map(int, input().split()))]
for i in lst:
	if sum(i) == 1:
		ind_1 = lst.index(i) + 1
		for k in i:
			ind_2 = i.index(1) + 1
print(abs(3 - ind_1) + abs(3 - ind_2))


(x, y) = (0, 0)
for i in range(5):
	for (j, number) in enumerate(input().split()):
		if number == '1':
			(x, y) = (i, j)
(tx, ty) = (abs(x - 2), abs(y - 2))
print(tx + ty)


matrix = []
for x in range(5):
	a = input().split(' ')
	matrix.append(a)
row = 0
col = 0
for x in range(5):
	for y in range(5):
		if matrix[x][y] == '1':
			row = x
			col = y
moves = 0
while row > 2:
	row = row - 1
	moves = moves + 1
while row < 2:
	row = row + 1
	moves = moves + 1
while col > 2:
	col = col - 1
	moves = moves + 1
while col < 2:
	col = col + 1
	moves = moves + 1
if row == 2 and col == 2:
	print(moves)


l = []
l1 = []
xi = 0
xj = 0
for i in range(5):
	l1 = list(map(int, input().split()))
	l.append(l1)
	l1 = []
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			xi = i + 1
			xj = j + 1
if xi < 3:
	xi = 3 - xi
else:
	xi = xi - 3
if xj < 3:
	xj = 3 - xj
else:
	xj = xj - 3
print(xi + xj)


list1 = []
for i in range(5):
	list2 = list(map(int, input().split()))
	if any((i == 1 for i in list2)) == True:
		chill = i
	list1.append(list2)
no = list1[chill].index(1) + 1
print(abs(chill + 1 - 3) + abs(no - 3))


a = list()
for _ in range(5):
	a.append(list(input().split()))
x = 0
bul = True
for y in range(5):
	for x in range(5):
		if a[y][x] == '1':
			d = x
	for x in range(5):
		if a[y][x] == '1':
			c = y
(c, d) = (abs(2 - c), abs(2 - d))
print(c + d)


def inp():
	for i in range(0, 5):
		line = input().strip('\n\r\t ')
		for (j, item) in enumerate(line.split(' ')):
			if item == '1':
				return (i, j)
(i, j) = inp()
print(abs(2 - i) + abs(2 - j))


a = []
r = 0
s = 0
p = 0
q = 0
for i in range(5):
	n = [int(x) for x in input().split()]
	a.append(n)
for i in range(len(a)):
	for l in range(len(a[i])):
		if a[i][l] == 1:
			r = i
			s = l
if r == 2:
	q = 0
if r < 2:
	q = -r + 2
if r > 2:
	q = r - 2
if s == 2:
	p = 0
if s < 2:
	p = -s + 2
if s > 2:
	p = s - 2
print(p + q)


s = []
for n in range(5):
	s.append([int(n) for n in input().split()])
l = m = 0
for n in range(5):
	for k in range(5):
		if s[n][k] == 1:
			l = n
			m = k
			break
print(abs(2 - l) + abs(2 - m))


left_index = 0
right_index = 0
for i in range(5):
	list = input().split(' ')
	for j in range(5):
		if list[j] == '1':
			left_index = i
			right_index = j
			break
		else:
			continue
		break
print(abs(left_index - 2) + abs(right_index - 2))


for x in range(5):
	w = list(map(int, input().split()))
	if w[0] == 1:
		i = x
		j = 0
	if w[1] == 1:
		i = x
		j = 1
	if w[2] == 1:
		j = 2
		i = x
	if w[3] == 1:
		j = 3
		i = x
	if w[4] == 1:
		j = 4
		i = x
s = 0
if i < 2:
	s = s + 2 - i
else:
	s = s + i - 2
if j < 2:
	s = s + 2 - j
else:
	s = s + j - 2
print(int(s))


a = list()
a = [[0] * 5 for p in range(5)]
for i in range(5):
	a[i] = [int(j) for j in input().split(' ')]
for j in range(5):
	for k in range(5):
		if a[j][k] == 1:
			p = abs(j + 1 - 3) + abs(k + 1 - 3)
			print(p)
			exit


ans = 0
for i in range(5):
	vvod = map(int, input().split())
	stroka = list(vvod)
	for j in range(5):
		if stroka[j] == 1:
			if i == 0 or i == 4:
				ans += 2
			elif i == 1 or i == 3:
				ans += 1
			else:
				ans += 0
			if j == 0 or j == 4:
				ans += 2
			elif j == 1 or j == 3:
				ans += 1
			else:
				ans += 0
print(ans)


for i in range(1, 6):
	s = list(map(int, input().split()))
	if 1 in s:
		ind1 = i
		ind2 = s.index(1) + 1
print(abs(3 - ind1) + abs(3 - ind2))


(i, j) = (0, 0)
for x in range(5):
	s = input().split()
	if s.count('1'):
		i = x
		j = s.index('1')
print(abs(i - 2) + abs(j - 2))


for i in range(5):
	w = input()
	if w.count('1'):
		print(int(abs(3 - (w.find('1') / 2 + 1)) + abs(3 - (i + 1))))


from math import *
for i in range(5):
	l = input().split()
	if '1' in l:
		print(abs(i - 2) + abs(l.index('1') - 2))


a = 0
b = 0
for i in range(5):
	s = input().split()
	if s != ['0', '0', '0', '0', '0']:
		a = i
		for k in range(5):
			if s[k] != '0':
				b = k
print(abs(a - 2) + abs(b - 2))


for i in range(5):
	lst = []
	lst = input()
	lst = lst.split()
	for j in range(len(lst)):
		if int(lst[j]) == 1:
			x_i = i + 1
			y_i = j + 1
ans = 0
if 3 > x_i:
	ans = 3 - x_i
else:
	ans = x_i - 3
if 3 > y_i:
	ans += 3 - y_i
else:
	ans += y_i - 3
print(ans)


a = []
r = 0
c = 0
for i in range(5):
	p = list(map(int, input().split()))
	a.append(p)
	if 1 in p:
		r = abs(p.index(1) - 2)
		c = abs(i - 2)
print(r + c)


matrix = []
for i in range(5):
	row = [int(x) for x in input().split(' ')]
	matrix.append(row)
(row, col) = (None, None)
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] == 1:
			(row, col) = (i + 1, j + 1)
print(abs(3 - row) + abs(3 - col))


table = [input().split(), input().split(), input().split(), input().split(), input().split()]
for row in table:
	if '1' in row:
		trow = table.index(row)
		tcol = row.index('1')
move = abs(trow - 2) + abs(tcol - 2)
print(move)


slist = []
ans = 0
for i in range(0, 5):
	x = input()
	y = []
	for ii in range(0, 9):
		if x[ii] != ' ':
			y.append(x[ii])
	slist.append(y)
for i in range(0, 5):
	for j in range(0, 5):
		if slist[i][j] == '1':
			ans = abs(i - 2) + abs(j - 2)
			print(ans)
			ans = -1
			break
	if ans == -1:
		break


a = [[int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()]]
c = 0
b = 0
d = 0
for i in range(len(a)):
	if 1 in a[i]:
		b = a[i].index(1)
		c = i
while c != 2:
	if c > 2:
		c -= 1
		d += 1
	elif c < 2:
		c += 1
		d += 1
while b != 2:
	if b > 2:
		b -= 1
		d += 1
	elif b < 2:
		b += 1
		d += 1
print(d)


matrix = []
for i in range(5):
	matrix.append(input().split())
r = 0
c = 0
for row in matrix:
	for integer in row:
		if integer == '1':
			r = matrix.index(row) + 1
			c = row.index(integer) + 1
			break
	if r != 0:
		break
print(abs(3 - r) + abs(3 - c))


a = list()
c = 0
d = 0
e = False
for i in range(5):
	b = list(map(int, input().split()))
	a.append(b)
for i in range(5):
	for g in range(5):
		if a[i][g] == 1:
			c = i + 1
			d = g + 1
			e = True
			break
	if e:
		break
print(abs(3 - c) + abs(3 - d))


l = []
for i in range(5):
	r = list(map(int, input().split()))
	l.append(r)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			break
	if l[i][j] == 1:
		break
z = i + 1
y = j + 1
c = abs(3 - z) + abs(3 - y)
print(c)


M = []
c = 0
n = 0
m = 0
for i in range(5):
	temp = input()
	if temp.count('1') != 0:
		temp = temp.split()
		if temp.index('1') > -1:
			n = temp.index('1')
			m = i
c = abs(m - 2) + abs(n - 2)
print(c)


control_list = []
for i in range(5):
	lyst = list(map(int, input().split(' ')))
	control_list.append(lyst)
for i in range(len(control_list)):
	for j in range(len(control_list[i])):
		if control_list[i][j] == 1:
			a = i + 1
			b = j + 1
			break
print(abs(a - 3) + abs(b - 3))


matrix = []
for i in range(5):
	a = list(map(int, input().split()))
	matrix.append(a)
flag = False
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			ans = abs(i - 2) + abs(j - 2)
			flag = True
			break
	if flag:
		break
print(ans)


l = []
for i in range(5):
	num = list(map(int, input().split(' ')))
	l.append(num)
	i = i + 1
k = 0
x = 0
test = False
for i in l:
	k = k + 1
	x = 0
	for j in i:
		x = x + 1
		if j == 1:
			test = True
			break
	if test == True:
		break
print(abs(3 - k) + abs(3 - x))


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
for q in range(5):
	for p in range(5):
		if mat[q][p] == 1:
			q1 = q
			p1 = p
print(abs(p1 - 2) + abs(q1 - 2))


def read_input():
	matrix = []
	for row in range(5):
		line = input()
		matrix.append([])
		for column in range(5):
			matrix[row].append(int(line[2 * column]))
	return matrix

def locate_one(matrix):
	for row in range(5):
		for column in range(5):
			if matrix[row][column] == 1:
				return (row, column)
matrix = read_input()
(one_row, one_column) = locate_one(matrix)
print(abs(one_row - 2) + abs(one_column - 2))


def beautifullMatrix(arr):
	(row, col, res) = (0, 0, 0)
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				row = i
				col = j
				break
	res += abs(2 - row) + abs(2 - col)
	return res
array = []
for _ in range(5):
	array.append(list(map(int, input().rstrip().split())))
print(beautifullMatrix(array))


for i in range(5):
	new = list(map(int, input().split()))
	if new.count(1) == 1:
		ans = abs(i - 2) + abs(new.index(1) - 2)
print(ans)


columFound = 0
rowFound = 0
for l in range(0, 5):
	row = input().split()
	for i in range(0, 5):
		if int(row[i]) == 1:
			columFound = i
			rowFound = l
movesRowNeeded = abs(rowFound - 2)
movesColumNeeded = abs(columFound - 2)
totalMovesNeeded = movesRowNeeded + movesColumNeeded
print(totalMovesNeeded)


m = []
n = 1
while n < 6:
	m = input().split(' ')
	try:
		print(abs(m.index('1') + 1 - 3) + abs(3 - n))
		break
	except ValueError:
		n += 1


def make_beutiful_matrix(ugly_eye):
	beautiful_eye = (2, 2)
	return abs(beautiful_eye[0] - ugly_eye[0]) + abs(beautiful_eye[1] - ugly_eye[1])
eye_position = (0, 0)
for i in range(5):
	row_of_matrix = [int(i) for i in input().split()]
	if 1 in row_of_matrix:
		eye_position = (i, row_of_matrix.index(1))
print(make_beutiful_matrix(eye_position))


a = []
for i in range(0, 5):
	a.append([int(j) for j in input().split()])
for i in range(5):
	for j in range(5):
		if int(a[i][j] == 1):
			if i == 0 and j == 0 or (i == 0 and j == 4) or (i == 4 and j == 0) or (i == 4 and j == 4):
				count = 4
			elif i == 0 and j == 1 or (i == 1 and j == 0) or (i == 0 and j == 3) or (i == 3 and j == 4) or (i == 4 and j == 3) or (i == 3 and j == 0) or (i == 4 and j == 1) or (i == 1 and j == 4):
				count = 3
			elif i == 2 and j == 0 or (i == 2 and j == 4) or (i == 4 and j == 2) or (i == 0 and j == 2) or (i == 1 and j == 1) or (i == 1 and j == 3) or (i == 3 and j == 3) or (i == 3 and j == 1):
				count = 2
			elif i == 1 and j == 2 or (i == 2 and j == 1) or (i == 3 and j == 2) or (i == 2 and j == 3):
				count = 1
			else:
				count = 0
print(count)


count = 0
i1 = input().split()
i2 = input().split()
i3 = input().split()
i4 = input().split()
i5 = input().split()
for element in i1:
	if element == '1':
		count += 2
for element in i2:
	if element == '1':
		count += 1
for element in i4:
	if element == '1':
		count += 1
for element in i5:
	if element == '1':
		count += 2
new_list = i1 + i2 + i3 + i4 + i5
new_list = [int(y) for y in new_list]
i = 0
if new_list[0] == 1 or new_list[5] == 1 or new_list[10] == 1 or (new_list[15] == 1) or (new_list[20] == 1):
	count += 2
if new_list[1] == 1 or new_list[6] == 1 or new_list[11] == 1 or (new_list[16] == 1) or (new_list[21] == 1):
	count += 1
if new_list[2] == 1 or new_list[7] == 1 or new_list[12] == 1 or (new_list[17] == 1) or (new_list[22] == 1):
	count += 0
if new_list[3] == 1 or new_list[8] == 1 or new_list[13] == 1 or (new_list[18] == 1) or (new_list[23] == 1):
	count += 1
if new_list[4] == 1 or new_list[9] == 1 or new_list[14] == 1 or (new_list[19] == 1) or (new_list[24] == 1):
	count += 2
print(count)


def solution():
	matrix = []
	for _ in range(5):
		matrix.append(input().split(' '))
	(x, y) = (0, 0)
	for r in range(5):
		for c in range(5):
			if matrix[r][c] == '1':
				(x, y) = (r, c)
				break
	moves = 0
	while matrix[2][2] != '1':
		if x > 2:
			(matrix[x][y], matrix[x - 1][y]) = (matrix[x - 1][y], matrix[x][y])
			moves += 1
			x -= 1
		if x < 2:
			(matrix[x][y], matrix[x + 1][y]) = (matrix[x + 1][y], matrix[x][y])
			moves += 1
			x += 1
		if y > 2:
			(matrix[x][y], matrix[x][y - 1]) = (matrix[x][y - 1], matrix[x][y])
			moves += 1
			y -= 1
		if y < 2:
			(matrix[x][y], matrix[x][y + 1]) = (matrix[x][y + 1], matrix[x][y])
			moves += 1
			y += 1
	print(moves)
solution()


matrix = []
index_one_x = 0
index_one_y = 0
for i in range(5):
	input_arr = input().split(' ')
	index_one_x = i if '1' in input_arr else index_one_x
	index_one_y = input_arr.index('1') if '1' in input_arr else index_one_y
	matrix.append(input_arr)
print(abs(2 - int(index_one_y)) + abs(2 - int(index_one_x)))


i = []
j = [3, 3]
n = 0
m = 1
while m < 6:
	line = input()
	if '1' in line:
		i.append(m)
		i.append(line.split().index('1') + 1)
	m += 1
number_moves = abs(j[0] - i[0]) + abs(j[1] - i[1])
print(number_moves)


matrix = []
for x in range(5):
	row_in = [int(x) for x in input().split()]
	matrix.insert(x, row_in)

def find_1(matrix):
	for x in range(5):
		for i in range(5):
			if matrix[x][i] == 1:
				cord = (x, i)
				return cord

def min_move_to_center(cord):
	vert_move = abs(2 - cord[0])
	horizont_move = abs(2 - cord[1])
	return vert_move + horizont_move
print(min_move_to_center(find_1(matrix)))


r1 = input().split(' ')
r2 = input().split(' ')
r3 = input().split(' ')
r4 = input().split(' ')
r5 = input().split(' ')

def n(r):
	for i in range(5):
		if r[i] == '1':
			c = i + 1
			return c
if '1' in r1:
	r = 1
	c = n(r1)
if '1' in r2:
	r = 2
	c = n(r2)
if '1' in r3:
	r = 3
	c = n(r3)
if '1' in r4:
	r = 4
	c = n(r4)
if '1' in r5:
	r = 5
	c = n(r5)
s = abs(3 - r) + abs(3 - c)
print(s)


import copy
temp = []
temp.append(list(map(int, input().split(' '))))
temp.append(list(map(int, input().split(' '))))
temp.append(list(map(int, input().split(' '))))
temp.append(list(map(int, input().split(' '))))
temp.append(list(map(int, input().split(' '))))
for i in range(5):
	r = temp[i]
	for j in range(5):
		if r[j] == 1:
			x = i
			y = j
			break
ans = abs(x - 2) + abs(y - 2)
print(ans)


a = [[i for i in input().split()] for _ in range(5)]
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			y = i
			x = j
print(abs(y - 2) + abs(x - 2))


def solve():
	matrix = [input().split() for i in range(5)]
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == '1':
				print(abs(i - 2) + abs(j - 2))
				return None
solve()


import math
n = 5
l = []
while n > 0:
	x = input()
	l = l + x.split()
	n -= 1
b = True
i = 0
while i < len(l) and b:
	if l[i] == '1':
		b = False
	i += 1
e = math.ceil(i / 5)
r = abs(e - 3)
if i % 5 == 0:
	r += 2
else:
	r += abs(i % 5 - 3)
print(r)


n = 5
matrix = []
for i in range(5):
	matrix.append(input().split())
for i in range(n):
	if '1' in matrix[i]:
		col_pos = 0
		row_pos = 0
		_index = matrix[i].index('1')
		if _index >= 3:
			col_pos = _index - 2
		else:
			col_pos = 2 - _index
		if i >= 2:
			row_pos = i - 2
		else:
			row_pos = 2 - i
		print(col_pos + row_pos)
		break


A = []
for i in range(5):
	p = [int(x) for x in input().split()]
	if 1 in p:
		l = p.index(1)
		ans = abs(l - 2) + abs(i - 2)
		print(ans)
		exit()


r = 1
while True:
	n = input().split()
	if '1' in n:
		c = n.index('1') + 1
		break
	r += 1
print(abs(r - 3) + abs(c - 3))


list1 = input().split()
list2 = input().split()
list3 = input().split()
list4 = input().split()
list5 = input().split()
str1 = ''.join(list1)
str2 = ''.join(list2)
str3 = ''.join(list3)
str4 = ''.join(list4)
str5 = ''.join(list5)
a = str1.find('1')
b = str2.find('1')
c = str3.find('1')
d = str4.find('1')
e = str5.find('1')
n = 0
if a >= 0:
	n = abs(a - 2) + 2
else:
	n = n
if b >= 0:
	n = abs(b - 2) + 1
else:
	n = n
if c >= 0:
	n = abs(c - 2)
else:
	n = n
if d >= 0:
	n = abs(d - 2) + 1
else:
	n = n
if e >= 0:
	n = abs(e - 2) + 2
else:
	n = n
print(n)


i = 0
while i < 5:
	matrix = list(map(int, input().split()))
	for j in range(0, 5):
		if matrix[j] == 1:
			(x, y) = (i, j)
			break
	i += 1
dist = abs(x - 2) + abs(y - 2)
print(dist)


row1 = [int(x) for x in input().split()]
row2 = [int(x) for x in input().split()]
row3 = [int(x) for x in input().split()]
row4 = [int(x) for x in input().split()]
row5 = [int(x) for x in input().split()]
row = row1 + row2 + row3 + row4 + row5
index = row.index(1)
if index >= 0 and index <= 4:
	tes = row1.index(1)
	if tes == 2:
		print(2)
		exit()
	else:
		print(abs(2 - tes) + 2)
elif index >= 5 and index <= 9:
	tes = row2.index(1)
	if tes == 2:
		print(1)
		exit()
	else:
		print(abs(2 - tes) + 1)
elif index >= 10 and index <= 14:
	tes = row3.index(1)
	if tes == 2:
		print(0)
		exit()
	else:
		print(abs(2 - tes) - 0)
elif index >= 15 and index <= 19:
	tes = row4.index(1)
	if tes == 2:
		print(1)
		exit()
	else:
		print(abs(2 - tes) + 1)
elif index >= 20 and index <= 24:
	tes = row5.index(1)
	if tes == 2:
		print(2)
		exit()
	else:
		print(abs(2 - tes) + 2)


for i in range(5):
	x = list(map(int, input().split()))
	if 1 in x:
		i1 = i + 1
		i2 = x.index(1) + 1
cnt = 0
if i1 > 3:
	cnt = cnt + (i1 - 3)
elif i1 < 3:
	cnt = cnt + (3 - i1)
else:
	cnt = cnt + 0
if i2 > 3:
	cnt = cnt + (i2 - 3)
elif i2 < 3:
	cnt = cnt + (3 - i2)
else:
	cnt = cnt + 0
print(cnt)


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
mat = [l1, l2, l3, l4, l5]
cr = mat[2][2]
f = 0
for i in range(len(mat)):
	f += 1
	if 1 in mat[i]:
		temp = mat[i]
		break
if f != 0:
	f = f - 1
	s = temp.index(1)
else:
	f = 0
	s = temp.index(1)
x1 = abs(2 - f)
x2 = abs(2 - s)
print(x1 + x2)


for i in range(5):
	elements = list(map(int, input().split()))
	if 1 in elements:
		actual_j = elements.index(1)
		actual_i = i
target_j = 5 // 2
target_i = 5 // 2
print(abs(target_j - actual_j) + abs(target_i - actual_i))


l = []
for i in range(5):
	l.extend(list(input().split(' ')))
ind = l.index('1') + 1
if ind % 5 > 0:
	i = ind // 5 + 1
else:
	i = ind // 5
j = ind % 5
if i % 5 == 0:
	i = 5
if j == 0:
	j = 5
moves = 0
if i < 3:
	moves += 3 - i
if i > 3:
	moves += i - 3
if j < 3:
	moves += 3 - j
if j > 3:
	moves += j - 3
print(moves)


import sys
for i in range(0, 5):
	line = list(map(int, sys.stdin.readline().strip().split()))
	for j in range(0, 5):
		if line[j] == 1:
			n = abs(i - 2) + abs(j - 2)
print(n)


a = []
for i in range(5):
	col = list(map(int, input().split()))
	a.append(col)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			row = i
			c = j
n = abs(row - 2) + abs(c - 2)
print(n)


matrix = [[int(v) for v in input().split(' ')] for _ in range(5)]
(r, c) = (0, 0)
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			(r, c) = (i, j)
			break
print(abs(r - 2) + abs(c - 2))


listy = []
for i in range(5):
	listx = list(map(str, input().split()))
	listy = listy + listx
n = listy.index('1')
if (n + 1) % 5 == 0:
	y = 5
	x = (n + 1) / 5
else:
	y = (n + 1) % 5
	x = int(n / 5) + 1
ans = abs(x - 3) + abs(y - 3)
print(int(ans))


import sys
c_size = 5
ll = []
row = 0
col = 0
for i in range(c_size):
	ll.append(list(map(int, sys.stdin.readline().split())))
	for j in range(c_size):
		if ll[i][j] == 1:
			row = i
			col = j
mid = int(c_size / 2)
print(abs(row - mid) + abs(col - mid))


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
r = 0
c = 0
for i in range(5):
	if 1 in matrix[i]:
		r = i
		c = matrix[i].index(1)
ans = abs(2 - r) + abs(2 - c)
print(ans)


import os
import sys

def fileInput(file_name):
	Input = []
	if not os.path.exists(file_name):
		print("The input file didn't exist,", 'please re-enter the input filename')
		fileInput(file_name)
	else:
		print('\nProcessing the input...')
		try:
			inputFile = open(file_name, 'r')
		except IOError:
			print('Cannot open the file')
		vars = inputFile.readlines()
		pos = None
		for (i, v) in enumerate(vars):
			for (j, e) in enumerate(v.split(' ')):
				el = int(e.strip('\n'))
				Input.append(el)
				if el == 1:
					pos = (i + 1, j + 1)
		inputFile.close()
	return pos

def parser_and_return_pos():
	pos = None
	for (i, line) in enumerate(sys.stdin):
		for (j, e) in enumerate(line.split(' ')):
			if 1 == int(e.strip('\n')):
				pos = (i + 1, j + 1)
		if i == 4:
			break
	return pos
pos = parser_and_return_pos()
beautiful = (3, 3)
print(abs(beautiful[0] - pos[0]) + abs(beautiful[1] - pos[1]))


mat = []
for i in range(5):
	m = list(map(int, input().split()))
	mat.append(m)
	if 1 in m:
		ix = m.index(1)
		res = abs(ix - 2) + abs(i - 2)
print(res)


j = k = 0
for i in range(5):
	s = input()
	if '1' in s:
		j = i + 1
		k = s.index('1') // 2 + 1
		break
print(abs(j - 3) + abs(k - 3))


for m in range(1, 6):
	str_1 = input()
	if str_1 != '0 0 0 0 0':
		break
row = abs(3 - m)
list_1 = str_1.split()
n = list_1.index('1') + 1
col = abs(3 - n)
print(row + col)


def beautiful(values):
	count = 0
	for i in range(5):
		for j in range(5):
			if values[i][j] == 1:
				x = i
				y = j
				break
	mid_x = len(values) // 2
	mid_y = len(values) // 2
	if x != mid_x:
		count = count + abs(mid_x - x)
	if y != mid_y:
		count = count + abs(mid_y - y)
	return count
values = []
for i in range(5):
	value = list(map(int, input().split()))
	values.append(value)
print(beautiful(values))


from sys import stdin
for l in range(0, 5):
	a = stdin.readline().split()
	for k in range(0, 5):
		if int(a[k]) == 1:
			print(abs(k - 2) + abs(l - 2))


import sys
from itertools import groupby
I = abs
H = range
B = {}
C = 0
D = 0
for A in H(1, 6):
	B[A] = list(map(int, input().split()))
for A in H(1, 6):
	if 1 in B[A]:
		C = A
		F = B[A]
E = 0
for A in F:
	E += 1
	if A == 1:
		D = E
G = I(3 - C) + I(3 - D)
print(G)


def main():
	grid = []
	for i in range(5):
		inp = [x for x in input().split()]
		if '1' in inp:
			posX = i + 1
			posY = inp.index('1') + 1
			return abs(posX - 3) + abs(posY - 3)
		grid.append(inp)
print(main())


import sys
import os
not_found = True
row = 1
one_row = 0
one_col = 0
while not_found:
	t = sys.stdin.readline()
	vals = t.split()
	for (col, val) in enumerate(vals):
		if int(val) == 1:
			one_row = row
			one_col = col + 1
			not_found = False
	row += 1
steps = abs(one_row - 3) + abs(one_col - 3)
print(steps)


m = []
for i in range(5):
	m.append(list(map(int, input().rstrip().split())))
a = [[4, 3, 2, 3, 4], [3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3], [4, 3, 2, 3, 4]]
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			print(a[i][j])


def isContained(list, x):
	i = 0
	while i < len(list):
		if list[i] == x:
			return i + 1
		else:
			j = 200
		i = i + 1
	return j
l = 1
f = 0
while f < 5:
	line = input()
	linelist = line.split()
	if isContained(linelist, '1') != 200:
		g = l
		message = abs(isContained(linelist, '1') - 3) + abs(g - 3)
	l = l + 1
	f = f + 1
print(message)


r = []
for i in range(0, 5, 1):
	x = list(map(int, input().split(' ')))
	r.append(x)
m = []
for j in range(5):
	for k in range(5):
		m.append(r[j][k])
pos = m.index(1)
rp = pos // 5
cp = pos % 5
ans = 0
if rp == 2:
	ans += 0
elif rp < 2:
	ans += 2 - rp
elif rp > 2:
	ans += rp - 2
if cp == 2:
	ans += 0
elif cp < 2:
	ans += 2 - cp
elif cp > 2:
	ans += cp - 2
print(ans)


a = [list(map(int, input().split())) for i in range(5)]
for r in range(len(a)):
	for c in range(len(a[r])):
		if a[r][c] == 1:
			print(abs(r + 1 - 3) + abs(c + 1 - 3))
			break


import sys
input = sys.stdin.readline
for i in range(0, 5):
	limbak = [int(x) for x in input().split()]
	try:
		one = limbak.index(1)
		row = i + 1
	except ValueError:
		continue
one += 1
swaps = abs(3 - row) + abs(3 - one)
print(swaps)


def moves():
	matrix = []
	moves = 0
	for i in range(5):
		matrix.append(list(map(int, input().split())))
	for j in range(5):
		for k in range(5):
			if matrix[j][k] == 1:
				moves += abs(j - 2) + abs(k - 2)
	return moves
print(moves())


a = [] * 5
kj = 0
ki = 0
for i in range(5):
	a.append(list(map(int, input().split())))
	for j in range(5):
		if a[i][j] == 1:
			kj = j
			ki = i
			break
if ki <= 2:
	ki = 2 - ki
else:
	ki = ki - 2
if kj <= 2:
	kj = 2 - kj
else:
	kj = kj - 2
print(kj + ki)


A = [[0 for i in range(7)] for i in range(7)]
for i in range(5):
	temp = [int(x) for x in input().split()]
	for j in range(5):
		A[i + 1][j + 1] = temp[j]
for i in range(1, 6):
	for j in range(1, 6):
		if A[i][j] == 1:
			I = i
			J = j
			break
print(abs(J - 3) + abs(I - 3))


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))
for i in range(5):
	if r1[i] == 1:
		c = 2 + abs(3 - i - 1)
	elif r2[i] == 1:
		c = 1 + abs(3 - i - 1)
	elif r3[i] == 1:
		c = abs(3 - i - 1)
	elif r4[i] == 1:
		c = 1 + abs(3 - i - 1)
	elif r5[i] == 1:
		c = 2 + abs(3 - i - 1)
print(c)


for i in range(-2, 3):
	n = list(map(int, input().split()))
	if 1 in n:
		print(abs(i) + abs(n.index(1) - 2))


for x in range(0, 5):
	s = input()
	if '1' in s:
		print(abs(2 - x) + abs(2 - s.index('1') // 2))
		break


l = []
for i in range(5):
	s = input().split(' ')
	temp = [int(i) for i in s]
	l.append(temp)
IndexList = [(i, j) for (i, row) in enumerate(l) for (j, column) in enumerate(row) if column == 1]
temp = IndexList[0]
x = temp[0] - 2
y = temp[1] - 2
print(abs(x) + abs(y))


import math
i = 0
j = 0
for temp in range(1, 6):
	st = input().split()
	if '1' in st:
		i = temp
		j = st.index('1') + 1
		break
res = int(math.fabs(i - 3) + math.fabs(j - 3))
print(res)


l = []
for i in range(5):
	l.append(list(map(int, input().split())))
for (ix, row) in enumerate(l):
	for (iy, k) in enumerate(row):
		if k == 1:
			x = abs(2 - ix) + abs(2 - iy)
print(x)


a = []
k = 0
for i in range(5):
	a.append(input().split())
while '1' not in a[k]:
	k += 1
print(abs(2 - k) + abs(2 - a[k].index('1')))


for num_row in range(1, 6):
	row = input()
	num_column = row.find('1')
	if num_column != -1:
		num_column = num_column // 2 + 1
		print(abs(3 - num_row) + abs(3 - num_column))


mtx = []
i = 0
j = 0
for q in range(5):
	mtx.append(list(input().split(' ')))
for x in range(5):
	for y in range(5):
		if int(mtx[x][y]) & 1 == 1:
			i = x + 1
			j = y + 1
print(abs(j - 3) + abs(i - 3))


for i in range(1, 6):
	innput = input().split()
	if '1' in innput:
		(x, y) = (innput.index('1') + 1, i)
print(abs(3 - x) + abs(3 - y))


input_matrix = [[], [], [], [], []]
input_matrix[0] = input()
input_matrix[1] = input()
input_matrix[2] = input()
input_matrix[3] = input()
input_matrix[4] = input()
for i in range(0, 4 + 1):
	for j in range(0, 8 + 1, 2):
		if input_matrix[i][j] == '1':
			y = i
			x = j // 2
print(abs(2 - x) + abs(2 - y))


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
steps = 0
while c[2] != 1:
	if 1 in c:
		i = c.index(1)
		if i < 2:
			c[i + 1] = 1
			c[i] = 0
			steps += 1
		else:
			c[i - 1] = 1
			c[i] = 0
			steps += 1
	elif 1 in b:
		i = b.index(1)
		c[i] = 1
		b[i] = 0
		steps += 1
	elif 1 in d:
		i = d.index(1)
		c[i] = 1
		d[i] = 0
		steps += 1
	elif 1 in a:
		i = a.index(1)
		b[i] = 1
		steps += 1
	elif 1 in e:
		i = e.index(1)
		d[i] = 1
		a[i] = 0
		steps += 1
print(steps)


def main():
	l = []
	for i in range(5):
		l.append(list(map(int, input().strip().split())))
	flag = 1
	for i in range(5):
		for j in range(5):
			if l[i][j] == 1:
				flag = 0
				break
		if flag == 0:
			break
	print(abs(i - 2) + abs(j - 2))
main()


matrix = []
for _ in range(5):
	matrix.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			one = (i, j)
print(abs(one[0] - 2) + abs(one[1] - 2))


matrix = [[int(n) for n in input().split()] for _ in range(5)]
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			moves = abs(i - 2) + abs(j - 2)
			print(moves)
			break


nums = []
for i in range(5):
	nums.append(input().split())
for a in range(5):
	for b in range(5):
		if nums[a][b] == '1':
			k = [a, b]
for i in range(2):
	k[i] = k[i] - 2
	if k[i] < 0:
		k[i] = -1 * k[i]
print(k[0] + k[1])


def beautiful_matrix():
	found = 0
	n_row = 0
	while n_row <= 4:
		row = str(input()).split()
		row = [int(i) for i in row]
		if 1 in row:
			n_col = row.index(1)
			n_manip_col = abs(2 - n_col)
			n_manip_row = abs(2 - n_row)
			print(n_manip_row + n_manip_col)
			return
		n_row += 1
beautiful_matrix()


for a in range(1, 6):
	row = input().split()
	if row.count('1') == 1:
		moves = abs(a - 3) + abs(row.index('1') - 2)
print(moves)


def beautifulMatrix():
	for i in range(1, 6):
		colList = [x for x in input().split()]
		for j in range(1, 6):
			if colList[j - 1] == '1':
				iCoord = i
				jCoord = j
	return abs(iCoord - 3) + abs(jCoord - 3)
print(beautifulMatrix())


matrix = []
(x, y) = (0, 0)
for i in range(5):
	matrix.append(input().split())
	if '1' in matrix[i]:
		(x, y) = (i, matrix[i].index('1'))
if (x, y) == (2, 2):
	print(0)
elif (x, y) == (1, 2) or (x, y) == (2, 1) or (x, y) == (3, 2) or ((x, y) == (2, 3)):
	print(1)
elif (x, y) == (2, 0) or (x, y) == (0, 2) or (x, y) == (2, 4) or ((x, y) == (4, 2)) or ((x, y) == (1, 1)) or ((x, y) == (3, 1)) or ((x, y) == (1, 3)) or ((x, y) == (3, 3)):
	print(2)
elif (x, y) == (0, 0) or (x, y) == (0, 4) or (x, y) == (4, 0) or ((x, y) == (4, 4)):
	print(4)
else:
	print(3)


matrix = [list(map(int, input().split())) for i in range(5)]
for r in range(5):
	for c in range(5):
		if matrix[r][c] == 1:
			location = (r, c)
			break
steps = 0
steps += abs(location[0] - 2)
steps += abs(location[1] - 2)
print(steps)


q = []
for i in [0] * 5:
	k = list(map(int, input().split()[:5]))
	q += k
k = 0
t = q.index(1)
if t < 10:
	while t not in range(10, 15):
		t += 5
		k += 1
elif t > 14:
	while t not in range(10, 15):
		t -= 5
		k += 1
p = abs(12 - t)
print(k + p)


a = []

def intmaker(list):
	for i in range(len(list)):
		list[i] = int(list[i])
	return list

def get_index(list, value):
	result = [-1, -1]
	which_mini_list = 0
	for mini_list in list:
		if value in mini_list:
			result[0] = which_mini_list
			result[1] = mini_list.index(value)
		which_mini_list += 1
	return result
for i in range(5):
	a.append(intmaker(input().split()))
index_of_one = get_index(a, 1)
print(abs(index_of_one[0] - 2) + abs(index_of_one[1] - 2))


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

def find_one(mat):
	for (i, li) in enumerate(mat):
		for (j, el) in enumerate(li):
			if li[j] == 1:
				return [i + 1, j + 1]
print(abs(3 - find_one(mat)[0]) + abs(3 - find_one(mat)[1]))


matrix = []
(r, c) = (0, 0)
for i in range(5):
	k = list(map(int, input().split()))
	if 1 in k:
		r = i + 1
		c = k.index(1) + 1
print(abs(3 - r) + abs(3 - c))


l1 = input()
l2 = input()
l3 = input()
l4 = input()
l5 = input()
if l1[0] == '1' or l1[8] == '1' or l5[0] == '1' or (l5[8] == '1'):
	print(4)
elif l1[2] == '1' or l1[6] == '1' or l5[2] == '1' or (l5[6] == '1') or (l2[0] == '1') or (l2[8] == '1') or (l4[0] == '1') or (l4[8] == '1'):
	print(3)
elif l1[4] == '1' or l2[2] == '1' or l2[6] == '1' or (l3[0] == '1') or (l3[8] == '1') or (l4[2] == '1') or (l4[6] == '1') or (l5[4] == '1'):
	print(2)
elif l2[4] == '1' or l3[2] == '1' or l3[6] == '1' or (l4[4] == '1'):
	print(1)
elif l3[4] == '1':
	print(0)


def foo(arr):
	for i in range(5):
		arr.append([int(i) for i in input().split(' ')])
arr = []
foo(arr)
(x, y) = (0, 0)
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			(x, y) = (i, j)
			break
print(abs(2 - x) + abs(2 - y))


for i in range(5):
	s = input()
	if s.count('1') == 0:
		continue
	print(abs(i - 2) + int(abs(s.find('1') - 4) / 2))
	exit()


for l in range(5):
	line = [int(x) for x in input().split()]
	try:
		c = line.index(1)
		x = c
		y = l
	except ValueError:
		pass
print(abs(x - 2) + abs(y - 2))


matrix = [[int(i) for i in input().split(' ')] for i in range(5)]
(ii, jj) = (int(), int())
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			(ii, jj) = (i, j)
print(abs(2 - ii) + abs(2 - jj))


l = []
(a, b) = (0, 0)
for i in range(5):
	x = list(map(int, input().split()))
	if x.count(1) == 1:
		a = i + 1
		b = x.index(1) + 1
	l.append(x)
print(abs(3 - a) + abs(3 - b))


matrix = [[int(x) for x in input().split()] for _ in range(5)]
for x in range(5):
	for y in range(5):
		if matrix[x][y] == 1:
			(absc, ordi) = (x + 1, y + 1)
print(abs(ordi - 3) + abs(absc - 3))


a = []
for x in range(5):
	a.append(list(map(int, input().split())))
result = 0
b = [2, 1, 0, 1, 2]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			result = result + b[j]
for m in range(5):
	if 1 in a[m]:
		result = result + b[m]
print(result)


rows = 5
columns = 5
n = []
for i in range(rows):
	a = list(map(int, input().strip().split()))
	n.append(a)
step = 0
for i in range(rows):
	for j in range(columns):
		if n[i][j] == 1:
			step = abs(i - 2) + abs(j - 2)
print(step)


for i in [1, 2, 3, 4, 5]:
	for (m, k) in enumerate(input().split()):
		if k == '1':
			print(abs(i - 3) + abs(m + 1 - 3))


a = []
x = 0
for i in range(5):
	a.append(list(input().split()))
for i in a:
	if '1' in i:
		stroka = a.index(i)
		stolb = i.index('1')
if stroka == 4 or stroka == 0:
	x += 2
if stroka == 3 or stroka == 1:
	x += 1
if stolb == 4 or stolb == 0:
	x += 2
if stolb == 3 or stolb == 1:
	x += 1
print(x)


a = []
for _ in range(5):
	b = list(map(int, input().rstrip().split()))
	a.append(b)
x = 0
y = 0
for _ in range(5):
	for i in range(5):
		if a[_][i] == 1:
			x = _
			y = i
			break
	if a[x][y] == 1:
		break
print(abs(x - 2) + abs(y - 2))


def main():
	x = []
	a = 1
	for i in range(5):
		x.append(map(int, input().split()))
		b = i
	for i in range(5):
		n = x[i]
		b = 1
		for j in range(5):
			z = n.__next__()
			if z == 1:
				print(abs(a - 3) + abs(b - 3))
				break
			b += 1
		a += 1
main()


for i in range(5):
	row = input()[::2]
	if '1' in row:
		hmove = abs(row.index('1') - 2)
		vmove = abs(i - 2)
print(hmove + vmove)


i = 1
moves = 0
while i <= 5:
	listnum = [int(b) for b in input().split()]
	if 1 in listnum:
		indexX = listnum.index(1) + 1
		indexY = i
	i += 1
moves += abs(indexX - 3)
moves += abs(indexY - 3)
print(moves)


import math
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
if 1 in l1:
	(index1, index2) = (1, l1.index(1) + 1)
elif 1 in l2:
	(index1, index2) = (2, l2.index(1) + 1)
elif 1 in l3:
	(index1, index2) = (3, l3.index(1) + 1)
elif 1 in l4:
	(index1, index2) = (4, l4.index(1) + 1)
else:
	(index1, index2) = (5, l5.index(1) + 1)
print(abs(3 - index1) + abs(3 - index2))


for i in range(5):
	tx = list(map(int, input().split()))
	if tx.count(1) == 1:
		for k in range(5):
			if tx[k] == 1:
				x = i + 1
				y = k + 1
ans = abs(x - 3) + abs(y - 3)
print(ans)


rows = list()
x = int()
y = int()
mv = 0
for i in range(5):
	col = list(map(int, input().split(' ')))
	for j in range(5):
		if col[j] == 1:
			y = i
			x = j
	rows.append(col)
mv = abs(2 - y)
mv += abs(2 - x)
print(mv)


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()))
matrix = [row1, row2, row3, row4, row5]
found = False
for (i, l) in enumerate(matrix):
	for (j, el) in enumerate(l):
		if el == 1:
			found = True
			break
	if found:
		break
print(abs(i - 2) + abs(j - 2))


a = [input().split() for i in range(5)]
d = 0
b = 0
s = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			d = i + 1
			b = j + 1
			break
while d < 3:
	d += 1
	s += 1
while d > 3:
	d -= 1
	s += 1
while b < 3:
	b += 1
	s += 1
while b > 3:
	b -= 1
	s += 1
print(s)


def matrix(l1, l2, l3, l4, l5):
	if 1 in l1:
		a = l1.index(1)
		return abs(a - 2) + 2
	elif 1 in l2:
		b = l2.index(1)
		return abs(b - 2) + 1
	elif 1 in l3:
		c = l3.index(1)
		return abs(c - 2)
	elif 1 in l4:
		b = l4.index(1)
		return abs(b - 2) + 1
	elif 1 in l5:
		a = l5.index(1)
		return abs(a - 2) + 2
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
print(matrix(l1, l2, l3, l4, l5))


a = [input().split(' '), input().split(' '), input().split(' '), input().split(' '), input().split(' ')]

def get_index():
	for i in range(len(a)):
		if '1' in a[i]:
			return (i, a[i].index('1'))
	return (-1, -1)
(x, y) = get_index()
print(abs(x - 2) + abs(y - 2))


arrList = [input().split(), input().split(), input().split(), input().split(), input().split()]
(a, b) = (0, 0)
for i in range(0, 5):
	for j in range(0, 5):
		if arrList[i][j] == '1':
			a = i + 1 - 3
			b = j + 1 - 3
			break
	if arrList[i][j] == '1':
		break
if a < 0:
	a *= -1
if b < 0:
	b *= -1
print(a + b)


matrix = [[0 for i in range(5)] for i in range(5)]
for i in range(5):
	ch = input()
	ch = ch.split()
	if '1' in ch:
		col = ch.index('1') + 1
		row = i + 1
		break
print(abs(3 - col) + abs(3 - row))


filas = 0
movimientos = 0
posicion = []
for entrada in range(5):
	entrada = list(map(int, input().split()))
	filas = filas + 1
	for i in range(len(entrada)):
		if entrada[i] == 1:
			posicion.append(filas)
			posicion.append(i + 1)
if posicion[0] > 3 or posicion[0] < 3:
	movimientos = movimientos + abs(posicion[0] - 3)
if posicion[1] > 3 or posicion[1] < 3:
	movimientos = movimientos + abs(posicion[1] - 3)
print(movimientos)


l = []
ans = 0
for _ in range(5):
	arr = list(map(int, input().split()))
	l.append(arr)
for i in range(5):
	if 1 in l[i]:
		r = i
		c = l[i].index(1)
		break
ans += abs(r - 2)
ans += abs(c - 2)
print(ans)


n = 0
m = 0
for i in range(-2, 3):
	arr = map(int, input().split())
	for (pos, item) in enumerate(arr, start=-2):
		if item == 1:
			n = i
			m = pos
print(abs(n) + abs(m))


import sys
import math
from collections import Counter
from collections import OrderedDict
from functools import reduce
sys.setrecursionlimit(10 ** 6)

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

def printt(n):
	sys.stdout.write(str(n) + '\n')

def listt():
	return [int(i) for i in inputt().split()]

def gcd(a, b):
	return math.gcd(a, b)

def lcm(a, b):
	return a * b // gcd(a, b)

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def comb(n, k):
	factn = math.factorial(n)
	factk = math.factorial(k)
	fact = math.factorial(n - k)
	ans = factn // (factk * fact)
	return ans
l = []
for _ in range(5):
	li = listt()
	l.append(li)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			a = abs(2 - i) + abs(2 - j)
			printt(a)
			break


def jj(num):
	if num >= 0:
		return num
	else:
		return -num
mat = [[] for i in range(5)]
for i in range(5):
	line = input().split(' ')
	for j in range(len(line)):
		mat[i].append(int(line[j]))
x = 0
y = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			x = i + 1
			y = j + 1
print(jj(x - 3) + jj(y - 3))


i1 = 0
j1 = 0
for i in range(5):
	a = input().split()
	if a.count('1') == 1:
		i1 = i
		j1 = a.index('1')
		break
print(abs(i1 - 2) + abs(j1 - 2))


import math
n1 = input()
n2 = input()
n3 = input()
n4 = input()
n5 = input()
(m, n) = (0, 0)
if '1' in n1:
	print(int(math.fabs(3 - n1.find('1') // 2 - 1) + 2))
elif '1' in n5:
	print(int(math.fabs(3 - n5.find('1') // 2 - 1) + 2))
elif '1' in n4:
	print(int(math.fabs(3 - n4.find('1') // 2 - 1) + 1))
elif '1' in n3:
	print(int(math.fabs(3 - n3.find('1') // 2 - 1)))
elif '1' in n2:
	print(int(math.fabs(3 - n2.index('1') // 2 - 1) + 1))


i1 = 0
j2 = 0
for i in range(5):
	col = input()
	columna = col.split(' ')
	for j in range(5):
		if columna[j] == '1':
			i1 = i + 1
			j1 = j + 1
			break
x_moves = abs(j1 - 3)
y_moves = abs(i1 - 3)
print(x_moves + y_moves)


import sys
for i in range(5):
	s = list(map(int, input().split()))
	if 1 in s:
		x = s.index(1)
		print(abs(2 - x) + abs(2 - i))
		sys.exit()


mat = []
for x in range(5):
	a = list(input())
	a.remove(' ')
	a.remove(' ')
	a.remove(' ')
	a.remove(' ')
	mat.append(a)
for i in range(5):
	for j in range(5):
		if mat[i][j] == '1':
			m = i + j
			if i == 2 and j == 2:
				print(0)
			elif i % 4 == 0 and j % 4 == 0:
				print(4)
			elif m % 2 != 0 and (i == 2 or j == 2):
				print(1)
			elif m % 2 == 0:
				print(2)
			else:
				print(3)


a = []
c = 0
for i in range(5):
	c += 1
	a = [int(i) for i in input().split()]
	if sum(a) == 1:
		s = c
		f = a.index(1) + 1
print(abs(3 - s) + abs(3 - f))


for i in range(5):
	for (j, v) in enumerate(input().split()):
		if v == '1':
			dist = abs(2 - j) + abs(2 - i)
			print(dist)
			exit()


y = []
(n, m) = (1, 1)
for i in range(1, 6):
	x = input().split()
	y.append(x)
for a in range(0, 5):
	for b in range(0, 5):
		if y[a][b] == '1':
			n = a + 1
			m = b + 1
p = 0
if n == 3 and m == 3:
	print(0)
elif n == 3:
	p = 3 - m
	if p >= 0:
		print(p)
	else:
		print(-p)
elif m == 3:
	p = 3 - n
	if p >= 0:
		print(p)
	else:
		print(-p)
elif (n == 5 or n == 1) and (m == 5 or m == 1):
	print(4)
else:
	p = (3 - n) * (3 - m)
	if p >= 0:
		print(p + 1)
	else:
		print(-p + 1)


from math import fabs
l = []
l.append(list(map(int, input().split())))
l.append(list(map(int, input().split())))
l.append(list(map(int, input().split())))
l.append(list(map(int, input().split())))
l.append(list(map(int, input().split())))
(r, c) = (0, 0)
for x in l:
	r += 1
	if 1 in x:
		c = x.index(1)
		c += 1
		break
print(int(fabs(3 - r)) + int(fabs(3 - c)))


q = 1
f = 0
c = 0
while q <= 5 and f == 0:
	l = list(map(int, input().split()))
	for i in range(5):
		if l[i] == 1:
			f = 1
			break
	i += 1
	if f == 1:
		if q > 3:
			c += q - 3
		elif q < 3:
			c += 3 - q
		if i > 3:
			c += i - 3
		elif i < 3:
			c += 3 - i
	q += 1
print(c)


c = 0
pos = 0
for i in range(0, 5):
	if pos != 0:
		break
	c = c + 1
	list1 = list(map(int, input().split()))
	for i in range(0, len(list1)):
		if list1[i] == 1:
			pos = i + 1
			break
print(abs(3 - c) + abs(3 - pos))


line1 = input()
l1 = line1.split()
line2 = input()
l2 = line2.split()
line3 = input()
l3 = line3.split()
line4 = input()
l4 = line4.split()
line5 = input()
l5 = line5.split()
matrix = [l1, l2, l3, l4, l5]
for i in range(5):
	for j in range(5):
		if int(matrix[i][j]) == 1:
			n1 = 2 - i
			n2 = 2 - j
			n = abs(n1) + abs(n2)
print(n)


l = [input().split() for x in range(5)]
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			(r, c) = (i, j)
			break
print(abs(2 - r) + abs(2 - c))


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
import bisect as bi
import heapq

def I():
	return int(input())

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

def main():
	try:
		l = []
		for x in range(5):
			temp = list(In())
			l.append(temp)
		ans = []
		for x in range(5):
			for j in range(5):
				if l[x][j] == 1:
					ans = [x, j]
					break
		print(abs(2 - ans[0]) + abs(2 - ans[1]))
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


for i in range(5):
	A = input().split()
	if '1' in A:
		a = i
		break
for k in range(5):
	if A[k] == '1':
		b = k
		break
n = abs(a - 2) + abs(b - 2)
print(n)


import sys
l = []
for i in range(5):
	l.append([i for i in input().split(' ')])
for i in l:
	if '1' in i:
		c = i.index('1')
		r = l.index(i)
count = 0
while r != 2:
	if r > 2:
		r = r - 1
	else:
		r = r + 1
	count = count + 1
while c != 2:
	if c > 2:
		c = c - 1
	else:
		c = c + 1
	count = count + 1
print(count)


import sys

def main():
	for i in range(1, 6):
		line = ''.join(sys.stdin.readline().strip().split(' '))
		j = line.find('1') + 1
		if j > 0:
			ans = abs(3 - i) + abs(3 - j)
	print(ans)
main()


a = [input().split() for i in range(5)]
rad = 0
stolbik = 0
for i in range(5):
	for x in range(5):
		if a[i][x] == '1':
			rad = i
			stolbik = x
print(abs(rad - 2) + abs(stolbik - 2))


R = 5
C = 5
matrix = []
for i in range(R):
	(j1, j2, j3, j4, j5) = map(int, input().split())
	m = [j1, j2, j3, j4, j5]
	matrix.append(m)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			a = i
			b = j
l1 = []
l = []

def cal(a):
	while a > 2:
		a = a - 1
		l.append(a)
	while a < 2:
		a = a + 1
		l.append(a)
	return l
if a == 2 and b == 2:
	print(0)
else:
	if a > 2 or a < 2:
		l1 = cal(a)
	if b < 2 or b > 2:
		l1 = cal(b)
	print(len(l1))


n1 = list(map(int, input().split()))
n2 = list(map(int, input().split()))
n3 = list(map(int, input().split()))
n4 = list(map(int, input().split()))
n5 = list(map(int, input().split()))
if sum(n1) > 0:
	index1 = n1.index(1)
	print(abs(3 - (index1 + 1)) + 2)
elif sum(n5) > 0:
	index5 = n5.index(1)
	print(abs(3 - (index5 + 1)) + 2)
elif sum(n2) > 0:
	index2 = n2.index(1)
	print(abs(3 - (index2 + 1)) + 1)
elif sum(n4) > 0:
	index4 = n4.index(1)
	print(abs(3 - (index4 + 1)) + 1)
else:
	index3 = n3.index(1)
	print(abs(3 - (index3 + 1)))


import sys

def main():
	y = 0
	for line in sys.stdin:
		nums = line.strip().split(' ')
		nums = [int(n) for n in nums if not n == '']
		if 1 in nums:
			x = nums.index(1)
			j = y
			x = abs(x - 2)
			y = abs(y - 2)
			print(x + y)
			break
		y += 1
main()


a = []
x = 0
y = 0
for i in range(5):
	c = list(map(int, input().strip().split(' ')))
	if c.count(1) > 0:
		x = c.index(1)
		y = i
print(abs(x - 2) + abs(y - 2))


for i in range(5):
	n = input().split()
	if '1' in n:
		col = n.index('1')
		row = i
swap = 0
while row != 2:
	swap = swap + 1
	if row > 2:
		row = row - 1
	else:
		row = row + 1
while col != 2:
	swap = swap + 1
	if col > 2:
		col = col - 1
	else:
		col = col + 1
print(swap)


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()))
s = 0
for i in range(len(a)):
	if a[i] == 1:
		if i <= 2:
			s = 4 - i
		else:
			s = i
for i in range(len(b)):
	if b[i] == 1:
		if i <= 2:
			s = 3 - i
		else:
			s = i - 1
for i in range(len(c)):
	if c[i] == 1:
		if i < 2:
			s = 2 - i
		elif i >= 3:
			s = i - 2
		else:
			s = 0
for i in range(len(d)):
	if d[i] == 1:
		if i <= 2:
			s = 3 - i
		else:
			s = i - 1
for i in range(len(e)):
	if e[i] == 1:
		if i <= 2:
			s = 4 - i
		else:
			s = i
print(s)


import math
for i in range(5):
	n = list(filter(str.isdigit, input()))
	m = list(map(int, n))
	num = sum(m)
	if num == 1:
		D = i + 1
		er = m
for O in range(5):
	if er[O] == 1:
		C = O + 1
print(abs(3 - C) + abs(3 - D))


matrix = []
for i in range(5):
	l = list(map(int, input().split()))
	matrix.append(l)
d = [[index, row.index(1)] for (index, row) in enumerate(matrix) if 1 in row]
c = d[0]
print(abs(c[0] - 2) + abs(c[1] - 2))


row1 = input()
row1 = [int(i) for i in row1.split()]
row2 = input()
row2 = [int(i) for i in row2.split()]
row3 = input()
row3 = [int(i) for i in row3.split()]
row4 = input()
row4 = [int(i) for i in row4.split()]
row5 = input()
row5 = [int(i) for i in row5.split()]
matrix = [row1, row2, row3, row4, row5]
row = 0
column = 0
for e in range(len(matrix)):
	for j in range(len(matrix[e])):
		if matrix[e][j] == 1:
			row = e + 1
			column = j + 1
row = 3 - row
column = 3 - column
if row < 0:
	row = row * -1
if column < 0:
	column = column * -1
print(row + column)


n = 5
a = []
hod = 0
for i in range(n):
	b = []
	b = list(map(int, input().split()))
	a.append(b)
if 1 in a[0]:
	b = a[0].index(1)
	hod += 2
elif 1 in a[1]:
	b = a[1].index(1)
	hod += 1
elif 1 in a[2]:
	b = a[2].index(1)
elif 1 in a[3]:
	b = a[3].index(1)
	hod += 1
elif 1 in a[4]:
	b = a[4].index(1)
	hod += 2
if b == 0 or b == 4:
	hod += 2
elif b == 1 or b == 3:
	hod += 1
print(hod)


import math
n = []
n.append(input().split())
n.append(input().split())
n.append(input().split())
n.append(input().split())
n.append(input().split())
for (idx, val) in enumerate(n):
	for (idx2, val2) in enumerate(val):
		if val2 == '1':
			i = math.fabs(idx - 2)
			j = math.fabs(idx2 - 2)
			print(int(i + j))


import sys
matrix = sys.stdin.read().splitlines()
for (i, row) in enumerate(matrix):
	for (j, column) in enumerate(row.replace(' ', '')):
		if int(column) == 1:
			answer = abs(3 - (i + 1)) + abs(3 - (j + 1))
			break
print(answer)


ct = 0
mat = []
add_val = [2, 1, 0, 1, 2]
for i in range(5):
	temp = list(map(int, input().split()))
	mat.append(temp)
	if 1 in temp:
		ct = ct + add_val[i]
		ct = ct + add_val[temp.index(1)]
print(ct)


matrix = [[] for _ in range(5)]
hoehe = 0
breite = 0
output = 0
for i in range(5):
	e = input()
	matrix[i] = e.split(' ')
for ar in range(5):
	if '1' in matrix[ar]:
		breite = matrix[ar].index('1')
		hoehe = ar
	else:
		pass

def zaeler(wert):
	global output
	for _ in range(5):
		if wert == 2:
			break
		elif wert < 3:
			wert += 1
			output += 1
		elif wert > 2:
			wert -= 1
			output += 1
		else:
			pass
zaeler(breite)
zaeler(hoehe)
print(output)


matrix = []
loc = tuple()
for i in range(5):
	raw = [j for j in input().split()]
	matrix.append(raw)
	if '1' in raw:
		loc = (i + 1, raw.index('1') + 1)
abs(3 - loc[0]) + abs(3 - loc[1])
print(abs(3 - loc[0]) + abs(3 - loc[1]))


n = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(0, 5):
		if sum(n[i]) == 1:
			sum2 = abs(2 - i)
			if n[i][j] == 1:
				sum1 = abs(2 - j)
print(sum1 + sum2)


lines = []
one_x_pos = 0
one_y_pos = 0
for i in range(5):
	x = list(map(int, input().split()))
	lines.append(x)
for line in lines:
	for one in line:
		if one == 1:
			one_x_pos = line.index(one)
			one_y_pos = lines.index(line)
need = 0
if one_y_pos == 0:
	need += 2
if one_y_pos == 1:
	need += 1
if one_y_pos == 3:
	need += 1
if one_y_pos == 4:
	need += 2
if one_x_pos == 0:
	need += 2
if one_x_pos == 1:
	need += 1
if one_x_pos == 3:
	need += 1
if one_x_pos == 4:
	need += 2
print(need)


import math
a = []
for i in range(5):
	l = list(map(int, input().split()))
	a.append(l)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			c = math.fabs(j - 2)
			r = math.fabs(i - 2)
			break
print(int(c + r))


count = 0
for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	if b == 1 or d == 1:
		count += 1
	if a == 1 or e == 1:
		count += 2
	if 1 in [a, b, c, d, e]:
		if i == 1 or i == 3:
			count += 1
		if i == 0 or i == 4:
			count += 2
print(count)


def checklist(a):
	j = -1
	for i in range(len(a)):
		if a[i] == 1:
			j = i
	return j
sum = 0
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s3 = list(map(int, input().split()))
s4 = list(map(int, input().split()))
s5 = list(map(int, input().split()))
s = [s1, s2, s3, s4, s5]
for i in range(5):
	if checklist(s[i]) != -1:
		if i == 3 or i == 1:
			sum = sum + 1
		elif i == 0 or i == 4:
			sum = sum + 2
		if checklist(s[i]) == 3 or checklist(s[i]) == 1:
			sum = sum + 1
		elif checklist(s[i]) == 0 or checklist(s[i]) == 4:
			sum = sum + 2
print(sum)


l = []
n = 0
while n != 5:
	l.append(list(map(int, input().split())))
	if 1 in l[n]:
		col = l[n].index(1) + 1
		row = n + 1
	n = n + 1
print(abs(3 - row) + abs(col - 3))


matrix = []
c = 0
while c < 5:
	matrix.append([int(i) for i in input().split()])
	c += 1
x = 0
y = 0
step = 0
pos = False
for i in matrix:
	c = 0
	for j in i:
		if j == 1:
			x = c
			pos = True
			break
		elif c == 4:
			break
		else:
			c += 1
			continue
	if pos == True:
		break
	else:
		y += 1
		continue
while x != 2:
	if x > 2:
		x -= 1
		step += 1
	else:
		x += 1
		step += 1
while y != 2:
	if y > 2:
		y -= 1
		step += 1
	else:
		y += 1
		step += 1
print(step)


ls = list()
mx = 0
for i in range(0, 5):
	ele = input()
	num = list(map(int, ele.split()))
	ls.append(num)
for i in range(0, 5):
	for j in range(0, 5):
		if ls[i][j] == 1:
			if i <= 2:
				mx += 2 - i
			elif i > 2:
				mx += i - 2
			if j <= 2:
				mx += 2 - j
			elif j > 2:
				mx += j - 2
print(mx)


def solve():
	n = 5
	ans = 0
	for i in range(n):
		for (j, s) in enumerate([int(s) for s in input().split()]):
			if s == 1:
				ans = abs(2 - j) + abs(2 - i)
	print(ans)
solve()


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def inn():
	return int(input())
mo = 1000000007
a = [[int(x) for x in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
			exit()


m = []
for _ in range(5):
	m.append(input().split())
(row, col) = (0, 0)
for i in range(5):
	for j in range(5):
		if m[i][j] == '1':
			(row, col) = (i, j)
print(abs(row - 2) + abs(col - 2))


l = []
x = 1
y = 1
for u in range(5):
	l1 = list(map(int, input().split()))
	l += [l1]
	if 1 in l1:
		x += l1.index(1)
		y += l.index(l1)
print(abs(x - 3) + abs(y - 3))


mvFromMid = [2, 1, 0, 1, 2]
for i in mvFromMid:
	x = list(input())
	if '1' in x:
		print(i + mvFromMid[x.index('1') // 2])


import sys
j = None
for (i, line) in enumerate(sys.stdin):
	for c in range(0, 10, 2):
		if line[c] == '1':
			j = c // 2
			break
	if j != None:
		break
print(abs(j - 2) + abs(i - 2))


matline = []
for i in range(5):
	matline.append(input().split())
r_num = 0
c_num = 0
for i in range(5):
	for j in range(5):
		if matline[i][j] == '1':
			row = i + 1
			column = j + 1
print(abs(3 - row) + abs(3 - column))


x = 0
y = 0
a = 0
b = 0
flag = 0
summer = 0
for _ in range(5):
	y += 1
	l = list(map(int, input().split()))
	x = 0
	for i in l:
		x += 1
		if i == 1:
			b = y
			a = x
			flag = 1
			break
	if flag == 1:
		break
summer = abs(3 - a) + abs(3 - b)
print(summer)


matrix = [input().split() for i in range(5)]
index_row = 0
index_column = 0
moves = 0
for (index, row) in enumerate(matrix):
	if '1' in row:
		index_row = index
		for (index2, column) in enumerate(row):
			if column == '1':
				index_column = index2
moves += abs(index_row - 2)
moves += abs(index_column - 2)
print(moves)


(r, c) = (5, 5)
mat = []
for i in range(r):
	mat.append(list(map(int, input().split())))
for i in range(r):
	for j in range(c):
		if mat[i][j] == 1:
			val1 = i
			val2 = j
			break
print(abs(val1 - 2) + abs(val2 - 2))


maytricks = []
for _ in range(5):
	new_row = [int(a) for a in input().strip().split()]
	maytricks.append(new_row)
one_col = None
one_row = None
center = (2, 2)
for row in range(5):
	for column in range(5):
		if maytricks[row][column] == 1:
			one_col = column
			one_row = row
moves = abs(one_col - 2) + abs(one_row - 2)
print(moves)


for i in range(5):
	Matrix = input().split()
	for j in range(5):
		if Matrix[j] != '0':
			result = abs(i - 2) + abs(j - 2)
			print(result)


cun = []
for i in range(5):
	judge = 0
	list = input().split()
	for j in range(5):
		if list[j] == '0':
			judge += 0
			continue
		if list[j] == '1':
			judge += 1
			cun.append(j + 1)
			break
	if judge == 0:
		continue
	if judge == 1:
		cun.append(i + 1)
		break
x = cun[0]
y = cun[1]
print(abs(x - 3) + abs(y - 3))


now = []
count = 1
for x in range(5):
	now.append(input().split())
for i in range(len(now)):
	for j in range(len(now[i])):
		if '1' == now[i][j]:
			row = i + 1
			colm = j + 1
rows = row - 3
colms = colm - 3
print(abs(rows) + abs(colms))


rows = 5
array = []
get_row = 0
get_col = 0
for i in range(rows):
	data = list(map(int, input().split()))
	try:
		get_col = data.index(1)
		get_row = i
	except:
		pass
	array.append(data)
print(abs(get_row - 2) + abs(get_col - 2))


matrix = []
for i in range(1, 6):
	k = input().split()
	c = []
	for j in range(1, 6):
		c.append(int(k[j - 1]))
		if int(k[j - 1]) == 1:
			ii = i
			jj = j
		else:
			pass
	matrix.append(c)
moves = 0
y = abs(ii - 3)
u = abs(jj - 3)
moves = y + u
print(moves)


import math
a = input('').split()
b = input('').split()
c = input('').split()
d = input('').split()
e = input('').split()
ycor = 0
for i in (a, b, c, d, e):
	ycor += 1
	if '1' in str(i):
		lis = i
		break
xcor = 1
for k in range(len(lis)):
	if str(lis[k]) != '1':
		xcor += 1
	else:
		break
print(int(math.fabs(3 - xcor) + math.fabs(3 - ycor)))


li = []
index = []
for i in range(5):
	li.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if li[i][j] == 1:
			index = [i, j]
diff1 = abs(3 - (index[0] + 1))
diff2 = abs(3 - (index[1] + 1))
print(diff1 + diff2)


a = []
(inner, outer) = (0, 0)
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if 1 in a[j]:
			inner = a[j].index(1) + 1
			outer = j + 1
(x, y) = (((3 - inner) ** 2) ** 0.5, ((3 - outer) ** 2) ** 0.5)
print(int(x + y))


for i in range(5):
	a = input().split()
	for j in range(5):
		if a[j] != '0':
			x = i
			y = j
			break
print(abs(x - 2) + abs(y - 2))


matrix = []
for i in range(5):
	n = input().split()
	matrix.append(n)

def create(matrix):
	for i in range(5):
		for j in range(5):
			if matrix[i][j] != '0':
				row = 2 - i
				column = 2 - j
				if row < 0:
					row = -row
				if column < 0:
					column = -column
	m = row + column
	print(m)
create(matrix)


row = 0
col = 0
for i in range(5):
	a = input().split()
	try:
		a.index('1')
		row = i
		col = a.index('1')
	except:
		continue
print(abs(2 - row) + abs(2 - col))


def row_l(mat, i):
	global s
	while i != 2:
		(mat[i], mat[i + 1]) = (mat[i + 1], mat[i])
		i += 1
		s += 1
	return s

def row_u(mat, i):
	global s
	while i != 2:
		(mat[i], mat[i - 1]) = (mat[i - 1], mat[i])
		i -= 1
		s += 1
	return s
mat = []
s = 0
for i1 in range(5):
	row = list(map(int, input().split(' ')))
	for j1 in row:
		if j1 == 1:
			(i, j) = (i1, row.index(j1))
	mat.append(row)
if i == 2:
	pass
elif i < 2:
	row_l(mat, i)
else:
	row_u(mat, i)
mat = list(zip(*mat))
if j == 2:
	print(s)
elif j < 2:
	print(row_l(mat, j))
else:
	print(row_u(mat, j))


import math
odin = 0
for i in range(2, -3, -1):
	x = input().split()
	for j in range(-2, 3):
		if '1' == x[j + 2]:
			odin = j
			koord = i
			break
	if odin > 0:
		break
krasota = math.fabs(koord) + math.fabs(odin)
print(int(krasota))


matrix = []
(res, r, c) = (0, 0, 0)
for i in range(5):
	matrix.append(list(filter(lambda a: a != ' ', input())))
for i in range(5):
	row = matrix[i]
	if '1' in row:
		r = i + 1
		c = row.index('1') + 1
		break
res = abs(r - 3) + abs(c - 3)
print(res)


r1 = input().split() + ['2']
r2 = input().split() + ['3']
r3 = input().split() + ['4']
r4 = input().split() + ['5']
r5 = input().split() + ['6']
for c in [r1, r2, r3, r4, r5]:
	if '1' in c:
		x = int(c[5]) - 1
		y = c.index('1')
print(str(abs(x - 3) + abs(y - 2)))


for x in range(0, 5):
	inp = input()
	if '1' in inp:
		row = x + 1
		fullRow = inp.split(' ')
		for y in range(0, len(fullRow)):
			if int(fullRow[y]) == 1:
				column = y + 1
result = abs(row - 3) + abs(column - 3)
print(result)


import math

def get_int_vector():
	return [int(x) for x in input().split()]
(i, j) = (0, 0)
for row in range(5):
	vec = get_int_vector()
	for idx in range(5):
		if vec[idx] == 1:
			i = row
			j = idx
print(abs(2 - i) + abs(2 - j))


m = []
for i in range(5):
	n = list(map(int, input().split()))
	m.append(n)
x = 0
y = 0
for i in range(len(m)):
	for j in range(len(m)):
		if m[i][j] == 1:
			x = i
			y = j
			break
		pass
print(abs(x - 2) + abs(y - 2))


A = []
(x, y) = (0, 0)
for i in range(5):
	A.append([int(i) for i in input().split()])
	try:
		x = A[i].index(1) + 1
		y = i + 1
	except ValueError:
		pass
print(abs(x - 3) + abs(y - 3))


a = []
for i in range(5):
	arr = list(map(int, input().rstrip().split()))
	if 1 in arr:
		d = [abs(2 - i), abs(2 - arr.index(1))]
print(d[0] + d[1])


matrix = []
for _ in range(5):
	matrix.append([int(a) for a in input().split(' ')])
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			(i_one, j_one) = (i, j)
			break
print(abs(i_one - 2) + abs(j_one - 2))


def solve():
	a = []
	(oner, onec) = (0, 0)
	for i in range(5):
		t = [int(i) for i in input().split()]
		for (ind, tt) in enumerate(t):
			if tt == 1:
				oner = i
				onec = ind
		a.append(t)
	print(abs(onec - 2) + abs(oner - 2))
solve()


a = 0
b = 0
for i in range(1, 6):
	mat = input().split()
	if '1' in mat:
		a = i
		b = mat.index('1')
result = abs(a - 3) + abs(b + 1 - 3)
print(result)


li = []
for jk in range(5):
	li.append(input().split(' '))
for bn in range(5):
	if '1' in li[bn]:
		chai = li[bn].index('1')
		bh = bn
print(abs(2 - bh) + abs(2 - chai))


r1 = str(input())
r2 = str(input())
r3 = str(input())
r4 = str(input())
r5 = str(input())
if '1' in r1:
	m = 2
	if '1' == r1[0]:
		m += 2
		print(m)
	elif '1' == r1[2]:
		m += 1
		print(m)
	elif '1' == r1[4]:
		m += 0
		print(m)
	elif '1' == r1[6]:
		m += 1
		print(m)
	elif '1' == r1[8]:
		m += 2
		print(m)
elif '1' in r2:
	m = 1
	if '1' == r2[0]:
		m += 2
		print(m)
	elif '1' == r2[2]:
		m += 1
		print(m)
	elif '1' == r2[4]:
		m += 0
		print(m)
	elif '1' == r2[6]:
		m += 1
		print(m)
	elif '1' == r2[8]:
		m += 2
		print(m)
elif '1' in r3:
	m = 0
	if '1' == r3[0]:
		m += 2
		print(m)
	elif '1' == r3[2]:
		m += 1
		print(m)
	elif '1' == r3[4]:
		m += 0
		print(m)
	elif '1' == r3[6]:
		m += 1
		print(m)
	elif '1' == r3[8]:
		m += 2
		print(m)
elif '1' in r4:
	m = 1
	if '1' == r4[0]:
		m += 2
		print(m)
	elif '1' == r4[2]:
		m += 1
		print(m)
	elif '1' == r4[4]:
		m += 0
		print(m)
	elif '1' == r4[6]:
		m += 1
		print(m)
	elif '1' == r4[8]:
		m += 2
		print(m)
if '1' in r5:
	m = 2
	if '1' == r5[0]:
		m += 2
		print(m)
	elif '1' == r5[2]:
		m += 1
		print(m)
	elif '1' == r5[4]:
		m += 0
		print(m)
	elif '1' == r5[6]:
		m += 1
		print(m)
	elif '1' == r5[8]:
		m += 2
		print(m)


si = 0
sj = 0
for i in range(0, 5):
	l = [int(x) for x in input().split()]
	for j in range(0, 5):
		if l[j] == 1:
			si = i + 1
			sj = j + 1
ans = abs(si - 3) + abs(sj - 3)
print(ans)


a = []
for i in range(1, 5 + 1):
	x = input().split()
	a.append(x)
for i in range(0, 4 + 1):
	for j in range(0, 4 + 1):
		if a[i][j] == '1':
			p = i + 1
			q = j + 1
r = abs(p - 3) + abs(q - 3)
print(r)


def beautifulMatrix(mat):
	cnt = 0
	for i in range(len(mat)):
		for j in range(len(mat[i])):
			if mat[i][j] == 1:
				print(abs(i - 2) + abs(j - 2))
arr = [list(map(int, input().split())) for x in range(0, 5)]
beautifulMatrix(arr)


x = 5
while x:
	t = list(map(int, input().strip().split()))
	if 1 in t:
		p = 5 - x
		c = abs(p - 2) + abs(t.index(1) - 2)
	x = x - 1
print(c)


L = []
n = 5
while n:
	l = list(input().split())
	L.append(l)
	n = n - 1
count = 0
if '1' in L[0]:
	count = count + 2
	if '1' == L[0][0]:
		count = count + 2
	elif '1' == L[0][1]:
		count = count + 1
	elif '1' == L[0][3]:
		count = count + 1
	elif '1' == L[0][4]:
		count = count + 2
elif '1' in L[1]:
	count = count + 1
	if '1' == L[1][0]:
		count = count + 2
	elif '1' == L[1][1]:
		count = count + 1
	elif '1' == L[1][3]:
		count = count + 1
	elif '1' == L[1][4]:
		count = count + 2
elif '1' in L[2]:
	if '1' == L[2][0]:
		count = count + 2
	elif '1' == L[2][1]:
		count = count + 1
	elif '1' == L[2][3]:
		count = count + 1
	elif '1' == L[2][4]:
		count = count + 2
elif '1' in L[3]:
	count = count + 1
	if '1' == L[3][0]:
		count = count + 2
	elif '1' == L[3][1]:
		count = count + 1
	elif '1' == L[3][3]:
		count = count + 1
	elif '1' == L[3][4]:
		count = count + 2
elif '1' in L[4]:
	count = count + 2
	if '1' == L[4][0]:
		count = count + 2
	elif '1' == L[4][1]:
		count = count + 1
	elif '1' == L[4][3]:
		count = count + 1
	elif '1' == L[4][4]:
		count = count + 2
print(count)


temp_list = []
for i in range(5):
	temp = input().split()
	temp_list.append(temp)
for i in range(5):
	for j in range(5):
		if temp_list[i][j] == '1':
			print(abs(j - 2) + abs(i - 2))


s = 0
i = 0
j = 0
k = 0
m = 0
rows = 5
matrix = []
for m in range(rows):
	matrix.append(list(map(int, input().rstrip().split())))
while s == 0:
	if i < 5 and j < 5:
		s = matrix[i][j]
		i = i + 1
	elif i == 5:
		j = j + 1
		i = 0
k = abs(i - 3) + abs(j - 2)
print(k)


n = 5
(x, y) = (0, 0)
for row in range(n):
	lst = list(map(int, input().split()[:n]))
	for column in range(len(lst)):
		if lst[column] == 1:
			x = row
			y = column
absX = abs(x - 2)
absy = abs(y - 2)
print(absX + absy)


d = []
h = 0
g = 0
for i in range(5):
	f = input()
	f = f.split()
	d.append(f)
for i in range(5):
	for j in range(5):
		if d[i][j] == '1':
			h = i
			g = j
gh = abs(g - 2)
hh = abs(h - 2)
print(gh + hh)


row_1 = input()
final_1 = row_1.split()
row_2 = input()
final_2 = row_2.split()
row_3 = input()
final_3 = row_3.split()
row_4 = input()
final_4 = row_4.split()
row_5 = input()
final_5 = row_5.split()
final_matrix = [final_1, final_2, final_3, final_4, final_5]
location_row = 0
location_column = 0
middle_row = 2
middle_column = 2
for row_index in range(len(final_matrix)):
	for column_index in range(len(final_matrix)):
		if final_matrix[row_index][column_index] == '1':
			location_row = row_index
			location_column = column_index
			break
x = abs(location_row - middle_row)
y = abs(location_column - middle_column)
sum = x + y
print(sum)


col = 0
row = 0
found = 0
for i in range(0, 5):
	line = input().split()
	for j in range(0, 5):
		if line[j] == '1':
			col = j
			found = 1
			break
	if found != 0:
		row = i
		break
print(abs(row - 2) + abs(col - 2))


matrix = {}
line1 = input().split()
line2 = input().split()
line3 = input().split()
line4 = input().split()
line5 = input().split()
a = 1
for x in line1:
	matrix['1 ' + str(int(a))] = x
	a += 1
b = 1
for x in line2:
	matrix['2 ' + str(int(b))] = x
	b += 1
c = 1
for x in line3:
	matrix['3 ' + str(int(c))] = x
	c += 1
d = 1
for x in line4:
	matrix['4 ' + str(int(d))] = x
	d += 1
e = 1
for x in line5:
	matrix['5 ' + str(int(e))] = x
	e += 1
for key in matrix:
	if matrix[key] == '1':
		pos = key.split()
print(abs(3 - int(pos[0])) + abs(3 - int(pos[1])))


row1 = str(input()).split(' ')
row2 = str(input()).split(' ')
row3 = str(input()).split(' ')
row4 = str(input()).split(' ')
row5 = str(input()).split(' ')
row = row1 + row2 + row3 + row4 + row5
place = row.index('1')
y = int(place / 5) + 1
x = place - int((y - 1) * 5) + 1
turns = abs(3 - y) + abs(3 - x)
print(turns)


counter = 0
string_numb = 0
for i in range(5):
	string = input().split()
	if '1' in string:
		string_numb = i + 1
		break
for i in string:
	counter += 1
	if i == '1':
		break
answer = abs(3 - string_numb) + abs(3 - counter)
print(answer)


s = input().split()
count = 0
if '1' in s:
	count = count + 2
	z = s.index('1') + 1
	if z == 3:
		f = 0
	elif z > 3:
		f = z - 3
	else:
		f = 3 - z
	count = count + f
s1 = input().split()
if '1' in s1:
	count = count + 1
	z = s1.index('1') + 1
	if z == 3:
		f = 0
	elif z > 3:
		f = z - 3
	else:
		f = 3 - z
	count = count + f
s2 = input().split()
if '1' in s2:
	z = s2.index('1') + 1
	if z == 3:
		f = 0
	elif z > 3:
		f = z - 3
	else:
		f = 3 - z
	count = count + f
s3 = input().split()
if '1' in s3:
	count = count + 1
	z = s3.index('1') + 1
	if z == 3:
		f = 0
	elif z > 3:
		f = z - 3
	else:
		f = 3 - z
	count = count + f
s4 = input().split()
if '1' in s4:
	count = count + 2
	z = s4.index('1') + 1
	if z == 3:
		f = 0
	elif z > 3:
		f = z - 3
	else:
		f = 3 - z
	count = count + f
print(count)


for i in range(5):
	c = input().replace(' ', '').find('1')
	if c != -1:
		row = i + 1
		collumn = c + 1
print(abs(row - 3) + abs(collumn - 3))


r1 = input()
r1 = r1.split(' ')
r2 = input()
r2 = r2.split(' ')
r3 = input()
r3 = r3.split(' ')
r4 = input()
r4 = r4.split(' ')
r5 = input()
r5 = r5.split(' ')
ini_row = 3
ini_col = 3
col = 0
row = 0
if '1' in r1:
	col = 1
	row = r1.index('1') + 1
	print(abs(ini_col - col) + abs(ini_row - row))
elif '1' in r2:
	col = 2
	row = r2.index('1') + 1
	print(abs(ini_col - col) + abs(ini_row - row))
elif '1' in r3:
	col = 3
	row = r3.index('1') + 1
	print(abs(ini_col - col) + abs(ini_row - row))
elif '1' in r4:
	col = 4
	row = r4.index('1') + 1
	print(abs(ini_col - col) + abs(ini_row - row))
elif '1' in r5:
	col = 5
	row = r5.index('1') + 1
	print(abs(ini_col - col) + abs(ini_row - row))


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().strip().split())))
oneListR = 0
oneListC = 0
for j in range(len(matrix)):
	if 1 in matrix[j]:
		oneListR = j
		oneListC = matrix[j].index(1)
print(abs(oneListR - 2) + abs(oneListC - 2))


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
for i in range(len(l1)):
	if l1[i] == 1:
		print(2 + abs(3 - (i + 1)))
	if l2[i] == 1:
		print(1 + abs(3 - (i + 1)))
	if l3[i] == 1:
		print(abs(3 - (i + 1)))
	if l4[i] == 1:
		print(1 + abs(3 - (i + 1)))
	if l5[i] == 1:
		print(2 + abs(3 - (i + 1)))


a = [[str(j) for j in input().split()] for i in range(5)]
r = 1
c = 1
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			q = 2 - i
			w = 2 - j
			if q < 0:
				q = -q
			if w < 0:
				w = -w
			print(q + w)
			exit(0)


matrix = []
n = 1
res = ''
while n < 6:
	m = input().split()
	if '1' in m:
		y = n
		x = m.index('1') + 1
		res = abs(3 - x) + abs(3 - y)
	n = n + 1
print(res)


matrix = []
for i in range(5):
	line = input().split(' ')
	matrix.append(line)
for x in range(5):
	for y in range(5):
		if matrix[x][y] == '1':
			row = x
			column = y
steps = 0
if row > 2:
	steps = steps + row - 2
else:
	steps = steps + 2 - row
if column > 2:
	steps = steps + column - 2
else:
	steps = steps + 2 - column
print(steps)


t = ''
for i in range(0, 5):
	a = input()
	t += a
	t = t.replace(' ', '')
a = len(t.split('1')[0])
row = int(a / 5 + 1)
col = a % 5 + 1
print(abs(row - 3) + abs(col - 3))


x = []
for _ in range(5):
	x.append(list(map(int, input().split())))
i1 = 0
for i in x:
	if 1 in i:
		j = i.index(1)
		break
	i1 = i1 + 1
(p, q) = (2, 2)
r1 = 0
r2 = 0
if p != i1:
	r1 = abs(p - i1)
if q != j:
	r2 = abs(q - j)
print(r1 + r2)


l = [[int(x) for x in input().split()] for j in range(5)]
for (i, x) in enumerate(l):
	if 1 in x:
		p = i
		q = x.index(1)
print(abs(p - 2) + abs(q - 2))


a = list()
for i in range(0, 5):
	a.append(list(map(int, input().split())))
i = 0
flag = 1
while i < 5:
	j = 0
	while j < 5:
		if a[i][j] == 1:
			flag = 0
			break
		j += 1
	if flag:
		i += 1
	else:
		break
print(abs(i - 2) + abs(j - 2))


def beep(db):
	for y in range(5):
		for x in range(5):
			if db[y][x] == 1:
				return (x + 1, y + 1)
db = []
for i in range(5):
	(a, b, c, d, e) = input().split(' ')
	db.append([int(a), int(b), int(c), int(d), int(e)])
(Xindex, Yindex) = beep(db)
count = 0
if Xindex > 3:
	count = Xindex - 3
else:
	count = 3 - Xindex
if Yindex > 3:
	count = Yindex - 3 + count
else:
	count = 3 - Yindex + count
print(count)


ROW = 5
mtx = []
for i in range(ROW):
	mtx.append(input().split(' '))
flag = False
for x in range(ROW):
	for y in range(len(mtx[x])):
		if mtx[x][y] == '1':
			flag = True
			break
	if flag:
		break
x += 1
y += 1
print(abs(x - 3) + abs(y - 3))


p = [[], [], [], [], []]
for i in range(5):
	(q, w, e, r, t) = map(int, input().split())
	p[i].append(q)
	p[i].append(w)
	p[i].append(e)
	p[i].append(r)
	p[i].append(t)
for i in range(5):
	for j in range(5):
		if p[i][j] == 1:
			x = i
			y = j
if x <= 2 and y <= 2:
	print(4 - x - y)
elif x >= 2 and y <= 2:
	print(x - y)
elif x <= 2 and y >= 2:
	print(y - x)
elif x >= 2 and y >= 2:
	print(x + y - 4)


from sys import stdin
r = 1
c = 1
for i in range(1, 6):
	a = [int(i) for i in stdin.readline().split(' ')]
	if 1 in a:
		c = a.index(1) + 1
		r = i
print(abs(r - 3) + abs(c - 3))


for a in range(5):
	b = input().split()
	for c in range(5):
		if b[c] == '1':
			d = abs(a - 2) + abs(c - 2)
print(d)


one = input()
two = input()
tree = input()
four = input()
five = input()
one = one.replace(' ', '')
two = two.replace(' ', '')
tree = tree.replace(' ', '')
four = four.replace(' ', '')
five = five.replace(' ', '')
if one[0] == '1' or one[4] == '1' or five[0] == '1' or (five[4] == '1'):
	print(4)
elif one[1] == '1' or one[3] == '1' or two[0] == '1' or (two[4] == '1') or (four[0] == '1') or (four[4] == '1') or (five[1] == '1') or (five[3] == '1'):
	print(3)
elif one[2] == '1' or five[2] == '1' or tree[0] == '1' or (tree[4] == '1') or (two[1] == '1') or (two[3] == '1') or (four[1] == '1') or (four[3] == '1'):
	print(2)
elif tree[2] == '1':
	print(0)
else:
	print(1)


import sys
import math
import os
l = []
for x in range(5):
	temp = sys.stdin.readline().split()
	if '1' in temp:
		col = temp.index('1') + 1
		row = x + 1
		rep = abs(col - 3) + abs(row - 3)
print(rep)


L = []
for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	L.append([a, b, c, d, e])
for i in range(5):
	if 1 in L[i]:
		line = L[i]
		row = i + 1
for j in range(5):
	if line[j] == 1:
		col = j + 1
print(abs(row - 3) + abs(col - 3))


mat = []
for x in range(5):
	l = [int(x) for x in input().split()]
	mat.append(l)
for x in range(5):
	for y in range(5):
		if mat[x][y] == 1:
			row = x + 1
			col = y + 1
			break
swaps = abs(row - 3) + abs(col - 3)
print(swaps)


x = 0
for i in range(5):
	l1 = list(map(int, input().split()))
	if 1 in l1:
		res = l1.index(1, 0)
		x = i
		break
print(abs(res - 2) + abs(x - 2))


matrix = []
swap = 0
for i in range(5):
	ele = list(map(int, input().split()))
	if 1 in ele:
		row = i
		col = ele.index(1)
	matrix.append(ele)
while row != 2:
	if row > 2:
		(matrix[row][col], matrix[row - 1][col]) = (matrix[row - 1][col], matrix[row][col])
		row = row - 1
		swap = swap + 1
	else:
		(matrix[row][col], matrix[row + 1][col]) = (matrix[row + 1][col], matrix[row][col])
		row = row + 1
		swap = swap + 1
while col != 2:
	if col > 2:
		(matrix[row][col], matrix[row][col - 1]) = (matrix[row][col - 1], matrix[row][col])
		col = col - 1
		swap = swap + 1
	else:
		(matrix[row][col], matrix[row][col + 1]) = (matrix[row][col + 1], matrix[row][col])
		col = col + 1
		swap = swap + 1
print(swap)


def main():
	from sys import stdout
	res = 0
	for i in range(-2, 3):
		line = list(map(int, input().split()))
		if not line[0] == line[1] == line[2] == line[3] == line[4]:
			res += abs(i)
			for j in range(5):
				if line[j] == 1:
					res += abs(j - 2)
	stdout.write(str(res))
main()


m = []
for i in range(5):
	l = list(map(int, input().split()))
	if l.count(1) == 1:
		p = abs(2 - i) + abs(2 - l.index(1))
print(p)


import sys
INF = 10000000
matrix = []
for line in sys.stdin:
	row = [int(x) for x in line.split()]
	matrix.append(row)
steps = INF
for i in range(5):
	for j in range(5):
		if matrix[i][j] != 1:
			continue
		newSteps = abs(i - 2) + abs(j - 2)
		if newSteps < steps:
			steps = newSteps
if steps == INF:
	print(0)
else:
	print(steps)


l = []
x1 = 0
y1 = 0
for i in range(5):
	t = []
	ip = input()
	t = ip.split(' ')
	for j in range(5):
		t[j] = int(t[j])
		if t[j] == 1:
			x1 = i
			y1 = j
	l.append(t)
ans = abs(2 - x1) + abs(2 - y1)
print(ans)


cont = 0
for i in range(1, 6):
	x = input()
	y = x.find('1')
	if y != -1:
		if y >= 4:
			cont = cont + (y - 4) // 2
		elif y <= 4:
			cont = cont + (4 - y) // 2
		if i < 3:
			cont = cont + (3 - i)
		elif i > 3:
			cont = cont + (i - 3)
print(cont)


def find_coordinates(lst):
	for j in range(5):
		for k in range(5):
			if lst[j][k] == 1:
				return (j, k)

def main():
	lin = []
	for i in range(5):
		lin.append([int(x) for x in input().split()])
	val = find_coordinates(lin)
	print(abs(2 - val[0]) + abs(2 - val[1]))
main()


def main():
	for i in range(1, 6):
		str = input()
		str = str.replace(' ', '')
		for j in range(5):
			if str[j] == '1':
				(a, b) = (i, j + 1)
				break
	print(abs(3 - a) + abs(3 - b))
main()


t = 0
for x in range(5):
	mt = list(map(int, input().split(' ')))
	for y in range(5):
		if mt[y] == 1:
			t += abs(x - 2) + abs(y - 2)
			break
print(t)


k = 0
x = 0
y = 0
for i in range(5):
	list = input().split()
	if '1' in list:
		p = list.index('1')
		x = abs(2 - p)
		y = abs(2 - k)
		k = k + 1
	else:
		k = k + 1
print(x + y)


for i in range(5):
	line = list(map(int, input().split()))
	if 1 in line:
		x = i + 1
		let = line
y = let.index(1)
y = abs(2 - y)
x = abs(3 - x)
print(x + y)


i = 0
for x in range(5):
	str1 = input()
	i += 1
	if str1 != '0 0 0 0 0':
		break
list1 = [int(m) for m in str1.split()]
j = list1.index(1) + 1
print(abs(i - 3) + abs(j - 3))


for i in range(1, 6):
	k = list(map(int, input().split()))
	if 1 in k:
		print(abs(i - 3) + abs(k.index(1) - 2))


def bublesort(a):
	n = len(a)
	fl1 = False
	while not fl1:
		fl1 = True
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				(a[i], a[i + 1]) = (a[i + 1], a[i])
				fl1 = False

def isgood(a):
	k = 0
	for x in a:
		if x == 'a':
			k += 1
	return k > len(a) // 2

def dell(a):
	k = 0
	for x in a:
		if x != 'a':
			return a[:k] + a[k + 1:]
		k += 1

def pl2d(a):
	for t in a:
		for x in t:
			print(x, end=' ')
		print()

def foundm(x, a, row, col):
	for i in range(row):
		for j in range(col):
			if a[i][j] == x:
				return (i, j)

def swaprow(a, n1, n2):
	(a[n1], a[n2]) = (a[n2], a[n1])

def swapcol(a, k1, k2):
	for lst in a:
		swaprow(lst, k1, k2)
(row, col) = (5, 5)
a = []
for i in range(row):
	b = list(map(int, input().split()))
	a.append(b)
(row1, col1) = foundm(1, a, 5, 5)
k = 0
while col1 != 2:
	if col1 > 2:
		swapcol(a, col1, col1 - 1)
		col1 -= 1
	else:
		swaprow(a, col1, col1 + 1)
		col1 += 1
	k += 1
while row1 != 2:
	if row1 > 2:
		swaprow(a, row1, row1 - 1)
		row1 -= 1
	else:
		swaprow(a, row1, row1 + 1)
		row1 += 1
	k += 1
print(k)


matrix = []
for i in (1, 2, 3, 4, 5):
	row = list(map(int, input().split(' ')))
	matrix.append(row)
ir = -1
ic = -1
for i in (0, 1, 2, 3, 4):
	for j in (0, 1, 2, 3, 4):
		if matrix[i][j] == 1:
			ir = i
			ic = j
mr = abs(ir - 2) + abs(ic - 2)
print(mr)


matrix = list()
for i in range(5):
	matrix.append(input().split())
for i in range(5):
	if '1' in matrix[i]:
		print(abs(2 - i) + abs(2 - matrix[i].index('1')))


n = 5
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	if 1 in a[i]:
		count = abs(2 - a[i].index(1)) + abs(2 - i)
		print(count)
		break


matrix = [[], [], [], [], []]
num_pos = []
for _ in range(5):
	n = input().split(' ')
	if '1' in n:
		num_pos.append(_)
		num_pos.append(n.index('1'))
	matrix[_].append(n)
print(abs(int(num_pos[0]) - 2) + abs(int(num_pos[1]) - 2))


for i in range(5):
	line = input()
	if '1' in line:
		j = line.find('1') // 2
		break
print(abs(2 - i) + abs(2 - j))


import sys
l = []

def pos(a):
	if a >= 0:
		return a
	else:
		return -a
for x in range(5):
	a = sys.stdin.readline()
	a = a.split()
	a = [int(x) for x in a]
	l.append(a)
smm = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			smm = pos(2 - i) + pos(j - 2)
print(smm)


def get_pos(l):
	index = 0
	for i in l:
		if i is '1':
			return index
		index = index + 1
for i in range(5):
	a = input().split()
	if '1' in a:
		if get_pos(a) > 2:
			f = get_pos(a) - 2
		else:
			f = 2 - get_pos(a)
		if i > 2:
			g = i - 2
		else:
			g = 2 - i
n = f + g
print(n)


lis = []
for i in range(5):
	temp = list(map(int, input().split()))
	lis.append(temp)
for i in range(5):
	for j in range(5):
		if lis[i][j] == 1:
			res = [i, j]
print(abs(res[0] - 2) + abs(res[1] - 2))


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')

def main():
	arr = []
	for i in range(5):
		arr.append(ain())
	row = -1
	col = -1
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				row = i
				col = j
		if row != -1:
			break
	print(abs(row - 2) + abs(col - 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')
main()


for i in range(5):
	m = list(map(int, input().split()))
	for j in range(5):
		if m[j] == 1:
			output = abs(j - 2) + abs(i - 2)
			break
print(output)


cont = 0
for i in range(5):
	matrix = list(map(int, input().split()))
	if i == 0 or i == 4:
		if matrix[0] == 1 or matrix[4] == 1:
			cont = 4
			break
		elif matrix[1] == 1 or matrix[3] == 1:
			cont = 3
			break
		elif matrix[2] == 1:
			cont = 2
			break
	elif i == 1 or i == 3:
		if matrix[0] == 1 or matrix[4] == 1:
			cont = 3
			break
		elif matrix[1] == 1 or matrix[3] == 1:
			cont = 2
			break
		elif matrix[2] == 1:
			cont = 1
			break
	elif i == 2:
		if matrix[0] == 1 or matrix[4] == 1:
			cont = 2
			break
		elif matrix[1] == 1 or matrix[3] == 1:
			cont = 1
			break
		elif matrix[2] == 1:
			cont = 0
			break
print(cont)


a = list(input())
b = list(input())
c = list(input())
d = list(input())
e = list(input())
S = [a, b, c, d, e]
p = len(S)
t = len(a)
Q = []
for i in range(p):
	if '1' in S[i]:
		T = S[i]
		n = i + 1
if n > 3:
	m = n - 3
else:
	m = 3 - n
for i in range(t):
	if T[i] == ' ':
		Q += T[i]
for i in Q:
	T.remove(i)
s = T.index('1')
s += 1
if s > 3:
	y = s - 3
else:
	y = 3 - s
r = m + y
print(r)


a = [[0] * 5 for _ in range(5)]
p = 0
for i in range(5):
	a[i] = [int(j) for j in input().strip().split(' ')]
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			p = i
			q = j
			break
	if p:
		break
print(abs(p - 2) + abs(q - 2))


lis = []
for n in range(5):
	lis.append(input())
length = len(lis[0])
row = 0
result = 0
for i in range(5):
	for j in range(length):
		if lis[i][j] == '1':
			row = i + 1
if row == 1 or row == 5:
	result = 2
elif row == 2 or row == 4:
	result = 1
elif row == 3:
	result = 0
column = 0
for j in range(length):
	if lis[row - 1][j] == '1':
		column = j + 1
		break
if column == 1 or column == 9:
	result = result + 2
elif column == 3 or column == 7:
	result = result + 1
elif column == 5:
	result = result + 0
print(result)


def main():
	(indI, indJ) = (0, 0)
	for i in range(1, 6):
		a = list(map(int, input().split()))
		for j in range(5):
			if a[j] == 1:
				print(abs(3 - (j + 1)) + abs(3 - i))
				return 0
main()


m = []
for i in range(5):
	m.append(input().replace(' ', ''))
for (idy, i) in enumerate(m):
	if i.find('1') != -1:
		d = abs(2 - m[idy].find('1')) + abs(2 - idy)
		break
print(d)


matrix = []
for _ in range(0, 5):
	matrix.append(input().split())
x = 0
y = 0
for i in range(0, len(matrix)):
	if '1' in matrix[i]:
		y = i
		x = matrix[i].index('1')
print(abs(2 - x) + abs(2 - y))


mat = []
for i in range(5):
	row = list(map(int, input().split()))
	mat.append(row)
(x, y) = (-1, -1)
for r in range(5):
	for c in range(5):
		if mat[r][c] == 1:
			x = r + 1
			y = c + 1
			break
x = x - 3
y = y - 3
if x < 0:
	x *= -1
if y < 0:
	y *= -1
print(x + y)


def solve():
	mt = []
	pos = None
	for i in range(5):
		x = list(map(int, input().split()))
		if not pos:
			for j in range(5):
				if x[j] == 1:
					pos = (i, j)
		mt.append(x)
	print(abs(pos[0] - 2) + abs(pos[1] - 2))

def main():
	solve()
main()


n = 1
col = 0
while n <= 5:
	row = list(map(int, input().split()))
	if 1 in row:
		col = row.index(1)
		col += 1
		break
	n += 1
step = abs(n - 3) + abs(col - 3)
print(step)


mat = [[0 for x in range(5)] for y in range(5)]
for i in range(0, 5):
	a = input().split()
	for j in range(0, 5):
		mat[i][j] = int(a[j])
(locx, locy) = (0, 0)
for i in range(0, 5):
	for j in range(0, 5):
		if mat[i][j] == 1:
			locx = i
			locy = j
dist = abs(locx - 2) + abs(locy - 2)
print(dist)


matrix = [input().split(' '), input().split(' '), input().split(' '), input().split(' '), input().split(' ')]

def where_is_1(the_matrix):
	for i in range(5):
		for j in range(5):
			if the_matrix[i][j] == '1':
				return (i, j)
no_of_moves = 0
while matrix[2][2] != '1':
	row = where_is_1(matrix)[0]
	column = where_is_1(matrix)[1]
	if column == 2 or abs(column - 2) < abs(row - 2):
		matrix[row][column] = '0'
		if row > 2:
			matrix[row - 1][column] = '1'
		else:
			matrix[row + 1][column] = '1'
	else:
		matrix[row][column] = '0'
		if column > 2:
			matrix[row][column - 1] = '1'
		else:
			matrix[row][column + 1] = '1'
	no_of_moves += 1
print(no_of_moves)


y1 = input().split()
y2 = input().split()
y3 = input().split()
y4 = input().split()
y5 = input().split()
me = [y1, y2, y3, y4, y5]
y = 0
for i in me:
	if '1' in i:
		x = 0
		for m in i:
			if m == '1':
				xx = x
			else:
				x += 1
		yy = y
	else:
		y += 1
xx = int(xx)
yy = int(yy)
ans = abs(2 - xx) + abs(2 - yy)
print(ans)


lines = []
(x, y) = (0, 1)
yFound = False
for _ in range(5):
	line = [int(x) for x in input().split()]
	if 1 in line:
		yFound = True
		x = line.index(1) + 1
	elif not yFound:
		y += 1
	lines.append(line)
moves = 0
if x > 3:
	moves += x - 3
elif x < 3:
	moves += 3 - x
if y > 3:
	moves += y - 3
elif y < 3:
	moves += 3 - y
print(moves)


s = []
for i in range(5):
	k = input().split()
	for j in range(5):
		l = int(k[j])
		s.append(l)
k1 = (s.index(1) + 1) / 5
if k1 <= 1:
	k2 = 1
if 1 < k1 <= 2:
	k2 = 2
if 2 < k1 <= 3:
	k2 = 3
if 3 < k1 <= 4:
	k2 = 4
if 4 < k1 <= 5:
	k2 = 5
k3 = abs(3 - k2)
if k1 * 5 > 15:
	k4 = abs(k1 * 5 - k3 * 5)
else:
	k4 = abs(k1 * 5 + k3 * 5)
k5 = abs(13 - k4)
print(int(k5 + k3))


t = []
x = 0
y = 0
for i in range(5):
	h = tuple(map(int, input().split()))
	for j in range(5):
		if h[j] == 1:
			x = i
			y = j
a1 = abs(x - 2) + abs(y - 2)
print(a1)


lll = list()
for l in range(5):
	lll.append(input())
for line in lll:
	if line != '0 0 0 0 0':
		rowindex = lll.index(line)
	else:
		continue
rowwithone = lll[rowindex].replace(' ', '')
for letter in rowwithone:
	if letter == '1':
		columnindex = rowwithone.index(letter)
ans = abs(2 - rowindex) + abs(2 - columnindex)
print(ans)


matrix = []
row_index = 0
row_value = []
for i in range(5):
	inp = input()
	if '1' in inp:
		row_index = i
		row_value = inp.split()
	matrix.append(inp)
vertical_move = abs(2 - row_index)
horizontal_move = abs(2 - row_value.index('1'))
moves = vertical_move + horizontal_move
print(moves)


T = []
for i in range(5):
	T.append(input())
	if T[i].split().count('1') > 0:
		c = T[i].split().index('1')
		d = abs(i - 2) + abs(c - 2)
print(d)


l = []
for i in range(5):
	l.append(input().split())
a = 0
b = 0
flag = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			a = i
			b = j
c = abs(2 - a)
d = abs(2 - b)
print(c + d)


import sys
n = 0
colNum = 0
rowNum = 0
for l in sys.stdin:
	n = n + 1
	p = 0
	for k in l.split():
		k = int(k)
		p = p + 1
		if k == 1:
			colNum = p
			rowNum = n
			break
	if n == 5:
		break
colMove = 0
rowMove = 0
if colNum > 3:
	while colNum > 3:
		colNum = colNum - 1
		colMove = colMove + 1
elif colNum < 3:
	while colNum < 3:
		colNum = colNum + 1
		colMove = colMove + 1
if rowNum > 3:
	while rowNum > 3:
		rowNum = rowNum - 1
		rowMove = rowMove + 1
elif rowNum < 3:
	while rowNum < 3:
		rowNum = rowNum + 1
		rowMove = rowMove + 1
print(colMove + rowMove)


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
mat = []
mat.append(l1)
mat.append(l1)
mat.append(l1)
mat.append(l1)
mat.append(l1)
p = 0
q = 0
if 1 in l1:
	p = 1
	q = l1.index(1) + 1
elif 1 in l2:
	p = 2
	q = l2.index(1) + 1
elif 1 in l3:
	p = 3
	q = l3.index(1) + 1
elif 1 in l4:
	p = 4
	q = l4.index(1) + 1
else:
	p = 5
	q = l5.index(1) + 1
i = 0
c = abs(p - 3) + abs(q - 3)
print(c)


for i in range(0, 5):
	val = [int(i) for i in input().split()[:5]]
	if 1 in val:
		b = val.index(1) + 1
		a = i + 1
print(abs(3 - a) + abs(3 - b))


a = []
import math
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] > 0:
			x = i
			y = j
z = math.fabs(2 - x)
y = math.fabs(2 - y)
print(math.ceil(z + y))


l = []
ni = 0
mj = 0
for _ in range(5):
	l.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			ni += i
			mj += j
		else:
			continue
r = abs(ni - 2) + abs(mj - 2)
print(r)


target = [3, 3]
for i in range(5):
	row = input()
	for j in range(5):
		if row.split(' ')[j] == '1':
			vector = [int(j) + 1, int(i) + 1]
			break
x = abs(target[0] - vector[0])
y = abs(target[1] - vector[1])
print(x + y)


import math
a = []
for i in range(5):
	a.append([int(j) for j in input().split()])
cen = 2
sto = 0
stro = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			sto = i
			stro = j
print(abs(cen - sto) + abs(cen - stro))


m = []
for j in range(5):
	i = list(map(int, input().strip().split()))
	if 1 in i:
		y = j
	m.append(i)
x = m[y].index(1)
print(abs(y - 2) + abs(x - 2))


l = [[] for i in range(5)]
for i in range(5):
	l[i].extend(map(int, input().split()))
for row in range(5):
	for col in range(5):
		if l[row][col] == 1:
			print(abs(row - 2) + abs(col - 2))
			exit()


matrix = []
ones_row = -1
ones_col = -1
for i in range(5):
	a = input('')
	row = a.split(' ')
	if '1' in row:
		ones_col = row.index('1')
		ones_row = i
	matrix.append(row)
path = abs(ones_col - 2) + abs(ones_row - 2)
print(path)


a = []
i = 0
j = 0
iu = 3
for k in range(5):
	b = []
	x = list(map(int, input().split()))
	b.append(x)
	a.append(b)
for r in a:
	i = i + 1
	for q in r:
		j = 0
		for l in q:
			j = j + 1
			if l == 1:
				bc = i
				mc = j
				break
res1 = abs(bc - iu)
res2 = abs(mc - iu)
res = res1 + res2
if bc or mc != 3:
	print(abs(res))
elif bc == 3:
	print(abs(iu - mc))
elif mc == 3:
	print(abs(iu - mc))


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

def find_one():
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == '1':
				return [i, j]

def min_moves(coords):
	minmoves1 = abs(2 - coords[0])
	minmoves2 = abs(2 - coords[1])
	return minmoves1 + minmoves2
print(min_moves(find_one()))


for i in range(5):
	(p, v, t, x, y) = map(int, input().strip().split())
	if p + v + t + x + y == 1:
		d = abs(i - 2)
	if p or y == 1:
		d = d + 2
	elif v or x == 1:
		d = d + 1
print(d)


import math
lines = []
r = 0
c = 0
for i in range(5):
	line = input().split()
	lines.append(line)
	if line.count('1') == 1:
		r = math.fabs(i - 2)
		c = math.fabs(line.index('1') - 2)
print(int(c + r))


n = 5
m = []
for i in range(n):
	l = list(map(int, input().split()))
	m.append(l)
	if l.count(1) == 1:
		x = i
		y = l.index(1)
print(abs(2 - x) + abs(2 - y))


matrix_row1 = input()
matrix_row2 = input()
matrix_row3 = input()
matrix_row4 = input()
matrix_row5 = input()
matrix = [matrix_row1.split(' '), matrix_row2.split(' '), matrix_row3.split(' '), matrix_row4.split(' '), matrix_row5.split(' ')]
index_x = 0
index_y = 0
move_x = 0
move_y = 0
for i in matrix:
	index_x = matrix.index(i)
	if '1' in i:
		index_y = i.index('1')
		break
if index_x > 2:
	while index_x != 2:
		index_x -= 1
		move_x += 1
elif index_x < 2:
	while index_x != 2:
		index_x += 1
		move_x += 1
if index_y > 2:
	while index_y != 2:
		index_y -= 1
		move_y += 1
elif index_y < 2:
	while index_y != 2:
		index_y += 1
		move_y += 1
print(move_x + move_y)


a = []
for i in range(5):
	s = input()
	a.append(s)
for i in range(len(a)):
	if '1' in a[i]:
		pos = i
dem = 0
while pos != 2:
	if pos > 2:
		mid = a[pos]
		a[pos] = a[pos - 1]
		a[pos - 1] = mid
		pos -= 1
		dem += 1
	else:
		mid = a[pos]
		a[pos] = a[pos + 1]
		a[pos + 1] = mid
		pos += 1
		dem += 1
posi = a[pos].index('1')
while posi != 4:
	dem += int(abs((posi - 4) / 2))
	a[pos] = '0 0 1 0 0'
	posi = 4
print(dem)


q = 1
w = []
while 5 >= q:
	w.append(input().split())
	q = 1 + q

def abs(x):
	if x >= 0:
		return x
	else:
		return -x
for i in range(1, 6):
	for j in range(1, 6):
		if int(w[i - 1][j - 1]) != 0:
			d = abs(i - 3) + abs(j - 3)
			print(d)
		else:
			pass


n = 5
a = []
for i in range(n):
	b = list(map(int, input().split()))
	if b.count(1) > 0:
		x1 = i
		y1 = b.index(1)
	a.append(b)
o = abs(2 - x1) + abs(2 - y1)
print(o)


matriz = []
for k in range(5):
	matriz.append(list(map(int, input().split())))
ans = 0
for i in range(5):
	for j in range(5):
		if matriz[i][j] == 1:
			ans += abs(i - 2) + abs(j - 2)
			break
print(ans)


matrix = []
for temp in range(5):
	matrix.append(list(map(int, input().split())))
row = 0
colunm = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i
			colunm = j
			break
print(abs(row - 2) + abs(colunm - 2))


I = input()
II = input()
III = input()
IV = input()
V = input()
b = 0
if '1' in I or '1' in V:
	b += 2
	if '1' in I:
		it = I
	else:
		it = V
	n = it.find('1')
	n = int(abs(n - 4) / 2)
	b += n
elif '1' in II or '1' in IV:
	b += 1
	if '1' in II:
		it = II
	else:
		it = IV
	n = it.find('1')
	n = int(abs(n - 4) / 2)
	b += n
else:
	n = III.find('1')
	n = int(abs(n - 4) / 2)
	b += n
print(b)


m = []
for i in range(5):
	t = input().split()
	m.append(t)
	if t.__contains__('1'):
		a = (t.index('1') + 1, i + 1)
print((a[0] - 3).__abs__() + (a[1] - 3).__abs__())


dim = 5
matrix = [input() for row in range(dim)]
text = ''.join(matrix).replace(' ', '')
idx = list(text).index('1')
n = idx // dim
m = idx % dim
print(abs(2 - n) + abs(2 - m))


ls = []
for i in range(5):
	s = input().split()
	if '1' in s:
		row = i
		col = s.index('1')
print(abs(2 - row) + abs(2 - col))


for i in range(5):
	s = input()
	crdn = s.find('1')
	if crdn != -1:
		print(int(abs(i - 2) + abs(crdn - 4) / 2))
		break


l = []
for _ in range(5):
	t = input().split()
	for i in range(5):
		t[i] = int(t[i])
	l.append(t)
count = 0
while l[2][2] != 1:
	for i in range(5):
		if 1 in l[i]:
			if i != 2:
				if i > 2:
					l[i - 1] = l[i]
					l[i] = [0, 0, 0, 0, 0]
				elif i < 2:
					l[i + 1] = l[i]
					l[i] = [0, 0, 0, 0, 0]
				count += 1
			else:
				for x in range(5):
					if l[i][x] == 1:
						if x > 2:
							l[i][x - 1] = l[i][x]
							l[i][x] = 0
						elif x < 2:
							l[i][x + 1] = l[i][x]
							l[i][x] = 0
						count += 1
						break
			break
print(count)


for i in range(5):
	s = [*map(int, input().split())]
	for x in range(5):
		if s[x] == 1:
			pos_ = x
			pos = i
print(abs(pos_ - 2) + abs(pos - 2))


(row, col) = (1, 0)
for _ in range(5):
	string = input().split()
	if '1' in string:
		(row, col) = (_ + 1, string.index('1') + 1)
print(abs(row - 3) + abs(col - 3))


matrix = []
a = input().split(' ')
b = input().split(' ')
c = input().split(' ')
d = input().split(' ')
e = input().split(' ')
matrix.append(a)
matrix.append(b)
matrix.append(c)
matrix.append(d)
matrix.append(e)
for j in range(5):
	if matrix[0][j] == '1' or matrix[4][j] == '1':
		if j == 1 or j == 3:
			print('3')
		if j == 0 or j == 4:
			print('4')
		if j == 2:
			print('2')
for j in range(5):
	if matrix[1][j] == '1' or matrix[3][j] == '1':
		if j == 1 or j == 3:
			print('2')
		if j == 0 or j == 4:
			print('3')
		if j == 2:
			print('1')
for j in range(5):
	if matrix[2][j] == '1':
		if j == 1 or j == 3:
			print('1')
		if j == 0 or j == 4:
			print('2')
		if j == 2:
			print('0')


array = []
for i in range(5):
	array += [[int(x) for x in input().split()]]
	if 1 in array[-1]:
		ind = [i, array[i].index(1)]
		break
print(abs(2 - ind[0]) + abs(2 - ind[1]))


no_of_rows = 0
no_of_cols = 0
no_of_steps = 0
for i in range(5):
	s = [int(i) for i in input().split()]
	no_of_rows += 1
	if sum(s) == 1:
		no_of_steps += abs(3 - no_of_rows)
		for i in range(5):
			if s[i] == 1:
				no_of_cols = i + 1
		no_of_steps += abs(3 - no_of_cols)
print(no_of_steps)


d = 0
p = []
for i in range(5):
	row = input().split()
	if '1' in row:
		print(abs(row.index('1') - 2) + abs(2 - i))


for i in range(5):
	l = input()
	a = [int(n) for n in l.split()]
	if 1 in a:
		index = int(a.index(1) + 1)
		print(abs(3 - (i + 1)) + abs(3 - index))
		break


i = 1
while i <= 5:
	x = ''.join(input().split())
	if x.find('1') >= 0:
		print(abs(x.index('1') - 2) + abs(i - 3))
		break
	i += 1


a = 1
while a <= 5:
	lst = input().split()
	if '1' not in lst:
		a += 1
	else:
		break
t = 3 - a
if t < 0:
	t = -t
f = lst.index('1') + 1
g = 3 - f
if g < 0:
	g = -g
print(g + t)


L = []
for i in range(5):
	L.append(tuple(map(int, input().split())))
indice_i = 0
indice_j = 0
for i in range(0, len(L)):
	for j in range(0, len(L[0])):
		if L[i][j] == 1:
			indice_i = i + 1
			indice_j = j + 1
result = abs(3 - indice_i) + abs(3 - indice_j)
print(result)


l1 = [int(i) for i in input().split(' ')]
l2 = [int(i) for i in input().split(' ')]
l3 = [int(i) for i in input().split(' ')]
l4 = [int(i) for i in input().split(' ')]
l5 = [int(i) for i in input().split(' ')]
tl = [l1, l2, l3, l4, l5]
count = 0
for i in range(len(tl)):
	if 1 in tl[i]:
		if i != 2:
			if i == 0 or i == 4:
				count += 2
			elif i == 1 or i == 3:
				count += 1
		n = tl[i].index(1)
		if n != 2:
			if n == 0 or n == 4:
				count += 2
			elif n == 1 or n == 3:
				count += 1
print(count)


class Matrix:

	def __init__(self):
		self.matrix = []
		for i in range(5):
			self.matrix.append(input().split())

	def answer(self):
		for i in range(5):
			if '1' in self.matrix[i]:
				for j in range(5):
					if self.matrix[i][j] == '1':
						index = [i, j]
						return abs(2 - index[0]) + abs(2 - index[1])
matrix = Matrix()
print(matrix.answer())


for r in range(5):
	row = input().split()
	for c in range(5):
		if row[c] == '1':
			print(abs(r - 3 + 1) + abs(c - 3 + 1))
			break


rows = 5
columns = 5
result = []
for i in range(rows):
	lst = list(map(int, input().split()))
	result.append(lst)
for i in range(rows):
	for j in range(columns):
		if result[i][j] == 1:
			x_pos = i
			y_pos = j
			if x_pos == 2:
				ans = abs(2 - y_pos)
				print(ans)
			else:
				ans = abs(2 - x_pos)
				ans = ans + abs(2 - y_pos)
				print(ans)


matriz = []
mov = 0
for i in range(5):
	h = [int(y) for y in input().split(' ')]
	matriz.append(h)
for i in range(len(matriz)):
	for j in range(len(matriz)):
		if matriz[i][j] == 1:
			aux1 = i + 1
			aux2 = j + 1
if aux1 < 3:
	mov += 3 - aux1
elif aux1 > 3:
	mov += aux1 % 3
if aux2 < 3:
	mov += 3 - aux2
elif aux2 > 3:
	mov += aux2 % 3
print(mov)


import math
l = []
(x, y) = (-1, -1)
for i in range(5):
	l.append(''.join(input().split(' ')))
for i in range(5):
	x = l[i].find('1')
	if x > -1:
		y = i
		break
print(int(abs(2 - x) + abs(2 - y)))


(tx, ty) = (2, 2)
(x, y) = (0, 0)

def _():
	global x, y
	for y in range(5):
		for (x, n) in enumerate(input().split()):
			if n == '1':
				return
_()
print(abs(x - tx) + abs(y - ty))


def matrix(x, y):
	return abs(2 - x) + abs(2 - y)
mat = []
for i in range(5):
	a = list(map(int, input().split()))
	if 1 in a:
		indx = i
		indy = a.index(1)
print(matrix(indx, indy))


for x in range(1, 6):
	mass = input().split()
	if '1' in mass:
		print(abs(3 - x) + abs(3 - (mass.index('1') + 1)))


a = []
l = []
for i in range(1, 6):
	l = list(map(int, input().split()))
	a.append(l)
for i in range(5):
	if 1 in a[i]:
		b = a[i].index(1)
		break
print(abs(2 - i) + abs(2 - b))


r = 0
C = 0
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()))
for i in range(5):
	if a[i] == 1:
		r = 1
		C = i + 1
		break
	elif b[i] == 1:
		r = 2
		C = i + 1
		break
	elif c[i] == 1:
		r = 3
		C = i + 1
		break
	elif d[i] == 1:
		r = 4
		C = i + 1
		break
	elif e[i] == 1:
		r = 5
		C = i + 1
		break
print(abs(3 - r) + abs(3 - C))


row = -1
col = -1
for i in range(5):
	s = input()
	s = s.split()
	for f in range(5):
		if int(s[f]) == 1:
			row = i
			col = f
			break
print(abs(row - 2) + abs(col - 2))


for i in range(5):
	num_list = input().split()
	num = map(int, num_list)
	if sum(num) == 1:
		row_index = int(i + 1)
		col_index = int(num_list.index('1') + 1)
		break
remove_num = abs(row_index - 3) + abs(col_index - 3)
print(remove_num)


n = 5
saida = ''
contador = 0
while n != 0:
	entrada = list(map(str, input().split()))
	existe = entrada.count('1')
	if existe == 1 and (contador == 0 or contador == 4):
		if entrada[0] == '1' or entrada[4] == '1':
			saida = '4'
		elif entrada[1] == '1' or entrada[3] == '1':
			saida = '3'
		else:
			saida = '2'
	elif existe == 1 and (contador == 1 or contador == 3):
		if entrada[0] == '1' or entrada[4] == '1':
			saida = '3'
		elif entrada[1] == '1' or entrada[3] == '1':
			saida = '2'
		else:
			saida = '1'
	elif existe == 1 and contador == 2:
		if entrada[0] == '1' or entrada[4] == '1':
			saida = '2'
		elif entrada[1] == '1' or entrada[3] == '1':
			saida = '1'
		else:
			saida = '0'
	contador += 1
	n -= 1
print(saida)


for i in range(5):
	for (idx, num) in enumerate(input().split(' ')):
		if num == '1':
			point = (idx, i)
			print(str(abs(i - 2) + abs(idx - 2)))


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
maxi = 0
maxj = 0
for i in range(len(arr)):
	for j in range(len(arr[0])):
		if arr[i][j] == 1:
			maxi = i
			maxj = j
			break
maxi += 1
maxj += 1
print(abs(3 - maxi) + abs(3 - maxj))


for i in range(0, 5, 1):
	string = input().split()
	if string.count('1') != 0:
		sum = abs(int(i) - 2) + abs(string.index('1') - 2)
print(sum)


m = []
for i in range(5):
	m.append(list(map(int, input().split())))
	if 1 in m[i]:
		oneCol = m[i].index(1)
		onerow = i
sol = abs(oneCol - 2) + abs(onerow - 2)
print(sol)


import math
matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
	if 1 in matrix[i]:
		(x, y) = (i, matrix[i].index(1))
print(str(int(math.fabs(x - 2) + math.fabs(y - 2))))


for i in range(1, 6):
	l = input().split()
	for j in range(5):
		if l[j] == '1':
			print(abs(3 - i) + abs(3 - j - 1))


M = list()
for i in range(1, 6, 1):
	M.append(input().split())
x = 0
y = 0
for i in range(0, 5, 1):
	for j in range(0, 5, 1):
		if M[i][j] == '1':
			x = i
			y = j
			break
minmoves = abs(x - 2) + abs(y - 2)
print(minmoves)


import sys
import io

def run(test, res):
	x = io.StringIO()
	with io.StringIO(test) as sys.stdin:
		with x as sys.stdout:
			work()
			z = x.getvalue().strip()
	sys.stdout = sys.__stdout__
	print(z == test)
	print(res)
	print(z)

def work():
	for x in range(0, 5):
		a = input().split()
		if '1' in a:
			print(abs(2 - x) + abs(2 - a.index('1')))

def test():
	run('0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0', '3')
	run('0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0', '1')
if len(sys.argv) > 1:
	test()
else:
	work()


matrix = [input().split(maxsplit=4) for i in range(5)]
R = [0, 1]
L = [3, 4]
B = [0, 1]
T = [3, 4]
CENTER = [2, 2]
turns = 0
unpacked = ' '.join([' '.join(item) for item in matrix]).split()
current_location = [unpacked.index('1') // 5, unpacked.index('1') % 5]
while current_location != CENTER:
	turns += 1
	if current_location[0] in B:
		current_location = [current_location[0] + 1, current_location[1]]
	elif current_location[0] in T:
		current_location = [current_location[0] - 1, current_location[1]]
	elif current_location[1] in L:
		current_location = [current_location[0], current_location[1] - 1]
	else:
		current_location = [current_location[0], current_location[1] + 1]
print(turns)


matrix = []
for i in range(0, 5):
	row = input().split(' ')
	matrix.append(row)
x = '1'
for (i, row) in enumerate(matrix):
	if x in row:
		position = (matrix.index(row), row.index(x))
x1 = abs(position[0] - 2)
x2 = abs(position[1] - 2)
print(x1 + x2)


for i in range(5):
	x = input().split()
	if '1' in x:
		num = i
		for n in range(5):
			if x[n] == '1':
				z = n
				break
g = 2 - z
if g < 0:
	g = -g
s = 2 - num
if s < 0:
	s = -s
print(g + s)


found = False
index = 0
for i in range(5):
	if found:
		break
	input_row = list(map(int, input().split()))
	for num in input_row:
		index += 1
		if num == 1:
			found = True
			break

def get_row(index):
	row = 0
	if index <= 5:
		row = 1
	elif index <= 10:
		row = 2
	elif index <= 15:
		row = 3
	elif index <= 20:
		row = 4
	else:
		row = 5
	return row

def get_col(index):
	col = 0
	if index <= 5:
		col = index
	elif index <= 10:
		col = index - 5
	elif index <= 15:
		col = index - 10
	elif index <= 20:
		col = index - 15
	else:
		col = index - 20
	return col

def get_moves_count(row, col):
	moves_count = 0
	while row != 3:
		if row < 3:
			row += 1
			moves_count += 1
		else:
			row -= 1
			moves_count += 1
	while col != 3:
		if col < 3:
			col += 1
			moves_count += 1
		else:
			col -= 1
			moves_count += 1
	return moves_count
row = get_row(index)
col = get_col(index)
moves_count = get_moves_count(row, col)
print(moves_count)


one = input().split()
two = input().split()
three = input().split()
four = input().split()
five = input().split()
board = [one, two, three, four, five]
centre = [3, 3]
for i in range(5):
	try:
		x = board[i].index('1')
		pos = [i + 1, x + 1]
	except ValueError:
		pass
dis = [abs(centre[0] - pos[0]), abs(centre[1] - pos[1])]
print(sum(dis))


matrix = []
for i in range(5):
	row = input().split()
	matrix.append(row)
for x in range(len(matrix)):
	for y in range(len(matrix[x])):
		if matrix[x][y] == '1':
			print(str(abs(2 - x) + abs(2 - y)))


s = []
s = [input().split() for i in range(5)]
for i in range(len(s)):
	for j in range(len(s[i])):
		if int(s[i][j]) != 0:
			print(abs(i - 2) + abs(j - 2))


a = []
row = 0
col = 0
for i in range(5):
	string = input().split()
	a.append(string)
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			row = i
			col = j
cal = abs(2 - row) + abs(2 - col)
print(cal)


l = []
for i in range(5):
	l1 = list(input().split())
	if '1' in l1:
		(x, y) = (i + 1, l1.index('1') + 1)
print(abs(x - 3) + abs(y - 3))


def beautifulMatrix(arr):
	col = int()
	row = int()
	ans = 0
	for i in range(len(arr)):
		for j in range(len(arr[i])):
			if arr[i][j] == '1':
				row = i
				col = j
	ans += abs(2 - row) + abs(2 - col)
	return ans
arr = list()
for i in range(5):
	a = input().strip().split()
	arr.append(a)
print(beautifulMatrix(arr))


ln1 = list(map(int, input().rstrip().split()))
ln2 = list(map(int, input().rstrip().split()))
ln3 = list(map(int, input().rstrip().split()))
ln4 = list(map(int, input().rstrip().split()))
ln5 = list(map(int, input().rstrip().split()))
c = 0
if 1 in ln1:
	c += 2
	indx = ln1.index(1)
elif 1 in ln2:
	c += 1
	indx = ln2.index(1)
elif 1 in ln3:
	indx = ln3.index(1)
elif 1 in ln4:
	c += 1
	indx = ln4.index(1)
elif 1 in ln5:
	c += 2
	indx = ln5.index(1)
if indx == 4:
	print(c + 2)
elif indx == 3:
	print(c + 1)
elif indx == 2:
	print(c)
elif indx == 1:
	print(c + 1)
elif indx == 0:
	print(c + 2)


r1 = input().split(' ')
r2 = input().split(' ')
r3 = input().split(' ')
r4 = input().split(' ')
r5 = input().split(' ')
moves = 0
m = [r1, r2, r3, r4, r5]
for i in range(len(m)):
	for j in range(len(m[i])):
		if m[i][j] == '1':
			oney = int(i)
			onex = int(j)
if oney < 2:
	moves += 2 - oney
elif oney > 2:
	moves += oney - 2
if onex < 2:
	moves += 2 - onex
elif onex > 2:
	moves += onex - 2
print(str(moves))


def index_2d(myList, v):
	for (i, x) in enumerate(myList):
		if v in x:
			return (i, x.index(v))
a = []
for i in range(5):
	a.append([int(j) for j in input().split()])
(m, n) = index_2d(a, 1)
dis = abs(m - 2) + abs(n - 2)
print(dis)


numArray = []
for i in range(5):
	numbers = list(map(int, input().split()))
	numArray.append(numbers)
for i in range(len(numArray)):
	for j in range(5):
		if numArray[i][j] == 1:
			rowNum = i
			columnNum = j
		else:
			pass
moves = abs(2 - rowNum) + abs(2 - columnNum)
print(moves)


import math
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
e = [int(i) for i in input().split()]
if 1 in a:
	g = 1
	f = a.index(1) + 1
elif 1 in b:
	g = 2
	f = b.index(1) + 1
elif 1 in c:
	g = 3
	f = c.index(1) + 1
elif 1 in d:
	g = 4
	f = d.index(1) + 1
elif 1 in e:
	g = 5
	f = e.index(1) + 1
print(abs(f - 3) + abs(g - 3))


m = []
(ox, oy) = (0, 0)
for i in range(5):
	row = [int(i) for i in input().split(' ')]
	m.append(row)
	if 1 in row:
		oy = i
		ox = row.index(1)
print(abs(ox - 2) + abs(oy - 2))


tmp = []
for i in range(5):
	tmp = str(input())
	tmp = tmp.split(' ')
	for j in range(5):
		if tmp[j] == '1':
			r = i
			c = j
print(abs(r - 2) + abs(c - 2))


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
matrix = []
count = -1
iRow = 0
iCol = 0
for x in range(5):
	count += 1
	inputList = list(invr())
	if 1 in inputList:
		iRow = count
		iCol = inputList.index(1)
total = abs(2 - iRow) + abs(2 - iCol)
print(total)


m = []
count = 0
for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	m = m + [[a, b, c, d, e]]
for i in range(0, 5):
	for j in range(0, 5):
		if m[i][j] == 1:
			if j >= 2 and i >= 2:
				count = j - 2 + (i - 2)
			elif j >= 2 and i <= 2:
				count = j - 2 + (2 - i)
			elif j <= 2 and i >= 2:
				count = 2 - j + (i - 2)
			elif j <= 2 and i <= 2:
				count = 2 - j + (2 - i)
print(count)


matrix = list()
for _ in range(5):
	s = list(map(int, input().split()))
	matrix.append(s)
x: int = 0
y: int = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			x = i + 1
			y = j + 1
			break
print(abs(3 - x) + abs(3 - y))


pos = [0, 0]
i = 0
while i < 5:
	s = [int(x) for x in input().split()]
	j = 0
	while j < len(s):
		if s[j] == 1:
			pos[0] = i
			pos[1] = j
		j = j + 1
	i = i + 1
ans = abs(pos[0] - 2) + abs(pos[1] - 2)
print(ans)


arr = []
for i in range(5):
	arr.append([int(x) for x in input().split()])
val = 1
a = [abs(index + 1 - 3) + abs(row.index(val) + 1 - 3) for (index, row) in enumerate(arr) if val in row]
b = str(a)
print(b[1])


s = '4 3 2 3 4\n3 2 1 2 3\n2 1 0 1 2\n3 2 1 2 3\n4 3 2 3 4'
m = [j.split() for i in range(5) for j in input().split('\n')]
ar = [i.split() for i in s.split('\n')]
x = [x for x in m if '1' in x][0]
print(ar[m.index(x)][x.index('1')])


for i in range(0, 5):
	w = list(map(int, input().split()))
	if 1 in w:
		j = w.index(1)
		print(abs(i - 2) + abs(j - 2))
		break


import math
L = 2
for i in range(2 * L + 1):
	t = input().split(' ')
	for j in range(len(t)):
		if t[j] == '1':
			print(int(math.fabs(i - L) + math.fabs(j - L)))
			exit()


import math
x = []
for i in range(5):
	z = input().split()
	x.append(z)
l = 0
for i in range(5):
	for j in range(5):
		if x[i][j] == '1':
			l = abs(2 - j) + abs(2 - i)
print(l)


BM = [2, 2]

def create_matrix():
	m = []
	for i in range(5):
		col = list(map(int, input().split()))
		m.append(col)
	return m

def beautiful_matrix(m):
	moves = 0
	for col in m:
		if 1 in col:
			moves += abs(m.index(col) - BM[1]) + abs(col.index(1) - BM[0])
			break
	return moves
matrix = create_matrix()
print(beautiful_matrix(matrix))


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split(' '))))
for i in range(5):
	if 1 in matrix[i]:
		b = i
c = matrix[b].index(1)
sub = abs(b - 2)
sub2 = abs(c - 2)
print(sub2 + sub)


a = []
for x in range(5):
	z = list(map(int, input().split()))
	a.append(z)
if a[2][2] == 1:
	print(0)
elif a[1][2] == 1 or a[2][1] == 1 or a[2][3] == 1 or (a[3][2] == 1):
	print(1)
elif a[0][2] == 1 or a[1][1] == 1 or a[1][3] == 1 or (a[2][0] == 1) or (a[2][4] == 1) or (a[3][1] == 1) or (a[3][3] == 1) or (a[4][2] == 1):
	print(2)
elif a[0][0] == 1 or a[0][4] == 1 or a[4][0] == 1 or (a[4][4] == 1):
	print(4)
else:
	print(3)


mat = []
for t in range(5):
	mat.append(input().strip().split())
ind = 0
for row in range(5):
	for col in range(5):
		if mat[row][col] == '1':
			ind = 1
			break
	if ind == 1:
		break
ans = abs(2 - row) + abs(2 - col)
print(ans)


coord = []
for x in range(5):
	i = str(input())
	i = i.split()
	if '1' in i:
		coord = [i.index('1'), x]
print(abs(coord[0] - 2) + abs(coord[1] - 2))


count = 0
k = {}
while count < 5:
	n = input()
	k[str(count + 1)] = n.split(' ')
	count += 1
for (x, y) in k.items():
	if '1' in y:
		locx = x
	else:
		pass
for i in range(0, 5):
	if k[locx][i] == '1':
		locy = i + 1
	else:
		pass
move = 0
if int(locx) != 3:
	move += abs(int(locx) - 3)
	if locy != 3:
		move += abs(locy - 3)
	else:
		pass
elif locy != 3:
	move += abs(locy - 3)
else:
	pass
print(move)


t = [0] * 5
index = 0
for i in range(5):
	t[i] = list(map(int, input().split()))
	for j in range(5):
		if t[i][j] == 1:
			index = [i, j]
cpt = 0
while index[0] != 2 or index[1] != 2:
	if index[0] < 2:
		index[0] += 1
	elif index[0] > 2:
		index[0] -= 1
	elif index[1] < 2:
		index[1] += 1
	elif index[1] > 2:
		index[1] -= 1
	cpt += 1
print(cpt)


m = [[0] * 5 for i in range(5)]
for i in range(5):
	m[i] = [int(j) for j in input().split()]
(k, l) = (0, 0)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			k = i
			l = j
ans = abs(2 - k) + abs(2 - l)
print(ans)


from math import *
y = []
for i in range(0, 5):
	x = input().split()
	y.append(x)
for k in range(0, 5):
	for l in range(0, 5):
		if y[k][l] == '1':
			n = k + 1
			m = l + 1
p = abs(3 - n) + abs(3 - m)
print(p)


v1 = input().split(' ')
v2 = input().split(' ')
v3 = input().split(' ')
v4 = input().split(' ')
v5 = input().split(' ')
l = [v1, v2, v3, v4, v5]
row = 0
c = 0
x = 0
for i in l:
	row += 1
	col = 0
	for j in i:
		col += 1
		if j == '1':
			c = col
			x = 1
			break
	if x == 1:
		break
print(abs(3 - row) + abs(3 - c))


matrix = []
for i in range(5):
	entries = list(map(int, input().split()))
	matrix.append(entries)
row = 0
col = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i
			col = j
			break
result = abs(row - 2) + abs(col - 2)
print(result)


num = 0
for i in range(5):
	n = [int(x) for x in input().split()]
	if max(n) == 1:
		num += abs(3 - (i + 1))
		num += abs(3 - (n.index(1) + 1))
print(num)


def index2d(list2d, value):
	return next(((i, j) for (i, lst) in enumerate(list2d) for (j, x) in enumerate(lst) if x == value))
a = []
for x in range(5):
	a.append(input().split())
b = index2d(a, '1')
ans = abs(b[0] - 2) + abs(b[1] - 2)
print(ans)


posI = 0
posJ = 0
for i in range(0, 5):
	rajIn = input()
	if '1' in rajIn:
		posI = i
		posJ = rajIn.split(' ').index('1')
result = abs(2 - posI) + abs(2 - posJ)
print(result)


b = []
for i in range(5):
	a = list(map(int, input().strip().split()))
	for j in range(5):
		if a[j] == 1:
			c = j
			d = i
			break
print(abs(2 - c) + abs(2 - d))


s = []
for i in range(5):
	v = []
	(a, b, c, d, e) = [int(x) for x in input().split()]
	v.append(a)
	v.append(b)
	v.append(c)
	v.append(d)
	v.append(e)
	s.append(v)
k = 0
l = 0
for i in range(5):
	for j in range(5):
		if s[i][j] != 0:
			k = i + 1
			l = j + 1
			break
t = abs(k - 3) + abs(l - 3)
print(t)


matrix = []
row = 0
colum = 0
for i in range(5):
	l = list(map(str, input().split()))
	if '1' in l:
		row = i
		colum = l.index('1')
	matrix.append(l)
r_row = 2
r_colum = 2
move_row = abs(r_row - row)
move_colum = abs(r_colum - colum)
print(move_colum + move_row)


i = 0
for i in range(5):
	get = list(map(int, input().split()))
	found = 1 in get
	if found != False:
		break
print(abs(2 - get.index(1)) + abs(2 - i))


a = [[j for j in input().strip().split(' ')] for i in range(5)]
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
			break


M = []
for i in range(5):
	M.append([int(n) for n in input().split()])
for j in range(5):
	for k in range(5):
		if M[j][k] == 1:
			print(abs(j - 2) + abs(k - 2))


m = [list(map(int, input().split())) for i in range(5)]
x = (i for i in range(5) if max(m[i]) == 1).__next__()
y = (i for i in range(5) if m[x][i] == 1).__next__()
print(abs(x - 2) + abs(y - 2))


def main():
	d = 5
	m = [[] for i in range(d)]
	for i in range(d):
		m[i].extend(map(int, input().split()))
	x = 0
	y = 0
	for i in range(d):
		for j in range(d):
			if m[i][j] == 1:
				x = abs(j - 2)
				y = abs(-i + 2)
	print(x + y)
main()


i1 = input()
i2 = input()
i3 = input()
i4 = input()
i5 = input()
(i, j) = (0, 0)
if '1' in i1:
	i = 1
	j = i1.index('1')
elif '1' in i2:
	i = 2
	j = i2.index('1')
elif '1' in i3:
	i = 3
	j = i3.index('1')
elif '1' in i4:
	i = 4
	j = i4.index('1')
elif '1' in i5:
	i = 5
	j = i5.index('1')
j = j / 2
res = abs(i - 3) + abs(j - 2)
print(int(res))


matrix = []
row = 0
column = 0
for i in range(0, 5):
	matrix.append(list(input().strip().split()))
for i in range(0, 5):
	if '1' in matrix[i]:
		row = i
		for j in range(0, 5):
			if '1' == matrix[i][j]:
				column = j
sol = abs(row - 2) + abs(column - 2)
print(sol)


mat = []
for x in range(5):
	mat.append(list(map(int, input().split())))
for x in range(5):
	for y in range(5):
		if mat[x][y] == 1:
			location = (x, y)
			break
total = abs(location[0] - 2)
total += abs(location[1] - 2)
print(total)


(x, y) = (0, 0)
for i in range(5):
	row = list(map(int, input().strip().split()))
	if 1 in row:
		x = i + 1
		y = row.index(1) + 1
result = abs(3 - x) + abs(3 - y)
print(result)


for m in range(1, 6):
	a = list(map(str, input().split()))
	a = ''.join(a)
	f = a.find('1')
	if f != -1:
		f += 1
		print(abs(3 - f) + abs(3 - m))


li = []
x = 0
y = 0
for i in range(5):
	z = list(map(int, input().split()))
	if 1 in set(z):
		x = i
		y = z.index(1)
	li.append(z)
print(abs(x - 2) + abs(y - 2))


arr = []
for _ in range(5):
	row = [int(x) for x in input().split()]
	arr.append(row)
i = 0
j = 0
flag = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			flag = 1
			break
	if flag == 1:
		break
print(abs(2 - i) + abs(2 - j))


for i in range(5):
	inp = input()
	list1 = inp.split(' ')
	if '1' in list1:
		m = inp.find('1') // 2
		n = i
nom = abs(2 - m) + abs(2 - n)
print(nom)


rsum = 0
for i in range(5):
	rowarr = list(map(int, input().split()))
	for j in rowarr:
		rsum = rsum + j
	if rsum == 1:
		x = i + 1
		row = rowarr
	rsum = 0
for i in range(5):
	if row[i] == 1:
		y = i + 1
a = abs(3 - x)
b = abs(3 - y)
print(a + b)


t = [[0 for i in range(5)] for j in range(5)]
for i in range(5):
	t[i] = [int(e) for e in input().split()]
a = ()
for i in range(5):
	for j in range(5):
		if t[i][j] == 1:
			a = (i + 1, j + 1)
			i = 5
			break
if a == (3, 3):
	print(0)
elif a == (1, 1) or a == (1, 5) or a == (5, 1) or (a == (5, 5)):
	print(4)
elif a == (1, 2) or a == (2, 1) or a == (1, 4) or (a == (4, 1)) or (a == (2, 5)) or (a == (5, 2)) or (a == (4, 5)) or (a == (5, 4)):
	print(3)
elif a == (1, 3) or a == (3, 1) or a == (3, 5) or (a == (5, 3)) or (a == (2, 2)) or (a == (2, 4)) or (a == (4, 2)) or (a == (4, 4)):
	print(2)
else:
	print(1)


from math import fabs
r = []
x = 0
y = 0
for i in range(5):
	g = list(map(int, input().split()))
	if 1 in g:
		x = g.index(1) + 1
		y = i + 1
	r.append(g)
print(int(fabs(x - 3) + fabs(y - 3)))


x = 0
y = 0
for i in range(5):
	row = list(map(int, input().split(' ')))
	j = 0
	while j < 5 and row[j] != 1:
		j += 1
	if j < 5 and row[j] == 1:
		x = i
		y = j
print(abs(x - 2) + abs(y - 2))


mm = []
m = 1
for i in range(5):
	n = 1
	a = list(map(int, input().split()))
	for j in a:
		mm.append((m, n, j))
		n += 1
	m += 1
for k in mm:
	if k[2] == 1:
		print(abs(3 - k[0]) + abs(3 - k[1]))


from sys import stdin
arr = []
i = 0
while i < 5:
	arrr = str(stdin.readline()).replace('\n', '').split(' ')
	arr.append(arrr)
	i += 1
i = 0
j = 0
found = False
while i < 5:
	ar = arr[i]
	j = 0
	while j < 5:
		if int(ar[j]) == 1:
			found = True
			break
		j += 1
	if found:
		break
	i += 1
i += 1
j += 1
print(abs(i - 3) + abs(j - 3))


from sys import stdin
_input = stdin.readline
(_range, _int, _abs) = (range, int, abs)

def solution():
	for i in _range(5):
		line = [_int(i) for i in _input().split()]
		if line.count(1) > 0:
			j = line.index(1)
			ans = _abs(i - 2) + _abs(j - 2)
			print(ans)
			break
solution()


l = []
for i in range(5):
	lt = list(map(int, input().split()))
	l.append(lt)
x = 0
y = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			x = i
			y = j
print(abs(2 - x) + abs(2 - y))


M = [[0] * 5] * 5
for j in range(5):
	M[j] = [int(i) for i in input().split()]
for i in range(5):
	if int(sum(M[i])) == 1:
		break
	else:
		pass
for j in range(5):
	if M[i][j] == 1:
		break
	else:
		pass
if i != 2 and j != 2:
	print(abs(i - 2) + abs(j - 2))
elif i == 2:
	print(abs(j - 2))
elif j == 2:
	print(abs(i - 2))


ans = 0
for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	if a == 1:
		ans += abs(2 - i) + 2
	if b == 1:
		ans += abs(2 - i) + 1
	if c == 1:
		ans += abs(2 - i)
	if d == 1:
		ans += abs(2 - i) + 1
	if e == 1:
		ans += abs(2 - i) + 2
print(ans)


array = [] * 5
for i in range(5):
	str = input()
	temp = str.split()
	array.append(temp)
check = 0
for i in range(5):
	for j in range(5):
		if array[i][j] == '1':
			count = 0
			t = 2 - i
			if t < 0:
				count += t * -1
			else:
				count += t
			t = 2 - j
			if t < 0:
				count += t * -1
			else:
				count += t
			check = 1
			print(count)
			break
	if check == 1:
		break


from sys import stdin

def transpuesta(matriz):
	trans = []
	for j in range(len(matriz)):
		columna = []
		for i in range(len(matriz)):
			columna.append(matriz[i][j])
		trans.append(columna)
	return trans

def main():
	n = [int(x) for x in stdin.readline().split()]
	matriz = []
	while n:
		matriz.append(n)
		n = [int(x) for x in stdin.readline().split()]
	trans = transpuesta(matriz)
	col = trans.index(max(trans)) + 1
	fil = matriz.index(max(matriz)) + 1
	if col < 3 and fil < 3:
		col -= 3
		fil -= 3
		print(abs(col) + abs(fil))
	elif col > 3 and fil > 3:
		col -= 3
		fil -= 3
		print(abs(col + fil))
	elif col > 3 and fil < 3:
		col -= 3
		fil -= 3
		print(abs(col + abs(fil)))
	else:
		col -= 3
		fil -= 3
		print(abs(fil + abs(col)))
main()


for i in range(1, 6):
	inp = input().split()
	if '1' in inp:
		break
j = inp.index('1') + 1
ic = 0
jc = 0
if i < 3:
	while True:
		(i, ic) = (i + 1, ic + 1)
		if i == 3:
			break
elif i > 3:
	while True:
		(i, ic) = (i - 1, ic + 1)
		if i == 3:
			break
if j > 3:
	while True:
		(j, jc) = (j - 1, jc + 1)
		if j == 3:
			break
elif j < 3:
	while True:
		(j, jc) = (j + 1, jc + 1)
		if j == 3:
			break
print(ic + jc)


for i in range(5):
	l = input().split()
	for j in range(len(l)):
		if int(l[j]) == 1:
			print(abs(i + 1 - 3) + abs(j + 1 - 3))


A = [list(map(int, input().split())) for i in range(5)]
for i in range(len(A)):
	try:
		print(abs(2 - i) + abs(2 - A[i].index(1)))
		break
	except:
		0


a = input().split(' ')
b = input().split(' ')
c = input().split(' ')
d = input().split(' ')
e = input().split(' ')
m = 0
n = 0
if '1' in a or '1' in e:
	m = 2
elif '1' in b or '1' in d:
	m = 1
else:
	m = 0
if '1' == a[0] or '1' == b[0] or '1' == c[0] or ('1' == d[0]) or ('1' == e[0]) or ('1' == a[4]) or ('1' == b[4]) or ('1' == c[4]) or ('1' == d[4]) or ('1' == e[4]):
	n = 2
elif '1' == a[1] or '1' == b[1] or '1' == c[1] or ('1' == d[1]) or ('1' == e[1]) or ('1' == a[3]) or ('1' == b[3]) or ('1' == c[3]) or ('1' == d[3]) or ('1' == e[3]):
	n = 1
print(m + n)


x = []
for i in range(0, 5):
	y = input().split(' ')
	x.append(y)
for j in x:
	for k in j:
		if k == '1':
			print(abs(2 - x.index(j)) + abs(2 - j.index(k)))
		else:
			pass


m = []
for i in range(1, 6):
	t = list(map(int, input().split()))
	if 1 in t:
		ind_i = i
		ind_j = t.index(1) + 1
	m.append(t)
print(abs(ind_i - 3) + abs(ind_j - 3))


import sys
matrix = [sys.stdin.readline().split() for loop in range(5)]
for a in range(5):
	for b in range(5):
		if matrix[a][b] == '1':
			print(abs(a - 2) + abs(b - 2))


a = []
u = 0
for i in range(5):
	row = input().split()
	for i in range(len(row)):
		row[i] = int(row[i])
		if row[i] == 1:
			y = u + 1
			s = i + 1
		a.append(row)
	u += 1
print(abs(s - 3) + abs(y - 3))


m = 0
for i in range(0, 5):
	n = input()
	if '1' in n:
		l = n.find('1')
		m += abs(l // 2 - 2) + abs(i - 2)
print(m)


summ = 0
for i in range(1, 6):
	t = str(input()).split()
	j = 0
	for j in range(5):
		if int(t[j]) == 1:
			summ = summ + abs(3 - i) + abs(2 - j)
print(summ)


s = 0
for i in range(5):
	a = input().split()
	if '1' in a:
		s += abs(2 - i)
		if a[0] == '1' or a[4] == '1':
			s += 2
		elif a[1] == '1' or a[3] == '1':
			s += 1
print(s)


for i in range(5):
	row = list(map(int, input().split()))
	for j in range(5):
		if row[j] == 1:
			r = i
			c = j
print(abs(r - 2) + abs(c - 2))


cols = 5
rows = 5

def calc(i, j):
	return abs(i - 2) + abs(j - 2)

def find_one(input_list):
	for i in range(rows):
		for j in range(cols):
			if input_list[i][j] == 1:
				return calc(i, j)
input_list = []
for i in range(cols):
	input_list.append(list(map(int, input().split())))
print(find_one(input_list))


arr = lambda : map(int, input().split())
for x in range(5):
	i = list(arr())
	if 1 in i:
		print(f'{abs(2 - x) + abs(2 - i.index(1))}')
		break


for i in range(1, 6):
	l = list(map(int, input().split()))
	if 1 in l:
		y = l.index(1)
		y += 1
		print(abs(i - 3) + abs(y - 3), end='')


a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a4 = list(map(int, input().split()))
a5 = list(map(int, input().split()))
count = 0
if 1 in a1:
	count += 2
if 1 in a2:
	count += 1
if 1 in a3:
	count += 0
if 1 in a4:
	count += 1
if 1 in a5:
	count += 2
if a1[0] == 1:
	count += 2
if a1[1] == 1:
	count += 1
if a1[2] == 1:
	count += 0
if a1[3] == 1:
	count += 1
if a1[4] == 1:
	count += 2
if a2[0] == 1:
	count += 2
if a2[1] == 1:
	count += 1
if a2[2] == 1:
	count += 0
if a2[3] == 1:
	count += 1
if a2[4] == 1:
	count += 2
if a3[0] == 1:
	count += 2
if a3[1] == 1:
	count += 1
if a3[2] == 1:
	count += 0
if a3[3] == 1:
	count += 1
if a3[4] == 1:
	count += 2
if a4[0] == 1:
	count += 2
if a4[1] == 1:
	count += 1
if a4[2] == 1:
	count += 0
if a4[3] == 1:
	count += 1
if a4[4] == 1:
	count += 2
if a5[0] == 1:
	count += 2
if a5[1] == 1:
	count += 1
if a5[2] == 1:
	count += 0
if a5[3] == 1:
	count += 1
if a5[4] == 1:
	count += 2
print(count)


for i in range(0, 5):
	num0 = str(input())
	num = [int(n) for n in num0.split()]
	for j in range(0, 5):
		if num[j] == 1:
			s = abs(i - 2) + abs(j - 2)
print(s)


pos = [0, 0]
for i in range(0, 5):
	inp = input()
	if '1' in inp:
		pos[0] = i
		pos[1] = [f for f in inp if f != ' '].index('1')
ans = 0
print(abs(2 - pos[0]) + abs(2 - pos[1]))


n = 1
flag = 0
for i in range(5):
	inp = list(map(int, input().split()))
	for j in range(len(inp)):
		if inp[j] == n:
			colpos = j + 1
			flag = 1
			break
	if flag == 1:
		rowpos = i + 1
		flag = 0
n1 = abs(3 - rowpos)
n2 = abs(3 - colpos)
print(n1 + n2)


x = y = 0
matrix = []
for i in range(5):
	sm = list(input().split())
	matrix.append(sm)
for submatrix in matrix:
	if max(submatrix) == '1':
		x = matrix.index(submatrix)
		y = submatrix.index('1')
m = abs(2 - x) + abs(2 - y)
print(m)


ans = 0
for i in range(5):
	x = input().replace(' ', '')
	if '1' in x:
		ans = abs(i - 2) + abs(x.index('1') - 2)
print(ans)


lst = []
for i in range(5):
	row = list(map(int, input().split()))
	lst.append(row)
for i in range(5):
	for j in range(5):
		if lst[i][j] == 1:
			(x, y) = (i + 1, j + 1)
print(abs(x - 3) + abs(y - 3))


matrix = []
cnt = 0
for i in range(5):
	rows = list(map(int, input().split()))
	matrix.append(rows)
	for j in range(5):
		if rows[j] == 1:
			cnt = abs(2 - i) + abs(2 - j)
print(cnt)


l1 = []
l2 = []
l3 = []
l4 = []
l5 = []
l = [l1, l2, l3, l4, l5]
for i in range(5):
	l[i] = [int(x) for x in input().split()]
	if max(l[i]) == 0:
		continue
	if max(l[i]) == 1:
		for j in range(5):
			if l[i][j] == 0:
				continue
			if l[i][j] == 1:
				n = abs(i - 2) + abs(j - 2)
				break
print(n)


r = []
i = 5
while i:
	r.append(list(map(int, input().split())))
	i -= 1
i_one = 0
j_one = 0
for i in r:
	if 1 in i:
		i_one = r.index(i)
		j_one = i.index(1)
print(abs(i_one - 2) + abs(j_one - 2))


L = []
num = (0, 0)
for i in range(1, 6):
	(x, y, z, m, d) = [int(x) for x in input().split()]
	if x == 1:
		num = (1, i)
	elif y == 1:
		num = (2, i)
	elif z == 1:
		num = (3, i)
	elif m == 1:
		num = (4, i)
	elif d == 1:
		num = (5, i)
	else:
		pass
	L.append([x, y, z, m])
print(abs(num[1] - 3) + abs(num[0] - 3))


n = [input().split(), input().split(), input().split(), input().split(), input().split()]
location = ()
for i in range(5):
	for j in range(5):
		if n[i][j] == '1':
			location = (i + 1, j + 1)
print(abs(location[0] - 3) + abs(location[1] - 3))


k = 2
for i in range(5):
	if i == 3 or i == 4:
		k += 1
	check = input().split()
	if '1' in check:
		check2 = check.index('1')
		if check2 == 0 or check2 == 4:
			k += 2
		elif check2 == 1 or check2 == 3:
			k += 1
		else:
			k += 0
		break
	if i == 0 or i == 1:
		k -= 1
print(k)


matrix = [list(map(int, input().split())) for i in range(5)]
location = None
flag = True
i = 0
while i < len(matrix) and flag:
	j = 0
	while j < len(matrix[i]) and flag:
		if matrix[i][j] == 1:
			location = [i, j]
			flag = False
		j += 1
	i += 1
res = abs(location[0] - 2) + abs(location[1] - 2)
print(res)


t = 1
while t <= 5:
	(a, b, c, d, e) = input().split()
	if a == '1':
		p = 1
		q = t
	if b == '1':
		p = 2
		q = t
	if c == '1':
		p = 3
		q = t
	if d == '1':
		p = 4
		q = t
	if e == '1':
		p = 5
		q = t
	t = t + 1
q = abs(q - 3)
p = abs(p - 3)
print(p + q)


def beautiful_matrix(li):
	r = c = 2
	for i in range(5):
		for j in range(5):
			if li[i][j] == 1:
				break
		if li[i][j] == 1:
			break
	if r < i:
		(r, i) = (i, r)
	if c < j:
		(c, j) = (j, c)
	print(r - i + (c - j))
arr = []
for _ in range(5):
	li = list(map(int, input().split()))
	arr.append(li)
beautiful_matrix(arr)


n = 5
z = 2
y = 2
for i in range(0, 5):
	x = [int(x) for x in input().split()]
	for j in range(0, 5):
		if x[j] == 1:
			if z >= i and y >= j:
				result = z - i
				result1 = y - j
			elif z >= i and y <= j:
				result = z - i
				result1 = j - y
			elif z <= i and y >= j:
				result = i - z
				result1 = y - j
			elif z <= i and y <= j:
				result = i - z
				result1 = j - y
print(result + result1)


for i in range(5):
	row = input()
	if row.find('1') == -1:
		continue
	else:
		rowno = i + 1
		goodrow = row
ele = goodrow.split()
col = ele.index('1')
col += 1
steps = abs(col - 3) + abs(rowno - 3)
print(steps)


rowOne = list(map(int, input().split()))
rowTwo = list(map(int, input().split()))
rowThree = list(map(int, input().split()))
rowFour = list(map(int, input().split()))
rowFive = list(map(int, input().split()))
i = 0
row = 0
column = 0
while i < 5:
	if rowOne[i] == 1:
		row = 1
		column = i + 1
	if rowTwo[i] == 1:
		row = 2
		column = i + 1
	if rowThree[i] == 1:
		row = 3
		column = i + 1
	if rowFour[i] == 1:
		row = 4
		column = i + 1
	if rowFive[i] == 1:
		row = 5
		column = i + 1
	i += 1
j = 1
k = 1
count = 0
if row != 3:
	while row != 3:
		if row > 3:
			row = row - j
			count = count + 1
		else:
			row = row + j
			count = count + 1
if column != 3:
	while column != 3:
		if column > 3:
			column = column - k
			count = count + 1
		else:
			column = column + k
			count = count + 1
print(count)


import sys
matrix = [[0] * 5 for _ in range(5)]
(row, col) = (0, 0)
for (i, _) in enumerate(range(5)):
	row_data = sys.stdin.readline().split()
	if '1' in row_data:
		row = i
		col = row_data.index('1')
		break
print(abs(row - 2) + abs(col - 2))


li = [list(map(int, input().split())) for x in range(5)]
for x in li:
	kk = li.index(x) + 1
	if sum(x) == 1:
		if kk == 3:
			for j in x:
				if j == 1:
					k = x.index(j) + 1
					if k == 3:
						print(0)
					elif k < 3:
						print(3 - k)
					elif k > 3:
						print(k - 3)
		elif kk < 3:
			for j in x:
				if j == 1:
					k = x.index(j) + 1
					if k == 3:
						print(0 + (3 - kk))
					elif k < 3:
						print(3 - k + (3 - kk))
					elif k > 3:
						print(k - 3 + (3 - kk))
		elif kk > 3:
			for j in x:
				if j == 1:
					k = x.index(j) + 1
					if k == 3:
						print(0 + (kk - 3))
					elif k < 3:
						print(3 - k + (kk - 3))
					elif k > 3:
						print(k - 3 + (kk - 3))


for i in range(1, 6):
	nums = list(map(int, input().split()))
	for j in range(len(nums)):
		if nums[j] == 1:
			a = i
			b = j + 1
print(abs(a - 3) + abs(b - 3))


for m in range(5):
	string = list(map(int, input().split()))
	k = 1
	for n in string:
		if n == 1:
			move = abs(k - 3) + abs(m - 2)
			break
		else:
			k = k + 1
print(move)


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()))
if sum(A) == 1:
	n = 2
	i = 0
	while i < len(A):
		if A[i] == 1:
			s = abs(i - 2)
		i += 1
elif sum(B) == 1:
	n = 1
	i = 0
	while i < len(B):
		if B[i] == 1:
			s = abs(i - 2)
		i += 1
elif sum(C) == 1:
	n = 0
	i = 0
	while i < len(C):
		if C[i] == 1:
			s = abs(i - 2)
		i += 1
elif sum(D) == 1:
	n = 1
	i = 0
	while i < len(D):
		if D[i] == 1:
			s = abs(i - 2)
		i += 1
elif sum(E) == 1:
	n = 2
	i = 0
	while i < len(E):
		if E[i] == 1:
			s = abs(i - 2)
		i += 1
print(n + s)


matrix = [input().split() for _ in range(5)]
l = None
c = None
for line in range(5):
	for column in range(5):
		if matrix[line][column] == '1':
			l = line + 1
			c = column + 1
print(abs(l - 3) + abs(c - 3))


matrix = []
for _ in range(5):
	row = list(map(int, input().split()))
	matrix.append(row)
ith = 0
jth = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			ith = i
			jth = j
			break
print(abs(2 - ith) + abs(2 - jth))


matrix = []
for i in range(0, 5):
	a = list(map(int, input().split()[:5]))
	matrix.append(a)
fvar = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			fvar = 1
			break
	if fvar == 1:
		break
if i == 2 and j == 2:
	print(0)
elif i >= 2 and j >= 2:
	print(i - 2 + (j - 2))
elif i >= 2 and j <= 2:
	print(i - 2 + (2 - j))
elif i <= 2 and j >= 2:
	print(2 - i + (j - 2))
elif i <= 2 and j <= 2:
	print(2 - i + (2 - j))


for i in range(5):
	a = input().split()
	if a.__contains__('1'):
		j = 0
		while j < 5 and a[j] != '1':
			j += 1
		print(abs(3 - i - 1) + abs(3 - j - 1))


l = []
row = 1
col = 1
present = 0
for i in range(5):
	l1 = list(map(int, input().split()))
	l.append(l1)
	if 1 in l1:
		row = i + 1
		present = 1
	if present == 1:
		count = 0
		for i in l1:
			count += 1
			if i == 1:
				col = count
rowdiff = 3 - row
coldiff = 3 - col
if rowdiff < 0:
	rowdiff *= -1
if coldiff < 0:
	coldiff *= -1
print(coldiff + rowdiff)


def beutiful(s):
	for i in range(5):
		for j in range(5):
			if s[i][j] == 1:
				res = abs(i - 2) + abs(j - 2)
				break
	return res
list1 = []
for i in range(5):
	l = [int(n) for n in input().split()]
	list1.append(l)
print(beutiful(list1))


a = 0
b = 0
for i in range(1, 6):
	list = input().split(' ')
	for j in range(1, 6):
		d = list[j - 1]
		if d == '1':
			a = i
			b = j
print(abs(3 - a) + abs(3 - b))


a = list(map(str, input().split()))
b = list(map(str, input().split()))
c = list(map(str, input().split()))
d = list(map(str, input().split()))
e = list(map(str, input().split()))
y = 0
x = 0
if '1' in a:
	for i in range(len(a)):
		if a[i] == '1':
			x += i
	y = 1
elif '1' in b:
	for i in range(len(a)):
		if b[i] == '1':
			x = i
	y = 2
elif '1' in c:
	for i in range(len(a)):
		if c[i] == '1':
			x = i
	y = 3
elif '1' in d:
	for i in range(len(a)):
		if d[i] == '1':
			x = i
	y = 4
elif '1' in e:
	for i in range(len(a)):
		if e[i] == '1':
			x = i
	y = 5
l = 0
l += abs(2 - x)
l += abs(3 - y)
print(l)


set1 = input().split(' ')
set2 = input().split(' ')
set3 = input().split(' ')
set4 = input().split(' ')
set5 = input().split(' ')
set6 = [set1, set2, set3, set4, set5]
for i in set6:
	if '1' in i:
		y = set6.index(i) + 1
		x = i.index('1') + 1
		break
deltay = 3 - y if 3 - y > 0 else y - 3
deltax = 3 - x if 3 - x > 0 else x - 3
answer = deltax + deltay
print(answer)


row = 0
col = 0
for i in range(5):
	lst = list(map(int, input().split()))
	if lst.count(1) == 1:
		row = i + 1
		col = lst.index(1) + 1
print(abs(3 - row) + abs(3 - col))


a = []
for _ in range(5):
	l = list(map(int, input().split()))
	a.append(l)
c = 1
k = 0
y = [(i, x.index(c)) for (i, x) in enumerate(a) if c in x]
for (p, q) in y:
	if p < 2:
		k += 2 - p
	elif p == 2:
		pass
	else:
		k += p - 2
	if q < 2:
		k += 2 - q
	elif q == 2:
		pass
	else:
		k += q - 2
print(k)


matrix = [[0 for i in range(0, 5)] for j in range(0, 5)]
rowsum = [0 for i in range(0, 5)]
for i in range(0, 5):
	matrix[i] = list(map(int, input().split()))
for i in range(0, 5):
	rowsum[i] = sum(matrix[i])
	if rowsum[i] == 1:
		row = i
		break
for j in range(0, 5):
	if matrix[i][j] == 1:
		column = j
		break
print(abs(row - 2) + abs(column - 2))


def beautiful_matrix(matrix):
	(ei, ej) = (3, 3)
	(pi, pj) = (0, 0)
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == '1':
				(pi, pj) = (i + 1, j + 1)
	moves = abs(ei - pi) + abs(ej - pj)
	print(moves)
mtx = []
for i in range(5):
	mtx.append(input().strip(' ').split(' '))
beautiful_matrix(mtx)


h = 0
for i in range(5):
	h += 1
	y = [int(b) for b in input().split()]
	if 1 in y:
		j = y.index(1)
		g = h
print(abs(g - 3) + abs(j - 2))


column = -1
row = -1
for i in range(5):
	curr = input().split()
	if '1' in curr:
		column = curr.index('1') + 1
		row = i + 1
		break
print(abs(3 - column) + abs(3 - row))


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
steps = 0
for row in range(5):
	for col in range(5):
		if arr[row][col] == 1:
			steps = abs(row - 2) + abs(col - 2)
print(steps)


fila1 = list(map(int, input().split()))
fila2 = list(map(int, input().split()))
fila3 = list(map(int, input().split()))
fila4 = list(map(int, input().split()))
fila5 = list(map(int, input().split()))
if 1 in fila1:
	columna = fila1.index(1)
	print(2 + abs(3 - (columna + 1)))
elif 1 in fila2:
	columna = fila2.index(1)
	print(1 + abs(3 - (columna + 1)))
elif 1 in fila3:
	columna = fila3.index(1)
	print(abs(3 - (columna + 1)))
elif 1 in fila4:
	columna = fila4.index(1)
	print(1 + abs(3 - (columna + 1)))
elif 1 in fila5:
	columna = fila5.index(1)
	print(2 + abs(3 - (columna + 1)))


h = []
for i in range(5):
	k = list(map(int, input().split()))
	h.append(k)
for i in range(5):
	for j in range(5):
		if h[i][j]:
			ans = abs(i - 2) + abs(j - 2)
print(ans)


a = []
for i in range(5):
	n = input()
	n = n.split()
	if list(set(n)) != ['0']:
		a = n
		w = i + 1
for i in range(5):
	a[i] = int(a[i])
	if a[i] == 1:
		s = i + 1
h = 0
if s == 1 or s == 5:
	h += 2
if s == 2 or s == 4:
	h += 1
if w == 1 or w == 5:
	h += 2
if w == 2 or w == 4:
	h += 1
print(h)


import math
import string
t1 = input().replace(' ', '')
t2 = input().replace(' ', '')
t3 = input().replace(' ', '')
t4 = input().replace(' ', '')
t5 = input().replace(' ', '')
count = 0
m = 0
s = 0
l = 0
ax = [t1, t2, t3, t4, t5]
for i in range(0, 5):
	r = ax[i].find('1')
	if r != -1:
		count = abs(2 - i) + abs(2 - r)
		break
print(count)


i = 0
line = []
for i in range(1, 6):
	line = input().split()
	if '1' in line:
		break
print(abs(3 - i) + abs(line.index('1') - 2))


matrix = []
boolean_break = False
for row in range(5):
	matrix.append(input().split())
	for col in range(5):
		boolean_break = matrix[row][col] == '1'
		if boolean_break:
			break
	if boolean_break:
		break
for _ in range(row + 1, 5):
	input()
print(abs(row - 2) + abs(col - 2))


a = []
for i in range(5):
	temp = input().split()
	a.append(temp)
x = -1
y = -1
for i in range(5):
	for j in range(5):
		if a[i][j] == '1':
			x = i
			y = j
ans = abs(2 - x) + abs(2 - y)
print(ans)


row = []
col = []
ck = 0
for i in range(5):
	elm = input().split()
	row.append(elm)
for i in range(len(row)):
	col.append([row[j][i] for j in range(len(row[i]))])
for i in range(len(row)):
	for j in range(len(row[i])):
		if row[i][j] != '0':
			ck = ck + abs(2 - i)
for i in range(len(col)):
	for j in range(len(col[i])):
		if col[i][j] != '0':
			ck = ck + abs(2 - i)
print(ck)


n = []
for i in range(5):
	s = list(map(int, input().strip().split(' ')))
	n.append(s)
	if s.count(1) >= 1:
		k = i + 1
		j = s.index(1) + 1
print(abs(k - 3) + abs(j - 3))


def get_pos():
	for x in range(5):
		line = [int(x) for x in input().split()]
		if 1 in line:
			return (x, line.index(1))
(x, y) = get_pos()
print(abs(2 - x) + abs(2 - y))


for i in range(5):
	ar = list(map(int, input().split()))
	for j in range(5):
		if ar[j] == 1:
			row = j
			col = i
			break
print(abs(2 - row) + abs(2 - col))


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
c = 0
d = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			c = i
			d = j
sum = 0
sum += abs(2 - c)
sum += abs(2 - d)
print(sum)


def main():
	m = []
	for i in range(5):
		m.append(list(map(int, input().split())))
	ans = 0
	for r in range(len(m)):
		if 1 in m[r]:
			ans += abs(2 - r)
			ans += abs(2 - m[r].index(1))
	print(ans)
main()


class check:

	def calc(self):
		res = 0
		line = []
		for r in range(5):
			line.append([int(x) for x in input().split()])
			if line[r].count(1):
				c = line[r].index(1)
				if c >= 2:
					res += c - 2
				else:
					res += 2 - c
				if r >= 2:
					res += r - 2
				else:
					res += 2 - r
		print(res)
o = check()
o.calc()


for i in range(5):
	n = list(map(int, input().split()))
	for j in range(5):
		if n[j] == 1:
			ans = abs(i - 2) + abs(j - 2)
			break
print(ans)


import math
c = 0
for i in range(5):
	l = input().split()
	if l.count('1') != 0:
		c += math.fabs(i - 2) + math.fabs(int(l.index('1')) - 2)
print(int(c))


matrix = []
for i in range(5):
	a = list(map(int, input().split(' ')))
	matrix.append(a)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i + 1
			col = j + 1
			break
ans = 0
if row == 1 or row == 5:
	ans += 2
elif row == 2 or row == 4:
	ans += 1
if col == 1 or col == 5:
	ans += 2
elif col == 2 or col == 4:
	ans += 1
print(ans)


mat = []
for i in range(5):
	mat.append([int(j) for j in input().split()])
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			i1 = i
			j1 = j
			break
print(abs(i1 - 2) + abs(j1 - 2))


def module(n):
	if n < 0:
		return -n
	return n
matrix = []
index = []
for i in range(1, 6):
	x = [int(i) for i in input().split()]
	if 1 in x:
		index.append(x.index(1) + 1)
		index.append(i)
ans = 0
ans = module(3 - index[0])
ans += module(3 - index[1])
print(ans)


i = n = 0
rows = []
while i <= 4:
	(a, b, c, d, e) = map(int, input().split())
	if a == 1 or e == 1:
		n = 2 + abs(i - 2)
	elif b == 1 or d == 1:
		n = 1 + abs(i - 2)
	elif c == 1:
		n = abs(i - 2)
	i += 1
print(n)


for i in range(5):
	row = input()
	for j in range(9):
		if row[j] == '1':
			print(int(abs(i - 2) + abs(j - 4) / 2))
			exit(0)


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(' ')))
T = [A, B, C, D, E]
for i in range(0, 5):
	for j in range(0, 5):
		if T[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))
		else:
			continue


s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s3 = list(map(int, input().split()))
s4 = list(map(int, input().split()))
s5 = list(map(int, input().split()))
if 1 in s1:
	print(abs(2 - s1.index(1)) + 2)
elif 1 in s2:
	print(abs(2 - s2.index(1)) + 1)
elif 1 in s3:
	print(abs(2 - s3.index(1)))
elif 1 in s4:
	print(abs(2 - s4.index(1)) + 1)
elif 1 in s5:
	print(abs(2 - s5.index(1)) + 2)


for i in range(5):
	l1 = list(map(int, input().split()))
	if sum(l1) == 1:
		r = i
		for j in range(5):
			if l1[j] == 1:
				c = j
rans = abs(r - 2)
cans = abs(c - 2)
print(rans + cans)


n = []
for i in range(5):
	n.append(list(map(int, input().split())))
for i in range(len(n)):
	if 1 in n[i]:
		x = i
		y = n[i].index(1)
print(abs(2 - x) + abs(2 - y))


matrix = []
matrix_2 = []
a = 0
b = 0
z = 0
for j in range(5):
	rows = [int(i) for i in input().split()]
	matrix.append(rows)
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			a = abs(3 - (i + 1))
			b = abs(3 - (j + 1))
			break
print(a + b)


ik = 0
jk = 0
mat = []
for i in range(1, 6, 1):
	mat.append(list(map(int, input().split(' '))))
for i in range(0, 5, 1):
	for j in range(0, 5, 1):
		if mat[i][j] == 1:
			ik = int(i)
			jk = int(j)
			break
ik += 1
jk += 1
if ik > 3:
	resulti = ik - 3
else:
	resulti = 3 - ik
if jk > 3:
	resultj = jk - 3
else:
	resultj = 3 - jk
print(int(resulti + resultj))


matrix = []
position = []
for i in range(5):
	matrix.append(list(input()))
	matrix[i] = [int(j) for j in matrix[i] if j != ' ']
	for j in range(5):
		if matrix[i][j] == 1:
			position = [i + 1, j + 1]
answer = abs(3 - position[0]) + abs(3 - position[1])
print(answer)


import math
pos = [0, 0]
for x in range(1, 6):
	row = str(input()).split(' ')
	if row.count('1') != 0:
		pos = [int(x), int(row.index('1')) + 1]
print(int(math.sqrt(pow(pos[0] - 3, 2)) + math.sqrt(pow(pos[1] - 3, 2))))


(l1, l2, l3, l4, l5) = ([], [], [], [], [])

def func(list):
	list.append(input().split())
	return list
func(l1)
func(l2)
func(l3)
func(l4)
func(l5)
mylist = []
mylist.append(l1)
mylist.append(l2)
mylist.append(l3)
mylist.append(l4)
mylist.append(l5)
hang = 0
lie = 0
move1 = 0
move2 = 0
for i in range(5):
	if '1' in mylist[i][0]:
		hang = i + 1
		if hang >= 3:
			move1 = hang - 3
		else:
			move1 = 3 - hang
		for n in range(5):
			if '1' in mylist[i][0][n]:
				lie = n + 1
				if lie >= 3:
					move2 = lie - 3
				else:
					move2 = 3 - lie
print(move1 + move2)


Matrix = []
for i in range(5):
	x = list(map(int, input().rstrip().split()))
	Matrix.append(x)
for i in range(len(Matrix)):
	for j in range(len(Matrix[0])):
		if Matrix[i][j] == 1:
			location = (i, j)
print(abs(location[0] - 2) + abs(location[1] - 2))


from __future__ import print_function
import sys
DEBUG = '-d' in sys.argv

def debug(*args, **kwargs):
	if DEBUG:
		print(*args, file=sys.stderr, **kwargs)
	return None
x = -1
y = -1
for i in range(1, 6):
	a = input().split(' ')
	try:
		y = a.index('1')
		x = i
	except:
		pass
print(abs(x - 3) + abs(y - 2))


a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
c = [int(s) for s in input().split()]
d = [int(s) for s in input().split()]
e = [int(s) for s in input().split()]
n = None
if 1 in a:
	n = [1, a.index(1) + 1]
elif 1 in b:
	n = [2, b.index(1) + 1]
elif 1 in c:
	n = [3, c.index(1) + 1]
elif 1 in d:
	n = [4, d.index(1) + 1]
else:
	n = [5, e.index(1) + 1]
print(abs(n[0] - 3) + abs(n[1] - 3))


matrix = [input().split() for i in range(5)]
for i in range(5):
	if '1' in matrix[i]:
		print(abs(2 - i) + abs(2 - matrix[i].index('1')))
	else:
		continue


row = 0
col = 0
for i in range(5):
	s = list(input().split(' '))
	if '1' in s:
		col = s.index('1') + 1
		row = i + 1
step = 0
if row != 3:
	step += abs(row - 3)
if col != 3:
	step += abs(col - 3)
print(step)


X = []
for I in range(5):
	L = list(map(int, input().split()))
	X.append(L)
	if 1 in L:
		K = I
		J = L.index(1)
SUM = 0
if K > 2:
	SUM += K - 2
elif K < 2:
	SUM += 2 - K
if J > 2:
	SUM += J - 2
elif J < 2:
	SUM += 2 - J
print(SUM)


for i in range(5):
	m = list(map(int, input().split()))
	if sum(m) > 0:
		if i == 2 and m.index(1) == 2:
			print(0)
		else:
			print(abs(2 - i) + abs(2 - m.index(1)))


te = []
for _ in range(5):
	l = list(map(int, input().split()))
	te.append(l)
for i in range(5):
	for j in range(5):
		if te[i][j] == 1:
			res = abs(2 - i) + abs(2 - j)
			print(res)
			break


i1 = list(map(int, input().split()))
i2 = list(map(int, input().split()))
i3 = list(map(int, input().split()))
i4 = list(map(int, input().split()))
i5 = list(map(int, input().split()))
t = [i1, i2, i3, i4, i5]
for i in range(5):
	if 1 in t[i]:
		indexi = i + 1
		for j in range(5):
			if t[i][j] == 1:
				indexj = j + 1
		break
sum = 0
if indexi in [1, 5]:
	sum += 2
if indexi in [2, 4]:
	sum += 1
if indexj in [1, 5]:
	sum += 2
if indexj in [2, 4]:
	sum += 1
print(sum)


l = [[], [], [], [], []]
for i in range(5):
	l[i].extend(list(map(int, input().split())))
cnt = 1
c = -1
for x in l:
	if 1 in x:
		c = x.index(1) + 1
		break
	cnt = cnt + 1
a = 3 - cnt
b = 3 - c
print(abs(a) + abs(b))


k = 0
j = 0
i = 0
con = 0
while k < 5:
	M = [int(x) for x in input().split()]
	if 1 in M:
		i = M.index(1)
		j = k
	k += 1
if i >= 2:
	while i > 2:
		con = con + 1
		i = i - 1
	if j > 2:
		while j > 2:
			con = con + 1
			j = j - 1
	if j < 2:
		while j < 2:
			con = con + 1
			j = j + 1
if i <= 2:
	while i < 2:
		con = con + 1
		i = i + 1
	if j < 2:
		while j < 2:
			con = con + 1
			j = j + 1
	if j > 2:
		while j > 2:
			con = con + 1
			j = j - 1
print(con)


matrix = []
for i in range(5):
	a = []
	a = list(map(int, input().strip().split()))[:5]
	for j in range(5):
		if a[j] == 1:
			x_coord = i
			y_coord = j
	matrix.append(a)
num = abs(2 - x_coord) + abs(2 - y_coord)
print(num)


rows = []
for i in range(5):
	row = input()
	rows.append(row)
for i in range(5):
	if '1' in rows[i]:
		j = rows[i].find('1')
		pos = (i + 1, int(j - (int(j / 2) - 1)))
steps = abs(pos[0] - 3) + abs(pos[1] - 3)
print(steps)


x = 0
y = 0
for i in range(5):
	a = input().replace(' ', '')
	if a.find('1') > -1:
		x = a.find('1')
		y = i
		break
print(str(abs(x - 3 + 1) + abs(y - 3 + 1)))


row = 0
col = 0
for i in range(5):
	arr = input().split(' ')
	for j in range(len(arr)):
		if arr[j] == '1':
			row = i + 1
			col = j + 1
			res = abs(3 - row) + abs(3 - col)
			print(res)


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()))
for i in range(5):
	if a[i] == 1:
		m = 1
		n = i + 1
	elif b[i] == 1:
		m = 2
		n = i + 1
	elif c[i] == 1:
		m = 3
		n = i + 1
	elif d[i] == 1:
		m = 4
		n = i + 1
	elif e[i] == 1:
		m = 5
		n = i + 1
print(abs(m - 3) + abs(n - 3))


matrix = []
for i in range(5):
	matrix.append(input().split(' '))
for x in range(5):
	for y in range(5):
		if matrix[x][y] == '1':
			pos = (x, y)
			break
totalSteps = abs(2 - pos[0]) + abs(2 - pos[1])
print(totalSteps)


a = list(map(int, input().strip().split()))[:5]
b = list(map(int, input().strip().split()))[:5]
c = list(map(int, input().strip().split()))[:5]
d = list(map(int, input().strip().split()))[:5]
e = list(map(int, input().strip().split()))[:5]
main = list()
main.append(a)
main.append(b)
main.append(c)
main.append(d)
main.append(e)
m = 0
for x in range(5):
	for y in range(5):
		if main[x][y] == 1:
			l = x
			m = y
result = abs(l - 2) + abs(m - 2)
print(result)


a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
a4 = list(map(int, input().split()))
a5 = list(map(int, input().split()))
m = []
m.append(a1)
m.append(a2)
m.append(a3)
m.append(a4)
m.append(a5)
row = col = -1
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			row = i
			col = j
			break
	if row != -1 and col != -1:
		break
r = abs(row - 2)
c = abs(col - 2)
print(r + c)


matrix = []
better_matrix = []
iterator = 0
i_row = 0
i_column = 0
for i in range(5):
	matrix.append(input())
for i in range(5):
	better_matrix.append(matrix[i].split())
for i in range(5):
	for o in range(5):
		if better_matrix[i][o] == '1':
			i_row = i
			i_column = o
while i_row != 2:
	if i_row < 2:
		i_row += 1
	if i_row > 2:
		i_row -= 1
	iterator += 1
while i_column != 2:
	if i_column < 2:
		i_column += 1
	if i_column > 2:
		i_column -= 1
	iterator += 1
print(iterator)


arr = []
for _ in range(5):
	arr.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			choosen1 = i + 1
			choosen2 = j + 1
print(sum([abs(choosen1 - 3), abs(choosen2 - 3)]))


matrix = [[int(i) for i in input().split()] for i in range(5)]
(a, b) = (0, 0)
m = 0
for p in range(5):
	for q in range(5):
		if matrix[p][q] == 1:
			(a, b) = (p, q)
			break
n = abs(a - 2) + abs(b - 2)
print(n)


counter_1 = 0
while counter_1 < 5:
	j = input()
	if not j == '0 0 0 0 0':
		k = j.split()
		for counter_2 in range(5):
			if k[counter_2] == '1':
				print(abs(int(counter_2) - 2) + abs(int(counter_1) - 2))
	counter_1 += 1


for i in range(5):
	line = list(map(int, input().split()))
	if 1 in line:
		idx = [i, line.index(1)]
		break
d = abs(2 - idx[0]) + abs(2 - idx[1])
print(d)


for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	x = -1
	if a == 1:
		x = 0
	elif b == 1:
		x = 1
	elif c == 1:
		x = 2
	elif d == 1:
		x = 3
	elif e == 1:
		x = 4
	if x != -1:
		y = i
		break
total = 0
if x > 2:
	while x > 2:
		x -= 1
		total += 1
elif x < 2:
	while x < 2:
		x += 1
		total += 1
if y > 2:
	while y > 2:
		y -= 1
		total += 1
elif y < 2:
	while y < 2:
		y += 1
		total += 1
print(total)


def steps():
	new = []
	for i in range(5):
		lis = list(map(int, input().split()))
		new.append(lis)
	for i in range(1, 6):
		for j in range(1, 6):
			if new[i - 1][j - 1] == 1:
				row = i
				column = j
	else:
		step_row = 3 - row
		step_col = 3 - column
	if step_row < 0:
		step_row = -step_row
	if step_col < 0:
		step_col = -step_col
	print(step_row + step_col)
steps()


x = []
for i in range(5):
	x.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if x[i][j] == 1:
			k = [i + 1, j + 1]
ans = 0
if k[0] > 3:
	ans += k[0] - 3
else:
	ans += 3 - k[0]
if k[1] > 3:
	ans += k[1] - 3
else:
	ans += 3 - k[1]
print(ans)


import sys
(a, b) = (0, 0)
flag = 0
for i in range(5):
	mat = list(map(int, input().split()))
	if flag == 0:
		for j in range(5):
			if mat[j] == 1:
				(a, b) = (i, j)
				flag = 1
ans = abs(a - 2) + abs(b - 2)
print(ans)


matrix = []
for i in range(1, 6):
	lis = list(map(int, input().split()))
	if 1 in lis:
		_ind = lis.index(1) + 1
		__ind = i
	matrix.append(lis)
print(abs(_ind - 3) + abs(__ind - 3))


a = str(input())
b = str(input())
c = str(input())
d = str(input())
e = str(input())
l1 = a.split(' ')
l2 = b.split(' ')
l3 = c.split(' ')
l4 = d.split(' ')
l5 = e.split(' ')
l11 = [1]
l22 = [2]
l33 = [3]
l44 = [4]
l55 = [5]
for i in range(5):
	if l1[i] == '1':
		l11.append(i + 1)
	else:
		continue
for i in range(5):
	if l2[i] == '1':
		l22.append(i + 1)
	else:
		continue
for i in range(5):
	if l3[i] == '1':
		l33.append(i + 1)
	else:
		continue
for i in range(5):
	if l4[i] == '1':
		l44.append(i + 1)
	else:
		continue
for i in range(5):
	if l5[i] == '1':
		l55.append(i + 1)
	else:
		continue
if len(l11) == 2:
	z = abs(3 - l11[0]) + abs(3 - l11[1])
elif len(l22) == 2:
	z = abs(3 - l22[0]) + abs(3 - l22[1])
elif len(l33) == 2:
	z = abs(3 - l33[0]) + abs(3 - l33[1])
elif len(l44) == 2:
	z = abs(3 - l44[0]) + abs(3 - l44[1])
else:
	z = abs(3 - l55[0]) + abs(3 - l55[1])
print(z)


i = 0
j = 0
for i in range(5):
	inp = input().split()
	for j in range(5):
		if inp[j] == '1':
			print(abs(3 - i - 1) + abs(3 - j - 1))


def main():
	input_list = []
	for i in range(5):
		input_list.append([int(i) for i in input().split()])
		if 1 in input_list[i]:
			value = abs(i - 2) + abs(input_list[i].index(1) - 2)
	print(value)
main()


c = 0
for i in range(5):
	l = input().split()
	for j in range(5):
		if l[j] == '1':
			if i == 2:
				pass
			elif i > 2:
				c = i - 2
			else:
				c = 2 - i
			if j == '2':
				pass
			elif j > 2:
				c = c + j - 2
			else:
				c = c + 2 - j
print(c)


F = []
for i in range(5):
	F.append(list(map(int, input().split())))
for x in range(len(F)):
	for y in range(len(F)):
		if F[x][y] == 1:
			print(abs(2 - x) + abs(2 - y))
			break


mtrx = [[int(j) for j in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if mtrx[i][j] == 1:
			a = i + 1
			b = j + 1
c = abs(a - 3) + abs(b - 3)
print(c)


a = []
for i in range(5):
	a.append(''.join(input().split()))
for i in a:
	if i.find('1') >= 0:
		posi = abs(2 - i.find('1')) + abs(2 - a.index(i))
		break
print(posi)


a = []
for el in range(5):
	a.append(list(map(int, input().split())))
for x in range(5):
	for y in range(5):
		if a[x][y] == 1:
			print(abs(2 - x) + abs(2 - y))
			exit(0)


arr = []
onepos = []
for i in range(5):
	line = input().split()
	arr.append(line)
	for j in range(5):
		if line[j] == '1':
			onepos.append(i)
			onepos.append(j)
print(abs(onepos[0] - 2) + abs(onepos[1] - 2))


mat = list()
mat.append([int(s) for s in input().split()])
mat.append([int(s) for s in input().split()])
mat.append([int(s) for s in input().split()])
mat.append([int(s) for s in input().split()])
mat.append([int(s) for s in input().split()])
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			I = i + 1
			J = j + 1
x1 = abs(I - 3)
x2 = abs(J - 3)
print(x1 + x2)


a = input()
b = input()
c = input()
d = input()
e = input()
lis = [a, b, c, d, e]
for i in lis:
	s = i.split(' ')
	try:
		ind = s.index(str(1))
		if i == a or i == e:
			if ind == 0 or ind == 4:
				print('4')
			elif ind == 1 or ind == 3:
				print('3')
			elif ind == 2:
				print('2')
		elif i == b or i == d:
			if ind == 0 or ind == 4:
				print('3')
			elif ind == 1 or ind == 3:
				print('2')
			elif ind == 2:
				print('1')
		elif i == c:
			if ind == 0 or ind == 4:
				print('2')
			elif ind == 1 or ind == 3:
				print('1')
			elif ind == 2:
				print('0')
	except ValueError:
		pass


m = []
line = 0
element = 0
for i in range(5):
	s = input().split()
	m += s
	try:
		noice = s.index('1')
		line = i
		element = noice
	except ValueError:
		pass
print(abs(line - 2) + abs(element - 2))


l = []
for i in range(5):
	a = input().split(' ')
	l.append(a)
for j in range(5):
	for k in range(5):
		if l[j][k] == '1':
			x = j
			y = k
			break
count = 0
while x != 2 or y != 2:
	if x > 2:
		count = count + 1
		x = x - 1
	elif y > 2:
		count = count + 1
		y = y - 1
	elif x < 2:
		count = count + 1
		x = x + 1
	elif y < 2:
		count = count + 1
		y = y + 1
print(count)


x = []
z = 0
for i in range(5):
	x.append(list(map(int, input().split(' '))))
	for j in range(len(x[i])):
		if x[i][j] == 1:
			if i != 2:
				if i % 2 == 0:
					z += 2
				else:
					z += 1
			if j != 2:
				if j % 2 == 0:
					z += 2
				else:
					z += 1
print(z)


matrix = []
rows = []
for i in range(1, 6):
	rows = list(input().split())
	matrix.append(rows)
x = y = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			x = i
			y = j
n = abs(2 - x) + abs(2 - y)
print(n)


for i in range(5):
	w = input().split()
	if w.count('1'):
		print(abs(2 - i) + abs(2 - w.index('1')))


def index_2d(myList, v):
	for (i, x) in enumerate(myList):
		if v in x:
			return (i, x.index(v))
matrix = [[int(i) for i in input().split()] for j in range(5)]
(i, j) = index_2d(matrix, 1)
print(abs(2 - i) + abs(2 - j))


import sys

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

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

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

def rln(n):
	l = [None] * n
	for i in range(n):
		l[i] = int(rl())
	return l
pos = [0, 0]
for i in range(5):
	p = rn()
	if 1 in p:
		pos[0] = i
		for j in range(5):
			if p[j] == 1:
				pos[1] = j
				break
print(abs(2 - pos[0]) + abs(2 - pos[1]))


lst = []
for i in range(5):
	lst.append(list(map(int, input().split())))
for i in range(5):
	if 1 in lst[i]:
		row = i
		break
for j in range(5):
	if 1 == lst[row][j]:
		column = j
		break
row1 = 2
column1 = 2
ans = abs(row - row1) + abs(column - column1)
print(ans)


i = input
f = lambda : list(map(int, i().split()))
A = [f() for i in range(5)]
f = lambda A: [sum(A[i]) for i in range(5)].index(1)
print(abs(f(A) - 2) + abs(A[f(A)].index(1) - 2))


n1 = list(map(int, input().split(' ')))
n2 = list(map(int, input().split(' ')))
n3 = list(map(int, input().split(' ')))
n4 = list(map(int, input().split(' ')))
n5 = list(map(int, input().split(' ')))
n = [n1, n2, n3, n4, n5]
for i in range(len(n)):
	for j in range(len(n)):
		if n[i][j] == 1:
			x = i + 1
			y = j + 1
print(abs(3 - x) + abs(3 - y))


x = 0
y = 0
for i in range(5):
	list_l = input().split(' ')
	for j in range(5):
		if list_l[j] == '1':
			x = i
			y = j
mount = abs(x - 2) + abs(y - 2)
print(mount)


from sys import stdin, stdout
center = [3, 3]
matrix = []

def input():
	for i in range(0, 5):
		matrix.append(stdin.readline().split())
	return matrix

def search(matrix):
	counter = 0
	countera = 0
	x = 0
	for i in range(0, 5):
		for a in range(0, 5):
			if matrix[i][a] == '1':
				x = [i, a]
	return x

def main(x):
	a = x[0] + 1 - 3
	b = x[1] + 1 - 3
	return abs(int(a)) + abs(int(b))
print(main(search(input())))


import sys
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

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

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	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
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	arr = []
	for i in range(1, 6):
		a = ain()
		if sum(a) == 1:
			arr.append([i, a.index(1) + 1])
	print(abs(int(arr[0][0]) - 3) + abs(int(arr[0][1]) - 3))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
main()


for k in range(5):
	x = input().find('1')
	if x != -1:
		print(abs(2 - x // 2) + abs(2 - k))


for i in range(5):
	line = eval(input().replace(' ', ','))
	for j in range(5):
		num = line[j]
		if num == 1:
			one_i = i
			one_j = j
print(abs(one_i - 2) + abs(one_j - 2))


v_moves = -2
h_moves = -2
found = False
for i in range(5):
	data = input().split(' ')
	if '1' in data:
		v_moves += data.index('1')
		found = True
	if not found:
		h_moves += 1
moves = abs(v_moves) + abs(h_moves)
print(moves)


row = 0
column = 0
new = ''
for item in range(5):
	string = input()
	new = string.replace(' ', '')
	boolean = '1' in new
	if boolean == True:
		row = item + 1
		column = new.index('1') + 1
		break
print(abs(3 - row) + abs(3 - column))


l = []
for i in range(5):
	l.append(''.join(input().split(' ')))
for i in range(5):
	if '1' in l[i]:
		print(abs(2 - i) + abs(len(str(int(l[i]))) - 3))
		break


inp1 = list(map(int, input().split()))
inp2 = list(map(int, input().split()))
inp3 = list(map(int, input().split()))
inp4 = list(map(int, input().split()))
inp5 = list(map(int, input().split()))
list1 = [inp1, inp2, inp3, inp4, inp5]
result = 0
for i in range(5):
	for j in range(5):
		if list1[i][j] == 1:
			result = abs(j - 2) + abs(i - 2)
print(result)


onePos_i = 0
onePos_j = 0
for i in range(5):
	lineStr = input()
	line = lineStr.split()
	for j in range(5):
		if int(line[j]) == 1:
			onePos_i = i
			onePos_j = j
			break
ans = abs(onePos_i - 2) + abs(onePos_j - 2)
print(ans)


(oneX, oneY) = (-1, -1)
for y in range(1, 5 + 1):
	x = input().split(' ')
	try:
		oneX = x.index('1') + 1
		oneY = y
	except:
		pass
n = abs(3 - oneX) + abs(3 - oneY)
print(n)


x = []
for i in range(5):
	x += [input().split(' ')]
if x[0][4] == '1' or x[0][0] == '1' or x[4][4] == '1' or (x[4][0] == '1'):
	c = 4
elif x[0][3] == '1' or x[0][1] == '1' or x[4][3] == '1' or (x[4][1] == '1'):
	c = 3
elif x[0][2] == '1' or x[4][2] == '1':
	c = 2
elif x[1][4] == '1' or x[1][0] == '1' or x[3][4] == '1' or (x[3][0] == '1'):
	c = 3
elif x[1][3] == '1' or x[1][1] == '1' or x[3][3] == '1' or (x[3][1] == '1'):
	c = 2
elif x[1][2] == '1' or x[3][2] == '1':
	c = 1
elif x[2][0] == '1' or x[2][4] == '1':
	c = 2
elif x[2][1] == '1' or x[2][3] == '1':
	c = 1
else:
	c = 0
print(c)


rows = []
for i in range(0, 5):
	s = str(input())
	s = s.split(' ')
	s = [int(i) for i in s]
	rows += [s]
for i in range(0, len(rows)):
	for j in range(0, len(rows[i])):
		if rows[i][j] == 1:
			count = 0
			count += abs(2 - i)
			count += abs(2 - j)
			print(count)
			break


from array import *
stringA = input()
stringB = input()
stringC = input()
stringD = input()
stringE = input()
T = [[], []]
x = 0
y = 0
T.insert(0, stringA.split())
T.insert(1, stringB.split())
T.insert(2, stringC.split())
T.insert(3, stringD.split())
T.insert(4, stringE.split())
for tellerX in range(0, 5):
	for tellerY in range(0, 5):
		if int(T[tellerX][tellerY]) == 1:
			x = tellerX
			y = tellerY
print(abs(2 - x) + abs(2 - y))


matriz = []
for i in range(1, 6):
	linea = input()
	linea = linea.split(' ')
	matriz.append(linea)
for i in range(5):
	for j in range(5):
		if matriz[i][j] == '1':
			indiceI = i
			indiceJ = j
cont = 0
while indiceI != 2:
	if indiceI < 2:
		indiceI += 1
		cont += 1
	else:
		indiceI -= 1
		cont += 1
while indiceJ != 2:
	if indiceJ < 2:
		indiceJ += 1
		cont += 1
	else:
		indiceJ -= 1
		cont += 1
print(cont)


c = 1
for i in range(5):
	row = [str(x) for x in input().split()]
	if '1' in row:
		r = row.index('1') + 1
		break
	else:
		c += 1
print(abs(r - 3) + abs(c - 3))


a = list()
foundOne = False
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			foundOne = True
			break
	if foundOne == True:
		break
moves = abs(2 - i) + abs(2 - j)
print(moves)


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))

def xaxis_postion(l):
	position = l.index(1)
	if position == 2:
		x = 0
	elif position == 0 or position == 4:
		x = 2
	else:
		x = 1
	return x
if 1 in l1:
	y = 2
	x = xaxis_postion(l1)
	print(x + y)
elif 1 in l2:
	y = 1
	x = xaxis_postion(l2)
	print(x + y)
elif 1 in l3:
	y = 0
	x = xaxis_postion(l3)
	print(x + y)
elif 1 in l4:
	y = 1
	x = xaxis_postion(l4)
	print(x + y)
else:
	y = 2
	x = xaxis_postion(l5)
	print(x + y)


for i in range(5):
	line = list(map(int, input().split()))
	if 1 in line:
		k = line.index(1)
		j = i
steps = abs(k - 2) + abs(j - 2)
print(steps)


a = []
row = 0
column = 0
for i in range(5):
	a.append(input().split(' ', 4))
for i in range(len(a)):
	try:
		index_value = a[i].index('1')
	except ValueError:
		index_value = -1
	if index_value != -1:
		column = index_value + 1
		row = i + 1
		break
print(abs(row - 3) + abs(column - 3))


l = []
amount = 0
for i in range(5):
	s = list(map(int, input().split()))
	if 1 in s:
		x = s.index(1)
		y = i
	l.append(s)
try:
	if x != 2:
		amount += abs(2 - x)
	if y != 2:
		amount += abs(2 - y)
except:
	None
print(amount)
ex = '\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n'


__author__ = 'widoc'
matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
	if 1 in matrix[i]:
		a = i
result = abs(2 - a) + abs(2 - matrix[a].index(1))
print(result)


import math
matrix = []
for i in range(5):
	matrix.extend([int(i) for i in input().split()])
idx_1 = matrix.index(1) + 1
i_1 = math.ceil(idx_1 / 5)
j_1 = 5 if idx_1 % 5 == 0 else idx_1 % 5
print(abs(3 - j_1) + abs(3 - i_1))


x = [[], [], [], [], []]
for i in range(0, 5):
	x[i] = input().split()
	for (j, val) in enumerate(x[i]):
		x[i][j] = int(val)

def find_one():
	global x
	for i in range(5):
		for j in range(5):
			pos_val = int(x[i][j])
			if pos_val == 1:
				return (i, j)

def swap_i(pos_i, pos_f, pos_j):
	global x
	temp = x[pos_i][pos_j]
	x[pos_i][pos_j] = x[pos_f][pos_j]
	x[pos_f][pos_j] = temp
	return pos_f

def swap_j(pos_i, pos_f):
	global x
	i = pos_i
	temp = x[2][i]
	x[2][i] = x[2][pos_f]
	x[2][pos_f] = temp
	return pos_f
move = 0
(pos_i, pos_j) = find_one()
while pos_i != 2 or pos_j != 2:
	move = move + 1
	if pos_i < 2:
		pos_i = swap_i(pos_i, pos_i + 1, pos_j)
		continue
	elif pos_i > 2:
		pos_i = swap_i(pos_i, pos_i - 1, pos_j)
		continue
	elif pos_j < 2:
		pos_j = swap_j(pos_j, pos_j + 1)
		continue
	elif pos_j > 2:
		pos_j = swap_j(pos_j, pos_j - 1)
		continue
print(move)


for i in range(5):
	lis = list(map(int, input().split()))
	if 1 in lis:
		num = lis.index(1)
		row = i
count = abs(row - 2) + abs(num - 2)
print(count)


3
array = [list(map(int, input().split())) for _ in range(5)]
i = [_ for _ in range(5) if 1 in array[_]][0]
array = list(zip(*array))
j = [_ for _ in range(5) if 1 in array[_]][0]
print(abs(i - 2) + abs(j - 2))


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
one_row = 0
one_col = 0
for row in range(5):
	for col in range(5):
		if matrix[row][col] == 1:
			one_row = row + 1
			one_col = col + 1
if one_row == 1 and one_col == 1:
	print(4)
elif one_row == 1 and one_col == 2:
	print(3)
elif one_row == 1 and one_col == 3:
	print(2)
elif one_row == 1 and one_col == 4:
	print(3)
elif one_row == 1 and one_col == 5:
	print(4)
elif one_row == 2 and one_col == 1:
	print(3)
elif one_row == 2 and one_col == 2:
	print(2)
elif one_row == 2 and one_col == 3:
	print(1)
elif one_row == 2 and one_col == 4:
	print(2)
elif one_row == 2 and one_col == 5:
	print(3)
elif one_row == 3 and one_col == 1:
	print(2)
elif one_row == 3 and one_col == 2:
	print(1)
elif one_row == 3 and one_col == 3:
	print(0)
elif one_row == 3 and one_col == 4:
	print(1)
elif one_row == 3 and one_col == 5:
	print(2)
elif one_row == 4 and one_col == 1:
	print(3)
elif one_row == 4 and one_col == 2:
	print(2)
elif one_row == 4 and one_col == 3:
	print(1)
elif one_row == 4 and one_col == 4:
	print(2)
elif one_row == 4 and one_col == 5:
	print(3)
elif one_row == 5 and one_col == 1:
	print(4)
elif one_row == 5 and one_col == 2:
	print(3)
elif one_row == 5 and one_col == 3:
	print(2)
elif one_row == 5 and one_col == 4:
	print(3)
elif one_row == 5 and one_col == 5:
	print(4)


l = []
for a in range(5):
	x = input()
	l.append(x.split())
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			b = i
			c = j
n = abs(b - 2) + abs(c - 2)
print(n)


mylist = [([] for i in range(5)) for i in range(5)]
i = 4
while i >= 0:
	mylist[i] = list(map(int, input().split()))
	i = i - 1
m = 0
n = 0
k = 1
while m < 5 and k == 1:
	n = 0
	while n < 5 and k == 1:
		if mylist[m][n] == 1:
			k = 0
		n = n + 1
	m = m + 1
print(abs(m - 3) + abs(n - 3))


matrix = [[int(x) for x in input().strip().split()] for _ in range(5)]

def get_pos_1():
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				return [i, j]
(pos_x, pos_y) = get_pos_1()
moves = 0
while pos_x != 2 or pos_y != 2:
	if pos_x > 2:
		pos_x -= 1
	elif pos_x < 2:
		pos_x += 1
	elif pos_y > 2:
		pos_y -= 1
	elif pos_y < 2:
		pos_y += 1
	else:
		continue
	moves += 1
print(moves)


from sys import exit as sys_return
matrix = [list(map(int, input().split())) for i in range(5)]
x = y = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			(x, y) = (i, j)
print(abs(2 - x) + abs(2 - y))


i = 0
j = 0
while j < 5:
	m = input().replace(' ', '')
	i = m.find('1')
	if i != -1:
		break
	j += 1
print(abs(j - 2) + abs(i - 2))


mat = []
for i in range(5):
	ls = list(map(int, input().split()))
	mat.append(ls)
for i in range(5):
	if 1 in mat[i]:
		row = mat[i].index(1)
		column = i
		break
step = 0
while row != 2:
	if row > 2:
		row = row - 1
		step += 1
	elif row < 2:
		row = row + 1
		step += 1
while column != 2:
	if column > 2:
		column = column - 1
		step += 1
	elif column < 2:
		column = column + 1
		step += 1
print(step)


def bm():
	mat = []
	for i in range(5):
		mat.append(list(map(int, input().split())))
	i = 0
	j = 0
	for row in range(5):
		for col in range(5):
			if mat[row][col] == 1:
				i = row
				j = col
				break
	return abs(i - 2) + abs(j - 2)
print(bm())


(rows, columns) = (5, 5)
matrix = []
(moves1, moves2) = (0, 0)
moves = int
for i in range(rows):
	matrix.append([int(j) for j in input().split()])
position_tuple = list([(index, rows.index(1)) for (index, rows) in enumerate(matrix) if 1 in rows])
position = [item for t in position_tuple for item in t]
if position[0] < 2:
	moves1 = position[0] - 2
elif position[0] > 2:
	moves1 = 2 - position[0]
if position[1] < 2:
	moves2 = position[1] - 2
elif position[1] > 2:
	moves2 = 2 - position[1]
moves = abs(moves1) + abs(moves2)
print(moves)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	(x, y) = (0, 0)
	for i in range(5):
		for (j, elem) in enumerate(read()):
			if elem == 1:
				(x, y) = (i + 1, j + 1)
	print(abs(x - 3) + abs(y - 3))
solve()


mat = []
res = 0
for i in range(5):
	s = input().split()
	mat.append(s)
for i in range(5):
	for j in range(5):
		if mat[i][j] == '1':
			a = int(3 - i - 1)
			b = int(3 - j - 1)
			break
if a < 0:
	a = -a
if b < 0:
	b = -b
res = a + b
print(res)


raws = []
i = 0
r = 0
c = 0
while i < 5:
	raws.append(input().split())
	j = 0
	while j < 5:
		if int(raws[i][j]) == 1:
			r = i
			c = j
		j += 1
	i += 1
print(abs(2 - r) + abs(2 - c))


matrix = []
for i in range(5):
	matrix.append(input().split())
x: int = 0
y: int = 0
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if int(matrix[i][j]) == 1:
			x = i + 1
			y = j + 1
			break
print(f'{abs(x - 3) + abs(y - 3)}')


def get_coords():
	for i in range(0, 5):
		k = [int(i) for i in input().split(' ')]
		for j in range(0, 5):
			if k[j] == 1:
				return (i, j)
(x, y) = get_coords()
print(abs(2 - x) + abs(2 - y))


zj = []
for i in range(5):
	x = input().split()
	zj.append(x)
counter = 0
xj = 0
yj = 0
for x in range(5):
	for y in range(5):
		if zj[x][y] == '1':
			xj = x
			yj = y
while True:
	if zj[2][2] == '1':
		break
	counter += 1
	if xj > 2:
		temp = zj[xj]
		zj[xj] = zj[xj - 1]
		zj[xj - 1] = temp
		xj = xj - 1
	elif xj < 2:
		temp = zj[xj]
		zj[xj] = zj[xj + 1]
		zj[xj + 1] = temp
		xj = xj + 1
	elif yj > 2:
		zj[xj][yj] = '0'
		zj[xj][yj - 1] = '1'
		yj = yj - 1
	elif yj < 2:
		zj[xj][yj] = '0'
		zj[xj][yj + 1] = '1'
		yj = yj + 1
print(counter)


l1 = []
x = 0
y = 0
for i in range(1, 6):
	l = list(map(int, input().split()))
	l1.append(l)
	if 1 in l:
		x = i
		y = l.index(1) + 1
x1 = abs(3 - x)
y1 = abs(3 - y)
print(x1 + y1)


found = False
for i in range(1, 6):
	arr = list(map(int, input().split()))
	if not found:
		for j in range(1, 6):
			if arr[j - 1] == 1:
				(a, b) = (i, j)
				found = True
ans = abs(a - 3)
ans += abs(b - 3)
print(ans)


ans = 0
for i in range(0, 5):
	m = input().split()
	for j in range(0, len(m)):
		if m[j] == '1':
			ans = abs(i - 2) + abs(j - 2)
print(ans)


import sys
l1 = sys.stdin.readline().replace('\n', '').replace(' ', '')
while l1:
	l2 = sys.stdin.readline().replace('\n', '').replace(' ', '')
	l3 = sys.stdin.readline().replace('\n', '').replace(' ', '')
	l4 = sys.stdin.readline().replace('\n', '').replace(' ', '')
	l5 = sys.stdin.readline().replace('\n', '').replace(' ', '')
	mat = [l1, l2, l3, l4, l5]
	res = 0
	for i in range(5):
		if '1' in mat[i]:
			v_m = abs(2 - i)
			res += v_m
			index = mat[i].index('1')
			h_m = abs(2 - index)
			res += h_m
			break
	print(res)
	l1 = sys.stdin.readline()


for y in range(5):
	array = [int(num) for num in input().split()]
	for x in range(5):
		if array[x] == 1:
			x2 = x
			y2 = y
			break
print(abs(2 - x2) + abs(2 - y2))


done = False
for i in range(5):
	r = [int(x) for x in input().split()]
	for x in r:
		if x == 1:
			j = r.index(1)
			print(abs(i - 2) + abs(j - 2))
			done = True
			break
	if done == True:
		break


l1 = []
for i in range(1, 6):
	l1.append([int(x) for x in input().split()])
row = 0
for item in l1:
	row += 1
	if 1 in item:
		column = item.index(1) + 1
		break
print(abs(3 - row) + abs(3 - column))


matrix = [[0 for x in range(0, 5)] for x in range(5)]
op = 0
for y in range(0, 5):
	a = input().split()
	if '1' in a:
		op += abs(2 - y)
		for x in range(0, 5):
			if a[x] == '1':
				op += abs(2 - x)
				break
print(op)


n = 5
index1 = 0
index2 = 0
for i in range(n):
	string = input().split()
	for j in range(len(string)):
		if string[j] == '1':
			index1 = i
			index2 = j
a = abs(2 - index1)
b = abs(2 - index2)
answ = a + b
print(answ)


lis = []
for i in range(5):
	lis1 = list(map(str, input().split()))
	lis.append(lis1)
(ac, ar) = (0, 0)
for i in range(len(lis)):
	if '1' in lis[i]:
		ar = i
		ac = lis[i].index('1')
		break
ans = 0
ans += abs(ac - 2)
ans += abs(ar - 2)
print(ans)


(x, y) = (0, 0)
for i in range(1, 6):
	row = input().split()
	j_index = 1
	for j in row:
		if j == '1':
			x = j_index
			y = i
			break
		else:
			j_index += 1
	if x != 0 and y != 0:
		break
print(abs(3 - x) + abs(3 - y))


A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
E = [int(i) for i in input().split()]
cond = 0
x = 0
y = 0
if cond == 0:
	for i in range(0, len(A)):
		if A[i] == 1:
			x = 1
			y = i + 1
			cond = 1
if cond == 0:
	for i in range(0, len(B)):
		if B[i] == 1:
			x = 2
			y = i + 1
			cond = 1
if cond == 0:
	for i in range(0, len(C)):
		if C[i] == 1:
			x = 3
			y = i + 1
			cond = 1
if cond == 0:
	for i in range(0, len(D)):
		if D[i] == 1:
			x = 4
			y = i + 1
			cond = 1
if cond == 0:
	for i in range(0, len(E)):
		if E[i] == 1:
			x = 5
			y = i + 1
			cond = 1
ans = abs(x - 3) + abs(y - 3)
print(ans)


dict = {}
x = 0
y = 0
for i in range(5):
	dict[i] = list(map(int, input().split()))
for i in range(5):
	for j in range(5):
		if dict[i][j] == 1:
			x = i
			y = j
			break
n = abs(x - 2) + abs(y - 2)
print(n)


from sys import stdin, stdout, setrecursionlimit

def get_int():
	return int(stdin.readline().strip())

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

def get_string():
	return stdin.readline().strip()

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

def solve():
	if x == 2 and y == 2:
		return '0'
	if x == 0 and y == 0 or (x == 4 and y == 0) or (x == 0 and y == 4) or (x == 4 and y == 4):
		return '4'
	if x == 1 and y == 0 or (x == 3 and y == 0) or (x == 0 and y == 1) or (x == 4 and y == 1) or (x == 0 and y == 3) or (x == 4 and y == 3) or (x == 1 and y == 4) or (x == 3 and y == 4):
		return '3'
	if x == 2 and y == 0 or (x == 1 and y == 1) or (x == 3 and y == 1) or (x == 0 and y == 2) or (x == 4 and y == 2) or (x == 1 and y == 3) or (x == 3 and y == 3) or (x == 2 and y == 4):
		return '2'
	if x == 2 and y == 1 or (x == 1 and y == 2) or (x == 3 and y == 2) or (x == 2 and y == 3):
		return '1'
x = 0
y = 0
solved = False
getOut = 5
for _ in range(5):
	list = get_ints()
	getOut -= 1
	for pos in list:
		if pos == 1:
			solved = True
			break
		x += 1
	if solved:
		break
	x = 0
	y += 1
for _ in range(getOut):
	list = get_ints()
stdout.write(solve())


m = 0
for i in range(5):
	s = [int(x) for x in input().split()]
	if sum(s) == 1:
		j = s.index(1)
		m += abs(j - 2)
		m += abs(i - 2)
		print(m)
		break


def do():
	a = [input('').split() for i in range(5)]
	count = 0
	rc = 3
	for (i, j) in enumerate(a):
		if '1' in j:
			if i + 1 > rc:
				count += i + 1 - rc
			else:
				count += rc - (i + 1)
			if j.index('1') + 1 > rc:
				count += j.index('1') + 1 - rc
			else:
				count += rc - (j.index('1') + 1)
	print(count)
do()


def display_matrix(matrix):
	for i in matrix:
		print(i)
	print()

def swap_rows(matrix, row_no_1, row_no_2):
	new_matrix = list(matrix)
	new_matrix[row_no_1 - 1] = matrix[row_no_2 - 1]
	new_matrix[row_no_2 - 1] = matrix[row_no_1 - 1]
	return new_matrix

def swap_columns(matrix, column_no_1, column_no_2):
	new_matrix = list(matrix)
	deleting = []
	for i in range(len(new_matrix)):
		deleting.append(matrix[i][column_no_1 - 1])
		new_matrix[i][column_no_1 - 1] = matrix[i][column_no_2 - 1]
		new_matrix[i][column_no_2 - 1] = deleting[i]
	return new_matrix

def row_to_column(matrix):
	row_index = 0
	shifts_required = 0
	new_matrix = []
	for (r_index, row) in enumerate(matrix):
		if row.count('1') > 0:
			for i in range(len(row)):
				if row[i] == '1':
					row_index = r_index
	if row_index < 2:
		shifts_required = 2 - row_index
		row_index += 1
		for k in range(shifts_required):
			matrix = swap_rows(matrix, row_index, row_index + 1)
			row_index += 1
	elif row_index > 2:
		shifts_required = row_index - 2
		row_index += 1
		for k in range(shifts_required):
			matrix = swap_rows(matrix, row_index, row_index - 1)
			row_index -= 1
	return (matrix, shifts_required)

def column_to_mid(matrix):
	one_index = 0
	shifts_required = 0
	for i in range(len(matrix[2])):
		if matrix[2][i] == '1':
			one_index = i
	if one_index < 2:
		shifts_required = 2 - one_index
		for k in range(shifts_required):
			one_index += 1
			matrix = swap_columns(matrix, one_index, one_index + 1)
	elif one_index > 2:
		shifts_required = one_index - 2
		one_index += 1
		for k in range(shifts_required):
			matrix = swap_columns(matrix, one_index, one_index - 1)
			one_index -= 1
	return shifts_required

def get_swap_count(matrix):
	if matrix[2][2] == '1':
		return 0
	elif matrix[2].count('1') > 0:
		count = column_to_mid(matrix)
		return count
	else:
		(new_matrix, count_1) = row_to_column(matrix)
		count_2 = get_swap_count(new_matrix)
		return count_1 + count_2

def main():
	matrix = []
	for i in range(5):
		matrix.append(input().split())
	count = get_swap_count(matrix)
	print(count)
main()


a = []
for i in range(5):
	b = list(map(int, input().split()))
	a.append(b)
for i in a:
	if sum(i) == 1:
		o = a.index(i)
		c = i
		l = c.index(1)
print(abs(2 - l) + abs(2 - o))


a = list((int(x) for x in input().split()))
b = list((int(x) for x in input().split()))
c = list((int(x) for x in input().split()))
d = list((int(x) for x in input().split()))
e = list((int(x) for x in input().split()))
f = [a, b, c, d, e]
g = -1
for i in f:
	g += 1
	k = 0
	for j in i:
		if j == 1:
			if g == 0 and k == 0 or (g == 4 and k == 4):
				print(4)
			elif g == 3 and k == 3 or (g == 1 and k == 1):
				print(2)
			elif g == 1 and k == 0 or (g == 0 and k == 1) or (g == 4 and k == 3) or (g == 3 and k == 4):
				print(3)
			else:
				print(abs(g - k))
		else:
			k += 1


l = []
for i in range(5):
	ch = input()
	l.append(ch.split())
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			x = i
			y = j
print(abs(x - 2) + abs(2 - y))


n = 5
full = list()
for i in range(n):
	full = input().split(' ')
	for j in range(len(full)):
		if full[j] == '1':
			a = i
			b = j
			break
print(abs(2 - a) + abs(2 - b))


culumn = 1
lign = 1
for i in range(5):
	row = [int(j) for j in input().split(' ')] * 5
	if row[0] + row[1] + row[2] + row[3] + row[4] == 1:
		lign = i + 1
	for k in range(5):
		if row[k] == 1:
			culumn = k + 1
print(abs(culumn - 3) + abs(lign - 3))


rows = []
for x in range(5):
	rows.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if rows[i][j] == 1:
			(l, m) = (i, j)
			break
row_add = abs(2 - l)
col_add = abs(2 - m)
print(row_add + col_add)


row1 = input().split()
row2 = input().split()
row3 = input().split()
row4 = input().split()
row5 = input().split()
count = 0
while True:
	if '1' in row1:
		for item in row1:
			if item == '1':
				row2[row1.index(item)] = '1'
				row1[row1.index(item)] = '0'
				count += 1
	if '1' in row2:
		for item in row2:
			if item == '1':
				row3[row2.index(item)] = '1'
				row2[row2.index(item)] = '0'
				count += 1
	if '1' in row4:
		for item in row4:
			if item == '1':
				row3[row4.index(item)] = '1'
				row4[row4.index(item)] = '0'
				count += 1
	if '1' in row5:
		for item in row5:
			if item == '1':
				row4[row5.index(item)] = '1'
				row5[row5.index(item)] = '0'
				count += 1
				continue
	else:
		break
if row3[2] != '1':
	count += abs(row3.index('1') - 2)
print(count)


for x in range(5):
	r = input().replace(' ', '')
	y = r.find('1')
	if not y == -1:
		coords = [x, y]
print(abs(coords[0] - 2) + abs(coords[1] - 2))


list1 = []
list2 = []
loc_i = loc_j = 0
for i in range(5):
	list1 = list(map(int, input().split()))
	list2.append(list1)
for i in range(5):
	for j in range(5):
		if list2[i][j] == 1:
			loc_i = i + 1
			loc_j = j + 1
print(abs(loc_i - 3) + abs(loc_j - 3))


r1 = [int(n) for n in input().split(' ')]
r2 = [int(n) for n in input().split(' ')]
r3 = [int(n) for n in input().split(' ')]
r4 = [int(n) for n in input().split(' ')]
r5 = [int(n) for n in input().split(' ')]
matrix = [r1, r2, r3, r4, r5]
steps = 0
for i in range(len(matrix)):
	for n in range(len(matrix[i])):
		if matrix[i][n] == 1:
			steps = abs(2 - n) + abs(2 - i)
print(steps)


def findLocationOf1(a):
	flag = 0
	for i in range(5):
		for j in range(5):
			if a[i][j] == 1:
				flag = 1
				break
		if flag == 1:
			break
	return (j, i)
a = []
for i in range(5):
	x = list(map(int, input().split()))
	a.append(x)
(x, y) = findLocationOf1(a)
step = abs(x - 2) + abs(y - 2)
print(step)


matrow = []
onelocation = 0
movecount = 0
for index in range(1, 6):
	matrow.append(list(map(int, input().split())))
	if matrow[index - 1].__len__() != 5:
		exit(0)
	if matrow[index - 1].__contains__(1):
		onelocation = index
movecount = abs(3 - onelocation) + abs(matrow[onelocation - 1].index(1) - 2)
print(movecount)


import math
grid = []
solved = 0
for i in range(5):
	grid.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if grid[i][j] == 1:
			one_position = (i, j)
			break
print(abs(one_position[0] - 2) + abs(one_position[1] - 2))


a = [[int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()]]
x = 0
while x in range(len(a)):
	for i in range(len(a[0])):
		if a[x][i] == 1:
			break
	if a[x][i] == 1:
		break
	else:
		x += 1
print(abs(x - 2) + abs(i - 2))


i = 0
while i < 5:
	s = input().split()
	if '1' in s:
		moves = abs(i - 2) + abs(s.index('1') - 2)
	i += 1
print(moves)


for i in range(5):
	n = input().split()
	for j in range(5):
		if n[j] != '0':
			c = i
			r = j
print(abs(c - 2) + abs(r - 2))


r = 0
c = 0
for k in range(1, 6):
	f = ''.join(map(str, input().split())).find('1')
	if f != -1:
		r = f + 1
		c = k
		break
print(abs(r - 3) + abs(c - 3))


from math import *
list1 = [[], [], [], [], []]
list1[0] = input().split()
if '1' in list1[0]:
	n = 1
list1[1] = input().split()
if '1' in list1[1]:
	n = 2
list1[2] = input().split()
if '1' in list1[2]:
	n = 3
list1[3] = input().split()
if '1' in list1[3]:
	n = 4
list1[4] = input().split()
if '1' in list1[4]:
	n = 5
m = list1[n - 1].index('1') + 1
print(abs(m - 3) + abs(n - 3))


Arr = []
for u in range(5):
	A = list(map(int, input().split()))
	Arr.append(A)
ans = 0
for u in range(5):
	for v in range(5):
		if Arr[u][v] == 1:
			m = u
			n = v
			break
print(abs(m - 2) + abs(n - 2))


for i in range(5):
	row = input()
	row = row.replace(' ', '')
	if row.find('1') >= 0:
		row_index = row.find('1') + 1
		column_index = i + 1
move = abs(row_index - 3) + abs(column_index - 3)
print(move)


for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	if a == 0 and b == 0 and (c == 0) and (d == 0) and (e == 0):
		continue
	s = abs(i - 2)
	if a == 1 or e == 1:
		s = s + 2
	elif b == 1 or d == 1:
		s = s + 1
print(s)


Li = [[], [], [], [], []]
i1 = 0
j1 = 0
for i in range(5):
	c = input()
	c = c.split()
	for j in range(5):
		Li[i].append(c[j])
		if c[j] == '1':
			j1 = j + 1
			i1 = i + 1
di = abs(j1 - 3)
dj = abs(i1 - 3)
print(di + dj)


for i in range(5):
	s = [int(x) for x in input().split()]
	for j in range(5):
		if s[j] == 1:
			print(abs(2 - i) + abs(2 - j))
			exit


mat = []
x = 0
y = 0
for i in range(5):
	mat.append([int(i) for i in input().split()])
for i in mat:
	for j in i:
		if j == 1:
			x = i.index(j) + 1
			y = mat.index(i) + 1
			break
print(abs(3 - x) + abs(3 - y))


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))
myMat = [r1, r2, r3, r4, r5]
for row in range(0, len(myMat)):
	for col in range(0, len(r1)):
		if myMat[row][col] == 1:
			pos = [row, col]
ops = 0
while pos[0] != 2:
	if pos[0] > 2:
		temp = myMat[pos[0]]
		myMat[pos[0]] = myMat[pos[0] - 1]
		myMat[pos[0] - 1] = temp
		ops += 1
		pos[0] -= 1
	elif pos[0] < 2:
		temp = myMat[pos[0]]
		myMat[pos[0]] = myMat[pos[0] + 1]
		myMat[pos[0] + 1] = temp
		ops += 1
		pos[0] += 1
while pos[1] != 2:
	if pos[1] > 2:
		for rows in myMat:
			temp = rows[pos[1] - 1]
			rows[pos[1] - 1] = rows[pos[1]]
			rows[pos[1]] = temp
		pos[1] -= 1
		ops += 1
	elif pos[1] < 2:
		for rows in myMat:
			temp = rows[pos[1] + 1]
			rows[pos[1] + 1] = rows[pos[1]]
			rows[pos[1]] = temp
		pos[1] += 1
		ops += 1
print(ops)


row = 0
col = 0
flag = False
for i in range(5):
	row += 1
	arr = input().split()
	arr = [int(x) for x in arr]
	for j in range(5):
		temp = arr[j]
		col = j + 1
		if temp == 1:
			flag = True
			break
	if flag:
		break
print(abs(row - 3) + abs(col - 3))


a = [[int(j) for j in input().split()] for i in range(5)]
k = 0
if a[2][2] == 1:
	print(0)
else:
	for i in range(5):
		for j in range(5):
			if a[i][j] == 1:
				c = abs(i - 2)
				c1 = abs(j - 2)
	print(c + c1)


i = 3
j = 3
for k in range(1, 6):
	m = input().split()
	if '1' in m:
		one = m.index('1') + 1
		print(abs(i - k) + abs(j - one))


def check():
	matrix = [[0] * 5 for i in range(5)]
	for i in range(5):
		values = list(map(int, input().split()))
		for j in range(len(values)):
			if values[j] == 1:
				value = abs(2 - j) + abs(2 - i)
	return value
print(check())


def getmoves(arr):
	posof1 = None
	for x in range(len(arr)):
		if 1 in arr[x]:
			posof1 = (x, arr[x].index(1))
	return abs(2 - posof1[0]) + abs(2 - posof1[1])
grid = []
for _ in range(5):
	grid.append(list(map(int, input().rstrip().split())))
print(getmoves(grid))


li = []
for i in range(5):
	li.append([int(j) for j in input().split()])
a = 0
while a < 5:
	if 1 in li[a]:
		break
	a = a + 1
b = li[a].index(1)
a = a + 1
b = b + 1
x = 0
y = 0
if a > 3:
	x = a - 3
else:
	x = 3 - a
if b + 1 > 3:
	y = b - 3
else:
	y = 3 - b
print(x + y)


for i in range(5):
	a = [int(x) for x in input().split()]
	if 1 in a:
		k = i + 1
		te = a
l = te.index(1) + 1
print(abs(l - 3) + abs(k - 3))


a = []
p = 0
q = 0
for i in range(1, 6):
	a.append([int(j) for j in input().split()])
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			p += i
			q += j
print(abs(2 - p) + abs(2 - q))


distance = 4
for i in range(5):
	inputs = input().split(' ')
	for j in range(len(inputs)):
		inputs2 = int(inputs[j])
		if inputs2 == 1:
			print(abs(2 - i) + abs(2 - j))


(O1, O2, O3, O4, O5) = input().split()
(B1, B2, B3, B4, B5) = input().split()
(T1, T2, T3, T4, T5) = input().split()
(F1, F2, F3, F4, F5) = input().split()
(P1, P2, P3, P4, P5) = input().split()
if int(O1) == 1:
	i = 1
	j = 1
if int(O2) == 1:
	i = 1
	j = 2
if int(O3) == 1:
	i = 1
	j = 3
if int(O4) == 1:
	i = 1
	j = 4
if int(O5) == 1:
	i = 1
	j = 5
if int(B1) == 1:
	i = 2
	j = 1
if int(B2) == 1:
	i = 2
	j = 2
if int(B3) == 1:
	i = 2
	j = 3
if int(B4) == 1:
	i = 2
	j = 4
if int(B5) == 1:
	i = 2
	j = 5
if int(T1) == 1:
	i = 3
	j = 1
if int(T2) == 1:
	i = 3
	j = 2
if int(T3) == 1:
	i = 3
	j = 3
if int(T4) == 1:
	i = 3
	j = 4
if int(T5) == 1:
	i = 3
	j = 5
if int(F1) == 1:
	i = 4
	j = 1
if int(F2) == 1:
	i = 4
	j = 2
if int(F3) == 1:
	i = 4
	j = 3
if int(F4) == 1:
	i = 4
	j = 4
if int(F5) == 1:
	i = 4
	j = 5
if int(P1) == 1:
	i = 5
	j = 1
if int(P2) == 1:
	i = 5
	j = 2
if int(P3) == 1:
	i = 5
	j = 3
if int(P4) == 1:
	i = 5
	j = 4
if int(P5) == 1:
	i = 5
	j = 5
print(abs(3 - i) + abs(3 - j))


for i in range(5):
	s = list(map(int, input().split()))
	for j in range(5):
		if s[j] == 1:
			z = i - 2
			x = j - 2
print(abs(z) + abs(x))


matrix = []
iIndex = 0
jIngex = 0
for i in range(5):
	newLine = [int(number) for number in input().split()]
	matrix.append(newLine)
	if newLine.count(1) == 1:
		iIndex = i + 1
		jIngex = newLine.index(1) + 1
print(abs(iIndex - 3) + abs(jIngex - 3))


for i in range(5):
	inp = input().split()
	column = [int(string) for string in inp]
	if 1 in column:
		steps_row = abs(column.index(1) - 2)
		break
	else:
		continue
steps = steps_row + abs(i - 2)
print(steps)


b = []
cnt = 0
hl = 0
c = 0
for i in range(5):
	a = input()
	if '1' in a:
		hl = i + 1
		b.append(a)
for i in b:
	for j in i:
		if j != ' ':
			cnt += 1
		if j == '1':
			if 3 - cnt < 0:
				c = -(3 - cnt)
			else:
				c = 3 - cnt
				break
if hl <= 3:
	d = 3 - hl
else:
	d = hl - 3
print(c + d)


i = 0
x = input().split()
while '1' not in x:
	i += 1
	x = input().split()
print(abs(2 - i) + abs(2 - x.index('1')))


for i in range(5):
	numbers = list(map(int, input().split()))
	for j in range(5):
		if numbers[j] == 1:
			(I, J) = (i, j)
print(abs(2 - I) + abs(2 - J))


lt1 = list(input())
lt2 = list(input())
lt3 = list(input())
lt4 = list(input())
lt5 = list(input())
var = True
var1 = ''
var3 = 0
num = 0
while var == True:
	for i in lt1:
		if i == '1':
			num += 2
			var = False
			var1 = lt1
	for i in lt2:
		if i == '1':
			num += 1
			var = False
			var1 = lt2
	for i in lt3:
		if i == '1':
			var = False
			var1 = lt3
	for i in lt4:
		if i == '1':
			num += 1
			var = False
			var1 = lt4
	for i in lt5:
		if i == '1':
			num += 2
			var = False
			var1 = lt5
var4 = var1.index('1')
if var4 == 0 or var4 == 8:
	print(num + 2)
elif var4 == 2 or var4 == 6:
	print(num + 1)
else:
	print(num)


i = 0
j = 0
for ii in range(5):
	t = [int(x) for x in input().split()]
	if sum(t) != 0:
		i = ii + 1
		j = t.index(1) + 1
result = abs(i - 3) + abs(j - 3)
print(result)


for i in range(5):
	str = input().split()
	for j in range(len(str)):
		if str[j] == '1':
			if i + 1 == 3:
				print(abs(3 - (j + 1)))
				exit()
			else:
				print(abs(3 - (j + 1)) + abs(3 - (i + 1)))
				exit()


def main():
	moves = 0
	for (e, x) in enumerate(range(5)):
		r = str(input()).split(' ')
		if '1' in r:
			moves += abs(2 - e)
			for (l, c) in enumerate(r):
				if c == '1':
					moves += abs(2 - l)
	print(moves)
main()


k = [input().split() for i in range(5)]

def find(k):
	count_row = 0
	count_columns = 0
	for i in k:
		count_row += 1
		for j in i:
			count_columns += 1
			if int(j):
				pos_row = abs(3 - count_row)
				pos_col = abs(3 - count_columns)
				print(pos_row + pos_col)
				return None
		count_columns = 0
find(k)


lines = []
for x in range(5):
	line = input()
	lines.append(line)
	number = line.split(' ')
	if '1' in number:
		n = int(x)
a = lines[n]
b = a.split(' ')
m = b.index('1')
move = abs(n - 2) + abs(m - 2)
print(move)


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
row = 0
column = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			while i < 2:
				i = i + 1
				row = row + 1
			while j < 2:
				j = j + 1
				row = row + 1
			while i > 2:
				i = i - 1
				column = column + 1
			while j > 2:
				j = j - 1
				column = column + 1
print(row + column)


for i in range(5):
	s = list(map(int, input().strip().split()))
	for k in range(5):
		if s[k] == 1:
			x = i + 1
			y = k + 1
			print(abs(x - 3) + abs(y - 3))
			break


for i in range(5):
	line = list(input())
	for j in line:
		if j == ' ':
			line.remove(j)
	for j in line:
		j = int(j)
	if '1' in line:
		location = line.index('1') + 1
		columndist = abs(location - 3)
		rowdist = abs(i - 2)
j = columndist + rowdist
print(j)


from math import *
F1 = str(input())
F2 = str(input())
F3 = str(input())
F4 = str(input())
F5 = str(input())
L = [[F1[0], F1[2], F1[4], F1[6], F1[8]], [F2[0], F2[2], F2[4], F2[6], F2[8]], [F3[0], F3[2], F3[4], F3[6], F3[8]], [F4[0], F4[2], F4[4], F4[6], F4[8]], [F5[0], F5[2], F5[4], F5[6], F5[8]]]
for i in [0, 1, 2, 3, 4]:
	for j in [0, 1, 2, 3, 4]:
		if L[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))


number_of_moves = 0
for i in range(1, 6):
	row = list(map(int, input().split()))
	if sum(row) == 1:
		number_of_moves += abs(3 - i)
		number_of_moves += abs(3 - (row.index(1) + 1))
print(number_of_moves)


flag = False
for i in range(5):
	s = input().split()
	if flag == False:
		for j in range(5):
			if s[j] == '1':
				x = i + 1
				y = j + 1
				flag = True
				break
print(abs(x - 3) + abs(y - 3))


b = []
for _ in range(5):
	r = [int(x) for x in input().split()]
	b.append(r)
for i in range(5):
	for j in range(5):
		if b[i][j] == 1:
			(r, c) = (i, j)
print(abs(2 - r) + abs(2 - c))


tx = 0
ty = 0
for i in range(1, 6):
	str = input()
	t = map(int, str.split())
	k = 0
	for j in t:
		k += 1
		if j:
			tx = i
			ty = k
print(abs(3 - tx) + abs(3 - ty))


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
if a[0] == '1' or a[4] == '1' or e[0] == '1' or (e[4] == '1'):
	print(4)
elif a[1] == '1' or a[3] == '1' or b[0] == '1' or (b[4] == '1') or (d[0] == '1') or (d[4] == '1') or (e[1] == '1') or (e[3] == '1'):
	print(3)
elif a[2] == '1' or b[1] == '1' or b[3] == '1' or (c[0] == '1') or (c[4] == '1') or (d[1] == '1') or (d[3] == '1') or (e[2] == '1'):
	print(2)
elif c[2] == '1':
	print(0)
elif c[1] == '1' or c[3] == '1' or b[2] == '1' or (d[2] == '1'):
	print(1)


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
r5 = list(map(int, input().split()))
m = [r1, r2, r3, r4, r5]
count = 0
for i in range(5):
	if 1 in m[i]:
		x = i
		break
if m[2][2] == 1:
	print(count)
else:
	if m[x][2] == 1:
		for j in range(2):
			if x in range(0, 2):
				temp = m[x + 1]
				m[x + 1] = m[x]
				m[x] = temp
				x = x + 1
				count = count + 1
				if x == 2:
					break
				else:
					continue
			elif x in range(3, 5):
				temp = m[x - 1]
				m[x - 1] = m[x]
				m[x] = temp
				x = x - 1
				count = count + 1
				if x == 2:
					break
				else:
					continue
	else:
		for k in range(2):
			if x in range(0, 2):
				temp = m[x + 1]
				m[x + 1] = m[x]
				m[x] = temp
				x = x + 1
				count = count + 1
				if x == 2:
					break
				else:
					continue
			elif x in range(3, 5):
				temp = m[x - 1]
				m[x - 1] = m[x]
				m[x] = temp
				x = x - 1
				count = count + 1
				if x == 2:
					break
				else:
					continue
		y = m[2].index(1)
		for l in range(0, 2):
			if y in range(0, 2):
				tem = m[x][y + 1]
				m[x][y + 1] = m[x][y]
				m[x][y] = tem
				count = count + 1
				y = y + 1
				if y == 2:
					break
				else:
					continue
			elif y in range(3, 5):
				tem = m[x][y - 1]
				m[x][y - 1] = m[x][y]
				m[x][y] = tem
				count = count + 1
				y = y - 1
				if y == 2:
					break
				else:
					continue
	print(count)


import sys
input = sys.stdin.readline

def main():
	tizu = [list(map(int, input().split())) for _ in range(5)]
	for i in range(5):
		if 1 in tizu[i]:
			ind = tizu[i].index(1)
			print(abs(i - 2) + abs(ind - 2))
			return
main()


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
	for j in range(5):
		if matrix[i][j] == 1:
			row = i + 1
			column = j + 1
if row >= 3:
	x = row - 3
if row < 3:
	x = 3 - row
if column >= 3:
	y = column - 3
if column < 3:
	y = 3 - column
print(x + y)


n1 = input().split()
n2 = input().split()
n3 = input().split()
n4 = input().split()
n5 = input().split()
movesup = 0
movesleft = 0
if '1' in n1:
	movesup += 2
	a = n1.index('1')
	b = abs(2 - a)
	movesleft += b
elif '1' in n2:
	movesup += 1
	a = n2.index('1')
	b = abs(2 - a)
	movesleft += b
elif '1' in n3:
	a = n3.index('1')
	b = abs(2 - a)
	movesleft += b
elif '1' in n4:
	movesup += 1
	a = n4.index('1')
	b = abs(2 - a)
	movesleft += b
elif '1' in n5:
	movesup += 2
	a = n5.index('1')
	b = abs(2 - a)
	movesleft += b
moves = movesup + movesleft
print(moves)


full_matrix = []
for i in range(5):
	i = input()
	z = i.split(' ')
	full_matrix = full_matrix + z
test = full_matrix.index('1')
result = 0
if test == 12:
	print(result)
else:
	while test != 12:
		if 12 - test >= 5:
			test = test + 5
			result = result + 1
		elif 12 - test <= -5:
			test = test - 5
			result = result + 1
		elif abs(test - 12) != 4:
			result = result + abs(test - 12)
			test = 12
		else:
			result = result + 2
			test = 12
	print(result)


x = y = 0
for j in range(5):
	enter = [int(i) for i in input().split()]
	for (i, el) in enumerate(enter):
		if el == 1:
			x = i
			y = j
			break
print(abs(2 - x) + abs(2 - y))


for i in range(1, 6):
	a = input()
	if a.count('1') == 1:
		break
p = a.index('1') // 2 + 1
print(max(3, p) - min(p, 3) + max(3, i) - min(3, i))


import math
l1 = []
for i in range(5):
	x = input().split()
	l1.append(x)
for i in range(5):
	for j in range(5):
		if l1[i][j] is '1':
			print(abs(2 - i) + abs(2 - j))


a = []
for i in range(1, 6):
	a.append([int(x) for x in input('').split(' ')])
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == 1:
			if i >= 2 and j >= 2:
				print(i + j - 4)
			elif i >= 2 and j <= 2:
				print(i - j)
			elif i <= 2 and j >= 2:
				print(j - i)
			elif i <= 2 and j <= 2:
				print(-i - j + 4)


for r in range(5):
	m = list(map(int, input().split()))
	if 1 in m:
		row = r + 1
		col = m.index(1) + 1
print(abs(3 - col) + abs(3 - row))


count = 0
for j in range(5):
	z = input().split(' ')
	if '1' in z:
		i = z.index('1')
		if j >= 2 and i >= 2:
			count += j + i - 4
		elif j >= 2 and i < 2:
			count += j - i
		elif i >= 2 and j < 2:
			count += i - j
		else:
			count += 4 - j - i
	else:
		continue
print(count)


mat = []
for i in range(5):
	l = list(map(int, input().split()))
	mat.append(l)
satr = 0
sotun = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			satr = i + 1
			sotun = j + 1
print(abs(3 - satr) + abs(3 - sotun))


count = 0
for i in range(1, 6):
	s = input()
	q = s.split()
	count = count + 1
	if '1' in q:
		z = q.index('1') + 1
		break
for i in range(1, 6 - count):
	g = input()
print(abs(z - 3) + abs(count - 3))


def main():
	(x, y) = (0, 0)
	for i in range(5):
		iv = [int(v) for v in input().split()]
		for (j, v) in enumerate(iv):
			if v == 1:
				x = i
				y = j
	print(abs(x - 2) + abs(y - 2))
main()


x = []
tot = 0
for i in range(0, 5):
	y = input().split()
	z = [int(t) for t in y]
	if 1 in z:
		if i <= 2:
			tot += 2 - i
		else:
			tot += i - 2
		if z.index(1) <= 2:
			tot += 2 - z.index(1)
		else:
			tot += z.index(1) - 2
print(tot)


matrix = []
location = 0
for x in range(5):
	matrix.append(input().split())
rowIndex = 0
for row in matrix:
	try:
		row.index('1')
	except:
		continue
	else:
		columnIndex = row.index('1')
		break
	finally:
		rowIndex += 1
rowIndex -= 1
while rowIndex != 2:
	if rowIndex < 2:
		location += 1
		rowIndex += 1
	else:
		location += 1
		rowIndex -= 1
while columnIndex != 2:
	if columnIndex < 2:
		location += 1
		columnIndex += 1
	else:
		location += 1
		columnIndex -= 1
print(location)


for i in range(1, 6):
	s = input()
	if '1' in s:
		print(int(abs(i - 3) + abs(s.index('1') - 4) / 2))


matrix = []
target_row = target_col = None
for i in range(5):
	entry = list(map(int, input().split()))
	if 1 in entry:
		target_row = i
		target_col = entry.index(1)
		print(abs(target_row - 2) + abs(target_col - 2))
		break


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	if 1 in a[i]:
		c = a[i].index(1) + 1
		d = i + 1
		print(abs(c - 3) + abs(d - 3))
		break


def Post(x, A):
	i = 0
	while A[i] != x and i < len(A) - 1:
		i += 1
	return i

def ScovaErTesoro(A, B, C, D, E):
	if '1' in A:
		return (1, Post('1', A) + 1)
	elif '1' in B:
		return (2, Post('1', B) + 1)
	elif '1' in C:
		return (3, Post('1', C) + 1)
	elif '1' in D:
		return (4, Post('1', D) + 1)
	else:
		return (5, Post('1', E) + 1)
M1 = input()
M2 = input()
M3 = input()
M4 = input()
M5 = input()
M1 = M1.split()
M2 = M2.split()
M3 = M3.split()
M4 = M4.split()
M5 = M5.split()
(F, C) = ScovaErTesoro(M1, M2, M3, M4, M5)
print(max(3, F) - min(3, F) + max(3, C) - min(3, C))


row = ''
for i in range(5):
	row = input()
	if '1' in row:
		break
j = row.replace(' ', '').index('1')
print(abs(2 - i) + abs(2 - j))


def main():
	mat = [list(map(int, input().split())) for _ in range(5)]
	for i in range(5):
		for j in range(5):
			if mat[i][j] == 1:
				print(abs(i - 2) + abs(j - 2))
				break
main()


grid = [[int(x) for x in input().split()] for y in range(5)]
ind = (0, 0)
for r in range(len(grid)):
	for c in range(len(grid[r])):
		if grid[r][c] == 1:
			ind = (r, c)
print(abs(ind[0] - 2) + abs(ind[1] - 2))


import sys
grid = [[int(x) for x in i.split(' ')] for i in sys.stdin.read().split('\n')[:5]]
row = 0
for line in grid:
	if 1 in line:
		sys.stdout.write(str(abs(row - 2) + abs(line.index(1) - 2)))
		break
	row += 1


a = []
for i in range(1, 6):
	a.append(input())
b = []
for i in a:
	b.append(i.split())
x = 0
y = 0
for i in range(0, 5):
	for j in range(0, 5):
		if b[i][j] == '1':
			x = i + 1
			y = j + 1
			break
print(abs(x - 3) + abs(y - 3))


l = []
for _ in range(5):
	a = list(map(int, input().split()))
	l.append(a)
comp = [[4, 3, 2, 3, 4], [3, 2, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 2, 3], [4, 3, 2, 3, 4]]
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			print(comp[i][j])


moves = 0
n = []
for i in range(5):
	n.append(list(map(int, input().split())))
for i in range(1, 6):
	if 1 in n[i - 1]:
		moves += abs(3 - i)
		horizontal = n[i - 1].index(1) + 1
		moves += abs(3 - horizontal)
print(moves)


n = 5
a = []
b = []
count = 0
for i in range(n):
	b = input().split()
	b_len = len(b)
	for i in range(b_len):
		b[i] = int(b[i])
	a.append(b)
for i in range(n):
	for j in range(n):
		if a[i][j] == 1:
			if i == 0 or i == 4:
				count += 2
			elif i == 1 or i == 3:
				count += 1
			if j == 0 or j == 4:
				count += 2
			elif j == 1 or j == 3:
				count += 1
print(count)


import sys
import math
import bisect

def main():
	n = 5
	A = []
	for i in range(n):
		A.append(list(map(int, input().split())))
	ans = 0
	for i in range(n):
		for j in range(n):
			if A[i][j]:
				ans = abs(i - 2) + abs(j - 2)
	print(ans)
main()


n = []
for i in range(5):
	m = list(map(int, input().split(' ')))
	ans = sum(m)
	if ans == 1:
		j = i
		k = m.index(1)
	n.append(m)
n = abs(2 - j) + abs(2 - k)
print(n)


a = []
x = 0
y = 0
answer = 0
for i in range(5):
	u = [int(i) for i in input().split()]
	a.append(u)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i
			y = j
			o = abs(x - 2)
			p = abs(y - 2)
			z = o + p
print(z)


x = list()
flag = 0
count = 0
for i in range(5):
	x.append([int(j) for j in input().split()])
for i in range(5):
	if flag == 1:
		break
	for j in range(5):
		if x[i][j] == 1:
			pos_i = i
			pos_j = j
			flag = 1
			break
while pos_i != 2 or pos_j != 2:
	if pos_i == 2 or pos_j != 2:
		while pos_j != 2:
			if pos_j < 2:
				pos_j = pos_j + 1
				count = count + 1
			else:
				pos_j = pos_j - 1
				count = count + 1
	elif pos_j == 2 or pos_i != 2:
		while pos_i != 2:
			if pos_i < 2:
				pos_i = pos_i + 1
				count = count + 1
			else:
				pos_i = pos_i - 1
				count = count + 1
print(count)


matrix = []
moves = 0
for x in range(5):
	matrix.append(input().replace(' ', ''))

def findOne():
	count_2 = 0
	for char in matrix:
		for y in char:
			if '1' in y:
				return count_2 + 1
			else:
				count_2 += 1

def solve(pos):
	global moves
	if getDist(pos) >= 4:
		moves += 1
		solve(pos + 5)
	elif getDist(pos) <= -4:
		moves += 1
		solve(pos - 5)
	elif getDist(pos) == 0:
		print(f'{moves}')
	elif getDist(pos) < 0:
		moves += 1
		solve(pos - 1)
	elif getDist(pos) > 0:
		moves += 1
		solve(pos + 1)

def getDist(pos):
	return int(13 - pos)
solve(findOne())


s = [2, 1, 0, 1, 2]
for i in range(5):
	r = [int(x) for x in input().split()]
	for j in range(5):
		if r[j] == 1:
			print(s[i] + s[j])
			break


i = 0
while i < 5:
	i = i + 1
	a = list(map(int, input().split()))
	if 1 in a:
		if a.index(1) >= 0:
			index1 = a.index(1)
			movementHorizontal = abs(2 - index1)
			movementVertical = abs(3 - i)
			print(movementHorizontal + movementVertical)


a = []
for i in range(5):
	b = list(map(int, input().split(' ')))
	a.append(b)
b = 0
b1 = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			b = i
			b1 = j
			break
print(abs(b - 2) + abs(b1 - 2))


count = -1
row = 0
col = 0
for i in range(5):
	a = input().split()
	count += 1
	if '1' in a:
		row = a.index('1')
		col = count
print(abs(2 - row) + abs(2 - col))


x1 = input().split()
x2 = input().split()
x3 = input().split()
x4 = input().split()
x5 = input().split()
x = x1 + x2 + x3 + x4 + x5
foo = 0
steps = 0
while abs(12 - x.index('1')) >= 4 and x[12] != 1:
	if x.index('1') > 12:
		foo = x.index('1')
		(x[foo], x[foo - 5]) = (x[foo - 5], x[foo])
		steps += 1
	else:
		foo = x.index('1')
		(x[foo], x[foo + 5]) = (x[foo + 5], x[foo])
		steps += 1
steps += abs(12 - x.index('1'))
print(steps)


li = []
for i in range(5):
	sub_li = list(map(int, input().split()))
	if 1 in sub_li:
		r = i
	li.append(sub_li)
c = li[r].index(1)
print(abs(c - 2) + abs(r - 2))


r = c = 5
for i in range(r):
	a = list(map(int, input().split()))
	if 1 in a:
		ci = a.index(1)
		ri = i
		break
ans = abs(ci - 2) + abs(ri - 2)
print(ans)


l1 = []
for i in range(5):
	l = list(map(int, input().split()))
	l1.append(l)
if l1[2][2] == 1:
	print(0)
else:
	for i in range(len(l1)):
		for j in range(len(l1)):
			if l1[i][j] == 1:
				x = i
				y = j
	print(abs(x - 2) + abs(y - 2))


ct = 5
pp = []
for i in range(ct):
	qq = [int(x) for x in input().split()]
	pp.append(qq)
posx = 0
posy = 0
for i in range(5):
	for j in range(5):
		if pp[i][j] == 1:
			posx = i
			posy = j
val = abs(2 - posx) + abs(2 - posy)
print(val)


import math as mt
import sys
from collections import *
inf = float('inf')

def ii():
	return int(input())

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

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

def gmat(n, m):
	return [[0] * m for _ in range(n)]

def imat(n):
	return [list(mii()) for _ in range(n)]
try:
	sys.stdin = open('data\\a.in', 'r')
	input = sys.stdin.readline
except:
	pass
mat = imat(5)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))


def ii():
	return int(input())

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

def li():
	return list(mi())
a = []
for i in range(5):
	a.append(li())
c = 0
d = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			c = i
			d = j
res = abs(2 - c) + abs(2 - d)
print(res)


p = 0
for n in range(5):
	ss = input()
	s = ss.replace(' ', '')
	x = s.find('1')
	if x == -1:
		p = p
	elif x != -1:
		if n == 0 or n == 4:
			y = 2 - x
			if y < 0:
				y = -y
				p = 2 + y
			elif y >= 0:
				p = 2 + y
		elif n == 1 or n == 3:
			y = 2 - x
			if y < 0:
				y = -y
				p = 1 + y
			elif y >= 0:
				p = 1 + y
		elif n == 2:
			y = 2 - x
			if y < 0:
				y = -y
				p = 0 + y
			elif y >= 0:
				p = 0 + y
print(p)


list1 = [1, 1, 1, 1, 1]
n = 0
m = 0
for i in range(5):
	list1[i] = input().split()
for i in range(5):
	for j in range(5):
		if list1[i][j] == '1':
			n = i
			m = j
w = abs(n - 2) + abs(m - 2)
print(w)


set6 = []
for i in range(5):
	set6.append(input().split(' '))
for i in set6:
	if '1' in i:
		y = set6.index(i) + 1
		x = i.index('1') + 1
		break
deltay = 3 - y if 3 - y > 0 else y - 3
deltax = 3 - x if 3 - x > 0 else x - 3
answer = deltax + deltay
print(answer)


matrix = []
x = 0
y = 0
for i in range(5):
	line = [int(num) for num in input().split()]
	matrix.append(line)
	if 1 in line:
		(x, y) = (i, line.index(1))
beautiful_x = abs(2 - x)
beautiful_y = abs(2 - y)
print(beautiful_x + beautiful_y)


a = []
for i in range(0, 5):
	n = list(map(int, input().split()))
	a.append(n)
	c = 0
	for x in a:
		c += 1
		if any(n) == 1:
			o = n.index(1)
			if c == 1 or c == 5:
				if o == 0 or o == 4:
					y = 4
				elif o == 1 or o == 3:
					y = 3
				elif o == 2:
					y = 2
			elif c == 2 or c == 4:
				if o == 0 or o == 4:
					y = 3
				elif o == 1 or o == 3:
					y = 2
				elif o == 2:
					y = 1
			elif c == 3:
				if o == 0 or o == 4:
					y = 2
				elif o == 1 or o == 3:
					y = 1
				elif o == 2:
					y = 0
print(y)


(x, y) = (0, 0)
for i in range(1, 6):
	row = list(map(int, input().split()))
	if row.count(1) == 1:
		y = row.index(1) + 1
		x = i
print(abs(x - 3) + abs(y - 3))


(x, y) = (0, 0)
for i in range(5):
	line = map(int, input().split())
	for (j, value) in enumerate(line):
		if value == 1:
			x = j
			y = i
print(abs(2 - x) + abs(2 - y))


(x, y) = (0, 0)
for i in range(1, 6):
	r = [int(x) for x in input().split()]
	for j in range(1, 6):
		if r[j - 1]:
			(x, y) = (i, j)
print(abs(3 - x) + abs(3 - y))


l = []
for _ in range(5):
	x = []
	x = list(map(int, input().split()))
	l.append(x)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			r = i + 1
			c = j + 1
			break
print(abs(r - 3) + abs(3 - c))


r = 1
c = 1
for i in range(0, 5):
	a = input().split()
	if '1' in a:
		r = i
		c = a.index('1')
		break
print(abs(r - 2) + abs(c - 2))


a = []
for i in range(5):
	l = list(map(int, input().split()))
	a.append(l)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))
		else:
			pass


(i_one, j_one) = (0, 0)
arr = [0] * 5
for i in range(5):
	arr[i] = input().split()
for i in range(5):
	for j in range(5):
		if arr[i][j] == '1':
			i_one = i
			j_one = j
print(abs(i_one - 2) + abs(j_one - 2))


table = []
(x, y) = (0, 0)
for i in range(1, 6):
	line = str(input()).split()
	if '1' in line:
		y = i
		x = int(line.index('1')) + 1
moves = abs(3 - x) + abs(3 - y)
print(moves)


(i, j) = (0, 0)
for i in range(5):
	found = False
	a = input().split(' ')
	for j in range(5):
		if int(a[j]) == 1:
			found = True
			break
		else:
			j += 1
	if found:
		break
	else:
		i += 1
print(abs(2 - i) + abs(2 - j))


arr = []
for i in range(5):
	n = input().split(' ')
	arr.append(n)
l = len(arr)
get_i = 0
get_j = 0
for i in range(0, l):
	if '1' in arr[i]:
		get_i = i
		break
for i in range(0, l):
	if arr[get_i][i] == '1':
		get_j = i
		break
get_i += 1
get_j += 1
print(abs(3 - get_i) + abs(3 - get_j))


mat = [[], [], [], [], []]
row = 0
col = 0
for i in range(5):
	str = input()
	mat[i].append(str[0:1])
	mat[i].append(str[2:3])
	mat[i].append(str[4:5])
	mat[i].append(str[6:7])
	mat[i].append(str[8:9])
for i in range(5):
	for j in range(5):
		if mat[i][j] == '1':
			row = i + 1
			col = j + 1
m = abs(row - 3) + abs(col - 3)
print(m)


a = (input(), input(), input(), input(), input())
count = -1
for i in a:
	i = i.replace(' ', '')
	count += 1
	if '1' in i:
		m = i.index('1')
		break
print(abs(2 - m) + abs(2 - count))


a = [[0]] * 5
row = 0
colon = 0
for i in range(5):
	a[i] = list(map(int, input().split()))
tik_mini = 0
for i in range(5):
	for j in a[i]:
		if j == 1:
			row = i
			colon = tik_mini
		tik_mini += 1
	tik_mini = 0
tik = 0
while row != 2:
	if row > 2:
		row -= 1
		tik += 1
	else:
		row += 1
		tik += 1
while colon != 2:
	if colon > 2:
		colon -= 1
		tik += 1
	else:
		colon += 1
		tik += 1
print(tik)


Index_count = 0
for i in range(5):
	K = list(map(int, input().split()))
	if 1 in K:
		print(abs(K.index(1) - 2) + abs(Index_count - 2))
	Index_count += 1


m = []
for i in range(5):
	l = list(map(int, input().split()))
	m.append(l)
row = 0
for i in range(5):
	if 1 in m[i]:
		row = i
		break
col = m[row].index(1)
print(abs(2 - col) + abs(2 - row))


for i in range(5):
	(a1, a2, a3, a4, a5) = map(int, input().split())
	b = [a1, a2, a3, a4, a5]
	if 1 in b:
		c = b.index(1)
		d = abs(2 - i) + abs(2 - c)
		print(d)


for i in range(5):
	line = input()
	lst = list(map(int, line.split()))
	for elem in range(5):
		if lst[elem] == 1:
			loc = (i, elem)
print(abs(loc[0] - 2) + abs(loc[1] - 2))


A = []
for i in range(5):
	A.append(input().split())
z = 0
b = 0
a = 0
for j in A:
	z = z + 1
	if j.count('1') == 1:
		b = j.index('1') + 1
		a = z
		break
print(abs(3 - a) + abs(3 - b))


def make_board_beautiful(board, x, y):
	(x_c, y_c, count) = (2, 2, 0)
	count = count + abs(x_c - x) + abs(y_c - y)
	return count
board = []
(x, y) = (0, 0)
for i in range(5):
	board.append(list(map(lambda x: int(x), input().split(' '))))
	if 1 in board[i]:
		(x, y) = (i, board[i].index(1))
print('{}'.format(make_board_beautiful(board, x, y)))


for FirstCounter in range(5):
	s = input()
	for SecondCounter in range(0, 9, 2):
		if s[SecondCounter] == '1':
			XCoordinate = FirstCounter
			YCoordinate = SecondCounter // 2
print(abs(XCoordinate - 2) + abs(YCoordinate - 2))


n_1 = list(map(int, input().split()))
n_2 = list(map(int, input().split()))
n_3 = list(map(int, input().split()))
n_4 = list(map(int, input().split()))
n_5 = list(map(int, input().split()))
matrix = [n_1, n_2, n_3, n_4, n_5]
for i in range(5):
	if sum(matrix[i]) == 1:
		count = abs(3 - (i + 1))
		m_needed = matrix[i]
for j in range(len(m_needed)):
	if m_needed[j] == 1:
		ind_needed = j + 1
count = count + abs(3 - ind_needed)
print(count)


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
l5 = list(map(int, input().split()))
for i in range(0, 5):
	if l1[i] == 1:
		if i == 2:
			print(2)
		else:
			print(abs(2 - i) + 2)
for i in range(0, 5):
	if l2[i] == 1:
		if i == 2:
			print(1)
		else:
			print(abs(2 - i) + 1)
for i in range(0, 5):
	if l3[i] == 1:
		if i == 2:
			print(0)
		else:
			print(abs(2 - i))
for i in range(0, 5):
	if l4[i] == 1:
		if i == 2:
			print(1)
		else:
			print(abs(2 - i) + 1)
for i in range(0, 5):
	if l5[i] == 1:
		if i == 2:
			print(2)
		else:
			print(abs(2 - i) + 2)


m = [list(input().split()) for i in range(5)]
for i in range(5):
	for j in range(5):
		if m[i][j] == '1':
			(x, y) = (i, j)
			break
print(abs(x - 2) + abs(y - 2))


array = []
for i in range(0, 5):
	array.append(input())

def rm(arr):
	arr2 = []
	for i in arr:
		for words in i:
			if words == ' ':
				pass
			else:
				arr2.append(int(words))
	return arr2

def get_matrix(arr):
	for i in (0, len(arr), 4):
		print(i)
array = rm(array)

def get_matrix(array):
	matrix = []
	init = 0
	last = 0
	for i in range(5, len(array) + 1, 5):
		matrix.append(array[init:i])
		init += 5
	return matrix
array = get_matrix(array)

def get_value_index(array):
	for row in range(0, len(array)):
		for col in range(0, len(array)):
			if array[row][col] == 0:
				pass
			elif array[row][col] == 1:
				return [row, col]

def magic(array, xy):
	x = xy[0]
	y = xy[1]
	x_magic = abs(2 - x)
	y_magic = abs(2 - y)
	print(x_magic + y_magic)
position = get_value_index(array)
magic(array, position)


t = 0
r = 0
k = 0
c = 0
i = 0
j = 0
for i in range(0, 5):
	n = input()
	j = list(map(int, n.split(' ')))
	for a in range(0, 5):
		c = a + 1
		if j[a] > 0:
			t = 1
			break
	r = i + 1
	if t == 1:
		break
print(abs(3 - r) + abs(3 - c))


mat = []
row = col = 0
for i in range(5):
	mat.append(list(map(int, input().split())))
	if sum(mat[i]) == 1:
		row = i
for (i, n) in enumerate(mat[row]):
	if n == 1:
		col = i
ans = max(row, 2) - min(row, 2) + max(col, 2) - min(col, 2)
print(ans)


def minmovematrix(matrix):
	if matrix[2][2] == 1:
		return 0
	(i, j) = findrowcol(matrix)
	count = 0
	while i < 2 or i > 2:
		if i < 2:
			count += 1
			i += 1
		elif i > 2:
			count += 1
			i -= 1
	while j < 2 or j > 2:
		if j < 2:
			count += 1
			j += 1
		elif j > 2:
			count += 1
			j -= 1
	return count

def findrowcol(matrix):
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				return (i, j)
arr = []
for i in range(5):
	temp = list(map(int, input().split()))
	arr.append(temp)
print(minmovematrix(arr))


r = 1
while r <= 5:
	n = input()
	c = n.find('1')
	if c != -1:
		print(int(abs(r - 3) + 0.5 * abs(c - 4)))
		r = 6
	else:
		r = r + 1


l = []
for x in range(0, 5):
	z = input().split()
	l.append(z)
for i in range(0, 5):
	for j in range(0, 5):
		if l[i][j] == '1':
			k = i + 1
			m = j + 1
			break
if k == 3:
	k = 0
else:
	k = abs(k - 3)
if m == 3:
	m = 0
else:
	m = abs(m - 3)
print(k + m)


import sys
import math
import operator as op
from functools import reduce

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
mat = []
for i in range(5):
	r = read_int_line()
	mat.append(r)
x = -1
y = -1
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			x = i
			y = j
			break
ans = abs(2 - x) + abs(2 - y)
print(ans)


for a in range(0, 5):
	fila = input()
	fila2 = fila.split(' ')
	if '1' in fila2:
		col = fila2.index('1')
		fil = a
mov = abs(col - 2) + abs(fil - 2)
print(mov)


li = []
count = 0
for i in range(5):
	a = input().split()
	li.append(a)
for i in li:
	count = count + 1
	if '1' in i:
		z = i.index('1')
		count = li.index(i)
		if z == 0 or z == 4:
			z = 2
		elif z == 1 or z == 3:
			z = 1
		else:
			z = 0
		if count == 0 or count == 4:
			count = 2
		elif count == 1 or count == 3:
			count = 1
		else:
			count = 0
		print(count + z)
		break


arr = []
for i in range(5):
	a = list(map(int, input().split()))[:5]
	arr.append(a)
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			curx = i + 1
			cury = j + 1
path = abs(curx - 3) + abs(cury - 3)
print(path)


import math
l = []
l1 = []
for i in range(5):
	a = input().split()
	l.extend(a)
	l1.append(a)
l = ''.join(l)
n = l.find('1')
row = n // 5
coloumn = n % 5
counter = abs(coloumn - 2) + abs(row - 2)
print(counter)


a = [[int(j) for j in input().split()] for i in range(5)]
for i in range(5):
	if a[i].count(1) == 0:
		continue
	else:
		(x, y) = (i, a[i].index(1))
counter = 0
counter += abs(2 - x)
counter += abs(2 - y)
print(counter)


a = []
for _ in range(5):
	a.append(list(map(str, input().split())))
for r in a:
	if '1' in r:
		print(abs(2 - a.index(r)) + abs(2 - r.index('1')))
		break


for i in range(1, 6):
	t = input()
	k = t.split()
	j = 1
	for p in k:
		if int(p) == 1:
			col = j
			row = i
			mov = abs(row - 3) + abs(col - 3)
		j += 1
print(mov)


row0 = input().split()
row1 = input().split()
row2 = input().split()
row3 = input().split()
row4 = input().split()
result = ''
if '1' in row0:
	result = abs(2 - row0.index('1')) + 2
elif '1' in row1:
	result = abs(2 - row1.index('1')) + 1
elif '1' in row2:
	result = abs(2 - row2.index('1'))
elif '1' in row3:
	result = abs(2 - row3.index('1')) + 1
elif '1' in row4:
	result = abs(2 - row4.index('1')) + 2
print(result)


a = []
for j in range(5):
	a.append([int(i) for i in input().split()])
k = [(i, a.index(1)) for (i, a) in enumerate(a) if 1 in a]
(i, j) = k[0]
count = abs(2 - i) + abs(2 - j)
print(count)


M = []
solution = 0
for _ in range(5):
	M.append([int(a) for a in input().split()])
x = None
y = None
for i in range(5):
	for h in range(5):
		if M[i][h] == 1:
			x = i
			y = h
			break
	if x != None:
		break
dx = abs(x - 2)
dy = abs(y - 2)
print(dx + dy)


mas = []
for i in range(5):
	mas.append(input().split(' '))
(row, col) = (0, 0)
for i in range(5):
	for j in range(5):
		if mas[i][j] == '1':
			(row, col) = (i, j)
ddd = abs(2 - row) + abs(2 - col)
print(ddd)


m = []
x = 5
for i in range(x):
	a = []
	c = input().split(' ')
	for d in range(5):
		a.append(int(c[d]))
	m.append(a)
flag = -1
for y in range(x):
	for z in range(x):
		if m[y][z] == 1:
			if y == 2 and z == 2:
				flag = 0
			else:
				flag = abs(y - 2) + abs(z - 2)
print(flag)


matrx = []
row = 0
col = 0
for i in range(0, 5):
	matrx.append(list(map(int, input().split(' '))))
	if 1 in matrx[i]:
		col = matrx[i].index(1)
		row = i
ans = abs(2 - row) + abs(2 - col)
print(ans)


(x, y) = (0, 0)
for i in range(5):
	array = input().split()
	for j in range(len(array)):
		if int(array[j]) == 1:
			x = i + 1
			y = j + 1
answer = abs(x - 3) + abs(y - 3)
print(answer)


for x in range(1, 6):
	s = list(map(int, input().split()))
	if 1 in s:
		index = s.index(1) + 1
		moves = abs(3 - x) + abs(3 - index)
	else:
		continue
print(moves)


n = 5
a = []
k = 0
for i in range(0, n):
	b = [int(i) for i in input().split()]
	if b.count(1) == 1:
		k = i
	a.append(b)
for j in range(0, n):
	if a[k][j] == 1:
		break
value = abs(k - 2) + abs(j - 2)
print(value)


for i in range(5):
	row = [int(x) for x in input().split()]
	for j in range(5):
		if row[j] == 1:
			(x, y) = [i + 1, j + 1]
		else:
			pass
print(abs(x - 3) + abs(y - 3))


list_of_str = []
for srting in range(5):
	list_of_str.append([x for x in input().split()])
count = 0
for string in list_of_str:
	try:
		index = string.index('1')
	except:
		continue
	if index < 2:
		count += 2 - index
	elif index > 2:
		count += index - 2
	index_of_string = list_of_str.index(string)
	if index_of_string < 2:
		count += 2 - index_of_string
	elif index_of_string > 2:
		count += index_of_string - 2
print(count)


arr = []
for i in range(5):
	arr.append(list(map(int, input().split())))
p = 0
k = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			p = i + 1
			k = j + 1
if p >= 3:
	l = p - 3
else:
	l = 3 - p
if k >= 3:
	s = k - 3
else:
	s = 3 - k
print(l + s)


def tusk():
	for i in range(5):
		s = input().split()
		for (j, S) in enumerate(s):
			if S == '1':
				return abs(2 - i) + abs(2 - j)
print(tusk())


row = 0
col = 0
for i in range(5):
	s = input().split(' ')
	if '1' in s:
		col = s.index('1')
		row = i
x = abs(2 - row) + abs(2 - col)
print(x)


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i
			y = j
i = 0
count1 = 0
while x != 2:
	if x < 2:
		x = x + 1
		count1 = count1 + 1
	else:
		x = x - 1
		count1 = count1 + 1
j = 0
count2 = 0
while y != 2:
	if y < 2:
		y = y + 1
		count2 = count2 + 1
	else:
		y = y - 1
		count2 = count2 + 1
print(count1 + count2, end='')


m = []
for x in range(5):
	m.append(list(map(int, input().split(' '))))
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			c = i
			d = j
			k = abs(c - 2) + abs(d - 2)
print(k)


l1 = list(map(int, input().split(' ')))
l2 = list(map(int, input().split(' ')))
l3 = list(map(int, input().split(' ')))
l4 = list(map(int, input().split(' ')))
l5 = list(map(int, input().split(' ')))
moves = 0
while 1 in l1 or 1 in l2 or 1 in l4 or (1 in l5):
	if 1 in l1:
		(l2, l1) = (l1, l2)
	elif 1 in l2:
		(l3, l2) = (l2, l3)
	elif 1 in l4:
		(l4, l3) = (l3, l4)
	else:
		(l5, l4) = (l4, l5)
	moves += 1
index = l3.index(1)
if index < 2:
	moves += 2 - index
elif index > 2:
	moves += index - 2
print(moves)


a = [[int(j) for j in input().split()] for i in range(5)]
ans = 0
fl = 1
for i in range(5):
	for y in range(5):
		if a[i][y] == 1:
			print(abs(2 - y) + abs(2 - i))
			fl = 0
			break
	if fl == 0:
		break


for i in range(5):
	line = input().split()
	if sum((int(x) for x in line)) == 1:
		print(abs(i - 2) + abs(line.index('1') - 2))


a = []
b = []
sum = 0
for i in range(1, 6):
	s = list(map(int, input().split(maxsplit=4)))
	if 1 in s:
		b.append([abs(i - 3), abs(s.index(1) + 1 - 3)])
	a.append(s)
for j in range(1):
	sum = b[0][0] + b[0][1]
print(sum)


for i in range(5):
	a = list(map(int, input().rstrip().split()))
	if a.count(1) > 0:
		x = a.index(1) + 1
		y = i + 1
		break
z = abs(3 - x) + abs(3 - y)
print(z)


s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s3 = list(map(int, input().split()))
s4 = list(map(int, input().split()))
s5 = list(map(int, input().split()))
S = [s1, s2, s3, s4, s5]
for i in range(len(S)):
	for j in range(len(S[i])):
		if S[i][j] == 1:
			k = i
			m = j
print(abs(2 - k) + abs(2 - m))


mat = [[int(p) for p in input().split()] for p in range(5)]
for i in range(5):
	for j in range(5):
		if mat[i][j] != 0:
			(r, c) = (i, j)
print(abs(2 - r) + abs(2 - c))


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

def findOne(lst):
	for i in range(len(lst)):
		if lst[i] == 1:
			return i
		elif i == len(lst) - 1:
			return -99
		else:
			continue

def getMat():
	for i in range(5):
		result = findOne(getData())
		if result != -99:
			return (i, result)
		else:
			continue

def beautiful(tuple):
	(row, col) = tuple
	row = abs(row - 2)
	col = abs(col - 2)
	print(col + row)
beautiful(getMat())


h = []
for i in range(5):
	h.append(list(map(int, input().split())))
test = False
for i in range(5):
	for j in range(5):
		if h[i][j] != 0:
			test = True
			break
	if test:
		break
print(abs(i - 2) + abs(j - 2))


for i in range(5):
	val = input().split()
	for j in range(5):
		if val[j] == '1':
			new = [i + 1, j + 1]
print(abs(3 - new[0]) + abs(3 - new[1]))


def get_position(z, M):
	(x, y) = (0, 1)
	for i in M:
		if z in i:
			x = i.index(z) + 1
			return (x, y)
		else:
			y += 1
L = []
for i in range(5):
	L.append([int(x) for x in input().split()])
(x, y) = get_position(1, L)
print(abs(x - 3) + abs(y - 3))


for i in range(1, 6):
	s = input()
	if '1' in s:
		k1 = i
		k2 = s.replace(' ', '').index('1') + 1
print(abs(3 - k1) + abs(3 - k2))


first_line = input().split()
second_line = input().split()
third_line = input().split()
fourth_line = input().split()
fifth_line = input().split()
matrix = [first_line, second_line, third_line, fourth_line, fifth_line]
max_moves = 0
for i in range(0, 5):
	if '1' in matrix[i]:
		found = matrix[i].index('1')
		while found != 2:
			if found > 2:
				found -= 1
				max_moves += 1
			else:
				found += 1
				max_moves += 1
		while i != 2:
			if i > 2:
				i -= 1
				max_moves += 1
			else:
				i += 1
				max_moves += 1
print(max_moves)


ans = 0
for i in range(5):
	n = list(map(int, input().split()))
	for j in range(5):
		if n[j] == 1:
			if i > 2:
				ans = i - 2
			else:
				ans = 2 - i
			if j > 2:
				ans = ans + j - 2
			else:
				ans = ans + 2 - j
print(ans)


list1 = []
list1.append(input().split(' '))
list1.append(input().split(' '))
list1.append(input().split(' '))
list1.append(input().split(' '))
list1.append(input().split(' '))
for i in range(5):
	for j in range(5):
		if list1[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))
			exit(0)


a = []
for i in range(5):
	a.append([int(x) for x in input().split()])
for r in range(5):
	for c in range(5):
		if a[r][c] == 1:
			print(abs(r - 2) + abs(c - 2))
			break


num = int(5)
j = 0
for x in range(1, 6):
	str = input().split(' ')
	if str[0] == '1':
		j = 1
		break
	elif str[1] == '1':
		j = 2
		break
	elif str[2] == '1':
		j = 3
		break
	elif str[3] == '1':
		j = 4
		break
	elif str[4] == '1':
		j = 5
		break
print(abs(3 - x) + abs(3 - j))


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
if sum(a) != 0:
	(x, y) = (1, a.index(1) + 1)
elif sum(b) != 0:
	(x, y) = (2, b.index(1) + 1)
elif sum(c) != 0:
	(x, y) = (3, c.index(1) + 1)
elif sum(d) != 0:
	(x, y) = (4, d.index(1) + 1)
else:
	(x, y) = (5, e.index(1) + 1)
(r, c) = (3, 3)
print(abs(x - r) + abs(c - y))


i = 0
j = 0
for f in range(1, 6):
	try:
		j = list(map(int, input().split())).index(1) + 1
		i = f
	except ValueError:
		pass
print(0 if i == 3 and j == 3 else abs(3 - i) + abs(3 - j))


(mid_i, mid_j) = (2, 2)
j = 0
for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		print(abs(mid_i - l.index(1)) + abs(mid_j - j))
	j += 1


l1 = input()
l2 = input()
l3 = input()
l4 = input()
l5 = input()
L = [l1, l2, l3, l4, l5]
destino = [3, 3]
condicion = []
for linea in L:
	i = 1
	for numero in linea.replace(' ', ''):
		if numero == '1':
			condicion = [i, L.index(linea) + 1]
			break
		else:
			i += 1
pasos = 0
for posicion in condicion:
	pasos = pasos + abs(posicion - 3)
print(pasos)


n = 0
while n < 5:
	line = input()
	lists = line.split()
	if '1' in lists:
		i = n
		j = lists.index('1')
	n += 1
print(abs(i - 2) + abs(j - 2))


j = []
for i in range(5):
	inp = input().split()
	if '1' in inp:
		x = i
	j.append(inp)
for (count, ele) in enumerate(j[x]):
	if ele == '1':
		y = count
		break
if x > 2:
	x = 4 - x
if y > 2:
	y = 4 - y
print(4 - (x + y))


n = 5
matr = [input().split() for _ in range(0, n)]
row_number = 1
col_number = 1
for row in matr:
	if '1' in row:
		col_number = row.index('1') + 1
		break
	row_number += 1
print(abs(row_number - 3) + abs(col_number - 3))


c = 0
for i in range(0, 5):
	lst = list(map(int, input().strip().split()))[:5]
	for j in range(0, 5):
		if lst[j] == 1:
			c = abs(i - 2) + abs(j - 2)
			break
print(c)


mat = []
r = 0
c = 0
for i in range(5):
	k = [int(x) for x in input().split()]
	mat.append(k)
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			r = abs(2 - i)
			c = abs(2 - j)
			break
print(r + c)


i = 0
s = ''
for o in range(5):
	s = input()
	if '1' in s:
		i = o
		break
s = list(s)
ans = abs(2 - i) + abs(2 - s.index('1') // 2)
print(ans)


from math import *
n = 0
big_list = []
(input0, input1, input2, input3, input4) = (input(), input(), input(), input(), input())
input0 = input0.split(' ')
big_list.append(input0)
input1 = input1.split(' ')
big_list.append(input1)
input2 = input2.split(' ')
big_list.append(input2)
input3 = input3.split(' ')
big_list.append(input3)
input4 = input4.split(' ')
big_list.append(input4)
for i in big_list:
	a = big_list.index(i)
	if '1' not in input2 and '1' in i:
		n += abs(2 - a)
	for g in big_list[a]:
		if g == '1':
			n += abs(2 - big_list[a].index(g))
print(n)


m = [[int(j) for j in input().split()] for i in range(5)]
ii = 0
jj = 0
for i in range(len(m)):
	for j in range(len(m[0])):
		if m[i][j] == 1:
			ii = i
			jj = j
			break
res_i = abs(2 - ii)
res_j = abs(2 - jj)
print(res_i + res_j)


A = [list(input().replace(' ', '')) for j in range(5)]
(a, b) = (0, 0)
for i in range(5):
	try:
		a = i
		b = A[i].index('1')
		break
	except:
		pass
print(abs(a - 2) + abs(b - 2))


l = []
for i in range(5):
	l.append(list(map(int, input().split())))
for i in range(5):
	if l[i].count(1) == 1:
		ind = l[i].index(1)
		tup = (i + 1, ind + 1)
d = 0
for i in range(len(tup)):
	d += abs(tup[i] - 3)
print(d)


lst = []
for i in range(1, 6):
	for j in range(1):
		z = list(map(int, input().split()))
		if sum(z) == 1:
			x = i
			lst = z
for i in range(1):
	for j in range(len(lst)):
		if lst[j] == 1:
			y = j
a = 3 - x
if a < 0:
	a = -1 * a
b = 3 - (y + 1)
if b < 0:
	b = -1 * b
print(a + b)


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

def multiple_input():
	return map(int, input().split())
for i in range(5):
	a = list_input()
	if sum(a) == 1:
		row = i
		for j in range(5):
			if a[j] == 1:
				col = j
				break
(r, c) = (2, 2)
print(abs(row - r) + abs(col - c))


l = []
(x, y) = (0, 0)
for i in range(5):
	l = input().split()
	for j in range(5):
		if l[j] == '1':
			(x, y) = (i, j)
result = abs(x - 2) + abs(y - 2)
print(result)


matrix = []
x1 = 0
y1 = 0
for i in range(5):
	temp = list(input().split())
	matrix.append(temp)
	if '1' in temp:
		x1 = i + 1
		y1 = temp.index('1') + 1
moves = abs(3 - x1) + abs(3 - y1)
print(moves)


line = []
steps = 0
for i in range(5):
	line.append(input().split())
	if '1' in line[i]:
		steps = abs(2 - i) + abs(2 - line[i].index('1'))
		break
print(steps)


(a, b) = (0, 0)
for i in range(1, 6):
	s = input()
	if '1' in s:
		a = i
		b = s.split().index('1') + 1
		break
print(abs(3 - a) + abs(3 - b))


for i in range(5):
	l = list(map(int, input().split()))
	if sum(l) > 0:
		for j in range(5):
			if l[j] == 1:
				dist = abs(2 - i) + abs(2 - j)
				break
print(dist)


l = []
for i in range(0, 5):
	p = input().rstrip().split(' ')
	if '1' in p:
		a = i + 1
		b = p.index('1') + 1
print(abs(3 - a) + abs(3 - b))


a = [[int(i) for i in input().split()] for i in range(5)]
(m, n) = (0, 0)
c = 0
M = 2
N = 2
for i in range(5):
	if 1 in a[i]:
		m = a[i].index(1)
		n = i
while n != N or m != M:
	while n < N:
		n += 1
		c += 1
	while n > N:
		n -= 1
		c += 1
	while m < M:
		m += 1
		c += 1
	while m > M:
		m -= 1
		c += 1
print(c)


def main():
	mat = []
	for _ in range(5):
		mat.append([int(num) for num in input().split()])
	(x, y) = (0, 0)
	for i in range(5):
		for j in range(5):
			if mat[i][j] == 1:
				(x, y) = (i, j)
				break
	print(abs(x - 2) + abs(y - 2))
main()


for i in range(1, 6):
	arr = list(map(int, input().strip().split(' ')))
	for j in range(1, 6):
		if arr[j - 1] == 1:
			print(abs(3 - i) + abs(3 - j))
			break


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

def myIndex(l):
	for i in l:
		if 1 in i:
			return (i.index(1), l.index(i))
(x, y) = myIndex(l)
print(abs(2 - x) + abs(2 - y))


push = lambda : map(int, input().split())
posi = 0
posj = 0
for i in range(0, 5):
	a = list(push())
	for j in range(0, 5):
		if a[j] == 1:
			posi = i
			posj = j
print(abs(2 - posi) + abs(2 - posj))


n = 5
r = 0
c = 0
for i in range(n):
	row = list(map(int, input().split()))
	for k in range(n):
		if row[k] == 1:
			r = i
			c = k
print(abs(2 - r) + abs(2 - c))


list = []
for i in range(5):
	(a, b, c, d, e) = map(int, input().split(' '))
	list.append([a, b, c, d, e])
for m in range(5):
	for n in range(5):
		if list[m][n] != 0:
			print(abs(m - 2) + abs(n - 2))


mas = []
answer = 0
for i in range(5):
	mas.append(mas)
	for j in range(1):
		mas[i] = input().split(' ')
for i in range(5):
	if '1' in mas[i]:
		mas[2] = mas[i]
		answer = abs(i - 3 + 1)
		break
for j in range(5):
	if '1' == mas[2][j]:
		answer = answer + abs(j - 3 + 1)
		break
print(answer)


n = 5
a = []
a1 = j1 = None
count = 0
for i in range(n):
	a.append(list(map(int, input().split())))
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == 1:
			(a1, j1) = (i, j)
if a1 < 2:
	while a1 < 2:
		a1 += 1
		count += 1
if a1 > 2:
	while a1 > 2:
		a1 -= 1
		count += 1
if j1 < 3:
	while j1 < 2:
		j1 += 1
		count += 1
if j1 > 2:
	while j1 > 2:
		j1 -= 1
		count += 1
print(count)


list_1 = list(map(int, input().split()))
list_2 = list(map(int, input().split()))
list_3 = list(map(int, input().split()))
list_4 = list(map(int, input().split()))
list_5 = list(map(int, input().split()))
if 1 in list_1:
	x = list_1.index(1)
	y = abs(2 - x)
	print(2 + y)
elif 1 in list_2:
	x = list_2.index(1)
	y = abs(2 - x)
	print(1 + y)
elif 1 in list_3:
	x = list_3.index(1)
	y = abs(2 - x)
	print(y)
elif 1 in list_4:
	x = list_4.index(1)
	y = abs(2 - x)
	print(1 + y)
elif 1 in list_5:
	x = list_5.index(1)
	y = abs(2 - x)
	print(2 + y)


ans = 0
for i in range(0, 5):
	str = input().split()
	for j in range(0, 5):
		if str[j] == '1':
			ans += abs(j - 2) + abs(i - 2)
print(ans, sep='', end='\n')


for i in range(5):
	line = input().split(' ')
	if '1' in line:
		row = i + 1
		col = line.index('1') + 1
		break
	else:
		continue
print(abs(row - 3) + abs(col - 3))


(x, y) = (0, 0)
for i in range(5):
	a = input()
	if a[0] == '1':
		(x, y) = (i, 0)
	elif a[2] == '1':
		(x, y) = (i, 1)
	elif a[4] == '1':
		(x, y) = (i, 2)
	elif a[6] == '1':
		(x, y) = (i, 3)
	elif a[8] == '1':
		(x, y) = (i, 4)
print(abs(2 - y) + abs(2 - x))


operations_list = []
for i in range(5):
	num = list(map(int, input().split()))
	operations_list.append(num)
for a in range(5):
	for b in range(5):
		if operations_list[a][b] == 1:
			print(abs(a - 2) + abs(b - 2))


from math import *
for i in range(0, 5):
	a = input().replace(' ', '').find('1')
	if a != -1:
		print(abs(i - 2) + abs(a - 2))
		break


m = []
for i in range(5):
	a = input().split()
	m.append(a)
for i in m:
	for j in i:
		if j == '1':
			r = 2 - m.index(i)
			c = 2 - i.index(j)
print(abs(r) + abs(c))


m = []
for i in range(5):
	a = input()
	m.append([int(i) for i in a.split(' ')])
row = 0
column = 0
for i in range(5):
	if m[i].count(1) > 0:
		row = i + 1
		column = m[i].index(1) + 1
		break
print(abs(3 - row) + abs(3 - column))


import math
lst = [[0 for i in range(5)] for j in range(5)]
for i in range(5):
	string = input()
	s = string.split(' ')
	for j in range(5):
		lst[i][j] = s[j]
for i in range(5):
	for j in range(5):
		if lst[i][j] == '1':
			k = abs(i - 2) + abs(j - 2)
			print(k)
			break


(I, K) = (0, 0)
ar = [[int(i) for i in input().split()] for k in range(5)]
flag = True
for i in range(5):
	if not flag:
		break
	for k in range(5):
		if ar[i][k] == 1:
			(I, K) = (i, k)
			flag = False
			break
w = abs(I - 2) + abs(K - 2)
print(w)


(a, i, j, p, q) = (0, 0, 0, 0, 0)
l = list()
while a < 5:
	l2 = list(map(int, input().split()))
	l.append(l2)
	a += 1
while i < 5:
	for x in l[i]:
		if x == 1:
			(p, q) = (i, l[i].index(x))
			j = 1
			break
	if j == 1:
		break
	else:
		i += 1
print(abs(2 - p) + abs(2 - q))


for i in range(5):
	l = list(map(int, input().split()))
	if 1 in l:
		break
k = 2
j = 2
m = l.index(1)
print(abs(m - j) + abs(i - k))


x = []
for i in range(5):
	_in = list(map(int, input().split()))
	x.append(_in)
_y = 0
_x = 0
for i in range(5):
	for j in range(5):
		if x[i][j] == 1:
			_x = i
			_y = j
			break
count = abs(_x - 2)
count += abs(_y - 2)
print(count)


matrix = []
for i in range(5):
	inp = list(map(int, input().rstrip().split()))
	for (idx, num) in enumerate(inp):
		if num == 1:
			x = idx
			y = i
	matrix.append(inp)
print(abs(x - 2) + abs(y - 2))


N = 5
matrix = []
for i in range(N):
	matrix.extend(input().split(' '))
index = matrix.index('1')
x = index // N + 1
y = index % N + 1
result = abs(3 - x) + abs(3 - y)
print(result)


list2 = []
l1 = []
l2 = []
count1 = 0
count2 = 0
index = 0
index2 = 0
for i in range(5):
	read = input().split()
	list1 = list(map(int, read))
	list2.extend(list1)
for j in range(6):
	l1 = list2[j - 1:25:5]
	if 1 in l1:
		index = l1.index(1)
		break
for k in range(6):
	l2 = list2[(k - 1) * 5:k * 5]
	if 1 in l2:
		index2 = l2.index(1)
		break
count1 = abs(index - 2)
count2 = abs(index2 - 2)
print(count2 + count1)


for i in range(5):
	a = list(input().split())
	if max(a) == '1':
		b = a.index('1')
		if b == 0 or b == 4:
			c = 2
		elif b == 1 or b == 3:
			c = 1
		else:
			c = 0
		if i == 0 or i == 4:
			c += 2
		elif i == 1 or i == 3:
			c += 1
print(c)


a = input().replace(' ', '')
b = input().replace(' ', '')
c = input().replace(' ', '')
d = input().replace(' ', '')
e = input().replace(' ', '')
count = 0
w = a.find('1') + e.find('1')
if w != -2:
	if w == 3 or w == -1:
		count = 4
	elif w == 0 or w == 2:
		count = 3
	elif w == 1:
		count = 2
w = b.find('1') + d.find('1')
if w != -2:
	if w == 3 or w == -1:
		count = 3
	elif w == 0 or w == 2:
		count = 2
	elif w == 1:
		count = 1
w = c.find('1')
if w != -1:
	if w == 4 or w == 0:
		count = 2
	elif w == 1 or w == 3:
		count = 1
	elif w == 2:
		count = 0
print(count)


for i in range(5):
	inpt = input().replace(' ', '')
	if '1' in inpt:
		print(abs(2 - i) + abs(2 - inpt.find('1')))
		break


for i in range(5):
	row = input().split()
	if '1' in row:
		row_location = row.index('1')
		break
column_location = i
column_distance = abs(column_location - 2)
row_distance = abs(row_location - 2)
total_distance = column_distance + row_distance
print(total_distance)


def BeautifulMatrix():
	for row in range(5):
		matrix_row = input().strip().split()
		if '1' in matrix_row:
			pos = (row, matrix_row.index('1'))
	return abs(2 - pos[0]) + abs(2 - pos[1])
	return 0
a = BeautifulMatrix()
print(a)


def solve():
	matrix = []
	for _ in range(5):
		matrix.append(input().split())
	print(find_min_num(matrix))

def find_min_num(matrix):
	for i in range(3):
		for j in range(5):
			item = matrix[i][j]
			opp_item = matrix[4 - i][4 - j]
			if item != '0' or opp_item != '0':
				return abs(2 - j) + abs(2 - i)
solve()


a1 = input()
a2 = input()
a3 = input()
a4 = input()
a5 = input()
l1 = a1.split()
l2 = a2.split()
l3 = a3.split()
l4 = a4.split()
l5 = a5.split()
if l1[0] == '1' or l1[4] == '1':
	print(4)
elif l1[1] == '1' or l1[3] == '1':
	print(3)
elif l1[2] == '1':
	print(2)
else:
	pass
if l2[0] == '1' or l2[4] == '1':
	print(3)
elif l2[1] == '1' or l2[3] == '1':
	print(2)
elif l2[2] == '1':
	print(1)
else:
	pass
if l3[0] == '1' or l3[4] == '1':
	print(2)
elif l3[1] == '1' or l3[3] == '1':
	print(1)
elif l3[2] == '1':
	print(0)
else:
	pass
if l4[0] == '1' or l4[4] == '1':
	print(3)
elif l4[1] == '1' or l4[3] == '1':
	print(2)
elif l4[2] == '1':
	print(1)
else:
	pass
if l5[0] == '1' or l5[4] == '1':
	print(4)
elif l5[1] == '1' or l5[3] == '1':
	print(3)
elif l5[2] == '1':
	print(2)
else:
	pass


import math
st = ''

def func(k):
	return abs(2 - k[0]) + abs(2 - k[1])
for _ in range(1):
	k = []
	for i in range(5):
		inp = input().split()
		if '1' in inp:
			k = [i, inp.index('1')]
	st += str(func(k)) + '\n'
print(st)


from sys import stdin
input = stdin.readline

def matrix():
	for i in range(5):
		x = input().split()
		if '1' in x:
			s = (i + 1, x.index('1') + 1)
			break
	return abs(s[0] - 3) + abs(s[1] - 3)
print(matrix())


ll = []
for n in range(1, 6):
	l = list(map(int, input().split()))
	ll.append(l)
b = 0
r = 0
c = 0
for i in range(0, 5):
	for j in range(0, 5):
		if ll[i][j] == 1:
			r = i
			c = j
			b = 1
			break
	if b == 1:
		break
r = abs(2 - r)
c = abs(2 - c)
print(r + c)


for i in range(1, 6):
	cadena = input().replace(' ', '')
	posfila = cadena.find('1')
	if posfila != -1:
		posfila += 1
		print(abs(3 - i) + abs(3 - posfila))


t = []
for i in range(5):
	t = input()
	if t.find('1') != -1:
		j = t.find('1') // 2
		ii = i
print(abs(2 - ii) + abs(2 - j))


lst = []
c = 0
r = 0
for x in range(5):
	a = list(map(int, input().split(' ')))
	if 1 in a:
		c = a.index(1) + 1
		r = x + 1
print(abs(3 - r) + abs(3 - c))


list1 = input().split()
list2 = input().split()
list3 = input().split()
list4 = input().split()
list5 = input().split()
mat = [list1, list2, list3, list4, list5]
for i in range(5):
	if '1' in mat[i]:
		rname = i
		rch = abs(2 - i)
		break
for j in range(5):
	if mat[rname][j] == '1':
		cname = j
		cch = abs(2 - j)
		break
print(rch + cch)


ansx = 0
ansy = 0
for i in range(0, 5):
	line = input()
	j = 0
	for x in line.split():
		if int(x) == 1:
			ansx = i
			ansy = j
		else:
			j += 1
print(abs(ansx - 2) + abs(ansy - 2))


import math
l = []
for j in range(5):
	l.append([i for i in map(int, input().split(' '))])
for i in range(len(l)):
	if 1 in l[i]:
		j = l[i].index(1)
		i = i
		break
print(int(math.fabs(2 - j) + math.fabs(2 - i)))


l = []
for _ in range(5):
	l.append(input())
a = 0
for i in range(5):
	if '1' in l[i]:
		a = l[i].find('1')
		break
a //= 2
print(abs(a - 2) + abs(i - 2))


M = []
for i in range(5):
	M.append(list(map(int, input().split())))
	for j in range(5):
		if M[i][j] == 1:
			m = abs(3 - i - 1)
			n = abs(3 - j - 1)
print(m + n)


s = []
x = [0, 0]
for i in range(5):
	s.append(input().split())
	for j in range(5):
		if s[-1][j] == '1':
			x = [i, j]
print(abs(x[0] - 2) + abs(x[1] - 2))


l = [2, 1, 0, 1, 2]
for s in l:
	v = input()
	if '1' in v:
		print(s + l[v.find('1') // 2])


a = list()
for i in range(5):
	x = [int(i) for i in input().split()]
	a.append(x)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = i
			y = j
if x <= 2:
	x = 2 - x
else:
	x = -(2 - x)
if y <= 2:
	y = 2 - y
else:
	y = -(2 - y)
print(x + y)


myMatrix = []
for x in range(5):
	myMatrix.append(input().split())
row_num = 0
no_of_steps = 0
for each_row in myMatrix:
	if '1' in each_row:
		no_of_steps = abs(each_row.index('1') - 2) + abs(row_num - 2)
		print(no_of_steps)
		break
	else:
		row_num += 1


def func():
	dict = {}
	for d in range(5):
		str = input()
		value = []
		value = str.split(' ')
		dict[d] = []
		for k in range(5):
			dict[d].append(value[k])
	a = 0
	b = 0
	for d in range(5):
		if '1' in dict[d]:
			a = int(d)
			for k in range(5):
				if dict[d][k] == '1':
					b = int(k)
					break
			break
	print(abs(a - 2) + abs(b - 2))
func()


def get_steps(x, y):
	return abs(x - 2) + abs(y - 2)

def solve(matrix):
	x = y = 0
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				x = i
				y = j
				return get_steps(x, y)
matrix = []
for _ in range(5):
	matrix.append([number for number in list(map(int, input().split()))])
print(solve(matrix))


li = []
for i in range(5):
	li1 = list(map(int, input().split()))
	li.append(li1)
num = []
for i in range(5):
	for j in range(len(li[i])):
		if li[i][j] == 1:
			num = [i, j]
s = 0
if num[0] > 2:
	s = s + num[0] - 2
else:
	s += 2 - num[0]
if num[1] > 2:
	s += num[1] - 2
else:
	s += 2 - num[1]
print(s)


import sys
for i in range(1, 6):
	a = list(map(int, input().split()))
	for k in range(0, 5):
		if a[k] == 1:
			print(abs(3 - i) + abs(2 - k))
			sys.exit()


import math
for i in range(5):
	l = [int(k) for k in input().split(' ')]
	if sum(l) == 1:
		print(int(math.fabs(l.index(1) - 2) + math.fabs(i - 2)))


def main(strlist):
	for string in strlist:
		for num in string:
			if num == '1':
				x = string.index(num)
				y = strlist.index(string)
				break
	steps = 0
	while x != 2:
		if x > 2:
			x -= 1
			steps += 1
		elif x < 2:
			x += 1
			steps += 1
	while y != 2:
		if y > 2:
			y -= 1
			steps += 1
		elif y < 2:
			y += 1
			steps += 1
	return steps
strlist = []
for i in range(5):
	spl = input().split(' ')
	strlist.append(spl)
print(main(strlist))


a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
e = [int(x) for x in input().split()]
if 1 in a:
	i = a.index(1)
	print(2 + abs(2 - i))
if 1 in b:
	j = b.index(1)
	print(1 + abs(2 - j))
if 1 in c:
	k = c.index(1)
	print(abs(2 - k))
if 1 in d:
	l = d.index(1)
	print(1 + abs(2 - l))
if 1 in e:
	m = e.index(1)
	print(2 + abs(2 - m))


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
mid_i = 2
mid_j = 2
for i in range(5):
	if 1 in mat[i]:
		print(abs(mid_i - i) + abs(mid_j - mat[i].index(1)))
		break


matrix = []
i1 = 0
j1 = 0
for i in range(5):
	s = input()
	matrix.append(s.split())
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			i1 = i + 1
			j1 = j + 1
			break
(i, j) = (3, 3)
print(abs(i1 - i) + abs(j1 - j))


matrix = []
for i in range(5):
	matrix.append(input().split())
line_num = 0
col_num = 1
for line in matrix:
	line_num += 1
	if '1' in line:
		col_num += line.index('1')
		break
print(abs(3 - line_num) + abs(3 - col_num))


dic = {}
for i in range(5):
	x = input()
	ls = x.split()
	for j in range(5):
		dic[i + 1, j + 1] = int(ls[j])
		if int(ls[j]) == 1:
			position = (i + 1, j + 1)
num = abs(3 - position[0]) + abs(3 - position[1])
print(num)


mat = []
for _ in range(5):
	mat.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if mat[i][j]:
			row = i
			col = j
			break
print(abs(row - 2) + abs(col - 2))


arr = []
arr = [[int(x) for x in input().split()] for j in range(5)]
for row in range(5):
	for column in range(5):
		if arr[row][column] == 1:
			i = row + 1
			j = column + 1
			break
if j >= 3:
	j = j - 3
elif j < 3:
	j = 3 - j
if i >= 3:
	i = i - 3
elif i < 3:
	i = 3 - i
print(i + j)


i1 = input('').split()
i2 = input('').split()
i3 = input('').split()
i4 = input('').split()
i5 = input('').split()
List = [i1, i2, i3, i4, i5]
for x in List:
	for y in x:
		if y == '1':
			count = 0
			temp = x.index(y)
			if x.index(y) < 2:
				while temp != 2:
					temp += 1
					count += 1
			elif x.index(y) > 2:
				while temp != 2:
					temp -= 1
					count += 1
			if List.index(x) < 2:
				count += 2 - List.index(x)
			elif List.index(x) > 2:
				count += List.index(x) - 2
			break
print(count)


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()))
if (1 in row1) == True:
	steps = abs(row1.index(1) + 1 - 3)
	steps += 2
	print(steps)
elif (1 in row2) == True:
	steps = abs(row2.index(1) + 1 - 3)
	steps += 1
	print(steps)
elif (1 in row3) == True:
	steps = abs(row3.index(1) + 1 - 3)
	steps += 0
	print(steps)
elif (1 in row4) == True:
	steps = abs(row4.index(1) + 1 - 3)
	steps += 1
	print(steps)
elif (1 in row5) == True:
	steps = abs(row5.index(1) + 1 - 3)
	steps += 2
	print(steps)
else:
	pass


a = []
t = 0
for z in range(5):
	a.append([int(x) for x in input().split()])
	for y in range(5):
		if a[z][y] == 1:
			t = abs(z - 2) + abs(y - 2)
print(t)


a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
e = [int(i) for i in input().split()]
if 1 in a:
	i = 1
	x = a
elif 1 in b:
	i = 2
	x = b
elif 1 in c:
	i = 3
	x = c
elif 1 in d:
	i = 4
	x = d
elif 1 in e:
	i = 5
	x = e
j = x.index(1) + 1
p = max(3, i) - min(3, i)
q = max(3, j) - min(3, j)
print(p + q)


col = row = 1
for i in range(0, 5):
	a = list(input().split())
	if len(set(a)) == 1:
		row += 1
	else:
		col = a.index('1') + 1
		break
print(abs(3 - row) + abs(3 - col))


(a, b, c, d, e) = map(int, input().split())
(f, g, h, i, j) = map(int, input().split())
(k, l, m, n, o) = map(int, input().split())
(p, q, r, s, t) = map(int, input().split())
(u, v, w, x, y) = map(int, input().split())
F = [[a, b, c, d, e], [f, g, h, i, j], [k, l, m, n, o], [p, q, r, s, t], [u, v, w, x, y]]
V = 0
while V < 5:
	A = F[0][V]
	if A == 1:
		P = 0
		H = V
	V = V + 1
W = 0
while W < 5:
	B = F[1][W]
	if B == 1:
		P = 1
		H = W
	W = W + 1
X = 0
while X < 5:
	C = F[2][X]
	if C == 1:
		P = 2
		H = X
	X = X + 1
Y = 0
while Y < 5:
	D = F[3][Y]
	if D == 1:
		P = 3
		H = Y
	Y = Y + 1
Z = 0
while Z < 5:
	E = F[4][Z]
	if E == 1:
		P = 4
		H = Z
	Z = Z + 1
G = abs(2 - P)
T = abs(2 - H)
J = G + T
print(J)


z = 0
p = 0
(w, h) = (5, 5)
matrix = [[int(x) for x in input().split()] for y in range(h)]
for x in range(5):
	for y in range(5):
		if matrix[x][y] == 1:
			if x - 2 > 0:
				z = x - 2
			else:
				z = 2 - x
			if y - 2 > 0:
				p = y - 2
			else:
				p = 2 - y
				p = 2 - y
print(p + z)


import math
tabela = [None] * 5
for num in range(5):
	tabela[num] = input().split(' ')
count = 0
for row in tabela:
	for num in row:
		if num == '1':
			count += abs(row.index(num) - 2)
			count += abs(tabela.index(row) - 2)
print(count)


l = []
for i in range(5):
	lst = []
	lst.extend([int(x) for x in input().split()])
	l.append(lst)
for i in range(5):
	ele = l[i]
	for j in range(5):
		if ele[j] == 1:
			x = i
			y = j
result = abs(x - 2) + abs(y - 2)
print(result)


def findone(matrix):
	for i in range(len(matrix)):
		for j in range(len(matrix)):
			if matrix[i][j] == 1:
				return [i + 1, j + 1]

def calculate(coordinate):
	x = coordinate[0]
	y = coordinate[1]
	ans = abs(x - 3) + abs(y - 3)
	return ans
matrix = []
for i in range(5):
	line = list(map(int, input().split()))
	matrix.append(line)
print(calculate(findone(matrix)))


for y in range(5):
	s = input('')
	input_lists = s.split(' ')
	matrixX = [int(x.strip()) for x in input_lists]
	for x in range(len(matrixX)):
		if matrixX[x] == 1:
			xPos = x + 1
			yPos = y + 1
		else:
			pass
xTarget = 3
yTarget = 3
xMovement = abs(xPos - xTarget)
yMovement = abs(yPos - yTarget)
total_moves = xMovement + yMovement
print(total_moves)


def main():
	matrix = [[] * 5] * 5
	for i in range(0, 5):
		a = list(input().split())
		for j in range(0, 5):
			if a[j] == '1':
				ans = abs(i - 2) + abs(j - 2)
		matrix.append(a)
	print(ans)
main()


n = m = 5
a = []
for i in range(n):
	a.append([int(j) for j in input().split()])
for i in range(n):
	for j in range(m):
		if a[i][j] == 1:
			(x, y) = (i, j)
			x = abs(x - 2)
			y = abs(y - 2)
			suma = x + y
print(suma)


for i in range(1, 6):
	this = list(map(int, input().split()))
	if this != [0, 0, 0, 0, 0]:
		x = i
		break
if this == [0, 0, 0, 0, 0]:
	print(0)
else:
	for j in range(0, 5):
		if this[j] == 1:
			number = j + 1
			break
print(abs(3 - number) + abs(3 - x))


for row in range(5):
	rows = input().split()
	if '1' in rows:
		col = rows.index('1')
		print(abs(row - 2) + abs(col - 2))
		break


row = [2, 1, 0, 1, 2]
for i in row:
	column = list(map(int, input().split()))
	for j in range(len(column)):
		if column[j] == 1:
			l = i + row[j]
print(l)


matrix = []
for i in range(5):
	a = [int(x) for x in input().split()]
	for j in range(5):
		if a[j] == 1:
			i1 = i + 1
			j1 = j + 1
mutari = abs(3 - i1) + abs(3 - j1)
print(mutari)


arr = [input().split() for i in range(5)]
one = []
for i in range(5):
	if arr[i].count('1'):
		one.append(i)
		one.append(arr[i].index('1'))
	if len(one) == 2:
		break
print(abs(one[0] - 2) + abs(one[1] - 2))


(w, h) = (5, 5)
point = []
counter = 0
matrix_map = [[0 for x in range(w)] for y in range(h)]
for x in range(5):
	matrix_map[x] = input().split()
for x in range(5):
	for y in range(5):
		if matrix_map[x][y] == '1':
			point.append(x)
			point.append(y)
while True:
	if point[1] > 2:
		matrix_map[point[0]][point[1]] = '0'
		matrix_map[point[0]][point[1] - 1] = '1'
		point[1] = point[1] - 1
		counter += 1
	elif point[1] < 2:
		matrix_map[point[0]][point[1]] = '0'
		matrix_map[point[0]][point[1] + 1] = '1'
		point[1] = point[1] + 1
		counter += 1
	else:
		break
while True:
	if point[0] > 2:
		matrix_map[point[0]][point[1]] = '0'
		matrix_map[point[0] - 1][point[1]] = '1'
		point[0] = point[0] - 1
		counter += 1
	elif point[0] < 2:
		matrix_map[point[0]][point[1]] = '0'
		matrix_map[point[0] + 1][point[1]] = '1'
		point[0] = point[0] + 1
		counter += 1
	else:
		break
print(counter)


l1 = [int(i) for i in input().split()]
l2 = [int(i) for i in input().split()]
l3 = [int(i) for i in input().split()]
l4 = [int(i) for i in input().split()]
l5 = [int(i) for i in input().split()]
if l3[2] == 1:
	print('0')
elif l1[0] == 1 or l1[4] == 1 or l5[0] == 1 or (l5[4] == 1):
	print('4')
elif l1[1] == 1 or l1[3] == 1 or l2[0] == 1 or (l2[4] == 1) or (l4[0] == 1) or (l4[4] == 1) or (l5[1] == 1) or (l5[3] == 1):
	print('3')
elif l2[2] == 1 or l3[1] == 1 or l3[3] == 1 or (l4[2] == 1):
	print('1')
else:
	print('2')


moves = 0
found = 0
y = 1
x = 1
while y <= 5 and found == 0:
	row = [''] + list(input().split(maxsplit=4))
	x = 1
	while x <= 5 and found == 0:
		row[x] = int(row[x])
		if row[x] == 1:
			found = 1
		x += 1
	y += 1
y -= 1
x -= 1
if x > 3:
	moves += x - 3
else:
	moves += 3 - x
if y > 3:
	moves += y - 3
else:
	moves += 3 - y
print(moves)


mat = []
for i in range(0, 5):
	(a, b, c, d, e) = map(int, input().split())
	tmp = [a, b, c, d, e]
	mat.append(tmp)
onex = -1
oney = -1
for i in range(0, 5):
	for j in range(0, 5):
		if mat[i][j] == 1:
			onex = i
			oney = j
print(abs(3 - (onex + 1)) + abs(3 - (oney + 1)))


def mod(par):
	return par - 3 if par - 3 >= 0 else 3 - par
for a in range(5):
	tt = input().split(' ')
	if '1' in tt:
		m = tt.index('1')
		print(mod(m + 1) + mod(a + 1))
		break


def findOne(matrix):
	oneLocationR = 0
	oneLocationC = 0
	for row in range(len(matrix)):
		for column in range(len(matrix[0])):
			if int(matrix[row][column]) == 1:
				oneLocationR = row
				oneLocationC = column
				return [oneLocationR, oneLocationC]

def calculateMoves(position):
	moveRows = abs(position[0] - 2)
	moveColumns = abs(position[1] - 2)
	totalMoves = moveRows + moveColumns
	return totalMoves
matrix = []
for _ in range(5):
	listOfInputs = input().split()
	matrix.append(listOfInputs)
print(calculateMoves(findOne(matrix)))


matrix = [[], [], [], [], []]
for i in range(1, 6):
	(a, b, c, d, e) = map(int, input().split())
	if a == 1:
		j = i
		k = 1
	if b == 1:
		j = i
		k = 2
	if c == 1:
		j = i
		k = 3
	if d == 1:
		j = i
		k = 4
	if e == 1:
		j = i
		k = 5
print(abs(j - 3) + abs(k - 3))


for i in range(5):
	next = input()
	next = next.split(' ')
	for j in range(len(next)):
		if next[j].__eq__('1'):
			count = abs(j - 2)
			count += abs(i - 2)
print(count)


for i in range(5):
	l = [int(x) for x in input().split()]
	if 1 in l:
		print(abs(2 - l.index(1)) + abs(2 - i))
for j in range(4 - i):
	s = input()


for i in range(1, 6):
	index = input().find('1') // 2 + 1
	if index > 0:
		print(abs(3 - i) + abs(3 - index))


n = [input().split() for i in range(5)]
operations = 0
for i in range(len(n)):
	for (index, item) in enumerate(n[i]):
		if int(item) == 1:
			if index > 2:
				operations += index - 2
			elif index < 2:
				operations += 2 - index
			if i > 2:
				operations += i - 2
			elif i < 2:
				operations += 2 - i
print(operations)


for item in range(5):
	s = input()
	if '1' in s:
		a = abs(item - 2) + abs(s.find('1') // 2 - 2)
print(a)


def sol(matrix):
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == '1':
				return abs(2 - i) + abs(2 - j)
	return None
matrix = []
for _ in range(5):
	matrix.append(input().split())
print(sol(matrix))


res = 0
pos = 0
for y in range(5):
	i = input().split()
	if '1' in i:
		res += abs(2 - y)
		res += abs(2 - i.index('1'))
print(res)


from math import *
glob = []
for i in range(5):
	arr = [int(i) for i in input().split()]
	glob.append(arr)
index_x = 0
index_y = 0
for i in range(5):
	for j in range(5):
		if glob[i][j] == 1:
			index_x = i
			index_y = j
			break
print(abs(2 - index_x) + abs(2 - index_y))


point1 = []
center = [2, 2]
for i in range(0, 5):
	try:
		line = input().split(' ')
		if len(point1) == 0:
			idx = line.index('1')
			point1 = [i, idx]
			break
	except ValueError:
		continue
print(abs(center[0] - point1[0]) + abs(center[1] - point1[1]))


def calculate(i, j):
	if i == 2 and j == 2:
		print('0')
		return 0
	move_counter = 0
	while i != 2:
		if i < 2:
			i += 1
		elif i > 2:
			i -= 1
		move_counter += 1
	while j != 2:
		if j < 2:
			j += 1
		elif j > 2:
			j -= 1
		move_counter += 1
	print(move_counter)
	return 0

def main():
	matrix = []
	for i in range(5):
		s = str(input().strip())
		s = s.replace(' ', '')
		matrix.append(s)
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == '1':
				calculate(i, j)
				return 0
main()


from sys import stdin
from itertools import chain
(y, x) = divmod(tuple(chain.from_iterable((stdin.readline().split() for _ in range(5)))).index('1'), 5)
print(abs(y - 2) + abs(x - 2))


ai = []
(x1, y1) = (3, 3)
(x2, y2) = (None, None)
for i in range(1, 6):
	lst = list(map(int, input().split()))
	if 1 in lst:
		x2 = i
		y2 = lst.index(1) + 1
print(abs(x1 - x2) + abs(y1 - y2))


kv = []
for i in range(5):
	kv.append(list(map(int, input().split())))
for j in range(5):
	for i in range(5):
		if kv[j][i] == 1:
			a = j
			b = i
a = 2 - a
b = 2 - b
a = abs(a)
b = abs(b)
ab = a + b
if ab == 0:
	print(0)
elif ab == 1:
	print(1)
elif ab == 2:
	print(2)
elif ab == 3:
	print(3)
elif ab == 4:
	print(4)


d = []
count = 0
for i in range(0, 5):
	rows = []
	for j in range(0, 1):
		(a, b, c, f, e) = map(int, input().split())
		rows.append(a)
		rows.append(b)
		rows.append(c)
		rows.append(f)
		rows.append(e)
	d.append(rows)
for i in range(0, 5):
	for j in range(0, 5):
		if d[i][j] == 1:
			(p, q) = (i, j)
if p < 2 and q == 2:
	count = 2 - p
elif q < 2 and p == 2:
	count = 2 - q
elif p < 2 and q < 2:
	count = 2 - p + (2 - q)
elif p > 2 and q == 2:
	count = p - 2
elif q > 2 and p == 2:
	count = q - 2
elif p > 2 and q > 2:
	count = p - 2 + (q - 2)
elif p > 2 and q < 2:
	count = p - 2 + (2 - q)
elif p < 2 and q > 2:
	count = 2 - p + (q - 2)
print(count)


import math
i = 0
a = -1
matrix = []
while i < 5:
	line = input().split()
	matrix.append(line)
	i = i + 1
i = 0
while i < 5:
	line = matrix[i]
	j = 0
	while j < 5:
		number = line[j]
		if number == '1':
			a = j
			break
		else:
			j = j + 1
	if a == -1:
		i = i + 1
	else:
		b = i
		break
beautiful = math.sqrt((a - 2) ** 2) + math.sqrt((b - 2) ** 2)
print(int(beautiful))


g = 1
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = list(map(int, input().split()))
k = list(map(int, input().split()))
m = list(map(int, input().split()))
if g == z[2]:
	print(0)
elif g == z[1] or g == z[3] or g == y[2] or (g == k[2]):
	print(1)
elif g == y[1] or g == y[3] or g == x[2] or m[2] or (g == z[0]) or (g == z[4]) or (g == k[1]) or (g == k[3]):
	print(2)
elif g == y[0] or g == y[4] or g == k[0] or (g == k[4]) or (g == x[1]) or (g == x[3]) or (g == m[1]) or (g == m[3]):
	print(3)
else:
	print(4)


i = -1
j = 0
check = 0
for n in range(5):
	matrix = list(map(int, input().split()))
	if check == 0:
		i += 1
	if 1 in matrix:
		check = 1
		j = matrix.index(1)
if i < 2:
	row = 2 - i
else:
	row = i - 2
if j < 2:
	col = 2 - j
else:
	col = j - 2
print(row + col)


n = 5
loc = 2
moves = 0
for i in range(n):
	l = input().replace(' ', '')
	index = l.find('1')
	if index != -1:
		moves += abs(loc - index)
		moves += abs(i - loc)
		break
print(moves)


mat = []
(m, n) = (0, 0)
for i in range(5):
	a = list(map(int, input().split()))
	if 1 in a:
		m = i
		n = a.index(1)
c = 0
c = abs(2 - n) + abs(2 - m)
print(c)


a = []
for a0 in range(5):
	l = [int(i) for i in input().strip().split()]
	a.append(l)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			g = i
			h = j
			break
g = abs(2 - g)
h = abs(2 - h)
print(g + h)


for k in range(5):
	a = input()[::2]
	if '1' in a:
		print(abs(k - 2) + abs(a.index('1') - 2))


count = 0
for i in range(5):
	(num1, num2, num3, num4, num5) = [int(x) for x in input().split()]
	if num1:
		count += abs(3 - (i + 1)) + 2
	elif num2:
		count += abs(3 - (i + 1)) + 1
	elif num3:
		count += abs(3 - (i + 1))
	elif num4:
		count += abs(3 - (i + 1)) + 1
	elif num5:
		count += abs(3 - (i + 1)) + 2
print(count)


ans = 0
for i in range(5):
	x = list(map(int, input().split()))
	if 1 in x:
		c = x.index(1)
		if i == 0:
			if c == 0:
				ans = 4
			elif c == 1:
				ans = 3
			elif c == 2:
				ans = 2
			elif c == 3:
				ans = 3
			elif c == 4:
				ans = 4
		elif i == 1:
			if c == 0:
				ans = 3
			elif c == 1:
				ans = 2
			elif c == 2:
				ans = 1
			elif c == 3:
				ans = 2
			elif c == 4:
				ans = 3
		elif i == 2:
			if c == 0:
				ans = 2
			elif c == 1:
				ans = 1
			elif c == 2:
				ans = 0
			elif c == 3:
				ans = 1
			elif c == 4:
				ans = 2
		elif i == 3:
			if c == 0:
				ans = 3
			elif c == 1:
				ans = 2
			elif c == 2:
				ans = 1
			elif c == 3:
				ans = 2
			elif c == 4:
				ans = 3
		elif i == 4:
			if c == 0:
				ans = 4
			elif c == 1:
				ans = 3
			elif c == 2:
				ans = 2
			elif c == 3:
				ans = 3
			elif c == 4:
				ans = 4
print(ans)


for i in range(5):
	a = input().split(' ')
	for j in range(5):
		if a[j] == '1':
			print(max(j - 2, 2 - j) + max(i - 2, 2 - i))


for i in range(5):
	l = input().split()
	if '1' not in l:
		continue
	y = i + 1
	x = 1 + l.index('1')
	print(abs(x - 3) + abs(y - 3))
	break


matrix = [None] * 5
for i in range(5):
	line = input().split('\n')
	line = line[0]
	matrix[i] = [int(number) for number in line.split()]
for i in matrix:
	for j in i:
		if j is 1:
			(one, two) = (matrix.index(i), i.index(j))
(one, two) = (abs(one - 2), abs(two - 2))
print(one + two)


t = []
for i in range(5):
	s = [int(x) for x in input().split()]
	for j in range(5):
		if s[j] == 1:
			a = i
			b = j
			A = abs(a - 2) + abs(b - 2)
print(A)


i = 0
length_of_matrix = 5
strInputs = list()
while i < length_of_matrix:
	strInputs.append(input())
	i += 1
for i in range(0, len(strInputs)):
	strInputs[i] = strInputs[i].replace(' ', '')
row = None
column = None
call = False
for i in range(0, len(strInputs)):
	for j in range(0, len(strInputs[i])):
		if strInputs[i][j] == '1':
			row = j
			column = i
			call = True
	if call == True:
		break
movement_in_row_direction = abs(2 - row)
movement_in_column_direction = abs(2 - column)
print(movement_in_column_direction + movement_in_row_direction)


a = [input().split() for i in range(5)]
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == '1':
			p = abs(i - 2) + abs(j - 2)
print(p)


a = []
c = 0
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	if 1 in a[i]:
		i1 = a[i].index(1)
		break
if i == 2 and i1 == 2:
	pass
if i > 2:
	while i != 2:
		i -= 1
		c += 1
elif i < 2:
	while i != 2:
		i += 1
		c += 1
if i1 > 2:
	while i1 != 2:
		i1 -= 1
		c += 1
elif i1 < 2:
	while i1 != 2:
		i1 += 1
		c += 1
print(c)


for i in range(5):
	c = input().split()
	if '1' in c:
		print(abs(3 - (i + 1)) + abs(3 - (c.index('1') + 1)))


list1 = []
for i in range(5):
	temp = [int(x) for x in input().strip().split()]
	list1.append(temp)
(fi, fj) = (0, 0)
for i in range(5):
	for j in range(5):
		if list1[i][j] == 1:
			(fi, fj) = (i, j)
answer = abs(2 - fi) + abs(2 - fj)
print(answer)


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()))
ans = 0
if sum(a) == 1:
	ans += 2
	for i in range(5):
		if a[i] == 1:
			ans += abs(i - 2)
elif sum(b) == 1:
	ans += 1
	for i in range(5):
		if b[i] == 1:
			ans += abs(i - 2)
elif sum(d) == 1:
	ans += 1
	for i in range(5):
		if d[i] == 1:
			ans += abs(i - 2)
elif sum(e) == 1:
	ans += 2
	for i in range(5):
		if e[i] == 1:
			ans += abs(i - 2)
else:
	for i in range(5):
		if c[i] == 1:
			ans += abs(i - 2)
print(ans)


row = 0
column = 0
for index in range(5):
	current_row = input().split()
	if '1' in current_row:
		row = index + 1
		column = current_row.index('1') + 1
		break
print(abs(3 - row) + abs(3 - column))


cen_position = None
for i in range(5):
	stdin = input()
	row = stdin.split(' ')
	for j in range(len(row)):
		if row[j] == '1':
			cen_position = (i, j)
			break
res = abs(2 - cen_position[0]) + abs(2 - cen_position[1])
print(res)


def solution(matrix):
	(x, y) = find_one(matrix)
	return abs(3 - (x + 1)) + abs(3 - (y + 1))

def find_one(matrix):
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				return (i, j)
matrix = []
for _ in range(5):
	matrix.append(list(map(int, input().split())))
print(solution(matrix))


n = []
for i in range(5):
	n.append(list(map(int, input().strip().split(' '))))
	if n[i].count(1) == 1:
		p = i
		q = n[i].index(1)
c = 0
print(abs(p - 2) + abs(q - 2))


c_idx = 0
r_idx = 0
for i in range(5):
	str = input().strip()
	if '1' in str:
		r_idx = i
		c_idx = str.split(' ').index('1')
print(abs(r_idx - 2) + abs(c_idx - 2))


fila = 0
column = 0
for i in range(5):
	num = list(map(int, input().split(' ')))
	if sum(num) == 1:
		fila = i
		column = num.index(1)
print(abs(column - 2) + abs(fila - 2))


for i in range(5):
	row = input()
	if '1' in row:
		(row_index, column_index) = (i, row.replace(' ', '').index('1'))
print(abs(row_index - 2) + abs(column_index - 2))


matrix = [[0 for i in range(5)] for i in range(5)]
for i in range(5):
	a = list(input().split())
	matrix[i] = a
loc = [0, 0]
best_loc = [2, 2]
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			loc[0] = i
			loc[1] = j
			break
		else:
			continue
sum = abs(loc[0] - best_loc[0]) + abs(loc[1] - best_loc[1])
print(sum)


for i in range(5):
	lsmall = [str(x) for x in input().split()]
	if '1' in lsmall:
		m = i + 1
		n = lsmall.index('1') + 1
output = abs(m - 3) + abs(n - 3)
print(output)


import sys
from math import ceil, log
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

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

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('Yes')

def NO():
	print('No')
INF = 10 ** 18
MOD = 10 ** 9 + 7
(r, c) = (-1, -1)
for i in range(5):
	temp = RI()
	for j in range(len(temp)):
		if temp[j] == 1:
			r = i
			c = j
print(abs(2 - r) + abs(2 - c))


for j in range(5):
	line = [int(i) for i in input().split()]
	if 1 in line:
		m = j
		n = line.index(1)
count = 0
while True:
	if m == n == 2:
		break
	elif m > 2:
		m -= 1
		count += 1
	elif m < 2:
		m += 1
		count += 1
	elif n > 2:
		n -= 1
		count += 1
	elif n < 2:
		n += 1
		count += 1
print(count)


n = {}
x = 1
while True:
	try:
		line = input()
	except EOFError:
		break
	n[x] = line
	x += 1
for x in n:
	row = list(map(int, n[x].split()))
	s = sum(row)
	if s == 1:
		row_n = x
k = 0
col = list(map(int, n[row_n].split()))
for x in col:
	if x == 0:
		k += 1
	else:
		cn = k + 1
		break

def result(a, b):
	print(abs(a - 3) + abs(b - 3))
result(row_n, cn)


matrix = []
for k in range(0, 5):
	l = list(map(int, input().split()))
	matrix.append(l)
row = 0
column = 0
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == 1:
			row = i + 1
			column = j + 1
diff_in_row = abs(3 - row)
diff_in_column = abs(3 - column)
swaps = diff_in_column + diff_in_row
print(swaps)


l = [1, 2, 3, 4, 5]
k = 0
for j in range(0, 5):
	l[j] = input()
	for i in range(0, 5):
		if l[j][2 * i] == '1':
			k = ((i - 2) ** 2) ** 0.5 + ((j - 2) ** 2) ** 0.5
print(int((k ** 2) ** 0.5))


def main():
	matrix = []
	beautiful_place = (2, 2)
	current_place = (0, 0)
	Breaker = False
	for i in range(5):
		matrix.append(input().split(' '))
	for i in range(len(matrix)):
		for j in range(len(matrix[i])):
			if matrix[i][j] == '1':
				current_place = (i, j)
				Breaker = True
				break
		if Breaker:
			break
	print(abs(current_place[0] - beautiful_place[0]) + abs(current_place[1] - beautiful_place[1]))
main()


(row, col) = (0, 0)
(x, y) = (2, 2)
for i in range(5):
	arr = input().split()
	for j in range(5):
		if int(arr[j]) == 1:
			row = i
			col = j
result = abs(x - row) + abs(y - col)
print(result)


line1 = input()
line2 = input()
line3 = input()
line4 = input()
line5 = input()
result1 = line1.split(' ')
result2 = line2.split(' ')
result3 = line3.split(' ')
result4 = line4.split(' ')
result5 = line5.split(' ')
for i in range(5):
	if int(result1[i]) == 1:
		fila = 0
		columna = i
	elif int(result2[i]) == 1:
		fila = 1
		columna = i
	elif int(result3[i]) == 1:
		fila = 2
		columna = i
	elif int(result4[i]) == 1:
		fila = 3
		columna = i
	elif int(result5[i]) == 1:
		fila = 4
		columna = i
fila = abs(fila - 2)
columna = abs(columna - 2)
print(fila + columna)


import math
x = 0
p = 0
n = 0
q1 = input().split()
q2 = input().split()
q3 = input().split()
q4 = input().split()
q5 = input().split()
for i in range(5):
	if int(q1[x]) == 1:
		n = x + 1
		p = 1
	else:
		x = x + 1
x = 0
for i in range(5):
	if int(q2[x]) == 1:
		n = x + 1
		p = 2
	else:
		x = x + 1
x = 0
for i in range(5):
	if int(q3[x]) == 1:
		n = x + 1
		p = 3
	else:
		x = x + 1
x = 0
for i in range(5):
	if int(q4[x]) == 1:
		n = x + 1
		p = 4
	else:
		x = x + 1
x = 0
for i in range(5):
	if int(q5[x]) == 1:
		n = x + 1
		p = 5
	else:
		x = x + 1
x = 0
q1 = 3 - n
q2 = 3 - p
q1 = q1 if q1 > 0 else -q1
q2 = q2 if q2 > 0 else -q2
q3 = q1 + q2
print(q3)


Matriz = []
for x in range(5):
	fila = input().split()
	Matriz.append(fila)
posi = -1
posj = -1
for x in range(0, len(Matriz)):
	for y in range(0, len(Matriz[0])):
		if Matriz[x][y] == '1':
			posi = x
			posj = y
print(abs(posi - 2) + abs(posj - 2))


i = 1
lst = []
while i <= 5:
	lst.append(input())
	i += 1
for el in lst:
	a = el.split()
	for b in a:
		if int(b) == 1:
			c = a.index(b) + 1
			r = lst.index(el) + 1
movesc = abs(3 - c)
movesr = abs(3 - r)
print(movesc + movesr)


s = [[] for _ in range(5)]
for j in range(5):
	s[j] = input().split(' ')
for i in range(5):
	if '1' in s[i]:
		print(abs(i - 2) + abs(s[i].index('1') - 2))


for iter in range(5):
	l = list(map(int, input().split()))
	for x in range(5):
		if l[x] == 1:
			col = x
			row = iter
col = abs(col - 2)
row = abs(row - 2)
print(row + col)


m = []
for i in range(5):
	m.append([int(i) for i in input().split()])
for i in range(5):
	if sum(m[i]) == 1:
		r = i
		c = m[r].index(1)
print(abs(2 - r) + abs(2 - c))


row = 1
correctRow = 0
while row <= 5:
	string = input().split(' ')
	for i in range(5):
		if string[i] == '1':
			column = i + 1
			correctRow = row
			break
	row += 1
diff = abs(correctRow - 3) + abs(column - 3)
print(diff)


def main():
	for row in range(5):
		line = input().split()
		if '1' in line:
			row += 1
			break
	col = line.index('1') + 1
	rowMove = abs(3 - row)
	colMove = abs(3 - col)
	print(rowMove + colMove)
main()


moves = 0
row1 = input('')
row2 = input('')
row3 = input('')
row4 = input('')
row5 = input('')
matrixstr = row1 + ' ' + row2 + ' ' + row3 + ' ' + row4 + ' ' + row5
matrix = matrixstr.split()
pos_one = int(''.join([str(pos + 1) for (pos, value) in enumerate(matrix) if value == '1']))
if pos_one == 1 or pos_one == 5 or pos_one == 21 or (pos_one == 25):
	print(4)
elif pos_one == 2 or pos_one == 4 or pos_one == 6 or (pos_one == 10) or (pos_one == 16) or (pos_one == 20) or (pos_one == 22) or (pos_one == 24):
	print(3)
elif pos_one == 3 or pos_one == 7 or pos_one == 9 or (pos_one == 11) or (pos_one == 15) or (pos_one == 17) or (pos_one == 19) or (pos_one == 23):
	print(2)
elif pos_one == 13:
	print(0)
else:
	print(1)


strling = [0 for i in range(0, 5)]
flag = 0
for i in range(0, 5):
	s = input()
	strling = s.split()
	for j in range(0, 5):
		if strling[j] == '1':
			flag = 1
			break
	if flag == 1:
		break
row = i + 1
column = j + 1

def positive(num):
	if num >= 0:
		return num
	else:
		return -num
y = positive(row - 3)
x = positive(column - 3)
print(x + y)


import math
c = int(0)
for i in range(-2, 3):
	a = list(map(int, input().split()))
	if a.count(1) != 0:
		c += math.fabs(a.index(1) - 2)
		c += math.fabs(i)
print(int(c))


k = 0
t = 0
for i in range(5):
	n = input()
	a = n.split()
	a = list(map(int, a))
	if 1 in a:
		k = i
		t = a.index(1)
y = abs(t - 2) + abs(k - 2)
print(y)


matrix = []
for i in range(5):
	matrix.append([int(x) for x in input().split()])
row = 0
column = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i + 1
			column = j + 1
print(abs(row - 3) + abs(column - 3))


L = []
(n, m) = (0, 0)
for i in range(5):
	line = input().split()
	L.append(line)
for i in range(5):
	for j in range(5):
		if int(L[i][j]) == 1:
			n = i + 1
			m = j + 1
step = abs(n - 3) + abs(m - 3)
print(step)


matrix = [[0]] * 5
(x, y) = (0, 0)
for _ in range(5):
	matrix[_] = list(map(int, input().split()))
	if 1 in matrix[_]:
		(x, y) = (_ + 1, matrix[_].index(1) + 1)
		break
print(abs(x - 3) + abs(y - 3))


l = []
for _ in range(5):
	l.append(list(map(int, input().split())))
flagg = False
for ii in range(5):
	for jj in range(5):
		if l[ii][jj] == 1:
			flagg = True
			break
	if flagg == True:
		break
print(abs(2 - ii) + abs(2 - jj))


for wi in range(1, 6):
	Str = input()
	Sl = Str.split(' ')
	if '1' in Sl:
		print(abs(wi - 3) + abs(Sl.index('1') - 2))
		break


row = 0
ls = ''
for i in range(5):
	s = input()
	if '1' in s:
		row = i + 1
		ls = s
		break
col = 0
arr = list(map(int, ls.split()))
for i in range(5):
	if arr[i] == 1:
		col = i + 1
		break
res = int(abs(3 - row) + abs(3 - col))
print(res)


l = []
for i in range(5):
	arr = list(map(int, input().split()))
	l.append(arr)
(x, y) = (3, 3)
for i in range(1, 6):
	for j in range(1, 6):
		if l[i - 1][j - 1] == 1:
			print(abs(x - i) + abs(y - j))


for row in range(5):
	index = input().find('1')
	if index >= 0:
		col = index // 2
		print(abs(2 - row) + abs(2 - col))
		break


arr = []
movement = 0
for x in range(5):
	arr_l = [int(arr_i) for arr_i in input().strip().split()]
	arr.append(arr_l)
for row in arr:
	for col in row:
		if col == 1:
			movement = abs(row.index(col) - 2) + abs(arr.index(row) - 2)
print(movement)


a = input().split()
b = input().split()
c = input().split()
d = input().split()
e = input().split()
r = 0
if '1' in a:
	r = a.index('1') + 1
	c = 1
elif '1' in b:
	r = b.index('1') + 1
	c = 2
elif '1' in c:
	r = c.index('1') + 1
	c = 3
elif '1' in d:
	r = d.index('1') + 1
	c = 4
elif '1' in e:
	r = e.index('1') + 1
	c = 5
path = abs(3 - c) + abs(3 - r)
print(path)


array = []
for _ in range(5):
	array.append(list(map(int, input().split(' '))))
(xVal, yVal) = (0, 0)
for x in range(5):
	for y in range(5):
		if array[x][y] == 1:
			(xVal, yVal) = (x + 1, y + 1)
xVal = xVal - 3
yVal = yVal - 3
if xVal < 0:
	xVal = -xVal
if yVal < 0:
	yVal = -yVal
print(xVal + yVal)


line = []
for _ in range(5):
	line.append(list(map(int, input().rstrip().split())))
for (i, j) in enumerate(line):
	if 1 in j:
		(a, b) = (i, j.index(1))
		break
print(abs(a - 2) + abs(b - 2))


l1 = input().split()
l2 = input().split()
l3 = input().split()
l4 = input().split()
l5 = input().split()
l = [l1, l2, l3, l4, l5]
ll = sorted(l)[-1]
col = abs(ll.index('1') - 2)
linen = abs(l.index(ll) - 2)
print(str(linen + col))


l = []
for i in range(5):
	l += [list(map(int, input().rstrip().split()))]
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			row = i
			col = j
			break
ans = abs(2 - row) + abs(2 - col)
print(ans)


matrix = list()
one_location = [0, 0]
steps = 0
for y in range(0, 5):
	user_input = input().replace(' ', '')
	x = user_input.find('1')
	if x != -1:
		one_location = [x, y]
	matrix.append(user_input)
while one_location != [2, 2]:
	if one_location[0] > 2:
		one_location[0] -= 1
		steps += 1
	elif one_location[0] < 2:
		one_location[0] += 1
		steps += 1
	if one_location[1] > 2:
		one_location[1] -= 1
		steps += 1
	elif one_location[1] < 2:
		one_location[1] += 1
		steps += 1
print(steps)


import math

def main():
	for i in range(5):
		li = list(map(int, input().split()))
		for j in range(5):
			if li[j] == 1:
				sumt = abs(2 - i) + abs(2 - j)
	print(sumt)
main()


r = 0
c = 0
for i in range(5):
	s = input()
	if s.count('1') == 1:
		r = i + 1
		s = s.split(' ')
		c = 0
		for q in range(5):
			if s[q] == '1':
				c = q + 1
print(abs(3 - r) + abs(3 - c))


matrix = []
for i in range(5):
	m = input()
	matrix.append(m)
index_i = 1
pos_i = 0
pos_y = 0
for i in matrix:
	if '1' in i:
		pos_i = index_i
		pos_y = i.find('1')
	index_i = index_i + 1
moves = 0

def calc_i():
	if pos_i == 1 or pos_i == 5:
		return 2
	elif pos_i == 2 or pos_i == 4:
		return 1
	elif pos_i == 3:
		return 0
	else:
		return 0

def calc_y():
	if pos_y == 0 or pos_y == 8:
		return 2
	elif pos_y == 2 or pos_y == 6:
		return 1
	elif pos_y == 4:
		return 0
	else:
		pass
moves_i = calc_i()
moves_j = calc_y()
moves = moves_i + moves_j
print(moves)


given = ''
without_spaces = ''
horizontal = []
blank = []
xvar = 0
yvar = 0
for n in range(0, 5):
	given += input()
for n in given:
	if not n == ' ':
		without_spaces += n
for n in range(0, 5):
	for x in range(n * 5, (n + 1) * 5):
		blank.append(without_spaces[x])
	horizontal.append(blank)
	blank = []
for n in range(0, 5):
	if '1' in horizontal[n]:
		yvar = n
for n in range(0, 5):
	if '1' in horizontal[yvar][n]:
		xvar = n
distance = abs(2 - xvar) + abs(2 - yvar)
print(distance)


def beautiful(m):
	r = 0
	c = 0
	for fila in range(5):
		for col in range(5):
			if m[fila][col] == '1':
				r = fila
				c = col
	cont = 0
	if r > 2:
		cont += r - 2
	else:
		cont += 2 - r
	if c > 2:
		cont += c - 2
	else:
		cont += 2 - c
	return cont
matrix = []
for i in range(5):
	ren = input()
	ren = ren.split()
	matrix.append(ren)
contador = beautiful(matrix)
print(contador)


def getLines(num):
	inputLines = []
	for i in range(0, num):
		line = input()
		if line:
			inputLines.append(line)
		else:
			break
	return inputLines

def notZeroPow(num, p):
	return True if num >= 1 and num <= pow(10, p) else False
lines = getLines(5)
result = 0
mx = []
for l in lines:
	arr = [int(e) for e in l.split()]
	mx.append(arr)
i = [(index, row.index(1)) for (index, row) in enumerate(mx) if 1 in row][0]
r = abs(i[0] - 2)
c = abs(i[1] - 2)
result = c + r
print(result)


def watermelon():
	w = int(input())
	if w % 2 == 0:
		print('YES')
	else:
		print('NO')

def way_too_long_words():
	n = int(input())
	words = [input() for x in range(n)]
	for word in words:
		if len(word) > 10:
			print(f'{word[0]}{len(word) - 2}{word[-1]}')
		else:
			print(word)

def team():
	n = int(input())
	v = [[int(x) for x in input().split()] for i in range(n)]
	o = 0
	for l in v:
		if l.count(1) >= 2:
			o += 1
	print(o)

def next_round():
	(n, k) = map(int, input().split())
	s = [int(x) for x in input().split()]
	o = 0
	i = s[k - 1]
	for j in s:
		if j >= i and j != 0:
			o += 1
	print(o)

def domino_piling():
	import math
	(m, n) = map(int, input().split())
	o = 0
	if m * n < 2:
		print(0)
		exit()
	if m % 2 == 0:
		o = m * n / 2
	elif n % 2 == 0:
		o = m * n / 2
	else:
		o = math.floor(m * n / 2)
	print(int(o))

def bitplusplus():
	n = int(input())
	s = [input() for i in range(n)]
	o = 0
	for j in s:
		if '++' in j:
			o += 1
		if '--' in j:
			o -= 1
	print(o)

def petya_and_strings():
	a = input().lower()
	b = input().lower()
	c = [a, b]
	c.sort()
	if a == b:
		print(0)
	elif b == c[0]:
		print(1)
	elif a == c[0]:
		print(-1)

def beautiful_matrix():
	for i in range(5):
		r = [int(x) for x in input().split()]
		if 1 in r:
			xmove = abs(r.index(1) - 2)
			ymove = abs(i - 2)
			o = xmove + ymove
	print(o)
beautiful_matrix()


L = []
for i in range(5):
	s = input().split()
	L.append(list(s))
for i in range(5):
	for j in range(5):
		if L[i][j] == '1':
			row = i
			col = j
x = abs(row - 2) + abs(col - 2)
print(x)


l = []
p = 0
q = 0
for i in range(5):
	temp = input('')
	l.append(list(map(int, temp.split(' '))))
for i in range(len(l)):
	for j in range(len(l[i])):
		if l[i][j] == 1:
			p = i
			q = j
			break
print(abs(2 - p) + abs(2 - q))


list = []
result = 0
for iteration in range(5):
	list += input().split()
position = list.index('1')
(row, col) = (position // 5, position % 5)
print(abs(2 - row) + abs(2 - col))


import sys
readline = sys.stdin.readline
for row in range(5):
	line = readline().split()
	for column in range(5):
		if line[column] == '1':
			x = row + 1
			y = column + 1
print(abs(3 - x) + abs(3 - y))


import math
a1 = input().split()
a2 = input().split()
a3 = input().split()
a4 = input().split()
a5 = input().split()
findrow = 0
findcol = 0
ca1 = 0
for i in range(5):
	if a1[i] == '1':
		ca1 = i + 1
		findcol = ca1
ca2 = 0
for i in range(5):
	if a2[i] == '1':
		ca2 = i + 1
		findcol = ca2
ca3 = 0
for i in range(5):
	if a3[i] == '1':
		ca3 = i + 1
		findcol = ca3
ca4 = 0
for i in range(5):
	if a4[i] == '1':
		ca4 = i + 1
		findcol = ca4
ca5 = 0
for i in range(5):
	if a5[i] == '1':
		ca5 = i + 1
		findcol = ca5
if ca1 != 0:
	findrow = 1
if ca2 != 0:
	findrow = 2
if ca3 != 0:
	findrow = 3
if ca4 != 0:
	findrow = 4
if ca5 != 0:
	findrow = 5
drow = 3 - findrow
drow = math.sqrt(drow ** 2)
dcol = 3 - findcol
dcol = math.sqrt(dcol ** 2)
final = drow + dcol
final = int(final)
print(final)


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
coords = None
moves = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			coords = (i, j)
moves = abs(coords[0] - 2) + abs(coords[1] - 2)
print(moves)


a = [[int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()], [int(x) for x in input().split()]]
ans = 0
for i in range(len(a)):
	for k in range(len(a[i])):
		if a[i][k] == 1:
			ans = abs(2 - i) + abs(2 - k)
			break
print(ans)


for i in range(5):
	a = input()
	a = a.split(' ')
	for j in range(len(a)):
		if a[j] == '1':
			n = i + 1
			m = j + 1
print(abs(n - 3) + abs(3 - m))


l = []
for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	l.append(a)
	l.append(b)
	l.append(c)
	l.append(d)
	l.append(e)
if l.index(1) == 7 or l.index(1) == 11 or l.index(1) == 13 or (l.index(1) == 17):
	print(1)
elif l.index(1) == 6 or l.index(1) == 8 or l.index(1) == 16 or (l.index(1) == 18) or (l.index(1) == 10) or (l.index(1) == 2) or (l.index(1) == 14) or (l.index(1) == 22):
	print(2)
elif l.index(1) == 0 or l.index(1) == 4 or l.index(1) == 20 or (l.index(1) == 24):
	print(4)
elif l.index(1) == 12:
	print(0)
else:
	print(3)


n1 = input().split()
n2 = input().split()
n3 = input().split()
n4 = input().split()
n5 = input().split()
if n1.count('1') > 0:
	s = n1.index('1')
	w = s - 2
	if w < 0:
		w = w * -1
	print(w + 2)
elif n2.count('1') > 0:
	s = n2.index('1')
	w = s - 2
	if w < 0:
		w = w * -1
	print(w + 1)
elif n3.count('1') > 0:
	s = n3.index('1')
	w = s - 2
	if w < 0:
		w = w * -1
	print(w)
elif n4.count('1') > 0:
	s = n4.index('1')
	w = s - 2
	if w < 0:
		w = w * -1
	print(w + 1)
elif n5.count('1') > 0:
	s = n5.index('1')
	w = s - 2
	if w < 0:
		w = w * -1
	print(w + 2)


l = [0, 0, 0, 0, 0]
m = 0
for i in range(0, 5):
	l[i] = list(map(int, input().split()))
while l[2][2] != 1:
	for i in l:
		if 1 in i:
			r = l.index(i)
			c = i.index(1)
			l[r][c] = 0
			if r < 2:
				r += 1
				m += 1
			elif r > 2:
				r -= 1
				m += 1
			if c < 2:
				c += 1
				m += 1
			elif c > 2:
				c -= 1
				m += 1
			l[r][c] = 1
print(m)


mat = [[int(x) for x in input().split()] for _ in range(5)]
ii = jj = 0
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			ii = i
			jj = j
			break
print(abs(ii - 2) + abs(jj - 2))


for i in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		m = i + 1
		n = row.index(1) + 1
		out = abs(m - 3) + abs(n - 3)
print(out)


fila = 0
while True:
	entrada = input()[::2]
	if '1' in entrada:
		print(abs(fila - 2) + abs(entrada.index('1') - 2))
		break
	fila += 1


s = 0
j = 0
b = 0
for i in range(5):
	a = list(map(int, input().split()))
	if 1 in a:
		j = a.index(1)
		b = i
print(abs(3 - b - 1) + abs(3 - j - 1))


row = 5
col = 5
ls = []
for r in range(0, row, 1):
	ls.append([])
	for l in range(1):
		s = ls[r] = input().strip().split(' ')
		if '1' in s:
			p = r
			d = ls[r].index('1')
pos = abs(2 - p) + abs(2 - d)
print(pos)


x1 = input()
x2 = input()
x3 = input()
x4 = input()
x5 = input()
l = (x1.split(), x2.split(), x3.split(), x4.split(), x5.split())
for i in range(5):
	for j in range(5):
		x = int(l[i][j])
		if x == 1:
			print(abs(i - 2) + abs(j - 2))
			break


for i in range(5):
	l = input().split()
	for j in range(5):
		if l[j] == '1':
			m = i
			n = j
print(abs(m - 2) + abs(n - 2))


import math
ans = 0
maxi = []
for i in range(0, 5):
	x = [int(x) for x in input().split()]
	maxi.append(x)
for list in maxi:
	if list.count(1) == 1:
		ans = abs(3 - maxi.index(list) - 1) + abs(3 - list.index(1) - 1)
print(ans)


a = []
for i in range(5):
	a.append(input().split())
row = 0
col = 0
for i in range(5):
	if '1' in a[i]:
		row = i + 1
		break
col = a[row - 1].index('1') + 1
print(abs(3 - row) + abs(3 - col))


a = []
(e, f) = (0, 0)
for i in range(5):
	b = list(map(int, input().split()))
	a.append(b)
for (i, j) in enumerate(a):
	if 1 in j:
		e = i
		f = j.index(1)
print(abs(2 - e) + abs(2 - f))


for k in range(5):
	a = list(map(int, input().split()))
	for x in range(5):
		if a[x] == 1:
			l = abs(x + 1 - 3)
			c = k + 1
if c != 3:
	print(l + abs(c - 3))
else:
	print(l)


a = []
for _ in range(5):
	a.append(input().split())
for i in range(len(a)):
	if '1' in a[i]:
		print(abs(2 - a[i].index('1')) + abs(2 - i))


m = []
for i in range(5):
	fila = list(map(int, input().split()))
	m.append(fila)
	if 1 in fila:
		posx = i
		for j in range(5):
			if fila[j] == 1:
				posy = j
moves = abs(posx - 2) + abs(posy - 2)
print(moves)


count = 0
re = 0
k = 0
for i in range(1, 6):
	arr = list(map(int, input().split(' ')))
	count = 0
	for j in range(len(arr)):
		if arr[j] == 1:
			re = i
			k = count + 1
			break
		else:
			count += 1
print(abs(3 - re) + abs(3 - k))


def solver():
	for i in range(5):
		row = list(map(int, input().split()))
		for (j, el) in enumerate(row):
			if el == 1:
				res = abs(j - 2) + abs(i - 2)
				print(res)
solver()


found = False
i = 0
y = 0
x = 0
while not found:
	line = input().split()
	j = 0
	for elem in line:
		if elem == '1':
			found = True
			y = i
			x = j
		j += 1
	i += 1
print(abs(2 - y) + abs(2 - x))


out = 0
for i in range(5):
	row = input().split()
	tracker = 0
	for j in range(5):
		if row[j] == '1':
			tracker = j
			out = abs(3 - (i + 1)) + abs(j + 1 - 3)
			break
	if out:
		break
	elif i + 1 == 3 and tracker + 1 == 3:
		out = 0
		break
print(out)


a = []
posi = -1
posj = -1
for i in range(5):
	x = [int(tmp) for tmp in input().split()]
	a.append(x)
for i in range(len(a)):
	for j in range(len(a[i])):
		if a[i][j] == 1:
			posi = i
			posj = j
print(abs(posi - 2) + abs(posj - 2))


M = []
for _ in range(5):
	M.append([int(i) for i in input().split()])
for i in range(5):
	for j in range(5):
		if M[i][j] == 1:
			c = abs(i - 2) + abs(j - 2)
			print(c)


x = input()
r = input()
n = input()
s = input()
y = input()
if '1' in x:
	c = x.find('1')
	if c == 4:
		print(2)
	elif c == 0 or c == 8:
		print(4)
	else:
		print(3)
elif '1' in y:
	c = y.find('1')
	if c == 4:
		print(2)
	elif c == 0 or c == 8:
		print(4)
	else:
		print(3)
elif '1' in r:
	c = r.find('1')
	if c == 4:
		print(1)
	elif c == 0 or c == 8:
		print(3)
	else:
		print(2)
elif '1' in s:
	c = s.find('1')
	if c == 4:
		print(1)
	elif c == 0 or c == 8:
		print(3)
	else:
		print(2)
else:
	c = n.find('1')
	if c == 4:
		print(0)
	elif c == 0 or c == 8:
		print(2)
	else:
		print(1)


m = []
r0 = c0 = None
for i in range(5):
	r = list(map(int, input().split()))
	if 1 in r:
		r0 = i
		c0 = r.index(1)
	m.append(r)
print(abs(r0 - 2) + abs(c0 - 2))


c = 0
a = []
while c < 5:
	b = input()
	l = b.split()
	a.append(l)
	c += 1
for i in range(len(a)):
	for j in range(len(a)):
		if a[i][j] == '1':
			i = i - 2
			j = j - 2
			if i < 0:
				i = i * -1
			if j < 0:
				j = j * -1
			print(i + j)
			break


n = 5
matrix = []
(x, y) = (0, 0)

def manhatan(i, j, x, y):
	return abs(i - x) + abs(j - y)
for rc in range(n):
	row = list(map(int, input().split()))
	for i in range(len(row)):
		if row[i] == 1:
			(x, y) = (rc, i)
			break
	matrix.append(row)
print(manhatan(x, y, 2, 2))


matrix = []
coords = [0, 0]
for t in range(5):
	n = [x for x in input().split()]
	if '1' in n:
		coords[0] = t
		coords[1] = n.index('1')
dy = abs(coords[0] - 2)
dx = abs(coords[1] - 2)
print(dx + dy)


matrix = []
location_one = []
for i in range(5):
	row = list(map(int, input().split(' ')))
	for j in range(len(row)):
		if row[j] == 1:
			location_one.append(i)
			location_one.append(j)
	matrix.append(row)
moves = 0
if location_one[0] != 2:
	moves += abs(location_one[0] - 2)
if location_one[1] != 2:
	moves += abs(location_one[1] - 2)
print(moves)


a = []
for i in range(5):
	temp = list(map(int, input().split()))
	a.append(temp)
	if temp.count(1) != 0:
		(x, y) = (i, temp.index(1))
print(abs(2 - x) + abs(2 - y))


Matrix = []
row = 0
col = 0
for i in range(1, 6):
	x = list(map(int, input().split()))
	if 1 in x:
		row = i
		col = x.index(1) + 1
	Matrix.append(x)
result = abs(3 - row) + abs(3 - col)
print(result)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
A = []
for r in range(5):
	A.append([int(x) for x in input().split()])
(row, col) = (-1, -1)
for r in range(5):
	for c in range(5):
		if A[r][c] == 1:
			row = r + 1
			col = c + 1
ans = abs(row - 3) + abs(col - 3)
print(ans)


matrix = [list(map(int, input().split())) for i in range(5)]
cntr = 0
indexList = 0
indexNum = 0
if matrix[2][2] != 1:
	for x in matrix:
		if 1 in x:
			indexList = matrix.index(x)
			indexNum = x.index(1)
	for _ in range(5):
		if indexNum != 2:
			if indexNum > 2:
				indexNum -= 1
				cntr += 1
			elif indexNum < 2:
				indexNum += 1
				cntr += 1
		if indexList != 2:
			if indexList > 2:
				indexList -= 1
				cntr += 1
			elif indexList < 2:
				indexList += 1
				cntr += 1
	print(cntr)
else:
	print(0)


l = list()
for i in range(5):
	l1 = list(input().split())
	l.append(l1)
	if '1' in l1:
		ligne = i + 1
		colonne = l1.index('1') + 1
moves = abs(ligne - 3) + abs(colonne - 3)
print(moves)


m = []
for i in range(5):
	a = [int(k) for k in input().split()]
	m.append(a)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			p = i
			q = j
r = abs(2 - p)
s = abs(2 - q)
res = r + s
print(res)


matrix = []
for i in range(5):
	a = []
	a = input().split()
	matrix.append(a)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			mi = i
			mj = j
c = abs(mi - 2) + abs(mj - 2)
print(c)


one_row = 0
one_column = 0
for i in range(1, 6):
	row = input().replace(' ', '')
	if '1' in row:
		one_row = i
		one_column = row.index('1') + 1
minimum_moves = abs(one_row - 3) + abs(one_column - 3)
print(minimum_moves)


dis = [2, 1, 0, 1, 2]
i = 1
while i <= 5:
	c = input().split()
	if '1' in c:
		R = dis[int(c.index('1'))] + int(dis[i - 1])
		break
	i = i + 1
print(R)


a = [[0] * 5 for _ in range(0, 5)]
x = 0
y = 0
count = 0
for i in range(0, 5):
	a[i] = list(map(int, input().split()))
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == 1:
			x = i
			y = j
if x == 2 and y == 2:
	count = 0
else:
	if x > 2:
		while x > 2:
			x -= 1
			count += 1
			if x == 2:
				break
	else:
		while x < 2:
			x += 1
			count += 1
			if x == 2:
				break
	if y > 2:
		while y > 2:
			y -= 1
			count += 1
			if y == 2:
				break
	else:
		while y < 2:
			y += 1
			count += 1
			if y == 2:
				break
print(count)


import sys

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

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def beautify(arr):
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				(r, c) = (i, j)
	res = abs(2 - r) + abs(2 - c)
	return res

def input_matrix():
	mat = []
	for i in range(5):
		mat.append(l())
	print(beautify(mat))
input_matrix()


f = 1
for j in range(5):
	ri = [int(i) for i in input().split()]
	if 1 in ri:
		c = ri.index(1) + 1
		r = j + 1
	f += 1
m = abs(3 - r) + abs(3 - c)
print(m)


x = 1
y = 1
for i in range(5):
	a = list(map(int, input().split()))
	for z in range(len(a)):
		if a[z] == 1:
			y = z + 1
			x = i + 1
			pass
print(abs(3 - x) + abs(3 - y))


li = [[int(x) for x in input().split()] for i in range(5)]
for i in range(5):
	for j in range(5):
		if li[i][j] == 1:
			note = (i + 1, j + 1)
			break
print(abs(note[0] - 3) + abs(note[1] - 3))


matrix = []
pos = []
for i in range(5):
	lst = list(map(int, input().split()))
	for item in lst:
		if item == 1:
			pos.extend([i, lst.index(1)])
	matrix.append(lst)
print(abs(pos[0] - 2) + abs(pos[1] - 2))


import sys

def solution(row_idx, row):
	center_row = 2
	center_column = 2
	n_moves_row = abs(row_idx - 2)
	num_row = row.split()
	for (i, num) in enumerate(num_row):
		if num == '1':
			n_moves_col = abs(i - 2)
	result = n_moves_col + n_moves_row
	return result
row = sys.stdin.readline()
while row:
	rows = []
	rows.append(row)
	for i in range(5):
		if '1' in row:
			row_idx = i
			print(solution(row_idx, row))
		row = sys.stdin.readline()
		rows.append(row)


(desx, desy) = (2, 2)
x = 0
y = 0
for i in range(5):
	(a, b, c, d, e) = input().split()
	if int(a) == 1:
		x = i
		y = 0
	if int(b) == 1:
		x = i
		y = 1
	if int(c) == 1:
		x = i
		y = 2
	if int(d) == 1:
		x = i
		y = 3
	if int(e) == 1:
		x = i
		y = 4
print(abs(desx - x) + abs(desy - y))


n = 5
matrix = []
i_one = -1
j_one = -1

def module(x):
	if x < 0:
		return -1 * x
	else:
		return x
for i in range(n):
	s = input()
	line = list(map(int, s.split()))
	for j in range(n):
		if line[j] == 1:
			i_one = i + 1
			j_one = j + 1
			break
width = 3 - i_one
height = 3 - j_one
print(module(width) + module(height))


matrix = []
for i in range(5):
	matrix.append(list(map(int, input().split())))
for row in matrix:
	for cell in row:
		if cell == 1:
			one_x = row.index(cell) + 1
			one_y = matrix.index(row) + 1
			break
		else:
			continue
answer = abs(one_x - 3) + abs(one_y - 3)
print(answer)


for i in range(5):
	a = [int(x) for x in input().split()]
	if sum(a) > 0:
		col = abs(3 - a.index(1) - 1)
		row = abs(3 - i - 1)
		break
print(col + row)


ctr = 0
st = ''
for i in range(1, 6):
	s = input()
	for k in s:
		if k != ' ':
			st = st + k
	for j in st:
		ctr += 1
		if j == '1':
			x = i
			y = ctr
	ctr = 0
	st = ''
c = abs(x - 3) + abs(y - 3)
print(c)


def swap_rows(m, x, y):
	global row_one
	for c in range(5):
		tmp = m[x][c]
		m[x][c] = m[y][c]
		m[y][c] = tmp
	row_one = y
	return m

def swap_cols(m, x, y):
	global col_one
	for d in range(5):
		tmp = m[d][x]
		m[d][x] = m[d][y]
		m[d][y] = tmp
	col_one = y
	return m
first_row = [int(x) for x in input().split(' ')]
second_row = [int(x) for x in input().split(' ')]
third_row = [int(x) for x in input().split(' ')]
fourth_row = [int(x) for x in input().split(' ')]
fifth_row = [int(x) for x in input().split(' ')]
a = [first_row, second_row, third_row, fourth_row, fifth_row]
row_one = 0
col_one = 0
count = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			row_one = i
			col_one = j
while row_one != 2 or col_one != 2:
	if row_one < 2:
		a = swap_rows(a, row_one, row_one + 1)
		count += 1
	if row_one > 2:
		a = swap_rows(a, row_one, row_one - 1)
		count += 1
	if col_one < 2:
		a = swap_cols(a, col_one, col_one + 1)
		count += 1
	if col_one > 2:
		a = swap_cols(a, col_one, col_one - 1)
		count += 1
print(count)


mat = []
one = []
for i in range(1, 6):
	tmp = list(map(int, input().split()))
	if 1 in tmp:
		one.append(i)
		one.append(tmp.index(1) + 1)
	mat.append(tmp)
print(abs(3 - one[0]) + abs(3 - one[1]))


l = []
for i in range(5):
	a = list(map(int, input().split()))
	l.append(a)
c = 1
r = 0
for i in l:
	for j in i:
		if j == 0:
			c += 1
		else:
			break
	r += 1
	if c != 6:
		break
	else:
		c = 1
print(abs(3 - c) + abs(3 - r))


x = -1
y = -1
for k in range(5):
	arr = list(map(int, input().split()))
	if 1 in arr:
		x = arr.index(1) + 1
		y = k + 1
res = abs(3 - x) + abs(3 - y)
print(res)


row = 0
column = 0
for i in range(5):
	value = input()
	if value > '0 0 0 0 0':
		row = i
		for j in range(0, 9, 2):
			if value[j] == '1':
				column = j // 2
				break
		break
print(abs(row - 2) + abs(column - 2))


def read_int_row():
	return [int(x) for x in input().split()]

def find_1(matx):
	for (i, row) in enumerate(matx):
		for (j, val) in enumerate(row):
			if val == 1:
				return (i, j)

def chess_distance(src, dest):
	row_mov = abs(src[0] - dest[0])
	col_mov = abs(src[1] - dest[1])
	return row_mov + col_mov
matx = []
for _ in range(5):
	matx.append(read_int_row())
loc_of_1 = find_1(matx)
center = (2, 2)
print(chess_distance(center, loc_of_1))


row = 0
moves = 0
while row < 5:
	columns = list(map(int, input().split()))
	try:
		col = columns.index(1)
		moves = abs(2 - row) + abs(2 - col)
	except:
		pass
	row += 1
print(moves)


matrix = []
for i in range(5):
	l = list(map(int, input().split()))
	matrix.append(l)
current_index = [0, 0]
for i in range(len(matrix)):
	for j in range(len(matrix[i])):
		if matrix[i][j] == 1:
			current_index = [i, j]
count = 0
while current_index != [2, 2]:
	if current_index[1] != 2:
		if current_index[1] < 2:
			current_index[1] += 1
		else:
			current_index[1] -= 1
		count += 1
	if current_index[0] != 2:
		if current_index[0] < 2:
			current_index[0] += 1
		else:
			current_index[0] -= 1
		count += 1
print(count)


matrix = []
for i in range(0, 5):
	matrix_input = list(map(int, input().split()))
	matrix.append(matrix_input)
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == 1:
			print(abs(2 - i) + abs(2 - j))
			break


for i in range(1, 6):
	x = input()
	if x != '0 0 0 0 0':
		y = x.find('1') / 2 + 1
		print(int(abs(3 - i) + abs(3 - y)))


n = 5
a = []
for x in range(n):
	a.append([int(y) for y in input().split()])
for i in range(n):
	for j in range(n):
		if a[i][j] == 1:
			r = i
			c = j
r = abs(r - 2)
c = abs(c - 2)
print(r + c)


t = 5
for h in range(t):
	ls1 = list(map(int, input().split()))
	for i in ls1:
		if i == 1:
			k = ls1.index(i)
			jj = h
			break
n = abs(2 - k)
b = abs(2 - jj)
sum = n + b
print(sum)


for i in range(1, 6):
	x = input()
	if '1' in x:
		row_n = i
		break
x = x.replace(' ', '')
r_steps = abs(row_n - 3)
c_steps = abs(x.find('1') + 1 - 3)
print(r_steps + c_steps)


counter = 0
init_row = 3
init_col = 3
row = 0
col = 0
matrix = []
for i in range(0, 5):
	inpt = input().split(' ')
	matrix.append(inpt)
for i in enumerate(matrix):
	if '1' in i[1]:
		col = i[1].index('1') + 1
		row = i[0] + 1
		break
while True:
	if row == init_row and col == init_col:
		break
	if row != init_row:
		if row > init_row:
			row -= 1
			counter += 1
		else:
			row += 1
			counter += 1
	if col != init_col:
		if col > init_col:
			col -= 1
			counter += 1
		else:
			col += 1
			counter += 1
print(counter)


x = []
a = 0
b = 0
x1 = list(map(int, input().split()))
x2 = list(map(int, input().split()))
x3 = list(map(int, input().split()))
x4 = list(map(int, input().split()))
x5 = list(map(int, input().split()))
x.append(x1)
x.append(x2)
x.append(x3)
x.append(x4)
x.append(x5)
for i in range(5):
	for j in range(5):
		if x[i][j] == 1:
			(a, b) = (i, j)
			break
z = abs(2 - a) + abs(2 - b)
print(z)


from math import *
(a, fi, se) = ([], None, None)
for i in range(5):
	li = list(map(int, input().split()))
	if 1 in set(li):
		(fi, se) = (i, li.index(1))
	a.append(li)
middle = ceil(5 / 2) - 1
print(abs(middle - fi) + abs(middle - se))


(i, j) = (0, 0)
for k in range(5):
	t = list(map(int, input().split()))
	if sum(t) > 0:
		i = k
		for q in range(5):
			if t[q] == 1:
				j = q
				break
print(abs(i - 2) + abs(j - 2))


from math import fabs
TARGET_VALUE = 3
MATRIX_SIZE = 5
matrix = {}
x = y = 0
for i in range(MATRIX_SIZE):
	matrix[i] = [int(x) for x in input().split()]
	for j in range(MATRIX_SIZE):
		if matrix[i][j] == 1:
			x = j + 1
			y = i + 1
res = fabs(TARGET_VALUE - x) + fabs(TARGET_VALUE - y)
print(int(res))


m = [[] * 5] * 5
x = 0
for i in m:
	i = input().split(' ')
	m[x] = i
	x += 1
mid = [2, 2]
one = [0, 0]
i = 0
while i != 5:
	j = 0
	while j != 5:
		if m[i][j] == '1':
			one = [i, j]
		j += 1
	i += 1
mov = abs(mid[0] - one[0]) + abs(mid[1] - one[1])
print(mov)


answ = 0
a = [0]
for i in range(5):
	a += list(map(int, input().split()))
b = a.index(1)
if b % 5 == 0:
	c = b // 5
else:
	c = b // 5 + 1
d = abs(b - (c - 1) * 5)
answ += abs(c - 3)
answ += abs(d - 3)
print(answ)


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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
for i in range(5):
	line = invr()
	for w in range(5):
		if next(line) == 1:
			print(abs(2 - i) + abs(2 - w))


matrix = []
while True:
	try:
		line = input()
		matrix.append(line.split())
	except EOFError:
		break
for (i, row) in enumerate(matrix):
	for (j, col) in enumerate(row):
		if matrix[i][j] == '1':
			result = abs(2 - i) + abs(2 - j)
			print(result)
			break


(x, y) = (-1, -1)
for c in range(5):
	line = input().replace(' ', '')
	i = line.find('1')
	if i > -1:
		y = c
		x = i
		break
print(abs(2 - x) + abs(2 - y))


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

def zz(matrix):
	for (e, row) in enumerate(matrix):
		for (e2, x) in enumerate(row):
			if x == 1:
				return abs(2 - e) + abs(2 - e2)
print(zz(matrix))


def main():
	n = m = 0
	for i in range(5):
		line = [int(x) for x in input().strip().split()]
		for (j, el) in enumerate(line):
			if el == 1:
				(n, m) = (i, j)
	print(abs(2 - n) + abs(2 - m))
main()


index = 0
col = 0
for i in range(5):
	n = input()
	if n.find('1') != -1:
		col = n.find('1') // 2
		break
	index += 1
moves = abs(2 - index) + abs(2 - col)
print(moves)


for i in range(1, 6):
	x = list(map(int, input().split()))
	for j in range(0, len(x)):
		if x[j] == 1:
			if j > 2 or j == 2:
				if i > 3 or i == 3:
					k = i - 3 + j - 2
				else:
					k = 3 - i + j - 2
			elif i > 3 or i == 3:
				k = i - 3 + 2 - j
			else:
				k = 3 - i + 2 - j
			break
print(k)


c = 0
for i in range(1, 6):
	a = list(input())
	if '1' in a:
		c = c + abs(i - 3)
		for x in range(1, 10):
			if a[x - 1] == '1':
				c = c + abs((x + 1) / 2 - 3)
print(int(c))


m = []
n = 0
rezult = 0
for i in range(5):
	m.append(list(map(int, input().split())))
for i in range(5):
	if 1 in m[i]:
		n = i
rezult += abs(n - 2)
rezult += abs(m[n].index(1) - 2)
print(rezult)


a = [[0] * 5 for _ in range(5)]
for i in range(5):
	a[i] = [int(j) for j in input().strip().split(' ')]
	for j in range(5):
		if a[i][j] == 1:
			x = i
			y = j
t1 = x - 2
t2 = y - 2
if t1 < 0:
	t1 = t1 * -1
if t2 < 0:
	t2 = t2 * -1
t = t1 + t2
print(t)


matrix = []
for i in range(5):
	data = list(map(int, input().split()))
	if 1 in data:
		line = i + 1
		row = data.index(1) + 1
	matrix.append(data)
print(abs(3 - line) + abs(3 - row))


(m, n) = (0, 0)
for a in range(5):
	l = input()
	if '1' in l:
		m = a + 1
		n = l.index('1') // 2 + 1
		break
print(abs(3 - m) + abs(3 - n))


x_index = 0
y_index = 0
for x in range(5):
	line = input().split(' ')
	for y in range(len(line)):
		if line[y] == '1':
			y_index = y
			x_index = x
result = abs(x_index - 2) + abs(y_index - 2)
print(result)


b = []
e = 0
for i in range(0, 5):
	a = list(map(int, input().split()))
	if 1 in a:
		e = i
	b.append(a)
t = b[e]
a = 0
if t.index(1) < 2:
	a = 2 - t.index(1)
elif t.index(1) > 2:
	a = t.index(1) - 2
if e < 2:
	a += 2 - e
elif e > 2:
	a += e - 2
print(a)


a = []
for i in range(5):
	numbers = [int(n) for n in input().split()]
	a.append(numbers)
if a[2][2] == 1:
	print(0)
else:
	for i in range(5):
		for j in range(5):
			if a[i][j] == 1:
				calc = abs(2 - i) + abs(2 - j)
				print(calc)


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

def getIJ(matrix):
	for i in range(len(matrix)):
		for j in range(len(matrix[0])):
			if matrix[i][j] == 1:
				return (i, j)
(i, j) = getIJ(mat)
moves = 0
if i != 2:
	while i > 2:
		i -= 1
		moves += 1
	while i < 2:
		i += 1
		moves += 1
if j != 2:
	while j > 2:
		j -= 1
		moves += 1
	while j < 2:
		j += 1
		moves += 1
print(moves)


for i in range(1, 6):
	line = list(map(int, input().split()))
	if 1 in line:
		I = i
		J = line.index(1) + 1
print(abs(I - 3) + abs(J - 3))


import math
x = -1
y = -1
for i in range(1, 6):
	_str = input()
	for j in range(0, 9, 2):
		if _str[j] != '0':
			x = i
			y = math.floor(j / 2 + 1)
if x < 3:
	x = 3 - x
else:
	x = x - 3
if y < 3:
	y = 3 - y
else:
	y = y - 3
print(x + y)


m = []
count = 0
for i in range(5):
	l = list(input().split())
	if '1' in l:
		if i < 2:
			count += 2 - i
		elif i > 2:
			count += i - 2
		if l.index('1') < 2:
			count += 2 - l.index('1')
		elif l.index('1') > 2:
			count += l.index('1') - 2
print(count)


for i in range(5):
	try:
		j = input().index('1') // 2
		print(abs(i - 2) + abs(j - 2))
		break
	except:
		pass


def getCoordinate(mat):
	for i in range(5):
		for j in range(5):
			if mat[i][j] == '1':
				return (i, j)
mat = []
for i in range(5):
	mat.append(input().split())
(row, col) = getCoordinate(mat)
print(abs(row - 2) + abs(col - 2))


def main():
	matrix = []
	for i in range(5):
		matrix.append(input().split())
	for i in range(len(matrix)):
		for j in range(len(matrix[i])):
			if matrix[i][j] == '1':
				print(abs(i - 2) + abs(j - 2))
main()


arr = []
for i in range(0, 5):
	a = map(int, input().split())
	arr.append(list(a))
ctr = 0
i = 0
while i < len(arr):
	a = 0
	while a < len(arr[i]):
		if arr[i][a] == 1:
			if arr[i].index(1) == 2 and arr.index(arr[i]) == 2:
				print(0)
				exit()
			if arr[i].index(1) != 2:
				inner = arr[i].index(1)
				if inner == 4 or inner == 0:
					ctr += 2
				else:
					ctr += 1
				outer = arr.index(arr[i])
				if outer != 2:
					if outer == 1 or outer == 3:
						ctr += 1
					else:
						ctr += 2
				break
			else:
				outer = arr.index(arr[i])
				if outer == 1 or outer == 3:
					ctr += 1
				else:
					ctr += 2
				break
		a += 1
	i += 1
print(ctr)


row = 0
column = 0
for i in range(0, 5):
	a = list(map(int, input().split()))
	if a.count(1) == 1:
		row = i + 1
		column = a.index(1) + 1
print(abs(row - 3) + abs(column - 3))


for i in range(5):
	s = input()
	if '1' in s:
		step = abs(i - 2) + abs(s.index('1') // 2 - 2)
print(step)


for i in range(5):
	a = input().split()
	k = 0
	for j in a:
		k += 1
		if j != '0':
			maxtrix_row = i + 1
			maxtrix_column = k
			break
print(abs(3 - maxtrix_row) + abs(3 - maxtrix_column))


matrix = []
for i in range(5):
	list1 = [int(s) for s in input().split(' ')]
	matrix.append(list1)
oneR = 0
oneC = 0
for i in range(5):
	for n in range(5):
		if matrix[i][n] == 1:
			oneR = i + 1
			oneC = n + 1
moveR = abs(3 - oneR)
moveC = abs(3 - oneC)
print(moveR + moveC)


matrix = []
for i in range(5):
	l = list(map(int, input().strip().split()))
	matrix.append(l)
main = []
row = 0
for i in range(5):
	if 1 in matrix[i]:
		row = i
		main = matrix[i]
col = 0
for i in range(5):
	if main[i] == 1:
		col = i
dist = abs(2 - row) + abs(2 - col)
print(int(dist))


t = []
for x in range(5):
	t.append(input().split())
for x in t:
	if '1' in x:
		zero = t.index(x)
		one = x.index('1')
print(abs(2 - zero) + abs(2 - one))


m = [input() for i in range(5)]
m = [[int(x) for x in k.split()] for k in m]
for (i, r) in enumerate(m):
	if sum(r) == 1:
		if i == 0 or i == 4:
			a = 2
		elif i == 1 or i == 3:
			a = 1
		else:
			a = 0
		break
if r[0] == 1 or r[4] == 1:
	print(a + 2)
elif r[1] == 1 or r[3] == 1:
	print(a + 1)
else:
	print(a)


a = []
for i in range(5):
	s = list(map(int, input().split()))
	a.append(s)
k = 0
s = 0
for i in range(len(a)):
	if 1 in a[i]:
		k = a[i].index(1)
		s = i
		break
if s == 0 or s == 4:
	if k == 0 or k == 4:
		print(4)
	elif k == 1 or k == 3:
		print(3)
	elif k == 2:
		print(2)
elif s == 1 or s == 3:
	if k == 0 or k == 4:
		print(3)
	elif k == 1 or k == 3:
		print(2)
	elif k == 2:
		print(1)
elif s == 2:
	if k == 0 or k == 4:
		print(2)
	elif k == 1 or k == 3:
		print(1)
	elif k == 2:
		print(0)


moves = 0
for i in range(5):
	for (j, v) in enumerate(input().split(' ')):
		if v == '1':
			moves += abs(i - 2) + abs(j - 2)
			break
print(moves)


m = []
i = 0

def mod(n):
	return -n if n < 0 else n
for j in range(5):
	m.append(input().split())
	if '1' in m[j]:
		i = j
print(mod(2 - ''.join(m[i]).find('1')) + mod(i - 2))


rows = []
row = 0
col = 1
for i in range(5):
	rows.append([int(s) for s in input().split(' ')])
for i in rows:
	row += 1
	if int(1) in i:
		col += i.index(1)
		break
moves = abs(3 - col) + abs(3 - row)
print(moves)


l = []
for x in range(0, 5):
	l.append(list(map(int, input().split())))
count = 0
for j in range(0, len(l)):
	for t in range(0, len(l[j])):
		if l[j][t] == 1:
			count += abs(2 - j)
			count += abs(2 - t)
print(count)


l = []
for i in range(5):
	l.append(input().split(' '))
r = 0
c = 0
flag = False
for i in range(5):
	for j in range(5):
		if l[i][j] == '1':
			r = i
			c = j
			flag = True
			break
	if flag is True:
		break
r = abs(r - 2)
c = abs(c - 2)
print(r + c)


a = []
for i in range(5):
	row = list(map(int, input().split()))
	for i in range(len(row)):
		row[i] = int(row[i])
	a.append(row)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			I = i
			J = j
			break
temp = 2 - I
if temp < 0:
	temp = -temp
counter = temp
temp = 2 - J
if temp < 0:
	temp = -temp
counter = counter + temp
print(counter)


mat = []
for i in range(5):
	line = input()
	line = line.split()
	line = [int(i) for i in line]
	mat.append(line)
indexX = 0
indexY = 0
for i in range(len(mat)):
	try:
		indexX = mat[i].index(1)
		indexY = i
	except:
		continue
counter = 0
counter += abs(indexX - 2)
counter += abs(indexY - 2)
print(counter)


diffX = 0
diffY = 0
matrix = []
(x, y) = (0, 0)
for _ in range(5):
	matrix.append(list(map(int, input().split(' '))))
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			x = i
			y = j
if y > 2:
	diffY = 2 - y
else:
	diffY = y - 2
if x > 2:
	diffX = 2 - x
else:
	diffX = x - 2
print(abs(diffX + diffY))


matrix = []
row = []
for i in range(5):
	row = input().split(' ')
	matrix.append(row)
for i in range(5):
	for j in range(5):
		if int(matrix[i][j]) == 1:
			if 2 > i and 2 > j:
				print(2 - i + 2 - j)
			elif 2 > i and 2 < j:
				print(2 - i + j - 2)
			elif 2 > i and 2 == j:
				print(2 - i)
			elif 2 < i and 2 > j:
				print(i - 2 + 2 - j)
			elif 2 < i and 2 < j:
				print(i - 2 + j - 2)
			elif 2 < i and j == 2:
				print(i - 2)
			elif 2 == i and 2 > j:
				print(2 - j)
			elif 2 == i and 2 < j:
				print(j - 2)
			elif 2 == i and 2 == j:
				print(0)
			break


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			(m, n) = (i, j)
			break
t = 0
if m > 2:
	t = t + m - 2
elif m < 2:
	t = t + 2 - m
if n > 2:
	t = t + n - 2
elif n < 2:
	t = t + 2 - n
print(t)


l = []
for _ in range(5):
	l.append(list(map(int, input().split())))
for i in range(len(l)):
	if 1 in l[i]:
		index = [i, l[i].index(1)]
		break
print(abs(index[0] - 2) + abs(index[1] - 2))


import math
mtrx = []
column = 0
row = 0
for i in range(0, 5):
	string = input()
	mtrx.append(string.split(' '))
for i in range(0, 5):
	for j in range(0, 5):
		if int(mtrx[i][j]) == 1:
			row = i - 2
			column = j - 2
answer = math.fabs(row) + math.fabs(column)
print(int(answer))


def move(array, posi):
	if posi == 2:
		return 0
	elif posi > 2:
		return posi - 2
	elif posi < 2:
		return 2 - posi

def odd_location_and_calculation(array):
	check = 0
	for i in range(5):
		for j in range(5):
			if array[i][j] == 1:
				y_coordinate = i
				x_coordinate = j
				break
				check = 1
		if check == 1:
			break
	x_move = move(array, x_coordinate)
	y_move = move(array, y_coordinate)
	return x_move + y_move
array = []
for i in range(5):
	rowArray = list(map(int, input().split(' ')))
	array.append(rowArray)
print(odd_location_and_calculation(array))


from math import fabs
x = []
x.append(list(map(int, input().split())))
x.append(list(map(int, input().split())))
x.append(list(map(int, input().split())))
x.append(list(map(int, input().split())))
x.append(list(map(int, input().split())))
n = 0
for i in x:
	n += 1
	m = 0
	for j in i:
		m += 1
		if j == 1:
			print(int(fabs(m - 3) + fabs(n - 3)))
			break
	else:
		continue
	break


a = []
for i in range(5):
	a += [input().split()]
for i in range(5):
	d = a[i].count('1')
	if d > 0:
		c = i + 1
		e = a[i]
		for x in range(5):
			if int(e[x]) > 0:
				print(abs(2 - x) + abs(3 - c))
				break


from math import fabs
l = []
r = 0
c = 0
for i in range(5):
	x = list(map(int, input().split()))
	for j in range(5):
		if x[j] == 1:
			r = i
			c = j
print(int(fabs(r - 2) + fabs(c - 2)))


n1 = input().split()
n2 = input().split()
n3 = input().split()
n4 = input().split()
n5 = input().split()
row = 0
col = 0
for i in n1:
	if i == '1':
		a = n1.index('1')
		if a == 2:
			col = 0
		if a < 2:
			col = 2 - a
		if a > 2:
			col = a - 2
		if n1:
			row = 2
for i in n2:
	if i == '1':
		a = n2.index('1')
		if a == 2:
			col = 0
		if a < 2:
			col = 2 - a
		if a > 2:
			col = a - 2
		if n2:
			row = 1
for i in n3:
	if i == '1':
		a = n3.index('1')
		if a == 2:
			col = 0
		if a < 2:
			col = 2 - a
		if a > 2:
			col = a - 2
		if n3:
			row = 0
for i in n4:
	if i == '1':
		a = n4.index('1')
		if a == 2:
			col = 0
		if a < 2:
			col = 2 - a
		if a > 2:
			col = a - 2
		if n4:
			row = 1
for i in n5:
	if i == '1':
		a = n5.index('1')
		if a == 2:
			col = 0
		if a < 2:
			col = 2 - a
		if a > 2:
			col = a - 2
		if n5:
			row = 2
rc = row + col
print(rc)


row1 = input().split()
row2 = input().split()
row3 = input().split()
row4 = input().split()
row5 = input().split()
matrix = list([row1, row2, row3, row4, row5])
count = 0
for it in range(0, len(matrix)):
	if '1' in matrix[it]:
		numberOne = matrix[it].index('1')
		while numberOne != 2:
			if numberOne > 2:
				numberOne -= 1
			else:
				numberOne += 1
			count += 1
		while it != 2:
			if it > 2:
				it -= 1
			else:
				it += 1
			count += 1
print(count)


from sys import stdin

def x(A):
	for i in range(len(A)):
		for j in range(len(A[0])):
			if A[i][j] == 1:
				return (i, j)
A = []
for i in range(5):
	k = [int(i) for i in stdin.readline().split()]
	A.append(k)
(r, c) = x(A)
print(abs(r - 2) + abs(c - 2))


def abs(n):
	return -n if n < 0 else n
x = 0
y = 0
for i in range(5):
	temp = input().split(' ')
	if '1' in temp:
		y = temp.index('1')
		x = i
n = abs(2 - x) + abs(2 - y)
print(n)


l = []
for i in range(5):
	n = list(map(int, input().strip().split()))
	l.append(n)
for (index, val) in enumerate(l):
	if 1 in val:
		(i, j) = (index + 1, val.index(1) + 1)
		break
ans = abs(i - 3) + abs(j - 3)
print(ans)


list1 = [int(x) for x in input().split()]
list2 = [int(x) for x in input().split()]
list3 = [int(x) for x in input().split()]
list4 = [int(x) for x in input().split()]
list5 = [int(x) for x in input().split()]
if 1 == list1[0] or 1 == list5[0] or 1 == list1[4] or (1 == list5[4]):
	print('4')
elif 1 == list1[1] or 1 == list5[1] or 1 == list1[3] or (1 == list5[3]) or (1 == list2[0]) or (1 == list2[-1]) or (1 == list4[0]) or (1 == list4[-1]):
	print('3')
elif 1 == list1[2] or 1 == list5[2] or 1 == list3[0] or (1 == list3[-1]) or (1 == list2[1]) or (1 == list2[-2]) or (1 == list4[1]) or (1 == list4[-2]):
	print('2')
elif 1 == list2[2] or 1 == list3[1] or 1 == list3[-2] or (1 == list4[2]):
	print('1')
else:
	print('0')


a = []
for i in range(5):
	temp = list(map(int, input().split()))
	a.append(temp)
beautiful_x = 2
beautiful_y = 2
for x in range(len(a)):
	if 1 in a[x]:
		xpos = x
		for y in range(len(a[x])):
			if a[x][y] == 1:
				ypos = y
y_count = abs(beautiful_y - ypos)
x_count = abs(beautiful_x - xpos)
print(x_count + y_count)


I = 0
J = 0
for i in range(1, 6):
	k = [int(n) for n in input().split(' ')]
	for j in range(1, 6):
		if k[j - 1] == 1:
			I = abs(3 - i)
			J = abs(3 - j)
print(I + J)


for row in range(5):
	col = input().find('1')
	if col > -1:
		break
res = abs(2 - row) + abs(4 - col) // 2
print(res)


def solve(arr):
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				return abs(i - 2) + abs(j - 2)
	return -1
arr = []
for i in range(5):
	arr.append(list(map(int, input().strip().split())))
result = solve(arr)
print(result)


l1 = []
for k in range(5):
	x = input()
	l1.append(x.split())
for i in range(5):
	for j in range(5):
		lt = l1[i]
		if lt[j] == '1':
			remi = i
			remj = j
moves = abs(2 - remi) + abs(2 - remj)
print(moves)


b = [2, 1, 0, 1, 2]
for x in b:
	a = input()
	if '1' in a:
		print(x + b[a.find('1') // 2])


t = []
for i in range(5):
	t.append(input().split())
for i in range(len(t)):
	if '1' in t[i]:
		row = i + 1
for i in range(len(t[row - 1])):
	if t[row - 1][i] == '1':
		col = i + 1
print(abs(3 - col) + abs(3 - row))


i = 0
while i < 5:
	mat = list(map(int, input().split()))
	j = 0
	while j < 5:
		if mat[j] == 1:
			row = i + 1
			col = j + 1
		j += 1
	i += 1
print(abs(row - 3) + abs(col - 3))


row = 0
col = 0
for i in range(5):
	n = list(map(int, input().split()))
	if n.count(1) > 0:
		col = abs(2 - n.index(1))
		row = i
		if row == 2:
			print(col)
		else:
			row = abs(2 - row)
			print(col + row)


inp = []
inp.extend((list(map(int, input().split())) for x in range(5)))
finalXY = 2
for x in inp:
	if 1 in x:
		inix = x.index(1)
		iniy = inp.index(x)
print(abs(inix - finalXY) + abs(iniy - finalXY))


for i in range(5):
	a = input().split(' ')
	if '1' in a:
		ans = (i + 1, a.index('1') + 1)
print(abs(ans[0] - 3) + abs(ans[1] - 3))


a1 = input()
b1 = a1.split()
count1 = 0
c_1 = []
m = 0
for let in b1:
	c_1.append(int(let))
	count1 += int(let)
a2 = input()
b2 = a2.split()
count2 = 0
c2 = []
for let in b2:
	c2.append(int(let))
	count2 += int(let)
a3 = input()
b3 = a3.split()
count3 = 0
c3 = []
for let in b3:
	c3.append(int(let))
	count3 += int(let)
a4 = input()
b4 = a4.split()
count4 = 0
c4 = []
for let in b4:
	c4.append(int(let))
	count4 += int(let)
a5 = input()
b5 = a5.split()
count5 = 0
c5 = []
for let in b5:
	c5.append(int(let))
	count5 += int(let)
if count1 == 1:
	m = 1
if count2 == 1:
	m = 2
if count3 == 1:
	m = 3
if count4 == 1:
	m = 4
if count5 == 1:
	m = 5
d = []
d.append(c_1)
d.append(c2)
d.append(c3)
d.append(c4)
d.append(c5)
e = d[m - 1]
f = e.index(1)
h = f + 1
cou = 0
if h >= 3:
	cou += h - 3
else:
	cou += 3 - h
if m >= 3:
	cou += m - 3
else:
	cou += 3 - m
print(cou)


import re
row = []
for i in range(5):
	row.append(input().split())
for i in range(5):
	if '1' in row[i]:
		rows = i + 1
		column = row[i].index('1') + 1
r = 3 - rows
c = 3 - column
moves = abs(r) + abs(c)
print(moves)


a = input()
b = input()
c = input()
d = input()
e = input()
alist = list(a.split(' '))
blist = list(b.split(' '))
clist = list(c.split(' '))
dlist = list(d.split(' '))
elist = list(e.split(' '))
if '1' in alist:
	x = alist.index('1')
	y = 0
elif '1' in blist:
	x = blist.index('1')
	y = 1
elif '1' in clist:
	x = clist.index('1')
	y = 2
elif '1' in dlist:
	x = dlist.index('1')
	y = 3
elif '1' in elist:
	x = elist.index('1')
	y = 4
xmove = 0
ymove = 0
counter = 0
while abs(x - xmove) != 2:
	if x > 2:
		xmove += 1
	else:
		xmove -= 1
	counter += 1
while abs(y - ymove) != 2:
	if y > 2:
		ymove += 1
	else:
		ymove -= 1
	counter += 1
print(counter)


M = []
for i in range(5):
	M.append(list(map(int, input().split())))
r = 0
c = 0
for i in range(5):
	for j in range(5):
		if M[i][j] == 1:
			r = i
			c = j
print(abs(2 - r) + abs(2 - c))


lst = []
for i in range(0, 5):
	value = list(map(int, input().split()))
	lst.append(value)
for i in range(0, 5):
	for j in range(0, 5):
		if lst[i][j] == 1:
			r = i
			c = j
			break
row = 0
if r < 2:
	row = 2 - r
elif r > 2:
	row = r - 2
col = 0
if c < 2:
	col = 2 - c
elif c > 2:
	col = c - 2
print(row + col)


def noOfMoves(arr):
	for i in arr:
		if '1' in i:
			row = i.index('1') + 1
			coloumn = arr.index(i) + 1
			break
	return abs(3 - row) + abs(3 - coloumn)
arr = []
for i in range(5):
	arr.append([x for x in input().split()])
print(noOfMoves(arr))


for i in range(5):
	a = input()[::2]
	if a != '00000':
		print(abs(i - 2) + abs(a.find('1') - 2))


matrix = []
for i in range(5):
	line = list(map(int, input().split()))
	matrix.append(line)
k = 0
while 1 not in matrix[k]:
	k += 1
else:
	kk = k
	s = 0
	while k + 1 < 3:
		s += 1
		k += 1
	else:
		while k + 1 > 3:
			s += 1
			k -= 1
i = 0
while 1 != matrix[kk][i]:
	i += 1
i += 1
if i > 3:
	while i != 3:
		i -= 1
		s += 1
elif i < 3:
	while i != 3:
		i += 1
		s += 1
print(s)


list = []
for i in range(0, 5):
	list.append(input())
	if list[i].count('1') > 0:
		list1 = list[i].split()
		n = list1.index('1') + 1
		m = i + 1
print(abs(n - 3) + abs(m - 3))


n = 5
l = []
for i in range(n):
	x = input().split()
	c = []
	for j in range(n):
		c.append(int(x[j]))
	l.append(c)
for i in range(n):
	for j in range(n):
		if l[i][j] != 0:
			row = i
			col = j
sol = abs(2 - row) + abs(2 - col)
print(sol)


import math
import sys
for i in range(5):
	s = input()
	if '1' in s:
		a = s.find('1') // 2 + 1
		print(abs(3 - a) + abs(3 - i - 1))


def index_2d(l, n):
	for (i, x) in enumerate(l):
		if n in x:
			return (i, x.index(n))

def main():
	l = []
	for i in range(5):
		k = list(map(int, input().split()))
		l.append(k)
	idx = index_2d(l, 1)
	print(abs(2 - idx[0]) + abs(2 - idx[1]))
main()


import sys
l = []
for i in range(5):
	l.append(sys.stdin.readline().split())
for row in range(5):
	for element in range(5):
		if l[row][element] == '1':
			(i, j) = (int(element), int(row))
print(abs(i - 2) + abs(j - 2))


matrix = []
while len(matrix) < 5:
	line = input()
	matrix.append(line.split(' '))
row = 0
column = 0
for matrix_row in range(len(matrix)):
	for i in range(len(matrix[matrix_row])):
		if matrix[matrix_row][i] == '1':
			row = matrix_row + 1
			column = i + 1
total_moves = 0
if row < 3:
	total_moves += 3 - row
if row > 3:
	total_moves += row - 3
if column < 3:
	total_moves += 3 - column
if column > 3:
	total_moves += column - 3
print(total_moves)


matrix = []
for i in range(5):
	a = []
	a = [int(x) for x in input().split()]
	matrix.append(a)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			n = i
			m = j
k = n - 2
l = m - 2
if k < 0:
	k = -k
if l < 0:
	l = -l
print(l + k)


n = 5
pi = pj = 0
for i in range(n):
	k = list(map(int, input().split()))
	try:
		pj = k.index(1)
		pi = i
	except:
		pass
print(abs(2 - pi) + abs(2 - pj))


for x in range(5):
	n = input()
	n = list(n)
	for y in range(len(n) // 2):
		n.remove(' ')
	for z in range(len(n)):
		if n[z] == '1':
			temp1 = x + 1
			temp2 = z + 1
temp1 = int(((temp1 - 3) ** 2) ** 0.5)
temp2 = int(((temp2 - 3) ** 2) ** 0.5)
print(temp1 + temp2)


from sys import stdin, stdout
matrix = []
row_1 = -1
col_1 = -1
row_num = -1
for i in range(5):
	row = list(map(int, stdin.readline().strip().split()))
	row_num += 1
	if 1 in row:
		row_1 = row_num
		col_1 = row.index(1)
	matrix.append(row)
row_moves = abs(row_1 - 2)
col_moves = abs(col_1 - 2)
stdout.write(str(row_moves + col_moves))


line = 1
m = 0
while line < 6:
	for i in range(0, 5):
		martix = []
		martix = input().split()
		for i in range(0, 5):
			if martix[i] == '1':
				a = abs(line - 3)
				b = abs(i - 2)
				m = a + b
			if martix[i] == '0':
				pass
		line = line + 1
print(m)
exit()


for i in range(5):
	line = [int(x) for x in input().split()]
	if 1 in line:
		m = line.index(1) + 1
		n = i + 1
print(abs(m - 3) + abs(n - 3))


y = 0
while True:
	a = input()
	y += 1
	if '1' in a:
		break
x = a.replace(' ', '').index('1') + 1
y_steps = abs(3 - y)
x_steps = abs(3 - x)
print(y_steps + x_steps)


a = [i for i in input().split()]
b = [i for i in input().split()]
c = [i for i in input().split()]
d = [i for i in input().split()]
e = [i for i in input().split()]
matrix = [a, b, c, d, e]
matrix_dim = len(matrix[0])
item_index = 0
for row in matrix:
	for i in row:
		if i == '1':
			break
		item_index += 1
	if i == '1':
		break
y = int(item_index / matrix_dim)
x = item_index % matrix_dim
c = 0
while x != 2:
	if x > 2:
		x -= 1
		c += 1
	else:
		x += 1
		c += 1
while y != 2:
	if y > 2:
		y -= 1
		c += 1
	else:
		y += 1
		c += 1
print(c)


rows = []
moves = 0
for x in range(5):
	rows.append(list(input().split(' ')))
for i in range(5):
	for j in range(5):
		if rows[i][j] == '1':
			sum = abs(2 - i) + abs(2 - j)
print(sum)


import sys
for r in range(5):
	k = list(map(int, input().split()))
	if 1 in k:
		i = k.index(1)
		print(abs(2 - r) + abs(2 - i))
		sys.exit(0)


i = 0
x = 0
y = 0
while i < 5:
	a = list(map(int, input().split()))
	if a.count(1) == 1:
		y = i
		x = a.index(1)
	i += 1
print(abs(x - 2) + abs(y - 2))


s = []
for i in range(5):
	l = input().split()
	for j in range(5):
		if l[j] == '1':
			s.append(i + 1)
			s.append(j + 1)
			if s == [1, 1] or s == [5, 1] or s == [1, 5] or (s == [5, 5]):
				print(4)
			elif s == [2, 1] or s == [4, 1] or s == [1, 2] or (s == [1, 4]) or (s == [5, 2]) or (s == [5, 4]) or (s == [2, 5]) or (s == [4, 5]):
				print(3)
			elif s == [3, 1] or s == [2, 2] or s == [4, 2] or (s == [1, 3]) or (s == [5, 3]) or (s == [2, 4]) or (s == [4, 4]) or (s == [3, 5]):
				print(2)
			elif s == [3, 2] or s == [3, 4] or s == [2, 3] or (s == [4, 3]):
				print(1)
			elif s == [3, 3]:
				print(0)
			quit()


l1 = list(input().split())
l2 = list(input().split())
l3 = list(input().split())
l4 = list(input().split())
l5 = list(input().split())
count = 0
if l1.count('1') != 0:
	count = 1
if l2.count('1') != 0:
	count = 2
if l3.count('1') != 0:
	count = 3
if l4.count('1') != 0:
	count = 4
if l5.count('1') != 0:
	count = 5
ans = 0
ans = ans + abs(3 - count)
if count == 1:
	s = l1.index('1')
	ans = ans + abs(3 - s - 1)
if count == 2:
	s = l2.index('1')
	ans = ans + abs(3 - s - 1)
if count == 3:
	s = l3.index('1')
	ans = ans + abs(3 - s - 1)
if count == 4:
	s = l4.index('1')
	ans = ans + abs(3 - s - 1)
if count == 5:
	s = l5.index('1')
	ans = ans + abs(3 - s - 1)
print(ans)


l1 = []
for m in range(5):
	l1.append(list(map(eval, input().split())))
for i in range(5):
	if 1 in l1[i]:
		for j in range(5):
			if 1 == l1[i][j]:
				print(abs(i - 2) + abs(j - 2))


from sys import stdin, stdout

def solve():
	for i in range(5):
		row = list(map(int, stdin.readline().split()))
		for (j, cell) in enumerate(row):
			if cell:
				return abs(j - 2) + abs(i - 2)
stdout.write(str(solve()))


MATRIX_SIZE = 5
MID = 2

def main():
	found = 0
	for i in range(MATRIX_SIZE):
		row = list(map(int, input().strip().split()))
		if found == 0:
			for j in range(len(row)):
				if row[j] == 1:
					rowPos = i
					colPos = j
					found = 1
	print(int(abs(rowPos - MID) + abs(colPos - MID)))
main()


li_all = []
for i in range(5):
	li = input().split()
	li_all.append(li)
for i in range(5):
	if '1' in li_all[i]:
		num = li_all[i].index('1')
		print(abs(i - 2) + abs(num - 2))


matrix = []
for i in range(5):
	matrix.append(input().split())
pos = [2, 1, 0, 1, 2]
for r in range(5):
	for c in range(5):
		if matrix[r][c] == '1':
			res = pos[r] + pos[c]
			break
print(res)


i = 0
while i < 5:
	r = input()
	if '1' in r:
		n = r.index('1') // 2 + 1
		m = i + 1
	i = i + 1
moves = abs(n - 3) + abs(m - 3)
print(moves)


arr = [input().split() for i in range(5)]
for i in range(5):
	for j in range(5):
		if arr[i][j] == '1':
			a = i
			b = j
			break
c = abs(a - 2) + abs(b - 2)
print(c)


r1 = str(input())
r2 = str(input())
r3 = str(input())
r4 = str(input())
r5 = str(input())
r1 = ''.join(r1.split())
r2 = ''.join(r2.split())
r3 = ''.join(r3.split())
r4 = ''.join(r4.split())
r5 = ''.join(r5.split())
A = [r1, r2, r3, r4, r5]
row = 0
column = 0
newx = 0
newy = 0
for x in range(0, 5):
	for y in range(0, 5):
		if int(A[x][y]) == 1:
			row = x + 1
			column = y + 1
			break
if row > 3:
	newx = row - 3
elif row < 3:
	newx = 3 - row
if column > 3:
	newy = column - 3
elif column < 3:
	newy = 3 - column
print(newx + newy)


for x in range(5):
	s = list(map(int, input().split()))
	if 1 in s:
		f = s.index(1)
		v = abs(2 - x)
		v += abs(f - 2)
		print(v)
		exit(0)


i = -1
j = -1
while j < 0:
	line = input()
	i = i + 1
	j = line.find('1') / 2
print(int(abs(2 - i) + abs(2 - j)))


x = 0
y = 0
for i in range(0, 5):
	s = list(map(int, input().split()))
	if 1 in s:
		y = i
		x = s.index(1)
xmoves = abs(x - 2)
ymoves = abs(y - 2)
print(xmoves + ymoves)


a = 0
for i in range(5):
	str_a = input()
	for j in range(5):
		if int(str_a[2 * j]):
			a += abs(j - 2) + abs(i - 2)
print(abs(a))


A = []
cnt = 0
for i in range(5):
	A.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if A[i][j] == 1:
			s = i
			s1 = j
			break
while s != 2 or s1 != 2:
	if s < 2:
		s += 1
		cnt += 1
	elif s > 2:
		s -= 1
		cnt += 1
	if s1 < 2:
		s1 += 1
		cnt += 1
	elif s1 > 2:
		s1 -= 1
		cnt += 1
print(cnt)


for i in range(5):
	try:
		column = input().replace(' ', '').index('1')
		print(abs(2 - column) + abs(2 - i))
	except:
		pass


def index2D(lst, x):
	for i in range(len(lst)):
		if x in lst[i]:
			return [i, lst[i].index(1)]
rows = []
for i in range(5):
	row = list(map(int, input().split(' ')))
	rows.append(row)
current = index2D(rows, 1)
count = 0
for i in range(4):
	for j in range(4):
		if current[0] < 2:
			current[0] += 1
			count += 1
		elif current[0] > 2:
			current[0] -= 1
			count += 1
		else:
			break
	if current[1] < 2:
		current[1] += 1
		count += 1
	elif current[1] > 2:
		current[1] -= 1
		count += 1
	else:
		break
print(count)


l2 = []
for i in range(5):
	l3 = list(map(int, input().split()))
	l2.append(l3)
ans = 0
for i in range(5):
	for j in range(5):
		if l2[i][j] == 1:
			ans = abs(2 - i) + abs(2 - j)
			break
print(ans)


s = []
for a in range(5):
	s.append(input().split(' '))
k = 0
for i in range(5):
	for j in range(5):
		if s[i][j] == '1':
			n = i
			m = j
while m != 2:
	if m > 2:
		m -= 1
		k += 1
	elif m < 2:
		m += 1
		k += 1
while n != 2:
	if n > 2:
		n -= 1
		k += 1
	elif n < 2:
		n += 1
		k += 1
print(k)


out0 = 0
for x in range(1, 6):
	in0 = [int(x) for x in input().split()]
	if 1 in in0:
		out0 = abs(2 - in0.index(1)) + abs(3 - x)
		break
print(out0)


import sys

def main():
	lines = sys.stdin.readlines()
	m = [line.rstrip(' \r\n').split(' ') for line in lines]
	for (i, row) in enumerate(m):
		for (j, value) in enumerate(row):
			if value == '1':
				return abs(2 - i) + abs(2 - j)
	return None
print(main())


n = []
for i in range(5):
	n.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if n[i][j] == 1:
			(r, c) = (i + 1, j + 1)
			break
m = 0
if r >= 3:
	m += r - 3
elif r < 3:
	m += 3 - r
if c >= 3:
	m += c - 3
elif c < 3:
	m += 3 - c
print(m)


matrix1 = []
for i in range(5):
	matrix1.append(input().split())
for (index1, list1) in list(enumerate(matrix1)):
	for (index2, num) in list(enumerate(list1)):
		if num == '1':
			column = index1
			row = index2
			print(abs(row - 2) + abs(column - 2))
			break
		else:
			continue


(row, col) = (-1, -1)
for i in range(5):
	x = list(map(int, input().split(' ')))
	if 1 in x:
		row = i + 1
		col = x.index(1) + 1
print(abs(row - 3) + abs(col - 3))


M = [list(map(int, input().split())) for i in range(5)]
rs = [sum(r) for r in M]
row = rs.index(1)
col = M[row].index(1)
print(abs(2 - row) + abs(2 - col))


import math
a = input()
b = input()
c = input()
d = input()
e = input()
cnt = 0
if '1' in a:
	cnt += 2
	cols = a.split(' ')
	index = cols.index('1')
	cnt += math.fabs(index - 2)
elif '1' in b:
	cnt += 1
	cols = b.split(' ')
	index = cols.index('1')
	cnt += math.fabs(index - 2)
elif '1' in c:
	cnt += 0
	cols = c.split(' ')
	index = cols.index('1')
	cnt += math.fabs(index - 2)
elif '1' in d:
	cnt += 1
	cols = d.split(' ')
	index = cols.index('1')
	cnt += math.fabs(index - 2)
elif '1' in e:
	cnt += 2
	cols = e.split(' ')
	index = cols.index('1')
	cnt += math.fabs(index - 2)
print(int(cnt))


matrix = list()
number_one_x = 0
number_one_y = 0
for i in range(5):
	matrix.append(list())
	fr = list(map(int, input().split()))
	for j in range(len(fr)):
		if fr[j] == 1:
			number_one_x = i
			number_one_y = j
		matrix[i].append(fr[j])
counter = 0
while number_one_x != 2:
	if number_one_x < 2:
		counter += 1
		while True:
			f1 = matrix[number_one_x]
			del matrix[number_one_x]
			matrix.insert(number_one_x + 1, f1)
			number_one_x += 1
			break
	else:
		counter += 1
		while True:
			f1 = matrix[number_one_x]
			del matrix[number_one_x]
			matrix.insert(number_one_x - 1, f1)
			number_one_x -= 1
			break
while number_one_y != 2:
	if number_one_y < 2:
		counter += 1
		while True:
			f1 = matrix[2][number_one_y]
			del matrix[2][number_one_y]
			matrix[2].insert(number_one_y + 1, f1)
			number_one_y += 1
			break
	else:
		counter += 1
		while True:
			f1 = matrix[2][number_one_y]
			del matrix[2][number_one_y]
			matrix[2].insert(number_one_y - 1, f1)
			number_one_y -= 1
			break
print(counter)


COORD = 0
for i in range(5):
	flag = False
	n = input().split()
	for j in range(len(n)):
		if n[j] == '1':
			COORD = (i + 1, j + 1)
			flat = True
			break
	if flag:
		break
print(abs(3 - COORD[0]) + abs(3 - COORD[1]))


s = []
for i in range(5):
	s.append(input().split())
	if '1' in s[i]:
		r = i
for i in range(5):
	if s[r][i] == '1':
		c = i
print(abs(r - 2) + abs(c - 2))


m = [[int(i) for i in input().split()] for j in range(5)]
for (j, n) in enumerate(m):
	if 1 in m[j]:
		print(abs(2 - j) + abs(2 - m[j].index(1)))
		break


arr = []
r = 0
c = 0
for i in range(5):
	str = input()
	if '1' in str:
		r = i
		c = int(str.find('1') / 2)
print(abs(2 - r) + abs(2 - c))


matrix = []
for a in range(5):
	matrix.append(input().split())
for a in range(5):
	for b in range(5):
		if matrix[a][b] == '1':
			print(abs(int(a) - 2) + abs(int(b) - 2))
			break


final = []
for _ in range(5):
	l = []
	l = [int(a) for a in input().split()]
	final.append(l)
for i in range(5):
	for j in range(5):
		if final[i][j] == 1:
			print(abs(i - 2) + abs(j - 2))
			break
			break


inputs = []
n = 0
while n < 5:
	y = input().split()
	n += 1
	for i in y:
		inputs.append(i)
i = 0
while inputs[i] != '1':
	i += 1
moves4 = ['0', '4', '20', '24']
moves3 = ['1', '3', '5', '9', '15', '19', '21', '23']
moves2 = ['2', '6', '8', '10', '14', '16', '18', '22']
moves1 = ['7', '11', '13', '17']
moves0 = ['12']
if str(i) in moves4:
	print('4')
if str(i) in moves3:
	print('3')
if str(i) in moves2:
	print('2')
if str(i) in moves1:
	print('1')
if str(i) in moves0:
	print('0')


matrix = []
for i in range(5):
	matrix.append(list(input().split()))
position = [(index, row.index('1')) for (index, row) in enumerate(matrix) if '1' in row]
(r, c) = position[0]
beauty = abs(r - 2) + abs(c - 2)
print(beauty)


def f(lst):
	lst = [i.split() for i in lst]
	coor = list()
	row = [lst.index(x) for x in lst if '1' in x][0]
	coor.append(row)
	col = lst[row].index('1')
	coor.append(col)
	result = abs(2 - coor[0]) + abs(2 - coor[1])
	return result
lst = list()
for _ in range(5):
	s = input()
	lst.append(s)
print(f(lst))


matrix = []
for x in range(5):
	tempList = list(map(int, input().split()))
	if sum(tempList) == 1:
		row = x + 1
		column = tempList.index(1) + 1
matrix.append(tempList)
print(abs(3 - row) + abs(3 - column))


for K in range(5):
	D = input('')
	D = D.split()
	for J in range(5):
		if int(D[J]) == 1:
			PH = J
			PV = K
if PH > 2:
	P = PH - 2
	if PV > 2:
		PP = PV - 2
	else:
		PP = 2 - PV
	print(PP + P)
else:
	P = 2 - PH
	if PV > 2:
		PP = PV - 2
	else:
		PP = 2 - PV
	print(PP + P)


def matrix_index(matrix):
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				return [i, j]
matrix = []
for i in range(5):
	row = list(map(int, input().split()))
	matrix.append(row)
(x, y) = matrix_index(matrix)
dx = abs(x - 2)
dy = abs(y - 2)
print(dx + dy)


import re
import math
fstr = list(input().split())
sstr = list(input().split())
tstr = list(input().split())
fostr = list(input().split())
fistr = list(input().split())
i = 0
j = 0
massive = fstr + sstr + tstr + fostr + fistr
index1 = massive.index('1') + 1
posO = index1
index1 = math.ceil(index1 / 5)
i = index1
if posO % 5 == 0:
	j = 5
else:
	j = posO % 5
i = math.fabs(i - 3) + math.fabs(j - 3)
print(math.trunc(i))


i = 1
a = 0
b = 0
while i <= 5:
	line = input().split()
	for j in line:
		if j == '1':
			a = i
			b = int(line.index(j)) + 1
			break
	if b > 0:
		break
	i = i + 1
print(abs(a - 3) + abs(b - 3))


i = 0
ii = 0
while i < 5 and ii == 0:
	m = input().split()
	if '1' in m:
		ii = 1
	i += 1
i2 = 0
while i2 < 5 and ii == 1:
	if m[i2] == '1':
		ii = 0
	i2 += 1
x = abs(i - 3)
y = abs(i2 - 3)
print(x + y)


input_int = 5
a = []
for i in range(0, input_int):
	b = [int(inp) for inp in input().split()]
	a.append(b)
res = 0
if a[2][2] == 1:
	print(0)
else:
	for i in a:
		for j in i:
			if j == 1:
				res += abs(a.index(i) - 2) + abs(i.index(j) - 2)
	print(res)


def beaut(ls):
	for i in range(5):
		for j in range(5):
			if ls[i][j] == 1:
				return abs(2 - i) + abs(2 - j)
ls = []
for i in range(5):
	ls += (list(map(int, input().split(' '))),)
print(beaut(ls))


def main():
	matrix = []
	contador = 0
	fila_uno = 0
	for i in range(5):
		fila = list(map(int, input().split()))
		matrix.append(fila)
		if 1 in fila:
			index = fila.index(1)
			fila_uno = contador
		contador += 1
	contador = 0
	while fila_uno != 2:
		if fila_uno > 2:
			fila_uno -= 1
			contador += 1
		else:
			fila_uno += 1
			contador += 1
	while index != 2:
		if index > 2:
			index -= 1
			contador += 1
		else:
			index += 1
			contador += 1
	print(contador)
main()


string = ''
a = []
mass = []
for i in range(5):
	string = input()
	a = string.split()
	mass.append(a)
coord_i = 0
coord_j = 0
counter = 0
counter_2 = 0
for i in mass:
	counter += 1
	if '1' in i:
		coord_i = counter
		break
	else:
		continue
for j in mass[coord_i - 1]:
	counter_2 += 1
	if '1' in j:
		coord_j = counter_2
		break
	else:
		continue
steps = abs(3 - coord_j) + abs(3 - coord_i)
print(steps)


co = 0
ro = 0
answer = 0
for i in [1, 2, 3, 4, 5]:
	row = input().split()
	if '1' in row:
		ro = i
		co = row.index('1') + 1
answer = abs(ro - 3) + abs(co - 3)
print(answer)


def h(s):
	return s * ((s > 0) - (s < 0))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
s = list(map(int, input().split()))
t = list(map(int, input().split()))
if sum(p) != 0:
	(d, f) = (1, p.index(1) + 1)
elif sum(q) != 0:
	(d, f) = (2, q.index(1) + 1)
elif sum(r) != 0:
	(d, f) = (3, r.index(1) + 1)
elif sum(s) != 0:
	(d, f) = (4, s.index(1) + 1)
else:
	(d, f) = (5, t.index(1) + 1)
print(h(d - 3) + h(3 - f))


List = []
k = 0
for i in range(1, 6):
	n = list(map(int, input().split()))
	if 1 in n:
		k = abs(i - 3) + abs(n.index(1) - 2)
		break
print(k)


matrix = []
for i in range(5):
	matrix.append([i for i in input().split()])
	if '1' in matrix[i]:
		y = i
		for k in range(5):
			if matrix[i][k] == '1':
				x = k
				break
print(abs(y - 2) + abs(x - 2))


A = []
for i in range(5):
	A.append(list(map(int, input().split())))
(x, y) = (5, 5)
for i in range(len(A)):
	for j in range(len(A[i])):
		if A[i][j] == 1:
			(x, y) = (i, j)
			break
	if (x, y) != (5, 5):
		break
ans = abs(x - 2) + abs(y - 2)
print(ans)


for row in range(1, 6):
	col = input().split(' ')
	if '1' in col:
		result = abs(col.index('1') - 2) + abs(row - 3)
print(result)


M = [[j for j in input().replace(' ', '')] for i in range(5)]
ti = 0
tj = 0
for i in range(5):
	for j in range(5):
		if M[i][j] == '1':
			tj = j
			ti = i
print(abs(ti - 2) + abs(tj - 2))


T = []
m = 0
n = 0
for x in range(0, 5):
	h = input()
	h = h.split()
	T.append(h)
w = False
a = 0
while w == False and a < 5:
	b = 0
	while w == False and b < 5:
		if T[a][b] == '1':
			m = a
			n = b
			w = False
		b = b + 1
	a = a + 1
print(abs(2 - m) + abs(2 - n))


matrix = []
for i in range(5):
	line = list(map(int, input().split()))
	matrix.append(line)
	for j in range(5):
		if line[j] == 1:
			row = abs(i - 2)
			colume = abs(j - 2)
print(row + colume)


def solve():
	rowN = 1
	columnN = 1
	for x in range(0, 5):
		row = list(input().split())
		for y in range(0, 5):
			if int(row[y]) == 1:
				columnN = y + 1
				return abs(rowN - 3) + abs(columnN - 3)
		rowN += 1
	return -1
print(solve())


matrix = []
matrixl = []
r = 0
c = 0
for n in range(5):
	line = input()
	linel = line.split(' ')
	matrix.append(line)
	matrixl.append(linel)
for (i, k) in enumerate(matrix):
	if k != '0 0 0 0 0':
		r = i + 1
		break
for (i, k) in enumerate(matrixl[r - 1]):
	if k != '0':
		c = i + 1
		break
tries = abs(r - 3) + abs(c - 3)
print(tries)


for i in range(5):
	row = input().split()
	if '1' in row:
		j = row.index('1')
		answer = abs(3 - (i + 1)) + abs(3 - (j + 1))
		print(answer)


l = []
for i in range(5):
	x = input()
	x = x.replace(' ', '')
	l.append(x)
for num in range(5):
	for i in range(5):
		if l[num][i] == '1':
			row = num + 1
			col = i + 1
print(abs(3 - row) + abs(3 - col))


matrix = [[int(x) for x in input().split()] for _ in range(5)]

def FindPosition(matrix):
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				return (i, j)
(x, y) = FindPosition(matrix)
print(abs(x - 2) + abs(y - 2))


a = [[0] * 5 for i in range(5)]

def find():
	for i in range(5):
		a[i] = input().split()
	for i in range(5):
		for j in range(5):
			if a[i][j] == '1':
				print(abs(2 - i) + abs(2 - j))
				return
find()


m = 0
for i in range(5):
	bo = False
	h = [int(x) for x in input().split()]
	for q in range(5):
		if h[q] == 1:
			if q == 2:
				m += 0
			elif q < 2:
				m += 2 - q
			elif q > 2:
				m += q - 2
			bo = True
			break
	if bo == True:
		if i == 2:
			m += 0
		elif i < 2:
			m += 2 - i
		elif i > 2:
			m += i - 2
print(m)


for x in range(5):
	num = input().split()
	if '1' in num:
		print(abs(x - 2) + abs(num.index('1') - 2))


matrix = list(input())
matrix1 = list(input())
matrix2 = list(input())
matrix3 = list(input())
matrix4 = list(input())
matrix_list = [matrix, matrix1, matrix2, matrix3, matrix4]
new_list = []
n = 0
for each_list in matrix_list:
	if '1' in each_list:
		n = matrix_list.index(each_list)
		for i in each_list:
			if i == '0' or i == '1':
				new_list.append(i)
m = new_list.index('1')
if n <= 2:
	n = 2 - n
else:
	n = n - 2
if m <= 2:
	m = 2 - m
else:
	m = m - 2
print(m + n)


matrix = []
index_string = 0
index_column = 0
item = 0
for i in range(5):
	s = input().split(' ')
	matrix.append(s)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			index_string = i
			index_column = j
while index_string != 2 or index_column != 2:
	if index_column < 2:
		index_column += 1
		item += 1
	if index_column > 2:
		index_column -= 1
		item += 1
	if index_string < 2:
		index_string += 1
		item += 1
	if index_string > 2:
		index_string -= 1
		item += 1
print(item)


mas = ''
(n, m) = (0, 0)
for i in range(5):
	mas += ''.join(input().split())
n = mas.index('1') // 5 + 1
m = mas.index('1') - 5 * (n - 1) + 1
print(abs(3 - n) + abs(3 - m))


array1 = input()
array1 = array1.split()
array2 = input()
array2 = array2.split()
array3 = input()
array3 = array3.split()
array4 = input()
array4 = array4.split()
array5 = input()
array5 = array5.split()
for i in range(5):
	if array1[i] != '0':
		print(2 + abs(2 - i))
	elif array2[i] != '0':
		print(1 + abs(2 - i))
	elif array3[i] != '0':
		print(abs(2 - i))
	elif array4[i] != '0':
		print(1 + abs(2 - i))
	elif array5[i] != '0':
		print(2 + abs(2 - i))


def matrix_row(dictionary):
	counter = 0
	for x in range(1, 6):
		if dictionary[x] != '0 0 0 0 0':
			if x < 3:
				(dictionary[x], dictionary[x + 1]) = (dictionary[x + 1], dictionary[x])
				counter += 1
			elif x == 4:
				(dictionary[x], dictionary[x - 1]) = (dictionary[x - 1], dictionary[x])
				counter += 1
			elif x == 5:
				(dictionary[x - 1], dictionary[x]) = (dictionary[x], dictionary[x - 1])
				(dictionary[x - 2], dictionary[x - 1]) = (dictionary[x - 1], dictionary[x - 2])
				counter += 2
			else:
				break
	return (counter, dictionary)

def matrix_column(counter, dictionary):
	counter = counter
	dictnry = dictionary[3]
	dictionary = dictnry.split()
	for x in range(5):
		if dictionary[x] == '1' and dictionary[x] != dictionary[2]:
			if x < 2:
				(dictionary[x], dictionary[x + 1]) = (dictionary[x + 1], dictionary[x])
				counter += 1
			elif x == 3:
				(dictionary[x - 1], dictionary[x]) = (dictionary[x], dictionary[x - 1])
				counter += 1
			elif x == 4:
				(dictionary[x - 1], dictionary[x]) = (dictionary[x], dictionary[x - 1])
				(dictionary[x - 2], dictionary[x - 1]) = (dictionary[x - 1], dictionary[x - 2])
				counter += 2
			else:
				break
	return counter
dictionary = {}
for x in range(1, 6):
	dictionary[x] = input()
a = matrix_row(dictionary)
b = matrix_column(a[0], a[1])
print(b)


lst = []
for i in range(5):
	lst.append(input().split())
for i in range(5):
	if '1' in lst[i]:
		row = i + 1
for i in range(5):
	if lst[row - 1][i] == '1':
		column = i + 1
print(abs(row - 3) + abs(column - 3))


for i in range(5):
	r = input().split()
	for j in range(5):
		if r[j] == '1':
			print(max(i, 2) - min(i, 2) + max(j, 2) - min(j, 2))


def main():
	M = tuple((tuple(map(int, input().rstrip().split())) for _ in range(5)))
	for i in range(5):
		for j in range(5):
			if M[i][j] == 1:
				print(abs(i - 2) + abs(j - 2))
				break
main()


rowNumber = 1
collum = 1
for i in range(5):
	row = list(map(int, input().split()))
	if sum(row) == 0:
		rowNumber += 1
	else:
		tureRow = rowNumber
		targetRow = row
for i in targetRow:
	if i == 0:
		collum += 1
	else:
		break
print(abs(tureRow - 3) + abs(collum - 3))


m = 0
for i in range(5):
	r = list(map(int, input().split()))
	if 1 in r:
		x = r.index(1)
		m += abs(2 - x)
		y = abs(2 - i)
		m += y
	else:
		pass
print(m)


row = 0
col = 0
for i in range(1, 6):
	l = [int(num) for num in input().split()]
	if 1 in l:
		row = i
		col = l.index(1) + 1
rowDiff = abs(3 - row)
colDiff = abs(3 - col)
print(rowDiff + colDiff)


l = []
for i in range(5):
	l.append(list(map(str, input().split())))
line = 0
col = 0
res = 0
for i in range(5):
	if '1' in l[i]:
		line = i
for i in range(5):
	if '1' in l[line][i]:
		col = i
res = abs(2 - line) + abs(2 - col)
print(res)


import math
a = []
for i in range(5):
	a.append([int(j) for j in input().split()])
k = 3
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			x = math.fabs(k - (i + 1))
			y = math.fabs(k - (j + 1))
			print(int(x + y))
			exit()


one_coord = (0, 0)
target_row = (2, 2)
for i in range(5):
	row = list(map(int, input().split(' ')))
	for (j, elem) in enumerate(row):
		if elem == 1:
			one_coord = (i, j)
print(abs(target_row[0] - one_coord[0]) + abs(target_row[1] - one_coord[1]))


for i in range(5):
	string = input().split()
	for j in range(5):
		if string[j] == '1':
			pos = (i, j)
			break
print(abs(pos[0] - 2) + abs(pos[1] - 2))


a = []
(x, y) = (0, 0)
for i in range(5):
	b = []
	k = input().split()
	a.append(k)
	if '1' in k:
		x = i
		y = k.index('1')
x = 2 - x
y = 2 - y
sum = abs(x) + abs(y)
print(int(sum))


import sys
matrix = []
row = -1
col = -1
no_of_lines = 5
for i in range(no_of_lines):
	line = input()
	count = 0
	for data in line.split():
		if int(data) == 1:
			row = i
			col = count
		count += 1
ans = abs(2 - row) + abs(2 - col)
print(ans)


rows = []
for _ in range(5):
	rows.append(input().split())
for (i, r) in enumerate(rows):
	if '1' in r:
		print(abs(2 - r.index('1')) + abs(2 - i))


l = list()
for i in range(5):
	temp = list(map(int, input().split()))
	if 1 in temp:
		ind = i
	l.append(temp)
ans = abs(ind - 2)
for i in range(5):
	if l[ind][i] == 1:
		break
ans += abs(i - 2)
print(ans)


arr = []
for i in range(5):
	inp = input()
	if '1' in inp:
		y = i
		x = inp.index('1') // 2
		break
x_diff = abs(x - 2)
y_diff = abs(y - 2)
print(x_diff + y_diff)


a1 = input().split()
a2 = input().split()
a3 = input().split()
a4 = input().split()
a5 = input().split()
if '1' in a1:
	b = a1.index('1')
	d = 0
	if b == 0 or b == 4:
		d = 2
	elif b == 1 or b == 3:
		d = 1
	print(2 + d)
if '1' in a5:
	b = a5.index('1')
	d = 0
	if b == 0 or b == 4:
		d = 2
	elif b == 1 or b == 3:
		d = 1
	print(2 + d)
if '1' in a2:
	b = a2.index('1')
	d = 0
	if b == 0 or b == 4:
		d = 2
	elif b == 1 or b == 3:
		d = 1
	print(1 + d)
if '1' in a4:
	b = a4.index('1')
	d = 0
	if b == 0 or b == 4:
		d = 2
	elif b == 1 or b == 3:
		d = 1
	print(1 + d)
if '1' in a3:
	b = a3.index('1')
	d = 0
	if b == 0 or b == 4:
		d = 2
	elif b == 1 or b == 3:
		d = 1
	print(d)


i = 5
s = []
for i in range(5):
	l = list(map(int, input().split()))
	s.append(l)
	if sum(l) == 1:
		k = i + 1
		p = l.index(1) + 1
print(abs(3 - k) + abs(3 - p))


oneRowIndex = -1
oneColumnIndex = -1
for i in range(5):
	row = list(map(int, input().split()))
	if 1 in row:
		oneRowIndex = i + 1
		oneColumnIndex = row.index(1) + 1
print(abs(3 - oneRowIndex) + abs(3 - oneColumnIndex))


n = 5
i = 0
j = 0
k = 0
l = 0
a = []
for i in range(n):
	a.append([int(j) for j in input().split()])
for i in a:
	j = j + 1
	if 1 in i:
		k = j
		l = i.index(1) + 1
i = abs(3 - k)
j = abs(3 - l)
j = i + j
print(j)


a = []
for i in range(0, 5):
	a.append([int(j) for j in input().split()])
for x in range(0, 5):
	for y in range(0, 5):
		if a[x][y] == 1:
			i = x
			j = y
c = 0
if i < 2:
	for l in range(i, 2, 1):
		a[i][j] = 0
		a[i + 1][j] = 1
		c = c + 1
elif i > 2:
	for l in range(i, 2, -1):
		a[i][j] = 0
		a[i - 1][j] = 1
		c = c + 1
if j < 2:
	for l in range(j, 2, 1):
		a[2][j] = 0
		a[2][j + 1] = 1
		c = c + 1
elif j > 2:
	for l in range(j, 2, -1):
		a[2][j] = 0
		a[2][j - 1] = 1
		c = c + 1
print(c)


def main():
	coords = [0, 0]
	for i in range(5):
		a = input().replace(' ', '')
		coords[1] = a.find('1')
		if coords[1] != -1:
			coords[0] = i
			break
	coords[0] -= 2
	coords[1] -= 2
	print(abs(coords[0]) + abs(coords[1]))
main()


n = [input().split(' ') for i in range(5)]
for i in n:
	for j in i:
		if j == '1':
			(r, c) = (n.index(i) + 1, i.index(j) + 1)
if r > 3:
	p = r - 3
else:
	p = 3 - r
if c > 3:
	p += c - 3
else:
	p += 3 - c
print(p)


rows = 2
cols = 2
matrix = []
for i in range(5):
	row = input().split()
	if '1' in row:
		one_i = i
		one_j = row.index('1')
		break
r_shifts = abs(one_i - rows)
c_shifts = abs(one_j - cols)
print(r_shifts + c_shifts)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def in_int():
	return int(input())

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

def in_str():
	s = input()
	return list(s[:len(s) - 1])

def in_ints() -> object:
	return map(int, input().split())
ans = 0
for i in range(5):
	a = in_list()
	for j in range(5):
		if a[j] == 1:
			ans = abs(2 - i) + abs(2 - j)
print(ans)


table = []
for i in range(5):
	table.append(input().split())
for (v, tabl) in enumerate(table):
	for (c, num) in enumerate(tabl):
		if int(num) == 1:
			print(abs(v - 2) + abs(c - 2))
			break


mat = []
for row in range(5):
	mat.append(list(map(int, input().split())))
midr = midcol = 2
posr = poscol = 0
for row in range(len(mat)):
	for col in range(len(mat[0])):
		if mat[row][col] == 1:
			posr = row
			poscol = col
print(abs(midr - posr) + abs(midcol - poscol))


for i in range(0, 5):
	line = input().split(' ')
	if '1' in line:
		location = line.index('1')
		step = abs(2 - location) + abs(2 - i)
		print(step)
		break


(r, c) = (1, 1)
for _ in range(5):
	arr = list(map(int, input().split()))
	for k in range(len(arr)):
		if arr[k] == 1:
			c = k + 1
			print(abs(r - 3) + abs(c - 3))
	r += 1


switch = {0: 2, 1: 1, 2: 0, 3: 1, 4: 2}
for i in range(5):
	l = [int(x) for x in input().split()]
	if sum(l) == 1:
		b = l.index(1)
		a = i
		m = switch.get(a)
		n = switch.get(b)
print(m + n)


import sys
moves = [2, 1, 0, 1, 2]
for i in range(5):
	row = list(map(int, sys.stdin.readline().split()))
	if 1 in row:
		print(moves[i] + moves[row.index(1)])
		break


mat = []
for i in range(5):
	mat1 = input().split()
	mat.append(mat1)
r = 0
c = 0
for i in range(5):
	for j in range(5):
		if int(mat[i][j]) == 1:
			r = abs(j - 2)
			c = abs(i - 2)
s = r + c
print(s)


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()))
if 1 in row1:
	print(2 + abs(row1.index(1) + 1 - 3))
elif 1 in row2:
	print(1 + abs(row2.index(1) + 1 - 3))
elif 1 in row3:
	print(0 + abs(row3.index(1) + 1 - 3))
elif 1 in row4:
	print(1 + abs(row4.index(1) + 1 - 3))
elif 1 in row5:
	print(2 + abs(row5.index(1) + 1 - 3))


matrix = [[], [], [], [], []]
matrix[0] = input().split(' ')
matrix[1] = input().split(' ')
matrix[2] = input().split(' ')
matrix[3] = input().split(' ')
matrix[4] = input().split(' ')
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
			break


import sys
lines = sys.stdin.readlines()
for i in range(5):
	for j in range(5):
		if lines[i].split()[j] == '1':
			lmao = [i, j]
print(abs(2 - lmao[0]) + abs(2 - lmao[1]))


import sys
m = sys.stdin.read().lower().split('\n')
(x, y) = next(((i, j) for j in range(5) for i in range(5) if m[i].split()[j] == '1'))
print(abs(2 - x) + abs(2 - y))


lst = [list(map(int, input().split())) for i in range(5)]
y1 = 0
x1 = 0
for y in range(5):
	for x in range(5):
		if lst[y][x] == 1:
			y1 = y
			x1 = x
print(abs(2 - y1) + abs(2 - x1))


lines = []
for i in range(0, 5):
	lines.append(list(map(int, input().split(' '))))
row = 0
for i in lines:
	if 1 in i:
		break
	row += 1
col = i.index(1)
if col < 3:
	col = 2 + 2 - col
if row < 3:
	row = 2 + 2 - row
tot = col - 2 + row - 2
print(tot)


for i in range(5):
	line = [int(x) for x in input().split()]
	for j in range(5):
		if line[j] == 1:
			a = i + 1
			b = j + 1
			break
		else:
			continue
print(abs(a - 3) + abs(b - 3))


m = []
f = 0
for i in range(5):
	rowli = list(map(int, input().split()))
	m.append(rowli)
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			li = i
			ri = j
			f = 1
			break
	if f == 1:
		break
ans = abs(i - 2) + abs(j - 2)
print(ans)


matrix = []
for i in range(5):
	row = input().split(' ')
	for i in range(len(row)):
		row[i] = int(row[i])
	matrix.append(row)
distance = [0, 0]
for i in range(len(matrix)):
	for j in range(len(matrix)):
		if matrix[i][j] == 1:
			distance[0] = i
			distance[1] = j
			break
distance_y = 2 - distance[0]
distance_x = 2 - distance[1]
if distance_x < 0:
	distance_x = distance_x * -1
if distance_y < 0:
	distance_y = distance_y * -1
total_moves = distance_x + distance_y
print(total_moves)


for i in range(5):
	array = list(map(int, input().split()))
	try:
		x = array.index(1)
	except ValueError:
		x = -1
	if x != -1:
		print(abs(2 - i) + abs(2 - x))


import sys

def work(l):
	for i in range(5):
		for j in range(5):
			if l[i][j] == '1':
				return (i + 1, j + 1)
(x, y) = work([i.rstrip().split() for i in sys.stdin.readlines()])
print(abs(x - 3) + abs(y - 3))


matrix = []
R = 0
C = 0
for j in range(1, 6):
	li = input().split()
	matrix.append(li)
for r in range(5):
	for c in range(5):
		if matrix[r][c] == '1':
			R = r
			C = c
			break
print(abs(R - 2) + abs(C - 2))


try:
	arr = []
	for i in range(5):
		aj = list(map(int, input().split()))
		arr.append(aj)
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				ci = abs(i - 2)
				cj = abs(j - 2)
	print(ci + cj)
except EOFError:
	pass


k = 1
for num in range(0, 5):
	q = input()
	i = 1
	for num2 in range(0, 5):
		p = int(q.split(' ')[i - 1])
		if p == 1:
			x = abs(3 - k) + abs(3 - i)
		else:
			i = i + 1
	k = k + 1
print(x)


j = 0
for i in range(1, 6):
	js = str(input())
	if '1' in js:
		for c in js:
			if c == '0' or c == '1':
				j = j + 1
			if c == '1':
				print(abs(3 - i) + abs(3 - j))


for i in range(5):
	row = list(map(int, input().split()))
	for j in row:
		if j == 1:
			row_mark = i
			col_mark = row.index(1)
			row_shifts = abs(2 - row_mark)
			col_shifts = abs(2 - col_mark)
print(row_shifts + col_shifts)


n = 0
m = 0
a = []
c = 0
for i in range(5):
	b = list(map(int, input().split()))
	a.append(b)
for i in range(5):
	if 1 in a[i]:
		q = i
		for j in range(5):
			if a[i][j] == 1:
				w = j
				while q != 2:
					if q > 2:
						q -= 1
					else:
						q += 1
					c += 1
				while w != 2:
					if w > 2:
						w -= 1
					else:
						w += 1
					c += 1
print(c)


from math import fabs
matrix = []
lst = []
for i in range(5):
	lst.append(0)
for i in range(5):
	matrix.append([])
	matrix[i].append(input())
for i in range(5):
	s = ' '.join(matrix[i])
	lst[i] = s.split(' ')
for i in range(5):
	for j in range(5):
		if lst[i][j] == '1':
			index_i = i
			index_j = j
ans = 0
if index_j > 2:
	while index_j != 2:
		index_j -= 1
		ans += 1
if index_j < 2:
	while index_j != 2:
		index_j += 1
		ans += 1
if index_i > 2:
	while index_i != 2:
		index_i -= 1
		ans += 1
if index_i < 2:
	while index_i != 2:
		index_i += 1
		ans += 1
print(ans)


a = [input() for k in range(5)]
count = 0
for i in range(5):
	for j in range(0, len(a[i]), 2):
		if a[i][j] == '1':
			count = 1
			break
	if count == 1:
		break
count = abs(i - 2) + abs(j // 2 - 2)
print(count)


mat = []
rc = 0
cc = 0
for i in range(5):
	row = list(map(int, input().split()))
	mat.append(row)
	if 1 in row:
		rc = i
		for j in range(5):
			if row[j] == 1:
				cc = j
				break
moves = abs(cc - 2) + abs(rc - 2)
print(moves)


a = []
for i in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if 1 == a[i][j]:
			p = [i, j]
			break
dp = [2, 2]
m = 0
while p != dp:
	if p[0] < dp[0]:
		p[0] += 1
		m += 1
	if p[1] < dp[1]:
		m += 1
		p[1] += 1
	if p[0] > dp[0]:
		m += 1
		p[0] -= 1
	if p[1] > dp[1]:
		m += 1
		p[1] -= 1
print(m)


mat = []
for t in range(5):
	sol = input()
	mat.append(list(sol.replace(' ', '')))
c = '1'
position = [(i, colour.index(c)) for (i, colour) in enumerate(mat) if c in colour]
print(abs(2 - position[0][0]) + abs(2 - position[0][1]))


for i in range(5):
	ch = input().split()
	for h in range(5):
		if ch[h] == '1':
			a = h + 1
			b = i + 1
print(abs(a - 3) + abs(b - 3))


def findItem(theList, item):
	return [(ind + 1, theList[ind].index(item) + 1) for ind in range(len(theList)) if item in theList[ind]]
matrix = [input().split() for i in range(5)]
matrix2 = []
for mat in matrix:
	matrix2.append(list(map(int, mat)))
for i in findItem(matrix2, 1):
	(x, y) = i
print(abs(x - 3) + abs(y - 3))


def makeint(x):
	for i in x:
		x[x.index(i)] = int(i)
	return x
mat = []
r1 = input().split()
makeint(r1)
mat.append(r1)
r2 = input().split()
makeint(r2)
mat.append(r2)
r3 = input().split()
makeint(r3)
mat.append(r3)
r4 = input().split()
makeint(r4)
mat.append(r4)
r5 = input().split()
makeint(r5)
mat.append(r5)
n = 0
b = 'False'
for i in mat:
	m = 0
	for j in i:
		if j == 1:
			b = 'True'
			break
		m += 1
	if b == 'True':
		break
	n += 1
x = abs(m - 2)
y = abs(n - 2)
result = x + y
print(result)


(x, y) = (2, 2)
for i in range(5):
	lis = list(map(int, input().split(' ')))
	for j in range(5):
		if lis[j] != 0:
			(x, y) = (abs(j - x), abs(i - y))
			break
print(x + y)


matrices = []
location = []
movesX = 0
movesY = 0
for i in range(5):
	matrices.append(list(map(int, input().split())))
for i in range(len(matrices)):
	for j in range(len(matrices[i])):
		if matrices[i][j] == 1:
			location.append(i + 1)
			location.append(j + 1)
			break
movesX = abs(location[0] - 3)
movesY = abs(location[1] - 3)
print(movesX + movesY)


for i in range(5):
	matriz = input()
	index = matriz.find('1')
	if index != -1:
		if index == 4:
			print(int(abs(i - 2)))
		elif index == 0 or index == 8:
			print(int(2 + abs(i - 2)))
		elif index == 2 or index == 6:
			print(int(1 + abs(i - 2)))


mat = []
for _ in range(5):
	mat.append(input().split())
s1 = [(k, i) for (k, m) in enumerate(mat, 1) for (i, j) in enumerate(m, 1) if '1' in j]
dist = abs(3 - int(s1[0][0])) + abs(3 - int(s1[0][1]))
print(dist)


N1 = list(map(int, input().split()))
N2 = list(map(int, input().split()))
N3 = list(map(int, input().split()))
N4 = list(map(int, input().split()))
N5 = list(map(int, input().split()))
N = [N1, N2, N3, N4, N5]
c = 0
m = 0
s = 0
for i in N:
	if 1 in i:
		c += 1
		m = c - 1
		break
	else:
		c += 1
if 1 in N1 or 1 in N5:
	s += 2
elif 1 in N2 or 1 in N4:
	s += 1
d = 0
for i in N[m]:
	if i == 1:
		if d == 0 or d == 4:
			s += 2
		elif d == 1 or d == 3:
			s += 1
	else:
		d += 1
print(s)


import sys
import math
import array
a = []
x = 0
y = 0
for i in range(0, 5):
	a.append([int(j) for j in input().split()])
for i in range(0, 5):
	for j in range(0, 5):
		if a[i][j] == 1:
			x = i
			y = j
print(abs(2 - x) + abs(2 - y))


matrix = []
for i in range(5):
	arr = list(map(int, input().split()))
	matrix.append(arr)
for (index, sublist) in enumerate(matrix):
	for j in range(5):
		if sublist[j] == 1:
			(row, col) = (index, j)
			break
moves = 0
if row != 2:
	moves = abs(row - 2)
if col != 2:
	moves = moves + abs(col - 2)
if col == 2 and row == 2:
	moves = 0
print(moves)


(dx, dy, tx, ty) = (int(), int(), int(), int)
for x in range(5):
	tm = input().split()
	for i in range(5):
		if tm[i] == '1':
			(tx, ty) = (x, i)
dx = abs(2 - tx)
dy = abs(2 - ty)
print(dx + dy)


n = 5
matrix = [[int(j) for j in input().split()] for i in range(n)]
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			(x, y) = (i, j)
r = 0
while x != 2 or y != 2:
	if y > 2:
		y -= 1
		r += 1
	elif y < 2:
		y += 1
		r += 1
	if x > 2:
		x -= 1
		r += 1
	elif x < 2:
		x += 1
		r += 1
print(r)


def detect_one(matrix):
	for i in range(len(matrix)):
		for j in range(len(matrix[0])):
			if matrix[i][j] == 1:
				return (i + 1, j, +1)

def abs(x):
	if x < 0:
		return x * -1
	return x
matrix = [[] for i in range(5)]
counter = 0
one = []
for row in matrix:
	row.extend([int(x) for x in input().split()])
	if 1 in row:
		one.append(counter + 1)
		one.append(row.index(1) + 1)
	counter += 1
diff = [abs(one[0] - 3), abs(one[1] - 3)]
print(diff[0] + diff[1])


col = 0
row = 0
found = 0
for i in range(0, 5):
	line = input().split(' ')
	if found != 1:
		for j in range(0, 5):
			if line[j] == '1':
				found = 1
				col = j + 1
				row = i + 1
				break
	else:
		continue
print(abs(col - 3) + abs(row - 3))


Matrix = [list(map(int, input().split()))]
Matrix.append(list(map(int, input().split())))
Matrix.append(list(map(int, input().split())))
Matrix.append(list(map(int, input().split())))
Matrix.append(list(map(int, input().split())))
for i in range(len(Matrix)):
	if 1 in Matrix[i]:
		j = Matrix[i].index(1)
		break
print(abs(i - 2) + abs(j - 2))


for i in range(5):
	temp = list(map(int, input().split()))
	if sum(temp) > 0:
		x_loc = i
		mat = temp
for i in range(5):
	if mat[i] == 1:
		y_loc = i
loc = abs(x_loc - 2) + abs(y_loc - 2)
print(loc)


matrix = []
for _ in range(5):
	temp = list(map(int, input().split()))
	matrix.append(temp)
row = 0
column = 0
move_row = 0
move_column = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			row = i
			column = j
if row == 0 or row == 4:
	move_row = 2
elif row == 1 or row == 3:
	move_row = 1
elif row == 0:
	move_row = 0
if column == 0 or column == 4:
	move_column = 2
elif column == 1 or column == 3:
	move_column = 1
elif column == 0:
	move_column = 0
print(move_column + move_row)


for i in range(5):
	row = [str(a) for a in input().split()]
	if '1' in row:
		print(abs(3 - (i + 1)) + abs(3 - (row.index('1') + 1)))


s = []
x = 0
j = 0
for n in range(5):
	s = list(map(int, input().split()))
	if 1 in s:
		x = n
		j = s.index(1)
print(abs(2 - x) + abs(2 - j))


line = []
for i in range(0, 5):
	line = input().split()
	for j in range(0, 5):
		aux = int(line[j])
		if aux == 1:
			print(abs(i - 2) + abs(j - 2))
			break


import math
for i_ in range(5):
	m = list(map(int, input().split()))
	if 1 in m:
		j = m.index(1)
		i = i_
i = i + 1
j = j + 1
print(abs(3 - i) + abs(3 - j))


li = []
for i in range(5):
	s = list(map(int, input().split()))
	li.append(s)
for i in range(len(li)):
	if 1 in li[i]:
		a = li[i].index(1)
		break
x = abs(i - 2)
y = abs(a - 2)
ans = x + y
print(ans)


z = []
for j in range(5):
	z.append([int(i) for i in input().split()][:5])
a = 0
b = 0
c = 0
for item in z:
	if item.count(1) == 1:
		if a == 2 and item.index(1) == 2:
			output = 0
		else:
			b = abs(2 - a)
			c = abs(2 - item.index(1))
			output = b + c
	a += 1
print(output)


a = []
ubicacion = []
for i in range(5):
	a = list(map(int, input().split()))
	for j in range(len(a)):
		if a[j] == 1:
			ubicacion.append(i)
			ubicacion.append(j)
m = 0
n = 0
if ubicacion[0] <= 2:
	while ubicacion[0] != 2:
		ubicacion[0] = ubicacion[0] + 1
		n = n + 1
else:
	while ubicacion[0] != 2:
		ubicacion[0] = ubicacion[0] - 1
		n = n + 1
if ubicacion[1] <= 2:
	while ubicacion[1] != 2:
		ubicacion[1] = ubicacion[1] + 1
		m = m + 1
else:
	while ubicacion[1] != 2:
		ubicacion[1] = ubicacion[1] - 1
		m = m + 1
mov = m + n
print(mov)


matrix = []
for i in range(5):
	ai = input()
	matrix.append(ai)
for i in matrix:
	if i != '0 0 0 0 0':
		unit = i
row = abs(2 - matrix.index(unit))
for i in unit:
	if i == '1':
		one = i
col = int(abs(4 - unit.index(one)) / 2)
print(col + row)


N = 5
matrix = [0] * N
for i in range(N):
	matrix[i] = list(map(int, input().split()))
for k in range(N):
	for j in range(N):
		if matrix[k][j] == 1:
			result = abs(3 - k - 1) + abs(3 - j - 1)
			break
print(result)


a = [[int(j) for j in input().split()] for i in range(5)]
for i in range(len(a)):
	for j in range(len(a)):
		if a[i][j] == 1:
			(line, column) = (i, j)
print(abs(line - 2) + abs(column - 2))


m = []
row = 0
column = 0
for i in range(0, 5):
	m.append(input().replace(' ', ''))
	count = 0
	for j in m[i]:
		if j == '1':
			row = i
			column = count
		count += 1
if row > 2:
	result = row - 2
else:
	result = 2 - row
if column > 2:
	result += column - 2
else:
	result += 2 - column
print(result)


matrix = []
matrix_rows = 5
for matrix_row in range(matrix_rows):
	matrix.append(input())
one_row = None
for (index, rows) in enumerate(matrix):
	if '1' in rows:
		one_row = index
one_position = None
for (index, numbers) in enumerate(matrix[one_row]):
	if '1' in numbers:
		one_position = index
vertical_movement = None
if one_row == 2:
	vertical_movement = 0
elif one_row == 1 or one_row == 3:
	vertical_movement = 1
else:
	vertical_movement = 2
horizontal_movement = None
if one_position == 4:
	horizontal_movement = 0
elif one_position == 2 or one_position == 6:
	horizontal_movement = 1
else:
	horizontal_movement = 2
amount_of_moves = vertical_movement + horizontal_movement
print(amount_of_moves)


a = []
for i in range(5):
	x = list(map(int, input().split()))
	for j in range(5):
		if x[j] == 1:
			str1 = i
			stlb1 = j
f = 0
while str1 != 2:
	if str1 > 2:
		str1 -= 1
		f += 1
	elif str1 < 2:
		str1 += 1
		f += 1
while stlb1 != 2:
	if stlb1 > 2:
		stlb1 -= 1
		f += 1
	elif stlb1 < 2:
		stlb1 += 1
		f += 1
print(f)


for i in range(5):
	a = list(map(int, input().split()))
	if 1 in a:
		mi = i
		for j in range(len(a)):
			if a[j] == 1:
				mj = j
print(abs(2 - mi) + abs(2 - mj))


n1 = input().split(' ')
n2 = input().split(' ')
n3 = input().split(' ')
n4 = input().split(' ')
n5 = input().split(' ')
l = [n1, n2, n3, n4, n5]
r = 0
c = 0
b = 0
for i in l:
	r = r + 1
	col = 0
	for j in i:
		col += 1
		if j == '1':
			c = col
			b = 1
			break
	if b == 1:
		break
if 3 - r < 0:
	r = (3 - r) * -1
else:
	r = 3 - r
if 3 - c < 0:
	c = (3 - c) * -1
else:
	c = 3 - c
print(r + c)


mat = []
submat = []
for i in range(5):
	submat = list(map(int, input().strip().split(' ')))
	if 1 in submat:
		(res, res1) = (submat.index(1) + 1, i + 1)
	mat.append(submat)
(res1, res) = (abs(3 - res1), abs(3 - res))
result = res + res1
print(result)


l = []
for x in range(5):
	t = list(map(int, input().split()))
	for y in range(5):
		if t[y] == 1:
			print(abs(2 - x) + abs(2 - y))


matrix = []
for i in range(5):
	row = input().split()
	matrix.append(row)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			a = int(i + 1)
			b = int(j + 1)
			break
print(abs(a - 3) + abs(b - 3))


m = []
for i in range(5):
	m.append([int(x) for x in input().split()])
index1 = 0
index2 = 0
for i in range(1, 6):
	for j in range(1, 6):
		if m[i - 1][j - 1] == 1:
			index1 = i
			index2 = j
d = abs(index1 - 3) + abs(index2 - 3)
print(d)


mat = []
for a in range(5):
	n = input().split()
	mat.append(n)
columns = 0
for a in mat:
	if '1' in a:
		find = a.index('1')
		rows = abs(find - 2)
		cols = abs(columns - 2)
		print(rows + cols)
		break
	columns += 1


l = list()
for i in [0, 1, 2, 3, 4]:
	p = list(map(int, input().split()))
	l.append(p)
x = 0
y = 0
for m in [0, 1, 2, 3, 4]:
	for n in [0, 1, 2, 3, 4]:
		if l[m][n] == 1:
			x = m
			y = n
c = 0
c = abs(x - 2) + abs(y - 2) + c
print(c)


mat = []
for _ in range(5):
	mat.append(input().split())
for (i, row) in enumerate(mat):
	for (j, c) in enumerate(row):
		if c == '1':
			print(str(abs(i - 2) + abs(j - 2)))


for i in range(5):
	n = list(map(int, input('\n').strip().split()))[:5]
	for j in n:
		if j == 1:
			s = abs(2 - i) + abs(2 - n.index(j))
			break
print(s)


m = []
for _ in range(5):
	m.append(list(map(int, input().split())))
(i, j) = (0, 0)
for (idx, row) in enumerate(m):
	if 1 in row:
		i = idx
		j = row.index(1)
		break
print(abs(i - 2) + abs(j - 2))


lista = []
for i in range(5):
	fila = input()
	lista.append(fila)
position = [0, 0]
count = 0
speller = 0
steps = 0
for i in lista:
	if '1' in i:
		position[1] = count
		hola = i.split(' ')
		for o in hola:
			if o == '1':
				position[0] = speller
				break
			speller += 1
	count += 1
x = position[0] + 1
y = position[1] + 1
if x != 3:
	if x > 3:
		steps += x - 3
	if x < 3:
		steps += 3 - x
if y != 3:
	if y > 3:
		steps += y - 3
	if y < 3:
		steps += 3 - y
print(steps)


mat = [[int(x) for x in input().split()] for i in range(5)]
for (i, j) in enumerate(mat):
	for (k, l) in enumerate(j):
		if l == 1:
			if k != 2 or i != 2:
				print(abs(i - 2) + abs(k - 2))
			else:
				print(0)


list_1 = list(map(int, input().split()))
list_2 = list(map(int, input().split()))
list_3 = list(map(int, input().split()))
list_4 = list(map(int, input().split()))
list_5 = list(map(int, input().split()))
matrix = [list_1, list_2, list_3, list_4, list_5]
x = 0
y = 0
for row in matrix:
	for col in row:
		if col != 0:
			x = int(matrix.index(row))
			y = int(row.index(col))
x += 1
y += 1
f = 0
s = 0

def result_1(x):
	if x > 3:
		s = x - 3
		return s
	else:
		s = 3 - x
		return s

def result_2(y):
	if y > 3:
		f = y - 3
		return f
	else:
		f = 3 - y
		return f
result_1(x)
result_2(y)
re = result_1(x) + result_2(y)
print(re)


for i in range(5):
	a = list(map(int, input().split()))
	for j in range(5):
		if a[j] == 1:
			row = j
			coloumb = i
if (row == 0 or row == 4) and (coloumb == 0 or coloumb == 4):
	print('4')
elif (row == 1 or row == 3) and (coloumb == 0 or coloumb == 4):
	print('3')
elif row == 2 and (coloumb == 0 or coloumb == 4):
	print('2')
elif (row == 1 or row == 3) and coloumb == 2:
	print('1')
elif (row == 1 or row == 3) and (coloumb == 1 or coloumb == 3):
	print('2')
elif row == 2 and (coloumb == 1 or coloumb == 3):
	print('1')
elif (row == 0 or row == 4) and (coloumb == 1 or coloumb == 3):
	print('3')
elif (row == 0 or row == 4) and coloumb == 2:
	print('2')
else:
	print('0')


li = input().split()
li = list(map(int, li))
count = 0
for i in range(5):
	if sum(li) == 1:
		count = i
		break
	else:
		li = input().split()
		li = list(map(int, li))
col = 0
for i in range(5):
	if li[i] == 1:
		col = i
		break
moves = abs(col - 2) + abs(count - 2)
print(moves)


a = []
for i in range(5):
	b = list(map(int, input().split()))
	a.append(b)
	try:
		(x, y) = (i, b.index(1))
	except:
		pass
(fin_x, fin_y) = (2, 2)
diff_x = abs(fin_x - x)
diff_y = abs(fin_y - y)
print(diff_x + diff_y)


(row, col) = (2, 6)
for i in range(5):
	lst = input().split()
	if '1' in lst:
		row = 1 + i
		col = lst.index('1') + 1
print(abs(3 - row) + abs(3 - col))


table = []
for i in range(5):
	temp = input().split(' ')
	temp = [int(i) for i in temp]
	table.append(temp)
moves = 0
for i in range(len(table)):
	if sum(table[i]) == 1:
		for l in range(len(table[i])):
			if table[i][l] == 1:
				moves += abs(2 - l) + abs(2 - i)
print(moves)


n = -3
for i in range(5):
	matrix = list(map(int, input().split(' ')))
	if sum(matrix) != 0:
		y = abs(i - 2)
		for j in range(5):
			if matrix[j] != 0:
				x = abs(j - 2)
print(x + y)


final_array = []
check_array = []
for _ in range(5):
	final_array.append(list(map(int, input().split())))
for index1 in range(len(final_array)):
	for index2 in range(len(final_array)):
		if final_array[index1][index2] == 1:
			check_array.append(index1)
			check_array.append(index2)
print(abs(2 - check_array[0]) + abs(2 - check_array[1]))


(a, b) = (0, 0)
flag = 0
for i in range(0, 5):
	s = input()
	s = s.split(' ')
	if flag == 1:
		continue
	for j in range(0, 5):
		if s[j] == '1':
			a = i
			b = j
			flag = 1
			break
ans = abs(2 - a) + abs(2 - b)
print(ans)


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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
L = []
for i in range(5):
	d = inlt()
	L.append(d)

def indice():
	for i in range(5):
		for j in range(5):
			if L[i][j] == 1:
				return [i, j]
a = indice()[0]
b = indice()[1]
c = abs(a - 2) + abs(b - 2)
print(c)


import math
for i in range(5):
	temp = [int(i) for i in input().split()]
	for j in range(5):
		if temp[j] == 1:
			ind_i = i
			ind_j = j
			break
print(abs(ind_i - 2) + abs(ind_j - 2))


from math import *
str_matrix = ''
point = 0
answer = 0
for i in range(5):
	str_matrix = input().replace(' ', '')
	for j in range(5):
		if str_matrix[j] == '1':
			point = i * 10 + j
			break
answer = fabs(2 - int(point / 10)) + fabs(2 - point % 10)
print(int(answer))


tot = 0
for i in range(5):
	numbers = list(map(int, input().split()))
	for number in numbers:
		if number != 0:
			tot += abs(i - 2)
			for j in range(5):
				if numbers[j] != 0:
					tot += abs(j - 2)
print(tot)


a0 = input().split(' ')
a1 = input().split(' ')
a2 = input().split(' ')
a3 = input().split(' ')
a4 = input().split(' ')
j = 0
one_found = False
for i in range(0, 5):
	if a0[i] == '1':
		one_found = True
		j = 0
		break
if one_found == False:
	for i in range(0, 5):
		if a1[i] == '1':
			one_found = True
			j = 1
			break
if one_found == False:
	for i in range(0, 5):
		if a2[i] == '1':
			one_found = True
			j = 2
			break
if one_found == False:
	for i in range(0, 5):
		if a3[i] == '1':
			one_found = True
			j = 3
			break
if one_found == False:
	for i in range(0, 5):
		if a4[i] == '1':
			one_found = True
			j = 4
			break
print(abs(i - 2) + abs(j - 2))


import math
x = 0
y = 0
line1 = [int(x) for x in input().split()]
for i in range(5):
	if line1[i] == 0:
		pass
	elif line1[i] == 1:
		x = abs(i - 2)
		y = 2
line2 = [int(x) for x in input().split()]
for i in range(5):
	if line2[i] == 0:
		pass
	elif line2[i] == 1:
		x = abs(i - 2)
		y = 1
line3 = [int(x) for x in input().split()]
for i in range(5):
	if line3[i] == 0:
		pass
	elif line3[i] == 1:
		x = abs(i - 2)
		y = 0
line4 = [int(x) for x in input().split()]
for i in range(5):
	if line4[i] == 0:
		pass
	elif line4[i] == 1:
		x = abs(i - 2)
		y = 1
line5 = [int(x) for x in input().split()]
for i in range(5):
	if line5[i] == 0:
		pass
	elif line5[i] == 1:
		x = abs(i - 2)
		y = 2
print(x + y)


import math
arr = []
for i in range(5):
	arr.append(input().split())
colIndex = -1
rowIndex = -1
for (j, i) in enumerate(arr):
	if '1' in i:
		rowIndex = j
		colIndex = i.index('1')
print(abs(int(rowIndex) - 2) + abs(int(colIndex) - 2))


from sys import stdin, stdout
input = stdin.readline

def write(n, sep='\n'):
	stdout.write(str(n))
	stdout.write(sep)

def gil():
	return list(map(int, input().split()))
for indi in range(5):
	mat = gil()
	if 1 in mat:
		row = indi + 1
		column = mat.index(1) + 1
print(abs(3 - row) + abs(3 - column))


matrix = []
row_column = []
moves = 0
for i in range(5):
	matrix.append(input().split())
mid_row = 3
mid_column = 3
for i in range(1, 6):
	for j in range(1, 6):
		if matrix[i - 1][j - 1] == '1':
			row = i
			column = j
		else:
			continue
row -= 3
column -= 3
row_column.append(row)
row_column.append(column)
for i in range(len(row_column)):
	if row_column[i] < 0:
		row_column[i] *= -1
	else:
		continue
for i in row_column:
	moves += i
print(moves)


matrix = [[0] * 5 for i in range(5)]
for i in range(5):
	matrix[i] = list(map(int, input().split()))
for i in range(5):
	for j in range(5):
		if matrix[i][j] != 0:
			(row, column) = (i, j)
count = 0
while True:
	if column == 2:
		break
	elif column < 2:
		count += 1
		column += 1
	else:
		count += 1
		column -= 1
while True:
	if row == 2:
		break
	elif row < 2:
		count += 1
		row += 1
	else:
		count += 1
		row -= 1
print(count)


k = 0
p = 0
for i in range(0, 5):
	s = input().split(' ')
	if '1' in s:
		k = i
		p = s.index(max(s))
print(abs(2 - k) + abs(2 - p))


a = [0 for i in range(5)]
for i in range(5):
	b = list(map(int, input().split()))
	a[i] = b
(fx, fy) = (3, 3)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			(x, y) = (i + 1, j + 1)
if fx == x and fy == y:
	print(0)
else:
	count = abs(fx - x) + abs(fy - y)
	print(count)


def _263A(grid):
	for row_index in range(5):
		if '1' in grid[row_index]:
			row = row_index
			col = grid[row_index].index('1')
	return abs(row - 2) + abs(col - 2)
grid = []
for index in range(5):
	grid.append(input().split())
print(_263A(grid))


one_i = 0
one_j = 0
input_lines = []
for i in range(0, 5):
	input_lines.append(input())
	j = 0
	for char in input_lines[i].split(' '):
		if char == '1':
			one_i = i + 1
			one_j = j + 1
			break
		j += 1
print(abs(3 - one_i) + abs(3 - one_j))


for r in range(1, 6):
	row = [int(x) for x in input().split(' ')]
	if 1 in row:
		c = row.index(1)
		steps = abs(3 - r) + abs(3 - c - 1)
		print(steps)


m = []
for row in range(5):
	s = input()
	r = s.split(' ')
	r = [int(i) for i in r if i != '']
	m.append(r)
col_idx = 0
row_idx = 0
for row in range(5):
	try:
		col_idx = m[row].index(1)
		row_idx = row
	except:
		continue
r_c = 2
c_c = 2
print(abs(row_idx - r_c) + abs(c_c - col_idx))


lvl = 0
s = [[], [], [], [], []]
s[0] = list(input().split())
s[1] = list(input().split())
s[2] = list(input().split())
s[3] = list(input().split())
s[4] = list(input().split())
a = 0
for i in s:
	a += 1
	b = 0
	for j in i:
		b += 1
		if j == '1':
			m = a
			n = b
			break
m = abs(m - 3)
n = abs(n - 3)
print(m + n)


s = 0
a = '21012'
for i in range(5):
	n_1 = [x for x in input().split()]
	n = ''.join(n_1)
	num = n.find('1') + 1
	if num != 0:
		s = abs(num - 3) + int(a[i])
print(s)


import sys
import math
from sys import stdin, stdout

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

def get_string():
	return sys.stdin.readline().strip()
n = 5
arr = [[0] * 5] * int(n)
for i in range(0, n):
	arr[i] = get_ints()
for i in range(0, n):
	for k in range(0, n):
		if arr[i][k] == 1:
			stdout.write(str(abs(i - 2) + abs(k - 2)))


def fixMatrix(m):
	row = 0
	col = 0
	f = False
	for i in range(len(m)):
		for j in range(len(m[i])):
			if int(m[i][j]) == 1:
				row = i
				col = j
				f = True
				break
		if f:
			break
	total = 0
	if row > 2:
		total += row - 2
	else:
		total += 2 - row
	if col > 2:
		total += col - 2
	else:
		total += 2 - col
	return total
matriz = []
for i in range(5):
	renglon = input().split()
	matriz.append(renglon)
print(fixMatrix(matriz))


matrix = []
columnNo = 0
rowNo = 0
for i in range(0, 5):
	matrix.append(input().split(' '))
for (rowIndex, row) in enumerate(matrix):
	for (columnIndex, column) in enumerate(row):
		if column == '1':
			columnNo = columnIndex
			rowNo = rowIndex
print(abs(columnNo - 2) + abs(rowNo - 2))


import random
vectors = []
x1 = 0
x2 = 0
for i in range(5):
	vector = list(map(int, input().split(' ')))
	vectors.append(vector)
for i in range(0, len(vectors)):
	for j in range(0, 5):
		if vectors[i][j] == 1:
			x = j + 1
			y = i + 1
sum = abs(x - 3) + abs(y - 3)
print(sum)


middle_y = 3
middle_x = 3
lines = []
for i in range(5):
	lines.insert(i, input())
for i in range(5):
	line = [int(x) for x in lines[i].split()]
	idx = 0
	for val in line:
		if val > 0:
			swap_x = abs(idx + 1 - middle_x)
			swap_y = abs(i + 1 - middle_y)
			print(swap_x + swap_y)
		idx += 1


l = []
for i in range(5):
	l1 = []
	l1 = list(map(int, input().split()))
	l.append(l1)
if l[0][0] == 1 or l[0][4] == 1 or l[4][0] == 1 or (l[4][4] == 1):
	print(4)
elif l[0][1] == 1 or l[0][3] == 1 or l[1][0] == 1 or (l[1][4] == 1) or (l[3][0] == 1) or (l[3][4] == 1) or (l[4][1] == 1) or (l[4][3] == 1):
	print(3)
elif l[0][2] == 1 or l[1][1] == 1 or l[1][3] == 1 or (l[2][0] == 1) or (l[2][4] == 1) or (l[3][1] == 1) or (l[3][3] == 1) or (l[4][2] == 1):
	print(2)
elif l[1][2] == 1 or l[2][1] == 1 or l[3][2] == 1 or (l[2][3] == 1):
	print(1)
elif l[2][2] == 1:
	print(0)


a = []
count = 0
for i in range(5):
	arr = list(map(int, input().split()))
	a.append(arr)
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			m = i
			n = j
if m < 2:
	while m != 2:
		for j in range(5):
			t = a[m][j]
			a[m][j] = a[m + 1][j]
			a[m + 1][j] = t
		m = m + 1
		count = count + 1
if m > 2:
	while m != 2:
		for j in range(5):
			t = a[m][j]
			a[m][j] = a[m - 1][j]
			a[m - 1][j] = t
		m = m - 1
		count = count + 1
if n < 2:
	while n != 2:
		for i in range(5):
			t = a[i][n]
			a[i][n] = a[i][n + 1]
			a[i][n + 1] = t
		n = n + 1
		count = count + 1
if n > 2:
	while n != 2:
		for i in range(5):
			t = a[i][n]
			a[i][n] = a[i][n - 1]
			a[i][n - 1] = t
		n = n - 1
		count = count + 1
print(count)


import sys

def get_vals(func=str):
	return map(func, input().split())

def get(func=str):
	return func(input())
input = lambda : sys.stdin.readline().rstrip('\r\n')
write = sys.stdout.write

def test():
	pass

def main():
	for (i, line) in enumerate(sys.stdin):
		line = [*map(int, line.split())]
		try:
			index = line.index(1)
		except ValueError:
			continue
		else:
			print(abs(2 - index) + abs(2 - i))
main()


matrix = []
for i in range(5):
	matrix.append(list(input().split()))
m = -1
n = -1
for j in range(5):
	for k in range(5):
		if matrix[j][k] == '1':
			m = j
			n = k
			break
print(abs(m - 2) + abs(n - 2))


index = -1
col = -1
for i in range(5):
	line = input()
	row = [int(s) for s in line.split()]
	try:
		index = row.index(1)
		col = i
	except:
		continue
print(abs(2 - index) + abs(2 - col))


array_input = []
for x in range(5):
	array_input.append([int(y) for y in input().split()])
(indi, indy) = (0, 0)
for i in range(5):
	for j in range(5):
		if array_input[i][j] == 1:
			indi = i
			indy = j
print(abs(2 - indi) + abs(2 - indy))


u = 0
v = 0
tot = 0
list1 = [int(x) for x in input('').split()]
list2 = [int(y) for y in input('').split()]
list3 = [int(f) for f in input('').split()]
list4 = [int(g) for g in input('').split()]
list5 = [int(b) for b in input('').split()]
for i in range(1, 6):
	if list1[i - 1] == 1:
		u = 1
		v = i
	elif list2[i - 1] == 1:
		u = 2
		v = i
	elif list3[i - 1] == 1:
		u = 3
		v = i
	elif list4[i - 1] == 1:
		u = 4
		v = i
	elif list5[i - 1] == 1:
		u = 5
		v = i
if v == 3 and u == 3:
	print(0)
elif u == 3:
	print(abs(3 - v))
else:
	print(abs(3 - u) + abs(3 - v))


for i in range(5):
	elems = list(map(int, input().split(' ')))
	try:
		j = elems.index(1)
		startRow = i
		startColumn = j
	except ValueError:
		pass
numSteps = abs(2 - startRow) + abs(2 - startColumn)
print(numSteps)


l = [list(map(int, input().split())) for i in range(5)]
r = [i for i in range(len(l)) if 1 in l[i]]
c = l[r[0]].index(1)
source = [r[0], c]
dest = [2, 2]
count = 0
while source[0] != dest[0] or source[1] != dest[1]:
	if source[0] != dest[0]:
		if source[0] < dest[0]:
			source[0] = source[0] + 1
		else:
			source[0] = source[0] - 1
		count = count + 1
	if source[1] != dest[1]:
		if source[1] < dest[1]:
			source[1] = source[1] + 1
		else:
			source[1] = source[1] - 1
		count = count + 1
print(count)


for i in range(5):
	k = input().split()
	if k.count('1') > 0:
		x_pos = k.index('1') + 1
		y_pos = i + 1
print(abs(x_pos - 3) + abs(y_pos - 3))


l = 0
for i in range(5):
	s = [int(x) for x in input().split()]
	l += 1
	if 1 in s:
		a = s.index(1) + 1
		b = l
if a > 3:
	a = a - 3
elif a < 3:
	a = 3 - a
elif a == 3:
	a = 0
if b > 3:
	b = b - 3
elif b < 3:
	b = 3 - b
elif b == 3:
	b = 0
print(a + b)


for i in range(0, 5):
	l = input()
	if l.find('1') > -1:
		a = i
		b = int(l.find('1') / 2)
print(abs(a - 2) + abs(b - 2))


def matrix():
	array = [[0 for x in range(5)] for y in range(5)]
	for i in range(5):
		array[i] = input().split()
	for j in range(5):
		for k in range(5):
			if '1' in array[j][k]:
				x = j
				y = k
			else:
				continue
	count = 0
	while x != 2:
		if x > 2:
			x -= 1
			count += 1
		elif x < 2:
			x += 1
			count += 1
	while y != 2:
		if y > 2:
			y -= 1
			count += 1
		elif y < 2:
			y += 1
			count += 1
	print(count)
matrix()


m = []
for i in range(5):
	ii = input().replace(' ', '').find('1')
	if ii != -1:
		res = abs(2 - ii) + abs(2 - i)
print(res)


lista = []
for i in range(5):
	lista.append(input(''))
indI = 0
indJ = 0
for i in range(5):
	line = lista.pop()
	lineStr = line.split(' ')
	for j in range(5):
		a = int(lineStr.pop())
		if a == 1:
			indI = i + 1
			indJ = j + 1
result = abs(indI - 3) + abs(indJ - 3)
print(result)


found = False
for i in range(5):
	matrix_row = list(map(int, input().split()))
	for j in range(5):
		if matrix_row[j] == 1:
			print(abs(2 - i) + abs(2 - j))
			found = True
			break
	if found:
		break


try:
	li = []
	for _ in range(5):
		li.append(list(map(int, input().split())))
	for i in range(5):
		for j in range(5):
			if li[i][j] == 1:
				print(abs(i - 2) + abs(j - 2))
except:
	pass


import math
mat = [input().split() for i in range(5)]
x = False
for i in range(5):
	for j in range(5):
		if mat[i][j] == '1':
			print(abs(2 - i) + abs(2 - j))
			x = True
			break
	if x:
		break


import sys
icount = 0
for i in range(1, 6):
	l = sys.stdin.readline().split()
	if '1' in l:
		icount = i
		jcount = l.index('1')
jcount += 1
minMoves = abs(jcount - 3) + abs(icount - 3)
print(minMoves)


arr1 = input().split()
arr2 = input().split()
arr3 = input().split()
arr4 = input().split()
arr5 = input().split()
result = [arr1, arr2, arr3, arr4, arr5]
for i in range(5):
	for j in range(5):
		if result[i][j] == '1':
			m = abs(j - 2) + abs(i - 2)
			print(m)


matrix = []
r = 5
c = 5
for i in range(r):
	a = []
	a = list(map(int, input().split()))
	matrix.append(a)
r1 = int(r / 2)
c1 = int(c / 2)
for i in range(r):
	for j in range(c):
		if matrix[i][j] == 1:
			g = abs(r1 - i)
			f = abs(c1 - j)
			d = g + f
print(d)


index1 = 0
index2 = 0
for i in range(1, 6, 1):
	a = list(input().split())
	for j in range(len(a)):
		if a[j] == '1':
			index1 = i
			index2 = j + 1
print(abs(index1 - 3) + abs(index2 - 3))


line = 0
col = 0
for x in range(0, 5):
	s = input()
	s = s.replace(' ', '')
	res = s.find('1')
	if res != -1:
		line = x + 1
		col = res + 1
print(abs(col - 3) + abs(line - 3))


a = []
for i in range(5):
	t = input().split(' ')
	t = list(map(int, t))
	a.append(t)
ans = 0
for i in a:
	c = i.count(1)
	if c > 0:
		b = i.index(1)
		num = abs(2 - b)
		num += abs(2 - a.index(i))
		ans = abs(num)
		break
print(ans)


L = []
for i in range(5):
	L.append(list(map(int, input().split())))
for i in range(5):
	if 1 in L[i]:
		a = (i, L[i].index(1))
		print(abs(2 - a[0]) + abs(2 - a[1]))
		break


a = []
for i in range(5):
	a.append(list((int(y) for y in input().split())))
c = 0
for i in a:
	for j in i:
		if j == 1:
			col = i.index(j)
			row = a.index(i)
			c = abs(col - 2) + abs(row - 2)
print(c)


a = [[int(i) for i in input().split(' ')] for j in range(5)]
b = 0
c = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			b = i
			c = j
sum = abs(b - 2) + abs(c - 2)
print(sum)


matrix = list()
while True:
	matrix.append(input().split())
	if len(matrix) == 5:
		break
count = 1
for i in matrix:
	if '1' in i:
		temp = i.index('1') + 1
		break
	else:
		count += 1
x = abs(3 - count)
y = abs(3 - temp)
temp = x + y
print(temp)


Matrix = [0] * 5
point = [0, 0]
for i in range(5):
	string = input().split()
	for j in range(5):
		string[j] = int(string[j])
		if string[j] == 1:
			point[0] = i + 1
			point[1] = j + 1
	Matrix[i] = string
res = abs(3 - point[0]) + abs(3 - point[1])
print(res)


for i in range(1, 5 + 1):
	l = list(map(int, input().split()))
	if 1 in l:
		p = i
		q = l.index(1) + 1
print(abs(3 - p) + abs(3 - q))


def getOnePosition(matrix):
	for (x, row) in enumerate(matrix):
		if 1 in row:
			return (x, row.index(1))
matrix = [list(map(int, input().split(' '))) for _ in range(0, 5)]
(x, y) = getOnePosition(matrix)
print(abs(x - 2) + abs(y - 2))


def switchRows(row1, row2):
	global row, count
	if row == row1:
		row = row2
	elif row == row2:
		row = row1
	count += 1

def switchColumns(clm1, clm2):
	global clm, count
	if clm == clm1:
		clm = clm2
	elif clm == clm2:
		clm = clm1
	count += 1
matrix = []
count = 0
row = 0
clm = 0
for r in range(5):
	matrix.append(list(map(int, input().rstrip().split())))
	if 1 in matrix[r]:
		row = r
		clm = matrix[r].index(1)
while clm != 2:
	if clm < 2:
		switchColumns(clm, clm + 1)
	else:
		switchColumns(clm, clm - 1)
while row != 2:
	if row < 2:
		switchRows(row, row + 1)
	else:
		switchRows(row, row - 1)
print(count)


def main():
	x = 0
	y = 0
	for i in range(5):
		arr = input().split(' ')
		if '1' in arr:
			x = i
			for j in range(5):
				if arr[j] == '1':
					y = j
	print(abs(x - 2) + abs(y - 2))
main()


(i, j) = (0, 0)
for y in range(5):
	x = ''.join(input().split()).find('1')
	if x != -1:
		(i, j) = (y, x)
print(abs(2 - i) + abs(2 - j))


import math
matrix = [list(map(int, input().split())) for i in range(5)]
row_counter = 0
for i in range(5):
	if sum(matrix[i]) > 0:
		break
	row_counter += 1
col_counter = 0
for i in range(5):
	if matrix[row_counter][i] == 1:
		break
	col_counter += 1
row = abs(row_counter - 2)
col = abs(col_counter - 2)
print(row + col)


for _ in range(5):
	a = list(input().split())
	if '1' in a:
		x = a.index('1')
		print(abs(2 - _) + abs(2 - x))
		break


rows = [input().split() for i in range(5)]
pos = [0, 0]
for (i, row) in enumerate(rows, start=1):
	for (j, currVal) in enumerate(row, start=1):
		if currVal == '1':
			pos = [i, j]
print(abs(pos[0] - 3) + abs(pos[1] - 3))


for i in range(0, 5):
	s = input().split()
	a = ''.join(s)
	j = a.find('1')
	if j >= 0:
		n = abs(2 - i)
		k = abs(2 - j)
		print(n + k)
		break


for row in range(5):
	column = input()
	if column.find('1') != -1:
		print(int(abs(2 - column.find('1') / 2) + abs(2 - row)))


for i in range(1, 6):
	a = input()
	if '1' in a:
		b = i
		c = a.find('1') // 2 + 1
print(abs(b - 3) + abs(c - 3))


from math import fabs

class Matrix:

	def __init__(self):
		self.matrix = []
		for i in range(5):
			self.matrix.append(input().split())

	def answer(self):
		for i in range(5):
			if '1' in self.matrix[i]:
				for j in range(5):
					if self.matrix[i][j] == '1':
						index = [i, j]
						return int(fabs(2 - index[0]) + fabs(2 - index[1]))
matrix = Matrix()
print(matrix.answer())


m = [list(map(int, input().split())) for _ in range(5)]
mid = 2
k = 0
for i in range(5):
	for j in range(5):
		if m[i][j] == 1:
			if i == 2 and j == 2:
				print('0')
				break
			else:
				count = abs(mid - i) + abs(mid - j)
				print(count)
				break


a = [[int(x) for x in input().split()] for i in range(5)]
sum1 = 0
for j in a:
	if 1 in j:
		sum1 = abs(a.index(j) + 1 - 3) + abs(j.index(1) + 1 - 3)
		break
print(sum1)


a = [[int(x) for x in input().split()] for i in range(5)]
i = 0
j = 0
flag = 0
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			flag = 1
			break
	if flag == 1:
		break
x = i
y = j
h = abs(x - 2)
v = abs(y - 2)
print(h + v)


for i in range(1, 5 + 1):
	a = input().split()
	for j in a:
		c = int(j)
		if c == 1:
			d = a
			e = i
for k in range(5):
	f = int(d[k])
	if f == 1:
		b = k + 1
print(max(3 - e, e - 3) + max(b - 3, 3 - b))


for i in range(5):
	row = input()
	if '1' in row:
		j = row.split().index('1')
		break
moves = abs(2 - i) + abs(2 - j)
print(moves)


Matrix = [list(map(int, input().split())) for i in range(5)]
for i in Matrix:
	if sum(i) == 1:
		z = Matrix.index(i)
		x = i.index(1)
count = z - 2 if z > 2 else 2 - z
count += x - 2 if x > 2 else 2 - x
print(count)


def matrix():
	matrix = []
	for i in range(5):
		matrix.append(input().split())
	x_var = 0
	y_var = 0
	for x in range(len(matrix[0])):
		for y in range(len(matrix)):
			if matrix[x][y] == '1':
				if x >= 2:
					x_var = x - 2
				else:
					x_var = 2 - x
				if y >= 2:
					y_var = y - 2
				else:
					y_var = 2 - y
	print(x_var + y_var)
matrix()


import math
s = []
for i in range(5):
	x = input()
	x = x.split()
	s += x
idx = int(s.index('1'))
idx += 1
a = math.ceil(idx / 5)
b = idx % 5
if b == 0:
	b = 5
print(abs(a - 3) + abs(b - 3))


for i in range(5):
	a = input().split()
	if '1' in a:
		b = i + 1
		c = a.index('1') + 1
		x = abs(b - 3)
		y = abs(c - 3)
		print(x + y)


def pos():
	y = 0
	for i in range(5):
		row = [int(x) for x in input().split()]
		x = 0
		for b in range(len(row)):
			if row[b] == 1:
				x = b
				return (x, y)
		y += 1
(x, y) = pos()
print(abs(x - 2) + abs(y - 2))


li = []
_i = 0
_j = 0
for i in range(5):
	li.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if li[i][j] == 1:
			_i = i + 1
			_j = j + 1
			print(abs(3 - _i) + abs(3 - _j))
			break


for g in range(1, 6):
	m = input().split()
	for p in range(len(m)):
		if m[p] == '1':
			i = p + 1
			j = g
if i > 3:
	if j > 3:
		print(i - 3 + (j - 3))
	if j <= 3:
		print(i - 3 + (3 - j))
if i <= 3:
	if j > 3:
		print(3 - i + (j - 3))
	if j <= 3:
		print(3 - i + (3 - j))


ls = []
for i in range(5):
	row = input()
	ls.append(row.split(' '))
for i in range(5):
	for j in range(5):
		if int(ls[i][j]) == 1:
			coord1 = i
			coord2 = j
distance = abs(2 - coord1) + abs(2 - coord2)
print(distance)


n = 5
arr = []
while n:
	m = list(map(int, input().split()))
	arr.append(m)
	n -= 1
target = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			target = abs(2 - i) + abs(2 - j)
			break
print(target)


mat = []
for i in range(5):
	mat.append(input().split())
coord = [(x, y) for (x, row) in enumerate(mat) for (y, col) in enumerate(row) if col == '1']
move = abs(coord[0][0] - 2) + abs(coord[0][1] - 2)
print(move)


lineNum = 0
line = input()
while '1' not in line:
	lineNum += 1
	line = input()
print(abs(2 - lineNum) + abs(line.index('1') // 2 - 2))


import math

def distance(distance1, distance2):
	num1 = abs(distance1[0] - distance2[0])
	num2 = abs(distance1[1] - distance2[1])
	result = num1 + num2
	return result
lines = []
for i in range(0, 5):
	line = []
	user_input = input()
	line = user_input.split()
	lines.append(line)
center = (2, 2)
one = ()
for outer in range(0, 5):
	for inner in range(0, 5):
		if lines[inner][outer] == '1':
			one = (inner, outer)
print(distance(one, center))


def sol():
	(x, y) = (3, 3)
	for i in range(1, 6):
		s = input().split(' ')
		if '1' in s:
			row = i
			column = s.index('1') + 1
			break
	return abs(row - x) + abs(column - y)
print(sol())


x = 0
y = 0
loop = True
a = []
for l in range(5):
	a.append(list(map(int, input().split())))
for i in range(5):
	x = 0
	for j in range(5):
		if a[i][j] == 1:
			loop = False
			break
		x += 1
	if not loop:
		break
	y += 1
print(abs(2 - x) + abs(2 - y))


for i in range(5):
	b = input().split()
	for j in range(len(b)):
		if b[j] == '1':
			n = j
			m = i
print(abs(n - 2) + abs(m - 2))


q = []
for i in range(5):
	a = list(map(int, input().split()))
	q.append(a)
ans = 0
for i in q:
	r = q.index(i)
	for j in i:
		if j == 1:
			if r == 0 or r == 4:
				ans += 2
			if r == 1 or r == 3:
				ans += 1
			e = i.index(j)
			if e == 0 or e == 4:
				ans += 2
			if e == 1 or e == 3:
				ans += 1
print(ans)


for _ in range(5):
	arr = list(map(int, input().split()))
	if 1 in arr:
		x = arr.index(1)
		print(abs(2 - x) + abs(2 - _))
		exit()


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
result = None
for row_idx in range(5):
	row = inlt()
	if result is None:
		for (idx, position) in enumerate(row):
			if position == 1:
				result = abs(3 - (row_idx + 1)) + abs(3 - (idx + 1))
print(result)


matrix = []
for i in range(5):
	li = [int(x) for x in input().split()]
	matrix.append(li)
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			r = i
			c = j
rdif = abs(r - 2)
cdif = abs(c - 2)
print(f'{rdif + cdif}')


i1 = input()
i2 = input()
i3 = input()
i4 = input()
i5 = input()
s = 0
i1_1 = list(i1.replace(' ', ''))
i2_2 = list(i2.replace(' ', ''))
i3_3 = list(i3.replace(' ', ''))
i4_4 = list(i4.replace(' ', ''))
i5_5 = list(i5.replace(' ', ''))
if '1' in i1_1 or '1' in i5_5:
	try:
		i = i1_1.index('1')
	except ValueError:
		i = i5_5.index('1')
	if i == 0 or i == 4:
		s = 4
	elif i == 1 or i == 3:
		s = 3
	else:
		s = 2
elif '1' in i2_2 or '1' in i4_4:
	try:
		i = i2_2.index('1')
	except ValueError:
		i = i4_4.index('1')
	if i == 0 or i == 4:
		s = 3
	elif i == 1 or i == 3:
		s = 2
	else:
		s = 1
elif '1' in i3_3:
	i = i3_3.index('1')
	if i == 0 or i == 4:
		s = 2
	elif i == 1 or i == 3:
		s = 1
	else:
		s = 0
print(s)


for a in range(0, 5):
	l1 = list(map(int, input().strip().split()))
	if 1 in l1:
		res = [a, l1.index(1)]
print(abs(res[0] - 2) + abs(2 - res[1]))


from sys import stdin, stdout
input = stdin.readline

def write(n, sep='\n'):
	stdout.write(str(n))
	stdout.write(sep)

def gil():
	return list(map(int, input().split()))
for i in range(5):
	l = gil()
	if 1 in l:
		r = i + 1
		c = l.index(1) + 1
		ans = abs(r - 3) + abs(c - 3)
print(ans)


mX = []
for i in range(1, 6):
	a = list(map(int, input().split(' ')))
	if 1 in a:
		yV = a.index(1) + 1
		xV = i
print(abs(xV - 3) + abs(yV - 3))


for i in range(1, 6):
	s = list(map(int, input().split()))
	if s.count(1):
		j = s.index(1) + 1
		print(abs(3 - j) + abs(3 - i))
		break


matrix = []
for _ in range(5):
	matrix.extend(input().split())
(x, y) = divmod(matrix.index('1'), 5)
print(abs(x - 2) + abs(y - 2))


ind1 = None
ind2 = None
finInd1 = 2
finInd2 = 2
for i in range(5):
	temp = [i for (i, x) in enumerate(input().split()) if int(x) == 1]
	if len(temp) == 1:
		ind1 = i
		ind2 = temp[0]
print(abs(finInd1 - ind1) + abs(finInd2 - ind2))


l = []
for i in range(5):
	i = list(map(int, input().split()))
	l += [i]
a = -1
b = 0
for r in l:
	a += 1
	if 1 in r:
		b = r.index(1)
		a = l.index(r)
		if a > 2:
			a = 4 - a
		if b > 2:
			b = 4 - b
		print(4 - a - b)
		break


for i in range(5):
	for j in range(5):
		x = input().split(' ')
		if '1' not in x:
			break
		if '1' in x:
			j = x.index('1')
			print(abs(i - 2) + abs(j - 2))
			break
	if '1' in x:
		break


(i, j) = (0, 0)
for k in range(5):
	param = input().split(' ')
	if '1' in param:
		i = k + 1
		j = param.index('1') + 1
print(abs(i - 3) + abs(j - 3))


arr = [[0] * 5 for i in range(5)]

def addToArray(index, arr1):
	count = 0
	for k in range(0, 5):
		arr[index][k] = arr1[k]
		if arr1[k] == 1:
			count += abs(2 - index)
			count += abs(2 - k)
			print(count)
			return False
	return True
for i in range(0, 5):
	inputArr = [int(x) for x in input().strip().split()]
	if addToArray(i, inputArr) == False:
		break


a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
e = [int(i) for i in input().split()]
m = 0
j = 0
for i in range(5):
	if a[i] == 1:
		m += 1
		break
	elif b[i] == 1:
		m += 2
		break
	elif c[i] == 1:
		m += 3
		break
	elif d[i] == 1:
		m += 4
		break
	elif e[i] == 1:
		m += 5
		break
if i == 0 or i == 4:
	j += 2
elif i == 1 or i == 3:
	j += 1
if m == 1 or m == 5:
	j += 2
elif m == 2 or m == 4:
	j += 1
print(j)


(pozi, pozj) = (0, 0)
for i in range(5):
	if pozi != 0:
		break
	v = input().split()
	for j in range(5):
		if v[j] == '1':
			pozi = i + 1
			pozj = j + 1
			break
print(abs(3 - pozi) + abs(3 - pozj))


mat = []
for i in range(0, 5):
	mat.append(list(map(int, input().split())))
for i in range(0, 5):
	for j in range(0, 5):
		if mat[i][j] == 1:
			idx1 = abs(i + 1 - 3)
			idx2 = abs(j + 1 - 3)
			print(idx1 + idx2)
			break


import math
for i in range(5):
	a = [int(x) for x in input().split()]
	for j in range(5):
		if a[j] == 1:
			sum = 0
			x = i + 1
			y = j + 1
			sum += abs(x - 3) + abs(y - 3)
print(sum)


m = []
(c1, c2) = (0, 0)
for x in range(0, 5):
	m = list(map(int, input().split()))
	if 1 in m:
		c1 = x + 1
		for x2 in range(0, 5):
			if m[x2] == 1:
				c2 = x2 + 1
				break
print(str(abs(c1 - 3) + abs(c2 - 3)))


row = 0
column = 0
is_found = False
for i in range(5):
	li = list(map(int, input().strip().split(' ')))
	for i in range(5):
		if li[i] == 1:
			column = i
			is_found = True
			break
	if is_found:
		break
	row += 1
remainder = abs(2 - row) + abs(2 - column)
print(remainder)


x = [input().split() for _ in range(5)]
i = 0
for ad in x:
	i = i + 1
	if any((er == '1' for er in ad)):
		b = ad.index('1') + 1
		break
	else:
		continue
print(abs(i - 3) + abs(b - 3))


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()))
bigL = []
for i in (a, b, c, d, e):
	bigL.append(i)
for row in bigL:
	for column in row:
		if column == 1:
			x = row.index(column)
			y = bigL.index(row)
			if x == 2 and y == 2:
				print('0')
			else:
				print(abs(2 - x) + abs(2 - y))


array = []
for i in range(5):
	array.append(list(map(str, input().split(' '))))
for i in range(5):
	for j in range(5):
		if array[i][j] == '1':
			ans = abs(i - 2) + abs(j - 2)
print(ans)


k = []
rows = 0
col = 0
for i in range(1, 6):
	x = list(map(int, input().split()))
	if 1 in x:
		rows = i
	k.append(x)
for i in range(5):
	if k[rows - 1][i] == 1:
		col = i + 1
print(abs(col - 3) + abs(rows - 3))


x = []
y = []
for i in range(5):
	s = input().split()
	s = list(map(int, s))
	y.append(s)
y
i = [(ix, iy) for (ix, row) in enumerate(y) for (iy, i) in enumerate(row) if i == 1]
n = abs(i[0][0] - 2) + abs(i[0][1] - 2)
print(n)


import sys
matrix = []
answer = 0
for i in range(5):
	row = sys.stdin.readline().split()
	for j in range(len(row)):
		r = int(row[j])
		if r == 1:
			answer = abs(i + 1 - 3) + abs(j + 1 - 3)
			break
print(answer)


row = 0
col = 0
for i in range(1, 6):
	s = input().replace(' ', '')
	r = s.find('1')
	if r != -1:
		col = r + 1
		row = i
		break
print(abs(3 - row) + abs(3 - col))


(x, y, c) = (-1, -1, -1)
for i in range(5):
	a = [int(j) for j in input().split()]
	c += 1
	if a.__contains__(1):
		x = a.index(1)
		y = c
print(abs(x - 2) + abs(y - 2))


l = f = []
for _ in range(5):
	f = list(map(int, input().split()))
	l.append(f)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			print(abs(3 - i - 1) + abs(3 - j - 1))


l = []
s = 0
m = 0
for i in range(5):
	n = input().split()
	l.append(n)
for i in range(5):
	if '1' in l[i]:
		s = i + 1
for i in range(5):
	if l[s - 1][i] == '1':
		m = i + 1
print(abs(m - 3) + abs(s - 3))


row_no = -3
col_no = -3
row_max = '0 0 0 0 0'
for i in range(0, 5):
	row = input()
	row_no = row_no + 1
	if row > row_max:
		row_max = row
		break
row_no = abs(row_no)
n1 = row_no % 3
row_max = row_max.split()
l = len(row_max)
for i in range(0, l):
	col_no = col_no + 1
	if row_max[i] == '1':
		break
col_no = abs(col_no)
n2 = col_no % 3
n = n1 + n2
print(n)


data = []
for _ in range(5):
	data.append(list(map(int, input().split())))
for i in range(len(data)):
	if data[i].__contains__(1):
		print(abs(i - 2) + abs(data[i].index(1) - 2))
		break


supermatrix = []
for i in range(5):
	matrix = list(map(int, input().split()))
	supermatrix.append(matrix)
for i in supermatrix:
	if 1 in i:
		ind = [supermatrix.index(i), i.index(1)]
for i in range(2):
	ind[i] = abs(2 - ind[i])
print(sum(ind))


try:
	m = []
	for i in range(5):
		l = list(map(int, input().split()))
		if l.count(1) == 1:
			m.append(i + 1)
			m.append(l.index(1) + 1)
	print(abs(3 - m[0]) + abs(3 - m[1]))
except:
	pass


matr = []
for x in range(5):
	matr.append(input().split())
loc = []
for x in range(5):
	for y in range(5):
		if int(matr[x][y]) == 1:
			loc = [x, y]
dist = abs(loc[0] - 2) + abs(loc[1] - 2)
print(dist)


l = []
for i in range(5):
	a = [int(x) for x in input().split()]
	l.append(a)
a = 0
b = 0
for i in range(5):
	t = l[i]
	for J in range(5):
		if str(t[J]) == '1':
			a = J
			b = i
print(abs(a + 2 - 4) + abs(b + 2 - 4))


a = [[int(j) for j in input().split()] for i in range(5)]
for i in range(5):
	for j in range(len(a[i])):
		if a[i][j] == 1:
			inum1 = i
			jnum1 = j
print(abs(inum1 - 2) + abs(jnum1 - 2))


l = [input().split(), input().split(), input().split(), input().split(), input().split()]
x = 0
for i in range(5):
	if l[i].count('1') == 1:
		x = abs(2 - l[i].index('1')) + abs(2 - i)
print(x)


moves = 0
for i in range(0, 5):
	line = input()
	if line.__contains__('1'):
		moves += abs(2 - i)
		line = line.split(' ')
		moves += abs(2 - line.index('1'))
		break
print(moves)


l1 = input().split()
l2 = input().split()
l3 = input().split()
l4 = input().split()
l5 = input().split()
x = []
y = [3, 3]
if '1' in l1:
	x.append(1)
	x.append(l1.index('1') + 1)
elif '1' in l2:
	x.append(2)
	x.append(l2.index('1') + 1)
elif '1' in l3:
	x.append(3)
	x.append(l3.index('1') + 1)
elif '1' in l4:
	x.append(4)
	x.append(l4.index('1') + 1)
elif '1' in l5:
	x.append(5)
	x.append(l5.index('1') + 1)
print(abs(x[0] - y[0]) + abs(x[1] - y[1]))


import math
from sys import stdin

def ii():
	return int(input())

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

def li():
	return list(mi())
for i in range(5):
	s = input().split()
	if '1' in s:
		print(abs(i - 2) + abs(s.index('1') - 2))


from sys import stdin, stdout
li = []
for i in range(5):
	li.append(list(map(int, stdin.readline().split())))
for i in range(5):
	if 1 in li[i]:
		m = li[i].index(1)
		stdout.write(str(abs(i + 1 - 3) + abs(m + 1 - 3)))
		break


import math
h = 0
l = 0
for i in range(5):
	st = input()
	st = st.split(' ')
	st = list(st)
	if '1' in st:
		h = i + 1
		l = st.index('1') + 1
col = math.fabs(3 - l) + math.fabs(3 - h)
print(int(col))


def solve():
	matrix = [input().split() for _ in range(5)]
	matrix = [list(map(int, x)) for x in matrix]
	midle_point = 2
	for x in range(len(matrix)):
		i = 0
		for y in matrix[x]:
			if y == 1:
				col = x
				row = i
				break
			i += 1
	moves = 0
	while True:
		while True:
			if row > midle_point:
				row -= 1
				moves += 1
			elif row < midle_point:
				row += 1
				moves += 1
			else:
				break
		if col > midle_point:
			col -= 1
			moves += 1
		elif col < midle_point:
			col += 1
			moves += 1
		else:
			break
	print(moves)
solve()


for num in range(5):
	x = input().split()
	try:
		j = x.index('1')
		i = num
	except:
		pass
print(abs(i - 2) + abs(j - 2))


matrix = []
for i in range(5):
	matrix.append([])
	matrix[i] = [int(j) for j in input().split()]
for i in range(5):
	if 1 in matrix[i]:
		x_coord = i + 1
		y_coord = matrix[i].index(1) + 1
result = 0
if x_coord != 3:
	result += abs(x_coord - 3)
if y_coord != 3:
	result += abs(y_coord - 3)
print(result)


n = 1
while n <= 5:
	line = input()
	if '1' in line:
		row = n
		x = line.split()
		for (i, y) in enumerate(x):
			if y == '1':
				col = i + 1
				pass
	n += 1
print(abs(3 - row) + abs(3 - col))


lst1 = list(map(int, input().split()))
lst2 = list(map(int, input().split()))
lst3 = list(map(int, input().split()))
lst4 = list(map(int, input().split()))
lst5 = list(map(int, input().split()))
if 1 in lst1:
	for i in range(5):
		if lst1[i] == 1:
			c = i + 1
			r = 1
			break
		else:
			pass
elif 1 in lst2:
	for j in range(5):
		if lst2[j] == 1:
			c = j + 1
			r = 2
			break
		else:
			pass
elif 1 in lst3:
	for k in range(5):
		if lst3[k] == 1:
			c = k + 1
			r = 3
			break
		else:
			pass
elif 1 in lst4:
	for l in range(5):
		if lst4[l] == 1:
			c = l + 1
			r = 4
			break
		else:
			pass
else:
	for m in range(5):
		if lst5[m] == 1:
			c = m + 1
			r = 5
			break
		else:
			pass
if r >= 3:
	if c >= 3:
		print(c + r - 6)
	else:
		print(r - c)
elif c >= 3:
	print(c - r)
else:
	print(6 - (c + r))


a = 0
for i in range(5):
	line = input()
	if '1' not in line:
		a += 1
		continue
	if '1' in line:
		line = line.split()
		b = line.index('1')
		break
a += 1
b += 1
print(abs(3 - a) + abs(3 - b))


n = 5
matrix = []
for i in range(n):
	a = list(map(int, input().split()))
	matrix.append(a)
for i in range(n):
	for j in range(n):
		if matrix[i][j] == 1:
			I = i
			J = j
		else:
			continue
if I >= 2:
	r = I - 2
else:
	r = 2 - I
if J >= 2:
	r = r + J - 2
else:
	r = r + 2 - J
print(r)


def main():
	i = 0
	j = 1
	k = 1
	for _ in range(5):
		m = list(input().split())
		if '1' in m:
			i = m.index('1') + 1
			j = k
		k += 1
	print(abs(3 - i) + abs(3 - j))
main()


from math import *
b = []
for i in range(5):
	a = list((int(x) for x in input().split()))
	b.append(a)
for i in range(5):
	for j in range(5):
		if b[i][j] == 1:
			c = i - 2
			d = j - 2
			c = abs(c)
			d = abs(d)
			print(c + d)
			exit()


a = []
a.append(input().replace(' ', ''))
a.append(input().replace(' ', ''))
a.append(input().replace(' ', ''))
a.append(input().replace(' ', ''))
a.append(input().replace(' ', ''))
m = 0
n = 0
for i in a:
	if '1' in i:
		m = a.index(i)
		n = i.index('1')
print(abs(m - 2) + abs(n - 2))


x = 0
y = 0
i = 0
while i <= 4:
	i += 1
	a = input()[::2]
	for j in range(len(a)):
		if a[j] == '1':
			x = i - 1
			y = j
			break
print(abs(x - 2) + abs(y - 2))


one = input('').split()
one = [int(i) for i in one]
two = input('').split()
two = [int(i) for i in two]
three = input('').split()
three = [int(i) for i in three]
four = input('').split()
four = [int(i) for i in four]
five = input('').split()
five = [int(i) for i in five]
if sum(one) == 1:
	r = 1
	row = one
if sum(two) == 1:
	r = 2
	row = two
if sum(three) == 1:
	r = 3
	row = three
if sum(four) == 1:
	r = 4
	row = four
if sum(five) == 1:
	r = 5
	row = five
ver = abs(r - 3)
count = 0
for number in range(len(row)):
	count += 1
	if row[number] == 1:
		break
	else:
		continue
hor = abs(count - 3)
print(hor + ver)


for i in range(5):
	s = input()
	check = 0
	for j in range(0, 9, 2):
		if s[j] == '1':
			print(abs(i - 2) + abs(j - 4) // 2)
			check = 1
			break
	if check:
		break


matrix = ''
for i in range(5):
	matrix += input()
location = 6
location1 = -1
location2 = 0
for i in matrix:
	if i == '0':
		location1 += 1
	elif i == '1':
		location1 += 1
		location = location1
location1 = location / 5
location1 = int(location1)
location2 = location % 5
print(abs(2 - location1) + abs(2 - location2))


lst = []
z = 0
for row in range(5):
	x = input().split()
	lst.append(x)
	for col in range(5):
		if lst[row][col] == '1':
			z = abs(row - 2) + abs(col - 2)
print(z)


line0 = input()
result0 = line0.split(' ')
line1 = input()
result1 = line1.split(' ')
line2 = input()
result2 = line2.split(' ')
line3 = input()
result3 = line3.split(' ')
line4 = input()
result4 = line4.split(' ')
for i in range(0, 4 + 1):
	if int(result0[i]) == 1:
		x = i
		y = 0
		break
	elif int(result1[i]) == 1:
		x = i
		y = 1
		break
	elif int(result2[i]) == 1:
		x = i
		y = 2
		break
	elif int(result3[i]) == 1:
		x = i
		y = 3
		break
	elif int(result4[i]) == 1:
		x = i
		y = 4
		break
result = abs(x - 2) + abs(y - 2)
print(result)


for j in range(0, 5, 1):
	n = list(map(int, input().split()))
	for i in n:
		if i == 1:
			row = n.index(1) + 1
			column = j + 1
			break
ans = abs(3 - row) + abs(3 - column)
print(ans)


a = []
for i in range(1, 6):
	a.append(list(map(int, input().split())))
for i in range(1, 6):
	for j in range(1, 6):
		if a[i - 1][j - 1] == 1:
			k = i
			l = j
			break
c = 3 - k
d = 3 - l
if c < 0:
	c = 0 - c
if d < 0:
	d = 0 - d
print(c + d)


ar = []
for k in range(5):
	a = input()
	a = a.split()
	ar.append(a)
for n in range(len(ar)):
	for m in range(len(ar)):
		if ar[n][m] == '1':
			fila = n
			columna = m
			break
suma1 = abs(2 - fila)
suma2 = abs(2 - columna)
respuesta = suma1 + suma2
print(respuesta)


mat = []
findx = 0
findy = 0
count = 0
for _ in range(5):
	a = list(input().split())
	for i in range(len(a)):
		if a[i] == '1':
			findy = int(i)
			findx = int(_)
	mat.append(a)
count = abs(findy - 2) + count
count += abs(findx - 2)
print(count)


x = 0
y = 0
l = []
for i in range(0, 5):
	l.append([int(i) for i in input().split()])
for i in range(0, 5):
	for j in range(0, 5):
		if l[i][j] == 1:
			x = i
			y = j
res = abs(x - 2) + abs(y - 2)
print(res)


import math as m
var = 1
x = 0
y = 0
while var != 6:
	(a, b, c, d, e) = map(int, input().split())
	if a == 1:
		x = 1
		y = var
	if b == 1:
		x = 2
		y = var
	if c == 1:
		x = 3
		y = var
	if d == 1:
		x = 4
		y = var
	if e == 1:
		x = 5
		y = var
	var += 1
print(int(m.fabs(x - 3) + m.fabs(y - 3)))


for i in range(5):
	lis = input().split()
	for j in range(5):
		if '1' == lis[j]:
			r = abs(i - 2) + abs(j - 2)
			print(r)


from sys import stdin
input = stdin.readline
i = 1
while i < 6:
	s = list(map(int, str(input()).split()))
	if sum(s) == 1:
		x = s.index(1) + 1
		y = i
	i += 1
print(abs(3 - y) + abs(3 - x))


matrix = []
for a in range(5):
	matrix.append(list(map(int, input().split())))
for b in range(5):
	for c in range(5):
		if matrix[b][c] == 1:
			m = b
			n = c
			break
result = abs(m - 2) + abs(n - 2)
print(result)


def main():
	from sys import stdin, stdout
	for i in range(5):
		a = list(map(int, stdin.readline().split()))
		try:
			x = a.index(1) + 1
			y = i + 1
		except:
			g = ''
	stdout.write(str(abs(x - 3) + abs(y - 3)))
main()


a = []
n = 0
for i in range(5):
	a.append(list(map(int, input().split())))
while a[2][2] != 1:
	for i in range(5):
		for j in range(5):
			if a[i][j] == 1:
				if i < 2:
					a[i][j] = 0
					a[i + 1][j] = 1
					n += 1
					continue
				if i > 2:
					a[i][j] = 0
					a[i - 1][j] = 1
					n += 1
					continue
				if j < 2:
					a[i][j] = 0
					a[i][j + 1] = 1
					n += 1
					continue
				if j > 2:
					a[i][j] = 0
					a[i][j - 1] = 1
					n += 1
					j -= 1
					continue
print(n)


a = []
r1 = 0
r2 = 0
for i in range(5):
	x = [int(s) for s in input().split()]
	a.append(x)
	if 1 in x:
		r1 = i
		r2 = x.index(1)
print(abs(r1 - 2) + abs(r2 - 2))


for i in range(1, 6):
	l = input()
	if '1' in l:
		a = l.find('1') // 2 + 1
		print(abs(3 - i) + abs(3 - a))


point = (0, 0)
for i in range(5):
	s = input()
	if s.count('1') == 1:
		point = (i + 1, s.index('1') // 2 + 1)
print(abs(3 - point[0]) + abs(3 - point[1]))


a = []
for i in range(0, 5):
	a.append([int(x) for x in input().split()])
answer = 0
for i in range(0, 5):
	if 1 in a[i]:
		answer = abs(i - 2) + abs(a[i].index(1) - 2)
print(answer)


res = 0
matrix = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
for i in range(5):
	k = input().split()
	for j in range(5):
		matrix[i][j] = int(k[j])
		if matrix[i][j] == 1:
			res = abs(i - 2) + abs(j - 2)
print(res)


(i, j) = (5, 5)
for i in range(1, 6):
	row = input()
	if '1' in row:
		j = row.find('1') // 2 + 1
		break
min_moves = abs(3 - i) + abs(3 - j)
print(min_moves)


l = []
for i in range(5):
	s = list(map(int, input().strip().split()))[:5]
	l.append(s)
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			i1 = i
			j1 = j
i1 = i1 - 2
j1 = j1 - 2
if i1 < 0:
	i1 = -1 * i1
if j1 < 0:
	j1 = -1 * j1
print(i1 + j1)


matrix = [[], [], [], [], []]
pos = 0
count = 0
for i in range(5):
	matrix[i] = input().split()
	if '1' in matrix[i]:
		pos = [i, matrix[i].index('1')]
while pos[0] != 2:
	if pos[0] > 2:
		pos[0] -= 1
	else:
		pos[0] += 1
	count += 1
while pos[1] != 2:
	if pos[1] > 2:
		pos[1] -= 1
	else:
		pos[1] += 1
	count += 1
print(count)


q = 0
for i in range(5):
	q += 1
	s = list(map(int, input().split()))
	if 1 in s:
		k = s.index(1)
		sh1 = abs(3 - (k + 1))
		sh2 = abs(3 - q)
print(sh1 + sh2)


rows = []
for i in range(5):
	rows.append(input().replace(' ', ''))
numsteps = 0
for row in rows:
	for item in row:
		if item == '1':
			horizdist = abs(2 - row.index(item))
			numsteps += horizdist
for row in rows:
	listrow = []
	for item in row:
		listrow.append(int(item))
	if sum(listrow) == 1:
		vertdist = abs(2 - rows.index(row))
		numsteps += vertdist
print(str(numsteps))


for i in range(5):
	matrix = list(map(int, input().split()))
	for m in range(5):
		if matrix[m] == 1:
			px = i
			py = m
			break
lx = px - 2
ly = py - 2
if lx < 0:
	lx = lx * -1
if ly < 0:
	ly = ly * -1
print(lx + ly)


n = 5
r = 0
c = 0
k = 0
while n > 0:
	n = n - 1
	r += 1
	a = list(map(int, input().split()))
	if 1 in a:
		c = a.index(1) + 1
		k = r
print(abs(k - 3) + abs(c - 3))


n = list(map(int, input().split()))
n2 = list(map(int, input().split()))
n3 = list(map(int, input().split()))
n4 = list(map(int, input().split()))
n5 = list(map(int, input().split()))
string = 0
column = 0
for (array_index, array) in enumerate((n, n2, n3, n4, n5)):
	for (number_index, number) in enumerate(array):
		if number == 1:
			string = array_index
			column = number_index
a = abs(string - 2)
b = abs(column - 2)
c = a + b
print(c)


import math
data = [[] * 5] * 5
for i in range(5):
	data[i] = list(map(int, input().split()))
x = -1
y = -1
for i in range(5):
	for j in range(5):
		if data[i][j] == 1:
			x = j
			y = i
print(abs(x + 1 - 3) + abs(y + 1 - 3))


import math
b = []
for i in range(5):
	a = list(map(int, input().split(' ')))
	b.append(a)
for i in range(len(b)):
	if 1 in b[i]:
		pos = b[i].index(1)
		de = i
		break
x = de - 2
y = pos - 2
if x < 0:
	x = x * -1
if y < 0:
	y = y * -1
print(x + y)


s = []
for i in range(5):
	s.append(input())
	if '1' in s[i]:
		m = i
		n = int(s[i].index('1') / 2)
print(abs(m - 2) + abs(n - 2))


matrix = []
for i in range(0, 5):
	row = input()
	row = row.strip()
	row = row.split()
	for j in range(0, 5):
		row[j] = int(row[j])
	matrix.append(row)
ni = 0
nj = 0
for i in range(0, 5):
	for j in range(0, 5):
		if matrix[i][j] == 1:
			ni = i
			nj = j
			break
i = ni - 2
if i < 0:
	i = i * -1
j = nj - 2
if j < 0:
	j = j * -1
print(i + j)


r = c = -1
for i in range(5):
	s = list(map(int, input().split()))
	if s.count(1) > 0:
		r = i + 1
		c = s.index(1) + 1
		break
print(abs(r - 3) + abs(c - 3))


m = []
r = 0
s = 0
for i in range(5):
	a = list(map(int, input().split()))
	m = m + [a]
	if 1 in a:
		r = i
		s = a.index(1)
b = abs(2 - r) + abs(2 - s)
print(b)


for i in range(1, 6):
	str = input()
	for g in range(0, len(str)):
		if str[g] == '1':
			print(int(abs(3 - (g / 2 + 1)) + abs(3 - i)))
			break


def shiftOne(matrix):
	for i in range(len(matrix)):
		for j in range(len(matrix[i])):
			if matrix[i][j] == 1:
				coordinates = (i, j)
	return abs(coordinates[0] - 2) + abs(coordinates[1] - 2)

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


s = []
for i in range(5):
	s.append([x for x in map(int, input().split())])
for i in range(5):
	if 1 in s[i]:
		a = i
		b = s[i].index(1)
		break
print(abs(a - 2) + abs(b - 2))


m = []
for i in range(5):
	m.append(input().split())
for i in range(5):
	if m[i].count('1') == 1:
		r = i
		c = m[i].index('1')
x = abs(2 - r) + abs(2 - c)
print(x)


for t in range(5):
	f = [int(x) for x in input().split()]
	if 1 in f:
		j = f.index(1)
		i = t
print(abs(i - 2) + abs(j - 2))


m = []
x = 0
r = 0
c = 0
while x < 5:
	y = list(map(int, input().split()))
	m.append(y)
	x += 1
r1 = 0
while r1 <= 4:
	c1 = 0
	while c1 <= 4:
		if m[r1][c1] == 1:
			r = r + r1
			c = c + c1
		c1 += 1
	r1 += 1
ans = abs(r - 2) + abs(c - 2)
print(ans)


for i in range(5):
	nums = list(map(int, input().split()))
	for k in range(5):
		if nums[k] == 1:
			I = i + 1
			J = k + 1
			break
n = abs(I - 3) + abs(J - 3)
print(n)


from sys import stdin, stdout
arr = [[int(i) for i in stdin.readline().split()] for j in range(5)]
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			stdout.write(str(abs(i - 2) + abs(j - 2)) + '\n')
			break


matrix = [list(input().replace(' ', '')) for i in range(5)]

def locate_one(matr):
	for x in matr:
		if '1' in x:
			return (x.index('1'), matr.index(x))
(one_x, one_y) = locate_one(matrix)
moves = abs(2 - one_x) + abs(2 - one_y)
print(moves)


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 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())
a = []
for i in range(5):
	a.append(inlist())
for i in range(5):
	for j in range(5):
		if a[i][j] == 1:
			res = abs(i + 1 - 3) + abs(j + 1 - 3)
			print(res)
			sys.exit()


for x in range(5):
	m = input().replace(' ', '')
	if '1' in m:
		print(abs(2 - x) + abs(2 - m.find('1')))


matrix_list = []
for _ in range(5):
	col_list = list(map(int, input().split()))
	for num in col_list:
		matrix_list.append(num)
one_index = matrix_list.index(1) + 1
one_column = 0
if 0 < one_index / 5 <= 1:
	one_column = 1
elif 1 < one_index / 5 <= 2:
	one_column = 2
elif 2 < one_index / 5 <= 3:
	one_column = 3
elif 3 < one_index / 5 <= 4:
	one_column = 4
elif 4 < one_index / 5 <= 5:
	one_column = 5
one_row = one_index - 5 * (one_column - 1)
col_attempt = abs(3 - one_column)
row_attempt = abs(3 - one_row)
print(int(col_attempt + row_attempt))


arr = [[], [], [], [], []]
for q in range(5):
	arr[q] = list(map(int, input().split()))
	if 1 in arr[q]:
		x1 = q
		y1 = arr[q].index(1)
ans = abs(2 - x1) + abs(2 - y1)
print(ans)


lst = []
for i in range(5):
	l = []
	l = list(map(int, input().split()))
	lst.append(l)
for i in lst:
	if 1 in i:
		q = i.index(1)
		p = lst.index(i)
print(abs(2 - q) + abs(2 - p))


i = 1
while i < 6:
	a = list(map(int, input().split()))
	if 1 in a:
		c = a.index(1) + 1
		break
	i += 1
print(abs(3 - i) + abs(3 - c))


import sys
for count in range(0, 5):
	numbers = list(map(int, input().split()))
	for cell in range(0, 5):
		if numbers[cell] == 1:
			row = count
			column = cell

def count_shift(element):
	if element == 0 or element == 4:
		result = 2
	if element == 1 or element == 3:
		result = 1
	if element == 2:
		result = 0
	return result
print(count_shift(row) + count_shift(column))


lis = []
for i in range(5):
	s = input()
	for j in s.split():
		lis.append(j)
print(abs(lis.index('1') // 5 - 2) + abs(lis.index('1') % 5 - 2))


ar = []
a = 0
for i in range(0, 5):
	ar.append(list(map(int, input().rstrip().split())))
for i in range(0, 5):
	for j in range(0, 5):
		if ar[i][j] == 1:
			if 2 - i >= 0:
				a = a + (2 - i)
			else:
				a = a + (i - 2)
			if 2 - j >= 0:
				a = a + (2 - j)
			else:
				a = a + (j - 2)
			break
print(a)


arr = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			o1 = max(i, 2) - min(i, 2) + (max(j, 2) - min(j, 2))
print(o1)


for i in range(5):
	string = input()
	if string.count('1') == 1:
		a = i
		b = string.find('1') // 2
		res = abs(2 - a) + abs(2 - b)
		print(res)


row1 = input()
row2 = input()
row3 = input()
row4 = input()
row5 = input()
rows = [row1, row2, row3, row4, row5]
i = 0
row = 0
column = 0
while i < len(rows):
	if '1' in rows[i]:
		row = i + 1
	i += 1
oneRow = rows[row - 1].split(' ')
i = 0
while i < len(oneRow):
	if oneRow[i] == '1':
		column = i + 1
	i += 1
print(abs(row - 3) + abs(column - 3))


n = int(5)
l = []
for i in range(n):
	x = input().split()
	c = []
	for j in range(n):
		c.append(int(x[j]))
	l.append(c)
for i in range(len(l)):
	m = [sub[i] for sub in l]
	for j in range(len(m)):
		ans = 0
		if m[j] == 1:
			c = i
			r = j
			ans = abs(2 - c) + abs(2 - r)
			print(ans)


x = [2, 1, 0, 1, 2]
s = 0
for i in range(5):
	a = input().replace(' ', '')
	if '1' in a:
		s = x[i] + x[a.index('1')]
		break
print(s)


import sys
from sys import stdin, stdout
import math
import random
import heapq
from collections import Counter
from functools import lru_cache
try:
	for _ in range(1):
		mat = [[int(i) for i in input().split()] for i in range(5)]
		diff = 0
		for i in range(5):
			for j in range(5):
				if mat[i][j] == 1:
					diff = abs(2 - i) + abs(2 - j)
					break
			if diff:
				break
		print(diff)
except EOFError as e:
	print(e)


a = input()
l1 = a.split(' ')
l1 = [int(x) for x in l1]
b = input()
l2 = b.split(' ')
l2 = [int(x) for x in l2]
c = input()
l3 = c.split(' ')
l3 = [int(x) for x in l3]
d = input()
l4 = d.split(' ')
l4 = [int(x) for x in l4]
e = input()
l5 = e.split(' ')
l5 = [int(x) for x in l5]
ans = 0
total = 0
while total == 0:
	for i in range(0, 5):
		total = total + l1[i]
	if total == 1:
		prob = l1
		ans = ans + 2
		break
	for i in range(0, 5):
		total = total + l2[i]
	if total == 1:
		prob = l2
		ans = ans + 1
		break
	for i in range(0, 5):
		total = total + l3[i]
	if total == 1:
		prob = l3
		break
	for i in range(0, 5):
		total = total + l4[i]
	if total == 1:
		prob = l4
		ans = ans + 1
		break
	for i in range(0, 5):
		total = total + l5[i]
	if total == 1:
		prob = l5
		ans = ans + 2
		break
if prob[0] == 1:
	ans = ans + 2
	print(ans)
elif prob[1] == 1:
	ans = ans + 1
	print(ans)
elif prob[2] == 1:
	print(ans)
elif prob[3] == 1:
	ans = ans + 1
	print(ans)
else:
	ans = ans + 2
	print(ans)


k = 0
ind = 0
for i in range(5):
	s = list(map(int, input().split()))
	if 1 in s:
		ind = s.index(1)
		k = i
print(abs(k - 2) + abs(ind - 2))


(w, h) = (5, 5)
(x, y) = (0, 0)
a = []
for i in range(h):
	ls = list(map(int, input().split()))
	a.append(ls)
for i in range(h):
	for j in range(w):
		if a[i][j] == 1:
			(x, y) = (i, j)
print(abs(x - 2) + abs(y - 2))


lista = []
for i in range(5):
	inpx = input('')
	lista.append(inpx)
for i in lista:
	if '1' in i:
		x = i.split()
		t = lista.index(i) + 1
		y = x.index('1') + 1
		break
	else:
		continue
print(abs(3 - t) + abs(3 - y))


mat = []
for i in range(5):
	mat.append(list(map(int, input().split())))
(x, y) = (None, None)
f = False
for i in range(5):
	for j in range(5):
		if mat[i][j] == 1:
			x = i
			y = j
			f = True
			break
	if f == True:
		break
print(abs(x - 2) + abs(y - 2))


t = []
q = []
e = 0
for i in range(5):
	t = list(map(int, input().split()))
	q.append(t)
for i in range(5):
	for j in range(5):
		if q[i][j] == 1:
			if i + 1 >= 3:
				e += i + 1 - 3
			else:
				e += 3 - i - 1
			if j + 1 >= 3:
				e += j - 3 + 1
				break
			else:
				e += 3 - j - 1
				break
print(e)


i = 0
a = []
while i < 5:
	a.append([int(j) for j in input().split()])
	if sum(a[i]) > 0:
		break
	i += 1
print(abs(2 - i) + abs(2 - a[i].index(1)))


import math
grid = []
for _unk in range(5):
	input_arr = [int(x) for x in input().split(' ')]
	grid.append(input_arr)
middle_pos = [2, 2]
one_pos = [0, 0]
for i in range(5):
	for j in range(5):
		if grid[i][j] == 1:
			one_pos = [i, j]
x_movements = 0
y_movements = 0
while one_pos[0] != middle_pos[0]:
	if one_pos[0] < middle_pos[0]:
		one_pos[0] += 1
		x_movements += 1
	elif one_pos[0] > middle_pos[0]:
		one_pos[0] -= 1
		x_movements += 1
while one_pos[1] != middle_pos[1]:
	if one_pos[1] < middle_pos[1]:
		one_pos[1] += 1
		y_movements += 1
	elif one_pos[1] > middle_pos[1]:
		one_pos[1] -= 1
		y_movements += 1
print(y_movements + x_movements)


for i in range(1, 6):
	x = [int(x) for x in input().split()]
	if 1 in x:
		col = x.index(1) + 1
		row = i
print(abs(row - 3) + abs(col - 3))


a = []
moves = 0
for i in range(5):
	a.append([int(x) for x in input().split()])
for list in a:
	if 1 in list:
		val1 = list.index(1)
		val2 = a.index(list)
moves += abs(2 - val1)
moves += abs(2 - val2)
print(moves)


r1 = input().split()
r2 = input().split()
r3 = input().split()
r4 = input().split()
r5 = input().split()
ro1 = 2
co1 = 2
for j in range(0, 5):
	r1[j] = int(r1[j])
	if r1[j] == 1:
		ro1 = 2
		if j == 0 or j == 1:
			co1 -= j
		else:
			co1 = j - co1
for j in range(0, 5):
	r2[j] = int(r2[j])
	if r2[j] == 1:
		ro1 = 1
		if j == 0 or j == 1:
			co1 -= j
		else:
			co1 = j - co1
for j in range(0, 5):
	r3[j] = int(r3[j])
	if r3[j] == 1:
		ro1 = 0
		if j == 0 or j == 1:
			co1 -= j
		else:
			co1 = j - co1
for j in range(0, 5):
	r4[j] = int(r4[j])
	if r4[j] == 1:
		ro1 = 1
		if j == 0 or j == 1:
			co1 -= j
		else:
			co1 = j - co1
for j in range(0, 5):
	r5[j] = int(r5[j])
	if r5[j] == 1:
		ro1 = 2
		if j == 0 or j == 1:
			co1 -= j
		else:
			co1 = j - co1
v = [r1, r2, r3, r4, r5]
print(co1 + ro1)


(n, m) = (5, 5)
arr = []
for i in range(n):
	arr.append([int(x) for x in input().split()])
for i in range(n):
	for j in range(n):
		if arr[i][j] == 1:
			(z, x) = (i + 1, j + 1)
print(abs(z - 3) + abs(x - 3))


from sys import stdin, stdout

def index_2d(mylist, v):
	for (i, x) in enumerate(mylist):
		if v in x:
			return (i, x.index(v))
col = []
for i in range(5):
	row = [int(x) for x in stdin.readline().split()]
	col.append(row)
(a, b) = index_2d(col, 1)
res = abs(2 - a) + abs(2 - b)
print(res)


for i in range(1, 6):
	nList = list(map(int, input().split()))
	if 1 in nList:
		column = nList.index(1) + 1
		break
print(abs(i - 3) + abs(column - 3))


list1 = []
for i in range(5):
	l = list(map(int, input().split()))
	list1.append(l)
for i in range(5):
	for j in range(5):
		if list1[i][j] == 1:
			x = i
			y = j
			break
if x - 2 >= 0:
	xmove = x - 2
else:
	xmove = 2 - x
if y - 2 >= 0:
	ymove = y - 2
else:
	ymove = 2 - y
print(xmove + ymove)


answer = 0
for i in range(5):
	line = list(map(int, input().strip().split()))
	if 1 in line:
		answer = abs(i - 2)
		break
answer += abs(line.index(1) - 2)
print(answer)


from sys import stdin
(lines, line_index) = (stdin.readlines(), -1)

def get_line():
	global lines, line_index
	line_index += 1
	return lines[line_index]

def main():
	matrix = []
	for _ in range(5):
		matrix.append([int(x) for x in get_line().split()])
	flag = False
	(i, j) = (0, 0)
	for i in range(5):
		for j in range(5):
			if matrix[i][j] == 1:
				flag = True
				break
		if flag:
			break
	print(abs(3 - (i + 1)) + abs(3 - (j + 1)))
main()


arr = []
for i in range(5):
	(a, b, c, d, e) = map(int, input().split())
	arr.append([a, b, c, d, e])
t = []
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			t.append(i)
			t.append(j)
			break
print(abs(t[0] - 2) + abs(t[1] - 2))


(a, b) = (0, 0)
for i in range(5):
	m = input().split()
	if m.count('1') > 0:
		a = m.index('1')
		b = i
print(abs(a - 2) + abs(b - 2))


cols = 1
rows = 0
for i in range(1, 6):
	c = input()
	row = c.split(' ')
	row = list(map(int, row))
	if 1 in row:
		cols = row.index(1) + 1
		rows = i
rows_trials = abs(rows - 3)
cols_trials = abs(cols - 3)
print(rows_trials + cols_trials)


def main():
	mat = []
	ox = 0
	oy = 0
	for i in range(0, 5):
		mat.append([])
	for i in range(0, 5):
		mat[i] = input().split(' ')
		for j in range(0, 5):
			mat[i][j] = int(mat[i][j])
			if mat[i][j] == 1:
				ox = j
				oy = i
	print(abs(ox - 2) + abs(oy - 2))
main()


matrix = []
for row in range(5):
	l = list(map(int, input().split()))
	try:
		idx = l.index(1)
	except:
		pass
	else:
		r = row
		c = idx
	matrix.append(l)
print(abs(2 - r) + abs(2 - c))


import math
ls = []
t = 0
a = 0
b = 0
for i in range(5):
	ls.append(str.split(input()))
	for j in range(0, 5):
		if int(ls[i][j]) == 1:
			a = math.fabs(i - 2)
			b = math.fabs(j - 2)
print(int(a) + int(b))


a = []
for i in range(5):
	b = input().split()
	a.append(b)
x = 0
y = 0
for (i, row) in enumerate(a):
	if '1' in row:
		x = i
		y = row.index('1')
		break
print(abs(x - 2) + abs(y - 2))


arr = []
arr += [list(map(int, input().split()))]
arr += [list(map(int, input().split()))]
arr += [list(map(int, input().split()))]
arr += [list(map(int, input().split()))]
arr += [list(map(int, input().split()))]
i1 = 0
j1 = 0
for i in range(5):
	for j in range(5):
		if arr[i][j] == 1:
			i1 = i
			j1 = j
			break
diff = abs(2 - i1) + abs(2 - j1)
print(diff)


row1 = input()
row2 = input()
row3 = input()
row4 = input()
row5 = input()
lst1 = row1.split()
lst2 = row2.split()
lst3 = row3.split()
lst4 = row4.split()
lst5 = row5.split()
x = 0
y = 0
for i in range(5):
	if lst1[i] == '1':
		x = 0
		y = i
	elif lst2[i] == '1':
		x = 1
		y = i
	elif lst3[i] == '1':
		x = 2
		y = i
	elif lst4[i] == '1':
		x = 3
		y = i
	elif lst5[i] == '1':
		x = 4
		y = i
sum = 0
if x <= 2:
	sum += 2 - x
elif x > 2:
	sum += x - 2
if y <= 2:
	sum += 2 - y
elif y > 2:
	sum += y - 2
print(sum)


a = 5
i = 0
j = 0
w = 0
while a != 0:
	myList = list(map(int, input().split(' ')))
	if w == 0:
		v = myList.count(1)
		if v > 0:
			j = myList.index(1)
			w = 1
		else:
			i += 1
	a -= 1
print(abs(i - 2) + abs(j - 2))


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

def find(a, v):
	for (i, j) in enumerate(a):
		if v in j:
			return (i, j.index(v))
c = 0
curr = find(a, 1)
for (i, j) in zip(curr, final):
	c += abs(i - j)
print(c)


m = []
r = 0
c = 0
flag = False
for i in range(1, 6):
	x = ''.join(input().split(' '))
	if not flag:
		for j in range(1, 6):
			if x[j - 1] == '1':
				r = i
				c = j
				flag = True
				break
swap = 0
while r != 3:
	if r < 3:
		swap += 1
		r += 1
	elif r > 3:
		swap += 1
		r -= 1
while c != 3:
	if c < 3:
		swap += 1
		c += 1
	elif c > 3:
		swap += 1
		c -= 1
print(swap)


l = []
for i in range(5):
	k = list(map(int, input().split()))
	l.append(k)
x1 = 0
y1 = 0
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			x1 = i + 1
			y1 = j + 1
			i = 5
			break
dis = abs(x1 - 3) + abs(y1 - 3)
print(dis)


lst = []
for _ in range(5):
	lst.append([int(i) for i in input().split()])
si = 0
sj = 0
for i in range(0, 5):
	for j in range(0, 5):
		if lst[i][j] == 1:
			si = i + 1
			sj = j + 1
			break
print(abs(3 - si) + abs(3 - sj))


def min_moves(rowindex, colIndex):
	print(abs(rowIndex - 2) + abs(2 - colIndex))

def read_matrix():
	rowIndex = None
	colIndex = None
	for i in range(5):
		line = input().split(' ')
		for j in range(5):
			if line[j] == '1':
				rowIndex = i
				colIndex = j
	return (rowIndex, colIndex)
(rowIndex, colIndex) = read_matrix()
min_moves(rowIndex, colIndex)


list = []
list.append(input().split(' '))
list.append(input().split(' '))
list.append(input().split(' '))
list.append(input().split(' '))
list.append(input().split(' '))
cN = 1
rN = 1
for c in list:
	if '1' in c:
		rN = 1
		for r in c:
			if '1' in r:
				break
			else:
				rN += 1
		break
	cN += 1
movCou = 0
if cN > 3:
	movCou += cN - 3
elif cN < 3:
	movCou += (cN - 3) * -1
if rN > 3:
	movCou += rN - 3
elif rN < 3:
	movCou += (rN - 3) * -1
print(movCou)


for i in range(5):
	array = list((int(num) for num in input().split(' ')))
	for n in range(5):
		if array[n] == 1:
			position = [i, n]
print(abs(position[0] - 2) + abs(position[1] - 2))


import math
m = []
i = 0
while i < 5:
	m.append(input().split())
	i += 1
i = 0
while i < 5:
	j = 0
	while j < 5:
		if m[i][j] == '1':
			print(abs(i - 2) + abs(j - 2))
			break
		j += 1
	if j < 5:
		break
	i += 1


N = 5
M = 5
(i_dest, j_dest) = (2, 2)
for i in range(N):
	row = list(map(int, input().split()))
	if any(row):
		i_idx = i
		j_idx = row.index(1)
steps = abs(i_dest - i_idx) + abs(j_dest - j_idx)
print(steps)


index = 0
didFind = False
for i in range(5):
	row = [int(x) for x in input().split(' ')]
	for item in row:
		if item == 1:
			didFind = True
			break
		index += 1
	if didFind:
		break
row = index // 5 + 1
col = index % 5 + 1
print(abs(3 - row) + abs(3 - col))


def main():
	matrix = list()
	count = 0
	(row, col) = (-1, -1)
	for i in range(5):
		l = list(map(int, input().split()))
		matrix.append(l)
	for i in range(5):
		if 1 in matrix[i]:
			row = i
			col = matrix[row].index(1)
	res = abs(row - 2) + abs(col - 2)
	print(res)
main()


import re
import math
fstr = list(input().split())
sstr = list(input().split())
tstr = list(input().split())
fostr = list(input().split())
fistr = list(input().split())
i = 0
j = 0
if '1' in fstr:
	j = fstr.index('1') + 1
	i += 1
elif '1' in sstr:
	j = sstr.index('1') + 1
	i += 2
elif '1' in tstr:
	j = tstr.index('1') + 1
	i += 3
elif '1' in fostr:
	j = fostr.index('1') + 1
	i += 4
elif '1' in fistr:
	j = fistr.index('1') + 1
	i += 5
i = math.fabs(i - 3) + math.fabs(j - 3)
print(math.trunc(i))


row = -1
col = -1
for i in range(5):
	s = input().replace(' ', '')
	loc = s.find('1')
	if loc != -1:
		row = i
		col = loc
num = abs(2 - row) + abs(2 - col)
print(num)


(i, j) = (0, 0)
for _ in range(5):
	row = input().split()
	if '1' in row:
		i = _ + 1
		j = row.index('1') + 1
print(abs(3 - i) + abs(3 - j))


f = lambda : map(int, input().split())
x = 0
y = 0
for i in range(5):
	l = list(f())
	if l.count(1):
		x = l.index(1)
		y = i
print(abs(x - 2) + abs(y - 2))


for i in range(5):
	b = input()
	b = b.split(' ')
	for j in range(5):
		if b[j] == '1':
			d = [i, j]
			break
		else:
			continue
		break
print(abs(d[0] - 2) + abs(d[1] - 2))


matrix = []
minimum_number_of_moves = 0
one_line = 0
one_column = 0
for line in range(0, 5):
	input_line = input().split(' ')
	for (column, element) in enumerate(input_line):
		input_line[column] = int(element)
		if input_line[column] == 1:
			minimum_number_of_moves = abs(2 - line) + abs(2 - column)
print(minimum_number_of_moves)


l = []
count = 0
while not l or len(l) < len(l[0]):
	l.append(list(map(int, input().split())))
for i in range(5):
	for j in range(5):
		if l[i][j] == 1:
			s = i
			k = j
if not s == 2:
	s = 2 - s
else:
	s = 0
if not k == 2:
	k = 2 - k
else:
	k = 0
print(abs(k) + abs(s))


matrix = []
rows = []
for i in range(1, 6):
	rows = list(input().split())
	matrix.append(rows)
x = y = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == '1':
			x = i
			y = j
if x >= 2 and y >= 2:
	n = x - 2 + (y - 2)
elif x < 2 and y >= 2:
	n = 2 - x + (y - 2)
elif x >= 2 and y < 2:
	n = 2 - y + (x - 2)
else:
	n = 2 - y + (2 - x)
print(n)


from math import sqrt

def Sqr(a):
	return a * a
matrix = []
for i in range(5):
	matrix.append(input().split())
for j in range(5):
	for i in range(5):
		if int(matrix[j][i]) == 1:
			j = int(3 - (j + 1))
			i = int(3 - (i + 1))
			if j < 0:
				j = j * -1
			if i < 0:
				i = i * -1
			print(j + i)


data = [[int(el) for el in input().split()] for x in range(5)]
for i in range(5):
	for j in range(5):
		if data[i][j] == 1:
			x = i + 1
			y = j + 1
print(abs(x - 3) + abs(y - 3))


irow1 = input().split(' ')
irow2 = input().split(' ')
irow3 = input().split(' ')
irow4 = input().split(' ')
irow5 = input().split(' ')
row1 = []
row2 = []
row3 = []
row4 = []
row5 = []
for i in range(5):
	row1.append(int(irow1[i]))
for i in range(5):
	row2.append(int(irow2[i]))
for i in range(5):
	row3.append(int(irow3[i]))
for i in range(5):
	row4.append(int(irow4[i]))
for i in range(5):
	row5.append(int(irow5[i]))
matrix = [row1, row2, row3, row4, row5]
op = 0
for i in range(5):
	for j in range(5):
		if matrix[i][j] == 1:
			if i == 0 or i == 4:
				op = op + 2
			if i == 1 or i == 3:
				op = op + 1
			if j == 0 or j == 4:
				op = op + 2
			if j == 1 or j == 3:
				op = op + 1
print(op)


try:
	arr = [[int(ele) for ele in input().split()] for j in range(5)]
	row = 0
	col = 0
	for i in range(5):
		for j in range(5):
			if arr[i][j] == 1:
				row = i
				col = j
	if row == 0 or col == 0:
		pass
	if row == 2 and col == 2:
		print(0)
	else:
		count = 0
		if row > 2:
			while row != 2:
				(arr[row - 1][col], arr[row][col]) = (arr[row][col], arr[row - 1][col])
				row = row - 1
				count += 1
		elif row < 2:
			while row != 2:
				(arr[row][col], arr[row + 1][col]) = (arr[row + 1][col], arr[row][col])
				row = row + 1
				count += 1
		if col > 2:
			while col != 2:
				(arr[row][col - 1], arr[row][col]) = (arr[row][col], arr[row][col - 1])
				col = col - 1
				count += 1
		elif col < 2:
			while col != 2:
				(arr[row][col], arr[row][col + 1]) = (arr[row][col + 1], arr[row][col])
				col = col + 1
				count += 1
		print(count)
except Exception:
	pass


x = None
y = None
for i in range(5):
	row = input()
	if x is not None:
		continue
	row = row.split(' ')
	try:
		x = row.index('1')
		y = i
	except ValueError:
		pass
print(abs(x - 2) + abs(y - 2))