PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000216. Người lính và phù hiệu (Soldier and Badges)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Người lính và phù hiệu (Soldier and Badges)

Soldier and Badges

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn soldiers, each with a badge whose initial coolness factor is aia_i. Spending one coin increases the factor of any badge by exactly 11. All final coolness factors must be pairwise distinct. You cannot decrease a factor or exchange badges between soldiers. Calculate the minimum total number of coins required.

Input

  • Line 1 contains nn, the number of soldiers.
  • Line 2 contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, the initial coolness factors of their badges.

Output

Print one integer: the minimum number of coins that must be spent.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤ai≤n1\le a_i\le n for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤3001\le n\le 300; 1≤ai≤n1\le a_i\le n for all 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤30001\le n\le 3000; 1≤ai≤n1\le a_i\le n for all 1≤i≤n1\le i\le n.

Examples

Input

5
1 2 3 2 5

Output

2

Explanation

Initial values are 1,2,3,2,51,2,3,2,5, so two badges have factor 22. Keep one at 22 and increase the other to 44, at a cost of two coins, giving distinct factors 1,2,3,4,51,2,3,4,5. Spending only one coin would turn the duplicate 22 into another duplicate at 33. Thus the answer is 22.