import javax.swing.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static long[] tree;
    static int m = 100000000;
    static int k1,k2;
    static boolean[] vis;
    static tuple[] tuples;
    public static void main(String[] args) throws IOException {
        //BufferedReader reader=new BufferedReader(new FileReader("input.txt"));
        //PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //Scanner sc=new Scanner(System.in);
        Reader sc = new Reader();
        //String[] in=reader.readLine().split(" ");

        int n=sc.nextInt();
        int[] h=new int[n];
        for (int i = 0; i <n ; i++) {
            h[i]=sc.nextInt();
        }
        System.out.println(dp(0,n,h));

















        out.close();
    }
    static Integer[] memo=new Integer[100005];
    static int dp(int x,int n,int[] h){
        if (x==n-1)return 0;
        if (memo[x]!=null){
            return memo[x];
        }
        int a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
        if (x+1<n)a=dp(x+1,n,h)+Math.abs(h[x]-h[x+1]);
        if (x+2<n)b=dp(x+2,n,h)+Math.abs(h[x]-h[x+2]);
        return memo[x]=Math.min(a,b);

    }



    static boolean bfs(int a,int b){
        Queue<Integer> queue=new LinkedList<>();
        queue.add(a);

        while (!queue.isEmpty()){
            int now=queue.poll();
            vis[now]=true;

            for (int i = 0; i <k1 ; i++) {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            }
        }

        Arrays.fill(vis,false);
        return false;

    }
    static int find(int[] p,int x){
        if (p[x]==x)return x;

        return p[x]=find(p,p[x]);
    }
    static void union(int[] p,int a,int b){
        p[find(p,b)]=find(p,a);
    }
    static void built(long[] a,int at,int l,int r,int n){
        if (l==r){
            tree[at]=a[l];
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            built(a,left,l,mid,n-1);
            built(a,right,mid+1,r,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    }
    static void update(int at,int l,int r,int i,long v,int n){
        if (i<l || i>r)return;

        if (l==r){
            tree[at]=v;
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            update(left,l,mid,i,v,n-1);
            update(right,mid+1,r,i,v,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    }




}

    class node implements Comparable<node> {
        Integer no;
        Integer cost;
        Vector<node> adj = new Vector<>();

        public node(Integer no, Integer cost) {
            this.no = no;
            this.cost = cost;
        }

        @Override
        public String toString() {
            return "node{" +
                    "no=" + no +
                    ", cost=" + cost +
                    '}';
        }

        @Override
        public int compareTo(node o) {
            return o.cost - this.cost;
        }
    }

    class edge implements Comparable<edge> {
        tuple u;
        Double cost;

        public edge(tuple u, Double cost) {
            this.u = u;
            this.cost = cost;
        }

        @Override
        public int compareTo(edge o) {
            return this.cost.compareTo(o.cost);
        }

        @Override
        public String toString() {
            return "edge{" +
                    "u=" + u +
                    ", cost=" + cost +
                    '}';
        }
    }

    ///*
    class tuple implements Comparable<tuple> {
        Integer a;
        Integer b;

        public tuple(Integer a, Integer b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(tuple o) {
            return (int) (this.b - o.b);
        }

        @Override
        public String toString() {
            return "tuple{" +
                    "a=" + a +
                    ", b=" + b +
                    '}';
        }
    }


    //*/
    class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
            if (neg) return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead) fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null) return;
            din.close();
        }
    } import javax.swing.*; swing.* javax import java.io.*; io.* java import java.math.BigInteger; BigInteger java.math import java.util.*; util.* java public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static long[] tree;
    static int m = 100000000;
    static int k1,k2;
    static boolean[] vis;
    static tuple[] tuples;
    public static void main(String[] args) throws IOException {
        //BufferedReader reader=new BufferedReader(new FileReader("input.txt"));
        //PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //Scanner sc=new Scanner(System.in);
        Reader sc = new Reader();
        //String[] in=reader.readLine().split(" ");

        int n=sc.nextInt();
        int[] h=new int[n];
        for (int i = 0; i <n ; i++) {
            h[i]=sc.nextInt();
        }
        System.out.println(dp(0,n,h));

















        out.close();
    }
    static Integer[] memo=new Integer[100005];
    static int dp(int x,int n,int[] h){
        if (x==n-1)return 0;
        if (memo[x]!=null){
            return memo[x];
        }
        int a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
        if (x+1<n)a=dp(x+1,n,h)+Math.abs(h[x]-h[x+1]);
        if (x+2<n)b=dp(x+2,n,h)+Math.abs(h[x]-h[x+2]);
        return memo[x]=Math.min(a,b);

    }



    static boolean bfs(int a,int b){
        Queue<Integer> queue=new LinkedList<>();
        queue.add(a);

        while (!queue.isEmpty()){
            int now=queue.poll();
            vis[now]=true;

            for (int i = 0; i <k1 ; i++) {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            }
        }

        Arrays.fill(vis,false);
        return false;

    }
    static int find(int[] p,int x){
        if (p[x]==x)return x;

        return p[x]=find(p,p[x]);
    }
    static void union(int[] p,int a,int b){
        p[find(p,b)]=find(p,a);
    }
    static void built(long[] a,int at,int l,int r,int n){
        if (l==r){
            tree[at]=a[l];
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            built(a,left,l,mid,n-1);
            built(a,right,mid+1,r,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    }
    static void update(int at,int l,int r,int i,long v,int n){
        if (i<l || i>r)return;

        if (l==r){
            tree[at]=v;
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            update(left,l,mid,i,v,n-1);
            update(right,mid+1,r,i,v,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    }




} Main static PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) static long[] tree; tree static int m = 100000000; m 100000000 static int k1 k1 k2; k2 static boolean[] vis; vis static tuple[] tuples; tuples static Integer[] memo=new Integer[100005]; memo new Integer[100005] 100005 public static void main(String[] args) throws IOException {
        //BufferedReader reader=new BufferedReader(new FileReader("input.txt"));
        //PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //Scanner sc=new Scanner(System.in);
        Reader sc = new Reader();
        //String[] in=reader.readLine().split(" ");

        int n=sc.nextInt();
        int[] h=new int[n];
        for (int i = 0; i <n ; i++) {
            h[i]=sc.nextInt();
        }
        System.out.println(dp(0,n,h));

















        out.close();
    } main {
        //BufferedReader reader=new BufferedReader(new FileReader("input.txt"));
        //PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //Scanner sc=new Scanner(System.in);
        Reader sc = new Reader();
        //String[] in=reader.readLine().split(" ");

        int n=sc.nextInt();
        int[] h=new int[n];
        for (int i = 0; i <n ; i++) {
            h[i]=sc.nextInt();
        }
        System.out.println(dp(0,n,h));

















        out.close();
    } Reader sc = new Reader(); sc new Reader() 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 System.out.println(dp(0,n,h)) System.out.println System.out System System.out dp(0,n,h) dp 0 n h out.close() out.close out String[] args args static int dp(int x,int n,int[] h){
        if (x==n-1)return 0;
        if (memo[x]!=null){
            return memo[x];
        }
        int a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
        if (x+1<n)a=dp(x+1,n,h)+Math.abs(h[x]-h[x+1]);
        if (x+2<n)b=dp(x+2,n,h)+Math.abs(h[x]-h[x+2]);
        return memo[x]=Math.min(a,b);

    } dp {
        if (x==n-1)return 0;
        if (memo[x]!=null){
            return memo[x];
        }
        int a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
        if (x+1<n)a=dp(x+1,n,h)+Math.abs(h[x]-h[x+1]);
        if (x+2<n)b=dp(x+2,n,h)+Math.abs(h[x]-h[x+2]);
        return memo[x]=Math.min(a,b);

    } if (x==n-1)return 0; x==n-1 x n-1 n 1 return 0; 0 if (memo[x]!=null){
            return memo[x];
        } memo[x]!=null memo[x] memo x null {
            return memo[x];
        } return memo[x]; memo[x] memo x int a=Integer.MAX_VALUE a Integer.MAX_VALUE Integer Integer.MAX_VALUE b=Integer.MAX_VALUE; b Integer.MAX_VALUE Integer Integer.MAX_VALUE if (x+1<n)a=dp(x+1,n,h)+Math.abs(h[x]-h[x+1]); x+1<n x+1 x 1 n a=dp(x+1,n,h)+Math.abs(h[x]-h[x+1]) a dp(x+1,n,h)+Math.abs(h[x]-h[x+1]) dp(x+1,n,h) dp x+1 x 1 n h Math.abs(h[x]-h[x+1]) Math.abs Math h[x]-h[x+1] h[x] h x h[x+1] h x+1 x 1 if (x+2<n)b=dp(x+2,n,h)+Math.abs(h[x]-h[x+2]); x+2<n x+2 x 2 n b=dp(x+2,n,h)+Math.abs(h[x]-h[x+2]) b dp(x+2,n,h)+Math.abs(h[x]-h[x+2]) dp(x+2,n,h) dp x+2 x 2 n h Math.abs(h[x]-h[x+2]) Math.abs Math h[x]-h[x+2] h[x] h x h[x+2] h x+2 x 2 return memo[x]=Math.min(a,b); memo[x]=Math.min(a,b) memo[x] memo x Math.min(a,b) Math.min Math a b int x x int n n int[] h h static boolean bfs(int a,int b){
        Queue<Integer> queue=new LinkedList<>();
        queue.add(a);

        while (!queue.isEmpty()){
            int now=queue.poll();
            vis[now]=true;

            for (int i = 0; i <k1 ; i++) {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            }
        }

        Arrays.fill(vis,false);
        return false;

    } bfs {
        Queue<Integer> queue=new LinkedList<>();
        queue.add(a);

        while (!queue.isEmpty()){
            int now=queue.poll();
            vis[now]=true;

            for (int i = 0; i <k1 ; i++) {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            }
        }

        Arrays.fill(vis,false);
        return false;

    } Queue<Integer> queue=new LinkedList<>(); queue new LinkedList<>() queue.add(a) queue.add queue a while (!queue.isEmpty()){
            int now=queue.poll();
            vis[now]=true;

            for (int i = 0; i <k1 ; i++) {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            }
        } !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
            int now=queue.poll();
            vis[now]=true;

            for (int i = 0; i <k1 ; i++) {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            }
        } int now=queue.poll(); now queue.poll() queue.poll queue vis[now]=true vis[now] vis now true for (int i = 0; i <k1 ; i++) {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            } int i = 0; int i = 0; i 0 i <k1 i k1 i++ i++ i {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            } {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            } if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                } !vis[i] vis[i] vis i {
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                } if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    } (tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b) (tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b) tuples[i].a<tuples[now].a tuples[i].a tuples[i] tuples i tuples[i].a tuples[now].a tuples[now] tuples now tuples[now].a tuples[now].a<tuples[i].b tuples[now].a tuples[now] tuples now tuples[now].a tuples[i].b tuples[i] tuples i tuples[i].b (tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b) tuples[i].a<tuples[now].b tuples[i].a tuples[i] tuples i tuples[i].a tuples[now].b tuples[now] tuples now tuples[now].b tuples[now].b<tuples[i].b tuples[now].b tuples[now] tuples now tuples[now].b tuples[i].b tuples[i] tuples i tuples[i].b {
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    } queue.add(i) queue.add queue i if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        } i==b i b {
                            Arrays.fill(vis,false);
                            return true;
                        } Arrays.fill(vis,false) Arrays.fill Arrays vis false return true; true Arrays.fill(vis,false) Arrays.fill Arrays vis false return false; false int a a int b b static int find(int[] p,int x){
        if (p[x]==x)return x;

        return p[x]=find(p,p[x]);
    } find {
        if (p[x]==x)return x;

        return p[x]=find(p,p[x]);
    } if (p[x]==x)return x; p[x]==x p[x] p x x return x; x return p[x]=find(p,p[x]); p[x]=find(p,p[x]) p[x] p x find(p,p[x]) find p p[x] p x int[] p p int x x static void union(int[] p,int a,int b){
        p[find(p,b)]=find(p,a);
    } union {
        p[find(p,b)]=find(p,a);
    } p[find(p,b)]=find(p,a) p[find(p,b)] p find(p,b) find p b find(p,a) find p a int[] p p int a a int b b static void built(long[] a,int at,int l,int r,int n){
        if (l==r){
            tree[at]=a[l];
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            built(a,left,l,mid,n-1);
            built(a,right,mid+1,r,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    } built {
        if (l==r){
            tree[at]=a[l];
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            built(a,left,l,mid,n-1);
            built(a,right,mid+1,r,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    } if (l==r){
            tree[at]=a[l];
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            built(a,left,l,mid,n-1);
            built(a,right,mid+1,r,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        } l==r l r {
            tree[at]=a[l];
        } tree[at]=a[l] tree[at] tree at a[l] a l {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            built(a,left,l,mid,n-1);
            built(a,right,mid+1,r,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        } int mid=(l+r)/2; mid (l+r)/2 (l+r) l r 2 int right=2*at; right 2*at 2 at int left=(2*at)+1; left (2*at)+1 (2*at) 2 at 1 built(a,left,l,mid,n-1) built a left l mid n-1 n 1 built(a,right,mid+1,r,n-1) built a right mid+1 mid 1 r n-1 n 1 if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right]; n%2==0 n%2 n 2 0 tree[at]=tree[left]^tree[right] tree[at] tree at tree[left]^tree[right] tree[left] tree left tree[right] tree right tree[at]=tree[left]|tree[right] tree[at] tree at tree[left]|tree[right] tree[left] tree left tree[right] tree right long[] a a int at at int l l int r r int n n static void update(int at,int l,int r,int i,long v,int n){
        if (i<l || i>r)return;

        if (l==r){
            tree[at]=v;
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            update(left,l,mid,i,v,n-1);
            update(right,mid+1,r,i,v,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    } update {
        if (i<l || i>r)return;

        if (l==r){
            tree[at]=v;
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            update(left,l,mid,i,v,n-1);
            update(right,mid+1,r,i,v,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    } if (i<l || i>r)return; i<l || i>r i<l i l i>r i r return; if (l==r){
            tree[at]=v;
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            update(left,l,mid,i,v,n-1);
            update(right,mid+1,r,i,v,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        } l==r l r {
            tree[at]=v;
        } tree[at]=v tree[at] tree at v {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            update(left,l,mid,i,v,n-1);
            update(right,mid+1,r,i,v,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        } int mid=(l+r)/2; mid (l+r)/2 (l+r) l r 2 int right=2*at; right 2*at 2 at int left=(2*at)+1; left (2*at)+1 (2*at) 2 at 1 update(left,l,mid,i,v,n-1) update left l mid i v n-1 n 1 update(right,mid+1,r,i,v,n-1) update right mid+1 mid 1 r i v n-1 n 1 if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right]; n%2==0 n%2 n 2 0 tree[at]=tree[left]^tree[right] tree[at] tree at tree[left]^tree[right] tree[left] tree left tree[right] tree right tree[at]=tree[left]|tree[right] tree[at] tree at tree[left]|tree[right] tree[left] tree left tree[right] tree right int at at int l l int r r int i i long v v int n n class node implements Comparable<node> {
        Integer no;
        Integer cost;
        Vector<node> adj = new Vector<>();

        public node(Integer no, Integer cost) {
            this.no = no;
            this.cost = cost;
        }

        @Override
        public String toString() {
            return "node{" +
                    "no=" + no +
                    ", cost=" + cost +
                    '}';
        }

        @Override
        public int compareTo(node o) {
            return o.cost - this.cost;
        }
    } node Integer no; no Integer cost; cost Vector<node> adj = new Vector<>(); adj new Vector<>() public node(Integer no, Integer cost) {
            this.no = no;
            this.cost = cost;
        } node {
            this.no = no;
            this.cost = cost;
        } this.no = no this.no this this.no no this.cost = cost this.cost this this.cost cost Integer no no Integer cost cost @Override
        public String toString() {
            return "node{" +
                    "no=" + no +
                    ", cost=" + cost +
                    '}';
        } toString {
            return "node{" +
                    "no=" + no +
                    ", cost=" + cost +
                    '}';
        } return "node{" +
                    "no=" + no +
                    ", cost=" + cost +
                    '}'; "node{" +
                    "no=" + no +
                    ", cost=" + cost +
                    '}' cost ", cost=" no "node{" +
                    "no=" + no +
                    ", cost=" + cost +
                    '}' "node{" "no=" no ", cost=" cost '}' @Override
        public int compareTo(node o) {
            return o.cost - this.cost;
        } compareTo {
            return o.cost - this.cost;
        } return o.cost - this.cost; o.cost - this.cost o.cost o o.cost this.cost this this.cost node o o Comparable class edge implements Comparable<edge> {
        tuple u;
        Double cost;

        public edge(tuple u, Double cost) {
            this.u = u;
            this.cost = cost;
        }

        @Override
        public int compareTo(edge o) {
            return this.cost.compareTo(o.cost);
        }

        @Override
        public String toString() {
            return "edge{" +
                    "u=" + u +
                    ", cost=" + cost +
                    '}';
        }
    } edge tuple u; u Double cost; cost public edge(tuple u, Double cost) {
            this.u = u;
            this.cost = cost;
        } edge {
            this.u = u;
            this.cost = cost;
        } this.u = u this.u this this.u u this.cost = cost this.cost this this.cost cost tuple u u Double cost cost @Override
        public int compareTo(edge o) {
            return this.cost.compareTo(o.cost);
        } compareTo {
            return this.cost.compareTo(o.cost);
        } return this.cost.compareTo(o.cost); this.cost.compareTo(o.cost) this.cost.compareTo this.cost this this.cost o.cost o o.cost edge o o @Override
        public String toString() {
            return "edge{" +
                    "u=" + u +
                    ", cost=" + cost +
                    '}';
        } toString {
            return "edge{" +
                    "u=" + u +
                    ", cost=" + cost +
                    '}';
        } return "edge{" +
                    "u=" + u +
                    ", cost=" + cost +
                    '}'; "edge{" +
                    "u=" + u +
                    ", cost=" + cost +
                    '}' cost ", cost=" u "edge{" +
                    "u=" + u +
                    ", cost=" + cost +
                    '}' "edge{" "u=" u ", cost=" cost '}' Comparable class tuple implements Comparable<tuple> {
        Integer a;
        Integer b;

        public tuple(Integer a, Integer b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(tuple o) {
            return (int) (this.b - o.b);
        }

        @Override
        public String toString() {
            return "tuple{" +
                    "a=" + a +
                    ", b=" + b +
                    '}';
        }
    } tuple Integer a; a Integer b; b public tuple(Integer a, Integer b) {
            this.a = a;
            this.b = b;
        } tuple {
            this.a = a;
            this.b = b;
        } this.a = a this.a this this.a a this.b = b this.b this this.b b Integer a a Integer b b @Override
        public int compareTo(tuple o) {
            return (int) (this.b - o.b);
        } compareTo {
            return (int) (this.b - o.b);
        } return (int) (this.b - o.b); (int) (this.b - o.b) this.b this this.b o.b o o.b tuple o o @Override
        public String toString() {
            return "tuple{" +
                    "a=" + a +
                    ", b=" + b +
                    '}';
        } toString {
            return "tuple{" +
                    "a=" + a +
                    ", b=" + b +
                    '}';
        } return "tuple{" +
                    "a=" + a +
                    ", b=" + b +
                    '}'; "tuple{" +
                    "a=" + a +
                    ", b=" + b +
                    '}' b ", b=" a "tuple{" +
                    "a=" + a +
                    ", b=" + b +
                    '}' "tuple{" "a=" a ", b=" b '}' Comparable class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
            if (neg) return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead) fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null) return;
            din.close();
        }
    } Reader final private int BUFFER_SIZE = 1 << 16; BUFFER_SIZE 1 << 16 1 16 private DataInputStream din; din private byte[] buffer; buffer private int bufferPointer bufferPointer bytesRead; bytesRead public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        } Reader {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        } din = new DataInputStream(System.in) din new DataInputStream(System.in) buffer = new byte[BUFFER_SIZE] buffer new byte[BUFFER_SIZE] BUFFER_SIZE bufferPointer = bytesRead = 0 bufferPointer bytesRead = 0 bytesRead 0 public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        } Reader {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        } din = new DataInputStream(new FileInputStream(file_name)) din new DataInputStream(new FileInputStream(file_name)) buffer = new byte[BUFFER_SIZE] buffer new byte[BUFFER_SIZE] BUFFER_SIZE bufferPointer = bytesRead = 0 bufferPointer bytesRead = 0 bytesRead 0 String file_name file_name public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        } readLine {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        } byte[] buf = new byte[64]; buf new byte[64] 64 int cnt = 0 cnt 0 c; c while ((c = read()) != -1) {
                if (c == '\n') break;
                buf[cnt++] = (byte) c;
            } (c = read()) != -1 (c = read()) c read() read -1 1 {
                if (c == '\n') break;
                buf[cnt++] = (byte) c;
            } if (c == '\n') break; c == '\n' c '\n' break; buf[cnt++] = (byte) c buf[cnt++] buf cnt++ cnt (byte) c return new String(buf, 0, cnt); new String(buf, 0, cnt) public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        } nextInt {
            int ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        } int ret = 0; ret 0 byte c = read(); c read() read while (c <= ' ') c = read(); c <= ' ' c ' ' c = read() c read() read boolean neg = (c == '-'); neg (c == '-') c '-' if (neg) c = read(); neg c = read() c read() read do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9'); (c = read()) >= '0' && c <= '9' (c = read()) >= '0' (c = read()) c read() read '0' c <= '9' c '9' {
                ret = ret * 10 + c - '0';
            } ret = ret * 10 + c - '0' ret ret * 10 + c - '0' ret * 10 + c ret * 10 ret 10 c '0' if (neg) return -ret; neg return -ret; -ret ret return ret; ret public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        } nextLong {
            long ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        } long ret = 0; ret 0 byte c = read(); c read() read while (c <= ' ') c = read(); c <= ' ' c ' ' c = read() c read() read boolean neg = (c == '-'); neg (c == '-') c '-' if (neg) c = read(); neg c = read() c read() read do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9'); (c = read()) >= '0' && c <= '9' (c = read()) >= '0' (c = read()) c read() read '0' c <= '9' c '9' {
                ret = ret * 10 + c - '0';
            } ret = ret * 10 + c - '0' ret ret * 10 + c - '0' ret * 10 + c ret * 10 ret 10 c '0' if (neg) return -ret; neg return -ret; -ret ret return ret; ret public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
            if (neg) return -ret;
            return ret;
        } nextDouble {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
            if (neg) return -ret;
            return ret;
        } double ret = 0 ret 0 div = 1; div 1 byte c = read(); c read() read while (c <= ' ') c = read(); c <= ' ' c ' ' c = read() c read() read boolean neg = (c == '-'); neg (c == '-') c '-' if (neg) c = read(); neg c = read() c read() read do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9'); (c = read()) >= '0' && c <= '9' (c = read()) >= '0' (c = read()) c read() read '0' c <= '9' c '9' {
                ret = ret * 10 + c - '0';
            } ret = ret * 10 + c - '0' ret ret * 10 + c - '0' ret * 10 + c ret * 10 ret 10 c '0' if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10); c == '.' c '.' while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10); (c = read()) >= '0' && c <= '9' (c = read()) >= '0' (c = read()) c read() read '0' c <= '9' c '9' ret += (c - '0') / (div *= 10) ret (c - '0') / (div *= 10) (c - '0') c '0' (div *= 10) div 10 if (neg) return -ret; neg return -ret; -ret ret return ret; ret private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) buffer[0] = -1;
        } fillBuffer {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) buffer[0] = -1;
        } bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE) bytesRead din.read(buffer, bufferPointer = 0, BUFFER_SIZE) din.read din buffer bufferPointer = 0 bufferPointer 0 BUFFER_SIZE if (bytesRead == -1) buffer[0] = -1; bytesRead == -1 bytesRead -1 1 buffer[0] = -1 buffer[0] buffer 0 -1 1 private byte read() throws IOException {
            if (bufferPointer == bytesRead) fillBuffer();
            return buffer[bufferPointer++];
        } read {
            if (bufferPointer == bytesRead) fillBuffer();
            return buffer[bufferPointer++];
        } if (bufferPointer == bytesRead) fillBuffer(); bufferPointer == bytesRead bufferPointer bytesRead fillBuffer() fillBuffer return buffer[bufferPointer++]; buffer[bufferPointer++] buffer bufferPointer++ bufferPointer public void close() throws IOException {
            if (din == null) return;
            din.close();
        } close {
            if (din == null) return;
            din.close();
        } if (din == null) return; din == null din null return; din.close() din.close din public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static long[] tree;
    static int m = 100000000;
    static int k1,k2;
    static boolean[] vis;
    static tuple[] tuples;
    public static void main(String[] args) throws IOException {
        //BufferedReader reader=new BufferedReader(new FileReader("input.txt"));
        //PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //Scanner sc=new Scanner(System.in);
        Reader sc = new Reader();
        //String[] in=reader.readLine().split(" ");

        int n=sc.nextInt();
        int[] h=new int[n];
        for (int i = 0; i <n ; i++) {
            h[i]=sc.nextInt();
        }
        System.out.println(dp(0,n,h));

















        out.close();
    }
    static Integer[] memo=new Integer[100005];
    static int dp(int x,int n,int[] h){
        if (x==n-1)return 0;
        if (memo[x]!=null){
            return memo[x];
        }
        int a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
        if (x+1<n)a=dp(x+1,n,h)+Math.abs(h[x]-h[x+1]);
        if (x+2<n)b=dp(x+2,n,h)+Math.abs(h[x]-h[x+2]);
        return memo[x]=Math.min(a,b);

    }



    static boolean bfs(int a,int b){
        Queue<Integer> queue=new LinkedList<>();
        queue.add(a);

        while (!queue.isEmpty()){
            int now=queue.poll();
            vis[now]=true;

            for (int i = 0; i <k1 ; i++) {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            }
        }

        Arrays.fill(vis,false);
        return false;

    }
    static int find(int[] p,int x){
        if (p[x]==x)return x;

        return p[x]=find(p,p[x]);
    }
    static void union(int[] p,int a,int b){
        p[find(p,b)]=find(p,a);
    }
    static void built(long[] a,int at,int l,int r,int n){
        if (l==r){
            tree[at]=a[l];
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            built(a,left,l,mid,n-1);
            built(a,right,mid+1,r,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    }
    static void update(int at,int l,int r,int i,long v,int n){
        if (i<l || i>r)return;

        if (l==r){
            tree[at]=v;
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            update(left,l,mid,i,v,n-1);
            update(right,mid+1,r,i,v,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    }




} public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static long[] tree;
    static int m = 100000000;
    static int k1,k2;
    static boolean[] vis;
    static tuple[] tuples;
    public static void main(String[] args) throws IOException {
        //BufferedReader reader=new BufferedReader(new FileReader("input.txt"));
        //PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //Scanner sc=new Scanner(System.in);
        Reader sc = new Reader();
        //String[] in=reader.readLine().split(" ");

        int n=sc.nextInt();
        int[] h=new int[n];
        for (int i = 0; i <n ; i++) {
            h[i]=sc.nextInt();
        }
        System.out.println(dp(0,n,h));

















        out.close();
    }
    static Integer[] memo=new Integer[100005];
    static int dp(int x,int n,int[] h){
        if (x==n-1)return 0;
        if (memo[x]!=null){
            return memo[x];
        }
        int a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
        if (x+1<n)a=dp(x+1,n,h)+Math.abs(h[x]-h[x+1]);
        if (x+2<n)b=dp(x+2,n,h)+Math.abs(h[x]-h[x+2]);
        return memo[x]=Math.min(a,b);

    }



    static boolean bfs(int a,int b){
        Queue<Integer> queue=new LinkedList<>();
        queue.add(a);

        while (!queue.isEmpty()){
            int now=queue.poll();
            vis[now]=true;

            for (int i = 0; i <k1 ; i++) {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            }
        }

        Arrays.fill(vis,false);
        return false;

    }
    static int find(int[] p,int x){
        if (p[x]==x)return x;

        return p[x]=find(p,p[x]);
    }
    static void union(int[] p,int a,int b){
        p[find(p,b)]=find(p,a);
    }
    static void built(long[] a,int at,int l,int r,int n){
        if (l==r){
            tree[at]=a[l];
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            built(a,left,l,mid,n-1);
            built(a,right,mid+1,r,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    }
    static void update(int at,int l,int r,int i,long v,int n){
        if (i<l || i>r)return;

        if (l==r){
            tree[at]=v;
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            update(left,l,mid,i,v,n-1);
            update(right,mid+1,r,i,v,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    }




} Main
import javax.swing.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static long[] tree;
    static int m = 100000000;
    static int k1,k2;
    static boolean[] vis;
    static tuple[] tuples;
    public static void main(String[] args) throws IOException {
        //BufferedReader reader=new BufferedReader(new FileReader("input.txt"));
        //PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //Scanner sc=new Scanner(System.in);
        Reader sc = new Reader();
        //String[] in=reader.readLine().split(" ");

        int n=sc.nextInt();
        int[] h=new int[n];
        for (int i = 0; i <n ; i++) {
            h[i]=sc.nextInt();
        }
        System.out.println(dp(0,n,h));

















        out.close();
    }
    static Integer[] memo=new Integer[100005];
    static int dp(int x,int n,int[] h){
        if (x==n-1)return 0;
        if (memo[x]!=null){
            return memo[x];
        }
        int a=Integer.MAX_VALUE,b=Integer.MAX_VALUE;
        if (x+1<n)a=dp(x+1,n,h)+Math.abs(h[x]-h[x+1]);
        if (x+2<n)b=dp(x+2,n,h)+Math.abs(h[x]-h[x+2]);
        return memo[x]=Math.min(a,b);

    }



    static boolean bfs(int a,int b){
        Queue<Integer> queue=new LinkedList<>();
        queue.add(a);

        while (!queue.isEmpty()){
            int now=queue.poll();
            vis[now]=true;

            for (int i = 0; i <k1 ; i++) {
                if (!vis[i]){
                    if((tuples[i].a<tuples[now].a&&tuples[now].a<tuples[i].b)
                                ||(tuples[i].a<tuples[now].b&&tuples[now].b<tuples[i].b)){
                        queue.add(i);
                        if (i==b){
                            Arrays.fill(vis,false);
                            return true;
                        }
                    }
                }
            }
        }

        Arrays.fill(vis,false);
        return false;

    }
    static int find(int[] p,int x){
        if (p[x]==x)return x;

        return p[x]=find(p,p[x]);
    }
    static void union(int[] p,int a,int b){
        p[find(p,b)]=find(p,a);
    }
    static void built(long[] a,int at,int l,int r,int n){
        if (l==r){
            tree[at]=a[l];
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            built(a,left,l,mid,n-1);
            built(a,right,mid+1,r,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    }
    static void update(int at,int l,int r,int i,long v,int n){
        if (i<l || i>r)return;

        if (l==r){
            tree[at]=v;
        }
        else {
            int mid=(l+r)/2;
            int right=2*at;
            int left=(2*at)+1;
            update(left,l,mid,i,v,n-1);
            update(right,mid+1,r,i,v,n-1);
            if (n%2==0)
                tree[at]=tree[left]^tree[right];
            else
                tree[at]=tree[left]|tree[right];
        }
    }




}

    class node implements Comparable<node> {
        Integer no;
        Integer cost;
        Vector<node> adj = new Vector<>();

        public node(Integer no, Integer cost) {
            this.no = no;
            this.cost = cost;
        }

        @Override
        public String toString() {
            return "node{" +
                    "no=" + no +
                    ", cost=" + cost +
                    '}';
        }

        @Override
        public int compareTo(node o) {
            return o.cost - this.cost;
        }
    }

    class edge implements Comparable<edge> {
        tuple u;
        Double cost;

        public edge(tuple u, Double cost) {
            this.u = u;
            this.cost = cost;
        }

        @Override
        public int compareTo(edge o) {
            return this.cost.compareTo(o.cost);
        }

        @Override
        public String toString() {
            return "edge{" +
                    "u=" + u +
                    ", cost=" + cost +
                    '}';
        }
    }

    ///*
    class tuple implements Comparable<tuple> {
        Integer a;
        Integer b;

        public tuple(Integer a, Integer b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(tuple o) {
            return (int) (this.b - o.b);
        }

        @Override
        public String toString() {
            return "tuple{" +
                    "a=" + a +
                    ", b=" + b +
                    '}';
        }
    }


    //*/
    class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
            if (neg) return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead) fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null) return;
            din.close();
        }
    }