import java.util.Scanner;

/**
 * https://atcoder.jp/contests/dp/tasks/dp_a
 * Frog 1
 */
public class Main {

	public static void main(String...args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			}

			int[] dp = new int[n];
			dp[0] = 0;
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			}

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

	public static int mindp(int a, int b) {
		if (a > b) {
			a = b;
		}
		return a;
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String...args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			}

			int[] dp = new int[n];
			dp[0] = 0;
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			}

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

	public static int mindp(int a, int b) {
		if (a > b) {
			a = b;
		}
		return a;
	}
} Main public static void main(String...args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			}

			int[] dp = new int[n];
			dp[0] = 0;
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			}

			System.out.println(dp[n-1]);
		}
	} main {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			}

			int[] dp = new int[n];
			dp[0] = 0;
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			}

			System.out.println(dp[n-1]);
		}
	} try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			}

			int[] dp = new int[n];
			dp[0] = 0;
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			}

			System.out.println(dp[n-1]);
		} {
			int n = sc.nextInt();
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			}

			int[] dp = new int[n];
			dp[0] = 0;
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			}

			System.out.println(dp[n-1]);
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] h = new int[n]; h new int[n] n for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				h[i] = sc.nextInt();
			} {
				h[i] = sc.nextInt();
			} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int[] dp = new int[n]; dp new int[n] n dp[0] = 0 dp[0] dp 0 0 for (int i = 0; i < n; i++) {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			} {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			} if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				} i == 0 i 0 {
					dp[i] = 0;
				} dp[i] = 0 dp[i] dp i 0 if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				} i == 1 i 1 {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} dp[i] = Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1])) dp[i] dp i mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1])) mindp dp[i] dp i dp[i-1] + Math.abs(h[i]-h[i-1]) dp[i-1] dp i-1 i 1 Math.abs(h[i]-h[i-1]) Math.abs Math h[i]-h[i-1] h[i] h i h[i-1] h i-1 i 1 {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				} dp[i] = Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1])) dp[i] dp i mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1])) mindp dp[i] dp i dp[i-1] + Math.abs(h[i]-h[i-1]) dp[i-1] dp i-1 i 1 Math.abs(h[i]-h[i-1]) Math.abs Math h[i]-h[i-1] h[i] h i h[i-1] h i-1 i 1 dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2])) dp[i] dp i mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2])) mindp dp[i] dp i dp[i-2] + Math.abs(h[i]-h[i-2]) dp[i-2] dp i-2 i 2 Math.abs(h[i]-h[i-2]) Math.abs Math h[i]-h[i-2] h[i] h i h[i-2] h 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 static int mindp(int a, int b) {
		if (a > b) {
			a = b;
		}
		return a;
	} mindp {
		if (a > b) {
			a = b;
		}
		return a;
	} if (a > b) {
			a = b;
		} a > b a b {
			a = b;
		} a = b a b return a; a int a a int b b public class Main {

	public static void main(String...args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			}

			int[] dp = new int[n];
			dp[0] = 0;
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			}

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

	public static int mindp(int a, int b) {
		if (a > b) {
			a = b;
		}
		return a;
	}
} public class Main {

	public static void main(String...args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			}

			int[] dp = new int[n];
			dp[0] = 0;
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			}

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

	public static int mindp(int a, int b) {
		if (a > b) {
			a = b;
		}
		return a;
	}
} Main
import java.util.Scanner;

/**
 * https://atcoder.jp/contests/dp/tasks/dp_a
 * Frog 1
 */
public class Main {

	public static void main(String...args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				h[i] = sc.nextInt();
			}

			int[] dp = new int[n];
			dp[0] = 0;
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					dp[i] = 0;
				} else if (i == 1) {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
				} else {
					dp[i] = Integer.MAX_VALUE;
					dp[i] = mindp(dp[i], dp[i-1] + Math.abs(h[i]-h[i-1]));
					dp[i] = mindp(dp[i], dp[i-2] + Math.abs(h[i]-h[i-2]));
				}
			}

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

	public static int mindp(int a, int b) {
		if (a > b) {
			a = b;
		}
		return a;
	}
}
