import java.util.Scanner;
import java.util.*;
public class Main {
	
	
	
	public static int Frog1(int n, int h[]) {
		int dp[] = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[1]-h[0]);
		
		for(int i=2;i<n;i++) {
			int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1];
			int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2];
			dp[i] = Math.min(op1, op2);
		}
		
		return dp[n-1];
	}
    
    public static void main(String[] arg) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int h[] = new int[n];
        for(int i=0;i<n;i++) {
        	h[i] = s.nextInt();
        }
        System.out.println(Frog1(n,h));
    }
} import java.util.Scanner; Scanner java.util import java.util.*; util.* java public class Main {
	
	
	
	public static int Frog1(int n, int h[]) {
		int dp[] = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[1]-h[0]);
		
		for(int i=2;i<n;i++) {
			int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1];
			int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2];
			dp[i] = Math.min(op1, op2);
		}
		
		return dp[n-1];
	}
    
    public static void main(String[] arg) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int h[] = new int[n];
        for(int i=0;i<n;i++) {
        	h[i] = s.nextInt();
        }
        System.out.println(Frog1(n,h));
    }
} Main public static int Frog1(int n, int h[]) {
		int dp[] = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[1]-h[0]);
		
		for(int i=2;i<n;i++) {
			int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1];
			int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2];
			dp[i] = Math.min(op1, op2);
		}
		
		return dp[n-1];
	} Frog1 {
		int dp[] = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[1]-h[0]);
		
		for(int i=2;i<n;i++) {
			int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1];
			int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2];
			dp[i] = Math.min(op1, op2);
		}
		
		return dp[n-1];
	} int dp[] = new int[n]; dp new int[n] n dp[0] = 0 dp[0] dp 0 0 dp[1] = Math.abs(h[1]-h[0]) dp[1] dp 1 Math.abs(h[1]-h[0]) Math.abs Math h[1]-h[0] h[1] h 1 h[0] h 0 for(int i=2;i<n;i++) {
			int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1];
			int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2];
			dp[i] = Math.min(op1, op2);
		} int i=2; int i=2; i 2 i<n i n i++ i++ i {
			int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1];
			int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2];
			dp[i] = Math.min(op1, op2);
		} {
			int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1];
			int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2];
			dp[i] = Math.min(op1, op2);
		} int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1]; op1 Math.abs(h[i] - h[i-1]) + dp[i-1] Math.abs(h[i] - h[i-1]) Math.abs Math h[i] - h[i-1] h[i] h i h[i-1] h i-1 i 1 dp[i-1] dp i-1 i 1 int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2]; op2 Math.abs(h[i] - h[i-2]) + dp[i-2] Math.abs(h[i] - h[i-2]) Math.abs Math h[i] - h[i-2] h[i] h i h[i-2] h i-2 i 2 dp[i-2] dp i-2 i 2 dp[i] = Math.min(op1, op2) dp[i] dp i Math.min(op1, op2) Math.min Math op1 op2 return dp[n-1]; dp[n-1] dp n-1 n 1 int n n int h[] h public static void main(String[] arg) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int h[] = new int[n];
        for(int i=0;i<n;i++) {
        	h[i] = s.nextInt();
        }
        System.out.println(Frog1(n,h));
    } main {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int h[] = new int[n];
        for(int i=0;i<n;i++) {
        	h[i] = s.nextInt();
        }
        System.out.println(Frog1(n,h));
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int h[] = new int[n]; h new int[n] n for(int i=0;i<n;i++) {
        	h[i] = s.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
        	h[i] = s.nextInt();
        } {
        	h[i] = s.nextInt();
        } h[i] = s.nextInt() h[i] h i s.nextInt() s.nextInt s System.out.println(Frog1(n,h)) System.out.println System.out System System.out Frog1(n,h) Frog1 n h String[] arg arg public class Main {
	
	
	
	public static int Frog1(int n, int h[]) {
		int dp[] = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[1]-h[0]);
		
		for(int i=2;i<n;i++) {
			int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1];
			int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2];
			dp[i] = Math.min(op1, op2);
		}
		
		return dp[n-1];
	}
    
    public static void main(String[] arg) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int h[] = new int[n];
        for(int i=0;i<n;i++) {
        	h[i] = s.nextInt();
        }
        System.out.println(Frog1(n,h));
    }
} public class Main {
	
	
	
	public static int Frog1(int n, int h[]) {
		int dp[] = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[1]-h[0]);
		
		for(int i=2;i<n;i++) {
			int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1];
			int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2];
			dp[i] = Math.min(op1, op2);
		}
		
		return dp[n-1];
	}
    
    public static void main(String[] arg) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int h[] = new int[n];
        for(int i=0;i<n;i++) {
        	h[i] = s.nextInt();
        }
        System.out.println(Frog1(n,h));
    }
} Main
import java.util.Scanner;
import java.util.*;
public class Main {
	
	
	
	public static int Frog1(int n, int h[]) {
		int dp[] = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[1]-h[0]);
		
		for(int i=2;i<n;i++) {
			int op1 = Math.abs(h[i] - h[i-1]) + dp[i-1];
			int op2 = Math.abs(h[i] - h[i-2]) + dp[i-2];
			dp[i] = Math.min(op1, op2);
		}
		
		return dp[n-1];
	}
    
    public static void main(String[] arg) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int h[] = new int[n];
        for(int i=0;i<n;i++) {
        	h[i] = s.nextInt();
        }
        System.out.println(Frog1(n,h));
    }
}