import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] stones = new int[N];
        for (int i = 0; i < N; i++) {
            stones[i] = sc.nextInt();
        }
        int[] cost = new int[N];
        cost[0] = 0;
        cost[1] = Math.abs(stones[1] - stones[0]);
        for (int i = 2; i < N; i++) {
            int cost1 = Math.abs(stones[i] - stones[i-1]) + cost[i-1];
            int cost2 = Math.abs(stones[i] - stones[i-2]) + cost[i-2];
            cost[i] = Math.min(cost1, cost2);
        }
        System.out.println(cost[N-1]);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] stones = new int[N];
        for (int i = 0; i < N; i++) {
            stones[i] = sc.nextInt();
        }
        int[] cost = new int[N];
        cost[0] = 0;
        cost[1] = Math.abs(stones[1] - stones[0]);
        for (int i = 2; i < N; i++) {
            int cost1 = Math.abs(stones[i] - stones[i-1]) + cost[i-1];
            int cost2 = Math.abs(stones[i] - stones[i-2]) + cost[i-2];
            cost[i] = Math.min(cost1, cost2);
        }
        System.out.println(cost[N-1]);
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] stones = new int[N];
        for (int i = 0; i < N; i++) {
            stones[i] = sc.nextInt();
        }
        int[] cost = new int[N];
        cost[0] = 0;
        cost[1] = Math.abs(stones[1] - stones[0]);
        for (int i = 2; i < N; i++) {
            int cost1 = Math.abs(stones[i] - stones[i-1]) + cost[i-1];
            int cost2 = Math.abs(stones[i] - stones[i-2]) + cost[i-2];
            cost[i] = Math.min(cost1, cost2);
        }
        System.out.println(cost[N-1]);
    } main {

        Scanner sc = new Scanner(System.in);

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

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] stones = new int[N];
        for (int i = 0; i < N; i++) {
            stones[i] = sc.nextInt();
        }
        int[] cost = new int[N];
        cost[0] = 0;
        cost[1] = Math.abs(stones[1] - stones[0]);
        for (int i = 2; i < N; i++) {
            int cost1 = Math.abs(stones[i] - stones[i-1]) + cost[i-1];
            int cost2 = Math.abs(stones[i] - stones[i-2]) + cost[i-2];
            cost[i] = Math.min(cost1, cost2);
        }
        System.out.println(cost[N-1]);
    }
} public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] stones = new int[N];
        for (int i = 0; i < N; i++) {
            stones[i] = sc.nextInt();
        }
        int[] cost = new int[N];
        cost[0] = 0;
        cost[1] = Math.abs(stones[1] - stones[0]);
        for (int i = 2; i < N; i++) {
            int cost1 = Math.abs(stones[i] - stones[i-1]) + cost[i-1];
            int cost2 = Math.abs(stones[i] - stones[i-2]) + cost[i-2];
            cost[i] = Math.min(cost1, cost2);
        }
        System.out.println(cost[N-1]);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] stones = new int[N];
        for (int i = 0; i < N; i++) {
            stones[i] = sc.nextInt();
        }
        int[] cost = new int[N];
        cost[0] = 0;
        cost[1] = Math.abs(stones[1] - stones[0]);
        for (int i = 2; i < N; i++) {
            int cost1 = Math.abs(stones[i] - stones[i-1]) + cost[i-1];
            int cost2 = Math.abs(stones[i] - stones[i-2]) + cost[i-2];
            cost[i] = Math.min(cost1, cost2);
        }
        System.out.println(cost[N-1]);
    }
}