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(i_of_1,j_of_1)
print(abs(i_of_1-2)+abs(int((j_of_1-4)/2)))

flag = 0
for i in range(5):
    a = input().split()
    for j in range(5):
        if a[j] == "1":
            if j == 1 or j == 3:
                flag += 1
            elif j == 0 or j == 4:
                flag += 2
            if i == 1 or i == 3:
                flag += 1
            elif i == 0 or i == 4:
                flag += 2
print(flag)

a = []
for i in range(5):
    l = str(input())
    l = list(map(int, l.split()))
    a.append(l)
for i in range(len(a)):
    for j in range(len(a[i])):
        if a[i][j] == 0:
            continue
        if a[i][j] == 1:
            current = (i+1, j+1)
target = (3, 3)
moves_i = abs(target[0] - current[0])
moves_j = abs(target[1] - current[1])
print(moves_i + moves_j)

x = 0
y = 0
for i in range(5):
    line = raw_input().split(" ")
    for j in range(5):
        if (int(line[j]) == 1):
            x = i
            y = j

print abs(x - 2) + abs(y - 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))

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)]
print(abs(x[0]-2)+abs(x[1]-2))

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

a = raw_input()
a = a + " "
b = raw_input()
b = b + " "
c = raw_input()
c = c + " "
d = raw_input()
d = d + " "
e = raw_input()
e = e + " "
m = 0
s = 0
a = a + b + c + d + e

a = a.split()
for i in range(0,25):
    if a[i] == "1":
        m = i
while m <> 12:
    if m < 12:
        if m < 10:
            m =  m + 5
        else:
            m = m + 1
    else:
        if m > 14:
            m = m - 5
        else:
            m = m - 1
    s = s + 1
print s

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

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)

a=0
b=0
for i in range(0,5):
	m=input().split(" ")
	if "1" in m:
		a=i+1
		b=m.index("1")+1
print(abs(a-3)+abs(b-3))

A = [map(int,raw_input().split()) for i in range(5)]
pos = (0,0)
for i in range(5):
    for j in range(5):
        if A[i][j] == 1:
           pos = (i,j)
ans = abs(pos[0]-2) + abs(pos[1]-2)
print(ans)

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 = [2, 1, 0, 1, 2]
for i in l:
    s = input()
    if "1" in s:
        print(i + l[s.find("1") // 2])
        break

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

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)

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

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

if __name__ == '__main__':
    main()

for i in range(5):
  x = map(int, raw_input().split())
  if 1 in x:
    print abs(x.index(1) - 2) + abs(i - 2)
    break

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

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

for i in range(5):
    for j in range(5):
        if matrix[i][j] == 1:
            m = i
            n = j

if m == 2 and n == 2:
    print 0
else:
    if m >= 2 and n >= 2:
        sum = sum+(m-2)+(n-2)
        print sum
    elif m >= 2 and n < 2:
        sum = sum+(m-2)+(2-n)
        print sum
    elif m <2 and n >=2:
        sum = sum+(2-m)+(n-2)
        print sum
    else:
        sum = sum+(2-m)+(2-n)
        print sum

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

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

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

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

if __name__ == '__main__':
    main()

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
    )

if __name__ == '__main__':
    solution = solve(_input=[list(map(int, input().split())) for _ in range(5)])
    print(solution)

x = ''.join([''.join(input().split()) for i in range(5)]).index('1')
print(abs(2 - x % 5) + abs(2 - x // 5))

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

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

xcount = 0
ycount = 0
y = 0
for x in range(5):
    x = int(x)
    a,b,c,d,e = raw_input().split()
    a,b,c,d,e = int(a),int(b),int(c),int(d),int(e)
    if a == 1:
        xcount = abs(2-x)
        ycount = 2
    if b == 1:
        xcount = abs(2-x)
        ycount = 1
    if c == 1:
        xcount = abs(2-x)
        ycount = 0
    if d == 1:
        xcount = abs(2-x)
        ycount = 1
    if e == 1:
        xcount = abs(2-x)
        ycount = 2
print xcount + ycount

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)

x = []
flag = 0
for i in range(5):
    x.append(raw_input().split(" "))

for i in x:
    flag+=1
    for xo,j in enumerate(i):
        if j == "1":
            lol = flag-1
            lo1 = int(xo)
a = max((2-lol),lol-2)
b = max((2 - lo1),lo1-2)
print a+b

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

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

mat = [[0 for i in range(5)]for i in range(5)]
row = 0
col = 0
for i in range(5):

	temp = map(int, raw_input().split())

	for j in range(len(temp)):

		mat[i][j] = temp[j]
		if temp[j]:

			row, col = i + 1, j + 1

change = 0

change += abs(row - 3)
change += abs(col - 3)

print change

##s1=raw_input()
##s2=raw_input()
##s3=raw_input()
##s4=raw_input()
##s5=raw_input()
##if '1' in s1:
##    s1=filter(lambda a: a != ' ' , s1)
##    u=s1.index('1')
##    o=abs(u-2)+2
##if '1' in s2:
##    s2=filter(lambda a: a != ' ' , s2)
##    u=s2.index('1')
##    o=abs(u-2)+1
##if '1' in s3:
##    s3=filter(lambda a: a != ' ' , s3)
##    u=s3.index('1')
##    o=abs(u-2)
##if '1' in s4:
##    s4=filter(lambda a: a != ' ' , s4)
##    u=s4.index('1')
##    o=abs(u-2)+1
##if '1' in s5:
##    s5=filter(lambda a: a != ' ' , s5)
##    u=s5.index('1')
##    o=abs(u-2)+2
##print o
for i in range(5):
    s=raw_input()
    if '1' in s:
        s = filter(lambda a: a != ' ', s)
        o=abs(s.index('1')-2)+abs(2-i)
print o

s1=raw_input()
s2=raw_input()
s3=raw_input()
s4=raw_input()
s5=raw_input()
if '1' in s1:
    s1=filter(lambda a: a != ' ' , s1)
    u=s1.index('1')
    o=abs(u-2)+2
if '1' in s2:
    s2=filter(lambda a: a != ' ' , s2)
    u=s2.index('1')
    o=abs(u-2)+1
if '1' in s3:
    s3=filter(lambda a: a != ' ' , s3)
    u=s3.index('1')
    o=abs(u-2)
if '1' in s4:
    s4=filter(lambda a: a != ' ' , s4)
    u=s4.index('1')
    o=abs(u-2)+1
if '1' in s5:
    s5=filter(lambda a: a != ' ' , s5)
    u=s5.index('1')
    o=abs(u-2)+2
print o

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

temp2 = -1
temp = -1
for i in range(5):
    s = raw_input()
    if(s.find("1")!=-1):
        arr = s.split(" ")
        temp2 = i
        temp = arr.index("1")
print abs(2-temp2) + abs(2-temp)

count1=-1
for x in range(5):
    count1+=1
    a=[int(i) for i in raw_input().split()]
    for j in range(len(a)):
        if a[j]==1:
            count2=j
            a1=abs(2-count1)
            a2=abs(2-count2)
            print a1+a2

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

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

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

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)

a = [[0 for j in range(5)] for i in range(5)]
x = 0
y = 0
for i in range(0,5):
	a[i] = map(int,raw_input().split())

for i in range(0,5):
	for j in range(0,5):
		if a[i][j] == 1:
			x = i + 1
			y = j + 1
			break
print abs(x-3) + abs(y-3)

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

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

#https://codeforces.com/problemset/problem/263/A
#11Apr2020
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))

i, j = divmod(''.join(input().replace(' ', '') for i in range(5)).index('1'), 5)
print(abs(i - 2) + abs(j - 2))

i, j = divmod(' '.join(input() for i in range(5)).index('1') // 2, 5)
print(abs(i - 2) + abs(j - 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()))

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)
else:
    if c >= 3:
        print(c-r)
    else:
        print(6-(c+r))

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

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

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

# 263A => Beautiful Matrix
# https://codeforces.com/problemset/problem/263/A

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

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

if __name__ == "__main__":

    move_num_to_center_of_matrix()

'''
Beautiful Matrix

You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one.
rows : (1 ≤ i < 5), cols : (1 ≤ j < 5)
In one move, you are allowed to apply one of the two transf. to the matrix:

1. Swap two neighboring matrix rows
2. Swap two neighboring matrix columns
A matrix looks beautiful, if the single number one of the matrix is located
in its middle
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
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 the minimum number of moves needed to make the matrix beautiful.
'''
# import time

def solve():
	matrix = []
	for _ in range(5):
		matrix.append(input().split())
	# solve.start = time.time()
	print(find_min_num(matrix))
	# solve.end = time.time()

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

# print(f'TIME TAKEN IN SECONDS:\n\
# {solve.end - solve.start}')
'''
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=[]
for i in range(5):
    a=[]
    a=input().split()
    matrix.append(a)
# print(matrix)
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)

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)

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 11 21:20:49 2020

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

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)

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)

counter = 0
for i in range(5):
    row = input().split()
    if "1" in row:
        nRow = i
        for j in range(5):
            if row[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)

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)

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

r=0
for i in range(5):
        raw_answer = raw_input()
        answers = raw_answer.split(' ')
        for j in range(5):
            if answers[j]=='1':
                r=abs(i-2)+abs(j-2)
print(r)

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
#finds the non-zero number
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

#find the distance from the center
distance = abs(dx-2)+abs(dy-2)

print(distance)

r1=raw_input()
r2=raw_input()
r3=raw_input()
r4=raw_input()
r5=raw_input()
r1=r1.split(' ')
r2=r2.split(' ')
r3=r3.split(' ')
r4=r4.split(' ')
r5=r5.split(' ')
k=0
a=[r1,r2,r3,r4,r5]
for c in a:
    if '1' in c:
        one=c.index('1')
        k=k+abs(one-2)
        if c==r1:
            k=k+2
        if c==r2:
            k=k+1
        if c==r4:
            k=k+1
        if c==r5:
            k=k+2
print k

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:
            print(abs(i-2)+abs(j-2))
            break;
    if a[i][j]==1:
        break;

for i in range(5):
    s = raw_input()
    for j in range(len(s)):
        if s[j] == '1':
            x, y = i, j/2
print abs(x-2)+abs(y-2)

list_ = []
for i in range(0, 5):
	list_.append([int(i) for i in raw_input().split()])
ans = 0
for i in range(0, 5):
	for j in range(0, 5):
		if (list_[i][j] == 1):
			ans = abs(i-2) + abs(j-2)
print(ans)

for i in xrange(5) :
    a = map(int, raw_input().split())
    if 1 in a :
        row = i + 1
        column = a.index(1) + 1

print abs(3 - row) + abs(3 - column)

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

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

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)

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

for i in range(5):
    for j in range(5):
        if matrix[i][j] == "1":
            row,col = i, j
print(abs(2 - row) + abs(2 - col))

t=5

while t!=0:

	a=map(int,raw_input().split())
	for i in range(len(a)):
		if a[i]==1:
			x=5-t
			y=i
	t=t-1

x=x+1
y=y+1
print abs(3-x)+abs(3-y)

for row in range(5):
    s = input().split()
    for col in range(5):
        if s[col] == "1":
            a = abs(row-2)+abs(col-2)

print(a)

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

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)

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

n1 = list(map(int, raw_input().split()))
n2 = list(map(int, raw_input().split()))
n3 = list(map(int, raw_input().split()))
n4 = list(map(int, raw_input().split()))
n5 = list(map(int, raw_input().split()))

if 1 in n1:
    row = 0
    column = n1.index(1)
elif 1 in n2:
    row = 1
    column = n2.index(1)
elif 1 in n3:
    row = 2
    column = n3.index(1)
elif 1 in n4:
    row = 3
    column = n4.index(1)
elif 1 in n5:
    row = 4
    column = n5.index(1)

if row >2:
	res= row-2
	if column > 2:
		res += (column-2)
	elif column <2:
		res += (2- column)
	elif column == 2:
		res += 0
	print res
	exit()
elif row < 2:
	res = 2-row
	if column > 2:
		res += (column-2)
	elif column <2:
		res += (2- column)
	elif column == 2:
		res += 0
	print res
	exit()
elif row==2:
	res = 0
	if column > 2:
		res += (column-2)
	elif column <2:
		res += (2- column)
	elif column == 2:
		res += 0
	print res
	exit()

def matrix():
    for i in range(5):
        k = raw_input().split()
        k = map(int,k)
        for x in range(5):
            if (k[x]==1):
                #print (i,x)
                a = abs(i-2)
                b = abs(x-2)
                print (a+b)

matrix()

r_count = 0
c_count = 0
f_row = 0
f_column = 0

for i in range(5):
 r_count += 1
 row = raw_input()
 c_count = row.find('1')
 if(c_count >= 0):
  f_row = r_count
  f_column = c_count/2

print abs(f_row - 3)+abs(f_column - 2)

import sys
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp(): #Integer
    return(int(input()))
def inlt(): #integer list
    return(list(map(int,input().split())))
def insr(): #String
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

result = 0
for row_idx in range(5):
    row = inlt()
    for idx, position in enumerate(row):
        if position == 1:
            result = abs(3-row_idx) + abs(3-idx)
print(result)

from sys import stdin
real_number = [int(x) for x in stdin.read().split()]
c = 0
for x in real_number[0:]:
    if x == 0:
        c += 1
    if x ==1:
        break
if c == 12:
    print('0')
if 0<=c<=4:
    if c==2:
        print('2')
    elif c%2 == 0:
        print('4')
    elif c%2 != 0 and c != 0:
        print('3')
if 5<=c<=9:
    if c==7:
        print('1')
    elif c%2 == 0:
        print('2')
    elif c%2 != 0 and c!=7:
        print('3')
if 11<=c<=15:
    if c%2 == 0 and c !=12:
        print('2')
    elif c%2!=0:
        print(1)
if 15<=c<=19:
    if c==17:
        print('1')
    elif c%2 == 0:
        print('2')
    elif c%2 != 0 and c==17:
        print('3')
if 20<=c<=24:
    if c == 22:
        print('2')
    elif c%2 ==0 and c!=22 and c != 24:
        print('3')
    elif c%2 != 0:
        print('3')
    elif c == 24:
        print('4')

l = []
for i in range(5):
	l.append(list(map(int,raw_input().split(' '))))
for i in range(5):
	for j in range(5):
		if l[i][j]:
			ii,jj = i,j
print abs(3-ii)+abs(3-jj)

for i in range(5):
    column = input().split()
    for j in range(5):
        if column[j]=='1':
            moves = (3-i)+(3-j)
            print(moves)

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]:
        if col == i:
            print(col)
        else:
            final = col - i
            print(abs(final))

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

def matrix():
    for i in range(5):
        k = raw_input().split()
        k = map(int,k)
        for x in range(5):
            if (k[x]==1):
                s = (x-i)
    if (s>=0):
        print s
    else:
        print -s
matrix()

matrix = [[int(x) for x in input().split()] for i in range(5)]
moves = 0

for i in range(0,5,1) :
    for n in range(0,5,1):
        if matrix [i][n] == 1:
            if i != n :
                moves = abs (i - 2) + abs(n - 2)
            elif i == n :
                if n == 2 :
                    moves = 0
                else :
                    moves = (int(i/2))+2

print(moves)

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

xi, xj = 0, 0
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))

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

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
               c=l
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)

# -*- coding: utf-8 -*-
"""
Created on Mon Nov  2 22:21:51 2020

@author: 86177

"""
a=list(input())
b=list(input())
c=list(input())
d=list(input())
e=list(input())
f=[a,b,c,d,e]
for i in range(5):
    for n in range(5):
        if f[i][n] in ["1"]:
           h=int(i)--2
           q=int(n)--2
           h=abs(h)
           q=abs(q)
           print(h++q)
        else:
            continue

import sys
'''
  - Matrix is assumed to be 5 x 5 of all 0s and exactly one 1.
  - Can swap matrix rows or columns.
  - Find minimum moves required to move 1 to the center.
'''
def min_moves_for_beautiful_matrix(m):
  x = 0
  y = 0
  for i in range(0, 5):
    for j in range(0, 5):
      if m[i][j]:
        x = i
        y = j

  return abs(2-x) + abs(2-y)

#matrix = [map(lambda x: int(x), line.split(' ')) for line in sys.stdin.read().split('\n')]
#print min_moves_for_beautiful_matrix(matrix)
print sys.stdin.read().split('\n')

t = 0
i = 0
for j in range(5):
    s = input().replace(' ', '')
    pos = s.find('1')
    if s.find('1') > 0:
        t += abs(3 - pos + 1)
        t += abs(3 - i + 1)
    i += 1
print(t)

l = [2, 1 ,0, 2, 1]

for i in l:
    s = input()
    if "1" in s:print(i+abs(s.find('1') - 2))

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

s = [0,1,0,0,0]
s[0] = input()
s[1] = input()
s[2] = input()
s[3] = input()
s[4]= input()
line1 = 0
line2 = 0
for i in range(5):
    if "1" in s[i]:
        m = i
        line1 = i+1-3
        line1 = abs(line1)
for x in range(5):
    if s[m][x] == "1":
        line2 = abs(x+1-3)
print(line1+line2)

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

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((row-3) + (column-3))

a = []

for i in range(5):
    i = input().split(' ')
    a.append(i)

for i in range(5):
    if '1' in a[i]:
        if a[i].index('1') >= 4:
            final = a[i].index('1') - 1
            print(final)
        else:
            print(a[i].index('1'))
        break

for x in range(0,5):
    r = raw_input()

    if r != '0 0 0 0 0':
        l = list(r)
        p = 0
        if x > 3:
            p = x - 3
        else:
            p = 3 - x

        q =0
        for a in range(0,9):
            if l[a]=='1':
                if a > 5:
                    q = a - 5
                else:
                    q = 5 - a

        add = p + q/2

print add

# CF-A Q1

# a,b = input().split()

# kids = [int(i) for i in input().split()]

# count = 0
# for i in kids:
# 	if i >int(b):
# 		count += 2
# 	else:
# 		count += 1

# print(count)

#CF-A Q2

# a = int(input())
# game = input()
# danik = game.count('D')
# anton = game.count('A')

# if danik>anton:
# 	print('Danik')
# elif danik<anton:
# 	print('Anton')
# else:
# 	print('Friendship')

#CF-A Q3

# a,b = input().split()
# a = int(a)
# b = int(b)
# count = 0

# while a<=b:
# 	print(a,b)
# 	a = a * 3
# 	b = b * 2

# 	count = count + 1
# 	if a>b:
# 		print(count)
# 		break

#CF-A Q4

# solved in the past

#CF-A Q5

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] # element position in matrix

row = row + 1
column = column + 1

if row + column != 6:
	if row>column:
		print(row-column)
	else:
		print(column-row)

else:
	print(0)

# n = input
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)
				break
			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)

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)
if x != 2: amount += abs(2 - x)
elif y != 2: amount += abs(2 - y)
print(amount)

#  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

n = input()
count = 0
row = 0
col = 0
for i in range(5):
    for j in range(5):
        if n[i][j] == 1:
            row = i
            col = j
            break
        break
if row > 2 and row != 2:
    row -= 1
    count += 1
elif row < 2 and row != 2:
    row += 1
    count += 1
else:
    pass

if col < 2 and col != 2:
    col += 1
    count += 1
elif col > 2 and col != 2:
    col -= 1
    count += 1
else:
    pass

print(count+1)

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

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

def matrix():
    for i in range(5):
        k = raw_input().split()
        k = map(int,k)
        for x in range(5):
            if (k[x]==1):
                if (x==i)and(x!=2):
                    s = 4
                else:
                    s = (x-i)
    if (s>=0):
        print s
    else:
        print -s
matrix()

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

found = 0
for row in range (5):
    if (found == 1):
        break;
    col = 0
    for number in raw_input().split():
        if number == "1":
            found = 1
            break;
        else:
            col = col + 1
print (abs(row - 2) + abs(col - 2))

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

arr =[[0 for _ in range(5)] for _ in range(5)]
# print(arr)
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(-4+posJ+posI))

x = 0
y = 0
for i in range(5):
    line = raw_input().split(" ")
    for j in range(5):
        if (int(line[j]) == 1):
            x = i
            y = j

print abs(x - 3) + abs(y - 3)

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==3:
    count+=1
if col==1 or col==5:
    count+=2
elif col==2 or col==3:
    count+=1
print(count)

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

# Getting all inputs
for i in range(5):
    a = map(int, raw_input().split())
    print a

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

i = 1

while i <= 5:
    listnum = [int(b) for b in input().split()]

    if 1 in listnum:
        indexX = listnum.index(1)+1
        indexY = i

    i += 1

print(indexX, indexY)

a = []

row = []
col = []

for i in range(5):
    i = input().split(' ')
    a.append(i)

# print(a[2][2])  center

# print(a[b][0])  row

i = 0
n = 0
while i < 6:
    # print(a[i][n])
    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]:
        final = col - i
        print(abs(final))

row1 = input("")
row2 = input("")
row3 = input("")
row4 = input("")
row5 = input("")
total = f"{row1} {row2} {row3} {row4} {row5}"
total = total.split(" ")
for i in total:
    if i == "1":
        ans = 13 - total.index(i)
        print(ans)

def lie(n):
    m=1
    if '1' in n:
        for i in n:
            if i=='1':
                return m
            else:
                m=m+1
def zong():
    for o in range(5):
        c = 1
        a = str(input())
        b = list(a)
        if '1' in b:
            return c
        else:
            c = c+1
    print(abs(3-c)+abs(3-lie(b)))

zong()

import sys

stringsList = []
width = 0

for line in sys.stdin:
    stringsList.append(line)
print(stringsList)
for index in range(0, len(stringsList)):
    if '1' in stringsList[index]:
        width = index
        break

result = abs(width - 3) + abs(stringsList[width].find('1') - 3)

a = [list(map(int, input().split()))]
for r in range(len(a)):
    for c in range(len(a[r])):
        if a[r][c] == 0:
            print(abs(r+1-3)+abs(c+1-3))
            break

import sys
l = []
count = 0

for i in range(5):
	l.append(map(int, raw_input().split(" ")))

for i in range(5):
	if(l[2][2] == 1):
		print("{0}".format(count))
		break
	for j in range(5):
		if(l[i][j] == 1) and (i<2):
			temp = l[i+1][j]
			l[i+1][j] = l[i][j]
			l[i][j] = temp

			count+=1
		if(l[i][j] == 1) and (j<2):
			temp = l[i][j+1]
			l[i][j+1] = l[i][j]
			l[i][j] = temp

			count+=1

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

m=[];
for i in range(5):
    m.append(map(int,raw_input().split()));
for i in range(5):
    for j in range(5):
        if(m[i][j]==1):
            print i+j;
            break;

# CF-A Q1

# a,b = input().split()

# kids = [int(i) for i in input().split()]

# count = 0
# for i in kids:
# 	if i >int(b):
# 		count += 2
# 	else:
# 		count += 1

# print(count)

#CF-A Q2

# a = int(input())
# game = input()
# danik = game.count('D')
# anton = game.count('A')

# if danik>anton:
# 	print('Danik')
# elif danik<anton:
# 	print('Anton')
# else:
# 	print('Friendship')

#CF-A Q3

# a,b = input().split()
# a = int(a)
# b = int(b)
# count = 0

# while a<=b:
# 	print(a,b)
# 	a = a * 3
# 	b = b * 2

# 	count = count + 1
# 	if a>b:
# 		print(count)
# 		break

#CF-A Q4

# solved in the past

#CF-A Q5

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] # element position in matrix

row = row + 1
column = column + 1

pos = row+column

if pos > 6 or pos < 6:
	if row>column:
		print(row-column)
	elif column>row:
		print(column-row)
	else:
		print((row-3) + (column-3))

else:
	print(0)

matrix = [input().split() for i in range(5)]
for i in range(5):
    for j in range(5):
        if matrix[i][j] == "1":
            break

print(abs(i-2)+abs(j-2))

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)

a = [list(map(int, input().split()))]
for r in range(len(a)):
    for c in range(len(a[r])):
        if a[r][c] == 0:
            print(abs(r-3)+abs(c-3))
            break

for i in range(1,6):
    x=input()
    if "1" in x:
        row_n= i
        row = x
r_steps=abs(row_n - 3)
c_steps = abs((x.find("1") + 1) - 3)
print(r_steps + c_steps)

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

arr =[[0 for _ in range(5)] for _ in range(5)]
# print(arr)
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(-4+posJ+posI))

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

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

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

for i in range(len(b)):
    if b[i]==1:
        if i<=2:
            s=4-i
        else:
            s=i-1

for i in range(len(c)):
    if c[i]==1:
        if i<2:
            s=i
        elif i>3:
            s=i-2
        else:
            s=0

for i in range(len(d)):
    if d[i]==1:
        if i<=2:
            s=4-i
        else:
            s=i-1

for i in range(len(e)):
    if e[i]==1:
        if i<=2:
            s=4-i
        else:
            s=i-1

print(s)

diffX = 0
diffY = 0
matrix = []
x,y = 0,0
for _ in range(4):
    #matrix.append(list(map(int,"0 0 0 0 0".split(' '))))
    matrix.append(list(map(int,input().split(' '))))
#matrix.append(list(map(int,"0 0 1 0 0".split(' '))))
print(matrix)
for i in range(4):
    for j in range(4):
        if matrix[i][j] == 1:
            x = i
            y = j
print("x: " + str(x) + " y: " + str(y))

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 = [x.split() for x in input().split("\n")]
i, j = 0, 0

for y in matrix:
    for x in y:
        if(x == "1"):
            i, j = matrix.index(y), y.index(x)
print(5-i + 5-j - 2)

found = 0
for row in range (1, 5):
    if (found == 1):
        break;
    col = 1
    for number in raw_input().split():
        if number == "1":
            found = 1
            break;
        else:
            col = col + 1
print (abs(row - 3) + abs(col - 3)) - 1

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

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)+(2 -y))

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

for i in range(0,5):
    a = input()

    print(a,type(a))

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 - 3) + abs(j - 3)
        else:
            continue
print(total)

arr =[[0 for _ in range(5)] for _ in range(5)]
# print(arr)
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(10-posJ-posI)

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

print(abs(3-a) + abs(3-b))

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
            c=j
m=abs(3-r+1)+abs(3-c+1)
print(m)

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

# 263A => Beautiful Matrix
# https://codeforces.com/problemset/problem/263/A

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 - 2) + abs(coluna - 2)
print(moves)

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(6-(C+D)))

import math
l=[]
for i in range(5):
    ch=input()
    l.append(ch.split())
def test(l):
    for i in range(len(l)):
        for j in range(len(l)):
            if l[i][j]=="1":
                return (i,j)
x=test(l)
print(abs(x[0]-x[1]))

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

for x in range(0,5):
    r = raw_input()

    if r != '0 0 0 0 0':
        l = list(r)
        p = 0
        if x > 3:
            p = x - 3
        else:
            p = 3 - x - 1

        q =0
        for a in range(0,9):
            if l[a]=='1':
                if a > 5:
                    q = a - 5
                else:
                    q = 5 - a

        add = p + q/2

print add

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)))
        quit(0)
    row += 1

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]

print(position)

beauty = abs((r-2))+abs((c-2))

print(beauty)

mat=[]
for i in range(0,5):
    mat.append([]);
    taker=raw_input()
    print taker
    for j in range(0,len(taker)):
        if taker[j]!=' ':
           mat[i].append(taker[j]);
ii=-1;
jj=-1;
for i in range(0,len(mat)):
    for j in range(0,len(mat[i])):
        if mat[i][j]=='1':
            ii=i;
            jj=j;
            break
        if ii==i:
            break
print abs(ii-2)+abs(jj-2)

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(p.index(1))
elif q.count(1):
    print(q.index(1)-1)
elif s.count(1):
    print(abs(s.index(1)-2))
elif t.count(1):
    print(t.index(1))
elif r.count(1):
    print(r.index(1)-1)

a1, a2, a3, a4, a5 = (input().split())
b1, b2, b3, b4, b5 = (input().split())
c1, c2, c3, c4, c5 = (input().split())
d1, d2, d3, d4, d5 = (input().split())
e1, e2, e3, e4, e5 = (input().split())

if '1' in c3:
    print('0')
elif '1' in b3 or c4 or c2 or d3:
    print('1')
elif '1' in a3 or b4 or c5 or d4 or e3 or d2 or c1 or b2:
    print('2')
elif 'i' in a2 or a4 or b5 or d5 or e4 or e2 or d1 or b1:
    print('3')
else:
    print('4')

for i in xrange(5):
    s = raw_input().split()
    t = c = 0
    if '1' in s:
        t = i
        c = s.index('1')
print abs(2-t)+abs(c-2)

"""
https://codeforces.com/problemset/problem/263/A
"""
def move (array, posi):    #this is to find the moves of the number and return it
    if posi == "3":
        return 0
    elif (posi>3):
        return (5 - posi)
    elif (posi<3):
        return (3-posi)

def odd_location_and_calculation(array):
    # this function willl return the location of "1" in the diven 3-D matrix in tems of x, y coordinates
    check = 0
    for i in range(5):
        for j in range(5):
            if array[i][j] == 1:
                x_coordinate = i
                y_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)

if __name__ == "__main__":
    array = []
    for i in range(5):
        rowArray = list(map(int, input().split(" ")))
        array.append(rowArray)
    print(odd_location_and_calculation(array))

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

moves=0

for i in range(1,6):

    line=raw_input()
    line=line.replace(" ", "")

    if "1" in line:
        column=line.find("1")

        moves=abs(3-i)+abs(3-column)

print moves

for x in range(0,5):
    r = raw_input()

    if r != '0 0 0 0 0':
        l = list(r)
        p = 0
        if x > 3:
            p = x +1 - 3
        else:
            p = 3 - x - 1

        q =0
        for a in range(0,9):
            if l[a]=='1':
                if a > 5:
                    q = a + 1 - 5
                else:
                    q = 5 - a - 1

        add = p + q/2

print add

n1 = list(map(int, raw_input().split()))
n2 = list(map(int, raw_input().split()))
n3 = list(map(int, raw_input().split()))
n4 = list(map(int, raw_input().split()))
n5 = list(map(int, raw_input().split()))
mrow=2
mcol=2

if 1 in n1:
    row = 0
    column = n1.index(1)
elif 1 in n2:
    row = 1
    column = n2.index(1)
elif 1 in n3:
    row = 2
    column = n3.index(1)
elif 1 in n4:
    row = 3
    column = n4.index(1)
elif 1 in n5:
    row = 4
    column = n5.index(1)
res=(mrow-row)+(mcol-column)
print res

l=[]
for i in range(5):
    ch=input()
    l.append(ch.split())
def test(l):
    for i in range(len(l)):
        for j in range(len(l)):
            if l[i][j]=="1":
                return (i,j)
x=test(l)
if x[0]>x[1]:
    print(abs(x[0]-x[1]))
else:
    print(abs(x[1]-x[0]))

# Getting all inputs
for i in range(5):
    a = map(int, raw_input().split())
    print a

import sys

stringsList = []
height = 0
width = 0

for line in sys.stdin:
    print(line)

for i in range(5):
    column = input().split()
    for j in range(5):
        if column[j]=='1':
            moves = (3-i)+(3-j)
            print(moves)

from math import *
row1 = input("")
row2 = input("")
row3 = input("")
row4 = input("")
row5 = input("")
total = f"{row1} {row2} {row3} {row4} {row5}"
total = total.split(" ")
for i in total:
    if i == "1" and total.index(i) <= 12:
        ans = 12 - abs(total.index(i))
        print(ans)
    elif i == "1" and total.index(i) > 12:
        ans = 12 - total.index(i)
        print(ans)

row1 = input("")
row2 = input("")
row3 = input("")
row4 = input("")
row5 = input("")
total = f"{row1} {row2} {row3} {row4} {row5}"
total = total.split(" ")
for i in total:
    if i == "1":
        ans = 12 - total.index(i)
        print(ans)

"""
"""
def move (array, posi):    #this is to find the moves of the number and return it
    if posi == 2:
        return 0
    elif (posi>2):
        return (posi - 2)
    elif (posi<2):
        return (2 - posi)

def odd_location_and_calculation(array):
    # this function willl return the location of "1" in the diven 3-D matrix in tems of x, y coordinates
    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)
    print(x_coordinate)
    print(y_coordinate)
    return (x_move+y_move)

#this is a new program

if __name__ == "__main__":
    array = []
    for i in range(5):
        rowArray = list(map(int, input().split(" ")))
        array.append(rowArray)
    print(odd_location_and_calculation(array))

from operator import add
m = reduce(add, (raw_input().split() for _ in xrange(5)), [])
i = m.index('1')
print abs(i / 5 - 3) + abs(i % 5 - 3)

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