#D6451. Area Folding
Area Folding
Area Folding
You are given one polygonal line, which is a collection of line segments. Your task is to calculate the sum of areas enclosed by the polygonal line.
A point is defined to be "enclosed" if and only if the point is unreachable without crossing at least one line segment from the point at infinity.
Input
The first line contains one integers N (2 ≤ N ≤ 100). N is the number of segments.
Each of the following N lines consists of two integers Xi and Yi (-105 ≤ Xi, Yi ≤ 105, 1 ≤ i ≤ N) which represents a vertex. A polygonal line is the segments which connect (Xj, Yj) and (Xj+1, Yj+1) ((Xj, Yj) ≠ (Xj+1, Yj+1), 1 ≤ j ≤ N-1). The distance between a segment Sj and all vertices except the end points on segment Sj is guaranteed to be greater than 0.01.
Output
Output the answer in a line. The answer may be printed with an arbitrary number of decimal digits, but may not contain an absolute or relative error greater than or equal to 10-6.
Examples
Input
5 0 0 1 1 1 0 0 1 0 0
Output
0.5
Input
5 0 0 1 1 1 0 0 1 1 0
Output
0.25
Input
21 1 1 -1 1 -1 2 -2 2 -2 1 -1 1 -1 -1 -2 -1 -2 -2 -1 -2 -1 -1 1 -1 1 -2 2 -2 2 -1 1 -1 1 1 2 1 2 2 1 2 1 1
Output
8
Input
16 0 0 1 0 1 1 0 1 0 2 0 3 1 3 1 2 2 2 2 3 3 3 3 2 3 1 2 1 2 0 3 0
Output
0
Input
7 26 52 33 12 -51 68 16 61 43 -26 87 24 12 10
Output
2714.840579710
inputFormat
Input
The first line contains one integers N (2 ≤ N ≤ 100). N is the number of segments.
Each of the following N lines consists of two integers Xi and Yi (-105 ≤ Xi, Yi ≤ 105, 1 ≤ i ≤ N) which represents a vertex. A polygonal line is the segments which connect (Xj, Yj) and (Xj+1, Yj+1) ((Xj, Yj) ≠ (Xj+1, Yj+1), 1 ≤ j ≤ N-1). The distance between a segment Sj and all vertices except the end points on segment Sj is guaranteed to be greater than 0.01.
outputFormat
Output
Output the answer in a line. The answer may be printed with an arbitrary number of decimal digits, but may not contain an absolute or relative error greater than or equal to 10-6.
Examples
Input
5 0 0 1 1 1 0 0 1 0 0
Output
0.5
Input
5 0 0 1 1 1 0 0 1 1 0
Output
0.25
Input
21 1 1 -1 1 -1 2 -2 2 -2 1 -1 1 -1 -1 -2 -1 -2 -2 -1 -2 -1 -1 1 -1 1 -2 2 -2 2 -1 1 -1 1 1 2 1 2 2 1 2 1 1
Output
8
Input
16 0 0 1 0 1 1 0 1 0 2 0 3 1 3 1 2 2 2 2 3 3 3 3 2 3 1 2 1 2 0 3 0
Output
0
Input
7 26 52 33 12 -51 68 16 61 43 -26 87 24 12 10
Output
2714.840579710
样例
5
0 0
1 1
1 0
0 1
1 0
0.25