#K41307. Minimum Candies Distribution

    ID: 26836 Type: Default 1000ms 256MiB

Minimum Candies Distribution

Minimum Candies Distribution

You are given n children standing in a line, each with a performance score. The task is to distribute candies to these children with the following rules:

  • Every child must receive at least one candy.
  • If a child has a higher score than an immediate neighbor, then they must receive more candies than that neighbor.

Your goal is to determine the minimum number of candies you must distribute to satisfy these conditions.

The relation for candy distribution can be summarized by the following constraints in LaTeX format:

\( candy[i] \geq 1 \) for all \( i \), and if \( scores[i] > scores[i-1] \), then \( candy[i] = candy[i-1] + 1 \); similarly, if \( scores[i] > scores[i+1] \), then \( candy[i] = max(candy[i], candy[i+1] + 1) \).

The input will be provided via stdin and the output must be printed via stdout.

inputFormat

The first line contains an integer \( n \) representing the number of children.

The second line contains \( n \) space-separated integers representing the performance scores of each child.

outputFormat

Output a single integer which is the minimum number of candies required.

## sample
1
5
1

</p>