cho.sh
Notes
Loading...

Warehouse Polygon

Time limit

2s

Memory limit

128 MB

Problem

N vertical pillars stand in a row. Every pillar has width 1 m, and their heights may be different. A tin warehouse must be built so that it contains all pillars.

The roof of the warehouse must satisfy the following conditions.

  1. The roof consists of horizontal and vertical parts, and all parts must be connected.
  2. Every horizontal part of the roof must touch the top of at least one pillar.
  3. Every vertical part of the roof must touch the side of at least one pillar.
  4. Both outer edges of the roof must touch the ground.
  5. The roof must not have any concave indentation where rainwater could collect.

Viewed from the side, the polygon enclosed by the roof and the ground is called the warehouse polygon. Given the positions and heights of the pillars, find the minimum possible area of the warehouse polygon.

Input

The first line contains an integer N, the number of pillars. N is between 1 and 1,000, inclusive.

Each of the next N lines contains two integers L and H, separated by a space. L is the position of the left side of the pillar, and H is its height. Both L and H are between 1 and 1,000, inclusive.

Output

Print one integer: the minimum area of the warehouse polygon.