import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        int N = Integer.parseInt(input.readLine());
        StringTokenizer st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
            if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1]));
            if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2]));
        }
        output.println(dp[N-1]);

        /*boolean[] visited = new boolean[N];
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        PriorityQueue<Node> pq = new PriorityQueue<Node>();
        pq.add(new Node(1, Math.abs(arr[0] - arr[1])));
        if(N>2)
            pq.add(new Node(2, Math.abs(arr[0] - arr[2])));

        while(!pq.isEmpty()){
            Node n = pq.poll();
            if(visited[n.i]) continue;
            visited[n.i] = true;
            if(n.i == N-1){
                output.println(n.d);
                break;
            }
            if(n.i<N-1)
                pq.add(new Node(n.i+1, n.d + Math.abs(arr[n.i] - arr[n.i+1])));
            if(n.i<N-2)
                pq.add(new Node(n.i+2, n.d + Math.abs(arr[n.i] - arr[n.i+2])));
        }
        */
        output.close();
    }
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        int N = Integer.parseInt(input.readLine());
        StringTokenizer st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
            if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1]));
            if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2]));
        }
        output.println(dp[N-1]);

        /*boolean[] visited = new boolean[N];
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        PriorityQueue<Node> pq = new PriorityQueue<Node>();
        pq.add(new Node(1, Math.abs(arr[0] - arr[1])));
        if(N>2)
            pq.add(new Node(2, Math.abs(arr[0] - arr[2])));

        while(!pq.isEmpty()){
            Node n = pq.poll();
            if(visited[n.i]) continue;
            visited[n.i] = true;
            if(n.i == N-1){
                output.println(n.d);
                break;
            }
            if(n.i<N-1)
                pq.add(new Node(n.i+1, n.d + Math.abs(arr[n.i] - arr[n.i+1])));
            if(n.i<N-2)
                pq.add(new Node(n.i+2, n.d + Math.abs(arr[n.i] - arr[n.i+2])));
        }
        */
        output.close();
    }
} Main public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        int N = Integer.parseInt(input.readLine());
        StringTokenizer st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
            if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1]));
            if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2]));
        }
        output.println(dp[N-1]);

        /*boolean[] visited = new boolean[N];
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        PriorityQueue<Node> pq = new PriorityQueue<Node>();
        pq.add(new Node(1, Math.abs(arr[0] - arr[1])));
        if(N>2)
            pq.add(new Node(2, Math.abs(arr[0] - arr[2])));

        while(!pq.isEmpty()){
            Node n = pq.poll();
            if(visited[n.i]) continue;
            visited[n.i] = true;
            if(n.i == N-1){
                output.println(n.d);
                break;
            }
            if(n.i<N-1)
                pq.add(new Node(n.i+1, n.d + Math.abs(arr[n.i] - arr[n.i+1])));
            if(n.i<N-2)
                pq.add(new Node(n.i+2, n.d + Math.abs(arr[n.i] - arr[n.i+2])));
        }
        */
        output.close();
    } main {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        int N = Integer.parseInt(input.readLine());
        StringTokenizer st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
            if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1]));
            if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2]));
        }
        output.println(dp[N-1]);

        /*boolean[] visited = new boolean[N];
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        PriorityQueue<Node> pq = new PriorityQueue<Node>();
        pq.add(new Node(1, Math.abs(arr[0] - arr[1])));
        if(N>2)
            pq.add(new Node(2, Math.abs(arr[0] - arr[2])));

        while(!pq.isEmpty()){
            Node n = pq.poll();
            if(visited[n.i]) continue;
            visited[n.i] = true;
            if(n.i == N-1){
                output.println(n.d);
                break;
            }
            if(n.i<N-1)
                pq.add(new Node(n.i+1, n.d + Math.abs(arr[n.i] - arr[n.i+1])));
            if(n.i<N-2)
                pq.add(new Node(n.i+2, n.d + Math.abs(arr[n.i] - arr[n.i+2])));
        }
        */
        output.close();
    } BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); input new BufferedReader(new InputStreamReader(System.in)) PrintWriter output = new PrintWriter(System.out); output new PrintWriter(System.out) int N = Integer.parseInt(input.readLine()); N Integer.parseInt(input.readLine()) Integer.parseInt Integer input.readLine() input.readLine input StringTokenizer st = new StringTokenizer(input.readLine()); st new StringTokenizer(input.readLine()) int[] arr = new int[N]; arr new int[N] N int[] dp = new int[N+1]; dp new int[N+1] N+1 N 1 Arrays.fill(dp, Integer.MAX_VALUE) Arrays.fill Arrays dp Integer.MAX_VALUE Integer Integer.MAX_VALUE dp[0] = 0 dp[0] dp 0 0 for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
            arr[i] = Integer.parseInt(st.nextToken());
        } {
            arr[i] = Integer.parseInt(st.nextToken());
        } arr[i] = Integer.parseInt(st.nextToken()) arr[i] arr i Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st for(int i = 0; i<N; i++){
            if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1]));
            if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2]));
        } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
            if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1]));
            if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2]));
        } {
            if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1]));
            if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2]));
        } if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1])); i+1<N i+1 i 1 N dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1])) dp[i+1] dp i+1 i 1 Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1])) Math.min Math dp[i+1] dp i+1 i 1 dp[i] + Math.abs(arr[i] - arr[i+1]) dp[i] dp i 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 if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2])); i+2<N i+2 i 2 N dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2])) dp[i+2] dp i+2 i 2 Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2])) Math.min Math dp[i+2] dp i+2 i 2 dp[i] + Math.abs(arr[i] - arr[i+2]) dp[i] dp i 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 output.println(dp[N-1]) output.println output dp[N-1] dp N-1 N 1 output.close() output.close output String[] args args public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        int N = Integer.parseInt(input.readLine());
        StringTokenizer st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
            if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1]));
            if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2]));
        }
        output.println(dp[N-1]);

        /*boolean[] visited = new boolean[N];
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        PriorityQueue<Node> pq = new PriorityQueue<Node>();
        pq.add(new Node(1, Math.abs(arr[0] - arr[1])));
        if(N>2)
            pq.add(new Node(2, Math.abs(arr[0] - arr[2])));

        while(!pq.isEmpty()){
            Node n = pq.poll();
            if(visited[n.i]) continue;
            visited[n.i] = true;
            if(n.i == N-1){
                output.println(n.d);
                break;
            }
            if(n.i<N-1)
                pq.add(new Node(n.i+1, n.d + Math.abs(arr[n.i] - arr[n.i+1])));
            if(n.i<N-2)
                pq.add(new Node(n.i+2, n.d + Math.abs(arr[n.i] - arr[n.i+2])));
        }
        */
        output.close();
    }
} public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        int N = Integer.parseInt(input.readLine());
        StringTokenizer st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
            if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1]));
            if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2]));
        }
        output.println(dp[N-1]);

        /*boolean[] visited = new boolean[N];
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        PriorityQueue<Node> pq = new PriorityQueue<Node>();
        pq.add(new Node(1, Math.abs(arr[0] - arr[1])));
        if(N>2)
            pq.add(new Node(2, Math.abs(arr[0] - arr[2])));

        while(!pq.isEmpty()){
            Node n = pq.poll();
            if(visited[n.i]) continue;
            visited[n.i] = true;
            if(n.i == N-1){
                output.println(n.d);
                break;
            }
            if(n.i<N-1)
                pq.add(new Node(n.i+1, n.d + Math.abs(arr[n.i] - arr[n.i+1])));
            if(n.i<N-2)
                pq.add(new Node(n.i+2, n.d + Math.abs(arr[n.i] - arr[n.i+2])));
        }
        */
        output.close();
    }
} Main
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter output = new PrintWriter(System.out);
        int N = Integer.parseInt(input.readLine());
        StringTokenizer st = new StringTokenizer(input.readLine());
        int[] arr = new int[N];
        int[] dp = new int[N+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        for(int i = 0; i<N; i++){
            if(i+1<N) dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(arr[i] - arr[i+1]));
            if(i+2<N) dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(arr[i] - arr[i+2]));
        }
        output.println(dp[N-1]);

        /*boolean[] visited = new boolean[N];
        for(int i = 0; i<N; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        PriorityQueue<Node> pq = new PriorityQueue<Node>();
        pq.add(new Node(1, Math.abs(arr[0] - arr[1])));
        if(N>2)
            pq.add(new Node(2, Math.abs(arr[0] - arr[2])));

        while(!pq.isEmpty()){
            Node n = pq.poll();
            if(visited[n.i]) continue;
            visited[n.i] = true;
            if(n.i == N-1){
                output.println(n.d);
                break;
            }
            if(n.i<N-1)
                pq.add(new Node(n.i+1, n.d + Math.abs(arr[n.i] - arr[n.i+1])));
            if(n.i<N-2)
                pq.add(new Node(n.i+2, n.d + Math.abs(arr[n.i] - arr[n.i+2])));
        }
        */
        output.close();
    }
}