atcoder#ARC128D. [ARC128D] Neq Neq
[ARC128D] Neq Neq
Score : points
Problem Statement
We have balls arranged in a row, numbered to from left to right. Ball has an integer written on it.
You can do the following operation any number of times.
- Choose three consecutive balls ). Here, and must hold. Then, eat Ball . After this operation, Balls and are considered adjacent.
Find the number of possible sets of balls remaining in the end, modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4
1 2 1 2
3
There are three possible sets of balls remaining in the end: .
5
5 4 3 2 1
8
Different sequences of operations are not distinguished if they result in the same set of balls.
5
1 2 3 2 1
8
Different sets of remaining balls are distinguished even if they have the same sequence of integers written on them.
9
1 4 2 2 9 6 9 6 6
14