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