cswork / OAOpen practice workspace

The D. E. Shaw GroupOA #3

Count the Number of Incremovable Subarrays II

Estimated HardJudge-ready

Topics (AI-labelled)Two PointersBinary Search

Given an array of positive integers, removing one non-empty contiguous subarray is a valid removal if the remaining array (which may be empty) is strictly increasing. Count all valid removals.

The standard input/output, the ranges added by this site, and the examples follow this problem's description.

Input

The first line contains n (1≤n≤100000); the second line contains n positive integers, 1≤nums[i]≤10^9. The ranges are taken from the original problem's constraints.

Output

Output the number of valid contiguous subarrays, stored as a 64-bit integer.

Example 1

Input:

4
1 2 3 4

Output:

10

Example 2

Input:

4
6 5 7 8

Output:

7

Example 3

Input:

4
8 7 6 6

Output:

3

Editorial

Loading solution…