Polygon Area

easy geometry 1000 ms · 256 MB

Polygon Area

You are given the vertices of a simple polygon (its edges do not cross), listed in order around the boundary — either clockwise or counter-clockwise. Compute its area.

Input

The first line contains n (3 ≤ n ≤ 10^5).

Each of the next n lines contains two real numbers x y with at most 3 digits after the decimal point (|x|, |y| ≤ 10^4).

Output

Print the area. Your answer is accepted if its absolute or relative error is at most 10^-6.

Answers within 1e-06 absolute or relative error are accepted.

Example 1

Input

4
0 0
4 0
4 3
0 3

Output

12

Example 2

Input

3
0 0
0 1
1.5 0

Output

0.75

Hints · reveal one at a time if you're stuck

Hint 1

Pick the origin and draw a triangle from it to each edge of the polygon. If each triangle gets a signed area, what happens to the parts that lie outside the polygon?

Hint 2

Each triangle's signed area is a cross product of two consecutive vertices. Add these over the whole boundary, including the edge from the last vertex back to the first, then fix the overall sign and scale. Real inputs are fine in double precision.

Hint 3

This is the shoelace formula: area = |Σ (x_i · y_{i+1} − x_{i+1} · y_i)| / 2, with indices taken modulo n.

report an issue Prefer your own editor? sooks prep 5 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.