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
82
83
84
85
86
87
88
89
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
//#pragma GCC optimize ("trapv")

using namespace std;

//#define local
#ifdef local
    #include "debug.h"
    #define pr(...) debug(#__VA_ARGS__, __VA_ARGS__)
    #define prs(...) debug_nameless(__VA_ARGS__)
#else
    #define pr(...) 69
    #define prs(...) 69
#endif

#define pb push_back
#define endl '\n'

typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;

const int inf = 1e9;
const ll binf = 1e18;
const dbl eps = 1e-9;

void setIO(string s = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(s.size() > 0){
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
}

void solve(int tc){
    int n;
    cin >> n;

    vector <int> freq(n+1, 0);
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        freq[tmp] += 1;
    }

    sort(freq.begin(), freq.end());
    int ans = 0;
    for(int l = 1, r = n; l <= r; ){
        if(freq[r] == 0){
            r -= 1;
            continue;
        }
        if(freq[l] == 0){
            l += 1;
            continue;
        }
        if(l == r){
            ans += 1;
            break;
        }

        int delta = min(freq[r]-1, freq[l]);
        freq[r] -= delta;
        freq[l] -= delta;

        l += (freq[l] == 0);
        ans += (freq[r] == 1);
        r -= (freq[r] == 1);
    }

    cout << ans << endl;
}   

int main(){
    setIO();

    int tc = -1;
    tc = 1;
    if(tc != 1) cin >> tc;
    
    for (int t = 0; t < tc; t++) {
        pr(t); prs(string(50, '-'));
        solve(t);
        prs(string(50, '-') + "\n");
    }

    return 0;
}