#include #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; const int INF = 1e9; const ll LINF = 1e18; template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template vector make_vec(size_t a) { return vector(a); } template auto make_vec(size_t a, Ts... ts) { return vector(ts...))>(a, make_vec(ts...)); } template istream& operator>>(istream& is, vector& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template ostream& operator<<(ostream& os, const vector& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < int(v.size()) - 1) os << ' '; } return os; } int main() { int n; cin >> n; vector cnt(200200); rep(i, n) { int a; cin >> a; cnt[a]++; } int ok = 0, ng = n, mid; while (ng - ok > 1) { // 0以上mid未満を2枚ずつ揃えられるか mid = (ok + ng) / 2; int x = 0, y = 0; rep(i, 200200) { if (i < mid) { if (cnt[i] < 2) x += 2 - cnt[i]; if (cnt[i] > 2) y += cnt[i] - 2; } else { y += cnt[i]; } } (x <= 1 && y >= x ? ok : ng) = mid; } cout << ok << '\n'; }