Plus
Pin


Problem description Progress
ID 38194. Chess board
Темы: 2D arrays    Cell geometry   

From the chessboard along the borders of the cells, a connected (not falling apart) figure without holes was cut out. It is required to determine its perimeter.

Input
First enter the number N (1 ≤ N ≤ 64) – the number of excised cells. In the next N lines, enter the coordinates of the sawn cells, separated by a space (line and column number – numbers from 1 to 8). Each sawn cell is indicated once.

Imprint
Print one number – the perimeter of the sawn figure (the side of the cell is equal to one).

Examples
# Input Output Explanations
1 3
1 1
1 2
2 1
8 Cut out a corner of three cells. The sum of the lengths of its sides is 8.
2 1
8 8
4 One cell cut out. Its perimeter is 4.