nc=gets.chomp.split(" ").map(&:to_i)
h=gets.chomp.split(" ").map(&:to_i)

dp=Array.new(nc[0])
dp[0]=0
dp[1]=(h[0]-h[1])**2+nc[1]
for i in 2..nc[0]-1
	min=dp[i-1]+(h[i]-h[i-1])**2+nc[1]
	for j in 2..i
		result=dp[i-j]+(h[i]-h[i-j])**2+nc[1]
		if(min>result)
			min=result
		end
	end
	dp[i]=min
end
p dp[nc[0]-1]