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;
//types
typedef long long ll;
typedef pair<int,int> pii;
//input
bool SR(int &_x){return scanf("%d",&_x)==1;}bool SR(ll &_x){return scanf("%lld",&_x)==1;}
bool SR(double &_x){return scanf("%lf",&_x)==1;}bool SR(char *_s){return scanf("%s",_s)==1;}
bool RI(){return true;}
template<typename I,typename... T>bool RI(I &_x,T&... _tail){return SR(_x) && RI(_tail...);}
//output
void SP(const int _x){printf("%d",_x);}void SP(const ll _x){printf("%lld",_x);}
void SP(const double _x){printf("%.16lf",_x);}void SP(const char *s){printf("%s",s);}
void PL(){puts("");}
template<typename I,typename... T>void PL(const I _x,const T... _tail)
{SP(_x);if(sizeof...(_tail)) putchar(' ');PL(_tail...);}
//macro
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<int(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=int(b);i++)
#define PER1(i,a,b) for(int i=(a);i>=int(b);i--)
#define pb push_back
#define mkp make_pair
#define F first
#define S second
//debug
#ifdef darry140
template<typename A,typename B>
ostream& operator <<(ostream&_s, const pair<A,B> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename It>
ostream& _OUTC(ostream &_s,It _b,It _e)//container
{
    _s<<"{";
    for(auto _it=_b;_it!=_e;_it++) _s<<(_it==_b?"":" ")<<*_it;
    _s<<"}";
    return _s;
}
template<typename A,typename B>
ostream& operator <<(ostream&_s, const map<A,B> &_c){return _OUTC(_s,ALL(_c));}
template<typename T>
ostream& operator <<(ostream&_s, const set<T> &_c){return _OUTC(_s,ALL(_c));}
template<typename T>
ostream& operator <<(ostream&_s, const vector<T> &_c){return _OUTC(_s,ALL(_c));}
template<typename I>
void _DOING(const char *_s,I&& _x){cerr<<_s<<"="<<_x<<endl;}//without ','
template<typename I,typename... T>
void _DOING(const char *_s,I&& _x,T&&... _tail)//with ','
{
    int _c=0;
    static const char _bra[]="({[";
    static const char _ket[]=")}]";
    while(*_s!=',' || _c!=0)//eg. mkp(a,b)
    {
        if(strchr(_bra,*_s)) _c++;
        if(strchr(_ket,*_s)) _c--;
        cerr<<*_s++;
    }
    cerr<<"="<<_x<<", ";
    _DOING(_s+1,_tail...);
}
#define debug(...) do{\
    fprintf(stderr,"%s:%d - ",__PRETTY_FUNCTION__,__LINE__);\
    _DOING(#__VA_ARGS__,__VA_ARGS__);\
}while(0)
#else
#define debug(...)
#endif
//}}}
typedef long double ld;
const ld global_eps=1e-8;
#if 0
enum cases{insi,bord,outs};//inside, border, outside
enum cases{para,coin,inte};//parallel, coincide, intersect
#else
enum Case
{
    insi,bord,outs,//inside, border, outside
    para,coin,inte, //parallel, coincide, intersect
    tang,tang_in,tang_out //tangent
};
#endif
int sign(ld x,ld eps=global_eps){return (x>=eps)-(x<=-eps);}
int cmp(ld a,ld b,ld eps=global_eps){return sign(a-b,eps);}
struct Point
{
    ld x,y;
    Point():x(0),y(0){}
    Point(ld _x,ld _y):x(_x),y(_y){}
    Point operator +(const Point &p) const
    {return Point(x+p.x,y+p.y);}
    Point operator -(const Point &p) const
    {return Point(x-p.x,y-p.y);}
    ld operator *(const Point &p) const
    {return x*p.x+y*p.y;}
    ld operator %(const Point &p) const
    {return x*p.y-y*p.x;}   
    bool operator <(const Point &p) const
    {return tie(y,x) < tie(p.y,p.x);}
    bool operator ==(const Point &p) const
    {return tie(y,x) == tie(p.y,p.x);}
    Point operator /(const ld &l) const
    {return Point(x/l,y/l);}
    Point operator *(const ld &l) const
    {return Point(x*l,y*l);}
    ld len() const{return hypot(x,y);}
    ld len2() const{return x*x+y*y;}
    ld dis(const Point &a)const{return (*this-a).len();}
    ld dis2(const Point &a)const{return (*this-a).len2();}
    Point unit()const{return *this/len();}
    Point resize(const ld &l)const{return unit()*l;}
};
struct Line
{
    Point p1,p2;
    Line(){}
    Line(Point a,Point b):p1(a),p2(b){}
    Point way() const{return p2-p1;}
    Point norm() const{return {p1.y-p2.y,p2.x-p1.x};}
    bool online(const Point &p) const{return sign((p-p1)%way())==0;}
    bool onsegment(const Point &p)const
    {
        return online(p) && sign((p-p1)*(p2-p))>=0;
    }
    pair<int,Point> intersect(const Line &I) const
    {
        if(sign(I.way()%way())==0) return {online(I.p1)?coin:para,{0,0}};
        const Point &p3=I.p1,&p4=I.p2;
        auto _143=(p1-p4)%(p4-p3),_342=(p3-p4)%(p4-p2);
        return {inte,(p1*_342+p2*_143)/(_143+_342)};
    }
    ld linedistance(const Point &p) const
    {
        return abs((p-p1)%way())/way().len();
    }
    ld signedlinedistance(const Point &p) const
    {
        return ((p-p1)%way())/way().len();
    }
    Point project(const Point &p) const
    {
        return intersect(Line(p,p+norm())).second;
    }
    ld segmentdistance(const Point &p) const
    {
        const auto &pro=project(p);
        if(onsegment(pro)) return p.dis(pro);
        return min(p.dis(p1),p.dis(p2));
    }
};
int main()
{
    int n;RI(n);
    vector<Point> g(n);
    REP(i,n) cin>>g[i].x>>g[i].y;
    g.pb(g[0]);
    int q;RI(q);
    while(q--)
    {
        Line I;
        cin>>I.p1.x>>I.p1.y>>I.p2.x>>I.p2.y;
        vector<Point> v;
        REP(i,n)
        {
            if(I.signedlinedistance(g[i])<0) v.pb(g[i]);
            Point o=I.intersect(Line(g[i],g[i+1])).S;
            if(I.online(o)&&Line(g[i],g[i+1]).onsegment(o))
                v.pb(o);
        }
        int m=SZ(v);if(SZ(v)==0){PL(0);continue;}v.pb(v[0]);
        ld ans=0;
        REP(i,m) ans+=v[i]%v[i+1];
        ans=abs(ans/2);
        PL((double)ans);
    }

    return 0;
}