Language: C++

    cin.tie();
    ios::sync_with_stdio(false);

    // input
    int N;
    cin >> N;
    vector<int> vec(N), even, odd;
    REP(i, N) cin >> vec.at(i);
    
    REP(i, N) {
        if (i%2 == 0) {
            even.push_back(vec.at(i));
        } else {
            odd.push_back(vec.at(i));
        }
    }
    sort(ALL(even));
    sort(ALL(odd));
    // calculation
    vector<int> copy_even, copy_odd;
    COPY(even, copy_even);
    COPY(odd, copy_odd);
    sort(ALL(copy_even));
    sort(ALL(copy_odd));
    UNIQUE(copy_even);
    UNIQUE(copy_odd);
    // process
    // even
    int even_idx = 0;
    int unique_even_idx = 0;
    vector<int> count_even(copy_even.size());
    while (unique_even_idx < copy_even.size()) {
        int begin = copy_even.at(unique_even_idx);
        while (even.at(even_idx) == begin) {
            count_even.at(unique_even_idx) += 1;
            even_idx++;
            if (even_idx == N/2) break;
        }
        unique_even_idx++;
    }
    
    int odd_idx = 0;
    int unique_odd_idx = 0;
    vector<int> count_odd(copy_odd.size());
    while (unique_odd_idx < copy_odd.size()) {
        int begin = copy_odd.at(unique_odd_idx);
        while (odd.at(odd_idx) == begin) {
            count_odd.at(unique_odd_idx) += 1;
            odd_idx++;
            if (odd_idx == N/2) break;
        }
        unique_odd_idx++;
        
    }
    
    sort(ALL(vec));
    UNIQUE(vec);
    vector<int>::iterator even_iter = MAX(count_even), odd_iter = MAX(count_odd);
    int idx_even = IDX(count_even, even_iter), idx_odd = IDX(count_odd, odd_iter);
    int max_even = copy_even.at(idx_even), max_odd = copy_odd.at(idx_odd);
    int even_count_max = *even_iter, odd_count_max = *odd_iter;
    if (vec.size() == 1) {
        cout << N/2 << "\n";
    } else if (max_even == max_odd) {
        sort(ALL(count_even));
        sort(ALL(count_odd));
        UNIQUE(count_even);
        UNIQUE(count_odd);
        int rather = max(count_even.at(count_even.size() - 2), count_odd.at(count_odd.size() - 2));
        if (count_even.at(count_even.size() - 2) == rather) {
            cout << (even.size() - rather) + (odd.size() - odd_count_max) << "\n";
        } else {
            cout << (even.size() - even_count_max) + (odd.size() - rather) << "\n";
        }
    } else {
        cout << (even.size() - *MAX(count_even)) + (odd.size() - *MAX(count_odd)) << "\n";
    }
    
    
    return 0;


Compiler output:
a.cc:1:5: error: 'cin' does not name a type
    1 |     cin.tie();
      |     ^~~
a.cc:2:5: error: 'ios' does not name a type
    2 |     ios::sync_with_stdio(false);
      |     ^~~
a.cc:6:5: error: 'cin' does not name a type
    6 |     cin >> N;
      |     ^~~
a.cc:7:5: error: 'vector' does not name a type
    7 |     vector<int> vec(N), even, odd;
      |     ^~~~~~
a.cc:8:8: error: expected constructor, destructor, or type conversion before '(' token
    8 |     REP(i, N) cin >> vec.at(i);
      |        ^
a.cc:10:8: error: expected constructor, destructor, or type conversion before '(' token
   10 |     REP(i, N) {
      |        ^
a.cc:17:9: error: expected constructor, destructor, or type conversion before '(' token
   17 |     sort(ALL(even));
      |         ^
a.cc:18:9: error: expected constructor, destructor, or type conversion before '(' token
   18 |     sort(ALL(odd));
      |         ^
a.cc:20:5: error: 'vector' does not name a type
   20 |     vector<int> copy_even, copy_odd;
      |     ^~~~~~
a.cc:21:9: error: expected constructor, destructor, or type conversion before '(' token
   21 |     COPY(even, copy_even);
      |         ^
a.cc:22:9: error: expected constructor, destructor, or type conversion before '(' token
   22 |     COPY(odd, copy_odd);
      |         ^
a.cc:23:9: error: expected constructor, destructor, or type conversion before '(' token
   23 |     sort(ALL(copy_even));
      |         ^
a.cc:24:9: error: expected constructor, destructor, or type conversion before '(' token
   24 |     sort(ALL(copy_odd));
      |         ^
a.cc:25:11: error: expected constructor, destructor, or type conversion before '(' token
   25 |     UNIQUE(copy_even);
      |           ^
a.cc:26:11: error: expected constructor, destructor, or type conversion before '(' token
   26 |     UNIQUE(copy_odd);
      |           ^
a.cc:31:5: error: 'vector' does not name a type
   31 |     vector<int> count_even(copy_even.size());
      |     ^~~~~~
a.cc:32:5: error: expected unqualified-id before 'while'
   32 |     while (unique_even_idx < copy_even.size()) {
      |     ^~~~~
a.cc:44:5: error: 'vector' does not name a type
   44 |     vector<int> count_odd(copy_odd.size());
      |     ^~~~~~
a.cc:45:5: error: expected unqualified-id before 'while'
   45 |     while (unique_odd_idx < copy_odd.size()) {
      |     ^~~~~
a.cc:56:9: error: expected constructor, destructor, or type conversion before '(' token
   56 |     sort(ALL(vec));
      |         ^
a.cc:57:11: error: expected constructor, destructor, or type conversion before '(' token
   57 |     UNIQUE(vec);
      |           ^
a.cc:58:5: error: 'vector' does not name a type
   58 |     vector<int>::iterator even_iter = MAX(count_even), odd_iter = MAX(count_odd);
      |     ^~~~~~
a.cc:59:24: error: 'count_even' was not declared in this scope
   59 |     int idx_even = IDX(count_even, even_iter), idx_odd = IDX(count_odd, odd_iter);
      |                        ^~~~~~~~~~
a.cc:59:36: error: 'even_iter' was not declared in this scope; did you mean 'even_idx'?
   59 |     int idx_even = IDX(count_even, even_iter), idx_odd = IDX(count_odd, odd_iter);
      |                                    ^~~~~~~~~
      |                                    even_idx
a.cc:59:20: error: 'IDX' was not declared in this scope
   59 |     int idx_even = IDX(count_even, even_iter), idx_odd = IDX(count_odd, odd_iter);
      |                    ^~~
a.cc:60:20: error: 'copy_even' was not declared in this scope
   60 |     int max_even = copy_even.at(idx_even), max_odd = copy_odd.at(idx_odd);
      |                    ^~~~~~~~~
a.cc:61:27: error: 'even_iter' was not declared in this scope; did you mean 'even_idx'?
   61 |     int even_count_max = *even_iter, odd_count_max = *odd_iter;
      |                           ^~~~~~~~~
      |                           even_idx
a.cc:62:5: error: expected unqualified-id before 'if'
   62 |     if (vec.size() == 1) {
      |     ^~
a.cc:64:7: error: expected unqualified-id before 'else'
   64 |     } else if (max_even == max_odd) {
      |       ^~~~
a.cc:75:7: error: expected unqualified-id before 'else'
   75 |     } else {
      |       ^~~~
a.cc:80:5: error: expected unqualified-id before 'return'
   80 |     return 0;
      |     ^~~~~~