import java.util.*;

public class Main{
	public static int n;
	public static int [] arr;
	public static int[] dp;
	public static int minCost(int pos)
	{
		if(pos>=n-1) 
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int onestep=Integer.MAX_VALUE;
		int twostep=Integer.MAX_VALUE;
		if(pos+1<n)
		{
			onestep=Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1);
		//	System.out.println(onestep);
		}
		if(pos+2<n)
		{
			twostep=Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2);
			//System.out.println(twostep);
		}
		return dp[pos]=Math.min(onestep, twostep);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(minCost(0));
		
	}

} import java.util.*; util.* java public class Main{
	public static int n;
	public static int [] arr;
	public static int[] dp;
	public static int minCost(int pos)
	{
		if(pos>=n-1) 
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int onestep=Integer.MAX_VALUE;
		int twostep=Integer.MAX_VALUE;
		if(pos+1<n)
		{
			onestep=Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1);
		//	System.out.println(onestep);
		}
		if(pos+2<n)
		{
			twostep=Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2);
			//System.out.println(twostep);
		}
		return dp[pos]=Math.min(onestep, twostep);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(minCost(0));
		
	}

} Main public static int n; n public static int [] arr; arr public static int[] dp; dp public static int minCost(int pos)
	{
		if(pos>=n-1) 
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int onestep=Integer.MAX_VALUE;
		int twostep=Integer.MAX_VALUE;
		if(pos+1<n)
		{
			onestep=Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1);
		//	System.out.println(onestep);
		}
		if(pos+2<n)
		{
			twostep=Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2);
			//System.out.println(twostep);
		}
		return dp[pos]=Math.min(onestep, twostep);
	} minCost {
		if(pos>=n-1) 
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int onestep=Integer.MAX_VALUE;
		int twostep=Integer.MAX_VALUE;
		if(pos+1<n)
		{
			onestep=Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1);
		//	System.out.println(onestep);
		}
		if(pos+2<n)
		{
			twostep=Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2);
			//System.out.println(twostep);
		}
		return dp[pos]=Math.min(onestep, twostep);
	} if(pos>=n-1) 
			return 0; pos>=n-1 pos n-1 n 1 return 0; 0 if(dp[pos]!=-1)
			return dp[pos]; dp[pos]!=-1 dp[pos] dp pos -1 1 return dp[pos]; dp[pos] dp pos int onestep=Integer.MAX_VALUE; onestep Integer.MAX_VALUE Integer Integer.MAX_VALUE int twostep=Integer.MAX_VALUE; twostep Integer.MAX_VALUE Integer Integer.MAX_VALUE if(pos+1<n)
		{
			onestep=Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1);
		//	System.out.println(onestep);
		} pos+1<n pos+1 pos 1 n {
			onestep=Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1);
		//	System.out.println(onestep);
		} onestep=Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1) onestep Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1) Math.abs(arr[pos]-arr[pos+1]) Math.abs Math arr[pos]-arr[pos+1] arr[pos] arr pos arr[pos+1] arr pos+1 pos 1 minCost(pos+1) minCost pos+1 pos 1 if(pos+2<n)
		{
			twostep=Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2);
			//System.out.println(twostep);
		} pos+2<n pos+2 pos 2 n {
			twostep=Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2);
			//System.out.println(twostep);
		} twostep=Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2) twostep Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2) Math.abs(arr[pos]-arr[pos+2]) Math.abs Math arr[pos]-arr[pos+2] arr[pos] arr pos arr[pos+2] arr pos+2 pos 2 minCost(pos+2) minCost pos+2 pos 2 return dp[pos]=Math.min(onestep, twostep); dp[pos]=Math.min(onestep, twostep) dp[pos] dp pos Math.min(onestep, twostep) Math.min Math onestep twostep int pos pos public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(minCost(0));
		
	} main {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(minCost(0));
		
	} Scanner in=new Scanner(System.in); in new Scanner(System.in) n=in.nextInt() n in.nextInt() in.nextInt in arr=new int[n] arr new int[n] n dp=new int[n] dp new int[n] n for(int i=0;i<n;i++)
			arr[i]=in.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i arr[i]=in.nextInt(); arr[i]=in.nextInt() arr[i] arr i in.nextInt() in.nextInt in Arrays.fill(dp,-1) Arrays.fill Arrays dp -1 1 System.out.println(minCost(0)) System.out.println System.out System System.out minCost(0) minCost 0 String[] args args public class Main{
	public static int n;
	public static int [] arr;
	public static int[] dp;
	public static int minCost(int pos)
	{
		if(pos>=n-1) 
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int onestep=Integer.MAX_VALUE;
		int twostep=Integer.MAX_VALUE;
		if(pos+1<n)
		{
			onestep=Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1);
		//	System.out.println(onestep);
		}
		if(pos+2<n)
		{
			twostep=Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2);
			//System.out.println(twostep);
		}
		return dp[pos]=Math.min(onestep, twostep);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(minCost(0));
		
	}

} public class Main{
	public static int n;
	public static int [] arr;
	public static int[] dp;
	public static int minCost(int pos)
	{
		if(pos>=n-1) 
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int onestep=Integer.MAX_VALUE;
		int twostep=Integer.MAX_VALUE;
		if(pos+1<n)
		{
			onestep=Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1);
		//	System.out.println(onestep);
		}
		if(pos+2<n)
		{
			twostep=Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2);
			//System.out.println(twostep);
		}
		return dp[pos]=Math.min(onestep, twostep);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(minCost(0));
		
	}

} Main
import java.util.*;

public class Main{
	public static int n;
	public static int [] arr;
	public static int[] dp;
	public static int minCost(int pos)
	{
		if(pos>=n-1) 
			return 0;
		if(dp[pos]!=-1)
			return dp[pos];
		int onestep=Integer.MAX_VALUE;
		int twostep=Integer.MAX_VALUE;
		if(pos+1<n)
		{
			onestep=Math.abs(arr[pos]-arr[pos+1])+minCost(pos+1);
		//	System.out.println(onestep);
		}
		if(pos+2<n)
		{
			twostep=Math.abs(arr[pos]-arr[pos+2])+minCost(pos+2);
			//System.out.println(twostep);
		}
		return dp[pos]=Math.min(onestep, twostep);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		n=in.nextInt();
		arr=new int[n];
		dp=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=in.nextInt();
		Arrays.fill(dp,-1);
		System.out.println(minCost(0));
		
	}

}
