
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] h = new int[N];
        for(int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        int[] minCost = new int[N];
        minCost[0] = 0;
        minCost[1] = h[1] - h[0];
        minCost[1] *= minCost[1] > 0 ? 1 : -1;
        for(int i=2;i<N;i++){
            int cost2 = minCost[i-2] + ((h[i] > h[i-2]) ? (h[i] - h[i-2]) : (h[i-2] - h[i]));
            int cost1 = minCost[i-1] + ((h[i] > h[i-1]) ? (h[i] - h[i-1]) : (h[i-1] - h[i]));
            minCost[i] = Math.min(cost1, cost2);
        }
        System.out.println(minCost[N-1]);
    }
} import java.util.Scanner; Scanner java.util public class Main {

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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] h = new int[N];
        for(int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        int[] minCost = new int[N];
        minCost[0] = 0;
        minCost[1] = h[1] - h[0];
        minCost[1] *= minCost[1] > 0 ? 1 : -1;
        for(int i=2;i<N;i++){
            int cost2 = minCost[i-2] + ((h[i] > h[i-2]) ? (h[i] - h[i-2]) : (h[i-2] - h[i]));
            int cost1 = minCost[i-1] + ((h[i] > h[i-1]) ? (h[i] - h[i-1]) : (h[i-1] - h[i]));
            minCost[i] = Math.min(cost1, cost2);
        }
        System.out.println(minCost[N-1]);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] h = new int[N];
        for(int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        int[] minCost = new int[N];
        minCost[0] = 0;
        minCost[1] = h[1] - h[0];
        minCost[1] *= minCost[1] > 0 ? 1 : -1;
        for(int i=2;i<N;i++){
            int cost2 = minCost[i-2] + ((h[i] > h[i-2]) ? (h[i] - h[i-2]) : (h[i-2] - h[i]));
            int cost1 = minCost[i-1] + ((h[i] > h[i-1]) ? (h[i] - h[i-1]) : (h[i-1] - h[i]));
            minCost[i] = Math.min(cost1, cost2);
        }
        System.out.println(minCost[N-1]);
    }
} Main

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] h = new int[N];
        for(int i=0;i<N;i++){
            h[i] = sc.nextInt();
        }
        int[] minCost = new int[N];
        minCost[0] = 0;
        minCost[1] = h[1] - h[0];
        minCost[1] *= minCost[1] > 0 ? 1 : -1;
        for(int i=2;i<N;i++){
            int cost2 = minCost[i-2] + ((h[i] > h[i-2]) ? (h[i] - h[i-2]) : (h[i-2] - h[i]));
            int cost1 = minCost[i-1] + ((h[i] > h[i-1]) ? (h[i] - h[i-1]) : (h[i-1] - h[i]));
            minCost[i] = Math.min(cost1, cost2);
        }
        System.out.println(minCost[N-1]);
    }
}
