Problem2129--AtCoder Grand Contest 031 B - Reversi

2129: AtCoder Grand Contest 031 B - Reversi

[Creator : ]
Time Limit : 2.000 sec  Memory Limit : 1024 MB

Description

Problem Statement

There are N stones arranged in a row. The i-th stone from the left is painted in the color Ci.
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 109+7.

Constraints

  • 1N2×105
  • 1Ci2×105(1iN)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N 
C1
::
CN

Output

Print the number of possible final sequences of colors of the stones, modulo 109+7


Sample Input Copy

5
1
2
1
2
2

Sample Output Copy

3

HINT

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.

Source/Category