A land surveyor records the corner posts of a plot as a simple polygon, listing the vertices in order around the boundary (either clockwise or counter-clockwise). All vertices have integer coordinates. To avoid fractions, report twice the area enclosed by the boundary; for a polygon with integer vertices this doubled value is always a whole number.
Line 1: an integer n, the number of vertices.
Next n lines: two integers x y, the coordinates of each vertex in boundary order.
A single integer: twice the area enclosed by the polygon.
Example 1
Input
4 0 0 4 0 4 3 0 3
Expected
24
Explanation
The posts outline a 4 by 3 rectangle with area 12, so twice the area is 24.
Example 2
Input
3 0 0 5 0 0 4
Expected
20
Explanation
A right triangle with legs 5 and 4 has area 10, so twice the area is 20.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →