546B.md (1433B)
1 Source: https://codeforces.com/problemset/problem/546/B 2 3 B. Soldier and Badges 4 5 time limit per test 6 7 3 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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. 22 23 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. 24 25 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. 26 27 Input 28 29 First line of input consists of one integer *n* (1 ≤ *n* ≤ 3000). 30 31 Next line consists of *n* integers *a**i* (1 ≤ *a**i* ≤ *n*), which stand for coolness factor of each badge. 32 33 Output 34 35 Output single integer — minimum amount of coins the colonel has to pay. 36 37 Examples 38 39 Input 40 41 ``` 42 4 43 1 3 1 4 44 ``` 45 46 Output 47 48 ``` 49 1 50 ``` 51 52 Input 53 54 ``` 55 5 56 1 2 3 2 5 57 ``` 58 59 Output 60 61 ``` 62 2 63 ``` 64 65 Note 66 67 In first sample test we can increase factor of first badge by 1. 68 69 In second sample test we can increase factors of the second and the third badge by 1.