Language: C++

#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n/2]={0};
  int b[n/2]={0};
  int j=0,k=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      cin >> a[j];
      j++;
    }else{
      cin >> b[k];
      k++;
    }
  }
  sort(a,a+(n/2));
  sort(b,b+(n/2));
  /*for(int i=0;i<n/2;i++){
    cout << a[i] << endl;
  }*/
  int na,nb;
  int s=0;
  int cnt=0;
  int a1=0,b1=0,a2=0,b2=0;
  for(int i=0;i<n/2;i++){
    if(s!=a[i]){
      if(cnt>=a1){
          a2=a1;
        }
        a1=cnt;
        na=s;
      }else if(cnt>=a2){
        a2=cnt;
      }else{
        s=a[i];
      }
      s=a[i];
      cnt=1;
    }else{
      cnt++;
    }
  }
  cnt=0;
  s=0;
  for(int i=0;i<n/2;i++){
    if(s!=b[i]){
      if(cnt>=b1){
          b2=b1;
        }
        b1=cnt;
        nb=s;
      }else if(cnt>=b2){
        b2=cnt;
      }else{
        s=b[i];
      }
      s=b[i];
      cnt=1;
    }else{
      cnt++;
    }
  }

  ll cost=0;
  if(na!=nb){
    cost=n-a1-b1;
    cout << cost << endl;
    return 0;
  }else{
    if(a1>=b1){
      cost=n-a1-b2;
    }else{
      cost=n-b1-a2;
    }
  }
  cout << cost << endl;
  /*cout << a1 << b1 << a2 << b2 <<endl;*/
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:6: error: 'else' without a previous 'if'
   74 |     }else{
      |      ^~~~
a.cc: At global scope:
a.cc:78:3: error: 'cnt' does not name a type; did you mean 'int'?
   78 |   cnt=0;
      |   ^~~
      |   int
a.cc:79:3: error: 's' does not name a type
   79 |   s=0;
      |   ^
a.cc:80:3: error: expected unqualified-id before 'for'
   80 |   for(int i=0;i<n/2;i++){
      |   ^~~
a.cc:80:15: error: 'i' does not name a type
   80 |   for(int i=0;i<n/2;i++){
      |               ^
a.cc:80:21: error: 'i' does not name a type
   80 |   for(int i=0;i<n/2;i++){
      |                     ^
a.cc:94:6: error: expected unqualified-id before 'else'
   94 |     }else{
      |      ^~~~
a.cc:97:3: error: expected declaration before '}' token
   97 |   }
      |   ^
a.cc:100:3: error: expected unqualified-id before 'if'
  100 |   if(na!=nb){
      |   ^~
a.cc:104:4: error: expected unqualified-id before 'else'
  104 |   }else{
      |    ^~~~
a.cc:111:3: error: 'cout' does not name a type
  111 |   cout << cost << endl;
      |   ^~~~
a.cc:113:3: error: expected unqualified-id before 'return'
  113 |   return 0;
      |   ^~~~~~
a.cc:114:1: error: expected declaration before '}' token
  114 | }
      | ^