eolymp
bolt
Try our new interface for solving problems
Problems

Computer game (platforms) with quadratic jumps

Computer game (platforms) with quadratic jumps

Can you remember at least single your acquaintance, who is less than twenty years old and didn't play computer games in childhood? If yes, you might not know this kind of entertainment. But it wouldn't prevent you to solve this problem. In older games, which have 2D graphics, one can run into the next situation. The hero jumps along the platforms that hang in the air. He must move himself from one side of the screen to the other. When the hero jumps from one platform to the neighboring, he spends \textbf{|y_2-y_1|^2} energy, where \textbf{y_1} and \textbf{y_2} are the heights where these platforms hang. Also the hero has super skill  he can make a super jump that allows him to skip one platform, but it takes him\textbf{3·|y_3-y_1|^2} energy. Obviously, energy should be spent frugally. You are given the heights of the platforms in order from the left side to the right. Can you nd the minimum amount of energy to get from the \textbf{1}-st (start) platform to the \textbf{N}-th (last)? \InputFile The first line contains the number of platforms \textbf{N} (\textbf{2} ≤ \textbf{N} ≤ \textbf{100000}). The second line gives \textbf{N} integers the heights of the platforms, which absolute values are not greater than \textbf{4000}. \OutputFile Print the integer which is the minimum amount of energy to get from the \textbf{1}-st platform to the \textbf{N}-th (assuming, that player is forbidden to use cheat codes).
Time limit 1 second
Memory limit 64 MiB
Input example #1
4
1 2 3 30
Output example #1
731
Author Илья Порублёв
Source Летняя школа Севастополь 2013, Волна 1, День 2