Problem: 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

Solution (in CPP):

Solution:
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1);
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline double ABS(double a){return max(a,-a);}
struct Pt {
	double x, y;
	Pt() {}
	Pt(double x, double y) : x(x), y(y) {}
	Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
	Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
	Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
	Pt operator-() const { return Pt(-x, -y); }
	Pt operator*(const double &k) const { return Pt(x * k, y * k); }
	Pt operator/(const double &k) const { return Pt(x / k, y / k); }
	double ABS() const { return sqrt(x * x + y * y); }
	double abs2() const { return x * x + y * y; }
	double arg() const { return atan2(y, x); }
	double dot(const Pt &a) const { return x * a.x + y * a.y; }
	double det(const Pt &a) const { return x * a.y - y * a.x; }
};
double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }
int iSP(Pt a, Pt b, Pt c) {
	int s = sig((b - a).det(c - a));
	if (s) return s;
	if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
	if (sig((a - b).dot(c - b)) < 0) return +2; // a-b-c
	return 0;
}
int iLL(Pt a, Pt b, Pt c, Pt d) {
	if (sig((b - a).det(d - c))) return 1; // intersect
	if (sig((b - a).det(c - a))) return 0; // parallel
	return -1; // correspond
}
bool iSS(Pt a, Pt b, Pt c, Pt d) {
	return (iSP(a, b, c) * iSP(a, b, d) <= 0 && iSP(c, d, a) * iSP(c, d, b) <= 0);
}
Pt pLL(Pt a, Pt b, Pt c, Pt d) {
	b = b - a; d = d - c; return a + b * (c - a).det(d) / b.det(d);
}
Pt p[110];
int it[110][110];
int ind[110][110];
Pt ip[110][110];
int t[110];
vector<int> g[12000];
vector<Pt> hb;
int add(Pt a){
	for(int i=0;i<hb.size();i++){
		if((a-hb[i]).ABS()<EPS)return i;
	}
	hb.push_back(a);
	return hb.size()-1;
}
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++){
		double X,Y;
		scanf("%lf%lf",&X,&Y);
		p[i]=Pt(X,Y);
		t[i]=add(p[i]);
	}
	for(int i=0;i<a-1;i++){
		for(int j=0;j<a-1;j++){
			if(i==j)continue;
			if(iLL(p[i],p[i+1],p[j],p[j+1])>0&&iSS(p[i],p[i+1],p[j],p[j+1])){
				it[i][j]=1;
				ip[i][j]=pLL(p[i],p[i+1],p[j],p[j+1]);
				ind[i][j]=add(ip[i][j]);
			}
		}
	}
	int sz=hb.size();
	for(int i=0;i<a-1;i++){
		vector<pair<double,int> > tmp;
		tmp.push_back(make_pair(0,t[i]));
		tmp.push_back(make_pair((p[i+1]-p[i]).ABS(),t[i+1]));
		for(int j=0;j<a-1;j++){
			if(!it[i][j])continue;
			tmp.push_back(make_pair((ip[i][j]-p[i]).ABS(),ind[i][j]));
		}
		std::sort(tmp.begin(),tmp.end());
		for(int j=0;j<tmp.size()-1;j++){
			if(tmp[j].second==tmp[j+1].second)continue;
			g[tmp[j].second].push_back(tmp[j+1].second);
			g[tmp[j+1].second].push_back(tmp[j].second);
		}
	}
	double ret=0;
	int start=0;
	for(int i=1;i<sz;i++){
		if(hb[start].x>hb[i].x)start=i;
	}
	int at=start;
	Pt vec=Pt(0,-1);
	while(1){
		int to=-1;
		double val=9999999;
		double curth=vec.arg();
		for(int i=0;i<g[at].size();i++){
			double th=(hb[g[at][i]]-hb[at]).arg()-curth;
			if(th>PI+EPS)th-=2*PI;
			if(th<-PI+EPS)th+=2*PI;
			if(val>th){
				val=th;
				to=g[at][i];
			}
		}
		vec=hb[to]-hb[at];
		ret+=hb[at].det(hb[to]);
		at=to;
		if(at==start)break;
	}
	printf("%.12f\n",ABS(ret)/2);
}