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

Vdic = [{}, {}]

for i in range(len(V_list)):
    v = V_list[i]

    tmp = (i + 1) % 2
    Vdic[tmp][v] = Vdic[tmp].get(v, 0) + 1

even = sorted(Vdic[0].values())
odd = sorted(Vdic[1].values())

ans_even = [(-1, 0)]
ans_odd = [(-2, 0)]
if(len(even) == 1):
    t = max(Vdic[0], key=Vdic[0].get)
    ans_even.append((t, even[0]))
else:
    n1 = even[-1]
    n2 = even[-2]

    f1 = True
    f2 = True
    if(n1 == n2):
        for k, v in Vdic[0].items():
            if(v == n1):
                if(f1 is False and f2 is False):
                    continue
                if(f1 is False):
                    f2 = False
                f1 = False
                ans_even.append((k, v))
    else:
        for k, v in Vdic[0].items():
            if(v == n1 and f1 is True):
                f1 = False
                ans_even.append((k, v))
            if(v == n2 and f2 is True):
                f2 = False
                ans_even.append((k, v))

if(len(odd) == 1):
    t = max(Vdic[1], key=Vdic[1].get)
    ans_odd.append((t, odd[0]))
else:
    n1 = odd[-1]
    n2 = odd[-2]

    f1 = True
    f2 = True
    if(n1 == n2):
        for k, v in Vdic[1].items():
            if(v == n1):
                if(f1 is False and f2 is False):
                    continue
                if(f1 is False):
                    f2 = False
                f1 = False
                ans_odd.append((k, v))
    else:
        for k, v in Vdic[1].items():
            if(v == n1 and f1 is True):
                f1 = False
                ans_odd.append((k, v))
            if(v == n2 and f2 is True):
                f2 = False
                ans_odd.append((k, v))




ans = []
for ke, ve in ans_even:
    for ko, vo in ans_odd:
        if(ke != ko):
            ans.append(n - ve - vo)

print(min(ans))

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

odd_cnt = {}
even_cnt = {}

for i,vi in enumerate(vn):
    if i % 2 == 0:
        if vi in even_cnt:
            even_cnt[vi] += 1
        else:
            even_cnt[vi] = 1
    else:
        if vi in odd_cnt:
            odd_cnt[vi] += 1
        else:
            odd_cnt[vi] = 1





even_max = 0
even_max_num = 0
even_sum = 0
odd_max = 0
odd_max_num = 0
odd_sum = 0
ans = 0
for k,v in sorted(even_cnt.items(), key=lambda x: -x[1]):
    even_sum += v
    if v > even_max:
        even_max = v
        even_max_num = k

for k,v in sorted(odd_cnt.items(), key=lambda x: -x[1]):
    odd_sum += v
    if v > odd_max:
        odd_max = v
        odd_max_num = k

if len(even_cnt) > 1:
    even_2nd = sorted(even_cnt.items(), key=lambda x: -x[1])[1][1]
else:
    even_2nd = 0
if len(odd_cnt) > 1:
    odd_2nd = sorted(odd_cnt.items(), key=lambda x: -x[1])[1][1]
else:
    odd_2nd = 0

if odd_max_num == even_max_num:
    if odd_max == even_max:
        if len(odd_cnt) == 1 and len(even_cnt) == 1:
            ans = even_sum
        elif len(odd_cnt) == 1:
            ans = even_sum - even_2nd
        elif len(even_cnt) == 1:
            ans = odd_sum - odd_2nd
        else:
            if even_2nd > odd_2nd:
                ans = odd_sum - odd_max + even_sum - even_2nd
            else:
                ans = odd_sum - odd_2nd + even_sum - even_max
    elif odd_max > even_max:
        ans = odd_sum - odd_max + even_sum - even_2nd
    else:
        ans = odd_sum - odd_2nd + even_sum - even_max
else:
    ans = odd_sum - odd_max + even_sum - even_max
print(ans)

Solution (Python):


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

former = []
latter = []
counter = 0
for node in v:
    if(counter % 2 == 0):
        former.append(node)
    else:
        latter.append(node)
    counter += 1

forlen = len(former)
latlen = len(latter)

forfreq = [0] * forlen
latfreq = [0] * latlen

former_sorted = sorted(former)
latter_sorted = sorted(latter)


counter = 0
for_val_num = []
next_idx = 0
for i in range(forlen):
    if(former_sorted[i] == former_sorted[next_idx]):
        counter += 1
    else:
        for_val_num.append([former_sorted[next_idx], counter])
        next_idx = i
        counter = 1
    if (i == forlen - 1):
        for_val_num.append([former_sorted[next_idx], counter])

forfreqidx1 = 0

for i in range(len(for_val_num)):
    if(for_val_num[i][1] > for_val_num[forfreqidx1][1]):
        forfreqidx1 = i


forfreqnum1 = for_val_num[forfreqidx1][1]


counter = 0
lat_val_num = []
next_idx = 0
for i in range(latlen):
    if(latter_sorted[i] == latter_sorted[next_idx]):
        counter += 1
    else:
        lat_val_num.append([latter_sorted[next_idx], counter])
        next_idx = i
        counter = 1
    if (i == latlen - 1):
        lat_val_num.append([latter_sorted[next_idx], counter])

latfreqidx1 = 0

for i in range(len(lat_val_num)):
    if(lat_val_num[i][1] > lat_val_num[latfreqidx1][1]):
        latfreqidx1 = i


latfreqnum1 = lat_val_num[latfreqidx1][1]


if(for_val_num[forfreqidx1][0] == lat_val_num[latfreqidx1][0]):
    
    for_val_num[forfreqidx1][1] = 0
    lat_val_num[latfreqidx1][1] = 0

    forfreqidx2 = 0

    for i in range(len(for_val_num)):
        if (for_val_num[i][1] > for_val_num[forfreqidx2][1]):
            forfreqidx2 = i

    
    forfreqnum2 = for_val_num[forfreqidx2][1]

    latfreqidx2 = 0

    for i in range(len(lat_val_num)):
        if (lat_val_num[i][1] > lat_val_num[latfreqidx2][1]):
            latfreqidx2 = i

    
    latfreqnum2 = lat_val_num[latfreqidx2][1]

    if(forfreqnum1 - forfreqnum2 >= latfreqnum1 - latfreqnum2):
        print((forlen - forfreqnum1) + (latlen - latfreqnum2))
    else:
        print((forlen - forfreqnum2) + (latlen - latfreqnum1))
else:
    print((forlen - forfreqnum1) + (latlen - latfreqnum1))

Solution (Python):
import collections

n = int(input())
a = [ int(x) for x in input().split() ]

def count_elem(x):
    coll = collections.Counter(x)
    return coll.most_common()

b = count_elem(a[::2])
c = count_elem(a[1::2])

if b[0][0] != c[0][0]:
    print(len(a) - b[0][1] - c[0][1])
else:
    if b[0][1] > c[0][1]:
        if len(c) > 1:
            print(len(a) - b[0][1] - c[1][1])
        else:
            print(len(a) - b[0][1])
    elif b[0][1] < c[0][1]:
        if len(b) > 1:
            print(len(a) - b[1][1] - c[0][1])
        else:
            print(len(a) - c[0][1])
    elif b[0][1] == c[0][1]:
        if len(a)/2 == b[0][1]:
            print(int(len(a)/2))
        else:
            if b[1][1] >= c[1][1]:
                print(len(a) - b[1][1] - c[0][1])
            else:
                print(len(a) - b[0][1] - c[1][1])

Solution (Python):
from collections import Counter

if __name__ == '__main__':
    n = int(input())
    vs = list(map(int, input().split()))

    even = vs[::2]
    odd = vs[1::2]

    def solve(even, odd):
        ce = Counter(even)
        co = Counter(odd)
        
        emode = ce.most_common()
        omode = co.most_common()
        
        result = 0
        if emode[0][0] != omode[0][0]:
            for i in range(1, len(emode)):
                result += emode[i][1]
            for i in range(1, len(omode)):
                result += omode[i][1]
            
            return result
        
        else:
            temp1 = 0
            temp2 = 0
            for i in range(1, len(emode)):
                temp1 += emode[i][1]
            
            if len(omode) == -1:
                temp1 += len(odd)
            else:
                for i in range(len(omode)):
                    if i == 1:
                        continue
                    else:
                        temp1 += omode[i][1]
                        
                        
            for i in range(1, len(omode)):
                temp2 += omode[i][1]
            
            if len(emode) == -1:
                temp2 += len(even)
            else:
                for i in range(len(emode)):
                    if i == 1:
                        continue
                    else:
                        temp2 += emode[i][1]
            result = min(temp1, temp2)
            
            return result
        
    print(solve(even, odd))

Solution (Python):
import collections

n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
ac = collections.Counter(a)
bc = collections.Counter(b)
ac = sorted(ac.items(), key=lambda x: x[1], reverse=True)
bc = sorted(bc.items(), key=lambda x: x[1], reverse=True)
if ac[0][0] == bc[0][0]:
    if len(ac) == len(bc) and len(ac) == 1:
        print(ac[0][1])
        exit()
    i = 0
    while ac[i][1] == bc[i][1]:
        i += 1
        if i == len(ac) - 1 or i == len(bc) - 1:
            break
    if ac[i][1] > bc[i][1]:
        ac.remove(ac[i])
        bc.remove(bc[0])
    elif ac[i][1] < bc[i][1]:
        ac.remove(ac[0])
        bc.remove(bc[i])
    else:
        ac.remove(ac[0])
        bc.remove(bc[1])
else:
    ac.remove(ac[0])
    bc.remove(bc[0])
ans = 0
for i in range(len(ac)):
    ans += ac[i][1]
for i in range(len(bc)):
    ans += bc[i][1]
print(ans)

Solution (Python):

from collections import defaultdict

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

d0 = defaultdict(int)
d1 = defaultdict(int)
for i in range(len(v)):
    if i % 2 == 1:
        d1[v[i]] += 1
    else:
        d0[v[i]] += 1

max1 = 0
max12 = 0
for i in d1.keys():
    if max1 < d1[i]:
        max12 = max1
        max1 = d1[i]
        max1n = i
    elif max12 < d1[i]:
        max12 = d1[i]
max0 = 0
max02 = 0
for i in d0.keys():
    if max0 < d0[i]:
        max02 = max0
        max0 = d0[i]
        max0n = i
    elif max02 < d0[i]:
        max02 = d0[i]
if max1n == max0n:
    if max0 < max1:
        print(int(n / 2 - max02 + n / 2 - max1))
    elif max1 < max0:
        print(int(n / 2 - max0 + n / 2 - max12))
    else:
        if max12 < max02:
            print(int(n / 2 - max02 + n / 2 - max1))
        else:
            print(int(n / 2 - max0 + n / 2 - max12))
else:
    print(int(n / 2 - max0 + n / 2 - max1))

Solution (Python):
import collections
import sys

n = input()
n = int(n)
v = [0]*int(n)
v[:] = map(int, input().split())


v_o = [0]*int((n/2))
v_e = [0]*int((n/2))
for i in range(n):
    if i%2 == 0:
        v_o[i//2] = v[i]
    else:
        v_e[i//2] = v[i]

cnt_o = collections.Counter(v_o).most_common(2)

collections.Counter(v_e).most_common(1)
cnt_e = collections.Counter(v_e).most_common(2)


if cnt_o[0][0] == cnt_e[0][0]:
    if (cnt_o[0][1] == n//2) and (cnt_e[0][1] == n//2):
        print(n//2)
        sys.exit()
    if cnt_o[0][1] >= cnt_e[0][1]:
        n_min = n -cnt_o[0][1] - cnt_e[1][1]
        if (n_min > n -cnt_o[1][1] - cnt_e[0][1]):
            n_min = n -cnt_o[1][1] - cnt_e[0][1]
        print(n_min)
        sys.exit()
    elif cnt_o[0][1] < cnt_e[0][1]:
        n_min = n -cnt_o[1][1] - cnt_e[0][1]
        if (n_min > n -cnt_o[0][1] - cnt_e[1][1]):
            n_min = n -cnt_o[0][1] - cnt_e[1][1]
        print(n_min)
        sys.exit()
else:
    n_min = n -cnt_o[0][1] - cnt_e[0][1]
    print(n_min)
    sys.exit()

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
even = {}
odd = {}
for i in range(n):
    if i % 2 == 0:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1
    else:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1

def check(dic1, dic2):
    if len(dic1) == 1 and len(dic2) == 1 and list(dic1.keys()) != list(dic2.keys()):
        return True
    else:
        return False

def maxkey(dic):
    maxkey = 0
    maxvalue = 0
    for key in dic:
        value = dic[key]
        if maxvalue < value:
            maxvalue = value
            maxkey = key
    return maxkey

if check(even, odd):
    print(0)
elif len(list(set(v))) == 1:
    print(int(n/2))
else:
    evenlist = sorted(list(even.values()))
    oddlist = sorted(list(odd.values()))
    evenlist.reverse()
    oddlist.reverse()
    if maxkey(even) != maxkey(odd):
        ans = n/2 - evenlist[0] + n/2 - oddlist[0]
        print(int(ans))
    else:
        if len(evenlist) == 1:
            ans = n/2-evenlist[0] + n/2-oddlist[1]
        elif len(oddlist) == 1:
            ans = n/2-evenlist[1] + n/2-oddlist[0]
        else:
            ans = min(n/2-evenlist[0] + n/2-oddlist[1], n/2-evenlist[1] + n/2-oddlist[0])
        print(int(ans))

Solution (Python):
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())
a = ai()
if all(i == a[0] for i in a):
    print(n//2)
    exit()

a1 = a[::2]
a2 = a[1::2]

from collections import Counter
c1 = Counter(a1)
c2 = Counter(a2)
m1 = c1.most_common(2)
m2 = c2.most_common(2)
if m1[0][0] == m2[0][0]:
    if len(c1) == 1:
        print(n-m1[0][1]-m2[1][1])
    elif len(c2) == 1:
        print(n - m1[0][1] - m2[1][1])
    else:
        print(min(n-m1[0][1]-m2[1][1], n-m1[1][1]-m2[0][1]))
else:
    print(n-m1[0][1] - m2[0][1])

Solution (Python):
import bisect

n=int(input())
v = list(map(int,input().split()))
x = []
y = []

for i in range(n):
    if i %2 ==0:
        x.append(v[i])
    else:
        y.append(v[i])
x.sort()
y.sort()
xk = list(set(x))
yk= list(set(y))
xk.sort()
yk.sort()

a = []
b = []
k = 0
l = 0
while k < len(x) :
    aa = bisect.bisect_right(x,x[k])
    a.append(aa-k)
    k = aa
while l < len(y) :
    bb = bisect.bisect_right(y,y[l])
    b.append(bb-l)
    l = bb

c = sorted(a)
d = sorted(b)

aaa = [i for i, xx in enumerate(a) if xx == c[-1]]
bbb = [i for i, xx in enumerate(b) if xx == d[-1]]






if len(aaa)>= 2 or len(bbb)>= 2:
    print(n-c[-1]-d[-1])
else:
    jkl = a.index(c[-1])
    jkll= b.index(d[-1])
    if xk[jkl] == yk[jkll]:
        ans = 100000000000000
        if len(d) >= 2:
            ans = n-c[-1]-d[-2]
        if len(c) >= 2:
            ans = min(ans,n-c[-2]-d[-1])
        if ans == 100000000000000:
            ans = n//2
        print(ans)
    else:
        print(n-c[-1]-d[-1])

Solution (Python):
import collections



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

odd = [suuretsu[i] for i in range(n) if i % 2 != 0]
even = [suuretsu[i] for i in range(n) if i % 2 == 0]
ans = 0




count_dict_odd = collections.Counter(odd)
count_dict_even = collections.Counter(even)

if count_dict_odd.most_common(n)[0][0] == count_dict_even.most_common(n)[0][0]:
  
  if count_dict_odd.most_common(n)[0][1] == count_dict_even.most_common(n)[0][1]:
    if len(count_dict_odd.most_common(n))== 1 and len(count_dict_even.most_common(n)) == 1:
      ans = int(n/2)
    elif len(count_dict_odd.most_common(n)) > len(count_dict_even.most_common(n)):
      ans = n-count_dict_odd.most_common(n)[0][1]-count_dict_even.most_common(n)[1][1]
    elif len(count_dict_odd.most_common(n)) < len(count_dict_even.most_common(n)):
      ans = n-count_dict_odd.most_common(n)[1][1]-count_dict_even.most_common(n)[0][1]
    else:
      if count_dict_odd.most_common(n)[1][1] >= count_dict_even.most_common(n)[1][1]:
        ans = n-count_dict_odd.most_common(n)[1][1]-count_dict_even.most_common(n)[0][1]
      else:
        ans = n-count_dict_odd.most_common(n)[0][1]-count_dict_even.most_common(n)[1][1]	      
  elif count_dict_odd.most_common(n)[0][1] > count_dict_even.most_common(n)[0][1]:
    ans = n-count_dict_odd.most_common(n)[0][1]-count_dict_even.most_common(n)[1][1]
  else:
    ans = n-count_dict_odd.most_common(2)[0][1]-count_dict_even.most_common(1)[0][1]
else:
    ans = n-count_dict_odd.most_common(n)[0][1]-count_dict_even.most_common(n)[0][1]

    
print(ans)

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

kisu = [str(v) for i,v in enumerate(V) if i % 2 == 1]
gusu = [str(v) for i,v in enumerate(V) if i % 2 == 0]

from collections import Counter

kisu_c = Counter(kisu).most_common()
gusu_c = Counter(gusu).most_common()

ans = 0


if len(kisu_c) == 1 and len(gusu_c) == 1:
    if kisu_c[0][0] == gusu_c[0][0]:
        print(kisu_c[0][1])
    else:
        print(0)
    exit()
elif len(kisu_c) == 1:
    gusu_c.pop(0)

    for i in gusu_c:
        ans += i[1]
    print(ans)
    exit()
elif len(gusu_c) == 1:
    kisu_c.pop(0)

    for i in kisu_c:
        ans += i[1]
    print(ans)
    exit()



if kisu_c[0][0] == gusu_c[0][0]:
    if kisu_c[0][1] < gusu_c[0][1]:
        gusu_c.pop(0)
        kisu_c.pop(1)
    elif kisu_c[0][1] > gusu_c[0][1]:
        gusu_c.pop(1)
        kisu_c.pop(0)
    else:
        if kisu_c[1][1] > gusu_c[1][1]:
            kisu_c.pop(1)
            gusu_c.pop(0)
        else:
            kisu_c.pop(0)
            gusu_c.pop(1)

else:
    kisu_c.pop(0)
    gusu_c.pop(0)


for i in kisu_c:
    ans += i[1]
for i in gusu_c:
    ans += i[1]

print(ans)

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

A1=[]
A2=[]
for i in range(len(A)):
    if i%2==0:
        A1.append(A[i])
    else:
        A2.append(A[i])
        
B1=collections.Counter(A1)
B2=collections.Counter(A2)

if N==2:
    print(0)

elif B1.most_common(2)[0][1]==B2.most_common(2)[0][1] and B1.most_common(2)[0][1]==int(N/2):
    if B1.most_common(1)==B2.most_common(1):
        print(int(N/2))
    else:
        print(0)
else:
    
    
    if B1.most_common(1)==B2.most_common(1):
        
        if B1.most_common(2)[1][1]>=B2.most_common(2)[1][1]:
            ans=N-B1.most_common(2)[1][1]-B2.most_common(2)[0][1]
        else:
            ans=N-B2.most_common(2)[1][1]-B1.most_common(2)[0][1]
    elif B1.most_common(2)[0][0]==B2.most_common(2)[0][0]:
        if B1.most_common(2)[0][1]>=B2.most_common(2)[0][1]:
            ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[1][1]
        else:
            ans=N-B2.most_common(2)[0][1]-B1.most_common(2)[1][1]
    else:
        ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[0][1]
    print(ans)

Solution (Python):
from collections import Counter 

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

x=[]
y=[]

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

cx=Counter(x)
cy=Counter(y)

ax=cx.most_common(2)
ay=cy.most_common(2)

if len(ax)==1:
    ax=ax+ax

if len(ay)==1:
    ay=ay+ay
   

if not ax[0][0]==ay[0][0]:
    print(n-ax[0][1]-ay[0][1])
else:
    if ax[0][1]==n//2:
        if ay[0][1]==n//2:
            print(n-ay[0][1])
        else:
            print(n//2-ay[1][1])
    elif ay[0][1]==n//2:
        print(n//2-ax[1][1])
    else:
        if ax[0][1]<ay[0][1]:
            print(n-ax[1][1]-ay[0][1])
        elif ax[0][1]>ay[0][1]:  
            print(n-ax[0][1]-ay[1][1])
        else:
            if ax[1][1]<ay[1][1]: 
                print(n-ax[0][1]-ay[1][1])
            else:
                print(n-ay[0][1]-ax[1][1])

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


odd = v[::2]
even = v[1::2]

odd2 = Counter(odd)
even2 = Counter(even)

if len(list(set(v))) == 1:
    print(n//2)

else:
    if odd2.most_common()[0][0] == even2.most_common()[0][0]:
        if odd2.most_common()[0][1] > even2.most_common()[0][1]:
            print(n - odd2.most_common()[0][1] - even2.most_common()[1][1])
        elif odd2.most_common()[0][1] < even2.most_common()[0][1]:
            print(n - odd2.most_common()[1][1] - even2.most_common()[0][1])
        else:
            if odd2.most_common()[1][1] > even2.most_common()[1][1]:
                print(n - odd2.most_common()[1][1] - even2.most_common()[0][1])
            else:
                print(n - odd2.most_common()[0][1] - even2.most_common()[1][1])
    else:
        print(n - odd2.most_common()[0][1] - even2.most_common()[0][1])

Solution (Python):
import collections as cole


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

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

d1 = cole.Counter(v1)
d2 = cole.Counter(v2)

values1, counts1 = zip(*d1.most_common())
values2, counts2 = zip(*d2.most_common())

max1 = values1[0]
max2 = values2[0]

if max1 == max2:
    if len(counts1) != 1 and counts1[0] == counts1[1]:
        max1 = values1[1]
    elif len(counts2) != 1 and counts2[0] == counts2[1]:
        max2 = values2[1]
    elif len(counts1) != 1 and len(counts2) != 1:
        if counts1[1] > counts2[1]:
            max1 = values1[1]
        else:
            max2 = values2[1]
    elif len(counts1) != 1:
        max1 = values1[1]
    elif len(counts2) != 1:
        max2 = values2[1]


count = 0
if max1 != max2:
    count += len([x for x in v1 if x != max1])
    count += len([y for y in v2 if y != max2])

else:
    count += len(v1)


print(count)

Solution (Python):
import collections

N = int(raw_input().replace("\n", ""))

a_list = map(int, raw_input().replace("\n", "").split(" "))
even_list = a_list[::2]
odd_list = a_list[1::2]

len_vec = N / 2

even_c = collections.Counter(even_list)
odd_c = collections.Counter(odd_list)

even_c_most_common = even_c.most_common()
odd_c_most_common = odd_c.most_common()

even_first_value, even_first_count = even_c_most_common[0]
odd_first_value, odd_first_count  = odd_c_most_common[0]



if even_first_value == odd_first_value and len(even_c) == 1 and len(odd_c) == 1:
    cost = len_vec
elif even_first_value != odd_first_value:
    cost =  (even_first_count + odd_first_count)
elif len(even_c) == 1 and len(odd_c) > 1:
    odd_second_value, odd_second_count = odd_c_most_common[1]
    cost = len_vec + odd_second_count
elif len(odd_c) == 1 and len(even_c) > 1:
    even_second_value, even_second_count = even_c_most_common[1]
    
    cost = len_vec + even_second_count
else: 
    odd_second_value, odd_second_count = odd_c_most_common[1]
    even_second_value, even_second_count = even_c_most_common[1]
    cost = max(even_first_count+odd_second_count, even_second_count+odd_first_count)

print(2* len_vec - cost)

Solution (Python):

import collections

n = int(input())
sl = input().split()

sl1 = sl[0::2]
sl2 = sl[1::2]
c1 = collections.Counter(sl1)
c2 = collections.Counter(sl2)
mc1k = c1.most_common()[0][0]
mc1v = c1.most_common()[0][1]
mc2k = c2.most_common()[0][0]
mc2v = c2.most_common()[0][1]

if mc1k == mc2k:
    mc1ks = len(c1.most_common())
    mc2ks = len(c2.most_common())
    if mc1ks > 1 and mc2ks > 1:
        mc1_2v = c1.most_common()[1][1]
        mc2_2v = c2.most_common()[1][1]
        if mc1_2v > mc2_2v:
            mc1v = mc1_2v
        else:
            mc2v = mc2_2v
    elif mc1ks > 1:
        mc1_2v = c1.most_common()[1][1]
        mc1v = mc1_2v
    elif mc2ks > 1:
        mc2_2v = c2.most_common()[1][1]
        mc2v = mc2_2v
    else:
        mc2v = 0
print(n - mc1v - mc2v)

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int, input().split()))
v1=[]
v2=[]
for i in range(0,n-1,2):
    v1.append(v[i])
    v2.append(v[i+1])

v1C=list(sorted(list(Counter(v1).items()), key=lambda x: x[1]))
v2C=list(sorted(list(Counter(v2).items()), key=lambda x: x[1]))

a=v1C[-1][1]
b=v2C[-1][1]
if v1C[-1][0]==v2C[-1][0]:

    if len(v1C)>1 and len(v2C)>1:
        if (len(v1)-v1C[len(v1C)-2][1]+len(v2)-b)>(len(v1)-a+len(v2)-v2C[len(v2C)-2][1]):
            b=v2C[len(v2C)-2][1]
        else:
            a=v1C[len(v1C)-2][1]
    elif a>=b and (len(v1C)>1 or len(v2C)>1):
        b=v2C[len(v2C)-2][1]
    elif a<b and (len(v1C)>1 or len(v2C)>1):
        a=v1C[len(v1C)-2][1]
    else:
        b=0

print(len(v1)-a+len(v2)-b)

Solution (Python):
import collections
n = int(raw_input())
a = map(int,raw_input().split())
a1 = []
a2 = []
for i in range(1,n+1,2):
  a1.append(a[i-1])
for i in range(2,n+2,2):
  a2.append(a[i-1])
c = collections.Counter(a1)
d = collections.Counter(a2)
b1 = c.most_common()
b2 = d.most_common()
x = b1[0]
x1 = x[1]
y = b2[0]
y1 = y[1]
if x1==n/2 and y1==n/2 and x[0]==y[0]:
  print n/2
elif x1==n/2 and x[0]==y[0]:
  w = b2[1]
  w1 = w[1]
  print n/2-w1
elif x1==n/2:
  print n/2-y1
elif y1==n/2 and x[0]==y[0]:
  z = b1[1]
  z1 = z[1]
  print n/2-z1
elif y1==n/2:
  print n/2-x1
else:
  z = b1[1]
  z1 = z[1]
  w = b2[1]
  w1 = w[1]
  if x[0]==y[0]:
    if x1+w1 >= y1+z1:
      print n-x1-w1
    else:
      print n-y1-z1
  else:
    print n-x1-y1

Solution (Python):
n = int(input())
l = [int(_) for _ in input().split()]

dict_e = {}
for i in range(1, n, 2):
    if l[i] in dict_e.keys():
        dict_e[l[i]] += 1
    else:
        dict_e[l[i]] = 1

even_key, even_value = max(dict_e.items(),key = lambda x:x[1])

dict_a = {}
for i in range(0, n, 2):
    if l[i] in dict_a.keys():
        dict_a[l[i]] += 1
    else:
        dict_a[l[i]] = 1

add_key, add_value = max(dict_a.items(),key = lambda x:x[1])

if even_key != add_key:
    ans = n - even_value - add_value
else:
    if even_value > add_value:
        if len(dict_a) >= 2:
            add_value = sorted(dict_a.items(), key = lambda x:x[1])[-2][1]
        else:
            add_value = 0
        ans = n - even_value - add_value
    elif even_value == add_value:
        if len(dict_e) == 1:
            even_value = 0
            ans = n - add_value - even_value
        else:
            even_value = sorted(dict_e.items(), key = lambda x:x[1])[-2][1]
            add_value = sorted(dict_a.items(), key = lambda x:x[1])[-2][1]
            if even_value > add_value:
                add_value = max(dict_a.items(),key = lambda x:x[1])[1]
                ans = n - even_value - add_value
            else:
                even_value = max(dict_e.items(),key = lambda x:x[1])[1]
                ans = n - even_value - add_value
    else:
        if len(dict_e) >= 2:
            even_value = sorted(dict_e.items(), key = lambda x:x[1])[-2][1]
        else:
            even_value = 0
        ans = n - even_value - add_value

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1m = max(c1.items(), key=lambda x:x[1])
c2m = max(c2.items(), key=lambda x:x[1])
if len(set(A)) == 1:
    print(N // 2)
    exit()
c1c2 = max(c for k,c in c2.items() if c1m[0]!=k)
c2c1 = max(c for k,c in c1.items() if c2m[0]!=k)
print(min(N - c1m[1] - c1c2, N - c2m[1] - c2c1))

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
vo = [v[i] for i in range(n) if i%2 == 0]
ve = [v[i] for i in range(n) if i%2 == 1]
vo_dict = collections.Counter(vo)
ve_dict = collections.Counter(ve)
if vo_dict == ve_dict and len(vo_dict) == 1:
    ans = n//2
else:
    if vo_dict.most_common()[0][0] != ve_dict.most_common()[0][0]:
        ans = n - vo_dict.most_common()[0][1] - ve_dict.most_common()[0][1]
    else:
        ans = min(n - vo_dict.most_common()[0][1] - ve_dict.most_common(2)[1][1],
                  n - vo_dict.most_common(2)[1][1] - ve_dict.most_common()[0][1])
print(ans)

Solution (Python):

import collections

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


def map_all(li):
    return all([e == li[0] for e in li[1:]]) if li else False


evel = collections.Counter()
evel2 = []
odd = collections.Counter()
odd2 = []
for index, v in enumerate(V):
    if index % 2 == 0:
        evel[v] += 1
        evel2.append(v)
    else:
        odd[v] += 1
        odd2.append(v)

if map_all(evel2) and map_all(odd2):
    
    if evel2[0] == odd2[0]:
        
        print(int(n / 2))
    else:
        print(0)
else:
    el = evel.most_common(100)
    ol = odd.most_common(100)
    max_val = 0
    for index_e, num_e in el:
        for index_o, num_o in ol:
            if index_e != index_o:
                max_val = max(max_val, num_e + num_o)
    ans = n - max_val
    print(ans)

Solution (Python):
import copy
n=int(input())
V=list(map(int, input().split(" ")))
d1=[0 for i in range(100000)]
for i in V[::2]:
    d1[i-1]+=1
d2=[0 for i in range(100000)]
for i in V[1::2]:
    d2[i-1]+=1

m1=max(d1)
m2=max(d2)
maxind1 = [i for i, x in enumerate(d1) if x == m1]
maxind2 = [i for i, x in enumerate(d2) if x == m2]






if (maxind1[0] == maxind2[0]) and (len(maxind1) == 1) and (len(maxind2) == 1):
    
    
    tmp=copy.copy(d2)
    tmp[maxind2[0]]=0
    result1=n-max(d1)-max(tmp)

    
    
    tmp=copy.copy(d1)
    tmp[maxind1[0]]=0
    result2=n-max(tmp)-max(d2)
    print(int(min(result1,result2)))
else:


    tmp1=n/2-max(d1)
    tmp2=n/2-max(d2)
    print(int(tmp1+tmp2))

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

min_num = 0

even = {}
odd = {}

for i, v in enumerate(v_list):
    if i % 2 == 0:
        if v in even:
            even[v] += 1
        else:
            even[v] = 1
    else:
        if v in odd:
            odd[v] += 1
        else:
            odd[v] = 1

even_max = sorted(even.items(), key=lambda x: -x[1])
odd_max = sorted(odd.items(), key=lambda x: -x[1])

even_num = even_max[0][0]
odd_num = odd_max[0][0]

if odd_num == even_num:
    if len(odd_max) == 1 and len(even_max) == 1:
        odd_num = 10 ** 5 + 1
    elif len(odd_max) == 1:
        even_num = even_max[1][0]
    elif len(even_max) == 1:
        odd_num = odd_max[1][0]
    else:
        first_e = even_max[0][1]
        first_d = odd_max[0][1]
        if first_e > first_d:
            odd_num = odd_max[1][0]
        elif first_e < first_d:
            even_num = even_max[1][0]
        elif first_e == first_d:
            second_e = even_max[1][1]
            second_d = odd_max[1][1]
            if second_e >= second_d:
                even_num = even_max[1][0]
            else:
                odd_num = odd_max[1][0]

for i, v in enumerate(v_list):
    if i % 2 == 0:
        if v != even_num:
            min_num += 1
    else:
        if v != odd_num:
            min_num += 1
print(min_num)

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

if len(set(v)) == 1:
    print(N//2)
else:
    v_gu = v[::2]
    v_ki = v[1::2]
    gu_con = collections.Counter(v_gu)
    ki_con = collections.Counter(v_ki)
    gugu = gu_con.most_common()
    kiki = ki_con.most_common()
    
    if gugu[0][0] != kiki[0][0]:
        print(N-gugu[0][1]-kiki[0][1])
    
    elif len(gugu) == 1 and len(kiki) >=2:
        print(N-gugu[0][1]-kiki[1][1])
        
    elif len(gugu) >= 2 and len(kiki) == 1:
        print(N-gugu[1][1]-kiki[0][1])
    else:
        print(min(N-gugu[0][1]-kiki[1][1],N-gugu[1][1]-kiki[0][1]))