import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        int[] dp = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        }

//        // もらうDP
//        dp[1] = Math.abs(h[0] - h[1]);
//        for(int i = 2; i < N; i++) {
//            dp[i] = Math.min(Math.abs(h[i] - h[i-1]) + dp[i-1], Math.abs(h[i] - h[i-2]) + dp[i-2]);
//        }
        // 配るDP
        dp[0] = 0;
        for(int i = 0; i < N-2; i++) {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        }
        dp[N-1] = Math.min(Math.abs(h[N-2] - h[N-1]) + dp[N-2], dp[N-1]);

        System.out.println(dp[N-1]);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        int[] dp = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        }

//        // もらうDP
//        dp[1] = Math.abs(h[0] - h[1]);
//        for(int i = 2; i < N; i++) {
//            dp[i] = Math.min(Math.abs(h[i] - h[i-1]) + dp[i-1], Math.abs(h[i] - h[i-2]) + dp[i-2]);
//        }
        // 配るDP
        dp[0] = 0;
        for(int i = 0; i < N-2; i++) {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        }
        dp[N-1] = Math.min(Math.abs(h[N-2] - h[N-1]) + dp[N-2], dp[N-1]);

        System.out.println(dp[N-1]);
    }
} Main public static void main(String[] args) {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        int[] dp = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        }

//        // もらうDP
//        dp[1] = Math.abs(h[0] - h[1]);
//        for(int i = 2; i < N; i++) {
//            dp[i] = Math.min(Math.abs(h[i] - h[i-1]) + dp[i-1], Math.abs(h[i] - h[i-2]) + dp[i-2]);
//        }
        // 配るDP
        dp[0] = 0;
        for(int i = 0; i < N-2; i++) {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        }
        dp[N-1] = Math.min(Math.abs(h[N-2] - h[N-1]) + dp[N-2], dp[N-1]);

        System.out.println(dp[N-1]);
    } run {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        int[] dp = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        }

//        // もらうDP
//        dp[1] = Math.abs(h[0] - h[1]);
//        for(int i = 2; i < N; i++) {
//            dp[i] = Math.min(Math.abs(h[i] - h[i-1]) + dp[i-1], Math.abs(h[i] - h[i-2]) + dp[i-2]);
//        }
        // 配るDP
        dp[0] = 0;
        for(int i = 0; i < N-2; i++) {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        }
        dp[N-1] = Math.min(Math.abs(h[N-2] - h[N-1]) + dp[N-2], dp[N-1]);

        System.out.println(dp[N-1]);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] h = new int[N]; h new int[N] N int[] dp = new int[N]; dp new int[N] N for(int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        } {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        } h[i] = scanner.nextInt() h[i] h i scanner.nextInt() scanner.nextInt scanner dp[i] = Integer.MAX_VALUE dp[i] dp i Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[0] = 0 dp[0] dp 0 0 for(int i = 0; i < N-2; i++) {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        } int i = 0; int i = 0; i 0 i < N-2 i N-2 N 2 i++ i++ i {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        } {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        } dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]) dp[i+1] dp i+1 i 1 Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]) Math.min Math Math.abs(h[i] - h[i+1]) + dp[i] 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] dp i dp[i+1] dp i+1 i 1 dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]) dp[i+2] dp i+2 i 2 Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]) Math.min Math Math.abs(h[i] - h[i+2]) + dp[i] 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] dp i dp[i+2] dp i+2 i 2 dp[N-1] = Math.min(Math.abs(h[N-2] - h[N-1]) + dp[N-2], dp[N-1]) dp[N-1] dp N-1 N 1 Math.min(Math.abs(h[N-2] - h[N-1]) + dp[N-2], dp[N-1]) Math.min Math Math.abs(h[N-2] - h[N-1]) + dp[N-2] Math.abs(h[N-2] - h[N-1]) Math.abs Math h[N-2] - h[N-1] h[N-2] h N-2 N 2 h[N-1] h N-1 N 1 dp[N-2] dp N-2 N 2 dp[N-1] dp N-1 N 1 System.out.println(dp[N-1]) System.out.println System.out System System.out dp[N-1] dp N-1 N 1 public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        int[] dp = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        }

//        // もらうDP
//        dp[1] = Math.abs(h[0] - h[1]);
//        for(int i = 2; i < N; i++) {
//            dp[i] = Math.min(Math.abs(h[i] - h[i-1]) + dp[i-1], Math.abs(h[i] - h[i-2]) + dp[i-2]);
//        }
        // 配るDP
        dp[0] = 0;
        for(int i = 0; i < N-2; i++) {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        }
        dp[N-1] = Math.min(Math.abs(h[N-2] - h[N-1]) + dp[N-2], dp[N-1]);

        System.out.println(dp[N-1]);
    }
} public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        int[] dp = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        }

//        // もらうDP
//        dp[1] = Math.abs(h[0] - h[1]);
//        for(int i = 2; i < N; i++) {
//            dp[i] = Math.min(Math.abs(h[i] - h[i-1]) + dp[i-1], Math.abs(h[i] - h[i-2]) + dp[i-2]);
//        }
        // 配るDP
        dp[0] = 0;
        for(int i = 0; i < N-2; i++) {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        }
        dp[N-1] = Math.min(Math.abs(h[N-2] - h[N-1]) + dp[N-2], dp[N-1]);

        System.out.println(dp[N-1]);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] h = new int[N];
        int[] dp = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = scanner.nextInt();
            dp[i] = Integer.MAX_VALUE;
        }

//        // もらうDP
//        dp[1] = Math.abs(h[0] - h[1]);
//        for(int i = 2; i < N; i++) {
//            dp[i] = Math.min(Math.abs(h[i] - h[i-1]) + dp[i-1], Math.abs(h[i] - h[i-2]) + dp[i-2]);
//        }
        // 配るDP
        dp[0] = 0;
        for(int i = 0; i < N-2; i++) {
            dp[i+1] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i], dp[i+1]);
            dp[i+2] = Math.min(Math.abs(h[i] - h[i+2]) + dp[i], dp[i+2]);
        }
        dp[N-1] = Math.min(Math.abs(h[N-2] - h[N-1]) + dp[N-2], dp[N-1]);

        System.out.println(dp[N-1]);
    }
}
