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 Counter
def solve():
  ans = 0
  N = int(input())
  V = list(map(int, input().split()))
  V1 = [V[i] for i in range(0,N,2)]
  V2 = [V[i] for i in range(1,N,2)]
  v1 = Counter(V1)
  v2 = Counter(V2)
  v1 = sorted(v1.items(),key=lambda x:-x[1])
  v2 = sorted(v2.items(),key=lambda x:-x[1])
  if v1[0][0]!=v2[0][0]:
    ans = N-(v1[0][1]+v2[0][1])
  else:
    if len(v1)==1:
      if len(v2)==1:
        return N//2
      return N-(v1[0][1]+v2[1][1])
    if len(v2)==1:
      return N-(v1[1][1]+v2[0][1])
    ans = N-max(v1[1][1]+v2[0][1],v1[0][1]+v2[1][1])
  return ans
print(solve())

Solution (Python):
from collections import *
n = int(input())
v = list(map(int,input().split()))
if len(set(v))==1:
    print(len(v)//2)
    exit()
n_even = v[0::2]
n_odd = v[1::2]
a = Counter(n_even).most_common()+[(0,0)]
b = Counter(n_odd).most_common()+[(0,0)]


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):
import collections
N = int(input())
v = list(map(int,input().split()))
v1,v2 = v[::2],v[1::2]
A1 = collections.Counter(v1)
A2 = collections.Counter(v2)
B = list(A1.values())
C = list(A2.values())
B.sort(reverse=True)
C.sort(reverse=True)

if A1.most_common()[0][0] == A2.most_common()[0][0]:
    if len(A1) == 1:
        ans = N//2
    else:
        if B[1] > C[1]: ans = N//2 - B[0] + N//2 - B[1]
        else: ans = N//2 - B[0] + N//2 - C[1]

else:
    ans = N//2 - B[0] + N//2 - C[0]
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
odd = []
even = []
for i in range(n//2):
    odd.append(l[2*i])
    even.append(l[2*i+1])
c_odd = list(Counter(odd).items()) + [(-1,0)]
c_even = list(Counter(even).items()) + [(-1,0)]
c_odd = sorted(c_odd, key=lambda x:-x[1])
c_even = sorted(c_even, key=lambda x:-x[1])

c_odd = c_odd[:2]
c_even = c_even[:2]


if c_odd[0][0] != c_even[0][0]:
    print(n-c_odd[0][1]-c_even[0][1])
    exit()
else:
    print(n-c_odd[0][1]-max(c_odd[1][1],c_even[1][1]))

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

from collections import*
C1=Counter(V[::2]).most_common()+[(0,0)]
C2=Counter(V[1::2]).most_common()+[(0,0)]

K1=C1[0][0]
V1=C1[0][1]
K2=C2[0][0]
V2=C2[0][1]
if K1==K2:
    if V1>V2:
        V2=C2[1][1]
    elif V2>V1:
        V1=C[1][1]
    else:
        V2=max(C1[1][1],C2[1][1])

print(N-V1-V2)

Solution (Python):

from collections import Counter

n, *v = map(int, open(0).read().split())
odd = [v[i] for i in range(0, n, 2)]
even = [v[i] for i in range(1, n, 2)]
o = Counter(odd)
e = Counter(even)

if o.most_common()[0][0] != e.most_common()[0][0]:
    print(n - o.most_common()[0][1] - e.most_common()[0][1])
else:
    a = n - o.most_common()[0][1] - max(sorted(e.values())[:-1] + [0])
    b = n - e.most_common()[0][1] - max(sorted(o.values())[:-1] + [0])
    print(min(a, b))

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
numg=[]
numk=[]
for i in range(n):
    if i%2==0:
        numk.append(v[i])
    else:
        numg.append(v[i])
numk.sort()
numg.sort()
numk2=[]
numg2=[]
num1=0
cnt=0
for i in range(len(numk)):
    if num1!=numk[i]:
        numk2.append([num1,cnt])
        num1=numk[i]
        cnt=1
    else:
        cnt+=1
numk2.append([num1,cnt])
num1=0
cnt=0
for i in range(len(numg)):
    if num1!=numg[i]:
        numg2.append([num1,cnt])
        num1=numg[i]
        cnt=1
    else:
        cnt+=1
numg2.append([num1,cnt])
str1= lambda val: val[1]
numg2.sort(key=str1)
numk2.sort(key=str1)
if numg2[-1][0]==numk2[-1][0]:
    print(n-max(numg2[-1][1]+numk2[-2][1],numg2[-2][1]+numk2[-1][1]))
else:
    print(n-(numg2[-1][1]+numk2[-1][1]))

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

from collections import*
C1=Counter(V[::2]).most_common()+[(0,0)]
C2=Counter(V[1::2]).most_common()+[(0,0)]

K1=C1[0][0]
V1=C1[0][1]
K2=C2[0][0]
V2=C2[0][1]
if K1==K2:
    if V1>V2:
        V2=C2[1][1]
    elif V2>V1:
        V1=C[1][1]
    else:
        V2=max(C1[1][1],C2[1][1])

print(N-V1-V2)

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

from collections import*
C1=Counter(V[::2])
C1=sorted(C1.items(),key=lambda x:x[1])
C2=Counter(V[1::2])
C2=sorted(C2.items(),key=lambda x:x[1])

K1=C1[-1][0]
V1=C1[-1][1]
K2=C2[-1][0]
V2=C2[-1][1]
if V1>V2:
    if K1==K2:
        V2=C2[-2][1]
elif V2>V1:
    if K1==K2:
        V1=C1[-2][1]
else:
    if K1==K2:
        if len(set(V))==1:
            V2=0
        else:
            V2=max(C1[-2][1],C2[-2][1])

print(N-V1-V2)

Solution (Python):
import copy

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


la = [0 for i in range(5+10**5)]
lb = [0 for i in range(5+10**5)]

for i in range(0, n, 2):
    la[v[i]] += 1
for i in range(1, n, 2):
    lb[v[i]] += 1








sla = sum(la)
slb = sum(lb)
maxla = max(la)
maxlb = max(lb)
argmaxla = la.index(max(la))
argmaxlb = lb.index(max(lb))

if argmaxla != argmaxlb:
    if sla-maxla == 0 and slb-maxlb == 0:
        print(0)
    else:
        print(sla-maxla+slb-maxlb)
else:
    
    _la = copy.deepcopy(la)
    _la[argmaxla] = 0
    _maxla = max(_la)
    aa = sla-_maxla+slb-maxlb
    
    _lb = copy.deepcopy(lb)
    _lb[argmaxlb] = 0
    _maxlb = max(_lb)
    bb = sla-maxla+slb-_maxlb
    if bb > aa:
        print(aa)
    else:
        print(bb)

Solution (Python):
from collections import Counter
n = int(input())
V = list(map(int, input().split()))
_n = n // 2
C0 = Counter()
C1 = Counter()
for i in range(n):
    if i % 2 == 0:
        C0[V[i]] += 1
    else:
        C1[V[i]] += 1
C0 = C0.most_common()
C1 = C1.most_common()
if C0[0][0] == C1[0][0]:
    if len(C0) == 1 and len(C1) == 1:
        print(_n)
    elif C0[0][1] == C1[0][1]:
        if C0[1][1] <= C1[1][1]:
            print(abs(C0[0][1] - _n) + abs(C1[1][1] - _n))
        else:
            print(abs(C0[1][1] - _n) + abs(C1[0][1] - _n))
    else:
        if C0[0][1] < C1[0][1]:
            print(abs(C0[1][1] - _n) + abs(C1[0][1] - _n))
        else:
            print(abs(C0[0][1] - _n) + abs(C1[1][1] - _n))
else:
    print(abs(C0[0][1] - _n) + abs(C1[0][1] - _n))

Solution (Python):
from collections import Counter

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

e=Counter(v[0::2])
o=Counter(v[1::2])
e_key=sorted(e.items(),reverse=True,key=lambda x:x[1])
o_key=sorted(o.items(),reverse=True,key=lambda x:x[1])

if e_key[0][0]!=o_key[0][0]: print(n-e_key[0][1]-o_key[0][1])
else:
    if len(e_key)==1 and len(o_key)==1: print(n//2)
    elif len(e_key)==1: print(n//2-o_key[1][1])
    elif len(o_key)==1: print(n//2-e_key[1][1])
    else:
        if e_key[0][1]>o_key[0][1]: print(n-e_key[0][1]-o_key[1][1])
        elif e_key[0][1]<o_key[0][1]: print(n-o_key[0][1]-e_key[1][1])
        else:
            if e_key[1][1]>o_key[1][1]: print(n-e_key[1][1]-o_key[0][1])
            else: print(n-o_key[1][1]-e_key[0][1])

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

import collections

if len(set(V)) == 1:
  print(N//2)
else:
  evens = [V[n] for n in range(0,N,2)]
  odds = [V[n] for n in range(1,N,2)]
  
  c_evens = collections.Counter(evens).most_common()
  c_odds = collections.Counter(odds).most_common()
  
  mode_in_evens = c_evens[0][0]
  mode_number_in_evens = c_evens[0][1]
  
  mode_in_odds = c_odds[0][0]
  mode_number_in_odds = c_odds[0][1]
  
  ans = N - (mode_number_in_evens+mode_number_in_odds)
  
  if mode_in_evens == mode_in_odds:
    if len(c_evens) != 1:
      second_mode_number_in_evens = c_evens[1][1]
    else:
      second_mode_number_in_evens = 0
    ans_candidate_1 = N - (second_mode_number_in_evens+mode_number_in_odds)      
      
    if len(c_odds) != 1:
      second_mode_number_in_odds = c_odds[1][1]
    else:
      second_mode_number_in_odds = 0
    ans_candidate_2 = N - (mode_number_in_evens+second_mode_number_in_odds) 
    
    ans = min(ans_candidate_1,ans_candidate_2)
    
  print(ans)

Solution (Python):
import collections
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])
c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
c1Common = c1.most_common(2)
c2Common = c2.most_common(2)
answer = 0
if c1Common[0][0] != c2Common[0][0]:
    c1Count = n // 2 - c1Common[0][1]
    c2Count = n // 2 - c2Common[0][1]
    answer = c1Count + c2Count
else:
    c1Count = n // 2 - c1Common[0][1]
    c2Count = n // 2 - c2Common[0][1]
    if len(c1Common) > 1:
        c1Count2 = n // 2 - c1Common[1][1]
    else:
        c1Count2 = n // 2
    if len(c2Common) > 1:
        c2Count2 = n // 2 - c2Common[1][1]
    else:
        c2Count2 = n // 2
    case1 = c1Count + c2Count2
    case2 = c2Count + c1Count2
    if case1 < case2:
        answer = case1
    else:
        answer = case2
print(answer)

Solution (Python):
import collections
import sys
n = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1:
  print(n//2)
  sys.exit()
a1 = [a[x] for x in range(0,n,2)]
l_a1 = len(a1)
a2 = [a[y] for y in range(1,n,2)]
l_a2 = len(a2)
c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
K_a1 = c1.most_common()[0][0]
K_a2 = c2.most_common()[0][0]
F_a1 = c1.most_common()[0][1]
F_a2 = c2.most_common()[0][1]
if K_a1 == K_a2:
  if  F_a1 > F_a2:
    F_a2 = c2.most_common()[1][1]
  elif F_a1 == F_a2:
    if  c1.most_common()[1][1] >  c2.most_common()[1][1]:
      F_a1 =  c1.most_common()[1][1]
    else:
      F_a2 =  c2.most_common()[1][1]
  else:
    F_a1 = c1.most_common()[1][1]
print((l_a1 - F_a1)+(l_a2 - F_a2))

Solution (Python):

from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]

odd = Counter(nums[1::2]).most_common()
even = Counter(nums[::2]).most_common()
odd.append((0, 0))
even.append((0, 0))
if odd[0][0] != even[0][0]:
    ans = n - (odd[0][1] + even[0][1])
else:
    s = n - (odd[0][1] + even[1][1])
    t = n - (odd[1][1] + even[0][1])
    ans = min(s, t)
print(ans)
'''
6
1 1 1 1 2 1
'''

Solution (Python):
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
cv1 = Counter(V[::2]).most_common()
cv2 = Counter(V[1::2]).most_common()
cv1.append((-1,0)); cv2.append((-1,0))
if cv1[0][0] != cv2[0][0]:
    print(n-cv1[0][1]-cv2[0][1])
else:
    print(min(n-cv1[1][1]-cv2[0][1], n-cv1[0][1]-cv2[1][1]))

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

d0 = {-1: 0}
for a in la[::2]:
    d0[a] = d0.get(a, 0) + 1
d1 = {-1: 0}
for a in la[1::2]:
    d1[a] = d1.get(a, 0) + 1

n0 = sorted([(v, k) for k, v in d0.items()], reverse=True)
n1 = sorted([(v, k) for k, v in d1.items()], reverse=True)


if n0[0][1] != n1[0][1]:
    answer = n - n0[0][0] - n1[0][0]
else:
    if n0[1][0] > n1[1][0]:
        answer = n - n0[1][0] - n1[0][0]
    else:
        answer = n - n0[0][0] - n1[1][0]


print(answer)

Solution (Python):
n = int(input())
v = [i for i in input().split()]
v1 = {}
v2 = {}
for i in range(n//2):
    if  v[2 *i +1] in v1.keys():
        v1[v[2 * i +1]] += 1
    else:
        v1[v[2 * i + 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1
v1 = sorted(v1.items(),key=lambda x:  x[1])
v2 = sorted(v2.items(),key=lambda x:  x[1])
v1.reverse()
v2.reverse()
v1.append((None,0))
v2.append((None,0))

if v1[0][0] == v2[0][0]:
    ans = max(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]
print(n - ans)

Solution (Python):
import collections
N = int(input())
V = [int(X) for X in input().split()]

if len(set(V))==1:
    print(N//2)
else:
    OddV  = V[::2]
    EvenV = V[1::2]
    LenOddV  = len(set(OddV))
    LenEvenV = len(set(EvenV))
    if LenOddV==1 and LenEvenV==1:
        NOddV  = OddV[0]
        NEvenV = EvenV[0]
        print(0)
    elif LenOddV!=1 and LenEvenV==1:
        OddCount = collections.Counter(OddV)
        NEvenV   = EvenV[0]
        if OddCount.most_common()[0][0]==NEvenV:
            NOddV = OddCount.most_common()[1][0]
            print(N//2-OddCount.most_common()[1][1])
        else:
            NOddV = OddCount.most_common()[0][0]
            print(N//2-OddCount.most_common()[0][1])
    elif LenOddV==1 and LenEvenV!=1:
        NOddV     = OddV[0]
        EvenCount = collections.Counter(EvenV)
        if EvenCount.most_common()[0][0]==NOddV:
            NEvenV = EvenCount.most_common()[1][0]
            print(N//2-EvenCount.most_common()[1][1])
        else:
            NEvenV = EvenCount.most_common()[0][0]
            print(N//2-EvenCount.most_common()[0][1])
    elif LenOddV!=1 and LenEvenV!=1:
        OddCount  = collections.Counter(OddV)
        EvenCount = collections.Counter(EvenV)
        if OddCount.most_common()[0][0]!=EvenCount.most_common()[0][0]:
            NOddV  = OddCount.most_common()[0][0]
            NEvenV = EvenCount.most_common()[0][0]
            print(N-OddCount.most_common()[0][1]-EvenCount.most_common()[0][1])
        else:
            if OddCount.most_common()[0][1]>EvenCount.most_common()[0][1]:
                NOddV  = OddCount.most_common()[0][0]
                NEvenV = EvenCount.most_common()[1][0]
                print(N-OddCount.most_common()[0][1]-EvenCount.most_common()[1][1])
            elif OddCount.most_common()[0][1]<EvenCount.most_common()[0][1]:
                NOddV  = OddCount.most_common()[1][0]
                NEvenV = EvenCount.most_common()[0][0]
                print(N-OddCount.most_common()[1][1]-EvenCount.most_common()[0][1])
            else:
                if OddCount.most_common()[1][1]>=EvenCount.most_common()[1][1]:
                    NOddV  = OddCount.most_common()[1][0]
                    NEvenV = EvenCount.most_common()[0][0]
                    print(N-OddCount.most_common()[1][1]-EvenCount.most_common()[0][1])
                elif OddCount.most_common()[1][1]<EvenCount.most_common()[1][1]:
                    NOddV  = OddCount.most_common()[0][0]
                    NEvenV = EvenCount.most_common()[1][0]
                    print(N-OddCount.most_common()[0][1]-EvenCount.most_common()[1][1])

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Vs = list(mapint())

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

from collections import Counter
ceven = Counter(even)
ans = 0
even_second = 0
for i, (num, cnt) in enumerate(ceven.most_common()):
    if i==0:
        even_most = cnt
        even_num = num
    if i==1:
        even_second = cnt
    ans += cnt
codd = Counter(odd)
odd_second = 0
for i, (num, cnt) in enumerate(codd.most_common()):
    if i==0:
        odd_most = cnt
        odd_num = num
    if i==1:
        odd_second = cnt
    ans += cnt

if even_num==odd_num:
    ans = min(ans-odd_most-even_second, ans-odd_second-even_most)
else:
    ans -= odd_most+even_most
print(ans)

Solution (Python):
def resolve():
    '''
    code here
    '''
    import collections
    n = int(input())
    vs = [int(item) for item in input().split()]
    num_max = max(vs)

    cnt_od = collections.Counter(vs[::2])
    cnt_ev = collections.Counter(vs[1::2])

    cnt_od = cnt_od.most_common()
    cnt_ev = cnt_ev.most_common()

    if cnt_od[0][0] == cnt_ev[0][0]:
        if (len(cnt_od)>1) and (len(cnt_ev)>1):
            ans = min(n - cnt_od[1][1] - cnt_ev[0][1], n - cnt_od[0][1] - cnt_ev[1][1])
        elif len(cnt_od) > 1:
            ans = n//2 - cnt_od[1][1]
        elif len(cnt_ev) > 1:
            ans = n//2 - cnt_ev[1][1]
        else:
            ans = n//2
    else:
        ans = n - cnt_ev[0][1] - cnt_od[0][1]

    print(ans)
if __name__ == "__main__":
    resolve()

Solution (Python):
def main():
    from collections import Counter
    n = int(input())
    V = map(int,input().split())
    odds = []
    evens = []
    for i,v in enumerate(V):
        if i & 1:
            evens.append(v)
        else:
            odds.append(v)
    
    odds_modes= Counter(odds).most_common(2)
    evens_modes = Counter(evens).most_common(2)

    if odds_modes[0][0] != evens_modes[0][0]:
        print(len(odds)- odds_modes[0][1] + len(evens) - evens_modes[0][1])
    else:
        odds_modes.append((-1,0))
        evens_modes.append((-1,0))

        print(
            min(
                len(odds)-odds_modes[0][1] + len(evens) - evens_modes[1][1],
                len(odds)-odds_modes[1][1] + len(evens) - evens_modes[0][1],
            )
        )
            

main()

Solution (Python):
def main():
    from collections import Counter
    n = int(input())
    V = map(int,input().split())
    odds = []
    evens = []
    for i,v in enumerate(V):
        if i & 1:
            evens.append(v)
        else:
            odds.append(v)
    
    odds_counter = list(Counter(odds).items())
    eves_counter = list(Counter(evens).items())
    
    odds_counter.sort(reverse=True, key= lambda x: x[1])
    eves_counter.sort(reverse=True, key= lambda x: x[1])

    if odds_counter[0][0] != eves_counter[0][0]:
        print(len(odds)- odds_counter[0][1] + len(evens) - eves_counter[0][1])
    else:
        odds_counter.append((-1,0))
        eves_counter.append((-1,0))

        print(
            min(
                len(odds)-odds_counter[0][1] + len(evens) - eves_counter[1][1],
                len(odds)-odds_counter[1][1] + len(evens) - eves_counter[0][1],
            )
        )
            
        

    

    
    
    


main()

Solution (Python):
from collections import Counter
n = int(input())
X = list(map(int, input().split()))
A = Counter(X[::2]).most_common()
B = Counter(X[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[0][1]-B[1][1], n-A[1][1]-B[0][1]))

Solution (Python):
from collections import *
N = int(input())
V = list(map(int,input().split()))
E = Counter(V[0::2]).most_common()+[(0,0)]
O = Counter(V[1::2]).most_common()+[(0,0)]

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 collections import *
N = int(input())
V = list(map(int,input().split()))
C1 = Counter(V[0::2]).most_common()
C2 = Counter(V[1::2]).most_common()

if len(set(V))==1:
  ans = N//2
else:
  if C1[0][0]==C2[0][0]:
    ans = min(N-C1[0][1]-C2[1][1],N-C1[1][1]-C2[0][1])
  else:
    ans = N-C1[0][1]-C2[0][1]

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
lst = list(map(int, input().split()))
odd = Counter(lst[::2])
even = Counter(lst[1::2])

omax = odd.most_common()[0]
emax = even.most_common()[0]
if len(odd) >= 2:
  osec = odd.most_common()[1]
if len(even) >= 2:
  esec = even.most_common()[1]


if omax[0] == emax[0]:
  if len(even) == 1 and len(odd) == 1:
    print(n // 2)
  elif len(even) == 1:
    print(n - emax[1] - osec[1])
  elif len(odd) == 1:
    print(n - omax[1] - esec[1])
  else:
    print(min(n - emax[1] - osec[1], n - omax[1] - esec[1]))
else:
  print(n - omax[1] - emax[1])

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
from collections import Counter
odd_ary = v[::2]
even_ary = v[1::2]


oc = Counter(odd_ary).most_common(2)
ec = Counter(even_ary).most_common(2)

if len(oc) == 1:
    oc.append((0, 0))
if len(ec) == 1:
    ec.append((0, 0))

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

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

Solution (Python):
from collections import Counter
n=int(input())
v=list(input().split())
v1=Counter(v[0::2]).most_common()
v2=Counter(v[1::2]).most_common()
ans=0
if v1[0][0]!=v2[0][0]:
  ans=(len(v[0::2])-v1[0][1])+(len(v[1::2])-v2[0][1])
elif len(v1)==1 and len(v2)==1:
  ans=min(v1[0][1],v2[0][1])
elif len(v1)==1:
  ans=len(v[1::2])-v2[1][1]
elif len(v2)==1:
  ans=(len(v[0::2])-v1[1][1])
else:
  ans=min((len(v[0::2])-v1[1][1])+(len(v[1::2])-v2[0][1]),(len(v[0::2])-v1[0][1])+(len(v[1::2])-v2[1][1]))
print(ans)

Solution (Python):
from itertools import permutations
import collections
N = int(input())
nums = list(map(int, input().split()))
odd_nums = []
even_nums = []
for i, num in enumerate(nums):
    if i % 2 == 1:
        even_nums.append(num)
    else:
        odd_nums.append(num)

useable_nums = set(nums)
even_length = len(even_nums)
odd_length = len(odd_nums)
even_counter = collections.Counter(even_nums).most_common()
odd_counter = collections.Counter(odd_nums).most_common()
even_counter.append((0, 0))
odd_counter.append((0, 0))
even_counter.sort(key=lambda x: x[1], reverse=True)
odd_counter.sort(key=lambda x: x[1], reverse=True)




min_ans = None
if even_counter[0][0] == odd_counter[0][0]:
    min_ans = min((odd_length - odd_counter[0][1]) + (even_length - even_counter[1][1]),
                  (odd_length - odd_counter[1][1]) + (even_length - even_counter[0][1]))
else:

    min_ans = odd_length - odd_counter[0][1] + even_length - even_counter[0][1]
print(min_ans)

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter

from fractions  import gcd

import bisect
n=int(input())
v=list(map(int,input().split()))
even={}
odd={}
for i in range(n):
    if i%2==0:
        if v[i] not in even:
            even[v[i]]=1
        else:
            even[v[i]]+=1
    else:
        if v[i] not in odd:
            odd[v[i]]=1
        else:
            odd[v[i]]+=1
    
even=sorted(even.items(),key=lambda x: x[1],reverse=True)
odd=sorted(odd.items(),key=lambda x:x[1],reverse=True)
if even[0][0]==odd[0][0]:
    e1=even[0][1]
    e2=even[1][1] if len(even)>1 else 0
    o1=odd[0][1]
    o2=odd[1][1] if len(odd)>1 else 0
    print(min((n-e1-o2),(n-e2-o1)))
else:
    e=even[0][1]
    o=odd[0][1]
    print(n-e-o)

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

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]

if odd1 != num1:
    print(n-odd_count.most_common()[0][1]-num_count.most_common()[0][1])
    exit()

if len(set(arr)) == 1:
    print(int(n/2))
    exit()

if len(set(num_list))==1 and len(set(odd_list))==1:
    print(0)
    exit()

if len(set(odd_count)) == 1 and len(set(num_count)) != 1:
    num2 = num_count[num_count.most_common()[1][0]]
    if odd_list[0] == num_count.most_common()[0][0]:
        print(int(n/2)-num2)
        exit()
    if odd_list[0] != num_count.most_common()[0][0]:
        print(int(n/2)-num1)
        exit()

if len(set(odd_count)) != 1 and len(set(num_count)) == 1:
    odd2 = odd_list[odd_count.most_common()[1][0]]
    if num_list[0] == odd_count.most_common()[0][0]:
        print(int(n/2)-odd2)
        exit()
    if num_list[0] != odd_count.most_common()[0][0]:
        print(int(n/2)-odd1)
        exit()

odd2 = odd_count[odd_count.most_common()[1][0]]
num2 = num_count[num_count.most_common()[1][0]]

if odd_count.most_common()[0][0] != num_count.most_common()[0][0]:
    print(n-odd1-num1)

if odd_count.most_common()[0][0] == num_count.most_common()[0][0]:
    print(min(n-odd1-num2, n-odd2-num1))

Solution (Python):

from collections import Counter
import sys
input = sys.stdin.readline  
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1_k,co1_v = zip(*Counter(vo1).most_common())
ce2_k,ce2_v = zip(*Counter(ve2).most_common())

ans =0

if vo1 ==ve2:
    if len(ce2_k) <=2:
        ans =sum(ce2_v)
    else:
        ans =sum(ce2_v) +sum(co1_v[2:])   
elif len(co1_v) ==len(ce2_v) ==1:
    ans =0
elif co1_k[0] ==ce2_k[0]:
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    elif len(co1_v) ==len(ce2_v) ==2:
        ans1 =co1_v[1] +ce2_v[0]
        ans2 =co1_v[0] +ce2_v[1]
        ans =min(ans1,ans2)
    elif len(co1_v) ==2:
        ans1 =co1_v[1] +ce2_v[0] +sum(ce2_v[2:])
        ans2 =co1_v[0] +sum(ce2_v[1:])
        ans =min(ans1,ans2)
    elif len(ce2_v) ==2:
        ans1 =ce2_v[1] +co1_v[0] +sum(co1_v[2:])
        ans2 =ce2_v[0] +sum(co1_v[1:])
        ans =min(ans1,ans2)
    else:
        ans1 =sum(co1_v[1:]) +ce2_v[0] +sum(ce2_v[2:] )
        ans2 =sum(ce2_v[1:]) +co1_v[0] +sum(co1_v[2:] )
        ans =min(ans1,ans2)
else: 
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    else:
        ans =sum(co1_v[1:]) +sum(ce2_v[1:])  
   
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
odd = [v[2*i] for i in range(n//2)]
even = [v[2*i+1] for i in range(n//2)]

co = Counter(odd)
ce = Counter(even)
co = co.most_common()
ce = ce.most_common()
if co[0][0] == ce[0][0]:
  if (len(co)>1) and (len(ce)>1):
    ans = min(n//2-co[1][1]+n//2-ce[0][1], n//2-co[0][1]+n//2-ce[1][1])
  elif len(co) > 1:
    ans = n//2 - co[1][1]
  elif len(ce) > 1:
    ans = n//2 - ce[1][1]
  else:
    ans = n//2
else:
  ans = n//2-co[0][1] + n//2-ce[0][1]
print(ans)

Solution (Python):
from collections import Counter
n, *v = map(int, open(0).read().split())
vo = Counter(v[::2])
ve = Counter(v[1::2])
vomc = vo.most_common() + [(0, 0)]
vemc = ve.most_common() + [(0, 0)]
if vomc[0][0] == vemc[0][0]:
    ans = min(n//2 - vomc[0][1] + n//2 - vemc[1][1], n//2 - vomc[1][1] + n//2 - vemc[0][1])
else:
    ans = n//2 - vomc[0][1] + n//2 - vemc[0][1]
print(ans)

Solution (Python):
"""
与えられた数列の奇数番目の数と偶数番目の数をそれぞれ確認し、
要素数の多いものにそれぞれ書き換える。
文字種が1種類にならないように注意する
"""
from collections import Counter

N = int(input())
V_LI = list(map(int, input().split()))
if len(set(V_LI)) == 1:
    
    print(N // 2)
    exit()
odd_li = [V_LI[i] for i in range(0, N, 2)]
even_li = [V_LI[i] for i in range(1, N, 2)]
odd_c = sorted(Counter(odd_li).items(), key=lambda x: -x[1])
even_c = sorted(Counter(even_li).items(), key=lambda x: -x[1])
if odd_c[0][0] == even_c[0][0]:
    cnt_1 = N
    cnt_2 = N
    
    if len(even_c) > 1:
        odd_cnt = len(odd_li) - odd_c[0][1]
        even_cnt = len(even_li) - even_c[1][1]
        cnt_1 = odd_cnt + even_cnt

    
    if len(odd_c) > 1:
        odd_cnt = len(odd_li) - odd_c[1][1]
        even_cnt = len(even_li) - even_c[0][1]
        cnt_2 = odd_cnt + even_cnt

    print(min(cnt_1, cnt_2))
else:
    odd_cnt = len(odd_li) - odd_c[0][1]
    even_cnt = len(even_li) - even_c[0][1]
    print(odd_cnt + even_cnt)

Solution (Python):
import collections
N = int(input())
V = list(map(int,input().split()))
E = []
O = []
for i in range(N):
    if i % 2 == 0:
        O.append(V[i])
    else:
        E.append(V[i])
EC = collections.Counter(E).most_common()
OC = collections.Counter(O).most_common()
if len(EC) == 1 and len(OC) == 1:
    if EC[0][0] == OC[0][0]:
        print(N//2)
    else:
        print(0)
elif len(EC) == 1 and len(OC) != 1:
    if EC[0][0] == OC[0][0]:
        print(N-EC[0][1]-OC[1][1])
    else:
        print(N//2-OC[0][1])
elif len(EC) != 1 and len(OC) == 1:
    if EC[0][0] == OC[0][0]:
        print(N//2-EC[1][1])
    else:
        print(N//2-EC[0][1])
elif EC[0][0] == OC[0][0]:
    if EC[0][1]+OC[1][1] == EC[1][1]+OC[0][1]:
        print(N-EC[0][1]-OC[1][1])
    elif EC[0][1]+OC[1][1] > EC[1][1]+OC[0][1]:
        print(N-EC[0][1]-OC[1][1])
    else:
        print(N-EC[1][1]-OC[0][1])
else:
    print(N-EC[0][1]-OC[0][1])

Solution (Python):
from collections import Counter

n, *v = map(int, open(0).read().split())
vo = Counter(v[::2])
ve = Counter(v[1::2])
vo_mc = vo.most_common()[0]
ve_mc = ve.most_common()[0]
if vo_mc[0] == ve_mc[0]:
    ans = n
    if ve_mc[1] != n//2:
        ans = min(n//2 - vo_mc[1] + n//2 - ve.most_common()[1][1], ans)
    if vo_mc[1] != n//2:
        ans = min(n//2 - vo.most_common()[1][1] + n//2 - ve_mc[1], ans)
    ans = min(n//2 - vo_mc[1] + n//2, ans)
else:
    ans = n//2 - vo_mc[1] + n//2 - ve_mc[1]
print(ans)

Solution (Python):
from collections import Counter

n, *v = map(int, open(0).read().split())
vo = Counter(v[::2])
ve = Counter(v[1::2])
vo_mc = vo.most_common()[0]
ve_mc = ve.most_common()[0]
if vo_mc[0] == ve_mc[0]:
    if vo_mc[1] > ve_mc[1]:
        ans = n//2 - vo_mc[1]
        if ve_mc[1] != n//2:
            ans += n//2 - ve.most_common()[1][1]
        else:
            ans += n//2
    elif vo_mc[1] < ve_mc[1]:
        ans =  n//2 - ve_mc[1]
        if vo_mc[1] != n//2:
            ans += n//2 - vo.most_common()[1][1]
        else:
            ans += n//2
    else:
        ans = n
        if ve_mc[1] != n//2:
            ans = min(n//2 - vo_mc[1] + n//2 - ve.most_common()[1][1], ans)
        if vo_mc[1] != n//2:
            ans = min(n//2 - vo.most_common()[1][1] + n//2 - ve_mc[1], ans)
        ans = min(n//2 - vo_mc[1] + n//2, ans)
else:
    ans = n//2 - vo_mc[1] + n//2 - ve_mc[1]
print(ans)

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil



import string

from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    
    n = int(input())
    a = [int(x) for x in input().split()]
    e = defaultdict(int)
    o = defaultdict(int)
    for i in range(n):
        if i % 2:
            e[a[i]] += 1
        else:
            o[a[i]] += 1
    ee = n // 2
    oo = n // 2 + 1
    x = [(e[el], el) for el in e] + [(0, 0)]
    y = [(o[el], el) for el in o] + [(0, 0)]
    x.sort(reverse=True)
    y.sort(reverse=True)
    ans = n
    if x[0][1] == y[0][1]:
        ans = min(ans, n - x[0][0] - y[1][0])
        ans = min(ans, n - x[1][0] - y[0][0])
    else:
        ans = n - x[0][0] - y[0][0]
    print(ans)

t = 1

for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=Counter(v[::2])
v2=Counter(v[1::2])
v1[0]=0
v2[0]=0
v1_max=v1.most_common()[0]
v2_max=v2.most_common()[0]
v1_second=v1.most_common()[1]
v2_second=v2.most_common()[1]
if v1_max[0]!=v2_max[0]:
    print(n-v1_max[1]-v2_max[1])
else:
    print(min(n-v1_max[1]-v2_second[1],n-v2_max[1]-v1_second[1]))