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
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

#define real long double //albo long double
const real eps=1e-9;
inline bool iszero(real x){return x<=eps && x>=-eps;}
struct pt {
	real x,y;
	pt(real xx=0,real yy=0):x(xx),y(yy){}
	bool operator==(pt &a){return iszero(a.x-x) && iszero(a.y-y);}
};
bool operator<(const pt &a, const pt &b) {
	if (a.x!=b.x) return a.x<b.x;
	return a.y<b.y;
}
ostream& operator<<(ostream &s,pt p) {return s<<"("<<p.x<<","<<p.y<<")";}
pt operator+(pt a,pt b){return pt(a.x+b.x,a.y+b.y);}
pt operator-(pt a,pt b){return pt(a.x-b.x,a.y-b.y);}
pt operator*(pt a,real r){return pt(a.x*r,a.y*r);}
real vec(pt a,pt b){return a.x*b.y-a.y*b.x;}
real det(pt a,pt b,pt c){return vec(b-a,c-a);}
bool left(pt a, pt b, pt c) { return det(a,b,c) > 0; }
pt operator*(pt a,pt b){return pt(a.x*b.x-a.y*b.y,b.x*a.y+b.y*a.x);}
real sqabs(pt a){return a.x*a.x+a.y*a.y;}
pt operator/(pt a,pt b) {return (a*pt(b.x,-b.y))/sqabs(b);}
real abs(pt a){return sqrt(a.x*a.x+a.y*a.y);}
real dist(pt a,pt b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
real sqdist(pt a,pt b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
real arg(pt a){return atan2(a.y,a.x);}//z przedzialu [-pi,pi]
real skal(pt a,pt b){return a.x*b.x+a.y*b.y;}
// odleglosc A od prostej BC
real dist(pt a,pt b,pt c){return abs(det(b,c,a))/dist(b,c);}
//dlugosc (ze znakiem) rzutu A na prosta B
real dlrzut(pt a,pt b){return skal(a,b)/abs(b);}
pt rzut(pt a,pt b,pt c) { //rzut punktu A na prosta BC
	pt d=c-b;
	return b+d*(skal(a-b,d)/sqabs(d));
}
bool insegment(pt a,pt b,pt c) { //A nalezy do BC
	if (iszero(det(a,b,c)))
	if (min(b.x,c.x)-eps<=a.x && a.x-eps<=max(b.x,c.x))
	if (min(b.y,c.y)-eps<=a.y && a.y-eps<=max(b.y,c.y)) return 1;
	return 0;
}
bool przecinanie(pt a,pt b,pt c,pt d) { //czy przeciecie AB CD niepuste
	real d1=vec(b-a,c-a),d2=vec(b-a,d-a);
	if ((d1>eps && d2>eps) || (d1<-eps && d2<-eps)) return 0;
	if (iszero(d1) && iszero(d2)) {
		if (iszero(a.x-b.x) && iszero(c.x-d.x)) {
			a=a*pt(0,1);b=b*pt(0,1);c=c*pt(0,1);d=d*pt(0,1);
		}
		if (a.x>b.x) swap(a,b);
		if (c.x>d.x) swap(c,d);
		if (a.x<c.x+eps && c.x<b.x+eps) return 1;
		if (a.x<d.x+eps && d.x<b.x+eps) return 1;
		if (c.x<a.x+eps && a.x<d.x+eps) return 1;
		return 0;
	}
	d1=vec(d-c,a-c),d2=vec(d-c,b-c);
	if ((d1>eps && d2>eps) || (d1<-eps && d2<-eps)) return 0;
	return 1;
}
//przeciecie w dokl 1 punkcie ktory nie jest koncem
bool przecinanie_wl(pt a,pt b,pt c,pt d) {
	real d1=vec(b-a,c-a),d2=vec(b-a,d-a);
	if (!(d1>eps && d2<-eps) && !(d1<-eps && d2>eps)) return 0;
	d1=vec(d-c,a-c),d2=vec(d-c,b-c);
	if (!(d1>eps && d2<-eps) && !(d1<-eps && d2>eps)) return 0;
	return 1;
}
int line_cross(pt a, pt b,pt c,pt d,pt& wyn) { // 0 brak, 1 przec, 2 pokrywaja
	real pczw=vec(b-a,c-d);
	if (iszero(pczw)) {
		if (iszero(det(a,b,c))) return 2;
		else return 0;
	}
	real ptr=vec(b-a,c-a);
	wyn=c+(d-c)*(ptr/pczw);
	return 1;
}
vector<pt> circle_cross(pt c1,real c1r,pt c2,real c2r) {
	vector<pt> wyn;
	real d=sqabs(c2-c1), r1=c1r*c1r/d, r2=c2r*c2r/d;
	pt u=c1*((r2-r1+1)*0.5)+c2*((r1-r2+1)*0.5);
	if (r1>r2) swap(r1,r2);
	real a=(r1-r2+1)*0.5; a*=a;
	if (a>=r1+eps) return wyn;
	if (a>r1-eps) {wyn.pb(u);return wyn;}
	pt v(c2-c1);
	v=pt(-v.y,v.x);
	real h=sqrt(r1-a);
	wyn.pb(u+v*h);
	wyn.pb(u-v*h);
	return wyn;
}
vector<pt> circle_line_cross(pt c,real cr,pt a,pt b) {
	vector<pt> r;
	pt d=rzut(c,a,b);
	real X=dist(c,d);
	if (iszero(X-cr)){r.pb(d);return r;}//1 pkt
	if (X>cr) return r;//prosta za daleko
	real Y=sqrt(cr*cr-X*X);
	pt K=b-a;
	K=K*(Y/abs(K));
	r.pb(d+K);r.pb(d-K);
	return r;
}
bool circle_3points(pt a,pt b,pt c,pt &sr,real &r) {
	pt sym1[2],sym2[2];
	sym1[0]=(a+b)*0.5;sym1[1]=sym1[0]+(b-a)*pt(0,10.0);
	sym2[0]=(b+c)*0.5;sym2[1]=sym2[0]+(c-b)*pt(0,10.0);
	pt srodek;
	if (line_cross(sym1[0],sym1[1],sym2[0],sym2[1],sr)!=1) return 0;
	r=dist(sr,a);
	return 1;
}
//czy nalezy do wnetrza, jesli jest na brzegu to undefined behaviour
bool inpoly(pt a, vector<pt> &pol) {
	pt b(3e8+500.0,4e6+77777.0);
	int pr=0;
	FOR(i,SZ(pol)) pr+=przecinanie_wl(a,b,pol[i],pol[(i+1)%SZ(pol)]);
	return pr%2;
}
bool onborder(pt a, vector<pt> &pol) { //czy nalezy do brzegu
	FOR(i,SZ(pol)) if (insegment(a,pol[i],pol[(i+1)%SZ(pol)])) return 1;
	return 0;
}
//w srodku lub na brzegu, uzywac dla real=ll
bool PointInConvexPol(vector<pt>& l, pt p) {
	int a = 1, b = SZ(l)-1, c;
	if (det(l[0], l[a], l[b]) > 0) swap(a,b);
	if (det(l[0], l[a], p) > 0 || det(l[0], l[b], p) < 0) return 0;
	while(abs(a-b) > 1) {
		c = (a+b)/2;
		if (det(l[0], l[c], p) > 0) b = c; else a = c;
	}
	return det(l[a], l[b], p) <= 0;
}
//we wnetrzu bez brzegu, uzywac dla real=ll
bool PointInsideConvexPol(vector<pt>& l, pt p) {
	int a = 1, b = SZ(l)-1, c;
	if (det(l[0], l[a], l[b]) > 0) swap(a,b);
	if (det(l[0], l[a], p) >= 0 || det(l[0], l[b], p) <= 0) return 0;
	while(abs(a-b) > 1) {
		c = (a+b)/2;
		if (det(l[0], l[c], p) > 0) b = c; else a = c;
	}
	return det(l[a], l[b], p) < 0;
}
real pole(vector<pt> &po) { // dla arg. całkowitych wynik jest półcałkowity
	real pole=0.0;
	int dl=SZ(po);
	FOR(i,dl) pole+=po[i].x*po[(i+1)%dl].y-po[(i+1)%dl].x*po[i].y;
	return fabs(pole)/2.0;
}
//przeciecie wypuklego wielokata p i polplaszczyzny {x:det(a,b,x)<=0}
vector<pt> poly_halfplane(vector<pt> p,pt a,pt b) { //zlozonosc O(|p|)
	int n=SZ(p);
	if (!n) return p;
	p.pb(p[0]);
	vector<pt> wyn;
	vector<int> side(n+1);
	pt cross;
	FOR(i,n+1) { side[i]=(det(a,b,p[i])>=-eps); }//printf("[%d %.2le %.1lf %.1lf, %.1lf %.1lf, %.1lf %.1lf]\n", side[i], det(a,b,p[i]), a.x, a.y, b.x, b.y, p[i].x, p[i].y); } printf("\n");
	FOR(i,n) {
		if (side[i]==1) {
			wyn.pb(p[i]);
			if (side[i+1]==0 && line_cross(p[i],p[i+1],a,b,cross)==1
			&& !(cross==p[i])) wyn.pb(cross);
		}
		if (side[i]==0 && side[i+1]==1 && line_cross(p[i],p[i+1],a,b,cross)==1
		&& !(cross==p[i+1])) wyn.pb(cross);
	}
	return wyn;
}

const int N = 111;
int n;
pt t[N][2];
vector<pair<pt,pt>> hp;

int main() {
	scanf("%d", &n);
	FOR(i,n) scanf("%Lf%Lf%Lf%Lf", &t[i][0].x, &t[i][0].y, &t[i][1].x, &t[i][1].y);
	FOR(i,n) FOR(j,n) if (i!=j) {
		FOR(a,2) FOR(b,2) {
			pt A = t[i][a], B = t[j][b];
			if (left(B, A, t[i][1-a])) continue;
			//if (left(B, A, t[j][1-b])) continue;
			bool bad = 0;
			FOR(k,n) if (k!=i) {
				if (left(A, B, t[k][0]) && left(A, B, t[k][1])) {
					bad = 1;
					break;
				}
			}
			if (bad) continue;
			hp.pb(mp(A, B));
		}
	}
	//FOR(i,SZ(hp)) printf("%.1lf %.1lf -- %.1lf %.1lf\n", hp[i].fi.x, hp[i].fi.y, hp[i].se.x, hp[i].se.y);
	int m = SZ(hp);
	vector<pt> poly;
	poly.pb(pt(-1000, -1000));
	poly.pb(pt(-1000, 1000));
	poly.pb(pt(1000, 1000));
	poly.pb(pt(1000, -1000));
	FOR(i,m) {
		poly = poly_halfplane(poly, hp[i].se, hp[i].fi);
		//printf("\nafter %d, poly=\n", i);
		//FOR(i,SZ(poly)) printf("%.4lf %.4lf\n", poly[i].x, poly[i].y);
	}
	//FOR(i,SZ(poly)) printf("%.4lf %.4lf\n", poly[i].x, poly[i].y);
	printf("%.13Lf\n", pole(poly));
	return 0;
}