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
/*
 * w programie urzyłem bezczelnie (choć legalnie) kodu ogólnie dostępnego, znajdującego się pod tym linkiem
 * https://github.com/mareksom/acmlib/blob/master/code/kamil/halfplanes.cpp
*/
#include <bits/stdc++.h>
#define f first
#define s second
#define LL long long
#define ALL(V) V.begin(),V.end()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define debug(x) cerr<<#x<<": "<<x<<endl
#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 SZ(x) ((int)(x).size())
#define LD long double
using namespace std;
const LL N=1e6+69, base=1024*1024,mod=1e9+7;
// halfplanes_online
#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 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;
    }
    vector <line> oddawaj() {
        vector <line> re;
        for(auto v:S) {
            re.push_back(v);
        }
        return re;
    }
    long double kurwa_moje_pole() {
        long double re=0;
        for(auto it=S.begin();it!=S.end();it++) {
            line u = (*it);
            complex<LD> a = prosta_prosta(u, (*next(it)));
            complex<LD> b = prosta_prosta(u, (*prev(it)));
            long double ile=(a.X-b.X)*fabs(a.Y+b.Y)/2;
            re+=ile;
        }
        return fabs(re);
    }
};

przeciecie_polplaszczyzn S;
vector <pair<pair<int,int>,pair<int,int>>> vek;
vector <line> huj;
int n;
int wektor(pair<int,int> a, pair<int,int> b, pair<int,int> c) {
    b.f -= a.f;
    b.s -= a.s;
    c.f -= a.f;
    c.s -= a.s;
    return b.f * c.s - c.f * b.s;
}
void is_correct(pair<int,int> a, pair<int,int> b) {
    if(a==b) return;
    for(int i=0;i<vek.size();i++) {
        int w1=wektor(a,b,vek[i].f);
        int w2=wektor(a,b,vek[i].s);
        if(w1>0 && w2>0) return;
    }
    P a1 = {a.f,a.s};
    P b1 = {b.f,b.s};
    S.add({b1,a1});
}
void check_lines(int a,int b) {
    pair<int,int> a1 = vek[a].f;
    pair<int,int> a2 = vek[a].s;
    pair<int,int> b1 = vek[b].f;
    pair<int,int> b2 = vek[b].s;
    is_correct(a1, a2);
    is_correct(a1, b1);
    is_correct(a1, b2);
    is_correct(a2, b1);
    is_correct(a2, b2);
    is_correct(b1, b2);
}
int32_t main(void) {
    cin>>n;
    for(int i=0;i<n;i++) {
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        b+=1000;
        d+=1000;
        vek.push_back({{a,b},{c,d}});
    }
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            check_lines(i,j);
        }
    }
    if(S.type()!=5) {
        long double odp=0;
        printf("%.15LF\n", odp);
        return 0;
    }
    long double odpowiedz=S.kurwa_moje_pole();
    printf("%.15LF\n", odpowiedz);
}