Problem:
Score : 700 points

Problem Statement

There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i.

Snuke will perform the following operation zero or more times:

Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.

Find the number of possible final sequences of colors of the stones, modulo 10^9+7.

Constraints

1 \leq N \leq 2\times 10^5

1 \leq C_i \leq 2\times 10^5(1\leq i\leq N)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
C_1
:
C_N

Output

Print the number of possible final sequences of colors of the stones, modulo 10^9+7.

Sample Input 1

5
1
2
1
2
2

Sample Output 1

3

We can make three sequences of colors of stones, as follows:

(1,2,1,2,2), by doing nothing.

(1,1,1,2,2), by choosing the first and third stones to perform the operation.

(1,2,2,2,2), by choosing the second and fourth stones to perform the operation.

Sample Input 2

6
4
2
5
4
2
4

Sample Output 2

5

Sample Input 3

7
1
3
1
2
3
3
2

Sample Output 3

5

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef double db;
const int MAXN = 2e5 + 5, MAXM = 2e6 + 5, BOUND = 2e5, MOD = 1e9 + 7, INF = 0x3f3f3f3f, inv2 = 500000004;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-6;
#define mid l + ((r-l)>>1)
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define lc(x) c[x][0]
#define PII pair<int,int>
#define rc(x) c[x][1]
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
char gdffsaw;
#define G gdffsaw=getchar()
#define GO G;while(gdffsaw<'-')G
#define in(z) GO;z=gdffsaw&15;G;while(gdffsaw>'-')z*=10,z+=gdffsaw&15,G
int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n, c[MAXN];
vector<int> v[MAXN];
ll dp[MAXN][2];
int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	rep(i, 1, n) {
		cin >> c[i];
	}
	dp[0][0] = 1;
	rep(i, 1, n) {
		dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
		int len = (int)v[c[i]].size() - 1;
		rep(j, 0, len) {
			if (v[c[i]][j] != i - 1) {
				if (j < len && v[c[i]][j + 1] == i - 1)continue;
				dp[i][1] = (dp[i][1] + dp[v[c[i]][j]][0]) % MOD;
			}
		}
		v[c[i]].push_back(i);
	}
	cout << (dp[n][0] + dp[n][1]) % MOD << '\n';
	return 0;
}