Polygon
A polygon has been drawn on a plane, with its vertices located at integer coordinates. The sides of this polygon are aligned parallel to the coordinate axes. However, all the horizontal sides have been erased, leaving only N
vertical sides visible. Your task is to determine the perimeter P
and the area S
of the original polygon.
The input begins with a single integer N
, representing the number of vertical sides. The next N
lines each contain three integers: X
, Y[1]
, and Y[2]
. These integers define a vertical side with endpoints at (X, Y[1])
and (X, Y[2])
. Your program should output two numbers: the perimeter P
and the area S
of the original polygon.
Constraints:
N < 10000
|X| ≤ 1000
|Y| ≤ 1000
Note that the sides of the polygon do not intersect, and each vertex is shared by exactly two sides of the polygon.