import java.util.*;

public class Main{
  public static int dp[];
  public static int func(int a[],int i)
  {
    if(i>=a.length)
    return 10000000;
    if(i==a.length-1)
    return 0;
    if(dp[i]!=-1)
    return dp[i];
    if(i<a.length-2)
    {
      dp[i]=Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1));
    }
    else
    {
      dp[i]=Math.abs(a[i]-a[i+1])+func(a,i+1);
    }
    return dp[i];
  }
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    dp=new int[n+1];
    for(int i=0;i<n;i++)
    a[i]=sc.nextInt();
    for(int i=0;i<=n;i++)
    dp[i]=-1;
    System.out.println(func(a,0));
  }
} import java.util.*; util.* java public class Main{
  public static int dp[];
  public static int func(int a[],int i)
  {
    if(i>=a.length)
    return 10000000;
    if(i==a.length-1)
    return 0;
    if(dp[i]!=-1)
    return dp[i];
    if(i<a.length-2)
    {
      dp[i]=Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1));
    }
    else
    {
      dp[i]=Math.abs(a[i]-a[i+1])+func(a,i+1);
    }
    return dp[i];
  }
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    dp=new int[n+1];
    for(int i=0;i<n;i++)
    a[i]=sc.nextInt();
    for(int i=0;i<=n;i++)
    dp[i]=-1;
    System.out.println(func(a,0));
  }
} Main public static int dp[]; dp public static int func(int a[],int i)
  {
    if(i>=a.length)
    return 10000000;
    if(i==a.length-1)
    return 0;
    if(dp[i]!=-1)
    return dp[i];
    if(i<a.length-2)
    {
      dp[i]=Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1));
    }
    else
    {
      dp[i]=Math.abs(a[i]-a[i+1])+func(a,i+1);
    }
    return dp[i];
  } func {
    if(i>=a.length)
    return 10000000;
    if(i==a.length-1)
    return 0;
    if(dp[i]!=-1)
    return dp[i];
    if(i<a.length-2)
    {
      dp[i]=Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1));
    }
    else
    {
      dp[i]=Math.abs(a[i]-a[i+1])+func(a,i+1);
    }
    return dp[i];
  } if(i>=a.length)
    return 10000000; i>=a.length i a.length a a.length return 10000000; 10000000 if(i==a.length-1)
    return 0; i==a.length-1 i a.length-1 a.length a a.length 1 return 0; 0 if(dp[i]!=-1)
    return dp[i]; dp[i]!=-1 dp[i] dp i -1 1 return dp[i]; dp[i] dp i if(i<a.length-2)
    {
      dp[i]=Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1));
    }
    else
    {
      dp[i]=Math.abs(a[i]-a[i+1])+func(a,i+1);
    } i<a.length-2 i a.length-2 a.length a a.length 2 {
      dp[i]=Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1));
    } dp[i]=Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1)) dp[i] dp i Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1)) Math.min Math Math.abs(a[i]-a[i+2])+
            func(a,i+2) Math.abs(a[i]-a[i+2]) Math.abs Math a[i]-a[i+2] a[i] a i a[i+2] a i+2 i 2 func(a,i+2) func a i+2 i 2 Math.abs(a[i]-a[i+1])+
            func(a,i+1) Math.abs(a[i]-a[i+1]) Math.abs Math a[i]-a[i+1] a[i] a i a[i+1] a i+1 i 1 func(a,i+1) func a i+1 i 1 {
      dp[i]=Math.abs(a[i]-a[i+1])+func(a,i+1);
    } dp[i]=Math.abs(a[i]-a[i+1])+func(a,i+1) dp[i] dp i Math.abs(a[i]-a[i+1])+func(a,i+1) Math.abs(a[i]-a[i+1]) Math.abs Math a[i]-a[i+1] a[i] a i a[i+1] a i+1 i 1 func(a,i+1) func a i+1 i 1 return dp[i]; dp[i] dp i int a[] a int i i public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    dp=new int[n+1];
    for(int i=0;i<n;i++)
    a[i]=sc.nextInt();
    for(int i=0;i<=n;i++)
    dp[i]=-1;
    System.out.println(func(a,0));
  } main {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    dp=new int[n+1];
    for(int i=0;i<n;i++)
    a[i]=sc.nextInt();
    for(int i=0;i<=n;i++)
    dp[i]=-1;
    System.out.println(func(a,0));
  } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int a[]=new int[n]; a new int[n] n dp=new int[n+1] dp new int[n+1] n+1 n 1 for(int i=0;i<n;i++)
    a[i]=sc.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i]=sc.nextInt(); a[i]=sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc for(int i=0;i<=n;i++)
    dp[i]=-1; int i=0; int i=0; i 0 i<=n i n i++ i++ i dp[i]=-1; dp[i]=-1 dp[i] dp i -1 1 System.out.println(func(a,0)) System.out.println System.out System System.out func(a,0) func a 0 String[] args args public class Main{
  public static int dp[];
  public static int func(int a[],int i)
  {
    if(i>=a.length)
    return 10000000;
    if(i==a.length-1)
    return 0;
    if(dp[i]!=-1)
    return dp[i];
    if(i<a.length-2)
    {
      dp[i]=Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1));
    }
    else
    {
      dp[i]=Math.abs(a[i]-a[i+1])+func(a,i+1);
    }
    return dp[i];
  }
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    dp=new int[n+1];
    for(int i=0;i<n;i++)
    a[i]=sc.nextInt();
    for(int i=0;i<=n;i++)
    dp[i]=-1;
    System.out.println(func(a,0));
  }
} public class Main{
  public static int dp[];
  public static int func(int a[],int i)
  {
    if(i>=a.length)
    return 10000000;
    if(i==a.length-1)
    return 0;
    if(dp[i]!=-1)
    return dp[i];
    if(i<a.length-2)
    {
      dp[i]=Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1));
    }
    else
    {
      dp[i]=Math.abs(a[i]-a[i+1])+func(a,i+1);
    }
    return dp[i];
  }
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    dp=new int[n+1];
    for(int i=0;i<n;i++)
    a[i]=sc.nextInt();
    for(int i=0;i<=n;i++)
    dp[i]=-1;
    System.out.println(func(a,0));
  }
} Main
import java.util.*;

public class Main{
  public static int dp[];
  public static int func(int a[],int i)
  {
    if(i>=a.length)
    return 10000000;
    if(i==a.length-1)
    return 0;
    if(dp[i]!=-1)
    return dp[i];
    if(i<a.length-2)
    {
      dp[i]=Math.min(Math.abs(a[i]-a[i+2])+
            func(a,i+2),
            Math.abs(a[i]-a[i+1])+
            func(a,i+1));
    }
    else
    {
      dp[i]=Math.abs(a[i]-a[i+1])+func(a,i+1);
    }
    return dp[i];
  }
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[]=new int[n];
    dp=new int[n+1];
    for(int i=0;i<n;i++)
    a[i]=sc.nextInt();
    for(int i=0;i<=n;i++)
    dp[i]=-1;
    System.out.println(func(a,0));
  }
}