stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<map>

#define in(a) scanf("%d",&a)

using namespace std;

const int maxn = 1e5 + 10;

int a[maxn]; int b[maxn];



int main()

{

	int n; in(n);

	for (int i = 1; i <= n; i++)

	{

		int x; in(x);

		if (i & 1 == 1)a[x] += 1;

		else b[x] += 1;

	}

	

	int pmax = 0; int sec = 0; int pos = 0;

	for (int i = 1; i < maxn; i++)

	{

		if (a[i] > pmax)

		{

			sec = pmax; pmax = a[i]; pos = i;

		}

		else

		{

			sec = max(sec, a[i]);

		}

	}

	int ans = 1e9;

	for (int i = 1; i < maxn; i++)

	{

		if (pos != i)ans = min(ans, n - pmax - b[i]);

		else ans = min(ans, n - sec - b[i]);

	}

	printf("%d\n", ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2476648967879895x):
#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

#define debug cout<<"****************"<<endl

using namespace std;

typedef long long ll;

inline void ju() {

	freopen("***.in","r",stdin);

	freopen("***.out","w",stdout);

}

inline ll rd() {

	ll x=0,f=1; char c=getchar();

	while((c<'0'||c>'9')&&(c!='-')) c=getchar();

	if(c=='-') f=-1,c=getchar();

	while(c>='0'&&c<='9') {

		x=(x<<3)+(x<<1)+c-'0';

		c=getchar();

	}

	return x*f;

}

const int N=1e5+10;

int a[N],b1[N],b2[N];

int main() {

	int n=rd(),x1=0,y1=0,x2=0,y2=0;

	for(int i=1;i<=n;++i) a[i]=rd();

	for(int i=1;i<=n;i+=2) ++b1[a[i]];

	for(int i=2;i<=n;i+=2) ++b2[a[i]];

	for(int i=1;i<N;++i) {

		if(b1[i]>b1[x1]) y1=x1,x1=i;

		else if(b1[i]>b1[y1]) y1=i;

		if(b2[i]>b2[x2]) y2=x2,x2=i;

		else if(b2[i]>b2[y2]) y2=i;

	}

	int ans;

	if(x1!=x2) ans=n-b1[x1]-b2[x2];

	else ans=n-max(b1[x1]+b2[y2],b1[y1]+b2[x2]);

	printf("%d\n",ans);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

typedef long long ll;

typedef long double ld;

using namespace std;

mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());

#define ii for(int i=1;i<=n;++i)

#define ji for(int j=1;j<=n;++j)

#define jj for(int j=1;j<=m;++j)

#define ij for(int i=1;i<=m;++i)

#define sz(x) ((ll)x.size())

#define all(x) x.begin(),x.end()

#define alll(x) x+1,x+1+n

#define asd cout<<"ok"<<endl;

#define endl '\n'



int a[100005];

int cnt[100005],cnt2[100005];

int main()

{

    int n;

    cin>>n;

    ii cin>>a[i];

    for(int i=1;i<=n;i+=2) cnt[a[i]]++;

    for(int i=2;i<=n;i+=2) cnt2[a[i]]++;

    int mx1=0,mx2=0,mi1=0,mi2=0;

    for(int i=1;i<=100000;++i) {

        if(cnt[i] > mx1) {

            mx2 = mx1, mi2 = mi1;

            mx1 = cnt[i], mi1 = i;

        } else if(cnt[i] > mx2) {

            mx2 = cnt[i], mi2 = i;

        }

    }

    int mx12=0,mx22=0,mi12=0,mi22=0;

    for(int i=1;i<=100000;++i) {

        if(cnt2[i] > mx12) {

            mx22 = mx12, mi22 = mi12;

            mx12 = cnt2[i], mi12 = i;

        } else if(cnt2[i] > mx22) {

            mx22 = cnt2[i], mi22 = i;

        }

    }

    if(mi12 != mi1) cout << n - mx1 - mx12 << endl;

    else cout << min(n-mx1-mx22,n-mx2-mx12) << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.2473237212368786x):
#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

#define debug cout<<"****************"<<endl

using namespace std;

typedef long long ll;

inline void ju() {

	freopen("***.in","r",stdin);

	freopen("***.out","w",stdout);

}

inline ll rd() {

	ll x=0,f=1; char c=getchar();

	while((c<'0'||c>'9')&&(c!='-')) c=getchar();

	if(c=='-') f=-1,c=getchar();

	while(c>='0'&&c<='9') {

		x=(x<<3)+(x<<1)+c-'0';

		c=getchar();

	}

	return x*f;

}

const int N=1e5+10;

int a[N],b1[N],b2[N];

int main() {

	int n=rd(),x1=0,y1=0,x2=0,y2=0;

	for(int i=1;i<=n;++i) a[i]=rd();

	for(int i=1;i<=n;i+=2) ++b1[a[i]];

	for(int i=2;i<=n;i+=2) ++b2[a[i]];

	for(int i=1;i<N;++i) {

		if(b1[i]>b1[x1]) y1=x1,x1=i;

		else if(b1[i]>b1[y1]) y1=i;

		if(b2[i]>b2[x2]) y2=x2,x2=i;

		else if(b2[i]>b2[y2]) y2=i;

	}

	int ans;

	if(x1!=x2) ans=n-b1[x1]-b2[x2];

	else ans=n-max(b1[x1]+b2[y2],b1[y1]+b2[x2]);

	printf("%d\n",ans);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<map>

#define in(a) scanf("%d",&a)

using namespace std;

const int maxn = 1e5 + 10;

int a[maxn]; int b[maxn];



int main()

{

	int n; in(n);

	for (int i = 1; i <= n; i++)

	{

		int x; in(x);

		if (i & 1 == 1)a[x] += 1;

		else b[x] += 1;

	}

	

	int pmax = 0; int sec = 0; int pos = 0;

	for (int i = 1; i < maxn; i++)

	{

		if (a[i] > pmax)

		{

			sec = pmax; pmax = a[i]; pos = i;

		}

		else

		{

			sec = max(sec, a[i]);

		}

	}

	int ans = 1e9;

	for (int i = 1; i < maxn; i++)

	{

		if (pos != i)ans = min(ans, n - pmax - b[i]);

		else ans = min(ans, n - sec - b[i]);

	}

	printf("%d\n", ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8254781771063613x):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define pf push_front

#define pii pair <int, int>

#define all(vv) (vv).begin(), (vv).end()

#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0

 

//link: https://atcoder.jp/contests/arc103/tasks/arc103_a

 

vector <int> e;

vector <int> o;

map <int, int> mpe;

map <int, int> mpo;

int32_t main() {

	ios_base::sync_with_stdio(0); cin.tie(0);

	bool can = true;

	int n; cin >> n;

	for(int i = 0; i < n; ++i) {

		int x; cin >> x;

		if (i % 2 == 0) o.pb(x);

		else e.pb(x);

	}

	// find the top 2 modes

	for(auto it:e) {

		++mpe[it];

	}

	vector <pii> MPE; // convert to vector for sorting

	for(auto it:mpe) {

		MPE.pb(make_pair(it.second, it.first));

	}

	sort(all(MPE), greater<pair<int, int> > ());

	int e1 = MPE[0].second;

	int e2 = MPE[1].second;

	cerr << e1 << ' ' << e2 << '\n';

	// repeat!!

	for(auto it:o) {

		++mpo[it];

	}

	vector <pii> MPO;

	for(auto it:mpo) {

		MPO.pb(make_pair(it.second, it.first));

	}

	sort(all(MPO), greater<pair<int, int> >());

	int o1 = MPO[0].second;

	int o2 = MPO[1].second;

	cerr << o1 << ' ' << o2 << '\n';

 

	if (e1 != o1) {

		// assert(0);

		int count = 0;

		for(auto it:e) {

			if (it != e1) ++count;

		}

		for(auto it:o) {

			if (it != o1) ++count;

		}

		cout << count;

		time;

	}

 

	// find the number of changes required for first type

	int count = 0;

	for(auto it:e) {

		if (it != e1) ++count;

	}

	for(auto it:o) {

		if (it != o2) ++count;

	}

	// second type

	int sum = 0;

	for(auto it:e) {

		if (it != e2) ++sum;

	}

	for(auto it:o) {

		if (it != o1) ++sum;

	}

	cout << min(count, sum);

}
// Slower C++ solution:
#include<bits/stdc++.h>

typedef long long ll;

typedef long double ld;

using namespace std;

mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());

#define ii for(int i=1;i<=n;++i)

#define ji for(int j=1;j<=n;++j)

#define jj for(int j=1;j<=m;++j)

#define ij for(int i=1;i<=m;++i)

#define sz(x) ((ll)x.size())

#define all(x) x.begin(),x.end()

#define alll(x) x+1,x+1+n

#define asd cout<<"ok"<<endl;

#define endl '\n'



int a[100005];

int cnt[100005],cnt2[100005];

int main()

{

    int n;

    cin>>n;

    ii cin>>a[i];

    for(int i=1;i<=n;i+=2) cnt[a[i]]++;

    for(int i=2;i<=n;i+=2) cnt2[a[i]]++;

    int mx1=0,mx2=0,mi1=0,mi2=0;

    for(int i=1;i<=100000;++i) {

        if(cnt[i] > mx1) {

            mx2 = mx1, mi2 = mi1;

            mx1 = cnt[i], mi1 = i;

        } else if(cnt[i] > mx2) {

            mx2 = cnt[i], mi2 = i;

        }

    }

    int mx12=0,mx22=0,mi12=0,mi22=0;

    for(int i=1;i<=100000;++i) {

        if(cnt2[i] > mx12) {

            mx22 = mx12, mi22 = mi12;

            mx12 = cnt2[i], mi12 = i;

        } else if(cnt2[i] > mx22) {

            mx22 = cnt2[i], mi22 = i;

        }

    }

    if(mi12 != mi1) cout << n - mx1 - mx12 << endl;

    else cout << min(n-mx1-mx22,n-mx2-mx12) << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.8249789977796695x):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define pf push_front

#define pii pair <int, int>

#define all(vv) (vv).begin(), (vv).end()

#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0

 

//link: https://atcoder.jp/contests/arc103/tasks/arc103_a

 

vector <int> e;

vector <int> o;

map <int, int> mpe;

map <int, int> mpo;

int32_t main() {

	ios_base::sync_with_stdio(0); cin.tie(0);

	bool can = true;

	int n; cin >> n;

	for(int i = 0; i < n; ++i) {

		int x; cin >> x;

		if (i % 2 == 0) o.pb(x);

		else e.pb(x);

	}

	// find the top 2 modes

	for(auto it:e) {

		++mpe[it];

	}

	vector <pii> MPE; // convert to vector for sorting

	for(auto it:mpe) {

		MPE.pb(make_pair(it.second, it.first));

	}

	sort(all(MPE), greater<pair<int, int> > ());

	int e1 = MPE[0].second;

	int e2 = MPE[1].second;

	cerr << e1 << ' ' << e2 << '\n';

	// repeat!!

	for(auto it:o) {

		++mpo[it];

	}

	vector <pii> MPO;

	for(auto it:mpo) {

		MPO.pb(make_pair(it.second, it.first));

	}

	sort(all(MPO), greater<pair<int, int> >());

	int o1 = MPO[0].second;

	int o2 = MPO[1].second;

	cerr << o1 << ' ' << o2 << '\n';

 

	if (e1 != o1) {

		// assert(0);

		int count = 0;

		for(auto it:e) {

			if (it != e1) ++count;

		}

		for(auto it:o) {

			if (it != o1) ++count;

		}

		cout << count;

		time;

	}

 

	// find the number of changes required for first type

	int count = 0;

	for(auto it:e) {

		if (it != e1) ++count;

	}

	for(auto it:o) {

		if (it != o2) ++count;

	}

	// second type

	int sum = 0;

	for(auto it:e) {

		if (it != e2) ++sum;

	}

	for(auto it:o) {

		if (it != o1) ++sum;

	}

	cout << min(count, sum);

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

#define debug cout<<"****************"<<endl

using namespace std;

typedef long long ll;

inline void ju() {

	freopen("***.in","r",stdin);

	freopen("***.out","w",stdout);

}

inline ll rd() {

	ll x=0,f=1; char c=getchar();

	while((c<'0'||c>'9')&&(c!='-')) c=getchar();

	if(c=='-') f=-1,c=getchar();

	while(c>='0'&&c<='9') {

		x=(x<<3)+(x<<1)+c-'0';

		c=getchar();

	}

	return x*f;

}

const int N=1e5+10;

int a[N],b1[N],b2[N];

int main() {

	int n=rd(),x1=0,y1=0,x2=0,y2=0;

	for(int i=1;i<=n;++i) a[i]=rd();

	for(int i=1;i<=n;i+=2) ++b1[a[i]];

	for(int i=2;i<=n;i+=2) ++b2[a[i]];

	for(int i=1;i<N;++i) {

		if(b1[i]>b1[x1]) y1=x1,x1=i;

		else if(b1[i]>b1[y1]) y1=i;

		if(b2[i]>b2[x2]) y2=x2,x2=i;

		else if(b2[i]>b2[y2]) y2=i;

	}

	int ans;

	if(x1!=x2) ans=n-b1[x1]-b2[x2];

	else ans=n-max(b1[x1]+b2[y2],b1[y1]+b2[x2]);

	printf("%d\n",ans);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.4631157627387805x):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define pf push_front

#define pii pair <int, int>

#define all(vv) (vv).begin(), (vv).end()

#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0

 

//link: https://atcoder.jp/contests/arc103/tasks/arc103_a

 

vector <int> e;

vector <int> o;

map <int, int> mpe;

map <int, int> mpo;

int32_t main() {

	ios_base::sync_with_stdio(0); cin.tie(0);

	bool can = true;

	int n; cin >> n;

	for(int i = 0; i < n; ++i) {

		int x; cin >> x;

		if (i % 2 == 0) o.pb(x);

		else e.pb(x);

	}

	// find the top 2 modes

	for(auto it:e) {

		++mpe[it];

	}

	vector <pii> MPE; // convert to vector for sorting

	for(auto it:mpe) {

		MPE.pb(make_pair(it.second, it.first));

	}

	sort(all(MPE), greater<pair<int, int> > ());

	int e1 = MPE[0].second;

	int e2 = MPE[1].second;

	cerr << e1 << ' ' << e2 << '\n';

	// repeat!!

	for(auto it:o) {

		++mpo[it];

	}

	vector <pii> MPO;

	for(auto it:mpo) {

		MPO.pb(make_pair(it.second, it.first));

	}

	sort(all(MPO), greater<pair<int, int> >());

	int o1 = MPO[0].second;

	int o2 = MPO[1].second;

	cerr << o1 << ' ' << o2 << '\n';

 

	if (e1 != o1) {

		// assert(0);

		int count = 0;

		for(auto it:e) {

			if (it != e1) ++count;

		}

		for(auto it:o) {

			if (it != o1) ++count;

		}

		cout << count;

		time;

	}

 

	// find the number of changes required for first type

	int count = 0;

	for(auto it:e) {

		if (it != e1) ++count;

	}

	for(auto it:o) {

		if (it != o2) ++count;

	}

	// second type

	int sum = 0;

	for(auto it:e) {

		if (it != e2) ++sum;

	}

	for(auto it:o) {

		if (it != o1) ++sum;

	}

	cout << min(count, sum);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int n; cin >> n;

	vector<int> v(n);

	for (int i = 0; i < n; i++) cin >> v[i];

	vector<int> cnt(110000, 0);

	for (int i = 0; i < n; i += 2) {

		cnt[v[i]]++;

	}

	int i1 = max_element(cnt.begin(), cnt.end()) - cnt.begin(), i2 = 0;

	for (int i = 0; i < cnt.size(); i++) {

		if (i != i1) {

			if (cnt[i2] < cnt[i]) i2 = i;

		}

	}

	int ci1 = cnt[i1], ci2 = cnt[i2];

	for (auto& val : cnt) val = 0;

	for (int i = 1; i < n; i += 2) {

		cnt[v[i]]++;

	}

	int j1 = max_element(cnt.begin(), cnt.end()) - cnt.begin(), j2 = 0;

	for (int i = 0; i < cnt.size(); i++) {

		if (i != j1) {

			if (cnt[j2] < cnt[i]) j2 = i;

		}

	}

	int cj1 = cnt[j1], cj2 = cnt[j2];

	int ans;

	if (i1 == j1) {

		ans = n - ci1 - max(ci2, cj2);

	} else {

		ans = n - ci1 - cj1;

	}

	cout << ans << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.003040334171637x):
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define pf push_front

#define pii pair <int, int>

#define all(vv) (vv).begin(), (vv).end()

#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0

 

//link: https://atcoder.jp/contests/arc103/tasks/arc103_a

 

vector <int> e;

vector <int> o;

map <int, int> mpe;

map <int, int> mpo;

int32_t main() {

	ios_base::sync_with_stdio(0); cin.tie(0);

	bool can = true;

	int n; cin >> n;

	for(int i = 0; i < n; ++i) {

		int x; cin >> x;

		if (i % 2 == 0) o.pb(x);

		else e.pb(x);

	}

	// find the top 2 modes

	for(auto it:e) {

		++mpe[it];

	}

	vector <pii> MPE; // convert to vector for sorting

	for(auto it:mpe) {

		MPE.pb(make_pair(it.second, it.first));

	}

	sort(all(MPE), greater<pair<int, int> > ());

	int e1 = MPE[0].second;

	int e2 = MPE[1].second;

	cerr << e1 << ' ' << e2 << '\n';

	// repeat!!

	for(auto it:o) {

		++mpo[it];

	}

	vector <pii> MPO;

	for(auto it:mpo) {

		MPO.pb(make_pair(it.second, it.first));

	}

	sort(all(MPO), greater<pair<int, int> >());

	int o1 = MPO[0].second;

	int o2 = MPO[1].second;

	cerr << o1 << ' ' << o2 << '\n';

 

	if (e1 != o1) {

		// assert(0);

		int count = 0;

		for(auto it:e) {

			if (it != e1) ++count;

		}

		for(auto it:o) {

			if (it != o1) ++count;

		}

		cout << count;

		time;

	}

 

	// find the number of changes required for first type

	int count = 0;

	for(auto it:e) {

		if (it != e1) ++count;

	}

	for(auto it:o) {

		if (it != o2) ++count;

	}

	// second type

	int sum = 0;

	for(auto it:e) {

		if (it != e2) ++sum;

	}

	for(auto it:o) {

		if (it != o1) ++sum;

	}

	cout << min(count, sum);

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<map>

#define in(a) scanf("%d",&a)

using namespace std;

const int maxn = 1e5 + 10;

int a[maxn]; int b[maxn];



int main()

{

	int n; in(n);

	for (int i = 1; i <= n; i++)

	{

		int x; in(x);

		if (i & 1 == 1)a[x] += 1;

		else b[x] += 1;

	}

	

	int pmax = 0; int sec = 0; int pos = 0;

	for (int i = 1; i < maxn; i++)

	{

		if (a[i] > pmax)

		{

			sec = pmax; pmax = a[i]; pos = i;

		}

		else

		{

			sec = max(sec, a[i]);

		}

	}

	int ans = 1e9;

	for (int i = 1; i < maxn; i++)

	{

		if (pos != i)ans = min(ans, n - pmax - b[i]);

		else ans = min(ans, n - sec - b[i]);

	}

	printf("%d\n", ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8598894255207514x):
#include <bits/stdc++.h>

using namespace std;

 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)

#define mod 1000000007LL

#define FOR(i,m,n) for(int i = (m); i < (n); i++)

#define pb push_back

#define mp make_pair

#define fst first

#define snd second

#define all(v) v.begin(),v.end()

#define sz(v) int(v.size())

 

 

typedef long long ll;

typedef vector<int> vi; 

typedef pair<int,int> ii;





ll pow(ll a, ll b){

    int ans = 1;

    while(b){

        if(b&1) ans=(ans*a)%mod;

        b>>=1;

        a=(a*a)%mod;

    }

    return ans;

}





const int N=1e5;





void run(){

	

	int n; cin>>n;

	

	vi v(n);

	FOR(i,0,n) cin>>v[i];

	

	map<int, int> m, p;

	int x=0, ans=0, b;

	

	for(int i=0; i<n; i=i+2){

		if(!m.count(v[i])){

			m[v[i]]=1;

		}

		else m[v[i]]=m[v[i]]+1;

		

		if(m[v[i]]>x){

			x=m[v[i]]; b=v[i];

		}

	}

	

	

	int y=0, c;

	

	for(int i=1; i<n; i=i+2){

		if(!p.count(v[i])){

			p[v[i]]=1;

		}

		else p[v[i]]=p[v[i]]+1;

		

		if(p[v[i]]>y){

			y=p[v[i]]; c=v[i];

		}

	}

		

	if(b==c){

		int w=0, z=0;

		for(auto xd : m){

			if(xd.fst==b) continue;

			w=max(w,xd.snd);

		}

		for(auto xd : p){

			if(xd.fst==c) continue;

			w=max(w,xd.snd);

		}

		ans=n-x-max(w,z);

	}

	else ans=n-x-y;

	

	cout<<ans<<"\n";

}





int main(){

	

	fastio;

	

	int tt=1; 

	//cin>>tt;

	

	while(tt--){

		run();

	}

	

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

typedef long long ll;

typedef long double ld;

using namespace std;

mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());

#define ii for(int i=1;i<=n;++i)

#define ji for(int j=1;j<=n;++j)

#define jj for(int j=1;j<=m;++j)

#define ij for(int i=1;i<=m;++i)

#define sz(x) ((ll)x.size())

#define all(x) x.begin(),x.end()

#define alll(x) x+1,x+1+n

#define asd cout<<"ok"<<endl;

#define endl '\n'



int a[100005];

int cnt[100005],cnt2[100005];

int main()

{

    int n;

    cin>>n;

    ii cin>>a[i];

    for(int i=1;i<=n;i+=2) cnt[a[i]]++;

    for(int i=2;i<=n;i+=2) cnt2[a[i]]++;

    int mx1=0,mx2=0,mi1=0,mi2=0;

    for(int i=1;i<=100000;++i) {

        if(cnt[i] > mx1) {

            mx2 = mx1, mi2 = mi1;

            mx1 = cnt[i], mi1 = i;

        } else if(cnt[i] > mx2) {

            mx2 = cnt[i], mi2 = i;

        }

    }

    int mx12=0,mx22=0,mi12=0,mi22=0;

    for(int i=1;i<=100000;++i) {

        if(cnt2[i] > mx12) {

            mx22 = mx12, mi22 = mi12;

            mx12 = cnt2[i], mi12 = i;

        } else if(cnt2[i] > mx22) {

            mx22 = cnt2[i], mi22 = i;

        }

    }

    if(mi12 != mi1) cout << n - mx1 - mx12 << endl;

    else cout << min(n-mx1-mx22,n-mx2-mx12) << endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.8593808363944633x):
#include <bits/stdc++.h>

using namespace std;

 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)

#define mod 1000000007LL

#define FOR(i,m,n) for(int i = (m); i < (n); i++)

#define pb push_back

#define mp make_pair

#define fst first

#define snd second

#define all(v) v.begin(),v.end()

#define sz(v) int(v.size())

 

 

typedef long long ll;

typedef vector<int> vi; 

typedef pair<int,int> ii;





ll pow(ll a, ll b){

    int ans = 1;

    while(b){

        if(b&1) ans=(ans*a)%mod;

        b>>=1;

        a=(a*a)%mod;

    }

    return ans;

}





const int N=1e5;





void run(){

	

	int n; cin>>n;

	

	vi v(n);

	FOR(i,0,n) cin>>v[i];

	

	map<int, int> m, p;

	int x=0, ans=0, b;

	

	for(int i=0; i<n; i=i+2){

		if(!m.count(v[i])){

			m[v[i]]=1;

		}

		else m[v[i]]=m[v[i]]+1;

		

		if(m[v[i]]>x){

			x=m[v[i]]; b=v[i];

		}

	}

	

	

	int y=0, c;

	

	for(int i=1; i<n; i=i+2){

		if(!p.count(v[i])){

			p[v[i]]=1;

		}

		else p[v[i]]=p[v[i]]+1;

		

		if(p[v[i]]>y){

			y=p[v[i]]; c=v[i];

		}

	}

		

	if(b==c){

		int w=0, z=0;

		for(auto xd : m){

			if(xd.fst==b) continue;

			w=max(w,xd.snd);

		}

		for(auto xd : p){

			if(xd.fst==c) continue;

			w=max(w,xd.snd);

		}

		ans=n-x-max(w,z);

	}

	else ans=n-x-y;

	

	cout<<ans<<"\n";

}





int main(){

	

	fastio;

	

	int tt=1; 

	//cin>>tt;

	

	while(tt--){

		run();

	}

	

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

#define debug cout<<"****************"<<endl

using namespace std;

typedef long long ll;

inline void ju() {

	freopen("***.in","r",stdin);

	freopen("***.out","w",stdout);

}

inline ll rd() {

	ll x=0,f=1; char c=getchar();

	while((c<'0'||c>'9')&&(c!='-')) c=getchar();

	if(c=='-') f=-1,c=getchar();

	while(c>='0'&&c<='9') {

		x=(x<<3)+(x<<1)+c-'0';

		c=getchar();

	}

	return x*f;

}

const int N=1e5+10;

int a[N],b1[N],b2[N];

int main() {

	int n=rd(),x1=0,y1=0,x2=0,y2=0;

	for(int i=1;i<=n;++i) a[i]=rd();

	for(int i=1;i<=n;i+=2) ++b1[a[i]];

	for(int i=2;i<=n;i+=2) ++b2[a[i]];

	for(int i=1;i<N;++i) {

		if(b1[i]>b1[x1]) y1=x1,x1=i;

		else if(b1[i]>b1[y1]) y1=i;

		if(b2[i]>b2[x2]) y2=x2,x2=i;

		else if(b2[i]>b2[y2]) y2=i;

	}

	int ans;

	if(x1!=x2) ans=n-b1[x1]-b2[x2];

	else ans=n-max(b1[x1]+b2[y2],b1[y1]+b2[x2]);

	printf("%d\n",ans);

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.4906962841616234x):
#include <bits/stdc++.h>

using namespace std;

 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)

#define mod 1000000007LL

#define FOR(i,m,n) for(int i = (m); i < (n); i++)

#define pb push_back

#define mp make_pair

#define fst first

#define snd second

#define all(v) v.begin(),v.end()

#define sz(v) int(v.size())

 

 

typedef long long ll;

typedef vector<int> vi; 

typedef pair<int,int> ii;





ll pow(ll a, ll b){

    int ans = 1;

    while(b){

        if(b&1) ans=(ans*a)%mod;

        b>>=1;

        a=(a*a)%mod;

    }

    return ans;

}





const int N=1e5;





void run(){

	

	int n; cin>>n;

	

	vi v(n);

	FOR(i,0,n) cin>>v[i];

	

	map<int, int> m, p;

	int x=0, ans=0, b;

	

	for(int i=0; i<n; i=i+2){

		if(!m.count(v[i])){

			m[v[i]]=1;

		}

		else m[v[i]]=m[v[i]]+1;

		

		if(m[v[i]]>x){

			x=m[v[i]]; b=v[i];

		}

	}

	

	

	int y=0, c;

	

	for(int i=1; i<n; i=i+2){

		if(!p.count(v[i])){

			p[v[i]]=1;

		}

		else p[v[i]]=p[v[i]]+1;

		

		if(p[v[i]]>y){

			y=p[v[i]]; c=v[i];

		}

	}

		

	if(b==c){

		int w=0, z=0;

		for(auto xd : m){

			if(xd.fst==b) continue;

			w=max(w,xd.snd);

		}

		for(auto xd : p){

			if(xd.fst==c) continue;

			w=max(w,xd.snd);

		}

		ans=n-x-max(w,z);

	}

	else ans=n-x-y;

	

	cout<<ans<<"\n";

}





int main(){

	

	fastio;

	

	int tt=1; 

	//cin>>tt;

	

	while(tt--){

		run();

	}

	

	return 0;

}