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




import collections as cl
a0 = cl.Counter(o[0::2]).most_common()
a1 = cl.Counter(o[1::2]).most_common()
a0.append((0,0))
a1.append((0,0))
if a0[0] != a1[0]:
    count = n - a0[0][1] - a1[0][1]
else:
    count = min(n - a0[1][1] - a1[0][1], n - a0[0][1] - a1[1][1])

print(count)

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

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

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm1[0])
else:
    if km1[0]-km2[0]>=gm1[0]-gm2[0]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])

Solution (Python):
import numpy as np
n = int(input())
v = list(map(int, input().split()))
v_odd = []
v_even = []
for i in range(n):
  if i%2 == 0:
    v_odd.append(v[i])
  else:
    v_even.append(v[i])

vs_odd = np.array(v_odd)
vs_even = np.array(v_even)
count_odd = np.bincount(vs_odd)
count_even = np.bincount(vs_even)
mode_odd = np.argmax(count_odd)
mode_even = np.argmax(count_even)
a = v_odd.count(mode_odd)
b = v_even.count(mode_even)
if mode_odd != mode_even:
  print(n-a-b)
else:
  if len(v_odd) != v_odd.count(mode_odd):
    v_odd2 = [i for i in v_odd if i != mode_odd]
    vs_odd2 = np.array(v_odd2)
    count_odd2 = np.bincount(vs_odd2)
    mode_odd2 = np.argmax(count_odd2)
    a2 = v_odd.count(mode_odd2)
  else:
    a2 = 0
  if len(v_even) != v_even.count(mode_even):
    v_even2 = [i for i in v_even if i != mode_even]
    vs_even2 = np.array(v_even2)
    count_even2 = np.bincount(vs_even2)
    mode_even2 = np.argmax(count_even2)
    b2 = v_even.count(mode_even2)
  else:
    b2 = 0
  if a2 > b2:
    print(n-a2-b)
  else:
    print(n-a-b2)

Solution (Python):
import sys

def mode(list1):
    dic = {}
    for n in list1:
        if n in dic:
            dic[n] += 1
        else:
            dic[n] = 1
    max1 = 0
    num1  = -1
    for key in dic:
        if max1 < dic[key]:
            max1 = dic[key] 
            num1 = key

    max2 = 0
    num2 = -1
    for key in dic:
        if key == num1:
            continue
        if max2 < dic[key]:
            max2 = dic[key] 
            num2 = key
    return max1,num1,max2,num2

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

if min(vlist) == max(vlist):
    print(n//2)
    sys.exit()

alist=[]
blist=[]
for i in range(n//2):
    alist.append(vlist[2*i])
    blist.append(vlist[2*i+1])

amax,ka,amax2,ka2 = mode(alist)
bmax,kb,bmax2,kb2 = mode(blist)

if ka != kb:
    ans = n - amax - bmax
else:
    if amax2 <= bmax2:
        ans =n - amax -bmax2
    else:
        ans =n - bmax -amax2
print(ans)

Solution (Python):
from collections import Counter

ans = int(input())
V = [int(i) for i in input().split()]

v1 = []
v2 = []

for i, v in enumerate(V):
    if i % 2 == 0:
       v1.append(v)
    else:
        v2.append(v)

v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()

k1, v1 = v1c[0][0], v1c[0][1]
k2, v2 = v2c[0][0], v2c[0][1]

if k1 == k2:
    ans -= v2
    m = 0
    if len(v1c) >= 2:
        m = max(m, v1c[1][1])
    if len(v2c) >= 2:
        m = max(m, v2c[1][1])
    ans -= m
else:
    ans -= v1 + v2

print(ans)

Solution (Python):
from collections import Counter

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

E = list(Counter(V[0::2]).most_common())+[(10001,0)]
O = list(Counter(V[1::2]).most_common())+[(10002,0)]

need_not_change = 0
if E[0][0] != O[0][0]:
    need_not_change = E[0][1] + O[0][1]
else:
    need_not_change = max([E[0][1] + O[1][1],E[1][1] + O[0][1]])
print(N - need_not_change)

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

even = list(Counter(V[0::2]).most_common())
even.append((100001,0))
odd = list(Counter(V[1::2]).most_common())
odd.append((100001,0))
if even[0][0] == odd[0][0]:
    o = []
    o.append(even[0][1]+odd[1][1])
    o.append(even[1][1]+odd[0][1])
    print(N-max(o))
else:
    print(N-even[0][1]-odd[0][1])

Solution (Python):
from collections import Counter

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

E = list(Counter(V[0::2]).most_common())
O = list(Counter(V[1::2]).most_common())
E.append((10001,0))
O.append((10002,0))

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

Solution (Python):
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common(2)
odds_c = Counter(odds).most_common(2)

if evens_c[0][0] != odds_c[0][0]:
    print(n - evens_c[0][1] - odds_c[0][1])
    exit()

if len(evens_c) == 1 or len(odds_c) == 1:
    print(n // 2)
    exit()

print(n - max(evens_c[0][1] + odds_c[1][1], evens_c[1][1] + odds_c[0][1]))

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input()) 
    V=list(map(int,input().split()))
    
    if len(set(V))==1:
        print(n//2)
        return
    from collections import Counter
    E=Counter(V[::2]).most_common() 
    O=Counter(V[1::2]).most_common()
    if E[0][0]!=O[0][0]:
        print(n-E[0][1]-O[0][1])
    elif E[0][1]>O[0][1]:
        print(n-E[0][1]-O[1][1])
    elif E[0][1]<O[0][1]:
        print(n-E[1][1]-O[0][1])
    else:
        print(min(n-E[0][1]-O[1][1],n-E[1][1]-O[0][1]))
resolve()

Solution (Python):
import collections

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


odd=collections.Counter(v[::2])
even = collections.Counter(v[1::2])

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

Solution (Python):
import numpy as np

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

list1=[0]*(1+10**5)
list2=[0]*(1+10**5)

for i in range(0, n, 2):
  list1[v[i]]+=1
  
for i in range(1, n, 2):
  list2[v[i]]+=1
  
n1=np.max(list1)
m1=np.argmax(list1)
n2=np.max(list2)
m2=np.argmax(list2)

if m1!=m2:
  print(n-(n1+n2))
else:
  list1[m1]=0
  list2[m2]=0
  n12=np.max(list1)
  n22=np.max(list2)
  print(n-max(n1+n22, n2+n12))

Solution (Python):
import collections

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


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

vc_odd = collections.Counter(v_odd)
vc_even = collections.Counter(v_even)

odd_common = vc_odd.most_common()
even_common = vc_even.most_common()
if odd_common[0][0] != even_common[0][0]:
    print(n - odd_common[0][1] - even_common[0][1])
else:
    if len(odd_common) == 1 and len(even_common) == 1:
        print(len(v_even))
    elif len(odd_common) == 1:
        print(n - odd_common[0][1] - even_common[1][1])
    elif len(even_common) == 1:
        print(n - odd_common[1][1] - even_common[0][1])
    else:
        cnt1 = n - odd_common[1][1] - even_common[0][1]
        cnt2 = n - odd_common[0][1] - even_common[1][1]
        print(min(cnt1, cnt2))

Solution (Python):
import collections

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

even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])
evenc = collections.Counter(even)
oddc = collections.Counter(odd)


evenm = evenc.most_common()
oddm = oddc.most_common()
if evenm[0][0] == oddm[0][0]:
    if len(oddm) == 1:
        ans = n // 2
    else:
        ans = min(n - evenm[0][1] - oddm[1][1], n - evenm[1][1] - oddm[0][1])
else:
    ans = n - evenm[0][1] - oddm[0][1]
print(ans)

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
even_list = [0] * (100000 + 1)
odd_list = [0] * (100000 + 1)

for i in range(n):
    if i % 2 == 0:
        even_list[v[i]] += 1

    else:
        odd_list[v[i]] += 1

if even_list.index(max(even_list)) == odd_list.index(max(odd_list)):
    even_sorted, odd_sorted = sorted(even_list), sorted(odd_list)
    print(min(n - even_sorted[-1] - odd_sorted[-2], n - even_sorted[-2] - odd_sorted[-1]))

else:
    print(n - max(even_list) - max(odd_list))

Solution (Python):
n = int(input())
V = list(map(int,input().split()))
De = {}
Do = {}
for i in range(n):
    x = V[i]
    if i%2==0:
        if x not in De:
            De[x] = 0
        De[x] += 1
    else:
        if x not in Do:
            Do[x] = 0
        Do[x] += 1
DeL = sorted(list(De.items()),key=lambda x:x[1],reverse=True)
DoL = sorted(list(Do.items()),key=lambda x:x[1],reverse=True)
y = DeL[0][0]
z = DoL[0][0]
if y!=z:
    n0 = n//2-De[y]
    n1 = n//2-Do[z]
elif y==z:
    if De[y]>Do[z]:
        z = DoL[1][0]
        n0 = n//2-De[y]
        n1 = n//2-Do[z]
    elif De[y]<Do[z]:
        y = DeL[1][0]
        n0 = n//2-De[y]
        n1 = n//2-Do[z]
    elif De[y]==Do[z]:
        if De[y]==n//2:
            n0 = 0
            n1 = n//2
        elif DeL[1][1]>=DoL[1][1]:
            y = DeL[1][0]
            n0 = n//2-De[y]
            n1 = n//2-Do[z]
        else:
            z = DoL[1][0]
            n0 = n//2-De[y]
            n1 = n//2-Do[z]
print(n0+n1)

Solution (Python):
from collections import Counter
if __name__ == '__main__':
    N = int(input())
    V = list(map(int, input().split()))
    V_low = []
    V_up = []
    for i, v in enumerate(V):
        if i%2 == 0:
            V_low.append(v)
        else:
            V_up.append(v)
    

    count_low = Counter(V_low).most_common()
    count_up = Counter(V_up).most_common()
    
    low_most = count_low[0][0]
    up_most = count_up[0][0]
    
    if low_most != up_most:
        print(len(V_low) + len(V_up) - count_low[0][1] - count_up[0][1])
    else:
        if count_low[0][1] > count_up[0][1]:
            if(len(count_up) == 1):
                print(len(V_low) + len(V_up) - count_low[0][1])
            else:
                print(len(V_low) + len(V_up) - count_low[0][1] - count_up[1][1])
        elif count_low[0][1] <  count_up[0][1]:
            if(len(count_low) == 1):
                print(len(V_low) + len(V_up) - count_up[0][1])
            else:
                print(len(V_low) + len(V_up) - count_up[0][1] - count_low[1][1])
        else:
            if len(count_up) != 1 and len(count_low) != 1:
                if count_low[1][1] <= count_up[1][1]:
                    print(len(V_low) + len(V_up) - count_low[0][1] - count_up[1][1])
                else:
                    print(len(V_low) + len(V_up) - count_up[0][1] - count_low[1][1])
            else:
                if len(count_low) == 1 and len(count_up) == 1:
                    print(len(V_low) + len(V_up) - count_low[0][1])
                elif len(count_low) == 1:
                    print(len(V_low) + len(V_up) - count_low[0][1] - count_up[1][1])
                else:
                    print(len(V_low) + len(V_up) - count_up[0][1] - count_low[1][1])

Solution (Python):

from collections import Counter as ct

n = int(input())
a = [int(i) for i in input().split()]
oddlists=[a[i] for i in range(n)if i%2==0]
evenlists=[a[i]for i in range(n) if i%2!=0]

a1=ct(oddlists).most_common()
a2=ct(evenlists).most_common()


min1=a1[0][1]
min2=a2[0][1]
if a1[0][0]!=a2[0][0]:
    print(n-min1-min2)
if a1[0][0]==a2[0][0]:
    if a1[0][1]==int(n/2):
        print(int(n/2))
    elif a1[0][1]<int(n/2):
        print(min(n-a1[0][1]-a2[1][1],n-a2[0][1]-a1[1][1]))

Solution (Python):
n = int(input())
V = [int(v) for v in input().split(' ')]

even_map = {}
odd_map = {}

for i in range(0, n, 2):
    v = V[i]
    if not v in even_map:
        even_map[v] = 1
    else:
        even_map[v] += 1


for i in range(1, n, 2):
    v = V[i]
    if not v in odd_map:
        odd_map[v] = 1
    else:
        odd_map[v] += 1

even_map[0] = 0
odd_map[0] = 0
even_sorted = sorted(even_map.items(), key=lambda x: -x[1])
odd_sorted = sorted(odd_map.items(), key=lambda x: -x[1])

even1 = even_sorted[0][0]
odd1 = odd_sorted[0][0]

if even1 != odd1:
    print(n - (even_sorted[0][1] + odd_sorted[0][1]))
    exit()

print(min(n - (even_sorted[0][1] + odd_sorted[1][1]), n - (odd_sorted[0][1] + even_sorted[1][1])))

Solution (Python):
def sura_backsura():
    import collections

    N = int(input())
    a = [int(i) for i in input().split()]

    fp = collections.Counter(a[0::2]).most_common()
    sp = collections.Counter(a[1::2]).most_common()

    fp.append((0, 0))
    sp.append((0, 0))

    if fp[0] != sp[0]:
        count = N - fp[0][1] - sp[0][1]
    else:
        count = min(N - fp[0][1] - sp[1][1], N - fp[1][1] - sp[0][1])

    print(count)
    
if __name__ == "__main__":
    sura_backsura()

Solution (Python):





import collections

n=int(input())
li=list(map(int,input().split()))
l=[]
r=[]

for i in range(n):
    if i%2==0:
        l.append(li[i])
    else:
        r.append(li[i])

l_cnt=collections.Counter(l)
r_cnt=collections.Counter(r)


ll=l_cnt.most_common(2)
rr=r_cnt.most_common(2)


if ll[0][0]==rr[0][0]:
    if len(ll)==1 and len(rr)==1:
        print(n//2)
    elif len(ll)==1:
        print(n//2-rr[-1][1])
    elif len(rr)==1:
        print(n//2-ll[-1][1])
    else:
        print((n-max(ll[0][1]+rr[1][1],ll[1][1]+rr[0][1])))
else:
    print(n-ll[0][1]-rr[0][1])

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

odd = collections.defaultdict(int)

even = collections.defaultdict(int)

for i in range(n):
    if i % 2 == 0:
        even[v[i]] += 1

    else:
        odd[v[i]] += 1

even = list(even.items())
odd = list(odd.items())

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

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

Solution (Python):
import collections as col
N= int(input())
A = [int(x) for x in input().split()]
a = A[::2]

a = col.Counter(a)
b = A[1::2]

b = col.Counter(b)
ans = 0
i = 0
j = 0
if len(a.most_common())==1 and len(b.most_common())==1 and a.most_common()[i][0]==b.most_common()[j][0]:
  print(N//2)
  exit()
while a.most_common()[i][0]==b.most_common()[j][0]:
  m=a.most_common()[i][1]
  n=b.most_common()[j][1]
  if m>n:
    j +=1
  elif m==n:
      if a.most_common()[i+1][1]>b.most_common()[j+1][1]:
        i+=1
      else:
        j +=1
  else:
    i +=1

ans += sum(a.values())+sum(b.values())-a.most_common()[i][1]-b.most_common()[j][1]
print(ans)

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7



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

count = 0

from collections import Counter

odd = V[0::2]
even = V[1::2]

od = Counter(odd)
ev = Counter(even)


od[0] = 0
ev[0] = 0


co1 = od.most_common(1)
ce1 = ev.most_common(1)


co2 = od.most_common(2)
ce2 = ev.most_common(2)


if co1[0][0] == ce1[0][0]:
    print(min(N - co1[0][1] - ce2[1][1], N - co2[1][1] - ce1[0][1]))
else:
    
    print(N - co1[0][1] - ce1[0][1])

Solution (Python):
n = int(input())
vs = list(map(int, input().split()))
es = {}
os = {}
for i, v in enumerate(vs):
    if i % 2 == 0:
        v0 = es.get(v, 0)
        es[v] = v0 + 1
    else:
        v0 = os.get(v, 0)
        os[v] = v0 + 1

es_max = max(es, key=es.get)
es_cnt = sum(es.values())
es_ch_len = es_cnt - es[es_max]
del es[es_max]

os_max = max(os, key=os.get)
os_cnt = sum(os.values())
os_ch_len = os_cnt - os[os_max]
del os[os_max]

if os_max == es_max:
    if es == {}:
        es_len = 0
    else:
        es_snd = max(es, key=es.get)
        es_len = es[es_snd]
    if os == {}:
        os_len = 0
    else:
        os_snd = max(os, key=os.get)
        os_len = os[os_snd]
    if es_len > os_len:
        es_ch_len = es_cnt - es_len
    else:
        os_ch_len = os_cnt - os_len

print(os_ch_len+es_ch_len)

Solution (Python):
from collections import Counter

input()
V = [int(v) for v in input().split()]
count1 = 0
count2 = 0
c11 = Counter(V[::2]).most_common()[0][0]
c12 = Counter(V[1::2]).most_common()[0][0]
for v1, v2 in zip(V[::2], V[1::2]):
    if v1 != c11:
        count1 += 1
    if v2 != c12:
        count2 += 1
c21 = Counter(V[1::2]).most_common()
c22 = Counter(V[::2]).most_common()
c21.append((0, 1))
c22.append((0, 1))
c21 = c21[0][0] if c21[0][0] != c11 else c21[1][0]
c22 = c22[0][0] if c22[0][0] != c12 else c22[1][0]
for v1, v2 in zip(V[1::2], V[::2]):
    if v1 != c21:
        count1 += 1
    if v2 != c22:
        count2 += 1
print(min(count1, count2))

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

ki = {}
guu = {}

for i in range(len(V)):
    if i % 2 == 0:
        guu.setdefault(str(V[i]), 0)
        guu[str(V[i])] += 1
    else:
        ki.setdefault(str(V[i]), 0)
        ki[str(V[i])] += 1

guu = sorted(guu.items(), key=lambda x: -x[1])
ki = sorted(ki.items(), key=lambda x: -x[1])

if len(guu) == 1 and len(ki) != 1:
    if ki[0][0] != guu[0][0]:
        print(N//2 - ki[0][1])
        exit()
    else:
        print(N//2 - ki[1][1])
        exit()

if len(ki) == 1 and len(guu) != 1:
    if guu[0][0] != ki[0][0]:
        print(N//2 - guu[0][1])
        exit()
    else:
        print(N//2 - guu[1][1])
        exit()

if len(ki) == 1 and len(guu) == 1:
    if ki[0][0] == guu[0][0]:
        print(N//2)
        exit()
    else:
        print(0)
        exit()

if guu[0][0] != ki[0][0]:
    print(N - guu[0][1]-ki[0][1])
    exit()

if guu[0][1] > ki[0][1]:  
    print(N - guu[0][1] - ki[1][1])
    exit()
if ki[0][1] > guu[0][1]:  
    print(N - ki[0][1] - guu[1][1])
    exit()

if ki[0][1] == guu[0][1]:  
    print(N - ki[0][1] - max(ki[1][1], guu[1][1]))
    exit()

Solution (Python):
import collections

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

eNum=collections.Counter(r[1::2]).most_common()
oNum=collections.Counter(r[::2]).most_common()
eNum.append((0,0))
oNum.append((0,0))



if eNum[0][0]==oNum[0][0]:
  print(len(r)-max(eNum[0][1]+oNum[1][1],eNum[1][1]+oNum[0][1]))
else:
  print(len(r)-eNum[0][1]-oNum[0][1])

Solution (Python):
import collections

N = int(input())
V = list(map(int, input().split()))
Ve = V[::2]
Vo = V[1::2]

Ve_common = collections.Counter(Ve).most_common(2)
Vo_common = collections.Counter(Vo).most_common(2)
if len(set(V)) == 1:
    print(N//2)
elif Ve_common[0][0] != Vo_common[0][0]:
    print(N - Ve_common[0][1] - Vo_common[0][1])
else:
    print(min(N - Ve_common[1][1] - Vo_common[0][1], N - Ve_common[0][1] - Vo_common[1][1]))

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

E=Counter(V[::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[1][1]+O[0][1],E[0][1]+O[1][1]))

Solution (Python):
from sys import stdin
import collections



n = int(stdin.readline())
v = [int(x) for x in stdin.readline().rstrip().split()]



v1 = v[0::2]
v2 = v[1::2]

tmp = len(v1) - len(v2)

v_c = collections.Counter(v)
v1_c = collections.Counter(v1)
v2_c = collections.Counter(v2)

if v1_c.most_common()[0][0] == v2_c.most_common()[0][0]:

    if len(v) == (v_c.most_common()[0][1]):
        ans = len(v) // 2

    else:
        ansA = len(v1) - v1_c.most_common()[0][1] + \
            len(v2) - v2_c.most_common()[1][1]

        ansB = len(v1) - v1_c.most_common()[1][1] + \
            len(v2) - v2_c.most_common()[0][1]

        ans = min(ansA, ansB)

else:
    ans = len(v1) - v1_c.most_common()[0][1] + \
        len(v2) - v2_c.most_common()[0][1]

print(ans)

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

    
    count_seq_even = Counter(V[::2]).most_common(2)
    count_seq_odd = Counter(V[1::2]).most_common(2)

    
    
    
    

    
    
    
    if (len(count_seq_even) == 1 and len(count_seq_odd) == 1
            and count_seq_even[0] == count_seq_odd[0]):
        return N // 2

    ans = float('inf')
    for e, ve in count_seq_even:
        for o, vo in count_seq_odd:
            if e == o:
                continue  
            ans = min(ans, N - (ve + vo))
    return ans

print(c_zigzag())

Solution (Python):


import collections

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

odd = []
even = []

for i in range(n):
   if i % 2 == 0:
       odd.append(inp[i])
   else:
       even.append(inp[i])




o_c = collections.Counter(odd)
o_e = collections.Counter(even)

o_most = o_c.most_common()
e_most = o_e.most_common()

if len(o_most) == len(e_most) == 1:
   if o_most[0][0] != e_most[0][0]:
       ans = 0
   else:
       ans = min(o_most[0][1], e_most[0][1])

else:
   if o_most[0][0] != e_most[0][0]:
       
       if len(o_most) == 1:
           o_ans = 0
       else:
           o_ans = 0
           for i in range(len(o_most)-1):
               o_ans += o_most[i+1][1]

       
       if len(e_most) == 1:
           e_ans = 0
       else:
           e_ans = 0
           for i in range(len(e_most)-1):
               e_ans += e_most[i+1][1]
       
       ans = o_ans + e_ans

   else:
       
       
       o_total=0
       for i in o_most:
       	o_total += i[1]
       
       e_total=0
       for i in e_most:
       	e_total+=i[1]
       
       aa=e_total-e_most[1][1]+o_total-o_most[0][1]
       bb=o_total-o_most[1][1]+e_total-e_most[0][1]
       ans = min(aa,bb)
       
       
       	



print(ans)

Solution (Python):
from collections import Counter

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

evenCnt = Counter(V[::2]).items()
oddCnt = Counter(V[1::2]).items()

evenCnt = list(evenCnt)
oddCnt = list(oddCnt)

evenCnt.sort(key=lambda A: A[1], reverse=True)
oddCnt.sort(key=lambda A: A[1], reverse=True)

if evenCnt[0][0] != oddCnt[0][0]:
    ans = (-(-N // 2) - evenCnt[0][1]) + (N // 2 - oddCnt[0][1])
    print(ans)
else:
    ans = min(
        (-(-N // 2) - evenCnt[0][1]) + N // 2,
        -(-N // 2) + (N // 2 - oddCnt[0][1])
    )
    if len(evenCnt) > 1:
        ans = min(ans, (-(-N // 2) - evenCnt[1][1]) + (N // 2 - oddCnt[0][1]))
    if len(oddCnt) > 1:
        ans = min(ans, (-(-N // 2) - evenCnt[0][1]) + (N // 2 - oddCnt[1][1]))

    print(ans)

Solution (Python):
def calc(n, v):
    m1 = {}
    m2 = {}
    for i in range(0, n, 2):
        m1[v[i]] = 1 + (m1[v[i]] if v[i] in m1 else 0)
    for i in range(1, n, 2):
        m2[v[i]] = 1 + (m2[v[i]] if v[i] in m2 else 0)
    m1a = [(k, m1[k]) for k in m1]
    m1a.sort(key=lambda p: -p[1])
    m2a = [(k, m2[k]) for k in m2]
    m2a.sort(key=lambda p: -p[1])
    if (len(m1a) == 1):
        if (len(m2a) == 1):
            return m1a[0][1] if m1a[0][0] == m2a[0][0] else 0
        else:
            if (m1a[0][0] == m2a[0][0]):
                return n // 2 - m2a[1][1]
            else:
                return n // 2 - m2a[0][1]
    else:
        if(len(m2a) == 1):
            if (m1a[0][0] == m2a[0][0]):
                return n // 2 - m1a[1][1]
            return n // 2 - m1a[0][1]
        else:
            a = m1a[0][1] + (m2a[1][1] if m1a[0][0] ==
                             m2a[0][0] else m2a[0][1])
            b = m2a[0][1] + (m1a[1][1] if m1a[0][0] ==
                             m2a[0][0] else m1a[0][1])
            return n - a if a > b else n - b


n = int(input())
v = [int(s) for s in input().split()]
print(calc(n, v))

Solution (Python):
n = int(input())
V = [int(v) for v in input().split()]

V1 = [V[n] for n in range(0, n, 2)] 
V2 = [V[n] for n in range(1, n, 2)] 

mx_V1 = max(V1)
V1_cnt = [[0, 0]] 
for i in range(1, mx_V1+1):
  V1_cnt.append([i, 0])
for v in V1:
  V1_cnt[v][1] += 1  
V1_cnt.sort(key=lambda x: x[1], reverse=True)

mx_V2 = max(V2)
V2_cnt = [[0, 0]] 
for j in range(1, mx_V2+1):
  V2_cnt.append([j, 0])
for v in V2:
  V2_cnt[v][1] += 1  
V2_cnt.sort(key=lambda x: x[1], reverse=True)

mxnum_V1_cnt = V1_cnt[0][0] 
mxnum_V2_cnt = V2_cnt[0][0] 
if mxnum_V1_cnt != mxnum_V2_cnt:
  ans = n - (V1_cnt[0][1] + V2_cnt[0][1])
else:
  ans = n - max(V1_cnt[0][1] + V2_cnt[1][1], V1_cnt[1][1] + V2_cnt[0][1])

print(ans)

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)

from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    num = int(input())
    data = list(map(int, input().split()))
    odd_list = Counter(data[::2])
    even_list = Counter(data[1::2])
    odd_list = sorted(odd_list.items(), key=lambda x: -x[1])
    even_list = sorted(even_list.items(), key=lambda x: -x[1])

    a, b = num // 2, num // 2
    if odd_list[0][0] != even_list[0][0]:
        a = even_list[0][1]
        b = odd_list[0][1]
    elif len(odd_list) == 1 and len(even_list) == 1:
        a = 0
    elif len(odd_list) == 1:
        a = even_list[1][1]
    elif len(even_list) == 1:
        a = odd_list[1][1]
    else:
        if odd_list[0][1] + even_list[1][1] > odd_list[1][1] + even_list[0][1]:
            a = odd_list[0][1]
            b = even_list[1][1]
        else:
            a = odd_list[1][1]
            b = even_list[0][1]
    ans = num - a - b
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
c1, c2 = Counter(v[::2]), Counter(v[1::2])
mc1, mc2 = c1.most_common(2), c2.most_common(2)
mc1.append((0, 0))
mc2.append((0, 0))

print(n - (max(mc1[0][1] + mc2[1][1], mc1[1][1] + mc2[0][1]) if mc1[0][0] == mc2[0][0] else mc1[0][1] + mc2[0][1]))

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

Solution (Python):
import collections

n=int(input())
v=list(map(int,input().split()))
v0=v[::2]
v1=v[1::2]

v0_c=collections.Counter(v0)
m0=v0_c.most_common()
v1_c=collections.Counter(v1)
m1=v1_c.most_common()



if len(m0)==1:
	mm0=[[m0[0][0],len(v0)-m0[0][1]], ["X",len(v0)]]
else:
  	mm0=[[m0[0][0],len(v0)-m0[0][1]], [m0[1][0],len(v0)-m0[1][1]]]
if len(m1)==1:
	mm1=[[m1[0][0],len(v1)-m1[0][1]], ["X",len(v1)]]
else:
  	mm1=[[m1[0][0],len(v1)-m1[0][1]], [m1[1][0],len(v1)-m1[1][1]]]

print(mm0[0][1]+mm1[0][1] if mm0[0][0]!=mm1[0][0] else min(mm0[0][1]+mm1[1][1],mm0[1][1]+mm1[0][1]))

Solution (Python):
from collections import Counter
from itertools import product

NUM = 0
CNT = 1

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

c_odd = Counter(v[1::2])
c_even = Counter(v[0::2])

odd_12 = c_odd.most_common()[:2]
even_12 = c_even.most_common()[:2]


ans = n
for o, e in product(odd_12 + [(-1, 0)], even_12 + [(-1, 0)]):
    
    if o[NUM] == e[NUM]:
        continue
    ans = min(ans, n - (o[CNT] + e[CNT]))
print(ans)

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
o=[[0,i] for i in range(100001)]
e=[[0,i] for i in range(100001)]
for i in range(n//2):
 o[l[i*2]][0]+=1
 e[l[i*2+1]][0]+=1
o.sort(reverse=True)
e.sort(reverse=True)
res=10000000000000000
for i in range(2):
  for j in range(2):
    if o[i][1]!=e[j][1]:
      res=min(res,n-o[i][0]-e[j][0])
print(res)

Solution (Python):
import sys
from collections import Counter
def main():
    def input():
        return sys.stdin.readline()[:-1]
    n = int(input())
    v = list(map(int,input().split()))
    o = []
    e = []
    for k in range(n):
        if k%2 == 0:
            e.append(v[k])
        else:
            o.append(v[k])
    c = Counter(e).most_common()
    d = Counter(o).most_common()
    if c[0][0] != d[0][0]:
        print(n-c[0][1]-d[0][1])
    else:
        if len(c) >= 2 and len(d) >= 2:
            print(min(n-d[0][1]-c[1][1],n-d[1][1]-c[0][1]))
        elif len(c) >= 2 and len(d) == 1:
            print(n-d[0][1]-c[1][1])
        elif len(d) >= 2 and len(c) == 1:
            print(n-d[1][1]-c[0][1])
        else:
            print(n//2)
if __name__ == '__main__':
    main()

Solution (Python):

from collections import Counter


def main():
    N, *V = open(0).read().split()
    N = int(N)
    even, odd = Counter(V[::2]).most_common(2), Counter(V[1::2]).most_common(2)
    if even[0][0] != odd[0][0]:  
        ans = N - even[0][1] - odd[0][1]
    else:
        if len(even) == 1 or len(odd) == 1:
            ans = N // 2  
        else:  
            ans = N - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from collections import Counter


def main():
    N, *V = map(int, open(0).read().split())
    even, odd = Counter(V[::2]).most_common(2), Counter(V[1::2]).most_common(2)
    if even[0][0] != odd[0][0]:  
        ans = N - even[0][1] - odd[0][1]
    else:
        if len(even) == 1 or len(odd) == 1:
            ans = N // 2  
        else:  
            ans = N - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1])
    print(ans)


if __name__ == "__main__":
    main()