import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    private static long[] dp;
    private static long cost(int current, int[] arr){
        if(current >= arr.length) return Long.MAX_VALUE;
        if(current == arr.length - 1) return 0;
        if(dp[current] != -1) return dp[current];
        long x = cost(current + 1, arr);
        long y = cost(current + 2, arr);
        if(x != Long.MAX_VALUE) x += Math.abs(arr[current] - arr[current + 1]);
        if(y != Long.MAX_VALUE) y += Math.abs(arr[current] - arr[current + 2]);
        dp[current] = Math.min(x, y);
        return dp[current];
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        int[] arr = nextIntArray(br, n);
        dp = new long[n];
        Arrays.fill(dp, -1);
        sb.append(cost(0, arr));
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util import java.util.StringTokenizer; StringTokenizer java.util public class Main {
    private static long[] dp;
    private static long cost(int current, int[] arr){
        if(current >= arr.length) return Long.MAX_VALUE;
        if(current == arr.length - 1) return 0;
        if(dp[current] != -1) return dp[current];
        long x = cost(current + 1, arr);
        long y = cost(current + 2, arr);
        if(x != Long.MAX_VALUE) x += Math.abs(arr[current] - arr[current + 1]);
        if(y != Long.MAX_VALUE) y += Math.abs(arr[current] - arr[current + 2]);
        dp[current] = Math.min(x, y);
        return dp[current];
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        int[] arr = nextIntArray(br, n);
        dp = new long[n];
        Arrays.fill(dp, -1);
        sb.append(cost(0, arr));
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
} Main private static long[] dp; dp private static long cost(int current, int[] arr){
        if(current >= arr.length) return Long.MAX_VALUE;
        if(current == arr.length - 1) return 0;
        if(dp[current] != -1) return dp[current];
        long x = cost(current + 1, arr);
        long y = cost(current + 2, arr);
        if(x != Long.MAX_VALUE) x += Math.abs(arr[current] - arr[current + 1]);
        if(y != Long.MAX_VALUE) y += Math.abs(arr[current] - arr[current + 2]);
        dp[current] = Math.min(x, y);
        return dp[current];
    } cost {
        if(current >= arr.length) return Long.MAX_VALUE;
        if(current == arr.length - 1) return 0;
        if(dp[current] != -1) return dp[current];
        long x = cost(current + 1, arr);
        long y = cost(current + 2, arr);
        if(x != Long.MAX_VALUE) x += Math.abs(arr[current] - arr[current + 1]);
        if(y != Long.MAX_VALUE) y += Math.abs(arr[current] - arr[current + 2]);
        dp[current] = Math.min(x, y);
        return dp[current];
    } if(current >= arr.length) return Long.MAX_VALUE; current >= arr.length current arr.length arr arr.length return Long.MAX_VALUE; Long.MAX_VALUE Long Long.MAX_VALUE if(current == arr.length - 1) return 0; current == arr.length - 1 current arr.length - 1 arr.length arr arr.length 1 return 0; 0 if(dp[current] != -1) return dp[current]; dp[current] != -1 dp[current] dp current -1 1 return dp[current]; dp[current] dp current long x = cost(current + 1, arr); x cost(current + 1, arr) cost current + 1 current 1 arr long y = cost(current + 2, arr); y cost(current + 2, arr) cost current + 2 current 2 arr if(x != Long.MAX_VALUE) x += Math.abs(arr[current] - arr[current + 1]); x != Long.MAX_VALUE x Long.MAX_VALUE Long Long.MAX_VALUE x += Math.abs(arr[current] - arr[current + 1]) x Math.abs(arr[current] - arr[current + 1]) Math.abs Math arr[current] - arr[current + 1] arr[current] arr current arr[current + 1] arr current + 1 current 1 if(y != Long.MAX_VALUE) y += Math.abs(arr[current] - arr[current + 2]); y != Long.MAX_VALUE y Long.MAX_VALUE Long Long.MAX_VALUE y += Math.abs(arr[current] - arr[current + 2]) y Math.abs(arr[current] - arr[current + 2]) Math.abs Math arr[current] - arr[current + 2] arr[current] arr current arr[current + 2] arr current + 2 current 2 dp[current] = Math.min(x, y) dp[current] dp current Math.min(x, y) Math.min Math x y return dp[current]; dp[current] dp current int current current int[] arr arr public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        int[] arr = nextIntArray(br, n);
        dp = new long[n];
        Arrays.fill(dp, -1);
        sb.append(cost(0, arr));
        System.out.print(sb.toString());
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        int[] arr = nextIntArray(br, n);
        dp = new long[n];
        Arrays.fill(dp, -1);
        sb.append(cost(0, arr));
        System.out.print(sb.toString());
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int n = nextInt(br); n nextInt(br) nextInt br int[] arr = nextIntArray(br, n); arr nextIntArray(br, n) nextIntArray br n dp = new long[n] dp new long[n] n Arrays.fill(dp, -1) Arrays.fill Arrays dp -1 1 sb.append(cost(0, arr)) sb.append sb cost(0, arr) cost 0 arr System.out.print(sb.toString()) System.out.print System.out System System.out sb.toString() sb.toString sb String[] args args private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    } nextInt {
        return Integer.parseInt(br.readLine());
    } return Integer.parseInt(br.readLine()); Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br BufferedReader br br private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    } nextIntArray {
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    } StringTokenizer st = new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int[] arr = new int[n]; arr new int[n] n for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            arr[i] = Integer.parseInt(st.nextToken());
        } {
            arr[i] = Integer.parseInt(st.nextToken());
        } arr[i] = Integer.parseInt(st.nextToken()) arr[i] arr i Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st return arr; arr BufferedReader br br int n n static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    } Pair A first; first B second; second public Pair(A first, B second){
            this.first = first;
            this.second = second;
        } Pair {
            this.first = first;
            this.second = second;
        } this.first = first this.first this this.first first this.second = second this.second this this.second second A first first B second second public class Main {
    private static long[] dp;
    private static long cost(int current, int[] arr){
        if(current >= arr.length) return Long.MAX_VALUE;
        if(current == arr.length - 1) return 0;
        if(dp[current] != -1) return dp[current];
        long x = cost(current + 1, arr);
        long y = cost(current + 2, arr);
        if(x != Long.MAX_VALUE) x += Math.abs(arr[current] - arr[current + 1]);
        if(y != Long.MAX_VALUE) y += Math.abs(arr[current] - arr[current + 2]);
        dp[current] = Math.min(x, y);
        return dp[current];
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        int[] arr = nextIntArray(br, n);
        dp = new long[n];
        Arrays.fill(dp, -1);
        sb.append(cost(0, arr));
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
} public class Main {
    private static long[] dp;
    private static long cost(int current, int[] arr){
        if(current >= arr.length) return Long.MAX_VALUE;
        if(current == arr.length - 1) return 0;
        if(dp[current] != -1) return dp[current];
        long x = cost(current + 1, arr);
        long y = cost(current + 2, arr);
        if(x != Long.MAX_VALUE) x += Math.abs(arr[current] - arr[current + 1]);
        if(y != Long.MAX_VALUE) y += Math.abs(arr[current] - arr[current + 2]);
        dp[current] = Math.min(x, y);
        return dp[current];
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        int[] arr = nextIntArray(br, n);
        dp = new long[n];
        Arrays.fill(dp, -1);
        sb.append(cost(0, arr));
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    private static long[] dp;
    private static long cost(int current, int[] arr){
        if(current >= arr.length) return Long.MAX_VALUE;
        if(current == arr.length - 1) return 0;
        if(dp[current] != -1) return dp[current];
        long x = cost(current + 1, arr);
        long y = cost(current + 2, arr);
        if(x != Long.MAX_VALUE) x += Math.abs(arr[current] - arr[current + 1]);
        if(y != Long.MAX_VALUE) y += Math.abs(arr[current] - arr[current + 2]);
        dp[current] = Math.min(x, y);
        return dp[current];
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        int[] arr = nextIntArray(br, n);
        dp = new long[n];
        Arrays.fill(dp, -1);
        sb.append(cost(0, arr));
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}