Problem: <image>


As shown in the figure above, cut a convex polygon g by a line p1p2 and print the area of the cut polygon which is on the left-hand side of the line.

g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n−1) are sides of the convex polygon. The line segment connecting pn and p1 is also a side of the polygon.

Constraints

* 3 ≤ n ≤ 100
* 1 ≤ q ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* -10000 ≤ p1x,p1y,p2x,p2y ≤ 10000
* No point in g will occur more than once.
* p1 ≠ p2

Input

The input is given in the following format:


g (the sequence of the points of the polygon)
q (the number of queries = the number of target lines)
1st query
2nd query
:
qth query


g is given as a sequence of points p1,..., pn in the following format:


n
x1 y1
x2 y2
:
xn yn


The first integer n is the number of points. The coordinate of the i-th point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them. Note that all interior angles of given convex polygons are less than or equal to 180.

For each query, a line represented by two points p1 and p2 is given. The coordinates of the points are given by four integers p1x, p1y, p2x and p2y.

Output

For each query, print the area of the cut polygon. The output values should be in a decimal fraction with an error less than 0.00001.

Example

Input

4
1 1
4 1
4 3
1 3
2
2 0 2 4
2 4 2 0


Output

2.00000000
4.00000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;

const double eps = 1e-10;

int dcmp(double x) {
        if(fabs(x) < eps) return 0;
        return x < 0 ? -1 : 1;
}

bool same(double a, double b) {return dcmp(a - b) == 0;}
#define Vector P
struct P {
        double x, y;
        P(double x = 0, double y = 0): x(x), y(y) {}
        P operator + (P b) {return P(x + b.x, y + b.y);}
        P operator - (P b) {return P(x - b.x, y - b.y);}
        P operator * (double b) {return P(x * b, y * b);}
        P operator / (double b) {return P(x / b, y / b);}
        double operator * (P b) {return x * b.x + y * b.y;} // Dot
        double operator ^ (P b) {return x * b.y - y * b.x;} // Cross
        double abs() {return hypot(x, y);}
        P unit() {return *this / abs();}
        P spin(double o) {
                double c = cos(o), s = sin(o);
                return P(c * x - s * y, s * x + c * y);
        }
};

struct Line {
        //ax + by + c = 0
        double a, b, c, o;
        P pa, pb;
        Line(): a(0), b(0), c(0), o(0), pa(), pb() {}
        Line(P pa, P pb): a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb), o(atan2(-a, b)), pa(pa), pb(pb) {}    
                P projection(P p) {return pa + (pb - pa).unit() * ((pb - pa) * (p - pa) / (pb - pa).abs());}
                P reflection(P p) {return p + (projection(p) - p) * 2;}
        double get_ratio(P p) {return (p - pa) * (pb - pa) / ((pb - pa).abs() * (pb - pa).abs());}
        P dis(P p) {return ((pb - pa) ^ (p - pa)) / (pb - pa).abs();} // directed distance
};
bool is_parallel(Line l, Line r) {return same(l.a * r.b, l.b * r.a);}
P line_intersection(Line l, Line r) { // check l and r are not parallel first
        return P(l.b * r.c - l.c * r.b, l.c * r.a - l.a * r.c) / (l.a * r.b - l.b * r.a);
}
struct Circle {
        P c;
        double r;
        Circle(P c, double r = 0): c(c), r(r) {}
};
double dis(P a, P b) {return (a - b).abs();}
vector<P> ps;
bool cmp(Line a, Line b) {
        return same(a.o, b.o) ? dcmp((b.pb - b.pa) ^ (a.pb - b.pa)) == 1 : a.o < b.o;
}
bool check(Line l1, Line l2, Line l) {
        if(is_parallel(l1, l2)) return 0;
        P p = line_intersection(l1, l2);
        /*
        cout << "p: " << p.x << ' ' << p.y << '\n';
        cout << l.a << "x + " << l.b << "y + " << l.c << " = 0\n";
        cout << "pa: " << l.pa.x << ' ' << l.pa.y << " pb: " << l.pb.x << ' ' << l.pb.y << '\n';
        cout << "result = " << ((l.pb - l.pa) ^ (p - l.pa)) << "\n\n";
        */
        return dcmp((l.pb - l.pa) ^ (p - l.pa)) != -1;
}
vector<P> HPI(vector<Line> ls) {
        sort(ls.begin(), ls.end(), cmp);
        vector<Line> vec;
        for(int i = 0; i < int(ls.size()); i++) {
                if(!vec.empty() && dcmp(ls[i].o - vec.back().o) == 0) continue;
                vec.push_back(ls[i]);
        }
        deque<Line> dq;
        for(int i = 0; i < int(vec.size()); i++) {
                while(dq.size() >= 2 && !check(dq[dq.size() - 2], dq[dq.size() - 1], vec[i])) dq.pop_back();                while(dq.size() >= 2 && !check(dq[0], dq[1], vec[i])) dq.pop_front();
                dq.push_back(vec[i]);
        //for(int i = 0; i < dq.size(); i++) cout << dq[i].a << "x + " << dq[i].b << "y + " << dq[i].c << " = 0\n";

        }
        while(dq.size() >= 2 && !check(dq[dq.size() - 2], dq[dq.size() - 1], dq[0])) dq.pop_back();
        while(dq.size() >= 2 && !check(dq[0], dq[1], dq[dq.size() - 1])) dq.pop_front();
        //for(int i = 0; i < dq.size(); i++) cout << dq[i].a << "x + " << dq[i].b << "y + " << dq[i].c << " = 0\n";
        vector<P> res;
        for(int i = 0; i < dq.size(); i++) res.push_back(line_intersection(dq[i], dq[(i + 1) % dq.size()]));        return res;
}
double Area(vector<P> &p) {
        double res = 0;
        for(int i = 1; i < (int)p.size() - 1; i++)
                res += (p[i] - p[0]) ^ (p[i + 1] - p[0]);
        return res * 0.5;
}

int main() {
        ios_base::sync_with_stdio(false); cin.tie(0);
        int n; cin >> n;
        vector<Line> ls;
        for(int i = 0; i < n; i++) {
                P p; cin >> p.x >> p.y;
                ps.push_back(p);
        }
        for(int i = 0; i < n; i++) {
                ls.push_back(Line(ps[i], ps[(i + 1) % n]));
        }
        /*
        vector<P> v = HPI(ls);
        for(P p : v) cout << p.x << ' ' << p.y << '\n';
        */
        int q; cin >> q;
        while(q--) {
                vector<Line> lss = ls;
                P p1, p2; cin >> p1.x >> p1.y >> p2.x >> p2.y;
                lss.push_back(Line(p1, p2));
                vector<P> res = HPI(lss);

                double ans = Area(res);
                cout << fixed << setprecision(12) << ans << '\n';
        }
        return 0;
}