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
233
234
235
236
237
238
239
240
#include <bits/stdc++.h>
#define pb push_back

using namespace std;

using ld = long double;

const int N = 105;
const ld PI = acosl(-1);
const ld eps = 1e-10;

struct point_t {
	ld x, y;
	point_t(){ x = y = 0; }
	point_t(ld x, ld y):x(x), y(y){}
	friend point_t operator + (point_t x, point_t y){
		return point_t(x.x + y.x, x.y + y.y);
	}
	friend point_t operator - (point_t x, point_t y){
		return point_t(x.x - y.x, x.y - y.y);
	}
	friend point_t operator * (point_t x, ld y){
		return point_t(x.x * y, x.y * y);
	}
	ld angle() const {
		return atan2(y, x);
	}
	ld length(){
		return sqrtl(x * x + y * y);
	}
	friend ld operator * (point_t a, point_t b){
		return a.x * b.y - a.y * b.x;
	}
} a[N], b[N];
struct line_t {
	point_t u, v; 
	line_t(){}
	line_t(point_t u, point_t v):u(u), v(v){}
	ld angle() const { return (v - u).angle(); }
} ;
bool equal(ld x, ld y){
	return fabs(x - y) < eps;
}
bool equal(point_t a, point_t b){
	return equal(a.x, b.x) && equal(a.y, b.y);
}
ld normal(ld x){
	while (x < -PI) x += 2 * PI;
	while (x >= PI) x -= 2 * PI;
	return x;
}
ld distance(ld l, ld r){
	l = normal(l), r = normal(r);
	if (l <= r) return r - l;
	return r - l + 2 * PI;
}
bool on_left(point_t O, point_t A, point_t B){
	return (O - B) * (B - A) < eps;
}
bool on_left(point_t O, line_t L){
	return on_left(O, L.u, L.v);
}
point_t rotate(point_t o, ld angle){
	// clockwise
	ld sina = sinl(angle), cosa = cosl(angle);
	return point_t(o.x * cosa + o.y * sina, o.y * cosa - o.x * sina);
}
line_t rotate(line_t o, ld angle){
	return line_t(rotate(o.u, angle), rotate(o.v, angle));
}
ld area(vector<point_t> polygon){
	ld res = 0;
	int n = polygon.size(), i;
	for (i = 0; i < n; ++i) {
		res += (polygon[i] - polygon[0]) * (polygon[(i + 1) % n] - polygon[0]);
	}
	res = fabs(res) / 2;
	return res;
}
bool equal(line_t a, line_t b){
	return equal(area({a.u, b.u, b.v}), 0) && equal(area({a.v, b.u, b.v}), 0);
}
bool segmentcross(point_t a, point_t c, point_t b, point_t d, point_t &o) {
	ld Sabd = area({a, b, d});
	ld Scbd = area({c, b, d});
	if (equal(Sabd + Scbd, 0)) return false; 
	ld Q = Sabd / (Sabd + Scbd);
	if (Q < -eps || Q > 1 + eps) return false;
	return o = a + (c - a) * Q, true;
}
bool linecross(point_t a, point_t c, point_t b, point_t d, point_t &o) {
	ld Sabd = (b - a) * (d - a);
	ld Scbd = -((b - c) * (d - c));
	if (equal(fabs(Sabd) + fabs(Scbd), 0)) return false; 
	ld Q = Sabd / (Sabd + Scbd);
	return o = a + (c - a) * Q, true;
}
bool linecross(line_t a, line_t b, point_t &o){
	return linecross(a.u, a.v, b.u, b.v, o);
}
point_t cross(line_t a, line_t b){
	point_t res;
	assert(linecross(a, b, res));
	return res;
}
vector<point_t> convex_hull(vector<point_t> points){
	int i, o, n = points.size(), m;
	for (i = o = 0; i < n; ++i) {
		if (points[i].x < points[o].x || points[i].x == points[o].x && points[i].y < points[o].y) {
			o = i;
		}
	}
	swap(points[o], points[0]);
	for (i = 1; i < n; ++i) {
		points[i] = points[i] - points[0];
	}
	sort(points.begin() + 1, points.end(), [&](point_t a, point_t b){
		ld ca = a.angle(), cb = b.angle();
		if (equal(ca, cb)) return a.length() < b.length();
		return ca < cb;
		});
	vector<point_t> hull;
	hull.emplace_back(0, 0), m = 1;
	for (i = 1; i < n; ++i) {
		while (m > 1 && (points[i] - hull[m - 1]) * (hull[m - 1] - hull[m - 2]) > -eps) --m, hull.pop_back();
		++m, hull.pb(points[i]);
	}
	for (auto &v : hull) v = v + points[0];
	return hull;
}
vector<point_t> planecross(vector<line_t> planes){
	int n = planes.size(), l = 1, r = 0, x;
	vector<line_t> q(n + 2);
	sort(planes.begin(), planes.end(), [&](line_t x, line_t y){ return x.angle() < y.angle(); });
	while (planes.size() > 1 && equal(planes.back(), planes[0])) planes.pop_back(); 
	q[++r] = planes[0];
	for (x = 1; x < planes.size(); ++x) {
		if (equal(planes[x], planes[x - 1])) continue; 
		while (l < r && !on_left(cross(q[r - 1], q[r]), planes[x])) --r;
		while (l < r && !on_left(cross(q[l], q[l + 1]), planes[x])) ++l;
		q[++r] = planes[x];
	}
	while (l < r && !on_left(cross(q[r - 1], q[r]), q[l])) --r;
	while (l < r && !on_left(cross(q[l], q[l + 1]), q[r])) ++l;
	if (r - l <= 1) return vector<point_t>();
	/* 
	for (x = l; x <= r; ++x) {
		cerr << '(' << q[x].u.x << ", " << q[x].u.y << ')';
		cerr << "  ->  ";
		cerr << '(' << q[x].v.x << ", " << q[x].v.y << ')';
		cerr << endl;
	}
	*/
	vector<point_t> res;
	for (x = l; x < r; ++x) res.pb(cross(q[x], q[x + 1]));
	res.pb(cross(q[r], q[l]));
//	for (auto it : res) cerr << '(' << it.x << ", " << it.y << ')' << endl;
	return res;
}

#define random own_random 

using u64 = unsigned long long;
struct random {
	u64 s0, s1;
	random(){
		s0 = size_t(new char) xor time(nullptr);
		s1 = size_t(new char) xor (s0 + time(nullptr));
	}
	random(u64 s0, u64 s1):s0(s0), s1(s1){}
	u64 get(){
		std::swap(s0, s1);
		s1 ^= s1 << 23, s1 ^= (s1 >> 17) ^ s0 ^ (s0 >> 26);
		return s0 + s1;
	}
	int randint(int L, int R){
		return get() % (R - L + 1) + L;
	}
} random;
int n;

template <class T> bool chkmin(T &a, T b){ return b < a ? a = b, true : false; }
template <class T> bool chkmax(T &a, T b){ return a < b ? a = b, true : false; }

const ld inf = 23333;

int main(){
	int i, j, o;
	double x, y;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) {
		scanf("%lf%lf", &x, &y), a[i] = point_t(x, y);
		scanf("%lf%lf", &x, &y), b[i] = point_t(x, y);
	}
	vector<ld> ranges;
	ranges.clear();
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) if (i != j) {
		ranges.pb((a[j] - a[i]).angle());
		ranges.pb((a[j] - b[i]).angle());
		ranges.pb((b[j] - a[i]).angle());
		ranges.pb((b[j] - b[i]).angle());
	}
	for (i = 1; i <= n; ++i) {
		ranges.pb((b[i] - a[i]).angle());
		ranges.pb((a[i] - b[i]).angle());
	}
	sort(ranges.begin(), ranges.end());
	ranges.erase(unique(ranges.begin(), ranges.end()), ranges.end());
	vector<line_t> planes;
	for (i = 0; i < ranges.size(); ++i) {
		ld l = ranges[i], r = ranges[(i + 1) % ranges.size()];
		if (l > r) r += 2 * PI; 
		ld mid = (l + r) * 0.5;
		ld cur = inf;
		point_t pos, tmp;
		for (j = 1; j <= n; ++j) {
			ld ya = rotate(a[j], mid).y;
			ld yb = rotate(b[j], mid).y;
			if (chkmin(cur, max(ya, yb))) pos = ya < yb ? b[j] : a[j];
		}
		if (planes.size() && equal(planes.back().u, pos)) {
			planes.pop_back();
		} else {
			tmp = rotate(pos, l);
			planes.pb(rotate(line_t(tmp, tmp + point_t(1, 0)), -l));
		}
		tmp = rotate(pos, r);
		planes.pb(rotate(line_t(tmp, tmp + point_t(1, 0)), -r));
	}
	/* 
	for (auto edge : planes) {
		cerr << '(' << edge.u.x << ", " << edge.u.y << ')';
		cerr << "  ->  ";
		cerr << '(' << edge.v.x << ", " << edge.v.y << ')';
		cerr << endl;
	}
	*/
	vector<point_t> result = planecross(planes);
	printf("%.16lf\n", (double)area(result));
}