import java.util.*;
import java.io.*;

public class Main {
	static int dp[];
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return Integer.MAX_VALUE-100;
		if(i==a.length-1)
			return 0;
		
		
		int op1=Integer.MAX_VALUE,op2=Integer.MAX_VALUE;
		if(i+1<a.length)
		op1=Math.abs(a[i]-a[i+1])+rec(i+1, a);
		if(i+2<a.length)
		op2=Math.abs(a[i]-a[i+2])+rec(i+2, a);
		
		
		return dp[i]= Math.min(op1, op2);
	}
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
	static int dp[];
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return Integer.MAX_VALUE-100;
		if(i==a.length-1)
			return 0;
		
		
		int op1=Integer.MAX_VALUE,op2=Integer.MAX_VALUE;
		if(i+1<a.length)
		op1=Math.abs(a[i]-a[i+1])+rec(i+1, a);
		if(i+2<a.length)
		op2=Math.abs(a[i]-a[i+2])+rec(i+2, a);
		
		
		return dp[i]= Math.min(op1, op2);
	}
} Main static int dp[]; dp public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	} main {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	} Scanner s=new Scanner(System.in); s new Scanner(System.in) int n=s.nextInt(); n s.nextInt() s.nextInt s int a[]=new int[n]; a new int[n] n for(int i=0;i<n;i++)
			a[i]=s.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i]=s.nextInt(); a[i]=s.nextInt() a[i] a i s.nextInt() s.nextInt s dp=new int[n] dp new int[n] n Arrays.fill(dp, -1) Arrays.fill Arrays dp -1 1 System.out.println(rec(0,a)) System.out.println System.out System System.out rec(0,a) rec 0 a String[] args args private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return Integer.MAX_VALUE-100;
		if(i==a.length-1)
			return 0;
		
		
		int op1=Integer.MAX_VALUE,op2=Integer.MAX_VALUE;
		if(i+1<a.length)
		op1=Math.abs(a[i]-a[i+1])+rec(i+1, a);
		if(i+2<a.length)
		op2=Math.abs(a[i]-a[i+2])+rec(i+2, a);
		
		
		return dp[i]= Math.min(op1, op2);
	} rec {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return Integer.MAX_VALUE-100;
		if(i==a.length-1)
			return 0;
		
		
		int op1=Integer.MAX_VALUE,op2=Integer.MAX_VALUE;
		if(i+1<a.length)
		op1=Math.abs(a[i]-a[i+1])+rec(i+1, a);
		if(i+2<a.length)
		op2=Math.abs(a[i]-a[i+2])+rec(i+2, a);
		
		
		return dp[i]= Math.min(op1, op2);
	} if(dp[i]!=-1)
			return dp[i]; dp[i]!=-1 dp[i] dp i -1 1 return dp[i]; dp[i] dp i if(i>=a.length)
			return Integer.MAX_VALUE-100; i>=a.length i a.length a a.length return Integer.MAX_VALUE-100; Integer.MAX_VALUE-100 Integer.MAX_VALUE Integer Integer.MAX_VALUE 100 if(i==a.length-1)
			return 0; i==a.length-1 i a.length-1 a.length a a.length 1 return 0; 0 int op1=Integer.MAX_VALUE op1 Integer.MAX_VALUE Integer Integer.MAX_VALUE op2=Integer.MAX_VALUE; op2 Integer.MAX_VALUE Integer Integer.MAX_VALUE if(i+1<a.length)
		op1=Math.abs(a[i]-a[i+1])+rec(i+1, a); i+1<a.length i+1 i 1 a.length a a.length op1=Math.abs(a[i]-a[i+1])+rec(i+1, a) op1 Math.abs(a[i]-a[i+1])+rec(i+1, a) Math.abs(a[i]-a[i+1]) Math.abs Math a[i]-a[i+1] a[i] a i a[i+1] a i+1 i 1 rec(i+1, a) rec i+1 i 1 a if(i+2<a.length)
		op2=Math.abs(a[i]-a[i+2])+rec(i+2, a); i+2<a.length i+2 i 2 a.length a a.length op2=Math.abs(a[i]-a[i+2])+rec(i+2, a) op2 Math.abs(a[i]-a[i+2])+rec(i+2, a) Math.abs(a[i]-a[i+2]) Math.abs Math a[i]-a[i+2] a[i] a i a[i+2] a i+2 i 2 rec(i+2, a) rec i+2 i 2 a return dp[i]= Math.min(op1, op2); dp[i]= Math.min(op1, op2) dp[i] dp i Math.min(op1, op2) Math.min Math op1 op2 int i i int[] a a public class Main {
	static int dp[];
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return Integer.MAX_VALUE-100;
		if(i==a.length-1)
			return 0;
		
		
		int op1=Integer.MAX_VALUE,op2=Integer.MAX_VALUE;
		if(i+1<a.length)
		op1=Math.abs(a[i]-a[i+1])+rec(i+1, a);
		if(i+2<a.length)
		op2=Math.abs(a[i]-a[i+2])+rec(i+2, a);
		
		
		return dp[i]= Math.min(op1, op2);
	}
} public class Main {
	static int dp[];
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return Integer.MAX_VALUE-100;
		if(i==a.length-1)
			return 0;
		
		
		int op1=Integer.MAX_VALUE,op2=Integer.MAX_VALUE;
		if(i+1<a.length)
		op1=Math.abs(a[i]-a[i+1])+rec(i+1, a);
		if(i+2<a.length)
		op2=Math.abs(a[i]-a[i+2])+rec(i+2, a);
		
		
		return dp[i]= Math.min(op1, op2);
	}
} Main
import java.util.*;
import java.io.*;

public class Main {
	static int dp[];
	public static void main(String[] args) throws IOException {	
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		
		System.out.println(rec(0,a));
		
	}

	private static int rec(int i, int[] a) {
		if(dp[i]!=-1)
			return dp[i];
		if(i>=a.length)
			return Integer.MAX_VALUE-100;
		if(i==a.length-1)
			return 0;
		
		
		int op1=Integer.MAX_VALUE,op2=Integer.MAX_VALUE;
		if(i+1<a.length)
		op1=Math.abs(a[i]-a[i+1])+rec(i+1, a);
		if(i+2<a.length)
		op2=Math.abs(a[i]-a[i+2])+rec(i+2, a);
		
		
		return dp[i]= Math.min(op1, op2);
	}
}