Autocorrelation Function

A piecewise linear function is given by its endpoints; compute the integral of f(x)f(x+r) over the whole line for a given shift r.

Medium5MathGeometryImplementationSimulationInterviewNo attempts yetTime limit8sMemory limit512 MB

Problem

Autocorrelation measures how much a signal matches a shifted copy of itself. For a continuous function f(x)f(x) defined on the whole real line, the autocorrelation function Rf(r)R_f(r) is

Rf(r)=f(x)f(x+r)dxR_f(r) = \int_{-\infty}^{\infty} f(x)\,f(x + r)\,dx

where rr is a real number.

Every function in this problem is piecewise linear and continuous. It is given by nn endpoints (x1,y1)(x_1, y_1) through (xn,yn)(x_n, y_n) with distinct xx-coordinates, and consecutive endpoints are joined by a straight segment. The first and the last endpoint have yy-coordinate 0, and ff is 0 outside the interval [x1,xn][x_1, x_n]. The figure below shows one such function.

An example of a given function

Given ff and rr, compute Rf(r)R_f(r).

Input

The input holds several data sets.

The first line of each data set has an integer nn (3n1003 \le n \le 100) and a real number rr (100r100-100 \le r \le 100). Here nn is the number of endpoints that form ff, and rr is the parameter of the autocorrelation function. Each of the next nn lines has two integers xix_i (100xi100-100 \le x_i \le 100) and yiy_i (50yi50-50 \le y_i \le 50), the coordinates of the ii-th endpoint. The endpoints come in increasing order of xx-coordinate, and no two endpoints share an xx-coordinate. The first and the last endpoint always have yy-coordinate 0.

A line with nn and rr both equal to 0 ends the input. That line is not a data set, so do not process it.

Output

For each data set, print the value of Rf(r)R_f(r) on its own line. Round the value at the seventh digit after the decimal point and print exactly six digits after the decimal point. If the value is 0, print 0.000000 and not -0.000000.