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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] h = new int[n];

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 0; i < n-2; i++) {
            dp[i+1] = Math.min(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]);
            dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]);
        }
        dp[n-1] = Math.min(dp[n-2] + Math.abs(h[n-2]-h[n-1]), dp[n-1]);

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

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
} 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 {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] h = new int[n];

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 0; i < n-2; i++) {
            dp[i+1] = Math.min(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]);
            dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]);
        }
        dp[n-1] = Math.min(dp[n-2] + Math.abs(h[n-2]-h[n-1]), dp[n-1]);

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

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
} Main public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] h = new int[n];

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 0; i < n-2; i++) {
            dp[i+1] = Math.min(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]);
            dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]);
        }
        dp[n-1] = Math.min(dp[n-2] + Math.abs(h[n-2]-h[n-1]), dp[n-1]);

        System.out.println(dp[n-1]);
    } main {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] h = new int[n];

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 0; i < n-2; i++) {
            dp[i+1] = Math.min(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]);
            dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]);
        }
        dp[n-1] = Math.min(dp[n-2] + Math.abs(h[n-2]-h[n-1]), dp[n-1]);

        System.out.println(dp[n-1]);
    } MyScanner sc = new MyScanner(); sc new MyScanner() 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[] dp = new int[n]; dp new int[n] n Arrays.fill(dp, Integer.MAX_VALUE) Arrays.fill Arrays dp 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(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]);
            dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), 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(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]);
            dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]);
        } {
            dp[i+1] = Math.min(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]);
            dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]);
        } dp[i+1] = Math.min(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]) dp[i+1] dp i+1 i 1 Math.min(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]) Math.min Math dp[i] + Math.abs(h[i]-h[i+1]) dp[i] 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+1] dp i+1 i 1 dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]) dp[i+2] dp i+2 i 2 Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]) Math.min Math dp[i] + Math.abs(h[i]-h[i+2]) dp[i] 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+2] dp i+2 i 2 dp[n-1] = Math.min(dp[n-2] + Math.abs(h[n-2]-h[n-1]), dp[n-1]) dp[n-1] dp n-1 n 1 Math.min(dp[n-2] + Math.abs(h[n-2]-h[n-1]), dp[n-1]) Math.min Math dp[n-2] + Math.abs(h[n-2]-h[n-1]) dp[n-2] dp n-2 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-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 String[] args args static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    } MyScanner BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15); reader new BufferedReader(new InputStreamReader(System.in), 1 << 15) StringTokenizer tokenizer; tokenizer String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        } next {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        } try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            } catch (IOException ignored) {
            } IOException ignored {
            } {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
                    tokenizer = new StringTokenizer(reader.readLine());
                } tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nextLong() {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] h = new int[n];

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 0; i < n-2; i++) {
            dp[i+1] = Math.min(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]);
            dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]);
        }
        dp[n-1] = Math.min(dp[n-2] + Math.abs(h[n-2]-h[n-1]), dp[n-1]);

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

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
} public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] h = new int[n];

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 0; i < n-2; i++) {
            dp[i+1] = Math.min(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]);
            dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]);
        }
        dp[n-1] = Math.min(dp[n-2] + Math.abs(h[n-2]-h[n-1]), dp[n-1]);

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

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] h = new int[n];

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 0; i < n-2; i++) {
            dp[i+1] = Math.min(dp[i] + Math.abs(h[i]-h[i+1]), dp[i+1]);
            dp[i+2] = Math.min(dp[i] + Math.abs(h[i]-h[i+2]), dp[i+2]);
        }
        dp[n-1] = Math.min(dp[n-2] + Math.abs(h[n-2]-h[n-1]), dp[n-1]);

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

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}