Codeforces Round 312 (Div. 2)
C
Amr and Chemistry
Codeforces
1900
原题
← BD →
翻译中…

Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.

翻译中…

Amr has $*n*$ different types of chemicals. Each chemical $*i*$ has an initial volume of $*a*_{*i*}$ liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his task is to make all the chemicals volumes equal.

翻译中…

To do this, Amr can do two different kind of operations.

翻译中…
  • Choose some chemical $*i*$ and double its current volume so the new volume will be $2*a*_{*i*}$
  • Choose some chemical $*i*$ and divide its volume by two (integer division) so the new volume will be image
翻译中…

Suppose that each chemical is contained in a vessel of infinite volume. Now Amr wonders what is the minimum number of operations required to make all the chemicals volumes equal?

翻译中…

Input

翻译中…

The first line contains one number $*n*$ ($1 ≤ *n* ≤ 10^{5}$), the number of chemicals.

翻译中…

The second line contains $*n*$ space separated integers $*a*_{*i*}$ ($1 ≤ *a*_{*i*} ≤ 10^{5}$), representing the initial volume of the $*i*$-th chemical in liters.

翻译中…

Output

翻译中…

Output one integer the minimum number of operations required to make all the chemicals volumes equal.

翻译中…

Note

翻译中…

In the first sample test, the optimal solution is to divide the second chemical volume by two, and multiply the third chemical volume by two to make all the volumes equal $4$.

翻译中…

In the second sample test, the optimal solution is to divide the first chemical volume by two, and divide the second and the third chemical volumes by two twice to make all the volumes equal $1$.

翻译中…

样例

Input #1
3
4 8 2
Output #1
2
InputCopy OutputCopy
Input #2
3
3 5 6
Output #2
5
InputCopy OutputCopy
题目信息
题号
558C
时间限制
1 s
内存限制
256 MB
标签
暴力
图论
贪心
数学
最短路

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