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]};p$*[N.times{|i|_,*q=q while q[-2]&&g[0]>-2*H[i];$*<<(i>0?$*[q[0]]+C+(H[q[0]]-H[i])**2:0);q.pop 2while(q<<i)[-3]&&g[-2]>g[-3]}-1]