Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) SORT(x),(x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define clr(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))

#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

template<class T> inline T gcd(T a,T b) //NOTE:__gcd(0,0) gives exception
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

/*bool sortby(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
    return (a.second < b.second);
}*/

const int MAX_N = 123456;

int arr[MAX_N];
int a[MAX_N];

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",arr+i);
    for(int i=0;i<n;i++) a[i+1]=arr[i];
    a[0]=arr[n-1];

    map<int,int> M;
    int ans=0,mx=0;
    for(int i=0;i<n;i+=2){
        M[arr[i]]++;
        ans++;
    }
    int tp;
    map<int,int>::iterator it;
    for(it=M.begin();it!=M.end();it++){
        mx = max(it->S,mx);
        if(it->S==mx){
            tp = it->F;
        }
    }
    ans-=mx;
    int res=ans;
    M.clear();
    for(int i=1;i<n;i+=2){
        if(arr[i]==tp){
            arr[i]=-1;
            ans++;
        }
    }
    int cnt=0,m=0;
    for(int i=1;i<n;i+=2){
        cnt++;
        M[arr[i]]++;
    }
    mx=0;
    for(it=M.begin();it!=M.end();it++){
        if(it->F!=-1)
            m=max(it->S,m);
        mx = max(it->S,mx);
    }
    //trace3(ans,cnt,mx);
    ans+=cnt-mx;
    res+=cnt-m;
    ans=min(res,ans);


    int ans1=0,mx1=0;
    M.clear();
    for(int i=0;i<n;i+=2){
        M[a[i]]++;
        ans1++;
    }
    int t;
    for(it=M.begin();it!=M.end();it++){
        mx1 = max(it->S,mx1);
        if(it->S==mx1){
            t = it->F;
        }
    }
    ans1-=mx1;
    res = ans1;
    M.clear();
    for(int i=1;i<n;i+=2){
        if(a[i]==t){
            a[i]=-1;
            ans1++;
        }
    }
    int cnt1=0;
    for(int i=1;i<n;i+=2){
        cnt1++;
        M[a[i]]++;
    }
    mx1=0;
    for(it=M.begin();it!=M.end();it++){
        if(it->F!=-1)
            m=max(it->S,m);
        mx1 = max(it->S,mx1);
    }
    //trace3(ans,cnt,mx);
    ans1+=cnt1-mx1;
    res+=cn1-m;
    ans1=min(res,ans1);

    printf("%d\n",min(ans,ans1));
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:148:10: error: 'cn1' was not declared in this scope; did you mean 'cnt1'?
  148 |     res+=cn1-m;
      |          ^~~
      |          cnt1