stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <stdio.h>

#include <assert.h>

#include <fstream>

#include <iostream>

#include <algorithm>

#include <array>

#include <vector>

#include <queue>

#include <set>

#include <cmath>

//#include <unordered_map>

//#include <unordered_set>

//#include <boost/container/static_vector.hpp>

//#include <boost/unordered_set.hpp>

//#include <boost/unordered_map.hpp>

//#include <unistd.h>



//#include <cv.h>

//#include <highgui.h>

#include <stdlib.h>

#include <string>



#include <stdio.h>

#include <assert.h>

#include <fstream>

#include <iostream>

#include <algorithm>

#include <array>

#include <vector>

#include <queue>

#include <set>

#include <cmath>

//#include <unordered_map>

//#include <unordered_set>

//#include <boost/container/static_vector.hpp>

//#include <boost/unordered_set.hpp>

//#include <boost/unordered_map.hpp>

//#include <unistd.h>



//#include <cv.h>

//#include <highgui.h>

#include <stdlib.h>

#include <time.h>



#include <string>



const int MAX_N = 200050;

const long long MOD = 1000000007;



int N;

int C[MAX_N];

long long tmpc[MAX_N];



int main(int argc, char **argv) {

    std::cin >> N;

    for (int i = 1; i <= N; i++) {

        std::cin >> C[i];

    }



    for (int i = 0; i < MAX_N; i++) {

        tmpc[i] = 0;

    }



    long long ret = 1;

    tmpc[C[1]] = 1;



    for (int i = 2; i <= N; i++) {

        if (tmpc[C[i]] == 0) {

            tmpc[C[i]] = ret;

        } else {

            if (C[i] != C[i-1]) {

                ret = (ret + tmpc[C[i]]) % MOD;

                tmpc[C[i]] = ret;

            }

        }

    }



    std::cout << ret << std::endl;



    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

#include <assert.h>

#include <fstream>

#include <iostream>

#include <sstream>

#include <iomanip>

#include <algorithm>

#include <bitset>

#include <array>

#include <vector>

#include <queue>

#include <set>

#include <cmath> // 変数名にy1が使えなくなるかも…。

#include <map>

#include <unordered_map>

#include <unordered_set>

#include <limits>

#include <functional>

#include <string>



typedef __int128_t int128_t;

std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。

    long long tmp; input >> tmp; value = tmp;

    return input;

}

std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。

    output << (long long)value;

    return output;

}



const int MAX_N = 2e5 + 10;

const int MOD = 1e9 + 7;

int N;

int c[MAX_N];



int128_t prev[MAX_N] = {};





int main(int argc, char **argv) {

    std::cin >> N;

    for (int i = 1; i <= N; i++) {

        std::cin >> c[i];

    }



    int128_t ret = 1;

    for (int i = 1; i <= N; i++) {

        if (c[i] != c[i-1]) {

            ret = (ret + prev[c[i]]) % MOD;

        }

        prev[c[i]] = ret;

    }

    

    std::cout << ret << std::endl;

    return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

template <class T>

inline bool chmax(T &a, T b)

{

    if (a < b)

    {

        a = b;

        return 1;

    }

    return 0;

}

template <class T>

inline bool chmin(T &a, T b)

{

    if (a > b)

    {

        a = b;

        return 1;

    }

    return 0;

}

typedef long long int ll;



#define ALL(v) (v).begin(), (v).end()

#define RALL(v) (v).rbegin(), (v).rend()

#define endl "\n"

const double EPS = 1e-7;

const int INF = 1 << 30;

const ll LLINF = 1LL << 60;

const double PI = acos(-1);

const int MOD = 1000000007;

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

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



//-------------------------------------



ll dp[202020];

vector<vector<ll>> place(202020);



int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    vector<int> c(n);

    for (int i = 0; i < n; i++)

    {

        cin >> c[i];

        place[c[i]].push_back(i);

    }

    dp[0] = 1;

    for (ll i = 1; i <= n; i++)

    {

        (dp[i] += dp[i - 1]) %= MOD;

        ll color = c[i - 1];

        ll itr = lower_bound(ALL(place[color]), i - 1) - place[color].begin();

        if (itr > 0)

        {

            ll j = place[color][itr - 1];

            if ((i - 1) - j > 1)

            {

                (dp[i] += dp[j + 1]) %= MOD;

            }

        }

    }

    cout << dp[n] << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

template <class T>

inline bool chmax(T &a, T b)

{

    if (a < b)

    {

        a = b;

        return 1;

    }

    return 0;

}

template <class T>

inline bool chmin(T &a, T b)

{

    if (a > b)

    {

        a = b;

        return 1;

    }

    return 0;

}

typedef long long int ll;



#define ALL(v) (v).begin(), (v).end()

#define RALL(v) (v).rbegin(), (v).rend()

#define endl "\n"

const double EPS = 1e-7;

const int INF = 1 << 30;

const ll LLINF = 1LL << 60;

const double PI = acos(-1);

const int MOD = 1000000007;

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

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



//-------------------------------------



ll dp[202020];

ll sum[202020];



int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    vector<int> c(n);

    for (int i = 0; i < n; i++)

    {

        cin >> c[i];

    }

    c.erase(unique(ALL(c)), c.end());

    n = c.size();

    dp[0] = 1;

    for (int i = 0; i < n; i++)

    {

        (sum[c[i]] += dp[i]) %= MOD;

        (dp[i + 1] += sum[c[i]]) %= MOD;

    }

    cout << dp[n] << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

template <class T>

inline bool chmax(T &a, T b)

{

    if (a < b)

    {

        a = b;

        return 1;

    }

    return 0;

}

template <class T>

inline bool chmin(T &a, T b)

{

    if (a > b)

    {

        a = b;

        return 1;

    }

    return 0;

}

typedef long long int ll;



#define ALL(v) (v).begin(), (v).end()

#define RALL(v) (v).rbegin(), (v).rend()

#define endl "\n"

const double EPS = 1e-7;

const int INF = 1 << 30;

const ll LLINF = 1LL << 60;

const double PI = acos(-1);

const int MOD = 1000000007;

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

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



//-------------------------------------



ll dp[202020];

vector<vector<ll>> place(202020);



int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    vector<int> c(n);

    for (int i = 0; i < n; i++)

    {

        cin >> c[i];

        place[c[i]].push_back(i);

    }

    dp[0] = 1;

    for (ll i = 0; i < n; i++)

    {

        (dp[i + 1] += dp[i]) %= MOD;

        ll color = c[i];

        ll itr = lower_bound(ALL(place[color]), i) - place[color].begin();

        if (itr > 0)

        {

            ll j = place[color][itr - 1];

            if (i - j > 1)

            {

                (dp[i + 1] += dp[j + 1]) %= MOD;

            }

        }

    }

    cout << dp[n] << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

template <class T>

inline bool chmax(T &a, T b)

{

    if (a < b)

    {

        a = b;

        return 1;

    }

    return 0;

}

template <class T>

inline bool chmin(T &a, T b)

{

    if (a > b)

    {

        a = b;

        return 1;

    }

    return 0;

}

typedef long long int ll;



#define ALL(v) (v).begin(), (v).end()

#define RALL(v) (v).rbegin(), (v).rend()

#define endl "\n"

const double EPS = 1e-7;

const int INF = 1 << 30;

const ll LLINF = 1LL << 60;

const double PI = acos(-1);

const int MOD = 1000000007;

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

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



//-------------------------------------



ll dp[202020];

ll sum[202020];



int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    vector<int> c(n);

    for (int i = 0; i < n; i++)

    {

        cin >> c[i];

    }

    c.erase(unique(ALL(c)), c.end());

    n = c.size();

    dp[0] = 1;

    for (int i = 0; i < n; i++)

    {

        (sum[c[i]] += dp[i]) %= MOD;

        (dp[i + 1] += sum[c[i]]) %= MOD;

    }

    cout << dp[n] << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<iostream>

#include<queue>

#include<vector>

#include <bitset>

#include <cmath>

#include <limits>

#include <iostream>

using namespace std;

#define INF 100000

#define MAX 100000

#define MOD 1000000007

typedef long long ll;

typedef pair<int,int> P;

typedef pair< pair<int,int>, int> p; 

#define bit(n,k) ((n>>k)&1) /*nのk bit目*/



//http://drken1215.hatenablog.com/entry/2019/03/17/130800

vector<int> places[210000];

ll dp[210000];

void add(ll &a,ll b){

    a+=b;

    if(a>=MOD) a-=MOD;

}



int main(){

    int N;

    cin>>N;

    vector<int> c(N);

    for(int i=0;i<N;i++) cin>>c[i];



    for(int i=0;i<210000;i++) places[i].clear();

    for(int i=0;i<N;i++) places[c[i]].push_back(i);



    dp[0]=1;

    for(int i=1;i<=N;i++){

        add(dp[i],dp[i-1]);



        int color=c[i-1];

        int it=lower_bound(places[color].begin(),places[color].end(),i-1)-places[color].begin();

        if(it>0){

            int j=places[color][it-1];

            if((i-1)-j>1) add(dp[i],dp[j+1]);

        }

    }

    cout<<dp[N]<<endl;

}




// Optimized solution to the same problem (faster):
#pragma GCC optimize("Ofast")

#include <cstdio>

#include <cstdlib>

#include <string>

#include <algorithm>

#include <iostream>

#include <queue>

#include <vector>

#include <bitset>

#include <cmath>

#include <limits>

#include <iostream>

#include <map>

#include <set>

#include <tuple>

using namespace std;

#define INF 1LL << 30

#define MAX 100000

#define MOD 1000000007

typedef long long ll;

typedef pair<int,int> P;

//typedef pair<pair<int,int>,int> p;

#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/

#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

struct edge

{

    ll to, cost, val;

};

template <class T, class U>

bool chmin(T &a, const U &b)

{

    if (a <= b)

        return false;

    a = b;

    return true;

}

template <class T, class U>

bool chmax(T &a, const U &b)

{

    if (a >= b)

        return false;

    a = b;

    return true;

}

//__builtin_popcount(S);

//C.erase(unique(C.begin(),C.end()),C.end());

//#define int ll



int C[210000];

ll dp[210000],pre[210000];



signed main(void)

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int N;

    cin>>N;

    vector<int> V;

    for(int i=0;i<N;i++) cin>>C[i];

    int now=C[0];

    V.push_back(-1);

    V.push_back(now);

    for(int i=1;i<N;i++){

        while(now==C[i]){

            i++;

        }

        if(i>=N) break;

        now=C[i];

        V.push_back(now);

    }

    N=(int)V.size();

    dp[0]=1;

    for(int i=1;i<=N;i++){

        dp[i]=dp[i-1]+pre[V[i]];

        dp[i]%=MOD;

        pre[V[i]]=dp[i];

    }

    cout<<dp[N]<<endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

using namespace std;

typedef long long ll;



int N,C[200010];

int col_id[200010] = {};

vector<vector<int>> col(200010);

vector<ll> col_sum(200010,0);

ll dp[200010] = {},inf = 1e9+7;

int main(){

    cin >> N;

    int c;

    for(int i=1;i<=N;i++){

        cin >> C[i];

        //col[c].push_back(i);

    }

    dp[0] = 1;

    for(int i=1;i<=N;i++){

        (dp[i] += dp[i-1]+(C[i-1]!=C[i]? col_sum[C[i]]:0))%=inf;

        (col_sum[C[i]] = dp[i])%=inf;

    }

    cout << dp[N] << endl;

}

// Optimized solution to the same problem (faster):
#include <iostream>

using namespace std;

typedef long long ll;



int N,C[200010];

int col_id[200010] = {};

int col_sum[200010] = {};

ll dp[200010] = {},inf = 1e9+7;

int main(){

    cin >> N;

    int c;

    for(int i=1;i<=N;i++){

        cin >> C[i];

    }

    dp[0] = 1;

    for(int i=1;i<=N;i++){

        (dp[i] += dp[i-1]+(C[i-1]!=C[i]? col_sum[C[i]]:0))%=inf;

        (col_sum[C[i]] = dp[i])%=inf;

    }

    cout << dp[N] << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MOD 1000000007

#define INF 1e9

#define rep(i,n) for (int i = 0; i < (n); ++i)

#define all(x) (x).begin(),(x).end()



vector<int> places[210000];

ll dp[210000];

void add(ll &a,ll b){a+=b; if(a>=MOD) a-=MOD;}



int main(){

	int n;

	cin>>n;

	vector<int> c(n);

	rep(i,n) cin>>c[i];



	for(int i=0;i<210000;i++) places[i].clear();

	rep(i,n) places[c[i]].push_back(i);



	dp[0]=1;

	for(int i=1;i<=n;i++){

		add(dp[i],dp[i-1]);



		int color=c[i-1];

		int it=lower_bound(places[color].begin(),places[color].end(),i-1)-places[color].begin();

		if(it>0){

			int j=places[color][it-1];

			if((i-1)-j>1) add(dp[i],dp[j+1]);

		}

	} 

	cout<<dp[n]<<endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

#define rep(i,n) for(int i = 0; i < (n); i++)

#define all(v) v.begin(), v.end()

#define MOD 1000000007

const int INF = 1LL<<30;



void add(int64_t& a, int64_t b){

    a = (a+b) % MOD;

}

 

int main(){

    int N, C[200000];

    cin >> N;

    for(int i=0; i<N; i++) cin >> C[i];

 

    int left[200001];

    for(int i=0; i<=200000; i++) left[i] = -1;

    static int64_t dp[200001];

    dp[0] = 1;

    for(int i=0; i<N; i++){

        add(dp[i+1], dp[i]);

        int c = C[i];

        if(left[c] >= 0 && left[c] < i-1) add(dp[i+1], dp[left[c]+1]);

        left[c] = i;

    }

    cout << dp[N] << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main() {

    int N; cin >> N;

    vector<int> C(N);

    for(int i=0; i<N; ++i) cin >> C[i];

    C.erase(unique(begin(C), end(C)), end(C));



    const long long MOD = 1000000007;

    long long sum[200001] = {};

    sum[C[0]] = 1;

    for(int i=1; i<C.size(); ++i) {

        sum[C[i]] = (sum[C[i]] + sum[C[i - 1]]) % MOD;

    }

    cout << sum[*rbegin(C)] << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

long long sum[200001] = {};



int main() {

    int N; cin >> N;

    vector<int> C(N);

    for(int i=0; i<N; ++i) cin >> C[i];

    C.erase(unique(begin(C), end(C)), end(C));



    const long long MOD = 1000000007;

    sum[C[0]] = 1;

    for(int i=1; i<C.size(); ++i) {

        sum[C[i]] = (sum[C[i]] + sum[C[i - 1]]) % MOD;

    }

    cout << sum[*rbegin(C)] << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



inline int read(){

  int x = 0; char c = getchar();

  while(!isdigit(c)) c = getchar();

  while(isdigit(c)) x = x * 10 + c - '0', c = getchar();

  return x;

}



const int maxn = 2e5;

const int mod = 1e9 + 7;

int num[maxn];

int a[maxn], pre[maxn], f[maxn] = {1};



int main(){

  srand(time(0));

  memset(num, -1, sizeof(num));

  int n = read();

  for(int i = 0; i < n; i++){

    a[i] = read() - 1;

    pre[i] = num[a[i]];

    num[a[i]] = i;

  }

  for(int i = 1; i < n; i++){

    f[i] = f[i - 1];

    if(pre[i] >= 0 && pre[i] != i - 1) f[i] = (f[i] + f[pre[i]]) % mod;

  }

  printf("%d", f[n - 1]);

  return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



const int mod = int(1e9) + 7;



int n, dp[200005][2], sum[200005], arr[200005];



int main() {

	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) scanf("%d", arr + i);

	dp[0][0] = 1;

	for (int i = 1; i <= n; ++i) {

		dp[i][0] = (dp[i - 1][1] + dp[i - 1][0]) % mod;

		if (arr[i] != arr[i - 1]) {

			dp[i][1] = sum[arr[i]];

			sum[arr[i]] = (sum[arr[i]] + dp[i][0]) % mod;

		}

	}

	printf("%d\n", (dp[n][0] + dp[n][1]) % mod);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

const int MAX_N = 202020;



int main() {

    int n;

    cin >> n;



    vector<int> c(MAX_N);

    rep(i, n) {

        cin >> c[i];

        c[i]--;

    }



    vector<ll> dp(MAX_N);

    vector<int> last(MAX_N, -1);



    dp[0] = 1;

    rep(i, n) {

        dp[i+1] = dp[i];

        if(last[c[i]] != -1 && last[c[i]] != i-1) {

            dp[i+1] += dp[last[c[i]] + 1];

            dp[i+1] %= mod;

        }

        last[c[i]] = i;

    }



    cout << dp[n] << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <numeric>

#include <functional>

using namespace std;

typedef long long ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

typedef pair<ll, ll> P;

#define rep(i, n) for(ll i = 0; i < n; i++)

#define exrep(i, a, b) for(ll i = a; i <= b; i++)

#define out(x) cout << x << endl

#define exout(x) printf("%.10f\n", x)

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

#define all(a) a.begin(), a.end()

#define rall(a) a.rbegin(), a.rend()

#define pb push_back

#define re0 return 0

const ll mod = 1000000007;

const ll INF = 1e16;

const ll MAX_C = 200010;

 

int main() {

    ll n;

    cin >> n;



    vl c(n);

    rep(i, n) {

        cin >> c[i];

    }



    vl v(n);

    vl w(MAX_C, -1);

    rep(i, n) {

        v[i] = w[c[i]];

        w[c[i]] = i;

    }



    vl dp(n);  // dp[i] : 石iまでの列の個数

    dp[0] = 1;

    exrep(i, 1, n-1) {

        dp[i] += dp[i-1];

        if(v[i] >= 0 && v[i] != i-1) {

            dp[i] += dp[v[i]];

        }

        dp[i] %= mod;

    }



    out(dp[n-1]);

    re0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

const int MAX_N = 200010;



int main() {

    int n;

    cin >> n;



    vector<int> c(MAX_N);

    for(int i = 1; i <= n; i++) {

        cin >> c[i];

    }



    vector<ll> dp(MAX_N);  // dp[i] : 最初からi個(iは1-index)の石の条件を満たす塗り方の個数

    vector<int> last(MAX_N);

    vector<int> pos(MAX_N);



    for(int i = 1; i <= n; i++) {

        last[i] = pos[c[i]];

        pos[c[i]] = i;

    }



    dp[0] = 1;

    for(int i = 1; i <= n; i++) {

        dp[i] = dp[i-1];

        if(last[i] != 0 && last[i] != i-1) {

            dp[i] += dp[last[i]];

            dp[i] %= mod;

        }

    }



    cout << dp[n] << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <numeric>

#include <functional>

using namespace std;

typedef long long ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

typedef pair<ll, ll> P;

#define rep(i, n) for(ll i = 0; i < n; i++)

#define exrep(i, a, b) for(ll i = a; i <= b; i++)

#define out(x) cout << x << endl

#define exout(x) printf("%.10f\n", x)

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

#define all(a) a.begin(), a.end()

#define rall(a) a.rbegin(), a.rend()

#define pb push_back

#define re0 return 0

const ll mod = 1000000007;

const ll INF = 1e16;

const ll MAX_C = 200010;

 

int main() {

    ll n;

    cin >> n;



    vl c(n);

    rep(i, n) {

        cin >> c[i];

    }



    vl v(n);

    vl w(MAX_C, -1);

    rep(i, n) {

        v[i] = w[c[i]];

        w[c[i]] = i;

    }



    vl dp(n);  // dp[i] : 石iまでの列の個数

    dp[0] = 1;

    exrep(i, 1, n-1) {

        dp[i] += dp[i-1];

        if(v[i] >= 0 && v[i] != i-1) {

            dp[i] += dp[v[i]];

        }

        dp[i] %= mod;

    }



    out(dp[n-1]);

    re0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

using namespace std;

typedef long long ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

#define rep(i, n) for(ll i = 0; i < n; i++)

#define exrep(i, a, b) for(ll i = a; i <= b; i++)

#define out(x) cout << x << endl

#define exout(x) printf("%.10f\n", x)

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

#define all(a) a.begin(), a.end()

#define rall(a) a.rbegin(), a.rend()

#define pb push_back

#define re0 return 0

const ll mod = 1000000007;

const ll INF = 1e16;

const ll MAX_N = 200010;



int main() {

    ll n;

    cin >> n;

 

    vl c(MAX_N);

    exrep(i, 1, n) {

        cin >> c[i];

    }

 

    vl dp(MAX_N);  // dp[i] : 最初からi個(iは1-index)の石の場合の数

    vl v(MAX_N);  // v[i] : j < i かつ c[j] = c[i] となる最大のj (存在しないときは0)

    vl w(MAX_N);  // vを埋めるための補助的なvector

 

    exrep(i, 1, n) {

        v[i] = w[c[i]];

        w[c[i]] = i;

    }

 

    dp[0] = 1;

    exrep(i, 1, n) {

        dp[i] = dp[i-1];  // i個目の石に操作をしない場合の数はdp[i-1]通り

        if(v[i] != 0 && v[i] != i-1) {  // j < i かつ c[j] = c[i] となるjが存在して、c[i-1] != c[i] のとき

            dp[i] += dp[v[i]];  // i個目とv[i]個目の石に対して操作を行うときの場合の数はdp[v[i]]通り

            dp[i] %= mod;

        }

    }

 

    out(dp[n]);

    re0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <string>

#include <algorithm>

#include <utility>

#include <cmath>

#include <vector>

#include <queue>

#include <set>

#include <map>

#include <numeric>

#include <functional>

using namespace std;

typedef long long ll;

typedef vector<ll> vl;

typedef vector<vector<ll>> vvl;

typedef pair<ll, ll> P;

#define rep(i, n) for(ll i = 0; i < n; i++)

#define exrep(i, a, b) for(ll i = a; i <= b; i++)

#define out(x) cout << x << endl

#define exout(x) printf("%.10f\n", x)

#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)

#define all(a) a.begin(), a.end()

#define rall(a) a.rbegin(), a.rend()

#define pb push_back

#define re0 return 0

const ll mod = 1000000007;

const ll INF = 1e16;

const ll MAX_C = 200010;

 

int main() {

    ll n;

    cin >> n;



    vl c(n);

    rep(i, n) {

        cin >> c[i];

    }



    vl v(n);

    vl w(MAX_C, -1);

    rep(i, n) {

        v[i] = w[c[i]];

        w[c[i]] = i;

    }



    vl dp(n);  // dp[i] : 石iまでの列の個数

    dp[0] = 1;

    exrep(i, 1, n-1) {

        dp[i] += dp[i-1];

        if(v[i] >= 0 && v[i] != i-1) {

            dp[i] += dp[v[i]];

        }

        dp[i] %= mod;

    }



    out(dp[n-1]);

    re0;

}

// Fastest known solution for this problem: