There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.

Each shark will grow some number of flowers s_{i}. For i-th shark value s_{i} is random integer equiprobably chosen in range from l_{i} to r_{i}. Wet Shark has it's favourite prime number p, and he really likes it! If for any pair of neighbouring sharks i and j the product s_{i}·s_{j} is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.

At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value.


-----Input-----

The first line of the input contains two space-separated integers n and p (3 ≤ n ≤ 100 000, 2 ≤ p ≤ 10^9) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime.

The i-th of the following n lines contains information about i-th shark — two space-separated integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 10^9), the range of flowers shark i can produce. Remember that s_{i} is chosen equiprobably among all integers from l_{i} to r_{i}, inclusive.


-----Output-----

Print a single real number — the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10^{ - 6}. 

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $\frac{|a - b|}{\operatorname{max}(1, b)} \leq 10^{-6}$.


-----Examples-----
Input
3 2
1 2
420 421
420420 420421

Output
4500.0

Input
3 5
1 4
2 3
11 14

Output
0.0



-----Note-----

A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.

Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (s_0, s_1, s_2) each shark grows: (1, 420, 420420): note that s_0·s_1 = 420, s_1·s_2 = 176576400, and s_2·s_0 = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars. (1, 420, 420421): now, the product s_2·s_0 is not divisible by 2. Therefore, sharks s_0 and s_2 will receive 1000 dollars, while shark s_1 will receive 2000. The total is 4000. (1, 421, 420420): total is 4000  (1, 421, 420421): total is 0.  (2, 420, 420420): total is 6000.  (2, 420, 420421): total is 6000.  (2, 421, 420420): total is 6000. (2, 421, 420421): total is 4000.

The expected value is $\frac{6000 + 4000 + 4000 + 0 + 6000 + 6000 + 6000 + 4000}{8} = 4500$.

In the second sample, no combination of quantities will garner the sharks any money.

Difficulty: interview

Starter code:

Solutions:
n,m=map(int,input().split())
def f():
	a,b=map(int,input().split())
	return(b//m-(a-1)//m)/(b-a+1)
a=[f() for _ in range(n)]
r=0
for i in range(n):
	r+=1-(1-a[i])*(1-a[(i+1)%n])
print(r*2000)

n, p = map(int, input().split())
L, R = [], []
for i in range(n):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
ans = 0
for i in range (n):
	l1, r1, l2, r2 = L[i], R[i], L[(i + 1) % n], R[(i + 1) % n]
	l_1, r_1, l_2, r_2 = L[i], R[i], L[(i + 1) % n], R[(i + 1) % n]
	if (l1 % p > 0):
		l1 += p - l1 % p
	if (l2 % p > 0):
		l2 += p - l2 % p
	r1 -= r1 % p
	r2 -= r2 % p
	#print(l1, r1, l2, r2)
	#print((r2 // p - l2 // p + 1) / (r_2 - l_2 + 1) + (r1 // p - l1 // p + 1) / (r_1 - l_1 + 1) - (r2 // p - l2 // p + 1) / (r_2 - l_2 + 1) * (r1 // p - l1 // p + 1) / (r_1 - l_1 + 1))
	ans += (2000 * (r2 // p - l2 // p + 1) / (r_2 - l_2 + 1) + 2000 * (r1 // p - l1 // p + 1) / (r_1 - l_1 + 1) - 2000 * (r2 // p - l2 // p + 1) / (r_2 - l_2 + 1) * (r1 // p - l1 // p + 1) / (r_1 - l_1 + 1))
print(ans)

n, p = [int(i) for i in input().split()]
kek = [0] * n
lol = [0] * n
for i in range(n):
    l, r = [int(i) for i in input().split()]
    a = ((r // p + 1) * p - l // p * p) // p
    if l % p:
        a -= 1
    lol[i] = r - l + 1
    kek[i] = a
ans = 0
for i in range(n):
    t = (i + 1) % n
    ans += ((kek[i] * (lol[t] - kek[t]) + kek[t] * (lol[i] - kek[i]) + kek[i] * kek[t]) * 2000) / (lol[i] * lol[t])
print(ans)

import re, sys, math, string, operator, functools, fractions, collections
sys.setrecursionlimit(10**7)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
RI=lambda: list(map(int,input().split()))
RS=lambda: input().rstrip().split()
mod=1e9+7
#################################################
n, p = RI()
sharks=[0]*n
for i in range(n):
    l,r=RI()
    tot=(math.floor(r/p)-math.ceil(l/p)+1)
    sharks[i]=1-tot/(r-l+1)
ans=0
for i in range(n):
    ans+=(1-(sharks[i])*(sharks[i-1]))
ans*=2000
print(ans)


n, p = [int(i) for i in input().split()]
s = []
q = [(0, 0)] * n
for i in range(n):
    l, r = [int(i) for i in input().split()]
    s.append((l, r))
for i in range(n):
    q[i] = ((s[i][1] - (s[i][1] % p) - ((s[i][0] + p - 1) // p) * p) // p + 1, s[i][1] - s[i][0] + 1)
sm = 0
for i in range(n):
    sm += (1 - ((q[i - 1][1] - q[i - 1][0]) / q[i - 1][1]) * ((q[i][1] - q[i][0]) / q[i][1])) * 2000
print(sm)

n, p = map(int, input().split())

prob = [0.0] * n

for i in range(n):
	l, r = map(int, input().split())
	prob[i] = 1.0 -  (r // p - (l - 1) // p) / (r - l + 1)

ans = 0.0
for i in range(n-1):
	ans += (1.0 - prob[i] * prob[i+1]) * 2000
ans += (1.0 - prob[n-1] * prob[0]) * 2000

print(ans)

n, p = list(map(int, input().split()))
e = []
for i in range(n):
    l, r = list(map(int, input().split()))
    L = -1
    R = 10 ** 9 + 7
    while L != R - 1:
        m = (L + R) // 2
        if m * p < l:
            L = m
        else:
            R = m
    col1 = R
    L = -1
    R = 10 ** 9 + 7
    while L != R - 1:
        m = (L + R) // 2
        if m * p <= r:
            L = m
        else:
            R = m
    col2 = R
    col = r - l + 1
    e.append(1 - (col2 - col1) / col)
sum = 0
for i in range(n):
    sum += 1000 * (1 - (e[i] * e[i - 1]))
print(sum * 2)

       
    
        


import math
from fractions import Fraction

n, p = [int(x) for x in input().split()]
exp_mean = 0
first_l, first_r = None, None
last_good, last_all = None, None

for i in range(n+1):
    l, r = None, None
    if i < n:
        l, r = [int(x) for x in input().split()]
        if first_l is None:
            first_l, first_r = l, r
    else:
        l, r = first_l, first_r

    upper = r // p
    lower = math.ceil(l / p)

    cur_good = upper - lower + 1
    cur_all = r - l + 1

    if last_good is not None:
        cur_mean = float(2000 * (cur_good * last_good + (cur_all - cur_good) *
                         last_good + (last_all - last_good) * cur_good) / (
                         cur_all * last_all))
        exp_mean += cur_mean

    last_good = cur_good
    last_all = cur_all

print(exp_mean)


n, p = [int(x) for x in input().split()]
segments = []
for i in range(n):
    segments.append(tuple(int(x) for x in input().split()))
divam = lambda p, s: (s[1] - s[0]) // p + (s[1]%p < s[0]%p or s[0]%p == 0)
def expectation(s1, s2):
    k1, k2 = divam(p, s1), divam(p, s2)
    n1, n2 = s1[1] - s1[0] + 1, s2[1] - s2[0] + 1
    return 2000 * (k1*n2 + k2*n1 - k1*k2) / (n1*n2)
print(sum(expectation(segments[i], segments[(i+1)%n]) for i in range(n)))


n,p = list(map(int,input().split()))

def count_divisors(a,b,p):
    x = b // p
    y = (a - 1) // p
    return x - y

arr = []

for i in range(n):
    a,b = list(map(int,input().split()))
    arr.append((count_divisors(a,b,p),b - a + 1))

ans = 0

for i in range(n - 1):
    a,b = arr[i][0],arr[i + 1][0]
    x,y = arr[i][1],arr[i + 1][1]
    ans += 1 - ((1 - a / x) * (1 - b / y))

a,b = arr[0][0],arr[-1][0]
x,y = arr[0][1],arr[-1][1]
ans += 1 - ((1 - a / x) * (1 - b / y))

# print(ans)

print(ans * 2000)


from math import floor,ceil
def mults(a,b,n):
    return max(floor(b/n)-ceil(a/n)+1,0)
def prob(a,b,n):
    return 1-(mults(a,b,n))/(b-a+1)
ans=0
n,p=(list(map(int,input().split())))
firststart,firstend=(list(map(int,input().split())))
prevstart=firststart
prevend=firstend
for i in range(1,n):
    nextstart,nextend=(list(map(int,input().split())))
    ans+=(1-prob(prevstart,prevend,p)*prob(nextstart,nextend,p))
    prevstart=nextstart
    prevend=nextend
ans+=1-prob(prevstart,prevend,p)*prob(firststart,firstend,p)
print(2000*ans)


n,p=list(map(int,input().split()))
z=1
a=[]
b=[]
for i in range(0,n):
    x,y=list(map(int,input().split()))
    a.append(int(y/p)-int((x-1)/p))
    b.append(y-x+1)
ans=0
for i in range (0,n):
    pz=a[(i+1)%n]
    z=b[(i+1)%n]
    py=a[i]
    y=b[i]
    px=a[(i-1+n)%n]
    x=b[(i-1+n)%n]
    ans+=((x*z*py*2000 + px*pz*(y-py)*2000 + px*(y-py)*(z-pz)*1000 + pz*(x-px)*(y-py)*1000))/float(x*y*z)
    
    
    
print(ans)



import math

(n, p) = tuple(map(int, input().split()))

expection = 0
probability = [0]*n
for i in range(n):
    (l, r) = tuple(map(int, input().split()))
    nump = math.floor(r/p) - math.ceil(l/p) + 1
    numa = r - l + 1
    probability[i] = nump/numa

for i in range(n):
    left = i-1
    right = i+1

    if left == -1:
        left = n-1
    if right == n:
        right = 0

    p_middle = probability[i]
    p_left = probability[left]
    p_right = probability[right]

    expection += (p_middle + (1-p_middle)*p_left*p_right)*2000
    expection += ((1-p_middle)*(p_left*(1-p_right)+(1-p_left)*p_right))*1000

print(str(expection))


n, p = list(map(int, input().split()))
l_1, r_1 = list(map(int, input().split()))
pre_l, pre_r = l_1, r_1
answer = 0
for i in range(n - 1):
    l, r = list(map(int, input().split()))
    now_shark = [l, r]
    x1 = (r // p - (l - 1) // p) / (r - l + 1)
    x2 = (pre_r // p - (pre_l - 1) // p) / (pre_r - pre_l + 1)
    answer += (1 - (1 - x1) * (1 - x2)) * 2000
    pre_l, pre_r = l, r
x1 = (r_1 // p - (l_1 - 1) // p) / (r_1 - l_1 + 1)
x2 = (pre_r // p - (pre_l - 1) // p) / (pre_r - pre_l + 1)
answer += (1 - (1 - x1) * (1 - x2)) * 2000
print(answer)




# C problem
import sys

buffer=input().split(' ')
[n, p] = [ int(buffer[i]) for i in range(len(buffer)) ]

shark = []
for i in range(n):
	buffer=input().split(' ')
	[a, b] = [ int(buffer[i]) for i in range(len(buffer)) ]
	shark.append([ int(b/p)-int((a-1)/p) , int(b-a+1) ])

result = 0.0
for i in range(n):
	[a, b] = shark[i]
	[c, d] = shark[(i+1)%n]
	temp = (float(a*d + b*c - a*c))*2000/(b*d)
	result += temp
print(result)

#!/usr/bin/env python3

try:
    while True:
        n, p = list(map(int, input().split()))
        a = [0] * n
        for i in range(n):
            lower, upper = list(map(int, input().split()))
            a[i] = (upper // p - (lower - 1) // p) / (upper - lower + 1)
        print(sum(a[i] + (1 - a[i]) * a[i - 1] for i in range(n)) * 2000)

except EOFError:
    pass


n, p = [int(i) for i in input().split()]
b = []
for i in range(n):
    a = [int(i) for i in input().split()]
    if a[0] % p == 0:
        l = a[0] // p
    else:
        l = a[0] // p + 1
    r = a[1] // p
    s = max(0, r - l + 1)
    s /= a[1] - a[0] + 1
    b += [s]
res = 0
for i in range(-1,n-1):
    res += (b[i] + b[i+1] - b[i] * b[i+1]) * 2000
print(res)
    
        


read = lambda: list(map(int, input().split()))
f = lambda x: (x[1] // p - (x[0] - 1) // p) / (x[1] - x[0] + 1)
n, p = read()
a = [f(tuple(read())) for i in range(n)]
ans = sum(1 - (1 - a[i]) * (1 - a[i - 1]) for i in range(n)) * 2000
print(ans)


n,p=[int(x) for x in input().split()]
mi=[]
for k in range(0,n):
	l,r=[int(x) for x in input().split()]
	#Probability that prime number multiple chosen in  list.
	x=(r//p- (l-1)//p)/(r-l+1)
	#1-x is Probability that it is not prime number multiple.
	mi.append(1-x)

#print(mi)
fin=0
for z in range(0,len(mi)):
	fin+=(1-mi[z]*mi[(z+1)%n])
print(fin*2000)


nextInt = lambda: list(map(int, input().split()))
n,p=nextInt()
a=[0]*n
ret=0
for i in range(n):
    l,r=nextInt()
    a[i]=(r//p-(l-1)//p)/(r-l+1)

for i in range(n):
    ret+=a[i]+a[i-1]-a[i]*a[i-1]

# print(a)

ret*=2000

print(ret)


np = [int(u) for u in input().split()]
n, p  = np
s  = [tuple(int(u) for u in input().split()) for i in range(n)]

def count_multiples(l,r,p):
    return r//p - (l-1)//p

def E_X_i(i):
    i %= n
    l_i = s[i]  [0]
    l_j = s[i+1][0]
    r_i = s[i]  [1]
    r_j = s[i+1][1]
    p_i = count_multiples(l_i,r_i,p)/(1+r_i-l_i)
    p_j = count_multiples(l_j,r_j,p)/(1+r_j-l_j)
    pr = p_i*p_j + (1-p_i)*p_j + (1-p_j)*p_i
    return pr*2*1000
s.append(s[0])
E_X = sum(E_X_i(i) for i in range(n))
print(E_X)


#!/usr/bin/env python3
N, p = map(int, input().split())
blah = []
for _ in range(N):
    l, r = map(int, input().split())
    lp = (l+p-1)//p
    rp = r//p
    count = rp - lp + 1
    blah.append(count / (r-l+1))

total = 0
for i in range(-1, N-1):
    a, b = blah[i], blah[i+1]
    total += a + b - a*b

print(total * 2000)

n,p = list(map(int,input().split(" ")))
l = []
r = []
for i in range(n):
    li,ri = list(map(int, input().split(" ")))
    l.append(li)
    r.append(ri)
ans = 0
for i in range(n):
    j = (i+1)%n
    range1 = r[i]-l[i]+1
    range2 = r[j]-l[j]+1
    prob1 = r[i]//p-(l[i]-1)//p
    prob2 = r[j]//p-(l[j]-1)//p
    ans += 2000*(prob1*range2+prob2*range1-prob1*prob2)/range1/range2
print(ans)


import sys

N, p = list(map(int, input().split()))

l = list()
r = list()

for i in range (0, N):
    a, b = list(map(int, input().split()))
    l.append(a)
    r.append(b)

l.append(l[0])
r.append(r[0])

answer = 2000 * N
answer = 0

for i in range (0, N):
    c1 = l[i] // p
    c2 = r[i] // p
    pos1 = c2-c1
    if (l[i] % p == 0):
        pos1 += 1

    total1 = r[i] - l[i] + 1

    bad_pos1 = total1-pos1

    c1 = l[i+1] // p
    c2 = r[i+1] // p
    pos2 = c2-c1
    if (l[i+1] % p == 0):
        pos2 += 1

    total2 = r[i+1] - l[i+1] + 1

    bad_pos2 = total2-pos2

    answer += 2000 * (1 - bad_pos1/total1 * bad_pos2/total2)



print (answer)





n, p = list(map(int, input().split()))
flowers = [list(map(int, input().split())) for _ in range(n)]
primes = [r // p - (l - 1) // p for l, r in flowers]

ret = 0

for i in range(n):
    j = (i + 1) % n
    total1 = flowers[i][1] - (flowers[i][0] - 1)
    total2 = flowers[j][1] - (flowers[j][0] - 1)
    probnot1 = (total1 - primes[i]) / total1
    probnot2 = (total2 - primes[j]) / total2
    ret += (1 - probnot1 * probnot2)

print(ret * 2000)