Problem: Magic Circle

Problem Statement

~ How to draw a magic circle ~

1. Prepare a sufficiently large and white floor.
2. Draw a circle with radii 1, 2, ..., R centered on the point at the floor coordinates (0,0).
3. Paint blue between the circle with radius 1 and the circle with radius 2, between the circle with radius 3 and the circle with radius 4, ... Do not paint outside the circle with radius R.
4. Draw a polygon with N vertices on the floor.
5. Repaint the white area inside the polygon with blue and the blue area with white.



It is said that the power of the magic circle becomes stronger as the magic circle contains more blue.
Therefore, I would like you to find the area of ​​the blue area included in the magic circle.

The following figure is an example of a magic circle that can be drawn by this procedure.

<image>

Constraints

* 3 ≤ N ≤ 100
* 1 ≤ R ≤ 100
* Polygons are included inside or on the circumference of a circle with radius R.
* Polygons do not have self-intersections.
* The vertices of the polygon are given in a counterclockwise order.

Input

Input follows the following format. All given numbers are integers.


N R
x_1 y_1
...
x_N y_N

(x_i, y_i) is the i-th vertex of the polygon.

Output

Output the area of ​​the blue area on one line.
The output value must have an absolute or relative error of less than 10 ^ {-8} with the true value.

Examples

Input

3 1
0 0
1 0
0 1


Output

0.500000000


Input

3 2
0 0
2 0
0 2


Output

8.995574288


Input

3 2
1 -1
1 1
-2 0


Output

11.123246567


Input

4 3
1 1
-1 1
-1 -1
1 -1


Output

11.707963268

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

static const double PI = acos(-1.0);

class Vec2
{
public:
    Vec2( double _x, double _y ) : x(_x), y(_y) {}

    double length() const { return sqrt(x*x + y*y); }
    double arg() const {
        if ( length() == 0 ) return 0.0;
        return atan2(y, x);
    }
    Vec2 normalize() const {
        if ( length() == 0 ) return *this;
        return Vec2(x/length(), y/length());
    }

    Vec2 operator+( const Vec2& rhs ) const { return Vec2(x+rhs.x, y+rhs.y); }
    Vec2 operator-( const Vec2& rhs ) const { return Vec2(x-rhs.x, y-rhs.y); }
    Vec2 operator*( double s ) const { return Vec2(x*s, y*s); }
    double dot( const Vec2& rhs ) const { return x*rhs.x + y*rhs.y; }
    double cross( const Vec2& rhs ) const { return x*rhs.y - y*rhs.x; }

private:
    double x;
    double y;
};

double DiffAngle( const Vec2& A, const Vec2& B )
{
    double d = fabs(A.arg()-B.arg());
    if ( d > PI ) d = 2*PI-d;
    return d;
}

vector<Vec2> IntSegCircle( const Vec2& A, const Vec2& B, double r )
{
    vector<Vec2> IntPoint;
    Vec2 D = B - A;
    Vec2 DU = D.normalize();
    Vec2 H = A - DU*(A.dot(DU));
    double h = H.length();
    if ( h >= r )
        return vector<Vec2>();

    double l = sqrt(r*r - h*h);
    double pa = (A-H).dot(DU), pb = (B-H).dot(DU);
    if ( pa < -l && -l < pb ) {
        IntPoint.push_back(H - DU*l);
    }
    if ( pa < l && l < pb ) {
        IntPoint.push_back(H + DU*l);
    }
    return IntPoint;
}

double IntTriCircle( const Vec2& A, const Vec2& B, double r )
{
    vector<Vec2> Int = IntSegCircle( A, B, r );
    if ( Int.empty() ) {
        return min( 0.5*r*r*DiffAngle(A,B), 0.5*A.length()*B.length()*sin(DiffAngle(A,B)) );
    } else if ( Int.size() == 1 ) {
        double area = 0.0;
        if ( A.length() > r ) {
            area += 0.5*r*r*DiffAngle(A,Int[0]);
        } else {
            area += 0.5*A.length()*r*sin(DiffAngle(A,Int[0]));
        }
        if ( B.length() > r ) {
            area += 0.5*r*r*DiffAngle(B,Int[0]);
        } else {
            area += 0.5*B.length()*r*sin(DiffAngle(B,Int[0]));
        }
        return area;
    } else {
        return 0.5*r*r*(sin(DiffAngle(Int[0],Int[1])) + DiffAngle(A,B) - DiffAngle(Int[0],Int[1]));
    }
}

double solve( int R, const vector<Vec2>& Poly )
{
    double sum = 0.0;
    for ( int r = 1; r <= R; r++ ) {
        double area = 0.0;
        for ( size_t i = 0; i < Poly.size()-1; i++ ) {
            double coef = Poly[i].cross(Poly[i+1]) > 0 ? 1.0 : -1.0;
            area += coef * fabs(IntTriCircle(Poly[i], Poly[i+1], r));
            area -= coef * fabs(IntTriCircle(Poly[i], Poly[i+1], r-1));
        }
        if ( r%2==0 ) {
            area = (2*r-1)*PI - area;
        }
        sum += area;
    }
    return sum;
}

int main()
{
    int N, R;
    cin >> N >> R;

    vector<Vec2> Poly;
    for ( int i = 0; i < N; i++ ) {
        double x, y;
        cin >> x >> y;
        Poly.push_back( Vec2(x,y) );
    }
    Poly.push_back( Poly.front() );

    printf( "%.10f\n", solve( R, Poly ) );
    return 0;
}