#K91517. Minimum Bonus Distribution

    ID: 37993 Type: Default 1000ms 256MiB

Minimum Bonus Distribution

Minimum Bonus Distribution

You are given n employees standing in a line, each with a performance rating. Your task is to determine the minimum total number of bonus units that must be distributed to the employees under the following rules:

  • Each employee must receive at least 1 unit.
  • If an employee has a higher rating than their immediate neighbor, they must receive more bonus units than that neighbor. In other words, if ratings[i] > ratings[i-1] then bonus[i] > bonus[i-1], and similarly for the right neighbor.

This condition can be mathematically expressed as: \(\text{if } ratings[i] > ratings[i-1], \text{ then } bonus[i] = bonus[i-1] + 1\).

Your goal is to compute the minimum sum of bonuses required to satisfy these conditions.

inputFormat

The input is provided via standard input (stdin) and has the following format:

n
r1 r2 ... rn

Here, n is the number of employees, and ri represents the rating of the i-th employee.

outputFormat

Output a single integer to standard output (stdout) representing the minimum number of bonus units required.

## sample
4
1 2 2 1
6