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>
using namespace std;
const double inf = 30000;
const double eps = 1e-8;
const int N = 2e5 + 100;
int sgn (double x) {
    if (fabs (x) < eps) return 0;
    if (x < 0) return -1;
    return 1;
}
struct point {
    double x, y;
    point () {}
    point (double _x, double _y) {
        x = _x, y = _y;
    }
    void input () {
        cin >> x >> y;
    }
    point operator - (const point &b) const {
        return point (x - b.x, y - b.y);
    }
    bool operator == (const point &b) const {
        return sgn (x - b.x) == 0 && sgn (y - b.y) == 0;
    }
    bool operator < (const point &b) const {
        if (sgn (y - b.y) == 0) return x < b.x;
        return y < b.y;
    }
    double operator * (const point &b) const {
        return x * b.x + y * b.y;
    }
    double operator ^ (const point &b) const {
        return x * b.y - y * b.x;
    }
    point operator / (const double &b) const {
        return point (x / b, y / b);
    }
    point operator * (const double &b) const {
        return point (x * b, y * b);
    }
    point operator + (const point &b) const {
        return point (x + b.x, y + b.y);
    }
    double cross (point a, point b) {
        return (point (a - *this) ^ point (b - *this));
    }
    double dot (point a, point b) {
        return (point (a - *this) * point (b - *this));
    }
    double len () {
        return hypot (x, y);
    }
    bool on_seg (point a, point b) {///点是否在线段ab上
        return sgn (cross (a, b)) == 0 && dot (a, b) <= 0;
    }
} s, e, s1, e1, val;
///两线段的交点
point spp (point s1, point e1, point s, point e) {
    if (s.dot (e, s1) > s.dot (e, e1)) swap (s1, e1);
    point p = e - s;
    double len = p.len ();
    double a = fabs (s.cross (e, s1)) / len;
    double b = fabs (s.cross (e, e1)) / len;
    double a1 = s.dot (e, s1) / len;
    double b1 = s.dot (e, e1) / len;
    double k = a1 + fabs(a1 - b1) / (a + b) * a;
    p = p / len, p = p * k, p = p + s;
    return p;
}
///两线段是否相交
bool seg (point a, point b, point c, point d) {
    if (a.on_seg (c, d)) return true;
    if (a.cross (b, d) * a.cross (b, c) < 0 && c.cross (d, b) * c.cross (d, a) < 0) return true;
    return false;
}
/// 点的投影是否在线段ab上
//bool check (point p, point a, point b) {
//    point x = b - a;
//    double k = x.len ();
//    double u = a.dot (p, b) / k;
//    x = (x / k) * u;
//    x = x + a;
//    if (x.on_seg (a, b)) return true;
//    return false;
//}
struct polygon {
    int n;
    point ps[N];
    void input () {
        cin >> n;
        for (int i = 0; i < n; i++) ps[i].input ();
    }
    ///排序规则
    struct cmp {
        point p;
        cmp (point _p) {
            p = _p;
        }
        bool operator () (const point &aa, const point &bb) {
            point a = aa, b = bb;
            int d = sgn (p.cross (a, b));
            if (d == 0) return point (a - p).len () < point (b - p).len ();
            else return d > 0;
        }
    };
    ///排序
    void norm () {
        point mi = ps[0];
        for (int i = 0; i < n; i++) mi = min (mi, ps[i]);
        sort (ps, ps + n, cmp (mi));
    }
    ///求凸包
//    void getconvex (polygon &convex) {
//        sort (ps, ps + n);
//        int &top = convex.n;
//        top = 0;
//        convex.ps[top++] = ps[0];
//        for (int i = 1; i < n; i++) {
//            while (top >= 2 && convex.ps[top - 2].cross (convex.ps[top - 1], ps[i]) < 0) top--;
//            convex.ps[top++] = ps[i];
//        }
//        int t = 0;
//        for (int i = n - 2; i >= 0; i--) {
//            while (t && convex.ps[top - 2].cross (convex.ps[top - 1], ps[i]) < 0) top--, t--;
//            if (!i) break;
//            convex.ps[top++] = ps[i];
//            t++;
//        }
//    }
    ///几何面积
    double mianji () {
        if (n < 2) return 0;
        double ans = 0;
        ps[n] = ps[0];
        for (int i = 1; i <= n; i++) ans += point (0, 0).cross (ps[i - 1], ps[i]);
        return ans;
    }
} dd, ans;
int main () {
//    freopen ("in.txt", "r", stdin);
//    freopen ("out.txt", "w", stdout);
    dd.input ();
    int Q;
    cin >> Q;
    while (Q --) {
        s.input (), e.input ();
        point s1 = point (e - s) / point (e - s).len () * inf + s;
        point e1 = point (s - e) / point (s - e).len () * inf + e;
        s = s1, e = e1;
        int &top = ans.n, t = 0, iiii = 0;
        top = 0;
        dd.ps[dd.n] = dd.ps[0];
        for (int i = 1; i <= dd.n; i++) if (seg (dd.ps[i], dd.ps[i - 1], s, e)) {
            ans.ps[top++] = spp (dd.ps[i], dd.ps[i - 1], s, e), t++;
            if (sgn (point (s - e) ^ point (dd.ps[i] - dd.ps[i - 1])) == 0) iiii = 1;
        }
        if (iiii || t < 2) {
            double u;
            int p = 0;
            for (int i = 0; i < dd.n; i++) if (s.cross (e, dd.ps[i]) < 0) p = 1;
            if (p) u = dd.mianji();
            else u = 0;
            printf ("%.8f\n", u / 2);
            continue;
        }
        for (int i = 0; i < dd.n; i++)
            if (s.cross (e, dd.ps[i]) < 0) ans.ps[top++] = dd.ps[i];
        ans.norm ();
        printf ("%.8f\n", ans.mianji () / 2);
    }
    return 0;
}