Gomory has just moved to the Lucky Mill. He cares a lot about the aesthetics of the fence surrounding the mill, but some planks are missing, and the remaining ones differ in height. For economic reasons, he will leave the planks that already exist in place and will only add new ones in the missing positions. Also, so that the mill does not appear too confusing to passersby, he wants a certain height to be a majority. Since Gomory is too busy counting his money, help him by counting the ways in which he can build the fence.
Task
Formally, you are given an array of length representing the heights of the planks. If a plank is missing at position , then you will receive the value . Otherwise, you will receive a natural number between and representing the height of the plank at position . You must output the number of ways to replace the values in the array with natural numbers between and such that there exists a majority element.
Input Data
On the first line, a natural number is read, representing the number of planks in the fence.
On the second line, the elements of the array are read, separated by a space.
Output Data
You must output a single number representing the number of ways modulo in which a majority element can be obtained.
Constraints and Notes
- or , for any from to
- An element is majority if it appears at least times.
| # | Score | Constraints |
|---|---|---|
| 1 | 15 | |
| 2 | 15 | The fence initially contains no planks (the array contains only the value ) |
| 3 | 30 | |
| 4 | 40 | No additional constraints |
Example
stdin
4
1 -1 2 -1
stdout
2
Explanation
The values equal to can be replaced with any value from to . The only possibilities with a majority element are: and . If we form the array , is not a majority element because it appears fewer than times, that is, fewer than times.