import java.util.*;
import java.io.*;
class Main{
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String in[]=br.readLine().split(" ");
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=Integer.parseInt(in[i]);
		int dp[]=new int[n];
		Arrays.fill(dp,1000000005);	
		dp[0]=0;	
		for(int i=0;i<n;i++){
			if(i+1 < n)
				dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1]));
			if(i+2 < n)
				dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2]));
		}
		System.out.println(dp[n-1]);
	}
} import java.util.*; util.* java import java.io.*; io.* java class Main{
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String in[]=br.readLine().split(" ");
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=Integer.parseInt(in[i]);
		int dp[]=new int[n];
		Arrays.fill(dp,1000000005);	
		dp[0]=0;	
		for(int i=0;i<n;i++){
			if(i+1 < n)
				dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1]));
			if(i+2 < n)
				dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2]));
		}
		System.out.println(dp[n-1]);
	}
} Main public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String in[]=br.readLine().split(" ");
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=Integer.parseInt(in[i]);
		int dp[]=new int[n];
		Arrays.fill(dp,1000000005);	
		dp[0]=0;	
		for(int i=0;i<n;i++){
			if(i+1 < n)
				dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1]));
			if(i+2 < n)
				dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2]));
		}
		System.out.println(dp[n-1]);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String in[]=br.readLine().split(" ");
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=Integer.parseInt(in[i]);
		int dp[]=new int[n];
		Arrays.fill(dp,1000000005);	
		dp[0]=0;	
		for(int i=0;i<n;i++){
			if(i+1 < n)
				dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1]));
			if(i+2 < n)
				dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2]));
		}
		System.out.println(dp[n-1]);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br String in[]=br.readLine().split(" "); in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int arr[]=new int[n]; arr new int[n] n for(int i=0;i<n;i++)
			arr[i]=Integer.parseInt(in[i]); int i=0; int i=0; i 0 i<n i n i++ i++ i arr[i]=Integer.parseInt(in[i]); arr[i]=Integer.parseInt(in[i]) arr[i] arr i Integer.parseInt(in[i]) Integer.parseInt Integer in[i] in i int dp[]=new int[n]; dp new int[n] n Arrays.fill(dp,1000000005) Arrays.fill Arrays dp 1000000005 dp[0]=0 dp[0] dp 0 0 for(int i=0;i<n;i++){
			if(i+1 < n)
				dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1]));
			if(i+2 < n)
				dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2]));
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			if(i+1 < n)
				dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1]));
			if(i+2 < n)
				dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2]));
		} {
			if(i+1 < n)
				dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1]));
			if(i+2 < n)
				dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2]));
		} if(i+1 < n)
				dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1])); i+1 < n i+1 i 1 n dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1])) dp[i+1] dp i+1 i 1 Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1])) Math.min Math dp[i+1] dp i+1 i 1 dp[i]+Math.abs(arr[i]-arr[i+1]) dp[i] dp i Math.abs(arr[i]-arr[i+1]) Math.abs Math arr[i]-arr[i+1] arr[i] arr i arr[i+1] arr i+1 i 1 if(i+2 < n)
				dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2])); i+2 < n i+2 i 2 n dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2])) dp[i+2] dp i+2 i 2 Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2])) Math.min Math dp[i+2] dp i+2 i 2 dp[i]+Math.abs(arr[i]-arr[i+2]) dp[i] dp i Math.abs(arr[i]-arr[i+2]) Math.abs Math arr[i]-arr[i+2] arr[i] arr i arr[i+2] arr 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
import java.util.*;
import java.io.*;
class Main{
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String in[]=br.readLine().split(" ");
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=Integer.parseInt(in[i]);
		int dp[]=new int[n];
		Arrays.fill(dp,1000000005);	
		dp[0]=0;	
		for(int i=0;i<n;i++){
			if(i+1 < n)
				dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(arr[i]-arr[i+1]));
			if(i+2 < n)
				dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(arr[i]-arr[i+2]));
		}
		System.out.println(dp[n-1]);
	}
}