

import java.util.Scanner;

public class Main {

	static int mincost(int i, int[] ar, int[] dp) {

		if (i >= ar.length)
			return 0;

		if (i == ar.length - 1)
			return 0;

		if (dp[i] != -1)
			return dp[i];

		int left = Math.abs(ar[i] - ar[i + 1]) + mincost(i + 1, ar, dp);
		
		int right = Integer.MAX_VALUE;
		
		if(i + 2 < ar.length)
			right = Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp);

		return dp[i] = Math.min(left, right);
	}

	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ar[] = new int[n];
		int dp[] = new int[n];

		for (int i = 0; i < n; i++) {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		}

		System.out.println(mincost(0, ar, dp));
	}

} import java.util.Scanner; Scanner java.util public class Main {

	static int mincost(int i, int[] ar, int[] dp) {

		if (i >= ar.length)
			return 0;

		if (i == ar.length - 1)
			return 0;

		if (dp[i] != -1)
			return dp[i];

		int left = Math.abs(ar[i] - ar[i + 1]) + mincost(i + 1, ar, dp);
		
		int right = Integer.MAX_VALUE;
		
		if(i + 2 < ar.length)
			right = Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp);

		return dp[i] = Math.min(left, right);
	}

	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ar[] = new int[n];
		int dp[] = new int[n];

		for (int i = 0; i < n; i++) {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		}

		System.out.println(mincost(0, ar, dp));
	}

} Main static int mincost(int i, int[] ar, int[] dp) {

		if (i >= ar.length)
			return 0;

		if (i == ar.length - 1)
			return 0;

		if (dp[i] != -1)
			return dp[i];

		int left = Math.abs(ar[i] - ar[i + 1]) + mincost(i + 1, ar, dp);
		
		int right = Integer.MAX_VALUE;
		
		if(i + 2 < ar.length)
			right = Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp);

		return dp[i] = Math.min(left, right);
	} mincost {

		if (i >= ar.length)
			return 0;

		if (i == ar.length - 1)
			return 0;

		if (dp[i] != -1)
			return dp[i];

		int left = Math.abs(ar[i] - ar[i + 1]) + mincost(i + 1, ar, dp);
		
		int right = Integer.MAX_VALUE;
		
		if(i + 2 < ar.length)
			right = Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp);

		return dp[i] = Math.min(left, right);
	} if (i >= ar.length)
			return 0; i >= ar.length i ar.length ar ar.length return 0; 0 if (i == ar.length - 1)
			return 0; i == ar.length - 1 i ar.length - 1 ar.length ar ar.length 1 return 0; 0 if (dp[i] != -1)
			return dp[i]; dp[i] != -1 dp[i] dp i -1 1 return dp[i]; dp[i] dp i int left = Math.abs(ar[i] - ar[i + 1]) + mincost(i + 1, ar, dp); left Math.abs(ar[i] - ar[i + 1]) + mincost(i + 1, ar, dp) Math.abs(ar[i] - ar[i + 1]) Math.abs Math ar[i] - ar[i + 1] ar[i] ar i ar[i + 1] ar i + 1 i 1 mincost(i + 1, ar, dp) mincost i + 1 i 1 ar dp int right = Integer.MAX_VALUE; right Integer.MAX_VALUE Integer Integer.MAX_VALUE if(i + 2 < ar.length)
			right = Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp); i + 2 < ar.length i + 2 i 2 ar.length ar ar.length right = Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp) right Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp) Math.abs(ar[i] - ar[i + 2]) Math.abs Math ar[i] - ar[i + 2] ar[i] ar i ar[i + 2] ar i + 2 i 2 mincost(i + 2, ar, dp) mincost i + 2 i 2 ar dp return dp[i] = Math.min(left, right); dp[i] = Math.min(left, right) dp[i] dp i Math.min(left, right) Math.min Math left right int i i int[] ar ar int[] dp dp public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ar[] = new int[n];
		int dp[] = new int[n];

		for (int i = 0; i < n; i++) {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		}

		System.out.println(mincost(0, ar, dp));
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ar[] = new int[n];
		int dp[] = new int[n];

		for (int i = 0; i < n; i++) {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		}

		System.out.println(mincost(0, ar, dp));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int ar[] = new int[n]; ar new int[n] n int dp[] = new int[n]; dp new int[n] n for (int i = 0; i < n; i++) {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		} {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		} ar[i] = sc.nextInt() ar[i] ar i sc.nextInt() sc.nextInt sc dp[i] = -1 dp[i] dp i -1 1 System.out.println(mincost(0, ar, dp)) System.out.println System.out System System.out mincost(0, ar, dp) mincost 0 ar dp String args[] args public class Main {

	static int mincost(int i, int[] ar, int[] dp) {

		if (i >= ar.length)
			return 0;

		if (i == ar.length - 1)
			return 0;

		if (dp[i] != -1)
			return dp[i];

		int left = Math.abs(ar[i] - ar[i + 1]) + mincost(i + 1, ar, dp);
		
		int right = Integer.MAX_VALUE;
		
		if(i + 2 < ar.length)
			right = Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp);

		return dp[i] = Math.min(left, right);
	}

	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ar[] = new int[n];
		int dp[] = new int[n];

		for (int i = 0; i < n; i++) {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		}

		System.out.println(mincost(0, ar, dp));
	}

} public class Main {

	static int mincost(int i, int[] ar, int[] dp) {

		if (i >= ar.length)
			return 0;

		if (i == ar.length - 1)
			return 0;

		if (dp[i] != -1)
			return dp[i];

		int left = Math.abs(ar[i] - ar[i + 1]) + mincost(i + 1, ar, dp);
		
		int right = Integer.MAX_VALUE;
		
		if(i + 2 < ar.length)
			right = Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp);

		return dp[i] = Math.min(left, right);
	}

	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ar[] = new int[n];
		int dp[] = new int[n];

		for (int i = 0; i < n; i++) {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		}

		System.out.println(mincost(0, ar, dp));
	}

} Main


import java.util.Scanner;

public class Main {

	static int mincost(int i, int[] ar, int[] dp) {

		if (i >= ar.length)
			return 0;

		if (i == ar.length - 1)
			return 0;

		if (dp[i] != -1)
			return dp[i];

		int left = Math.abs(ar[i] - ar[i + 1]) + mincost(i + 1, ar, dp);
		
		int right = Integer.MAX_VALUE;
		
		if(i + 2 < ar.length)
			right = Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp);

		return dp[i] = Math.min(left, right);
	}

	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ar[] = new int[n];
		int dp[] = new int[n];

		for (int i = 0; i < n; i++) {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		}

		System.out.println(mincost(0, ar, dp));
	}

}