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

/**
 * @author radhakm
 * https://atcoder.jp/contests/dp/tasks/dp_a
 */
public class Main {
    static int[] h;
    static int n;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }

        int minCost = Math.abs(h[idx] - h[idx+1]) + frogJump(idx+1);
        if(idx+2<n) {
            int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2);
            minCost = Math.min(minCost,cost);
        }
        dp[idx] = minCost;
        return minCost;
    }
}

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());
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main {
    static int[] h;
    static int n;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }

        int minCost = Math.abs(h[idx] - h[idx+1]) + frogJump(idx+1);
        if(idx+2<n) {
            int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2);
            minCost = Math.min(minCost,cost);
        }
        dp[idx] = minCost;
        return minCost;
    }
} Main static int[] h; h static int n; n static Integer[] dp; dp public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    } main {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    } InputReader reader = new InputReader(System.in); reader new InputReader(System.in) n = reader.nextInt() n reader.nextInt() reader.nextInt reader h = new int[n] h new int[n] n dp = new Integer[n] dp new Integer[n] n for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            h[i] = reader.nextInt();
        } {
            h[i] = reader.nextInt();
        } h[i] = reader.nextInt() h[i] h i reader.nextInt() reader.nextInt reader System.out.println(frogJump(0)) System.out.println System.out System System.out frogJump(0) frogJump 0 String[] args args static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }

        int minCost = Math.abs(h[idx] - h[idx+1]) + frogJump(idx+1);
        if(idx+2<n) {
            int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2);
            minCost = Math.min(minCost,cost);
        }
        dp[idx] = minCost;
        return minCost;
    } frogJump {
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }

        int minCost = Math.abs(h[idx] - h[idx+1]) + frogJump(idx+1);
        if(idx+2<n) {
            int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2);
            minCost = Math.min(minCost,cost);
        }
        dp[idx] = minCost;
        return minCost;
    } if(idx == n-1){
            return 0;
        } idx == n-1 idx n-1 n 1 {
            return 0;
        } return 0; 0 if(dp[idx]!=null){
            return dp[idx];
        } dp[idx]!=null dp[idx] dp idx null {
            return dp[idx];
        } return dp[idx]; dp[idx] dp idx int minCost = Math.abs(h[idx] - h[idx+1]) + frogJump(idx+1); minCost Math.abs(h[idx] - h[idx+1]) + frogJump(idx+1) Math.abs(h[idx] - h[idx+1]) Math.abs Math h[idx] - h[idx+1] h[idx] h idx h[idx+1] h idx+1 idx 1 frogJump(idx+1) frogJump idx+1 idx 1 if(idx+2<n) {
            int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2);
            minCost = Math.min(minCost,cost);
        } idx+2<n idx+2 idx 2 n {
            int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2);
            minCost = Math.min(minCost,cost);
        } int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2); cost Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2) Math.abs(h[idx] - h[idx+2]) Math.abs Math h[idx] - h[idx+2] h[idx] h idx h[idx+2] h idx+2 idx 2 frogJump(idx+2) frogJump idx+2 idx 2 minCost = Math.min(minCost,cost) minCost Math.min(minCost,cost) Math.min Math minCost cost dp[idx] = minCost dp[idx] dp idx minCost return minCost; minCost int idx idx 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());
  }
} 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 class Main {
    static int[] h;
    static int n;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }

        int minCost = Math.abs(h[idx] - h[idx+1]) + frogJump(idx+1);
        if(idx+2<n) {
            int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2);
            minCost = Math.min(minCost,cost);
        }
        dp[idx] = minCost;
        return minCost;
    }
} public class Main {
    static int[] h;
    static int n;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }

        int minCost = Math.abs(h[idx] - h[idx+1]) + frogJump(idx+1);
        if(idx+2<n) {
            int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2);
            minCost = Math.min(minCost,cost);
        }
        dp[idx] = minCost;
        return minCost;
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author radhakm
 * https://atcoder.jp/contests/dp/tasks/dp_a
 */
public class Main {
    static int[] h;
    static int n;
    static Integer[] dp;
    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        n = reader.nextInt();
        h = new int[n];
        dp = new Integer[n];
        for(int i=0;i<n;i++){
            h[i] = reader.nextInt();
        }
        System.out.println(frogJump(0));
    }

    static int frogJump(int idx){
        if(idx == n-1){
            return 0;
        }
        if(dp[idx]!=null){
            return dp[idx];
        }

        int minCost = Math.abs(h[idx] - h[idx+1]) + frogJump(idx+1);
        if(idx+2<n) {
            int cost = Math.abs(h[idx] - h[idx+2]) + frogJump(idx+2);
            minCost = Math.min(minCost,cost);
        }
        dp[idx] = minCost;
        return minCost;
    }
}

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());
  }
}