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
#include <bits/stdc++.h>                                                        
using namespace std;                                                            
const int maxn = 110;                                                          
typedef long long ll;
typedef long double ld;                                                           
typedef pair<int, int> Pii;                                                     
typedef vector<Pii> vpii;                                                       
typedef vector<int> vi;                                                         
typedef vector<ll> vll;
typedef vpii troj;
typedef pair<ld, ld> Pdd;                                                         
#define pb push_back                                                            
#define fst first                                                               
#define snd second
typedef ll LL;
typedef ld LD;

#define REP(i,j) for(int i = 0; i < (int)(j); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define X real()
#define Y imag()
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.Y-B.Y), b(B.X-A.X), c(A.X*B.Y-A.Y*B.X) {} //pts <= 10^6
	line (Pii a_, Pii b_) : line(complex<LL>{a_.fst, a_.snd}, complex<LL>{b_.fst, b_.snd}) {}
    line operator - () const {return line(-a, -b, -c); }
    bool up() const { return a?(a<0):(b>0);}
};


Pdd cross(line p, line q){
    ld base = p.a * q.b - p.b * q.a;
    if(fabs(base) < 1e-9) return Pdd(1e9, 1e9);
    return Pdd((p.b * q.c - q.b * p.c) / base, (p.c * q.a - q.c * p.a) / base);
}

/*void wypisz(Pdd d)
{
	cout << "(" << d.fst << ", " << d.snd << ")";
}*/

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.X * c.a + r.Y * 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(SZ(S) >= 2 && it == S.end()) it = S.begin();
        while(SZ(S) >= 2 && hide(l, *next(it), *it)) {
            iter del = it;
            it = next(it);
            S.erase(del);
        }
        //*it<p
        if(SZ(S) >= 2) it = prev(it);
        while(SZ(S) >= 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(SZ(S) <= 4){
            vector<line> res(ALL(S));
            if (SZ(res) == 2 && rown(res[0], res[1]) && weaker(res[0], -res[1])<0) return 0; 
            REP(i, SZ(res)) REP(j, i) if(pokr(res[i], res[j])) {
                if(SZ(res) == 2) return 4;
                if(SZ(res) == 3) return 3;
                if(SZ(res) == 4 && pokr(res[0], res[2]) && pokr(res[1], res[3])) return 1;
                return 2;
            }
            if(SZ(res) == 3 && pek) return 1;
        }
        return 5;
    }
};

/*Pii operator-(Pii a, Pii b)
{
	return {a.fst - b.fst, a.snd - b.snd};
}*/	
Pdd operator-(Pdd a, Pdd b)
{
	return {a.fst - b.fst, a.snd - b.snd};
}
ll det(Pii a, Pii b, Pii c)
{
	b = b - a;
	c = c - a;
	return 1ll * c.fst * b.snd - 1ll * c.snd * b.fst;
}
vector<Pdd> jebaj(vector<troj> hehe)
{
	for(troj& t : hehe)
	{
		if(det(t[0],t[1],t[2]) > 0)
			swap(t[1], t[2]);
		if(det(t[0],t[1],t[2]) == 0)
			return {};
		assert(det(t[0],t[1],t[2]) < 0);
	}
	przeciecie_polplaszczyzn pp;
	
	for(troj t : hehe)
	{
		pp.add(line(t[0], t[1]));
		pp.add(line(t[1], t[2]));
		pp.add(line(t[2], t[0]));
		//cout << pp.type() << ' ';
	}
	//cout << pp.type() << endl;
	if(pp.type() != 5) return {};
	vector<Pdd> res;
	line l1 = *(pp.S.rbegin());
	for(line l2 : pp.S)
	{
		res.pb(cross(l1, l2));
		l1 = l2;
	}
	return res;
}
int main2()
{
	vector<Pdd> res = jebaj({{{0,0}, {5, 0}, {0, 5}}});
	//for(auto r : res)
	//	wypisz(r);
	return 0;
}

ld func(line a, Pdd b){
    return a.a * b.first + a.b * b.second + a.c;
}

vector<Pdd> half_plane_intersect(vector<line> v){
	vector<Pdd> ret;
	int n = v.size();
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            Pdd crs = cross(v[i], v[j]);
            if(fabs(crs.first - 1e9) < 1e-4) continue;
            bool bad = 0;
            for(int k=0; k<n; k++){
                if(func(v[k], crs) < -1e-9){
                    bad = 1;
                    break;
                }
            }
            if(!bad) ret.push_back(crs);
        }
    }
	return ret;
}
vector<Pdd> jebaj2(vector<troj> hehe)
{
	for(troj& t : hehe)
	{
		if(det(t[0],t[1],t[2]) > 0)
			swap(t[1], t[2]);
		if(det(t[0],t[1],t[2]) == 0)
			return {};
		assert(det(t[0],t[1],t[2]) < 0);
	}
	vector<line> linie;
	for(troj t : hehe)
	{
		linie.pb(line(t[0], t[1]));
		linie.pb(line(t[1], t[2]));
		linie.pb(line(t[2], t[0]));
	}
	return half_plane_intersect(linie);
}
vector<Pdd> jebaj3(przeciecie_polplaszczyzn& pp)
{
	vector<Pdd> res;
	line l1 = *(pp.S.rbegin());
	for(line l2 : pp.S)
	{
		res.pb(cross(l1, l2));
		l1 = l2;
	}
	return res;
}
int n;
Pii W[maxn][2];
Pii lod()
{
	int x,y;
	scanf("%d%d", &x, &y);
	//static int ile = 0;
	//++ile;
	//printf("Wczytałem %d %d %d\n", x, y, ile);
	return {x,y};
}
ld ccw(Pdd a, Pdd b, Pdd c)
{
	b = b - a;
	c = c - a;
	return b.fst * c.snd - b.snd * c.fst;
}
int sgn(ll x)
{
	if(x < 0) return -1;
	if(x > 0) return 1;
	return 0;
}
int main()                                                                      
{               
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		W[i][0] = lod();
		W[i][1] = lod();
	}
	przeciecie_polplaszczyzn pp;
	
	
	for(int i = 0; i < n; ++i)
		for(int j = i + 1; j < n; ++j)
		{
			for(int ma = 0; ma < 4; ++ma)
			{
				Pii p1 = W[i][ma & 1];
				Pii p2 = W[j][(ma >> 1) & 1];
				bool ok1 = false, ok2 = false;
				for(int k = 0; k < n; ++k)
					if(k != i && k != j)
					{
						ll d0 = det(p1, p2, W[k][0]);
						ll d1 = det(p1, p2, W[k][1]);
						if(sgn(d0) * sgn(d1) == 1)
						{
							if(sgn(d0) == 1)
								ok1 = true;
							else
								ok2 = true;
						}
					}
				if(!ok1 && !ok2)
				{
					puts("0.0000000000000");
					return 0;
				}
				if(ok1 && ok2) continue;
				if(ok1)
				{
					pp.add(line{p2, p1});
				}
				else
				{
					pp.add(line{p1, p2});
				}
			}
		}
	if(pp.type() != 5)
	{
		puts("0.0000000000000");
		return 0;
	}
	vector<Pdd> punkty = jebaj3(pp);
	sort(punkty.begin(), punkty.end());
	vector<Pdd> hull;
	hull.reserve(punkty.size() + 1);
	for (int phase = 0; phase < 2; ++phase) {
			auto start = hull.size();
		for (auto& point : punkty) {
			while (hull.size() >= start+2 && ccw(point, hull.back(), hull[hull.size()-2]) <= 0)
			hull.pop_back();
			hull.push_back(point);
		}
		hull.pop_back();
		reverse(begin(punkty), end(punkty));
	}
	reverse(begin(hull), end(hull));
	if (hull.size() == 2 && hull[0] == hull[1]) hull.pop_back();
	//for(Pdd h : hull)
	//	wypisz(h);
	ld res = 0;
	
	for(int i = 1; i + 1 < (int)hull.size(); ++i)
	{
		//cout << "Pole " << ccw(hull[0], hull[i], hull[i+1]) << endl;
		res += ccw(hull[0], hull[i], hull[i+1]);
	}
	res /= 2.;
	///cout << res << endl;
	printf("%.13Lf\n", res);
}