cho.sh
NotesCho Mini
Loading...

Colored Paper Perimeter

Time limit

1s

Memory limit

128 MB

Problem

There is a white square sheet of paper whose width and height are both 100. On it, black square papers whose width and height are both 10 are attached. Every black paper is attached so that its sides are parallel to the sides of the white sheet.

After attaching one or more black papers, write a program that finds the perimeter of the entire black region covered by the papers. If papers overlap, the overlapped part is counted as one black region.

For example, if four black papers are attached to the white sheet as shown in <Figure 1>, the perimeter of the black region is 96.

Input

The first line contains the number of black papers. Starting from the second line, each line contains the position where one black paper is attached.

Each position is given as two natural numbers. The first number is the distance between the left side of the black paper and the left side of the white sheet. The second number is the distance between the bottom side of the black paper and the bottom side of the white sheet.

The number of black papers is at most 100, and no black paper extends outside the white sheet.

Output

Print the perimeter of the entire black region covered by the black papers on the first line.