/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		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();
		}
		
		int dp[]=new int[n];
		dp[0]=0;
		dp[1]=Math.abs(a[0]-a[1]);
		for(int i=2;i<n;i++)
		{
		    dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
		}
		System.out.println(dp[n-1]);
	}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		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();
		}
		
		int dp[]=new int[n];
		dp[0]=0;
		dp[1]=Math.abs(a[0]-a[1]);
		for(int i=2;i<n;i++)
		{
		    dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
		}
		System.out.println(dp[n-1]);
	}
} Main public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		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();
		}
		
		int dp[]=new int[n];
		dp[0]=0;
		dp[1]=Math.abs(a[0]-a[1]);
		for(int i=2;i<n;i++)
		{
		    dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
		}
		System.out.println(dp[n-1]);
	} main {
		// your code goes here
		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();
		}
		
		int dp[]=new int[n];
		dp[0]=0;
		dp[1]=Math.abs(a[0]-a[1]);
		for(int i=2;i<n;i++)
		{
		    dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
		}
		System.out.println(dp[n-1]);
	} 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]=s.nextInt() a[i] a i s.nextInt() s.nextInt s int dp[]=new int[n]; dp new int[n] n dp[0]=0 dp[0] dp 0 0 dp[1]=Math.abs(a[0]-a[1]) dp[1] dp 1 Math.abs(a[0]-a[1]) Math.abs Math a[0]-a[1] a[0] a 0 a[1] a 1 for(int i=2;i<n;i++)
		{
		    dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
		} int i=2; int i=2; i 2 i<n i n i++ i++ i {
		    dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
		} {
		    dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
		} dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]) dp[i] dp i Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]) Math.min Math Math.abs(a[i]-a[i-1])+dp[i-1] 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 dp[i-1] dp i-1 i 1 Math.abs(a[i]-a[i-2])+dp[i-2] 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 dp[i-2] dp 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
/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		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();
		}
		
		int dp[]=new int[n];
		dp[0]=0;
		dp[1]=Math.abs(a[0]-a[1]);
		for(int i=2;i<n;i++)
		{
		    dp[i]=Math.min(Math.abs(a[i]-a[i-1])+dp[i-1],Math.abs(a[i]-a[i-2])+dp[i-2]);
		}
		System.out.println(dp[n-1]);
	}
}
