Codeforces Round 304 (Div. 2)
B
Soldier and Badges
Codeforces
1200
原题
← AC →
翻译中…

Colonel has $*n*$ badges. He wants to give one badge to every of his $*n*$ soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.

翻译中…

For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors.

翻译中…

Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.

翻译中…

Input

翻译中…

First line of input consists of one integer $*n*$ ($1 ≤ *n* ≤ 3000$).

翻译中…

Next line consists of $*n*$ integers $*a*_{*i*}$ ($1 ≤ *a*_{*i*} ≤ *n*$), which stand for coolness factor of each badge.

翻译中…

Output

翻译中…

Output single integer — minimum amount of coins the colonel has to pay.

翻译中…

Note

翻译中…

In first sample test we can increase factor of first badge by $1$.

翻译中…

In second sample test we can increase factors of the second and the third badge by $1$.

翻译中…

样例

Input #1
4
1 3 1 4
Output #1
1
InputCopy OutputCopy
Input #2
5
1 2 3 2 5
Output #2
2
InputCopy OutputCopy
题目信息
题号
546B
时间限制
3 s
内存限制
256 MB
标签
暴力
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。