Intelligence in Perpendicularia

Given an orthogonal simple polygon, find the total length of wall that an observer looking along a principal axis direction cannot see.

Medium7GeometryImplementationSortingArrayNo attempts yetTime limit3sMemory limit512 MB

Problem

Perpendicularia has only two directions, vertical and horizontal. The government is going to build a new intelligence service facility. Several plans are on the table, and for each of them the government wants the total secured perimeter.

The total secured perimeter is the total length of the facility walls that an outside observer looking along an axis direction cannot see. A point of a wall is visible when the ray that leaves that point perpendicular to the wall, pointing away from the facility, never meets the facility again. Every other point of a wall is invisible.

The figure below shows one of the plans, with its secured perimeter drawn in bold.

Write a program that calculates the total secured perimeter of the given plan.

Input

The plan of the facility is given as a polygon.

The first line contains one integer nn, the number of vertices of the polygon (4n10004 \le n \le 1000). Each of the next nn lines contains two integers xix_i and yiy_i, the coordinates of the ii-th vertex (106xi,yi106-10^6 \le x_i, y_i \le 10^6). The vertices are listed in order along the boundary.

All vertices are distinct, and no vertex lies on another edge. Every edge is either vertical (xi=xi+1x_i = x_{i+1}) or horizontal (yi=yi+1y_i = y_{i+1}), and two edges that are not neighbors never meet.

Output

Print the total secured perimeter as a single integer.