Perimeter


Problem Statement

You have a square grid with length nn. Each cell in the grid can be either 11 or 00.

Return the length of the perimeter required to surround all the 11 cells in the grid.

Input

Your first line will contain nn.

Your next nn lines will each contain nn grids of 11's and 00s.

Output

A single integer representing the unit perimeter required to surround all the 11 cells in the grid.

Constraints

For all test cases:

  • 1≤n≤1031 \le n \le 10^3
  • All cells will be either 11 or 00.

Example 1

Input 1
3
010
111
010
Output 1
12

Example 2

Input 2
4
0110
1110
0000
0110
Output 2
16

Example 3

Input 3
2
01
10
Output 3
8

Python Template

Code 1
n = int(input())
grid = [list(map(int, input())) for _ in range(n)]

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.