stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

template<class T> T read(){

	T x=0,w=1;char c=getchar();

	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;

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

	return x*w;

}

template<class T> T read(T&x){

	return x=read<T>();

}

#define CO const

#define IN inline

typedef long long LL;



CO int mod=1000000000+7;

IN int add(int a,int b){

	return (a+=b)>=mod?a-mod:a;

}

IN int mul(int a,int b){

	return (LL)a*b%mod;

}

IN int fpow(int a,int b){

	int ans=1;

	for(;b;b>>=1,a=mul(a,a))

		if(b&1) ans=mul(ans,a);

	return ans;

}



CO int N=200000+10;

int lst[N],dp[N];



int main(){

	int n=read<int>();

	dp[0]=1;

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

		int val=read<int>();

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

		if(lst[val] and lst[val]<i-1) dp[i]=add(dp[i],dp[lst[val]]);

		lst[val]=i;

	}

	printf("%d\n",dp[n]);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.1545474961280515x):
#include<cstdio>

#include<vector>

#define ll long long

#define rep(i, l, r) for(int i=l; i<=r; ++i)

#define N 200005

#define mod 1000000007

using namespace std;

int t;

int n;

int a[N];

int dp[N];

int f[N];

int main() {

	scanf("%d", &n);

	rep(i, 1, n) scanf("%d", &a[i]);

	dp[0]=1;

	rep(i, 1, n){

		dp[i]=0;

		if(i==1 || a[i-1]!=a[i]) f[a[i]]=(f[a[i]]+dp[i-1])%mod;

		dp[i]=(dp[i]+f[a[i]])%mod;

	}

	printf("%d", dp[n]);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define modp 1000000007

#define Maxn 200007

int n,a[Maxn],f[Maxn],s[Maxn];

int main()

{

    scanf("%d",&n);

    int m=1;

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

        scanf("%d",&a[i]);

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

        if (a[i]!=a[m]) a[++m]=a[i];

    n=m;

    f[0]=1;

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

    {

        f[i]=(f[i-1]+s[a[i]])%modp;

        s[a[i]]=f[i];

    }

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.213410379482865x):
#include<cstdio>

#include<vector>

#define ll long long

#define rep(i, l, r) for(int i=l; i<=r; ++i)

#define N 200005

#define mod 1000000007

using namespace std;

int t;

int n;

int a[N];

int dp[N];

int f[N];

int main() {

	scanf("%d", &n);

	rep(i, 1, n) scanf("%d", &a[i]);

	dp[0]=1;

	rep(i, 1, n){

		dp[i]=0;

		if(i==1 || a[i-1]!=a[i]) f[a[i]]=(f[a[i]]+dp[i-1])%mod;

		dp[i]=(dp[i]+f[a[i]])%mod;

	}

	printf("%d", dp[n]);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

const int N = 200010;

const int MOD = 1e9+7;

int _w;



int n, c[N], f[N], last[N];



int main() {

	_w = scanf( "%d", &n );

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

		_w = scanf( "%d", c+i );

	f[1] = 1, last[c[1]] = 1;

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

		if( last[c[i]] ) {

			f[i] = (f[i] + f[last[c[i]]]) % MOD;

		}

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

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

		}

		// printf( "f[%d] = %d\n", i, f[i] );

		last[c[i]] = i;

	}

	cout << f[n] << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.192550179684373x):
#include<cstdio>

#include<vector>

#define ll long long

#define rep(i, l, r) for(int i=l; i<=r; ++i)

#define N 200005

#define mod 1000000007

using namespace std;

int t;

int n;

int a[N];

int dp[N];

int f[N];

int main() {

	scanf("%d", &n);

	rep(i, 1, n) scanf("%d", &a[i]);

	dp[0]=1;

	rep(i, 1, n){

		dp[i]=0;

		if(i==1 || a[i-1]!=a[i]) f[a[i]]=(f[a[i]]+dp[i-1])%mod;

		dp[i]=(dp[i]+f[a[i]])%mod;

	}

	printf("%d", dp[n]);

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#define N 200010

#define mod 1000000007

using namespace std;

int ans[N],stone[N];

int n;

int a[N];

int main()

{

	cin >> n;

	int sum = 1;

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

	{

		scanf("%d",stone + sum);

		if(stone[sum] ^ stone[sum - 1])

			sum ++;

	}

	sum --;

	ans[1] = 1;

	a[stone[1]] = 1;

	for(int i = 2;i <= sum;i ++)

	{

		int now_color = stone[i];

		ans[i] = (ans[i - 1] + ans[a[now_color]]) % mod;

		a[now_color] = i;

	}

	printf("%d\n",ans[sum]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2331255885566055x):
#include<cstdio>

#include<vector>

#define ll long long

#define rep(i, l, r) for(int i=l; i<=r; ++i)

#define N 200005

#define mod 1000000007

using namespace std;

int t;

int n;

int a[N];

int dp[N];

int f[N];

int main() {

	scanf("%d", &n);

	rep(i, 1, n) scanf("%d", &a[i]);

	dp[0]=1;

	rep(i, 1, n){

		dp[i]=0;

		if(i==1 || a[i-1]!=a[i]) f[a[i]]=(f[a[i]]+dp[i-1])%mod;

		dp[i]=(dp[i]+f[a[i]])%mod;

	}

	printf("%d", dp[n]);

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

const long long MOD = 1000000007;



vector<int> places[210000];

long long dp[210000];

void add(long long &a, long long 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];



    // places[i] := (c[j] = i となるような j の集まり)

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

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



    // DP

    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(); // itは c[i-1] が color 色の何番目の要素か

        if (it > 0) {

        	//もしもc[i-1]が color 色の1番目以上だったら

            int j = places[color][it - 1]; // c[j] = c[i] となる j

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

        }

    }

    cout << dp[N] << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.1353764882410293x):
#include <bits/stdc++.h>

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

#define ll long long

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



using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }



const ll mod = 1e9 + 7;

const ll INF = -1 * ((1LL << 63) + 1);

const int inf = -1 * ((1 << 31) + 1);



ll dp[(int)2e5+2];



int main(void){

    cin.tie(0);

    ios::sync_with_stdio(false);

    cout << fixed << setprecision(20);

    int n;

    cin >> n;

    ll ans = 1;

    vector<int> c(n);

    vector<vector<int>> g(2e5+2);

    rep(i,n){

        cin >> c[i];

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

    }

    dp[0] = 1;

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

        dp[i-1]%=mod;

        dp[i]%=mod;

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





        int color = c[i-1];



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

        if(it > 0){

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

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

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

                dp[i]%=mod;

                dp[j+1]%=mod;

            }

        }

    }

    cout << dp[n]%mod << endl;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int P=1e9+7;

const int M=2e5+5;

int n,m;

int a[M],col[M];

bool mark[M];

vector<int>vec[M];

int id[M],nxt[M],pre[M];

#define lowbit(x) (x&-x)

int C[M];

void Add(int x,int k){

	while(x<=m+1){

		(C[x]+=k)%=P;

		x+=lowbit(x);

	}

}

int sum(int x){

	ll res=0;

	while(x){

		(res+=C[x])%=P;

		x-=lowbit(x);

	}

	return res;

}

ll ss[M];

void solve(){

	Add(1,1);

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

		int s;

		if(pre[i]){

			s=sum(pre[i]-1);

			(ss[a[i]]+=s)%=P;

			Add(i,ss[a[i]]);

		}

	}

	int res=sum(m+1);

	printf("%d\n",res);

}

void Init(){

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

		if(id[a[i]])nxt[id[a[i]]]=i,pre[i]=id[a[i]];

		id[a[i]]=i;

	}

}

int main(){

	scanf("%d",&n);m=1;

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

	for(int i=1;i<=n;i++)if(col[i]!=col[i-1])a[++m]=col[i];

	Init();solve();

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.52466234335518x):
#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int P=1e9+7;

const int M=2e5+5;

int n,m;

int a[M],col[M];

int id[M],pre[M];

ll ss[M],sum[M];

void solve(){

	sum[0]=1;

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

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

		if(!pre[i])continue;

		int s=sum[pre[i]-1];

		(ss[a[i]]+=s)%=P;

		(sum[i]+=ss[a[i]])%=P;

	}

	printf("%d\n",sum[m]);

}

void Init(){

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

		if(id[a[i]])pre[i]=id[a[i]];

		id[a[i]]=i;

	}

}

int main(){

	scanf("%d",&n);

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

	for(int i=1;i<=n;i++)if(col[i]!=col[i-1])a[++m]=col[i];

	Init();solve();

	return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <iomanip>

#include <cassert>

#include <cstring>

#include <string>

#include <vector>

#include <cmath>

#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);

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

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

typedef long long ll;

using namespace std;

const ll MOD = 1e9+7LL;

int n;

int A[200005];

vector<int> M[200005];

ll dp[200005];



int main() {

  INCANT;

  cin >> n;

  rep(i, n) {

    cin >> A[i];

    A[i]--;

  }

  vector<int> P(n, -1);

  rep(i, n) {

    int sz = M[A[i]].size();

    if (sz) P[i] = M[A[i]][sz-1];

    M[A[i]].push_back(i);

  }



  fill(dp, dp+n, -1);

  dp[0] = 1ll;

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

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

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

      dp[i] += dp[P[i]];

      dp[i]%=MOD;

    } 

  }



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

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.5639398159219167x):
#include <algorithm>

#include <iostream>

#include <iomanip>

#include <cassert>

#include <cstring>

#include <string>

#include <vector>

#include <cmath>

#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);

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

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

typedef long long ll;

using namespace std;

const ll MOD = 1e9+7LL;

int n;

int A[200005];

int LastIdx[200005];

ll dp[200005];



int main() {

  INCANT;

  cin >> n;

  rep(i, n) {

    cin >> A[i];

    A[i]--;

  }

  vector<int> P(n, -1);

  fill(LastIdx, LastIdx+200005, -1);

  rep(i, n) {

    P[i] = LastIdx[A[i]];

    LastIdx[A[i]] = i;

  }



  fill(dp, dp+n, -1);

  dp[0] = 1ll;

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

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

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

      dp[i] += dp[P[i]];

      dp[i]%=MOD;

    } 

  }



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

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MM 1000000000

#define MOD MM+7

#define MAX 101000

#define MAP 110

#define initial_value -1

#define Pair pair<int,int>

#define lPair pair<ll,ll>

#define chmax(a,b) (a<b ? a=b:0)

#define chmin(a,b) (a>b ? a=b:0)

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

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



vector<int> places[200200];

ll dp[200200];

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 < 200200; 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]; //c[j] = c[i]となるj

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

        }

    }

    cout << dp[N] << endl;

}

// Faster C++ solution for the same problem (measured speedup: 7.131433608001738x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MM 1000000000

#define MOD MM+7

#define MAX 101000

#define MAP 110

#define initial_value -1

#define Pair pair<int,int>

#define lPair pair<ll,ll>

#define chmax(a,b) (a<b ? a=b:0)

#define chmin(a,b) (a>b ? a=b:0)

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

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

int C[200200];

int pre[200200];

ll dp[200200];

int main(){

    int N; cin >> N;

    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];

        int cur = C[i];

        if(pre[cur] && pre[cur] != i-1){

            dp[i] += dp[pre[cur]];

            dp[i] %= MOD;

        }

        pre[cur] = i;

    }

    cout << dp[N] << endl;

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<vector>

using namespace std;

struct stone{

    int color=0;

    int to_add=0;

};

int main(){

    int N;

    int mod=1e9+7;

    cin>>N;

    stone stones[200000];

    int out=1;

    int temp,last;

    int colors[N];

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

        cin>>colors[i];

    }

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

        temp=colors[i];

        if(i&&temp==last)

            continue;

        else

            last=temp;

        bool in=false;

        if(stones[temp].to_add)/*有记录*/{

            out+=stones[temp].to_add;

            out=out%mod;

            stones[temp].to_add=out;

            in = true;

        }

        else{

            stones[temp].color=temp;

            stones[temp].to_add=out;

        }//新颜色

    }

    cout<<out<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.6029396407357748x):
#include<iostream>

#include<vector>

#include<cstring>



using namespace std;

const int mod = 1e9+7;



int main(){

	int t,n,maxnum;

	cin >> t; cin >> n;

	vector<int> s;

	s.push_back(n);

	maxnum = n;

	while(--t){

        cin >> n;

		if(n == s.back())continue;

		s.push_back(n);

		if(n > maxnum)maxnum = n;

	}

    int dp[s.size()+1];

	int save[maxnum+1];

	memset(save, 0, sizeof(save));

    dp[0] = 1;

    for(int i = 0; i < s.size(); ++i){

		dp[i+1] = (dp[i] + save[s[i]])%mod;

		save[s[i]] = (save[s[i]]+ dp[i])%mod; 

    }

    cout << dp[s.size()];

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 2.586698145307561x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 6.510187913392261x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 6.502668406633698x):
#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;

}