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
Input
The input is given from Standard Input in the following format:
Each case is given in the following format:
Output
For each test case, print lines. The -th line must contain the answer to the -th query.
Constraints
- .
- .
- .
- ().
- ().
- The sum of over all test cases does not exceed .
- The sum of over all test cases does not exceed .
- All values in the input are integers.
Subtasks
Samples
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 .