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())
A = list(map(int, input().split()))

l = []
r = []
al = []
for i, x in enumerate(A):
  if i % 2 == 0:
    l.append(x)
  else:
    r.append(x)
  al.append(x)

c = collections.Counter(l)
d = collections.Counter(r)
e = collections.Counter(al)

if len(e.keys()) <= 1:
  print(N//2)
  exit()
else:
  mx = -1
  ans = 0
  ck = max(c.items(), key=lambda x:x[1])[0]
  cmx = max(c.items(), key=lambda x:x[1])[1]

  dk = max(d.items(), key=lambda x:x[1])[0]
  dmx = max(d.items(), key=lambda x:x[1])[1]

  if ck == dk:
    if cmx > dmx:
      ans += N//2 - cmx
      ans += N//2 - d.most_common(2)[1][1]
    elif cmx < dmx:
      ans += N//2 - dmx
      ans += N//2 - c.most_common(2)[1][1]
    else:
      if c.most_common(2)[1][1] >= d.most_common(2)[1][1]:
        ans += N//2 - dmx
        ans += N//2 - c.most_common(2)[1][1]
      else:
        ans += N//2 - cmx
        ans += N//2 - d.most_common(2)[1][1]
  else:
      ans += N//2 - cmx
      ans += N//2 - dmx

print(ans)

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

l = []
r = []
al = []
for i, x in enumerate(A):
  if i % 2 == 0:
    l.append(x)
  else:
    r.append(x)
  al.append(x)

c = collections.Counter(l)
d = collections.Counter(r)
e = collections.Counter(al)

if len(e.keys()) <= 1:
  print(N//2)
  exit()
else:
  mx = -1
  ans = 0
  ck = max(c.items(), key=lambda x:x[1])[0]
  cmx = max(c.items(), key=lambda x:x[1])[1]

  dk = max(d.items(), key=lambda x:x[1])[0]
  dmx = max(d.items(), key=lambda x:x[1])[1]

  if ck == dk:
    if cmx > dmx:
      ans += N//2 - cmx
      print(ans)
      print(c.most_common(2))
      print(d.most_common(2))
      ans += N//2 - (d.most_common(2)[1][1])
    elif cmx < dmx:
      ans += N//2 - dmx
      ans += N//2 - (c.most_common(2)[1][1])
    else:
      if c.most_common(2)[1][1] >= d.most_common(2)[1][1]:
        ans += N//2 - dmx
        ans += N//2 - (c.most_common(2)[1][1])
      else:
        ans += N//2 - cmx
        ans += N//2 - d.most_common(2)[1][1]
  else:
      ans += N//2 - cmx
      ans += N//2 - dmx

print(ans)

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    V = il()
    odd = collections.Counter(V[0::2]).most_common()
    even = collections.Counter(V[1::2]).most_common()

    odd.append([0, 0])
    even.append([0, 0])

    if odd[0][0] != even[0][0]:
        print(N - (odd[0][1] + even[0][1]))
    else:
        print(min(N - (odd[0][1] + even[1][1]), N - (odd[1][1] + even[0][1])))


if __name__ == '__main__':
    main()

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
e=[]
o=[]
for i, vi in enumerate(v,start=0):
  if i%2 == 0:
    e.append(vi)
  else:
    o.append(vi)
ec=collections.Counter(e)
oc=collections.Counter(o)

ecs = sorted(ec.items(), key=lambda x:x[1],reverse=True)
ocs = sorted(oc.items(), key=lambda x:x[1],reverse=True)

t=ecs[0][1]+ocs[0][1]
if ecs[0][0] == ocs[0][0]:
  if ecs[0][1] == ocs[0][1]:
    te = 0 if len(ecs) < 2 else ecs[1][1]
    to = 0 if len(ocs) < 2 else ocs[1][1]
    t=max(te,to)+ecs[0][1]
print(n-t)

Solution (Python):
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
fn=sorted(Counter(f).items(),key=lambda x:x[1],reverse=True) + [(0, 0)]
sn=sorted(Counter(s).items(),key=lambda x:x[1],reverse=True) + [(0, 0)]
if fn[0][0]!=sn[0][0]:
  ans=n-fn[0][1]-sn[0][1]
else:
  ans=n-max(fn[1][1]+sn[0][1],fn[0][1]+sn[1][1])
print(ans)

Solution (Python):
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
fn=sorted(Counter(f).items(),key=lambda x:x[1],reverse=True) + [(0, 0)]
sn=sorted(Counter(s).items(),key=lambda x:x[1],reverse=True) + [(0, 0)]
if fn[0][0]!=sn[0][0]:
  ans=n-fn[0][1]-sn[0][1]
else:
  ans=n-max(fn[1][1]+sn[0][1],fn[0][1]+sn[1][1])
print(ans)

Solution (Python):

from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(n: int, v: "List[int]"):
    v1 = v[::2]
    v2 = v[1::2]
    c1 = Counter(v1)
    c2 = Counter(v2)
    mc1 = c1.most_common(2)
    mc2 = c2.most_common(2)
    if len(mc1) == 1:
        mc1.append((999990, 0))
    if len(mc2) == 1:
        mc2.append((999999, 0))
    cv1, cnt1 = mc1[0]
    cv2, cnt2 = mc2[0]
    if cv1 != cv2:
        print(n - cnt1 - cnt2)
    else:
        print(n - max(cnt1 + mc2[1][1], cnt2 + mc1[1][1]))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    v = [int(next(tokens)) for _ in range(n)]  
    solve(n, v)


if __name__ == '__main__':
    main()

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

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


dic1={};dic2={}

for i in range(n):
    v=vl[i]
    if i%2==0:
        dic1[v]=dic1.get(v,0)+1
    else:
        dic2[v]=dic2.get(v,0)+1

dic1=sorted(dic1.items(),reverse=True,key=lambda x:x[1])
dic2=sorted(dic2.items(),reverse=True,key=lambda x:x[1])


mx1_val,mx1_count=dic1[0]
if len(dic1)==1:
    mx1_count2=0
else:
    mx1_count2=dic1[1][1]

mx2_val,mx2_count=dic2[0]
if len(dic2)==1:
    mx2_count2=0
else:
    mx2_count2=dic2[1][1]

ans=0
ansl=[]
total=n//2
if n==2:
    if vl[0]==vl[1]:
        ans=1
    else:
        ans=0
    print(ans)
else:
    if mx1_val != mx2_val:
        ans=n-(mx1_count+mx2_count)
    else:
        ans=min(n-mx1_count-mx2_count2,
        n-mx1_count2-mx2_count)
    print(ans)

Solution (Python):
import math
import sys

n = int(sys.stdin.readline().rstrip())
v = list(map(int, sys.stdin.readline().rstrip().split()))
v1 = v[::2]
v2 = v[1::2]
v1d = {}
v2d = {}
for vi in v1:
    if vi in v1d:
        v1d[vi] += 1
    else:
        v1d[vi] = 1
for vi in v2:
    if vi in v2d:
        v2d[vi] += 1
    else:
        v2d[vi] = 1

if max(v1d, key=v1d.get) != max(v2d, key=v2d.get):
    print(len(v1) - max(v1d.values()) + len(v2) - max(v2d.values()))
else:
    ans1 = 0
    if len(v1d.values()) == 1:
        tmp = 0
    else:
        tmp = sorted(v1d.values())[-2]
    ans1 = len(v1) - tmp + len(v2) - max(v2d.values())
    ans2 = 0
    if len(v2d.values()) == 1:
        tmp = 0
    else:
        tmp = sorted(v2d.values())[-2]
    ans2 = len(v1) - max(v1d.values()) + len(v2) - tmp
    print(min(ans1, ans2))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n // 2)
    exit()
kisu = v[::2]
gusu = v[1::2]
kisu_color = Counter(kisu).most_common()[:2]
gusu_color = Counter(gusu).most_common()[:2]
if kisu_color[0][0] != gusu_color[0][0]:
    ans = n - kisu_color[0][1] - gusu_color[0][1]
else:
    ans = min(n - kisu_color[0][1] - gusu_color[1][1], n - kisu_color[1][1] - gusu_color[0][1])
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

from collections import defaultdict 


N = ii()
A = li()

d_o = defaultdict(int)
d_e = defaultdict(int)

for i in range(N):
    if i % 2:
        d_o[A[i]] += 1
    else:
        d_e[A[i]] += 1

l_d = sorted(list(d_o.items()), key=lambda x:x[1], reverse=True)
l_e = sorted(list(d_e.items()), key=lambda x:x[1], reverse=True)

if l_d[0][0] != l_e[0][0]:
    print(N - l_d[0][1] - l_e[0][1])
elif len(l_d) == len(l_e) == 1:
        print(N - max(l_d[0][1], l_e[0][1]))
elif len(l_d) == 1:
        
        
        print(N - l_d[0][1] - l_e[1][1])
elif len(l_e) == 1:
        
        
        print(N - l_d[1][1] - l_e[0][1])
else:
    ans = min(N-l_d[1][1]-l_e[0][1], N-l_d[0][1]-l_e[1][1])
    print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]

from collections import defaultdict 


N = ii()
A = li()

d_o = defaultdict(int)
d_e = defaultdict(int)

for i in range(N):
    if i % 2:
        d_o[A[i]] += 1
    else:
        d_e[A[i]] += 1

l_d = sorted(list(d_o.items()), key=lambda x:x[1], reverse=True)
l_e = sorted(list(d_e.items()), key=lambda x:x[1], reverse=True)

if l_d[0][0] != l_e[0][0]:
    print(N - l_d[0][1] - l_e[0][1])
elif len(l_d) == len(l_e) == 1:
        print(N - max(l_d[0][1], l_e[0][1]))
elif len(l_d) == 1:
        ans = min(N - l_d[0][1] - l_e[1][1], N - l_e[0][1])
        print(ans)
elif len(l_e) == 1:
        ans = min(N - l_d[1][1] - l_e[0][1], N - l_d[0][1])
        print(ans)
else:
    ans = min(N-l_d[1][1]-l_e[0][1], N-l_d[0][1]-l_e[1][1])
    print(ans)

Solution (Python):
import collections

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

if len(set(v)) == 1:
  print(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cmc1 = collections.Counter(v1).most_common()
  cmc2 = collections.Counter(v2).most_common()
  
  if cmc1[0][0] == cmc2[0][0]:    
    ans1 = (len(v1) - cmc1[0][1]) + (len(v2) - cmc2[1][1])
    ans2 = (len(v1) - cmc1[1][1]) + (len(v2) - cmc2[0][1])
    print(min(ans1, ans2))
  else:
    ans = (len(v1) - cmc1[0][1]) + (len(v2) - cmc2[0][1])
    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()
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):

import collections
N = int(input())
V = list(map(int, input().split()))

V1 = V[::2]
V2 = V[1::2]


C1 = collections.Counter(V1)
C2 = collections.Counter(V2)

C1_s = C1.most_common()
C2_s = C2.most_common()

max1 = C1_s[0][1]
index1 = C1_s[0][0]

max2 = C2_s[0][1]
index2 = C2_s[0][0]

max1_2 = 0
max2_2 = 0
if len(C1_s) > 1:
    max1_2 = C1_s[1][1]

if len(C2_s) > 1:
    max2_2 = C2_s[1][1]


nokori1 = len(V1) - max1
nokori2 = len(V2) - max2

nokori1_2 = len(V1) - max1_2
nokori2_2 = len(V2) - max2_2

ans = 0
if index1 == index2:
    ans = min(nokori1_2 + nokori2, nokori1 + nokori2_2)
else:
    ans = nokori1 + nokori2
print(ans)

Solution (Python):

import collections
N = int(input())
V = list(map(int, input().split()))

V1 = V[::2]
V2 = V[1::2]


C1 = collections.Counter(V1)
C2 = collections.Counter(V2)

C1_s = sorted(C1.items(), key=lambda x:x[1])[::-1]
C2_s = sorted(C2.items(), key=lambda x:x[1])[::-1]

max1 = C1_s[0][1]
index1 = C1_s[0][0]

max2 = C2_s[0][1]
index2 = C2_s[0][0]

max1_2 = 0
max2_2 = 0
if len(C1_s) > 1:
    max1_2 = C1_s[1][1]

if len(C2_s) > 1:
    max2_2 = C2_s[1][1]


nokori1 = len(V1) - max1
nokori2 = len(V2) - max2

nokori1_2 = len(V1) - max1_2
nokori2_2 = len(V2) - max2_2

ans = 0
if index1 == index2:
    ans = min(nokori1_2 + nokori2, nokori1 + nokori2_2)
else:
    ans = nokori1 + nokori2
print(ans)

Solution (Python):

import collections
N = int(input())
V = list(map(int, input().split()))

V1 = V[::2]
V2 = V[1::2]

if len(set(V1)) == 1 and len(set(V2)) == 1 and V1[0] == V2[0]:
    print(len(V1))
    exit()


C1 = collections.Counter(V1)
C2 = collections.Counter(V2)

C1_s = sorted(C1.items(), key=lambda x:x[1])[::-1]
C2_s = sorted(C2.items(), key=lambda x:x[1])[::-1]

max1 = C1_s[0][1]
index1 = C1_s[0][0]

max2 = C2_s[0][1]
index2 = C2_s[0][0]

max1_2 = 0
max2_2 = 0
if len(C1_s) > 1:
    max1_2 = C1_s[1][1]

if len(C2_s) > 1:
    max2_2 = C2_s[1][1]


nokori1 = len(V1) - max1
nokori2 = len(V2) - max2

nokori1_2 = len(V1) - max1_2
nokori2_2 = len(V2) - max2_2

ans = 0
if index1 == index2:
    if len(set(V1)) == 1:
        ans = nokori2_2
    elif len(set(V2)) == 1:
        ans = nokori1_2
    else:
        ans = min(nokori1_2 + nokori2, nokori1 + nokori2_2)
else:
    ans = nokori1 + nokori2
print(ans)

Solution (Python):

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

evn=dict()
odd=dict()

maxevn1=0
maxevnv1=0
maxodd1=0
maxoddv1=0

maxevn2=0
maxevnv2=0
maxodd2=0
maxoddv2=0

for i in range(n):
    if i%2==0:
        if v[i] in evn:
            evn[v[i]]+=1
        else:
            evn[v[i]]=1
        if evn[v[i]]>maxevn1  and v[i]==maxevnv1:
            maxevn1=evn[v[i]]
        elif evn[v[i]]>maxevn1  and v[i]!=maxevnv1:
            maxevn2=maxevn1
            maxevnv2=maxevnv1
            maxevn1=evn[v[i]]
            maxevnv1=v[i]           
        elif evn[v[i]]>maxevn2:
            maxevn2=evn[v[i]]
            maxevnv2=v[i]           
    else:
        if v[i] in odd:
            odd[v[i]]+=1
        else:
            odd[v[i]]=1
        if odd[v[i]]>maxodd1 and v[i]==maxoddv1:
            maxodd1=odd[v[i]]
        elif odd[v[i]]>maxodd1 and v[i]!=maxoddv1:
            maxodd2=maxodd1
            maxoddv2=maxoddv1
            maxodd1=odd[v[i]]
            maxoddv1=v[i]           
        elif odd[v[i]]>maxodd2:
            maxodd2=odd[v[i]]
            maxoddv2=v[i]           

if maxevnv1!=maxoddv1:
    print(n-maxevn1-maxodd1)
else:
    kk=min(n-maxevn1-maxodd2,n-maxevn2-maxodd1)
    print(kk)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
d = {}
for num,i in enumerate(a):
  if num%2==0:
    if i in d:
      d[i][0] += 1
    else:
      d[i] = [1,0]
  else:
    if i in d:
      d[i][1] += 1
    else:
      d[i] = [0,1]
b = [i for i in d.values()]
c = [i for i in d.values()]
b.append([0,0])
c.append([0,0])
b.sort(key=lambda x:x[0],reverse=True)
c.sort(key=lambda x:x[1],reverse=True)
if b[0][1] == c[0][0] and b[0][1] != 0:
  print(n-max(b[0][0]+c[1][1],b[1][0]+c[0][1]))
else:
  print(n-b[0][0]-c[0][1])

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

from collections import Counter

def solve():
    n = II()
    V = LI()
    
    even = V[::2]
    odd = V[1::2]
    harf = n // 2
    
    ec = Counter(even).most_common()
    oc = Counter(odd).most_common()
    
    
    
    e1 = ec[0][1]
    o1 = oc[0][1]
    
    if ec[0][0] == oc[0][0]:
      
      e2 = ec[1][1] if len(ec) > 1 else 0
      o2 = oc[1][1] if len(oc) > 1 else 0
      
      ans = min(n - e1 - o2, n - o1 - e2)
    else:
      ans = n - e1 - o1
    
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1
def II(): return int(input())

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

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

from collections import Counter

def solve():
    n = II()
    V = LI()
    
    even = V[::2]
    odd = V[1::2]
    harf = n // 2
    
    ec = Counter(even).most_common()
    oc = Counter(odd).most_common()
    
    
    

    
    if ec[0][0] == oc[0][0]:
      
      if ec[0][1] < oc[0][1]:
        ans = n - oc[0][1] - (ec[1][1] if len(ec) > 1 else 0)
      elif ec[0][1] == oc[0][1]:
        ans = n - ec[0][1] - max((ec[1][1] if len(ec) > 1 else 0), (oc[1][1] if len(oc) > 1 else 0))
      else:
        ans = n - ec[0][1] - (oc[1][1] if len(oc) > 1 else 0)
    else:
      ans = n - ec[0][1] - oc[0][1]
    
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter

N = int(input())
numbers = [int(x) for x in input().split()]

odds = numbers[::2]
evens = numbers[1::2]

c1 = Counter(odds).most_common(2)
c2 = Counter(evens).most_common(2)

if c1[0][0] == c2[0][0]:
  print(min(
    N - c1[0][1] - (c2[1][1] if len(c2) > 1 else 0),
    N - c2[0][1] - (c1[1][1] if len(c1) > 1 else 0)
  ))    
else:  
  print(N - c1[0][1] - c2[0][1])

Solution (Python):
N = int(input())
K = list(map(int,input().rstrip().split(" ")))
Ka = [0] * (10 ** 5 + 1)
Ke = [0] * (10 ** 5 + 1)
Ka2 = []
Ke2 = []

for i in range(N):
    if i % 2 == 0: Ka[K[i]] += 1
    else: Ke[K[i]] += 1
Ka2 = sorted(Ka,reverse = True)
Ke2 = sorted(Ke,reverse = True)

if Ka.index(Ka2[0]) == Ke.index(Ke2[0]):
    if Ka2[0] - Ka2[1] < Ke2[0] - Ke2[1]:
        print(N - Ka2[1] - Ke2[0])
    else:
        print(N - Ka2[0] - Ke2[1])
else:
    print(N -Ka2[0] - Ke2[0])

Solution (Python):

import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))


N = ir()
V = lr()
odd = V[::2]
even = V[1::2]
cnt_odd = Counter(odd)
cnt_even = Counter(even)
cnt_odd_most = cnt_odd.most_common()
cnt_even_most = cnt_even.most_common()
if cnt_odd_most[0][0] == cnt_even_most[0][0]:
    answer = N
    if len(cnt_odd_most) > 1:
        temp = N - cnt_odd_most[1][1] - cnt_even_most[0][1]
        answer = min(answer, temp)
    if len(cnt_even_most) > 1:
        temp = N - cnt_odd_most[0][1] - cnt_even_most[1][1]
        answer = min(answer, temp)
    if answer == N:
        answer = N // 2
else:
    answer = N - cnt_odd_most[0][1] - cnt_even_most[0][1]

print(answer)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
d_e={}
d_o={}
for i in range(n):
  if i%2==0:
    if v[i] in d_e:
      d_e[v[i]]+=1
    else:
      d_e[v[i]]=1
  else:
    if v[i] in d_o:
      d_o[v[i]]+=1
    else:
      d_o[v[i]]=1
d_o=sorted(d_o.items(),key=lambda x:x[1])
d_e=sorted(d_e.items(),key=lambda x:x[1])
if d_o[-1][0] != d_e[-1][0]:
    print(n-(d_o[-1][1]+d_e[-1][1]))
else:
  if (len(d_o)>=2) and(len(d_e)>=2):
    print(min(n-(d_o[-2][1]+d_e[-1][1]),n-(d_o[-1][1]+d_e[-2][1])))
  else:
    print(min(d_o[-1][1],d_e[-1][1]))

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
    n=int(input())
    V=[int(_) for _ in input().split()]
    even,odd=V[0::2],V[1::2]
    even_c,odd_c=Counter(even),Counter(odd)
    even_ci,odd_ci=list(even_c.items()),list(odd_c.items())
    even_ci.sort(key=itemgetter(1),reverse=True)
    odd_ci.sort(key=itemgetter(1),reverse=True)
    if even_ci[0][0]==odd_ci[0][0]:
        if len(even_ci)>1 and len(odd_ci)>1:
            print(min(sum(even_c.values())-even_ci[1][1]+sum(odd_c.values())-odd_ci[0][1],
                        sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[1][1]))
        elif len(even_ci)>1 and len(odd_ci)==1:
            print(sum(even_c.values())-even_ci[1][1])        
        elif len(even_ci)==1 and len(odd_ci)>1:
            print(sum(odd_c.values())-odd_ci[0][1])        
        else:
            print(n//2)   
    else:
        print(sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[0][1])

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
    n=int(input())
    V=[int(_) for _ in input().split()]
    even=V[0::2]
    odd=V[1::2]
    even_c=Counter(even)
    odd_c=Counter(odd)
    even_ci,odd_ci=list(even_c.items()),list(odd_c.items())
    even_ci.sort(key=itemgetter(1),reverse=True)
    odd_ci.sort(key=itemgetter(1),reverse=True)
    if even_ci[0][0]==odd_ci[0][0]:
        if len(even_ci)>1 and len(odd_ci)>1:
            print(min(sum(even_c.values())-even_ci[1][1]+sum(odd_c.values())-odd_ci[0][1],
                        sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[1][1]))
        elif len(even_ci)>1 and len(odd_ci)==1:
            print(sum(even_c.values())-even_ci[1][1])        
        elif len(even_ci)==1 and len(odd_ci)>1:
            print(sum(odd_c.values())-odd_ci[0][1])        
        else:
            print(n//2)   
    else:
        print(sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[0][1])

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
    n=int(input())
    V=[int(_) for _ in input().split()]
    even=V[0::2]
    odd=V[1::2]
    even_c=Counter(even)
    odd_c=Counter(odd)
    even_ci,odd_ci=list(even_c.items()),list(odd_c.items())
    even_ci.sort(key=itemgetter(1),reverse=True)
    odd_ci.sort(key=itemgetter(1),reverse=True)
    if even_ci[0][0]==odd_ci[0][0]:
        if len(even_ci)>1 and len(odd_ci)>1:
            print(min(sum(even_c.values())-even_ci[1][1]+sum(odd_c.values())-odd_ci[0][1],
                        sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[1][1]))
        elif len(even_ci)>1 and len(odd_ci)==1:
            print(sum(even_c.values())-even_ci[1][1])        
        elif len(even_ci)==1 and len(odd_ci)>1:
            print(sum(odd_c.values())-odd_ci[0][1])        
        else:
            print(n//2)   
    else:
        print(sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[0][1])

if __name__=='__main__':
    main()

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

li1=[]
li2=[]

for i in range(n):
    if i%2==0:
        li1.append(v[i])
    else:
        li2.append(v[i])

li1=collections.Counter(li1).most_common()
li2=collections.Counter(li2).most_common()

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

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
E = []
O = []
T = [[0,i] for i in range(10**5+1)]
U = [[0,i] for i in range(10**5+1)]
for i in range(n):
    if i%2 == 0:
        E.append(L[i])
        T[L[i]][0] += 1
    else:
        O.append(L[i])
        U[L[i]][0] += 1
T.sort()
U.sort()
if T[10**5][1] != U[10**5][1]:
    print(n-(T[10**5][0]+U[10**5][0]))
else:
    print(min(n-(T[10**5-1][0]+U[10**5][0]), n-(T[10**5][0]+U[10**5-1][0])))

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

n = int(input())
v = list(map(int, input().split()))
vodd = []
veven = []


for i in range(n):
    if i%2==0:veven.append(v[i])
    else: vodd.append(v[i])

lstodd = Counter(vodd)
lsteven = Counter(veven)

ans = []
for i, ii in zip(range(2), lstodd.most_common()):
    for j, jj in zip(range(2), lsteven.most_common()):
        if ii[0] == jj[0]:continue
        ans.append(len(vodd) - ii[1] + len(veven) - jj[1])
if ans == []:ans.append(n//2)

print(min(ans))

Solution (Python):
from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])





odd_1st = Counter(v_odd).most_common()[0][1]
even_1st = Counter(v_even).most_common()[0][1]
if Counter(v_odd).most_common()[0][0] != Counter(v_even).most_common()[0][0]:
    number_of_rewrites = len(v_odd) - odd_1st
    number_of_rewrites += len(v_even) - even_1st
else:
    odd_2nd = Counter(v_odd).most_common()[1][1] if len(Counter(v_odd).most_common()) >= 2 else 0
    even_2nd = Counter(v_even).most_common()[1][1] if len(Counter(v_even).most_common()) >= 2 else 0

    if odd_2nd >= even_2nd:
        number_of_rewrites = len(v_odd) - odd_2nd + len(v_even) - even_1st
    else:
        number_of_rewrites = len(v_odd) - odd_1st + len(v_even) - even_2nd
    
    
    
    

print(number_of_rewrites)

Solution (Python):
from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])





odd_1st = Counter(v_odd).most_common()[0][1]
even_1st = Counter(v_even).most_common()[0][1]
if Counter(v_odd).most_common()[0][0] != Counter(v_even).most_common()[0][0]:
    number_of_rewrites = len(v_odd) - odd_1st
    number_of_rewrites += len(v_even) - even_1st
else:
    odd_2nd = Counter(v_odd).most_common()[1][1] if len(Counter(v_odd).most_common()) >= 2 else 0
    even_2nd = Counter(v_even).most_common()[1][1] if len(Counter(v_even).most_common()) >= 2 else 0

    number_of_rewrites = min(
        len(v_odd) - odd_1st + len(v_even) - even_2nd,
        len(v_odd) - odd_2nd + len(v_even) - even_1st,
    )

print(number_of_rewrites)

Solution (Python):
from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])





if Counter(v_odd).most_common()[0][0] != Counter(v_even).most_common()[0][0]:
    number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
    number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]
else:
    odd_1st = Counter(v_odd).most_common()[0][1]
    even_1st = Counter(v_even).most_common()[0][1]
    odd_2nd = Counter(v_odd).most_common()[1][1] if len(Counter(v_odd).most_common()) >= 2 else 0
    even_2nd = Counter(v_even).most_common()[1][1] if len(Counter(v_even).most_common()) >= 2 else 0

    number_of_rewrites = min(
        len(v_odd) - odd_1st + len(v_even) - even_2nd,
        len(v_odd) - odd_2nd + len(v_even) - even_1st,
    )

print(number_of_rewrites)

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):
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):
import collections
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(n):
    if i % 2 == 1:
        a.append(v[i])
    elif i % 2 == 0:
        b.append(v[i])
ac = collections.Counter(a)
bc = collections.Counter(b)
p = ac.most_common()[0]
q = bc.most_common()[0]
if p[0] != q[0]:
    print(n - p[1] - q[1])
else:
    x = len(ac)
    y = len(bc)
    if x >= 2 and y >= 2: 
        r = ac.most_common()[1]
        s = bc.most_common()[1]
        if r[1] > s[1]:
            print(n - r[1] - q[1])
        elif r[1] <= s[1]:
            print(n - p[1] - s[1])
    elif x == 1 and y == 1:
        print(n//2)
    elif x == 1:
        s = bc.most_common()[1]
        print(n - p[1] - s[1])
    elif y == 1:
        r = ac.most_common()[1]
        print(n - r[1] - q[1])

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

v_even = v[::2]
v_odd = v[1::2]


from collections import Counter

c_even = Counter(v_even)
c_odd = Counter(v_odd)
elist = c_even.most_common()
olist = c_odd.most_common()

if elist[0][0] != olist[0][0]:
    print(len(v) - elist[0][1] - olist[0][1])
elif len(elist) >= 2 and len(olist) >= 2:
    print(len(v) - max(elist[0][1] + olist[1][1],elist[1][1] + olist[0][1]))
elif len(elist) >= 2:
    print(len(v) - max(elist[1][1] + olist[0][1], elist[0][1]))
elif len(olist) >= 2:
    print(len(v) - max(olist[1][1] + elist[0][1], olist[0][1]))
else:
    print(n//2)

Solution (Python):
from collections import*
n, *v = map(int, open(0).read().split())
a, b = [Counter(v[i::2]).most_common() + [(0,0)] for i in (0,1)]
s, x = a[0]
t, y = b[0]
print(n - [x+y, max(x+b[1][1], y+a[1][1])][s==t])

Solution (Python):
N = int(input())
v = list(map(int, input().split()))
d_ki = {0 : 0, -1 : 0}
d_gu = {-2 : 0, -3 : 0}
for i in range(N):
    if i % 2 == 0:
        if v[i] not in d_ki:
            d_ki[v[i]] = 1
        else:
            d_ki[v[i]] += 1
    else:
        if v[i] not in d_gu:
            d_gu[v[i]] = 1
        else:
            d_gu[v[i]] += 1
ki = sorted(d_ki.items(), key=lambda x : x[1], reverse=True)
gu = sorted(d_gu.items(), key=lambda x : x[1], reverse=True)
ans = 0
for i in range(2):
    for j in range(2):
        if ki[i][0] == gu[j][0]:
            continue
        ans = max(ans, ki[i][1] + gu[j][1])
print(N - ans)

Solution (Python):
import collections
n = int(input())
vlist = list(map(int,input().split()))
list_odd = [vlist[i] for i in  range(n) if i % 2 ==0]
list_even = [vlist[i] for i in range(n) if i % 2 !=0]

def f(list1):
  ary1 = [[0,i] for i in range(10**5+2)]
  len1 = len(list1)
  for i in range(len1):
    ary1[list1[i]+1][0] += 1
  ary2 = sorted(ary1)
  return [ary2[-1],ary2[-2]]

list3 = f(list_odd)
list4 = f(list_even)


if list3[0][1] != list4[0][1]:
  print(n-list3[0][0]-list4[0][0])
else:
  x1 = n-list3[0][0]-list4[1][0]
  x2 = n-list3[1][0]-list4[0][0]
  print(min(x1,x2))