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

public class Main{

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       
		
	    int stoneCount = Integer.parseInt(reader.readLine());
        String str[] = reader.readLine().split(" ");
	    int stones[] = new int[stoneCount];
	    
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str[i]);
	    
	     int dp[]  = new int[stoneCount + 1];
	     
	     for(int i=0; i<=stoneCount; i++) dp[i] = -1;
	     
	    int minimumIncurred = solve(stones, 0, stoneCount, dp);
	    
	    System.out.println(minimumIncurred);
	    
	    

	}
	
	public static int solve(int stones[], int i, int stoneCount, int dp[])
	{
		
		if(i==stoneCount-1)
			return 0;
		
		if(dp[i] != -1)
			return dp[i];
		int first = Integer.MAX_VALUE;
		int second = Integer.MAX_VALUE;
		if(i+1<stoneCount) 
		first = Math.abs(stones[i] - stones[i+1])+solve(stones, i+1, stoneCount, dp);
		if(i+2<stoneCount)
		second = Math.abs(stones[i] - stones[i+2])+ solve(stones, i+2, stoneCount, dp);
		dp[i] = Math.min(first, second);
		return Math.min(first, second);	
	}

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

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       
		
	    int stoneCount = Integer.parseInt(reader.readLine());
        String str[] = reader.readLine().split(" ");
	    int stones[] = new int[stoneCount];
	    
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str[i]);
	    
	     int dp[]  = new int[stoneCount + 1];
	     
	     for(int i=0; i<=stoneCount; i++) dp[i] = -1;
	     
	    int minimumIncurred = solve(stones, 0, stoneCount, dp);
	    
	    System.out.println(minimumIncurred);
	    
	    

	}
	
	public static int solve(int stones[], int i, int stoneCount, int dp[])
	{
		
		if(i==stoneCount-1)
			return 0;
		
		if(dp[i] != -1)
			return dp[i];
		int first = Integer.MAX_VALUE;
		int second = Integer.MAX_VALUE;
		if(i+1<stoneCount) 
		first = Math.abs(stones[i] - stones[i+1])+solve(stones, i+1, stoneCount, dp);
		if(i+2<stoneCount)
		second = Math.abs(stones[i] - stones[i+2])+ solve(stones, i+2, stoneCount, dp);
		dp[i] = Math.min(first, second);
		return Math.min(first, second);	
	}

} Main public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       
		
	    int stoneCount = Integer.parseInt(reader.readLine());
        String str[] = reader.readLine().split(" ");
	    int stones[] = new int[stoneCount];
	    
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str[i]);
	    
	     int dp[]  = new int[stoneCount + 1];
	     
	     for(int i=0; i<=stoneCount; i++) dp[i] = -1;
	     
	    int minimumIncurred = solve(stones, 0, stoneCount, dp);
	    
	    System.out.println(minimumIncurred);
	    
	    

	} main {
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       
		
	    int stoneCount = Integer.parseInt(reader.readLine());
        String str[] = reader.readLine().split(" ");
	    int stones[] = new int[stoneCount];
	    
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str[i]);
	    
	     int dp[]  = new int[stoneCount + 1];
	     
	     for(int i=0; i<=stoneCount; i++) dp[i] = -1;
	     
	    int minimumIncurred = solve(stones, 0, stoneCount, dp);
	    
	    System.out.println(minimumIncurred);
	    
	    

	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) int stoneCount = Integer.parseInt(reader.readLine()); stoneCount Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader String str[] = reader.readLine().split(" "); str reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " int stones[] = new int[stoneCount]; stones new int[stoneCount] stoneCount for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str[i]); int i=0; int i=0; i 0 i<stoneCount i stoneCount i++ i++ i stones[i] = Integer.parseInt(str[i]); stones[i] = Integer.parseInt(str[i]) stones[i] stones i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i int dp[]  = new int[stoneCount + 1]; dp new int[stoneCount + 1] stoneCount + 1 stoneCount 1 for(int i=0; i<=stoneCount; i++) dp[i] = -1; int i=0; int i=0; i 0 i<=stoneCount i stoneCount i++ i++ i dp[i] = -1; dp[i] = -1 dp[i] dp i -1 1 int minimumIncurred = solve(stones, 0, stoneCount, dp); minimumIncurred solve(stones, 0, stoneCount, dp) solve stones 0 stoneCount dp System.out.println(minimumIncurred) System.out.println System.out System System.out minimumIncurred String[] args args public static int solve(int stones[], int i, int stoneCount, int dp[])
	{
		
		if(i==stoneCount-1)
			return 0;
		
		if(dp[i] != -1)
			return dp[i];
		int first = Integer.MAX_VALUE;
		int second = Integer.MAX_VALUE;
		if(i+1<stoneCount) 
		first = Math.abs(stones[i] - stones[i+1])+solve(stones, i+1, stoneCount, dp);
		if(i+2<stoneCount)
		second = Math.abs(stones[i] - stones[i+2])+ solve(stones, i+2, stoneCount, dp);
		dp[i] = Math.min(first, second);
		return Math.min(first, second);	
	} solve {
		
		if(i==stoneCount-1)
			return 0;
		
		if(dp[i] != -1)
			return dp[i];
		int first = Integer.MAX_VALUE;
		int second = Integer.MAX_VALUE;
		if(i+1<stoneCount) 
		first = Math.abs(stones[i] - stones[i+1])+solve(stones, i+1, stoneCount, dp);
		if(i+2<stoneCount)
		second = Math.abs(stones[i] - stones[i+2])+ solve(stones, i+2, stoneCount, dp);
		dp[i] = Math.min(first, second);
		return Math.min(first, second);	
	} if(i==stoneCount-1)
			return 0; i==stoneCount-1 i stoneCount-1 stoneCount 1 return 0; 0 if(dp[i] != -1)
			return dp[i]; dp[i] != -1 dp[i] dp i -1 1 return dp[i]; dp[i] dp i int first = Integer.MAX_VALUE; first Integer.MAX_VALUE Integer Integer.MAX_VALUE int second = Integer.MAX_VALUE; second Integer.MAX_VALUE Integer Integer.MAX_VALUE if(i+1<stoneCount) 
		first = Math.abs(stones[i] - stones[i+1])+solve(stones, i+1, stoneCount, dp); i+1<stoneCount i+1 i 1 stoneCount first = Math.abs(stones[i] - stones[i+1])+solve(stones, i+1, stoneCount, dp) first Math.abs(stones[i] - stones[i+1])+solve(stones, i+1, stoneCount, dp) Math.abs(stones[i] - stones[i+1]) Math.abs Math stones[i] - stones[i+1] stones[i] stones i stones[i+1] stones i+1 i 1 solve(stones, i+1, stoneCount, dp) solve stones i+1 i 1 stoneCount dp if(i+2<stoneCount)
		second = Math.abs(stones[i] - stones[i+2])+ solve(stones, i+2, stoneCount, dp); i+2<stoneCount i+2 i 2 stoneCount second = Math.abs(stones[i] - stones[i+2])+ solve(stones, i+2, stoneCount, dp) second Math.abs(stones[i] - stones[i+2])+ solve(stones, i+2, stoneCount, dp) Math.abs(stones[i] - stones[i+2]) Math.abs Math stones[i] - stones[i+2] stones[i] stones i stones[i+2] stones i+2 i 2 solve(stones, i+2, stoneCount, dp) solve stones i+2 i 2 stoneCount dp dp[i] = Math.min(first, second) dp[i] dp i Math.min(first, second) Math.min Math first second return Math.min(first, second); Math.min(first, second) Math.min Math first second int stones[] stones int i i int stoneCount stoneCount int dp[] dp public class Main{

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       
		
	    int stoneCount = Integer.parseInt(reader.readLine());
        String str[] = reader.readLine().split(" ");
	    int stones[] = new int[stoneCount];
	    
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str[i]);
	    
	     int dp[]  = new int[stoneCount + 1];
	     
	     for(int i=0; i<=stoneCount; i++) dp[i] = -1;
	     
	    int minimumIncurred = solve(stones, 0, stoneCount, dp);
	    
	    System.out.println(minimumIncurred);
	    
	    

	}
	
	public static int solve(int stones[], int i, int stoneCount, int dp[])
	{
		
		if(i==stoneCount-1)
			return 0;
		
		if(dp[i] != -1)
			return dp[i];
		int first = Integer.MAX_VALUE;
		int second = Integer.MAX_VALUE;
		if(i+1<stoneCount) 
		first = Math.abs(stones[i] - stones[i+1])+solve(stones, i+1, stoneCount, dp);
		if(i+2<stoneCount)
		second = Math.abs(stones[i] - stones[i+2])+ solve(stones, i+2, stoneCount, dp);
		dp[i] = Math.min(first, second);
		return Math.min(first, second);	
	}

} public class Main{

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       
		
	    int stoneCount = Integer.parseInt(reader.readLine());
        String str[] = reader.readLine().split(" ");
	    int stones[] = new int[stoneCount];
	    
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str[i]);
	    
	     int dp[]  = new int[stoneCount + 1];
	     
	     for(int i=0; i<=stoneCount; i++) dp[i] = -1;
	     
	    int minimumIncurred = solve(stones, 0, stoneCount, dp);
	    
	    System.out.println(minimumIncurred);
	    
	    

	}
	
	public static int solve(int stones[], int i, int stoneCount, int dp[])
	{
		
		if(i==stoneCount-1)
			return 0;
		
		if(dp[i] != -1)
			return dp[i];
		int first = Integer.MAX_VALUE;
		int second = Integer.MAX_VALUE;
		if(i+1<stoneCount) 
		first = Math.abs(stones[i] - stones[i+1])+solve(stones, i+1, stoneCount, dp);
		if(i+2<stoneCount)
		second = Math.abs(stones[i] - stones[i+2])+ solve(stones, i+2, stoneCount, dp);
		dp[i] = Math.min(first, second);
		return Math.min(first, second);	
	}

} Main
import java.util.*;
import java.io.*;

public class Main{

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
       
		
	    int stoneCount = Integer.parseInt(reader.readLine());
        String str[] = reader.readLine().split(" ");
	    int stones[] = new int[stoneCount];
	    
	    for(int i=0;i<stoneCount; i++) stones[i] = Integer.parseInt(str[i]);
	    
	     int dp[]  = new int[stoneCount + 1];
	     
	     for(int i=0; i<=stoneCount; i++) dp[i] = -1;
	     
	    int minimumIncurred = solve(stones, 0, stoneCount, dp);
	    
	    System.out.println(minimumIncurred);
	    
	    

	}
	
	public static int solve(int stones[], int i, int stoneCount, int dp[])
	{
		
		if(i==stoneCount-1)
			return 0;
		
		if(dp[i] != -1)
			return dp[i];
		int first = Integer.MAX_VALUE;
		int second = Integer.MAX_VALUE;
		if(i+1<stoneCount) 
		first = Math.abs(stones[i] - stones[i+1])+solve(stones, i+1, stoneCount, dp);
		if(i+2<stoneCount)
		second = Math.abs(stones[i] - stones[i+2])+ solve(stones, i+2, stoneCount, dp);
		dp[i] = Math.min(first, second);
		return Math.min(first, second);	
	}

}
