#P11929. Good Permutations
Good Permutations
Good Permutations
We call a sequence \(a=[a_1,a_2,\ldots,a_k]\) increasing if and only if \(a_1 < a_2 < \cdots < a_k\), decreasing if and only if \(a_1 > a_2 > \cdots > a_k\), and unimodal if and only if there exists an index \(1 \le l \le k\) such that \([a_1,a_2,\ldots,a_l]\) is increasing and \([a_l,a_{l+1},\ldots,a_k]\) is decreasing. In particular, when \(k=1\) the sequence is increasing, decreasing, and unimodal simultaneously.
For three positive integers \(a,b,c\) we say that a permutation \(p\) is good if and only if:
- the length of the longest increasing subsequence (LIS) of \(p\) is exactly \(a\),
- the length of the longest decreasing subsequence (LDS) of \(p\) is exactly \(b\), and
- the length of the longest unimodal subsequence of \(p\) is exactly \(c\).
For example, when \(a=2,\; b=3,\; c=4\) the permutation [4, 5, 2, 3, 1]
is good since:
- LIS is \([4,5]\) (of length \(2\));
- LDS is \([4,2,1]\) (of length \(3\));
- and one of the longest unimodal subsequences is \([4,5,3,1]\) (of length \(4\)).
It can be shown that if \(1\le a\le b\le c < a+b\) then at least one good permutation exists, and moreover there are only finitely many good permutations. Define \(n\) to be the maximum possible length of a good permutation. In this problem you are to compute:
- The maximum length \(n\) among all good permutations \(p\).
- The number of good permutations of length \(n\), taken modulo the prime \(10^9+7\).
Observation and Hint: One may prove that when the triple \((a,b,c)\) satisfies \(1 \le a \le b \le c < a+b\) the maximum possible length is \[ n_{\max} = a \times b + c - a - b + 1. \] Furthermore, the number of good permutations of maximum length is given by the formula \[ \text{count} = \binom{a\times b - 1}{a+b-c-1} \pmod{10^9+7}, \] where \(\binom{n}{k}\) denotes the binomial coefficient. (It can be shown that when \(c = a+b-1\) the answer is unique.)
You need to compute and output these two numbers.
inputFormat
The input consists of a single line containing three integers \(a\), \(b\), and \(c\) separated by spaces, satisfying \(1 \le a \le b \le c < a+b\).
outputFormat
Output two integers separated by a space: the maximum possible length \(n\) of a good permutation, and the number of good permutations of length \(n\) modulo \(10^9+7\).
sample
2 3 4
6 1