#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

typedef long long ll;

bool debug = false;
const int NIL = -1;
const int INF = 1000000000;
const int NUM = 100010;
const double eps = 1e-10;
const double PI = 3.1415926535897946;
clock_t START, END;

//basic defitition
struct Point {
	double x, y;
	Point(double x = 0, double y = 0) :x(x), y(y) {}
};
typedef Point Vector;
Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Point A, Point B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x * p, A.y * p); }
Vector operator / (Vector A, double p) { return Vector(A.x / p, A.y / p); }
bool operator < (const Point& a, const Point& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
int dcmp(double x) { if (fabs(x) < eps)return 0; else return x < 0 ? -1 : 1; }
bool operator == (const Point& a, const Point& b) { return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; }
// basic operator
double Dot(Vector A, Vector B) { return A.x * B.x + A.y * B.y; }
double Length(Vector A) { return sqrt(Dot(A, A)); }
double Cross(Vector A, Vector B) { return A.x * B.y - A.y * B.x; }
//point and line
double Distance(Point A, Point B) {
	return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
}
Point GetLineProjection(Point P, Point A, Point B) {
	Vector v = B - A;
	return A + v * (Dot(v, P - A) / Dot(v, v));
}
double DistanceToSegment(Point P, Point A, Point B) {
	if (A == B) return Length(P - A);
	Vector v1 = B - A, v2 = P - A, v3 = P - B;
	if (dcmp(Dot(v1, v2)) < 0) return Length(v2);
	else if (dcmp(Dot(v1, v3)) > 0) return Length(v3);
	else return fabs(Cross(v1, v2)) / Length(v1);
}
struct Circle {
	Point c;
	double r;
	Circle(Point c, double r) :c(c), r(r) {}
	Point point(double a) {
		return Point(c.x + cos(a) * r, c.y + sin(a) * r);
	}
};
Point GetOne(Circle O, Point A, Point B) {
	Point S = GetLineProjection(O.c, A, B);
	Vector v = (B - A) / Length(B - A);
	double L = sqrt(O.r * O.r - Distance(O.c, S) * Distance(O.c, S));
	Point C = S + v * L, D = S - v * L;
	if (dcmp(Dot(C - A, C - B)) <= 0)
		return C;
	else
		return D;
}
void GetTwo(Circle O, Point A, Point B, Point& P, Point& Q) {
	Point S = GetLineProjection(O.c, A, B);
	Vector v = (B - A) / Length(B - A);
	double L = sqrt(O.r * O.r - Distance(O.c, S) * Distance(O.c, S));
	P = S + v * L;
	Q = S - v * L;
}
double SectorArea(Point A, Point B, double r) {
	if (A == B)
		return 0;
	Point O(0, 0);
	double ang = acos(Dot(A - O, B - O) / r / r);
	return ang * r * r / 2;
}

int main(void)
{
	if (debug) {
		START = clock();
		freopen("in29.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	};
	int n, u = -1, v = -1, cnt_i = 0, cnt_o = 0;
	double x, y, _ans = 0, r;
	vector<Point> polygon, sol;
	Point O, X, Y;
	O.x = O.y = 0;
	scanf("%d%lf", &n, &r);
	Circle OO(O, r);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x, &y);
		polygon.push_back(Point(x, y));
	}
	polygon.push_back(polygon[0]);
	for (int i = 0; i < n; i++) {
		double dis_u = Distance(Point(0, 0), polygon[i]);
		double dis_v = Distance(Point(0, 0), polygon[i + 1]);
		if (dcmp(dis_u - r) <= 0 && dcmp(dis_v - r) <= 0) {
			_ans += Cross(polygon[i] - O, polygon[i + 1] - O) / 2;
		}
		else if (dcmp(dis_u - r) > 0 && dcmp(dis_v - r) > 0) {
			double dist = fabs(Cross(polygon[i] - O, polygon[i + 1] - O) / Length(polygon[i + 1] - polygon[i]));
			if (dcmp(dist - r) >= 0) {
				X = GetOne(OO, O, polygon[i]);
				Y = GetOne(OO, O, polygon[i + 1]);
				if (dcmp(Cross(polygon[i + 1] - polygon[i], O - polygon[i])) > 0)
					_ans += SectorArea(X, Y, r);
				else
					_ans -= SectorArea(X, Y, r);
			}
			else {
				Point P, Q;
				GetTwo(OO, polygon[i + 1], polygon[i], P, Q);
				int t1 = dcmp(Dot(polygon[i + 1] - P, polygon[i] - P));
				int t2 = dcmp(Dot(polygon[i + 1] - Q, polygon[i] - Q));
				X = GetOne(OO, O, polygon[i]);
				Y = GetOne(OO, O, polygon[i + 1]);
				if (t1 >= 0 && t2 >= 0) {
					if (dcmp(Cross(polygon[i + 1] - polygon[i], O - polygon[i])) > 0)
						_ans += SectorArea(X, Y, r);
					else
						_ans -= SectorArea(X, Y, r);
				}
				else {
					if (dcmp(Length(X - Q) - Length(X - P)) < 0)
						swap(P, Q);
					if (dcmp(Cross(polygon[i + 1] - polygon[i], O - polygon[i])) > 0)
						_ans += SectorArea(X, P, r) + SectorArea(Y, Q, r) + dist * Length(P - Q) / 2;
					else
						_ans -= (SectorArea(X, P, r) + SectorArea(Y, Q, r) + dist * Length(P - Q) / 2);
				}
			}
		}
		else {
			if (dcmp(dis_u - r) <= 0) {
				X = GetOne(OO, polygon[i], polygon[i + 1]);
				_ans += Cross(polygon[i] - O, X - O) / 2;
				Y = GetOne(OO, O, polygon[i + 1]);
			}
			else {
				X = GetOne(OO, polygon[i + 1], polygon[i]);
				_ans += Cross(X - O, polygon[i + 1] - O) / 2;
				Y = GetOne(OO, O, polygon[i]);
			}
			if (dcmp(Cross(polygon[i + 1] - polygon[i], Y - polygon[i])) < 0)
				_ans -= SectorArea(X, Y, r);
			else
				_ans += SectorArea(X, Y, r);
		}
	}
	printf("%.10lf\n", _ans);
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}


Measured memory_bytes: 3360