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 <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
const int MAXN = 1e5 + 10;
const double eps = 1e-12;

struct vec {
    double x, y;
    double p;
    vec() {}
    vec(double a, double b)
    {
        x = a, y = b;
    }
    vec operator*(const vec& i_T) const
    {
        return vec(x * i_T.x, y * i_T.y);
    }
    vec operator*(double u) const
    {
        return vec(x * u, y * u);
    }
    bool operator>(const vec a) const
    {
        return x == a.x ? y > a.y : x > a.x;
    }
    vec operator-(const vec a) const
    {
        return vec(x - a.x, y - a.y);
    }
    vec operator+(const vec a) const
    {
        return vec(x + a.x, y + a.y);
    }
    bool operator<(const vec a) const
    {
        return y == a.y ? x < a.x : y < a.y;
    }
    friend ostream& operator<<(ostream& out, vec& a)
    {
        cout << a.x << ' ' << a.y;
        return out;
    }
    friend istream& operator>>(istream& in, vec& a)
    {
        in >> a.x >> a.y;
        return in;
    }
};
int n;
double chaji(vec A, vec B)
{
    return A.x * B.y - A.y * B.x;
}
double xuanzhuan(vec a, vec b, vec c)
{
    return chaji(b - a, c - a);
}
double dianji(vec A, vec B) //点积
{
    return A.x * B.x + A.y * B.y;
}
double changdu(vec a) //长度
{
    return sqrt(a.x * a.x + a.y * a.y);
}
int zhengfu(double d) //判断正负
{
    if (fabs(d) < eps)
        return 0;
    if (d > 0)
        return 1;
    return -1;
}
int zhixian_xianduan_xiangjiao(vec a, vec b, vec c, vec d) //直线与线段是否有交点
{
    double c1 = chaji(b - a, c - a), d1 = chaji(b - a, d - a);
    if (zhengfu(c1) == 0 && zhengfu(d1) == 0) { //重合
        return -1;
    } else if (zhengfu(c1 * d1) <= 0) //有交点
        return 1;
    return 0; //平行
}
vec touying(vec a, vec b, vec c) //c投影在ab上的位置
{
    vec A = b - a;
    vec B = c - a;
    double La = changdu(A);
    double Lc = dianji(A, B) / (La * La);
    return vec(Lc * A.x, Lc * A.y) + a;
}
vec fanshe(vec a, vec b, vec c) //求c关于ab的对称点c'
{
    vec A = touying(a, b, c);
    return (A - c) * 2.0 + c;
}
vec zhixian_xianduan_jiaodian(vec a, vec b, vec c, vec d) //直线与线段的交点
{
    vec ret;
	ret.x = ((b.x-a.x)*(c.y*(d.x-c.x)+c.x*(c.y-d.y))-(d.x-c.x)*(a.y*(b.x-a.x)+a.x*(a.y-b.y)))/((b.y-a.y)*(d.x-c.x)-(d.y-c.y)*(b.x-a.x));
	if(a.x != b.x){
		ret.y = ((b.y-a.y)*ret.x+a.y*(b.x-a.x)+a.x*(a.y-b.y))/(b.x-a.x);
	}else{
		ret.y = ((d.y-c.y)*ret.x+c.y*(d.x-c.x)+c.x*(c.y-d.y))/(d.x-c.x);
	}
	return ret;
}
vec p[MAXN];
double duobianxingmianji(int n) //多边形面积
{
    double ans = 0;
    p[0] = p[n];
    for (int i = 0; i < n; i++)
        ans += chaji(p[i], p[i + 1]);
    ans = fabs(ans) * 0.5;
    return ans;
}
vec q[MAXN];
void qiegetubao(vec p1, vec p2)
{
    int tail = 0;
    q[0] = q[n];
    int tf = -1, x;
    for (int i = 0; i < n; i++) {
        if (zhengfu(xuanzhuan(p1, p2, q[i])) == 1)
            p[++tail] = q[i];
        int f = zhixian_xianduan_xiangjiao(p1, p2, q[i], q[i + 1]);

        if (f == 1) {
            tf = 1;
            p[++tail] = zhixian_xianduan_jiaodian(p1, p2, q[i], q[i + 1]);
        } else if (f == -1) {
            tf = 0;
            x = i;
            break;
        }
    }
    if (tf == 0) {
        //cout<<q[x+1]<<' '<<q[x]<<' '<<endl;
        if (zhengfu(dianji(p2 - p1, q[x + 1] - q[x])) == -1)
            printf("%.8f\n", 0.0);
        else {
            for (int i = 1; i <= n; i++)
                p[i] = q[i];
            printf("%.8f\n", duobianxingmianji(n));
        }
    } else {
        /*for (int i = 1; i <= tail; i++)
            cout << p[i] << endl;*/
        printf("%.8f\n", duobianxingmianji(tail));
    }
    q[0] = vec(0, 0);
}
int main()
{
    //freopen("txt.txt", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> q[i];
    int t;
    cin >> t;
    while (t--) {
        vec p1, p2;
        cin >> p1 >> p2;
        memset(p, 0, sizeof(p));
        qiegetubao(p1, p2);
    }
    return 0;
}
/*
4
-57 5
52 -44
69 32
8 93
1
16 -88 42 -75

*/