#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <functional>
using namespace std;
 
 #define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define fill(a,b) memset(a, b, sizeof(a))
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int Maxn  =  200*1000 + 1;
const ld  pi   =  acos(-1);
const int mod =  1000000007;
 
 
template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x;return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}
int roundUp(int numToRound, int multiple)
{
 if(multiple == 0)
 {
  return numToRound;
 }
 
 int roundDown = ( (int) (numToRound) / multiple) * multiple;
 int roundUp = roundDown + multiple; 
 int roundCalc = roundUp;
 return (roundCalc);
}
 
 
 
 
int calc(int a, int b, int c) {
	return abs(a - b) + abs(a - c) + abs(b - c);
}
 
 
// gcd
int gcd(int a, int b){
    while(b){
        a=a%b;
        swap(a,b);
    }
    return a;
}
//lcm
int lcm(int a, int b){
    return (a*b)/gcd(a,b);
}
  
 bool isSubSequence(string str1, string str2 ) 
{ int m=str1.length(),n=str2.length();
   int j = 0; 
   for (int i=0; i<n&&j<m; i++) 
       if (str1[j] == str2[i]) 
         j++; 
  
   
   return (j==m); 
} 
  
  void eraseAllSubStr(string &mainStr, string &toErase)
{
	size_t pos = std::string::npos;
 
	
	while ((pos  = mainStr.find(toErase) )!= std::string::npos)
	{
		
		mainStr.erase(pos, toErase.length());
        mainStr.insert(pos," ");
	}
}
 
int isSubstring(string s1, string s2) 
{ 
    int M = s1.length(); 
    int N = s2.length(); 
  
    /* A loop to slide pat[] one by one */
    for (int i = 0; i <= N - M; i++) { 
        int j; 
  
        /* For current index i, check for pattern match */
        for (j = 0; j < M; j++) 
            if (s2[i + j] != s1[j]) 
                break; 
  
        if (j == M) 
            return i; 
    } 
  
    return -1; 
} 
 
 
 
 
 
 
 
int countPrimitiveRoots(int p) 
{ 
    int result = 1; 
    for (int i = 2; i < p; i++) 
        if (__gcd(i, p) == 1) 
            result++; 
  
    return result; 
} 
 
int cnt(int t){
    int c=0;
     while(t>0){
           t=t&(t-1);
           c++;
       }
       return c;
}
 
const int ma=10000007;
 
 
 
//Binary exponentiation
int binpow(int a,int b) {
    a=a%mod;
   
    int res = 1;
while (b > 0) {
        if (b & 1)res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
}
return (res+mod)%mod;
}
 
#define MAX 1000000 
  
vector<int> arr; 
  
bool prime[MAX]; 
 
void SieveOfEratosthenes() 
{ 
    
  
    memset(prime, true, sizeof(prime)); 
  
    for (int p = 2; p * p < MAX; p++) { 
        
  
        if (prime[p] == true) { 
  
            
            for (int i = p * 2; i < MAX; i += p) 
                prime[i] = false; 
        } 
    } 
  
    
} 
 
 
 
 
 
 
 
 
 
 
int32_t main(){
 IOS;
 
 
 int t;
 t=1;
 //cin>>t;
 while(t--){
 
 int n;
 cin>>n;

 vector<int>k(n);

 fr(i,0,n)cin>>k[i];

 vector<int>dp(n);

 dp[0]=0;
 dp[1]=abs(k[1]-k[0]);

 fr(i,2,n){

   dp[i]=min(dp[i-1]+(abs(k[i]-k[i-1])), dp[i-2]+abs(k[i]-k[i-2]));

   
 }

 cout<<dp[n-1]<<endl;
 
 
 
 }
 
 
  }

Measured memory_bytes: 4760