Language: C++

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int MAX_N = 300001;
const ll MOD = 1000000007;

ll dp[MAX_N+1];
int a[MAX_N+1], prev[MAX_N+1];

int main() {
    int n;
    cin >> n;
    for(int i=0;i<n;++i) cin >> a[i];

    dp[0] = 1LL;
    for(int i=0;i<n;++i) {
        if(i) {
            dp[i] += dp[i-1];
            dp[i] %= MOD;
        }
        if(prev[a[i]] != -1 && prev[a[i]] != i-1) {
            dp[i] += dp[prev[a[i]]];
            dp[i] %= MOD;
        }
        // cerr << a[i] << ": " << dp[i] << endl;
        prev[a[i]] = i;
    }

    cout << dp[n-1] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:12: error: reference to 'prev' is ambiguous
   41 |         if(prev[a[i]] != -1 && prev[a[i]] != i-1) {
      |            ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:28:17: note:                 'int prev [300002]'
   28 | int a[MAX_N+1], prev[MAX_N+1];
      |                 ^~~~
a.cc:41:32: error: reference to 'prev' is ambiguous
   41 |         if(prev[a[i]] != -1 && prev[a[i]] != i-1) {
      |                                ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:28:17: note:                 'int prev [300002]'
   28 | int a[MAX_N+1], prev[MAX_N+1];
      |                 ^~~~
a.cc:42:25: error: reference to 'prev' is ambiguous
   42 |             dp[i] += dp[prev[a[i]]];
      |                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:28:17: note:                 'int prev [300002]'
   28 | int a[MAX_N+1], prev[MAX_N+1];
      |                 ^~~~
a.cc:46:9: error: reference to 'prev' is ambiguous
   46 |         prev[a[i]] = i;
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:28:17: note:                 'int prev [300002]'
   28 | int a[MAX_N+1], prev[MAX_N+1];
      |                 ^~~~