//epcnhkapa's snippet v1.2
//In the name of Allah the beneficent, the merciful
//Here the Special Forces come
//I know a thing and it is that I dont know nothing
//Sub to Mcan

//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

//_______________%%%%%%%%%%%%%%__________________________________
//_____________%%%%%%%%%%%%%%%%%_________________________________
//____________%%%%%%%%%%%%%%%%%%%________________________________
//__________%%%%%%%%%%%%%%%%%%%%%%%______________________________
//__________%%%%%%%%%%%%%%%%%%%%%%%%_____________________________
//________%%%%%%%%%%%%%%%_____%%%%%%%____________________________
//________%%%%%%%%%%%%___________%%%%____________________________
//_______%%%%%%%%%%%%_____________%%%%___________________________
//_______%%%%%%%%%%%_______________%%%___________________________
//______%%%%%%%%%%%_________________%%%_____%%___________________
//______%%%%%%%%%%__________________________%%%__________________
//______%%%%%%%%%___________________________%%%__________________
//_____%%%%%%%%%%___________________________%%%%_________________
//_____%%%%%%%%%____________________________%%%%%%%%%%%%_________
//_____%%%%%%%%%___________________________%%%%%%%%%%%___________
//_____%%%%%%%%%_________________________%%%%%%%%%%%%____________
//_____%%%%%%%%%_______________________%%%%%%%%%%%%%_____________
//_____%%%%%%%%%_____________________%%%%%%%%%%%%%%%_____________
//_____%%%%%%%%%_________________________%%%%%%%%%%%_____________
//_____%%%%%%%%%___________________________%%%%%%%%%%____________
//_____%%%%%%%%%%___________________________%%%%%%%%%%___________
//______%%%%%%%%%___________________________%%%%%%%%%%___________
//______%%%%%%%%%___________________________%%%%____%%%__________
//_______%%%%%%%%%__________________________%%%_______%%_________
//_______%%%%%%%%%%_________________%_______%%__________%________
//________%%%%%%%%%%_______________%%_______%____________________
//________%%%%%%%%%%%_____________%%%____________________________
//_________%%%%%%%%%%%%%________%%%%_____________________________
//__________%%%%%%%%%%%%%%%%%%%%%%%______________________________
//___________%%%%%%%%%%%%%%%%%%%%%_______________________________
//____________%%%%%%%%%%%%%%%%%%%________________________________
//_____________%%%%%%%%%%%%%%%%%_________________________________
//______________%%%%%%%%%%%%%%%__________________________________
//_______________%%%%%%%%%%%%%___________________________________
//__________________%%%%%%%%_____________________________________

//        ⣠⣶⣾⣿⣿⢶⣶⡶⠦
//⠀⠀⠀⠀⠀⢀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢢
//⠀⠀⠀⠀⠀⢸⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡄

//⠀⠀⠀⠀⠀⢸⣿⠃⠀⢀⣠⣶⡆⢠⣶⣖⣻⣎⡇

//⠀⠀⠀⠀⠀⠁⡜⡄⠀⠉⠝⠋⠁⠘⣿⢿⡿⣳⠁

//⠀⠀⠀⠀⠀⠀⠀⣆⠀⠀⡠⠫⢤⣠⣿⡆⢘⡏

//⠀⠀⠀⠀⠀⠀⠀⣿⣦⡀⢧⣷⣬⢿⣽⣿⣾⠃

//⠀⠀⠀⢀⣴⣇⠙⣿⣿⣏⠚⠻⢿⣻⡿⠁

//⣤⣴⣶⣿⣿⣿⣿⣆⠈⠙⢿⣷⣾⣾⡿⣤⣤⣀

//⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠙⢿⠟⠁⣿⣿⣿⣿⣶⣄⡀

//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⣠⣾⣦⡀⠸⣿⣿⣿⣿⣿⣿⣧

//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠈⣿⣿⠃⠀⢿⣷⣿⣿⣿⣿⣿


//"Insert Problem name and code here"
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define nl '\n'
#define qquery int query;cin>>query;while(query--)
#define fillar(x) for(int i=0;i<x;i++)cin>>ar[i]
#define benfero freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//benfero
	int n;
	cin >>n;
	int dp[n+1];
	int ar[n+1];
	fillar(n);
	for(int i=0;i<n+1;i++){
		dp[i]=100005;
	}
	dp[1]=abs(ar[1]-ar[0]);
	dp[0]=0;
	for(int i=2;i<n;i++){
		
		dp[i]=min(abs(ar[i]-ar[i-1])+dp[i-1],abs(ar[i]-ar[i-2])+dp[i-2]);
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024