import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			if(k+1<N) {
				dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k]));
			}
			if(k+2<N) {
				dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k]));
			}
		}
		System.out.println(dp[N-1]);
	}
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java class Main{
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			if(k+1<N) {
				dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k]));
			}
			if(k+2<N) {
				dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k]));
			}
		}
		System.out.println(dp[N-1]);
	}
} Main public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			if(k+1<N) {
				dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k]));
			}
			if(k+2<N) {
				dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k]));
			}
		}
		System.out.println(dp[N-1]);
	} main {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			if(k+1<N) {
				dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k]));
			}
			if(k+2<N) {
				dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k]));
			}
		}
		System.out.println(dp[N-1]);
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int N=sc.nextInt(); N sc.nextInt() sc.nextInt sc int h[]=new int[N]; h new int[N] N for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			h[i]=sc.nextInt();
		} {
			h[i]=sc.nextInt();
		} h[i]=sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc int dp[]=new int[N]; dp new int[N] N dp[0]=0 dp[0] dp 0 0 for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		} int j=1; int j=1; j 1 j<N j N j++ j++ j {
			dp[j]=Integer.MAX_VALUE;
		} {
			dp[j]=Integer.MAX_VALUE;
		} dp[j]=Integer.MAX_VALUE dp[j] dp j Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int k=0;k<N;k++) {
			if(k+1<N) {
				dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k]));
			}
			if(k+2<N) {
				dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k]));
			}
		} int k=0; int k=0; k 0 k<N k N k++ k++ k {
			if(k+1<N) {
				dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k]));
			}
			if(k+2<N) {
				dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k]));
			}
		} {
			if(k+1<N) {
				dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k]));
			}
			if(k+2<N) {
				dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k]));
			}
		} if(k+1<N) {
				dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k]));
			} k+1<N k+1 k 1 N {
				dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k]));
			} dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k])) dp[k+1] dp k+1 k 1 Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k])) Math.min Math dp[k+1] dp k+1 k 1 dp[k]+Math.abs(h[k+1]-h[k]) dp[k] dp k Math.abs(h[k+1]-h[k]) Math.abs Math h[k+1]-h[k] h[k+1] h k+1 k 1 h[k] h k if(k+2<N) {
				dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k]));
			} k+2<N k+2 k 2 N {
				dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k]));
			} dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k])) dp[k+2] dp k+2 k 2 Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k])) Math.min Math dp[k+2] dp k+2 k 2 dp[k]+Math.abs(h[k+2]-h[k]) dp[k] dp k Math.abs(h[k+2]-h[k]) Math.abs Math h[k+2]-h[k] h[k+2] h k+2 k 2 h[k] h k System.out.println(dp[N-1]) System.out.println System.out System System.out dp[N-1] dp N-1 N 1 String []args args
import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			if(k+1<N) {
				dp[k+1]=Math.min(dp[k+1],dp[k]+Math.abs(h[k+1]-h[k]));
			}
			if(k+2<N) {
				dp[k+2]=Math.min(dp[k+2],dp[k]+Math.abs(h[k+2]-h[k]));
			}
		}
		System.out.println(dp[N-1]);
	}
}