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())
Z=list(map(int,input().split()))
from collections import Counter
c=Counter(Z[::2]).most_common(2)+[(0,0)]
c2=Counter(Z[1::2]).most_common(2)+[(0,0)]
if c[0][0]!=c2[0][0]:
    print(N-c[0][1]-c2[0][1])
else:
    print(min(N-c[1][1]-c2[0][1],N-c[0][1]-c2[1][1]))

Solution (Python):
from collections import Counter

n = int(input())
list_A = list(map(int, input().split()))
L, R = [], []

for i in range(n):
    if i % 2 == 0:
        L.append(list_A[i])
    else:
        R.append(list_A[i])

A = Counter(L)
A = sorted(A.items(), key=lambda x:x[1], reverse=True)
A.append((-1, 0))

B = Counter(R)
B = sorted(B.items(), key=lambda x:x[1], reverse=True)
B.append((-1, 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):
N = int(input())
V = list(map(int,input().split()))

from collections import Counter

def get_counter(X):
  counter = Counter(X)
  X = counter.most_common()
  X.append((0,0))
  return X

V1 = get_counter(V[::2])
V2 = get_counter(V[1::2])

if V1[0][0] != V2[0][0]:
  print(N - (V1[0][1] + V2[0][1]))
else:
  print(N - max(V1[0][1] + V2[1][1],V1[1][1] + V2[0][1]))

Solution (Python):

from collections import Counter


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    O = Counter(A[::2])
    E = Counter(A[1::2])

    most_O = O.most_common(2)
    most_E = E.most_common(2)
    
    most_O.append((0, 0))
    most_E.append((0, 0))

    cnt = 0
    
    if most_O[0][0] == most_E[0][0]:
        
        res1 = most_O[0][1] + most_E[1][1]
        res2 = most_O[1][1] + most_E[0][1]
        cnt = max(res1, res2)
    else:
        cnt = most_O[0][1] + most_E[0][1]

    
    print(N - cnt)


if __name__ == "__main__":
    resolve()

Solution (Python):
import collections
n = int(input())
a = [int(x) for x in input().split()]
even = []
uneven = []
for i in range(n):
  if i%2 == 0:
    uneven.append(a[i])
    continue
  even.append(a[i])

uneven_counter = collections.Counter(uneven)
sortede_uneven_counter = sorted(uneven_counter.items(),key=lambda x:x[1],reverse=True)
even_counter = collections.Counter(even)
sortede_even_counter = sorted(even_counter.items(),key=lambda x:x[1],reverse=True)
  
ans = (n/2 - sortede_uneven_counter[0][1]) + (n/2 - sortede_even_counter[0][1])

if sortede_uneven_counter[0][0] == sortede_even_counter[0][0]:
  if len(set(a)) == 1:
    ans = n/2
  elif sortede_uneven_counter[0][0] ==sortede_even_counter[0][0]:
    ans = (n/2 - sortede_uneven_counter[1][1]) + (n/2 - sortede_even_counter[0][1])
    ans2 = (n/2 - sortede_uneven_counter[0][1]) + (n/2 - sortede_even_counter[1][1])
    if ans2<ans:
      ans = ans2

print(int(ans))

Solution (Python):
n=int(input())
v=list(input().split())
v0={}
v1={}
for i in range(0,n,2):
    if v[i] in v0:
        v0[v[i]]+=1
    else:
        v0[v[i]]=1
for i in range(1,n,2):
    if v[i] in v1:
        v1[v[i]]+=1
    else:
        v1[v[i]]=1
v0=sorted(v0.items(), key=lambda x:x[1], reverse=True)
v1=sorted(v1.items(), key=lambda x:x[1], reverse=True)
if v0[0][0]==v1[0][0]:
    if len(v0)==1:
        print(int(n/2))
    else:
        print(n-v0[0][1]-(v0[1][1] if v0[1][1]>v1[1][1] else v1[1][1] ))
else:
    print(n-v0[0][1]-v1[0][1])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a1 = a[::2]
a2 = a[1::2]

from collections import Counter
c = Counter(a1)
c1 = []
for i in c:
    c1.append([c[i],i])
c1.sort(reverse = True)

c = Counter(a2)
c2 = []
for i in c:
    c2.append([c[i],i])
c2.sort(reverse = True)

ans = n
if c1[0][1] != c2[0][1]:
    ans -= c1[0][0]
    ans -= c2[0][0]
else:
    buf1 = 0
    buf1 += c1[0][0]
    if len(c2) > 1: buf1 += c2[1][0]
    buf2 = 0
    buf2 += c2[0][0]
    if len(c1) > 1: buf2 += c1[1][0]
    ans -= max(buf1,buf2)
print(ans)

Solution (Python):
N = int(input())
V = list(map(int,input().split()))
O = []
E = []
nums_O = []
nums_E = []

for i in range(0,N,2):
  O.append(V[i])
  E.append(V[i+1])

for j in range(100000):
  nums_O.append([0,j])
  nums_E.append([0,j])

for k in range(N//2):
  nums_O[O[k]-1][0] += 1
  nums_E[E[k]-1][0] += 1
  
nums_O.sort()
nums_E.sort()

if nums_O[-1][1] != nums_E[-1][1]:
  print(N-(nums_O[-1][0] + nums_E[-1][0]))
else:
  print(N-max(nums_E[-2][0]+nums_O[-1][0],nums_O[-2][0]+nums_E[-1][0]))

Solution (Python):









import os
import sys


from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    v_even = [v[i] for i in range(0, len(v), 2)]
    v_odd = [v[i] for i in range(1, len(v), 2)]
    even_cnt = sorted(map(list, Counter(v_even).items()), key=lambda x: x[1], reverse=True)
    odd_cnt = sorted(map(list, Counter(v_odd).items()), key=lambda x: x[1], reverse=True)
    odd_impo = 0
    even_impo = 0
    if len(even_cnt) == 1 and len(odd_cnt) == 1:
        if even_cnt[0][0] == odd_cnt[0][0]:
            if even_cnt[0][1] < odd_cnt[0][1]:
                print(even_cnt[0][1])
                return

            else:
                print(even_cnt[0][1])
                return

    if even_cnt[0][0] == odd_cnt[0][0]:
        if even_cnt[0][1] == odd_cnt[0][1]:
            if even_cnt[1][1] < odd_cnt[1][1]:
                odd_impo = 1
                even_impo = 0

            elif even_cnt[1][1] > odd_cnt[1][1]:
                odd_impo = 0
                even_impo = 1

            else:
                odd_impo = 1
                even_impo = 0

        elif even_cnt[0][1] < odd_cnt[0][1]:
            odd_impo = 0
            even_impo = 1

        else:
            odd_impo = 1
            even_impo = 0

    ans = len(v_even) - even_cnt[even_impo][1] + len(v_odd) - odd_cnt[odd_impo][1]

    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
import collections
url = "https://atcoder.jp//contests/abc111/tasks/arc103_a"

def main():
    input()
    t = list(map(int, input().split()))
    even_lis = t[::2]
    odd_lis = t[1::2]
    e = collections.Counter(even_lis).most_common()
    odd = collections.Counter(odd_lis).most_common()
    if e[0][0] == odd[0][0]:
        if e[0][1] + odd[0][1] == len(t):
            print(e[0][1])
            exit()
        else:
            print((len(t) - max(e[0][1], odd[0][1]) - max(e[1][1], odd[1][1])))
            exit()
    else:
        print(len(t) - e[0][1] - odd[0][1])


if __name__ == '__main__':
    main()

Solution (Python):
import collections

n = int(input())
n_half = n//2
v = list(map(int, input().split()))
v_gusu = v[0::2]
v_odd = v[1::2]
ans = 0
c1 = collections.Counter(v)
c2 = collections.Counter(v_gusu)
c3 = collections.Counter(v_odd)

if c1.most_common()[0][1] == n:
    print(n_half)
    exit()

if c2.most_common()[0][0] == c3.most_common()[0][0]:
    print(min((n_half - c2.most_common()[1][1]) + (n_half - c3.most_common()[0][1]),(n_half - c2.most_common()[0][1]) + (n_half - c3.most_common()[1][1])))
    exit()
else:
    print((n_half - c2.most_common()[0][1]) + (n_half - c3.most_common()[0][1]))
    exit()

Solution (Python):
n = int(input())
V = list(map(int, input().split()))
from collections import Counter
even = Counter(V[0::2])
even["0"]=0
even = sorted(even.items(), key=lambda x:x[1], reverse=True)
odd = Counter(V[1::2])
odd["-1"]=0
odd = sorted(odd.items(), key=lambda x:x[1], reverse=True)
i=0
even_top2, odd_top2 = [], []
for (e, o) in zip(even, odd):
  i+=1
  even_top2.append(e)
  odd_top2.append(o)
  if i==2:
    break
if even_top2[0][0] != odd_top2[0][0]:
  notchange = even_top2[0][1] + odd_top2[0][1]
else:
  notchange = max(even_top2[0][1]+odd_top2[1][1], even_top2[1][1]+odd_top2[0][1])
print(n-notchange)

Solution (Python):
from collections import Counter

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

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

c_even = Counter(even)
c_odd = Counter(odd)

e_max1 = [0, 0]
e_max2 = [0, 0]
o_max1 = [0, 0]
o_max2 = [0, 0]

for x, y in c_even.items():
    if y > e_max1[1]:
        e_max2 = e_max1
        e_max1 = [x, y]
    elif y > e_max2[1]:
        e_max2 = [x, y]

for x, y in c_odd.items():
    if y > o_max1[1]:
        o_max2 = o_max1
        o_max1 = [x, y]
    elif y > o_max2[1]:
        o_max2 = [x, y]


if e_max1[0] == o_max1[0]:
    print(min(n - e_max1[1] - o_max2[1], n - e_max2[1] - o_max1[1]))
else:
    print(n - e_max1[1] - o_max1[1])

Solution (Python):

import collections
n = int(input())
A = list(map(int,input().split()))

A1 = A[::2]
A2 = A[1::2]
cnt1 = collections.Counter(A1)
cnt2 = collections.Counter(A2)

items1 = list(cnt1.most_common())
items2 = list(cnt2.most_common())

if items1[0][0] != items2[0][0]:
    ans = (len(A1) - items1[0][1]) + (len(A2) - items2[0][1])
else:
    if len(items1) == len(items2) == 1:
        ans = min(len(A1),len(A2))

    else:
        ans1 = (len(A1) - items1[0][1]) + (len(A2) - items2[1][1])
        ans2 = (len(A1) - items1[1][1]) + (len(A2) - items2[0][1])
        ans = min(ans1,ans2)
print(ans)

Solution (Python):





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

even = {0:0}
odd = {0:0}

for i in range(n):
    v = V[i]
    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

omax = 0
emax = 0
onext = 0
enext = 0

for e in even:
    if even[e] > even[emax]:
        if even[emax] > even[enext]:
            enext = emax
        emax = e
    elif even[e] > even[enext]:
        enext = e

for o in odd:
    if odd[o] > odd[omax]:
        if odd[omax] > odd[onext]:
            onext = omax
        omax = o
    elif odd[o] > odd[onext]:
        onext = o

if omax != emax:
    print(n - even[emax] - odd[omax])
else:
    print(n - even[emax] - odd[omax] + min(even[emax] - even[enext], odd[omax] - odd[onext]))

Solution (Python):

import collections
n = int(input())
A = list(map(int,input().split()))

A1 = A[::2]
A2 = A[1::2]
cnt1 = collections.Counter(A1)
cnt2 = collections.Counter(A2)

items1 = list(cnt1.items())
items2 = list(cnt2.items())
items1 = sorted(items1,key = lambda x:x[1],reverse = True)
items2 = sorted(items2,key = lambda x:x[1],reverse = True)

if items1[0][0] != items2[0][0]:
    ans = (len(A1) - items1[0][1]) + (len(A2) - items2[0][1])
else:
    if len(items1) == len(items2) == 1:
        ans = min(len(A1),len(A2))

    else:
        ans1 = (len(A1) - items1[0][1]) + (len(A2) - items2[1][1])
        ans2 = (len(A1) - items1[1][1]) + (len(A2) - items2[0][1])
        ans = min(ans1,ans2)
print(ans)

Solution (Python):




import collections






def solve(N, Vi):
    V1 = Vi[::2]
    V2 = Vi[1::2]
    c_V1 = dict(collections.Counter(V1))
    c_V2 = dict(collections.Counter(V2))
    c_V1 = sorted(c_V1.items(), key=lambda x: x[1], reverse=True)
    c_V2 = sorted(c_V2.items(), key=lambda x: x[1], reverse=True)
    c_V1.append((-1, 0))
    c_V2.append((-1, 0))
    ans = 0
    if c_V1[0][0] == c_V2[0][0]:
        ans = min(len(V1) - c_V1[0][1] + len(V2) - c_V2[1][1],
                  len(V1) - c_V1[1][1] + len(V2) - c_V2[0][1])
    else:
        ans = len(V1) - c_V1[0][1] + len(V2) - c_V2[0][1]
    print(ans)


if __name__ == '__main__':
    N = int(input())
    Vi = [int(i) for i in input().split()]
    solve(N, Vi)

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

from collections import Counter

def get_counter(X):
  counter = Counter(X)
  X = sorted(counter.items(), key = lambda x:x[1], reverse = True)
  X.append((0,0))
  return X

V1 = get_counter(V[::2])
V2 = get_counter(V[1::2])

if V1[0][0] != V2[0][0]:
  print(N - (V1[0][1] + V2[0][1]))
else:
  print(N - max(V1[0][1] + V2[1][1],V1[1][1] + V2[0][1]))

Solution (Python):
import collections
n = int(input())
v = [int(x) for x in input().split()]
v_odd, v_evn = [], []
for i in range(n):
  if i%2==0:
    v_odd.append(v[i])
  else:
    v_evn.append(v[i])
v_odd_cnt = collections.Counter(v_odd)
v_evn_cnt = collections.Counter(v_evn)
if len(v_odd_cnt) == len(v_evn_cnt) == 1:
  if v[0] == v[1]:
    print(n//2)
    exit()
  else:
    print(0)
    exit()
max_kv_odd = max(v_odd_cnt.items(), key=lambda x: x[1])
max_kv_evn = max(v_evn_cnt.items(), key=lambda x: x[1])
if max_kv_odd[0] == max_kv_evn[0]:
  if len(v_odd_cnt) == 1:
    v_evn_cnt.pop(max_kv_evn[0])
    max_kv_evn_tmp = max(v_evn_cnt.items(), key=lambda x: x[1])
    print(n-max_kv_odd[1]-max_kv_evn_tmp[1])
    exit()
  if len(v_evn_cnt) == 1:
    v_odd_cnt.pop(max_kv_odd[0])
    max_kv_odd_tmp = max(v_odd_cnt.items(), key=lambda x: x[1])
    print(n-max_kv_odd_tmp[1]-max_kv_evn[1])
    exit()
  v_odd_cnt_tmp = v_odd_cnt
  v_evn_cnt_tmp = v_evn_cnt
  v_odd_cnt_tmp.pop(max_kv_odd[0])
  v_evn_cnt_tmp.pop(max_kv_evn[0])
  max_kv_odd_tmp = max(v_odd_cnt_tmp.items(), key=lambda x: x[1])
  max_kv_evn_tmp = max(v_evn_cnt_tmp.items(), key=lambda x: x[1])
  a = max_kv_odd[1] + max_kv_evn_tmp[1]
  b = max_kv_evn[1] + max_kv_odd_tmp[1]
  print(n-max(a, b))
  exit()
print(n-max_kv_odd[1]-max_kv_evn[1])

Solution (Python):
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1).most_common()
dic2 = Counter(list2).most_common()
dic1.append([0,0])
dic2.append([0,0])
if dic1[0][0]!=dic2[0][0]:
  print(n - dic1[0][1] - dic2[0][1])
else:
  print(min(n - dic1[0][1] - dic2[1][1], n -dic1[1][1] - dic2[0][1]))

Solution (Python):
from collections import defaultdict

def main():
    n = int(input())
    vlst = list(map(int, input().split()))
    dd = [defaultdict(int), defaultdict(int)]
    dd[0][-1] = 0
    dd[1][-1] = 0
    for i, v in enumerate(vlst):
        dd[i % 2][v] += 1
    odd = sorted(dd[0].items(), key = lambda x:x[1], reverse = True)
    even = sorted(dd[1].items(), key = lambda x:x[1], reverse = True)
    if odd[0][0] != even[0][0]:
        minus = odd[0][1] + even[0][1]
        ans = n - minus
    else:
        minus = 0
        minus = max(minus, odd[0][1] + even[1][1])
        minus = max(minus, odd[1][1] + even[0][1])
        ans = n - minus
    print(ans)
main()

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
cnt1=[0 for i in range(100001)]
cnt2=[0 for i in range(100001)]
for i in range(n):
    if i%2==0:
        cnt1[v[i]]+=1
    else:
        cnt2[v[i]]+=1
k1=0
k1m=0
k2=0
k2m=0
for i in range(100001):
    if cnt1[i]>=cnt1[k1]:
        k1,k1m=i,k1
    elif cnt1[i]>cnt1[k1m]:
        k1m=i
for i in range(100001):
    if cnt2[i]>=cnt2[k2]:
        k2,k2m=i,k2
    elif cnt2[i]>cnt2[k2m]:
        k2m=i
if k1!=k2:
    print(n-cnt1[k1]-cnt2[k2])
else:
    print(n-(cnt1[k1]+max(cnt1[k1m],cnt2[k2m])))

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 = Counter(v[::2]).most_common(2)
gusu = Counter(v[1::2]).most_common(2)

if kisu[0][0] == gusu[0][0]:
    keep = max(kisu[1][1] + gusu[0][1],
               kisu[0][1] + gusu[1][1])
else:
    keep = kisu[0][1] + gusu[0][1]

print(n - keep)

Solution (Python):
import collections

n = int(input())
v = list(map(int, input().split()))
even_odd_length = n / 2
replace_total = 0

list_odd = v[0::2]
list_even = v[1::2]

dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))
dict_c_even_bk = dict_c_even.copy()

replace_total_tmp = 0
replace_total_tmp2 = 0

max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even

max_c_odd_keys = [k for k, v in dict_c_odd.items() if v == max_count_c_odd]
max_c_even_keys = [k for k, v in dict_c_even.items() if v == max_count_c_even]

if len(set(v)) == 1:
    print(int(even_odd_length))
else:    
    if max_c_odd_keys[0] in dict_c_even:
        del dict_c_even[max_c_odd_keys[0]]
    max_count_c_even = max(dict_c_even.values())
    replace_total_tmp = (n - max_count_c_odd - max_count_c_even)
    
    dict_c_even = dict_c_even_bk
    max_count_c_even = max_count_c_even_bk
    
    if max_c_even_keys[0] in dict_c_odd:
        del dict_c_odd[max_c_even_keys[0]]
    max_count_c_odd = max(dict_c_odd.values())
    replace_total_tmp2 = (n - max_count_c_odd - max_count_c_even)
    
    if replace_total_tmp >= replace_total_tmp2:
         replace_total = replace_total_tmp2
    else:
         replace_total = replace_total_tmp

    print(replace_total)

Solution (Python):
import collections

n = int(input())
v = list(map(int, input().split()))
even_odd_length = n / 2
replace_total = 0

list_odd = v[0::2]
list_even = v[1::2]

dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))
dict_c_even_bk = dict_c_even.copy()
dict_c_odd_bk = dict_c_odd.copy()

replace_total_tmp = 0
replace_total_tmp2 = 0
max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even
max_c_odd_keys = [k for k, v in dict_c_odd.items() if v == max_count_c_odd]
max_c_even_keys = [k for k, v in dict_c_even.items() if v == max_count_c_even]

if len(set(v)) == 1:
    print(int(even_odd_length))
else:    
    if max_c_odd_keys[0] in dict_c_even:
        del dict_c_even[max_c_odd_keys[0]]
    max_count_c_even = max(dict_c_even.values())
    replace_total_tmp = (n - max_count_c_odd - max_count_c_even)
    
    dict_c_even = dict_c_even_bk
    max_count_c_even = max_count_c_even_bk
    
    if max_c_even_keys[0] in dict_c_odd:
        del dict_c_odd[max_c_even_keys[0]]
    max_count_c_odd = max(dict_c_odd.values())
    replace_total_tmp2 = (n - max_count_c_odd - max_count_c_even)
    
    if replace_total_tmp >= replace_total_tmp2:
         replace_total = replace_total_tmp2
    else:
         replace_total = replace_total_tmp
    print(replace_total)

Solution (Python):
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1).most_common()
dic2 = Counter(list2).most_common()
dic1.append([0,0])
dic2.append([0,0])
if dic1[0][0]!=dic2[0][0]:
  print(n - dic1[0][1] - dic2[0][1])
else:
  print(min(n - dic1[0][1] - dic2[1][1], n -dic1[1][1] - dic2[0][1]))

Solution (Python):

"""
Created on Thu Sep 17 21:11:38 2020

@author: liang
"""

"""
【２番目の取得】
"""
n = int(input())
E = list()
O = list()
i = 0
for v in input().split():
    if i%2 == 0:
        E.append(int(v))
    else:
        O.append(int(v))
    i += 1


edic = {}
odic = {}
for e in E:
    if e not in edic.keys():
        edic[e] = 1
    else:
        edic[e] += 1

for o in O:
    if o not in odic.keys():
        odic[o] = 1
    else:
        odic[o] += 1
        
etmp = [(-1,0),(-1,0)]
otmp = [(-1,0),(-1,0)]

for key in edic.keys():
    
    if edic[key] > etmp[0][1]:
        etmp[1] = etmp[0]
        etmp[0] = (key, edic[key])
    
    elif edic[key] > etmp[1][1]:
        etmp[1] = (key,edic[key])

for key in odic.keys():
    
    if odic[key] > otmp[0][1]:
        otmp[1] = otmp[0]
        otmp[0] = (key, odic[key])
    
    elif odic[key] > otmp[1][1]:
        otmp[1] = (key,odic[key])

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

Solution (Python):

"""
Created on Thu Sep 17 20:29:30 2020

@author: liang
"""

n = int(input())
E = list()
O = list()
i = 0
for v in input().split():
    if i%2 == 0:
        E.append(int(v))
    else:
        O.append(int(v))
    i += 1


edic = {-1:0}
odic = {-1:0}
for e in E:
    if e not in edic.keys():
        edic[e] = 1
    else:
        edic[e] += 1

for o in O:
    if o not in odic.keys():
        odic[o] = 1
    else:
        odic[o] += 1

etup = list()
otup = list()
for e in edic.keys():
    etup.append((e,edic[e]))
for o in odic.keys():
    otup.append((o,odic[o]))    
etup.sort(reverse=True,key=lambda x:x[1])
otup.sort(reverse=True,key=lambda x:x[1])



i = 0
j = 0
while True:
    ekey, etmp = etup[i]
    okey, otmp = otup[j]
    if ekey != okey:
        break
    if etup[i+1][1] < otup[j+1][1]:
        j += 1
    else:
        i += 1
    



ans = n - etmp - otmp
    
print(ans)

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

    even = [0] * (10 ** 5 + 100)
    odd = [0] * (10 ** 5 + 100)

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

    max_even = even.index(max(even))
    max_odd = odd.index(max(odd))

    if max_even == max_odd:
        even[max_even] = 0
        odd[max_odd] = 0
        if max(even) < max(odd):
            max_odd = odd.index(max(odd))
        else:
            max_even = even.index(max(even))
    ans = 0
    for i in range(n):
        if i % 2 == 0 and max_even != v[i]:
            ans += 1
        if i % 2 != 0 and max_odd != v[i]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

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

kisu = [0]*(10**6)
gusu = [0]*(10**6)
for i in range(n):
    if i % 2 == 0:
        gusu[v[i]] += 1
    else:
        kisu[v[i]] += 1

count = 0
gusu_m = gusu.index(max(gusu))
kisu_m = kisu.index(max(kisu))

if gusu_m == kisu_m:

    gusu[gusu_m] = 0
    kisu[kisu_m] = 0
    if max(gusu) > max(kisu):
        gusu_m = gusu.index(max(gusu))
    else:
        kisu_m = kisu.index(max(kisu))

for i in range(n):
    if i % 2 == 0 and gusu_m != v[i]:
        count += 1
    if i % 2 != 0 and kisu_m != v[i]:
        count += 1

print(count)

Solution (Python):
from collections import Counter

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

if a.count(a[0])==n:
    print(n//2)
    exit()


x=a[::2]
y=a[1::2]

xx=Counter(x)
yy=Counter(y)

xxx=xx.most_common()
yyy=yy.most_common()

if xxx[0][0]!=yyy[0][0]:
    print(n-xxx[0][1]-yyy[0][1])

else:
    print(min(n-xxx[1][1]-yyy[0][1],n-xxx[0][1]-yyy[1][1]))

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

v_odd = [0] * (n // 2)
v_even = [0] * (n // 2)

for i in range(n):
  if (i + 1) % 2 == 1:
    v_odd[i//2] += v_lis[i]
  else:
    v_even[i//2] += v_lis[i]
    
v_odd, v_even = Counter(v_odd).most_common(), Counter(v_even).most_common()

if v_odd[0][0] != v_even[0][0]:
  cnt = v_odd[0][1] + v_even[0][1]

else:
  tmp1 = v_odd[0][1] + (v_even[1][1] if len(v_even) >= 2 else 0)
  tmp2 = v_even[0][1] + (v_odd[1][1] if len(v_odd) >= 2 else 0)
  cnt = max(tmp1, tmp2)

print(n - cnt)

Solution (Python):
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
o = defaultdict(int)
e = defaultdict(int)
odd_num = 0
even_num = 0
for i, v_one in enumerate(v):
  if i % 2 == 1:
    o[v_one] += 1
    odd_num += 1
  else:
    e[v_one] += 1
    even_num += 1
sorted_o = sorted(o.items(), key=lambda x:-x[1])
sorted_e = sorted(e.items(), key=lambda x:-x[1])
if sorted_o[0][0] != sorted_e[0][0]:
  ans = odd_num - sorted_o[0][1] + even_num - sorted_e[0][1]
elif len(sorted_o) >= 2 and len(sorted_e) >= 2:
  ans1 = odd_num - sorted_o[1][1] + even_num - sorted_e[0][1]
  ans2 = odd_num - sorted_o[0][1] + even_num - sorted_e[1][1]
  ans = min(ans1, ans2)
elif len(sorted_o) >= 2:
  ans = sorted_o[0][1]
elif len(sorted_e) >=2:
  ans = sorted_e[0][1]
else:
  ans = odd_num
print(ans)

Solution (Python):
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])
from collections import Counter
even=Counter(even)
odd=Counter(odd)

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

a=even[0]
if a[1]==n//2:
  b=0
else:
  b=even[1][1]
  
c=odd[0]
if c[1]==n//2:
  d=0
else:
  d=odd[1][1]
  
if a[0]==c[0]:
  print(min(n-a[1]-d,n-b-c[1]))
else:
  print(n-a[1]-c[1])

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
v0 = v[0:n-1:2]
v1 = v[1:n:2]
from collections import Counter
V0 = Counter(v0)
V1 = Counter(v1)
if V0.most_common()[0][0] != V1.most_common()[0][0]:
    a = V0.most_common()[0][1]
    b = V1.most_common()[0][1]
else:
    if V0.most_common()[0][1] > V1.most_common()[0][1]:
        if len(V1) > 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        else:
            a = V0.most_common()[0][1]
            b = 0
    elif V0.most_common()[0][1] < V1.most_common()[0][1]:
        if len(V0) > 1:
            a = V1.most_common()[0][1]
            b = V0.most_common()[1][1]
        else:
            a = 0
            b = V1.most_common()[0][1]
    else:
        if len(V0) == 1 and len(V1) == 1:
            a = 0
            b = V0.most_common()[0][1]
        elif len(V0) == 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        elif len(V1) == 1:
            a = V0.most_common()[1][1]
            b = V1.most_common()[0][1]
        else:
            a = V0.most_common()[0][1]
            b = max(V0.most_common()[1][1],V1.most_common()[1][1])
print(n-a-b)

Solution (Python):
from collections import Counter

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

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

odd = [v[i] for i in range(0, n, 2)]
odd_val, odd_cnt = zip(*Counter(odd).most_common())

even = [v[i] for i in range(1, n, 2)]
even_val, even_cnt = zip(*Counter(even).most_common())

if even_val[0] != odd_val[0]:
    ans = n-even_cnt[0]-odd_cnt[0]
else:
    if (even_cnt[0] + odd_cnt[1]) >= (even_cnt[1] + odd_cnt[0]):
        ans = n-even_cnt[0]-odd_cnt[1]
    else:
        ans = n-even_cnt[1]-odd_cnt[0]
print(ans)

Solution (Python):
from collections import Counter

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

a_even = [0] * (n//2); a_odd = [0] * (n//2)

for i in range(n):
    if i % 2 == 0:
        a_even[i//2] = a[i]
    else:
        a_odd[i//2] = a[i]

dic_even = Counter(a_even); dic_odd = Counter(a_odd)

first_even_key, first_even_num = max(dic_even.items(), key=lambda x: x[1])
dic_even.pop(first_even_key)
if len(dic_even) > 0:
    second_even_key, second_even_num = max(dic_even.items(), key=lambda x: x[1])
else:
    second_even_key = -1; second_even_num = 0

first_odd_key, first_odd_num = max(dic_odd.items(), key=lambda x: x[1])
dic_odd.pop(first_odd_key)
if len(dic_odd) > 0:
    second_odd_key, second_odd_num = max(dic_odd.items(), key=lambda x: x[1])
else:
    second_odd_key = -1; second_odd_num = 0

if first_even_key == first_odd_key:
    print(n - max(first_even_num + second_odd_num, second_even_num + first_odd_num))
else:
    print(n - first_even_num - first_odd_num)

Solution (Python):
from collections import Counter
n = int(input())
V = list(map(int, input().split()))
x = len(set(V))
if x == 1:
    print(n // 2)
else:
    A = list()
    B = list()
    for i, v in enumerate(V):
        if i & 1:
            A.append(v)
        else:
            B.append(v)
    A = Counter(A).most_common()
    B = Counter(B).most_common()
    a = A[0]
    b = B[0]
    if a[0] == b[0]:
        if len(A) == 1:
            b = B[1]
        elif len(B) == 1:
            a = A[1]
        else:
            if A[1][1] >= B[1][1]:
                a = A[1]
            else:
                b = B[1]
    print(n - a[1] - b[1])

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    v = LI()
    acnt = collections.Counter(v[::2])
    bcnt = collections.Counter(v[1::2])
    acnt = list(acnt.items())
    bcnt = list(bcnt.items())
    acnt.sort(key=lambda x: x[1], reverse=True)
    bcnt.sort(key=lambda x: x[1], reverse=True)

    acnt.append((-1,0))
    bcnt.append((-1,0))

    ans = 0

    if acnt[0][0] != bcnt[0][0]:
        ans = n - acnt[0][1] - bcnt[0][1]
    else:
        ans = min(n-acnt[0][1]-bcnt[1][1], n-acnt[1][1]-bcnt[0][1])

    print(ans)

main()

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    v = LI()
    acnt = collections.Counter(v[::2])
    bcnt = collections.Counter(v[1::2])
    acnt = list(acnt.items())
    bcnt = list(bcnt.items())
    acnt.sort(key=lambda x: x[1], reverse=True)
    bcnt.sort(key=lambda x: x[1], reverse=True)

    ans = 0

    if len(acnt) == len(bcnt) == 1:
        if acnt[0][0] == bcnt[0][0]:
            ans = n//2
        else:
            ans = 0
    elif len(acnt)==1 or len(bcnt) == 1:
        if acnt[0][0] == bcnt[0][0]:
            if len(acnt) != 1:
                ans = n//2 - acnt[1][1]
            else:
                ans = n//2 - bcnt[1][1]
        else:
            ans = n//2 - min(acnt[0][1], bcnt[0][1])
    else:
        if acnt[0][0] == bcnt[0][0]:
            ans = n - acnt[0][1] - max(acnt[1][1], bcnt[1][1])
        else:
            ans = n - acnt[0][1]*2

    print(ans)

main()

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

list_odd=v[1::2]
list_even=v[0::2]

cnt_odd=Counter(list_odd)
cnt_even=Counter(list_even)

cnt_odd_sorted=sorted(cnt_odd.items(),reverse=True,key=lambda x:x[1])
cnt_even_sorted=sorted(cnt_even.items(),reverse=True,key=lambda x:x[1])

if cnt_odd_sorted[0][0]!=cnt_even_sorted[0][0]:
    ans=len(list_odd)-cnt_odd_sorted[0][1]
    ans+=len(list_even)-cnt_even_sorted[0][1]

else:
    if len(cnt_odd)==1 and len(cnt_even)==1:
        ans=len(list_even)
    elif len(cnt_odd)==1:
        ans=len(list_even)-cnt_even_sorted[1][1]
    elif len(cnt_even)==1:
        ans=len(list_odd)-cnt_odd_sorted[1][1]
    else:
        ans1=len(list_even)-cnt_even_sorted[1][1]
        ans1+=len(list_odd)-cnt_odd_sorted[0][1]

        ans2=len(list_odd)-cnt_odd_sorted[1][1]
        ans2+=len(list_even)-cnt_even_sorted[0][1]
        ans=min(ans1,ans2)

print(ans)