Problem:


Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int, input().split(" ")))

v1 = {}
v2 = {}
for i in range(len(v)):
    if(i % 2 == 0):
        if((v[i] in v1) == True):
            v1[v[i]] += 1
        else:
            v1[v[i]] = 1
    else: 
        if((v[i] in v2) == True):
            v2[v[i]] += 1
        else:
            v2[v[i]] = 1


if(max_k1 == max_k2):
    if(v1[max_k1] > v2[max_k2]):
        v2[max_k2] = 0
        max_k2 = max(v2, key=v2.get)
    else:
        v1[max_k1] = 0
        max_k1 = max(v1, key=v1.get)


ans = n // 2 - v1[max_k1]
ans += n // 2 - v2[max_k2]

print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
v = il()
a = dict()
b = dict()
for i in range(n):
    if i&1:
        if v[i] in a:
            a[v[i]] += 1
        else:
            a[v[i]] = 1
    else:
        if v[i] in b:
            b[v[i]] += 1
        else:
            b[v[i]] = 1
ans = 0
a = sorted(a.items(), key=lambda x:x[1])
b = sorted(b.items(), key=lambda x:x[1])

if a[-1][0] == b[-1][0]:
    ans += min(a[-1][1], b[-1][1])
else:
    if len(a) > 1:
        ans += n//2 - a[-1][1]
    if len(b) > 1:
        ans += n//2 - B[-1][1]

print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

#define ll long long
//#define int long long
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

#define dump(x)  cerr << #x << " = " << (x) << endl; 
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 


typedef pair<int, int> P;
struct Point{
	int x, y;
};
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = {1,0,-1,0};



int n;
int v[100001];
int even[100001], odd[100001];
int even1[100001], odd1[100001];

int main(){

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> v[i];
		if (i % 2 == 0) even[v[i]]++;
		else odd[v[i]]++;
	}
	for (int i = 0; i <=100000; i++){
		even1[i] = even[i];
		odd1[i] = odd[i];
	}

	sort(even, even + 100000, greater<int>());
	sort(odd, odd + 100000, greater<int>());

	int max_even;
	int max_odd;

	for (int i = 0; i <= 100000; i++){
		if (even1[i] == even[0]) max_even = i;
		if (odd1[i] == odd[0]) max_odd = i;
	}
	if (max_even != max_odd){
		cout << n - even[0] - odd[0] << endl;
	}
	else{
		cout << min(n - even[0] - odd[1], n - even[1] - odd[0]) << endl;
	}

	return 0;
}

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
l = [*map(int, input().split())]

l1 = [l[i] for i in range(0, n, 2)]
l2 = [l[i] for i in range(1, n, 2)]
c1 = sorted(Counter(l1).items(), key = lambda x: x[1], reverse = True) + [(0, 0)]
c2 = sorted(Counter(l2).items(), key = lambda x: x[1], reverse = True) + [(0, 0)]

res = c1[0][1] + c2[0][1]
if c1[0][0] == c2[0][0]:
    res = max((c1[1][1] + c2[0][1]), (c1[0][1] + c2[1][1]))

# print(c1, c2)
print(n - res)

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

one = sorted(Counter([v[i] for i in range(0, n, 2)]).items(), key=lambda x: x[1], reverse=True)
two = sorted(Counter([v[i] for i in range(1, n, 2)]).items(), key=lambda x: x[1], reverse=True)

print(one, two)
if one[0][0] != two[0][0]:
	print(n - one[0][1] - two[0][1])
else:
	if len(one) == 1 and len(two) == 1:
		print(n // 2)
	elif len(one) == 1:
		print(n // 2 - two[1][1])
	elif len(two) == 1:
		print(n // 2 - one[1][1])
	else:
		print(min(n - one[0][1] - two[1][1]), n - one[1][1] - two[0][1])

Submission status: Runtime Error

Solution code:
from numpy import argmax, argmin
N = int(input())
V = list(map(int, input().split()))
V1 = []
V2 = []
for i in range(N):
    if i%2==0:
        V1.append(V[i])
    else:
        V2.append(V[i])

Cnt = [0]*10001
for v in V1:
    Cnt[v] += 1
a1 = N//2-max(Cnt)
arg1 = argmax(Cnt)
Cnt[arg1] = 0
a11 = N//2-max(Cnt)


Cnt = [0]*10001
for v in V2:
    Cnt[v] += 1
a2 = N//2-max(Cnt)
arg2 = argmax(Cnt)
Cnt[arg2] = 0
a22 = N//2-max(Cnt)
#print(arg1, arg2, a1, a11, a2, a22)
if arg1==arg2:
    print(min(a1+a22, a2+a11))
else:
    print(a1+a2)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(raw_input())
v = map(int,raw_input().split())

seta= [0 for i in range(1,10**5 +1)]
setb= [0 for i in range(1,10**5 +1)]


for i in range(n/2):
    seta[v[2*i]]+=1
    setb[v[2*i+1]]+=1
seta = np.array(seta)
setb = np.array(setb)

argseta=seta.argsort()[::-1]
argsetb=setb.argsort()[::-1]

if argseta[0]!=argsetb[0]:
    print n - max(seta) - max(setb)
else:
    if setb[argseta[0]]-seta[argseta[1]]<setb[argsetb[0]]-setb[argsetb[1]]:
        print n - max(setb) - seta[argseta[1]]
    else:
        print n - max(seta) - setb[argsetb[1]]