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 <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define EPS 1e-10
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const double pi = acos(-1);
struct Point{
	double x,y;
	Point(double x = 0.0,double y = 0.0): x(x),y(y) {}
	Point operator + (Point p){
		return Point(x + p.x,y + p.y);
	}
	Point operator - (Point p){
		return Point(x - p.x,y - p.y);
	}
	Point operator * (double lambda){
		return Point(x * lambda,y * lambda);
	}
	Point operator / (double lambda){
		return Point(x / lambda,y / lambda);
	}
	double norm(){
		return x * x + y * y;
	}
	double abs_(){
		return sqrt(norm());
	}
	Point rot(double theta){
		return Point(cos(theta) * x - sin(theta) * y,sin(theta) * x + cos(theta) * y);
	}
	bool operator == (const Point &p)const
	{
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
	bool operator < (const Point &p)const
	{
		if(abs(x - p.x) < EPS) return y < p.y;
		else return x < p.x;
	}

	void print(){
		printf("%.3f %.3f",x,y);
	}

};
typedef Point Vector;
struct Segment{
	Point p1,p2;
	Segment(Point p1 = Point(),Point p2 = Point()): p1(p1),p2(p2) {}
};
typedef Segment Line;
struct Circle{
	Point c;
	double r;
	Circle(Point c = Point(),double r = 0.0): c(c),r(r) {}
};
typedef vector<Point> Polygon;
double dot(Vector a,Vector b){
	return a.x * b.x + a.y * b.y;
}
double det(Vector a,Vector b){
	return a.x * b.y - b.x * a.y;
}
Point proj(Point p,Line l){
	Vector a = l.p2 - l.p1;
	double r = dot(a,p - l.p1) / a.norm();
	return l.p1 + a * r;
}
vector <Point> crossCL(Circle o,Line l){//make sure crossing.
	Point A = proj(o.c,l);
	Vector a = l.p2 - l.p1, e = a / a.abs_();
	vector <Point> res(0);
	if(o.r * o.r < (A - o.c).norm() - EPS) return res;
	double AP = sqrt(max(o.r * o.r - (A - o.c).norm(),0.0));
	res.push_back(A + e * AP);
	if(AP > EPS) res.push_back(A - e * AP);
	return res;
}
int ccw(Segment/*Directed Segment*/ s,Point p){
  Vector a = s.p2 - s.p1,b = p - s.p1;
  if(det(a,b) > EPS) return 1;
  else if(det(a,b) < -EPS) return -1;
  else if(dot(a,b) < -EPS) return 2;
  else if(a.norm() < b.norm() - EPS) return -2;
  else return 0;
}
double inter_ang(Vector a,Vector b){
	double t = abs(atan2(a.y,a.x) - atan2(b.y,b.x));
	return min(t,2 * pi - t);
}
double intersect(Circle o,Vector a,Vector b){//absolute area.
	if(a.norm() > b.norm()) swap(a,b);
	if(a.norm() < o.r * o.r + EPS){
		if(b.norm() < o.r * o.r + EPS){
			return abs(det(a,b)) / 2.0;
		}else{
			vector <Point> cs = crossCL(o,Line(o.c + a,o.c + b));
			for(int i=0;i<(int)cs.size();i++){
				if(ccw(Segment(o.c + a,o.c + b),cs[i]) == 0){
					double ans = abs(det(a,cs[i] - o.c)) / 2.0;
					ans += inter_ang(cs[i] - o.c,b) * o.r * o.r / 2.0;
					return ans;
				}
			}
		}
	}else{
		vector <Point> cs = crossCL(o,Line(o.c + a,o.c + b));
		for(int i=0;i<(int)cs.size();i++){
			if(ccw(Segment(o.c + a,o.c + b),cs[i])) cs.erase(cs.begin() + i);
		}
		if(cs.size() < 2){
			return inter_ang(a,b) * o.r * o.r / 2.0;
		}else{
			Point p1 = cs[0], p2 = cs[1];
			double ans = abs(det(p1 - o.c, p2 - o.c)) / 2.0;
			ans += (inter_ang(a,b) - inter_ang(p1 - o.c,p2 - o.c)) * o.r * o.r / 2.0;
			return ans;
		}
	}
	return -1.0;
}
double intersectPC(Polygon po,Circle o){
	double res = 0.0;
	int n = po.size();
	for(int i=0;i<n;i++){
		double tmp = intersect(o,po[i] - o.c,po[(i + 1) % n] - o.c);
		if(det(po[i] - o.c,po[(i + 1) % n] - o.c) < -EPS) res -= tmp;
		else res += tmp;
	}
	return res;
}
Polygon po;
int n;
double r;
int main(){
	scanf("%d%lf",&n,&r);
	po.resize(n);
	for(int i=0;i<n;i++){
		scanf("%lf%lf",&po[i].x,&po[i].y);
	}
	printf("%.10f\n",intersectPC(po,Circle(Point(0.0,0.0),r)));
	return 0;
}