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):
import collections
n = int(input())
v = list(map(int, input().split()))

x = []
y = []
for i in range(n):
    if (i + 1) % 2 == 1:
        x.append(v[i])
    else:
        y.append(v[i])

xcnt = collections.Counter(x)
ycnt = collections.Counter(y)

x_max = []
if len(xcnt) > 1:
    x_max.append(xcnt.most_common()[0])
    x_max.append(xcnt.most_common()[1])
else:
    x_max.append(xcnt.most_common()[0])
    x_max.append(xcnt.most_common()[0])

y_max = []
if len(ycnt) > 1:
    y_max.append(ycnt.most_common()[0])
    y_max.append(ycnt.most_common()[1])
else:
    y_max.append(ycnt.most_common()[0])
    y_max.append(ycnt.most_common()[0])

ans = float("inf")
for i in range(2):
    for j in range(2):
        if x_max[i][0] != y_max[j][0]:
            sub = n - x_max[i][1] - y_max[j][1]
            ans = min(ans, sub)
if ans == float("inf"):
    ans = n // 2
print(ans)

Solution (Python):






import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


n = read_a_int()
V = read_ints()

from collections import Counter
gu = Counter(V[0::2]).most_common()
ki = Counter(V[1::2]).most_common()

c = gu[0][1] + ki[0][1]
if gu[0][0] == ki[0][0]:
    c //= 2
    if len(gu) == 1 and len(ki) == 1:
        pass
    elif len(gu) == 1:
        c += ki[1][1]
    elif len(ki) == 1:
        c += ki[1][1]
    else:
        c += max(gu[1][1], ki[1][1])

print(n - c)

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
odd=Counter(v[::2]).most_common(2)
odd.append((0,0))
even=Counter(v[1::2]).most_common(2)
even.append((0,0))
if odd[0][0]==even[0][0]:
	ans=min(n-odd[0][1]-even[1][1],n-odd[1][1]-even[0][1])
else:
	ans=n-odd[0][1]-even[0][1]
print(ans)

Solution (Python):


n = int(input())
a = list(map(int,input().split()))
cnt_odd = [0]*(10**5+1)
cnt_even = [0]*(10**5+1)
for i in range(n):
    if i  %2: cnt_odd[a[i]] += 1
    else: cnt_even[a[i]] += 1
odd,idx_odd=zip(*sorted(zip(cnt_odd,list(range(10**5+1)))))
even,idx_even=zip(*sorted(zip(cnt_even,list(range(10**5+1)))))

if idx_even[-1]!=idx_odd[-1]:
    print(n - odd[-1] - even[-1])
else:
    print(n - max(odd[-1]+even[-2],odd[-2]+even[-1]))

Solution (Python):
n, *v = map(int, open(0).read().split())
a, b = [[[0, 0] for i in range(100000)] for i in (1,1)]
for i in range(n):
        if i%2:
                b[v[i]-1][0] += 1
                b[v[i]-1][1] = v[i]
        else:
                a[v[i]-1][0] += 1
                a[v[i]-1][1] = v[i]
a.sort(key=lambda x:-x[0]);
b.sort(key=lambda x:-x[0]);

if a[0][1]==b[0][1]:
        print(n-max(a[0][0]+b[1][0], a[1][0]+b[0][0]))
else: print(n-a[0][0]-b[0][0])

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
if len(set(l))==1:print(n//2)
else:
  x,y=sorted(l[::2]),sorted(l[1::2])
  from collections import Counter as co
  ans=0
  mx,my=co(x).most_common(100),co(y).most_common(100)
  for i in mx:
    for j in my:
      k=i[1]+j[1] if i[0]!=j[0] else 0
      ans=max(ans,k)
  print(n-ans)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c1 = Counter(A[::2])  
    c2 = Counter(A[1::2])  
    c1_n = N//2 + 1 if N & 1 else N//2
    c2_n = N//2
    ans = 0
    if c1.most_common()[0][0] != c2.most_common()[0][0]:
        ans += c1_n - c1.most_common()[0][1]
        ans += c2_n - c2.most_common()[0][1]
    else:
        
        x = c1_n - c1.most_common()[0][1]
        y = c2_n - c2.most_common()[0][1]
        p = c1_n - c1.most_common()[1][1] if x != 0 else c1.most_common()[0][1]
        q = c2_n - c2.most_common()[1][1] if y != 0 else c2.most_common()[0][1]
        
        ans = min(p+y, x+q)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
o = []
e = []
for k in range(n):
    if k%2 == 0:
        e.append(a[k])
    else:
        o.append(a[k])

C1 = Counter(e).most_common()
C2 = Counter(o).most_common()
if C1[0][0] != C2[0][0]:
    print(n-C1[0][1]-C2[0][1])
else:
    if len(C1) == len(C2) == 1:
        print(n//2)
    elif len(C1) == 1 and len(C2) > 1:
        print(n//2 - C2[1][1])
    elif len(C1) > 1 and len(C2) == 1:
        print(n//2 - C1[1][1])
    else:
        print(min(n-C1[1][1]-C2[0][1],n-C1[0][1]-C2[1][1]))

Solution (Python):
import itertools
from collections import Counter
 
N = int(input())
V = [int(x) for x in input().split()]

EV_counter = Counter(V[::2])
OD_counter = Counter(V[1::2])
EV_counter[-1] = 0
OD_counter[-2] = 0
EV = EV_counter.most_common(2)
OD = OD_counter.most_common(2)




answer = N
for (k1,v1), (k2,v2) in itertools.product(EV,OD):
    
    if k1 == k2:
        continue
    x = (N - v1 - v2)
    if answer > x:
        answer = x 

print(answer)

Solution (Python):
from collections import Counter

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

oc = Counter(v[0::2]).most_common() + [(0, 0)]
ec = Counter(v[1::2]).most_common() + [(0, 0)]

if oc[0][0] != ec[0][0]:
    print(n - (oc[0][1] + ec[0][1]))
else:
    print(min(n - (oc[1][1] + ec[0][1]), n - (oc[0][1] + ec[1][1])))

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

A = []
B = []
for i in range(n):
    if i%2==0:A.append(v[i])
    else:B.append(v[i])
A = Counter(A).most_common(2)
B = Counter(B).most_common(2)
A.append((-1,0))
B.append((-2,0))
ans = float("inf")
if A[0][0]==B[0][0]:
    ans = min(n-A[0][1]-B[1][1],n-A[1][1]-B[0][1])
else:
    ans = n-A[0][1]-B[0][1]
print(ans)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
v1 = [v[2*i] for i in range(n//2)]

if len(set(v))==1:
    print(n//2)
    exit()
d1 = {}
for x in v1:
    if x in d1.keys():
        d1[x] = d1[x] + 1
    else:
        d1[x] = 1
d1 = sorted(d1.items(), key=lambda x:-x[1])

d2 = {}
v2 = [v[2*i+1] for i in range(n//2)]
ma2=0
for x in v2:
    if x in d2.keys():
        d2[x] = d2[x] + 1
    else:
        d2[x] = 1
d2 = sorted(d2.items(), key=lambda x:-x[1])
if d1[0][0] != d2[0][0]:
    print(n-d1[0][1]-d2[0][1])
else:
    if len(d1) == 1:
        print(n-d1[0][1]-d2[1][1])
    elif len(d2) == 1:
        print(n-d1[1][1]-d2[0][1])
    else:
        print(n-max(d1[0][1]+d2[1][1],d1[1][1]+d2[0][1]))

Solution (Python):
from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

Voc = Counter(Vodd)
Vec = Counter(Veven)

Voc_val, Voc_cnt = zip(*Voc.most_common())
Vec_val, Vec_cnt = zip(*Vec.most_common())

Voc_val, Voc_cnt = list(Voc_val), list(Voc_cnt)
Vec_val, Vec_cnt = list(Vec_val), list(Vec_cnt)

num = Voc.most_common()[0][1] + Vec.most_common()[0][1]

if Voc_val[0] == Vec_val[0]:
    Voc_cnt.append(0)
    Vec_cnt.append(0)
    num += max(Voc_cnt[1] - Voc_cnt[0], Vec_cnt[1] - Vec_cnt[0])

print(n - num)

Solution (Python):
import collections

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])

counter1 = collections.Counter(l1)
counter2 = collections.Counter(l2)

mode_v1 = counter1.most_common()
mode_v2 = counter2.most_common()


if mode_v1[0][0] != mode_v2[0][0]:
    print(n - mode_v1[0][1] - mode_v2[0][1])
else:
    if len(set(v)) == 1:
        print(n // 2)
    elif len(set(l1)) == 1:
        print(mode_v2[0][1])
    elif len(set(l2)) == 1:
        print(mode_v1[0][1])
    else:
        print(min(n - mode_v1[0][1] - mode_v2[1][1], n - mode_v1[1][1] - mode_v2[0][1]))

Solution (Python):
from collections import defaultdict
n = int(input())
v = list(map(int,input().split()))
a = v[::2]
b = v[1::2]
def calc(l):
    d = defaultdict(int)
    for x in l:
        d[x] += 1
    return sorted([(d[x], x) for x in d],reverse=True)
A = calc(a)
B = calc(b)
al,ax = A[0]
bl,bx = B[0]
if ax != bx:
    print(n-al-bl)
else:
    ar,ay = A[1] if len(A) > 1 else (0,None)
    br,by = B[1] if len(B) > 1 else (0,None)
    print(min(n-al-br,n-ar-bl))

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

arr = [int(s) for s in input().split(" ")]

def calculate(n, arr):
    evenDict = {}
    oddDict = {}

    for i in range(0, n, 2):
        if oddDict.get(arr[i]) == None:
            oddDict.__setitem__(arr[i], 1)
        else:
            oddDict.__setitem__(arr[i], oddDict.get(arr[i]) + 1)

    for i in range(1, n, 2):
        if evenDict.get(arr[i]) == None:
            evenDict.__setitem__(arr[i], 1)
        else:
            evenDict.__setitem__(arr[i], evenDict.get(arr[i]) + 1)

    if (len(evenDict.values()) == 1) and (len(oddDict.values()) == 1):
        if arr[0] == arr[1]:
            return n // 2

    evenMaxIndex = max(evenDict, key=evenDict.get)
    oddMaxIndex = max(oddDict, key=oddDict.get)
    s1 = (n // 2) - evenDict[evenMaxIndex]
    s2 = (n - n // 2) - oddDict[oddMaxIndex]
    m1 = s1 + s2

    if evenMaxIndex == oddMaxIndex:
        if len(evenDict.items()) != 1 and len(oddDict.items()) != 1:
            evenDict.pop(evenMaxIndex)
            evenSecondMaxIndex = max(evenDict, key=evenDict.get)
            evenSecondMaxvalue = evenDict[evenSecondMaxIndex]
            oddDict.pop(oddMaxIndex)
            oddSecondMaxIndex = max(oddDict, key=oddDict.get)
            oddSecondMaxValue = oddDict[oddSecondMaxIndex]

            m2 = (n - n // 2) - oddSecondMaxValue
            m3 = (n // 2) - evenSecondMaxvalue

            return min(s2+m2,s1+m3)

        if len(evenDict.items()) == 1 and len(oddDict.items()) != 1:
            oddDict.pop(oddMaxIndex)
            oddSecondMaxIndex = max(oddDict, key=oddDict.get)
            oddSecondMaxValue = oddDict[oddSecondMaxIndex]
            m2 =  s1 + (n - n // 2) - oddSecondMaxValue
            return m2

        if len(evenDict.items()) != 1 and len(oddDict.items()) == 1:
            evenDict.pop(evenMaxIndex)
            evenSecondMaxIndex = max(evenDict, key=evenDict.get)
            evenSecondMaxvalue = evenDict[evenSecondMaxIndex]
            m3 =  s2 + (n // 2) - evenSecondMaxvalue
            return m3




    return (s1 + s2)


result = calculate(n, arr)

print(result)

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

d1 = {}
d2 = {}
for i in range(n):
    if i % 2 == 0:
        if v[i] in d1:
            d1[v[i]] += 1
        else:
            d1[v[i]] = 1
    elif i % 2 == 1:
        if v[i] in d2:
            d2[v[i]] += 1
        else:
            d2[v[i]] = 1
l1 = list(d1.items())
l1 = sorted(l1, key=lambda x: x[1], reverse=True)
l2 = list(d2.items())
l2 = sorted(l2, key=lambda x: x[1], reverse=True)


if l1[0][0] != l2[0][0]:
    ans = n - l1[0][1] - l2[0][1]
    print(ans)
    sys.exit(0)


if len(l1) == len(l2) == 1 and l1[0][0] == l2[0][0]:
    print(int(n/2))


elif len(l1) >= 2 and len(l2) == 1:
    ans = n - l1[1][1] - l2[0][1]
    print(ans)


elif len(l1) == 1 and len(l2) >= 2:
    ans = n - l1[0][1] - l2[1][1]
    print(ans)
elif len(l1) >= 2 and len(l2) >= 2:
    ans = min(n - l1[0][1] - l2[1][1], n - l1[1][1] - l2[0][1])
    print(ans)

Solution (Python):

from collections import Counter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def calc():
    ans = 0
    for i in range(len(v)):
        if i % 2 == 0:
            if v[i] != f:
                ans += 1
        else:
            if v[i] != f2:
                ans += 1
    return ans


n = int(input())
v = list(map(int, input().split()))
V1 = Counter(v[::2]).most_common()
V2 = Counter(v[1::2]).most_common()
f = V1[0][0]
f2 = V2[0][0]
if f == f2:
    if len(V2) > 1:
        f2 = V2[1][0]
    else:
        f2 = 'x'
    a = calc()
    if len(V1) > 1:
        f = V1[1][0]
    else:
        f = 'x'
    f2 = V2[0][0]
    print(min(a, calc()))
else:
    print(calc())

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

    even=Counter(A[::2]).most_common()
    odd=Counter(A[1::2]).most_common()
    
    if even[0][0]!=odd[0][0]:
        ans=n-even[0][1]-odd[0][1]
    else:
        ans=0
        if len(even)>1:
            ans=max(even[1][1]+odd[0][1],ans)
        if len(odd)>1:
            ans=max(even[0][1]+odd[1][1],ans)
        else:
            ans=max(even[0][1],odd[0][1],ans)
        ans=n-ans
    print(ans)
if __name__=='__main__':
    main()

Solution (Python):

from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=[v[2*i] for i in range(n//2)]
v2=[v[2*i+1] for i in range(n//2)]

V1=Counter(v1).most_common()
V2=Counter(v2).most_common()

V1.append((0,0))
V2.append((0,0))

Ans=n-V1[0][1]-V2[0][1]

if V1[0][0]==V2[0][0]:
    Ans+=min(V1[0][1]-V1[1][1],V2[0][1]-V2[1][1])
     
print(Ans)

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

lis1 = [v[i] for i in range(n) if i%2==0]
lis2 = [v[i] for i in range(n) if i%2!=0]

c1 = collections.Counter(lis1).most_common()
c2 = collections.Counter(lis2).most_common()
c1.append((0,0)) 
c2.append((0,0)) 

m=n//2 
if c1[0][0]==c2[0][0]:
    p1 = m-c1[0][1] + m-c2[1][1]
    p2 = m-c1[1][1] + m-c2[0][1]
    print(min(p1,p2))
else:
    print(m-c1[0][1] + m-c2[0][1])

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = v[0::2]
b = v[1::2]
ca = Counter(a).most_common()
cb = Counter(b).most_common()
if len(ca) == len(cb) == 1:
    if ca[0][0] == cb[0][0]:
        print(n//2)
    else:
        print(0)
elif len(ca) == 1:
    if ca[0][0] == cb[0][0]:
        print(n//2 - cb[1][1])
    else:
        print(n // 2 - cb[0][1])
elif len(cb) == 1:
    if ca[0][0] == cb[0][0]:
        print(n//2 - ca[1][1])
    else:
        print(n // 2 - ca[0][1])
else:
    if ca[0][0] == cb[0][0]:
        print(n - max(ca[1][1]+cb[0][1], cb[1][1] + ca[0][1]))
    else:
        print(n - ca[0][1] - cb[0][1])

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

l_odd = []
l_even = []
for i, value in enumerate(v, 1):
  
  if i % 2 == 1:
    l_odd.append(value)
  else:
    l_even.append(value)


co = collections.Counter(l_odd).most_common(2)
ce = collections.Counter(l_even).most_common(2)

if co[0][0] == ce[0][0]:
  if len(co) == 1:
    print(int(n/2))
  else:
    print(n - co[0][1] - max(co[1][1], ce[1][1]))
else:
  print(n - co[0][1] - ce[0][1])

Solution (Python):
import collections 
n = int(input())
v = list(map(int,input().split()))
if len(set(v)) == 1:
    print(n//2)
    exit()
cnt = 0
e = []
o = []
for i in range(n):
    if (i+1) % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
E = collections.Counter(e)
O = collections.Counter(o)
list_e = []
list_o = []
set_e = set(e)
set_o = set(o)
E_1 = E.most_common()[0][0]
if len(set_e) != 1:
    E_2 = E.most_common()[1][0]
    E_2_kosu = E.most_common()[1][1]
else:
    E_2 = E.most_common()[0][0]
    E_2_kosu = E.most_common()[0][1]

O_1 = O.most_common()[0][0]
if len(set_o) != 1:
    O_2 = O.most_common()[1][0]
    O_2_kosu = O.most_common()[1][1]
else:
    O_2 = O.most_common()[0][0]
    O_2_kosu = O.most_common()[0][1]

if E_1 != O_1:
    ans = n - E.most_common()[0][1] - O.most_common()[0][1]
else:
    ans = min(n-E_2_kosu-O.most_common()[0][1],n-E.most_common()[0][1]-O_2_kosu)
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = [int(x) for x in input().split()]

v_odd = [v[x] for x in range(n) if x % 2 != 0]
v_eve = [v[x] for x in range(n) if x % 2 == 0]

odd_c = Counter(v_odd).most_common() + [(0,0)]
eve_c = Counter(v_eve).most_common() + [(0,0)]

if odd_c[0][0] != eve_c[0][0]:
    print(n - odd_c[0][1] - eve_c[0][1])
else:
    print(n - max(odd_c[1][1] + eve_c[0][1], odd_c[0][1] + eve_c[1][1]))

Solution (Python):
import itertools
import math
import sys
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
e = Counter(v[0::2]).most_common()
o = Counter(v[1::2]).most_common()
if len(e) == 1 and len(o) == 1:
    if e[0][0] == o[0][0]:
        print(n // 2)
    else:
        print(0)
elif len(e) == 1:
    if e[0][0] != o[0][0]:
        print(n - e[0][1] - o[0][1])
    else:
        print(n - max(e[0][1] + o[0][1], o[1][1]))
elif len(o) == 1:
    if e[0][0] != o[0][0]:
        print(n - e[0][1] - o[0][1])
    else:
        print(n - max(e[0][1] + o[0][1], e[1][1]))
else:
    if e[0][0] != o[0][0]:
        print(n - e[0][1] - o[0][1])
    else:
        print(n - max(e[0][1] + o[1][1], e[1][1] + o[0][1]))

Solution (Python):
from itertools import groupby
def main():
    _=input()
    vv=list(map(int,input().split()))
    ve=sorted(vv[0::2])
    vo=sorted(vv[1::2])
    le=len(set(ve))
    lo=len(set(vo))
    if le==lo==1:
        if ve[0]!=vo[0]:
            print(0)
            return
        else:
            print(len(ve))
            return
    if le==1 or lo==1:
        if lo==1:
            ve,vo=vo,ve
        c=0
        for k,g in groupby(vo):
            if k!=ve[0]:
                lg=len(list(g))
                if lg>c:
                    c=lg
        print(len(vo)-c)
        return
    ce=0
    ke=None
    for k,g in groupby(ve):
        lg=len(list(g))
        if lg>ce:
            ke=k
            ce=lg
    co=0
    ko=None
    for k,g in groupby(vo):
        lg=len(list(g))
        if lg>co:
            ko=k
            co=lg
    if ke!=ko:
        print(len(vo)*2-ce-co)
        return
    if ce<co:
        ke,ko=ko,ke
        ve,vo=vo,ve
        ce,co=co,ce
    if ce > co:
        c=0
        for k,g in groupby(vo):
            if k!=ke:
                lg=len(list(g))
                if lg>c:
                   c=lg
        print(len(vo)*2-c-ce)
        return
    ce2=0
    for k,g in groupby(ve):
        if k!=ke:
            lg=len(list(g))
            if lg>ce2:
               ce2=lg
    co2=0
    for k,g in groupby(vo):
        if k!=ko:
            lg=len(list(g))
            if lg>co2:
               co2=lg
    print(len(vo)*2-ce-max(ce2,co2))

main()

Solution (Python):
N = int(input())
U = list(map(int, input().split()))

tmp_even = {}
tmp_odd = {}

for i in range(N):
    u = U[i]
    if i % 2 == 0:
        if u not in tmp_even:
            tmp_even[u] = 0
        tmp_even[u] += 1
    else:
        if u not in tmp_odd:
            tmp_odd[u] = 0
        tmp_odd[u] += 1

even = [(e, tmp_even[e]) for e in tmp_even]
odd = [(o, tmp_odd[o]) for o in tmp_odd]



even.sort(reverse=True, key = lambda x: x[1])
odd.sort(reverse=True, key = lambda x: x[1])



if even[0][0] != odd[0][0]:
    print(N - even[0][1] - odd[0][1])
    exit()
if len(even) == 1 and len(odd) == 1:
    print(N // 2)
    exit()
if even[0][1] == odd[0][1]:
    if even[1][1] > odd[1][1]:
        print(N - odd[0][1] - even[1][1])
    else:
        print(N - even[0][1] - odd[1][1])
    exit()
elif even[0][1] > odd[0][1]:
    print(N - even[0][1] - odd[i][1])
else:
    print(N - even[1][1] - odd[0][1])

Solution (Python):
n = int(input())
v = list(input().split())
def f(b):
  h = v[b::2]
  d = {0:0}
  for i in h: d[i] = d.get(i,0)+1
  return sorted(d.items(),key=lambda k:-k[1])
l,r = f(0),f(1)
print(n-l[0][1]-[r[0][1],max(l[1][1],r[1][1])][l[0][0] == r[0][0]])

Solution (Python):
n = int(input())
l = list(input().split())
ll,lr = l[::2],l[1::2]
dl,dr = {},{}
for i in ll: dl[i] = dl.get(i,0)+1
for j in lr: dr[j] = dr.get(j,0)+1
ltl = sorted(dl.items(),key=lambda k:-k[1])
ltr = sorted(dr.items(),key=lambda k:-k[1])
if ltl[0][0] != ltr[0][0]:
  print(n-ltl[0][1]-ltr[0][1])
elif len(ltl)<2:
  print(n//2)
else:
  print(n-ltl[0][1]-max(ltl[1][1],ltr[1][1]))

Solution (Python):
def chkmax(ecnt):
    emax1=ecnt[0]
    vemax1=0
    if ecnt[1]>emax1:
        emax1=ecnt[1]
        vemax1=1
        emax2=ecnt[0]
    else:
        emax2=ecnt[1]
        
    for i in range(2,len(ecnt)):
        if ecnt[i]>emax1:
            emax2=emax1
            emax1=ecnt[i]
            vemax1=i
        elif ecnt[i]<=emax1 and ecnt[i]>emax2:
            emax2=ecnt[i]
    return emax1,emax2,vemax1    

n=int(input())
v=list(map(int,input().split()))
vmax=max(v)
vmin=min(v)

n2=n//2
ecnt=[0]*(vmax+1)
ocnt=[0]*(vmax+1)
for i in range(n2):
    ecnt[v[i*2]]=ecnt[v[i*2]]+1
    ocnt[v[i*2+1]]=ocnt[v[i*2+1]]+1

if vmax==vmin:
    print(n2)
else:
    emax1,emax2,vemax1=chkmax(ecnt)            
    omax1,omax2,vomax1=chkmax(ocnt)
    if vemax1!=vomax1:
        print(n-emax1-omax1)        
    elif emax1>omax1:
        print(n-emax1-omax2)        
    elif emax1<omax1:
        print(n-omax1-emax2)        
    else:
        if emax2<omax2:
            print(n-emax1-omax2)        
        else:
            print(n-omax1-emax2)

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

lisfnt = [0] * (max(v)+1)
lisbk = [0] * (max(v)+1)
for i in range(n):
    if i % 2 == 0:
        lisfnt[v[i]-1] += 1
    else:
        lisbk[v[i]-1] += 1

ans = sum(lisfnt) + sum(lisbk)
valfnt = 0
point = 0
for i in range(len(lisfnt)):
    if lisfnt[i] > valfnt:
        valfnt = lisfnt[i]
        point = i
valbk = 0
for i in range(len(lisbk)):
    if (lisbk[i] > valbk) and i != point:
        valbk = lisbk[i]
ans1 = ans - (valfnt + valbk)
valbk = 0
point = 0
for i in range(len(lisbk)):
    if lisbk[i] > valbk:
        valbk = lisbk[i]
        point = i
valfnt = 0
for i in range(len(lisfnt)):
    if (lisfnt[i] > valfnt) and i != point:
        valfnt = lisfnt[i]
ans2 = ans - (valfnt + valbk)

print(min(ans1,ans2))

Solution (Python):
from collections import Counter
n = int(input())
*v, = map(int, input().split())
a = Counter(v[0::2]).most_common()+[(0,0)]
b = Counter(v[1::2]).most_common()+[(0,0)]
if a[0][0] != b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(n-max(a[1][1]+b[0][1],a[0][1]+b[1][1]))

Solution (Python):
import collections

n = int(input())  
v = list(map(int, input().split()))
e = v[0::2]
o = v[1::2]
e_cnt = collections.Counter(e)
o_cnt = collections.Counter(o)
e_most = e_cnt.most_common() + ([(0, 0)])
e_most1 = e_most[0][1]
e_most2 = e_most[1][1]
o_most = o_cnt.most_common() + ([(0, 0)])
o_most1 = o_most[0][1]
o_most2 = o_most[1][1]
if e_most[0][0] != o_most[0][0]:
    print(n - e_most1 - o_most1)
else:
    print(min(n - e_most1 - o_most2, n - e_most2 - o_most1))

Solution (Python):
n = input()
vlist = list(map(int, input().split()))
gulist = {}
kilist = {}

for i in range(len(vlist)):
  x = vlist[i]

  if i % 2 == 0:
    if x not in gulist:
      gulist[x] = 0
    gulist[x] = gulist[x] + 1
  else:
    if x not in kilist:
      kilist[x] = 0
    kilist[x] = kilist[x] + 1

maxguname = 0
maxgunum = 0
maxkiname = 0
maxkinum = 0

for k, v in gulist.items():
  if maxgunum < v:
    maxguname = k
    maxgunum = v

for k, v in kilist.items():
  if maxkinum < v:
    maxkiname = k
    maxkinum = v

nextguname = 0
nextgunum = 0
nextkiname = 0
nextkinum = 0

for k, v in gulist.items():
  if maxguname == k:
    continue
  if nextgunum < v:
    nextguname = k
    nextgunum = v

for k, v in kilist.items():
  if maxkiname == k:
    continue
  if nextkinum < v:
    nextkiname = k
    nextkinum = v

maxgu = len(vlist)//2 - maxgunum
nexgu = len(vlist)//2 - nextgunum
maxki = len(vlist)//2 - maxkinum
nexki = len(vlist)//2 - nextkinum

if maxguname == maxkiname:
  if nextgunum > nextkinum:
    print(maxki + nexgu)
  else:
    print(maxgu + nexki)
else:
  print(maxgu + maxki)

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
	print (n//2)
	exit()
a = v[1::2]
b = v[0::2]
if len(set(a)) == 1 and len(set(b)) == 1:
	print (0)
	exit()
ans = 0

aa = collections.Counter(a)
bb = collections.Counter(b)

yousoa = aa.most_common()[0][0]
maa = aa.most_common()[0][1]
yousob = bb.most_common()[0][0]
mbb = bb.most_common()[0][1]
if len(set(a)) == 1:
	ans += len(b) - mbb
	print (ans)
	exit()
if len(set(b)) == 1:
	ans += len(a) - maa
	print (ans)
	exit()
maa2 = aa.most_common()[1][1]
mbb2 = bb.most_common()[1][1]
if yousoa == yousob:
	ans = min(n//2-maa + n//2-mbb2,n//2-maa2 + n//2-mbb)
	print (ans)
else:
	print (n-maa-mbb)

Solution (Python):
import collections

N = int(input())
VV = list(map(int, input().split()))
v_even = VV[::2]
v_odd = VV[1::2]

e = collections.Counter(v_even).most_common() + [(0, 0)]
o = collections.Counter(v_odd).most_common() + [(0, 0)]

if (e[0][0] == o[0][0]):
    tmp1 = e[0][1] + o[1][1]
    tmp2 = e[1][1] + o[0][1]
    answer = N - max(tmp1, tmp2)
else:
    tmp = e[0][1] + o[0][1]
    answer = N - tmp

print(answer)

Solution (Python):
import collections

N = int(input())
VV = list(map(int, input().split()))
v_even = VV[::2]
v_odd = VV[1::2]

e = collections.Counter(v_even)
o = collections.Counter(v_odd)
e_common = e.most_common()
o_common = o.most_common()


if (e_common[0] != o_common[0]):
    tmp = e_common[0][1] + o_common[0][1]
    answer = N - tmp

elif (len(e_common) == 1 or len(o_common) == 1): 
    if (len(e_common) == 1 and len(o_common) == 1):
        answer = N // 2
    elif (len(e_common) == 1):
        answer = N // 2 - o_common[1][1]
    elif (len(o_common) == 1):
        answer = N // 2 - e_common[1][1]

else:
    tmp1 = e_common[0][1] + o_common[1][1]
    tmp2 = e_common[1][1] + o_common[0][1]
    tmp = max(tmp1, tmp2)
    answer = N - tmp

print(answer)

Solution (Python):
import collections


def main():
    n = int(input())
    vn = list(map(int, input().split()))

    odd_vn = [v for i, v in enumerate(vn) if i % 2 == 0]
    even_vn = [v for i, v in enumerate(vn) if i % 2 == 1]

    odd_vn_counter = collections.Counter(odd_vn)
    even_vn_counter = collections.Counter(even_vn)

    odd_vn_mode = odd_vn_counter.most_common(2)
    even_vn_mode = even_vn_counter.most_common(2)

    odd_num = odd_vn_mode[0][0]
    even_num = even_vn_mode[0][0]

    if odd_vn_mode[0][0] == even_vn_mode[0][0]:
        if 2 <= len(odd_vn_mode) and 2 <= len(even_vn_mode):
            if odd_vn_mode[1][1] <= even_vn_mode[1][1]:
                even_num = even_vn_mode[1][0]
            else:
                odd_num = odd_vn_mode[1][0]
        elif 2 <= len(odd_vn_mode):
            odd_num = odd_vn_mode[1][0]
        elif 2 <= len(even_vn_mode):
            even_num = even_vn_mode[1][0]
        else:
            even_num = even_vn_mode[0][0] + 1

    ans = n - odd_vn.count(odd_num) - even_vn.count(even_num)
    print(ans)


main()

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

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


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


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()

nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    N = I()
    v = LI()
    first_counter = {}
    second_counter = {}

    for i in range(N):
        if i % 2 == 0:
            if v[i] not in first_counter:
                first_counter[v[i]] = 0
            first_counter[v[i]] += 1
        else:
            if v[i] not in second_counter:
                second_counter[v[i]] = 0
            second_counter[v[i]] += 1

    first_items = sorted([(v, k) for k, v in first_counter.items()], reverse=True)
    second_items = sorted([(v, k)
                           for k, v in second_counter.items()], reverse=True)

    
    first_counter, first_value = first_items.pop(0)
    second_counter, second_value = second_items.pop(0)

    first_total_count = (N + (2 - 1)) // 2
    second_total_count = N // 2

    if first_value != second_value:
        print(first_total_count - first_counter + second_total_count - second_counter)
    else:
        first_all_replace_count = first_total_count + second_total_count - second_counter
        second_all_replace_count = second_total_count + first_total_count - first_counter
        first_all_next_replace_count = 10 ** 9
        second_all_next_replace_count = 10 ** 9

        if len(first_items) > 0:
            next_first_counter, next_first_value = first_items.pop(0)
            first_all_next_replace_count = first_total_count - next_first_counter + \
                second_total_count - second_counter

        if len(second_items) > 0:
            next_second_counter, next_second_value = second_items.pop(0)
            second_all_next_replace_count = second_total_count - \
                next_second_counter + first_total_count - first_counter

        print(min(first_all_replace_count,
                  second_all_replace_count,
                  first_all_next_replace_count,
                  second_all_next_replace_count))


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
from operator import itemgetter

n = int(input())
v = [int(i) for i in input().split()]
a = sorted(Counter(v[::2]).items(), key=itemgetter(1))
b = sorted(Counter(v[1::2]).items(), key=itemgetter(1))
ka, va = a[-1]
kb, vb = b[-1]
if ka != kb:
    print(n - va - vb)
else:
    sa = a[-2][1] if len(a) > 1 else va
    sb = b[-2][1] if len(b) > 1 else vb
    if len(a) == len(b) == 1:
        sa, sb = 0, 0
    print(n - max(sa + vb, va + sb))

Solution (Python):
N = int(input())
listv = list(map(int, input().split()))
even = [listv[x] for x in range(N) if x%2 == 0]
odd = [listv[x] for x in range(N) if x%2 == 1]
import collections
evenc = collections.Counter(even)
oddc = collections.Counter(odd)
listeven = evenc.most_common()
listodd = oddc.most_common()
ae, be = listeven[0]
ao, bo = listodd[0]
if ae != ao:
    ans = N-be-bo
elif len(listeven) ==1 and len(listodd) ==1:
    ans = N/2    
elif len(listeven) == 1:
    ao1, bo1 = listodd[1]
    ans = N/2-bo1
elif len(listodd) == 1:
    ae1, be1 = listeven[1]
    ans = N/2-bo1    
else:
    ao1, bo1 = listodd[1]
    ae1, be1 = listeven[1] 
    ans = N-bo-max(bo1,be1)
print(int(ans))