Problem p03160 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define testcase(t)                                                            \
  int t;                                                                       \
  cin >> t;                                                                    \
  for (int testcnt = 1; testcnt <= t; testcnt++)
#define int long long
#define double long double
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define eb emplace_back
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int nod(int n) {
  string s = to_string(n);
  return (int)s.length();
}
int sod(int n) {
  int ans = 0;
  while (n)
    ans += (n % 10), n /= 10;
  return ans;
}
int modexpo(int x, int y, int p) {
  int res = 1;
  x %= p;
  while (y) {
    if (y & 1)
      res *= x, res %= p;
    x *= x, x %= p;
    y >>= 1;
  }
  return res;
}
int h[10005];
int dp[10005];
int32_t main() {
  IOS int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  dp[1] = abs(h[1] - h[0]);
  dp[0] = 0;
  for (int i = 2; i < n; i++) {
    dp[i] =
        min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n - 1];
}

Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define testcase(t)                                                            \
  int t;                                                                       \
  cin >> t;                                                                    \
  for (int testcnt = 1; testcnt <= t; testcnt++)
#define int long long
#define double long double
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define eb emplace_back
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int nod(int n) {
  string s = to_string(n);
  return (int)s.length();
}
int sod(int n) {
  int ans = 0;
  while (n)
    ans += (n % 10), n /= 10;
  return ans;
}
int modexpo(int x, int y, int p) {
  int res = 1;
  x %= p;
  while (y) {
    if (y & 1)
      res *= x, res %= p;
    x *= x, x %= p;
    y >>= 1;
  }
  return res;
}
int h[100005];
int dp[100005];
int32_t main() {
  IOS int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  dp[1] = abs(h[1] - h[0]);
  dp[0] = 0;
  for (int i = 2; i < n; i++) {
    dp[i] =
        min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n - 1];
}