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<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#include<set>
#include<map>
#define re register
#define ll long long
using namespace std;
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9'|| ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return sum*f;
}
const double eps=1e-10,Pi=acos(-1.0);
struct node{
    double x,y;
    node operator+(node b){return (node){x+b.x,y+b.y};}
    node operator-(node b){return (node){x-b.x,y-b.y};}
    node operator*(double b){return (node){x*b,y*b};}
    double len(){return sqrt(x*x+y*y);}
};
int fh(double a){return fabs(a)<eps?0:a>eps?1:-1;}
double cross(node a,node b){return a.x*b.y-a.y*b.x;}
double dot(node a,node b){return a.x*b.x+a.y*b.y;}
node projection(node p1,node p2,node p){node v=p2-p1;return p1+v*(dot(v,p-p1)/dot(v,v));}
node reflection(node p1,node p2,node p){node P=projection(p1,p2,p);P=P*2-p;return P;}
void Counter_Clockwise(node p1,node p2,node p){
    if(cross(p2-p1,p-p1)>eps){puts("COUNTER_CLOCKWISE");return;}
    if(cross(p2-p1,p-p1)<-eps){puts("CLOCKWISE");return;}
    if(dot(p2-p1,p-p1)<-eps){puts("ONLINE_BACK");return;}
    if(dot(p2-p1,p2-p1)>=dot(p-p1,p2-p1)){puts("ON_SEGMENT");return;}
    puts("ONLINE_FRONT");
}
bool insegment(node A,node B,node p){
    if(fh(cross(B-A,p-A)))return false;
    return ((fh(p.x-A.x)>=0 && fh(B.x-p.x)>=0) || (fh(p.x-A.x)<=0 && fh(B.x-p.x)<=0)) && ((fh(p.y-A.y)>=0 && fh(B.y-p.y)>=0) || (fh(p.y-A.y)<=0 && fh(B.y-p.y)<=0));
}
int parallel(node A1,node A2,node B1,node B2){
    if(!fh(cross(B2-B1,A2-A1)))return 2;
    if(!fh(dot(B2-B1,A2-A1)))return 1;
    return 0;
}
bool intersection(node A1,node A2,node B1,node B2){
    if(!fh(cross(B2-B1,A2-A1))){
        if(insegment(A1,A2,B1) || insegment(A1,A2,B2) || insegment(B1,B2,A1) || insegment(B1,B2,A2))return true;
        return false;
    }
    return fh(cross(A1-B1,B2-B1)*cross(A2-B1,B2-B1))<=0 && (fh(cross(B1-A1,A2-A1)*cross(B2-A1,A2-A1))<=0);
}
node getintersection(node A1,node A2,node B1,node B2){
    node v=A2-A1;
    return A1+v*(cross(B2-B1,B1-A1)/cross(B2-B1,A2-A1));
}
double distance(node A1,node A2,node B1,node B2){
    if(intersection(A1,A2,B1,B2))return 0.0;
    node p;double ans=1e18;
    ans=min(ans,(A1-B1).len());ans=min(ans,(A1-B2).len());ans=min(ans,(A2-B1).len());ans=min(ans,(A2-B2).len());
    p=projection(A1,A2,B1);
    if(insegment(A1,A2,p))ans=min(ans,(B1-p).len());
    p=projection(A1,A2,B2);
    if(insegment(A1,A2,p))ans=min(ans,(B2-p).len());
    p=projection(B1,B2,A1);
    if(insegment(B1,B2,p))ans=min(ans,(A1-p).len());
    p=projection(B1,B2,A2);
    if(insegment(B1,B2,p))ans=min(ans,(A2-p).len());
    return ans;
}
double area(node *p,int n){
    double area=0;
    for(int i=1;i<n;i++){
		area+=cross(p[i],p[i+1]);
	}
    area+=cross(p[n],p[1]);
    return area*0.5;
}
bool is_convex(node *p,int n){
    for(int i=2;i<n;i++)if(cross(p[i]-p[i-1],p[i+1]-p[i-1])<0)return false;
    if(cross(p[n]-p[n-1],p[1]-p[n-1])<0)return false;
    if(cross(p[1]-p[n],p[2]-p[n])<0)return false;
    return true;
}
int inConvex(node O,node *p,int n){
    int cnt=0;
    for(int i=0;i<n;i++){
        if(insegment(p[i],p[(i+1)%n],O))return 1;
        node A=p[i]-O,B=p[(i+1)%n]-O;
        if(A.y>B.y)swap(A,B);
        if(A.y<eps && B.y>eps && cross(A,B)>eps)cnt++;
    }
    return cnt&1?2:0;
}
bool cmp(node a,node b){return a.y<b.y || (!fh(a.y-b.y) && a.x<b.x);}
bool cmp1(node a,node b){return a.x<b.x || (!fh(a.x-b.x) && a.y<b.y);}
bool cmp2(node a,node b){return atan2(a.y,a.x)<atan2(b.y,b.x) || (!fh(atan2(a.y,a.x)-atan2(b.y,b.x)) && a.x>b.x);}
double Diameter(node *p,int n){
    int id=1;double ans=0;
    for(int i=0;i<n;i++){
        node p1=p[i],p2=p[(i+1)%n];
        for(int nxt=(id+1)%n;fh(fabs(cross(p[nxt]-p1,p2-p1))-fabs(cross(p[id]-p1,p2-p1)))>=0;id=nxt,nxt=(nxt+1)%n);
        ans=max(ans,max((p[id]-p1).len(),(p[id]-p2).len()));
    }
    return ans;
}
double cutarea(node *p,int n,node A1,node A2){
	node c[200010];int tot=0;
	for(int i=0;i<n;i++){
		node p1=p[i],p2=p[(i+1)%n];
		node P=getintersection(p1,p2,A1,A2);
		if(insegment(p1,p2,P))c[++tot]=P;
		if(cross(A2-A1,p2-A1)>-eps)c[++tot]=p2;
	}
	return area(c,tot);
}
node p[100010];int n;
int main(){
    n=gi();
    for(int i=0;i<n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
	int Q=gi();node p1,p2;
	while(Q--){
		p1.x=gi();p1.y=gi();p2.x=gi();p2.y=gi();
		printf("%.8lf\n",cutarea(p,n,p1,p2));
	}
    return 0;
}
/*
5
0 0
4 0
4 2
2 4
0 4
1
7 -2 8 -3
*/