import java.util.*;
public class Main{

static int[] dp=new int[10000001];
	
	
	public static int solve(int[] arr,int i,int n)
	{
		if(i==n-1)
		{
			return Math.abs(arr[i]-arr[n-1]);
		}
		if(dp[i]!=-1)
		{
			return dp[i];
		}
		int ans=solve(arr,i+1,n)+Math.abs(arr[i]-arr[i+1]);
		if(i<n-2)
		{
			ans=Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2]));
		}
		return dp[i]=ans;
	}

	public static void main(String[] args) {
		Arrays.fill(dp, 0,10000000,-1);
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
			
		}
		System.out.println(solve(arr,0,n));
		sc.close();

	}

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

static int[] dp=new int[10000001];
	
	
	public static int solve(int[] arr,int i,int n)
	{
		if(i==n-1)
		{
			return Math.abs(arr[i]-arr[n-1]);
		}
		if(dp[i]!=-1)
		{
			return dp[i];
		}
		int ans=solve(arr,i+1,n)+Math.abs(arr[i]-arr[i+1]);
		if(i<n-2)
		{
			ans=Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2]));
		}
		return dp[i]=ans;
	}

	public static void main(String[] args) {
		Arrays.fill(dp, 0,10000000,-1);
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
			
		}
		System.out.println(solve(arr,0,n));
		sc.close();

	}

} Main static int[] dp=new int[10000001]; dp new int[10000001] 10000001 public static int solve(int[] arr,int i,int n)
	{
		if(i==n-1)
		{
			return Math.abs(arr[i]-arr[n-1]);
		}
		if(dp[i]!=-1)
		{
			return dp[i];
		}
		int ans=solve(arr,i+1,n)+Math.abs(arr[i]-arr[i+1]);
		if(i<n-2)
		{
			ans=Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2]));
		}
		return dp[i]=ans;
	} solve {
		if(i==n-1)
		{
			return Math.abs(arr[i]-arr[n-1]);
		}
		if(dp[i]!=-1)
		{
			return dp[i];
		}
		int ans=solve(arr,i+1,n)+Math.abs(arr[i]-arr[i+1]);
		if(i<n-2)
		{
			ans=Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2]));
		}
		return dp[i]=ans;
	} if(i==n-1)
		{
			return Math.abs(arr[i]-arr[n-1]);
		} i==n-1 i n-1 n 1 {
			return Math.abs(arr[i]-arr[n-1]);
		} return Math.abs(arr[i]-arr[n-1]); Math.abs(arr[i]-arr[n-1]) Math.abs Math arr[i]-arr[n-1] arr[i] arr i arr[n-1] arr n-1 n 1 if(dp[i]!=-1)
		{
			return dp[i];
		} dp[i]!=-1 dp[i] dp i -1 1 {
			return dp[i];
		} return dp[i]; dp[i] dp i int ans=solve(arr,i+1,n)+Math.abs(arr[i]-arr[i+1]); ans solve(arr,i+1,n)+Math.abs(arr[i]-arr[i+1]) solve(arr,i+1,n) solve arr i+1 i 1 n 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<n-2)
		{
			ans=Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2]));
		} i<n-2 i n-2 n 2 {
			ans=Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2]));
		} ans=Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2])) ans Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2])) Math.min Math ans solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2]) solve(arr,i+2,n) solve arr i+2 i 2 n 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 return dp[i]=ans; dp[i]=ans dp[i] dp i ans int[] arr arr int i i int n n public static void main(String[] args) {
		Arrays.fill(dp, 0,10000000,-1);
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
			
		}
		System.out.println(solve(arr,0,n));
		sc.close();

	} main {
		Arrays.fill(dp, 0,10000000,-1);
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
			
		}
		System.out.println(solve(arr,0,n));
		sc.close();

	} Arrays.fill(dp, 0,10000000,-1) Arrays.fill Arrays dp 0 10000000 -1 1 Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr=new int[n]; arr new int[n] n for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
			
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			arr[i]=sc.nextInt();
			
		} {
			arr[i]=sc.nextInt();
			
		} arr[i]=sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc System.out.println(solve(arr,0,n)) System.out.println System.out System System.out solve(arr,0,n) solve arr 0 n sc.close() sc.close sc String[] args args public class Main{

static int[] dp=new int[10000001];
	
	
	public static int solve(int[] arr,int i,int n)
	{
		if(i==n-1)
		{
			return Math.abs(arr[i]-arr[n-1]);
		}
		if(dp[i]!=-1)
		{
			return dp[i];
		}
		int ans=solve(arr,i+1,n)+Math.abs(arr[i]-arr[i+1]);
		if(i<n-2)
		{
			ans=Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2]));
		}
		return dp[i]=ans;
	}

	public static void main(String[] args) {
		Arrays.fill(dp, 0,10000000,-1);
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
			
		}
		System.out.println(solve(arr,0,n));
		sc.close();

	}

} public class Main{

static int[] dp=new int[10000001];
	
	
	public static int solve(int[] arr,int i,int n)
	{
		if(i==n-1)
		{
			return Math.abs(arr[i]-arr[n-1]);
		}
		if(dp[i]!=-1)
		{
			return dp[i];
		}
		int ans=solve(arr,i+1,n)+Math.abs(arr[i]-arr[i+1]);
		if(i<n-2)
		{
			ans=Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2]));
		}
		return dp[i]=ans;
	}

	public static void main(String[] args) {
		Arrays.fill(dp, 0,10000000,-1);
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
			
		}
		System.out.println(solve(arr,0,n));
		sc.close();

	}

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

static int[] dp=new int[10000001];
	
	
	public static int solve(int[] arr,int i,int n)
	{
		if(i==n-1)
		{
			return Math.abs(arr[i]-arr[n-1]);
		}
		if(dp[i]!=-1)
		{
			return dp[i];
		}
		int ans=solve(arr,i+1,n)+Math.abs(arr[i]-arr[i+1]);
		if(i<n-2)
		{
			ans=Math.min(ans,solve(arr,i+2,n)+Math.abs(arr[i]-arr[i+2]));
		}
		return dp[i]=ans;
	}

	public static void main(String[] args) {
		Arrays.fill(dp, 0,10000000,-1);
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=sc.nextInt();
			
		}
		System.out.println(solve(arr,0,n));
		sc.close();

	}

}
