#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<complex>
using namespace std;

const double EPS = 1e-8;

#define curr(G, i) G[i%n]
#define next(G, i) G[(i+1)%n]

typedef complex<double> P;
typedef vector<P> triangle;
typedef vector<P> Poly;
struct L : public vector<P>{
    L(const P &a, const P &b){
        push_back(a), push_back(b);
    }
};

namespace std {
  bool operator < (const P& a, const P& b) {
    return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
  }
}

double cross(const P &a, const P &b){
    return imag(conj(a)*b);
}

double dot(const P &a, const P &b){
    return real(conj(a)*b);
}

int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > 0) return +1;
    if(cross(b,c) < 0) return -1;
    if(dot(b,c) < 0) return +2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}

triangle makeTriangle(const P &a, const P &b, const P &c){
    triangle res(3);
    res[0] = a;
    res[1] = b;
    res[2] = c;
    return res;
}

bool containment(const triangle &tri, const P &p){
    return ccw(tri[0], tri[1], p) >=0 && ccw(tri[1], tri[2], p) >=0 && ccw(tri[2], tri[0], p) >=0;
}

bool triangeJudge(int i, int j, int k, const Poly &G){
    if(ccw(G[i], G[j], G[k])<=0) return false;
    triangle tri = makeTriangle(G[i], G[j], G[k]);
    for (int l=0;l<G.size();l++){
        if(l != i && l != j && l != k){
            if(containment(tri, G[l])) return false;
        }
    }
    return true;
}

vector<triangle> triangulation(Poly &G){
    vector<triangle> res;
    int n = G.size();
    vector<int> l, r;
    for (int i=0;i<n;i++){
        l.push_back((i-1+n)%n);
        r.push_back((i+1+n)%n);
    }

    int i = n-1;
    while(res.size() < n-2){
        i = r[i];
        if(triangeJudge(l[i], i, r[i], G)){
            res.push_back(makeTriangle(G[l[i]], G[i], G[r[i]]));
            l[ r[i] ] = l[i];
            r[ l[i] ] = r[i];
        }
    }
    return res;
}

double area(vector<P> &G){
    int n = G.size();
    double S = 0;
    for (int i=0;i<n;i++){
        P p = curr(G, i);
        P q = next(G, i);
        S += (1.0/2)*cross(p, q);
    }
    return S;
}

double arcArea(P &p, P &q, double r){
    double theta = arg(q) - arg(p);
    if(theta < 0) theta += 2.0 * M_PI;
    return (1.0/2)*r*r*(theta - sin(theta));
}

vector<P> crossCircleLine(P p1, P p2, double r){
    vector<P> res;

    double a = p2.imag() - p1.imag();
    double b = -(p2.real() - p1.real());
    double c = p1.real()*p2.imag() - p2.real()*p1.imag();
    if ( ((a*a + b*b)*r*r - c*c) < 0 )  return res;
    double x1 = (a*c - b*sqrt((a*a + b*b)*r*r - c*c))/(a*a + b*b);
    double y1 = (b*c + a*sqrt((a*a + b*b)*r*r - c*c))/(a*a + b*b);
    double x2 = (a*c + b*sqrt((a*a + b*b)*r*r - c*c))/(a*a + b*b);
    double y2 = (b*c - a*sqrt((a*a + b*b)*r*r - c*c))/(a*a + b*b);
    P q1(x1, y1);
    P q2(x2, y2);

    if (norm(q1-p1) > norm(q2-p1)) swap(q1, q2);
    if (dot(q1- p1, q1 - p2) <= -EPS) res.push_back(q1);
    if (dot(q2- p1, q2 - p2) <= -EPS) res.push_back(q2);

    return res;
}

int inOnOutCircle(const P &p, double r){
    if(norm(p) < r*r - EPS) return 0;
    if(norm(p) > r*r + EPS) return 2;
    return 1;
}

double intersectionCicleTriangle(triangle &T, double r){

    P z(0, 0);
    bool crossing = false;
    for(int i=0;i<3;i++){
        vector<P> crossed = crossCircleLine(T[i], T[(i+1)%3], r);
        if (crossed.size() != 0){
            crossing = true;
            break;
        }
    }
    if(!crossing && norm(T[0]) > r*r + EPS && containment(T, z)) return M_PI*r*r;

    vector<P> Time;
    vector<P> Arc;
    vector<bool> type;
    int inOnOut;
    for(int i=0;i<3;i++){
        inOnOut = inOnOutCircle(T[i], r);
        vector<P> crossed = crossCircleLine(T[i], T[(i+1)%3], r);
        if(inOnOut == 0){
            Time.push_back(T[i]);
            if(crossed.size() == 1){
                Time.push_back(crossed[0]);
                Arc.push_back(crossed[0]);
                type.push_back(true);
            }
        }else if(inOnOut == 1){
            Time.push_back(T[i]);
            P tt(-T[i].imag(), T[i].real());
            P p1 = T[(i+2)%3] - T[i];
            P p2 = T[(i+1)%3] - T[i];
            if(cross(tt, p1) > EPS && cross(tt, p2) <= EPS){
                Arc.push_back(T[i]);
                type.push_back(true);
            }
            if(cross(tt, p1) <= EPS && cross(tt, p2) > EPS){
                Arc.push_back(T[i]);
                type.push_back(false);
            }
            if(crossed.size() == 1){
                Time.push_back(crossed[0]);
                Arc.push_back(crossed[0]);
                type.push_back(true);
            }
        }else{
            if(crossed.size() == 1){
                Time.push_back(crossed[0]);
                Arc.push_back(crossed[0]);
                type.push_back(false);
            }else if(crossed.size() == 2){
                Time.push_back(crossed[0]);
                Arc.push_back(crossed[0]);
                type.push_back(false);
                Time.push_back(crossed[1]);
                Arc.push_back(crossed[1]);
                type.push_back(true);
            }
        }
    }

    double S = 0;
    S += area(Time);
    if(Arc.size() != 0){
        if(!type[0]){
            for(int i=0;i<(Arc.size()/2)-1;i++){
                S += arcArea(Arc[2*i+1], Arc[2*i+2],r);
            }
            S += arcArea(Arc[Arc.size()-1], Arc[0],r);
        }else{
            for(int i=0;i<Arc.size()/2;i++){
                S += arcArea(Arc[2*i], Arc[2*i+1], r);
            }
        }
    }

    return S;
}

double intersectionOfCircleAndPolygon(Poly &G, double r){
    vector<triangle> ears = triangulation(G);
    double S = 0;
    for (int i=0;i<ears.size();i++){
        S += intersectionCicleTriangle(ears[i], r);
    }
    return S;

}

int main(){
    int n;
    double r, x, y;
    cin >> n >> r;
    Poly G;
    for (int i=0;i<n;i++){
        P p;
        cin >> p.real() >> p.imag();
        G.push_back(p);
    }

    printf("%.10f\n", intersectionOfCircleAndPolygon(G, r));

    return 0;
}

Measured memory_bytes: 3640