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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,n) for (auto i ## __ = (n), i = (a); i <= i ## __; ++i)
#define FORD(i,a,n) for (auto i ## __ = (n), i = (a); i >= i ## __; --i)
#define REP(i,n) FOR(i,0, n - 1)
#define ALL(h) begin(h), end(h)
#define EB emplace_back
#define X first
#define Y second
#define V vector
#define tpv typedef V<

typedef long long LL;
typedef pair<int, int> PII;
tpv int> VI;
tpv VI> VVI;
tpv PII> VPII;
tpv LL> VLL;

constexpr char nl = '\n';
#define endl nl
#define ris return *this
#define tem template<class t

tem, class u> inline void mini(t& a, u&& b) { if (b < a) a = b; }
tem, class u> inline void maxi(t& a, u&& b) { if (b > a) a = b; }
int ceil2(int h) { return h < 2 ? 1 : 1 << (sizeof(h) * 8 - __builtin_clz(h - 1)); }

tem> struct Dump { t a, b; };
tem> auto dump(t&& h) -> Dump<decltype(begin(h))> { return {ALL(h)}; }
tem> auto stub(t* h) -> decltype(cerr << *h, 0);
tem> char stub(...);
#define enif(o) tem> typename enable_if<sizeof stub<t>(0) o 1, debug&>::type operator<<(t h)
#define dor > debug& operator<<
struct debug {
#ifdef DEBUG
#define deb debug()
	~debug() { cerr << nl; }
	enif(!=) { cerr << boolalpha << h; ris; }
	enif(==) {
		*this << '{';
		for (auto a = begin(h), b = end(h); a != b;)
			*this << *a++ << &" "[a == b];
		ris << '}';
	}
	tem, class u dor(pair<t, u> p) { ris << '(' << p.X << ", " << p.Y << ')'; }
	tem dor(Dump<t> d) {
		*this << "{\n";
		for (t a = d.a, c = a; a != d.b; ++a)
			*this << "  " << distance(c, a) << ": " << *a << nl;
		ris << '}';
	}
#else
	operator int() { return 0; }
#define deb 0 and debug()
	tem dor(t&&) { ris; }
#endif
};

#define imie(h...) #h ": " << (h) << " "
#define LOG(h...) deb << imie(h)
#define DOG(h...) deb << #h ": " << dump(h) << " "

using point = complex<long double>;

inline point::value_type dot(point a, point b) noexcept {
	return (conj(a) * b).real();
}

inline point::value_type cross(point a, point b) noexcept {
	return (conj(a) * b).imag();
}

inline point::value_type dist(point a, point b) noexcept {
	return abs(a - b);
}

inline point normalized(point a) noexcept {
	return a / abs(a);
}

inline ostream& operator<<(ostream& os, point p) noexcept {
	return os << '(' << p.real() << ' ' << p.imag() << ')';
}

struct Line {
	point dir;
	point shift;
	// goes through shift and shift + dir

	Line() : Line(point(0, 0), point(1, 1)) {}

	// a ---> b
	Line(point a, point b) : dir(b - a), shift(a) {}

	Line& shift_to_through(point p) {
		shift = p;
		return *this;
	}

	// Rotates by theta (shift still lies on the line)
	Line& rotate(long double theta) {
		dir = dir * polar(1.0l, theta);
		return *this;
	}
};

inline point intersection(point a, point b, point p, point q) noexcept {
  long double c1 = cross(p - a, b - a), c2 = cross(q - a, b - a);
  return (c1 * q - c2 * p) / (c1 - c2); // undefined if parallel
}

inline point intersection(Line a, Line b) noexcept {
	return intersection(a.shift, a.shift + a.dir, b.shift, b.shift + b.dir);
}

inline ostream& operator<<(ostream& os, Line l) noexcept {
	return os << '(' << l.shift << ' ' << l.shift + l.dir << ')';
}

inline point project(point p, Line l) noexcept {
	p -= l.shift;
	p = l.dir * dot(p, l.dir) / norm(l.dir);
	return p += l.shift;
}

struct IntPoint {
	int x, y;

	IntPoint(int a, int b) : x(a), y(b) {}

	IntPoint(PII p) : IntPoint(p.X, p.Y) {}

	IntPoint& operator+=(IntPoint a) noexcept {
		x += a.x;
		y += a.y;
		return *this;
	}

	IntPoint& operator-=(IntPoint a) noexcept {
		x -= a.x;
		y -= a.y;
		return *this;
	}

	operator point() const noexcept { return point(x, y); }
};

inline IntPoint operator+(IntPoint a, IntPoint b) noexcept {
	return {a.x + b.x, a.y + b.y};
}

inline IntPoint operator-(IntPoint a, IntPoint b) noexcept {
	return {a.x - b.x, a.y - b.y};
}

inline long long dot(IntPoint a, IntPoint b) noexcept {
	return LL(a.x) * b.x + LL(a.y) * b.y;
}

inline long long cross(IntPoint a, IntPoint b) noexcept {
	return LL(a.x) * b.y - LL(a.y) * b.x;
}

ostream& operator <<(ostream& os, const IntPoint& x) {
	return os << "(" << x.x << ' ' << x.y << ")";
}

struct IntLine {
	IntPoint dir;
	IntPoint shift;
	// goes through shift and shift + dir

	IntLine() : IntLine(IntPoint(0, 0), IntPoint(1, 1)) {}

	// a ---> b
	IntLine(IntPoint a, IntPoint b) : dir(b - a), shift(a) {}

	IntLine& shift_to_through(IntPoint p) {
		shift = p;
		return *this;
	}

	operator Line() { return Line(shift, dir + shift); }
};

inline point intersection(IntLine a, IntLine b) noexcept {
	return intersection(a.shift, a.shift + a.dir, b.shift, b.shift + b.dir);
}

inline ostream& operator<<(ostream& os, IntLine l) noexcept {
	return os << '(' << l.shift << ' ' << l.shift + l.dir << ')';
}

inline int sgn(LL x) { return (x < 0 ? -1 : (x > 0 ? 1 : 0)); }

template<class T>
decltype(cross(T(), T())) area(const V<T>& v) {
	decltype(cross(T(), T())) res {};
	auto prev = v.back();
	for (auto const& p : v)
		res += cross(prev, p), prev = p;

	return abs(res);
}

// constexpr long double EPS = 1e-8;

// kod z publicznej biblioteczki: : https://github.com/mareksom/acmlib/blob/master/code/kamil/halfplanes.cpp
namespace kamil_acmlib {

typedef long double LD;

// halfplanes_online
typedef complex<LL> P;

struct line {
    LL a,b,c;
    line(LL a_ = 0, LL b_ = 0, LL c_ = 0): a(a_), b(b_), c(c_) {} // <= 10^9
    line (P const &A, P const &B): a(A.imag()-B.imag()), b(B.real()-A.real()), c(A.real()*B.imag()-A.imag()*B.real()) {} //pts <= 10^6

    line operator - () const {return line(-a, -b, -c); }
    bool up() const { return a?(a<0):(b>0);}
};

inline LL wek(line const &a, line const &b) {return a.a*b.b-a.b*b.a;}
inline bool rown(line a, line b) {return wek(a,b) == 0;}
inline bool pokr(line a, line b) {return rown(a,b) && a.a*b.c == b.a*a.c && a.b*b.c == b.b*a.c;}
inline bool podobne(line a, line b) {return rown(a,b) && a.up() == b.up();}

inline complex<LD> prosta_prosta(line a, line b) {
    LL det = wek(a,b);
    LL x =  -a.c*b.b+b.c*a.b;
    LL y =  -a.a*b.c+a.c*b.a;
    return complex<LD>(x,y)/(LD)det;
}

inline LL weaker (line a, line b) { // czy a jest slabsze niz b
    assert(rown(a,b));
    if (abs(a.a) > abs(a.b)) return a.c*abs(b.a) -  b.c*abs(a.a);
    else return a.c*abs(b.b) -  b.c*abs(a.b);
}

struct Comp {
    bool operator()(const line& a, const line& b) const {
        if (a.up() != b.up()) return a.up() > b.up();
        return wek(a,b) > 0;
    }
};

const LD EPS = 1e-12;

struct przeciecie_polplaszczyzn {
    bool empty, pek;
    set<line, Comp> S;
    typedef set<line, Comp>::iterator iter;

    przeciecie_polplaszczyzn() : empty(false), pek(false) {};

    iter next(iter it){return (++it == S.end() ? S.begin() : it);}
    iter prev(iter it){return (it == S.begin() ? --S.end() : --it);}

    bool hide(line a, line b, line c) {
        if (rown(a,b)) {
            if (weaker(a, -b) < 0) empty = true;
            return false;
        }
        if (wek(a,b) < 0) swap(a,b);
        complex<LD> r = prosta_prosta(a,b);
        LD v = r.real() * c.a + r.imag() * c.b + c.c;
        if (wek(a,c) >=0  && wek(c,b) >=0 && v > -EPS) return true;
        if (wek(a,c) < 0  && wek(c,b) < 0) {
            if (v < -EPS) empty = true;
            else if (v < EPS) pek = true;
        }
        return false;
    }

    void add(line l) {
        if (empty) return;
        if (l.a == 0 && l.b == 0) {
            if (l.c < 0) empty = true;
            return;
        }
        iter it = S.lower_bound(l);
        //rownolegle
        if(it != S.end() && podobne(*it, l)) {
            if (weaker(l, *it)>=0) return;
            iter del = it;
            it = next(it);
            S.erase(del);
        }
        //*it>p
        if(int(S.size()) >= 2 && it == S.end()) it = S.begin();
        while(int(S.size()) >= 2 && hide(l, *next(it), *it)) {
            iter del = it;
            it = next(it);
            S.erase(del);
        }
        //*it<p
        if(int(S.size()) >= 2) it = prev(it);
        while(int(S.size()) >= 2 && hide(l, *prev(it), *it)) {
            iter del = it;
            it = prev(it);
            S.erase(del);
        }
        if(S.size() < 2 || !hide(*it, *next(it), l)) S.insert(l);
    }
    /*	 0 - puste	 1 - punkt	 2 - odcinek	 3 - półprosta	 4 - prosta
         5 - dodatnie (może nieskończone) pole (S.size() daje wowczas liczbę boków) */
    int type() {
        if(empty) return 0;
        if(int(S.size()) <= 4){
            vector<line> res(ALL(S));
            if (int(res.size()) == 2 && rown(res[0], res[1]) && weaker(res[0], -res[1])<0) return 0;
            REP(i, int(res.size())) REP(j, i) if(pokr(res[i], res[j])) {
                if(int(res.size()) == 2) return 4;
                if(int(res.size()) == 3) return 3;
                if(int(res.size()) == 4 && pokr(res[0], res[2]) && pokr(res[1], res[3])) return 1;
                return 2;
            }
            if(int(res.size()) == 3 && pek) return 1;
        }
        return 5;
    }
};

} // namespace kacl

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	V<array<PII, 2>> in(n);
	for (auto& p : in)
		cin >> p[0].X >> p[0].Y >> p[1].X >> p[1].Y;

	vector<IntLine> lines;
	auto process = [&](PII pp, PII qq) {
		IntPoint p(pp), q(qq);
		IntPoint qmp = q - p;

		int left = 0, right = 0;
		for (auto const& a : in) {
			int k1 = sgn(cross(qmp, a[0] - p));
			int k2 = sgn(cross(qmp, a[1] - p));

			int k = k1 * k2;
			if (k < 1)
				continue;

			if (k1 > 0)
				++left;
			else
				++right;
		}

		LOG(p) imie(q) " -->  " imie(left) imie(right);

		if (left > 0 and right == 0)
			lines.EB(p, q);
		else if (left == 0 and right > 0)
			lines.EB(q, p);
		else if (left == 0 and right == 0) {
			puts("0.0000000000000");
			exit(0);
		}
	};

	REP (i, n)
		FOR (j, i + 1, n - 1)
			for (auto const& p : in[i])
				for (auto const& q : in[j])
					process(p, q);

	DOG(lines);
	if (lines.size() < 2)
		return puts("0.0000000000000"), 0;

	// Calculate the area
	// Sort lines by arg
	stable_sort(ALL(lines), [](const IntLine& a, const IntLine& b) {
		auto adir = a.dir;
		auto bdir = b.dir;

		int a_in_upper = (adir.y > 0 or (adir.y == 0 and adir.x > 0));
		int b_in_upper = (bdir.y > 0 or (bdir.y == 0 and bdir.x > 0));

		if (a_in_upper and not b_in_upper)
			return true;
		if (not a_in_upper and b_in_upper)
			return false;

		return cross(adir, bdir) > 0;
	});

	DOG(lines);
	for (auto l : lines)
		deb << arg(point(l.dir));

#if 0
	V<IntLine> unpar_lines;
	for (auto l : lines) {
		if (unpar_lines.empty()) {
			unpar_lines.EB(l);
			continue;
		}

		if (cross(l.dir, unpar_lines.back().dir) != 0) {
			unpar_lines.EB(l);
			continue;
		}

		// l and unpar_lines.back() are parallel...
		if (cross(l.dir, unpar_lines.back().shift - l.shift) < 0)
			unpar_lines.back() = l;
	}

	DOG(unpar_lines);
	for (auto l : unpar_lines)
		deb << arg(point(l.dir));
#else
	kamil_acmlib::przeciecie_polplaszczyzn pp;
	for (auto l : lines) {
		auto a = l.shift;
		auto b = l.dir + l.shift;
		pp.add(kamil_acmlib::line({a.x, a.y}, {b.x, b.y}));
	}

	LOG(pp.type());
	if (pp.type() < 5)
		return puts("0.0000000000000"), 0;

	V<point> points;
	auto prev = *pp.S.rbegin();
	for (auto const& l : pp.S) {
		points.EB(kamil_acmlib::prosta_prosta(l, prev));
		prev = l;
	}

	cout << fixed << setprecision(13) << area(points) / 2 << nl;
#endif

	return 0;
}