1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
| #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int d[100005];
bool used[100005];
int cnt[100005];
int main() {
int n;
cin >> n;
vector<int> v(n);
rep(i,n) cin >> v[i];
rep(i,100005) d[i] = INF;
memset(cnt,0,sizeof(cnt));
rep(i,n) {
memset(used,0,sizeof(used));
used[v[i]] = true;
if(d[v[i]] == INF) d[v[i]] = 0;
cnt[v[i]]++;
queue<pair<int,int> > que;
que.push(mp(v[i],0));
while(que.size()) {
pair<int,int> p = que.front();
que.pop();
int f = p.first;
int cost = p.second;
int t = f/2;
int t2 = f*2;
if(0 < t && t < 100005 && !used[t]) {
used[t] = true;
cnt[t]++;
if(d[t] == INF) d[t] = cost+1;
else d[t] += cost+1;
que.push(make_pair(t,cost+1));
}
if(0 < t2 && t2 < 100005 && !used[t2]) {
used[t2] = true;
cnt[t2]++;
if(d[t2] == INF) d[t2] = cost+1;
else d[t2] += cost+1;
que.push(make_pair(t2,cost+1));
}
}
}
int ans = INF;
rep(i,100005) {
if(cnt[i] == n) ans = min(ans,d[i]);
}
cout << ans << endl;
return 0;
}
|