#include <bits/stdc++.h>
using namespace std;

const int md = 998244353;
inline void add(int &a, int b) {
	a += b;
	if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
	a -= b;
	if (a < 0) a += md;
}
inline int mul(int a, int b) {
	return (int) ((long long) a * b % md);
}
inline int power(int a, long long b) {
	int res = 1;
	while (b > 0) {
		if (b & 1) {
			res = mul(res, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}
inline int inver(int a) {
	a %= md;
	if (a < 0) a += md;
	int b = md, u = 0, v = 1;
	while (a) {
		int t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	assert(b == 1);
	if (u < 0) u += md;
	return u;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(12);
	int n, p;
	cin >> n >> p;
	vector<int> l(n), r(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i] >> r[i];
	}
	double ans = 0;
	for (int i = 0; i < n; i++) {
		int x = r[i] / p - (l[i] - 1) / p;
		int y = r[(i + 1) % n] / p - (l[(i + 1) % n] - 1) / p;
		cerr << x << ' ' << y << '\n';
		ans += (double)((long long)x * (r[(i + 1) % n] - l[(i + 1) % n] + 1) + (long long)y * (r[i] - l[i] + 1) - (long long)x * y) / ((long long)(r[i] - l[i] + 1)  * (r[(i + 1) % n] - l[(i + 1) % n] + 1));
	}
	cout << ans * 2000 << '\n';
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define sz(v) sizeof(v)
#define MOD 1000000007
#define MAX (ll)1e12+5
using namespace std;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
//////
// prime Seive

bitset<1000005> bt;
//unordered_map<ll,bool> is_prime;
vector<ll> primes;
void pS(ll n){
    ll val = min(n+1,(ll)1000006);
    for(ll i=3;i<=val;i+=2){
        bt[i] =true;
    }
    bt[0] =false;
    bt[1] =false;
    bt[2] =false;
    //is_prime[2] =true;
    primes.pb((ll)2);
    for(ll i=3;i<=val;i+=2){
        if(bt[i])
            for(ll j=i*i;j<=val;j+=2*i)
                bt[j] =false;
    }
    for(ll i=3;i<=val;i+=2){
        if(bt[i]){primes.pb(i);
        //is_prime[i]=true;
        //cout<<i<<" :PRIME\n";
        }
    }
    return;
}

/////
// Fenwick Tree
/*
BIT[200005] ={0};
//BUILD BIT
// for(int i=1;i<1;i++){ cin>>a[i];update(i,a[i],n);};

void update(int i,int val,int n){
    while(i<=n){
    BIT[i]+= inc;
    i+= (i&(-i));
    }
}
ll query(int i){
    ll ans =0;
    while(i>0){
        ans+= BIT[i];
        i-=(i&(-i));
    }
    return ans;
}

*/
//__builtin_popcount(4)
ll logPow(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1){
            ans*=a;
        }
        a*=a;
        b= b>>1;
    }
    return ans;
}

ll gcd(ll a,ll b){
    return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return (a*b)/gcd(a,b);
}

/*
// dsu
const int N = 500009;
int p[N],cmp[N];
int getP(int cn){
    return ((cn==p[cn])?cn:(p[cn]=getP(p[cn])));
}

void unite(int a,int b){
    a = getP(a);
    b = getP(b);
    if(a==b) return ;
    if(cmp[a]<cmp[b])
        swap(a,b);
    p[b] = a;
    cmp[a] += cmp[b];
}
*/

/*
//dfs
bool dfs(ll src ,ll dest,unordered_map<ll,bool> &vis,unordered_map<ll,vector<ll>> &g){
    vis[src] =true;
    if(src== dest) return true;
    bool  ans =false;
    for(auto nbr: g[src]){
        if(!vis[nbr])
            ans = ans|dfs(nbr,dest,vis,g);
    }
    return ans;
}

*/

unordered_map<ll,vector<ll>> g;

ll modPow(ll a,ll b){
    ll ans =1;
    while(b>0){
        if(b&1){
            ans*=a;
            ans= (ans+MOD)%MOD;
        }
        a*=a;
        a= (a+MOD)%MOD;
        b = b>>1;
    }
    return  ans;
}

ll bfs(ll i,unordered_map<ll,bool> &vis){
    queue<ll> q;
    q.push(i);
    vis[i] =true;
    ll ans =0;
    while(!q.empty()){
        ans++;
        ll cur = q.front();
        q.pop();
        for(auto nbr: g[cur]){
            if(!vis[nbr]){
                vis[nbr] =true;
                q.push(nbr);
            }
        }
    }
    return ans;
}

int main(){
    ll n,p;
    cin>>n>>p;
    vector<pair<ld,ld> > vt;
    ll l,h;
    for(int i=0;i<n;i++){
        cin>>l>>h;
        ld r = h-l+1;
        ld val = h/p-(l-1)/p;
        vt.pb(mp(val,r));
    }
    ld ans =0;
    for(int i=0;i<n;i++){
        ld X1,X2,R1,R2;
        if(i==n-1){
            X1 = vt[i].first;
            X2 = vt[0].first;
            R1 = vt[i].second;
            R2 = vt[0].second;
        }
        else{
            X1 = vt[i].first;
            X2 = vt[i+1].first;
            R1 = vt[i].second;
            R2 = vt[i+1].second;
        }
        ld val =((X1*X2)+(X1*(R2-X2))+(X2*(R1-X2)))/(R1*R2);
        ans += ((ld)2000)*(val);
    }
    cout<<fixed<<setprecision(10)<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define sz(v) sizeof(v)
#define MOD 1000000007
#define MAX (ll)1e12+5
using namespace std;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
//////
// prime Seive

bitset<1000005> bt;
//unordered_map<ll,bool> is_prime;
vector<ll> primes;
void pS(ll n){
    ll val = min(n+1,(ll)1000006);
    for(ll i=3;i<=val;i+=2){
        bt[i] =true;
    }
    bt[0] =false;
    bt[1] =false;
    bt[2] =false;
    //is_prime[2] =true;
    primes.pb((ll)2);
    for(ll i=3;i<=val;i+=2){
        if(bt[i])
            for(ll j=i*i;j<=val;j+=2*i)
                bt[j] =false;
    }
    for(ll i=3;i<=val;i+=2){
        if(bt[i]){primes.pb(i);
        //is_prime[i]=true;
        //cout<<i<<" :PRIME\n";
        }
    }
    return;
}

/////
// Fenwick Tree
/*
BIT[200005] ={0};
//BUILD BIT
// for(int i=1;i<1;i++){ cin>>a[i];update(i,a[i],n);};

void update(int i,int val,int n){
    while(i<=n){
    BIT[i]+= inc;
    i+= (i&(-i));
    }
}
ll query(int i){
    ll ans =0;
    while(i>0){
        ans+= BIT[i];
        i-=(i&(-i));
    }
    return ans;
}

*/
//__builtin_popcount(4)
ll logPow(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1){
            ans*=a;
        }
        a*=a;
        b= b>>1;
    }
    return ans;
}

ll gcd(ll a,ll b){
    return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return (a*b)/gcd(a,b);
}

/*
// dsu
const int N = 500009;
int p[N],cmp[N];
int getP(int cn){
    return ((cn==p[cn])?cn:(p[cn]=getP(p[cn])));
}

void unite(int a,int b){
    a = getP(a);
    b = getP(b);
    if(a==b) return ;
    if(cmp[a]<cmp[b])
        swap(a,b);
    p[b] = a;
    cmp[a] += cmp[b];
}
*/

/*
//dfs
bool dfs(ll src ,ll dest,unordered_map<ll,bool> &vis,unordered_map<ll,vector<ll>> &g){
    vis[src] =true;
    if(src== dest) return true;
    bool  ans =false;
    for(auto nbr: g[src]){
        if(!vis[nbr])
            ans = ans|dfs(nbr,dest,vis,g);
    }
    return ans;
}

*/

unordered_map<ll,vector<ll>> g;

ll modPow(ll a,ll b){
    ll ans =1;
    while(b>0){
        if(b&1){
            ans*=a;
            ans= (ans+MOD)%MOD;
        }
        a*=a;
        a= (a+MOD)%MOD;
        b = b>>1;
    }
    return  ans;
}

ll bfs(ll i,unordered_map<ll,bool> &vis){
    queue<ll> q;
    q.push(i);
    vis[i] =true;
    ll ans =0;
    while(!q.empty()){
        ans++;
        ll cur = q.front();
        q.pop();
        for(auto nbr: g[cur]){
            if(!vis[nbr]){
                vis[nbr] =true;
                q.push(nbr);
            }
        }
    }
    return ans;
}

int main(){
    ll n,p;
    cin>>n>>p;
    vector<pair<ld,ld> > vt;
    ll l,h;
    for(int i=0;i<n;i++){
        cin>>l>>h;
        ld r = h-l+1;
        ld val = h/p-(l-1)/p;
        vt.pb(mp(val,r));
    }
    ld ans =0;
    for(int i=0;i<n;i++){
        ld X1,X2,R1,R2;
        if(i==n-1){
            X1 = vt[i].first;
            X2 = vt[0].first;
            R1 = vt[i].second;
            R2 = vt[0].second;
        }
        else{
            X1 = vt[i].first;
            X2 = vt[i+1].first;
            R1 = vt[i].second;
            R2 = vt[i+1].second;
        }
        ld val =((X1*X2)+(X1*(R2-X2))+(X2*(R1-X1)))/(R1*R2);
        //cout<<((ld)2000*(val))<<"\n";
        ans += ((ld)2000)*(val);
    }
    cout<<fixed<<setprecision(10)<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ffor(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define rfor(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) ffor(i, 0, j, 1)
#define rrep(i, j) rfor(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define inf (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define trace1(x)                     cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)        cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double pi=acos(-1.0);
typedef pair<long long int,long long int> pii;
typedef long long ll;
typedef vector<long long int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<long long int,long long int> mpii;
typedef set<long long int> sei;
typedef multiset<long long int> msei;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
////////////////////// DIJKSTRA ///////////////////////////////////////
void dijkstra(vector<pair<ll,ll> > v[],ll source,ll n)
{
    ll vis[n+1]={0};
    ll dis[n+1];
    for(ll i=0;i<=n;i++)
    dis[i]=1000000000;
    multiset<pair<ll,ll> > s;
    s.insert(mp(0,source));
    dis[source]=0;
    while(s.size()>0)
    {
        pair<ll,ll> p=*(s.begin());
        s.erase(s.begin());
        ll wei=p.first;
        ll x=p.second;
        if(vis[x])
            continue;
        vis[x]=1;
        for(ll i=0;i<v[x].size();i++)
        {
            ll e=v[x][i].first;                          //adjcent element
            ll wei2=v[x][i].second;                      //edge weigth
            if(dis[e]>dis[x]+wei2)
            {
                dis[e]=dis[x]+wei2;
                s.insert(mp(dis[e],e));
            }
        }
    }
}
///////////////////////////////////////////////////////////////////////
//////////////SEGMENT TREE/////////////////////////////////////////////
void contree(ll input[],ll segtree[],ll low,ll high,ll pos)
{
    //initilize segtree array with max values
    if(low==high)
    {
        segtree[pos]=input[low];
        return ;
    }
    ll mid=(low+high)/2;
    contree(input,segtree,low,mid,pos*2+1);
    contree(input,segtree,mid+1,high,pos*2+2);
    segtree[pos]=min(segtree[pos*2+1],segtree[pos*2+2]);
}
ll rmquery(ll segtree[],ll qlow,ll qhigh,ll low,ll high,ll pos)
{
    if(qlow<=low && qhigh>=high)
        return segtree[pos];
    if(qlow>high || qhigh<low)
        return 10000000000;
    ll mid=(low+high)/2;
    return min(rmquery(segtree,qlow,qhigh,low,mid,pos*2+1),rmquery(segtree,qlow,qhigh,mid+1,high,pos*2+2));
}
void updatetree(ll segtree[],ll lazy[],ll start,ll end,ll delta,ll low,ll high,ll pos)
{
    if(low>high)
    return ;
    if(lazy[pos]!=0)
    {
        segtree[pos]+=lazy[pos];
        if(low!=high)                                  //not a leaf node
        {
            lazy[pos*2+1]+=lazy[pos];
            lazy[pos*2+2]+=lazy[pos];
        }
        lazy[pos]=0;
    }
    if(start>high || end<low)                         //no overlap
    return ;
    if(start<=low && end>=high)                       //total overlap
    {
        segtree[pos]+=delta;
        if(low!=high)
        {
            lazy[2*pos+1]+=delta;
            lazy[2*pos+2]+=delta;
        }
        return ;
    }
    ll mid=(low+high)/2;
    updatetree(segtree,lazy,start,end,delta,low,mid,pos*2+1);
    updatetree(segtree,lazy,start,end,delta,mid+1,high,pos*2+2);
    segtree[pos]=min(segtree[2*pos+1],segtree[2*pos+2]);
}
///////////////////////////////////////////////////////////////////
/////////////////////// DISJOINT SET///////////////////////////////
struct node
{
    node *parent;
    ll data;
};
node *key[1000001];
void  makeset(ll x)
{
    node *temp=new node;
    temp->parent=temp;
    temp->data=x;
    key[x]=temp;
}
node *findparent(node *x)
{
    node *temp,*temp1;
    temp=x;
    temp1=x;
    while(temp!=temp->parent)
        temp=temp->parent;
    while(temp1!=temp1->parent)
    {
        temp1->parent=temp;
        temp1=temp1->parent;
    }
    return temp;
}
void union1(ll x,ll y)
{
    if(findparent(key[x])!=findparent(key[y]))
    {
        node *temp=findparent(key[x]);
        node *temp2=findparent(key[y]);
        temp2->parent=temp;
    }
}
///////////////////////////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m,p;
    cin>>n>>p;
    float expt=0;
    float rg[n][2];
    float ans=0;
    for(i=0;i<n;i++)
        cin>>rg[i][0]>>rg[i][1];
    for(i=0;i<n;i++)
    {
        float len=rg[i][1]-rg[i][0]+1;
        ll pp=rg[i][0];
        ll q=rg[i][1];
        ll tot=q/p-(pp-1)/p;
        float temp=len-tot;
        float len1=len;
        float len2=rg[(i+1)%n][1]-rg[(i+1)%n][0]+1;
        ll tot2=(rg[(i+1)%n][1]/p)-((rg[(i+1)%n][0]-1)/p);
        float temp2=len2-tot2;
        //trace4(temp2,temp,len1,len2)
        ans+=1-((temp)/(len1))*((temp2)/(len2));
    }
    cout<<ans*2000;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ffor(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define rfor(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) ffor(i, 0, j, 1)
#define rrep(i, j) rfor(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define inf (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define trace1(x)                     cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)        cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double pi=acos(-1.0);
typedef pair<long long int,long long int> pii;
typedef long long ll;
typedef vector<long long int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<long long int,long long int> mpii;
typedef set<long long int> sei;
typedef multiset<long long int> msei;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
////////////////////// DIJKSTRA ///////////////////////////////////////
void dijkstra(vector<pair<ll,ll> > v[],ll source,ll n)
{
    ll vis[n+1]={0};
    ll dis[n+1];
    for(ll i=0;i<=n;i++)
    dis[i]=1000000000;
    multiset<pair<ll,ll> > s;
    s.insert(mp(0,source));
    dis[source]=0;
    while(s.size()>0)
    {
        pair<ll,ll> p=*(s.begin());
        s.erase(s.begin());
        ll wei=p.first;
        ll x=p.second;
        if(vis[x])
            continue;
        vis[x]=1;
        for(ll i=0;i<v[x].size();i++)
        {
            ll e=v[x][i].first;                          //adjcent element
            ll wei2=v[x][i].second;                      //edge weigth
            if(dis[e]>dis[x]+wei2)
            {
                dis[e]=dis[x]+wei2;
                s.insert(mp(dis[e],e));
            }
        }
    }
}
///////////////////////////////////////////////////////////////////////
//////////////SEGMENT TREE/////////////////////////////////////////////
void contree(ll input[],ll segtree[],ll low,ll high,ll pos)
{
    //initilize segtree array with max values
    if(low==high)
    {
        segtree[pos]=input[low];
        return ;
    }
    ll mid=(low+high)/2;
    contree(input,segtree,low,mid,pos*2+1);
    contree(input,segtree,mid+1,high,pos*2+2);
    segtree[pos]=min(segtree[pos*2+1],segtree[pos*2+2]);
}
ll rmquery(ll segtree[],ll qlow,ll qhigh,ll low,ll high,ll pos)
{
    if(qlow<=low && qhigh>=high)
        return segtree[pos];
    if(qlow>high || qhigh<low)
        return 10000000000;
    ll mid=(low+high)/2;
    return min(rmquery(segtree,qlow,qhigh,low,mid,pos*2+1),rmquery(segtree,qlow,qhigh,mid+1,high,pos*2+2));
}
void updatetree(ll segtree[],ll lazy[],ll start,ll end,ll delta,ll low,ll high,ll pos)
{
    if(low>high)
    return ;
    if(lazy[pos]!=0)
    {
        segtree[pos]+=lazy[pos];
        if(low!=high)                                  //not a leaf node
        {
            lazy[pos*2+1]+=lazy[pos];
            lazy[pos*2+2]+=lazy[pos];
        }
        lazy[pos]=0;
    }
    if(start>high || end<low)                         //no overlap
    return ;
    if(start<=low && end>=high)                       //total overlap
    {
        segtree[pos]+=delta;
        if(low!=high)
        {
            lazy[2*pos+1]+=delta;
            lazy[2*pos+2]+=delta;
        }
        return ;
    }
    ll mid=(low+high)/2;
    updatetree(segtree,lazy,start,end,delta,low,mid,pos*2+1);
    updatetree(segtree,lazy,start,end,delta,mid+1,high,pos*2+2);
    segtree[pos]=min(segtree[2*pos+1],segtree[2*pos+2]);
}
///////////////////////////////////////////////////////////////////
/////////////////////// DISJOINT SET///////////////////////////////
struct node
{
    node *parent;
    ll data;
};
node *key[1000001];
void  makeset(ll x)
{
    node *temp=new node;
    temp->parent=temp;
    temp->data=x;
    key[x]=temp;
}
node *findparent(node *x)
{
    node *temp,*temp1;
    temp=x;
    temp1=x;
    while(temp!=temp->parent)
        temp=temp->parent;
    while(temp1!=temp1->parent)
    {
        temp1->parent=temp;
        temp1=temp1->parent;
    }
    return temp;
}
void union1(ll x,ll y)
{
    if(findparent(key[x])!=findparent(key[y]))
    {
        node *temp=findparent(key[x]);
        node *temp2=findparent(key[y]);
        temp2->parent=temp;
    }
}
ll n;
double p;
ll rg[100001][2];
ll kk(ll x)
{
    ll pp=p;
    return x/pp;
}
///////////////////////////////////////////////////////////////////
double find(ll index)
{
    double tot=kk(rg[index][1])-kk(rg[index][0]-1);
    double len=rg[index][1]-rg[index][0]+1;
    return (tot/len);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,m;
    cin>>n>>p;
    for(i=0;i<n;i++)
        cin>>rg[i][0]>>rg[i][1];
    double ans=0;
    for(i=0;i<n;i++)
    {
        double prob1=find(i);
        double prob2=find((i+1)%n);
        ans+=(prob1+prob2-prob1*prob2)*2000;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ffor(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define rfor(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) ffor(i, 0, j, 1)
#define rrep(i, j) rfor(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define inf (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define trace1(x)                     cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)        cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double pi=acos(-1.0);
typedef pair<long long int,long long int> pii;
typedef long long ll;
typedef vector<long long int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<long long int,long long int> mpii;
typedef set<long long int> sei;
typedef multiset<long long int> msei;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
////////////////////// DIJKSTRA ///////////////////////////////////////
void dijkstra(vector<pair<ll,ll> > v[],ll source,ll n)
{
    ll vis[n+1]={0};
    ll dis[n+1];
    for(ll i=0;i<=n;i++)
    dis[i]=1000000000;
    multiset<pair<ll,ll> > s;
    s.insert(mp(0,source));
    dis[source]=0;
    while(s.size()>0)
    {
        pair<ll,ll> p=*(s.begin());
        s.erase(s.begin());
        ll wei=p.first;
        ll x=p.second;
        if(vis[x])
            continue;
        vis[x]=1;
        for(ll i=0;i<v[x].size();i++)
        {
            ll e=v[x][i].first;                          //adjcent element
            ll wei2=v[x][i].second;                      //edge weigth
            if(dis[e]>dis[x]+wei2)
            {
                dis[e]=dis[x]+wei2;
                s.insert(mp(dis[e],e));
            }
        }
    }
}
///////////////////////////////////////////////////////////////////////
//////////////SEGMENT TREE/////////////////////////////////////////////
void contree(ll input[],ll segtree[],ll low,ll high,ll pos)
{
    //initilize segtree array with max values
    if(low==high)
    {
        segtree[pos]=input[low];
        return ;
    }
    ll mid=(low+high)/2;
    contree(input,segtree,low,mid,pos*2+1);
    contree(input,segtree,mid+1,high,pos*2+2);
    segtree[pos]=min(segtree[pos*2+1],segtree[pos*2+2]);
}
ll rmquery(ll segtree[],ll qlow,ll qhigh,ll low,ll high,ll pos)
{
    if(qlow<=low && qhigh>=high)
        return segtree[pos];
    if(qlow>high || qhigh<low)
        return 10000000000;
    ll mid=(low+high)/2;
    return min(rmquery(segtree,qlow,qhigh,low,mid,pos*2+1),rmquery(segtree,qlow,qhigh,mid+1,high,pos*2+2));
}
void updatetree(ll segtree[],ll lazy[],ll start,ll end,ll delta,ll low,ll high,ll pos)
{
    if(low>high)
    return ;
    if(lazy[pos]!=0)
    {
        segtree[pos]+=lazy[pos];
        if(low!=high)                                  //not a leaf node
        {
            lazy[pos*2+1]+=lazy[pos];
            lazy[pos*2+2]+=lazy[pos];
        }
        lazy[pos]=0;
    }
    if(start>high || end<low)                         //no overlap
    return ;
    if(start<=low && end>=high)                       //total overlap
    {
        segtree[pos]+=delta;
        if(low!=high)
        {
            lazy[2*pos+1]+=delta;
            lazy[2*pos+2]+=delta;
        }
        return ;
    }
    ll mid=(low+high)/2;
    updatetree(segtree,lazy,start,end,delta,low,mid,pos*2+1);
    updatetree(segtree,lazy,start,end,delta,mid+1,high,pos*2+2);
    segtree[pos]=min(segtree[2*pos+1],segtree[2*pos+2]);
}
///////////////////////////////////////////////////////////////////
/////////////////////// DISJOINT SET///////////////////////////////
struct node
{
    node *parent;
    ll data;
};
node *key[1000001];
void  makeset(ll x)
{
    node *temp=new node;
    temp->parent=temp;
    temp->data=x;
    key[x]=temp;
}
node *findparent(node *x)
{
    node *temp,*temp1;
    temp=x;
    temp1=x;
    while(temp!=temp->parent)
        temp=temp->parent;
    while(temp1!=temp1->parent)
    {
        temp1->parent=temp;
        temp1=temp1->parent;
    }
    return temp;
}
void union1(ll x,ll y)
{
    if(findparent(key[x])!=findparent(key[y]))
    {
        node *temp=findparent(key[x]);
        node *temp2=findparent(key[y]);
        temp2->parent=temp;
    }
}
ll n;
double p;
ll rg[100001][2];
ll kk(ll x)
{
    ll pp=p;
    return x/pp;
}
///////////////////////////////////////////////////////////////////
double find(ll index)
{
    double tot=kk(rg[index][1])-kk(rg[index][0]-1);
    double len=rg[index][1]-rg[index][0]+1;
    return (tot/len);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,m;
    cin>>n>>p;
    for(i=0;i<n;i++)
        cin>>rg[i][0]>>rg[i][1];
    double ans=0;
    for(i=0;i<n;i++)
    {
        double prob1=find(i);
        double prob2=find((i+1)%n);
        ans+=(prob1+prob2-prob1*prob2)*2000;
    }
    cout.precision(10);
    cout << fixed << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+2;
typedef long long ll;
int main()
{
    // freopen("data.txt","r",stdin);
    ll n,p;
    cin>>n>>p;
    double ans=0;
    double pro[MAX];
    for(int i=0;i<n;i++)
    {
        ll l,r;
        cin>>l>>r;
        pro[i]=1-(r/p-(l-1)/p)*1.0/(r-l+1);
    }
    for(int i=1;i<n;i++)
    {
        ans+=(1-pro[i]*pro[i-1]);
    }
    ans+=(1-pro[n-1]*pro[0]);
    printf("%.1f\n",ans*2000);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+2;
typedef long long ll;
int main()
{
     freopen("data.txt","r",stdin);
    ll n,p;
    cin>>n>>p;
    double ans=0;
    double pro[MAX];
    for(int i=0;i<n;i++)
    {
        ll l,r;
        cin>>l>>r;
        pro[i]=1-(r/p-(l-1)/p)*1.0/(r-l+1);
        cout<<pro[i]<<" ";
    }
    for(int i=1;i<n;i++)
    {
        ans+=(1-pro[i]*pro[i-1]);
    }
    ans+=(1-pro[n-1]*pro[0]);
    printf("%.1f\n",ans*2000);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=1e5+2;
typedef long long ll;
int main()
{
   //  freopen("data.txt","r",stdin);
    ll n,p;
    cin>>n>>p;
    double ans=0;
    double pro[MAX];
    for(int i=0;i<n;i++)
    {
        ll l,r;
        cin>>l>>r;
        pro[i]=1-(r/p-(l-1)/p)*1.0/(r-l+1);
    }
    for(int i=1;i<n;i++)
    {
        ans+=(1-pro[i]*pro[i-1]);
    }
    ans+=(1-pro[n-1]*pro[0]);
    printf("%f\n",ans*2000);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, p;
long long res = 0, ss = 1;
vector < pair < int, int > > v;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> p;
    for(int i = 0; i < n; i++){
        int l, r, currL, currR;
        cin >> l >> r;
        currL = l + (p - l % p) % p;
        currR = r - r % p;
        if(currL > currR) v.push_back({0, r - l + 1});
        else v.push_back({(currR - currL) / p + 1, r - l + 1});
        ss *= v.back().second;
    }
    double probability;
    for(int i = 0; i < n - 1; i++){
        res += v[i].first * v[i + 1].second;
        res += v[i + 1].first * v[i].second;
        res -= v[i].first * v[i + 1].first;
    }
    res += v[n - 1].first * v[0].second;
    res += v[0].first * v[n - 1].second;
    res -= v[0].first * v[n - 1].first;
    cout << fixed << setprecision(10) << 4.0 * res * 1000 / ss;
}


#include <bits/stdc++.h>

using namespace std;

int n, p;
double res = 0;
vector < pair < int, int > > v;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> p;
    for(int i = 0; i < n; i++){
        int l, r, currL, currR;
        cin >> l >> r;
        currL = l + (p - l % p) % p;
        currR = r - r % p;
        if(currL > currR) v.push_back({0, r - l + 1});
        else v.push_back({(currR - currL) / p + 1, r - l + 1});
    }
    double probability, probability2;
    for(int i = 0; i < n - 1; i++){
        probability = 1.0 * v[i].first / v[i].second;
        probability2 = 1.0 * v[i + 1].first / v[i + 1].second;
        res += 1000 * (1 - (1 - probability) * (1 - probability2));
    }
     probability = 1.0 * v[0].first / v[0].second;
     probability2 = 1.0 * v[n - 1].first / v[n - 1].second;
     res += 1000 * (1 - (1 - probability) * (1 - probability2));
    cout << fixed << setprecision(10) << 2.0 * res;
}


#if __APPLE__
    #include <iostream>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <algorithm>
    #include <cstdio>
    #include <iomanip>
#else
    #include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define xll __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define v(type) vector<type>
#define MATRIX(type) vector<vector<type>>
#define MAX(A,B,C) max(A,max(B,C))
#define MIN(A,B,C) min(A,min(B,C))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PREC 1e-9
struct range{
    int l,r;
};
int main(){
    int n;
    double p;
    cin >> n >> p;
    double res = 0;
    v(range) arr(n);
    for(int i=0;i<n;++i)
        cin >> arr[i].l >> arr[i].r;
    v(double) P(n);
    for(int s1=0;s1<n;++s1){
        int s2 = (s1 + 1)%n;
        double totalNumbers1 = arr[s1].r - arr[s1].l + 1;
        double totalNumbers2 = arr[s2].r - arr[s2].l + 1;
        int numbersDiv1 = ((arr[s1].r/p)) - ((arr[s1].l-1)/p);
        int numbersDiv2 = ((arr[s2].r/p)) - ((arr[s2].l-1)/p);
        P[s1] = ((totalNumbers1 - numbersDiv1)/totalNumbers1) * ((totalNumbers2 - numbersDiv2)/totalNumbers2);
    }
    for(int i=0;i<n;++i){
        res += 2000.0 * (1 - P[i]);
    }
    cout<<fixed<<setprecision(6)<<res<<'\n';
}


#if __APPLE__
    #include <iostream>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <algorithm>
    #include <cstdio>
    #include <iomanip>
#else
    #include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define xll __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define v(type) vector<type>
#define MATRIX(type) vector<vector<type>>
#define MAX(A,B,C) max(A,max(B,C))
#define MIN(A,B,C) min(A,min(B,C))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PREC 1e-9
struct range{
    int l,r;
};
int main(){
    int n,p;
    cin >> n >> p;
    double res = 0;
    v(range) arr(n);
    for(int i=0;i<n;++i)
        cin >> arr[i].l >> arr[i].r;
    v(double) P(n);
    for(int s1=0;s1<n;++s1){
        int s2 = (s1 + 1)%n;
        int totalNumbers1 = arr[s1].r - arr[s1].l + 1;
        int totalNumbers2 = arr[s2].r - arr[s2].l + 1;
        int numbersDiv1 = ((arr[s1].r/p)) - ((arr[s1].l-1)/p);
        int numbersDiv2 = ((arr[s2].r/p)) - ((arr[s2].l-1)/p);
        P[s1] = ((totalNumbers1 - numbersDiv1)*(totalNumbers2 - numbersDiv2))/((double)totalNumbers2 * totalNumbers1);
    }
    for(int i=0;i<n;++i){
        res += 2000.0 * (1 - P[i]);
    }
    cout<<fixed<<setprecision(8)<<res<<'\n';
}


#if __APPLE__
    #include <iostream>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <algorithm>
    #include <cstdio>
    #include <iomanip>
#else
    #include <bits/stdc++.h>
#endif
using namespace std;
#define ll long long
#define xll __int128
#define pii pair<int,int>
#define pll pair<ll,ll>
#define v(type) vector<type>
#define MATRIX(type) vector<vector<type>>
#define MAX(A,B,C) max(A,max(B,C))
#define MIN(A,B,C) min(A,min(B,C))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PREC 1e-9
struct range{
    int l,r;
};
int main(){
    int n,p;
    cin >> n >> p;
    double res = 0;
    v(range) arr(n);
    for(int i=0;i<n;++i)
        cin >> arr[i].l >> arr[i].r;
    v(double) P(n);
    for(int s1=0;s1<n;++s1){
        int s2 = (s1 + 1)%n;
        ll totalNumbers1 = arr[s1].r - arr[s1].l + 1;
        ll totalNumbers2 = arr[s2].r - arr[s2].l + 1;
        ll numbersDiv1 = ((arr[s1].r/p)) - ((arr[s1].l-1)/p);
        ll numbersDiv2 = ((arr[s2].r/p)) - ((arr[s2].l-1)/p);
        P[s1] = ((totalNumbers1 - numbersDiv1)*(totalNumbers2 - numbersDiv2))/((double)totalNumbers2 * totalNumbers1);
    }
    for(int i=0;i<n;++i){
        res += 2000.0 * (1 - P[i]);
    }
    cout<<fixed<<setprecision(8)<<res<<'\n';
}


#include <bits/stdc++.h>

using namespace std;

double f[100010];

int main(){
    int n;
	long long int p;
    long long int l, r;
    long long int cnt;
    cin >> n >> p;
    for(int i = 1; i <= n; i++){
        cin >> l >> r;
        cnt=r / p - l / p;
        if(l % p == 0){
            cnt++;
        }
        f[i] = (double)cnt / (r - l + 1);
    }
    f[0] = f[n];
    double ans=0.0;
    for(int i = 1; i <= n;i++)
       ans += 1000 * (1 - (1 - f[i]) * (1 - f[i - 1]));
    cout << ans * 2;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
double f[100010];

int main()
{
    int n;
	LL p;
    LL l,r;
    LL cnt;
    scanf("%d%lld",&n,&p);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&l,&r);
        cnt=r/p-l/p;
        if(l%p==0)cnt++;
        f[i]=(double)cnt/(r-l+1);
    }
    f[0]=f[n];
    double ans=0.0;
    for(int i=1;i<=n;i++)
       ans+=1000*(1-(1-f[i])*(1-f[i-1]));
    printf("%.6lf\n",ans*2);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    int p;
    cin >> n >> p;
    int u;
    int v;
    double a[n];
    double b[n];
    for(int i = 0; i < n; i++){
        cin >> u >> v;
        b[i] = v - u + 1;
        a[i] = v / p - (u - 1) / p;
    }
    double ans = 0;
    for(int i = 0; i <= n - 1; i++){
        ans += 1 - (b[i] - a[i]) * (b[(i + 1) % n] - a[(i + 1) % n]) / (b[i] * b[(i + 1) % n]);
    }
    cout << ans * 2000;
}


#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll bp(ll a,ll b)
{
    ll res=1;

    while(b>0)
    {
        if(b&1)
        res=(a*res);
        a=(a*a);
        b/=2;
    }
    return res;
}
main()
{
     IO
     ll n,p;
     cin>>n>>p;
     ll l[n],r[n];
     for(int x=0;x<n;x++)
     {
         cin>>l[x]>>r[x];
     }
     ld e=0;
     for(int x=0;x<n;x++)
     {   ll y=(x+1)%n;
         ll f=(r[x]-l[x]+1)*((r[y]-l[y]+1)/p);
         f+=(r[y]-l[y]+1)*((r[x]-l[x]+1)/p);
         f-=((r[y]-l[y]+1)/p)*((r[x]-l[x]+1)/p);
         ll u=(r[x]-l[x]+1)*(r[y]-l[y]+1);
        // cout<<u<<" "<<f<<"\n";
         e+=(1000.0*(((ld)f/(ld)u)));
     }
     cout<<fixed;
     cout<<setprecision(7)<<e*2<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll bp(ll a,ll b)
{
    ll res=1;

    while(b>0)
    {
        if(b&1)
        res=(a*res);
        a=(a*a);
        b/=2;
    }
    return res;
}
main()
{
     IO
     ll n,p;
     cin>>n>>p;
     ll l[n],r[n];
     for(int x=0;x<n;x++)
     {
         cin>>l[x]>>r[x];
     }
     ld e=0;
     for(int x=0;x<n;x++)
     {   ll y=(x+1)%n;
         ll f=(r[x]-l[x]+1)*((r[y]/p)-((l[y]-1)/p));
         f+=(r[y]-l[y]+1)*((r[x]/p)-((l[x]-1)/p));
         f-=((r[y]/p)-((l[y]-1)/p))*((r[x]/p)-((l[x]-1)/p));
         ll u=(r[x]-l[x]+1)*(r[y]-l[y]+1);
         e+=(2000.0*(((ld)f/(ld)u)));
     }
     cout<<fixed;
     cout<<setprecision(7)<<e<<"\n";
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
*/

#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define pi acos(-1.0)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()

//#define inf 1<<30

// isupper() -> upper case check
// tolower() -> convert upper to lower case
// idx = str.find("bear", pos)) != string::npos =>substring find
// Tuple access -> get<0>(v[i])
// cmnt - ctrl []
// stoi("...") -> decimel

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;

const int inf = 2e9;
const int mod = 1e9+7;

int dr[] = {-1, 0, 1,  0};// up, right, down, left
int dc[] = { 0, 1, 0, -1};

// King moves similar to 8 direction
//int dr[] = {-1, -1, 0, 1, 1,  1, 0, -1};
//int dc[] = { 0,  1, 1, 1, 0, -1,-1, -1};

// Knight moves
int kr[] = {-1,  1, -2, -2, -1, 1,  2,  2};
int kc[] = {-2, -2, -1,  1,  2, 2, -1,  1};
// diagonal moves
int dgr[] = {-1, -1,  1, 1};
int dgc[] = { 1, -1, -1, 1};

int main()
{
    ll n, p, tot = 1, cnt = 0;
    cin>>n>>p;

    vector<double>v, elem;
    while(n--){
        ll l, r;
        cnt = 0;
        cin>>l>>r;
        elem.pb(r-l+1);
        tot = tot * (r-l+1);
        ll x = ((l+1)/p)*p;
        if(x < l) x += p;
        if(x <= r) cnt++;
        cnt += (r-x)/p;
        //cnt = (r/p)-((l-1)/p);
        v.pb(cnt);
    }
    n = v.size();
    //cout << tot <<endl;
    double ans = 0;
    for(int i=0; i<n; i++){
        int l = i, r = (i+1)%n;
        // wrong
        //ans += (v[l]*elem[r])+(v[r]*elem[l])-(v[l]*v[r]);
        // right
        ans += (((((v[l]*v[r])+(v[l]*(elem[r]-v[r]))+
                    (v[r]*(elem[l]-v[l]))))*2000)/(elem[l]*elem[r]));
        //cout << ans <<endl;
    }
    //ans *= 2000;
    printf("%0.6f\n", ans);

    return 0;
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
*/

#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define pi acos(-1.0)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()

//#define inf 1<<30

// isupper() -> upper case check
// tolower() -> convert upper to lower case
// idx = str.find("bear", pos)) != string::npos =>substring find
// Tuple access -> get<0>(v[i])
// cmnt - ctrl []
// stoi("...") -> decimel

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;

const int inf = 2e9;
const int mod = 1e9+7;

int dr[] = {-1, 0, 1,  0};// up, right, down, left
int dc[] = { 0, 1, 0, -1};

// King moves similar to 8 direction
//int dr[] = {-1, -1, 0, 1, 1,  1, 0, -1};
//int dc[] = { 0,  1, 1, 1, 0, -1,-1, -1};

// Knight moves
int kr[] = {-1,  1, -2, -2, -1, 1,  2,  2};
int kc[] = {-2, -2, -1,  1,  2, 2, -1,  1};
// diagonal moves
int dgr[] = {-1, -1,  1, 1};
int dgc[] = { 1, -1, -1, 1};

int main()
{
    ll n, p, tot = 1, cnt = 0;
    cin>>n>>p;

    vector<ll>v, elem;
    while(n--){
        ll l, r;
        cnt = 0;
        cin>>l>>r;
        elem.pb(r-l+1);
        tot = tot * (r-l+1);
        ll x = ((l+1)/p)*p;
        if(x < l) x += p;
        if(x <= r) cnt++;
        cnt += (r-x)/p;
        v.pb(cnt);
    }
    n = v.size();
    //cout << tot <<endl;
    double ans = 0;
    for(int i=0; i<n; i++){
        int l = i, r = (i+1)%n;
        ans += (v[l]*elem[r])+(v[r]*elem[l])-(v[l]*v[r]);
        //cout << ans <<endl;
    }
    ans *=4000;
    printf("%0.6f\n", ans/tot);

    return 0;
}


#include <iostream>
#include <iomanip>
#define ll long long
#define ld long double

const int nmax = 1e5 + 5;

ll l[nmax], r[nmax];

int main()
{
	ll n, p;
	std::cin >> n >> p;
	for (int i = 1; i <= n; i++)
		std::cin >> l[i] >> r[i];
	ld ans = 0.0;
	for (int i = 1; i <= n; i++) {
		int j = ((i == n) ? 1 : (i + 1));
		ll x = r[i] / p - (l[i] - 1) / p, y = r[j] / p - (l[j] - 1) / p;
		ld prob = (1.0*(x * (r[j] - l[j] + 1) + y * (r[i] - l[i] + 1) - x * y))/(1.0*((r[i]-l[i]+1)*(r[j]-l[j]+1)));
		ans += prob;
	}
	ans *= 2000.0;
	std::cout << std::fixed << std::setprecision(6) << ans;
}


#include <iostream>
#include <iomanip>

#define ld long double

const int nmax = 1e5 + 5;

int l[nmax], r[nmax];

int main()
{
	int n, p;
	std::cin >> n >> p;
	for (int i = 1; i <= n; i++)
		std::cin >> l[i] >> r[i];
	ld ans = 0.0;
	for (int i = 1; i <= n; i++) {
		int j = ((i == n) ? 1 : (i + 1));
		int x = r[i] / p - (l[i] - 1) / p, y = r[j] / p - (l[j] - 1) / p;
		ld prob = (1.0*(x * (r[j] - l[j] + 1) + y * (r[i] - l[i] + 1) - x * y))/(1.0*((r[i]-l[i]+1)*(r[j]-l[j]+1)));
		ans += prob;
	}
	ans *= 2000.0;
	std::cout << std::fixed << std::setprecision(6) << ans;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    int n,p;
    cin>>n>>p;
    long double pr[n];
    int l,r;
    for(int i=0;i<n;++i)
    {
        cin>>l>>r;
        pr[i]=1.0-(double)((r/p)-(l-1)/p)/(r-l+1);
    }
    long double ans=1-pr[0]*pr[n-1];
    for(int i=1;i<n;++i)
        ans+=(1-pr[i]*pr[i-1]);
    ans=ans*2000.00;
    cout<<fixed<<setprecision(9)<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    int n,p;
    cin>>n>>p;
    int l[n],r[n],pr[n],npr[n];
    for(int i=0;i<n;++i)
    {
        cin>>l[i]>>r[i];
        pr[i]=r[i]/p-(l[i]-1)/p;
        npr[i]=(r[i]-l[i]+1)-pr[i];
        ///cout<<pr[i]<<' '<<npr[i]<<endl;
    }
    ll ans=0,cnt=0,x;
    for(int i=0;i<n;++i)
    {
        if(i==n-1)
        {
            x=(pr[i]*(r[0]-l[0]+1)*4000)+(npr[i]*pr[0]*4000);
            cnt+=(pr[i]*(r[0]-l[0]+1)+npr[i]*pr[0]);
        }
        else
            {x=(pr[i]*(r[i+1]-l[i+1]+1)*4000)+(npr[i]*pr[i+1]*4000);
            cnt+=(pr[i]*(r[i+1]-l[i+1]+1)+npr[i]*pr[i+1]);}
        ans+=x;
    }
    if(cnt==0)
    {
        cout<<"0.0"<<endl;
        return 0;
    }
    cnt-=1;
    long double a=(long double)ans/(long double) cnt;
    cout<<fixed<<setprecision(9)<<a<<endl;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <fstream>
#include <queue>
#include <deque>
#include <numeric>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long LL;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< LL > vl;
typedef vector< vl > vvl;
typedef pair <int, int> ii;
#define tr(c,it) for(decltype(c.begin()) it = c.begin(); it != c.end(); it++)
#define rep(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define repr(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define in(a,b) ( (b).find(a) != (b).end())

double ws_prob(LL l, LL r, LL p) {
	LL pl, pr;
	pl = max((LL)0, (l-1) / p);
	pr = r / p;

	return (double)(pr - pl) / (r - l + 1);
}

int main() {
	ios::sync_with_stdio(false);

	LL n, p, l, r;
	cin >> n >> p;

	vvl s(n);
	rep(i, n) {
		cin >> l >> r;
		s[i].pb(l);
		s[i].pb(r);
	}

	double p1, p2, sol;
	sol = 0;
	rep(i, n) {
		p1 = ws_prob(s[i][0], s[i][1], p);
		p2 = ws_prob(s[(i + 1) % n][0], s[(i + 1) % n][1], p);
		sol += 2000 * (p1 + p2*(1 - p1));
	}

	cout.precision(10);
	cout << fixed << sol;
}


#include <iostream>
#include <ctime>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define ll long long
#define ld long double
ll n,p;
ll arr[100005][2];
ld temp,t1,t2;
ld ans=0;

ld f(ll i){
	return static_cast<ld>(arr[i][1]-arr[i][0]+1-arr[i][1]/p+(arr[i][0]-1)/p)/(arr[i][1]-arr[i][0]+1);
}
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
#endif
	scanf("%lld%lld",&n,&p);
	for(int i=0; i<n; i++){
		scanf("%lld%lld",&arr[i][0],&arr[i][1]);
	}
	for(int i=1; i<n; i++){
		t1=f(i);
		t2=f(i-1);
		temp=(1-t1*t2)*2000;
		ans+=temp;
	}
	t1=f(0);
	t2=f(n-1);
	temp=(1-t1*t2)*2000;
	ans+=temp;
	printf("%.1Lf",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
ll n,p;
ll arr[100005][2];
ld temp,t1,t2;
ld ans=0;

ld f(ll i){
	return static_cast<ld>(arr[i][1]-arr[i][0]+1-arr[i][1]/p+(arr[i][0]-1)/p)/(arr[i][1]-arr[i][0]+1);
}
int main(){
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
#endif
	scanf("%lld%lld",&n,&p);
	for(int i=0; i<n; i++){
		scanf("%lld%lld",&arr[i][0],&arr[i][1]);
	}
	for(int i=1; i<n; i++){
		t1=f(i);
		t2=f(i-1);
		temp=(1-t1*t2)*2000;
		ans+=temp;
	}
	t1=f(0);
	t2=f(n-1);
	temp=(1-t1*t2)*2000;
	ans+=temp;
	printf("%.1Lf",ans);
	return 0;
}


#include <iostream>
#include <ctime>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define ll long long
#define ld long double
ll n,p;
ll arr[100005][2];
ld temp,ans;
ld f(ll i){
	return static_cast<ld>(arr[i][1]-arr[i][0]+1-arr[i][1]/p+(arr[i][0]-1)/p)/(arr[i][1]-arr[i][0]+1);
}
int main(){
	scanf("%lld%lld",&n,&p);
	for(int i=0; i<n; i++) scanf("%lld%lld",&arr[i][0],&arr[i][1]);
	for(int i=1; i<n; i++){
		temp=(1-f(i)*f(i-1))*2000;
		ans+=temp;
	}
	temp=(1-f(0)*f(n-1))*2000;
	ans+=temp;
	printf("%Lf",ans);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define MAX 100100
#define S 220
#define M 60
#define EIGHT 8
#define inf 1000000000
#define fora(n) for (int i=0;i<n;++i)
#define ford(n) for (int i=n-1;i>=0;--i)
#define FORA(i,n) for (i;i<n;++i)
#define FORD(i,n) for (i;i>=0;--i)
#define pb push_back
#define pii pair <int, int>
#define eps 0.0000000001
#include <iostream>
#include <algorithm>
#include <time.h>
#include <vector>
#include <set>
#include <string>
#include <iomanip>
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned char uc;
typedef unsigned short us;
typedef long double ld;
using namespace std;

ull P[MAX];
ull down[MAX];
ld MO[MAX];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//	cout << fixed << setprecision(8);

	int n, k;
	cin >> n >> k;

	fora(n) {
		int a, b;
		cin >> a >> b;

		int full = b - a + 1;

		if (a%k)
			a += (k - a % k);
		if (a > b) {
			continue;
		}
		if (b%k)
			b -= (k - b % k);

		int good = (b - a) / k;
		++good;

		P[i] = good;
		down[i] = full;
	}

	ld ans=0;
	for (int i = 1; i < n; ++i) {
		ans += ld(P[i]*down[i-1] + P[i-1]*down[i]-P[i]*P[i-1])/(down[i]*down[i-1]);
	}
	ans += ld(P[0] * down[n - 1] + P[n - 1] * down[0] - P[0] * P[n - 1]) / (down[0] * down[n - 1]);

	cout << ans * 2000;

	return 0;
}

/* Fri Jul 19 2019 13:52:42 GMT+0300 (MSK) */


#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iomanip>

using namespace std;

typedef pair<int, int> P;
typedef long double ld;
typedef long long ll;
int main()
{
	int n;
	int  p;
	cin >> n >> p;
	vector<P> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i].first >> arr[i].second;
	}

	vector<int> mas(n, 0);
	for (int i = 0; i < n; i++) {
		int z = 1;
		ll L = arr[i].first; ll R = arr[i].second;
		ll l0 = L + ((p - (L % p)) % p);
		ll r0 = R - (R % p);
		if (l0 > r0) mas[i] = 0;
		else {
			mas[i] = (r0 - l0) / p + 1;
		}
	}
	cout << fixed << setprecision(8);
	ld res = 0;
	for (int i = 1; i < n; i++) {
		ld  a = mas[i - 1]; ld b = mas[i]; ld r1 = arr[i - 1].second - arr[i - 1].first + 1; ld r2 = arr[i].second - arr[i].first + 1;
		res += (a*r2 + b * r1 - a * b) / (r1 * r2) * 2000;
	}
	ld  a = mas[0]; ld b = mas[n - 1]; ld r1 = arr[0].second - arr[0].first + 1; ld r2 = arr[n - 1].second - arr[n - 1].first + 1;
	res += (a*r2 + b * r1 - a * b) / (r1 * r2) * 2000;
	cout << res;
	//system("pause");
	return 0;
}

/* Fri Jul 19 2019 15:57:03 GMT+0300 (MSK) */


#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iomanip>

using namespace std;

typedef pair<int, int> P;
typedef long double ld;
typedef long long ll;
int main()
{
	int n;
	int p;
	cin >> n >> p;
	vector<P> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i].first >> arr[i].second;
	}
	ld count = 0;
	vector<int> mas(n, 0);
	ld res = 0;
	for (int i = 0; i < n; i++) {
		int z = 1;
		for (int j = arr[i].first; j <= arr[i].second; j += z) {
			if (j % p == 0) {
				mas[i]++;
				z = p;
			}
		}
		if (i > 0) {
			ld  a = mas[i - 1]; ld b = mas[i]; ld r1 = arr[i - 1].second - arr[i - 1].first + 1; ld r2 = arr[i].second - arr[i].first + 1;
			res += (a*r2 + b * r1 - a * b) / (r1 * r2) * 2000;
		}
	}
	cout << fixed << setprecision(8);
	ld  a = mas[0]; ld b = mas[n - 1]; ld r1 = arr[0].second - arr[0].first + 1; ld r2 = arr[n - 1].second - arr[n - 1].first + 1;
	res += (a*r2 + b * r1 - a * b) / (r1 * r2) * 2000;
	cout << res;
	//system("pause");
	return 0;
}
/* Fri Jul 19 2019 15:01:30 GMT+0300 (MSK) */


#include <iostream>
#include <algorithm>
#include <time.h>

using namespace std;

struct ak
{
	int l, r;
	int k;
};

ak mas[100005];
double rez[100005];

int main()
{
	int n, p, nd;
	int k = 0;

	scanf_s("%d%d", &n, &p);

	for (int i = 0; i < n; i++)
	{
		scanf_s("%d%d", &mas[i].l, &mas[i].r);

		mas[i].k = mas[i].r / p - (mas[i].l - 1) / p;
	}

	double R = 0;

	for (int i = 0; i < n; i++)
	{
		if (i != n - 1) R += double(mas[i].k*(mas[i].r - mas[i].l + 1) + mas[i + 1].k * (mas[i + 1].r - mas[i + 1].l + 1) - mas[i + 1].k*mas[i].k)/((mas[i].r - mas[i].l + 1)*(mas[i + 1].r - mas[i + 1].l + 1));
		else R += double(mas[i].k*(mas[i].r - mas[i].l + 1) + mas[0].k * (mas[0].r - mas[0].l + 1) - mas[0].k*mas[i].k) / ((mas[i].r - mas[i].l + 1)*(mas[0].r - mas[0].l + 1));
	}

	printf("%.10lf", R*2000);

	return 0;
}
/* Fri Jul 19 2019 17:06:31 GMT+0300 (MSK) */


#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iomanip>

using namespace std;

typedef pair<int, int> P;
typedef long double ld;
typedef long long ll;
int main()
{
	int n;
	int  p;
	cin >> n >> p;
	vector<P> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i].first >> arr[i].second;
	}
	ld count = 0;
	vector<int> mas(n, 0);
	for (int i = 0; i < n; i++) {
		int z = 1;
		for (int j = arr[i].first; j <= arr[i].second; j += z) {
			if (j % p == 0) {
				mas[i]++;
				z = p;
			}
			count += mas[i];
		}
	}
	cout << fixed << setprecision(8);
	ld res = 0;
	for (int i = 1; i < n; i++) {
		ld  a = mas[i - 1]; ld b = mas[i]; ld r1 = arr[i - 1].second - arr[i - 1].first + 1; ld r2 = arr[i].second - arr[i].first + 1;
		res += (a*r2 + b*r1 - a*b) / (r1 * r2) * 2000;
		//count /= (arr[i].second - arr[i].first + arr[i - 1].second - arr[i - 1].first);
	}
	ld  a = mas[0]; ld b = mas[n - 1]; ld r1 = arr[0].second - arr[0].first + 1; ld r2 = arr[n - 1].second - arr[n - 1].first + 1;
	res += (a*r2 + b * r1 - a * b) / (r1 * r2) * 2000;
	//count *= 2000 * n;
	cout << res;
	//system("pause");
	return 0;
}
/* Fri Jul 19 2019 14:51:00 GMT+0300 (MSK) */


#define _CRT_SECURE_NO_WARNINGS
#define MAX 100100
#define S 220
#define M 60
#define EIGHT 8
#define inf 1000000007
#define fora(n) for (int i=0;i<n;++i)
#define ford(n) for (int i=n-1;i>=0;--i)
#define FORA(i,n) for (i;i<n;++i)
#define FORD(i,n) for (i;i>=0;--i)
#define pb push_back
#define pii pair <int, int>
#define eps 0.0000000001
#include <iostream>
#include <algorithm>
#include <time.h>
#include <vector>
#include <set>
#include <string>
#include <iomanip>
typedef unsigned long long ll;
typedef long long ull;
typedef unsigned char uc;
typedef unsigned short us;
typedef long double ld;
using namespace std;

int n, k;

ll mas[MAX][2];

int p[MAX][2];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cout << fixed << setprecision(18);

	cin >> n >> k;

	fora(n) {
		int l, r;
		cin >> l >> r;

		mas[i][0] = (r / k) - ((l - 1) / k);
		mas[i][1] = (r - l + 1);
	}

	ld ans = 0;
	for (int i = 1; i < n; ++i) {
		ll up = mas[i][0] * mas[i - 1][1] + mas[i - 1][0] * mas[i][1] - mas[i][0] * mas[i - 1][0];
		ll down = mas[i][1] * mas[i - 1][1];
		ans += ld(up) / down;
	}

	ll up = mas[0][0] * mas[n - 1][1] + mas[n - 1][0] * mas[0][1] - mas[0][0] * mas[n - 1][0];
	ll down = mas[0][1] * mas[n - 1][1];
	ans += ld(up) / down;

	cout << ans * 2000;

	return 0;
}

/* Fri Jul 19 2019 15:52:15 GMT+0300 (MSK) */


#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iomanip>

using namespace std;

typedef pair<int, int> P;
typedef long double ld;
typedef long long ll;
int main()
{
	int n;
	int  p;
	cin >> n >> p;
	vector<P> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i].first >> arr[i].second;
	}
	ld count = 0;
	vector<int> mas(n, 0);
	for (int i = 0; i < n; i++) {
		int z = 1;
		for (int j = arr[i].first; j <= arr[i].second; j += z) {
			if (j % p == 0) {
				mas[i]++;
				z = p;
			}
			count += mas[i];
		}
	}
	cout << fixed << setprecision(8);
	ld res = 0;
	for (int i = 1; i < n; i++) {
		//res += ((ld)(mas[i] + mas[i - 1])) / (arr[i].second - arr[i].first + arr[i-1].second - arr[i-1].first) * 2000;
		count /= (arr[i].second - arr[i].first + arr[i - 1].second - arr[i - 1].first);
	}
	//res += ((ld)(mas[0] + mas[n - 1])) / (arr[0].second - arr[0].first + arr[n - 1].second - arr[n - 1].first) * 2000;
	count *= 2000 * n;
	cout << count;
	//system("pause");
	return 0;
}
/* Fri Jul 19 2019 12:35:34 GMT+0300 (MSK) */


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <numeric>

#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define vs vector<string>
#define endl '\n'
#define pb push_back
//#define int long long

using namespace std;

int p;

ll near(ll l,ll r) {
	if ((l % p == 0) || (r >= (l + (p - l % p)))) {
		if (l % p != 0) {
			l = l + (p - l % p);
		}
		if (r % p != 0) {
			r = r - r % p;
		}
		return (r - l) / p + 1;
	}
	else {
		return 0;
	}
}

int main() {
	int n;
	cin >> n >> p;
	vector<int> l(n), r(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i] >> r[i];
	}
	l.pb(l[0]);
	r.pb(r[0]);
	double mat = 0;
	for (int i = 0; i < n; i++) {
		double kol1 = near(l[i],r[i]), kol2 = near(l[i+1],r[i+1]);
		double p1 = kol1 / (r[i] - l[i] + 1);
		double p2 = kol2 / (r[i+1] - l[i+1] + 1);
		mat += 2000*(1-(1-p1)*(1-p2));
	}
	cout.precision(12);
	cout.fixed;
	cout << mat;
	return 0;
}
/* Fri Jul 19 2019 11:35:40 GMT+0300 (MSK) */


#define _CRT_SECURE_NO_WARNINGS
#define MAX 100100
#define S 220
#define M 60
#define EIGHT 8
#define inf 1000000000
#define fora(n) for (int i=0;i<n;++i)
#define ford(n) for (int i=n-1;i>=0;--i)
#define FORA(i,n) for (i;i<n;++i)
#define FORD(i,n) for (i;i>=0;--i)
#define pb push_back
#define pii pair <int, int>
#define eps 0.0000000001
#include <iostream>
#include <algorithm>
#include <time.h>
#include <vector>
#include <set>
#include <string>
#include <iomanip>
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned char uc;
typedef unsigned short us;
typedef long double ld;
using namespace std;

ull P[MAX];
ull down[MAX];
ld MO[MAX];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//	cout << fixed << setprecision(8);

	int n, k;
	cin >> n >> k;

	fora(n) {
		int a, b;
		cin >> a >> b;

		int full = b - a + 1;

		if (a%k)
			a += (k - a % k);
		if (a > b) {
			down[i] = full;
			continue;
		}
		if (b%k)
			b -= (k - b % k);

		int good = (b - a) / k;
		++good;

		P[i] = good;
		down[i] = full;
	}

	ld ans=0;
	for (int i = 1; i < n; ++i) {
		ans += ld(P[i]*down[i-1] + P[i-1]*down[i]-P[i]*P[i-1])/(down[i]*down[i-1]);
	}
	ans += ld(P[0] * down[n - 1] + P[n - 1] * down[0] - P[0] * P[n - 1]) / (down[0] * down[n - 1]);

	cout << ans * 2000;

	return 0;
}

/* Fri Jul 19 2019 13:54:00 GMT+0300 (MSK) */


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<time.h>
#include<queue>
#include<map>
#include<limits.h>

#define vi vector<int>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;

#define fast  std :: ios :: sync_with_stdio ( false )
#define pi 3.141592653589793238462643383279
#define rad 57.295779513082323
#define am &
#define sc scanf
#define scd(i) scanf("%d",am i)
#define pr printf
#define mp make_pair
#define poo(i,a,b) for(ll i=a;i<=b;i++)
#define oop(i,a,b) for(ll i=a;i>=b;i--)
using namespace std;
const int mod = 1e9 + 7;
int safe_mul(int x, int y)
{
	return x * (ll)1 * y % mod;
}
int safe_exp(int x, int y)
{
	int rez = 1;
	for (; y > 0; y >>= 1)
	{
		if (y & 1)
			rez = safe_mul(rez, x);
		x = safe_mul(x, x);
	}
	return rez;
}
ll gcd(ll a, ll b)
{
	while (a != 0 && b != 0)
	{
		if (a > b)
			a %= b;
		else
			b %= a;
	}
	return a + b;
}
/*int main()
{
	int a, b, c, d;
	double chance=0,h;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	h =(double) a / b;
	while (h >= (1 / 1e12))
	{
		chance += h;
		h *= (double)a / b * c / d;
	}
	printf("%.12f", chance);
	return 0;
}*/
int main()
{
	int modd, n,minn,maxx,bminn,bmaxx,tmp,tmp1;
	double k[100000] = {0};
	double money = 0;
	scd(n);
	scd(modd);
	for (int i = 0; i < n; i++)
	{
		scd(minn);
		scd(maxx);
		tmp1 = maxx - minn + 1;
		bminn = (modd-(minn % modd))%modd;
		bmaxx = maxx % modd;
		maxx -= bmaxx;
		minn += bminn;
		if (maxx < minn)k[i] = 0;
		else
		{
			tmp = maxx - minn;
			k[i] = ((double)tmp / modd + 1)/tmp1;
		}
	}
	money += k[0] * (2 - k[n - 1] - k[1]) + k[1] + k[n - 1];
	money += k[n-1] * (2 - k[n - 2] - k[0]) + k[0] + k[n - 2];
	for (int i = 1; i < n-1; i++)
	{
		money += k[i] * (2 - k[i - 1] - k[i + 1]) + k[i - 1] + k[i + 1];
	}
	money *= 1000;
	printf("%.12f", money);
	return 0;
}

/* Fri Jul 19 2019 11:46:38 GMT+0300 (MSK) */


#define _CRT_SECURE_NO_WARNINGS
#define MAX 100100
#define S 220
#define M 60
#define EIGHT 8
#define inf 1000000000
#define fora(n) for (int i=0;i<n;++i)
#define ford(n) for (int i=n-1;i>=0;--i)
#define FORA(i,n) for (i;i<n;++i)
#define FORD(i,n) for (i;i>=0;--i)
#define pb push_back
#define pii pair <int, int>
#define eps 0.0000000001
#include <iostream>
#include <algorithm>
#include <time.h>
#include <vector>
#include <set>
#include <string>
#include <iomanip>
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned char uc;
typedef unsigned short us;
typedef long double ld;
using namespace std;

ld P[MAX];
ld MO[MAX];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
//	cout << fixed << setprecision(8);

	int n, k;
	cin >> n >> k;

	fora(n) {
		int a, b;
		cin >> a >> b;

		int full = b - a + 1;

		if (a%k)
		a += (k - a % k);
		if (a > b) {
			continue;
		}
		if (b%k)
		b -= (k - b % k);

		int good = (b - a) / k;
		++good;

		P[i] = ld(good) / full;
	}

	ld ans = 0;
	for (int i = 1; i < n; ++i) {
		ans+= (P[i]+P[i-1]-P[i]*P[i-1]);
	}
	ans += (P[0] + P[n - 1] - P[0] * P[n - 1]);

	cout << ans * 2000;

	return 0;
}


#include <iostream>
#include <algorithm>
#include <time.h>

using namespace std;

struct ak
{
	int l, r;
	long long k;
};

ak mas[100005];
double rez[100005];

int main()
{
	int n, p, nd;
	int k = 0;

	scanf_s("%d%d", &n, &p);

	for (int i = 0; i < n; i++)
	{
		scanf_s("%d%d", &mas[i].l, &mas[i].r);

		mas[i].k = mas[i].r / p - (mas[i].l - 1) / p;
	}

	double R = 0;

	for (int i = 0; i < n; i++)
	{
		long long t1, t2;

		if (i != n - 1)
		{
			t1 = mas[i].r - mas[i].l + 1;
			t2 = mas[i + 1].r - mas[i + 1].l + 1;
			R += (double)(mas[i].k*t2 + mas[i + 1].k*t1 - mas[i].k*mas[i + 1].k) / (t1*t2);
		}
		else
		{
			t1 = mas[i].r - mas[i].l + 1;
			t2 = mas[0].r - mas[0].l + 1;
			R += (double)(mas[i].k*t2 + mas[0].k*t1 - mas[i].k*mas[0].k) / (t1*t2);
		}
	}

	printf("%.10lf", R*2000);

	return 0;
}
/* Fri Jul 19 2019 17:20:40 GMT+0300 (MSK) */


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
#define int long long

signed main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(18);

	int n, p;
	cin >> n >> p;
	vector<int> l(n), r(n);
	for (int i = 0; i < n; ++i)
		cin >> l[i] >> r[i];
	double e = 0;
	for (int i = 0; i < n; ++i)
	{
		int next = (i + 1) % n;

		int a1 = r[i] / p;
		if (l[i] > p) a1 -= (l[i] - 1) / p;
		//a1 *= (r[next] - l[next] + 1);

		int a2 = r[next] / p;
		if (l[next] > p) a2 -= (l[next] - 1) / p;
		//a2 *= (r[i] - l[i] + 1);

		double numerator = a1 * a2 + a1 * (r[next] - l[next] + 1 - a2) + a2 * (r[i] - l[i] + 1 - a1);
		double denumerator = (r[i] - l[i] + 1) * (r[next] - l[next] + 1);
		double probability = numerator / denumerator;
		e += probability;
	}
	cout << e * 2000.0;
	return 0;
}
/* Fri Jul 19 2019 12:27:09 GMT+0300 (MSK) */


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(18);

	int n, p;
	cin >> n >> p;
	vector<int> l(n), r(n);
	for (int i = 0; i < n; ++i)
		cin >> l[i] >> r[i];
	double e = 0;
	for (int i = 0; i < n; ++i)
	{
		int next = (i + 1) % n;

		int a1 = r[i] / p;
		if (l[i] > p) a1 -= (l[i] - 1) / p;
		//a1 *= (r[next] - l[next] + 1);

		int a2 = r[next] / p;
		if (l[next] > p) a2 -= (l[next] - 1) / p;
		//a2 *= (r[i] - l[i] + 1);

		double numerator = a1 * a2 + a1 * (r[next] - l[next] + 1 - a2) + a2 * (r[i] - l[i] + 1 - a1);
		double denumerator = (r[i] - l[i] + 1) * (r[next] - l[next] + 1);
		double probability = numerator / denumerator;
		e += probability;
	}
	cout << e * 2000.0;
	return 0;
}
/* Fri Jul 19 2019 12:25:04 GMT+0300 (MSK) */


	#include <iostream>
	#include <vector>
	#include <iomanip>
	using namespace std;

	int n, p;

	vector<pair<int, int>> vec;
	vector<double> vec_d;

	int main()
	{
		cin >> n >> p;
		vec.resize(n);
		vec_d.resize(n);
		int t1, t2;

		for (int i = 0; i < n; i++)
		{
			cin >> t1 >> t2;
			vec[i].first = t1;
			vec[i].second = t2;
		}

		long long tt1, tt2;
		long long c1, c2;
		long long sum = 0;
		double ver = 0;
		for (int i = 0; i < n; i++)
		{
			tt1 = vec[i].second - vec[i].first + 1;
			tt2 = vec[(i + 1) % n].second - vec[(i + 1) % n].first + 1;
			c1 = vec[i].second / p - (vec[i].first - 1) / p;
			c2 = vec[(i + 1) % n].second / p - (vec[(i + 1) % n].first - 1) / p;

			sum = c1 * tt2 + tt1 * c2 - c1 * c2;
			ver = sum / (double)(tt1 * tt2);
			vec_d[i] += ver;
			vec_d[(i + 1) % n] += ver;
		}

		ver = 0;
		for (auto i : vec_d)
			ver += i;
		cout << fixed << setprecision(12) <<  ver * 1000;
		return 0;
	}
/* Fri Jul 19 2019 16:49:30 GMT+0300 (MSK) */


#define _CRT_SECURE_NO_WARNINGS
#include <numeric>
#include <functional>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>

using namespace std;

long long gcd(long long a, long long b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

long long lcm(long long  a, long long  b) {
	return a * b / gcd(a, b);
}

int main() {
	long long n, p, a, b;
	long double res = 0;
	cin >> n >> p;
	vector<pair<long long, long long>> v(n);
	for (int i = 0; i < n; ++i) {
		scanf("%lld%lld", &a, &b);
		v[i].first = b - a + 1;
		v[i].second = b / p - a / p + (a%p == 0);
	}
	for (int i = 1; i < n; ++i) {
		res += (long double)1.0 / v[i].first/ v[i - 1].first* 2000 * (v[i - 1].first*v[i].second + v[i].first*v[i - 1].second - v[i - 1].second*v[i].second);
	}
	res += (long double)1.0 / v[n - 1].first / v[0].first * 2000 * (v[0].first*v[n - 1].second + v[n - 1].first*v[0].second - v[0].second*v[n - 1].second);
	printf("%.10f", res);
	/*system("pause");*/
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <numeric>
#include <functional>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>

using namespace std;

long long gcd(long long a, long long b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

long long lcm(long long  a, long long  b) {
	return a * b / gcd(a, b);
}

int main() {
	int n, p, num, numprev, allnum = 1;
	double res = 0;
	cin >> n >> p;
	vector<pair<int, int>> v(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &v[i].first, &v[i].second);
		allnum *= v[i].second - v[i].first + 1;
	}
	numprev = v[0].second/ p - v[0].first/ p + (v[0].first % p ==0);
	for (int i = 1; i < n;++i) {
		num = v[i].second / p - v[i].first / p + (v[i].first % p == 0);
		res += (allnum / (v[i].second-v[i].first + 1)/ (v[i-1].second - v[i-1].first + 1)) *2000 * ((v[i-1].second - v[i-1].first+ 1)*num + (v[i].second-v[i].first + 1)*numprev - num * numprev);
		numprev = num;
	}
	numprev = v[0].second / p - v[0].first / p + (v[0].first % p == 0);
	res += (allnum / (v[n-1].second - v[n-1].first + 1) / (v[0].second - v[0].first + 1)) * 2000 * ((v[0].second - v[0].first + 1)*num + (v[n-1].second - v[n-1].first + 1)*numprev - num * numprev);
	res /= allnum;
	printf("%.10f", res);
	/*system("pause");*/
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <numeric>
#include <functional>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>

using namespace std;

long long gcd(long long a, long long b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

long long lcm(long long  a, long long  b) {
	return a * b / gcd(a, b);
}

int main() {
	long long n, p, a, b;
	long double res = 0;
	cin >> n >> p;
	vector<pair<long long, long long>> v(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &a, &b);
		v[i].first = b - a + 1;
		v[i].second = b / p - a / p + (a%p == 0);
	}
	for (int i = 1; i < n; ++i) {
		res += (long double)1.0 / v[i].second / v[i - 1].second * 2000 * (v[i - 1].first*v[i].second + v[i].first*v[i - 1].second - v[i - 1].second*v[i].second);
	}
	res += (long double)1.0 / v[n - 1].second / v[0].second * 2000 * (v[0].first*v[n - 1].second + v[n - 1].first*v[0].second - v[0].second*v[n - 1].second);
	printf("%.10f", res);
	/*system("pause");*/
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <numeric>
#include <functional>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>

using namespace std;

long long gcd(long long a, long long b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

long long lcm(long long  a, long long  b) {
	return a * b / gcd(a, b);
}

int main() {
	int n, p, num, numprev, allnum = 1;
	double res = 0;
	cin >> n >> p;
	vector<pair<int, int>> v(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &v[i].first, &v[i].second);
		allnum *= v[i].second - v[i].first + 1;
	}
	numprev = v[0].second/ p - v[0].first/ p + (v[0].first % p ==0);
	for (int i = 1; i < n;++i) {
		num = v[i].second / p - v[i].first / p + (v[i].first % p == 0);
		res += (1.0 / (v[i].second-v[i].first + 1)/ (v[i-1].second - v[i-1].first + 1)) *2000 * ((v[i-1].second - v[i-1].first+ 1)*num + (v[i].second-v[i].first + 1)*numprev - num * numprev);
		numprev = num;
	}
	numprev = v[0].second / p - v[0].first / p + (v[0].first % p == 0);
	res += (1.0 / (v[n-1].second - v[n-1].first + 1) / (v[0].second - v[0].first + 1)) * 2000 * ((v[0].second - v[0].first + 1)*num + (v[n-1].second - v[n-1].first + 1)*numprev - num * numprev);
	printf("%.10f", res);
	/*system("pause");*/
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <numeric>
#include <functional>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>

using namespace std;

long long gcd(long long a, long long b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

long long lcm(long long  a, long long  b) {
	return a * b / gcd(a, b);
}

int main() {
	int n, p, a, b;
	long double res = 0;
	cin >> n >> p;
	vector<pair<int, int>> v(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &a, &b);
		v[i].first = b - a + 1;
		v[i].second = b / p - a / p + (a%p == 0);
	}
	for (int i = 1; i < n; ++i) {
		res += (long double)1.0 / v[i].first/ v[i - 1].first* 2000 * (v[i - 1].first*v[i].second + v[i].first*v[i - 1].second - v[i - 1].second*v[i].second);
	}
	res += (long double)1.0 / v[n - 1].first / v[0].first * 2000 * (v[0].first*v[n - 1].second + v[n - 1].first*v[0].second - v[0].second*v[n - 1].second);
	printf("%.10f", res);
	/*system("pause");*/
	return 0;
}


#include<stdio.h>

int main()
{
	int n;
	int p;
	int i;
	int li,ri;
	double meigegailu[100000];
	double qiwan=0;
	scanf("%d %d",&n,&p);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&li,&ri);
		meigegailu[i]=(double)(ri/p-(li-1)/p)/(ri-li+1.0);
	}
	for(i=0;i<n;i++)
	{
		if(i<n-1)
			qiwan+=(1.0-(1.0-meigegailu[i])*(1.0-meigegailu[i+1]))*2000.0;
		else
			qiwan+=(1.0-(1.0-meigegailu[i])*(1.0-meigegailu[0]))*2000.0;
	}

	printf("%llf",qiwan);

	return 0;
}


#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

int n, p;

vector<pair<int, int>> vec;
vector<double> vec_d;

int main()
{
	cin >> n >> p;
	vec.resize(n);
	vec_d.resize(n);
	int t1, t2;

	for (int i = 0; i < n; i++)
	{
		cin >> t1 >> t2;
		vec[i].first = t1;
		vec[i].second = t2;
	}

	long long tt1, tt2;
	long long c1, c2;
	long long sum = 0;
	double ver = 0;
	for (int i = 0; i < n; i++)
	{
		tt1 = vec[i].second - vec[i].first + 1;
		tt2 = vec[(i + 1) % n].second - vec[(i + 1) % n].first + 1;
		c1 = vec[i].second / p - (vec[i].first - 1) / p;
		c2 = vec[(i + 1) % n].second / p - (vec[(i + 1) % n].first - 1) / p;

		sum = c1 * tt2 + tt1 * c2 - c1 * c2;
		ver = sum / (double)(tt1 * tt2);
		vec_d[i] += ver;
		vec_d[(i + 1) % n] += ver;
	}

	ver = 0;
	for (auto i : vec_d)
		ver += i;
	cout << fixed << setprecision(12) <<  ver * 1000;
	return 0;
}


#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

int n, p;

vector<pair<int, int>> vec;
vector<double> vec_d;

int main()
{
	cin >> n >> p;
	vec.resize(n);
	vec_d.resize(n);
	int t1, t2;

	for (int i = 0; i < n; i++)
	{
		cin >> t1 >> t2;
		vec[i].first = t1;
		vec[i].second = t2;
	}

	int c1, c2;
	int sum = 0;
	double ver = 0;
	for (int i = 0; i < n; i++)
	{
		t1 = vec[i].second - vec[i].first + 1;
		t2 = vec[(i + 1) % n].second - vec[(i + 1) % n].first + 1;
		c1 = vec[i].second / p - (vec[i].first - 1) / p;
		c2 = vec[(i + 1) % n].second / p - (vec[(i + 1) % n].first - 1) / p;

		sum = c1 * t2 + t1 * c2 - c1 * c2;
		ver = sum / (double)(t1 * t2);
		vec_d[i] += ver;
		vec_d[(i + 1) % n] += ver;
	}

	ver = 0;
	for (auto i : vec_d)
		ver += i;
	cout << fixed << setprecision(12) <<  ver * 1000;
	return 0;
}


#pragma comment(linker, "/STACK:128777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <queue>
using namespace std;

#define For(i, n) for (int i = 0; i < (n); ++i)
#define sz(v) (int)(v).size()
#define forx(_name,_from, to, value) for (int name = from; name < to; name += value)
#define rforx(_name, from, to, value) for (int name = from; name > to; name -= _value)
#define all(_STL_NAME) _STL_NAME.begin(), _STL_NAME.end()
#define rall(_STL_NAME) _STL_NAME.rbegin(), _STL_NAME.rend()
#define mp(_FIRST,_SECOND) make_pair(_FIRST,_SECOND)

typedef long long ll;
typedef long long lint;
typedef unsigned long long llu;
typedef long double ld;
const ld eps = 1e-9;
mt19937 rndm;

void start() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(7); cout.setf(ios::fixed);
	rndm.seed((unsigned int)time(0));
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

const int MAX_N = (int)2e5 + 10;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;

void solve()
{
	int n, p;
	cin >> n >> p;
	vector<pair <int, int>> bounds(n);
	for (int i = 0; i < n; ++i) {
		cin >> bounds[i].first >> bounds[i].second;
	}
	double ans = 0;
	for (int i = 0; i < n; ++i) {
		long long len1 = bounds[i].second - bounds[i].first + 1, len2 = bounds[(i + 1) % n].second - bounds[(i + 1) % n].first + 1;
		long long cnt1 = bounds[i].second / p - (bounds[i].first - 1) / p;
		long long cnt2 = bounds[(i + 1) % n].second / p - (bounds[(i + 1) % n].first - 1) / p;
		ans += ((double)(cnt1 * len2 + cnt2 * len1 - cnt1 * cnt2) / (double)(len1 * len2));
	}
	cout << ans * 2000.;
}

void multitest()
{
	int t;
	cin >> t;
	for (int i = 1; i <= t; i++)
	{
		solve();
	}
}

int main() {
	start();
	solve();
	//multitest();
#ifdef _DEBUG
	cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <map>
#include <cmath>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
using namespace std;
int main()
{
#ifdef _DEBUG
	FILE* fin = freopen("in.txt","rt", stdin);
#endif
	int n,p;
    scanf("%d %d",&n,&p);

    vector<pair<ll, ll> > v(n);

    vector<ll> cnt(n);

    FOR(i,0,n)
    {
        ll l, r;
        scanf("%I64d %I64d", &l, &r);
        v[i] = make_pair(l,r);
        cnt[i] = r/p - l/p;
        if (l%p == 0)
            cnt[i]++;
    }

    double ret = 0;
    FOR(i,1,n)
    {
        ll sum = 0;
        if (cnt[i-1] != 0)
            sum += cnt[i-1] * (v[i].second - v[i].first + 1);
        if (cnt[i] != 0)
            sum += cnt[i] * (v[i-1].second - v[i-1].first + 1);
        sum-= cnt[i-1] * cnt[i];
        ret += (double)sum / ((v[i].second - v[i].first + 1) * (v[i-1].second - v[i-1].first + 1));
    }

    ll sum = 0;
    if (cnt[0] != 0)
        sum += cnt[0] * (v[n-1].second - v[n-1].first + 1);
    if (cnt[n-1]!= 0)
        sum += cnt[n-1] * (v[0].second - v[0].first + 1);
    sum -= cnt[0] * cnt[n-1];
    ret += (double)sum / ((v[n-1].second - v[n-1].first + 1) * (v[0].second - v[0].first + 1));

    printf("%.8lf\n", ret * 2000);

#ifdef _DEBUG
	fclose(fin);
#endif
	return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <iomanip>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

#define MAX 100001

using namespace std;

int n, p;
long double c[MAX], d[MAX];
long double a = 0, b = 0;

int main()
{
	cin >> n >> p;

	int l, r;
	for (int i = 0; i<n; i++) {
		cin >> l >> r;

		c[i] = r / p - (l - 1) / p;
		d[i] = r - l + 1;
	}

	long double result = 0;
	for (int i = 0; i < n; i++) {
		a = c[i] * d[(i + 1) % n] + c[(i + 1) % n] * (d[i] - c[i]);
		b = d[i] * d[(i + 1) % n];
		result += 2000.0 * a / b;
	}

	printf("%.6Lf\n", result);

	return 0;
}


//////// Kelvin 2016
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <unordered_map>
#include <complex>
#include <ctime>
#include <fstream>
#include <sstream>
//#include <windows.h>
//#include <stdint.h>
using namespace std;
const double PI = (acos(-1.0));
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
#define forn(i,s,n) i = (s); for( int _n = (int)(n), _di = (i > _n)?-1:1; i != _n; i += _di)
#define foreach(it,c) for ( auto it = (c).begin(); it!=(c).end(); it++)
#define endl '\n'

template<typename T> struct Point
{
	T x, y;
	Point(T ix = 0, T iy = 0):x(ix),y(iy){}
	Point& operator -= (const Point &b){ x -= b.x; y -= b.y; return *this; }
	Point operator - (const Point &b){ Point res = *this; res -= b; return res; }

	friend T dot(const Point &a, const Point &b) //|a||b|cosθ // 0 90 180 270 360 //x
	{														  // 1  0  -1  0  1
		return a.x*b.x + a.y*b.y;
	}
	friend T cross(const Point &a, const Point &b)  //|a||b|sinθ // 0 90 180 270 360 //y
	{															 // 0  1  0  -1  0
		return a.x*b.y - a.y*b.x;
	}
	friend double dist(const Point &a)
	{
		return sqrt(double(a.x*a.x + a.y*a.y));
	}
	friend T sdist(const Point &a)
	{
		return a.x*a.x + a.y*a.y;
	}
	bool operator < (const Point &b)
	{
		const Point &a = *this;
		bool ka = a.y<0 || a.y==0 && a.x<0;
		bool kb = b.y<0 || b.y==0 && b.x<0;
		return  ka < kb || ka==kb && cross(a, b)>0;
	}
	Point& operator *= (const Point &b)  //yg = yb - ya
	{
		T tx = dot(*this, b);
		y = cross(*this, b);
		x = tx; return *this;
	}
	Point operator * (const Point &b){ Point res = *this; res *= b; return res; }
};

typedef Point<int> point;

int main()
{
	int n,i,p, l, r;
	cin>>n>>p;
	double *ver = new double[n];
	forn(i,0,n)
	{
		cin>>l>>r;
		if(l>r) swap(l,r);
		ver[i] = double(r/p - (l-1)/p)/double(r-l+1);
	}

	double summ = 0;

	forn(i,0,n)
	{
		l = i-1; if(l<0) l+= n;
		r = i+1; if(r>=n) r-= n;
		summ += 2000.0 * (ver[i] + (1.0-ver[i]) * ver[l] * ver[r]);
		summ += 1000.0 * (1.0-ver[i]) * (ver[l] * (1.0 - ver[r]) + (1.0 - ver[l]) * ver[r]);
	}

	cout<<setprecision(16)<<summ<<endl;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <ctime>

using namespace std;

#define ll long long
#define sc second
#define fs first
#define mp make_pair

const int N = 1e5 + 10;
template<class T> T sqr(T x) { return x*x; }

ll n, p, l[2 * N], r[2 * N], all = 0, good = 0;

ll cnt(double a, double b)
{
	return a / (double)p - (b-1) / (double)p;
}

int main()
{
	cin >> n >> p;
	for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
	l[n] = l[0], r[n] = r[0];
	long double ans = 0;
	for (int i = 0; i < n; i++)
	{
		long double a1 = ((double)(r[i] - l[i] + 1 - cnt(r[i], l[i])) / double(r[i] - l[i] + 1));
		long double a2 = ((double)(r[i + 1] - l[i + 1] + 1 - cnt(r[i + 1], l[i + 1])) / double(r[i + 1] - l[i + 1] + 1));
		ans += 1.0 - a1*a2;
	}
	cout << 2*ans*1000;
	return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <ctime>

using namespace std;

#define ll long long
#define sc second
#define fs first
#define mp make_pair

const int N = 1e5 + 10;
template<class T> T sqr(T x) { return x*x; }

ll n, p, l[2 * N], r[2 * N], all = 0, good = 0;

ll cnt(ll a, ll b)
{
	return (a /p) - ((b-1) /p);
}

int main()
{
	cin >> n >> p;
	for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
	l[n] = l[0], r[n] = r[0];
	long double ans = 0;
	for (int i = 0; i < n; i++)
	{
		long double a1 = ((double)(r[i] - l[i] + 1 - cnt(r[i], l[i])) / double(r[i] - l[i] + 1));
		long double a2 = ((double)(r[i + 1] - l[i + 1] + 1 - cnt(r[i + 1], l[i + 1])) / double(r[i + 1] - l[i + 1] + 1));
		ans += 1.0 - a1*a2;
	}
	printf("%.9f", 2*ans*1000);
	return 0;
}


#include <stdio.h>
#include <algorithm>

using namespace std;

const int MAXN = 1E5+10;
struct folwer {
    long long l;
    long long r;
    long long cnt_of_multiple_to_p;
    long long all;
} a[MAXN];

int main() {
    int n;
    long long p;
    scanf("%d%lld", &n, &p);
    for (int i = 0; i < n; i++) {
        scanf("%lld%lld", &a[i].l, &a[i].r);
    }
    double ans = 0;
    for (int i = 0; i < n; i++) {
        a[i].all = a[i].r - a[i].l + 1;

        if (a[i].l % p != 0) a[i].l += p-a[i].l%p;
        a[i].r -= a[i].r%p;
        if (a[i].l <= a[i].r) {
            a[i].cnt_of_multiple_to_p = (a[i].r - a[i].l)/p+1;
        }
    }
    for (int i = 0; i < n-1; i++) {
        double cur_expected_value = a[i].cnt_of_multiple_to_p * a[i+1].all + a[i+1].cnt_of_multiple_to_p * a[i].all - a[i].cnt_of_multiple_to_p * a[i+1].cnt_of_multiple_to_p;
        cur_expected_value /= (a[i].all * a[i+1].all);
        cur_expected_value *= 2000;
        ans += cur_expected_value;
    }
    double cur_expected_value = a[0].cnt_of_multiple_to_p * a[n-1].all + a[n-1].cnt_of_multiple_to_p * a[0].all - a[0].cnt_of_multiple_to_p * a[n-1].cnt_of_multiple_to_p;
    cur_expected_value /= (a[0].all * a[n-1].all);
    cur_expected_value *= 2000;
    ans += cur_expected_value;
    printf("%.7lf\n", ans);
    return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<set>
#include<cstdio>
#include<map>
#include<unordered_map>
#include<ctime>
#include<deque>
#include<cmath>
#include<queue>
#include<vector>
#include<bitset>
#include<stack>
#include<sstream>
#include<algorithm>
typedef double db;
typedef long long ll;
using namespace std;

int main(){
	ll n, p1, p2;
	db p, ans=0, a, b;
	scanf("%I64d%lf", &n, &p);
	vector<db> l(n), r(n);
	for(int i=0; i<n; i++)
		scanf("%lf%lf", &l[i], &r[i]);
	l.push_back(l[0]); r.push_back(r[0]);
	for(int i=0; i<n; i++){
		a=r[i]-l[i]+1;
		b=r[i+1]-l[i+1]+1;
		p1=max(0ll, (ll)(floor(r[i]/p)-ceil(l[i]/p)+1));
		p2=max(0ll, (ll)(floor(r[i+1]/p)-ceil(l[i+1]/p)+1));
		ans+=2000.0*db(p1*b+p2*a-p1*p2)/(a*b);
	}
	printf("%.10f", ans);
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <limits>

typedef std::numeric_limits< double > dbl;
using namespace std;

int count_div(int l, int r, int p)
{
  int res = r/p - l/p + (l%p?0:1);
  return res;
}
int main()
{
#ifdef MY_DEBUG
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif

  int n = 0, p = 0;
  cin >> n >> p;
  vector<int> l(n), r(n);
  for(int i = 0; i < n; i++)
  {
    cin >> l[i] >> r[i];
  }

  double res = 0.0;
  unsigned long long a = 0, b = 0;
  vector<double> pr(n);
  for(int i = 0; i < n; i++)
  {
    pr[i] = double(count_div(l[i], r[i], p))/double(r[i]-l[i]+1);
  }

  for(int i = 0; i < n-1; i++)
  {
    res += pr[i] + pr[i+1] - pr[i]*pr[i+1];
  }
  res += pr[n-1] + pr[0] - pr[n-1]*pr[0];
  cout.precision(dbl::max_digits10);
  cout << res*2000;

  return 0;
}


#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, char* argv[])
{
    int n, pp, l[100000], r[100000];
    double a[100000];
    scanf_s("%d%d", &n, &pp);
    double p = (double)pp;
    for (int i = 0; i < n; i++)
    {
        scanf_s("%d%d", &l[i], &r[i]);
        //a[i] - ���������� �����, ������� ������� �� p �� ������� l[i],r[i]
        a[i] = (double)r[i]/p - (l[i]-1.0)/p;
    }
    /*
        ���������� �����, ������� �� ������� �� p ������� l[i],r[i]   r[i] - l[i] + 1 - a[i]
        �����������, ��� ����� �� ������� �� p (r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1)
        �����������, ��� ������������ ������� �� ������� �� p:
        (r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1) * (r[j] - l[j] + 1 - a[j])/(r[j] - l[j] + 1)
        �����������, ��� ������������ ������� ������� �� p:
        1 - ((r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1) * (r[j] - l[j] + 1 - a[j])/(r[j] - l[j] + 1))
    */
    double total = 0.0;
    for (int i = 0; i < n; i++)
    {
        int j = (i == n-1)?1:(i+1);
        total += 1.0 - ((r[i]-l[i]+1.0- a[i])/(r[i]-l[i]+1.0) * (r[j]-l[j]+1.0- a[j])/(r[j]-l[j]+1.0));
    }
    cout << total*2.0*1000.0;//������ �� 2-� ���� �� 1000
    return 0;
}
/*
� ���������� � ������ ����� ��������� n ����, ������� �� ������� ������.
����� �������, �������� �������� ����� � �������� i � i+1 ��� ���� i �� 1 �� n-1, � ��� �� ����� � �������� 1 � n.

������ ����� � ������� ��� �������� ��������� ���������� ������� s_i � ����� ����� �� l_i �� r_i,
��� ���� ��� �������� �������������. � ������ ����� ���� ������� ������� ����� p, �� �������� �� ���������� ��� ���!
���� ��� �����-�� ���� �������� ���� i � j ������������ ���������� ���������� ��� ������� s_i*s_j ������� �� p,
�� ������ ����� �������� � ��� ������ �� ���� ���� �� 1000 ������.

� ����� ��� ����� ���������� ������ � ���������� ��� ���������� �����. ��������� �������������� �������� ����� ����������.

-- ������� ������
� ������ ������ ������� ������ �������� ����� ����� n � p (3 <= n <= 100000, 2 <= p <= 10^9) � ���������� ���� �
������� ������� ����� ������ ����� ��������������. �������������, ��� p �������� ������� ������.

������ �� ����������� n ����� �������� �������� ����� �����.
� i �� ��� �������� ����� l_i � r_i (1 <= l_i <= r_i <= 10^9) � �������� ���������� ���������� ������, ���������� i-� ������.
�� ��������, ��� �������� ���������� ������ ���������� ������������� �� ���� �������, ������� �������.

�������� ������
�������� ������������ ������������ ����� � �������������� �������� ���������� ���������� ������, ������� ������� �����.
*/


#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
    int n, p, ll, rr;
    vector<int> a, l, r;
    scanf_s("%d%d", &n, &p);
    for (int i = 0; i < n; i++)
    {
        scanf_s("%d%d", &ll, &rr);
        //a[i] - ���������� �����, ������� ������� �� p �� ������� l[i],r[i]
        l.push_back(ll); r.push_back(rr);
        a.push_back((int)(rr/p) - (int)((ll-1)/p));
    }
    /*
        ���������� �����, ������� �� ������� �� p ������� l[i],r[i]   r[i] - l[i] + 1 - a[i]
        �����������, ��� ����� �� ������� �� p (r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1)
        �����������, ��� ������������ ������� �� ������� �� p:
        (r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1) * (r[j] - l[j] + 1 - a[j])/(r[j] - l[j] + 1)
        �����������, ��� ������������ ������� ������� �� p:
        1 - ((r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1) * (r[j] - l[j] + 1 - a[j])/(r[j] - l[j] + 1))
    */
    double total = 0.0;
    for (int i = 0; i < n; i++)
    {
        int j = (i == n-1)?0:(i+1);
        total += 1.0 - ((r[i]-l[i]+1.0- a[i])/(r[i]-l[i]+1.0) * (r[j]-l[j]+1.0- a[j])/(r[j]-l[j]+1.0));
    }
    cout << total*2.0*1000.0;//������ �� 2-� ���� �� 1000
    return 0;
}
/*
� ���������� � ������ ����� ��������� n ����, ������� �� ������� ������.
����� �������, �������� �������� ����� � �������� i � i+1 ��� ���� i �� 1 �� n-1, � ��� �� ����� � �������� 1 � n.

������ ����� � ������� ��� �������� ��������� ���������� ������� s_i � ����� ����� �� l_i �� r_i,
��� ���� ��� �������� �������������. � ������ ����� ���� ������� ������� ����� p, �� �������� �� ���������� ��� ���!
���� ��� �����-�� ���� �������� ���� i � j ������������ ���������� ���������� ��� ������� s_i*s_j ������� �� p,
�� ������ ����� �������� � ��� ������ �� ���� ���� �� 1000 ������.

� ����� ��� ����� ���������� ������ � ���������� ��� ���������� �����. ��������� �������������� �������� ����� ����������.

-- ������� ������
� ������ ������ ������� ������ �������� ����� ����� n � p (3 <= n <= 100000, 2 <= p <= 10^9) � ���������� ���� �
������� ������� ����� ������ ����� ��������������. �������������, ��� p �������� ������� ������.

������ �� ����������� n ����� �������� �������� ����� �����.
� i �� ��� �������� ����� l_i � r_i (1 <= l_i <= r_i <= 10^9) � �������� ���������� ���������� ������, ���������� i-� ������.
�� ��������, ��� �������� ���������� ������ ���������� ������������� �� ���� �������, ������� �������.

�������� ������
�������� ������������ ������������ ����� � �������������� �������� ���������� ���������� ������, ������� ������� �����.
*/


#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
    int n, p, ll, rr;
    vector<int> a, l, r;
    scanf_s("%d%d", &n, &p);
    for (int i = 0; i < n; i++)
    {
        scanf_s("%d%d", &ll, &rr);
        //a[i] - ���������� �����, ������� ������� �� p �� ������� l[i],r[i]
        l.push_back(ll); r.push_back(rr);
        a.push_back((int)(rr/p) - (int)((ll-1)/p));
    }
    /*
        ���������� �����, ������� �� ������� �� p ������� l[i],r[i]   r[i] - l[i] + 1 - a[i]
        �����������, ��� ����� �� ������� �� p (r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1)
        �����������, ��� ������������ ������� �� ������� �� p:
        (r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1) * (r[j] - l[j] + 1 - a[j])/(r[j] - l[j] + 1)
        �����������, ��� ������������ ������� ������� �� p:
        1 - ((r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1) * (r[j] - l[j] + 1 - a[j])/(r[j] - l[j] + 1))
    */
    double total = 0.0;
    for (int i = 0; i < n; i++)
    {
        int j = (i == n-1)?0:(i+1);
        total += 1.0 - ((r[i]-l[i]+1.0- a[i])/(r[i]-l[i]+1.0) * (r[j]-l[j]+1.0- a[j])/(r[j]-l[j]+1.0));
    }
    printf("%f", total*2.0*1000.0);//������ �� 2-� ���� �� 1000; ������ ��� e
    return 0;
}
/*
� ���������� � ������ ����� ��������� n ����, ������� �� ������� ������.
����� �������, �������� �������� ����� � �������� i � i+1 ��� ���� i �� 1 �� n-1, � ��� �� ����� � �������� 1 � n.

������ ����� � ������� ��� �������� ��������� ���������� ������� s_i � ����� ����� �� l_i �� r_i,
��� ���� ��� �������� �������������. � ������ ����� ���� ������� ������� ����� p, �� �������� �� ���������� ��� ���!
���� ��� �����-�� ���� �������� ���� i � j ������������ ���������� ���������� ��� ������� s_i*s_j ������� �� p,
�� ������ ����� �������� � ��� ������ �� ���� ���� �� 1000 ������.

� ����� ��� ����� ���������� ������ � ���������� ��� ���������� �����. ��������� �������������� �������� ����� ����������.

-- ������� ������
� ������ ������ ������� ������ �������� ����� ����� n � p (3 <= n <= 100000, 2 <= p <= 10^9) � ���������� ���� �
������� ������� ����� ������ ����� ��������������. �������������, ��� p �������� ������� ������.

������ �� ����������� n ����� �������� �������� ����� �����.
� i �� ��� �������� ����� l_i � r_i (1 <= l_i <= r_i <= 10^9) � �������� ���������� ���������� ������, ���������� i-� ������.
�� ��������, ��� �������� ���������� ������ ���������� ������������� �� ���� �������, ������� �������.

�������� ������
�������� ������������ ������������ ����� � �������������� �������� ���������� ���������� ������, ������� ������� �����.
*/


#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, char* argv[])
{
    int n, pp, l[100000], r[100000];
    double a[100000];
    scanf_s("%d%d", &n, &pp);
    double p = (double)pp;
    for (int i = 0; i < n; i++)
    {
        scanf_s("%d%d", &l[i], &r[i]);
        //a[i] - ���������� �����, ������� ������� �� p �� ������� l[i],r[i]
        a[i] = (double)r[i]/p - (l[i]-1.0)/p;
    }
    /*
        ���������� �����, ������� �� ������� �� p ������� l[i],r[i]   r[i] - l[i] + 1 - a[i]
        �����������, ��� ����� �� ������� �� p (r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1)
        �����������, ��� ������������ ������� �� ������� �� p:
        (r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1) * (r[j] - l[j] + 1 - a[j])/(r[j] - l[j] + 1)
        �����������, ��� ������������ ������� ������� �� p:
        1 - ((r[i] - l[i] + 1 - a[i])/(r[i] - l[i] + 1) * (r[j] - l[j] + 1 - a[j])/(r[j] - l[j] + 1))
    */
    double total = 0.0;
    for (int i = 0; i < n; i++)
    {
        int j = (i == n-1)?1:(i+1);
        total += 1.0 - ((r[i]-l[i]+1.0- a[i])/(r[i]-l[i]+1.0) * (r[j]-l[j]+1.0- a[j])/(r[j]-l[j]+1.0));
    }
    cout << total;
    return 0;
}
/*
� ���������� � ������ ����� ��������� n ����, ������� �� ������� ������.
����� �������, �������� �������� ����� � �������� i � i+1 ��� ���� i �� 1 �� n-1, � ��� �� ����� � �������� 1 � n.

������ ����� � ������� ��� �������� ��������� ���������� ������� s_i � ����� ����� �� l_i �� r_i,
��� ���� ��� �������� �������������. � ������ ����� ���� ������� ������� ����� p, �� �������� �� ���������� ��� ���!
���� ��� �����-�� ���� �������� ���� i � j ������������ ���������� ���������� ��� ������� s_i*s_j ������� �� p,
�� ������ ����� �������� � ��� ������ �� ���� ���� �� 1000 ������.

� ����� ��� ����� ���������� ������ � ���������� ��� ���������� �����. ��������� �������������� �������� ����� ����������.

-- ������� ������
� ������ ������ ������� ������ �������� ����� ����� n � p (3 <= n <= 100000, 2 <= p <= 10^9) � ���������� ���� �
������� ������� ����� ������ ����� ��������������. �������������, ��� p �������� ������� ������.

������ �� ����������� n ����� �������� �������� ����� �����.
� i �� ��� �������� ����� l_i � r_i (1 <= l_i <= r_i <= 10^9) � �������� ���������� ���������� ������, ���������� i-� ������.
�� ��������, ��� �������� ���������� ������ ���������� ������������� �� ���� �������, ������� �������.

�������� ������
�������� ������������ ������������ ����� � �������������� �������� ���������� ���������� ������, ������� ������� �����.
*/


n, m = map(int, raw_input().split())
f = range(n+1)

def find(a):
	if f[a] != a: a = find(f[a])
	return f[a]

ans = 1
for i in xrange(m):
	a, b = map(lambda x: find(int(x)), raw_input().split())
	if a != b:	f[a] = b
	else: ans = ans * 2
	while (ans > 1000000009): ans -= 1000000009
	print(ans - 1)


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;
using System.Linq;
using System.Threading;

class Program
{
    int[] p;
    int[] rank;
    void solve()
    {
        int n = nextInt();
        int m = nextInt();
        long res = 1;
        p = new int[n];
        rank = new int[n];
        for (int i = 0; i < n; i++)
            p[i] = i;
        for (int i = 0; i < m; i++)
        {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            if (find(a) != find(b))
            {
                union(find(a), find(b));
            }
            else
                res = 2 * res % 1000000009;
            println((res - 1 + 1000000009) % 1000000009);
        }

    }

    private void union(int x, int y)
    {
        if (rank[x] >= rank[y])
        {
            p[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
        else
            p[x] = y;
    }

    private int find(int x)
    {
        if (x != p[x])
            p[x] = find(p[x]);
        return p[x];
    }

    ////////////
    private void println(int[] ar)
    {
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i]);
            else
                print(ar[i] + " ");
        }
    }
    private void println(int[] ar, bool add)
    {
        int A = 0;
        if (add)
            A++;
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i] + A);
            else
                print((ar[i] + A) + " ");
        }
    }

    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        string s = Doublenum.ToString(CultureInfo.InvariantCulture);
        Console.WriteLine(s);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        return int.Parse(nextString());
    }
    long nextLong()
    {
        return long.Parse(nextString());
    }
    double nextDouble()
    {
        return double.Parse(nextString());
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        new Program().solve();
    }
}