#include <stdio.h>                                                                                                                           
#include <algorithm>                                                                                                                         
#include <vector>                                                                                                                            
#include <iostream>                                                                                                                          
#include <map>                                                                                                                               
#include <set>                                                                                                                               
#include <math.h>                                                                                                                            
#include <ctype.h>                                                                                                                           
#include <string.h>                                                                                                                          
#include <string>                                                                                                                            
#include <stdlib.h>                                                                                                                          
#include <queue>                                                                                                                             
#include <limits.h>                                                                                                                          
using namespace std;                                                                                                                         
                                                                                                                                             
typedef long long ll;                                                                                                                        
                                                                                                                                             
const int N = 1e5;                                                                                                                           
int n, h[N], dp[N];                                                                                                                          
                                                                                                                                             
int calc(int at) {                                                                                                                           
	if (at + 1 == n)                                                                                                                         
		return 0;                                                                                                                            
	int &res = dp[at];                                                                                                                       
	if (res != -1)                                                                                                                           
		return res;                                                                                                                          
	res = calc(at + 1) + abs(h[at] - h[at + 1]);                                                                                             
	if (at + 2 < n)                                                                                                                          
		res = min(res, calc(at + 2) + abs(h[at] - h[at + 2]));                                                                               
	return res;                                                                                                                              
}                                                                                                                                            
                                                                                                                                             
int main(int argc, char **argv) {                                                                                                            
	scanf("%d", &n);                                                                                                                         
	for (int i = 0; i < n; ++i)                                                                                                              
		scanf("%d", &h[i]);                                                                                                                  
	memset(dp, -1, sizeof dp);                                                                                                               
	printf("%d\n", calc(0));                                                                                                                 
	return 0;                                                                                                                                
}                                                                                                                                            
                                                                                                                                             

Measured memory_bytes: 4096