#### Codeforces Round #318 (Div. 2)

`这次也是后来补的，只做了前三道题，ACM练到这个时候，应该多专门做做第3、4题了`

### A. Bear and Elections

```#include <bits/stdc++.h>
using namespace std;

int main() {
int n, cur; scanf("%d%d", &n, &cur);
priority_queue<int> qu;
for(int i = 1; i < n; ++i) {
int x; scanf("%d", &x);
qu.push(x);
}
int cnt = 0;
while(!qu.empty() && qu.top() >= cur) {
int t = qu.top(); qu.pop();
++cur, ++cnt;
qu.push(t - 1);
}
printf("%d\n", cnt);
return 0;
}
```

#### B. Bear and Three Musketeers

```#include <bits/stdc++.h>
using namespace std;

const int maxn = 4096, inf = 0x3f3f3f3f;
int n, m;
vector<int> G[maxn];

int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) {
int x, y; scanf("%d%d", &x, &y);
G[x].push_back(y);
G[y].push_back(x);
}
int best = inf;
for(int i = 1; i <= n; ++i) {
if(G[i].size() <= 1) continue;
for(int j = 0; j < G[i].size(); ++j) {
for(int k = j + 1; k < G[i].size(); ++k) {
int a = G[i][j], b = G[i][k];
if(find(G[a].begin(), G[a].end(), b) != G[a].end()) {
int cur = G[i].size()-2 + G[a].size()-2 + G[b].size()-2;
best = min(best, cur);
}
}
}
}
if(best >= inf) puts("-1");
else printf("%d\n", best);
return 0;
}
```

#### C. Bear and Poker

```#include <bits/stdc++.h>
using namespace std;

int main() {
int n; cin >> n;
set<int> s;
while(n--) {
int x; cin >> x;
while(x % 2 == 0) x /= 2;
while(x % 3 == 0) x /= 3;
s.insert(x);
}
if(s.size() == 1) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
```