#P6885. [COCI 2016/2017 #3] Zoltan
[COCI 2016/2017 #3] Zoltan
Problem Description
Marton’s friend Cero has an array of positive integers.
First, Cero writes the first number of this array on the blackboard. Then, each time he writes the next number either to the left or to the right of all the numbers already written. Repeating this operation produces a sequence.
Note that two sequences constructed in this way are considered the same if and only if the writing order and the side chosen for every number are exactly the same. For example, may be different from : in the former, the second number is written to the left of the first one, while in the latter, the second number is written to the right of the first one.
Among all sequences that can be formed, let be the maximum possible length of the longest strictly increasing subsequence. Also, among all sequences whose longest strictly increasing subsequence length equals , compute the sum of the numbers of longest strictly increasing subsequences. Since the answer may be very large, output this value modulo .
Input Format
The first line contains a positive integer .
The next line contains positive integers, the elements of the array given in order.
Output Format
Output one line containing the maximum length and the required total count modulo .
2
1 1
1 4
4
2 1 3 4
4 1
Hint
Sample Explanation
Sample 1 Explanation
Cero can construct different sequences: and .
Clearly, the length of the longest strictly increasing subsequence is , and there are subsequences that satisfy this.
Sample 2 Explanation
The length of the longest strictly increasing subsequence is , and only satisfies this.
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, , and each element in the array is .
Note
Translated from COCI2016-2017 CONTEST #3 T5 Zoltan.
The explanations for Samples 1 and 2 are unofficial.
Translated by ChatGPT 5