//package src;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String args[]) {
		int n=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=scn.nextInt();
		}
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println(mincost(arr, 0,memo));
	}
		public static long mincost(int arr[],int i,long memo[])
		{	int n=arr.length;
			if(i==n-1)
				return 0;
			if(i>=n)
				return Integer.MAX_VALUE;
			if(memo[i]!=-1)
				return memo[i];
			long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
			a=mincost(arr, i+1,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)]);
			b=mincost(arr, i+2,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)]);
			memo[i]=Math.min(a, b);
			return Math.min(a, b);
		}
	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

}

class pair {
	int a;
	int b;

	pair(int x, int y) {
		this.a = x;
		this.b = y;
	}
}

class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub
		int a = o1.a - o2.a;
		if (a < 0)
			return -1;
		else
			return 1;
	}

} import java.util.Scanner; Scanner java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.Iterator; Iterator java.util import java.util.PriorityQueue; PriorityQueue java.util import java.util.Queue; Queue java.util import java.util.Stack; Stack java.util import java.util.StringTokenizer; StringTokenizer java.util import java.util.TreeMap; TreeMap java.util import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Comparator; Comparator java.util import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.lang.StringBuilder; StringBuilder java.lang import java.math.BigInteger; BigInteger java.math public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String args[]) {
		int n=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=scn.nextInt();
		}
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println(mincost(arr, 0,memo));
	}
		public static long mincost(int arr[],int i,long memo[])
		{	int n=arr.length;
			if(i==n-1)
				return 0;
			if(i>=n)
				return Integer.MAX_VALUE;
			if(memo[i]!=-1)
				return memo[i];
			long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
			a=mincost(arr, i+1,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)]);
			b=mincost(arr, i+2,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)]);
			memo[i]=Math.min(a, b);
			return Math.min(a, b);
		}
	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

} Main static Scanner scn = new Scanner(System.in); scn new Scanner(System.in) static int mod = 1000000007; mod 1000000007 public static void main(String args[]) {
		int n=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=scn.nextInt();
		}
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println(mincost(arr, 0,memo));
	} main {
		int n=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=scn.nextInt();
		}
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println(mincost(arr, 0,memo));
	} int n=scn.nextInt(); n scn.nextInt() scn.nextInt scn int arr[]=new int[n]; arr new int[n] n for(int i=0;i<n;i++)
		{
			arr[i]=scn.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			arr[i]=scn.nextInt();
		} {
			arr[i]=scn.nextInt();
		} arr[i]=scn.nextInt() arr[i] arr i scn.nextInt() scn.nextInt scn long memo[]=new long[n+1]; memo new long[n+1] n+1 n 1 Arrays.fill(memo, -1) Arrays.fill Arrays memo -1 1 System.out.println(mincost(arr, 0,memo)) System.out.println System.out System System.out mincost(arr, 0,memo) mincost arr 0 memo String args[] args public static long mincost(int arr[],int i,long memo[])
		{	int n=arr.length;
			if(i==n-1)
				return 0;
			if(i>=n)
				return Integer.MAX_VALUE;
			if(memo[i]!=-1)
				return memo[i];
			long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
			a=mincost(arr, i+1,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)]);
			b=mincost(arr, i+2,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)]);
			memo[i]=Math.min(a, b);
			return Math.min(a, b);
		} mincost {	int n=arr.length;
			if(i==n-1)
				return 0;
			if(i>=n)
				return Integer.MAX_VALUE;
			if(memo[i]!=-1)
				return memo[i];
			long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
			a=mincost(arr, i+1,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)]);
			b=mincost(arr, i+2,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)]);
			memo[i]=Math.min(a, b);
			return Math.min(a, b);
		} int n=arr.length; n arr.length arr arr.length if(i==n-1)
				return 0; i==n-1 i n-1 n 1 return 0; 0 if(i>=n)
				return Integer.MAX_VALUE; i>=n i n return Integer.MAX_VALUE; Integer.MAX_VALUE Integer Integer.MAX_VALUE if(memo[i]!=-1)
				return memo[i]; memo[i]!=-1 memo[i] memo i -1 1 return memo[i]; memo[i] memo i long a=Integer.MAX_VALUE a Integer.MAX_VALUE Integer Integer.MAX_VALUE b=Integer.MAX_VALUE; b Integer.MAX_VALUE Integer Integer.MAX_VALUE a=mincost(arr, i+1,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)]) a mincost(arr, i+1,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)]) mincost(arr, i+1,memo) mincost arr i+1 i 1 memo Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)]) Math.abs Math arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)] arr[Math.min(i,n-1 )] arr Math.min(i,n-1 ) Math.min Math i n-1 n 1 arr[Math.min(i+1, n-1)] arr Math.min(i+1, n-1) Math.min Math i+1 i 1 n-1 n 1 b=mincost(arr, i+2,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)]) b mincost(arr, i+2,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)]) mincost(arr, i+2,memo) mincost arr i+2 i 2 memo Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)]) Math.abs Math arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)] arr[Math.min(i,n-1 )] arr Math.min(i,n-1 ) Math.min Math i n-1 n 1 arr[Math.min(i+2, n-1)] arr Math.min(i+2, n-1) Math.min Math i+2 i 2 n-1 n 1 memo[i]=Math.min(a, b) memo[i] memo i Math.min(a, b) Math.min Math a b return Math.min(a, b); Math.min(a, b) Math.min Math a b int arr[] arr int i i long memo[] memo public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	} decode {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	} if (i == 0) {
			return 1;
		} i == 0 i 0 {
			return 1;
		} return 1; 1 int ind = str.length() - i; ind str.length() - i str.length() str.length str i if (str.charAt(ind) == '0')
			return 0; str.charAt(ind) == '0' str.charAt(ind) str.charAt str ind '0' return 0; 0 if (memo[i] != -1)
			return memo[i]; memo[i] != -1 memo[i] memo i -1 1 return memo[i]; memo[i] memo i int res = decode(str, i - 1, memo); res decode(str, i - 1, memo) decode str i - 1 i 1 memo if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		} i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26 i >= 2 i 2 Integer.parseInt(str.substring(ind, ind + 2)) <= 26 Integer.parseInt(str.substring(ind, ind + 2)) Integer.parseInt Integer str.substring(ind, ind + 2) str.substring str ind ind + 2 ind 2 26 {
			res += decode(str, i - 2, memo);
		} res += decode(str, i - 2, memo) res decode(str, i - 2, memo) decode str i - 2 i 2 memo memo[i] = res memo[i] memo i res return res; res String str str int i i int[] memo memo public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	} gcd {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	} if (a == 0)
			return b; a == 0 a 0 return b; b return gcd(b % a, a); gcd(b % a, a) gcd b % a b a a long a a long b b public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	} factorial {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	} BigInteger fac = new BigInteger("1"); fac new BigInteger("1") for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			fac = fac.multiply(BigInteger.valueOf(i));
		} {
			fac = fac.multiply(BigInteger.valueOf(i));
		} fac = fac.multiply(BigInteger.valueOf(i)) fac fac.multiply(BigInteger.valueOf(i)) fac.multiply fac BigInteger.valueOf(i) BigInteger.valueOf BigInteger i return fac.toString(); fac.toString() fac.toString fac int n n class pair {
	int a;
	int b;

	pair(int x, int y) {
		this.a = x;
		this.b = y;
	}
} pair int a; a int b; b pair(int x, int y) {
		this.a = x;
		this.b = y;
	} pair {
		this.a = x;
		this.b = y;
	} this.a = x this.a this this.a x this.b = y this.b this this.b y int x x int y y class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub
		int a = o1.a - o2.a;
		if (a < 0)
			return -1;
		else
			return 1;
	}

} sorting @Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub
		int a = o1.a - o2.a;
		if (a < 0)
			return -1;
		else
			return 1;
	} compare {
		// TODO Auto-generated method stub
		int a = o1.a - o2.a;
		if (a < 0)
			return -1;
		else
			return 1;
	} int a = o1.a - o2.a; a o1.a - o2.a o1.a o1 o1.a o2.a o2 o2.a if (a < 0)
			return -1;
		else
			return 1; a < 0 a 0 return -1; -1 1 return 1; 1 pair o1 o1 pair o2 o2 Comparator public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String args[]) {
		int n=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=scn.nextInt();
		}
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println(mincost(arr, 0,memo));
	}
		public static long mincost(int arr[],int i,long memo[])
		{	int n=arr.length;
			if(i==n-1)
				return 0;
			if(i>=n)
				return Integer.MAX_VALUE;
			if(memo[i]!=-1)
				return memo[i];
			long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
			a=mincost(arr, i+1,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)]);
			b=mincost(arr, i+2,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)]);
			memo[i]=Math.min(a, b);
			return Math.min(a, b);
		}
	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

} public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String args[]) {
		int n=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=scn.nextInt();
		}
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println(mincost(arr, 0,memo));
	}
		public static long mincost(int arr[],int i,long memo[])
		{	int n=arr.length;
			if(i==n-1)
				return 0;
			if(i>=n)
				return Integer.MAX_VALUE;
			if(memo[i]!=-1)
				return memo[i];
			long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
			a=mincost(arr, i+1,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)]);
			b=mincost(arr, i+2,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)]);
			memo[i]=Math.min(a, b);
			return Math.min(a, b);
		}
	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

} Main
//package src;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class Main {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String args[]) {
		int n=scn.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=scn.nextInt();
		}
		long memo[]=new long[n+1];
		Arrays.fill(memo, -1);
		System.out.println(mincost(arr, 0,memo));
	}
		public static long mincost(int arr[],int i,long memo[])
		{	int n=arr.length;
			if(i==n-1)
				return 0;
			if(i>=n)
				return Integer.MAX_VALUE;
			if(memo[i]!=-1)
				return memo[i];
			long a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
			a=mincost(arr, i+1,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+1, n-1)]);
			b=mincost(arr, i+2,memo)+Math.abs(arr[Math.min(i,n-1 )]-arr[Math.min(i+2, n-1)]);
			memo[i]=Math.min(a, b);
			return Math.min(a, b);
		}
	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

}

class pair {
	int a;
	int b;

	pair(int x, int y) {
		this.a = x;
		this.b = y;
	}
}

class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub
		int a = o1.a - o2.a;
		if (a < 0)
			return -1;
		else
			return 1;
	}

}
