Language: C++

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define srep(i) for(int i = 0; i < s.size(); i++)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 1e9
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

int N, W, A, B;
int a[100005];
int h[100005];
int weight[105] = {}, value[105] = {};
ll dp[1000000005];
ll dp2[10005][10005];
int in = 0;
int cnt = 0;

template <typename T> T gcd(T a, T b) {
    if(a < b) {
        swap(a, b);
    }
    if(a % b == 0)
        return b;
    return gcd(b, a % b);
}

ll fib(ll n) {
    dp[0] = 0;
    dp[1] = 1;
    for(int i = 2; i <= n; i++) {
        dp[i] = dp[i - 1] + dp[i - 2];
    }
    return dp[n];
}

void rec(int i, int j) {
    cout << "i: " << i << " j: " << j << " cnt: " << cnt << endl;
    cnt++;

    if(i == N) {
        return;
    }

    // cout << " cnt2: " << cnt << endl;
    rec(i + 1, j);
    cout << " cnt3: " << cnt << endl;
    rec(i + 1, j + 1);
    cout << " cnt4: " << cnt << endl;

    return;
}

void insert_sort(int a[], int n) {
    for(int i = 1; i < n; i++) {
        int v = a[i];
        int j = i - 1;
        for(; j >= 0; j--) {
            if(a[j] > v)
                a[j + 1] = a[j];
            else
                break;
        }
        a[j + 1] = v;
    }
}

void bubble_sort(int a[], int n) {
    bool flag = true;
    for(int i = 0; flag; i++) {
        flag = false;
        for(int j = n - 1; j > i; j--) {
            if(a[j] < a[j - 1]) {
                swap(a[j], a[j - 1]);
                flag = true;
            }
        }
    }
}

void select_sort(int a[], int n) {
    for(int i = 0; i < n - 1; i++) {
        int mini = i;
        for(int j = i + 1; j < n; j++) {
            if(a[mini] > a[j]) {
                mini = j;
            }
        }
        if(i != mini) {
            swap(a[mini], a[i]);
        }
    }
}

void merge(int a[], int left, int mid, int right) {
    vector<int> buf;
    for(int i = left; i < mid; ++i)
        buf.push_back(a[i]);
    for(int i = right - 1; i >= mid; --i)
        buf.push_back(a[i]);

    int iterator_left = 0;
    int iterator_right = (int)buf.size() - 1;
    for(int i = left; i < right; ++i) {
        if(buf[iterator_left] <= buf[iterator_right]) {
            a[i] = buf[iterator_left++];
        } else {
            a[i] = buf[iterator_right--];
        }
        cnt++;
    }
}

void merge_sort(int a[], int left, int right) {
    if(left == right - 1)
        return;
    int mid = left + (right - left) / 2;

    merge_sort(a, left, mid);
    merge_sort(a, mid, right);
    merge(a, left, mid, right);
}

void quick_sort(int a[], int left, int right) {
    if(left >= right - 1)
        return;

    int pivot_index = left + (right - left) / 2;
    int pivot = a[pivot_index];
    swap(a[pivot_index], a[right - 1]);

    int i = left;
    for(int j = left; j < right - 1; ++j) {
        if(a[j] < pivot)
            swap(a[i++], a[j]);
    }
    swap(a[i], a[right - 1]);

    quick_sort(a, left, i);
    quick_sort(a, i + 1, right);
}

int binary_search(int a[], int n, int target) {
    int left = 0;
    int right = n;
    int mid;
    while(left < right) {
        mid = left + (right - left) / 2;
        if(a[mid] == target) {
            return 1;
        } else if(a[mid] < target) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    return 0;
}

int res = INF;
int solve(int i, int sum) {
    if(i == N - 1) {
        return sum;
    }

    if(dp[sum]) {
        return dp[sum];
    }

    // cout << "i: " << i << endl;
    // cout << "res: " << sum + abs(h[i + 1] - h[i]) << endl;

    res = min(res, solve(i + 1, sum + abs(h[i + 1] - h[i])));
    if(i + 2 <= N - 1)
        res = min(res, solve(i + 2, sum + abs(h[i + 2] - h[i])));

    return dp[sum] = res;
}

int main() {
    cin >> N;
    rep(i, N) cin >> h[i];
    cout << solve(0, 0) << endl;
}


Compiler output:
/tmp/ccKWuDcn.o: in function `rec(int, int)':
a.cc:(.text+0x117): relocation truncated to fit: R_X86_64_PC32 against symbol `cnt' defined in .bss section in /tmp/ccKWuDcn.o
a.cc:(.text+0x139): relocation truncated to fit: R_X86_64_PC32 against symbol `cnt' defined in .bss section in /tmp/ccKWuDcn.o
a.cc:(.text+0x142): relocation truncated to fit: R_X86_64_PC32 against symbol `cnt' defined in .bss section in /tmp/ccKWuDcn.o
a.cc:(.text+0x185): relocation truncated to fit: R_X86_64_PC32 against symbol `cnt' defined in .bss section in /tmp/ccKWuDcn.o
a.cc:(.text+0x1d8): relocation truncated to fit: R_X86_64_PC32 against symbol `cnt' defined in .bss section in /tmp/ccKWuDcn.o
/tmp/ccKWuDcn.o: in function `merge(int*, int, int, int)':
a.cc:(.text+0x58f): relocation truncated to fit: R_X86_64_PC32 against symbol `cnt' defined in .bss section in /tmp/ccKWuDcn.o
a.cc:(.text+0x598): relocation truncated to fit: R_X86_64_PC32 against symbol `cnt' defined in .bss section in /tmp/ccKWuDcn.o
collect2: error: ld returned 1 exit status