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;

#define ld long double
#define eps 1e-9

bool cmp(ld A , ld B){return A + eps > B && A - eps < B;}

class vec{
public:
	ld x , y;
	vec(ld _x = 0 , ld _y = 0) : x(_x) , y(_y){}
	friend vec operator +(vec A , vec B){return vec(A.x + B.x , A.y + B.y);}
	friend vec operator -(vec A , vec B){return vec(A.x - B.x , A.y - B.y);}
	friend ld operator *(vec A , vec B){return A.x * B.x + A.y * B.y;}
	friend ld operator %(vec A , vec B){return A.x * B.y - A.y * B.x;}
	friend vec operator *(vec A , ld B){return vec(A.x * B , A.y * B);}
	ld len(){return sqrt(x * x + y * y);}
	ld len2(){return x * x + y * y;}
	ld angle(){return atan2(y , x);}
};
vec getvec(){ld x , y; cin >> x >> y; return vec(x , y);}

class segment{
public:
	vec st , ed , dir;
	segment(vec _a = vec() , vec _b = vec()) : st(_a) , ed(_b) , dir(_b - _a){}
	friend bool havesect(segment A , segment B){
		ld P = A.st.x , Q = A.ed.x , X = B.st.x , Y = B.ed.x;
		if(Q < P) swap(P , Q);
		if(Y < X) swap(X , Y);
		if(X - eps > Q || P - eps > Y) return 0;
		P = A.st.y , Q = A.ed.y , X = B.st.y , Y = B.ed.y;
		if(Q < P) swap(P , Q);
		if(Y < X) swap(X , Y);
		if(X - eps > Q || P - eps > Y) return 0;
		return
			((B.st - A.st) % A.dir) * (A.dir % (B.ed - A.st)) > -eps &&
			((B.st - A.ed) % A.dir) * (A.dir % (B.ed - A.ed)) > -eps &&
			((A.st - B.st) % B.dir) * (B.dir % (A.ed - B.st)) > -eps &&
			((A.st - B.ed) % B.dir) * (B.dir % (A.ed - B.ed)) > -eps;
	}
	friend vec getsect(segment A , segment B){
		ld t = ((A.st - B.st) % B.dir) / (B.dir % A.dir);
		return A.st + (A.dir * t);
	}
	ld len(){return dir.len();}
	ld len2(){return dir.len2();}
};
segment getseg(){vec A = getvec() , B = getvec(); return segment(A , B);}

ld dist(vec P , segment seg){//minimum dist from a point to a segment
	ld T = ((P - seg.st) * seg.dir) / seg.len2();
	if(T < 0) return (seg.st - P).len();
	else if(T > 1) return (seg.ed - P).len();
	else return (seg.st + (seg.dir * T) - P).len();
}

class polygon{//counter-clockwise
public:
	vector < vec > point; int sz; mt19937 rndLine;
	void input(){
		mt19937 rnd(time(0)); rndLine = rnd;
		cin >> sz; for(int i = 1 ; i <= sz ; ++i) point.push_back(getvec());
		for(int i = 0 ; i < sz ; ++i) point.push_back(point[i]);
	}
	ld area(){
		ld sum = 0;
		for(int i = 0 ; i < sz ; ++i) sum += point[i] % point[i + 1];
		return sum / 2;
	}
	bool isconvex(){
		for(int i = 1 ; i <= sz ; ++i)
			if((point[i - 1] - point[i]) % (point[i + 1] - point[i]) > eps) return 0;
		return 1;
	}
	bool checkin(vec P){
		vec tmp(pow(rndLine() , 0.1) , pow(rndLine() , 0.2));
		segment nowline(P , P + tmp * 1e10);
		int Count = 0;
		for(int i = 0 ; i < sz ; ++i)
			Count += havesect(segment(point[i] , point[i + 1]) , nowline);
		return Count & 1;
	}
	bool checkon(vec P){
		for(int i = 0 ; i < sz ; ++i)
			if(cmp(0 , (point[i + 1] - point[i]) % (P - point[i]))){
				ld t = (point[i + 1] - point[i]) * (P - point[i]) / (point[i + 1] - point[i]).len2();
				if(t > -eps && t < 1 + eps)
					return 1;
			}
		return 0;
	}
};

class convex : public polygon{
public:
	ld cut(segment now){
		int pos = 0; bool flg = 0; vector < vec > cp;
		for(auto t : point) if(now.dir % (t - now.st) < 0) flg = 1;
		if(!flg) return this->area();
		flg = 0;
		for(auto t : point) if(now.dir % (t - now.st) > 0) flg = 1;
		if(!flg) return 0;
		flg = 0;
		while(now.dir % (point[pos] - now.st) > -eps) ++pos;
		while(1){
			if(now.dir % (point[pos] - now.st) > -eps){
				if(!flg) cp.push_back(getsect(now , segment(point[pos] , point[pos - 1])));
				flg = 1; cp.push_back(point[pos]);
			}
			else if(flg){cp.push_back(getsect(now , segment(point[pos] , point[pos - 1]))); break;}
			++pos;
		}
		ld ans = 0;
		for(int i = 1 ; i + 1 < cp.size() ; ++i)
			ans += (cp[i] - cp[0]) % (cp[i + 1] - cp[0]);
		return ans / 2;
	}
};

convex getconvex(polygon now){
	vector < vec > p , p1; convex ans;
	p.insert(p.begin() , now.point.begin() , now.point.begin() + now.sz);
	sort(p.begin() , p.end() , [&](vec a , vec b){return a.y < b.y || a.y == b.y && a.x < b.x;});
	deque < vec > q;
	for(auto t : p){
		while(q.size() >= 2 && (q[q.size() - 1] - q[q.size() - 2]) % (t - q[q.size() - 2]) < eps)
			q.pop_back();
		q.push_back(t);
	}
	q.pop_back(); p1.insert(p1.end() , q.begin() , q.end()); reverse(p.begin() , p.end()); q.clear();
	for(auto t : p){
		while(q.size() >= 2 && (q[q.size() - 1] - q[q.size() - 2]) % (t - q[q.size() - 2]) < eps)
			q.pop_back();
		q.push_back(t);
	}
	q.pop_back(); p1.insert(p1.end() , q.begin() , q.end());
	p1.insert(p1.end() , p1.begin() , p1.end());
	ans.point = p1; ans.sz = p1.size() / 2; return ans;
}

int main(){
	convex now; now.input(); int Q;
	for(cin >> Q ; Q ; --Q){
		segment T = getseg();
		T = segment(T.st - T.dir * 3e4 , T.st + T.dir * 3e4);
		cout << fixed << setprecision(10) << now.cut(T) << endl;
	}
	return 0;
}