Problem: Find the area of intersection between a circle $c$ and a polygon $g$. The center coordinate of the circle is ($0, 0$).

The polygon $g$ is represented by a sequence of points $p_1$, $p_2$,..., $p_n$ where line segments connecting $p_i$ and $p_{i+1}$ ($1 \leq i \leq n−1$) are sides of the polygon. The line segment connecting $p_n$ and $p_1$ is also a side of the polygon.

Note that the polygon is not necessarily convex.

Constraints

* $3 \leq n \leq 100$
* $1 \leq r \leq 100$
* $-100 \leq x_i, y_i \leq 100$

Input

The input is given in the following format.

$n$ $r$
$x_1$ $y_1$
$x_2$ $y_2$
:
$x_n$ $y_n$


In the first line, an integer n representing the number of points in the polygon is given. The coordinate of a point $p_i$ is given by two integers $x_i$ and $y_i$. The coordinates of the points are given in the order of counter-clockwise visit of them. All input values are given in integers.

Output

Print the area of intersection in a line. The output values should be in a decimal fraction with an error less than 0.00001.

Examples

Input

3 5
1 1
4 1
5 5


Output

4.639858417607


Input

4 5
0 0
-3 -6
1 -3
5 -4


Output

11.787686807576

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define mm(a,b) memset(a,b,sizeof(a))
#define ACCELERATE (ios::sync_with_stdio(false),cin.tie(0))
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<long long,long long>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
#define E exp(1.0)
#define db double
#define ll long long
#define ld long double
#define ull unsigned long long
//#define io
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
//#define gc getchar
//char buf[1<<21],*p1=buf,*p2=buf;
//inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
//inline int read()
//{
//    int ret=0,f=0;char c=gc();
//    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
//    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
//    if(f)return -ret;return ret;
//}
const int N=1e2+5;
const db EPS=1e-10;
inline int sign(db a){return a<-EPS?-1:a>EPS;}
inline int cmp(db a,db b){return sign(a-b);}
inline db sqr(db x){return x*x;}
struct Point{
    db x,y;
    Point(){}
    Point(db _x,db _y):x(_x),y(_y){}
    void input(){scanf("%lf%lf",&x,&y);}
    void output(){printf("%.10f %.10f\n",x,y);}
    bool operator == (Point b)const{
        return sign(x-b.x)==0&&sign(y-b.y)==0;
    }
    bool operator < (Point b)const{
        return sign(x-b.x)==0?sign(y-b.y)<0:x<b.x;
    }
    Point operator + (const Point &b)const{
        return Point(x+b.x,y+b.y);
    }
    Point operator - (const Point &b)const{
        return Point(x-b.x,y-b.y);
    }
    db operator ^ (const Point &b)const{
        return x*b.y-y*b.x;
    }
    db operator * (const Point &b)const{
        return x*b.x+y*b.y;
    }
    db len(){return hypot(x,y);}
    db len2(){return x*x+y*y;}
    db distance(Point p){return hypot(x-p.x,y-p.y);}
    Point operator * (const db &k)const{
        return Point(x*k,y*k);
    }
    Point operator / (const db &k)const{
        return Point(x/k,y/k);
    }
    db rad(Point a,Point b){
        Point p=*this;
        return fabs(atan2(fabs((a-p)^(b-p)),(a-p)*(b-p)));
    }
    Point unit(){return *this/len();}
    Point trunc(db r){
        db l=len();
        if(!sign(l))return *this;
        r/=l;
        return Point(x*r,y*r);
    }
    Point rotleft(){return Point(-y,x);}
    Point rotright(){return Point(y,-x);}
    Point rotate(Point p,db angle){
        Point v=(*this)-p;
        db c=cos(angle),s=sin(angle);
        return Point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
    }
};
#define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
#define crossOp(p1,p2,p3) sign(cross(p1,p2,p3))
struct Line{
    Point s,e;
    Line(){}
    Line(Point _s,Point _e):s(_s),e(_e){}
    bool operator == (Line v){
        return (s==v.s)&&(e==v.e);
    }
    Line(Point p,db angle){
        s=p;
        if(sign(angle-PI/2)==0)e=(s+Point(0,1));
        else e=(s+Point(1,tan(angle)));
    }
    Line(db a,db b,db c){
        if(sign(a)==0){
            s=Point(0,-c/b);e=Point(1,-c/b);
        }else if(sign(b)==0){
            s=Point(-c/a,0);e=Point(-c/a,1);
        }else{
            s=Point(0,-c/b);e=Point(1,(-c-a)/b);
        }
    }
    void input(){s.input();e.input();}
    void adjust(){if(e<s)swap(s,e);}
    db length(){return s.distance(e);}
    //[0,PI)
    db angle(){
        db k=atan2(e.y-s.y,e.x-s.x);
        if(sign(k)<0)k+=PI;
        if(sign(k-PI)==0)k-=PI;
        return k;
    }
    //line|1 on the left|2 on the right|3 on line|
    int relation(Point p){
        int c=sign((p-s)^(e-s));
        if(c<0)return 1;
        else if(c>0)return 2;
        else return 3;
    }
    bool pointonseg(Point p){
        return sign((p-s)^(e-s))==0&&sign((p-s)*(p-e))<=0;
    }
    bool parallel(Line v){
        return sign((e-s)^(v.e-v.s))==0;
    }
    //|0 not intersect|1 non-standard|2 intersect|
    int segcrossseg(Line v){
        int d1=sign((e-s)^(v.s-s));
        int d2=sign((e-s)^(v.e-s));
        int d3=sign((v.e-v.s)^(s-v.s));
        int d4=sign((v.e-v.s)^(e-v.s));
        if((d1^d2)==-2&&(d3^d4)==-2)return 2;
        return (d1==0&&sign((v.s-s)*(v.s-e))<=0)||
            (d2==0&&sign((v.e-s)*(v.e-e))<=0)||
            (d3==0&&sign((s-v.s)*(s-v.e))<=0)||
            (d4==0&&sign((e-v.s)*(e-v.e))<=0);
    }
    //|0 not intersect|1 non-standard|2 intersect|
    int linecrossseg(Line v){
        int d1=sign((e-s)^(v.s-s));
        int d2=sign((e-s)^(v.e-s));
        if((d1^d2)==-2)return 2;
        return (d1==0||d2==0);
    }
    //|0 parallel|1 coincides|2 intersect|
    int linecrossline(Line v){
        if((*this).parallel(v))return v.relation(s)==3;
        return 2;
    }
    //要保证两直线不平行或重合
    Point crosspoint(Line v){
        db a1=(v.e-v.s)^(s-v.s);
        db a2=(v.e-v.s)^(e-v.s);
        return Point((s.x*a2-e.x*a1)/(a2-a1),(s.y*a2-e.y*a1)/(a2-a1));
    }
    db dispointtoline(Point p){
        return fabs((p-s)^(e-s))/length();
    }
    db dispointtoseg(Point p){
        if(sign((p-s)*(e-s))<0||sign((p-e)*(s-e))<0)return min(p.distance(s),p.distance(e));
        return dispointtoline(p);
    }
    //前提是两线段不相交，相交距离就是0了
    db dissegtoseg(Line v){
        return min(min(dispointtoseg(v.s),dispointtoseg(v.e)),min(v.dispointtoseg(s),v.dispointtoseg(e)));
    }
    Point lineprog(Point p){
		return s + ( ((e-s)*((e-s)*(p-s)))/((e-s).len2()) );
	}
	Point symmetrypoint(Point p){
		Point q = lineprog(p);
		return Point(2*q.x-p.x,2*q.y-p.y);
	}
};
struct circle{
    Point p;
    db r;
    circle(){}
    circle(Point _p,db _r):p(_p),r(_r){}
    circle(db _x,db _y,db _r){
        p=Point(_x,_y);r=_r;
    }
    Point point(db a){
        return Point(p.x+r*cos(a),p.y+r*sin(a));
    }
    //三角形的外接圆
    circle(Point a,Point b,Point c){
        Line u=Line((a+b)/2,((a+b)/2)+((b-a).rotleft()));
        Line v=Line((b+c)/2,((b+c)/2)+((c-b).rotleft()));
        p=u.crosspoint(v);
        r=p.distance(a);
    }
    //三角形的内切圆
    circle(Point a,Point b,Point c,bool t){
        Line u,v;
        db m=atan2(b.y-a.y,b.x-a.x),n=atan2(c.y-a.y,c.x-a.x);
        u.s=a;
        u.e=u.s+Point(cos((n+m)/2),sin((n+m)/2));
        m=atan2(a.y-b.y,a.x-b.x),n=atan2(c.y-b.y,c.x-b.x);
        v.s=b;
        v.e=v.s+Point(cos((n+m)/2),sin((n+m)/2));
        p=u.crosspoint(v);
        r=Line(a,b).dispointtoseg(p);
    }
    void input(){
        p.input();
        scanf("%lf",&r);
    }
    void output(){
        printf("%2.f %.2f %.2f\n",p.x,p.y,p,r);
    }
    bool operator == (circle v){
        return (p==v.p)&&sign(r-v.r)==0;
    }
    bool operator < (circle v)const{
        return ((p<v.p)||((p==v.p)&&sign(r-v.r)<0));
    }
    db area(){return PI*r*r;}
    db circumference(){return 2*PI*r;}
    //|0 not|1 on|2 in|
    int relation(Point b){
        db dst=b.distance(p);
        if(sign(dst-r)<0)return 2;
        else if(sign(dst-r)==0)return 1;
        return 0;
    }
    //|0 not|1 on|2 in|
    int relationseg(Line v){
        db dst=v.dispointtoseg(p);
        if(sign(dst-r)<0)return 2;
        else if(sign(dst-r)==0)return 1;
        return 0;
    }
    int relationline(Line v){
        db dst=v.dispointtoline(p);
        if(sign(dst-r)<0)return 2;
        else if(sign(dst-r)==0)return 1;
        return 0;
    }
    //|1 内含|2 内切|3 相交|4 外切|5 相离|
    int relationcircle(circle v){
        db d=p.distance(v.p);
        if(sign(d-r-v.r)>0)return 5;
        if(sign(d-r-v.r)==0)return 4;
        db l=fabs(r-v.r);
        if(sign(d-r-v.r)<0&&sign(d-l)>0)return 3;
        if(sign(d-l)==0)return 2;
        if(sign(d-l)<0)return 1;
    }
    //|0 没有交点|1 一个交点|2 两个交点|
    int pointcrosscircle(circle v,Point &p1,Point &p2){
        int rel=relationcircle(v);
        if(rel==1||rel==5)return 0;
        db d=p.distance(v.p);
        db l=(d*d+r*r-v.r*v.r)/(2*d);
        db h=sqrt(r*r-l*l);
        Point tmp=p+(v.p-p).trunc(l);
        p1 = tmp+((v.p-p).rotleft().trunc(h));
		p2 = tmp+((v.p-p).rotright().trunc(h));
        if(rel==2||rel==4)return 1;
        return 2;
    }
    int pointcrossline(Line v,Point &p1,Point &p2){
        if(!(*this).relationline(v))return 0;
        Point a=v.lineprog(p);
        db d=v.dispointtoline(p);
        d=sqrt(r*r-d*d);
        if(sign(d)==0){
            p1=a;p2=a;
            return 1;
        }
        p1=a+(v.e-v.s).trunc(d);
        p2=a-(v.e-v.s).trunc(d);
        return 2;
    }
    int getcircle(Point a,Point b,db r1,circle &c1,circle &c2){
        circle x(a,r1),y(b,r1);
        int t=x.pointcrosscircle(y,c1.p,c2.p);
        if(!t)return 0;
        c1.r=c2.r=r;
        return t;
    }
    int getcircle(Line u,Point q,db r1,circle &c1,circle &c2){
        db dis=u.dispointtoline(q);
        if(sign(dis-r1*2)>0)return 0;
        if(sign(dis)==0){
            c1.p=q+((u.e-u.s).rotleft().trunc(r1));
            c2.p=q+((u.e-u.s).rotright().trunc(r1));
            c1.r=c2.r=r1;
            return 2;
        }
        Line u1=Line((u.s+(u.e-u.s).rotleft().trunc(r1)),(u.e+(u.e-u.s).rotleft().trunc(r1)));
		Line u2=Line((u.s+(u.e-u.s).rotright().trunc(r1)),(u.e+(u.e-u.s).rotright().trunc(r1)));
		circle cc = circle(q,r1);
		Point p1,p2;
		if(!cc.pointcrossline(u1,p1,p2))cc.pointcrossline(u2,p1,p2);
		c1 = circle(p1,r1);
		if(p1 == p2){
			c2 = c1;
			return 1;
		}
		c2 = circle(p2,r1);
		return 2;
    }
    int getcircle(Line u,Line v,db r1,circle &c1,circle &c2,circle &c3,circle &c4){
        if(u.parallel(v))return 0;//两直线平行
		Line u1=Line(u.s+(u.e-u.s).rotleft().trunc(r1),u.e+(u.e-u.s).rotleft().trunc(r1));
		Line u2=Line(u.s+(u.e-u.s).rotright().trunc(r1),u.e+(u.e-u.s).rotright().trunc(r1));
		Line v1=Line(v.s+(v.e-v.s).rotleft().trunc(r1),v.e+(v.e-v.s).rotleft().trunc(r1));
		Line v2=Line(v.s+(v.e-v.s).rotright().trunc(r1),v.e+(v.e-v.s).rotright().trunc(r1));
		c1.r=c2.r=c3.r=c4.r=r1;
		c1.p=u1.crosspoint(v1);
		c2.p=u1.crosspoint(v2);
		c3.p=u2.crosspoint(v1);
		c4.p=u2.crosspoint(v2);
		return 4;
    }
    int getcircle(circle cx,circle cy,double r1,circle &c1,circle &c2){
		circle x(cx.p,r1+cx.r),y(cy.p,r1+cy.r);
		int t=x.pointcrosscircle(y,c1.p,c2.p);
		if(!t)return 0;
		c1.r=c2.r=r1;
		return t;
	}
	int tangentline(Point q,Line &u,Line &v){
		int x   = relation(q);
		if(x == 2)return 0;
		if(x == 1){
			u = Line(q,q + (q-p).rotleft());
			v = u;
			return 1;
		}
		double d = p.distance(q);
		double l = r*r/d;
		double h = sqrt(r*r-l*l);
		u = Line(q,p + ((q-p).trunc(l) + (q-p).rotleft().trunc(h)));
		v = Line(q,p + ((q-p).trunc(l) + (q-p).rotright().trunc(h)));
		return 2;
	}
	double areacircle(circle v){
		int rel = relationcircle(v);
		if(rel >= 4)return 0.0;
		if(rel <= 2)return min(area(),v.area());
		double d = p.distance(v.p);
		double hf = (r+v.r+d)/2.0;
		double ss = 2*sqrt(hf*(hf-r)*(hf-v.r)*(hf-d));
		double a1 = acos((r*r+d*d-v.r*v.r)/(2.0*r*d));
		a1 = a1*r*r;
		double a2 = acos((v.r*v.r+d*d-r*r)/(2.0*v.r*d));
		a2 = a2*v.r*v.r;
		return a1+a2-ss;
	}
	double areatriangle(Point a,Point b){
		if(sign((p-a)^(p-b)) == 0)return 0.0;
		Point q[5];
		int len = 0;
		q[len++] = a;
		Line l(a,b);
		Point p1,p2;
		if(pointcrossline(l,q[1],q[2])==2){
			if(sign((a-q[1])*(b-q[1]))<0)q[len++] = q[1];
			if(sign((a-q[2])*(b-q[2]))<0)q[len++] = q[2];
		}
		q[len++] = b;
		if(len == 4 && sign((q[0]-q[1])*(q[2]-q[1]))>0)swap(q[1],q[2]);
		double res = 0;
		for(int i = 0;i < len-1;i++){
			if(relation(q[i])==0||relation(q[i+1])==0){
				double arg = p.rad(q[i],q[i+1]);
				res += r*r*arg/2.0;
			}
			else{
				res += fabs((q[i]-p)^(q[i+1]-p))/2.0;
			}
		}
		return res;
	}
};
int getTangents(circle A,circle B,Point *a,Point *b)
{
    int cnt=0;        //存切点用
    if(sign(A.r-B.r)<0){
        swap(A,B);
        swap(a,b);
    }
    double d=sqrt((A.p.x-B.p.x)*(A.p.x-B.p.x)+(A.p.y-B.p.y)*(A.p.y-B.p.y));     //圆心距
    double rdiff=A.r-B.r;      //两圆半径差
    double rsum=A.r+B.r;       //两圆半径和
    if(sign(d-rdiff)<0)return 0;        //1.内含
    double base=atan2(B.p.y-A.p.y,B.p.x-A.p.x);      //向量AB的极角
    if(sign(d)== 0)return -1;        //2.重合
    if(sign(d-rdiff) == 0){       //3.内切
        a[cnt]=b[cnt]=A.point(base);
        cnt++;
        return 1;
    }
    double ang=acos((A.r-B.r)/d);
    a[cnt]=A.point(base+ang);b[cnt]=B.point(base+ang);cnt++;      //4.相交（外切、外离的外公切线也在此求出）
    a[cnt]=A.point(base-ang);b[cnt]=B.point(base-ang);cnt++;      //两条外公切线的切点
    if(sign(d-rsum)==0){        //5.外切
        a[cnt]=b[cnt]=A.point(base);
        cnt++;
    }
    else if(sign(d-rsum)>0){      //6.外离
        double ang=acos((A.r+B.r)/d);
        a[cnt]=A.point(base+ang);b[cnt]=B.point(PI+base+ang);cnt++;
        a[cnt]=A.point(base-ang);b[cnt]=B.point(PI+base-ang);cnt++;
    }
    return cnt;
}
struct polygon{
	int n;
	Point p[N];
	Line l[N];
	void input(int _n){
		n = _n;
		for(int i = 0;i < n;i++)
			p[i].input();
	}
	void add(Point q){
		p[n++] = q;
	}
	void getline(){
		for(int i = 0;i < n;i++){
			l[i] = Line(p[i],p[(i+1)%n]);
		}
	}
	struct cmp{
		Point p;
		cmp(const Point &p0){p = p0;}
		bool operator()(const Point &aa,const Point &bb){
			Point a = aa, b = bb;
			int d = sign((a-p)^(b-p));
			if(d == 0){
				return sign(a.distance(p)-b.distance(p)) < 0;
			}
			return d > 0;
		}
	};
	//`进行极角排序`
	//`首先需要找到最左下角的点`
	//`需要重载号好Point的 < 操作符(min函数要用) `
	void norm(){
		Point mi = p[0];
		for(int i = 1;i < n;i++)mi = min(mi,p[i]);
		sort(p,p+n,cmp(mi));
	}
	//`得到凸包`
	//`得到的凸包里面的点编号是0$\sim$n-1的`
	//`两种凸包的方法`
	//`注意如果有影响，要特判下所有点共点，或者共线的特殊情况`
	//`测试 LightOJ1203  LightOJ1239`
	void getconvex(polygon &convex){
		sort(p,p+n);
		convex.n = n;
		for(int i = 0;i < min(n,2);i++){
			convex.p[i] = p[i];
		}
		if(convex.n == 2 && (convex.p[0] == convex.p[1]))convex.n--;//特判
		if(n <= 2)return;
		int &top = convex.n;
		top = 1;
		for(int i = 2;i < n;i++){
			while(top && sign((convex.p[top]-p[i])^(convex.p[top-1]-p[i])) <= 0)
				top--;
			convex.p[++top] = p[i];
		}
		int temp = top;
		convex.p[++top] = p[n-2];
		for(int i = n-3;i >= 0;i--){
			while(top != temp && sign((convex.p[top]-p[i])^(convex.p[top-1]-p[i])) <= 0)
				top--;
			convex.p[++top] = p[i];
		}
		if(convex.n == 2 && (convex.p[0] == convex.p[1]))convex.n--;//特判
		convex.norm();//`原来得到的是顺时针的点，排序后逆时针`
	}
	//`得到凸包的另外一种方法`
	//`测试 LightOJ1203  LightOJ1239`
	void Graham(polygon &convex){
		norm();
		int &top = convex.n;
		top = 0;
		if(n == 1){
			top = 1;
			convex.p[0] = p[0];
			return;
		}
		if(n == 2){
			top = 2;
			convex.p[0] = p[0];
			convex.p[1] = p[1];
			if(convex.p[0] == convex.p[1])top--;
			return;
		}
		convex.p[0] = p[0];
		convex.p[1] = p[1];
		top = 2;
		for(int i = 2;i < n;i++){
			while( top > 1 && sign((convex.p[top-1]-convex.p[top-2])^(p[i]-convex.p[top-2])) <= 0 )
				top--;
			convex.p[top++] = p[i];
		}
		if(convex.n == 2 && (convex.p[0] == convex.p[1]))convex.n--;//特判
	}
	//`判断是不是凸的`
	bool isconvex(){
		bool s[2];
		memset(s,false,sizeof(s));
		for(int i = 0;i < n;i++){
			int j = (i+1)%n;
			int k = (j+1)%n;
			s[sign((p[j]-p[i])^(p[k]-p[i]))+1] = true;
			if(s[0] && s[2])return false;
		}
		return true;
	}
	//`判断点和任意多边形的关系`
	//` 3 点上`
	//` 2 边上`
	//` 1 内部`
	//` 0 外部`
	int relationpoint(Point q){
		for(int i = 0;i < n;i++){
			if(p[i] == q)return 3;
		}
		getline();
		for(int i = 0;i < n;i++){
			if(l[i].pointonseg(q))return 2;
		}
		int cnt = 0;
		for(int i = 0;i < n;i++){
			int j = (i+1)%n;
			int k = sign((q-p[j])^(p[i]-p[j]));
			int u = sign(p[i].y-q.y);
			int v = sign(p[j].y-q.y);
			if(k > 0 && u < 0 && v >= 0)cnt++;
			if(k < 0 && v < 0 && u >= 0)cnt--;
		}
		return cnt != 0;
	}
	//`直线u切割凸多边形左侧`
	//`注意直线方向`
	//`测试：HDU3982`
	void convexcut(Line u,polygon &po){
		int &top = po.n;//注意引用
		top = 0;
		for(int i = 0;i < n;i++){
			int d1 = sign((u.e-u.s)^(p[i]-u.s));
			int d2 = sign((u.e-u.s)^(p[(i+1)%n]-u.s));
			if(d1 >= 0)po.p[top++] = p[i];
			if(d1*d2 < 0)po.p[top++] = u.crosspoint(Line(p[i],p[(i+1)%n]));
		}
	}
	//`得到周长`
	//`测试 LightOJ1239`
	double getcircumference(){
		double sum = 0;
		for(int i = 0;i < n;i++){
			sum += p[i].distance(p[(i+1)%n]);
		}
		return sum;
	}
	//`得到面积`
	double getarea(){
		double sum = 0;
		for(int i = 0;i < n;i++){
			sum += (p[i]^p[(i+1)%n]);
		}
		return fabs(sum)/2;
	}
	//`得到方向`
	//` 1 表示逆时针，0表示顺时针`
	bool getdir(){
		double sum = 0;
		for(int i = 0;i < n;i++)
			sum += (p[i]^p[(i+1)%n]);
		if(sign(sum) > 0)return 1;
		return 0;
	}
	//`得到重心`
	Point getbarycentre(){
		Point ret(0,0);
		double area = 0;
		for(int i = 1;i < n-1;i++){
			double tmp = (p[i]-p[0])^(p[i+1]-p[0]);
			if(sign(tmp) == 0)continue;
			area += tmp;
			ret.x += (p[0].x+p[i].x+p[i+1].x)/3*tmp;
			ret.y += (p[0].y+p[i].y+p[i+1].y)/3*tmp;
		}
		if(sign(area)) ret = ret/area;
		return ret;
	}
	//`多边形和圆交的面积`
	//`测试：POJ3675 HDU3982 HDU2892`
	double areacircle(circle c){
		double ans = 0;
		for(int i = 0;i < n;i++){
			int j = (i+1)%n;
			if(sign( (p[j]-c.p)^(p[i]-c.p) ) >= 0)
				ans += c.areatriangle(p[i],p[j]);
			else ans -= c.areatriangle(p[i],p[j]);
		}
		return fabs(ans);
	}
	//`多边形和圆关系`
	//` 2 圆完全在多边形内`
	//` 1 圆在多边形里面，碰到了多边形边界`
	//` 0 其它`
	int relationcircle(circle c){
		getline();
		int x = 2;
		if(relationpoint(c.p) != 1)return 0;//圆心不在内部
		for(int i = 0;i < n;i++){
			if(c.relationseg(l[i])==2)return 0;
			if(c.relationseg(l[i])==1)x = 1;
		}
		return x;
	}
};
int n;
db _r;
polygon g;
circle c;
int main()
{
    sc(n);g.n=n;
    scanf("%lf",&_r);
    c.p.x=c.p.y=0.0;
    c.r=_r;
    rep(i,0,n-1)scanf("%lf%lf",&g.p[i].x,&g.p[i].y);
    db ans=g.areacircle(c);
    printf("%.12f\n",ans);
    return 0;
}