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

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

#define in read()

#define re register

#define fur(i,a,b) for(re int i=a;i<=b;++i)

#define fdr(i,a,b) for(re int i=a;i>=b;--i)

#define cl(a,b) memset(a,b,sizeof(a))

#define jinitaimei signed

#define int long long

inline int read()

{

	int x=0;

	char ch=getchar();

	for(;!isalnum(ch);ch=getchar());

	for(;isalnum(ch);ch=getchar()) x=x*10+ch-'0';

	return x;

}

const int xx=1e5+1;

struct point

{

	int x,y;

}tmp[xx],check[xx*9];

int w,h,n;

inline int num(point a){return (a.x-1)*w+a.y;}

inline bool cmp(point a,point b){return num(a)<num(b);}

inline bool cmpp(point a,point b){return a.x<b.x;}

inline int look_up(int k)

{

	int hd=1,tl=n,ans=n+1;

	while(hd<=tl)

	{

		int mid=hd+tl>>1;

		if(num(tmp[mid])>=k) ans=mid,tl=mid-1;

		else hd=mid+1;

	}

	return ans;

}

inline int look_down(int k)

{

	int hd=1,tl=n,ans=0;

	while(hd<=tl)

	{

		int mid=hd+tl>>1;

		if(num(tmp[mid])<=k) ans=mid,hd=mid+1;

		else tl=mid-1;

	}

	return ans;

}

int res[10],all=0;

jinitaimei main()

{

	h=in;w=in;n=in;

	fur(i,1,n) tmp[i]=(point){in,in};

	sort(tmp+1,tmp+n+1,cmp);

	res[0]=(w-2)*(h-2);

	fur(i,1,n) fur(x,tmp[i].x-2,tmp[i].x) fur(y,tmp[i].y-2,tmp[i].y) if(x>0&&y>0)

	{

		int ch=num((point){x,y});

		int chh=num(tmp[i]);

		int delta=chh-ch;

		if(delta/w>2||delta%w>2) continue;

		if(x+2>h||y+2>w) continue;

		int cnt=0;

		fur(k,0,2)

		{

			int l=look_up(ch+k*w),r=look_down(ch+k*w+2);

			cnt+=(r-l+1);

		}

		if(cnt>0) check[++all]=(point){ch,cnt};

	}

	sort(check+1,check+all+1,cmpp);

	fur(i,1,all)

	{

		while(check[i].x==check[i+1].x) ++i;

		++res[check[i].y];

		--res[0];

	}

	fur(i,0,9) printf("%lld\n",res[i]);

	return 0;

}


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

#include<stdlib.h>

#include<string.h>

#include<algorithm>

using namespace std;

#define INF (int(1e9)+7)//1e9+7进制

#define maxn (int(1e6)+5)

typedef long long ll;

ll node[maxn];

ll res[15];

int main(void)

{

	ll H, W, N;

	scanf("%lld %lld %lld", &H, &W, &N);

	int cnt = 0;

	while (N--)

	{

		ll a, b;

		scanf("%lld %lld", &a, &b);

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

			for (int j = -1; j <= 1; j++)

				if (a + i >= 2 && a + i <= H - 1 && b + j >= 2 && b + j <= W - 1)

					node[cnt++] = (a + i) * INF + (b + j);

	}

	sort(node, node + cnt);

	ll temp = node[0];

	ll sum = 1;

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

		if (node[i] == temp)

			sum++;

		else

			res[sum]++, sum = 1, temp = node[i];

	}

	if(cnt)res[sum]++;

	res[0] = (H - 2) * (W - 2);

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

		res[0] -= res[i];

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

		printf("%lld\n", res[i]);

	return 0;

}

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

#include<cstdio>

using namespace std;

typedef pair<int,int> pii;

typedef long long ll;

map<pii,int> mp;

long long cnt[10],h,w,n;

int max(int x,int y)

{

 return (x>=y)? x:y;

}

int min(int x,int y)

{

  return (x<y)? x:y;

}

inline int read(){

   int s=0,w=1;

   char ch=getchar();

   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}

   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();

   return s*w;

}

int main()

{   

	h=read(),w=read(),n=read();

    int i,j;

while(n--)

{

  int x=read(),y=read();

  for (i=max(1,x-2);i<=min(h-2,x);++i)

  {

    for (j=max(1,y-2);j<=min(w-2,y);++j)

	{

      mp[pii(i,j)]++; 

    }

    }

  }

for (map<pii,int>::iterator iter=mp.begin();iter!=mp.end();iter++) cnt[iter->second]++,n++;

ll ans=1ll*(h-2)*(w-2);

 printf("%lld\n",ans-n-1);

for (i=1;i<=9;++i) printf("%lld\n",cnt[i]);

}

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

#include<stdlib.h>

#include<string.h>

#include<algorithm>

using namespace std;

#define INF (int(1e9)+7)//1e9+7进制

#define maxn (int(1e6)+5)

typedef long long ll;

ll node[maxn];

ll res[15];

int main(void)

{

	ll H, W, N;

	scanf("%lld %lld %lld", &H, &W, &N);

	int cnt = 0;

	while (N--)

	{

		ll a, b;

		scanf("%lld %lld", &a, &b);

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

			for (int j = -1; j <= 1; j++)

				if (a + i >= 2 && a + i <= H - 1 && b + j >= 2 && b + j <= W - 1)

					node[cnt++] = (a + i) * INF + (b + j);

	}

	sort(node, node + cnt);

	ll temp = node[0];

	ll sum = 1;

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

		if (node[i] == temp)

			sum++;

		else

			res[sum]++, sum = 1, temp = node[i];

	}

	if(cnt)res[sum]++;

	res[0] = (H - 2) * (W - 2);

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

		res[0] -= res[i];

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

		printf("%lld\n", res[i]);

	return 0;

}

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



using namespace std;



typedef long long ll;



const int N=200050;

const ll MOD=1e9+7;

int n;

int a[N],p[N];

ll f[N];



int main(){

	scanf("%d",&n);

	for (int i=1;i<=n;++i) scanf("%d",&a[i]);

	f[0]=0;f[1]=1;

	memset(p,0,sizeof(p));p[a[1]]=1;

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

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

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

			f[i]=(f[i]+f[p[a[i]]])%MOD;

		p[a[i]]=i;

	}

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

}

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

#include <cstdio>

using namespace std;

const int M = 1000000007;

const int N = 2e5 + 10;

int n, dp[N], s[N], c[N];

int main() {

	scanf("%d", &n); dp[0] = 1;

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

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

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

			i --; n --;

		}

	}

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

		dp[i] = (s[c[i]] + dp[i - 1]) % M;

		(s[c[i]] += dp[i - 1]) %= M;

	}

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

	return 0;

}


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

 using namespace std;

 const long long mod = 1e9 + 7;

 int a[200005], b[200005], c[200005];

 long long num[200005];

int main() 

{

	 int n, k = 1;

	 cin >> n;

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

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

	 c[1] = a[1];

	 int t = 1;

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

	 {

		 if (a[i] != c[t])

			 c[++t] = a[i];

	

	  }

	  num[0] = 1;

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

		   if (b[c[i]])

			   num[i] = (num[i - 1] + num[b[c[i]]]) % mod;

		   else num[i] = num[i - 1];

		       num[i] %= mod;

		       b[c[i]] = i;

		

	  }

	  cout << num[t] << endl;

	  return 0;

}

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

#include <cstdio>

using namespace std;

const int M = 1000000007;

const int N = 2e5 + 10;

int n, dp[N], s[N], c[N];

int main() {

	scanf("%d", &n); dp[0] = 1;

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

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

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

			i --; n --;

		}

	}

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

		dp[i] = (s[c[i]] + dp[i - 1]) % M;

		(s[c[i]] += dp[i - 1]) %= M;

	}

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

	return 0;

}


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

using namespace std;



#define int long long

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

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

#define sz(x) ((int)x.size())

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

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



typedef pair<int, int> pii;

typedef vector<int> vi;

typedef vector<vi> vvi;



const int inf = 1LL<<60;

const int mod = 1e9 + 7;

const double eps = 1e-9;



/*{

  }*/



signed main(){

  int n;

  cin >> n;



  vi c(n);

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



  vi places[200001];

  vi dp(200001);



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



  dp[0] = 1;

  rep(i, 1, n+1){

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



    int color = c[i-1];

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

    if(it > 0){

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

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

    }

  }



  cout << dp[n] << endl;



  return 0;

}


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

using namespace std;



#define int long long

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

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

#define sz(x) ((int)x.size())

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

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



typedef pair<int, int> pii;

typedef vector<int> vi;

typedef vector<vi> vvi;



const int inf = 1LL<<60;

const int mod = 1e9 + 7;

const double eps = 1e-9;



/*{

  1 2 3

  1   2

  }*/



signed main(){

  int n;

  cin >> n;



  vi c(n);

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



  vi dp(n+1); 

  vi prev(200001, -1);

  dp[0] = 1;

  rep(i, 1, n+1){

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

    

    int &p = prev[c[i-1]];

    if(p != -1 and i-p > 1){

      (dp[i] += dp[p]) %= mod;

    }



    p = i;

  }



  cout << dp[n] << endl;



  return 0;

}


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

using namespace std;

const int M = 2e5 + 5;

const int P = 1e9 + 7;

int a[M], w[M], dp[M];

inline int Mod(int x) {

	return x >= P ? x - P : x;

}

int main() {

	int n; cin >> n;

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

	dp[n] = w[a[n]] = 1;

	for (int i = n - 1; i > 0; --i) {

        if (a[i] == a[i + 1]){dp[i] = dp[i + 1];continue;}

		dp[i] = Mod(dp[i + 1] + w[a[i]]);

		w[a[i]] = dp[i];

	}

	cout << dp[1] << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

} 

// Fastest known solution for this problem: