Problem p03096 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x)                                                                \
  ll(x);                                                                       \
  cin >> (x);
#define stin(x)                                                                \
  str(x);                                                                      \
  cin >> (x);
#define vllin(x, n)                                                            \
  vll(x)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n)                                                        \
  vll(a)(n);                                                                   \
  vll(b)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> b[i]; }
#define vpl4in(x, n)                                                           \
  vpl4(x)((n), mp(0, 0));                                                      \
  FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))

ll MOD = 1000000007;

signed main() {
  llin(n);
  vllin(c, n);
  vll m(n, -1);
  vll l(n, -1);
  m[0] = 1;
  l[c[0]] = 0;
  FOR(d, 1, n - 1) {
    if (c[d] == c[d - 1]) {
      m[d] = m[d - 1];
    } else {
      if (l[c[d]] == -1) {
        m[d] = m[d - 1];
      } else {
        m[d] = (m[d - 1] + m[l[c[d]]]) % MOD;
      }
    }
    l[c[d]] = d;
  }
  sal(m[n - 1]);
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x)                                                                \
  ll(x);                                                                       \
  cin >> (x);
#define stin(x)                                                                \
  str(x);                                                                      \
  cin >> (x);
#define vllin(x, n)                                                            \
  vll(x)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n)                                                        \
  vll(a)(n);                                                                   \
  vll(b)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> b[i]; }
#define vpl4in(x, n)                                                           \
  vpl4(x)((n), mp(0, 0));                                                      \
  FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))

ll MOD = 1000000007;

signed main() {
  llin(n);
  vllin(c, n);
  vll m(n, -1);
  vll l(200005, -1);
  m[0] = 1;
  l[c[0]] = 0;
  FOR(d, 1, n - 1) {
    if (c[d] == c[d - 1]) {
      m[d] = m[d - 1];
    } else {
      if (l[c[d]] == -1) {
        m[d] = m[d - 1];
      } else {
        m[d] = (m[d - 1] + m[l[c[d]]]) % MOD;
      }
    }
    l[c[d]] = d;
  }
  sal(m[n - 1]);
}