LogiQuest

274. Candy Distribution

HardGreedyTwo Passes

Children stand in a line with ratings. Each child gets at least one candy, and a child with a higher rating than a neighbour gets more candies than that neighbour. Print the minimum total candies.

Input format

Line 1: n Line 2: n ratings

Output format

The minimum total.

Example 1

Input

3
1 0 2

Output

5

Example 2

Input

3
1 2 2

Output

4

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.

Loading the MyLoginn IDE…