import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0;i < n;i++) h[i] = sc.nextInt();
        long[] memo = new long[n];
        for(int i = 0;i < n;i++) memo[i] = -1;
        System.out.println(dp(n, h, n - 1, memo));
    }

    private static long dp(int n, int[] h, int i, long[] memo) {
        if(memo[i] != -1) return memo[i];
        else {
            long cost1;
            long cost2;
            if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            }
            long result = Long.min(cost1, cost2);
            memo[i] = result;
            return result;
        }
    }

} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0;i < n;i++) h[i] = sc.nextInt();
        long[] memo = new long[n];
        for(int i = 0;i < n;i++) memo[i] = -1;
        System.out.println(dp(n, h, n - 1, memo));
    }

    private static long dp(int n, int[] h, int i, long[] memo) {
        if(memo[i] != -1) return memo[i];
        else {
            long cost1;
            long cost2;
            if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            }
            long result = Long.min(cost1, cost2);
            memo[i] = result;
            return result;
        }
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0;i < n;i++) h[i] = sc.nextInt();
        long[] memo = new long[n];
        for(int i = 0;i < n;i++) memo[i] = -1;
        System.out.println(dp(n, h, n - 1, memo));
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0;i < n;i++) h[i] = sc.nextInt();
        long[] memo = new long[n];
        for(int i = 0;i < n;i++) memo[i] = -1;
        System.out.println(dp(n, h, n - 1, memo));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] h = new int[n]; h new int[n] n for(int i = 0;i < n;i++) h[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i h[i] = sc.nextInt(); h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc long[] memo = new long[n]; memo new long[n] n for(int i = 0;i < n;i++) memo[i] = -1; int i = 0; int i = 0; i 0 i < n i n i++ i++ i memo[i] = -1; memo[i] = -1 memo[i] memo i -1 1 System.out.println(dp(n, h, n - 1, memo)) System.out.println System.out System System.out dp(n, h, n - 1, memo) dp n h n - 1 n 1 memo String[] args args private static long dp(int n, int[] h, int i, long[] memo) {
        if(memo[i] != -1) return memo[i];
        else {
            long cost1;
            long cost2;
            if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            }
            long result = Long.min(cost1, cost2);
            memo[i] = result;
            return result;
        }
    } dp {
        if(memo[i] != -1) return memo[i];
        else {
            long cost1;
            long cost2;
            if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            }
            long result = Long.min(cost1, cost2);
            memo[i] = result;
            return result;
        }
    } if(memo[i] != -1) return memo[i];
        else {
            long cost1;
            long cost2;
            if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            }
            long result = Long.min(cost1, cost2);
            memo[i] = result;
            return result;
        } memo[i] != -1 memo[i] memo i -1 1 return memo[i]; memo[i] memo i {
            long cost1;
            long cost2;
            if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            }
            long result = Long.min(cost1, cost2);
            memo[i] = result;
            return result;
        } long cost1; cost1 long cost2; cost2 if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            } i == 0 i 0 {
                cost1 = 0;
                cost2 = 0;
            } cost1 = 0 cost1 0 cost2 = 0 cost2 0 if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            } i == 1 i 1 {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            } cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]) cost1 dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]) dp(n, h, i - 1, memo) dp n h i - 1 i 1 memo 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 cost2 = Long.MAX_VALUE cost2 Long.MAX_VALUE Long Long.MAX_VALUE {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            } cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]) cost1 dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]) dp(n, h, i - 1, memo) dp n h i - 1 i 1 memo 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 cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]) cost2 dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]) dp(n, h, i - 2, memo) dp n h i - 2 i 2 memo 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 long result = Long.min(cost1, cost2); result Long.min(cost1, cost2) Long.min Long cost1 cost2 memo[i] = result memo[i] memo i result return result; result int n n int[] h h int i i long[] memo memo public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0;i < n;i++) h[i] = sc.nextInt();
        long[] memo = new long[n];
        for(int i = 0;i < n;i++) memo[i] = -1;
        System.out.println(dp(n, h, n - 1, memo));
    }

    private static long dp(int n, int[] h, int i, long[] memo) {
        if(memo[i] != -1) return memo[i];
        else {
            long cost1;
            long cost2;
            if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            }
            long result = Long.min(cost1, cost2);
            memo[i] = result;
            return result;
        }
    }

} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0;i < n;i++) h[i] = sc.nextInt();
        long[] memo = new long[n];
        for(int i = 0;i < n;i++) memo[i] = -1;
        System.out.println(dp(n, h, n - 1, memo));
    }

    private static long dp(int n, int[] h, int i, long[] memo) {
        if(memo[i] != -1) return memo[i];
        else {
            long cost1;
            long cost2;
            if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            }
            long result = Long.min(cost1, cost2);
            memo[i] = result;
            return result;
        }
    }

} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0;i < n;i++) h[i] = sc.nextInt();
        long[] memo = new long[n];
        for(int i = 0;i < n;i++) memo[i] = -1;
        System.out.println(dp(n, h, n - 1, memo));
    }

    private static long dp(int n, int[] h, int i, long[] memo) {
        if(memo[i] != -1) return memo[i];
        else {
            long cost1;
            long cost2;
            if(i == 0) {
                cost1 = 0;
                cost2 = 0;
            }
            else if(i == 1) {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = Long.MAX_VALUE;
            }
            else {
                cost1 = dp(n, h, i - 1, memo) + Math.abs(h[i] - h[i - 1]);
                cost2 = dp(n, h, i - 2, memo) + Math.abs(h[i] - h[i - 2]);  
            }
            long result = Long.min(cost1, cost2);
            memo[i] = result;
            return result;
        }
    }

}
