Distribution
Limits: 1 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Zenyk is the commander of an assault company. The company leadership has tasked him with eliminating the Russian military leadership. However, before proceeding with the mission, it is necessary to arm well. There are \(n\) platoons in Zenyk’s brigade, with the \(i\)-th platoon having \(a_i\) people. Zenyk needs to distribute ammunition to each platoon. The more people in a platoon, the more rounds they need. Ammunition is a very important thing in war, and therefore it must be saved. Thus, Zenyk will distribute the boxes of ammunition as follows:
each platoon will receive at least 1 box of ammunition,
if two platoons have the same number of people, they will receive the same number of boxes of ammunition,
if platoon \(x\) has a larger headcount than platoon \(y\), it will receive a larger number of boxes of ammunition,
among all ways to distribute the boxes of ammunition, Zenyk will choose the one where the total number of distributed boxes is minimized.
Help Zenyk, tell him how many boxes of ammunition will be needed to arm the company?
Input
The first line contains a single integer \(n\) — the number of platoons in Zenyk’s company.
The second line contains \(n\) integers \(a_i\) — the headcount of the \(i\)-th platoon.
Output
In a single line, output one integer — the minimum number of boxes needed to arm the company.
Constraints
\(1 \le n \le 10^{5}\),
\(1 \le a_i \le 10^{9}\),
In at least 7 tests, \(1 \le n \le 10^{3}\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 5 1 2 1 3 3 | 10 |
Notes
In the example, it is optimal to give 1 box of ammunition to the first and third platoons, 2 boxes to the second, and 3 boxes each to the fourth and fifth. Thus, Zenyk needs a total of 10 boxes.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|