Autocorrelation measures how much a signal matches a shifted copy of itself. For a continuous function f(x) defined on the whole real line, the autocorrelation function Rf(r) is
Rf(r)=∫−∞∞f(x)f(x+r)dx
where r is a real number.
Every function in this problem is piecewise linear and continuous. It is given by n endpoints (x1,y1) through (xn,yn) with distinct x-coordinates, and consecutive endpoints are joined by a straight segment. The first and the last endpoint have y-coordinate 0, and f is 0 outside the interval [x1,xn]. The figure below shows one such function.

Given f and r, compute Rf(r).