#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;
}



Measured memory_bytes: 3488