
import java.util.Scanner;
/**
 * ACEPTADO 
 * @author crisisanchezp
 *
 */

public class Main {

	static long n;
	static long[] stones;
	static long memo[];

	public static void main(String[] args) {

		String input1 = "";
		String input2 = "";
		Scanner scanner = new Scanner(System.in);
		input1 = scanner.nextLine();
		input2 = scanner.nextLine();

		n = Long.parseLong(input1.trim());
		String[] arr = input2.split(" ");
		stones = new long[(int) n];
		for (int i = 0; i < arr.length; i++) {
			stones[i] = Integer.parseInt(arr[i]);
		}

		memo = new long[(int) n];
		for (int i = 0; i < memo.length; i++) {
			memo[i] = -1;
		}
		System.out.println(getMinCostStone(0));
		scanner.close();
	}

	/**
	 * public static int getMinCostStone(int i, int j) { if (j == stones.length && i
	 * == stones.length - 1) { return 0; } if (j == stones.length - 1 && i ==
	 * stones.length - 2) { return memo[i] = Math.abs(stones[i] - stones[j]); } if
	 * (stones[i] == stones[j]) { return 0; } if (memo[i] != -1) { return memo[i]; }
	 * int cost1 = Math.abs(stones[i] - stones[j]) + getMinCostStone(j, j + 1);
	 * memo[i] = cost1; int cost2 = Math.abs(stones[i] - stones[j + 1]) +
	 * getMinCostStone(j + 1, j + 2);
	 * 
	 * memo[i] = cost2; return memo[i] = Integer.min(cost1, cost2); }
	 */

	public static long getMinCostStone(int i) {
		if (i >= stones.length) {
			return 0;
		}
		if (memo[i] != -1) {
			return memo[i];
		}
		if (i + 1 >= stones.length)
			return 0;
		long cost1 = Math.abs(stones[i] - stones[i + 1]) + getMinCostStone(i + 1);
		memo[i] = cost1;

		long cost2 = (long) 1e18;
		if (i != stones.length - 2) {
			cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2);
		}
		memo[i] = cost2;
		return memo[i] = Long.min(cost1, cost2);
	}

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

	static long n;
	static long[] stones;
	static long memo[];

	public static void main(String[] args) {

		String input1 = "";
		String input2 = "";
		Scanner scanner = new Scanner(System.in);
		input1 = scanner.nextLine();
		input2 = scanner.nextLine();

		n = Long.parseLong(input1.trim());
		String[] arr = input2.split(" ");
		stones = new long[(int) n];
		for (int i = 0; i < arr.length; i++) {
			stones[i] = Integer.parseInt(arr[i]);
		}

		memo = new long[(int) n];
		for (int i = 0; i < memo.length; i++) {
			memo[i] = -1;
		}
		System.out.println(getMinCostStone(0));
		scanner.close();
	}

	/**
	 * public static int getMinCostStone(int i, int j) { if (j == stones.length && i
	 * == stones.length - 1) { return 0; } if (j == stones.length - 1 && i ==
	 * stones.length - 2) { return memo[i] = Math.abs(stones[i] - stones[j]); } if
	 * (stones[i] == stones[j]) { return 0; } if (memo[i] != -1) { return memo[i]; }
	 * int cost1 = Math.abs(stones[i] - stones[j]) + getMinCostStone(j, j + 1);
	 * memo[i] = cost1; int cost2 = Math.abs(stones[i] - stones[j + 1]) +
	 * getMinCostStone(j + 1, j + 2);
	 * 
	 * memo[i] = cost2; return memo[i] = Integer.min(cost1, cost2); }
	 */

	public static long getMinCostStone(int i) {
		if (i >= stones.length) {
			return 0;
		}
		if (memo[i] != -1) {
			return memo[i];
		}
		if (i + 1 >= stones.length)
			return 0;
		long cost1 = Math.abs(stones[i] - stones[i + 1]) + getMinCostStone(i + 1);
		memo[i] = cost1;

		long cost2 = (long) 1e18;
		if (i != stones.length - 2) {
			cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2);
		}
		memo[i] = cost2;
		return memo[i] = Long.min(cost1, cost2);
	}

} Main static long n; n static long[] stones; stones static long memo[]; memo public static void main(String[] args) {

		String input1 = "";
		String input2 = "";
		Scanner scanner = new Scanner(System.in);
		input1 = scanner.nextLine();
		input2 = scanner.nextLine();

		n = Long.parseLong(input1.trim());
		String[] arr = input2.split(" ");
		stones = new long[(int) n];
		for (int i = 0; i < arr.length; i++) {
			stones[i] = Integer.parseInt(arr[i]);
		}

		memo = new long[(int) n];
		for (int i = 0; i < memo.length; i++) {
			memo[i] = -1;
		}
		System.out.println(getMinCostStone(0));
		scanner.close();
	} main {

		String input1 = "";
		String input2 = "";
		Scanner scanner = new Scanner(System.in);
		input1 = scanner.nextLine();
		input2 = scanner.nextLine();

		n = Long.parseLong(input1.trim());
		String[] arr = input2.split(" ");
		stones = new long[(int) n];
		for (int i = 0; i < arr.length; i++) {
			stones[i] = Integer.parseInt(arr[i]);
		}

		memo = new long[(int) n];
		for (int i = 0; i < memo.length; i++) {
			memo[i] = -1;
		}
		System.out.println(getMinCostStone(0));
		scanner.close();
	} String input1 = ""; input1 "" String input2 = ""; input2 "" Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) input1 = scanner.nextLine() input1 scanner.nextLine() scanner.nextLine scanner input2 = scanner.nextLine() input2 scanner.nextLine() scanner.nextLine scanner n = Long.parseLong(input1.trim()) n Long.parseLong(input1.trim()) Long.parseLong Long input1.trim() input1.trim input1 String[] arr = input2.split(" "); arr input2.split(" ") input2.split input2 " " stones = new long[(int) n] stones new long[(int) n] (int) n for (int i = 0; i < arr.length; i++) {
			stones[i] = Integer.parseInt(arr[i]);
		} int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i {
			stones[i] = Integer.parseInt(arr[i]);
		} {
			stones[i] = Integer.parseInt(arr[i]);
		} stones[i] = Integer.parseInt(arr[i]) stones[i] stones i Integer.parseInt(arr[i]) Integer.parseInt Integer arr[i] arr i memo = new long[(int) n] memo new long[(int) n] (int) n for (int i = 0; i < memo.length; i++) {
			memo[i] = -1;
		} int i = 0; int i = 0; i 0 i < memo.length i memo.length memo memo.length i++ i++ i {
			memo[i] = -1;
		} {
			memo[i] = -1;
		} memo[i] = -1 memo[i] memo i -1 1 System.out.println(getMinCostStone(0)) System.out.println System.out System System.out getMinCostStone(0) getMinCostStone 0 scanner.close() scanner.close scanner String[] args args /**
	 * public static int getMinCostStone(int i, int j) { if (j == stones.length && i
	 * == stones.length - 1) { return 0; } if (j == stones.length - 1 && i ==
	 * stones.length - 2) { return memo[i] = Math.abs(stones[i] - stones[j]); } if
	 * (stones[i] == stones[j]) { return 0; } if (memo[i] != -1) { return memo[i]; }
	 * int cost1 = Math.abs(stones[i] - stones[j]) + getMinCostStone(j, j + 1);
	 * memo[i] = cost1; int cost2 = Math.abs(stones[i] - stones[j + 1]) +
	 * getMinCostStone(j + 1, j + 2);
	 * 
	 * memo[i] = cost2; return memo[i] = Integer.min(cost1, cost2); }
	 */

	public static long getMinCostStone(int i) {
		if (i >= stones.length) {
			return 0;
		}
		if (memo[i] != -1) {
			return memo[i];
		}
		if (i + 1 >= stones.length)
			return 0;
		long cost1 = Math.abs(stones[i] - stones[i + 1]) + getMinCostStone(i + 1);
		memo[i] = cost1;

		long cost2 = (long) 1e18;
		if (i != stones.length - 2) {
			cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2);
		}
		memo[i] = cost2;
		return memo[i] = Long.min(cost1, cost2);
	} getMinCostStone {
		if (i >= stones.length) {
			return 0;
		}
		if (memo[i] != -1) {
			return memo[i];
		}
		if (i + 1 >= stones.length)
			return 0;
		long cost1 = Math.abs(stones[i] - stones[i + 1]) + getMinCostStone(i + 1);
		memo[i] = cost1;

		long cost2 = (long) 1e18;
		if (i != stones.length - 2) {
			cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2);
		}
		memo[i] = cost2;
		return memo[i] = Long.min(cost1, cost2);
	} if (i >= stones.length) {
			return 0;
		} i >= stones.length i stones.length stones stones.length {
			return 0;
		} return 0; 0 if (memo[i] != -1) {
			return memo[i];
		} memo[i] != -1 memo[i] memo i -1 1 {
			return memo[i];
		} return memo[i]; memo[i] memo i if (i + 1 >= stones.length)
			return 0; i + 1 >= stones.length i + 1 i 1 stones.length stones stones.length return 0; 0 long cost1 = Math.abs(stones[i] - stones[i + 1]) + getMinCostStone(i + 1); cost1 Math.abs(stones[i] - stones[i + 1]) + getMinCostStone(i + 1) Math.abs(stones[i] - stones[i + 1]) Math.abs Math stones[i] - stones[i + 1] stones[i] stones i stones[i + 1] stones i + 1 i 1 getMinCostStone(i + 1) getMinCostStone i + 1 i 1 memo[i] = cost1 memo[i] memo i cost1 long cost2 = (long) 1e18; cost2 (long) 1e18 if (i != stones.length - 2) {
			cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2);
		} i != stones.length - 2 i stones.length - 2 stones.length stones stones.length 2 {
			cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2);
		} cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2) cost2 Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2) Math.abs(stones[i] - stones[i + 2]) Math.abs Math stones[i] - stones[i + 2] stones[i] stones i stones[i + 2] stones i + 2 i 2 getMinCostStone(i + 2) getMinCostStone i + 2 i 2 memo[i] = cost2 memo[i] memo i cost2 return memo[i] = Long.min(cost1, cost2); memo[i] = Long.min(cost1, cost2) memo[i] memo i Long.min(cost1, cost2) Long.min Long cost1 cost2 int i i public class Main {

	static long n;
	static long[] stones;
	static long memo[];

	public static void main(String[] args) {

		String input1 = "";
		String input2 = "";
		Scanner scanner = new Scanner(System.in);
		input1 = scanner.nextLine();
		input2 = scanner.nextLine();

		n = Long.parseLong(input1.trim());
		String[] arr = input2.split(" ");
		stones = new long[(int) n];
		for (int i = 0; i < arr.length; i++) {
			stones[i] = Integer.parseInt(arr[i]);
		}

		memo = new long[(int) n];
		for (int i = 0; i < memo.length; i++) {
			memo[i] = -1;
		}
		System.out.println(getMinCostStone(0));
		scanner.close();
	}

	/**
	 * public static int getMinCostStone(int i, int j) { if (j == stones.length && i
	 * == stones.length - 1) { return 0; } if (j == stones.length - 1 && i ==
	 * stones.length - 2) { return memo[i] = Math.abs(stones[i] - stones[j]); } if
	 * (stones[i] == stones[j]) { return 0; } if (memo[i] != -1) { return memo[i]; }
	 * int cost1 = Math.abs(stones[i] - stones[j]) + getMinCostStone(j, j + 1);
	 * memo[i] = cost1; int cost2 = Math.abs(stones[i] - stones[j + 1]) +
	 * getMinCostStone(j + 1, j + 2);
	 * 
	 * memo[i] = cost2; return memo[i] = Integer.min(cost1, cost2); }
	 */

	public static long getMinCostStone(int i) {
		if (i >= stones.length) {
			return 0;
		}
		if (memo[i] != -1) {
			return memo[i];
		}
		if (i + 1 >= stones.length)
			return 0;
		long cost1 = Math.abs(stones[i] - stones[i + 1]) + getMinCostStone(i + 1);
		memo[i] = cost1;

		long cost2 = (long) 1e18;
		if (i != stones.length - 2) {
			cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2);
		}
		memo[i] = cost2;
		return memo[i] = Long.min(cost1, cost2);
	}

} public class Main {

	static long n;
	static long[] stones;
	static long memo[];

	public static void main(String[] args) {

		String input1 = "";
		String input2 = "";
		Scanner scanner = new Scanner(System.in);
		input1 = scanner.nextLine();
		input2 = scanner.nextLine();

		n = Long.parseLong(input1.trim());
		String[] arr = input2.split(" ");
		stones = new long[(int) n];
		for (int i = 0; i < arr.length; i++) {
			stones[i] = Integer.parseInt(arr[i]);
		}

		memo = new long[(int) n];
		for (int i = 0; i < memo.length; i++) {
			memo[i] = -1;
		}
		System.out.println(getMinCostStone(0));
		scanner.close();
	}

	/**
	 * public static int getMinCostStone(int i, int j) { if (j == stones.length && i
	 * == stones.length - 1) { return 0; } if (j == stones.length - 1 && i ==
	 * stones.length - 2) { return memo[i] = Math.abs(stones[i] - stones[j]); } if
	 * (stones[i] == stones[j]) { return 0; } if (memo[i] != -1) { return memo[i]; }
	 * int cost1 = Math.abs(stones[i] - stones[j]) + getMinCostStone(j, j + 1);
	 * memo[i] = cost1; int cost2 = Math.abs(stones[i] - stones[j + 1]) +
	 * getMinCostStone(j + 1, j + 2);
	 * 
	 * memo[i] = cost2; return memo[i] = Integer.min(cost1, cost2); }
	 */

	public static long getMinCostStone(int i) {
		if (i >= stones.length) {
			return 0;
		}
		if (memo[i] != -1) {
			return memo[i];
		}
		if (i + 1 >= stones.length)
			return 0;
		long cost1 = Math.abs(stones[i] - stones[i + 1]) + getMinCostStone(i + 1);
		memo[i] = cost1;

		long cost2 = (long) 1e18;
		if (i != stones.length - 2) {
			cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2);
		}
		memo[i] = cost2;
		return memo[i] = Long.min(cost1, cost2);
	}

} Main

import java.util.Scanner;
/**
 * ACEPTADO 
 * @author crisisanchezp
 *
 */

public class Main {

	static long n;
	static long[] stones;
	static long memo[];

	public static void main(String[] args) {

		String input1 = "";
		String input2 = "";
		Scanner scanner = new Scanner(System.in);
		input1 = scanner.nextLine();
		input2 = scanner.nextLine();

		n = Long.parseLong(input1.trim());
		String[] arr = input2.split(" ");
		stones = new long[(int) n];
		for (int i = 0; i < arr.length; i++) {
			stones[i] = Integer.parseInt(arr[i]);
		}

		memo = new long[(int) n];
		for (int i = 0; i < memo.length; i++) {
			memo[i] = -1;
		}
		System.out.println(getMinCostStone(0));
		scanner.close();
	}

	/**
	 * public static int getMinCostStone(int i, int j) { if (j == stones.length && i
	 * == stones.length - 1) { return 0; } if (j == stones.length - 1 && i ==
	 * stones.length - 2) { return memo[i] = Math.abs(stones[i] - stones[j]); } if
	 * (stones[i] == stones[j]) { return 0; } if (memo[i] != -1) { return memo[i]; }
	 * int cost1 = Math.abs(stones[i] - stones[j]) + getMinCostStone(j, j + 1);
	 * memo[i] = cost1; int cost2 = Math.abs(stones[i] - stones[j + 1]) +
	 * getMinCostStone(j + 1, j + 2);
	 * 
	 * memo[i] = cost2; return memo[i] = Integer.min(cost1, cost2); }
	 */

	public static long getMinCostStone(int i) {
		if (i >= stones.length) {
			return 0;
		}
		if (memo[i] != -1) {
			return memo[i];
		}
		if (i + 1 >= stones.length)
			return 0;
		long cost1 = Math.abs(stones[i] - stones[i + 1]) + getMinCostStone(i + 1);
		memo[i] = cost1;

		long cost2 = (long) 1e18;
		if (i != stones.length - 2) {
			cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2);
		}
		memo[i] = cost2;
		return memo[i] = Long.min(cost1, cost2);
	}

}
