eval"N,C,*H="+`dd`.split*?,;
*d=0;*q=0;
g=->i{1.0*(d[q[i-1]]-d[q[i]])/(H[q[i]]-H[q[i-1]])-H[q[i-1]]-H[q[i]]}
1.upto(N-1){|i|
	q.shift while q.size>1&&g[1]>-2*H[i];
	d<<d[q[0]]+(H[q[0]]-H[i])**2+C;
	q<<i
	q.delete_at(-2)while q.size>2&&g[-1]>g[-2];
}
p d[-1]