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

public class Main
{
  static class FastScanner
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    String next() {
      while(!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      }
      return st.nextToken();
    }
    
    int nextInt() {
      return Integer.parseInt(next());
    }
    
    long nextLong() {
      return Long.parseLong(next());
    }
    
  }
  
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int n = fs.nextInt();
    int[] arr = new int[n];
    for(int i = 0; i < n; ++i) {
      arr[i] = fs.nextInt();
    }
    int[] dp = new int[n];
    dp[1] = (int)Math.abs(arr[1]-arr[0]);
    for(int i = 2; i < n; ++i) {
      dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]));
    }
    PrintWriter out = new PrintWriter(System.out);
    out.println(dp[n-1]);
    out.close();
  }

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main
{
  static class FastScanner
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    String next() {
      while(!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      }
      return st.nextToken();
    }
    
    int nextInt() {
      return Integer.parseInt(next());
    }
    
    long nextLong() {
      return Long.parseLong(next());
    }
    
  }
  
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int n = fs.nextInt();
    int[] arr = new int[n];
    for(int i = 0; i < n; ++i) {
      arr[i] = fs.nextInt();
    }
    int[] dp = new int[n];
    dp[1] = (int)Math.abs(arr[1]-arr[0]);
    for(int i = 2; i < n; ++i) {
      dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]));
    }
    PrintWriter out = new PrintWriter(System.out);
    out.println(dp[n-1]);
    out.close();
  }

} Main public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int n = fs.nextInt();
    int[] arr = new int[n];
    for(int i = 0; i < n; ++i) {
      arr[i] = fs.nextInt();
    }
    int[] dp = new int[n];
    dp[1] = (int)Math.abs(arr[1]-arr[0]);
    for(int i = 2; i < n; ++i) {
      dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]));
    }
    PrintWriter out = new PrintWriter(System.out);
    out.println(dp[n-1]);
    out.close();
  } main {
    FastScanner fs = new FastScanner();
    int n = fs.nextInt();
    int[] arr = new int[n];
    for(int i = 0; i < n; ++i) {
      arr[i] = fs.nextInt();
    }
    int[] dp = new int[n];
    dp[1] = (int)Math.abs(arr[1]-arr[0]);
    for(int i = 2; i < n; ++i) {
      dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]));
    }
    PrintWriter out = new PrintWriter(System.out);
    out.println(dp[n-1]);
    out.close();
  } FastScanner fs = new FastScanner(); fs new FastScanner() int n = fs.nextInt(); n fs.nextInt() fs.nextInt fs int[] arr = new int[n]; arr new int[n] n for(int i = 0; i < n; ++i) {
      arr[i] = fs.nextInt();
    } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
      arr[i] = fs.nextInt();
    } {
      arr[i] = fs.nextInt();
    } arr[i] = fs.nextInt() arr[i] arr i fs.nextInt() fs.nextInt fs int[] dp = new int[n]; dp new int[n] n dp[1] = (int)Math.abs(arr[1]-arr[0]) dp[1] dp 1 (int)Math.abs(arr[1]-arr[0]) Math.abs Math arr[1]-arr[0] arr[1] arr 1 arr[0] arr 0 for(int i = 2; i < n; ++i) {
      dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]));
    } int i = 2; int i = 2; i 2 i < n i n ++i ++i i {
      dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]));
    } {
      dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]));
    } dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i])) dp[i] dp i Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i])) Math.min Math dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]) dp[i-1] dp i-1 i 1 (int)Math.abs(arr[i-1]-arr[i]) Math.abs Math arr[i-1]-arr[i] arr[i-1] arr i-1 i 1 arr[i] arr i dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]) dp[i-2] dp i-2 i 2 (int)Math.abs(arr[i-2]-arr[i]) Math.abs Math arr[i-2]-arr[i] arr[i-2] arr i-2 i 2 arr[i] arr i PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) out.println(dp[n-1]) out.println out dp[n-1] dp n-1 n 1 out.close() out.close out String[] args args static class FastScanner
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    String next() {
      while(!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      }
      return st.nextToken();
    }
    
    int nextInt() {
      return Integer.parseInt(next());
    }
    
    long nextLong() {
      return Long.parseLong(next());
    }
    
  } FastScanner BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st = new StringTokenizer(""); st new StringTokenizer("") String next() {
      while(!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      }
      return st.nextToken();
    } next {
      while(!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      }
      return st.nextToken();
    } while(!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      } !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      } try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {} catch (IOException e) {} IOException e {} {
          st = new StringTokenizer(br.readLine());
        } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st int nextInt() {
      return Integer.parseInt(next());
    } nextInt {
      return Integer.parseInt(next());
    } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next 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
{
  static class FastScanner
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    String next() {
      while(!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      }
      return st.nextToken();
    }
    
    int nextInt() {
      return Integer.parseInt(next());
    }
    
    long nextLong() {
      return Long.parseLong(next());
    }
    
  }
  
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int n = fs.nextInt();
    int[] arr = new int[n];
    for(int i = 0; i < n; ++i) {
      arr[i] = fs.nextInt();
    }
    int[] dp = new int[n];
    dp[1] = (int)Math.abs(arr[1]-arr[0]);
    for(int i = 2; i < n; ++i) {
      dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]));
    }
    PrintWriter out = new PrintWriter(System.out);
    out.println(dp[n-1]);
    out.close();
  }

} public class Main
{
  static class FastScanner
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    String next() {
      while(!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      }
      return st.nextToken();
    }
    
    int nextInt() {
      return Integer.parseInt(next());
    }
    
    long nextLong() {
      return Long.parseLong(next());
    }
    
  }
  
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int n = fs.nextInt();
    int[] arr = new int[n];
    for(int i = 0; i < n; ++i) {
      arr[i] = fs.nextInt();
    }
    int[] dp = new int[n];
    dp[1] = (int)Math.abs(arr[1]-arr[0]);
    for(int i = 2; i < n; ++i) {
      dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]));
    }
    PrintWriter out = new PrintWriter(System.out);
    out.println(dp[n-1]);
    out.close();
  }

} Main

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

public class Main
{
  static class FastScanner
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    String next() {
      while(!st.hasMoreTokens()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {}
      }
      return st.nextToken();
    }
    
    int nextInt() {
      return Integer.parseInt(next());
    }
    
    long nextLong() {
      return Long.parseLong(next());
    }
    
  }
  
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int n = fs.nextInt();
    int[] arr = new int[n];
    for(int i = 0; i < n; ++i) {
      arr[i] = fs.nextInt();
    }
    int[] dp = new int[n];
    dp[1] = (int)Math.abs(arr[1]-arr[0]);
    for(int i = 2; i < n; ++i) {
      dp[i] = Math.min(dp[i-1] + (int)Math.abs(arr[i-1]-arr[i]), 
          dp[i-2] + (int)Math.abs(arr[i-2]-arr[i]));
    }
    PrintWriter out = new PrintWriter(System.out);
    out.println(dp[n-1]);
    out.close();
  }

}
