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
#pragma region Template 
#include <bits/stdc++.h> 

using namespace std;

#define For(i, n) for (int i = 0; i < (n); i++)
#define ForD(i, n) for (int i = (n) - 1; i >= 0; i--)
#define SORT(x) sort(begin(x), end(x))
#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#if DEBUG
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string>) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
#else
#define error(...) do {} while (0)
#endif

#define _upgrade do { ios::sync_with_stdio(0); cin.tie(0); } while (0)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

#pragma endregion 

// Źródło: https://codeforces.com/blog/entry/48868
// https://codeforces.com/blog/entry/48122

template <class F>
struct Point {
  F x, y;
  Point() : x(0), y(0) {}
  Point(const F& x, const F& y) : x(x), y(y) {}
//   Point(const F x, const F y) : x(x), y(y) {}

  void swap(Point& other) { using std::swap; swap(x, other.x); swap(y, other.y); }
  template <class F1> explicit operator Point<F1> () const {
    return Point<F1>(static_cast<F1>(x), static_cast<F1>(y)); }
  template <class F1> Point& operator = (const Point<F1>& other) {
    x = other.x; y = other.y; return *this; }
  template <class F1> Point& operator += (const Point<F1>& other) {
    x += other.x; y += other.y; return *this; }
  template <class F1> Point& operator -= (const Point<F1>& other) {
    x -= other.x; y -= other.y; return *this; }
  template <class F1> Point& operator *= (const F1& factor) {
    x *= factor; y *= factor; return *this; }
  template <class F1> Point& operator /= (const F1& factor) {
    x /= factor; y /= factor; return *this; }
};

template <class F> int read(Point<F>& point) { return read(point.x, point.y) / 2; }
template <class F> int write(const Point<F>& point) { return write(point.x, point.y); }

template <class F> istream& operator >> (istream& is, Point<F>& point) {
  return is >> point.x >> point.y; }
template <class F> ostream& operator << (ostream& os, const Point<F>& point) {
  return os << point.x << ' ' << point.y; }

template <class F> inline Point<F> makePoint(const F& x, const F& y) { return Point<F>(x, y); }
template <class F> void swap(Point<F>& lhs, Point<F>& rhs) { lhs.swap(rhs); }

#define FUNC1(name, arg, expr) \
template <class F> inline auto name(const arg) -> decltype(expr) { return expr; }
#define FUNC2(name, arg1, arg2, expr) \
template <class F1, class F2> \
inline auto name(const arg1, const arg2) -> decltype(expr) { return expr; }
#define FUNC3(name, arg1, arg2, arg3, expr) \
template <class F1, class F2, class F3> \
inline auto name(const arg1, const arg2, const arg3) -> decltype(expr) { return expr; }

FUNC1(operator -, Point<F>& point, makePoint(-point.x, -point.y))
FUNC2(operator +, Point<F1>& lhs, Point<F2>& rhs, makePoint(lhs.x + rhs.x, lhs.y + rhs.y))
FUNC2(operator -, Point<F1>& lhs, Point<F2>& rhs, makePoint(lhs.x - rhs.x, lhs.y - rhs.y))
FUNC2(operator *, F1& factor, Point<F2>& rhs, makePoint(factor * rhs.x, factor * rhs.y))
FUNC2(operator *, Point<F1>& lhs, F2& factor, makePoint(lhs.x * factor, lhs.y * factor))
FUNC2(operator /, Point<F1>& lhs, F2& factor, makePoint(lhs.x / factor, lhs.y / factor))

FUNC2(operator *, Point<F1>& lhs, Point<F2>& rhs, lhs.x * rhs.x + lhs.y * rhs.y)
FUNC2(operator ^, Point<F1>& lhs, Point<F2>& rhs, lhs.x * rhs.y - lhs.y * rhs.x)

// < 0 if rhs <- lhs counter-clockwise, 0 if collinear, > 0 if clockwise.
FUNC2(ccw, Point<F1>& lhs, Point<F2>& rhs, rhs ^ lhs)
FUNC3(ccw, Point<F1>& lhs, Point<F2>& rhs, Point<F3>& origin, ccw(lhs - origin, rhs - origin))

FUNC2(operator ==, Point<F1>& lhs, Point<F2>& rhs, lhs.x == rhs.x && lhs.y == rhs.y)
FUNC2(operator !=, Point<F1>& lhs, Point<F2>& rhs, !(lhs == rhs))

FUNC2(operator <, Point<F1>& lhs, Point<F2>& rhs,
    lhs.y < rhs.y || (lhs.y == rhs.y && lhs.x < rhs.x))
FUNC2(operator >, Point<F1>& lhs, Point<F2>& rhs, rhs < lhs)
FUNC2(operator <=, Point<F1>& lhs, Point<F2>& rhs, !(lhs > rhs))
FUNC2(operator >=, Point<F1>& lhs, Point<F2>& rhs, !(lhs < rhs))

// Angles and rotations (counter-clockwise).
FUNC1(angle, Point<F>& point, atan2(point.y, point.x))
FUNC2(angle, Point<F1>& lhs, Point<F2>& rhs, atan2(lhs ^ rhs, lhs * rhs))
FUNC3(angle, Point<F1>& lhs, Point<F2>& rhs, Point<F3>& origin,
      angle(lhs - origin, rhs - origin))
FUNC3(rotate, Point<F1>& point, F2& angleSin, F3& angleCos,
      makePoint(angleCos * point.x - angleSin * point.y,
                angleSin * point.x + angleCos * point.y))
FUNC2(rotate, Point<F1>& point, F2& angle, rotate(point, sin(angle), cos(angle)))
FUNC3(rotate, Point<F1>& point, F2& angle, Point<F3>& origin,
      origin + rotate(point - origin, angle))
FUNC1(perp, Point<F>& point, makePoint(-point.y, point.x))

// Distances.
FUNC1(abs, Point<F>& point, point * point)
FUNC1(norm, Point<F>& point, sqrt(abs(point)))
FUNC2(dist, Point<F1>& lhs, Point<F2>& rhs, norm(lhs - rhs))
FUNC2(dist2, Point<F1>& lhs, Point<F2>& rhs, abs(lhs - rhs))
FUNC2(bisector, Point<F1>& lhs, Point<F2>& rhs, lhs * norm(rhs) + rhs * norm(lhs))

#undef FUNC1
#undef FUNC2
#undef FUNC3

template<typename T>
inline T Det(T a, T b, T c, T d)
{
	return a*d - b*c;
}

// To też gdzieś z neta

///Calculate intersection of two lines.
///\return true if found, false if not found or error
template<typename T>
bool LineLineIntersect(
	T x1, T y1, //Line 1 start
	T x2, T y2, //Line 1 end
	T x3, T y3, //Line 2 start
	T x4, T y4, //Line 2 end
	T &ixOut, T &iyOut) //Output 
{
	//http://mathworld.wolfram.com/Line-LineIntersection.html

	T detL1 = Det(x1, y1, x2, y2);
	T detL2 = Det(x3, y3, x4, y4);
	T x1mx2 = x1 - x2;
	T x3mx4 = x3 - x4;
	T y1my2 = y1 - y2;
	T y3my4 = y3 - y4;

	T xnom = Det(detL1, x1mx2, detL2, x3mx4);
	T ynom = Det(detL1, y1my2, detL2, y3my4);
	T denom = Det(x1mx2, y1my2, x3mx4, y3my4);
	if(abs((ld)denom) <= 0.0000000001 )//Lines don't seem to cross
	{
		ixOut = NAN;
		iyOut = NAN;
		return false;
	}

	ixOut = xnom / denom;	
	iyOut = ynom / denom;
	if(!isfinite(ixOut) || !isfinite(iyOut)) //Probably a numerical issue
		return false;

	return true; //All OK
}

pair<bool, Point<ld>> intersect(Point<ld> x1, Point<ld> y1, Point<ld> x2, Point<ld> y2) {
	Point<ld> result;
	if (LineLineIntersect(x1.x, x1.y, y1.x, y1.y, x2.x, x2.y, y2.x, y2.y, result.x, result.y)) {
		return {true, result};
	} else return {false, result};
}

void test_line_intersect() {
	while (true) {
		// Point<ld> ps[3];
		// For (i, 3) {
		// 	cin >> ps[i].x >> ps[i].y;
		// }

		// auto res = ccw(ps[0], ps[1], ps[2]);
		// cout << res << endl;
		Point<ld> ps[4];
		For (i, 4) {
			cin >> ps[i].x >> ps[i].y;
		}

		auto res = intersect(ps[0], ps[1], ps[2], ps[3]);
		cout << res.first << ": " << res.second.x << " " << res.second.y << endl;
	}
}

inline int prev(int i, int n) { return i == 0 ? n-1 : i-1; }
inline int next(int i, int n) { return i == n-1 ? 0 : i+1; }

const int N = 110;
typedef Point<ld> point;

// TODO: Use Point<long long>
ld get_side(point a, point b, point c) {
	return ccw(a, b, c);
}

pair<point, point> all_points[N];
vector<point> valid_area = {Point<ld>(-500, -500), Point<ld>(500, -500), Point<ld>(500, 500), Point<ld>(-500, 500)};

int n;

const ld EPS = 0.000000001;

int db_sign(ld x) {
	if (x < -EPS) return -1;
	if (x > EPS) return 1;
	return 0;
}

void exit_area_zero() {
	printf("%.14Lf\n", (ld)0.0);
	exit(0);
}

void cut_side(int side, pair<point, point> line) {
	// cout << endl << endl << "Doing cut" << endl;

	int start_pos = -1;
	For (i, (int)valid_area.size()) {
		// printf("line: (%.3Lf, %.3Lf) -> (%.3Lf, %.3Lf); point: (%.3Lf, %.3Lf); got side: %d, cut side: %d\n"
		//       , line.first.x, line.first.y, line.second.x, line.second.y
		// 	  , valid_area[i].x, valid_area[i].y
		// 	  , db_sign(get_side(line.first, line.second, valid_area[i]))
		// 	  , side);

		if (db_sign(get_side(line.first, line.second, valid_area[i])) * side < 0) {
			start_pos = i;
			break;
		}
	}

	if (start_pos == -1) {
		// cout << "Exit early here1" << endl;
		return exit_area_zero();
	}

	vector<point> next_area;
	For (iii, (int)valid_area.size()) {
		int next_pos = (start_pos + 1) % (int)valid_area.size();
		// strona obecnego względem cut-side
		int start_side = db_sign(get_side(line.first, line.second, valid_area[start_pos])) * side;
		// strona następnego względem cut-side
		int next_side = db_sign(get_side(line.first, line.second, valid_area[next_pos])) * side;

		// obecny punkt jest po przeciwnej stronie co cut-side, lub leży na cut-side
		if (start_side <= 0) {
			next_area.push_back(valid_area[start_pos]);
		}

		// dwa kolejne punkty są po dwóch stronach
		if (start_side * next_side < 0) {
			auto inter_res = intersect(line.first, line.second, valid_area[start_pos], valid_area[next_pos]);
			if (!inter_res.first) {
				// cout << "Exit early here2" << endl;
				return exit_area_zero();
			}

			next_area.push_back(inter_res.second);
		}

		start_pos = next_pos;
	}

	valid_area = next_area;

	// cout << "Exit valid area:" << endl;
	// for (auto x : valid_area) {
	// 	printf("(%.3Lf, %.3Lf)\n", x.x, x.y);
	// }
	// cout << "Done valid area" << endl;
}

ld area(const vector<point> &poly) {
  int nn = int(poly.size());
  ld area = 0.0;
  for (int i = 0; i < nn; ++i)
    area += poly[i].x * (poly[next(i, nn)].y - poly[prev(i, nn)].y);
  return area;
}

int main() {
	// _upgrade;

	scanf("%d", &n);

	For (i, n) {
		scanf("%Lf %Lf %Lf %Lf", &all_points[i].first.x, &all_points[i].first.y 
		     , &all_points[i].second.x, &all_points[i].second.y);
	}

	vector<pair<pair<int, int>, pair<point, point>>> lines;

	For (i, n) {
		for (int j = i + 1; j < n; j++) {
			lines.push_back({{i, j}, {all_points[i].first, all_points[j].first}});
			lines.push_back({{i, j}, {all_points[i].first, all_points[j].second}});
			lines.push_back({{i, j}, {all_points[i].second, all_points[j].first}});
			lines.push_back({{i, j}, {all_points[i].second, all_points[j].second}});
		}
	}

	for (auto l : lines) {
		int neg_cnt = 0;
		int pos_cnt = 0;

		// cout << endl << endl << "Doing search" << endl;
		// cout << "Entry valid area:" << endl;
		// for (auto x : valid_area) {
		// 	printf("(%.3Lf, %.3Lf)\n", x.x, x.y);
		// }
		// cout << "Done valid area" << endl;

		For (i, n) {
			// point is from one of the towers
			if (i == l.first.first || i == l.first.second) continue;
			if (neg_cnt > 0 && pos_cnt > 0) break;

			int s1 = db_sign(get_side(l.second.first, l.second.second, all_points[i].first));
			int s2 = db_sign(get_side(l.second.first, l.second.second, all_points[i].second));

			// printf("line: (%.3Lf, %.3Lf) -> (%.3Lf, %.3Lf); point 1: (%.3Lf, %.3Lf); got side: %d, point 2: (%.3Lf, %.3Lf); got side: %d\n"
		    //   , l.second.first.x, l.second.first.y, l.second.second.x, l.second.second.y
			//   , all_points[i].first.x, all_points[i].first.y, s1
			//   , all_points[i].second.x, all_points[i].second.y, s2);

			if (s1 == s2 && s1 < 0) neg_cnt++;
			if (s1 == s2 && s1 > 0) pos_cnt++;
		}

		// printf("line: (%.3Lf, %.3Lf) -> (%.3Lf, %.3Lf); neg: %d, pos: %d\n"
		//       , l.second.first.x, l.second.first.y, l.second.second.x, l.second.second.y
		// 	  , neg_cnt, pos_cnt);

		if (neg_cnt == 0 && pos_cnt == 0) {
			printf("%.14Lf\n", (ld)0.0);
			return 0;
		}

		if (neg_cnt == 0) {
			cut_side(-1, l.second);
		} 
		if (pos_cnt == 0) {
			cut_side(1, l.second);
		}
	}
	
	printf("%.14Lf\n", abs(area(valid_area) * (ld)0.5));
}