Language: C++

#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>
 
#define fir first
#define sec second
#define sz(s) (s).size();
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define repdown(i, j, k) for(int (i)=(j);(i)>=(j);(i)--)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
using ll = long long;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;
 
const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const ll INF = 10241024;
long double INFD = 100100100;
 
//_____________________________________Templates_________________________________________//
 
template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
 
 
 
//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}
 
inline void IN(void){
  return;
}
 
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}
 
inline void OUT(void){
  cout << "\n";
  return;
}
 
template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}
 
//_____________________array calc____________________________________//
/*
vvi mul(vvi &A, vvi &B){
  vvi C(A.size(), vi(B.size()))
  rep(i,A.size()){
    rep(j,B.size()){
      rep(k,B[0].size()){
        C[i][j] = (C[i][j] A[i][k] + B[k][j]) % Mod;
      }
    }
  }
 
  return C;
}
 
vvi pow(vvi A, ll n){
  vvi B(A.size(), vi(A.size()));
  rep(i=0;i<A.size();i++){
    B[i][i] = 1;
  }
 
  while (n >0){
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n = n >> 1;
  }
  return B;
}
*/
//_____________________Bynary Indexed Tree __________________________//
/*
const max_st = (1 << 15) - 1;
int bit[max_st];
int sum (int i){
  int s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}
 
void add(int i, int x){
  while(i <= n){
    bit[i] += x;
    i += i & -i;
  }
}
*/
//_____________________　following sorce code_________________________//
int n;
vi v;
void input(){
  IN(n);
  v.resize(n);
  rep(i,n)IN(v[i]);
}
void solve(){
  input();
  vi dp(n,INF);
  dp[0] = 0;
  for(int i=0;i<n;i++){
    if(i+1 < n)chmin(dp[i+1] , dp[i] + abs(v[i] - v[i+1]));
    if(i+2 < n)chmin(dp[i+2], dp[i] + abs(v[i] - v[i+2]));
  }
 
  OUT(dp[n-1]);
}
 
int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>

#define fir first
#define sec second
#define sz(s) (s).size();
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define repdown(i, j, k) for(int (i)=(j);(i)>=(j);(i)--)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using ll = long long;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;

const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const ll INF = 10241024;
long double INFD = 100100100;

//_____________________________________Templates_________________________________________//

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}



//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

//_____________________array calc____________________________________//
/*
vvi mul(vvi &A, vvi &B){
  vvi C(A.size(), vi(B.size()))
  rep(i,A.size()){
    rep(j,B.size()){
      rep(k,B[0].size()){
        C[i][j] = (C[i][j] A[i][k] + B[k][j]) % Mod;
      }
    }
  }

  return C;
}

vvi pow(vvi A, ll n){
  vvi B(A.size(), vi(A.size()));
  rep(i=0;i<A.size();i++){
    B[i][i] = 1;
  }

  while (n >0){
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n = n >> 1;
  }
  return B;
}
*/
//_____________________Bynary Indexed Tree __________________________//
/*
const max_st = (1 << 15) - 1;
int bit[max_st];
int sum (int i){
  int s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, int x){
  while(i <= n){
    bit[i] += x;
    i += i & -i;
  }
}
*/
//_____________________　following sorce code_________________________//
ll n;
vll v;
void input(){
  IN(n);
  v.resize(n);
  rep(i,n)IN(v[i]);
}
void solve(){
  input();
  vi dp(n,INF);
  dp[0] = 0ll;
  for(ll i=0ll;i<n;i++){
    if(i+1 < n)chmin(dp[i+1] , dp[i] + abs(v[i] - v[i+1]));
    if(i+2 < n)chmin(dp[i+2], dp[i] + abs(v[i] - v[i+2]));
  }

  OUT(dp[n-1]);
}

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Compiler output:
a.cc:193:11: error: redefinition of 'const int Mod'
  193 | const int Mod = (1e9) + 7;
      |           ^~~
a.cc:38:11: note: 'const int Mod' previously defined here
   38 | const int Mod = (1e9) + 7;
      |           ^~~
a.cc:194:11: error: redefinition of 'const int max_n'
  194 | const int max_n = 3 * (1e5) + 1;
      |           ^~~~~
a.cc:39:11: note: 'const int max_n' previously defined here
   39 | const int max_n = 3 * (1e5) + 1;
      |           ^~~~~
a.cc:195:11: error: redefinition of 'const int max_m'
  195 | const int max_m = 83 * (1e5) + 1;
      |           ^~~~~
a.cc:40:11: note: 'const int max_m' previously defined here
   40 | const int max_m = 83 * (1e5) + 1;
      |           ^~~~~
a.cc:196:10: error: redefinition of 'const ll INF'
  196 | const ll INF = 10241024;
      |          ^~~
a.cc:41:10: note: 'const ll INF' previously defined here
   41 | const ll INF = 10241024;
      |          ^~~
a.cc:197:13: error: redefinition of 'long double INFD'
  197 | long double INFD = 100100100;
      |             ^~~~
a.cc:42:13: note: 'long double INFD' previously defined here
   42 | long double INFD = 100100100;
      |             ^~~~
a.cc:201:42: error: redefinition of 'template<class T1, class T2> void chmin(T1&, T2)'
  201 | template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
      |                                          ^~~~~
a.cc:46:42: note: 'template<class T1, class T2> void chmin(T1&, T2)' previously declared here
   46 | template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
      |                                          ^~~~~
a.cc:202:42: error: redefinition of 'template<class T1, class T2> void chmax(T1&, T2)'
  202 | template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
      |                                          ^~~~~
a.cc:47:42: note: 'template<class T1, class T2> void chmax(T1&, T2)' previously declared here
   47 | template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}
      |                                          ^~~~~
a.cc:208:6: error: redefinition of 'template<class T1, class T2> void update(T1&, T2)'
  208 | void update(T1 &a, T2 b){
      |      ^~~~~~
a.cc:53:6: note: 'template<class T1, class T2> void update(T1&, T2)' previously declared here
   53 | void update(T1 &a, T2 b){
      |      ^~~~~~
a.cc:213:13: error: redefinition of 'void IN()'
  213 | inline void IN(void){
      |             ^~
a.cc:58:13: note: 'void IN()' previously defined here
   58 | inline void IN(void){
      |             ^~
a.cc:218:6: error: redefinition of 'template<class First, class ... Rest> void IN(First&, Rest& ...)'
  218 | void IN(First& first, Rest&... rest){
      |      ^~
a.cc:63:6: note: 'template<class First, class ... Rest> void IN(First&, Rest& ...)' previously declared here
   63 | void IN(First& first, Rest&... rest){
      |      ^~
a.cc:224:13: error: redefinition of 'void OUT()'
  224 | inline void OUT(void){
      |             ^~~
a.cc:69:13: note: 'void OUT()' previously defined here
   69 | inline void OUT(void){
      |             ^~~
a.cc:230:6: error: redefinition of 'template<class First, class ... Rest> void OUT(First, Rest ...)'
  230 | void OUT(First first, Rest... rest){
      |      ^~~
a.cc:75:6: note: 'template<class First, class ... Rest> void OUT(First, Rest ...)' previously declared here
   75 | void OUT(First first, Rest... rest){
      |      ^~~
a.cc:286:4: error: conflicting declaration 'll n'
  286 | ll n;
      |    ^
a.cc:131:5: note: previous declaration as 'int n'
  131 | int n;
      |     ^
a.cc:287:5: error: conflicting declaration 'vll v'
  287 | vll v;
      |     ^
a.cc:132:4: note: previous declaration as 'vi v'
  132 | vi v;
      |    ^
a.cc:288:6: error: redefinition of 'void input()'
  288 | void input(){
      |      ^~~~~
a.cc:133:6: note: 'void input()' previously defined here
  133 | void input(){
      |      ^~~~~
a.cc:293:6: error: redefinition of 'void solve()'
  293 | void solve(){
      |      ^~~~~
a.cc:138:6: note: 'void solve()' previously defined here
  138 | void solve(){
      |      ^~~~~
a.cc:305:5: error: redefinition of 'int main()'
  305 | int main () {
      |     ^~~~
a.cc:150:5: note: 'int main()' previously defined here
  150 | int main () {
      |     ^~~~