import java.io.IOException;
import java.util.Scanner;

class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c[] = new int[n];
        int dp[] = new int[n];
        for(int i=0;i<n;i++) {
            c[i] = sc.nextInt();
        }
        for(int i = n-1 ;i>=0;i--) {
            if(i == n-1) dp[i] = 0;
            else {
                int cn = Integer.MAX_VALUE;
                int cnn = Integer.MAX_VALUE;
                if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1];
                if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2];
                //System.out.println("i "+ i + " cn " + cn + " cnn " + cnn);
                dp[i] = Math.min(cn, cnn);
            }
        }
        //for(int i=0;i<n;i++) System.out.print(dp[i] + " ");
        System.out.println(dp[0]);
    }
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c[] = new int[n];
        int dp[] = new int[n];
        for(int i=0;i<n;i++) {
            c[i] = sc.nextInt();
        }
        for(int i = n-1 ;i>=0;i--) {
            if(i == n-1) dp[i] = 0;
            else {
                int cn = Integer.MAX_VALUE;
                int cnn = Integer.MAX_VALUE;
                if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1];
                if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2];
                //System.out.println("i "+ i + " cn " + cn + " cnn " + cnn);
                dp[i] = Math.min(cn, cnn);
            }
        }
        //for(int i=0;i<n;i++) System.out.print(dp[i] + " ");
        System.out.println(dp[0]);
    }
} Main public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c[] = new int[n];
        int dp[] = new int[n];
        for(int i=0;i<n;i++) {
            c[i] = sc.nextInt();
        }
        for(int i = n-1 ;i>=0;i--) {
            if(i == n-1) dp[i] = 0;
            else {
                int cn = Integer.MAX_VALUE;
                int cnn = Integer.MAX_VALUE;
                if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1];
                if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2];
                //System.out.println("i "+ i + " cn " + cn + " cnn " + cnn);
                dp[i] = Math.min(cn, cnn);
            }
        }
        //for(int i=0;i<n;i++) System.out.print(dp[i] + " ");
        System.out.println(dp[0]);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c[] = new int[n];
        int dp[] = new int[n];
        for(int i=0;i<n;i++) {
            c[i] = sc.nextInt();
        }
        for(int i = n-1 ;i>=0;i--) {
            if(i == n-1) dp[i] = 0;
            else {
                int cn = Integer.MAX_VALUE;
                int cnn = Integer.MAX_VALUE;
                if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1];
                if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2];
                //System.out.println("i "+ i + " cn " + cn + " cnn " + cnn);
                dp[i] = Math.min(cn, cnn);
            }
        }
        //for(int i=0;i<n;i++) System.out.print(dp[i] + " ");
        System.out.println(dp[0]);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int c[] = new int[n]; c new int[n] n int dp[] = new int[n]; dp new int[n] n for(int i=0;i<n;i++) {
            c[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            c[i] = sc.nextInt();
        } {
            c[i] = sc.nextInt();
        } c[i] = sc.nextInt() c[i] c i sc.nextInt() sc.nextInt sc for(int i = n-1 ;i>=0;i--) {
            if(i == n-1) dp[i] = 0;
            else {
                int cn = Integer.MAX_VALUE;
                int cnn = Integer.MAX_VALUE;
                if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1];
                if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2];
                //System.out.println("i "+ i + " cn " + cn + " cnn " + cnn);
                dp[i] = Math.min(cn, cnn);
            }
        } int i = n-1 ; int i = n-1 ; i n-1 n 1 i>=0 i 0 i-- i-- i {
            if(i == n-1) dp[i] = 0;
            else {
                int cn = Integer.MAX_VALUE;
                int cnn = Integer.MAX_VALUE;
                if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1];
                if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2];
                //System.out.println("i "+ i + " cn " + cn + " cnn " + cnn);
                dp[i] = Math.min(cn, cnn);
            }
        } {
            if(i == n-1) dp[i] = 0;
            else {
                int cn = Integer.MAX_VALUE;
                int cnn = Integer.MAX_VALUE;
                if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1];
                if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2];
                //System.out.println("i "+ i + " cn " + cn + " cnn " + cnn);
                dp[i] = Math.min(cn, cnn);
            }
        } if(i == n-1) dp[i] = 0;
            else {
                int cn = Integer.MAX_VALUE;
                int cnn = Integer.MAX_VALUE;
                if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1];
                if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2];
                //System.out.println("i "+ i + " cn " + cn + " cnn " + cnn);
                dp[i] = Math.min(cn, cnn);
            } i == n-1 i n-1 n 1 dp[i] = 0 dp[i] dp i 0 {
                int cn = Integer.MAX_VALUE;
                int cnn = Integer.MAX_VALUE;
                if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1];
                if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2];
                //System.out.println("i "+ i + " cn " + cn + " cnn " + cnn);
                dp[i] = Math.min(cn, cnn);
            } int cn = Integer.MAX_VALUE; cn Integer.MAX_VALUE Integer Integer.MAX_VALUE int cnn = Integer.MAX_VALUE; cnn Integer.MAX_VALUE Integer Integer.MAX_VALUE if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1]; (i+1) < n (i+1) i 1 n cn = Math.abs((c[i] - c[i+1])) + dp[i+1] cn Math.abs((c[i] - c[i+1])) + dp[i+1] Math.abs((c[i] - c[i+1])) Math.abs Math (c[i] - c[i+1]) c[i] c i c[i+1] c i+1 i 1 dp[i+1] dp i+1 i 1 if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2]; (i+2) < n (i+2) i 2 n cnn = Math.abs((c[i] - c[i+2])) + dp[i+2] cnn Math.abs((c[i] - c[i+2])) + dp[i+2] Math.abs((c[i] - c[i+2])) Math.abs Math (c[i] - c[i+2]) c[i] c i c[i+2] c i+2 i 2 dp[i+2] dp i+2 i 2 dp[i] = Math.min(cn, cnn) dp[i] dp i Math.min(cn, cnn) Math.min Math cn cnn System.out.println(dp[0]) System.out.println System.out System System.out dp[0] dp 0 String args[] args
import java.io.IOException;
import java.util.Scanner;

class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c[] = new int[n];
        int dp[] = new int[n];
        for(int i=0;i<n;i++) {
            c[i] = sc.nextInt();
        }
        for(int i = n-1 ;i>=0;i--) {
            if(i == n-1) dp[i] = 0;
            else {
                int cn = Integer.MAX_VALUE;
                int cnn = Integer.MAX_VALUE;
                if((i+1) < n) cn = Math.abs((c[i] - c[i+1])) + dp[i+1];
                if((i+2) < n) cnn = Math.abs((c[i] - c[i+2])) + dp[i+2];
                //System.out.println("i "+ i + " cn " + cn + " cnn " + cnn);
                dp[i] = Math.min(cn, cnn);
            }
        }
        //for(int i=0;i<n;i++) System.out.print(dp[i] + " ");
        System.out.println(dp[0]);
    }
}