eval"N,C,*H="+`dd`.split*?,;g,*q=->i{x,y=q[i,2];1.0*($*[x]-$*[y])/(H[y]-H[x])-H[x]-H[y]};N.times{|i|q.shift while q[-2]&&g[0]>-2*H[i];$*<<X=i>0?$*[q[0]]+C+(H[q[0]]-H[i])**2:0;q.pop 2while(q<<i)[-3]&&g[-2]>g[-3]};p X