Professor JOI is a leading expert on the study of the history of IOI Kingdom. When he was surveying an old temple in IOI Kingdom, he found ruins where the stone pillars were constructed. He also found an old document which was supposedly written by ancient people in IOI Kingdom. The document contains descriptions on the stone pillars. More precisely, the following is written in the document.
- Just after the construction, there were
stone pillars, numbered from to . - Just after the construction, for each
, there were exactly two stone pillars of height . - The earthquake occurred
times. After each earthquake, some of the stone pillars collapsed and their heights decreased by . However, other stone pillars were protected by ancient people. These stone pillars did not collapse, and their heights remained the same. - When an earthquake occurred, for each
, exactly one stone pillar of height was protected by ancient people. If there were more than one stone pillar of height when an earthquake occurred, the stone pillar of height with largest number was protected. In other words, if the height of the stone pillar was before an earthquake, then the stone pillar was protected if and only if and for every . - After the
earthquakes occurred, stone pillars remained (i.e. there were exactly stone pillars with height at least ).
Professor JOI thinks it would be a great discovery if he can recover the heights of the
Professor JOI wants to know the number of possible combinations of the heights of the
Write a program which, given the indices of the remaining stone pillars after the
Input Specification
Output Specification
Write one line to the standard output. Output the remainder when the answer is divided by
Constraints
Subtasks
- (6 points)
. - (52 points)
. - (42 points) No additional constraints.
Sample Input 1
3
3 4 6
Sample Output 1
5
Explanation for Sample 1
For example, assume that the heights of the stone pillars were 2, 2, 3, 3, 1, 1
, from the stone pillar
- When the first earthquake occurred, the stone pillars
, , were protected by ancient people. After the first earthquake, the heights of the stone pillars became1, 2, 2, 3, 0, 1
. - When the second earthquake occurred, the stone pillars
were protected by ancient people. After the second earthquake, the heights of the stone pillars became0, 1, 2, 3, 0, 1
. - When the third earthquake occurred, the stone pillars
were protected by ancient people. After the third earthquake, the heights of the stone pillars became0, 0, 2, 3, 0, 1
.
After the three earthquakes, the stone pillars
In addition to the above, there are four possible combinations of the heights of the stone pillars 2, 3, 2, 3, 1, 1
,
2, 3, 3, 2, 1, 1
, 3, 2, 2, 3, 1, 1
, 3, 2, 3, 2, 1, 1
.
Therefore, there are five possible combinations of the heights of the six stone pillars which agree with the description in the old document and the information given in the input.
Sample Input 2
1
1
Sample Output 2
0
Explanation for Sample 2
In this sample input,
Sample Input 3
10
5 8 9 13 15 16 17 18 19 20
Sample Output 3
147003663
Explanation for Sample 3
There are
Comments
why is there so much reading