A Little Bit of Cryptography Never Hurt Anybody
Recently, Professor L. developed a special cipher that no one could break. Anton took this personally and decided to crack it by himself. He noticed that before every message there was a small pyramid drawn and a permutation of elements.
After some brainstorming, he understood that every message had a different cipher based on the number of different permutations of elements that were both:
pyramidal permutations.
lexicographically smaller than .
Your task is for a given to find out how many pyramidal permutations exist that are lexicographically smaller than . As this number may be too large, output it by modulo .
A permutation of elements is called pyramidal if there exists an index , such that:
for each (), ;
for each (), .
A sequence of integers is called a permutation if the sequence contains each integer from to exactly once. For example, is a permutation. However, is not (it doesn't contain and contains , which should not appear in the sequence) and is not as well (it contains twice and doesn't contain ).
An array is lexicographically smaller than an array if and only if one of the following holds:
is a prefix of , but ;
in the first position where a and b differ, the array has a smaller element than array .
Input
The first line contains a single integer — the length of the permutation.
The second line contains integers () — elements of the permutations.
It is guaranteed that is a permutation.
Output
Output a single integer — answer for the task.
Examples
Note
In the first example, there are pyramidal permutations less or equal to :
Note that .
In the second example, there is only pyramidal permutation less or equal to :
Scoring
( points): ;
( points): ;
( points): ;
( points): ;
( points): ;
( points): ;
( points): no additional restrictions.