Under construction

Still being built. Things may change

HearthStone

Time limit1sMemory limit2048 MB

Summary
Given n minion health values, find the fewest unit changes so that one Defile cast chains into killing every minion.
Level

Medium7 of 10

Topics
Sorting, Dynamic programming, Greedy
Solved
No attempts yet

Problem

Alice loves playing HearthStone. She likes the Warlock hero class, which can cast the spell Defile. When cast, Defile deals 11 unit of damage to the health of all minions. If any minion dies, Defile is cast again automatically. If two or more minions die at the same time, Defile is still cast only once. That cast may kill other minions, which causes Defile to be cast again, and so on. The health of each minion is a nonnegative integer. A minion dies when its health becomes zero. When a minion dies, it disappears and does not die twice. There are nn minions. Before casting Defile, Alice can take zero or more steps. In each step, Alice changes the health of one minion by one. If a minion has health xx, Alice can change it to x−1x-1 or x+1x+1. Alice wants to find the minimum number of steps needed so that she can cast Defile once and kill all the minions.

Input

The first line contains a single integer nn (1≤n≤1061 \leq n \leq 10^6). The next line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1061 \leq a_i \leq 10^6), the health of the nn minions.

Output

Print one integer: the minimum number of steps before Alice can cast a single Defile to kill all the minions.

Examples1

  1. Example 1

    Input
    6
    4 6 8 9 2 4
    
    Expected output
    12