/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int[] a = {10,30,20,40};

		System.out.println("Test Case 1 Min Cost: " + minCostFrogJump(a));

		int[] b = {30, 10, 60, 10, 60, 50};

		System.out.println("Test Case 2 Min Cost: " + minCostFrogJump(b));
	}


	public static int minCostFrogJump(int[] height) {
		int n = height.length;
		if (n <= 1) return 0;
		
		// dp[i] stores the minimum cost to reach stair i
		int[] dp = new int[n];

		dp[0] = 0; 
		dp[1] = Math.abs(height[1] - height[0]); 

		for(int i = 2; i<n; i++){
			int jumpOne = dp[i - 1] + Math.abs(height[i] - height[i - 1]);
			int jumpTwo = dp[i-2] +Math.abs(height[i] - height[i-2]);

			dp[i] = Math.min(jumpOne,jumpTwo);
		}

		return dp[n-1];
	}
}