Language: C++

#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;
 sc(n);
 ll a[n+10];
 ll mx=0;
 rep(i,0,n){
  sc(a[i]);
  mx=max(mx,a[i]);
 }
 ll even[200000]={},odd[200000]={};
 ll mx_odd=0,sc_odd=0,mx_even=0,sc_even=0;
 ll memo1=0,memo2=0,memo3=0,memo4=0;
  
 rep(i,0,n){
  if((i+1)%2){
   odd[a[i]]++;
  }
  if((i+1)%2==0){
   even[a[i]]++;  
  }
 }
 rep(i,0,mx+1){
  if(mx_odd<odd[i]){
   sc_odd=mx_odd;
   memo2=memo1;
   mx_odd=odd[i];
   memo1=i;
  }
  if(mx_even<even[i]){
   sc_even=mx_even;
   memo4=memo3;
   mx_even=even[i];
   memo3=i;
  }
 }
 if(memo1!=memo3)ans=n-(mx_odd+mx_even);
 else if(memo1!=memo4&&mx_odd+sc_even>=sc_odd+mx_even)ans=n-(mx_odd+sc_even);
 else if(memo2!=memo3&&mx_odd+sc_even<sc_odd+mx_even)ans=n-(sc_odd+mx_even);
 else if(memo2!=memo4)ans=n-(sc_odd+sc_even);
 else ans=0;
 pr(ans);
 return 0;}#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;
 sc(n);
 ll a[n+10];
 ll mx=0;
 rep(i,0,n){
  sc(a[i]);
  mx=max(mx,a[i]);
 }
 ll even[200000]={},odd[200000]={};
 ll mx_odd=0,sc_odd=0,mx_even=0,sc_even=0;
 ll memo1=0,memo2=0,memo3=0,memo4=0;
  
 rep(i,0,n){
  if((i+1)%2){
   odd[a[i]]++;
  }
  if((i+1)%2==0){
   even[a[i]]++;  
  }
 }
 rep(i,0,mx+1){
  if(mx_odd<odd[i]){
   sc_odd=mx_odd;
   memo2=memo1;
   mx_odd=odd[i];
   memo1=i;
  }
  if(mx_even<even[i]){
   sc_even=mx_even;
   memo4=memo3;
   mx_even=even[i];
   memo3=i;
  }
 }
 if(memo1!=memo3)ans=n-(mx_odd+mx_even);
 else if(memo1!=memo4&&mx_odd+sc_even>=sc_odd+mx_even)ans=n-(mx_odd+sc_even);
 else if(memo2!=memo3&&mx_odd+sc_even<sc_odd+mx_even)ans=n-(sc_odd+mx_even);
 else if(memo2!=memo4)ans=n-(sc_odd+sc_even);
 else ans=0;
 pr(ans);
 return 0;}

Compiler output:
a.cc:93:12: error: stray '#' in program
   93 |  return 0;}#include<stdio.h>
      |            ^
a.cc:93:13: error: 'include' does not name a type
   93 |  return 0;}#include<stdio.h>
      |             ^~~~~~~
a.cc:132:14: error: redefinition of 'double pi'
  132 | /*pi*/double pi=acos(-1);
      |              ^~
a.cc:40:14: note: 'double pi' previously defined here
   40 | /*pi*/double pi=acos(-1);
      |              ^~
a.cc:133:20: error: redefinition of 'long long int cei(long long int, long long int)'
  133 | /*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
      |                    ^~~
a.cc:41:20: note: 'long long int cei(long long int, long long int)' previously defined here
   41 | /*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
      |                    ^~~
a.cc:134:18: error: redefinition of 'long long int gcd(long long int, long long int)'
  134 | /*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
      |                  ^~~
a.cc:42:18: note: 'long long int gcd(long long int, long long int)' previously defined here
   42 | /*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
      |                  ^~~
a.cc:135:18: error: redefinition of 'long long int lcm(long long int, long long int)'
  135 | /*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
      |                  ^~~
a.cc:43:18: note: 'long long int lcm(long long int, long long int)' previously defined here
   43 | /*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
      |                  ^~~
a.cc:136:11: error: redefinition of 'long long int llpow(long long int, long long int)'
  136 | /*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
      |           ^~~~~
a.cc:44:11: note: 'long long int llpow(long long int, long long int)' previously defined here
   44 | /*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
      |           ^~~~~
a.cc:137:12: error: redefinition of 'long long int fact(long long int)'
  137 | /*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
      |            ^~~~
a.cc:45:12: note: 'long long int fact(long long int)' previously defined here
   45 | /*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
      |            ^~~~
a.cc:138:11: error: redefinition of 'long long int ncr(long long int, long long int)'
  138 | /*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
      |           ^~~
a.cc:46:11: note: 'long long int ncr(long long int, long long int)' previously defined here
   46 | /*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
      |           ^~~
a.cc:139:11: error: redefinition of 'long long int npr(long long int, long long int)'
  139 | /*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
      |           ^~~
a.cc:47:11: note: 'long long int npr(long long int, long long int)' previously defined here
   47 | /*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
      |           ^~~
a.cc:140:20: error: redefinition of 'bool prime(long long int)'
  140 | /*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
      |                    ^~~~~
a.cc:48:20: note: 'bool prime(long long int)' previously defined here
   48 | /*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
      |                    ^~~~~
a.cc:141:21: error: redefinition of 'long long int fib(long long int)'
  141 | /*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
      |                     ^~~
a.cc:49:21: note: 'long long int fib(long long int)' previously defined here
   49 | /*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
      |                     ^~~
a.cc:142:12: error: redefinition of 'long long int dig(long long int)'
  142 | /*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
      |            ^~~
a.cc:50:12: note: 'long long int dig(long long int)' previously defined here
   50 | /*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
      |            ^~~
a.cc:118:18: error: redefinition of 'long long int i'
  118 | #define llfor ll i,j
      |                  ^
a.cc:143:1: note: in expansion of macro 'llfor'
  143 | llfor;ll ans=0;////////////////////////////////////////////////////////////
      | ^~~~~
a.cc:26:18: note: 'long long int i' previously declared here
   26 | #define llfor ll i,j
      |                  ^
a.cc:51:1: note: in expansion of macro 'llfor'
   51 | llfor;ll ans=0;////////////////////////////////////////////////////////////
      | ^~~~~
a.cc:118:20: error: redefinition of 'long long int j'
  118 | #define llfor ll i,j
      |                    ^
a.cc:143:1: note: in expansion of macro 'llfor'
  143 | llfor;ll ans=0;////////////////////////////////////////////////////////////
      | ^~~~~
a.cc:26:20: note: 'long long int j' previously declared here
   26 | #define llfor ll i,j
      |                    ^
a.cc:51:1: note: in expansion of macro 'llfor'
   51 | llfor;ll ans=0;////////////////////////////////////////////////////////////
      | ^~~~~
a.cc:143:10: error: redefinition of 'long long int ans'
  143 | llfor;ll ans=0;////////////////////////////////////////////////////////////
      |          ^~~
a.cc:51:10: note: 'long long int ans' previously defined here
   51 | llfor;ll ans=0;////////////////////////////////////////////////////////////
      |          ^~~
a.cc:144:5: error: redefinition of 'int main()'
  144 | int main(){
      |     ^~~~
a.cc:52:5: note: 'int main()' previously defined here
   52 | int main(){
      |     ^~~~