#P1183. 多边形的面积

多边形的面积

Description

Given a simple polygon without holes whose edges are vertical or horizontal, compute the area of the polygon.

The polygon is placed on an xOyxOy Cartesian plane, and all its edges are parallel to one of the two coordinate axes. The vertex coordinates are given in counterclockwise order. All coordinates are integers, so the area of the polygon is also an integer.

Note: There may be three consecutive vertices that are collinear.

Input Format

The first line contains the number of vertices nn.

The next nn lines each contain the coordinates xx and yy of a vertex, separated by a space.

The vertices are given one by one in counterclockwise order. The polygon is closed by drawing an edge from the last vertex to the first.

Output Format

One line with a single integer, representing the area of the polygon.

10
0 0
4 0
4 1
3 1
3 3
2 3
2 2
1 2
1 3
0 3
9

Hint

For 100%100\% of the testdata, 1n1001 \le n \le 100, 200x,y200-200 \le x, y \le 200.

Translated by ChatGPT 5