Cossack Vus and the Field of Wonders
Cossack Vus recently discovered a fascinating place called the Field of Wonders, where trees that grow coins can be found. He decided to plant coin trees and planned to harvest them the following year.
Upon returning to the Field of Wonders for an inspection, Vus found that each tree had grown at least one coin, with the -th tree having coins. Realizing that harvesting the coins manually would be too time-consuming, he constructed a machine capable of performing the following operation multiple times:
Select a positive integer ;
Identify the first tree (the one with the smallest index) that currently has at least coins;
Remove coins from that tree.
According to the coin tree care manual, after harvesting, each tree must retain at least one coin to ensure it produces coins the following year.
Cossack Vus wants to know the maximum number of coins the machine can collect through a series of operations, while ensuring that each tree is left with at least one coin.
Note that the value of can vary with each operation.
Input
The first line contains a single integer () — the number of trees in the Field of Wonders.
The second line contains integers () — the initial number of coins on each tree.
Output
Output a single integer — the maximum number of coins the machine can collect after performing a sequence of operations, ensuring that at least one coin remains on each tree.
Examples
Note
In the second example, it is impossible to choose a that allows for the collection of at least one coin while leaving coins on each tree.
Scoring
( points): ;
( points): ;
( points): ;
( points): ;
( points): ;
( points): ;
( points): no additional constraints.