import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        int n,a;
        n=in.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        a=0;
        int[] dp = new int[n];
        int ans = solver.call(arr , a , dp);
        out.println(ans);
        out.close();
    }

    static class TaskA {
        public int call( int[] arr , int a , int[] dp ) {
            if(arr.length!=2) {
                for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                }
                for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                }
            }
            else
            {
                dp[0]=Math.abs(arr[0] -arr[1]);
            }
            return dp[0];
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }


    }
} import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.StringTokenizer; StringTokenizer java.util import java.io.IOException; IOException java.io import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.InputStream; InputStream java.io public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        int n,a;
        n=in.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        a=0;
        int[] dp = new int[n];
        int ans = solver.call(arr , a , dp);
        out.println(ans);
        out.close();
    }

    static class TaskA {
        public int call( int[] arr , int a , int[] dp ) {
            if(arr.length!=2) {
                for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                }
                for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                }
            }
            else
            {
                dp[0]=Math.abs(arr[0] -arr[1]);
            }
            return dp[0];
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }


    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        int n,a;
        n=in.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        a=0;
        int[] dp = new int[n];
        int ans = solver.call(arr , a , dp);
        out.println(ans);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        int n,a;
        n=in.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        a=0;
        int[] dp = new int[n];
        int ans = solver.call(arr , a , dp);
        out.println(ans);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) TaskA solver = new TaskA(); solver new TaskA() int n n a; a n=in.nextInt() n in.nextInt() in.nextInt in int[] arr = new int[n]; arr new int[n] n for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            arr[i]=in.nextInt();
        } {
            arr[i]=in.nextInt();
        } arr[i]=in.nextInt() arr[i] arr i in.nextInt() in.nextInt in a=0 a 0 int[] dp = new int[n]; dp new int[n] n int ans = solver.call(arr , a , dp); ans solver.call(arr , a , dp) solver.call solver arr a dp out.println(ans) out.println out ans out.close() out.close out String[] args args static class TaskA {
        public int call( int[] arr , int a , int[] dp ) {
            if(arr.length!=2) {
                for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                }
                for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                }
            }
            else
            {
                dp[0]=Math.abs(arr[0] -arr[1]);
            }
            return dp[0];
        }
    } TaskA public int call( int[] arr , int a , int[] dp ) {
            if(arr.length!=2) {
                for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                }
                for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                }
            }
            else
            {
                dp[0]=Math.abs(arr[0] -arr[1]);
            }
            return dp[0];
        } call {
            if(arr.length!=2) {
                for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                }
                for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                }
            }
            else
            {
                dp[0]=Math.abs(arr[0] -arr[1]);
            }
            return dp[0];
        } if(arr.length!=2) {
                for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                }
                for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                }
            }
            else
            {
                dp[0]=Math.abs(arr[0] -arr[1]);
            } arr.length!=2 arr.length arr arr.length 2 {
                for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                }
                for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                }
            } for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                } int i = arr.length - 2; int i = arr.length - 2; i arr.length - 2 arr.length arr arr.length 2 i >= arr.length - 3 i arr.length - 3 arr.length arr arr.length 3 i-- i-- i {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                } {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                } dp[i] = Math.abs(arr[i] - arr[arr.length - 1]) dp[i] dp i Math.abs(arr[i] - arr[arr.length - 1]) Math.abs Math arr[i] - arr[arr.length - 1] arr[i] arr i arr[arr.length - 1] arr arr.length - 1 arr.length arr arr.length 1 for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                } int i = arr.length - 4; int i = arr.length - 4; i arr.length - 4 arr.length arr arr.length 4 i >= 0 i 0 i-- i-- i {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                } {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                } dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]) dp[i] dp i Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]) Math.min Math Math.abs(arr[i] - arr[i + 1]) + dp[i + 1] Math.abs(arr[i] - arr[i + 1]) Math.abs Math arr[i] - arr[i + 1] arr[i] arr i arr[i + 1] arr i + 1 i 1 dp[i + 1] dp i + 1 i 1 Math.abs(arr[i] - arr[i + 2]) + dp[i + 2] Math.abs(arr[i] - arr[i + 2]) Math.abs Math arr[i] - arr[i + 2] arr[i] arr i arr[i + 2] arr i + 2 i 2 dp[i + 2] dp i + 2 i 2 {
                dp[0]=Math.abs(arr[0] -arr[1]);
            } dp[0]=Math.abs(arr[0] -arr[1]) dp[0] dp 0 Math.abs(arr[0] -arr[1]) Math.abs Math arr[0] -arr[1] arr[0] arr 0 arr[1] arr 1 return dp[0]; dp[0] dp 0 int[] arr arr int a a int[] dp dp static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }


    } InputReader public BufferedReader reader; reader public StringTokenizer tokenizer; tokenizer public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        } InputReader {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        } reader = new BufferedReader(new InputStreamReader(stream), 32768) reader new BufferedReader(new InputStreamReader(stream), 32768) tokenizer = null tokenizer null InputStream stream stream public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } next {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } IOException e {
                    throw new RuntimeException(e);
                } throw new RuntimeException(e); new RuntimeException(e) {
                    tokenizer = new StringTokenizer(reader.readLine());
                } tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public 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) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        int n,a;
        n=in.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        a=0;
        int[] dp = new int[n];
        int ans = solver.call(arr , a , dp);
        out.println(ans);
        out.close();
    }

    static class TaskA {
        public int call( int[] arr , int a , int[] dp ) {
            if(arr.length!=2) {
                for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                }
                for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                }
            }
            else
            {
                dp[0]=Math.abs(arr[0] -arr[1]);
            }
            return dp[0];
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }


    }
} public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        int n,a;
        n=in.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        a=0;
        int[] dp = new int[n];
        int ans = solver.call(arr , a , dp);
        out.println(ans);
        out.close();
    }

    static class TaskA {
        public int call( int[] arr , int a , int[] dp ) {
            if(arr.length!=2) {
                for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                }
                for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                }
            }
            else
            {
                dp[0]=Math.abs(arr[0] -arr[1]);
            }
            return dp[0];
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }


    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        int n,a;
        n=in.nextInt();
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        a=0;
        int[] dp = new int[n];
        int ans = solver.call(arr , a , dp);
        out.println(ans);
        out.close();
    }

    static class TaskA {
        public int call( int[] arr , int a , int[] dp ) {
            if(arr.length!=2) {
                for (int i = arr.length - 2; i >= arr.length - 3; i--) {
                    dp[i] = Math.abs(arr[i] - arr[arr.length - 1]);
                }
                for (int i = arr.length - 4; i >= 0; i--) {
                    dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dp[i + 1], Math.abs(arr[i] - arr[i + 2]) + dp[i + 2]);
                }
            }
            else
            {
                dp[0]=Math.abs(arr[0] -arr[1]);
            }
            return dp[0];
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }


    }
}