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 /\/\/\/.

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
D1 = defaultdict(int)
D2 = defaultdict(int)

for i in range(0,N,2):
  D1[A[i]]+=1
for i in range(1,N,2):
  D2[A[i]]+=1
  
D1_sorted = sorted(D1.items(), key=lambda x:x[1], reverse = True) + [(-1,0)]
D2_sorted = sorted(D2.items(), key=lambda x:x[1], reverse = True) + [(-1,0)]
i, j = 0, 0
while i < len(D1_sorted) -1 and j < len(D2_sorted) -1:
  if D1_sorted[i][0] != D2_sorted[j][0]:
    break
  elif D1_sorted[i][1] > D2_sorted[j][1]:
    j+=1
  elif D1_sorted[i][1] < D2_sorted[j][1]:
    i+=1
  else:
    if D1_sorted[i+1][1] > D2_sorted[j+1][1]:
      i+=1
    else:
      j+=1

print(N-D1_sorted[i][1]-D2_sorted[j][1])

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
v1 = v[0::2]
v2 = v[1::2]

from collections import Counter
c1 = list(Counter(v1).items())
c2 = list(Counter(v2).items())

c1 = sorted(c1, key= lambda x: x[1], reverse= True)
c2 = sorted(c2, key= lambda x: x[1], reverse= True)

c1.append((0,0))
c2.append((0,0))


if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    a = c1[0][1] + c2[1][1]
    b = c1[1][1] + c2[0][1]
    if a < b:
        print(n - b)
    else:
        print(n - a)

Solution (Python):
from collections import Counter
import sys
n = int(input())
v = [[], []]
for i, j in enumerate(input().split()):
    if i & 1:
        v[0].append(int(j))
    else:
        v[1].append(int(j))

v1, v2 = Counter(v[0]), Counter(v[1])
mx1 , mx2 = v1.most_common()[0], v2.most_common()[0]
if mx1[0] == mx2[0]:
    if mx1[1] + mx2[1] == n:
        print(n//2)
        sys.exit() 
    nx1, nx2 = v1.most_common()[1][1], v2.most_common()[1][1]
    if nx1 > nx2:
        print(n - nx1 - mx2[1])
    else:
        print(n - mx1[1] - nx2)
else:
    print(n - mx1[1] - mx2[1])

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    v = i_list()

    fd = {}
    sd = {}
    for i,k in enumerate(v):
        if i%2==0:
            fd[k] = fd.get(k,0) + 1
        else:
            sd[k] = sd.get(k,0) + 1

    a = max(fd, key=fd.get)
    b = max(sd, key=sd.get)
    c = max(fd.values())
    d = max(sd.values())

    if a != b:
        print(n - c - d)
    else:
        fd[a] = 0
        sd[b] = 0
        e = max(fd.values())
        f = max(sd.values())
        z = max(c+f , d+e)
        print(n-z)


if __name__=="__main__":
    main()

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]

N,V = ilint()
odd = counter()
even = counter()
for i in range(N):
    if i%2==0:
        even.add(V[i])
    else:
        odd.add(V[i])
E = [(k,even[k]) for k in even]+[(0,0)]
O = [(k,odd[k]) for k in odd]+[(0,0)]
E.sort(reverse=True, key=lambda x:x[1])
O.sort(reverse=True, key=lambda x:x[1])
if E[0][0]!=O[0][0]:
    print(N-E[0][1]-O[0][1])
else:
    print(min(N-E[1][1]-O[0][1],N-E[0][1]-O[1][1]))

Solution (Python):
N = int(input())
V = list(map(int, input().split()))
odd_dict = {}
even_dict = {}
for i in range(N):
    if i % 2 == 0:
        if odd_dict.get(V[i]) is None:
            odd_dict[V[i]] = 1
        else:
            odd_dict[V[i]] += 1
    else:
        if even_dict.get(V[i]) is None:
            even_dict[V[i]] = 1
        else:
            even_dict[V[i]] += 1

odd_dict_sorted = sorted(odd_dict.items(), key=lambda a: a[1])
even_dict_sorted = sorted(even_dict.items(), key=lambda a: a[1])

odd_dict_max = odd_dict_sorted.pop()
even_dict_max = even_dict_sorted.pop()
if odd_dict_max[0] == even_dict_max[0] and N // 2 == odd_dict_max[1]:
    ans = N // 2
elif odd_dict_max[0] == even_dict_max[0]:
    odd_dict_max_t = odd_dict_sorted.pop()
    even_dict_max_t = even_dict_sorted.pop()
    ans = N - odd_dict_max[1] - max(even_dict_max_t[1],odd_dict_max_t[1])
else:
    ans = N - odd_dict_max[1] - even_dict_max[1]
print(ans)

Solution (Python):
import collections

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

vs_even = vs[0::2]
vs_odd = vs[1::2]

count_e = collections.Counter(vs_even).most_common()
count_o = collections.Counter(vs_odd).most_common()


count_e.append((0,0))
count_o.append((0,0))


e_max = len(vs_even) - count_e[0][1]
e_second = len(vs_even) - count_e[1][1]
o_max = len(vs_odd) - count_o[0][1]
o_second = len(vs_odd) - count_o[1][1]

if(count_e[0][0] != count_o[0][0]):
    print(e_max + o_max)

else:
    print(min(e_second+o_max, e_max+o_second))

Solution (Python):
import collections
N = int(input())
N_List = list(map(int,input().split()))
hanN = N//2
ki = N_List[1::2]
gu = N_List[0::2]
kicnt = collections.Counter(ki)
gucnt = collections.Counter(gu)

kidict = kicnt.most_common()
gudict = gucnt.most_common()

kilen = len(kidict)
gulen = len(gudict)

if kilen == 1 & gulen == 1:
    if kidict == gudict:
        ans = hanN
    else:
        ans = 0
elif kidict[0][0] == gudict[0][0]:
    if kidict[0][1] > gudict[0][1]:
        ans = sum(map(lambda x:x[1],kidict[1:])) + sum(map(lambda x:x[1],gudict[2:])) + gudict[0][1]
    elif kidict[0][1] < gudict[0][1]:
        ans = sum(map(lambda x:x[1],gudict[1:])) + sum(map(lambda x:x[1],kidict[2:])) + kidict[0][1]
    else:
        if gudict[1][1] >= kidict[1][1]:
            ans = sum(map(lambda x:x[1],kidict[1:])) + sum(map(lambda x:x[1],gudict[2:])) + gudict[0][1]
        else:
            ans = sum(map(lambda x:x[1],gudict[1:])) + sum(map(lambda x:x[1],kidict[2:])) + kidict[0][1]
else:
    ans = sum(map(lambda x:x[1],gudict[1:])) + sum(map(lambda x:x[1],kidict[1:]))

print(ans)

Solution (Python):
import collections
n = int(input())
lsp = list(map(int,input().split()))
lse = []
lso = []
for i in range(n):
    if i%2 == 0:
        lse.append(lsp[i])
    else:
        lso.append(lsp[i])

countere = collections.Counter(lse)
countero = collections.Counter(lso)

valuee = sorted(list(countere.values()),reverse=True)+[0]
valueo = sorted(list(countero.values()),reverse=True)+[0]

keyse = []
for i in countere.keys():
    if countere[i] == valuee[0]:
        keyse.append(i)
keyso = []
for i in countero.keys():
    if countero[i] == valueo[0]:
        keyso.append(i)
factor = 0
if len(keyse) == 1 and len(keyso) == 1 and keyso == keyse:
    factor = min(valuee[0]-valuee[1],valueo[0]-valueo[1])

print(n-valuee[0]-valueo[0]+factor)

Solution (Python):
import collections
import math

n=int(input())
a=list(map(int,input().split()))
ev=[a[2*i] for i in range(n//2)]
od=[a[2*i+1] for i in range(n//2)]

ccev=collections.Counter(ev)
ccod=collections.Counter(od)

mcev=ccev.most_common()
mcod=ccod.most_common()

if mcev[0][0]!=mcod[0][0]:
    print(n-mcev[0][1]-mcod[0][1])
    exit()
elif len(mcev)==1 and len(mcod)==1:
    print(n-mcev[0][1])
    exit()
elif len(mcev)==1:
    print(n-mcod[1][1])
    exit()
elif len(mcod)==1:
    print(n-mcev[1][1])
    exit()
else:
    tt=max(mcev[1][1],mcod[1][1])
    print(n-mcev[0][1]-tt)
    exit()

Solution (Python):
n, *v = map(int, open(0).read().split())
from collections import*
d, e = (Counter(i).most_common()+[(0,0)] for i in (v[0::2], v[1::2]))
print(n-d[0][1]-e[0][1] if d[0] != e[0] else n-max(d[0][1]+e[1][1], d[1][1]+e[0][1]))

Solution (Python):
n = int(input())
v  = list(map(int, input().split()))
a = [v[i] for i in range(0, n, 2)]
b = [v[i] for i in range(1, n, 2)]
d = {}
for i in a:
    if i not in d:
        d[i] = 1
    else:
        d[i] +=1
e = {}
for i in b:
    if i not in e:
        e[i] = 1
    else:
        e[i] +=1
d = sorted(d.items(), key=lambda x: -x[1])
e = sorted(e.items(), key=lambda x: -x[1])
if d[0] != e[0]:
    print(n-d[0][1]-e[0][1])
else:
    if len(d) == len(e) == 1:
        print(n//2)
    elif len(d) == 1 and len(e) > 1:
        print(n//2-e[1][1])
    elif len(d) > 1 and len(e) == 1:
        print(n//2-d[1][1])
    else:
        print(n-max(d[0][1]+e[1][1], d[1][1]+e[0][1]))

Solution (Python):


import sys

from collections import Counter


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    V = input_int_list()
    cnt = n // 2
    even = Counter(V[0::2]).most_common()
    odd = Counter(V[1::2]).most_common()
    if even[0][0] != odd[0][0]:
        ans = (cnt) - even[0][1] + (cnt) - odd[0][1]
    else:
        if len(even) > 1 and len(odd) > 1:
            ans = min(cnt - even[0][1] + cnt - odd[1][1], cnt - even[1][1] + cnt - odd[0][1])
        elif len(even) == 1 and len(odd) == 1:
            ans = cnt
        elif len(even) == 1 and len(odd) > 1:
            ans = min(cnt - odd[1][1])
        elif len(odd) == 1 and len(even) > 1:
            ans = min(cnt - even[1][1])
    print(ans)

    return


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter


n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()

ans = 0
l = n//2
if a[0][0] != b[0][0]:
    ans = l - a[0][1] + l - b[0][1]
else:
    if len(b) > 1:
        x = l - a[0][1] + l - b[1][1]
        y = l - a[1][1] + l - b[0][1]

    else:
        x = l - a[0][1] + l
        y = l - b[0][1] + l

    ans = min(x, y)

print(ans)

Solution (Python):
from collections import Counter


n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()

ans = 0

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

print(ans)

Solution (Python):
from collections import Counter
N=int(input())
v=list(map(int,input().split()))
even=[]
odd=[]
for n in range(N):
    if n%2==0:
        even.append(v[n])
    else:
        odd.append(v[n])
evens=Counter(even)
odds=Counter(odd)
even_value_max=max(evens.values())
odds_value_max=max(odds.values())
even_numbers=[]
odds_numbers=[]
for key,value in evens.items():
    if value==even_value_max:
        even_numbers.append(key)
for key,value in odds.items():
    if value==odds_value_max:
        odds_numbers.append(key)
if len(evens)==1 and len(odds)==1 and v[0]==v[1]:
    answer=N//2
elif len(even_numbers)>=2 or len(odds_numbers)>=2:
    answer=N-even_value_max-odds_value_max
else:
    even=even_numbers[0]
    odd=odds_numbers[0]
    if even!=odd:
        answer=N-even_value_max-odds_value_max
    else:
        evens[even]=0
        odds[odd]=0
        if max(odds.values())>=max(evens.values()):
            answer=N-max(odds.values())-even_value_max
        else:
            answer=N-max(evens.values())-odds_value_max
print(answer)

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
even = [v[2*i] for i in range(n//2)]
odd = [v[2*i+1] for i in range(n//2)]
dEven = collections.Counter(even).most_common()
dOdd = collections.Counter(odd).most_common()
if dEven[0][0] != dOdd[0][0]:
    ans = n - dEven[0][1]  - dOdd[0][1]
else:
    if len(dEven) >=2 and len(dOdd) >= 2:
        ans = n - max(dEven[0][1]+dOdd[1][1], dEven[1][1]+dOdd[0][1])
    elif len(dEven) < len(dOdd):
        ans = n - (dEven[0][1]+dOdd[1][1])
    elif len(dEven) > len(dOdd):
        ans = n - (dEven[1][1]+dOdd[0][1])
    else:
        ans = n//2
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
ev = Counter([v[i] for i in range(0, n, 2)])
od = Counter([v[i] for i in range(1, n, 2)])
evk = list(ev.keys())
odk = list(od.keys())
ev_key = evk[0]
for k in evk:
    if ev[k] > ev[ev_key]:
        ev_key = k
od_key = odk[0]
for k in odk:
    if od[k] > od[od_key]:
        od_key = k
evv = list(ev.values()) + [0]
evv.sort(reverse = True)
odv = list(od.values()) + [0]
odv.sort(reverse = True)

if ev_key != od_key:
    print(n - evv[0] - odv[0])
else:
    print(min(n - evv[0] - odv[1], n - evv[1] - odv[0]))

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]

one=[]
two=[]

for i in range(n):
    if i%2==0:
        one.append(a[i])
    else:
        two.append(a[i])

one_count=[0]*(10**5+1)
two_count=[0]*(10**5+1)

for i in one:
    one_count[i]+=1
for i in two:
    two_count[i]+=1

one_first_index=0
one_max_count=0
for i,value in enumerate(one_count):
    if one_max_count<value:
        one_max_count=value
        one_first_index=i
one_second_index=0
one_second_max_count=0
for i,value in enumerate(one_count):
    if one_second_max_count<value and i!=one_first_index:
        one_second_max_count=value
        one_second_index=i

two_first_index=0
two_max_count=0
for i,value in enumerate(two_count):
    if two_max_count<value:
        two_max_count=value
        two_first_index=i
two_second_index=0
two_second_max_count=0
for i,value in enumerate(two_count):
    if two_second_max_count<value and i!=two_first_index:
        two_second_max_count=value
        two_second_index=i



if one_first_index!=two_first_index:
    print(n-one_max_count-two_max_count)
elif one_max_count-one_second_max_count<=two_max_count-two_second_max_count:
    print(n - one_second_max_count - two_max_count)
else:
    print(n - two_second_max_count - one_max_count)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
import collections as col
o=col.Counter(v[0:n:2])
e=col.Counter(v[1:n:2])
ook=o.most_common()
eok=e.most_common()
ok=ook[0][1]+eok[0][1]
if ook[0][0]==eok[0][0]:
    if len(ook)<2 and len(eok)<2:
        print(n//2)
        exit()
    elif len(ook)<2:
        ok=ook[0][1]+eok[1][1]
    elif len(eok)<2:
        ok=ook[1][1]+eok[0][1]
    else:
        ok=max(ook[0][1]+eok[1][1],ook[1][1]+eok[0][1])
print(n-ok)

Solution (Python):
import collections

n = int(input())
a = list(map(int,input().split()))
a1 = collections.Counter(a[0::2]).most_common()
a2 = collections.Counter(a[1::2]).most_common()
a1.append((0,0))
a2.append((0,0))



if a1[0] != a2[0]:
    print(n-a1[0][1]-a2[0][1])
else:
    print(min(n-a1[0][1]-a2[1][1],n-a1[1][1]-a2[0][1]))

Solution (Python):
N=int(input())
*V,=map(int,input().split())
from collections import Counter

c1=Counter(V[0::2]).most_common()+[(0,0)]
c2=Counter(V[1::2]).most_common()+[(0,0)]
if c1[0][0]!=c2[0][0]:
    print(N-c1[0][1]-c2[0][1])
else:
    print(min(N-c1[0][1]-c2[1][1],N-c1[1][1]-c2[0][1]))

Solution (Python):
N=int(input())
*V,=map(int,input().split())
import collections

c1=collections.Counter(V[0::2]).most_common()
c2=collections.Counter(V[1::2]).most_common()
c1.append([0,0])
c2.append([0,0])
if c1[0][0]!=c2[0][0]:
    print(N-c1[0][1]-c2[0][1])
else:
    print(min(N-c1[0][1]-c2[1][1],N-c1[1][1]-c2[0][1]))

Solution (Python):
N=int(input())
*V,=map(int,input().split())
import collections

import collections

c1=collections.Counter(V[0::2])
c1=sorted(c1.items(), key=lambda x: x[1], reverse=True)
e=c1[0][0]

c2=collections.Counter(V[1::2])
c2=sorted(c2.items(), key=lambda x: x[1], reverse=True)
o=c2[0][0]

cnt=0
if e!=o:
    cnt=sum(e!=i for i in V[0::2])
    cnt+=sum(o!=i for i in V[1::2])
else:
    if len(c1)==1 and len(c2)==1:
        cnt=N//2
    elif len(c1)==1:
        cnt1=sum(e!=i for i in V[0::2])
        cnt1+=sum(c2[1][0]!=i for i in V[1::2])
        
        cnt2=sum(e!=i for i in V[0::2])
        cnt2+=sum(c2[1][1]!=i for i in V[1::2])
        cnt=min(cnt1,cnt2)
    elif len(c2)==1:
        cnt1=sum(c1[1][0]!=i for i in V[0::2])
        cnt1+=sum(o!=i for i in V[1::2])

        cnt2=sum(c1[1][1]!=i for i in V[0::2])
        cnt2+=sum(o!=i for i in V[1::2])
        cnt=min(cnt1,cnt2)
    else:    
        cnt1=sum(e!=i for i in V[0::2])
        cnt1+=sum(c2[1][0]!=i for i in V[1::2])
        
        cnt2=sum(c1[1][0]!=i for i in V[0::2])
        cnt2+=sum(o!=i for i in V[1::2])
        cnt=min(cnt1,cnt2)
print(cnt)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
kisu = []
gusu = []
for i in range(n):
    if i % 2 == 0:
        kisu.append(v[i])
    else:
        gusu.append(v[i])
k = sorted(Counter(kisu).items(), key=lambda x: x[1], reverse=True)
g = sorted(Counter(gusu).items(), key=lambda x: x[1], reverse=True)
ans1 = 0
ans2 = 0

if k[0][0] == g[0][0]:
    if k[0][1] > g[0][1]:
        ans1 = (n//2) - k[0][1]
        if len(g) < 2:
            ans2 = n // 2
        else:
            ans2 = (n//2) - g[1][1]
    elif k[0][1] < g[0][1]:
        ans1 = (n//2) - g[0][1]
        if len(k) < 2:
            ans2 = n // 2
        else:
            ans2 = (n//2) - k[1][1]
    else:
        if len(k) < 2:
            ans2 = n // 2
        else:
            if k[1][1] == g[1][1]:
                ans1 = (n // 2) - k[0][1]
                ans2 = (n // 2) - g[1][1]
            elif k[1][1] > g[1][1]:
                ans1 = (n // 2) - k[1][1]
                ans2 = (n // 2) - g[0][1]
            else:
                ans1 = (n // 2) - k[0][1]
                ans2 = (n // 2) - g[1][1]
else:
    ans1 = (n // 2) - k[0][1]
    ans2 = (n // 2) - g[0][1]
print(ans1 + ans2)

Solution (Python):

from collections import Counter

N = int(input())
X = list(map(int, input().split()))

evens = Counter(X[::2]).most_common()
odds = Counter(X[1::2]).most_common()

evens.append((0, 0))
odds.append((0, 0))

if evens[0][0] != odds[0][0]:
    print(N - evens[0][1] - odds[0][1])
else:
    print(min(N - evens[0][1] - odds[1][1], N - evens[1][1] - odds[0][1]))

Solution (Python):
from collections import Counter
def main():
    N = int(input())
    V = [int(a) for a in input().split()]
    
    even = list()
    odd = list()

    for i in range(N):
        if (i + 1) % 2 == 0:
            odd.append(V[i])
        else:
            even.append(V[i])

    even_counter = Counter(even).most_common()
    odd_counter = Counter(odd).most_common()

    ans = 0
    if even_counter[0][0] != odd_counter[0][0]:
        if len(even_counter) >= 2:
            ans += len(even) - even_counter[0][1]

        if len(odd_counter) >= 2:
            ans += len(odd) - odd_counter[0][1]

    else:
        if len(even_counter) == 1 and len(odd_counter) == 1:
            ans += even_counter[0][1]

        elif len(even_counter) == 1 and len(odd_counter) >= 2:
            ans += len(odd) - odd_counter[1][1]

        elif len(even_counter) >= 2  and len(odd_counter) == 1:
            ans += len(even) - even_counter[1][1]

        elif len(even_counter) >= 2 and len(odd_counter) >= 2:
            cost_even = len(even) - even_counter[0][1] + len(odd)  - odd_counter[1][1]
            cost_odd  = len(odd)  - odd_counter[0][1]  + len(even) - even_counter[1][1]
            ans += min(cost_even, cost_odd)

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
def main():
    N = int(input())
    V = [int(a) for a in input().split()]
    
    even = list()
    odd = list()

    for i in range(N):
        if (i + 1) % 2 == 0:
            odd.append(V[i])
        else:
            even.append(V[i])

    even_counter = Counter(even).most_common()
    odd_counter = Counter(odd).most_common()

    ans = 0
    if even_counter[0][0] != odd_counter[0][0]:
        if len(even_counter) >= 2:
            ans += len(even) - even_counter[0][1]

        if len(odd_counter) >= 2:
            ans += len(odd) - odd_counter[0][1]

    else:
        if len(even_counter) == 1 and len(odd_counter) == 1:
            ans += even_counter[0][1]

        elif len(even_counter) == 1 and len(odd_counter) >= 2:
            ans += len(odd) - odd_counter[1][1]

        elif len(even_counter) >= 2  and len(odd_counter) == 1:
            ans += len(even) - even_counter[1][1]

        elif len(even_counter) >= 2 and len(odd_counter) >= 2:
            cost_even = len(even) - even_counter[0][1] + len(odd)  - odd_counter[1][1]
            cost_odd  = len(odd)  - odd_counter[0][1]  + len(even) - even_counter[1][1]

            ans += min(cost_even, cost_odd)

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
B = {}
C = {}
for i, a in enumerate(A):
  if i % 2 == 0:
    B[a] = B.get(a, 0) + 1
  else:
    C[a] = C.get(a, 0) + 1
Bs = sorted(B.items(), key = lambda x: x[1], reverse = True)
Cs = sorted(C.items(), key = lambda x: x[1], reverse = True)
if Bs[0][0] != Cs[0][0]:
  print(n - Bs[0][1] - Cs[0][1])
elif len(Bs) == 1:
  if len(Cs) == 1:
    print(n // 2)
  else:
    print(n - Bs[0][1] - Cs[1][1])
else:
  if len(Cs) == 1:
    print(n - Bs[1][1] - Cs[0][1])
  else:
    print(min(n - Bs[0][1] - Cs[1][1], n - Bs[1][1] - Cs[0][1]))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
l1=[0]*100001
l2=[0]*100001
if a.count(a[0])==n:
    print(n//2)
    exit()

for i in range(0,n,2):
    l1[a[i]]+=1
for i in range(1,n,2):
    l2[a[i]]+=1

x,y=max(l1),max(l2)

i_x,i_y=l1.index(x),l2.index(y)


L1=sorted(l1,reverse=True)
L2=sorted(l2,reverse=True)

if i_x == i_y:
    
    ans=min(((n//2-L1[1])+(n//2-L2[0])),((n//2-L1[0])+(n//2-L2[1])))
else:
    ans=((n//2-L1[0])+(n//2-L2[0]))
print(ans)

Solution (Python):
n = int(input())
al = list(map(int, input().split()))

ol =al[::2]
el =al[1::2]

from collections import Counter
col = Counter(ol)
cel = Counter(el)
scol = sorted(col.items(), key=lambda x: x[1], reverse=True)  
scel = sorted(cel.items(), key=lambda x: x[1], reverse=True)  
scol.append(("x",0))
scel.append(("y",0))


temp = scol[0][1] + scel[0][1]

if scol[0][0]==scel[0][0]:
    temp2 = scol[0][1]+scel[1][1]
    temp3 = scol[1][1]+scel[0][1]
    print(n-max(temp2,temp3))
    
else:
    print(n-temp)

Solution (Python):
from collections import *
n=int(input())
l=list(map(int,input().split()))
x,y=[],[]
c=0
for i in range(0,n,2):
    x.append(l[i])
for i in range(1,n,2):
    y.append(l[i])
xx=-1
if(len(set(x))==1):
    xx=x[0]
else:
    d=defaultdict(int)
    for i in x:
        d[i]+=1
    m=0
    xx=-1
    for i in d:
        if(d[i]>m):
            xx=i
            m=d[i]
    c+=sum(d.values())-m
if(len(set(y))>1 or (len(set(y))==1 and y[0]==xx)):
    d=defaultdict(int)
    for i in y:
        d[i]+=1
    m=0
    yy=-1
    for i in d:
        if(d[i]>m and i!=xx):
            yy=i
            m=d[i]
    c+=sum(d.values())-m
cc=0
yy=-1
if(len(set(y))==1):
    yy=y[0]
else:
    d=defaultdict(int)
    for i in y:
        d[i]+=1
    m=0
    yy=-1
    for i in d:
        if(d[i]>m):
            yy=i
            m=d[i]
    cc+=sum(d.values())-m
if(len(set(x))>1 or (len(set(x))==1 and x[0]==yy)):
    d=defaultdict(int)
    for i in x:
        d[i]+=1
    m=0
    xx=-1
    for i in d:
        if(d[i]>m and i!=yy):
            xx=i
            m=d[i]
    cc+=sum(d.values())-m
print(min(cc,c))

Solution (Python):
import collections

def main():
    n = int(input())
    V = list(map(int, input().split()))
    if len(set(V)) == 1:
        print(n // 2)
        exit()
    evens = []
    odds = []
    for idx, v in enumerate(V, start=1):
        if idx % 2 == 0:
            evens.append(v)
        else:
            odds.append(v)
    c_even = collections.Counter(evens)
    c_odd = collections.Counter(odds)
    even_most_common = c_even.most_common()[0]
    odd_most_common = c_odd.most_common()[0]

    if even_most_common[0] != odd_most_common[0]:
        print(count_replace(c_even, even_most_common[0], c_odd, odd_most_common[0], n))
    else:
        even_second_most_common = c_even.most_common()[1]
        odd_second_most_common = c_odd.most_common()[1]
        vals = []
        vals.append(count_replace(c_even, even_most_common[0], c_odd, odd_second_most_common[0], n))
        vals.append(count_replace(c_even, even_second_most_common[0], c_odd, odd_most_common[0], n))
        print(min(vals))


def count_replace(c_even, even, c_odd, odd, n):
    return n - c_even[even] - c_odd[odd]


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
vs = list(map(int, input().split()))

eq_lis = []
odd_lis = []
for i in range(n):
    if i %2 ==0:
        eq_lis.append(vs[i])
    else:
        odd_lis.append(vs[i])
        
a = Counter(eq_lis)
b = Counter(odd_lis)
a_val = list(a.values())
b_val = list(b.values())
a_max = max(a_val)
b_max = max(b_val)

a_sorted = sorted(a.items(), key= lambda x:x[1])
b_sorted = sorted(b.items(), key= lambda x:x[1])

if a_sorted[-1][0] == b_sorted[-1][0]:
    if len(a_sorted) == 1 and len(b_sorted) == 1:
        print(n-a_max)
    elif len(a_sorted)==1 and len(b_sorted) >1:
        print(n-a_max-b_sorted[-2][1])
    elif len(a_sorted)>1 and len(b_sorted) ==1:
        print(n-b_max-a_sorted[-2][1])
    else:
        if b_sorted[-2][1] >= a_sorted[-2][1]:
            print(n-a_max-b_sorted[-2][1])
        else:
            print(n-b_max-a_sorted[-2][1])    
else:
    print(n-a_max-b_max)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = Counter(v[::2])
b = Counter(v[1::2])
a = a.most_common()
b = b.most_common()
a1 = a[0][1]
b1 = b[0][1]
if len(a) == 1:
    a2 = 0
else:
    a2 = a[1][1]
if len(b) == 1:
    b2 = 0
else:
    b2 = b[1][1]
if a[0][0] != b[0][0]:
    print(n-(a1+b1))
else:
    print(min(n-(a1+b2),n-(a2+b1)))

Solution (Python):
n=int(input())

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

lisa=[0 for _ in range(10**5)]
lisb=[0 for _ in range(10**5)]

for i in range(n):
  if i%2==0:
    lisa[v[i]-1]+=1
  else:
    lisb[v[i]-1]+=1

maxnuma=-1
maxnumb=-1

maxa=max(lisa)
maxb=max(lisb)


for i in range(10**5):
  if lisa[i]==maxa:
    maxnuma=i
for i in range(10**5):
  if lisb[i]==maxb:
    maxnumb=i


if maxnuma!=maxnumb:
  print(n-maxa-maxb)
else:
  lisa.sort(reverse=True)
  lisb.sort(reverse=True)
  print(n-max(lisa[0]+lisb[1],lisa[1]+lisb[0]))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
l1 = []
l2 = []
for i in range(n):
    if i % 2 == 0:
        l1.append(v[i])
    else:
        l2.append(v[i])
if Counter(l1).most_common()[0][0] != Counter(l2).most_common()[0][0]:
    print(len(l1)-Counter(l1).most_common()[0][1]+len(l2)-Counter(l2).most_common()[0][1])
elif min(len(set(l1)), len(set(l2))) >= 2:
    print(min(len(l1)-Counter(l1).most_common()[0][1]+len(l2)-Counter(l2).most_common()[1][1], len(l1)-Counter(l1).most_common()[1][1]+len(l2)-Counter(l2).most_common()[0][1]))
elif len(set(l1)) > 1:
    print(len(l1)-Counter(l1).most_common()[1][1]+len(l2)-Counter(l2).most_common()[0][1])
elif len(set(l2)) > 1:
    print(len(l1)-Counter(l1).most_common()[0][1]+len(l2)-Counter(l2).most_common()[1][1])
else:
    print(n//2)

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

v_even = [0]*100000
v_odd = [0]*100000

for i in range(n):
  if i%2==0:
    v_even[v[i]-1] += 1 
  else:
    v_odd[v[i]-1] += 1
    
res1 = max(v_even)
res2 = max(v_odd)
if v_even.index(res1) == v_odd.index(res2):
  if res1 > res2:
    v_odd[v_odd.index(res2)] = 0
    res2 = max(v_odd)
  elif res2 > res1:
    v_even[v_even.index(res1)] = 0
    res1 = max(v_even)
  elif res1 == res2:
    v_odd[v_odd.index(res2)] = 0
    v_even[v_even.index(res1)] = 0
    res3 = max(v_even)
    res4 = max(v_odd)
    if res3 > res4:
      res1 = res3
    else:
      res2 = res4
      
print(n//2-res1 + n//2-res2)

Solution (Python):
from collections import Counter

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

v0=list(Counter(v[::2]).items())
v1=list(Counter(v[1::2]).items())

v0.sort(key=lambda x:x[1],reverse=True)
v1.sort(key=lambda x:x[1],reverse=True)

k0,ma0=v0[0]
k1,ma1=v1[0]

if k0==k1 and len(v0)==1 and len(v1)==1:
    print(n//2)
elif k0==k1 and len(v0)==1:
    print((n+1)//2-v1[1][1]+n//2-ma0)
elif k0==k1 and len(v1)==1:
    print(n//2-v0[1][1]+(n+1)//2-ma1)
elif k0==k1:
    print(min((n+1)//2-v1[1][1]+n//2-ma0,n//2-v0[1][1]+(n+1)//2-ma1))
else:
    print((n+1)//2-ma0+n//2-ma1)