import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        // 引数を取得
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        // DP 配列全体を「DP の種類に応じた初期値」で初期化
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }

        // 初期条件を入力
        dp[0] = 0;

        // ループを回す
        for (int i = 1; i < n; i++) {
            int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            if (dp[i] > a) {
                dp[i] = a;
            }

            if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            }
        }

        // テーブルから解を得て出力
        System.out.println(dp[n - 1]);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        // 引数を取得
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        // DP 配列全体を「DP の種類に応じた初期値」で初期化
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }

        // 初期条件を入力
        dp[0] = 0;

        // ループを回す
        for (int i = 1; i < n; i++) {
            int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            if (dp[i] > a) {
                dp[i] = a;
            }

            if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            }
        }

        // テーブルから解を得て出力
        System.out.println(dp[n - 1]);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        // 引数を取得
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        // DP 配列全体を「DP の種類に応じた初期値」で初期化
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }

        // 初期条件を入力
        dp[0] = 0;

        // ループを回す
        for (int i = 1; i < n; i++) {
            int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            if (dp[i] > a) {
                dp[i] = a;
            }

            if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            }
        }

        // テーブルから解を得て出力
        System.out.println(dp[n - 1]);
    } main {
        Scanner sc = new Scanner(System.in);
        // 引数を取得
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        // DP 配列全体を「DP の種類に応じた初期値」で初期化
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }

        // 初期条件を入力
        dp[0] = 0;

        // ループを回す
        for (int i = 1; i < n; i++) {
            int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            if (dp[i] > a) {
                dp[i] = a;
            }

            if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            }
        }

        // テーブルから解を得て出力
        System.out.println(dp[n - 1]);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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 sc.close() sc.close sc int[] dp = new int[n]; dp new int[n] n for (int i = 0; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            dp[i] = Integer.MAX_VALUE;
        } {
            dp[i] = Integer.MAX_VALUE;
        } 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 = 1; i < n; i++) {
            int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            if (dp[i] > a) {
                dp[i] = a;
            }

            if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            }
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            if (dp[i] > a) {
                dp[i] = a;
            }

            if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            }
        } {
            int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            if (dp[i] > a) {
                dp[i] = a;
            }

            if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            }
        } int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]); a dp[i - 1] + Math.abs(h[i] - h[i - 1]) dp[i - 1] dp i - 1 i 1 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 if (dp[i] > a) {
                dp[i] = a;
            } dp[i] > a dp[i] dp i a {
                dp[i] = a;
            } dp[i] = a dp[i] dp i a if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            } i > 1 i 1 {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            } int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]); b dp[i - 2] + Math.abs(h[i] - h[i - 2]) dp[i - 2] dp i - 2 i 2 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 if (dp[i] > b) {
                    dp[i] = b;
                } dp[i] > b dp[i] dp i b {
                    dp[i] = b;
                } dp[i] = b dp[i] dp i b 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 public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        // 引数を取得
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        // DP 配列全体を「DP の種類に応じた初期値」で初期化
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }

        // 初期条件を入力
        dp[0] = 0;

        // ループを回す
        for (int i = 1; i < n; i++) {
            int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            if (dp[i] > a) {
                dp[i] = a;
            }

            if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            }
        }

        // テーブルから解を得て出力
        System.out.println(dp[n - 1]);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        // 引数を取得
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        // DP 配列全体を「DP の種類に応じた初期値」で初期化
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }

        // 初期条件を入力
        dp[0] = 0;

        // ループを回す
        for (int i = 1; i < n; i++) {
            int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            if (dp[i] > a) {
                dp[i] = a;
            }

            if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            }
        }

        // テーブルから解を得て出力
        System.out.println(dp[n - 1]);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        // 引数を取得
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        // DP 配列全体を「DP の種類に応じた初期値」で初期化
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
        }

        // 初期条件を入力
        dp[0] = 0;

        // ループを回す
        for (int i = 1; i < n; i++) {
            int a = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            if (dp[i] > a) {
                dp[i] = a;
            }

            if (i > 1) {
                int b = dp[i - 2] + Math.abs(h[i] - h[i - 2]);
                if (dp[i] > b) {
                    dp[i] = b;
                }
            }
        }

        // テーブルから解を得て出力
        System.out.println(dp[n - 1]);
    }
}
