stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}




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

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

}

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

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

}

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

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

}

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

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

}


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

#include <map>

using namespace std;

#define N 200001

#define DD 1000000007

int a[N];

int f = 1;

map<int,int> m;

int main()

{

	int n,tot = 1;

	cin >> n;

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

		cin >> a[i];

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

	{

		if(a[i] != a[i - 1])

			a[++tot] = a[i];

	}

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

	{

		f = (f + m[a[i]]) % DD;

		m[a[i]] = f;

	}

	cout << f << endl;

	return 0;

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

}


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

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

}

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

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

}

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

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

}

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

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

}

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

 

int main() {

    ll n;

    cin >> n;



    vl v(200010);

    vl w(200010);

    exrep(i, 1, n) {

        ll c;

        cin >> c;

        v[i] = w[c];

        w[c] = i;

    }



    vl dp(n+1);

    dp[0] = 1;

    exrep(i, 1, n) {

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

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

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

        }

        dp[i] %= mod;

    }

    

    out(dp[n]);

    re0;

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

}

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

 

int main() {

    ll n;

    cin >> n;



    vl v(200010);

    vl w(200010);

    exrep(i, 1, n) {

        ll c;

        cin >> c;

        v[i] = w[c];

        w[c] = i;

    }



    vl dp(n+1);

    dp[0] = 1;

    exrep(i, 1, n) {

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

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

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

        }

        dp[i] %= mod;

    }

    

    out(dp[n]);

    re0;

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

using namespace std;

//#define ull unsigned long long

#define ull uint

#define ul unsigned long

#define ll long long



int main(){

  int N;

  cin>>N;

  int inc,myno;

  ull SYO=1000000007,sameflg;

  vector<int> C(N,0);

  cin>>C[0];

  int newN=1,jid;//newN

  

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

    cin>>inc;

    if (C[newN-1]!=inc){

      C[newN]=inc;

      newN++;

    }

  }

  //Cの数値が何個出現するかを記憶する変数

  vector<int> Cnum(200000,0);

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

    Cnum[C[i]]++;

  }

  vector<int> Cnumsum(200000,0);//参照する最初のindexがこれでわかる

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

    Cnumsum[i]=Cnumsum[i-1]+Cnum[i-1];

  }

  vector<int> Cnumsum_dmy(200000,0);//参照する最初のindexがこれでわかる

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

    Cnumsum_dmy[i]=Cnumsum[i];

  }

  

  //Cの数値が出現したindexを記憶する変数

  vector<int> Cnumid(newN,0);

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

    Cnumid[Cnumsum_dmy[C[i]]]=i;

    Cnumsum_dmy[C[i]]++;

  }

  

  vector<int> sumdp(200000,0);

  

  

  vector<vector<ull>> dp = vector<vector<ull>>(newN, vector<ull>(2, 0));

  ull ans=0;

  dp[0][0]=1;

  sumdp[C[0]]=1;

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

    myno=C[i];

    sameflg=0;

    

    for(int j=0;j<Cnum[myno];j++){

      jid=Cnumid[Cnumsum[myno]+j];

      if (jid>=i){break;}

      //sameflg++;

    }

    

      sameflg+=sumdp[myno];

      sameflg%=SYO;

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

      sumdp[myno]=(sumdp[myno]+dp[i-1][0])%SYO;

    

    

  }

    

  ans=dp[newN-1][0];

  cout<<ans%SYO<<endl;

  return 0;

}

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

using namespace std;



int main(){

  uint N;

  cin>>N;

  uint inc,myno,SYO=1000000007,sameflg;

  vector<uint> C(N,0);

  cin>>C[0];

  uint newN=1,jid;//newN

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

    cin>>inc;

    if (C[newN-1]!=inc){

      C[newN]=inc;

      newN++;

    }

  }

  

  vector<uint> sumdp(200000,0);

  vector<uint> dp(newN,0);



  dp[0]=1;

  sumdp[C[0]]=1;

  for(uint i=1;i<newN;i++){

    myno=C[i];

    sameflg=sumdp[myno];

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

    sumdp[myno]=(sumdp[myno]+dp[i-1])%SYO;

  }



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

  return 0;

}