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

class Main {

    // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    }

    static void solve(long N, long[] h){
        if (N == 2) {
            System.out.print(h[1] - h[0]);
            return;
        }

        long[] dp = new long[(int)(N+1)];
        dp[2] = Math.abs(h[1] - h[0]);
        
        for (int i = 3; i <= N; i++){
            dp[i] = Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            );
        }
        System.out.print(dp[(int)(N)]);
        return;
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main {

    // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    }

    static void solve(long N, long[] h){
        if (N == 2) {
            System.out.print(h[1] - h[0]);
            return;
        }

        long[] dp = new long[(int)(N+1)];
        dp[2] = Math.abs(h[1] - h[0]);
        
        for (int i = 3; i <= N; i++){
            dp[i] = Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            );
        }
        System.out.print(dp[(int)(N)]);
        return;
    }
} Main // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    } main {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long N; N N = sc.nextLong() N sc.nextLong() sc.nextLong sc long[] h = new long[(int)(N)]; h new long[(int)(N)] (int)(N) for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        } int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
                h[i] = sc.nextLong();
        } {
                h[i] = sc.nextLong();
        } h[i] = sc.nextLong() h[i] h i sc.nextLong() sc.nextLong sc solve(N, h) solve N h String[] args args static void solve(long N, long[] h){
        if (N == 2) {
            System.out.print(h[1] - h[0]);
            return;
        }

        long[] dp = new long[(int)(N+1)];
        dp[2] = Math.abs(h[1] - h[0]);
        
        for (int i = 3; i <= N; i++){
            dp[i] = Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            );
        }
        System.out.print(dp[(int)(N)]);
        return;
    } solve {
        if (N == 2) {
            System.out.print(h[1] - h[0]);
            return;
        }

        long[] dp = new long[(int)(N+1)];
        dp[2] = Math.abs(h[1] - h[0]);
        
        for (int i = 3; i <= N; i++){
            dp[i] = Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            );
        }
        System.out.print(dp[(int)(N)]);
        return;
    } if (N == 2) {
            System.out.print(h[1] - h[0]);
            return;
        } N == 2 N 2 {
            System.out.print(h[1] - h[0]);
            return;
        } System.out.print(h[1] - h[0]) System.out.print System.out System System.out h[1] - h[0] h[1] h 1 h[0] h 0 return; long[] dp = new long[(int)(N+1)]; dp new long[(int)(N+1)] (int)(N+1) N 1 dp[2] = Math.abs(h[1] - h[0]) dp[2] dp 2 Math.abs(h[1] - h[0]) Math.abs Math h[1] - h[0] h[1] h 1 h[0] h 0 for (int i = 3; i <= N; i++){
            dp[i] = Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            );
        } int i = 3; int i = 3; i 3 i <= N i N i++ i++ i {
            dp[i] = Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            );
        } {
            dp[i] = Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            );
        } dp[i] = Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            ) dp[i] dp i Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            ) Math.min Math dp[i-1] + Math.abs(h[i-1] - h[i-2]) dp[i-1] dp i-1 i 1 Math.abs(h[i-1] - h[i-2]) Math.abs Math h[i-1] - h[i-2] h[i-1] h i-1 i 1 h[i-2] h i-2 i 2 dp[i-2] + Math.abs(h[i-1] - h[i-3]) dp[i-2] dp i-2 i 2 Math.abs(h[i-1] - h[i-3]) Math.abs Math h[i-1] - h[i-3] h[i-1] h i-1 i 1 h[i-3] h i-3 i 3 System.out.print(dp[(int)(N)]) System.out.print System.out System System.out dp[(int)(N)] dp (int)(N) return; long N N long[] h h
import java.io.*;
import java.util.*;

class Main {

    // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    }

    static void solve(long N, long[] h){
        if (N == 2) {
            System.out.print(h[1] - h[0]);
            return;
        }

        long[] dp = new long[(int)(N+1)];
        dp[2] = Math.abs(h[1] - h[0]);
        
        for (int i = 3; i <= N; i++){
            dp[i] = Math.min(
                dp[i-1] + Math.abs(h[i-1] - h[i-2]),
                dp[i-2] + Math.abs(h[i-1] - h[i-3])
            );
        }
        System.out.print(dp[(int)(N)]);
        return;
    }
}
