A subsequence of a sequence of length is a sequence obtained by removing zero or more elements from . The order of the remaining elements must be the same as in .
A subsequence is nondecreasing if every element is greater than or equal to the preceding element. Let be the length of a longest nondecreasing subsequence of .
You are given a sequence of length . For , define
You are also given queries. For each query , compute
The input is given from Standard Input in the following format:
For each test case, print lines. The -th line must contain the answer to the -th query.
The first query of the first test case contains six contiguous subarrays. Their values of are , whose sum is .
The sequence in the second test case is nondecreasing. For its first query, the sum of the lengths of all contiguous subarrays is .
Each case is given in the following format:
| 2 | 24 | (). |
| 3 | 25 |
|
| 4 | 40 | No additional constraints. |