#K42567. Minimum Operations to Make Sequence Strictly Increasing

    ID: 27116 Type: Default 1000ms 256MiB

Minimum Operations to Make Sequence Strictly Increasing

Minimum Operations to Make Sequence Strictly Increasing

You are given a sequence of n non-negative integers. In one operation, you can increment any element of the sequence by 1. The goal is to transform the sequence into a strictly increasing sequence with the minimum number of operations.

A sequence a1, a2, ..., an is strictly increasing if a1 < a2 < ... < an.

Formally, you need to find the minimum total number of increments needed so that for every i (2 ≤ in), the condition ai > ai-1 holds.

The relation between increments and the condition can be mathematically expressed as follows. For each index i (2 ≤ in), if the current value ai is not strictly greater than ai-1, you need to perform:

[ \text{increments} = a_{i-1} - a_i + 1 ]

Update the value of ai to ai-1 + 1 after performing the increments. Your task is to compute the sum of all such required increments.

inputFormat

The first line of input contains an integer n (1 ≤ n ≤ 105), representing the number of elements in the sequence.

The second line contains n space-separated non-negative integers representing the sequence.

outputFormat

Output a single integer, the minimum number of operations required to make the sequence strictly increasing.

## sample
4
1 2 2 4
1

</p>