1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto &i : a)
#define SZ(i) ((int)(i).size())
#define X first
#define Y second
#define PR std::pair
#define PII std::pair<int, int>
#define MP std::make_pair
#define ll long long
#define VI std::vector<int>
#define ld long double
#define Point PR<ld, ld>

ld EPS = 0.000000001;

void fail(){
	std::cout << "0.0000000000000000\n";
	std::exit(0);
}

struct Vec{
	Point A, B;
	Vec() : A(MP(-100000, -1000000)), B(MP(-1000000, -1000000)) {}
	Vec(Point pa, Point pb) : A(pa), B(pb) {}
	std::string str(){
		return "[(" + std::to_string(A.X) + "," + std::to_string(A.Y) + "), ("
				+ std::to_string(B.X) + "," + std::to_string(B.Y) + ")]";
	}
};

Point azero(const Vec &vec){
	return MP(vec.B.X-vec.A.X, vec.B.Y-vec.A.Y);
}

inline bool equal(ld a, ld b){
	return std::abs(a-b) < EPS;
}

bool parallel(Vec a, Vec b){
	Point pa = MP(a.B.X-a.A.X, a.B.Y-a.A.Y);
	Point pb = MP(b.B.X-b.A.X, b.B.Y-b.A.Y);
	return equal(pa.X*pb.Y, pa.Y*pb.X);
}
struct Line{
	ld A, B, C;
	Line(){}
	Line(ld a, ld b, ld c) : A(a), B(b), C(c) {}
};
inline Line get_line(ld x1, ld y1, ld x2, ld y2){
	return Line(y1-y2, x2-x1, (x1-x2)*y1+(y2-y1)*x1);
}
Point get_intersection(const Line &x, const Line &y){
	return MP((x.C*y.B-x.B*y.C)/(x.B*y.A-x.A*y.B), (x.A*y.C-x.C*y.A)/(x.B*y.A-x.A*y.B));
}

int side(Vec vec, Point a){
	ld det = (vec.B.X-vec.A.X)*(a.Y-vec.A.Y)-(vec.B.Y-vec.A.Y)*(a.X-vec.A.X);
	if(equal(0.0, det)) return 0;
	return (det > 0.0 ? 1 : -1);
}

int n;
std::vector<Vec> restr;
std::vector<std::vector<Vec> > pres;
std::vector<PR<Point, int> > points;
std::set<Point> goodpts;

void check_points(Vec vec, int n1, int n2, int i1, int i2){
	VI sd(n);
	bool left = false;
	bool right = false;
	TRAV(p, points){
		if(p.Y == n1 || p.Y == n2) continue;
		int s = side(vec, p.X);
		if(s != 0){
			if(s == sd[p.Y]){
				if(s == -1) left = true;
				if(s == 1) right = true;
			}else sd[p.Y] = s;
		}
	}
	if(!left && !right){
		fail();
	}
	if(!left){
		Point zerovec_left = azero(vec);
		bool good = true;
		FOR(i, SZ(pres[i1])){
			FOR(j, SZ(pres[i1])){
				if(side(pres[i1][i], vec.B) == 0){
					Point zero = azero(pres[i1][i]);
					if(zerovec_left.X*zero.X+zerovec_left.Y*zero.Y < 0) fail();
					else{
						good = false;
						break;
					}
					// if(side(pres[i1][i], MP(vec.B.X+49.210, vec.B.Y+50.012))
					// 	!= side(pres[i1][i], MP(vec.B.X+49.210, vec.B.Y+50.012))
					// 	||
					// 	side(pres[i1][i], MP(vec.B.X+21.210, vec.B.Y+50.012))
					// 	!= side(pres[i1][i], MP(vec.B.X+21.210, vec.B.Y+50.012))) fail();
					// else{
					// 	good = false;
					// 	break;
					// }
				}
				if(side(pres[i1][i], vec.B) == 1 && side(pres[i1][j], vec.B) == -1
					&& side(pres[i1][i], pres[i1][j].B) == 1) good = false;
			}
			if(!good) break;
		}
		if(good) pres[i1].push_back(vec);
	}
	if(!right){
		Point zerovec_right = azero(Vec(vec.B, vec.A));
		bool good = true;
		FOR(i, SZ(pres[i2])){
			FOR(j, SZ(pres[i2])){
				if(side(pres[i2][i], vec.A) == 0){
					Point zero = azero(pres[i2][i]);
					if(zerovec_right.X*zero.X+zerovec_right.Y*zero.Y < 0) fail();
					else{
						good = false;
						break;
					}
					// if(side(pres[i2][i], MP(vec.A.X+49.210, vec.A.Y+50.012))
					// 	!= side(pres[i2][i], MP(vec.A.X+49.210, vec.A.Y+50.012))
					// 	||
					// 	side(pres[i2][i], MP(vec.A.X+21.210, vec.A.Y+50.012))
					// 	!= side(pres[i2][i], MP(vec.A.X+21.210, vec.A.Y+50.012))) fail();
					// else{
					// 	good = false;
					// 	break;
					// }
				}
				if(side(pres[i2][i], vec.A) == 1 && side(pres[i2][j], vec.A) == -1
					&& side(pres[i2][i], pres[i2][j].B) == 1) good = false;
			}
			if(!good) break;
		}
		if(good) pres[i2].push_back(Vec(vec.B, vec.A));
	}
}

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin >> n;
	FOR(i, n){
		int ax, ay, bx, by;
		std::cin >> ax >> ay >> bx >> by;
		points.push_back(MP(MP(ax, ay), i));
		points.push_back(MP(MP(bx, by), i));
	}
	pres.resize(2*n);
	FOR(i, 2*n){
		REP(j, i+1, 2*n){
			if(points[i].Y == points[j].Y) continue;
			check_points(Vec(points[i].X, points[j].X), points[i].Y, points[j].Y, i, j);
		}
	}
	TRAV(p, pres) TRAV(v, p) restr.push_back(v);
	// std::cout << "RESTR " << SZ(restr) << std::endl;
	// std::cout << "RESTR:\n";
	// TRAV(r, restr) std::cout << r.str() << "\n";
	std::random_shuffle(restr.begin(), restr.end());
	FOR(i, SZ(restr)) REP(j, i+1, SZ(restr)){
		if(parallel(restr[i], restr[j])) continue;
		Point inter = get_intersection(get_line(restr[i].A.X, restr[i].A.Y,
														restr[i].B.X, restr[i].B.Y),
												get_line(restr[j].A.X, restr[j].A.Y,
														restr[j].B.X, restr[j].B.Y));
		bool bad = false;
		TRAV(r, restr){
			if(side(r, inter) == -1){
				bad = true;
				break;
			}
		}
		if(!bad){
			// std::cout << "adding " << inter.X << "," << inter.Y << " from " << restr[i].str() << " " << restr[j].str() << std::endl;
			goodpts.insert(inter);
		}
	}
	if(SZ(goodpts) < 3) fail();
	std::vector<Point> goodvec;
	TRAV(x, goodpts) goodvec.push_back(x);
	
	// uncomment ?!
	// bool col = true;
	// REP(i, 2, SZ(goodvec)) if(side(Vec(goodvec[0], goodvec[1]), goodvec[i]) != 0){
		// col = false;
		// break;
	// }
	// if(col) fail();

	// std::cout << "PTS: " << SZ(goodvec) << "\n";
	// TRAV(s, goodvec) std::cout << s.X << " " << s.Y << std::endl;
	std::vector<bool> was(SZ(goodvec));
	VI hull;
	hull.push_back(0);
	was[0] = true;
	do{
		int cur = 0;
		while(cur < SZ(was) && was[cur]) cur++;
		if(cur == SZ(was)){
			hull.push_back(0);
		}else{
			FOR(i, SZ(goodvec)){
				if(cur == i) continue;
				if(!was[i] && side(Vec(goodvec[hull.back()], goodvec[cur]), goodvec[i]) == 1)
					cur = i;
			}
			if(hull.back() != 0 && side(Vec(goodvec[hull.back()], goodvec[cur]), goodvec[0]) == 1)
				cur = 0;
			hull.push_back(cur);
			was[cur] = true;
		}
	}while(hull.back() != hull[0]);
	// std::cout << "HULL:\n";
	// TRAV(x, hull) std::cout << goodvec[x].X << " " << goodvec[x].Y << std::endl;
	ld ans = 0.0;
	FOR(i, SZ(hull)){
		Point cur = goodvec[hull[i]];
		Point next = goodvec[hull[(i+1)%SZ(hull)]];
		ans += 0.5*(cur.Y*next.X-cur.X*next.Y);
	}
	std::cout << std::fixed << std::setprecision(20) << ans << "\n";
	return 0;
}