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.

var coordinates = {
    row: -1,
    col: -1
};
for (var i = 0; i < 5; i++) {
    var line = readline();
    var unitIndex = -1;
    for (var j = 0; j < line.length; j += 2) {
        if (line[j] === "1") {
            unitIndex = Math.floor(j/2);
            break;
        }
    }

    if (unitIndex !== -1) {
        coordinates.row = i;
        coordinates.col = unitIndex;
        break;
    }
}

print(Math.abs(coordinates.row - 2) + Math.abs(coordinates.col - 2));

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  var T = 5;
  var arr = [];
  var ans = 0;
  while (T--) {
    var row = readLine().split(" ").map(Number);
    arr.push(row);
  }
  for (let row = 0; row < 5; row++) {
    for (let col = 0; col < 5; col++) {
      if (arr[row][col] === 1) {
        ans = Math.abs(2 - row) + Math.abs(2 - col);
      }
    }
  }
  console.log(ans);
}

let fs = require("fs")

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
})

for (let index = 0; index < txt.length; index += 5) {
    let tab = []
    for (let i = index; i < index + 5; i++) {
        tab.push(...txt[i].split(" ").filter(data => {
            return data.length > 0
        }).map(data => {
            return data * 1
        }))
    }
    football(tab)
}

function football(tab) {
    let pos = tab.indexOf(1);
    console.log(Math.abs(2 - Math.floor(pos / 5)) + Math.abs(2 - pos % 5));

}

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

let matrix = [], location = [];

rl.on('line', n => {
  matrix.push(n.split(' ').map(Number));
  if (matrix.length === 5) {
    for (let i = 0; i < matrix.length; i++) {
      if (matrix[i].includes(1)) {
        location.push(i, matrix[i].indexOf(1));
        break;
      }
    }

    console.log(Math.abs(location[0] - 2) + Math.abs(location[1] - 2));
    rl.close();
  }
});

var m = []
var c = []
var v = 0

for (i = 0; i < 5; i++) {
    m.push(readline().split(" "));
    if (m[i].includes("1")){
        v = Math.abs(2 - i) + Math.abs(2 - m[i].indexOf("1"))
    }
}

print(v)

var x = -1, y;
for (var i = 0; i < 5; i++) {
    if (x > -1) {
        readline();
        continue;
    }
    var l = readline().split(' ');
    x = l.indexOf('1');
    if (x > -1) {
        y = i;
    }
}
print(Math.abs(x - 2) + Math.abs(y - 2));

function readNums() {
    return readline().split(' ').map(v => v - 0);
}

var x = [readline().split(" ").map(x => parseInt(x))];
x[1] = readline().split(" ").map(x => parseInt(x));
x[2] = readline().split(" ").map(x => parseInt(x));
x[3] = readline().split(" ").map(x => parseInt(x));
x[4] = readline().split(" ").map(x => parseInt(x));

var i,j;
caught:
for( i = 0; i< x.length; i++) {
	for( j=0; j< x[i].length; j++) {
		if(x[i][j] === 1) {
			break caught;
		}
	}
}
print (Math.abs(2-i) + Math.abs(2-j))

const readline = require('readline');

const rl = readline.createInterface({
   input: process.stdin,
   output: process.stdout
});

let data = [];
rl.on('line', (input) => {
   data.push(input);
});

rl.on('close', () => {
   solve(data);
});

function solve(data) {

   let row, col;
   for (let i = 0; i < data.length; i++) {
      line = data[i].split(" ");
      for (let j = 0; j < line.length; j++) {
         if (line[j] === "1") {
            row = i + 1;
            col = j + 1;
         }
      }
   }

   console.log(Math.abs((3-row)) + Math.abs((3-col)));

}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  let n = 0;
  // input
  for (let i = 0; i < 5; i++) {
    const row = readline().split(' ').map(x => parseInt(x));
    const offsetX = row.indexOf(1);
    if (offsetX > -1) {
      n = Math.abs(offsetX - 2) + Math.abs(i - 2);
    }
  }

  // output
  print(n);
}

function findElem() {
    for (var i=0; i < 5; i++) {
        var myArray = readline().split(' ');
        if (myArray.indexOf('1') !== -1) {
            for (var j=0; j<5; j++) {
                if (myArray[j]==='1') {
                    return [i+1, j+1]
                }
            }
        }
    }
}

var result = findElem();
result = Math.abs(result[0]-3)+Math.abs(result[1]-3)
print(result)

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

let y = 1;

rl.on('line', (m) => {
    let x = m.split(' ').map(Number).indexOf(1);

    if (x !== -1) {
        console.log(Math.abs(x + 1 - 3) + Math.abs(y - 3));
    }

    y++;
});

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var input = [];
rl.on('line', function (line) {input.push(line);});
rl.on('close', function() {
  for (let i = 0; i < input.length; i++) {
    const newArray = input[i].split(' ');
    input[i] = newArray;
  }

//   console.log(input);

  for (let i = 0; i < input.length; i++) {
    for (let j = 0; j < input[i].length; j++) {
      if (input[i][j] === '1') {
        // 2
        let x = Math.abs(j - 2);
        let y = Math.abs(i - 2);
        // console.log(i+1,j+1);
        console.log(x + y)
      }
    }
  }
});

a1=readline().split(' ');
a2=readline().split(' ');
a3=readline().split(' ');
a4=readline().split(' ');
a5=readline().split(' ');

var array=[a1, a2, a3, a4, a5], counter=0;

for (y=0; y<5; y++) {
  for (x=0; x<5; x++) {
    if (array[y][x]==1) {counter=Math.abs(2-x) + Math.abs(2-y)}
  }
}

print(counter)

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function abs(x) {
    return x < 0 ? -x : x;
}

function solve() {
    let n = 5;
    let data = []
    for (let i = 0; i < n; i++) {
        let l = readLine();
        let d = l.split(' ');
        let len = d.length;
        let row = []
        for (let j = 0; j < len; j++)
            row.push(d[j] == "1" ? 1 : 0);
        data.push(row);
    }

    let x = 0, y = 0;
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < n; j++) {
            if (data[i][j] == 1) {
                x = j;
                y = i;
            }
        }
    }

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

function main() {
    console.log(solve());
}

var x = 0;
var y = 0;
for (var i = 0; i < 5; i++) {
    var row = readline().split(' ');
    for (var j = 0; j < 5; j++) {
        if (+row[j] === 1) {
            y = i;
            x = j;
            break;
        }
    }
}
var ans = Math.abs(y - 2) + Math.abs(x - 2);
print(ans);

var count = 0;
for (var i = 1; i < 6; i++) {
  var matrix = readline().split(" ");
  for (var j = 0; j < 5; j++) {
    if (matrix[j] == 1) {

      print(Math.abs(3 - i) + Math.abs(3 - (j + 1)));
      count = 1;
    }
    if (count == 1)
      break;
  }

}

var one=[readline(),readline(),readline(),readline(),readline()].join('').replace(/\s/g, '');

one=one.indexOf('1');
/* var row=Math.abs((one/5)-2);
var column =Math.abs(one%5-2); */
var row=parseInt(one/5);
var column =one%5;
print(Math.abs(row-2)+Math.abs(column-2));

// Generated by CoffeeScript 2.5.1
var find, lines, mainAux, numMoves, print, readline, rl, rli, sum, write;

rl = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

print = console.log;

write = function(...args) {
  return process.stdout.write(args.join(' '));
};

lines = [];

rl.on('line', function(line) {
  return lines.push(line);
});

rl.on('close', main);

rli = 0;

readline = function() {
  return lines[rli++];
};

sum = function(items) {
  return items.reduce((function(a, b) {
    return a + b;
  }), 0);
};

find = function(input) {
  return [
    input.find((inp) => {
      return inp.includes('1');
    }).split(' ').findIndex((str) => {
      return str === '1';
    }),
    input.findIndex((inp) => {
      return inp.includes('1');
    })
  ];
};

numMoves = function(v) {
  return Math.abs(2 - v);
};

mainAux = function() {
  var input;
  input = [];
  input.push(readline());
  input.push(readline());
  input.push(readline());
  input.push(readline());
  input.push(readline());
  return print(sum(find(input).map(function(v) {
    return numMoves(v);
  })));
};

  function main() {
    return mainAux();
  }
;

//# sourceMappingURL=matrix.js.map

var result = 0;
for(var i = 0; i < 5; i++) {
    var position = readline().replace(/ /g, "").indexOf("1") + 1;

    if(position) {
        result = +`${position - 3}`.replace("-", "") + +`${(i - 2)}`.replace("-", "");
    }
}

print(result);

for(var i = 0; i<5; i++){
    var j = readline().split(' ').indexOf('1');
    if(j>-1){
        break;
    }
}

print( Math.abs(2-i)+Math.abs(2-j) );

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  input.forEach( (line , i) => {
    line.split(' ').forEach( (x, j) => {
      if (x === '1') {
        console.log(
          Math.abs(2-i) + Math.abs(2-j)
        );
        process.exit();
      }
    });
  });
});

var x = 0;
var y = 0;

var found = false;
var line = readline()
while(line != null && !found){
    var lineSplitted = line.split(' ')
    for(var i = 0; i < lineSplitted.length; i++){
        if(lineSplitted[i] == "1"){
            y = i;
            found = true;
            break;
        }
    }

    if(found) break;
    x++;
    line = readline()
}

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

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
})

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
  data = data.split('\n');
  let count = 0;
  let idx = 0;
  let i;
  for (i = 0; i < data.length; i += 1) {
    idx = data[i].indexOf(1);
    if (idx >= 0) {
      idx /= 2;
      break;
    }
  }
  count = Math.abs(idx - 2) + Math.abs(i - 2);
  process.stdout.write(count + '');
}

var matrix = [];

function moves(matrix) {
	for ( var i = 0; i < 5; i++) {
		for (var j = 0; j < 5; j++){
			if (matrix[i][j] == "1") {
				return Math.abs(i - 2) + Math.abs(j - 2);
			}
		}
	}
}

for (var i = 0; i < 5; i++) {
	matrix.push(readline().split(' '));
}

print(moves(matrix));

function main() {
    // write code here:
    var arr=stdin.splice('\n').map(a => a.split(' '));
    for(let i=0;i<arr.length;i++){
        for(let j=0;j<arr[i].length;j++){
            if(arr[i][j]==='1'){
                var step=Math.abs(i-2)+Math.abs(j-2);
            }
        }
    }
    console.log(step);

}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {stdin.push(line);});
rl.on('close', main);

      function swap(arr, i, j) {
        var temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
      }
      var lines,
        multiArray = [],
        counter = 0;
      for (var i = 0; i < 5; i++) {
        lines = readline()
          .split(" ")
          .map((el) => parseInt(el));
        multiArray.push(lines);
      }
      for (var i = 0; i < 5; i++) {
        for (var j = 0; j < 5; j++) {
          if (multiArray[2][2] == 1) {
            break;
          }
          if (multiArray[2][j] == 1 && multiArray[2][2] != 1) {
            if (j < 2) {
              swap(multiArray[2], j, j + 1);
              counter++;
            } else if (j > 2) {
              swap(multiArray[2], j, j - 1);
              counter++;
            }
            if (multiArray[2][2] == 1) {
              break;
            }
          }
          if (multiArray[i][j] == 1) {
            if (i < 2) {
              swap(multiArray, i, i + 1);
              counter++;
              i = 0;
            }
            if (i > 2) {
              swap(multiArray, i, i - 1);
              counter++;
              i = 0;
            }
          }
        }
        if (multiArray[2][2] == 1) {
          break;
        }
      }
      print(counter);

var a = [];

var x = 1;
var y = 1;

for (var i = 0; i < 5; i++) {
   var tx = readline().split(' ').indexOf('1');
   if ( tx != -1) {
      x += tx;
      y += i;
      break;
   }
}

print(Math.abs(3 - x) + Math.abs(3 - y));

const readline = require('readline');

let inputs = [];

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', lineInput => {
    inputs.push(lineInput)
})

rl.on('close', () => {

    let arr = [];
    let bestPosition = [2, 2];

    for (let i = 0; i < inputs.length; i++) {
        const subArr = inputs[i].split(' ');
        arr.push(subArr);
    }

    // Get The position of 1
    let currentPositon = [];
    for (let i = 0; i < arr.length; i++) {

        for (let j = 0; j < arr[i].length; j++) {
            if (arr[i][j] == 1)
                currentPositon.push(i, j);
        }
    }

    // Get the max number that needs minimum steps

    const rowSteps = currentPositon[0] - bestPosition[0];
    const colSteps = currentPositon[1] - bestPosition[1];
    const minimumSteps = Math.abs(colSteps) + Math.abs(rowSteps);

    console.log(minimumSteps);

})

function bautifulMartix(matrix) {
  // determine the location of the current 1 point
  let coordinates = [];
  for (let row = 0; row < matrix.length; row++) {
    for (let col = 0; col < matrix[row].length; col++) {
      if (matrix[row][col] == "1") {
        coordinates.push(row);
        coordinates.push(col);
      }
    }
  }
  console.log(Math.abs(coordinates[0] - 2) + Math.abs(coordinates[1] - 2));
}

const readline = require("readline");
// Create readline Interface
let inputs = [];
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
rl.on("line", (lineInput) => {
  inputs.push(lineInput);
});
rl.on("close", () => {
  // call the function
  let matrix = [];
  inputs.forEach(function (el) {
    matrix.push(el.split(" "));
  });
  bautifulMartix(matrix);
});

var c = 0;
for (var i=1; i<6; i++){
	var str =readline().split(" ");
	for (var j=0; j<5; j++){
		if (str[j]==1){

			print(Math.abs(3-i)+ Math.abs(3-(j+1)));
			c=1;
		}
		if (c==1)
		break;
	}

}

const readline = require("readline")

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

//init
let tempi = 0;
let tempj = 0;
let columnCounter = 0;
let rowCounter = 0;

let inputCounterRow = 0;

rl.on('line', input => {
        inputCounterRow++;
        let array = input.split(" ").map(Number);
        for(let j = 0; j < 5; j++){
            if(array[j] === 1){
                tempi = inputCounterRow - 1;
                tempj = j;

                //j loop row counter
                while( tempj != 2){
                    if(tempj > 2)
                        tempj--;
                    else
                        tempj++;

                    rowCounter++;
                }
                //j loop column counter.
                while(tempi != 2){
                    if(tempi > 2)
                        tempi--;
                    else
                        tempi++;

                    columnCounter++;
                }
            }
        }

       if(inputCounterRow === 5){
            console.log(rowCounter + columnCounter);
            rl.close();
       }

  });

var read = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function (input) { inLine.push(input); });
read.on('close', function () {
    obj = init(inLine);
    myerr("-----start-----");
    var start = new Date();
    Main();
    var end = new Date() - start;
    myerr("----- end -----");
    myerr("Time: " + (end) + "ms");
    myerr("Memory: " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt() { return myconv(next(), 1); }
function nextStrArray() { return myconv(next(), 2); }
function nextIntArray() { return myconv(next(), 4); }
function nextCharArray() { return myconv(next(), 6); }
function next() { return obj.next(); }
function hasNext() { return obj.hasNext(); }
function init(input) {
    var returnObj = {
        list: input, index: 0, max: input.length,
        hasNext: function () { return (this.index < this.max); },
        next: function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { var returnInput = this.list[this.index]; this.index++; return returnInput; } }
    };
    return returnObj;
}
function myout(s) { console.log(s); }
function myerr(s) { console.error("debug:" + require("util").inspect(s, false, null)); }
function myconv(i, no) { try { switch (no) { case 1: return parseInt(i); case 2: return i.split(" "); case 4: return i.split(" ").map(Number); case 6: return i.split(""); case 7: return i.split("").map(Number); case 8: return i.join(" "); case 9: return i.join("\n"); case 0: return i.join(""); default: return i; } } catch (e) { return i; } }

function Main() {
    var mat = [];

    for (var i = 0; i < 5; i++) {
        mat[i] = nextIntArray();
        for (var j = 0; mat[i][j] < 5; j++) {
            if (mat[i][j] === 1) {
                myout(Math.abs(i - 2) + Math.abs(j - 2));
            }
        }
    }

} // Use Terminal to debug, not Debug Console!

function readNumbers() {
	return readline().split(' ').map(function (x) {
		return parseInt(x);
	});
}

var i = 0;
var j = 0;

while (i < 5) {
	j = readNumbers().indexOf(1)

	if (j != -1) {
		break;
	}

	i++;
}

print(
	Math.abs(i - 2) + Math.abs(j - 2)
);

var arr = [];
var inp;
const res = [];

for(var i = 0; i<5 ; i++){
inp = readline().split(" ");
arr.push(inp);
}

arr.forEach((cur, i) => {
    if(cur.indexOf('1') !== -1){
        res.push(cur.indexOf('1'));
        res.push(i);
    }
});

print(res.reduce((acc, c) => {
   return (acc + Math.abs(c-2));
},0));

const readline = require("readline");

let inputs = [];

const rl = readline.createInterface({
	input: process.stdin,
	output: process.stdout
});

rl.on("line", line => inputs.push(line));

rl.on("close", () => console.log(solution(inputs)));

const distance = (a, b) => a > b ? a - b : b > a ? b - a : 0;

function solution(data) {
    const matrix = data.map(str => str.split(" ").map(Number));
    let a = 1, b = 1;
    for (let i = a; i <= matrix.length; i++) {
        for (let j = b; j <= matrix[0].length; j++) {
            if (matrix[(i-1)][(j-1)] === 1) {
                a = i;
                b = j;
                break;
            }
        }
        if (a !== 1 || b !== 1) break;
    };

	return distance(3, a) + distance(3, b);
};

var count=0;
for(var i=0;i<5;i++){
    var row=readline();
    row=row.split(" ");
    for(var j=0;j<5;j++){
        if(row[j]==1){
            count=Math.abs(j-2)+Math.abs(i-2);
        }
    }
}
print(count);

//Beautiful Matrix

const {EOL} = require('os');

let inp = '';

process.stdin.on('data', c => inp += c);

process.stdin.on('end', () => {
    let lines = inp.split(EOL);

    let loc = [];
    for(let i in lines)  {
    	if(lines[i].indexOf('1') != -1)  {
    		loc = [+i, ~~(lines[i].indexOf('1') / 2)];
    	}
    }

    process.stdout.write(Math.abs(2 - loc[0]) + Math.abs(2 - loc[1]) + '');

    return;
});

var one = []
for(var i = 0; i < 5; i++) {
    var input = readline().split(" ")
    if(input.indexOf("1") != -1){
        one.push(i, input.indexOf("1"))
        break;
    }
}

step = Math.abs(2 - one[1]) + Math.abs(2 - one[0])

print(step)

var coordinates = {
    row: -1,
    col: -1
};
for (var i = 0; i < 5; i++) {
    var line = readline();
    var unitIndex = -1;
    for (var j = 0; j < line.length; j += 2) {
        if (line[j] === "1") {
            unitIndex = Math.floor(j/2);
            break;
        }
    }

    if (unitIndex !== -1) {
        coordinates.row = i;
        coordinates.col = unitIndex;
        break;
    }
}

print(Math.abs(coordinates.row - 2) + Math.abs(coordinates.col - 2));

var matrix = [];

function moves(matrix) {
	for ( var i = 0; i < 5; i++) {
		for (var j = 0; j < 5; j++){
			if (matrix[i][j] == "1") {
				return Math.abs(i - 2) + Math.abs(j - 2);
			}
		}
	}
}

for (var i = 0; i < 5; i++) {
	matrix.push(readline().split(' '));
}

print(moves(matrix));

/* TEST CASE
input
0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
output
3

input
0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
output
1

 */
function main() {
	var x = [1, 1, 1, 1];
	var i, j;
	var splitted = [];
	for (var x = 0; x < 5; x++) {
		splitted[x] = readline().split(' ');
	}
	for (var x = 0; x < 5; x++) {
		for (var y = 0; y < 5; y++) {
			if (splitted[x][y] == '1') {
				i = x;
				j = y;
				x = 5;
				break;
			}
		}
	}

	var answer = Math.abs(2 - i) + Math.abs(2 - j);
	print(answer);
}

main();

for(var i = 0; i < 5; i++){
	var j = readline().split(' ').indexOf('1');
	if(j > -1)
		break;
}

print(Math.abs(2-i)+Math.abs(2-j));

a1=readline().split(' ');
a2=readline().split(' ');
a3=readline().split(' ');
a4=readline().split(' ');
a5=readline().split(' ');

var array=[a1, a2, a3, a4, a5], counter=0;

for (y=0; y<5; y++) {
  for (x=0; x<5; x++) {
    if (array[y][x]==1) {counter=Math.abs(2-x) + Math.abs(2-y)}
  }
}

print(counter)

var matrix = [];
var num = 5;
while(num > 0){
    var input = readline().split(" ").map(x=>parseInt(x));
    matrix.push(input);
    num--;
}
var count = 0;
var row_index = 0;
var col_index = 0;
num = 5;
outer: for(var i = 0; i< num; i++){
    inner: for(var j = 0; j < num; j++){
        if(matrix[i][j]==1){
          row_index = i;
          col_index = j;
          break outer;
        }
    }
}
count = Math.abs(2-row_index)+Math.abs(2-col_index);
print(count);

var i = 0;
var j = 0;
var p = 0;
var q = 0;
for (i; i<5;i++){
    var r = readline().split(' ');
    for(j=0;j<5;j++){
        if(r[j] == 1){
            p = i;
            q = j;
        }
    }
}
print((Math.abs(2-p))+Math.abs((2-q)));

var x, y, ar;
for (var i = 0; i < 5; i ++) {
ar = readline().split(" ").map(function(x) { return parseInt(x); });
for (var j = 0; j < 5; j ++) {
if (ar[j] == 1) {
x = i; y = j;
}
}
}
print(Math.abs(2 - x) + Math.abs(2 - y));

// You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:

//     Swap two neighboring matrix rows, that is, rows with indexes i and i + 1 for some integer i (1 ≤ i < 5).
//     Swap two neighboring matrix columns, that is, columns with indexes j and j + 1 for some integer j (1 ≤ j < 5).

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

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

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

//print([1, 2, 3].includes(2))   // true)

var m = []
var c = []
var v = 0

for (i = 0; i < 5; i++) {
    m.push(readline().split(" "));
    if (m[i].includes("1")){
        v = Math.abs(2 - i) + Math.abs(2 - m[i].indexOf("1"))
    }
}

print(v)

var row1 = readline().split(' ');
var row2 = readline().split(' ');
var row3 = readline().split(' ');
var row4 = readline().split(' ');
var row5 = readline().split(' ');

var atRow = 0;
var atCol = 0;
var targetFound = false;

for (var i = 0; i < row1.length; i++) {
    if (targetFound)
        break;
    if (row1[i] != 0) {
        atRow = 0;
        atCol = i;
        targetFound = true;
    }
}

for (var i = 0; i < row2.length; i++) {
    if (targetFound)
        break;
    if (row2[i] != 0) {
        atRow = 1;
        atCol = i;
        targetFound = true;
    }
}

for (var i = 0; i < row3.length; i++) {
    if (targetFound)
        break;
    if (row3[i] != 0) {
        atRow = 2;
        atCol = i;
        targetFound = true;
    }
}

for (var i = 0; i < row4.length; i++) {
    if (targetFound)
        break;
    if (row4[i] != 0) {
        atRow = 3;
        atCol = i;
        targetFound = true;
    }
}

for (var i = 0; i < row5.length; i++) {
    if (targetFound)
        break;
    if (row5[i] != 0) {
        atRow = 4;
        atCol = i;
        targetFound = true;
    }
}

var step = 0;
if (atRow < 2) {
    step += 2 - atRow;
}
if (atRow > 2) {
    step += atRow - 2
}
if (atCol < 2) {
    step += 2 - atCol;
}
if (atCol > 2) {
    step += atCol - 2
}
print(step);

(function() {
    "use strict";
    var x , y;
    for(var i = 0; i < 5; i ++){
        var line = readline().replace(/\s/g, '');
        var index = line.indexOf('1');
        if(index != -1){
            x = i + 1;
            y = index + 1;
        }
    }

    print(Math.abs(x - 3) + Math.abs(y - 3));

})();

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let i = 0;
  let j = 0;
  for (let k = 0; k < 5; k++) {
    const line = readLine().split(' ').join('');
    if (line.includes('1')) {
      j = line.indexOf('1');
      break;
    }
    i++;
  }
  console.log(Math.abs(2 - i) + Math.abs(2 - j));
}

var line_number = 0;
const cs = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

var lines = {};
cs.on("line", (input) => {
  if (input == "") {
    cs.close();
  }
  lines[line_number] = input.split(" ");
  line_number += 1;
}).on("close", () => {
  main();
  process.exit();
});

function isOp(str) {
  return str.length === 1 && str.match(/[<=>]/);
}
function isChr(str) {
  return str.length === 1 && str.match(/[a-z]/i);
}
function isInt(str) {
  return str.length === 1 && !isNaN(str);
}

function print(str) {
  console.log(str);
}

function predict(test) {
  let op = "";
  let ops = [];
  let opVariables = [];
  let limits = [];
  for (let t of test) {
    // console.log(t);
    for (let i = 0; i < t.length; i++) {
      if (isOp(t[i])) {
        op = t[i];
        if (isOp(t[i + 1])) {
          op += t[i + 1];
          i += 1;
        }
        ops.push(op);
        op = "";
      } else if (isChr(t[i])) {
        // console.log(t[i])
        op = t[i];
        for (var j = i + 1; j < t.length; j++) {
          if (isChr(t[j]) || isInt(t[j])) {
            op += t[j];
            i = j;
          } else break;
        }
        opVariables.push(op);
        op = "";
      } else {
        if (i == 0 || (i > 0 && isOp(t[i - 1]))) {
          op = t[i];
          let j = i + 1;
          for (; j < t.length; j++) {
            if (isInt(t[j])) {
              op += t[j];
              i = j;
            } else break;
          }
          limits.push(op);
          op = "";
        }
      }
    }
  }

  let min = limits[0];
  let max = limits[1];

  let pvs = ops.map((o, i) => [o, opVariables[i]]);

  for (let pv of pvs) {
    if (pv[1] == undefined) {
      pv[1] = max;
    }
    // print(`${min} ${pv[0]} ${pv[1]} ?`)
    if (eval(`${min}${pv[0]}${pv[1]}`)) {
      // print(` ${min} ${pv[0]} ${pv[1]} true`)
      min = pv[1];
    } else {
      print("input error");
      process.exit();
    }
  }
}

var n;
function main() {
    for(let r = 0; r < 15; r++) {
        for(let c = 0; c < 15; c++) {
            if (lines[r][c] === '1') {
                print(Math.abs(3-1-r)+Math.abs(3-1-c))
                process.exit()
            }
        }
    }
}

var ans = 0;
for(var i = 0; i < 5; i++) {
  var line = readline(),
      index = line.split(" ").findIndex(item => item === "1");

  if(index >= 0) {
    ans = Math.abs(i - 2) + Math.abs(index - 2);
    break;
  }
}

print(ans);

const main = () => {
  const matrix = new Array(5);

  for (var i = 0; i < 5; i++) {
    matrix[i] = readline().split(" ");
  }

  for (var i = 0; i < 5; i++) {
    for (var j = 0; j < 5; j++) {
      if (matrix[i][j] === "1") {
        return Math.abs(2 - i) + Math.abs(2 - j);
      }
    }
  }
};

print(main());

var arrMatric = [];
for(var i = 0; i < 5; i++){
    arrMatric[i] = readline().split(' ');
}
for(var i = 0; i < 5; i++){
    for(var m = 0; m < 5; m++){
        if(arrMatric[i][m] == 1){
            k = i;
            n = m;
        }
    }
}
m = Math.abs(2 - k);
l = Math.abs(n - 2);
m += l
print(m);

'use strict';

// const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function main() {
    var matrix = [];
    for (var i = 0; i < 5; i++) {
        let arr = readLine()
            .split(' ')
            .map(value => parseInt(value));
        matrix.push(arr);
    }

    let coordinate = [];

    for (var i = 0; i < 5; i++) {
        if (matrix[i].indexOf(1) != -1) {
            coordinate.push(i);
            coordinate.push(matrix[i].indexOf(1));
        }
    }

    let ans = Math.abs(2 - coordinate[0]) + Math.abs(2 - coordinate[1]);
    console.log(ans);
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var list = new Array(5);
  for(var i = 0; i < 5; i++){
    list[i] = nextStrArray();
    if(list[i].indexOf("1") != -1){
      myout(Math.abs(list[i].indexOf("1") + 1 - 3) + Math.abs(3 - (i + 1)));
      return;
    }
  }

}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let place = [];

    for (let row = 0; row < 5; row++) {
        let found = readline().split(" ").indexOf('1');
        if (found > -1) {
            place = [row, found];
            break;
        }

    }

    let num1 = Math.abs(2- place[0]) >= 0 ?  Math.abs(2- place[0]) : 0;
    let num2 = Math.abs(2- place[1]) >= 0 ?  Math.abs(2- place[1])  : 0;
    console.log(num1 + num2);

    return;
}

var matrix = [];
for(var i = 0; i < 5; i++) matrix.push(readline().split(" "));
var xy = matrix.reduce((a, b, i) => b.indexOf("1") >= 0 ? [i, b.indexOf("1")] : a, [0, 0]);
print( Math.abs(2 - xy[0]) + Math.abs(2 - xy[1]));

var arr = [];
for(var i = 0; i < 5; ++i) {
    arr.push(readline().split(" "));
}
var rows = arr.length;
var cols = arr[0].length;
var rowOfTargetNum;
var colOfTargetNum;
var colIndexForBeatiful = Math.floor(cols / 2);
var rowIndexForBeatiful = Math.floor(rows / 2);

for(var i = 0; i < rows; ++i) {
    for(var j = 0; j < cols; ++j) {
        if(parseInt(arr[i][j]) == 1) {
            rowOfTargetNum = i;
            colOfTargetNum = j;
            break;
        }
    }
    if(rowOfTargetNum !== undefined) {
        break;
    }
}

print(Math.abs(rowIndexForBeatiful - rowOfTargetNum) + Math.abs(colIndexForBeatiful - colOfTargetNum));

for (i=0;i<5;i++){
    var x = readline().replace(/ /g,"");
    if (x.search("1")>-1){
        print(Math.abs((x.indexOf("1"))-2)+Math.abs(i-2))
    }
}

var result = 0;
for(var i = 0; i < 5; i++) {
    var position = readline().replace(/ /g, "").indexOf("1") + 1;

    if(position) {
        result = +`${position - 3}`.replace("-", "") + +`${(i - 2)}`.replace("-", "");
    }
}

print(result);

var r = 5;
var c = 5;

while (r > 0) {
    var s = readline();

    var i = s.indexOf('1');

    if (i !== -1) {
        c = i / 2 + 1;
        print(Math.abs(r - 3) + Math.abs(c - 3));
        break;
    }

    r--;
}

var r , c;
var input = [];
for(var i=0 ; i<5 ; i++){
    input = readline().split(' ').map(x=>parseInt(x));
    for(var j=0 ; j<5 ;j++){
        if(input[j]==1){
           r = i+1;
           c = j+1;
           break;
        }

    }
}

var res = Math.abs(r-3) + Math.abs(c-3) ;
print(res);

var res = sol();
print(res);

function sol() {

    var rowOfOne = -1;
    var colOfOne = -1;

    var trans = 0;

    for (var i = 0; i < 5; i++) {
        var row = readline().split(" ");
        for (var j = 0; j < 5; j++) {
            if (row[j] == 1) {
                rowOfOne = i;
                colOfOne = j;
                break;
            }
        }

        if(rowOfOne != -1){
            break;
        }
    }

    trans += Math.abs(rowOfOne - 2);
    trans += Math.abs(colOfOne - 2);

    return trans;
}

var x, y, ar;
for (var i = 0; i < 5; i ++) {
ar = readline().split(" ").map(function(x) { return parseInt(x); });
for (var j = 0; j < 5; j ++) {
if (ar[j] == 1) {
x = i; y = j;
}
}
}
print(Math.abs(2 - x) + Math.abs(2 - y));

var counter = 0;
var nRow;
var nColumn;

for(var i = 0; i < 5; i++)
{
    var row = readline().split(" ");
    if(row.findIndex(x => x == "1") != -1)
    {
        nRow = i;
        nColumn = row.findIndex(x => x == "1");
    }
}

if(nRow == 0 || nRow == 4)
    counter += 2;
else if(nRow == 1 || nRow == 3)
    counter++;

if(nColumn == 0 || nColumn == 4)
    counter += 2;
else if(nColumn == 1 || nColumn == 3)
    counter++;

print(counter);

var x = 0;
var y = 0;

var found = false;
var line = readline()
while(line != null && !found){
    var lineSplitted = line.split(' ')
    for(var i = 0; i < lineSplitted.length; i++){
        if(lineSplitted[i] == "1"){
            y = i;
            found = true;
            break;
        }
    }

    if(found) break;
    x++;
    line = readline()
}

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

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  input.forEach( (line , i) => {
    line.split(' ').forEach( (x, j) => {
      if (x === '1') {
        console.log(
          Math.abs(2-i) + Math.abs(2-j)
        );
        process.exit();
      }
    });
  });
});

const readline = require('readline');

let inputs = [];

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', lineInput => {
    inputs.push(lineInput)
})

rl.on('close', () => {

    let arr = [];
    let bestPosition = [2, 2];

    for (let i = 0; i < inputs.length; i++) {
        const subArr = inputs[i].split(' ');
        arr.push(subArr);
    }

    // Get The position of 1
    let currentPositon = [];
    for (let i = 0; i < arr.length; i++) {

        for (let j = 0; j < arr[i].length; j++) {
            if (arr[i][j] == 1)
                currentPositon.push(i, j);
        }
    }

    // Get the max number that needs minimum steps

    let minimumSteps = 0

    if (currentPositon.toString() != bestPosition.toString()) {
        const rowSteps = currentPositon[0] - bestPosition[0];
        const colSteps = currentPositon[1] - bestPosition[1];
        minimumSteps = Math.abs(colSteps) + Math.abs(rowSteps);
    }

    console.log(minimumSteps);

})

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function readAsInt(){
  return parseInt(readline());
}

function readAsIntList(){
  return readline().split(' ').filter(i => i).map(i => parseInt(i));
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  for(let i = 0; i < 5; i++) {
    let x = readAsIntList().findIndex(n => n);
    if(x>-1) {
      let result = (x > 2 ? ((x+1) % 3) : 2 - x) + (i > 2 ? ((i+1) % 3) : 2 - i);
      console.log(result);
      return;
    }
  }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
   const matrix = [];
   let minNumOfSwap;
   for( let i = 0 ; i < 5 ; i++){
       matrix[i] = readline().split(' ').map(x => parseInt(x))
   }

   for (let i=0 ; i <5 ;i++){
       for (let j =0 ; j < 5 ; j++){
           if (matrix[i][j] === 1 ){
               minNumOfSwap = Math.abs( i - 2) + Math.abs(j -2);
               break;
           }
       }
       if (minNumOfSwap > 0) break;
   }
    console.log(minNumOfSwap)

}

var m = []
var c = []
var v = 0

for (i = 0; i < 5; i++) {
    m.push(readline().split(" "));
    if (m[i].includes("1")){
        v = Math.abs(2 - i) + Math.abs(2 - m[i].indexOf("1"))
    }
}

print(v)

var n1 = readline().indexOf("1");
var n2 = readline().indexOf("1");
var n3 = readline().indexOf("1");
var n4 = readline().indexOf("1");
var n5 = readline().indexOf("1");
if (n1 >= 0){print(Math.abs(n1/2 - 2) + 2)}
else if(n2 >= 0){print(Math.abs(n2/2 - 2) + 1)}
else if(n3 >= 0){print(Math.abs(n3/2 - 2))}
else if(n4 >= 0){print(Math.abs(n4/2 - 2) + 1)}
else if(n5 >= 0){print(Math.abs(n5/2 - 2) + 2)}

var s = [];
for (var i = 0; i < 5; i ++)
    s.push(readline());
for (var i = 0; i < s.length; i++)
{
    var q = s[i].split(' ');
    for (var j = 0; j < q.length; j++)
        if (q[j] === '1')
        {
            print(Math.abs((i + 1) - 3) + Math.abs((j + 1) - 3));
            break;
        }
}

var mat = [], x = 0, y = 0, row;

for(var i=0; i<5; i++) {
    row = readline().split(' ');
    mat.push(row);

    if(row.indexOf('1') >= 0) {
        x = i;
        y = row.indexOf('1');
    }
}

print(Math.abs(2-x) + Math.abs(2-y));

var matrix = [];
var num = 5;
while(num > 0){
    var input = readline().split(" ").map(x=>parseInt(x));
    matrix.push(input);
    num--;
}
var count = 0;
var row_index = 0;
var col_index = 0;
num = 5;
outer: for(var i = 0; i< num; i++){
    inner: for(var j = 0; j < num; j++){
        if(matrix[i][j]==1){
          row_index = i;
          col_index = j;
          break outer;
        }
    }
}
count = Math.abs(2-row_index)+Math.abs(2-col_index);
print(count);

var one = []
for(var i = 0; i < 5; i++) {
    var input = readline().split(" ")
    if(input.indexOf("1") != -1){
        one.push(i, input.indexOf("1"))
        break;
    }
}

step = Math.abs(2 - one[1]) + Math.abs(2 - one[0])

print(step)

var c = 0;
for (var i=1; i<6; i++){
	var str =readline().split(" ");
	for (var j=0; j<5; j++){
		if (str[j]==1){

			print(Math.abs(3-i)+ Math.abs(3-(j+1)));
			c=1;
		}
		if (c==1)
		break;
	}

}

for(var i = 0 ; i < 5 ; i++) {
    inp = readline().split(" ");
    for(var j=0;j<5;j++){
        if(inp[j]==1){
            print(Math.abs(2-i)+Math.abs(2-j))
        }
    }
}

var posX = 0;
var posY = 0;
var res = 2;

for (var i = 0; i < 5; i++) {
	str = readline().split(' ').map(Number);

	for (var j = 0; j < str.length; j++) {
		if (str[j] === 1) {
			posX = j;
			posY = i;
		};
	};
};

print(Math.abs(res - posX) + Math.abs(res - posY));

var result = 0;
for(var i = 0; i < 5; i++) {
    var position = readline().replace(/ /g, "").indexOf("1") + 1;

    if(position) {
        result = +`${position - 3}`.replace("-", "") + +`${(i - 2)}`.replace("-", "");
    }
}

print(result);

var ans, val;

for (var i = 0 ; i < 5 ; i++) {
    val = readline().split(' ');

    for (var j = 0 ; j < 5 ; j++) {
        if (val[j] == '1') {
            ans = Math.abs(2 - i) + Math.abs(2 - j);
        }
    }
}

print(ans);

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

let y = 1;

rl.on('line', (m) => {
    let x = m.split(' ').map(Number).indexOf(1);

    if (x !== -1) {
        console.log(Math.abs(x + 1 - 3) + Math.abs(y - 3));
    }

    y++;
});

var ans1=-1,ans2=-1;
for(var i=0;i<5;i++)
{
    var j=readline().split(' ').indexOf('1');
    if(j>-1)
        ans1=i,ans2=j;
}
print(Math.abs(ans1-2)+Math.abs(ans2-2));

var a = readline().split(' ');
var b = readline().split(' ');
var c = readline().split(' ');
var d = readline().split(' ');
var e = readline().split(' ');
if (a.includes("1")) {
    var row = 1
    var col = a.indexOf("1") + 1;
    // print(Math.abs(row - col) );
    var moveByRow = Math.abs(3 - row);
    var moveByCol = Math.abs(3 - col);
    //  print(moveByRow);
    //  print(moveByCol);
    print(Math.abs(moveByRow + moveByCol));
}
if (b.includes("1")) {
    var row = 2
    var col = b.indexOf("1") + 1;
    var moveByRow = Math.abs(3 - row);
    var moveByCol = Math.abs(3 - col);
    //  print(moveByRow);
    //  print(moveByCol);
    print(Math.abs(moveByRow + moveByCol));
}
if (c.includes("1")) {
    var row = 3
    var col = c.indexOf("1") + 1;
    var moveByRow = Math.abs(3 - row);
    var moveByCol = Math.abs(3 - col);
    //  print(moveByRow);
    //  print(moveByCol);
    print(Math.abs(moveByRow + moveByCol));
}
if (d.includes("1")) {
    var row = 4
    var col = d.indexOf("1") + 1;
    var moveByRow = Math.abs(3 - row);
    var moveByCol = Math.abs(3 - col);
    //  print(moveByRow);
    //  print(moveByCol);
    print(Math.abs(moveByRow + moveByCol));
}
if (e.includes("1")) {
    var row = 5
    var col = e.indexOf("1") + 1;
    var moveByRow = Math.abs(3 - row);
    var moveByCol = Math.abs(3 - col);
    //  print(moveByRow);
    //  print(moveByCol);
    print(Math.abs(moveByRow + moveByCol));
}

var matrix = [];

function moves(matrix) {
	for ( var i = 0; i < 25; i++) {
		if (matrix[i] == "1") {
			return Math.abs(i - 12);
		}
	}
}

for (var i = 0; i < 5; i++) {
	var line = readline().split(' ');
	for (var j = 0; j < 5; j++) {
		matrix.push(line[j]);
	}
}
print(moves(matrix));

var matrix = [];
for(var i = 0; i < 5; i++) {
    matrix[i] = readline().split(' ').map(Number);
}
print(matrix);
var row = 0;
var column = 0;
for(var r = 0; r < 5; r ++) {
    for(var c = 0; c < 5; c++) {
        if(matrix[r][c] === 1) {
            row = r;
            column = c;
            break;
        }
    }
}
var result = Math.abs(row -2) + Math.abs(column - 2);
print(result);

var x, y;
for (var i = 0; i < 5; i++) {
    var s = readline().split(' ');
    for (var j = 0; j < s.length; j++) {
        if (s[j] == 1) {
            x = i+1;
            y = j+1;
        }
    }
}

print((3-x) + Math.abs((3 - y)));

//Beautiful Matrix
var one=[readline(),readline(),readline(),readline(),readline()].join('').replace(/\s/g, '');
one=one.indexOf('1');
var row=parseInt(Math.abs((one/5)-2));
var column =Math.abs(one%5-2);
print(row+column);

 var a=[readline(),readline(),readline(),readline(),readline()].join('').replace(/\s/g, '');

var one=a.indexOf('1');
/* var row=Math.abs((one/5)-2);
var column =Math.abs(one%5-2); */
var row=Math.abs(parseInt(one/5)-2);
var column =Math.abs(one%5);
/* print(a);
print(one);
print(row);

print(column);
print(Math.abs(row-2));
print(Math.abs(column-2)); */
print(column+row);

//Beautiful Matrix
var a = [readline(), readline(), readline(), readline(), readline()].join('').replace(/\s/g, '');
var one = a.indexOf('1');
var row = Math.abs((one / 5) - 2);
var column = Math.abs(one % 5 - 2);
if ((one + 1) % 5 == 0) row++;
print(parseInt(row + column));

var one=[readline(),readline(),readline(),readline(),readline()].join('').replace(/\s/g, '');
one=one.indexOf('1');
var row=parseInt(Math.abs((one/5)))-2;
var column =Math.abs(one%5-2);
print(row+column);

var one=[readline(),readline(),readline(),readline(),readline()].join('').replace(/\s/g, '');
one=one.indexOf('1');
var row=parseInt(Math.abs((one/5)-2));
var column =Math.abs(one%5-2);
print(Math.abs(row-2)+Math.abs(column-2));

var arr = [];
for(var i = 0; i < 5; ++i) {
    arr.push(readline().split(" "));
}
var rows = arr.length;
var cols = arr[0].length;
var rowOfTargetNum;
var colOfTargetNum;
var colIndexForBeatiful = Math.floor(cols / 2 + 1);
var rowIndexForBeatiful = Math.floor(rows / 2 + 1);

for(var i = 0; i < rows; ++i) {
    for(var j = 0; j < cols; ++j) {
        if(parseInt(arr[i][j]) == 1) {
            rowOfTargetNum = i;
            colOfTargetNum = j;
            break;
        }
    }
    if(rowOfTargetNum !== undefined) {
        break;
    }
}

print(Math.abs(rowIndexForBeatiful - rowOfTargetNum) + Math.abs(colIndexForBeatiful - colOfTargetNum));

function findElem() {
    for (var i=0; i < 5; i++) {
        var myArray = readline().split(' ');
        if (myArray.indexOf('1') !== -1 && myArray.indexOf('1') !== 0) {
            for (var j=0; j<5; j++) {
                if (myArray[j]==='1') {
                    return [i+1, j+1]
                }
            }
        }
    }
}

var result = findElem();
print(result)
result = Math.abs(result[0]-3)+Math.abs(result[1]-3)
print(result)

function findElem() {
    for (var i=0; i < 5; i++) {
        var myArray = readline().split(' ');
        if (myArray.indexOf('1') !== -1 && myArray.indexOf('1') !== 0) {
            for (var j=0; j<5; j++) {
                if (myArray[j]==='1') {
                    return [i, j]
                }
            }
        }
    }
}

var result = findElem();
result = Math.abs(result[0]-3)+Math.abs(result[1]-3)
print(result)

var arr = [];
for(var i = 0; i < 5; i++){
  arr.push(readline().split(" "));
}
print(arr);

var ans, val;

for (var i = 0 ; i < 5 ; i++) {
    for (var j = 0 ; j < 5 ; j++) {
        val = Number(readline());

        if (val == 1) {
            ans = Math.abs(2 - i) + Math.abs(2 - j);
        }
    }
}

print(ans);

var ans;

for (var i = 0 ; i < 5 ; i++) {
    for (var j = 0 ; j < 5 ; j++) {
        var val = Number(readline());

        if (val == 1) {
            ans = Math.abs(2 - i) + Math.abs(2 - j);
        }
    }
}

print(ans);

for (var i = 1; i <= 5; i++) {
    var numbers = readline().split(" ").map(function(x) { return parseInt(x); });

    var shouldBreak = false;

    for (var j = 1; j <= 5; j++) {
        if (numbers[j] === 1) {
            shouldBreak = true;
            break;
        }
    }

    if (shouldBreak) {
        break;
    }
}

print(Math.abs(i - 3) + Math.abs(j - 3));

for (var i = 1; i <= 5; i++) {
    var row = readline().split(" ").map(x => parseInt(x));
    for (var j = 1; j <= 5; j ++) {
        if (row[j] === 1) {
            print(Math.abs(i - 3) + Math.abs(j - 3));
        }
    }
}

var pending;

for (var i = 1; i <= 5; i++) {
    var row = readline().split(" ").map(x => parseInt(x));
    for (var j = 1; j <= 5; j ++) {
        if (row[j] === 1) {
            pending = Math.abs(i - 3) + Math.abs(j - 3);
        }
    }
}

print(pending);

for (var i = 1; i <= 5; i++) {
    var row = readline().split(" ").map(x => parseInt(x));
    for (var j = 1; j <= 5; j ++) {
        if (row[j] === 1) {
            print(Math.abs(i - 3) + Math.abs(j - 3));
            break;
        }
    }
}

var pending;

for (var i = 0; i < 5; i++) {
    var row = readline().split(" ").map(x => parseInt(x));
    for (var j = 0; j < 5; j ++) {
        if (row[j] === 1) {
            pending = Math.abs(i - 3) + Math.abs(j - 3);
        }
    }
}

print(pending);

var mati, matj;

for (var i = 1; i <= 5; i++) {
    var row = readline().split(" ").map(x => parseInt(x));
    for (var j = 1; j <= 5; j ++) {
        if (row[j] === 1) {
            mati = i;
            matj = j;
        }
    }
}

print(Math.abs(mati - 3) + Math.abs(matj - 3));

var n1 = readline().indexOf("1");
var n2 = readline().indexOf("1");
var n3 = readline().indexOf("1");
var n4 = readline().indexOf("1");
var n5 = readline().indexOf("1");
if (n1 >= 0){print( Math.abs((n1/2 +2)-6))}
else if(n2 >= 0){print( Math.abs((n1/2 +3)-6))}
else if(n3 >= 0){print( Math.abs((n1/2 +4)-6))}
else if(n4 >= 0){print( Math.abs((n1/2 +5)-6))}
else if(n5 >= 0){print( Math.abs((n1/2 +6)-6))}

var n1 = readline().indexOf("1");
var n2 = readline().indexOf("1");
var n3 = readline().indexOf("1");
var n4 = readline().indexOf("1");
var n5 = readline().indexOf("1");
if (n1 >= 0){print( Math.abs((n1/2 +2)-6))}
else if(n2 >= 0){print( Math.abs((n2/2 +3)-6))}
else if(n3 >= 0){print( Math.abs((n3/2 +4)-6))}
else if(n4 >= 0){print( Math.abs((n4/2 +5)-6))}
else if(n5 >= 0){print( Math.abs((n5/2 +6)-6))}

var n1 = readline().indexOf("1");
var n2 = readline().indexOf("1");
var n3 = readline().indexOf("1");
var n4 = readline().indexOf("1");
var n5 = readline().indexOf("1");
if (n1 >= 0){print(Math.abs(n1/2 - 2) + 2)}
else if(n2 >= 0){print(Math.abs(n1/2 - 2) + 1)}
else if(n3 >= 0){print(Math.abs(n1/2 - 2))}
else if(n4 >= 0){print(Math.abs(n1/2 - 2) + 1)}
else if(n5 >= 0){print(Math.abs(n1/2 - 2) + 2)}

for(var i=0;i<5;i++){
  var arr = readline().split(" ").map(x => parseInt(x));
  for(var j=0;j<5;j++){
    if(arr[i]==1){
      print(abs(2-i)+abs(2-j));
    }
  }
}

var matrix = [];
for(var i = 0; i < 5; i++) matrix.push(readline().split(" "));
var xy = matrix.reduce((a, b, i) => b.indexOf(1) > 0 ? [i, b.indexOf(1)] : a, [0, 0]);
print( Math.abs(3 - xy[0]) + Math.abs(3 - xy[1]));

var matrix = [];
for(var i = 0; i < 5; i++) matrix.push(readline().split(" "));
var xy = matrix.reduce((a, b, i) => b.indexOf(1) > 0 ? [i, b.indexOf(1)] : a, [0, 0]);
print( Math.abs(2 - xy[0]) + Math.abs(2 - xy[1]));

var matrix = [];
for(var i = 0; i < 5; i++) matrix.push(readline().split(" "));
var xy = matrix.reduce((a, b, i) => b.indexOf("1") > 0 ? [i, b.indexOf("1")] : a, [0, 0]);
print( Math.abs(2 - xy[0]) + Math.abs(2 - xy[1]));

var count = 0;
for (var i = 1; i < 6; i++) {
  var str = readline().split(" ");
  for (var j = 1; j < 6; j++) {
    if (str[j] == 1) {

      print(Math.abs(3 - i) + Math.abs(3 - (j + 1)));
      count = 1;
    }
    if (count == 1)
      break;
  }
}

for (i=0;i<5;i++){
    var x = readline().replace(/" "/g,"");
    if (x.search("1")>-1){
        print(Math.abs((x.indexOf("1"))-2)+Math.abs(i-2))
    }
}

for (i=0;i<5;i++){
    var x = readline().replace(/" ",""/g);
    if (x.search("1")>0){
        print(Math.abs((x.indexOf("1")/2)-2)+Math.abs(i-2))
    }
}

var a = -1, b = -1;

for (var i = 1; i < 6; i++) {
    var line = readline();
    if ( line.includes(1) ) {
        a = i;
        b = line.indexOf(1) + 1;
        break;
    }
}

print( Math.abs(2 - a) + Math.abs(2 - b));

var a = -1, b = -1;

for (var i = 1; i < 6; i++) {
    var line = readline();
    if ( line.includes(1) ) {
        a = i;
        b = line.indexOf(1) / 2 + 1;
        break;
    }
}

print( Math.abs(2 - a) + Math.abs(2 - b));

var a = -1, b = -1;

for (var i = 0; i < 5; i++) {
    var line = readline();
    if ( line.includes(1) ) {
        a = i;
        b = line.indexOf(1);
        break;
    }
}

print( Math.abs(2 - a) + Math.abs(2 - b));

for(var i = 0; i<5; i++){
    var j = readline().split(' ').indexOf('1');
    if(j>0){
        break;
    }
}

print(Math.abs(2-i)+Math.abs(2-j));

for(var i = 0; i<5; i++){
    var j = readline().split(" ").indexOf('1');
    if(j>-5){
        break;
    }
}

print(Math.abs(2-i)+Math.abs(2-j));

for(var i = 0; i<5; i++){
    var j = readline().split(" ").indexOf('1');
    if(j>-2){
        break;
    }
}

print(Math.abs(2-i)+Math.abs(2-j));

var a = readline().split(' ');
var b = readline().split(' ');
var c = readline().split(' ');
var d = readline().split(' ');
var e = readline().split(' ');

var a = a.concat(b,c,d,e);
print(12 - a.indexOf("1"));

var a = readline().split(' ');
var b = readline().split(' ');
var c = readline().split(' ');
var d = readline().split(' ');
var e = readline().split(' ');

var a = a.concat(b,c,d,e);
print(Math.abs(12 - a.indexOf("1")));

var a = readline().split(' ');
var b = readline().split(' ');
var c = readline().split(' ');
var d = readline().split(' ');
var e = readline().split(' ');

if (a.includes("1")) {
    var row = 1
    var col = a.indexOf("1");
     print(Math.abs(row - col) );

}
if (b.includes("1")) {
    var row = 2
    var col = b.indexOf("1") + 1 ;
    print(Math.abs(row - col) );
}
if (c.includes("1")) {
    var row = 3
    var col = c.indexOf("1") + 1;
    print(Math.abs(row - col) );
}

if (d.includes("1")) {
  var row = 4
    var col = d.indexOf("1") + 1;
    print(Math.abs(row - col) );
}

if (e.includes("1")) {
    var row = 5
    var col = e.indexOf("1") + 1;
    if(col === 5){
        print('4');
    }
    else {
        print(Math.abs(row - col));
    }

}

var a = readline().split(' ');
var b = readline().split(' ');
var c = readline().split(' ');
var d = readline().split(' ');
var e = readline().split(' ');

if (a.includes("1")) {
    var row = 1
    var col = a.indexOf("1") + 1;
    // print(Math.abs(row - col) );

     var moveByRow = Math.abs(3 - row);
     var moveByCol = Math.abs(3 - col);

     print(moveByRow);
     print(moveByCol);

     print(Math.abs(moveByRow + moveByCol) );

}
if (b.includes("1")) {
    var row = 2
    var col = b.indexOf("1") + 1 ;
    var moveByRow = Math.abs(3 - row);
     var moveByCol = Math.abs(3 - col);

     print(moveByRow);
     print(moveByCol);

     print(Math.abs(moveByRow + moveByCol) );
}
if (c.includes("1")) {
    var row = 3
    var col = c.indexOf("1") + 1;
   var moveByRow = Math.abs(3 - row);
     var moveByCol = Math.abs(3 - col);

     print(moveByRow);
     print(moveByCol);

     print(Math.abs(moveByRow + moveByCol) );
}

if (d.includes("1")) {
  var row = 4
  var col = d.indexOf("1") + 1;
    var moveByRow = Math.abs(3 - row);
     var moveByCol = Math.abs(3 - col);

     print(moveByRow);
     print(moveByCol);

     print(Math.abs(moveByRow + moveByCol) );

}

if (e.includes("1")) {
    var row = 5
    var col = e.indexOf("1") + 1;
    var moveByRow = Math.abs(3 - row);
     var moveByCol = Math.abs(3 - col);

     print(moveByRow);
     print(moveByCol);

     print(Math.abs(moveByRow + moveByCol) );

}

var row1 = readline().split(' ');
var row2 = readline().split(' ');
var row3 = readline().split(' ');
var row4 = readline().split(' ');
var row5 = readline().split(' ');

var atRow = 0;
var atCol = 0;
var targetFound = false;

for (var i = 0; i < row1.length; i++) {
    if (targetFound)
        break;
    if (row1[i] != 0) {
        atRow = 0;
        atCol = i;
        targetFound = true;
    }
}

for (var i = 0; i < row2.length; i++) {
    if (targetFound)
        break;
    if (row2[i] != 0) {
        atRow = 0;
        atCol = i;
        targetFound = true;
    }
}

for (var i = 0; i < row3.length; i++) {
    if (targetFound)
        break;
    if (row3[i] != 0) {
        atRow = 0;
        atCol = i;
        targetFound = true;
    }
}

for (var i = 0; i < row4.length; i++) {
    if (targetFound)
        break;
    if (row4[i] != 0) {
        atRow = 0;
        atCol = i;
        targetFound = true;
    }
}

for (var i = 0; i < row5.length; i++) {
    if (targetFound)
        break;
    if (row5[i] != 0) {
        atRow = 0;
        atCol = i;
        targetFound = true;
    }
}

var step = 0;
if (atRow < 2) {
    step += 2 - atRow;
}
if (atRow > 2) {
    step += atRow - 2
}
if (atCol < 2) {
    step += 2 - atCol;
}
if (atCol > 2) {
    step += atCol - 2
}
print(step);

var arrMatric = [];
for(var i = 0; i < 5; i++){
    arrMatric[i] = readline().split(' ');
}
for(var i = 0; i < 5; i++){
    for(var m = 0; m < 5; m++){
        if(arrMatric[i][m] == 1){
            k = i;
            n = m;
        }
    }
}
m = 2 - k + n - 2;
m = Math.abs(m);
print(m);

'use strict';
let x, y;
for (let i = 1; i <= 5; i++) {
    let row = readline();
    if (row.indexOf('1') !== -1) {
        y = i;
        x = row.replace(' ', '').indexOf('1') + 1;
    }
}
write(Math.abs(3 - y) + Math.abs(3 - x));

for(var i = 0; i < 5; i++) {
  var line = readline(),
      index = line.split(" ").findIndex(item => item === 1);

  if(index >= 0) {
    print(Math.abs(i - 2) + Math.abs(index - 2));
    break;
  }
}

var str = "";
for (var i=0; i<5; i++){
str = readline().split();

}
for(var i=0; i<str.length; i++){
		if (str[i]==1){
			print(Math.abs((13-(i+1))));
			break;
			}
}

var array=readline().split(" ");
var x=0;
for(var i=0; i<array.length; i++){
	 if(array[i]=="1")
		{
			x=array[i];
			break;
		}
}
var stroka = Math.ceil(x/5);
print(Math.abs(3-stroka+3-x));

var array=readline().split(" ");
var x=0;
for(var i=0; i<array.length; i++){
	 if(array[i]=="1")
		{
			x=array[i];
			break;
		}
}
var stroka = Math.ceil(x/5);
print(3-stroka+3-x);

var array=readline().split(" ");
var x=0;
for(var i=0; i<array.length; i++){
	 if(array[i]==1)
		{
			x=13-array[i];
			break;
		}
}
print(Math.abs(x));

var array=readline().split(" ");
var x=0;
for(var i=0; i<array.length; i++){
	 if(array[i]==1)
		{
			x=13-i+1;
			break;
		}
}
print(Math.abs(x));

var a = readline().split(" ");
var b = readline().split(" ");
var c = readline().split(" ");
var d = readline().split(" ");
var e = readline().split(" ");

var x=2,y=2;
var m =0, n=0;

if(a.indexOf('1') != -1) {
   m=0,n=a.indexOf('1');
}

if(b.indexOf('1') != -1) {
   m=1,n=b.indexOf('1');
}

if(c.indexOf('1') != -1) {
   m=2,n=c.indexOf('1');
}

if(d.indexOf('1') != -1) {
   m=3,n=d.indexOf('1');
}

var steps=0;

calc(m);
calc(n);

function calc(num) {
   while(num!=2 ) {
   if(num<2) {
       num++;
      steps++;
   }
   if(num>2) {
      num--;
      steps++;
   }
 }
}

print(steps);

function distToCenter(lines) {
    for (var i = 0; i < lines.length; i++) {
        var j = lines[i].indexOf("1");
        if (j !== -1) {
            return Math.abs(j - 2) + Math.abs(i - 2);
        }
    }
}
function main(stdin) {
    console.log(distToCenter(stdin.split("\n")));
}
main(require("fs")
    .readFileSync(0, "utf-8")
    .trim());

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

let matrix = [], location = [];

rl.on('line', n => {
  matrix.push(n.split(' ').map(Number));
  if (matrix.length === 5) {
    for (let i = 0; i < matrix.length; i++) {
      if (matrix[i].includes(1)) {
        location.push(i, matrix[i].indexOf(1));
        break;
      }
    }

    const yShift = Math.abs(location[0] - 2);
    const xShift = Math.abs(location[1] - 2);
    console.log(Math.max(xShift, yShift));
    rl.close();
  }
});

// Generated by CoffeeScript 2.5.1
var find, lines, mainAux, print, readline, rl, rli, sum, write;

rl = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

print = console.log;

write = function(...args) {
  return process.stdout.write(args.join(' '));
};

lines = [];

rl.on('line', function(line) {
  return lines.push(line);
});

rl.on('close', main);

rli = 0;

readline = function() {
  return lines[rli++];
};

sum = function(items) {
  return items.reduce((function(a, b) {
    return a + b;
  }), 0);
};

find = function(input) {
  return [
    input.find((inp) => {
      return inp.includes('1');
    }).split(' ').findIndex((str) => {
      return str === '1';
    }),
    input.findIndex((inp) => {
      return inp.includes('1');
    })
  ];
};

mainAux = function() {
  var input;
  input = [];
  input.push(readline());
  input.push(readline());
  input.push(readline());
  input.push(readline());
  input.push(readline());
  return print(sum(find(input).map(function(v) {
    return Math.abs(3 - v);
  })));
};

  function main() {
    return mainAux();
  }
;

//# sourceMappingURL=matrix.js.map

// Generated by CoffeeScript 2.5.1
var find, lines, mainAux, numMoves, print, readline, rl, rli, sum, write;

rl = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

print = console.log;

write = function(...args) {
  return process.stdout.write(args.join(' '));
};

lines = [];

rl.on('line', function(line) {
  return lines.push(line);
});

rl.on('close', main);

rli = 0;

readline = function() {
  return lines[rli++];
};

sum = function(items) {
  return items.reduce((function(a, b) {
    return a + b;
  }), 0);
};

find = function(input) {
  return [
    input.find((inp) => {
      return inp.includes('1');
    }).split(' ').findIndex((str) => {
      return str === '1';
    }),
    input.findIndex((inp) => {
      return inp.includes('1');
    })
  ];
};

numMoves = function(v) {
  return Math.abs(3 - v);
};

mainAux = function() {
  var input;
  input = [];
  input.push(readline());
  input.push(readline());
  input.push(readline());
  input.push(readline());
  input.push(readline());
  return print(sum(find(input).map(function(v) {
    return numMoves(v);
  })));
};

  function main() {
    return mainAux();
  }
;

//# sourceMappingURL=matrix.js.map

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});
let i = 0;
let point;
rl.on('line', (line) => {

    let row = line.split(' ').map(Number);
    if (!point) {
        for (let j = 0; j < row.length; j++) {
            if (row[j] === 1) {
                point = {i, j};
            }
        }
    }
    i++
    if (i === 5) {
        let moves = 0;
        if (point.i > 2) {
            moves += point.i - 2;
        } else if (point.i > 2) {
            moves += 2 - point.i;
        }
        if (point.j > 2) {
            moves += point.j - 2;
        } else if (point.j > 2) {
            moves += 2 - point.j;
        }
        console.log(moves);
    }
});

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
let matrix = [];
rl.on("line",(input)=>{
    let row = input.split(" ").map(Number)
    matrix.push(row)
    if(matrix[4]){
        rl.close();
        let perfectRow = 3;
        let perfectCol = 3;
        let steps = null ;
        let currentRow = null
        let currentCol = null
        matrix.forEach((row,index) => {
            if(row.includes(1)){
                currentRow = index+1;
                row.forEach((col,index)=>{
                    if(col==1) currentCol = index+1;
                })

            }
            if (currentRow!=perfectRow || currentCol!=perfectCol ) {
                steps = Math.abs(currentCol - perfectCol)+Math.abs(currentRow-perfectRow);
            }

        });
        console.log(steps)

    }
})

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
let matrix = [];
rl.on("line",(input)=>{
    let row = input.split(" ").map(Number)
    matrix.push(row)
    if(matrix[4]){
        rl.close();
        let perfectRow = 3;
        let perfectCol = 3;
        let steps = null ;
        let currentRow = null
        let currentCol = null
        matrix.forEach((row,index) => {
            if(row.includes(1)){
                currentRow = index+1;
                row.forEach((col,index)=>{
                    if(col==1) currentCol = index+1;
                })

            }
            if (currentRow!=perfectRow || currentCol!=perfectCol ) {
                steps = Math.abs((currentCol - perfectCol) + (currentRow-perfectRow));
            }

        });
        console.log(steps)

    }
})

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
let matrix = [];
rl.on("line",(input)=>{
    let row = input.split(" ").map(Number)
    matrix.push(row)
    if(matrix[4]){
        let steps = 0 ;
        rl.close();
        let perfectRow = 2;
        let perfectCol = 2;
        let currentRow = null
        let currentCol = null
        matrix.forEach((row,index) => {
            if(row.includes(1)){
                currentRow = index ;
                row.forEach((col,index)=>{
                    if(col==1) currentCol = index
                })

            }
            if (currentRow!=perfectRow || currentCol!=perfectCol ) {
                steps = (currentRow-perfectRow)+(currentCol-perfectRow)
            }

        });
        console.log(steps)

    }
})

"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on("end", (_) => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
   let matrix = [];
  for(let i=0;i<5;i++){
      matrix.push(readline()
    .split("")
    .map((x) => +x));
  }

  beautifulMatrix(matrix);
}

function beautifulMatrix(matrix) {
   for (let row = 0; row < matrix.length; row++) {
    for (let column = 0; column < matrix[row].length; column++) {
      if (matrix[row][column] == 1) {
        console.log(Math.abs(2 - row) + Math.abs(2 - column));
        return Math.abs(2 - row) + Math.abs(2 - column);
      }
    }
  }
}

"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on("end", (_) => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
   let matrix = [];
  for(let i=0;i<5;i++){
      matrix.push(readline()
    .split(" ")
    .map((x) => +x));
  }

  beautifulMatrix(matrix);
}

function beautifulMatrix(matrix) {
    console.log(matrix)
   for (let row = 0; row < matrix.length; row++) {
    for (let column = 0; column < matrix[row].length; column++) {
      if (matrix[row][column] == 1) {
        console.log(Math.abs(2 - row) + Math.abs(2 - column));
        return Math.abs(2 - row) + Math.abs(2 - column);
      }
    }
  }
}

const readline = require('readline');

let inputs = [];

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', lineInput => {
    inputs.push(lineInput)
})

rl.on('close', () => {

    let arr = [];
    let bestPosition = [2, 2];

    for (let i = 0; i < inputs.length; i++) {
        const subArr = inputs[i].split(' ');
        arr.push(subArr);
    }

    // Get The position of 1
    let currentPositon = [];
    for (let i = 0; i < arr.length; i++) {

        for (let j = 0; j < arr[i].length; j++) {
            if (arr[i][j] == 1)
                currentPositon.push(i, j);
        }
    }

    // Get the max number that needs minimum steps

    let minimumSteps = 0

    if (currentPositon.toString() != bestPosition.toString()) {
        const rowSteps = currentPositon[0] - bestPosition[0];
        const colSteps = currentPositon[1] - bestPosition[1];
        minimumSteps = Math.abs(rowSteps + colSteps);
    }

    console.log(minimumSteps);

})

const readline = require('readline');

let inputs = [];

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', lineInput => {
    inputs.push(lineInput)
})

rl.on('close', () => {

    let arr = [];
    let bestPosition = [2, 2];

    for (let i = 0; i < inputs.length; i++) {
        const subArr = inputs[i].split(' ');
        arr.push(subArr);
    }

    // Get The position of 1
    let currentPositon = [];
    for (let i = 0; i < arr.length; i++) {

        for (let j = 0; j < arr[i].length; j++) {
            if (arr[i][j] == 1)
                currentPositon.push(i, j);
        }
    }

    // Get the max number that needs minimum steps

    let minimumSteps = 0

    if (currentPositon.toString() == bestPosition.toString()) {
        minimumSteps = Math.max(...currentPositon) - bestPosition[1];
    } else {
        minimumSteps = Math.max(...currentPositon) - bestPosition[1] + 1;
    }

    console.log(minimumSteps);

})

const readline = require('readline');

let inputs = [];

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', lineInput => {
    inputs.push(lineInput)
})

rl.on('close', () => {

    let arr = [];
    let bestPosition = [2, 2];

    for (let i = 0; i < inputs.length; i++) {
        const subArr = inputs[i].split(' ');
        arr.push(subArr);
    }

    // Get The position of 1
    let currentPositon = [];
    for (let i = 0; i < arr.length; i++) {

        for (let j = 0; j < arr[i].length; j++) {
            if (arr[i][j] == 1)
                currentPositon.push(i, j);
        }
    }

    // Get the max number that needs minimum steps
    const minimumSteps = Math.max(...currentPositon) - bestPosition[1] + 1;

    console.log(minimumSteps);

})

// Interface of codeforces.com
let stdin = process.stdin;
stdin.setEncoding('utf8');

stdin.on('line', line => {
    makeMatrix(line);
    count ++;
    if (count >= 5) {
        console.log(solution(matrix));
    }
});

function makeMatrix(line) {
    const row = line.split(' ').map(char => Number(char));
    matrix.push(row);
}

function solution(matrix) {
// Get the matrix from the input and put it into a data structure
// Count the minimum number needed to make the matrix beautiful
    const index = getIndex(matrix);
    return (Math.abs(2 - index[0]) + Math.abs(2 - index[1]));

}

// Finds and returns the index of '1'
function getIndex(matrix) {
    let x = 0, y = 0;
    for (let i = 0; i < matrix.length; i++) {
        for (let j = 0; j < matrix.length; j++) {
            if (matrix[i][j] === 1) {
                return [i, j];
            }
        }
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  let n = readline();
  const numbers = readline().split(' ').map(x => parseInt(x)).sort();

  // output
  print(numbers.join(' '));
}

const readline = require('readline')

const rl = readline.createInterface({
	    input: process.stdin,
	    output: process.stdout,
	terminal : false
});

rl.on("line", main)
let i = 0;
let n = 0;
let m = []
function main(input){

	m.push(input.split(' '))
	i++
	if(i < 5){
		return
	}

	console.log(m)
	console.log(m[1][4])

	let x = 0
	let y = 0
	for(var j = 0; j < 5; j++){
		for(var k = 0 ; k < 5; k++){
			if(m[j][k] === "1"){
				y = j
				x = k
			}
		}
	}

	console.log(Math.abs((x+1)-3) + Math.abs((y+1)-3))
}

// https://codeforces.com/problemset/problem/263/A

function main(stdin) {
  const matrix = stdin.map(row => row.split(' ').map(Number))
  let y = 0; let x = 0

  while(matrix[y][x] !== 1)
    if(x < 5) { x++ }
    else { x = 0; y++ }

  process.stdout.write(Math.abs(((y - 2) * -1) + (x - 2)) + '')
}

// Handle standard input
process.stdin.resume()
process.stdin.setEncoding('utf-8')

let inputString = ''

process.stdin.on('data', (inputStdin) => inputString += inputStdin)
process.stdin.on('end', () =>
  main(inputString.trim().split('\n').map(s => s.trim())))

const readLine = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));
const matrix = () => {
    let oneStringRow;
    let oneColumn;
    let steps;
    for (let i = 0; i < input.length; i++) {
        if (input[i].includes('1')) {
            oneStringRow = i;
            oneColumn = input[i].indexOf('1') / 2;
        }
    }
    steps = Math.abs(2 - oneStringRow) + Math.abs(2 - oneColumn);
    console.log(steps);
    readLine.on('close', matrix);

};


Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.Ari draws a regular convex polygon on the floor and numbers it's vertices 1, 2, ..., n in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2, 3, ..., n (in this particular order). And then she puts a walnut in each region inside the polygon.  Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?

The first and only line of the input contains a single integer n (3 ≤ n ≤ 54321) - the number of vertices of the regular polygon drawn by Ari.

Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.

NoteOne of the possible solutions for the first sample is shown on the picture above.

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}

/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	var Prelude_1 = __webpack_require__(1);
	var d8 = __webpack_require__(2);
	var n = d8.readnumbers()[0];
	var regions = n - 2;
	for (var i = 2; i <= n; i++) {
	    var left = Prelude_1.max(0, i - 3);
	    var right = Prelude_1.max(0, n - i - 1);
	    regions += left + right;
	}
	print(regions);

/***/ },
/* 1 */
/***/ function(module, exports) {

	function min(a, b) {
	    return a < b ? a : b;
	}
	exports.min = min;
	function max(a, b) {
	    return a < b ? b : a;
	}
	exports.max = max;
	function curry(f) {
	    return function (x) { return function (y) { return f(x, y); }; };
	}
	exports.curry = curry;
	function uncurry(f) {
	    return function (x, y) { return f(x)(y); };
	}
	exports.uncurry = uncurry;
	function id(x) {
	    return x;
	}
	exports.id = id;
	function constant(x) {
	    return function (_) { return x; };
	}
	exports.constant = constant;
	function flip(f) {
	    return function (y) { return function (x) { return f(x)(y); }; };
	}
	exports.flip = flip;
	function flip2(f) {
	    return function (y, x) { return f(x, y); };
	}
	exports.flip2 = flip2;
	function compose(g, f) {
	    return function (x) { return g(f(x)); };
	}
	exports.compose = compose;
	function gcd(a, b) {
	    var r = a % b;
	    while (r !== 0) {
	        a = b;
	        b = r;
	        r = a % b;
	    }
	    return b;
	}
	exports.gcd = gcd;

/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {

	var List = __webpack_require__(3);
	function readnumbers() {
	    return List.map(parseInt, readline().split(' '));
	}
	exports.readnumbers = readnumbers;

/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {

	var Prelude_1 = __webpack_require__(1);
	function add(xs, ys) {
	    return xs.concat(ys);
	}
	exports.add = add;
	function head(xs) {
	    return xs[0];
	}
	exports.head = head;
	function last(xs) {
	    return xs[xs.length - 1];
	}
	exports.last = last;
	function tail(xs) {
	    return xs.slice(1);
	}
	exports.tail = tail;
	function init(xs) {
	    return xs.slice(0, xs.length - 1);
	}
	exports.init = init;
	function map(f, xs) {
	    var result = new Array(xs.length);
	    for (var i = 0; i < xs.length; i++) {
	        result[i] = f(xs[i]);
	    }
	    return result;
	}
	exports.map = map;
	function reverse(xs) {
	    return xs.slice().reverse();
	}
	exports.reverse = reverse;
	function intersperse(x, xs) {
	    if (xs.length == 0) {
	        return [];
	    }
	    var result = new Array(xs.length + xs.length - 1);
	    for (var i = 0; i + 1 < xs.length; i++) {
	        result[i + i] = xs[i];
	        result[i + i + 1] = x;
	    }
	    result[result.length - 1] = xs[xs.length - 1];
	    return result;
	}
	exports.intersperse = intersperse;
	function intercalate(xs, xss) {
	    return concat(intersperse(xs, xss));
	}
	exports.intercalate = intercalate;
	function foldl(f, initial, xs) {
	    var result = initial;
	    for (var i = 0; i < xs.length; i++) {
	        result = f(result, xs[i]);
	    }
	    return result;
	}
	exports.foldl = foldl;
	function foldr(f, initial, xs) {
	    var result = initial;
	    for (var i = xs.length - 1; i >= 0; i--) {
	        result = f(xs[i], result);
	    }
	    return result;
	}
	exports.foldr = foldr;
	function concat(xss) {
	    var total = sum(map(function (xs) { return xs.length; }, xss));
	    var result = new Array(total);
	    var m = 0;
	    for (var i = 0; i < xss.length; i++) {
	        var xs = xss[i];
	        for (var j = 0; j < xs.length; j++) {
	            result[m++] = xs[j];
	        }
	    }
	    return result;
	}
	exports.concat = concat;
	function sum(xs) {
	    var result = 0;
	    for (var i = 0; i < xs.length; i++) {
	        result += xs[i];
	    }
	    return result;
	}
	exports.sum = sum;
	function product(xs) {
	    var result = 1;
	    for (var i = 0; i < xs.length; i++) {
	        result *= xs[i];
	    }
	    return result;
	}
	exports.product = product;
	function sort(xs, compare) {
	    return copy(xs).sort(compare);
	}
	exports.sort = sort;
	function sortInPlace(xs, compare) {
	    xs.sort(compare);
	    return xs;
	}
	exports.sortInPlace = sortInPlace;
	function maximumInRange(xs, s, e) {
	    var result = xs[s];
	    for (var i = s + 1; i <= e; i++) {
	        if (result < xs[i])
	            result = xs[i];
	    }
	    return result;
	}
	exports.maximumInRange = maximumInRange;
	function maximum(xs) {
	    return maximumInRange(xs, 0, xs.length - 1);
	}
	exports.maximum = maximum;
	function maximumInRangeWith(xs, s, e, f) {
	    var result = f(xs[s]);
	    for (var i = s + 1; i <= e; i++) {
	        var candidate = f(xs[i]);
	        if (result < candidate)
	            result = candidate;
	    }
	    return result;
	}
	exports.maximumInRangeWith = maximumInRangeWith;
	function maximumWith(xs, f) {
	    return maximumInRangeWith(xs, 0, xs.length - 1, f);
	}
	exports.maximumWith = maximumWith;
	function minimumInRange(xs, s, e) {
	    var result = xs[s];
	    for (var i = s + 1; i <= e; i++) {
	        if (result > xs[i])
	            result = xs[i];
	    }
	    return result;
	}
	exports.minimumInRange = minimumInRange;
	function minimum(xs) {
	    return minimumInRange(xs, 0, xs.length - 1);
	}
	exports.minimum = minimum;
	function minimumInRangeWith(xs, s, e, f) {
	    var result = f(xs[s]);
	    for (var i = s + 1; i <= e; i++) {
	        var candidate = f(xs[i]);
	        if (result > candidate)
	            result = candidate;
	    }
	    return result;
	}
	exports.minimumInRangeWith = minimumInRangeWith;
	function minimumWith(xs, f) {
	    return minimumInRangeWith(xs, 0, xs.length - 1, f);
	}
	exports.minimumWith = minimumWith;
	function replicate(n, x) {
	    var result = new Array(n);
	    for (var i = 0; i < result.length; i++) {
	        result[i] = x;
	    }
	    return result;
	}
	exports.replicate = replicate;
	function take(n, xs) {
	    return xs.slice(0, n);
	}
	exports.take = take;
	function drop(n, xs) {
	    return xs.slice(n);
	}
	exports.drop = drop;
	function splitAt(n, xs) {
	    return [take(n, xs), drop(n, xs)];
	}
	exports.splitAt = splitAt;
	function takeWhile(f, xs) {
	    for (var i = 0; i < xs.length; i++) {
	        if (!f(xs[i])) {
	            return xs.slice(0, i);
	        }
	    }
	    return xs.slice();
	}
	exports.takeWhile = takeWhile;
	function dropWhile(f, xs) {
	    for (var i = 0; i < xs.length; i++) {
	        if (!f(xs[i])) {
	            return xs.slice(i);
	        }
	    }
	    return [];
	}
	exports.dropWhile = dropWhile;
	function group(xs) {
	    if (xs.length == 0)
	        return [];
	    var result = [];
	    var last = [xs[0]];
	    for (var i = 1; i < xs.length; i++) {
	        if (last[0] === xs[i]) {
	            last.push(xs[i]);
	        }
	        else {
	            result.push(last);
	            last = [xs[i]];
	        }
	    }
	    result.push(last);
	    return result;
	}
	exports.group = group;
	function nub(xs) {
	    if (xs.length == 0)
	        return [];
	    var result = [];
	    result.push(xs[0]);
	    for (var i = 1; i < xs.length; i++) {
	        if (xs[i] !== xs[i - 1]) {
	            result.push(xs[i]);
	        }
	    }
	    return result;
	}
	exports.nub = nub;
	function filter(f, xs) {
	    var result = [];
	    for (var i = 0; i < xs.length; i++) {
	        if (f(xs[i]))
	            result.push(xs[i]);
	    }
	    return result;
	}
	exports.filter = filter;
	function zip(xs, ys) {
	    var n = Prelude_1.min(xs.length, ys.length);
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = [xs[i], ys[i]];
	    }
	    return result;
	}
	exports.zip = zip;
	function unzip(xs) {
	    var r1 = new Array(xs.length);
	    var r2 = new Array(xs.length);
	    for (var i = 0; i < xs.length; i++) {
	        r1[i] = xs[i][0];
	        r2[i] = xs[i][1];
	    }
	    return [r1, r2];
	}
	exports.unzip = unzip;
	function range(from, to) {
	    var result = Array(to - from + 1);
	    for (var i = from; i <= to; i++) {
	        result[i - from] = i;
	    }
	    return result;
	}
	exports.range = range;
	function copy(xs) {
	    return xs.slice(0);
	}
	exports.copy = copy;
	function apply_permutation(p, xs) {
	    var n = xs.length;
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = xs[p[i]];
	    }
	    return result;
	}
	exports.apply_permutation = apply_permutation;
	function next_permutation(p) {
	    var n = p.length;
	    if (n < 2)
	        return null;
	    var r = copy(p);
	    var k = n - 2;
	    for (; k >= 0 && r[k] >= r[k + 1]; k--)
	        ;
	    if (k < 0)
	        return null;
	    for (var i = k + 1, j = n - 1; i < j; i++, j--) {
	        var t_1 = r[i];
	        r[i] = r[j];
	        r[j] = t_1;
	    }
	    var next = k + 1;
	    for (; r[next] <= r[k]; next++)
	        ;
	    var t = r[k];
	    r[k] = r[next];
	    r[next] = t;
	    return r;
	}
	exports.next_permutation = next_permutation;
	function create(n, value) {
	    return replicate(n, value);
	}
	exports.create = create;
	function createWith(n, f) {
	    var result = new Array(n);
	    for (var i = 0; i < n; i++) {
	        result[i] = f(i);
	    }
	    return result;
	}
	exports.createWith = createWith;
	function create2D(n1, n2, value) {
	    return map(function (_) { return replicate(n2, value); }, replicate(n1, 0));
	}
	exports.create2D = create2D;
	function create2DWith(n1, n2, f) {
	    var result = new Array(n1);
	    for (var i = 0; i < n1; i++) {
	        result[i] = new Array(n2);
	        for (var j = 0; j < n2; j++) {
	            result[i][j] = f(i, j);
	        }
	    }
	    return result;
	}
	exports.create2DWith = create2DWith;

/***/ }
/******/ ]);

var input = parseInt(readline());
print(((input - 3) * (input - 1)) + 1);


Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:   ">"  →  1000,  "<"  →  1001,  "+"  →  1010,  "-"  →  1011,  "."  →  1100,  ","  →  1101,  "["  →  1110,  "]"  →  1111. Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).

The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".

Output the size of the equivalent Unary program modulo 1000003 (106 + 3).

NoteTo write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program.

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}

function main() {
    let brain = readLine();
    while (brain.includes('>')) {
        brain = brain.replace('>', '1000');
    }
    while (brain.includes('<')) {
        brain = brain.replace('<', '1001');
    }
    while (brain.includes('+')) {
        brain = brain.replace('+', '1010');
    }
    while (brain.includes('-')) {
        brain = brain.replace('-', '1011');
    }
    while (brain.includes('.')) {
        brain = brain.replace('.', '1100');
    }
    while (brain.includes(',')) {
        brain = brain.replace(',', '1101');
    }
    while (brain.includes('[')) {
        brain = brain.replace('[', '1110');
    }
    while (brain.includes(']')) {
        brain = brain.replace(']', '1111');
    }
    let ans = convertBase(brain, 2, 10);

    let final = 0;
    let length = ans.length;
    for (let i = 0; i < length; i++) {
        final = (final * 10 + (ans[i] - 0)) % 1000003;
    }
    console.log(final);
}

function parseBigInt(bigint, base) {
    //convert bigint string to array of digit values
    for (var values = [], i = 0; i < bigint.length; i++) {
        values[i] = parseInt(bigint.charAt(i), base);
    }
    return values;
}

function formatBigInt(values, base) {
    //convert array of digit values to bigint string
    for (var bigint = '', i = 0; i < values.length; i++) {
        bigint += values[i].toString(base);
    }
    return bigint;
}

function convertBase(bigint, inputBase, outputBase) {
    //takes a bigint string and converts to different base
    var inputValues = parseBigInt(bigint, inputBase),
        outputValues = [], //output array, little-endian/lsd order
        remainder,
        len = inputValues.length,
        pos = 0,
        i;
    while (pos < len) {
        //while digits left in input array
        remainder = 0; //set remainder to 0
        for (i = pos; i < len; i++) {
            //long integer division of input values divided by output base
            //remainder is added to output array
            remainder = inputValues[i] + remainder * inputBase;
            inputValues[i] = Math.floor(remainder / outputBase);
            remainder -= inputValues[i] * outputBase;
            if (inputValues[i] == 0 && i == pos) {
                pos++;
            }
        }
        outputValues.push(remainder);
    }
    outputValues.reverse(); //transform to big-endian/msd order
    return formatBigInt(outputValues, outputBase);
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}

function main() {
    let brain = readLine();
    while (brain.includes('>')) {
        brain = brain.replace('>', '1000');
    }
    while (brain.includes('<')) {
        brain = brain.replace('<', '1001');
    }
    while (brain.includes('+')) {
        brain = brain.replace('+', '1010');
    }
    while (brain.includes('-')) {
        brain = brain.replace('-', '1011');
    }
    while (brain.includes('.')) {
        brain = brain.replace('.', '1100');
    }
    while (brain.includes(',')) {
        brain = brain.replace(',', '1101');
    }
    while (brain.includes('[')) {
        brain = brain.replace('[', '1110');
    }
    while (brain.includes(']')) {
        brain = brain.replace(']', '1111');
    }
    // console.log(brain);
    let ans = parseInt(brain, 2);
    let final = ans % 1000003;
    console.log(final);
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}

function main() {
    let brain = readLine();
    while (brain.includes('>')) {
        brain = brain.replace('>', '1000');
    }
    while (brain.includes('<')) {
        brain = brain.replace('<', '1001');
    }
    while (brain.includes('+')) {
        brain = brain.replace('+', '1010');
    }
    while (brain.includes('-')) {
        brain = brain.replace('-', '1011');
    }
    while (brain.includes('.')) {
        brain = brain.replace('.', '1100');
    }
    while (brain.includes(',')) {
        brain = brain.replace(',', '1101');
    }
    while (brain.includes('[')) {
        brain = brain.replace('[', '1110');
    }
    while (brain.includes(']')) {
        brain = brain.replace(']', '1111');
    }
    // console.log(brain);
    console.log(parseInt(brain, 2) % 1000003);
}