#P1693D. Decinc Dividing
Decinc Dividing
Description
Let's call an array of integers Decinc if can be made increasing by removing a decreasing subsequence (possibly empty) from it.
- For example, if , we can remove the decreasing subsequence from and obtain , which is increasing.
You are given a permutation of numbers from to . Find the number of pairs of integers with such that (the subarray of from to ) is a Decinc array.
The first line contains a single integer () — the size of .
The second line contains integers (, all are distinct) — elements of the permutation.
Output the number of pairs of integers such that (the subarray of from to ) is a Decinc array.
Input
The first line contains a single integer () — the size of .
The second line contains integers (, all are distinct) — elements of the permutation.
Output
Output the number of pairs of integers such that (the subarray of from to ) is a Decinc array.
Note
In the first sample, all subarrays are Decinc.
In the second sample, all subarrays except and are Decinc.