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

// Fragment kodu odpowiedzialny za obliczenie przeciecia polplaszczyzn jest skopiowany z publicznie dostępnej biblioteczkiki ACM:
// https://github.com/mareksom/acmlib/blob/master/code/kamil/halfplanes.cpp
// Nagłówki są z https://github.com/mareksom/acmlib/blob/master/code/kamil/geo_lib.cpp

using namespace std;

#define LL long long
#define LD long double
#define PB push_back
#define VI vector<int>
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define REP(i,n) FOR(i, 0, (int)n - 1)
#define PII pair<int,int>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

template<typename T> T K(T a) { return a * a; } // 'K(int)' may overflow!
typedef long double ll; // can be changed to 'long double'
typedef long double ld;
// const ld PI = 2 * acos(0);
const ld eps = 1e-12;
#pragma GCC diagnostic ignored "-Wnarrowing"

// halfplanes_online
#define X real()
#define Y imag()
typedef complex<LL> P;

const int N = 105;

int n;
LL pointsX[N][2], pointsY[N][2];

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 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.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;
    }
};



int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> pointsX[i][j] >> pointsY[i][j];
//             pointsX[i][j] += 501;
//             pointsY[i][j] += 501;
        }
    }
    vector<line> goodLines;
    przeciecie_polplaszczyzn prz;
    for (int i = 1; i <= n; i++) {
        for (int k = 0; k < 2; k++) {
            P ith(pointsX[i][k], pointsY[i][k]);
            for (int j = 1; j <= n; j++) {
                if (i == j) continue;
                for (int l = 0; l < 2; l++) {
                    P jth(pointsX[j][l], pointsY[j][l]);
                    line seg = line({pointsX[i][k], pointsY[i][k]}, {pointsX[j][l], pointsY[j][l]});
                    bool good = true;
                    for (int p = 1; p <= n; p++) {
                        if (i == p || j == p) continue;
                        P p1(pointsX[p][0], pointsY[p][0]);
                        P p2(pointsX[p][1], pointsY[p][1]);
                        if (wek(seg, line(ith, p1)) < 0 && wek(seg, line(ith, p2)) < 0) {
                            good = false;
                            
                            break;
                        }
                    }
                    if (good) {
                        prz.add(seg);
                    }
                }
            }
        }
    }
    
    if (prz.empty || prz.S.size() == 1) {
        cout << fixed << setprecision(13) << 0.0 << endl;
        return 0;
    }
    
    if (prz.S.size() == 2) {
        auto first = *prz.S.begin();
        auto second = *prz.S.rbegin();
        if (pokr(first, second)) {
            cout << fixed << setprecision(13) << 0.0 << endl;
            return 0;
        }
    }
    
    vector<line> lines;
    for (auto l : prz.S) {
        lines.push_back(l);
    }
    
    vector<complex<LD> > polygon;
    for (int i = 0; i < lines.size(); i++) {
        polygon.push_back(prosta_prosta(lines[i], lines[(i + 1) % lines.size()]));
    }
    
    LD area = 0;
    int m = polygon.size();
    for (int i = 0; i < polygon.size(); i++) {
        area += (polygon[(i + 1) % m].X - polygon[i].X) * (polygon[i].Y + 501 + polygon[(i + 1) % m].Y + 501);
    }
    
    cout << fixed << setprecision(13) << fabs(area / 2) << endl;
    
    return 0;
}