Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define DIM 100007
#define INF 10000000007
#define X 10000
#define epc 0.0000000000000000000001
#define pi 3.14159265358979323846
#define MAX 25
#define MODULO 1000000007

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef set<I> sI;
typedef set<ll> sll;
typedef set<pllll> spllll;

typedef stack<I> stI;
typedef stack<ll> stll;

typedef char cr;
typedef string str;

typedef queue<I> qI;
typedef queue<ll> qll;
typedef queue<pllll> qpllll;
typedef priority_queue<ll> pqllmin;
typedef priority_queue<pllll,vector<pllll>,greater<pllll> > pqpllllmax;

typedef tree<
I,
null_type,
greater<I>,
rb_tree_tag,
tree_order_statistics_node_update> mset;

ll n,a,res,maxc1,maxc3,sumc1,maxc2,maxc4,sumc2,p1,p2,p3,p4;
map<ll,ll> m1,m2;

struct num
{
    I d[DIM],l;

    num()
    {
    };

    num(ll x)
    {
        if(x==0)
        {
            l=1;
            d[0]=0;
        }
        else
        {
            l=0;
            while(x>0)
            {
                d[l++]=x%10;
                x/=10;
            }
        }
    }

    void read()
    {
        memset(d,0,sizeof(d));
        str s;
        cin>>s;
        l=s.size();
        for(int i=0; i<l; i++)d[l-i-1]=s[i]-'0';
    }

    void print()
    {
        for(int i=(l-1); i>=0; i--)cout<<d[i];
        cout<<endl;
    }
};

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //cout<<"ops"<<endl;

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a;
        if(i%2==1)m1[a]++;
        else m2[a]++;
    }

    maxc1=0;
    maxc3=0;
    sumc1=0;
    for(auto p:m1)
    {
        sumc1+=p.second;
        if(maxc1<p.second)
        {
            if(maxc3<maxc1){
             maxc3=maxc1;
             p2=p1;
            }
            maxc1=p.second;
            p1=p.first;
        }
        else if(maxc3<p.second){
         maxc3=p.second;
         p2=p.first;
        }
    }

    maxc2=0;
    maxc4=0;
    sumc2=0;
    for(auto p:m2)
    {
        sumc2+=p.second;
        if(maxc2<p.second)
        {
            if(max4<maxc2){
             maxc4=maxc2;
             p4=p3;
            }
            maxc2=p.second;
            p3=p.first;
        }
        else if(maxc4<p.second){
         maxc4=p.second;
         p4=p.first;
        }
    }

    //cout<<p1<<' '<<p2<<' '<<p3<<' '<<p4<<endl;

    if(p1==p3)
    {
        if(m1[p1]>=m2[p3])
        {
            if(p4==0)
            {
                if(p2==0)
                {
                    cout<<n/2<<endl;
                    return 0;
                }
                cout<<sumc1-m1[p2]+sumc2-m2[p3]<<endl;
            }
            cout<<sumc1-m1[p1]+sumc2-m2[p4]<<endl;
            return 0;
        }
        else
        {
            if(p2==0)
            {
                if(p4==0)
                {
                    cout<<n/2<<endl;
                    return 0;
                }
                cout<<sumc1-m1[p1]+sumc2-m2[p4]<<endl;
            }
            cout<<sumc1-m1[p2]+sumc2-m2[p3]<<endl;
            return 0;
        }
    }
    cout<<sumc1-m1[p1]+sumc2-m2[p3]<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:143:16: error: 'max4' was not declared in this scope; did you mean 'maxc4'?
  143 |             if(max4<maxc2){
      |                ^~~~
      |                maxc4