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

Difficulty: interview

Starter code:

Solutions:
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 = [list(map(int, input().split())) for i in range(5)]
for i in range(5):
    line = l[i]
    if 1 in line: print(abs(2 - i) + abs(2 - line.index(1)))

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



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

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 = [[] for i in range(5)]
for i in range(5):
    a[i].extend(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))



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



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

import math
matrix=[[int(i) for i in input().split(" ")] for i in range(0,5)]
(x,y)=(0,0)
for i in range(0,5):
    for j in range(0,5):
        if matrix[i][j]==1:
            (x,y)=(i,j)
print(int(math.fabs(x-2)+math.fabs(y-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()))
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)

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

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


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

for i in range(5):
    line = input().split()
    for j, value in enumerate(line):
        if value == "1":
            x, y = i, j

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


row = col = -1


def problem_input() -> None:
    nonlocal 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))

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


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)
#print(row_in, col_in)
steps = math.fabs((3 - (row_in))) + math.fabs((3 - (col_in)))
print(int(steps))

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


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

a=input().split(' ')
b=input().split(' ')
c=input().split(' ')
d=input().split(' ')
e=input().split(' ')
x=0
y=0
if '1' in a:
    y=a.index('1')
    x=0

if '1' in b:
    y=b.index('1')
    x=1

if '1' in c:
    y=c.index('1')
    x=2

if '1' in d:
    y=d.index('1')
    x=3

if '1' in e:
    y=e.index('1')
    x=4
print(abs(x-2)+abs(y-2))


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

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

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

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


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