Under construction

Still being built. Things may change

Ukje Is the Architecture King!!

Interview

Time limit2sMemory limit512 MB

Summary
Given the vertices of an axis-aligned orthogonally convex polygon in order, output its perimeter.
Level

Easy3 of 10

Topics
Geometry, Implementation, Math
Solved
No attempts yet

Problem

Ukje, having taken Introduction to Architecture, has been put in charge of designing a new building to be built in front of Seonrin's snack shop. Ukje is happy to have met Suji in his Introduction to Architecture class, but he has so little talent for architecture that he got a C-.

Ukje, a student in the Department of Computer Science, keeps the blueprint of this building not as a picture but as the coordinates of the vertices where line segments meet. This blueprint is a floor plan showing only the floor of the building. However, Ukje, who also got a C- in programming, cannot find a way to compute the perimeter of the building he designed and is pacing about in frustration.

The building Ukje designed is a closed curve that is orthogonally convex: viewed from any direction, it has no dent in the middle. You could say it is a digitized form of a simple oval. Ukje's blueprint is represented exactly on the grid of the 2D coordinate plane. (In English, such a shape is called an orthogonally convex rectilinear polygon.)

Ukje handed you the coordinates of all the vertices of the floor plan and asked for help. The blueprint can be reconstructed by drawing line segments connecting the i-th coordinate to the i+1-th coordinate in the order Ukje gives them. The N-th coordinate connects to the 1st coordinate, and every segment is given aligned with the grid.

Compute the perimeter of this building on Ukje's behalf and take the starring role in Introduction to Architecture!

Input

The first line gives the number of vertices N. (4 ≤ N ≤ 20)

Then, from the second line, N lines follow, each giving the coordinate (x, y) of a vertex. The coordinates are non-negative integers not exceeding 40, and no coordinate is repeated.

Output

Print the perimeter length of the building Ukje designed.

Examples2

  1. Example 1

    Input
    4
    10 10
    10 40
    40 40
    40 10
    
    Expected output
    120
    
  2. Example 2

    Input
    8
    0 0
    6 0
    6 6
    4 6
    4 8
    2 8
    2 6
    0 6
    
    Expected output
    28