You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
968 B
C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 50;
int a[N], cnt1[N], cnt2[N];
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", a + i);
for (int i = 0; i < n; i += 2)
cnt1[a[i]]++;
for (int i = 1; i < n; i += 2)
cnt2[a[i]]++;
vector<pair<int, int>> v1(n), v2(n);
v1.push_back({0, 0}), v2.push_back({0, 0});
for (int i = 0; i < N; i++)
if (cnt1[i])
v1.push_back({cnt1[i], i});
for (int i = 0; i < N; i++)
if (cnt2[i])
v2.push_back({cnt2[i], i});
sort(v1.begin(), v1.end(), greater<pair<int, int>>());
sort(v2.begin(), v2.end(), greater<pair<int, int>>());
if (v1[0].second != v2[0].second)
printf("%d", n - v1[0].first - v2[0].first);
else
printf("%d", min(n - v1[0].first - v2[1].first, n - v1[1].first - v2[0].first));
return 0;
}