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.

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.

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

using System;

namespace BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            char[,] Array = new char [5, 5];
            int count = 0;int rowindex = 0;
            int colindex = 0;

            for (int i=0;i<=4;i++)
            {
                rowindex = i;
                string value = Console.ReadLine();
                if(value.Contains("1"))
                {
                    //Console.WriteLine(value.IndexOf('1'));
                    colindex = value.IndexOf('1') / 2 ;
                    break;
                }

            }

          //  Console.WriteLine(2-rowindex/2+1+2-colindex);
            Console.WriteLine(Math.Abs(rowindex-2)+ Math.Abs(colindex-2));

        }
    }
}

using System;

namespace A_Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            for (int i = 0; i < 5; i++) {
                str = Console.ReadLine();
                string[] strs = str.Split(' ');
                for(int j=0; j<5; j++)
                {
                    if (strs[j] == "1")
                    {
                        Console.WriteLine(Math.Abs(2-i)+Math.Abs(2-j));
                        break;
                    }
                }
            }
        }
    }
}

using System;
using System.Linq;
using System.Text;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var first = Console.ReadLine().Replace(" ", "");
            var second = Console.ReadLine().Replace(" ", "");
            var third = Console.ReadLine().Replace(" ", "");
            var fourth = Console.ReadLine().Replace(" ", "");
            var fifth = Console.ReadLine().Replace(" ", "");

            const string one = "1";

            var counter = 0;
            if (first.Contains(one))
            {
                counter += 2;
                counter += Math.Abs(first.IndexOf("1", StringComparison.CurrentCulture) - 2);
            }
            else if (second.Contains(one))
            {
                counter += 1;
                counter += Math.Abs(second.IndexOf("1", StringComparison.CurrentCulture) - 2);
            }
            else if (third.Contains(one))
            {
                counter += Math.Abs(third.IndexOf("1", StringComparison.CurrentCulture) - 2);
            }
            else if (fourth.Contains(one))
            {
                counter += 1;
                counter += Math.Abs(fourth.IndexOf("1", StringComparison.CurrentCulture) - 2);
            }
            else
            {
                counter += 2;
                counter += Math.Abs(fifth.IndexOf("1", StringComparison.CurrentCulture) - 2);
            }

            Console.WriteLine(counter);
        }

    }
}

using System;

namespace BeautifulMatrix
{
    internal class Program
    {
        private static void Main()
        {
            var row = 0;
            var col = 0;

            string line;
            string[] splitLine;
            for (var i = 1; i <= 5; i++)
            {
                line = Console.ReadLine().Trim();

                if (row != 0)
                {
                    continue;
                }

                splitLine = line.Split(' ');

                for (var j = 1; j <= 5; j++)
                {
                    if (splitLine[j - 1] == "1")
                    {
                        row = i;
                        col = j;
                        break;
                    }
                }
            }

            Console.WriteLine(Math.Abs(row - 3) + Math.Abs(col - 3));
        }
    }
}

using System;

class Program
{
    static void Main(string[] args)
    {
        int ci, cj, k;
        ci = cj = 0;
        for (int i = 1; i <= 5; i++)
        {
            string a = Console.ReadLine();
            int b;
            k = 0;
            string[] at = a.Split(new Char[] { ' ' });
            foreach (var a_item in at)
            {
                k += 1;
                b = int.Parse(a_item);
                if (b == 1)
                {
                    ci = i;
                    cj = k;
                }
            }
        }
        int m = Math.Abs(cj-3)+Math.Abs(ci-3);
        Console.WriteLine(m);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        private static long count = 0;
        static void Main(string[] args)
        {
            string[] row = new string[5];
            decimal movement = 0;
            for (int i = 0; i < 5; ++i)
            {
                row[i] = Console.ReadLine();
                row[i] = row[i].Replace(" ", "");
                if (row[i].Contains("1"))
                {
                    movement = Math.Abs((decimal)(2 - row[i].IndexOf('1')));
                    movement += Math.Abs(2 - i);
                }
            }
            Console.WriteLine(movement);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace sp
{
    public class Program
    {

        private static void Main()
        {
            int get_x = 0, get_y = 0;
            int[,] ms = new int[5, 5];
            for (int i = 0; i < 5; i++) {
                int[] cut = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                for (int j=0;j<5;j++){
                    ms[i, j] = cut[j];
                    if (ms[i, j] == 1) { get_x = j; get_y = i; }
                }
            }
            int res = Math.Abs(2-get_x)+Math.Abs (2-get_y );
            Console.WriteLine(res);

        }
    }
}

using System;

public class Test {

	public static int[,] a = new int[5, 5];

	public static void Main() {
		int x = 0, y = 0;
		for (int i = 0; i < 5; i++) {
			string[] l = Console.ReadLine().Split();
			for (int j = 0; j < 5; j++) {
				a[i, j] = Convert.ToInt32(l[j]);
				if (a[i, j] == 1) {
					x = i;
					y = j;
				}
			}
		}

		Console.WriteLine(Math.Abs(x - 2) + Math.Abs(y - 2));
	}
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace Test
{
	class MainClass
	{
		public class Vector2
		{
			public byte x, y;

			public Vector2 (byte x, byte y)
			{
				this.x = x;
				this.y = y;
			}
		}

		public class Node
		{
			public static List<Node> nodes = new List<Node>();

			public Vector2 position;
			public byte number;

			public List<Node> neighnours = new List<Node>();

			public Node (Vector2 pos, byte number)
			{
				position = pos;
				this.number = number;
			}

			public void SetNeighbours (List<Node> newNodesList)
			{
				neighnours = newNodesList;
			}

			public byte MinMovesToPosition (Vector2 targetPosition)
			{
				byte moves = 0;

				if (position.x != targetPosition.x || position.y != targetPosition.y)
					RecursionToPosition (targetPosition, ref moves);

				return moves;
			}

			public void RecursionToPosition (Vector2 pos, ref byte moves)
			{
				Node nextNode = neighnours.OrderBy(n => Math.Abs(pos.x - n.position.x) + Math.Abs(pos.y - n.position.y)).FirstOrDefault();

				moves++;

				if (nextNode.position.x != pos.x || nextNode.position.y != pos.y)
				{
					nextNode.RecursionToPosition (pos, ref moves);
				}
			}
		}

		public static void Main ()
		{
			for (byte y = 0; y < 5; y++)
			{
				string input = Console.ReadLine();

				for (byte x = 0; x < 5; x++)
					Node.nodes.Add(new Node(new Vector2(x, y), byte.Parse(input[x * 2].ToString())));
			}

			for (byte i = 0; i < 25; i++)
			{
				var node = Node.nodes [i];
				node.SetNeighbours(Node.nodes.FindAll(n => Math.Abs (n.position.x - node.position.x) + Math.Abs (n.position.y - node.position.y) == 1));
			}
			Console.WriteLine(Node.nodes.Find(n => n.number == 1).MinMovesToPosition(new Vector2(2, 2)));
		}
	}
}

using System;
class Solution
{
    public static void Main(string[] args)
    {
        int row = 5;
        int[][] matrix = new int[row][];
        string[] input;
        int one_row = 0, one_col = 0;
        int result = 0;
        for (int x = 0; x < 5; x++)
        {
            input = Console.ReadLine().Split(' ');
            matrix[x] = Array.ConvertAll(input, Int32.Parse);

        }
        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                if (matrix[i][j] == 1)
                {
                    one_row = i + 1;
                    one_col = j + 1;
                    break;
                }
            }
            if (one_row != 0)
                break;
        }
        if (one_row > 3)
            result = result + one_row - 3;
        else
            result = result + (3 - one_row);

        if (one_col > 3)
            result = result + one_col - 3;
        else
            result = result + (3 - one_col);

        Console.WriteLine(result);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split(' ');
            var line2 = Console.ReadLine().Split(' ');
            var line3 = Console.ReadLine().Split(' ');
            var line4 = Console.ReadLine().Split(' ');
            var line5 = Console.ReadLine().Split(' ');

            var index = findNum1Index(new List<string[]> { line1, line2, line3, line4, line5 });

            Console.WriteLine(Math.Abs(index[0] - 3) + Math.Abs(index[1] - 3));

        }

        public static List<int> findNum1Index(List<string[]> matrix)
        {
            List<int> result = new List<int>();

            for (int i = 0; i < matrix.Count; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (matrix[i][j] == "1")
                    {
                        result.Add(i+1);
                        result.Add(j+1);
                    }
                }
            }

            return result;
        }

    }
}

using System;

namespace Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            byte x = 0;
            byte y = 0;
            bool done = false;

            while (y < 5 && !done)
            {
                string[] matrix = Console.ReadLine().Split();

                while (x < 5 && !done)
                {
                    if (matrix[x] == "1")
                    {
                        Console.WriteLine(Math.Abs(x-2)+Math.Abs(y - 2));
                        done = true;

                    }

                    x++;
                }

                x = 0;
                y++;

            }

            Console.ReadLine();
        }
    }
}

using System;

namespace ConsoleApp1
{
    internal static class Program
    {
        private static void Main()
        {
            int steps = 0;
            for (int i = 1; i <= 5; i++)
            {
                string s1 = Console.ReadLine();
                string[] s1values = s1.Split(' ');

                for (int j = 1; j <= 5; j++)
                {

                    int x = int.Parse(s1values[j-1]);
                    if (x == 1)
                    {
                        steps = Math.Abs(i - 3) + Math.Abs(j - 3);
                    }
                }
            }
            Console.WriteLine(steps);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _263A
{
    class Program
    {
        static void Main(string[] args)
        {
            int col=0;
            int str=0;
            for (int i = 0; i < 5; i++) {
                string[] arr = Console.ReadLine().Split(' ');
                for (int j = 0; j < 5; j++)
                {
                    if (arr[j] == "1") {
                        str = i;
                        col = j;
                    }
                }
            }

            int n = Math.Abs(col - 2) + Math.Abs(str - 2);

            Console.WriteLine(n);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Красивая_матрица
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = new string[5];
            int one_x = 0, one_y = 0;
            for (int i = 0; i < 5; i++)
            {
                input[i] = Console.ReadLine();
                if (input[i].Contains("1"))
                {
                    one_x = i;
                    one_y = input[i].IndexOf("1") / 2;
                }
            }
            decimal answer = Math.Abs(Convert.ToDecimal(one_x - 2)) + Math.Abs(Convert.ToDecimal(one_y - 2));
            Console.WriteLine(answer);
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LearningCSharp
{
    class _263A
    {

        static void Main()
        {
            char[] ar = new char[1000];
            string temp = ""; int row = 0, col = 0;
            for (int i = 1; i < 6; i++)
            {

                temp = Console.ReadLine();

                if (temp.Contains('1')) {
                    row = i;
                    string [] t=temp.Split(' ');
                    for (int k = 0; k < t.Length; k++) { if (t[k] == "1") { col = k + 1; } }
                }
            }

            int moveR = Math.Abs(row - 3);
                int moveC = Math.Abs(col - 3);

                Console.WriteLine(moveC + moveR);
           // Console.ReadKey();

            }
        }

        }

using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] row1 = Console.ReadLine().Split();
            string[] row2 = Console.ReadLine().Split();
            string[] row3 = Console.ReadLine().Split();
            string[] row4 = Console.ReadLine().Split();
            string[] row5 = Console.ReadLine().Split();

            if(row1[0] == "1" || row1[4] == "1" || row5[0] == "1" || row5[4] == "1")
            {
                Console.WriteLine("4");
            }
            else if(row1[1] == "1" || row1[3] == "1" || row5[1] == "1" || row5[3] == "1" || row2[0] == "1" || row2[4] == "1" || row4[0] == "1" || row4[4] == "1"){
                Console.WriteLine("3");
            }
            else if(row1[2] == "1" || row2[1] == "1" || row2[3] == "1" || row4[1] == "1" || row4[3] == "1" || row5[2] == "1" || row5[3] == "1" || row3[0] == "1" || row3[4] == "1"){
                Console.WriteLine("2");
            }
            else if(row2[2] == "1" || row3[1] == "1" || row4[2] == "1" || row3[3] == "1"){
                Console.WriteLine("1");
            }
            else{
                Console.WriteLine("0");
            }
        }
    }
}

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

namespace CSharp_Shell
{

    public static class Program
    {
        public static void Main()
        {
            string[][] s = new string[5][];
            for(int i=0; i<5; i++)
            {
            	s[i]=Console.ReadLine().Split(' ');
            }
            int a=0, b=0;
            for(int i=0; i<5; i++)
            {
            	for(int j=0; j<5; j++)
            	{
            		if(s[i][j]!="0")
            		{
            			a=i;
            			b=j;
            			break;
            		}
            	}
            }
            a=a-2<0?2-a:a-2;
            b=b-2<0?2-b:b-2;
            Console.WriteLine(a+b);
            /*string s = Console.ReadLine().ToLower();
            string w = Console.ReadLine().ToLower();

            int a=0;
            for(int i=0; i<s.Length; i++)
            {
            	if(s[i]!=w[i])
            	{
            		a=((int)s[i]-(int)w[i])<0?-1:1;
            		break;
                }

            }
            Console.WriteLine(a);*/

        	/*int a = int.Parse(Console.ReadLine());
        	int x=0;
        	for(int i = 0; i<a; i++)
        	{
        		string s = Console.ReadLine();
        		char[] c = new char[]{s[0], s[1], s[2]};

        		if(s.) x++;
        		else x--;
        	}
        	Console.WriteLine(x);*/
        	/*string[] s = Console.ReadLine().Split(" ");
        	int m = int.Parse(s[0]);
        	int n = int.Parse(s[1]);

        	Console.WriteLine(m.Equals(n));*/
        	/*HashSet<char> a = new HashSet<char>(new char[]{'U', 'u', 'I', 'i', 'E', 'e', 'A', 'a', 'O', 'o', 'Y', 'y'});
            string w="";
            foreach(char c in s)
            {
            	if(!a.Contains(c))
            	{
            		w+=".";
            		w+=c.ToString();
            	}
            }
            s=w.ToLower();
            Console.WriteLine(s);*/
        /*	int[] z=Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        	int n=z[0];
        	int k=z[1];
        	int[] y=Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        	int i=k;
        	if(y[k-1]>0)
        	{
        	while(i<n&&y[k-1]==y[i])
        	{
        		i++;
        	}
        	}
        	else
        	{
        		i=0;
        		while (y[i]>0)
        		{
        			i++;
        		}
        	}*/
        	//Console.WriteLine(s2);
        	/*string s = Console.ReadLine();
        	int a = int.Parse(s);
        	string[] w = new string[a];
        	for (int i = 0; i<a; i++)
        	{
        		w[i] = Console.ReadLine();
        		int x = w[i].Length;
        		Console.WriteLine(x>10?(w[i][0].ToString()+(x-2).ToString()+w[i][x-1].ToString()):w[i]);
        	}*/

            /*HashSet<int> d = new HashSet<int>();
            d.Add(345);
            d.Add(34);
            d.Add(0);
            d.Add(34);*/
        	//byte a=(byte)d;
        	/*string a = Console.ReadLine();
        	int w = int.Parse(a);
        	Console.WriteLine(w%2==0?"YES":"NO");*/
        	/*a=int.Parse(Console.ReadLine());
        	b=int.Parse(Console.ReadLine());
        	c=int.Parse(Console.ReadLine());
        	int[] z=Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        	if (z[0]>z[1])
        	{
        		if(z[0]>z[2]) d=z[0];
        		else d=z[2];
        	}
        	else
        	{
        		if(z[1]>z[2]) d=z[1];
        	    else d=z[2];
        	}
           Console.WriteLine(d);*/
        }

    }
}

using System;

namespace Beautiful_Matrix
{
    class Program
    {
        static int numberOfBeautifulMoves(int row, int col)
        {
            int moves = 0;
            while(!(row == 2 && col == 2))
            {
                if(row > 2)
                {
                    row--;
                    moves++;
                }

                if (col > 2)
                {
                    col--;
                    moves++;
                }

                if (row < 2)
                {
                    row++;
                    moves++;
                }

                if (col < 2)
                {
                    col++;
                    moves++;
                }

            }
            return moves;
        }

        static void Main(string[] args)
        {
            int[,] matrix = new int[5, 5];
            string[] splitted = new string[5];
            int row = 0, col = 0;

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                splitted = Console.ReadLine().Split();
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    matrix[i, j] = Int32.Parse(splitted[j]);
                    if(matrix[i, j] == 1)
                    {
                        row = i;
                        col = j;
                    }

                }
            }

            Console.WriteLine(numberOfBeautifulMoves(row, col).ToString());

        }
    }
}

using System;
class Test{
    static void Main(){
        string [] line;
        for(int i = 0; i < 5; i++){
            line = Console.ReadLine().Split();
            for(int j = 0; j < 5; j++){
                if(line[j] != "0"){
                    Console.WriteLine(Math.Abs(i - 2) + Math.Abs(j - 2));
                    return;
                }
            }
        }
    }
}

using System;
using System.Collections.Generic;
class Program
    {
        static void Main()
        {
             int numberOfMovement = 0;
            for (int i = 0; i < 5; i++)
            {
                string[] rowInputs = Console.ReadLine().Split(' ');
                for (int j = 0; j < 5; j++)
                {
                    if (rowInputs[j] == "1")
                    {
                        numberOfMovement = Math.Abs(2-i)+ Math.Abs(2 - j);
                    }
                }
            }

            Console.WriteLine(numberOfMovement);
        }

    }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            int row = 0;
            int column = 0;
            int[,] arr = new int[5, 5];
            for (int i = 0; i < 10; i+=2)
            {
                string line = Console.ReadLine();
                for (int j = 0; j < 10; j += 2)
                {
                    arr[i/2, j/2] =Convert.ToInt16(line[j].ToString());
                    if (arr[i / 2, j / 2] == 1)
                    {
                        row = i / 2 +1;
                        column = j / 2+1;
                    }
                }
            }
            int sum = Math.Abs(3 - row) + Math.Abs(3 - column);
            Console.WriteLine(sum);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KrasivMatr
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] matr = new int[5, 5];
            int k=0;
            int l = 0;
            for (int i = 0; i < 5; i++)
            {
                string str = Console.ReadLine();
                if (str.Contains('1'))
                    for (int j = 0; j < str.Length; j+=2)
                    {
                        if (str[j]=='1')
                        {
                            matr[i, j / 2] = 1;
                            k = i;
                            l = j / 2;
                        }
                    }
            }
            k = Math.Abs(k - 3+1);
            l = Math.Abs(l - 3+1);
            Console.WriteLine(k + l);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = 0;
            var result = 0;
            int matrixCount = 5;
            var count = 0;
            for (int i = 1; i <= matrixCount; i++)
            {
                string[] matrix = Console.ReadLine().Split(' ');
                count++;
                for (int z = 1; z <= matrix.Length; z++)
                {
                    if (matrix[z - 1] == "1" && i < 3)
                    {
                        x = Math.Abs(z - 3);
                        result = x + (Math.Abs(count - 3));
                    }
                    else if (matrix[z - 1] == "1" && i > 3)
                    {
                        x = Math.Abs(z - 3);
                        result = x + (Math.Abs(count - 3));
                    }
                    else if (matrix[z - 1] == "1" && i == 3)
                    {
                        x = Math.Abs(z - 3);
                        result = x + (Math.Abs(count - i));
                    }
                }
            }
            Console.WriteLine(result);
        }
    }
}

using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

namespace Problem263A {
    class Program {
        static void Main(string[] args) {
            int[,] matrix = new int[5, 5];
            for (int i = 0; i < 5; i++) {
                string[] line = Console.ReadLine().Split(' ');
                saveLineToMatrix(matrix, line, i);
            }

            int[] one = findOne(matrix);
            int moves = Math.Abs(one[0] - 2) + Math.Abs(one[1] - 2);
            Console.WriteLine(moves);
        }

        private static int[] findOne(int[,] matrix) {
            int[] position = new int[2];
            bool foundPosition = false;

            for (int i = 0; i < 5; i++) {
                for (int j = 0; j < 5; j++) {
                    if (matrix[i, j] == 1) {
                        position[0] = i;
                        position[1] = j;
                        foundPosition = true;
                        break;
                    }
                }
                if (foundPosition)
                    break;
            }

            return position;
        }

        private static void saveLineToMatrix(int[,] matrix, string[] line, int row) {
            for (int i = 0; i < 5; i++) {
                int elem = Convert.ToInt32(line[i]);
                matrix[row, i] = elem;
            }
        }
    }
}

using System;

namespace BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            char[,] Array = new char [5, 5];
            int count = 0;int rowindex = 0;
            int colindex = 0;

            for (int i=0;i<=4;i++)
            {
                rowindex = i;
                string value = Console.ReadLine();
                if(value.Contains("1"))
                {
                    //Console.WriteLine(value.IndexOf('1'));
                    colindex = value.IndexOf('1') / 2 ;
                    break;
                }

            }

          //  Console.WriteLine(2-rowindex/2+1+2-colindex);
            Console.WriteLine(Math.Abs(rowindex-2)+ Math.Abs(colindex-2));

        }
    }
}

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace CodeForces
{
    class Program
    {

        [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int scanf(string format, out int a, out int b, out int c, out int d, out int e);
        static void Main(string[] args)
        {
            int answer = 0;
            int[,] array = new int[5, 5];
            for (int i = 0; i<5;i++)
            {
                scanf("%d %d %d %d %d", out array[i, 0], out array[i, 1], out array[i, 2], out array[i, 3], out array[i, 4]);
                for (int j = 0; j<5; j++)
                {
                    if (array[i, j] == 1)
                        answer = Math.Abs(2 - j) + Math.Abs(2 - i);
                }
            }
            Console.WriteLine(answer);
        }
    }
}

using System;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            //Get one position.
            int oneX = 0;
            int oneY = 0;
            for (int i = 0; i < 5; i++)
            {
                int[] values = Array.ConvertAll(Console.ReadLine().Split(' '), input => int.Parse(input));
                for (int j = 0; j < 5; j++)
                {
                    if (values[j] == 1)
                    {
                        oneX = i;
                        oneY = j;
                    }
                }
            }

            //Get road to middle.
            int X = Math.Abs(oneX - 2);
            int Y = Math.Abs(oneY - 2);

            Console.WriteLine(X + Y);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            var res = 0;
            var liste = new List<int>();

            for (var i = 1; i <= 5; i++)
            {
                var array = Console.ReadLine().Trim().Split(' ');
                liste.Clear();

                foreach (var q in array) { liste.Add(int.Parse(q)); }

                if (liste.Contains(1))
                {
                    res += Math.Abs(i - 3);
                    res += Math.Abs(2 - liste.IndexOf(1));
                }
            }

            Console.WriteLine(res);
            Console.ReadLine();
        }
    }
}

using System;

public class Program
{

    public static void Main()
	{
	    int result = 0;
	    for(int i = 0; i < 5; i++)
	    {
	        string s = Console.ReadLine();
	        if(s.Contains("1"))
	        {
	            if((i - 2) < 0)
	            {
	                result = (i - 2) * (-1);
	            }
	            else
	            {
	                result = i - 2;
	            }
	            int[] array = Array.ConvertAll(s.Split(' '), int.Parse);
	            for(int j = 0; j < array.Length; j++)
	            {
	                if(array[j] == 1)
	                {
	                    if((j - 2) < 0)
	                    {
	                        result = result + (j - 2) * (-1);
	                    }
	                    else
	                    {
	                        result = result + (j - 2);
	                    }
	                }
	            }
	        }
	    }

	    Console.WriteLine(result);
	}
}

using System;

namespace _263A_BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] task = new string[25];
            int position = 1;

            for (int i = 0; i < 5; i++)
            {
                var mass = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                for (int j = i*5, k = 0; j < 25 & k<5; j++, k++)
                {
                task[j] = mass[k];
                }
             }

            for (int i =0; i < 25; i++)
            {
                if (task[i] == "0")
                {
                    position += 1;
                }
                else
                    break;
            }

            double caseNum = Math.Ceiling(position / 5.0);
            int caseMod = position % 5;
            if (caseMod == 0)
            {
                caseMod = 5;
            }

            if(caseMod == 3)
            {
                Console.WriteLine(Math.Abs(caseNum - caseMod));

            }
            else
            {
                caseNum = Math.Abs(caseNum - 3) + Math.Abs(caseMod - 3);
                Console.WriteLine(caseNum);
            }
        }
    }
}

using System;
class CFR161D2
{
    static void Main()
    {
        string[] line;
        for (int i = 0; i < 5; i++)
        {
            line = Console.ReadLine().Split(' ');
            for (int j = 0; j < 5; j++)
            {
                if (line[j] == "1")
                {
                    Console.WriteLine(Math.Abs(2-i) + Math.Abs(2-j));
                    return;
                }
            }
        }
        Console.WriteLine(0);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp_project
{
    class Program
    {
        static void Main(string[] args)
        {

            var arr = new int[5, 5];
            int z = 0, y = 0;

                for (int i = 0; i < 5; i++)
                {// 1 0 1 1 1 1 0 0

                    var x = Console.ReadLine().Split();

                    arr[i,0] = Convert.ToInt32(x[0]);
                    arr[i,1] = Convert.ToInt32(x[1]);
                    arr[i,2] = Convert.ToInt32(x[2]);
                    arr[i,3] = Convert.ToInt32(x[3]);
                    arr[i,4] = Convert.ToInt32(x[4]);
                    if (arr[i, 0] ==1)
                    { z = 0;
                      y = i;
                    }
                    if (arr[i, 1] == 1)
                    {
                        z = 1;
                        y = i;
                    break;
                    }
                    if (arr[i, 2] == 1)
                    {
                        z = 2;
                        y = i;
                    break;
                }
                    if (arr[i, 3] == 1)
                    {
                        z = 3;
                        y = i;
                    break;
                }
                    if (arr[i, 4] == 1)
                    {
                        z = 4;
                        y = i;
                    break;
                }

                }

            var ans = Math.Abs(2 - z)+Math.Abs(2-y);

            Console.WriteLine(ans);
        }
    }
}

using System;

namespace CF263A
{
    class Program
    {
        static void Main()
        {
            var j = 0;
            int i;
            for (i = 0; i < 5; i++)
            {
                j = Console.ReadLine().IndexOf("1");
                if (j <= -1) continue;

                j /= 2;
                break;
            }
            var value1 = 2 - i;
            if (value1 < 0)
            {
                value1 *= -1;
            }
            var value2 = 2 - j;
            if (value2 < 0)
            {
                value2 *= -1;
            }
            Console.WriteLine(value1 + value2);
        }
    }
}

using System;
using System.Data;
using System.Runtime.InteropServices;

namespace Coding
{
    class Program
    {
        static void Main(string[] args)
        {

            int[,] arr = new int[5, 5];
            int moves = 0;
            int row = 0;
            int col = 0;
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                string line = Console.ReadLine();

                string[] nums = line.Split(" ");

                if (line.Contains("1"))
                {
                    row = i;
                }

                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    arr[i, j] = Convert.ToInt32(nums[j]);
                    if (arr[i, j] == 1)
                    {
                        col = j;
                    }
                }
            }

            //row swap
            moves += Math.Abs(2 - row);

            //col swap
            moves += Math.Abs(2 - col);

            Console.Write(moves);

        }
    }
}

using System;

namespace Matriza
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] p = "".Split();
            int str = 0;
            int stol = 0;
            for (int i = 0; i < 5; i++)
            {
                string  k = Console.ReadLine();
                if (k != "0 0 0 0 0")
                {
                    string [] z = k.Split();
                    p = z;
                    str = i + 1;
                }
            }
            for (int u = 0; u < p.Length; u++)
            {
                if (p[u] == "1")
                {
                    stol = u + 1;
                }
            }
            int a = 3 - str;
            int b = 3 - stol;
            if (a < 0)
            {
                a = a - 2 * a;
            }
            if (b < 0)
            {
                b = b - b * 2;
            }
            int S = a + b;
            Console.WriteLine(S);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tests
{
    class Program
    {
        static void Main(string[] args)
        {
            string a1 = Console.ReadLine();
            string a2 = Console.ReadLine();
            string a3 = Console.ReadLine();
            string a4 = Console.ReadLine();
            string a5 = Console.ReadLine();
            string[] A1 = a1.Split(' ');
            string[] A2 = a2.Split(' ');
            string[] A3 = a3.Split(' ');
            string[] A4 = a4.Split(' ');
            string[] A5 = a5.Split(' ');
            string[,] B = new string[5, 5] {
                { A1[0],A1[1],A1[2],A1[3],A1[4]},
                { A2[0],A2[1],A2[2],A2[3],A2[4]},
                { A3[0],A3[1],A3[2],A3[3],A3[4]},
                { A4[0],A4[1],A4[2],A4[3],A4[4]},
                { A5[0],A5[1],A5[2],A5[3],A5[4]},
            };
            int x = 0, y = 0;
            for (int i = 0; i < B.GetLength(0); i++)
            {
                for (int j = 0; j < B.GetLength(1); j++)
                {
                    if (B[i, j] == "1")
                    {
                        x = i + 1;
                        y = j + 1;
                        break;
                    }
                }
            }
            int Q = Math.Abs(x - 3) + Math.Abs(y - 3);
            Console.WriteLine(Q);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

           int[,] arr = new int[5,5];
           int a1 = 0;
           int a2 = 0;

           for (int i = 0; i < 5; i++)
           {
               string str = Console.ReadLine();
               string []strArr = str.Split(' ');

               for (int j = 0; j < strArr.Length; j++)
               {
                   arr[i, j] = int.Parse( strArr[j]);

                   if (arr[i, j] == 1)
                   {
                       a1 = i;
                       a2 = j;
                   }
               }

           }
            int res=0;
            if(a1==2 && a2==2 )
            {
                Console.WriteLine(res);
            }
            else
            {
                if (a1 < 2)
                {
                    while (a1 < 2)
                    {
                        res += 1;
                        a1++;
                    }
                }
                else
                {
                    while (a1 > 2)
                    {
                        res += 1;
                        a1--;
                    }
                }

                if (a2 < 2)
                {
                    while (a2 < 2)
                    {
                        res += 1;
                        a2++;
                    }
                }
                else
                {
                    while (a2 > 2)
                    {
                        res += 1;
                        a2--;
                    }
                }

                Console.WriteLine(res);
           }

        }
    }
}

using System;
using System.Globalization;

namespace algorithms_700_01
{
    class Program
    {
        static void Main(string[] args)
        {
            var grid = Parse();
            var minimumShifts = Solve(grid);
            Print(minimumShifts);
        }

        private static void Print(int minimumShifts)
        {
            Console.WriteLine(minimumShifts);
        }

        private static int Solve(int[,] grid)
        {
            int x = 0, y = 0;
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (grid[i, j] == 1)
                    {
                        x = i;
                        y = j;
                    }
                }
            }
            return Math.Abs(x - 2) + Math.Abs(y - 2);
        }

        private static int[,] Parse()
        {
            var grid = new int[5, 5];
            for (int i = 0; i < 5; i++)
            {
                var input = Console.ReadLine();
                for (int j = 0; j < 5; j++)
                    grid[i, j] = int.Parse(input.Substring(2 * j, 1));
            }
            return grid;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemSolvingProject
{
    class BeautifulMatrix
    {
        public static void Main(string[] args)
        {
            int[,] arr = new int[5, 5];
            int r = 0;
            int c = 0;
            for(int i = 0; i < 5; i++)
            {
                string s = Console.ReadLine();
                var x = s.Split(' ');
                for(int j = 0; j < 5; j++)
                {
                    arr[i, j] = int.Parse(x[j]);
                    if(arr[i,j] == 1)
                    {
                        r = i+1;
                        c = j+1;
                    }
                }
            }
            int move = 0;
            move += Math.Abs(3 - r);
            move += Math.Abs(3 - c);
            Console.WriteLine(move);
           Console.ReadLine();
        }
    }
}

using System;
using System.IO;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main(string[] args)
		{
			for (int i = 1; i <= 5; i++)
			{
				string[] s = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
				for (int j = 1; j <= 5; j++)
				{
					if (s[j - 1] == "1")
					{
						Console.WriteLine(Math.Abs(i - 3) + Math.Abs(j - 3));
					}
				}
			}
		}
	}
}

using System;

namespace vanyanandfence
{
    class Program
    {
        static void Main(string[] args)
        {

            var input = new int[5, 5];
            for (int i = 0; i < 5; i++)
            {
                var line = Console.ReadLine().Split(' ');
                for (int k = 0; k < line.Length; k++)
                {
                    input[i, k] = int.Parse(line[k]);
                }
            }
            int row = 0, col = 0;
            for (int i = 0; i < 5; i++)
            {
                for (int k = 0; k < 5; k++)
                {
                    if (input[i, k] == 1)
                    {
                        row=i;
                        col=k;
                        break;
                    }
                }
            }
            var ymove =Math.Abs(row-2) ;
            var xmove = Math.Abs(col-2);
            System.Console.WriteLine(ymove+xmove);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LearningCSharp
{
    class _263A
    {

        static void Main()
        {
            char[] ar = new char[1000];
            string temp = ""; int row = 0, col = 0;
            for (int i = 1; i < 6; i++)
            {

                temp = Console.ReadLine();

                if (temp.Contains('1')) {
                    row = i;
                    string [] t=temp.Split(' ');
                    for (int k = 0; k < t.Length; k++) { if (t[k] == "1") { col = k + 1; } }
                }
            }

            int moveR = Math.Abs(row - 3);
                int moveC = Math.Abs(col - 3);

                Console.WriteLine(moveC + moveR);
           // Console.ReadKey();

            }
        }

        }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PS
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            string[] strArr;
            int x = 0 , y = 0 ;
            for (int i = 0; i < 5; ++i)
            {
               str = Console.ReadLine();
               strArr = str.Split(' ');
               for (int j = 0; j < 5; ++j)
                   if (strArr[j] == "1")
                   {
                       x= i;
                       y= j;
                   }
            }
            Console.WriteLine(Math.Abs(2 - x)+ Math.Abs(2 - y));

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Numerics;

namespace WarmingUpC_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0, j = 0, ans = 0;
            for (int k = 0; k < 5; k++)
            {
                string[] arr = Console.ReadLine().Split(' ');
                j = IndexOf(arr);
                if (j != -1)
                {
                    i = k >= 2 ? k - 2 : 2 - k;
                    j = j >= 2 ? j - 2 : 2 - j;
                    ans = i + j;
                }
            }
            Console.WriteLine(ans);
        }
        public static int IndexOf(string[] arr)
        {
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] == "1")
                    return i;
            }
            return -1;
        }
    }
}

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            String a;
            int output=0;
            for (int x = 0; x < 5; x++)
            {
                 a = Console.ReadLine();
                 string[] words = a.Split(' ');
                 for (int y = 0; y < 5; y++)
                 {
                     if (words[y] == "1")
                     {
                         output = Math.Abs(x - 2) + Math.Abs(y - 2);
                     }
                 }
            }

            Console.WriteLine(output);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            int row = 0;
            int column = 0;
            int[,] arr = new int[5, 5];
            for (int i = 0; i < 10; i+=2)
            {
                string line = Console.ReadLine();
                for (int j = 0; j < 10; j += 2)
                {
                    arr[i/2, j/2] =Convert.ToInt16(line[j].ToString());
                    if (arr[i / 2, j / 2] == 1)
                    {
                        row = i / 2 +1;
                        column = j / 2+1;
                    }
                }
            }
            int sum = Math.Abs(3 - row) + Math.Abs(3 - column);
            Console.WriteLine(sum);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

public static class Beautiful_Matrix
{
    private static void Solve()
    {
        int[][] matrix = ReadIntMatrix(5);

        int row = 0;
        int col = 0;
        bool found = false;

        for (int i = 0; i < matrix.Length && !found; i++)
        {
            for (int j = 0; j < matrix[i].Length && !found; j++)
            {
                if (matrix[i][j] == 1)
                {
                    row = i;
                    col = j;
                    found = true;
                }
            }
        }

        // center is 2, 2
        int absYMov = Math.Abs(row - 2);
        int absXMov = Math.Abs(col - 2);
        Write(absYMov + absXMov);
    }

    #region Main

    private static TextReader reader;
    private static TextWriter writer;
    public static void Main()
    {
#if DEBUG
        //reader = new StreamReader("C:\\Users\\Axel\\Desktop\\input.txt");
        reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            Solve();
            //var thread = new Thread(new Beautiful_Matrix().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string Read() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}

using System;

namespace vanyanandfence
{
    class Program
    {
        static void Main(string[] args)
        {

            var input = new int[5, 5];
            for (int i = 0; i < 5; i++)
            {
                var line = Console.ReadLine().Split(' ');
                for (int k = 0; k < line.Length; k++)
                {
                    input[i, k] = int.Parse(line[k]);
                }
            }
            int row = 0, col = 0;
            for (int i = 0; i < input.GetLength(0); i++)
            {
                for (int k = 0; k < input.GetLength(1); k++)
                {
                    if (input[i, k] == 1)
                    {
                        row=i;
                        col=k;
                        break;
                    }
                }
            }
            var ymove =Math.Abs(row-2) ;
            var xmove = Math.Abs(col-2);
            System.Console.WriteLine(ymove+xmove);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemSolving
{
    class Program
    {
        public static void Main(string[] args)
        {
            int rowNumber = 0,ColNumber = 0;
            string[] row;
            for (int i = 1; i <= 5; i++)
            {
                row = Console.ReadLine().Split();
                for (int j = 1; j <= 5; j++)
                {
                    if(row[j-1] == "1")
                    {
                        rowNumber = i;
                        ColNumber = j;
                    }
                }
            }
            Console.WriteLine(Math.Abs(ColNumber - 3) + Math.Abs(rowNumber - 3));
        }
    }
}

using System;

class program
{
    static void Main(string[]args)
    {
        int[,] Matrix = new int[5, 5];
            int rowNumber = 0;
            int columnNumber = 0;
            int rowSwaps = 0;
            int columnSwaps = 0;
            for (int i = 0; i < 5; i++)
            {
                string input = Console.ReadLine();
                string[] inputs = input.Split(' ');
                for (int j = 0; j < 5; j++)
                {
                    Matrix[i, j] = Convert.ToInt32(inputs[j]);
                }
            }

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (Matrix[i, j] == 1)
                    {
                        rowNumber = i;
                        columnNumber = j;
                    }
                }
            }

            if (rowNumber == 2)
                rowSwaps = 0;
            else
            {
                while (rowNumber > 2)
                {
                    rowNumber--;
                    rowSwaps++;
                }

                while (rowNumber < 2)
                {
                    rowNumber++;
                    rowSwaps++;
                }
            }

            if (columnNumber == 2)
                columnSwaps = 0;
            else
            {
                while (columnNumber > 2)
                {
                    columnNumber--;
                    columnSwaps++;
                }

                while (columnNumber < 2)
                {
                    columnNumber++;
                    rowSwaps++;
                }
            }

            Console.WriteLine(rowSwaps+columnSwaps);
    }
}

using System;
using System.IO;
using System.Linq;
namespace codechef
{
    public class Program{
            public static StreamWriter writer;

            public static void RealWork()
            {
                int ans = 0;
                int[,] m = new int[6,6];
                string pos="";
                for (int i = 1; i <6 ; i++)
                {
                    int[] val = Console.ReadLine().Split().Select(intParse).ToArray();
                    for (int j = 1; j < 6; j++)
                    {
                        if (val[j - 1] == 1)
                        { pos = "" + i + j;  }
                        m[i,j] = val[j - 1];
                    }
                }

                writer.Write(Math.Abs(3 - intParse(pos[0].ToString()))+Math.Abs(3 - intParse(pos[1].ToString())));
            }

            static void Main(string[] args)
            {
                writer = new StreamWriter(Console.OpenStandardOutput());
               //writer = new StreamWriter("output.txt");
               //Console.SetIn(new StreamReader(File.OpenRead("input.txt")));
                RealWork();
                writer.Close();
            }

            public static int intParse(string st)
            {
                int x = 0;
                for (int i = 0; i < st.Length; i++) { x = x * 10 + (st[i] - 48); }
                return x;
            }

    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingContests
{
    class Program
    {
        static void Main(string[] args)
        {
             int a = 0;
             int b = 0;

            var line = new string[5];
            var matrix = new int[5, 5];
            for (int i = 0; i < 5; i++)
            {
                line = Console.ReadLine().Split(' ').ToArray();
                for (int j = 0; j < 5; j++)
                {
                    matrix[i, j] = int.Parse(line[j]);
                    if (matrix[i, j] == 1)
                    {
                        a = i + 1;
                        b = j + 1;
                        break;
                    }
                }
                if (a != 0 && b != 0)
                    break;
            }

            Console.WriteLine(Math.Abs(a - 3) + Math.Abs(b - 3));
        }
    }
}

using System;

namespace Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {

            int y = -2;
            int x = 10;
            bool set = false;

            for (int i = 0; i < 5; i++)
            {
                if (set)
                {
                    Console.ReadLine();
                }
                else
                {

                    string input = Console.ReadLine();
                    input = input[0].ToString() + input[2].ToString() + input[4].ToString() + input[6].ToString() + input[8].ToString();
                    if (input.Contains("1"))
                    {

                        x = input.IndexOf('1')-2;
                        set = true;
                    }
                    else
                    {
                        y++;
                    }

                }
            }

            Console.WriteLine(Math.Abs(x) + Math.Abs(y));
            Console.ReadLine();

        }
    }
}

using System;

namespace CodeForce1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] matrix = new string[5];
            for (int i = 0; i < 5; i++)
            {
                matrix[i] = Console.ReadLine();
            }
            int[,] array = new int[matrix.Length, matrix.Length];
            int counter = 0;
            for (int i = 0; i < matrix.Length; i++)
            {
                counter = 0;
                for (int j = 0; j < matrix[i].Length; j += 2)
                {
                    array[i, counter] = int.Parse(matrix[i][j].ToString());
                    counter++;
                }
            }
            int coorI = 0;
            int coorJ = 0;
            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    if (array[i, j] == 1)
                    {
                        coorI = i;
                        coorJ = j;
                        break;
                    }
                }
            }

            counter = 0;
            bool flag = false;
            if (coorI == 2 && coorJ == 2)
            {
                flag = true;
                Console.WriteLine(0);
            }
            else
            {
                while (coorI != 2)
                    if (coorI > 2)
                    {
                        coorI--;
                        counter++;
                    }
                    else if (coorI < 2)
                    {
                        coorI++;
                        counter++;
                    }

                while (coorJ != 2)
                    if (coorJ > 2)
                    {
                        coorJ--;
                        counter++;
                    }
                    else if (coorJ < 2)
                    {
                        coorJ++;
                        counter++;
                    }
            }
            if (!flag)
            {
                Console.WriteLine(counter);
            }
            Console.Read();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static int[] ReadInt(int size)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] res = new int[size];
            for (int i=0; i<input.Length; i++)
            {
                res[i] = Convert.ToInt32(input[i]);
            }
            return res;
        }

        static int ReadInt()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            return n;
        }

        static String ReadString()
        {
            return Console.ReadLine();
        }

        static int Max(int a, int b)
        {
            return (a > b ? a : b);
        }

        static void WL<T> (T s)
        {
            Console.WriteLine(s);
        }

        static bool isLucky(int n)
        {
            String temp = n.ToString();
            char[] charArray = { '0', '1', '2', '3', '5', '6', '8', '9' };
            return !(temp.IndexOfAny(charArray) > -1);
        }

        static int GCD(int a, int b)
        {
            if (a < b)
            {
                int temp = a;
                a = b;
                b = temp;
            }
            while (b > 0)
            {
                if (a > b) a -= b;
                else b -= a;
            }
            return a;
        }

        static void Main(string[] args)
        {
            int row = 0, column = 0;
            for (int i = 1; i <= 5; i++)
            {
                String[] input = Console.ReadLine().Split(' ');
                for (int j = 1; j <= 5; j++)
                {
                    if (input[j-1] == "1")
                    {
                        row = i;
                        column = j;
                        break;
                    }
                }
            }
            WL(Math.Abs(row - 3) + Math.Abs(column - 3));
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = 0;
            var result = 0;
            int matrixCount = 5;
            var count = 0;
            for (int i = 1; i <= matrixCount; i++)
            {
                string[] matrix = Console.ReadLine().Split(' ');
                count++;
                for (int z = 1; z <= matrix.Length; z++)
                {
                    if (matrix[z - 1] == "1")
                    {
                        x = Math.Abs(z - 3);
                        result = x + (Math.Abs(count - 3));
                    }
                    //else if (matrix[z - 1] == "1" && i > 3)
                    //{
                    //    x = Math.Abs(z - 3);
                    //    result = x + (Math.Abs(count - 3));
                    //}
                    //else if (matrix[z - 1] == "1" && i == 3)
                    //{
                    //    x = Math.Abs(z - 3);
                    //    result = x + (Math.Abs(count - i));
                    //}

                }
            }
            Console.WriteLine(result);
        }
    }
}

    using System;
    using System.Linq;

    namespace CodeWars
    {
        class _263A
        {
            static void Main()
            {
                var input = new int[5][];
                var position = new Tuple<int, int>(0,0);
                for (int i = 0; i < 5; i++)
                {
                    input[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    var index = Array.IndexOf(input[i],1);
                    if (index != -1)
                        position = new Tuple<int, int>(index, i);
                }
                Console.WriteLine(Math.Abs(2 - position.Item1) + Math.Abs(2 - position.Item2));
            }
        }
    }

using System;

public class Program
{

    public static void Main()
	{
	    int result = 0;
	    for(int i = 0; i < 5; i++)
	    {
	        string s = Console.ReadLine();
	        if(s.Contains("1"))
	        {
	            if((i - 2) < 0)
	            {
	                result = (i - 2) * (-1);
	            }
	            else
	            {
	                result = i - 2;
	            }
	            int[] array = Array.ConvertAll(s.Split(' '), int.Parse);
	            for(int j = 0; j < array.Length; j++)
	            {
	                if(array[j] == 1)
	                {
	                    if((j - 2) < 0)
	                    {
	                        result = result + (j - 2) * (-1);
	                    }
	                    else
	                    {
	                        result = result + (j - 2);
	                    }
	                }
	            }
	        }
	    }

	    Console.WriteLine(result);
	}
}

using System;
namespace C_
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] positions = new int[5,5]
            {
                {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}
            };
            int value = 0;
            bool check = false;
            for(int i = 0; i < 5;i++)
            {
                string[] temp = Console.ReadLine().Trim().Split();
                for(int j = 0; j < temp.Length;j++)
                {
                    if(temp[j] == "1")
                    {
                        value = positions[i,j];
                        check = true;
                        break;
                    }
                }
                if(check == true)
                {
                    break;
                }

            }
            Console.WriteLine(value);
        }
    }
}

using System;

namespace _263A_A_Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i=1; i<=5; i++)
            {
                string s1 = Console.ReadLine();
                string[] s1values = s1.Split(' ');

                for (int j=1; j<=5; j++)
                {
                    int x = int.Parse(s1values[j-1]);
                    if (x==1)
                    {
                        Console.Write(Math.Abs(i-3)+ Math.Abs(j - 3));
                    }
                }
            }
        }
    }
}

 using System;
 using static System.Console;
 using static System.Convert;
 class Program_8
    {
        public static void Main()
        {
            string [] arr = new string[5];

            int index_coulmn = 0 , index_rows = 0;

            for (int i = 0; i < 5; i++)
            {
                arr[i] = ReadLine();
            }

            for (int i = 0; i < 5; i++)
            {
                if(arr[i].Contains('1'))
                {
                    index_coulmn = arr[i].IndexOf('1') >0 ? arr[i].IndexOf('1')-(arr[i].IndexOf('1') /2 ) : arr[i].IndexOf('1');
                    index_rows = i;
                    break;
                }
            }

            Result(index_rows,index_coulmn);

        }
        static int count = 0;
        public static void Result(int i, int j)
        {

            if(i==2 && j==2)
            {
                Console.WriteLine(count);
                return;
            }

            else if(i>2||i<2)
            {
                i = (i > 2) ? i - 1 : i + 1;
                count++;
                Result(i,j);
            }

            else if(j>2||j<2)
            {
                j = (j > 2) ? j - 1 : j + 1;
                count++;
                Result(i,j);
            }

        }

    }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            int row = -1, col = -1;//row and column of 1 in the matrix

            //enter a 5x5 matrix with 24 zeros
            int[,] mat = new int[5, 5];
            for (int i = 0; i < 5; i++)
            {
                string[] inputRow = Console.ReadLine().Split();
                for (int j = 0; j < 5; j++)
                {
                    mat[i, j] = int.Parse(inputRow[j]);

                    //set the row and column value of 1
                    if (mat[i, j] == 1)
                    {
                        row = i;
                        col = j;
                    }
                }
            }

            //logic to count the minimum no. of moves to bring 1 to the position (2, 2)
            int count = Math.Abs(2 - row) + Math.Abs(2 - col);

            Console.WriteLine(count);//display output
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _263A
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
            int[,] matr = new int[5, 5];
            for (int i = 0; i < 5; i++)
            {
                s = Console.ReadLine();
                string[] temp = s.Split(' ');
                for (int j = 0; j < 5; j++)
                    matr[i, j] = int.Parse(temp[j]);
            }

            for(int i = 0; i < 5; ++i)
            {
                for(int j = 0; j < 5; ++j)
                {
                    int x = i + 1; int y = j + 1;
                    if(matr[i, j] == 1)
                    {
                        Console.WriteLine(Math.Abs(3 - x) + Math.Abs(3 - y));
                    }
                }
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _263A_A_Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i=1; i<=5; i++)
            {
                string s1 = Console.ReadLine();
                string[] s1values = s1.Split(' ');

                for (int j=1; j<=5; j++)
                {
                    int x = int.Parse(s1values[j-1]);
                    if (x==1)
                    {
                        Console.Write(Math.Abs(i-3)+ Math.Abs(j - 3));
                    }
                }
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KrasivMatr
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] matr = new int[5, 5];
            int k=0;
            int l = 0;
            for (int i = 0; i < 5; i++)
            {
                string str = Console.ReadLine();
                if (str.Contains('1'))
                    for (int j = 0; j < str.Length; j+=2)
                    {
                        if (str[j]=='1')
                        {
                            matr[i, j / 2] = 1;
                            k = i;
                            l = j / 2;
                        }
                    }
            }
            k = Math.Abs(k - 3+1);
            l = Math.Abs(l - 3+1);
            Console.WriteLine(k + l);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int row,column = 0;

            for (row = 1; row <= 5; row++)
            {
                var numbersArray = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

                var index = numbersArray.IndexOf(1);

                if (index != -1)
                {
                    column = index + 1;
                    break;
                }

            }

            Console.WriteLine(Math.Abs(3-row) + Math.Abs(3-column));
        }
    }
}

using System;

namespace _10__A._Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] arr = new int[5, 5];

            int count = 0;
            int i_ = 0;
            int j_ = 0;

            for (int i = 0; i < 5; i++)
            {

                string s = Console.ReadLine();
                string[] values = s.Split(' ');
                for (int j = 0; j < 5; j++)
                {

                arr[i, j] = int.Parse(values[j]);
                }
                Console.WriteLine();
            }

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (arr[i, j] == 1)
                    {
                        i_ = i;
                        j_ = j;
                    }
                }

            }

            int ans1 = Math.Abs(2-i_);
            int ans2 = Math.Abs(2-j_);

            Console.WriteLine(ans1+ans2);

        }
    }
}

using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[,] arr = new int[5, 5];
        int x = 0, y = 0;

        for (int i = 0; i < 5; i++)
        {
            string str = Console.ReadLine();
            for (int j = 0; j < 5; j++)
            {
                int[] intArr = str.Split(' ').Select(int.Parse).ToArray();
                arr[i, j] = intArr[j];
                if (intArr[j] == 1) { x = i;  y = j; }
            }
        }

        int xD;
        int yD;

        if (x > 2) { xD = x - 2; }
        else { xD = 2 - x; }

        if (y > 2) { yD = y - 2; }
        else { yD = 2 - y; }
        Console.WriteLine(yD + xD);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PS
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            string[] strArr;
            int x = 0 , y = 0 ;
            for (int i = 0; i < 5; ++i)
            {
               str = Console.ReadLine();
               strArr = str.Split(' ');
               for (int j = 0; j < 5; ++j)
                   if (strArr[j] == "1")
                   {
                       x= i;
                       y= j;
                   }
            }
            Console.WriteLine(Math.Abs(2 - x)+ Math.Abs(2 - y));

        }
    }
}

using System;
using System.Collections.Generic;
class Program
    {
        static void Main()
        {
             int numberOfMovement = 0;
            for (int i = 0; i < 5; i++)
            {
                string[] rowInputs = Console.ReadLine().Split(' ');
                for (int j = 0; j < 5; j++)
                {
                    if (rowInputs[j] == "1")
                    {
                        numberOfMovement = Math.Abs(2-i)+ Math.Abs(2 - j);
                    }
                }
            }

            Console.WriteLine(numberOfMovement);
        }

    }

using System;
using System.Linq;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            var rowNo = 1;
            while (!String.IsNullOrWhiteSpace(line = Console.ReadLine()))
            {
                if (!line.Contains("1"))
                {
                    rowNo++;
                    line = string.Empty;
                    continue;
                }

                var columnNo = Array.FindIndex(line.Split(" "), row => row == "1") + 1;
                var xMoves = Math.Abs(columnNo - 3);
                var yMoves = Math.Abs(rowNo - 3);

                Console.WriteLine(xMoves + yMoves);
                break;
            }
        }

        static void ReadLines()
        {
            string line;
            while (!String.IsNullOrWhiteSpace(line = Console.ReadLine()))
            {
                //but here it seems to be an infinite loop
            }
        }
    }
}

using System;
using System.Linq;

namespace CodeForce
{
    class Program
    {
        static void Check(int value, ref int counter)
        {
            if (value > 3)
            {
                while (value > 3)
                {
                    value--;
                    counter++;
                }
            }

            else if (value < 3)
            {
                while (value < 3)
                {
                    value++;
                    counter++;
                }
            }
        }
        static void Main(string[] args)
        {
            int[][] matrix = new int[5][];
            for (int i = 0; i < matrix.Length; i++)
                matrix[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int raw = 0, column = 0;
            int counter = 0;

            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < matrix[i].Length; j++)
                {
                    if (matrix[i][j] == 1)
                    {
                        raw = i+1;
                        column = j+1;
                        break;
                    }

                }
            }

            Check(raw, ref counter);
            Check(column, ref counter);

            Console.WriteLine(counter);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int row = 0;
            int count = 0;
            for (int i = 0; i < 5; i++)
            {
                string n = Console.ReadLine();
                if (n.Contains("1"))
                {
                    count = Math.Abs(2 - row) + Math.Abs(2 - n.Split().ToList().IndexOf("1"));
                }
                row++;
            }
            Console.WriteLine(count);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        public static int GhadreMotlagh(int r)
        {
            int h = 0;
            if (r < 0)
            {
                h = r - r - r;
            }
            else
            {
                h = r;
            }
            return h;
        }

        static void Main(string[] args)
        {
            int Temp1 = 0;
            int Temp2 = 0;
            int a = 0;
            int b = 0;
            int c = 0;
            string[,] Matrix = new string[5, 5];
            string[] Table= new string[5];
            Table[0] = Console.ReadLine();
            Table[1] = Console.ReadLine();
            Table[2] = Console.ReadLine();
            Table[3] = Console.ReadLine();
            Table[4] = Console.ReadLine();
            //f = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e;
            while (Temp1 < 5)
            {
                while (Temp2 < 5)
                {
                    Matrix[Temp1, Temp2] = Table[Temp1].Split(' ')[Temp2];
                    if (Matrix[Temp1, Temp2] == "1")
                    {
                        a = Temp1+1;
                        b = Temp2+1;
                    }
                    if (Temp2 == 4)
                    {
                        Temp2 = 0;
                        break;
                    }
                    else
                    {
                        Temp2 += 1;
                    }
                }
                Temp1 += 1;
            }

            c = GhadreMotlagh(3 - a) + GhadreMotlagh(3 - b);
            Console.WriteLine(c.ToString());
        }
    }
}

using System;

namespace BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            char[,] Array = new char [5, 5];
            int count = 0;int rowindex = 0;
            int colindex = 0;

            for (int i=0;i<=4;i++)
            {
                rowindex = i;
                string value = Console.ReadLine();
                if(value.Contains("1"))
                {
                    //Console.WriteLine(value.IndexOf('1'));
                    colindex = value.IndexOf('1') / 2 ;
                    break;
                }

            }

          //  Console.WriteLine(2-rowindex/2+1+2-colindex);
            Console.WriteLine(Math.Abs(rowindex-2)+ Math.Abs(colindex-2));

        }
    }
}

using System;

namespace vanyanandfence
{
    class Program
    {
        static void Main(string[] args)
        {

            var input = new int[5, 5];
            for (int i = 0; i < 5; i++)
            {
                var line = Console.ReadLine().Split(' ');
                for (int k = 0; k < line.Length; k++)
                {
                    input[i, k] = int.Parse(line[k]);
                }
            }
            int row = 0, col = 0;
            for (int i = 0; i < input.GetLength(0); i++)
            {
                for (int k = 0; k < input.GetLength(1); k++)
                {
                    if (input[i, k] == 1)
                    {
                        row=i;
                        col=k;
                        break;
                    }
                }
            }
            var ymove =Math.Abs(row-2) ;
            var xmove = Math.Abs(col-2);
            System.Console.WriteLine(ymove+xmove);

        }
    }
}

using System;

namespace Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {

            int y = -2;
            int x = 10;
            bool set = false;

            for (int i = 0; i < 5; i++)
            {
                if (set)
                {
                    Console.ReadLine();
                }
                else
                {

                    string input = Console.ReadLine();
                    input = input[0].ToString() + input[2].ToString() + input[4].ToString() + input[6].ToString() + input[8].ToString();
                    if (input.Contains("1"))
                    {

                        x = input.IndexOf('1')-2;
                        set = true;
                    }
                    else
                    {
                        y++;
                    }

                }
            }

            Console.WriteLine(Math.Abs(x) + Math.Abs(y));
            Console.ReadLine();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication12
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = 0; int n = 0;
            for (int i = 0; i < 5; i++)
            {
                int[] c = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int m = 0; m < 5; m++)
                {
                    int y = c[m];
                    if (y == 1) { n = i; k = m; }

                }

            }

            Console.WriteLine(((k > 2) ? k - 2 : 2 - k) + ((n > 2) ? n - 2 : 2 - n));
        }

    }
}

using System;
class Program
{
    static void Main(string[] args)
    {
        var m = new string[5];
        int row = 0, col = 0;
        for (int i = 0; i < 5; i++)
        {
            m[i] = Console.ReadLine().Replace(" ", "");
            if ((row = m[i].IndexOf('1')) >= 0)
            {
                col = i;
                break;
            }
        }
        Console.WriteLine(Math.Abs(row - 2) + Math.Abs(col - 2));
    }
}

using System;

namespace _263A___Beautiful_Matrix
{
	class Program
	{
		static void Main(string[] args)
		{
			Matrixen();
		}

		private static void Matrixen()
		{
			Tuple<int, int> coords = GetCoords();
			int steps = Math.Abs(coords.Item1 - 3) + Math.Abs(coords.Item2 - 3);

			Console.WriteLine(steps);
		}

		private static Tuple<int, int> GetCoords()
		{
			for (int y = 0; y < 5; y++)
			{
				string[] line = Console.ReadLine().Split(' ');

				for (int x = 0; x < 5; x++)
					if (line[x] == "1")
						return new Tuple<int, int>(x + 1, y + 1);
			}

			return new Tuple<int, int>(0, 0);
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fun
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            List<string> lines = new List<string>();
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));

            int ans = 0;
            for (int i = 1; i < 6; i++)
            {
                if (lines[i-1].Contains('1'))
                {
                    if (i < 3)
                        ans += 3 - i;
                    else if(i>3)
                        ans += i - 3;

                    string s = lines[i-1];
                    for (int l = 1; l < 6; l++)
                    {
                        if (s[l-1] == '1')
                        {
                            if (l < 3)
                                ans += 3 - l;
                            else if(l > 3)
                                ans += l - 3;
                        }
                    }
                }

            }

                Console.WriteLine(ans);
        }
    }
}

using System.Collections.Generic;
using System.Collections;
using System;

class Solution
{
    static void Main(string[] args)
    {
        int[,] matrix = new int[5,5];
        int[] mat = new int[5];
        int rowcount=0,columncount=0,counter=0;
        for(int i=0;i<5;i++)
        {
            mat = Array.ConvertAll(Console.ReadLine().Split(' '), item => Convert.ToInt32(item));
            for(int j=0;j<5;j++)
            {
                matrix[i, j] = mat[j];
                if(matrix[i,j] == 1)
                {
                    rowcount = i; columncount = j;
                }
            }
        }
        if (rowcount == 2 && columncount == 2) Console.Write(counter);
        else
        {
            counter += (rowcount>2? rowcount-2 : 2-rowcount);
            counter += (columncount > 2 ? columncount - 2 : 2 - columncount);
            Console.Write(counter);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LearningCSharp
{
    class _263A
    {

        static void Main()
        {
            char[] ar = new char[1000];
            string temp = ""; int row = 0, col = 0;
            for (int i = 1; i < 6; i++)
            {

                temp = Console.ReadLine();

                if (temp.Contains('1')) {
                    row = i;
                    string [] t=temp.Split(' ');
                    for (int k = 0; k < t.Length; k++) { if (t[k] == "1") { col = k + 1; } }
                }
            }

            int moveR = Math.Abs(row - 3);
                int moveC = Math.Abs(col - 3);

                Console.WriteLine(moveC + moveR);
           // Console.ReadKey();

            }
        }

        }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp73
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] mas = new int[5, 5];
            int k = 0;
            int b = -1;
            int c = -1;
            for (int i = 0; i < 5; i++)
            {
                string s = Console.ReadLine();
                string[] ss = s.Split(' ');

                for (int j = 0; j < 5; j++)
                {
                    mas[i, j] = Convert.ToInt32(ss[j]);
                    if (mas[i, j] == 1)
                    {
                        b = i;
                        c = j;
                    }
                }
            }

            Console.WriteLine(Math.Abs(2 - b) + Math.Abs(2 - c));

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
using System.Numerics;

namespace probleme {
    class Program {
        static void Main(string[] args) {
            int i = 0, j = 0, ans = 0;
            for (i = 0; i < 5; i++) {
                string[] s = Console.ReadLine().Split(' ');
                for (j = 0; j < 5; j++)
                    if (s[j] == "1")
                        ans = Math.Abs(i - 2) + Math.Abs(j - 2);
            }
            Console.WriteLine(ans);

            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;

namespace For_C__exercise
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] arr = new int[5, 5];
            string[] input;
            for (int i = 0; i < 5; i++)
            {
                input = Console.ReadLine().Split(' ');
                for (int j = 0; j < 5; j++)
                {
                    arr[i, j] = int.Parse(input[j]);
                }
            }
            solution(arr);
        }
        public static void solution(int[,] s)
        {
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (s[i, j] == 1)
                    {
                        Console.WriteLine(Math.Abs(i - 2) + Math.Abs(j - 2));
                        return;
                    }
                }
            }
        }
    }
}

using System;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Numerics;

namespace ConsoleApp1
{
	 class Program
	{

		public static void Main(string[] args)
		{

			for(int i = 1; i <= 5; i++)
            {
				string input = Console.ReadLine();
				string[] input_values = input.Split(' ');
				for(int j = 1; j <= 5; j++)
                {
					int x = int.Parse(input_values[j-1]);////i dont know the purpose of this line tbh ---maybe because you indexing from 0?
                    if(x == 1)
                    {
						Console.WriteLine(Math.Abs(i - 3) + Math.Abs(j - 3));
                    }

                }
            }

		}

	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _263A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = new string[5];
            int index = 0, Rindex = 0, Cindex = 0;
            for (int i = 0; i < 5; i++)
            {
                s[i] = Console.ReadLine().Replace(" ", "");
                if (s[i].Contains("1"))
                {
                    Rindex = i;
                    for (int j = 0; j < 5; j++)
                    {
                        if (s[i][j].ToString() == "1")
                        {
                            Cindex = j;
                        }
                    }
                }
            }
            Rindex = Math.Abs(4 - Rindex - 2);
            Cindex = Math.Abs(4 - Cindex - 2);

            Console.Write(Rindex+Cindex);
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _263A_A_Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i=1; i<=5; i++)
            {
                string s1 = Console.ReadLine();
                string[] s1values = s1.Split(' ');

                for (int j=1; j<=5; j++)
                {
                    int x = int.Parse(s1values[j-1]);
                    if (x==1)
                    {
                        Console.Write(Math.Abs(i-3)+ Math.Abs(j - 3));
                    }
                }
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace for_codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] a = new int[5,5];
            int anss = 0;
            string s;
            string[] ss;
            for (int k = 0; k < 5; k++)
            {
                s = Console.ReadLine();
                ss = s.Split(' ');
                for (int k1 = 0; k1 < 5; k1++)
                {
                    a[k, k1] = int.Parse(ss[k1]);
                    if(a[k,k1] == 1)
                        anss = Math.Abs(k-2) + Math.Abs(k1-2);
                }
            }
            Console.WriteLine(""+anss);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MaceirzMacka
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] Arra = new string[5];
            var suma = 0;

            for (int i = 0; i < 5; i++)
                Arra[i] = Convert.ToString(Console.ReadLine());

            for (int i = 0; i < 5; i++)
            {
                var index = Arra[i].IndexOf("1");
                var row = Arra[i].Contains("1");

                if (row == true && (i == 0 || i == 4))
                    suma += 2;
                if (row == true && (i == 1 || i == 3))
                    suma += 1;
                if (row == true && (index == 0 || index == 8))
                    suma += 2;
                if (row == true && (index == 2 || index == 6))
                    suma += 1;
            }
            Console.WriteLine(suma);
        }
    }
}

using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] row1 = Console.ReadLine().Split();
            string[] row2 = Console.ReadLine().Split();
            string[] row3 = Console.ReadLine().Split();
            string[] row4 = Console.ReadLine().Split();
            string[] row5 = Console.ReadLine().Split();

            if(row1[0] == "1" || row1[4] == "1" || row5[0] == "1" || row5[4] == "1")
            {
                Console.WriteLine("4");
            }
            else if(row1[1] == "1" || row1[3] == "1" || row5[1] == "1" || row5[3] == "1" || row2[0] == "1" || row2[4] == "1" || row4[0] == "1" || row4[4] == "1"){
                Console.WriteLine("3");
            }
            else if(row1[2] == "1" || row2[1] == "1" || row2[3] == "1" || row4[1] == "1" || row4[3] == "1" || row5[2] == "1" || row5[3] == "1" || row3[0] == "1" || row3[4] == "1"){
                Console.WriteLine("2");
            }
            else if(row2[2] == "1" || row3[1] == "1" || row4[2] == "1"){
                Console.WriteLine("1");
            }
            else{
                Console.WriteLine("0");
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CF {
    class Program {

        static void Main(string[] args) {

#if DEBUG
            TextReader reader = new StreamReader("../../input.txt");
            TextWriter writer = Console.Out;
#else
			TextReader reader = Console.In;
            TextWriter writer = Console.Out;
#endif

            var line1 = reader.ReadLine().Replace(" ", "");
            var line2 = reader.ReadLine().Replace(" ", "");
            var line3 = reader.ReadLine().Replace(" ", "");
            var line4 = reader.ReadLine().Replace(" ", "");
            var line5 = reader.ReadLine().Replace(" ", "");

            int i = 0;
            int j = 0;
            int ii = 0;

            if ((ii = line1.IndexOf('1')) > 0) {
                i = ii;
                j = 1;
                i++;
            }
            if ((ii = line2.IndexOf('1')) > 0) {
                i = ii;
                j = 2;
                i++;
            }
            if ((ii = line3.IndexOf('1')) > 0) {
                i = ii;
                j = 3;
                i++;
            }
            if ((ii = line4.IndexOf('1')) > 0) {
                i = ii;
                j = 4;
                i++;
            }
            if ((ii = line5.IndexOf('1')) > 0) {
                i = ii;
                j = 5;
                i++;
            }

            Console.WriteLine((Math.Abs(i - 2) + Math.Abs(j - 2)));

#if DEBUG
            Console.ReadKey();
#endif
        }

    }

    class Pair<T1, T2> {
        public Pair(T1 first, T2 second) {
            First = first;
            Second = second;
        }
        public T1 First { get; set; }
        public T2 Second { get; set; }
        public override string ToString() {
            return "{" + First + " " + Second + "}";
        }
    }

    static class ReaderExtensions {

        public static string ReadToken(this TextReader reader) {
            int val;
            var builder = new StringBuilder();
            while (true) {
                val = reader.Read();
                if (val == ' ' || val == -1) {
                    if (builder.Length == 0) continue;
                    break;
                }
                if (val == 13) {
                    reader.Read();
                    if (builder.Length == 0) continue;
                    break;
                }
                builder.Append((char)val);
            }
            return builder.ToString();
        }

        public static T Read<T>(this TextReader reader) {
            return (T)Convert.ChangeType(reader.ReadToken(), typeof(T));
        }

        public static T[] ReadArr<T>(this TextReader reader) {
            return reader.ReadLine()
                .Split(' ').Select(str =>
                    (T)Convert.ChangeType(str, typeof(T))
                ).ToArray();
        }

    }

    static class LinqExtensions {
        /// <summary>Value / Index</summary>
        public static IEnumerable<Pair<T, int>> SelectIndexes<T>(this IEnumerable<T> collection) {
            return collection.Select((v, i) => new Pair<T, int>(v, i));
        }
        public static IEnumerable<T> SelectValues<T>(this IEnumerable<Pair<T, int>> collection) {
            return collection.Select(p => p.First);
        }
    }

}

using System;

namespace _263A_BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] task = new string[25];
            int position = 1;

            for (int i = 0; i < 5; i++)
            {
                var mass = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                for (int j = i*5, k = 0; j < 25 & k<5; j++, k++)
                {
                task[j] = mass[k];
                }
             }

            for (int i =0; i < 25; i++)
            {
                if (task[i] == "0")
                {
                    position += 1;
                }
                else
                    break;
            }

            double caseNum = Math.Ceiling(position / 5.0);
            int caseMod = position % 5;
            if (caseMod == 0)
            {
                caseMod = 5;
            }

            if (position == 14)
            {
                Console.WriteLine(0);
            }
            else if(caseMod == 3)
            {
                Console.WriteLine(Math.Abs(caseNum - caseMod));

            }
            else
            {
                caseNum = Math.Abs(caseNum - 3) + Math.Abs(caseMod - 3);
                Console.WriteLine(caseNum);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fun
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            List<string> lines = new List<string>();
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));

            int ans = 0;
            for (int i = 1; i < 6; i++)
            {
                if (lines[i-1].Contains('1'))
                {
                    if (i < 3)
                        ans += 3 - i;
                    else if(i>3)
                        ans += i - 3;

                    string s = lines[i-1];
                    for (int l = 1; l < 6; l++)
                    {
                        if (s[l-1] == '1')
                        {
                            if (l < 2)
                                ans += 3 - l;
                            else if(l > 2)
                                ans += l - 3;
                        }
                    }
                }

            }

                Console.WriteLine(ans);
        }
    }
}

using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int answer = 0;

        int[][] matrix = new int[5][];

        for (int i = 0; i < 5; ++i)
        {
            matrix[i] = Console.ReadLine().Split(' ')
                .Select(s => Convert.ToInt32(s)).ToArray();
        }

        for (int i = 0; i < 5; ++i)
        {
            for (int j = 0; j < 5; ++j)
            {
                if (matrix[i][j] == 1)
                {
                    if (j - i == 0 && (j != 3 && i != 3))
                    {
                        answer = 4;
                    }
                    else
                    {
                        answer = Math.Abs(j - i);
                    }
                    break;
                }
            }
        }

        Console.WriteLine(answer);
    }
}

using System;
using System.Linq;
using System.Text;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var first = Console.ReadLine();
            var second = Console.ReadLine();
            var third = Console.ReadLine();
            var fourth = Console.ReadLine();
            var fifth = Console.ReadLine();

            const string one = "1";

            var counter = 0;
            if (first.Contains(one))
            {
                counter += 2;
                counter = Math.Abs(first.IndexOf("1", StringComparison.CurrentCulture) - 3);
            }
            else if (second.Contains(one))
            {
                counter += 1;
                counter = Math.Abs(second.IndexOf("1", StringComparison.CurrentCulture) - 3);
            }
            else if (third.Contains(one))
            {
                counter = Math.Abs(third.IndexOf("1", StringComparison.CurrentCulture) - 3);
            }
            else if (fourth.Contains(one))
            {
                counter += 1;
                counter = Math.Abs(fourth.IndexOf("1", StringComparison.CurrentCulture) - 3);
            }
            else
            {
                counter += 2;
                counter = Math.Abs(fifth.IndexOf("1", StringComparison.CurrentCulture) - 3);
            }

            Console.WriteLine(counter);
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _263A
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
            int[,] matr = new int[5, 5];
            for (int i = 0; i < 5; i++)
            {
                s = Console.ReadLine();
                string[] temp = s.Split(' ');
                for (int j = 0; j < 5; j++)
                    matr[i, j] = int.Parse(temp[j]);
            }

            for(int i = 0; i < 5; ++i)
            {
                for(int j = 0; j < 5; ++j)
                {
                    if(matr[i, j] == 1)
                    {
                        Console.WriteLine(Math.Abs(3 - i) + Math.Abs(3 - j));
                    }
                }
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[][] Matrix = new int[5][];
            /*
            {
                {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},
            };
            */
            int MinMove = 0;
            for (int i = 0; i < 5; i++)
            {
                Matrix[i] = Array.ConvertAll(Console.ReadLine().Replace("\t" , " ").Split(), int.Parse);
                for (int j = 0; j < 5; j++)
                {
                    if (Matrix[i][j] == 1)
                    {
                        if (i == j)
                            MinMove += (i > 2) ? i - 2 : 2 - i;
                        else
                        {
                            MinMove += (i > 2) ? i - 2 : 2 - i;
                            MinMove += (j > 2) ? j - 2 : 2 - j;
                        }
                    }
                }
            }
            /*
            for(int i=0;i<5;i++)
            {
                for (int j = 0; j < 5; j++)
                     Console.Write(Matrix[i][j] + " ");
                Console.WriteLine();
            }
            */
            Console.WriteLine(MinMove);
            //Console.ReadLine();
        }
    }
}

    class Program
    {
        static void Main(string[] args)
        {

            int x=0, y = 0;
            int[,] matrix = new int[5,5];
            System.String[] lines = System.Console.ReadLine().Split();
            matrix[0, 0] = int.Parse(lines[0]);
            matrix[0, 1] = int.Parse(lines[1]);
            matrix[0, 2] = int.Parse(lines[2]);
            matrix[0, 3] = int.Parse(lines[3]);
            matrix[0, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[1, 0] = int.Parse(lines[0]);
            matrix[1, 1] = int.Parse(lines[1]);
            matrix[1, 2] = int.Parse(lines[2]);
            matrix[1, 3] = int.Parse(lines[3]);
            matrix[1, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[2, 0] = int.Parse(lines[0]);
            matrix[2, 1] = int.Parse(lines[1]);
            matrix[2, 2] = int.Parse(lines[2]);
            matrix[2, 3] = int.Parse(lines[3]);
            matrix[2, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[3, 0] = int.Parse(lines[0]);
            matrix[3, 1] = int.Parse(lines[1]);
            matrix[3, 2] = int.Parse(lines[2]);
            matrix[3, 3] = int.Parse(lines[3]);
            matrix[3, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[4, 0] = int.Parse(lines[0]);
            matrix[4, 1] = int.Parse(lines[1]);
            matrix[4, 2] = int.Parse(lines[2]);
            matrix[4, 3] = int.Parse(lines[3]);
            matrix[4, 4] = int.Parse(lines[4]);

            for (int i = 0; i < 5; i++)
                for (int j = 0; j < 5; j++)
                {
                    if (matrix[i, j] == 1)
                    {
                        x = i;
                        y = j;
                    }
                }
            if (x == 0 && y == 0)
                System.Console.WriteLine(4);
            else if (x == 0 && y == 4)
                System.Console.WriteLine(4);
            else if (x == 4 && y == 0)
                System.Console.WriteLine(4);
            else if (x == 4 && y == 4)
                System.Console.WriteLine(4);
            /////////////////////////////////////
            else if (x == 2 && y == 0)
                System.Console.WriteLine(2);
            else if (x == 0 && y == 2)
                System.Console.WriteLine(2);
            else if (x == 4 && y == 2)
                System.Console.WriteLine(2);
            else if (x == 2 && y == 4)
                System.Console.WriteLine(2);
            else if(x == 1 && y == 3)
                System.Console.WriteLine(2);
            else if (x == 3 && y == 1)
                System.Console.WriteLine(2);
            else if (x == 1 && y == 1)
                System.Console.WriteLine(2);
            else if (x == 3 && y == 3)
                System.Console.WriteLine(2);

            ////////////////////////////////////////////////////////////////////
            else if (x == 0 && y == 1)
                System.Console.WriteLine(3);
            else if (x == 1 && y == 0)
                System.Console.WriteLine(3);
            else if (x == 4 && y == 1)
                System.Console.WriteLine(3);
            else if (x == 1 && y == 4)
                System.Console.WriteLine(3);
            else if (x == 0 && y == 3)
                System.Console.WriteLine(3);
            else if (x == 3 && y == 0)
                System.Console.WriteLine(3);
            else if (x == 4 && y == 3)
                System.Console.WriteLine(3);
            else if (x ==3 && y == 4)
                System.Console.WriteLine(3);
            ////////////////////////////////////////////
            else
                System.Console.WriteLine(1);

        }
    }

using System;
using System.Linq;

namespace Problem_263A
{

    class Controller
    {
        /* Закрытые поля */

        public int[,] a;
        public int m;

        /* Метод, с помощью которого вводится массив */

        public void InputController(int[][] a, int m)
        {

            Console.WriteLine("Введите матрицу: ");

            for (int i = 0; i < a.Length; i++)
            {
                a[i] = Console.ReadLine()
                    .Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
                    .Select(int.Parse)
                    .ToArray();
            }
            Console.WriteLine();
        }

        /* Метод, который выводит массив */

        /*public void OutputController(int[][] a)
        {
            for (int i = 0; i < a.Length; i++)
            {
                for (int j = 0; j < a.Length; j++)
                {
                    Console.Write(a[i][j]);
                }
                Console.WriteLine();
            }
        }*/

        /* Метод создания красивой матрицы */

        public void NumberOfActions(int[][] a)
        {

            int n = 0;

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (a[i][j] == 1)
                    {
                        a[2][2] = a[i][j];
                        a[i][j] = 0;
                        n += Math.Abs(i - 2) + Math.Abs(j - 2);
                    }
                }
            }
            Console.WriteLine(n);
        }
    }

    class Program
    {
        static void Main()
        {
           /* Инициализация массива */

           const int m = 5;
           int[][] a = new int[m][];

           /* Вывод */

           Controller cont = new Controller();
           cont.InputController(a,m);
           /*cont.OutputController(a);*/
            cont.NumberOfActions(a);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemSolution
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var split = input.Split(' ');
            //var matrix = "";
            //var counter = 0;
            //for(var i = 0; i < split.Length; i++)
            //{
            //    if (counter < 5)
            //        matrix += split[i];
            //    else
            //    {
            //        matrix += "\r\n" + split[i];
            //        counter = 0;
            //    }

            //    counter++;
            //}

            var numberOne = Array.FindIndex(split, w => w.Contains('1'));
            var row = numberOne/5;
            var column = numberOne % 5;
            var swapRowIndex = Math.Abs(row-2);
            var swapColumnIndex = Math.Abs(column-2);
            var total = swapColumnIndex + swapRowIndex;
            Console.WriteLine(total);

            //Console.ReadKey();

        }
    }
}

using System;
namespace C_
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] positions = new int[5,5]
            {
                {5,3,2,3,5},{3,2,1,2,3},{2,1,0,1,2},{3,2,1,2,3},{5,3,2,3,5}
            };
            int value = 0;
            bool check = false;
            for(int i = 0; i < 5;i++)
            {
                string[] temp = Console.ReadLine().Trim().Split();
                for(int j = 0; j < temp.Length;j++)
                {
                    if(temp[j] == "1")
                    {
                        value = positions[i,j];
                        check = true;
                        break;
                    }
                }
                if(check == true)
                {
                    break;
                }

            }
            Console.WriteLine(value);
        }
    }
}

using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

namespace Problem236A {
    class Program {
        static void Main(string[] args) {
            char[] input = Console.ReadLine().ToCharArray();
            int inputLength = input.Length;
            int distinctLetters = inputLength;

            int number = 0;
            for (int i = 0; i < inputLength; i++) {
                char l = input[i];
                for (int j = i+1; j < inputLength; j++) {
                    char l2 = input[j];
                    if (l.Equals(l2)) {
                        distinctLetters--;
                        input[j] = (char)number;
                        number++;
                    }
                }
            }

            if (distinctLetters % 2 == 0) {
                Console.WriteLine("CHAT WITH HER!");
            } else {
                Console.WriteLine("IGNORE HIM!");
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = 5;
            var res = 0;
            while (t-- > 0) {
                var array = Console.ReadLine().Split(' ');
                var liste = new List<int>();

                foreach (var q in array) { liste.Add(int.Parse(q)); }

                if (liste.Contains(1)) { res += Math.Abs(t-3)+ Math.Abs(3 - liste.IndexOf(1));   }
            }
            Console.WriteLine(res);
            Console.ReadLine();
        }
    }
}

using System;

namespace Matriza
{
    class Program
    {
        static void Main(string[] args)
        {
            string p = "";
            int str = 0;
            int stol = 0;
            for (int i = 0; i < 5; i++)
            {
                string k = Console.ReadLine();
                if (k != "00000")
                {
                    p = k;
                    str = i + 1;
                }
            }
            for (int u = 0; u < p.Length; u++)
            {
                if (p[u] == '1')
                {
                    stol = u + 1;
                }
            }
            int a = 3 - str;
            int b = 3 - stol;
            if (a < 0)
            {
                a = a - 2 * a;
            }
            if (b < 0)
            {
                b = b - b * 2;
            }
            int S = a + b;

            Console.WriteLine(S);

        }
    }
}

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            String a;
            int output=0;
            for (int x = 0; x < 5; x++)
            {
                 a = Console.ReadLine();
                 string[] words = a.Split(' ');
                 for (int y = 0; y < 5; y++)
                 {
                     if (words[y] == "1")
                     {
                         output = x % 2 + y % 2;
                     }
                 }
            }

            Console.WriteLine(output);

        }
    }
}

using System;

namespace ConsoleApp1
{
    internal static class Program
    {
        private static void Main()
        {
            int steps = 0;
            for (int i = 1; i <= 5; i++)
            {
                string s1 = Console.ReadLine();
                string[] s1values = s1.Split(' ');

                for (int j = 1; j <= 5; j++)
                {
                    int x = int.Parse(s1values[j - 1]);
                    if (x == 1)
                    {
                        steps = Math.Abs(i - 2) + Math.Abs(j - 2);
                    }
                }
            }
            Console.WriteLine(steps);
        }
    }
}

using System;

namespace BeautifulMatrix
{
    class Program
    {
        private static int SIZE_MATRIX = 5;
        private static int PERFECT_POSITION;
        private static int[,] Matrix;

        static void Main(string[] args)
        {
            Matrix = new int[SIZE_MATRIX, SIZE_MATRIX];
            int[] temp = new int[SIZE_MATRIX], OriginalPos = new int[2];
            PERFECT_POSITION = (SIZE_MATRIX / 2) - 1;
            int steps = 0;

            for (int i = 0; i < SIZE_MATRIX;i++)
            {
                temp = Array.ConvertAll(Console.ReadLine().Split(' '), x => int.Parse(x));

                for (int j = 0;j < SIZE_MATRIX;j++)
                {
                    Matrix[i, j] = temp[j];

                    if (temp[j] == 1)
                    {
                        OriginalPos[0] = i;
                        OriginalPos[1] = j;
                    }
                }
            }

            for (int i = 0; i < 2;i++)
            {
                while (OriginalPos[i] != PERFECT_POSITION)
                {
                    if (OriginalPos[i] > PERFECT_POSITION)
                    {
                        OriginalPos[i]--;
                    }
                    else
                    {
                        OriginalPos[i]++;
                    }
                    steps++;
                }
            }

            Console.WriteLine(steps);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces_Sol_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int MovesNeed = 0;
            int[ , ] Matrix = new int[5, 5];
            for (var y = 0; y < 5; y++)
            {
                var p = Console.ReadLine().Split(' ');
                for(var x = 0; x < 5; x++)
                {
                    Matrix[x, y] = int.Parse(p[x]);
                    if(int.Parse(p[x]) == 1)
                    {
                        MovesNeed = 2 - x;
                        if (MovesNeed < 0) MovesNeed *= -1;
                        MovesNeed += 2 - y;
                        if (MovesNeed < 0) MovesNeed *= -1;
                    }
                }
            }
            Console.WriteLine(MovesNeed);
        }
    }
}

    class Program
    {
        static void Main(string[] args)
        {

            int x=0, y = 0;
            int[,] matrix = new int[5,5];
            System.String[] lines = System.Console.ReadLine().Split();
            matrix[0, 0] = int.Parse(lines[0]);
            matrix[0, 1] = int.Parse(lines[1]);
            matrix[0, 2] = int.Parse(lines[2]);
            matrix[0, 3] = int.Parse(lines[3]);
            matrix[0, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[1, 0] = int.Parse(lines[0]);
            matrix[1, 1] = int.Parse(lines[1]);
            matrix[1, 2] = int.Parse(lines[2]);
            matrix[1, 3] = int.Parse(lines[3]);
            matrix[1, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[2, 0] = int.Parse(lines[0]);
            matrix[2, 1] = int.Parse(lines[1]);
            matrix[2, 2] = int.Parse(lines[2]);
            matrix[2, 3] = int.Parse(lines[3]);
            matrix[2, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[3, 0] = int.Parse(lines[0]);
            matrix[3, 1] = int.Parse(lines[1]);
            matrix[3, 2] = int.Parse(lines[2]);
            matrix[3, 3] = int.Parse(lines[3]);
            matrix[3, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[4, 0] = int.Parse(lines[0]);
            matrix[4, 1] = int.Parse(lines[1]);
            matrix[4, 2] = int.Parse(lines[2]);
            matrix[4, 3] = int.Parse(lines[3]);
            matrix[4, 4] = int.Parse(lines[4]);

            for (int i = 0; i < 5; i++)
                for (int j = 0; j < 5; j++)
                {
                    if (matrix[i,j] == 1)
                        x = i;y = j;
                }
            if (x == 0 && y == 0)
                System.Console.WriteLine(4);
            else if (x == 0 && y == 4)
                System.Console.WriteLine(4);
            else if (x == 4 && y == 0)
                System.Console.WriteLine(4);
            else if (x == 4 && y == 4)
                System.Console.WriteLine(4);
            /////////////////////////////////////
            else if (x == 2 && y == 0)
                System.Console.WriteLine(2);
            else if (x == 0 && y == 2)
                System.Console.WriteLine(2);
            else if (x == 4 && y == 2)
                System.Console.WriteLine(2);
            else if (x == 2 && y == 4)
                System.Console.WriteLine(2);
            else if(x == 1 && y == 3)
                System.Console.WriteLine(2);
            else if (x == 3 && y == 1)
                System.Console.WriteLine(2);
            else if (x == 1 && y == 1)
                System.Console.WriteLine(2);
            else if (x == 3 && y == 3)
                System.Console.WriteLine(2);

            ////////////////////////////////////////////////////////////////////
            else if (x == 0 && y == 1)
                System.Console.WriteLine(3);
            else if (x == 1 && y == 0)
                System.Console.WriteLine(3);
            else if (x == 4 && y == 1)
                System.Console.WriteLine(3);
            else if (x == 1 && y == 4)
                System.Console.WriteLine(3);
            else if (x == 0 && y == 3)
                System.Console.WriteLine(3);
            else if (x == 3 && y == 0)
                System.Console.WriteLine(3);
            else if (x == 4 && y == 3)
                System.Console.WriteLine(3);
            else if (x ==3 && y == 4)
                System.Console.WriteLine(3);
            else if (x == 2 && y == 1)
                System.Console.WriteLine(1);
            ////////////////////////////////////////////
            else
                System.Console.WriteLine(1);

        }
    }

using System;
namespace BasicProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            int indexno = 0;
            for (int i = 0; i < 5; i++)
            {
                var j = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                int ar = 0;
                foreach (var item in j)
                {
                    ar++;
                    if(item==1)
                    {
                        indexno = i * 5 + ar;
                        int result = 13 - indexno;
                        Console.WriteLine(result);
                    }
                }
            }
       }
    }
}

using System;

namespace BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            char[,] Array = new char [5, 5];
            int count = 0;int rowindex = 0;
            int colindex = 0;

            for (int i=0;i<4;i++)
            {
                rowindex = i;
                string value = Console.ReadLine();
                if(value.Contains("1"))
                {
                    colindex = value.IndexOf('1') / 2 + 1;

                }

            }

          //  Console.WriteLine(2-rowindex/2+1+2-colindex);
            Console.WriteLine(rowindex/2+1-2+ colindex-2);

        }
    }
}

using System;

class Program {
    static void Main() {

        string[][] matrix = new string[5][];
        var pos = (0, 0);
        int steps = 0;

        for (int i = 0; i < 5; i++) {
            matrix[i] = Console.ReadLine().Split();
            for (int j = 0; j < 5; j++) {
                if (matrix[i][j] == "1") {
                    pos.Item2 = i;
                    pos.Item1 = j;
                }
            }
        }

        if (pos.Item1 < 2)
            steps += 2 - pos.Item1;
        else
            steps += 2 % pos.Item1;

        if (pos.Item2 < 2)
            steps += 2 - pos.Item2;
        else
            steps += 2 % pos.Item2;

        Console.WriteLine(steps);

    }
}

using System;
using System.Text;
class Problem
{
    static void Main()
    {
        int[] a = new int[25];
        int viTri = 0;
        for(int i = 0 ; i < 5 ; i++)
        {
            string[] str = Console.ReadLine().Split();
            for(int j = 0 ; j < 5 ; j++)
            {
                a[5 * i + j] = Convert.ToInt32( str[j] );
                if(a[5 * i + j] == 1)
                    viTri = 5 * i + j;
            }

        }
        Console.WriteLine( viTri - 13 );

    }
}

using System;

class Program
{
    static void Main()
    {
        for (var i = 0; i < 5; ++i)
            for(var j = 0; j < 5; ++j)
                if(Console.Read() == '1')
                    Console.WriteLine(Math.Abs(i - 2) + Math.Abs(j - 2));
    }
}

using System;

namespace Practise_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] Input = new int[5, 5];
            int LuuX = 0, LuuY = 0;
            for (var i = 0; i < 5; i++)
            {
                for(var j = 0; j < 5; j++)
                {
                    Input[i, j] = Convert.ToInt32(Console.Read());
                    if(Input[i,j] == 1)
                    {
                        LuuX = i;
                        LuuY = j;
                    }
                }
            }
            Console.WriteLine(Math.Abs(3-LuuX)+Math.Abs(3-LuuY));
        }
    }
}

using System;
using System.Linq;

namespace SOLID
{
    class Program
    {
        public static void Main(string[] args)
        {
            string[] input = new string[5];
            int[,] matrix = new int[5, 5];
            int oneX = -1, oneY = -1, answer = -1;

            for (int i = 0; i < 5; i++)
            {
                input[i] = Console.ReadLine();
            }
            for (int i = 0; i < 5; i++)
            {
                input[i] = input[i].Replace(" ", "");
                for (int j = 0; j < 5; j++)
                {
                    matrix[i, j] = (input[i][j]) - '0';
                    if (input[i][j] - '0' == 1)
                    {
                        oneX = i;
                        oneY = j;
                    }
                }
            }

            answer = (Math.Abs(2 - oneX) + Math.Abs(2 - oneY));

        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemSolution
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var split = input.Split(' ');
            //var matrix = "";
            //var counter = 0;
            //for(var i = 0; i < split.Length; i++)
            //{
            //    if (counter < 5)
            //        matrix += split[i];
            //    else
            //    {
            //        matrix += "\r\n" + split[i];
            //        counter = 0;
            //    }

            //    counter++;
            //}

            var numberOne = Array.FindIndex(split, w => w.Contains('1'));
            var row = numberOne/5;
            var column = numberOne % 5;
            var swapRowIndex = Math.Abs(2 - row);
            var swapColumnIndex = Math.Abs(2 - column);
            ValueType total = swapColumnIndex + swapRowIndex;
            Console.WriteLine(total);

            //Console.ReadKey();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace code
{
    class Wight
    {

        static void Main(string[] args)
        {
            int row = 5;
            int col = 5;
            int[,] matrix1;

            int[,] newmat = new int[5, 5];

            string[] inputs = new string[5];

            matrix1 = new int[5, 5];

            for (int i = 0; i < inputs.Length; i++)
            {

                   inputs[i] = Console.ReadLine();// i have problem with this line,... plz show me the correct form
            }

            for( int i=0; i<inputs.Length;i++)
            {
               string [] nums =inputs[i].Split(' ');

                for( int j=0; j<col;j++)
                {
                    matrix1[i, j] = Convert.ToInt16(nums[j]);
                }
            }

            int count = 0;

            for( int i=0; i<row; i++)
            {
                for(int j=0; j<col; j++)
                {
                    if (matrix1[i, j]==1)
                    {
                        if(i==2 && j<2)
                        {
                            matrix1[i, j + 1] = matrix1[i, j];
                            matrix1[i, j] = 0;
                            count++;

                        }

                        else if(i==2 && j>2)
                        {
                            matrix1[i, j - 1] = matrix1[i, j];
                            matrix1[i, j] = 0;
                            count++;
                        }

                        else if(i<2 && j>2)
                        {

                            for (int k = j; k >= 2; k--)
                            {
                                matrix1[i, k- 1] = matrix1[i, k];
                                matrix1[i,k] = 0;
                                count++;
                            }

                        }

                        else if (i > 2 && j > 2)
                        {

                            matrix1[i - 1, j - 1] = matrix1[i, j];
                            matrix1[i, j] = 0;
                            count++;
                        }

                        else if (i<2 && j==2)
                        {
                            matrix1[i + 1, j] = matrix1[i, j];
                            matrix1[i, j] = 0;
                            count++;
                        }

                    }
                }

            }

            Console.WriteLine(count);

        }
    }
}

using System;
class Program
{
    static void Main()
    {
        int d = 0;
        for (int i = -2; i <= 2; i++)
        {
            if ((d = Console.ReadLine().Replace(" ", "").IndexOf('1')) > 0)
            {
                d -= 2;
                d += i;
            }
        }
        Console.WriteLine(d);
    }
}

using System;
class program
{
    static void Main(string[]args)
    {
        int[,] Matrix = new int[5, 5];
            int rowNumber = 0;
            int columnNumber = 0;
            int rowSwaps = 0;
            int columnSwaps = 0;
            for (int i = 0; i < 5; i++)
            {
                string input = Console.ReadLine();
                string[] inputs = input.Split(' ');
                for (int j = 0; j < 5; j++)
                {
                    Matrix[i, j] = Convert.ToInt32(inputs[j]);
                }
            }

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (Matrix[i, j] == 1)
                    {
                        rowNumber = i;
                        columnNumber = j;
                    }
                }
            }
            if (rowNumber == 2 && columnNumber == 2)
                Console.WriteLine(0);

            if (rowNumber == 2)
                rowSwaps = 0;
            else
            {
                while (rowNumber > 2)
                {
                    rowNumber--;
                    rowSwaps++;
                }

                while (rowNumber < 2)
                {
                    rowNumber++;
                    rowSwaps++;
                }
            }

            if (columnNumber == 2)
                columnSwaps = 0;
            else
            {
                while (columnNumber > 2)
                {
                    columnNumber--;
                    columnSwaps++;
                }

                while (columnNumber < 2)
                {
                    columnNumber++;
                    rowSwaps++;
                }
            }

            Console.WriteLine(rowSwaps+columnSwaps);
    }
}

using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

namespace Problem236A {
    class Program {
        static void Main(string[] args) {
            char[] input = Console.ReadLine().ToCharArray();
            int inputLength = input.Length;
            int distinctLetters = inputLength;

            int number = 0;
            for (int i = 0; i < inputLength; i++) {
                char l = input[i];
                for (int j = i+1; j < inputLength; j++) {
                    char l2 = input[j];
                    if (l.Equals(l2)) {
                        distinctLetters--;
                        input[j] = (char)number;
                        number++;
                    }
                }
            }

            if (distinctLetters % 2 == 0) {
                Console.WriteLine("CHAT WITH HER!");
            } else {
                Console.WriteLine("IGNORE HIM!");
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForces5
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] A1 = Console.ReadLine().Split(' ');
            string[] A2 = Console.ReadLine().Split(' ');
            string[] A3 = Console.ReadLine().Split(' ');
            string[] A4 = Console.ReadLine().Split(' ');
            string[] A5 = Console.ReadLine().Split(' ');

            if (A1.Contains("1"))
            {
                var counter = 0;
                var rowNum = 1;
                var colNow = 0;
                //var colNum = 0;
                var colNum = Array.FindIndex(A1, z => z.Contains("1"));
                if (colNum > 2)
                {
                    colNow = colNum - 1;
                    counter++;
                    if (colNow == 2)
                    {
                        Console.WriteLine((Math.Abs(rowNum - 3))+counter);

                    }
                    else
                    {
                        colNow = colNow - 1;
                        counter++;
                        Console.WriteLine((Math.Abs(rowNum - 3))+counter);
                    }
                }
                else
                {
                    colNow = colNum + 1;
                    counter++;
                    if (colNow == 2)
                    {
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);

                    }
                    else
                    {
                        colNow = colNow + 1;
                        counter++;
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);
                    }
                }
            }
            if (A2.Contains("1"))
            {
                var counter = 0;
                var rowNum = 2;
                var colNow = 0;
                //var colNum = 0;
                var colNum = Array.FindIndex(A2, z => z.Contains("1"));
                if (colNum > 2)
                {
                    colNow = colNum - 1;
                    counter++;
                    if (colNow == 2)
                    {
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);

                    }
                    else
                    {
                        colNow = colNow - 1;
                        counter++;
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);
                    }
                }
                else
                {
                    colNow = colNum + 1;
                    counter++;
                    if (colNow == 2)
                    {
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);

                    }
                    else
                    {
                        colNow = colNow + 1;
                        counter++;
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);
                    }
                }
            }
            if (A3.Contains("1"))
            {
                var counter = 0;
                var rowNum = 3;
                var colNow = 0;
                //var colNum = 0;
                var colNum = Array.FindIndex(A3, z => z.Contains("1"));
                if (colNum > 2)
                {
                    colNow = colNum - 1;
                    counter++;
                    if (colNow == 2)
                    {
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);

                    }
                    else
                    {
                        colNow = colNow - 1;
                        counter++;
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);
                    }
                }
                else
                {
                    colNow = colNum + 1;
                    counter++;
                    if (colNow == 2)
                    {
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);

                    }
                    else
                    {
                        colNow = colNow + 1;
                        counter++;
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);
                    }
                }
            }
            if (A4.Contains("1"))
            {
                var counter = 0;
                var rowNum = 4;
                var colNow = 0;
                //var colNum = 0;
                var colNum = Array.FindIndex(A4, z => z.Contains("1"));
                if (colNum > 2)
                {
                    colNow = colNum - 1;
                    counter++;
                    if (colNow == 2)
                    {
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);

                    }
                    else
                    {
                        colNow = colNow - 1;
                        counter++;
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);
                    }
                }
                else
                {
                    colNow = colNum + 1;
                    counter++;
                    if (colNow == 2)
                    {
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);

                    }
                    else
                    {
                        colNow = colNow + 1;
                        counter++;
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);
                    }
                }
            }
            if (A5.Contains("1"))
            {
                var counter = 0;
                var rowNum = 5;
                var colNow = 0;
                //var colNum = 0;
                var colNum = Array.FindIndex(A5, z => z.Contains("1"));
                if (colNum > 2)
                {
                    colNow = colNum - 1;
                    counter++;
                    if (colNow == 2)
                    {
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);

                    }
                    else
                    {
                        colNow = colNow - 1;
                        counter++;
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);
                    }
                }
                else
                {
                    colNow = colNum + 1;
                    counter++;
                    if (colNow == 2)
                    {
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);

                    }
                    else
                    {
                        colNow = colNow + 1;
                        counter++;
                        Console.WriteLine((Math.Abs(rowNum - 3)) + counter);
                    }
                }
            }
        }
    }
}

using System;

namespace Beautiful_Matrix
{
    class Program
    {
        static int numberOfBeautifulMoves(int row, int col)
        {
            int moves = 0;

            while (!(row == 2 && col == 2))
            {
                if(row > 2)
                    row--;

                if (col > 2)
                   col--;

                if (row < 2)
                    row++;

                if (col < 2)
                   col++;

                moves++;

            }
            return ++moves;
        }

        static void Main(string[] args)
        {
            int[,] matrix = new int[5, 5];
            string[] splitted = new string[5];
            int row = 0, col = 0;

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                splitted = Console.ReadLine().Split();
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    matrix[i, j] = Int32.Parse(splitted[j]);
                    if(matrix[i, j] == 1)
                    {
                        row = i;
                        col = j;
                    }

                }
            }

            Console.WriteLine(numberOfBeautifulMoves(row, col).ToString());

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int outout=0;

            string Input;

            for (int i = 0; i < 5; i++)
            {
                Input = Console.ReadLine();
                string[] splitString = Input.Split(' ');
                for(int j=0;j<5;j++)
                {
                    if(splitString[j].ToString()=="1")
                    {
                        outout = Math.Abs(i - 3) + Math.Abs(j - 3);

                    }

                }

            }
               Console.WriteLine(outout.ToString());

        }
    }
}

using System;
using System.Globalization;

namespace algorithms_700_01
{
    class Program
    {
        static void Main(string[] args)
        {
            var grid = Parse();
            Console.WriteLine(grid);
            var minimumShifts = Solve(grid);
            Print(minimumShifts);
        }

        private static void Print(int minimumShifts)
        {
            Console.WriteLine(minimumShifts);
        }

        private static int Solve(int[,] grid)
        {
            int x = 0, y = 0;
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (grid[i, j] == 1)
                    {
                        x = i;
                        y = j;
                    }
                }
            }
            return Math.Abs(x - 2) + Math.Abs(y - 2);
        }

        private static int[,] Parse()
        {
            var grid = new int[5, 5];
            for (int i = 0; i < 5; i++)
            {
                var input = Console.ReadLine();
                for (int j = 0; j < 5; j++)
                    grid[i, j] = int.Parse(input.Substring(2 * j, 1));
            }
            return grid;
        }
    }
}

using System.Collections.Generic;
using System.Collections;
using System;

class Solution
{
    static void Main(string[] args)
    {
        int[,] matrix = new int[5,5];
        int[] mat = new int[5];
        int rowcount=0,columncount=0,counter=0;
        for(int i=0;i<5;i++)
        {
            mat = Array.ConvertAll(Console.ReadLine().Split(' '), item => Convert.ToInt32(item));
            for(int j=0;j<5;j++)
            {
                matrix[i, j] = mat[j];
                if(matrix[i,j] == 1)
                {
                    rowcount = i; columncount = j;
                }
            }
        }
        if (rowcount == 2 && columncount == 2) Console.Write(counter);
        else
        {
            counter += (rowcount>2? rowcount-2 : 2-rowcount);
            counter += (columncount > 2 ? columncount - 2 : 2 - columncount);
        }
        Console.Write(counter);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //Your code goes here
            var matrix = new string[5];
            for(var index = 0; index < 5; index++)
                matrix[index] = Console.ReadLine();

            int oneRow=0;
            int oneCol=0;
            for(var row = 0; row < 5; row++)
            {
                var col = matrix[row].IndexOf("1");
                if(col != -1){
                    oneRow = row;
                    oneCol = col;
                }
            }

            Console.WriteLine(Math.Abs(2-oneRow) + Math.Abs(2-oneCol));
        }
    }
}

using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int answer = 0;

        int[][] matrix = new int[5][];

        for (int i = 0; i < 5; ++i)
        {
            matrix[i] = Console.ReadLine().Split(' ')
                .Select(s => Convert.ToInt32(s)).ToArray();
        }

        for (int i = 0; i < 5; ++i)
        {
            for (int j = 0; j < 5; ++j)
            {
                if (matrix[i][j] == 1)
                {
                    if (j - i == 0 && (j == 3 && i == 3))
                    {
                        answer = 4;
                    }
                    else
                    {
                        answer = Math.Abs(j - i);
                    }
                    break;
                }
            }
        }

        Console.WriteLine(answer);
    }
}

using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int answer = 0;

        int[][] matrix = new int[5][];

        for (int i = 0; i < 5; ++i)
        {
            matrix[i] = Console.ReadLine().Split(' ')
                .Select(s => Convert.ToInt32(s)).ToArray();
        }

        for (int i = 0; i < 5; ++i)
        {
            for (int j = 0; j < 5; ++j)
            {
                if (matrix[i][j] == 1)
                {
                    answer = Math.Abs(j - i);
                    break;
                }
            }
        }

        Console.WriteLine(answer);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

           int[,] arr = new int[5,5];
           int a1 = 0;
           int a2 = 0;

           for (int i = 0; i < 5; i++)
           {
               string str = Console.ReadLine();
               string []strArr = str.Split(' ');

               for (int j = 0; j < strArr.Length; j++)
               {
                   arr[i, j] = int.Parse(strArr[j]);

                   if (arr[i, j] == 1)
                   {
                       a1 = i;
                       a2 = j;
                   }
               }

           }
            int res=0;
            if(a1==2 && a2==2 )
            {
                Console.WriteLine(res);
            }
            else
            {
                if (a1 < 2)
                {
                    while (a1 < 2)
                    {
                        res += 1;
                        a1++;
                    }
                }
                else
                {
                    while (a1 > 2)
                    {
                        res += 1;
                        a1--;
                    }
                }

                if (a2 < 2)
                {
                    while (a2 < 2)
                    {
                        res += 1;
                        a2++;
                    }
                }
                else
                {
                    while (a2 > 2)
                    {
                        res += 1;
                        a2--;
                    }
                }

           }

            Console.WriteLine(res);
        }
    }
}

using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Text;

    public class Program
    {
        public static void Main(string[] args)
        {
            var row1 = Console.ReadLine().Split();
            var row2 = Console.ReadLine().Split();
            var row3 = Console.ReadLine().Split();
            var row4 = Console.ReadLine().Split();
            var row5 = Console.ReadLine().Split();
            int i = 0;
            int j = 0;
            var one = 0;
            var row = 0;
            var torow = 3;
            var tocol = 3;

            var matrix = new int[5, 5];

            for (i = 0; i < 5; i++)
            {
                if (int.Parse(row1[i]) == 1)
                {
                    one = i + 1;
                    row = 1;
                }
                if (int.Parse(row2[i]) == 1)
                {
                    one = i + 1;
                    row = 2;
                }
                if (int.Parse(row3[i]) == 1)
                {
                    one = i + 1;
                    row = 3;
                }
                if (int.Parse(row4[i]) == 1)
                {
                    one = i + 1;
                    row = 4;
                }
                if (int.Parse(row5[i]) == 1)
                {
                    row = 5;
                    one = i + 1;
                }
            }

            var total = (-row - torow) - (-one - tocol);
            Console.WriteLine(Math.Abs(total));
        }
    }

using System;

namespace _263A_BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] task = new string[25];
            int position = 1;

            for (int i = 0; i < 5; i++)
            {
                var mass = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                for (int j = i*5, k = 0; j < 25 & k<5; j++, k++)
                {
                task[j] = mass[k];
                }
             }

            for (int i =0; i < 25; i++)
            {
                if (task[i] == "0")
                {
                    position += 1;
                }
                else
                    break;
            }

            int caseNum = position / 5 +1;
            int caseMod = position % 5;

            if (caseMod == caseNum)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(caseNum - caseMod);

            }
        }
    }
}

using System;

namespace BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            char[,] Array = new char [5, 5];
            int count = 0;int rowindex = 0;
            int colindex = 0;

            for (int i=0;i<4;i++)
            {
                rowindex = i;
                string value = Console.ReadLine();
                if(value.Contains("1"))
                {
                    //Console.WriteLine(value.IndexOf('1'));
                    colindex = value.IndexOf('1') / 2 ;
                    break;
                }

            }

          //  Console.WriteLine(2-rowindex/2+1+2-colindex);
            Console.WriteLine(Math.Abs(rowindex-2)+ Math.Abs(colindex-2));

        }
    }
}

using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int answer = 0;

        int[][] matrix = new int[5][];

        for (int i = 0; i < 5; ++i)
        {
            matrix[i] = Console.ReadLine().Split(' ')
                .Select(s => Convert.ToInt32(s)).ToArray();
        }

        for (int i = 0; i < 5; ++i)
        {
            for (int j = 0; j < 5; ++j)
            {
                if (matrix[i][j] == 1)
                {
                    if (j - i == 0)
                    {
                        answer = 4;
                    }
                    else
                    {
                        answer = Math.Abs(j - i);
                    }
                    break;
                }
            }
        }

        Console.WriteLine(answer);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = 0;
            var result = 0;
            int matrixCount = 5;
            var count = 0;
            for (int i = 1; i <= matrixCount; i++)
            {
                string[] matrix = Console.ReadLine().Split(' ');
                count++;
                for (int z = 1; z <= matrix.Length; z++)
                {
                    if (matrix[z - 1] == "1" && i < 3)
                    {
                        x = Math.Abs(z - 3);
                        result = x + (Math.Abs(x - 3));
                    }
                    else if (matrix[z - 1] == "1" && i > 3)
                    {
                        x = Math.Abs(z - 3);
                        result = x + (Math.Abs(x - 3));
                    }
                    else if (matrix[z - 1] == "1" && i == 3)
                    {
                        x = Math.Abs(z - 3);
                        result = x + (Math.Abs(count - i));
                    }
                }
            }
            Console.WriteLine(result);
        }
    }
}

using System;

namespace _10__A._Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] arr = new int[5, 5];

            int count = 0;
            int i_ = 0;
            int j_ = 0;

            for (int i = 0; i < 5; i++)
            {

                string s = Console.ReadLine();
                string[] values = s.Split(' ');
                for (int j = 0; j < 5; j++)
                {

                arr[i, j] = int.Parse(values[j]);
                }
                Console.WriteLine();
            }

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (arr[i, j] == 1)
                    {
                        i_ = i;
                        j_ = j;
                    }
                }

            }
           // Console.WriteLine(i_ + " " + j_);

            if ((i_ < 2 && j_ <= 4)   || (i_ == 2 && j_ < 2 ))
            {

                arr[2, 2] = 1;

                for (int i = i_; i < 5; i++)
                {
                    for (int j = j_ + 1; j < 5; j++)
                    {
                        if (arr[i, j] != 1)
                        {
                            count++;
                        }
                        else if (arr[i, j] == 1)
                        {
                            count++;
                            goto rtrt;

                        }
                    }
                    break;
                }

                for (int i = i_ + 1; i < 5; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        if (arr[i, j] != 1)
                        {
                            count++;
                        }
                        else if (arr[i, j] == 1)
                        {
                            count++;
                            goto rtrt;

                        }
                    }

                }

            rtrt:
                Console.WriteLine(count);
            }

            else if(j_ !=2)
            {
                for (int i = 2; i < 5; i++)
                {
                    for (int j = 3; j < 5; j++)
                    {
                        if (arr[i, j] != 1)
                        {
                            count++;
                        }
                        else if (arr[i, j] == 1)
                        {
                            count++;
                            goto rtrt2;

                        }
                    }
                    break;
                }

                for (int i = 3; i < 5; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        if (arr[i, j] != 1)
                        {
                            count++;
                        }
                        else if (arr[i, j] == 1)
                        {
                            count++;
                            goto rtrt2;

                        }
                    }

                }

            rtrt2:
                Console.WriteLine(count);
            }
            else
            {

                Console.WriteLine(count);
            }

        }
    }
}

    class Program
    {
        static void Main(string[] args)
        {

            int x=0, y = 0;
            int[,] matrix = new int[5,5];
            System.String[] lines = System.Console.ReadLine().Split();
            matrix[0, 0] = int.Parse(lines[0]);
            matrix[0, 1] = int.Parse(lines[1]);
            matrix[0, 2] = int.Parse(lines[2]);
            matrix[0, 3] = int.Parse(lines[3]);
            matrix[0, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[1, 0] = int.Parse(lines[0]);
            matrix[1, 1] = int.Parse(lines[1]);
            matrix[1, 2] = int.Parse(lines[2]);
            matrix[1, 3] = int.Parse(lines[3]);
            matrix[1, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[2, 0] = int.Parse(lines[0]);
            matrix[2, 1] = int.Parse(lines[1]);
            matrix[2, 2] = int.Parse(lines[2]);
            matrix[2, 3] = int.Parse(lines[3]);
            matrix[2, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[3, 0] = int.Parse(lines[0]);
            matrix[3, 1] = int.Parse(lines[1]);
            matrix[3, 2] = int.Parse(lines[2]);
            matrix[3, 3] = int.Parse(lines[3]);
            matrix[3, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[4, 0] = int.Parse(lines[0]);
            matrix[4, 1] = int.Parse(lines[1]);
            matrix[4, 2] = int.Parse(lines[2]);
            matrix[4, 3] = int.Parse(lines[3]);
            matrix[4, 4] = int.Parse(lines[4]);

            for (int i = 0; i < 5; i++)
                for (int j = 0; j < 5; j++)
                {
                    if (matrix[i,j] == 1)
                        x = i;y = j;

                }
            x =System.Math.Abs( x - 3);
            y = System.Math.Abs(y - 3);
            x = x + y;
            System.Console.WriteLine(x);

        }
    }

using System;
using System.Collections.Generic;
class Program
    {
        static void Main()
        {
             string[,] matrix=new string[5,5];
            int numberOfMovement = 0;
            for (int i = 0; i < 5; i++)
            {
                string[] rowInputs = Console.ReadLine().Split(' ');
                for (int j = 0; j < 5; j++)
                {
                    matrix[i, j] = rowInputs[j];
                    if (matrix[i, j] == "1")
                    {
                        numberOfMovement = Math.Abs(3-i+1)+ Math.Abs(3 - j+1);
                    }
                }
            }

            Console.WriteLine(numberOfMovement);
        }

    }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication29
{
    class Program
    {
        static void Main()
        {
            int[,] ar = new int[5, 5];
            int k=0, c=0;
            for ( var i = 0; i<5;i++)
            {
                var t = Console.ReadLine().Split(' ');
                var arr = t.Select(int.Parse).ToArray();
                for ( var j = 0; j<5;j++)
                {
                    ar[i, j] = arr[j];
                }
            }
            for ( var i = 0; i<5;i++)
            {
                for ( var j = 0; j<5;j++)
                {
                    if (ar[i,j]==1)
                    {
                        k = i;
                        c = j;
                    }
                }

            }
            var x = Math.Abs(3 - k) + Math.Abs(3 - c);
            Console.WriteLine(x);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace code
{
    class Wight
    {

        static void Main(string[] args)
        {
            int row = 5;
            int col = 5;
            int[,] matrix1;

            int[,] newmat = new int[5, 5];

            string[] inputs = new string[5];

            matrix1 = new int[5, 5];

            for (int i = 0; i < inputs.Length; i++)
            {

                   inputs[i] = Console.ReadLine();// i have problem with this line,... plz show me the correct form
            }

            for( int i=0; i<inputs.Length;i++)
            {
               string [] nums =inputs[i].Split(' ');

                for( int j=0; j<col;j++)
                {
                    matrix1[i, j] = Convert.ToInt16(nums[j]);
                }
            }

            int count = 0;

            for( int i=0; i<row; i++)
            {
                for(int j=0; j<col; j++)
                {
                    if (matrix1[i, j]==1)
                    {
                        if(i==2 && j<2)
                        {
                            matrix1[i, j + 1] = matrix1[i, j];
                            matrix1[i, j] = 0;
                            count++;

                        }

                        else if(i==2 && j>2)
                        {
                            matrix1[i, j - 1] = matrix1[i, j];
                            matrix1[i, j] = 0;
                            count++;
                        }

                        else if(i<2 && j>2)
                        {

                            for (int k = j; k >= 2; k--)
                            {
                                matrix1[i, k- 1] = matrix1[i, k];
                                matrix1[i,k] = 0;
                                count++;
                            }

                        }

                        else if (i > 2 && j > 2)
                        {

                            matrix1[2, j] = matrix1[i, j];
                            matrix1[i, j] = 0;
                            count++;
                            for (int k = j; k >= 2; k--)
                            {

                                matrix1[i, k - 1] = matrix1[i, k];
                                matrix1[i, k] = 0;
                                count++;
                            }
                        }

                        else if (i<2 && j==2)
                        {
                            matrix1[i + 1, j] = matrix1[i, j];
                            matrix1[i, j] = 0;
                            count++;
                        }

                    }
                }

            }

            Console.WriteLine(count);

        }
    }
}

using System;
 class Program
    {

        static void Main(string[] args)
        {
            string npt = Console.In.ReadToEnd();
            int i = 0;
            for (; i < npt.Length; ++i)
             if (npt[i] == '1') break;
            npt = null;
            i = (i + 1) / 2;
            int b = i / 5+1;
            i = i % 5;
            if(i==0)
            { b--; i = 5;}
            i = Math.Abs(3 - i)+ Math.Abs(3 - b);
            Console.WriteLine(i);
        }
    }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 5; i++)
            {
                var position = Console.ReadLine().Replace(" ", "").IndexOf("1");
                if (position != -1)
                    Console.WriteLine(Math.Abs(3 - position)+Math.Abs(2 - i));
            }
        }
    }
}

using System;

namespace _263A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] matrix = new int[5, 5];
            string[] s = new string[5];
            int numI = 0, numJ = 0;

            for (int i = 0; i < 5; i++)
            {
                s[i] = Console.ReadLine();
                s[i] = s[i].Replace(" ", "");
            }

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (j == 4)
                    {
                        matrix[i, j] = Convert.ToInt32(s[i].Substring(j));
                        if (matrix[i, j] == 0)
                        {
                            numI = i;
                            numJ = j;
                        }
                    }
                    else
                    {
                        matrix[i, j] = Convert.ToInt32(s[i].Substring(j, 1));
                        if (matrix[i, j] == 0)
                        {
                            numI = i;
                            numJ = j;
                        }
                    }
                }
            }

            int numOfOperation = Math.Abs(numI - 2) + Math.Abs(numJ - 2);
            Console.WriteLine(numOfOperation);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] matrix = new int[5, 5];
            int row = 0, col = 0;
            for (int i = 0; i < 5; i++)
            {
                for(int j=0;j<5;j++)
                {
                    matrix[i, j]= (int)Console.Read();
                    Console.Read();
                }
                Console.Read();
            }
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if ( matrix[i,j] == 49)
                    {
                        row = i+1;
                        col = j+1;
                        //Console.WriteLine(row);
                        //Console.WriteLine(col);
                    }
                }
            }
            int sol = Math.Abs(-2 + row) + Math.Abs(-2 + col);
            Console.WriteLine(sol);
        }
    }
}

using System;

namespace Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {

            int y = -2;
            int x = 10;
            bool set = false;

            for (int i = 0; i < 5; i++)
            {
                if (set)
                {
                    Console.ReadLine();
                                    }
                else
                {

                    string input = Console.ReadLine().Trim();
                    if (input.Contains("1"))
                    {

                        x = input.IndexOf('1')-2;
                        set = true;
                    }
                    else
                    {
                        y++;
                    }

                }
            }

            Console.WriteLine(Math.Abs(x) + Math.Abs(y));
            Console.ReadLine();

        }
    }
}

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[][] arr = new int[5][];
            for (int i = 0; i < 5; i++)
                arr[i] = new int[5];

            for (int i = 0; i < 5; i++)
            {
                var n = Console.ReadLine();
                Console.Write(n + " ");
                //for (int j = 0; j < 5; j++)
                //{
                //    var n = Console.ReadLine();
                //    Console.Write(n + " ");
                //    //arr[i][j] =
                //}
            }

            Console.WriteLine(arr[1][2]);
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CF {
    class Program {

        static void Main(string[] args) {

#if DEBUG
            TextReader reader = new StreamReader("../../input.txt");
            TextWriter writer = Console.Out;
#else
			TextReader reader = Console.In;
            TextWriter writer = Console.Out;
#endif

            var line1 = reader.ReadLine().Replace(" ","");
            var line2 = reader.ReadLine().Replace(" ","");
            var line3 = reader.ReadLine().Replace(" ","");
            var line4 = reader.ReadLine().Replace(" ","");
            var line5 = reader.ReadLine().Replace(" ","");

            int i = 0;
            int j = 0;
            int ii = 0;

            if ((ii = line1.IndexOf('1')) > 0) {
                i = ii;
                j = 1;
                i++;
            }
            if ((ii = line2.IndexOf('1')) > 0) {
                i = ii;
                j = 2;
                i++;
            }
            if ((ii = line3.IndexOf('1')) > 0) {
                i = ii;
                j = 3;
                i++;
            }
            if ((ii = line4.IndexOf('1')) > 0) {
                i = ii;
                j = 4;
                i++;
            }
            if ((ii = line5.IndexOf('1')) > 0) {
                i = ii;
                j = 5;
                i++;
            }

            Console.WriteLine((Math.Abs(i - 3) + Math.Abs(j - 3)));

#if DEBUG
            Console.ReadKey();
#endif
        }

    }

    class Pair<T1, T2> {
        public Pair(T1 first, T2 second) {
            First = first;
            Second = second;
        }
        public T1 First { get; set; }
        public T2 Second { get; set; }
        public override string ToString() {
            return "{" + First + " " + Second + "}";
        }
    }

    static class ReaderExtensions {

        public static string ReadToken(this TextReader reader) {
            int val;
            var builder = new StringBuilder();
            while (true) {
                val = reader.Read();
                if (val == ' ' || val == -1) {
                    if (builder.Length == 0) continue;
                    break;
                }
                if (val == 13) {
                    reader.Read();
                    if (builder.Length == 0) continue;
                    break;
                }
                builder.Append((char)val);
            }
            return builder.ToString();
        }

        public static T Read<T>(this TextReader reader) {
            return (T)Convert.ChangeType(reader.ReadToken(), typeof(T));
        }

        public static T[] ReadArr<T>(this TextReader reader) {
            return reader.ReadLine()
                .Split(' ').Select(str =>
                    (T)Convert.ChangeType(str, typeof(T))
                ).ToArray();
        }

    }

    static class LinqExtensions {
        /// <summary>Value / Index</summary>
        public static IEnumerable<Pair<T, int>> SelectIndexes<T>(this IEnumerable<T> collection) {
            return collection.Select((v, i) => new Pair<T, int>(v, i));
        }
        public static IEnumerable<T> SelectValues<T>(this IEnumerable<Pair<T, int>> collection) {
            return collection.Select(p => p.First);
        }
    }

}

using System;

class Program
{
    static void Main()
    {
        for (var i = 0; i < 5; ++i)
            for(var j = 0; j < 5; ++j)
                if(Console.Read() == '1')
                    Console.WriteLine(Math.Abs(i - 2) + Math.Abs(j - 2));
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{

    class Program
    {

        static void Main(string[] args)
        {

            int[,] intarray = new int[5, 5];

            int i, j;
            double result = 0;
            for (i = 0; i < 5; i++)
            {

                string lines = Console.ReadLine();

                string[] linessplit = lines.Split(' ');

                int[] newintarray = Array.ConvertAll(linessplit, int.Parse);

                for (j = 0; j < 5; j++)
                {
                    intarray[i, j] = newintarray[j];

                }

            }

            for (i = 0; i < 5; i++)
            {
                for (j = 0; j < 5; j++)
                {
                    if (intarray[i, j] == 1)
                    {
                        int a = i - 2;
                        int workofa = a * a;

                        int b = j - 2;
                        int workofb = b * b;

                       result = Math.Sqrt(workofa + workofb);
                    }
                }

            }
            Console.WriteLine(Math.Ceiling(result));

        }
    }
}

    class Program
    {
        static void Main(string[] args)
        {

            int x=0, y = 0;
            int[,] matrix = new int[5,5];
            System.String[] lines = System.Console.ReadLine().Split();
            matrix[0, 0] = int.Parse(lines[0]);
            matrix[0, 1] = int.Parse(lines[1]);
            matrix[0, 2] = int.Parse(lines[2]);
            matrix[0, 3] = int.Parse(lines[3]);
            matrix[0, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[1, 0] = int.Parse(lines[0]);
            matrix[1, 1] = int.Parse(lines[1]);
            matrix[1, 2] = int.Parse(lines[2]);
            matrix[1, 3] = int.Parse(lines[3]);
            matrix[1, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[2, 0] = int.Parse(lines[0]);
            matrix[2, 1] = int.Parse(lines[1]);
            matrix[2, 2] = int.Parse(lines[2]);
            matrix[2, 3] = int.Parse(lines[3]);
            matrix[2, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[3, 0] = int.Parse(lines[0]);
            matrix[3, 1] = int.Parse(lines[1]);
            matrix[3, 2] = int.Parse(lines[2]);
            matrix[3, 3] = int.Parse(lines[3]);
            matrix[3, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[4, 0] = int.Parse(lines[0]);
            matrix[4, 1] = int.Parse(lines[1]);
            matrix[4, 2] = int.Parse(lines[2]);
            matrix[4, 3] = int.Parse(lines[3]);
            matrix[4, 4] = int.Parse(lines[4]);

            for (int i = 0; i < 5; i++)
                for (int j = 0; j < 5; j++)
                {
                    if (matrix[i, j] == 1)
                    {
                        x = i;
                        y = j;
                    }
                }
            if (x == 0 && y == 0)
                System.Console.WriteLine(4);
            else if (x == 0 && y == 4)
                System.Console.WriteLine(4);
            else if (x == 4 && y == 0)
                System.Console.WriteLine(4);
            else if (x == 4 && y == 4)
                System.Console.WriteLine(4);
            /////////////////////////////////////
            else if (x == 2 && y == 0)
                System.Console.WriteLine(2);
            else if (x == 0 && y == 2)
                System.Console.WriteLine(2);
            else if (x == 4 && y == 2)
                System.Console.WriteLine(2);
            else if (x == 2 && y == 4)
                System.Console.WriteLine(2);
            else if (x == 1 && y == 3)
                System.Console.WriteLine(2);
            else if (x == 3 && y == 1)
                System.Console.WriteLine(2);
            else if (x == 1 && y == 1)
                System.Console.WriteLine(2);
            else if (x == 3 && y == 3)
                System.Console.WriteLine(2);

            ////////////////////////////////////////////////////////////////////
            else if (x == 0 && y == 1)
                System.Console.WriteLine(3);
            else if (x == 1 && y == 0)
                System.Console.WriteLine(3);
            else if (x == 4 && y == 1)
                System.Console.WriteLine(3);
            else if (x == 1 && y == 4)
                System.Console.WriteLine(3);
            else if (x == 0 && y == 3)
                System.Console.WriteLine(3);
            else if (x == 3 && y == 0)
                System.Console.WriteLine(3);
            else if (x == 4 && y == 3)
                System.Console.WriteLine(3);
            else if (x == 3 && y == 4)
                System.Console.WriteLine(3);
            else if (x == 3 && y == 3)
                System.Console.WriteLine(0);
            ////////////////////////////////////////////
            else
                System.Console.WriteLine(1);

        }
    }

using System;
class Program
{
    static void Main()
    {
        int d = 0;
        for (int i = 1; i <= 5; i++)
        {
            var m = Console.ReadLine().Replace(" ", "");
            if ((d = m.IndexOf('1')) > 0)
            {
                d++;
                d *= i;
                break;
            }
        }
        Console.WriteLine(Math.Abs(13 - d));
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PS
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            string[] strArr;
            int x = 0 , y = 0 ;
            for (int i = 0; i < 5; ++i)
            {
               str = Console.ReadLine();
               strArr = str.Split(' ');
               for (int j = 0; j < 5; ++j)
                   if (strArr[j] == "1")
                   {
                       x= i;
                       y= j;
                   }
            }
            Console.WriteLine(Math.Abs(2 - x + Math.Abs(2 - y)));

        }
    }
}

using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int answer = 0;

        int[][] matrix = new int[5][];

        for (int i = 0; i < 5; ++i)
        {
            matrix[i] = Console.ReadLine().Split(' ')
                .Select(s => Convert.ToInt32(s)).ToArray();
        }

        for (int i = 0; i < 5; ++i)
        {
            for (int j = 0; j < 5; ++j)
            {
                if (matrix[i][j] == 1)
                {
                    if (j - i == 0 && (j != 3 && i != 3))
                    {
                        answer = 4;
                    }
                    else
                    {
                        answer = Math.Abs(j - i);
                    }
                    break;
                }
            }
        }

        Console.WriteLine(answer);
    }
}

using System;
using System.Linq;

namespace Practise_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int LuuX = 0, LuuY = 0;
            for (var i = 0; i < 5; i++)
            {
                string[] Temp = Console.ReadLine().Split(' ');
                for (var j = 0; j < 5; j++)
                {
                    if(Temp[j] == "1")
                    {
                        LuuX = i;
                        LuuY = j;
                        break;
                    }
                }
            }
            Console.WriteLine(Math.Abs(3 - LuuX) + Math.Abs(3 - LuuY));
        }
    }
}

using System;

namespace _263A___Beautiful_Matrix
{
	class Program
	{
		static void Main(string[] args)
		{
			Matrixen();
		}

		private static void Matrixen()
		{
			Tuple<int, int> coords = GetCoords();
			int steps = Math.Abs(coords.Item1 - 3) + Math.Abs(coords.Item2 - 3);

			Console.WriteLine(steps);
		}

		private static Tuple<int, int> GetCoords()
		{
			for (int y = 0; y < 5; y++)
			{
				string[] line = Console.ReadLine().Split(' ');

				for (int x = 0; x < 5; x++)
					if (line[x] == "1")
						return new Tuple<int, int>(x, y);
			}

			return new Tuple<int, int>(0, 0);
		}
	}
}

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            String a;
            int output=0;
            for (int x = 0; x < 5; x++)
            {
                 a = Console.ReadLine();
                 string[] words = a.Split(' ');
                 for (int y = 0; y < 5; y++)
                 {
                     if (words[y] == "1")
                     {
                         output = x % 2 + y % 2;
                     }
                 }
            }

            Console.WriteLine(output);

        }
    }
}

using System;
class CFR161D2
{
    static void Main()
    {
        Console.WriteLine(GetRes());
    }

    static int GetRes()
    {
        int res = 0;
        string[] line;
        for (int i = 0; i < 5; i++)
        {
            line = Console.ReadLine().Split(' ');
            for (int j = 0; j < 5; j++)
            {
                if (line[j] == "1")
                {
                    res = Math.Abs(2-j) + Math.Abs(2-j);
                    return res;
                }
            }
        }
        return res;
    }
}

using System;
using System.Linq;

namespace Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            int columna = 2, fila = 0;
            for (int i = 0; i < 5; i++)
            {
                var matriz = Console.ReadLine().Split(' ');

                if (matriz.Contains("1"))
                {
                    Console.Write(columna+Math.Abs(Array.IndexOf(matriz, "1")-2));
                }
                columna--;
                if (i > 2)
                    columna += 2;
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fun
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            List<string> lines = new List<string>();
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));

            int ans = 0;
            for (int i = 0; i < 5; i++)
            {
                if (lines[i].Contains('1'))
                {
                    if (i < 3)
                        ans += 3 - i;
                    else
                        ans += 5 - i;

                    string s = lines[i];
                    for (int l = 0; l < 5; l++)
                    {
                        if (s[l] == '1')
                        {
                            if (l < 3)
                                ans += 3 - l;
                            else
                                ans += 5 - l;
                        }
                    }
                }

            }

                Console.WriteLine(ans);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
           int[,] array = new int[4,4];

           var result = 0;

           var arrayLength = array.GetLength(0);

           for (int i = 0; i < arrayLength; i++)
           {
               var line = ParseString(Console.ReadLine());

               for (int j = 0; j < arrayLength; j++)
               {
                   var number = line[j];
                   array[i, j] = number;

                   if (number == 1)
                   {
                       result = Calc(i) + Calc(j);
                   }
               }
           }

           Console.WriteLine(result);
        }

        static int Calc(int index)
        {
            switch (index)
            {
                case 0: return 2;
                case 1: return 1;
                case 2: return 0;
                case 3: return 1;
                case 4: return 2;
                default: throw new Exception();
            }
        }

        static int[] ParseString(string line)
        {
            var result = line.Split(' ').Select(int.Parse).ToArray();

            return result;
        }
    }
}

using System;

namespace Coding_challengfes
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] matrix = new string[5];
            int r = 0;
            int z = 0;
            int menge = 0;

            for(int i = 0; i< 5; i ++)
            {
                matrix[i] = Console.ReadLine();
            }

            for(int i = 0; i < 5; i++)
            {
                if (matrix[i].Contains("1"))
                {
                    z = i+1;
                }
            }

            string[] reihe = matrix[z].Split(" ");

            for (int i = 0; i < 5; i++)
            {
                if (reihe[i] == "1")
                {
                    r = i+1;
                }
            }

            if(r != 3)
            {
                if(r > 3)
                {
                    menge += r - 3;
                }
                else
                {
                    menge += 3 - r;
                }
            }

            if (z != 3)
            {
                if (z > 3)
                {
                    menge += z - 3;
                }
                else
                {
                    menge += 3 - z;
                }
            }

            Console.WriteLine(menge);
        }
    }
}

using System;
using System.Linq;
using System.Text;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var first = Console.ReadLine().Replace(" ", "");
            var second = Console.ReadLine().Replace(" ", "");
            var third = Console.ReadLine().Replace(" ", "");
            var fourth = Console.ReadLine().Replace(" ", "");
            var fifth = Console.ReadLine().Replace(" ", "");

            const string one = "1";

            var counter = 0;
            if (first.Contains(one))
            {
                counter += 2;
                counter = Math.Abs(first.IndexOf("1", StringComparison.CurrentCulture) - 3);
            }
            else if (second.Contains(one))
            {
                counter += 1;
                counter = Math.Abs(second.IndexOf("1", StringComparison.CurrentCulture) - 3);
            }
            else if (third.Contains(one))
            {
                counter = Math.Abs(third.IndexOf("1", StringComparison.CurrentCulture) - 3);
            }
            else if (fourth.Contains(one))
            {
                counter += 1;
                counter = Math.Abs(fourth.IndexOf("1", StringComparison.CurrentCulture) - 3);
            }
            else
            {
                counter += 2;
                counter = Math.Abs(fifth.IndexOf("1", StringComparison.CurrentCulture) - 3);
            }

            Console.WriteLine(counter);
        }

    }
}

using System;
using System.Collections.Specialized;
using System.Runtime.CompilerServices;
using System.Threading;

namespace ConsoleApp2
{
    class Program
    {
        static int InputN()
        {
            int num = int.Parse(Console.ReadLine());
            return num;
        }
        static string InputS()
        {
            string str = Console.ReadLine();
            return str;
        }
        static void Main(string[] args)
        {
            string s = "";
            for (int i = 0; i < 4; i++)
            {
                s += InputS() + " ";
            }
            s = s.Replace(" ", "");
            int PlaceOne = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '1')
                {
                    PlaceOne = i+1;
                }
            }
            Console.WriteLine(13 - PlaceOne);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fun
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            List<string> lines = new List<string>();
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));
            lines.Add(Console.ReadLine().Replace(" ", ""));

            int ans = 0;
            for (int i = 0; i < 5; i++)
            {
                if (lines[i].Contains('1'))
                {
                    if (i < 2)
                        ans += 2 - i+1;
                    else if(i>2)
                        ans += 4 - i-1;

                    string s = lines[i];
                    for (int l = 0; l < 5; l++)
                    {
                        if (s[l] == '1')
                        {
                            if (l < 2)
                                ans += 2 - l+1;
                            else if(l > 2)
                                ans += 4 - l-1;
                        }
                    }
                }

            }

                Console.WriteLine(ans);
        }
    }
}

using System;

namespace Practise_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] Input = new int[5, 5];
            int LuuX = 0, LuuY = 0;
            for (var i = 0; i < 5; i++)
            {
                for(var j = 0; j < 5; j++)
                {
                    Input[i, j] = Convert.ToInt32(Console.Read());
                    if(Input[i,j] == 1)
                    {
                        LuuX = i;
                        LuuY = j;
                    }
                }
            }
            Console.WriteLine(Math.Abs(3-LuuX)+Math.Abs(3-LuuY));
        }
    }
}

using System;
using System.Linq;

namespace CodeForce
{
    class Program
    {
        static void Check(int value, ref int counter)
        {
            if (value > 3)
            {
                while (value > 3)
                {
                    value--;
                    counter++;
                }
            }
            else if (value < 3)
            {
                while (value < 3)
                {
                    value++;
                    counter++;
                }
            }
        }
        static void Main(string[] args)
        {
            int[][] matrix = new int[5][];
            for (int i = 0; i < matrix.Length; i++)
                matrix[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int raw = 0, column = 0;
            int counter = 0;

            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < matrix[i].Length; j++)
                {
                    if (matrix[i][j] == 1)
                    {
                        raw = i;
                        column = j;
                    }

                }
            }

            Check(raw, ref counter);
            Check(column, ref counter);

            Console.WriteLine(counter);
        }
    }
}

using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int answer = 0;

        int[][] matrix = new int[5][];

        for (int i = 0; i < 5; ++i)
        {
            matrix[i] = Console.ReadLine().Split(' ')
                .Select(s => Convert.ToInt32(s)).ToArray();
        }

        for (int i = 0; i < 5; ++i)
        {
            for (int j = 0; j < 5; ++j)
            {
                if (matrix[i][j] == 1)
                {
                    answer = Math.Abs(j - i);
                    break;
                }
            }
        }

        Console.WriteLine(answer);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static int[] ReadInt(int size)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] res = new int[size];
            for (int i=0; i<input.Length; i++)
            {
                res[i] = Convert.ToInt32(input[i]);
            }
            return res;
        }

        static int ReadInt()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            return n;
        }

        static String ReadString()
        {
            return Console.ReadLine();
        }

        static int Max(int a, int b)
        {
            return (a > b ? a : b);
        }

        static void WL<T> (T s)
        {
            Console.WriteLine(s);
        }

        static bool isLucky(int n)
        {
            String temp = n.ToString();
            char[] charArray = { '0', '1', '2', '3', '5', '6', '8', '9' };
            return !(temp.IndexOfAny(charArray) > -1);
        }

        static int GCD(int a, int b)
        {
            if (a < b)
            {
                int temp = a;
                a = b;
                b = temp;
            }
            while (b > 0)
            {
                if (a > b) a -= b;
                else b -= a;
            }
            return a;
        }

        static void Main(string[] args)
        {
            int row = 0, column = 0;
            for (int i = 1; i <= 5; i++)
            {
                String input = Console.ReadLine();
                input = input.Trim(' ');
                int temp = input.IndexOf('1');
                if (temp > -1)
                {
                    row = i;
                    column = temp + 1;
                    break;
                }
            }
            WL(Math.Abs(row - 3) + Math.Abs(column - 3));
        }
    }
}

using System;

namespace _263A_BeautifulMatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] task = new string[25];
            int position = 1;

            for (int i = 0; i < 5; i++)
            {
                var mass = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                for (int j = i*5, k = 0; j < 25 & k<5; j++, k++)
                {
                task[j] = mass[k];
                }
             }

            for (int i =0; i < 25; i++)
            {
                if (task[i] == "0")
                {
                    position += 1;
                }
                else
                    break;
            }

            double caseNum = Math.Ceiling(position / 5.0);
            int caseMod = position % 5;
            if (caseMod == 0)
            {
                caseMod = 5;
            }

            if (position == 14)
            {
                Console.WriteLine(0);
            }
            else if(caseMod == 3)
            {
                Console.WriteLine(caseNum - caseMod);

            }
            else
            {
                caseNum = Math.Abs(caseNum - 3) + Math.Abs(caseMod - 3);
                Console.WriteLine(caseNum);
            }
        }
    }
}

using System;
using System.Linq;

namespace codeforces_console_app
{
    class Program
    {
        static void Main(string[] args)
        {
            var counter = 0;
            var rowLoc = 0;
            var colLoc = 0;
            while (counter < 5)
            {
                var input = Console.ReadLine();
                if (input.Any(s => s == '1')){
                    rowLoc = counter;
                    colLoc = Array.IndexOf(input.Split(null), '1');
                }

                counter++;
            }

            var rowMoves = rowLoc <= 2 ? 2 - rowLoc : rowLoc - 2;
            var colMoves = colLoc <= 2 ? 2 - colLoc : colLoc - 2;

            Console.WriteLine(rowMoves + colMoves);
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KrasivMatr
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] matr = new int[5, 5];
            int k=0;
            int l = 0;
            for (int i = 0; i < 5; i++)
            {
                string str = Console.ReadLine();
                if (str.Contains('1'))
                    for (int j = 0; j < str.Length; j+=2)
                    {
                        if (str[j]=='1')
                        {
                            matr[i, j / 2] = 1;
                            k = i;
                            l = j / 2;
                        }
                    }
            }
            k = Math.Abs(k - 3);
            l = Math.Abs(l - 3);
            Console.WriteLine(k + l);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = 5;
            var res = 0;
            while (t-- > 0) {
                var array = Console.ReadLine().Split(' ');
                var liste = new List<int>();

                foreach (var q in array) { liste.Add(int.Parse(q)); }

                if (liste.Contains(1)) { res += Math.Abs(t-3)+ Math.Abs(3 - liste.IndexOf(1));   }
            }
            Console.WriteLine(res);
            Console.ReadLine();
        }
    }
}

    class Program
    {
        static void Main(string[] args)
        {

            int x=0, y = 0;
            int[,] matrix = new int[5,5];
            System.String[] lines = System.Console.ReadLine().Split();
            matrix[0, 0] = int.Parse(lines[0]);
            matrix[0, 1] = int.Parse(lines[1]);
            matrix[0, 2] = int.Parse(lines[2]);
            matrix[0, 3] = int.Parse(lines[3]);
            matrix[0, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[1, 0] = int.Parse(lines[0]);
            matrix[1, 1] = int.Parse(lines[1]);
            matrix[1, 2] = int.Parse(lines[2]);
            matrix[1, 3] = int.Parse(lines[3]);
            matrix[1, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[2, 0] = int.Parse(lines[0]);
            matrix[2, 1] = int.Parse(lines[1]);
            matrix[2, 2] = int.Parse(lines[2]);
            matrix[2, 3] = int.Parse(lines[3]);
            matrix[2, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[3, 0] = int.Parse(lines[0]);
            matrix[3, 1] = int.Parse(lines[1]);
            matrix[3, 2] = int.Parse(lines[2]);
            matrix[3, 3] = int.Parse(lines[3]);
            matrix[3, 4] = int.Parse(lines[4]);

            lines = System.Console.ReadLine().Split();
            matrix[4, 0] = int.Parse(lines[0]);
            matrix[4, 1] = int.Parse(lines[1]);
            matrix[4, 2] = int.Parse(lines[2]);
            matrix[4, 3] = int.Parse(lines[3]);
            matrix[4, 4] = int.Parse(lines[4]);

            for (int i = 0; i < 5; i++)
                for (int j = 0; j < 5; j++)
                {
                    if (matrix[i,j] == 1)
                        x = i;y = j;
                }
            if (x == 0 && y == 0)
                System.Console.WriteLine(4);
            else if (x == 0 && y == 4)
                System.Console.WriteLine(4);
            else if (x == 4 && y == 0)
                System.Console.WriteLine(4);
            else if (x == 4 && y == 4)
                System.Console.WriteLine(4);
            /////////////////////////////////////
            else if (x == 2 && y == 0)
                System.Console.WriteLine(2);
            else if (x == 0 && y == 2)
                System.Console.WriteLine(2);
            else if (x == 4 && y == 2)
                System.Console.WriteLine(2);
            else if (x == 2 && y == 4)
                System.Console.WriteLine(2);
            else if(x == 1 && y == 3)
                System.Console.WriteLine(2);
            else if (x == 3 && y == 1)
                System.Console.WriteLine(2);
            else if (x == 1 && y == 1)
                System.Console.WriteLine(2);
            else if (x == 3 && y == 3)
                System.Console.WriteLine(2);

            ////////////////////////////////////////////////////////////////////
            else if (x == 0 && y == 1)
                System.Console.WriteLine(3);
            else if (x == 1 && y == 0)
                System.Console.WriteLine(3);
            else if (x == 4 && y == 1)
                System.Console.WriteLine(3);
            else if (x == 1 && y == 4)
                System.Console.WriteLine(3);
            else if (x == 0 && y == 3)
                System.Console.WriteLine(3);
            else if (x == 3 && y == 0)
                System.Console.WriteLine(3);
            else if (x == 4 && y == 3)
                System.Console.WriteLine(3);
            else if (x ==3 && y == 4)
                System.Console.WriteLine(3);
            ////////////////////////////////////////////
            else
                System.Console.WriteLine(1);

        }
    }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace ConsoleApplication1
{
    class Program
    {
        public static int x, y;
        public static void Beatiful_Matrix()
        {
            int[,] a = new int[5, 5];
            int mov = 0;

            for (int i = 0; i < 5; i++)
            {
                string s = Console.ReadLine();
                string [] ss = s.Split(' ');
                for (int j = 0; j < 5; j++)
                {
                    a[i, j] = Convert.ToInt32(ss[j]);
                    if (a[i, j] == 1)
                    {
                        x = i;
                        y = i;
                    }
                }
            }

            int z = x - 2;
            int e = y - 2;
            if (z < 0)
                z *= -1;
            if (e < 0)
                e *= -1;
            mov = e + z;
            Console.WriteLine(mov);
        }
        static void Main(string[] args)
        {
            Beatiful_Matrix();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Beautiful_Matrix
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] matrix = new int[5, 5];
            int row = 0, col = 0;
            for (int i = 0; i < 5; i++)
            {
                for(int j=0;j<5;j++)
                {
                    matrix[i, j]= (int)Console.Read();
                    Console.Read();
                }
                Console.Read();
            }
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if ( matrix[i,j] == 49)
                    {
                        row = i+1;
                        col = j+1;
                        //Console.WriteLine(row);
                        //Console.WriteLine(col);
                    }
                }
            }
            if (row == 3 && col == 3)
                Console.WriteLine(0);
            else
            {
                int sol = Math.Abs(-2 + row) + Math.Abs(-2 + col);
                Console.WriteLine(sol);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace beautifulmatrix
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j, num = 0 ;
            int[,] matrix = new int [5, 5];
            for (i = 0; i < 5; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                for (j = 0; j < 5; j++)
                {
                    matrix[i, j] = Int32.Parse(input[j]);
                    if(matrix[i,j]==1)
                    {
                        num=Math.Abs(6 - i - j);
                    }

                }
            }
            Console.WriteLine(num);
           // Console.ReadLine();

        }
    }
}

using System;
using System.Linq;

namespace SOLID
{
    class Program
    {
        public static void Main(string[] args)
        {
            string[] input = new string[5];
            int[,] matrix = new int[5, 5];
            int oneX = -1, oneY = -1, answer = -1;

            for (int i = 0; i < 5; i++)
            {
                input[i] = Console.ReadLine();
            }
            for (int i = 0; i < 5; i++)
            {
                input[i] = input[i].Replace(" ", "");
                for (int j = 0; j < 5; j++)
                {
                    matrix[i, j] = (input[i][j]) - '0';
                    if (input[i][j] - '0' == 1)
                    {
                        oneX = i;
                        oneY = j;
                    }
                }
            }

            answer = (Math.Abs(2 - oneX) + Math.Abs(2 - oneY));

        }
    }
}