Given an array of natural numbers, indexed from . We define the minimum number of operations of incrementing any element from the subarray to transform the subarray into a monotonically increasing subarray (not necessarily strictly increasing).
Task
Find , modulo .
Input data
The first line will contain the nonzero natural number , representing the size of the array.
The second line will contain natural numbers, separated by a single space, representing the elements of the array.
Output data
The first line will contain a single natural number, representing the required answer, modulo .
Constraints and clarifications
- ;
- ;
- Due to the very large input set, it is recommended to use fastio.
- For tests worth points: ;
- For other tests worth points: ;
- For other tests worth points: ;
- For other tests worth points: , it is guaranteed that the input data is generated randomly;
- For other tests worth points: ;
- For other tests worth points: no additional restrictions.
Example 1
stdin
3
10 5 1
stdout
23
Explanation
(we do not increment anything)
(we increment five times)
(we increment five times and nine times)
(we do not increment anything)
(we increment four times)
(we do not increment anything)
Example 2
stdin
4
1 1 3 4
stdout
0
Explanation
The entire array is already monotonically increasing, therefore all of its subarrays are already monotonically increasing.
Example 3
stdin
10
45 32 12 60 12 50 70 95 10 100
stdout
3253