Problem p03160 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FAST_IO                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define INF (1e10 + 5)
#define F first
#define S second
#define pb push_back
#define MP make_pair
#define FRL(i, a, n) for (i = a; i < n; i++)
#define FR(i, n) FRL(i, 0, n)
#define RFRL(i, n) for (i = n; i >= 0; i--)
#define MOD 1000000007
#define fill(a) memset(dp, a, sizeof(dp));

using namespace std;

typedef long long int ll;

typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;
typedef set<ll> st;
typedef map<ll, ll> mp;
typedef unordered_map<ll, ll> ump;

template <class T> T minn(T a, T b) { return (a > b) ? b : a; }
template <class T> T maxx(T a, T b) { return (a > b) ? a : b; }

void FILE_OP() {
#ifndef ONLINE_JUDGE
  freopen("inputf.txt", "r", stdin);
  freopen("output2.txt", "w", stdout);
#endif
}
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
ll n;
vi v(100005);
ll dp[100005];
/*ll frog(ll i,ll c)
{
        if(i>n)
                return 0;

        c=c+minn(frog(i+1,abs(v[i-1]-v[i])),frog(i+2,abs(v[i-2]-v[i])));
        return c;

}*/

void SOLVE() {

  ll tt, m, i, j, k, a, b, c, d, l, r;
  // cin>>tt;
  tt = 1;
  fill(0) while (tt--) {
    cin >> n;

    FR(i, n)
    cin >> v[i];
    dp[0] = 0;
    dp[1] = abs(v[1] - v[0]);
    for (i = 2; i < n; i++) {
      dp[i] += minn(dp[i - 1] + abs(v[i] - v[i - 1]),
                    dp[i - 2] + abs(v[i] - v[i - 2]));
    }
    cout << dp[n - 1];
  }
}

int main() {
  FAST_IO
  FILE_OP();
  SOLVE();

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FAST_IO                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define INF (1e10 + 5)
#define F first
#define S second
#define pb push_back
#define MP make_pair
#define FRL(i, a, n) for (i = a; i < n; i++)
#define FR(i, n) FRL(i, 0, n)
#define RFRL(i, n) for (i = n; i >= 0; i--)
#define MOD 1000000007
#define fill(a) memset(dp, a, sizeof(dp));

using namespace std;

typedef long long int ll;

typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;
typedef set<ll> st;
typedef map<ll, ll> mp;
typedef unordered_map<ll, ll> ump;

template <class T> T minn(T a, T b) { return (a > b) ? b : a; }
template <class T> T maxx(T a, T b) { return (a > b) ? a : b; }

void FILE_OP() {
#ifndef ONLINE_JUDGE
  freopen("inputf.txt", "r", stdin);
  freopen("output2.txt", "w", stdout);
#endif
}
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
ll n;
vi v(100005);
ll dp[100005];
/*ll frog(ll i,ll c)
{
        if(i>n)
                return 0;

        c=c+minn(frog(i+1,abs(v[i-1]-v[i])),frog(i+2,abs(v[i-2]-v[i])));
        return c;

}*/

void SOLVE() {

  ll tt, m, i, j, k, a, b, c, d, l, r;
  // cin>>tt;
  tt = 1;
  fill(0) while (tt--) {
    cin >> n;

    FR(i, n)
    cin >> v[i];
    dp[0] = 0;
    dp[1] = abs(v[1] - v[0]);
    for (i = 2; i < n; i++) {
      dp[i] += minn(dp[i - 1] + abs(v[i] - v[i - 1]),
                    dp[i - 2] + abs(v[i] - v[i - 2]));
    }
    cout << dp[n - 1];
  }
}

int main() {
  FAST_IO
  // FILE_OP();
  SOLVE();

  return 0;
}