#P1183. Calculate the Area of a Simple Orthogonal Polygon

    ID: 13929 Type: Default 1000ms 256MiB

Calculate the Area of a Simple Orthogonal Polygon

Calculate the Area of a Simple Orthogonal Polygon

Given a simple polygon with no self-intersections whose sides are either vertical or horizontal, compute its area. The polygon is placed on the Cartesian plane, and all of its edges are parallel to one of the coordinate axes. The vertices are provided in counter-clockwise order. Note that there may be cases where three consecutive vertices lie on a straight line.

You can use the shoelace formula in \(\LaTeX\) format as follows:

\[ \text{Area} = \frac{1}{2} \left| \sum_{i=0}^{n-1} (x_i y_{i+1} - x_{i+1} y_i) \right| \]

Since all coordinates are integers, the computed area is also an integer.

inputFormat

The first line contains an integer \(n\) (\(n \ge 4\)), representing the number of vertices of the polygon. Each of the following \(n\) lines contains two space-separated integers representing the \(x\) and \(y\) coordinates of a vertex. The vertices are given in counter-clockwise order.

outputFormat

Output a single integer which is the area of the polygon.

sample

4
0 0
4 0
4 3
0 3
12