import java.util.*;
class Main{
  static Integer []cache;
  public static void main(String []args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    cache=new Integer[n];
    int []height=new int[n];
    for(int i=0;i<n;i++){
      height[i]=sc.nextInt();
    }
    System.out.println(ans(height,0));
  }
        
    public static int ans(int[] h,int index){
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int one=Integer.MAX_VALUE;
        int two=Integer.MAX_VALUE;
        if(index+1<h.length){
            one=ans(h,index+1)+Math.abs(h[index]-h[index+1]);
        }
        if(index+2<h.length){
            two=ans(h,index+2)+Math.abs(h[index]-h[index+2]);
        }
        return cache[index]=Math.min(one,two);
    }
} import java.util.*; util.* java class Main{
  static Integer []cache;
  public static void main(String []args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    cache=new Integer[n];
    int []height=new int[n];
    for(int i=0;i<n;i++){
      height[i]=sc.nextInt();
    }
    System.out.println(ans(height,0));
  }
        
    public static int ans(int[] h,int index){
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int one=Integer.MAX_VALUE;
        int two=Integer.MAX_VALUE;
        if(index+1<h.length){
            one=ans(h,index+1)+Math.abs(h[index]-h[index+1]);
        }
        if(index+2<h.length){
            two=ans(h,index+2)+Math.abs(h[index]-h[index+2]);
        }
        return cache[index]=Math.min(one,two);
    }
} Main static Integer []cache; cache public static void main(String []args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    cache=new Integer[n];
    int []height=new int[n];
    for(int i=0;i<n;i++){
      height[i]=sc.nextInt();
    }
    System.out.println(ans(height,0));
  } main {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    cache=new Integer[n];
    int []height=new int[n];
    for(int i=0;i<n;i++){
      height[i]=sc.nextInt();
    }
    System.out.println(ans(height,0));
  } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc cache=new Integer[n] cache new Integer[n] n int []height=new int[n]; height new int[n] n for(int i=0;i<n;i++){
      height[i]=sc.nextInt();
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      height[i]=sc.nextInt();
    } {
      height[i]=sc.nextInt();
    } height[i]=sc.nextInt() height[i] height i sc.nextInt() sc.nextInt sc System.out.println(ans(height,0)) System.out.println System.out System System.out ans(height,0) ans height 0 String []args args public static int ans(int[] h,int index){
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int one=Integer.MAX_VALUE;
        int two=Integer.MAX_VALUE;
        if(index+1<h.length){
            one=ans(h,index+1)+Math.abs(h[index]-h[index+1]);
        }
        if(index+2<h.length){
            two=ans(h,index+2)+Math.abs(h[index]-h[index+2]);
        }
        return cache[index]=Math.min(one,two);
    } ans {
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int one=Integer.MAX_VALUE;
        int two=Integer.MAX_VALUE;
        if(index+1<h.length){
            one=ans(h,index+1)+Math.abs(h[index]-h[index+1]);
        }
        if(index+2<h.length){
            two=ans(h,index+2)+Math.abs(h[index]-h[index+2]);
        }
        return cache[index]=Math.min(one,two);
    } if(index==h.length-1) return 0; index==h.length-1 index h.length-1 h.length h h.length 1 return 0; 0 if(cache[index]!=null) return cache[index]; cache[index]!=null cache[index] cache index null return cache[index]; cache[index] cache index int one=Integer.MAX_VALUE; one Integer.MAX_VALUE Integer Integer.MAX_VALUE int two=Integer.MAX_VALUE; two Integer.MAX_VALUE Integer Integer.MAX_VALUE if(index+1<h.length){
            one=ans(h,index+1)+Math.abs(h[index]-h[index+1]);
        } index+1<h.length index+1 index 1 h.length h h.length {
            one=ans(h,index+1)+Math.abs(h[index]-h[index+1]);
        } one=ans(h,index+1)+Math.abs(h[index]-h[index+1]) one ans(h,index+1)+Math.abs(h[index]-h[index+1]) ans(h,index+1) ans h index+1 index 1 Math.abs(h[index]-h[index+1]) Math.abs Math h[index]-h[index+1] h[index] h index h[index+1] h index+1 index 1 if(index+2<h.length){
            two=ans(h,index+2)+Math.abs(h[index]-h[index+2]);
        } index+2<h.length index+2 index 2 h.length h h.length {
            two=ans(h,index+2)+Math.abs(h[index]-h[index+2]);
        } two=ans(h,index+2)+Math.abs(h[index]-h[index+2]) two ans(h,index+2)+Math.abs(h[index]-h[index+2]) ans(h,index+2) ans h index+2 index 2 Math.abs(h[index]-h[index+2]) Math.abs Math h[index]-h[index+2] h[index] h index h[index+2] h index+2 index 2 return cache[index]=Math.min(one,two); cache[index]=Math.min(one,two) cache[index] cache index Math.min(one,two) Math.min Math one two int[] h h int index index
import java.util.*;
class Main{
  static Integer []cache;
  public static void main(String []args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    cache=new Integer[n];
    int []height=new int[n];
    for(int i=0;i<n;i++){
      height[i]=sc.nextInt();
    }
    System.out.println(ans(height,0));
  }
        
    public static int ans(int[] h,int index){
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int one=Integer.MAX_VALUE;
        int two=Integer.MAX_VALUE;
        if(index+1<h.length){
            one=ans(h,index+1)+Math.abs(h[index]-h[index+1]);
        }
        if(index+2<h.length){
            two=ans(h,index+2)+Math.abs(h[index]-h[index+2]);
        }
        return cache[index]=Math.min(one,two);
    }
}