import java.util.Arrays;
import java.util.Scanner;


public class Main {

	static int N;
	static int[] nums;
	static int[] dp;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		int[] nums = new int[N+1];
		int[] dp = new int[N+1];


		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
		}

		Arrays.fill(dp, Integer.MAX_VALUE);

		dp[0] = 0;

		for (int i = 1; i < N; i++) {
			dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1]));
			if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			}
		}

		System.out.println(dp[N-1]);

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

	static int N;
	static int[] nums;
	static int[] dp;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		int[] nums = new int[N+1];
		int[] dp = new int[N+1];


		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
		}

		Arrays.fill(dp, Integer.MAX_VALUE);

		dp[0] = 0;

		for (int i = 1; i < N; i++) {
			dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1]));
			if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			}
		}

		System.out.println(dp[N-1]);

	}
} Main static int N; N static int[] nums; nums static int[] dp; dp public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		int[] nums = new int[N+1];
		int[] dp = new int[N+1];


		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
		}

		Arrays.fill(dp, Integer.MAX_VALUE);

		dp[0] = 0;

		for (int i = 1; i < N; i++) {
			dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1]));
			if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			}
		}

		System.out.println(dp[N-1]);

	} main {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		int[] nums = new int[N+1];
		int[] dp = new int[N+1];


		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
		}

		Arrays.fill(dp, Integer.MAX_VALUE);

		dp[0] = 0;

		for (int i = 1; i < N; i++) {
			dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1]));
			if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			}
		}

		System.out.println(dp[N-1]);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) N = sc.nextInt() N sc.nextInt() sc.nextInt sc int[] nums = new int[N+1]; nums new int[N+1] N+1 N 1 int[] dp = new int[N+1]; dp new int[N+1] N+1 N 1 for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			nums[i] = sc.nextInt();
		} {
			nums[i] = sc.nextInt();
		} nums[i] = sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc Arrays.fill(dp, Integer.MAX_VALUE) Arrays.fill Arrays dp Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[0] = 0 dp[0] dp 0 0 for (int i = 1; i < N; i++) {
			dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1]));
			if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			}
		} int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
			dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1]));
			if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			}
		} {
			dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1]));
			if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			}
		} dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1])) dp[i] dp i Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1])) Math.min Math dp[i] dp i dp[i-1] + Math.abs(nums[i] - nums[i-1]) dp[i-1] dp i-1 i 1 Math.abs(nums[i] - nums[i-1]) Math.abs Math nums[i] - nums[i-1] nums[i] nums i nums[i-1] nums i-1 i 1 if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			} i>1 i 1 {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			} dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2])) dp[i] dp i Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2])) Math.min Math dp[i] dp i dp[i-2] + Math.abs(nums[i] - nums[i-2]) dp[i-2] dp i-2 i 2 Math.abs(nums[i] - nums[i-2]) Math.abs Math nums[i] - nums[i-2] nums[i] nums i nums[i-2] nums i-2 i 2 System.out.println(dp[N-1]) System.out.println System.out System System.out dp[N-1] dp N-1 N 1 String[] args args public class Main {

	static int N;
	static int[] nums;
	static int[] dp;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		int[] nums = new int[N+1];
		int[] dp = new int[N+1];


		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
		}

		Arrays.fill(dp, Integer.MAX_VALUE);

		dp[0] = 0;

		for (int i = 1; i < N; i++) {
			dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1]));
			if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			}
		}

		System.out.println(dp[N-1]);

	}
} public class Main {

	static int N;
	static int[] nums;
	static int[] dp;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		int[] nums = new int[N+1];
		int[] dp = new int[N+1];


		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
		}

		Arrays.fill(dp, Integer.MAX_VALUE);

		dp[0] = 0;

		for (int i = 1; i < N; i++) {
			dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1]));
			if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			}
		}

		System.out.println(dp[N-1]);

	}
} Main
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	static int N;
	static int[] nums;
	static int[] dp;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		int[] nums = new int[N+1];
		int[] dp = new int[N+1];


		for (int i = 0; i < N; i++) {
			nums[i] = sc.nextInt();
		}

		Arrays.fill(dp, Integer.MAX_VALUE);

		dp[0] = 0;

		for (int i = 1; i < N; i++) {
			dp[i] = Math.min(dp[i], dp[i-1] + Math.abs(nums[i] - nums[i-1]));
			if (i>1) {
				dp[i] = Math.min(dp[i], dp[i-2] + Math.abs(nums[i] - nums[i-2]));
			}
		}

		System.out.println(dp[N-1]);

	}
}
