Time limit
2s
Memory limit
256 MB
N students participate in a programming contest. Before the contest, each student submits the rank they expect to receive among all N students.
The final ranks must be assigned without ties, using each rank from 1 through N exactly once. If a student expected rank A but receives actual rank B, that student's dissatisfaction is |A - B|.
Given every student's expected rank, assign the final ranks so that the total dissatisfaction is as small as possible, and output that minimum total.
The first line contains a natural number N. (1 <= N <= 500,000)
Each of the next N lines contains one student's expected rank. Every expected rank is a natural number no greater than 500,000.
Print the minimum possible total dissatisfaction.