In an array containing only positive integers, we say an integer is heavy if it appears more than once in the array, and light otherwise.
An array is good if the integers in the array alternate between light and heavy.
Given an array , count the number of ways to partition it into some number of contiguous subarrays such that each subarray, when considered as an array on its own, is good. As the answer may be large, output it modulo .
Input Specification
The first line of input contains a single integer, .
The next line contains integers .
Marks Awarded | Bounds on | Additional Constraints |
---|---|---|
3 marks | For each , . | |
4 marks | No additional constraints. | |
5 marks | If is odd, then . | |
6 marks | Any number appears at most twice in the array. | |
7 marks | No additional constraints. |
Output Specification
The number of ways to partition the array into good contiguous subarrays, modulo .
Sample Input 1
5
1 2 3 2 3
Sample Output 1
4
Explanation for Sample 1
There are four valid partitions of :
- , , , ,
- , ,
- , ,
- ,
Sample Input 2
5
1 2 1 3 1
Sample Output 2
6
Comments