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 <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <complex>
#include <cmath>
using namespace std;

typedef pair<double,double> pdd;
typedef complex<double> P;
typedef const P &rP;

#define EPS 1e-8

double dot(rP a, rP b){
	return real(a) * real(b) + imag(a) * imag(b);
}

double cross(rP a, rP b){
	return real(a) * imag(b) - imag(a) * real(b);
}

bool contains(const vector<P> &plg, rP p){
	int c = 0;
	double y = imag(p);
	
	for(int i = 1; i < plg.size(); ++i){
		double dy1 = imag(plg[i]) - y;
		double dy2 = y - imag(plg[i-1]);
		double tx = (dy1 * real(plg[i-1]) + dy2 * real(plg[i])) / (dy1 + dy2);

		if(imag(plg[i]) >= y && imag(plg[i-1]) < y){
			if(tx < real(p)){ ++c; }
		}
		else if(imag(plg[i]) < y && imag(plg[i-1]) >= y){
			if(tx < real(p)){ ++c; }
		}
	}
	
	return c % 2 != 0;
}

vector<P> intrlc(rP p1, rP p2, rP pc, double r){
	P v12 = p2 - p1, v1c = pc - p1;
	vector<P> ret;
	double a = norm(v12);
	double b = dot(v12, v1c);
	double c = norm(v1c) - r * r;
	double D = b * b - a * c;
	if(D >= 0.0){
		D = sqrt(D);
		double t1 = (b + D) / a, t2 = (b - D) / a;
		if(-EPS < t1 && t1 < 1.0 + EPS){
			ret.push_back(p1 + v12 * t1);
		}
		if(-EPS < t2 && t2 < 1.0 + EPS){
			ret.push_back(p1 + v12 * t2);
		}
	}
	return ret;
}

pdd intrll(rP pa1, rP pa2, rP pb1, rP pb2){
	P da12 = pa2 - pa1;
	P db21 = pb1 - pb2;
	P dab1 = pb1 - pa1;
	double D = cross(da12, db21);
	if(abs(D) < EPS){ return pdd(-1e300, -1e300); }
	return pdd(cross(dab1, db21) / D, cross(da12, dab1) / D);
}

int main(){
	double pi = acos(-1.0);

	int n, x, y;
	double r;
	scanf("%d%lf", &n, &r);
	
	vector<P> plg(n + 1);
	vector<double> args(1, 0.0);
	for(int i = 0; i < n; ++i){
		scanf("%d%d", &x, &y);
		plg[i] = P(x, y);
		if(x != 0 || y != 0){
			args.push_back(arg(plg[i]));
		}
	}
	plg[n] = plg[0];

	for(int i = 1; i < plg.size(); ++i){
		for(double j = 1.0; j <= r + EPS; j += 1.0){
			vector<P> res = intrlc(plg[i-1], plg[i], P(), j);
			for(int k = 0; k < res.size(); ++k){
				args.push_back(arg(res[k]));
			}
		}
	}

	sort(args.begin(), args.end());
	args.erase(unique(args.begin(), args.end()), args.end());
	args.push_back(args[0] + 2.0 * pi);

	double ans = 0.0;
	for(int i = 1; i < args.size(); ++i){
		double mid = 0.5 * (args[i-1] + args[i]);
		P d1 = polar(1.0, args[i-1]);
		P d2 = polar(1.0, mid);
		P d3 = polar(1.0, args[i]);

		vector<pdd> ev;
		for(double j = 1.0; j <= r + EPS; j += 1.0){
			ev.push_back(pdd(j, 0.5 * j * j * (args[i] - args[i-1])));
		}
		for(int j = 1; j < plg.size(); ++j){
			pdd t = intrll(P(), d2, plg[j-1], plg[j]);
			if(t.first > EPS && t.first < r){
				if(t.second > -EPS && t.second < 1.0 + EPS){
					P dif = plg[j-1] - plg[j];
					
					double u1 = intrll(plg[j], plg[j-1], P(), d1).first;
					double u2 = intrll(plg[j], plg[j-1], P(), d3).first;
					
					P a = plg[j] + u1 * dif;
					P b = plg[j] + u2 * dif;
					ev.push_back(pdd(t.first, 0.5 * abs(cross(a, b))));
				}
			}
		}
		
		if(contains(plg, polar(EPS, mid))){
			ev.push_back(pdd(0.0, 0.0));
		}
		
		sort(ev.begin(), ev.end());

		double S = 0.0;
		bool add = false;
		for(int j = 0; j < ev.size(); ++j){
			if(add){
				S += ev[j].second;
			}
			else if(j + 1 < ev.size()){
				S -= ev[j].second;
			}
			add = !add;
		}

		ans += S;
	}
	
	printf("%.15f\n", ans);
}