LearnPy Hub
← Arena
AdvancedRating 1700

Candies by Rating

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

Input

n, then n ratings.

Output

A number.

Sample 1

Input
3
1 0 2
Output
5

Sample 2

Input
3
1 2 2
Output
4
solution.py
Output appears here
Candies by Rating · Python Arena problem · LearnPy Hub