Problem:
 Score : 300 points    Problem Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:   For each i = 1,2,..., n-2 , a_i = a_{i+2} .  Exactly two different numbers appear in the sequence.   You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.      Constraints  2 \leq n \leq 10^5  n is even.  1 \leq v_i \leq 10^5  v_i is an integer.         Input Input is given from Standard Input in the following format:  n  v_1  v_2  ...  v_n       Output Print the minimum number of elements that needs to be replaced.        Sample Input 1 4
3 1 3 2      Sample Output 1 1  The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1 .       Sample Input 2 6
105 119 105 119 105 119      Sample Output 2 0  The sequence 105,119,105,119,105,119 is /\/\/\/.       Sample Input 3 4
1 1 1 1      Sample Output 3 2  The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a, b = [], []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])

c = list(Counter(a).items())
d = list(Counter(b).items())

c.sort(key=lambda x: x[1], reverse = True)
d.sort(key=lambda x: x[1], reverse=True)

if c[0] != d[0]:
    print(n - c[0][1] - d[0][1])
else:
    d1 = c[0][1]
    d2 = d[0][1]
    if len(d) > 1:
        d1 += d[1][1]
    if len(c) > 1:
        d2 += c[1][1]
    print(n - max(d1, d2))

Solution (Python):
N = int(input())
L = input().split(" ")

import collections

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

if even[0][0] != odd[0][0]:
    print(N - even[0][1] - odd[0][1])
else:
    
    if len(even) == 1 or len(odd) == 1:
        print(N // 2)
    else:
        print(N - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1]))

Solution (Python):
import collections

n = int(input())
v = [int(_) for _ in input().split()]

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

a_even = collections.Counter(v_even)
a_odd = collections.Counter(v_odd)

li_even = a_even.most_common()
li_odd = a_odd.most_common()

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

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

Dic = [[i,0] for i in range(1,(10**5)+1)]
Dic2 = [[i,0] for i in range(1,(10**5)+1)]
for i in range(n):
    if i%2 == 0:
        Dic[V[i]-1][1] += 1
    else:
        Dic2[V[i]-1][1] += 1
Dic.sort(key = lambda x:x[1],reverse = True)
Dic2.sort(key = lambda x:x[1], reverse = True)

cn = 0
if Dic[0][0] != Dic2[0][0]:
    cn += n - Dic[0][1] - Dic2[0][1]
else:
    cn += n - max((Dic[0][1]+Dic2[1][1]), (Dic[1][1]+Dic2[0][1]))
print(cn)

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

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

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

a1 = odd.most_common()[0][1]
if len(odd) >=2:
    a2 = odd.most_common()[1][1]

b1 = even.most_common()[0][1]
if len(even) >= 2:
    b2 = even.most_common()[1][1]

if odd.most_common()[0][0] != even.most_common()[0][0]:
    print(n-a1-b1)
elif len(even) == 1 and len(odd) >= 2:
    print(n-b1-a2)
elif len(odd) == 1 and len(even)>= 2: 
    print(n-a1-b2)
elif len(odd) == 1 and len(even) == 1:
    print(n//2)
elif a1+b2 >= a2+b1:
    print(n-a1-b2)
else:
    print(n-a2-b1)

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

from collections import Counter

v1 = [v[i] for i in range(len(v)) if i%2 == 0]
v2 = [v[i] for i in range(len(v)) if i%2 != 0]

v1c = Counter(v1)
v1cs = v1c.most_common(1)[0][0]
v1c = sorted(v1c.values())

v2c = Counter(v2)
v2cs = v2c.most_common(1)[0][0]
v2c = sorted(v2c.values())

if v1cs != v2cs:
    ans = sum(v1c[:-1]) + sum(v2c[:-1])
else:
    if len(v1c) == 1 and len(v2c) == 1:
        ans = sum(v2c)
    elif len(v1c) == 1:
        ans = sum(v2c) - v2c[-2]
    elif len(v2c) == 1:
        ans = sum(v1c) - v1c[-2]
    else:
        ans = min(sum(v1c) - v1c[-2] + sum(v2c[:-1]), sum(v1c[:-1]) + sum(v2c) - v2c[-2])

print(ans)

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

from collections import Counter

v1 = [v[i] for i in range(len(v)) if i%2 == 0]
v2 = [v[i] for i in range(len(v)) if i%2 != 0]

v1c = Counter(v1)
v1cs = v1c.most_common(1)[0][0]
v1c = sorted(v1c.values())

v2c = Counter(v2)
v2cs = v2c.most_common(1)[0][0]
v2c = sorted(v2c.values())

if v1cs != v2cs:
    ans = sum(v1c[:-1]) + sum(v2c[:-1])
else:
    if len(v1c) == 1 and len(v2c) == 1:
        ans = sum(v2c)
    elif len(v1c) == 1:
        ans = min(sum(v2c) - v2c[-2])
    elif len(v2c) == 1:
        ans = min(sum(v1c) - v1c[-2])
    else:
        ans = min(sum(v1c) - v1c[-2] + sum(v2c[:-1]), sum(v1c[:-1]) + sum(v2c) - v2c[-2])

print(ans)

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

even_dict = {}
odd_dict = {}
for i, value in enumerate(v):
    if i % 2:
        even_dict[value] = 1 if value not in even_dict else even_dict[value] + 1
    else:
        odd_dict[value] = 1 if value not in odd_dict else odd_dict[value] + 1

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

if even[0][0] == odd[0][0]:
    even_second = 0 if len(even) < 2 else even[1][1]
    odd_second = 0 if len(odd) < 2 else odd[1][1]
    if even[0][1] - even_second > odd[0][1] - odd_second:
        counter += sum([x[1] for x in even[1:]])
        counter += sum([x[1] for x in odd[2:] + [odd[0]]])
    else:
        counter += sum([x[1] for x in odd[1:]])
        counter += sum([x[1] for x in even[2:] + [even[0]]])
else:
    counter += sum([x[1] for x in even[1:]])
    counter += sum([x[1] for x in odd[1:]])

print(counter)

Solution (Python):
from collections import Counter
from math import ceil, floor
n = int(input())
v = list(map(int, input().split()))
v = [v[::2], v[1::2]]
v_c = [sorted(Counter(x).items(),key=lambda x:x[1], reverse=True) + [(0, 0)]for x in v]
if v_c[0][0][0] == v_c[1][0][0]:
  ans1 = ceil(n / 2) - v_c[0][0][1] + floor(n / 2) - v_c[1][1][1]
  ans2 = ceil(n / 2) - v_c[0][1][1] + floor(n / 2) - v_c[1][0][1]
  print(min(ans1, ans2))
else:
  print(ceil(n / 2) - v_c[0][0][1] + floor(n / 2) - v_c[1][0][1])

Solution (Python):

from collections import Counter

n = int(input())
lst = list(map(int, input().rstrip().split()))
even = Counter(lst[::2]).most_common(2)
odd = Counter(lst[1::2]).most_common(2)
ans = 0
if even[0][0] != odd[0][0]:
    print(n - even[0][1] - odd[0][1])
else:
    if len(even) == 1:
        print(n // 2)
    else:
        print(n - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1]))

Solution (Python):

from collections import Counter

n = int(input())
lst = list(map(int, input().rstrip().split()))
even = Counter(lst[::2]).most_common(2)
odd = Counter(lst[1::2]).most_common(2)
ans = 0
if even[0][0] != odd[0][0]:
    print(n - even[0][1] - odd[0][1])
else:
    if len(even) == 1 or len(odd) == 1:
        print(n // 2)
    else:
        print(n - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1]))

Solution (Python):
import collections
N=int(input())
V=list(map(int,input().split()))
V1=collections.Counter(V[0::2]).most_common()
V2=collections.Counter(V[1::2]).most_common()
V1.append((0,0))
V2.append((0,0))
if V1[0]!=V2[0]:
    print(N-V1[0][1]-V2[0][1])
else:
    print(min(N-V1[0][1]-V2[1][1],N-V1[1][1]-V2[0][1]))

Solution (Python):
n = int(input())
v = [int(i) for i in input().split()]
MAX_V = 100001
even = [[i, 0] for i in range(MAX_V)]
odd = [[i, 0] for i in range(MAX_V)]
for ni in range(n//2):
    even[v[ni*2]][1] += 1
    odd[v[ni*2+1]][1] += 1
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 even[1][1] > odd[1][1]:
        print(n-even[1][1]-odd[0][1])
    else:
        print(n-even[0][1]-odd[1][1])
else:
    print(n - even[0][1] - odd[0][1])

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    v = f()

    a = [ v[i] for i in range(n) if i%2 == 0]
    b = [ v[i] for i in range(n) if i%2 == 1]

    cnt_a = {}
    cnt_b = {}
    for i in a:
        if i in cnt_a:
            cnt_a[i] += 1
        else:
            cnt_a[i] = 1
    
    for i in b:
        if i in cnt_b:
            cnt_b[i] += 1
        else:
            cnt_b[i] = 1

    ncnt_a = sorted(cnt_a.items(), key = lambda x:-x[1])
    ncnt_b = sorted(cnt_b.items(), key = lambda x:-x[1])

    

    if ncnt_a[0][0]!=ncnt_b[0][0]:
        print(n -ncnt_a[0][1]- ncnt_b[0][1])
    else:
        ans1 = n - ncnt_b[0][1] - (ncnt_a[1][1] if len(ncnt_a)>1 else 0)
        ans2 = n -ncnt_a[0][1]- (ncnt_b[1][1] if len(ncnt_b)>1 else 0)
        print(min(ans1, ans2))



solve()

Solution (Python):
from collections import Counter

n = int(input())

e = []
o = []
for i, v in enumerate(input().split(' ')):
    if i % 2 == 0:
        e.append(int(v))
    else:
        o.append(int(v))

if len(set(e + o)) == 1:
    print(int(len(e + o) / 2))
    exit()

if Counter(o).most_common()[0][0] == Counter(e).most_common()[0][0]:
    ans = min(len(o) - Counter(o).most_common()[1][1] + len(e) - Counter(e).most_common()[0][1], len(o) - Counter(o).most_common()[0][1] + len(e) - Counter(e).most_common()[1][1])
    print(ans)
else:
    print(len(o) - Counter(o).most_common()[0][1] + len(e) - Counter(e).most_common()[0][1])

Solution (Python):
import collections
n = int(input())
l = list(int(x) for x in input().split())
el = []
ol = []
for i in range(n):
  if i % 2 == 0:
    el.append(l[i])
  else:
    ol.append(l[i])
if len(set(el + ol)) == 1:
  print(int(len(l)/2))
  exit()
e1 = collections.Counter(el).most_common()[0][0]
o1 = collections.Counter(ol).most_common()[0][0]
cnt1 = 0
cnt2 = 0
if e1 != o1:
  print(len(el) - collections.Counter(el).most_common()[0][1] + len(ol) - collections.Counter(ol).most_common()[0][1])
else:
  print(min(len(el)-collections.Counter(el).most_common()[0][1]+len(ol)-collections.Counter(ol).most_common()[1][1],len(el)-collections.Counter(el).most_common()[1][1]+len(ol)-collections.Counter(ol).most_common()[0][1]))

Solution (Python):
from collections import Counter

n = int(input())

e = []
o = []
for i, v in enumerate(input().split(' ')):
    if i % 2 == 0:
        e.append(int(v))
    else:
        o.append(int(v))

if len(set(e + o)) == 1:
    print(int(len(e + o) / 2))
    exit()

if Counter(o).most_common()[0][0] == Counter(e).most_common()[0][0]:
    ans = min(len(o) - Counter(o).most_common()[1][1] + len(e) - Counter(e).most_common()[0][1], len(o) - Counter(o).most_common()[0][1] + len(e) - Counter(e).most_common()[1][1])
    print(ans)
else:
    print(len(o) - Counter(o).most_common()[0][1] + len(e) - Counter(e).most_common()[0][1])

Solution (Python):

import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0] != b[0][0]:
    ans = n - (a[0][1]+b[0][1])
else:
    ans = min(n - (a[1][1]+b[0][1]), n - (a[0][1]+b[1][1]))
print(ans)

Solution (Python):
from collections import Counter

n = int(input())

e = []
o = []
for i, v in enumerate(input().split(' ')):
    if i % 2 == 0:
        e.append(int(v))
    else:
        o.append(int(v))

if len(set(e + o)) == 1:
    print(int(len(e + o) / 2))
    exit()

if Counter(o).most_common()[0][0] == Counter(e).most_common()[0][0]:
    ans = min(len(o) - Counter(o).most_common()[1][1] + len(e) - Counter(e).most_common()[0][1], len(o) - Counter(o).most_common()[0][1] + len(e) - Counter(e).most_common()[1][1])
    print(ans)
else:
    print(len(o) - Counter(o).most_common()[0][1] + len(e) - Counter(e).most_common()[0][1])

Solution (Python):
from sys import stdin
import collections
n = int(stdin.readline().rstrip())
V = [int(x) for x in stdin.readline().rstrip().split()]
V_odd = [V[2 * k] for k in range(int(n / 2))]
V_even = [V[2 * k + 1] for k in range(int(n / 2))]
co = collections.Counter(V_odd)
ce = collections.Counter(V_even)
if co.most_common()[0][0] != ce.most_common()[0][0]:
    print(n - co.most_common()[0][1] - ce.most_common()[0][1])
elif len(co.most_common()) == 1 and len(ce.most_common()) == 1:
    print(co.most_common()[0][1])
else:
    print(n - (max(co.most_common()[1][1] + ce.most_common()[0][1], co.most_common()[0][1] + ce.most_common()[1][1])))

Solution (Python):
from collections import Counter

n, *v = map(int, open(0).read().split())
c1 = Counter(v[::2]).most_common()
c2 = Counter(v[1::2]).most_common()

c1.append([0, 0])
c2.append([0, 0])

if c1[0][0] != c2[0][0]:
  print(n - c1[0][1] - c2[0][1])
else:
  print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))

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

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

e = collections.Counter(even).most_common()
o = collections.Counter(odd).most_common()

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

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
odd = []
even = []

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

o_count = Counter(odd)
e_count = Counter(even)
o_count[-1] = 0
e_count[-2] = 0

if o_count.most_common(1)[0] != e_count.most_common(1)[0]:
  print(n - o_count.most_common(1)[0][1] - e_count.most_common(1)[0][1])
else:
  o1e2 = n - o_count.most_common(2)[0][1] - e_count.most_common(2)[1][1]
  o2e1 = n - o_count.most_common(2)[1][1] - e_count.most_common(2)[0][1]
  ans = min(o1e2,o2e1)
  print(ans)

Solution (Python):

import sys
import collections


def solve(n: int, V: "List[int]"):

    ev = V[0::2]
    ov = V[1::2]

    ec = collections.Counter(ev)
    oc = collections.Counter(ov)

    em = ec.most_common()
    om = oc.most_common()

    if em[0][0] != om[0][0]:
        print( n-em[0][1]-om[0][1])
    else:
        if len(em) == 1 and len(om) == 1:
            print(n-em[0][1])
        elif  len(em) == 1:
            print( n-em[0][1]-om[1][1])
        elif  len(om) == 1:
            print( n-em[1][1]-om[0][1])
        else:
            print(min(n-em[0][1]-om[1][1], n-em[1][1]-om[0][1]))

            




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

if __name__ == '__main__':
    main()

Solution (Python):
import collections

n = int(input())
v = [int(i) for i in input().split()]

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

odds = collections.Counter(odd).most_common()
evens = collections.Counter(even).most_common()

cnt_odd = 0
cnt_even = 0

ans = 0
if odds[0][0]  == evens[0][0]:
    if len(evens) == 1 and len(odds) == 1:
        ans = evens[0][1]
        print(ans)
        exit()

    ans1 = 10 ** 5
    ans2 = 10 ** 5

    if len(evens) > 1:
        for i, e in enumerate(evens):
            if i != 1:
                cnt_even += e[1]
        for i, o in enumerate(odds):
            if i > 0:
                cnt_odd += o[1]
        ans1 = cnt_even + cnt_odd
        cnt_even, cnt_odd = 0,0
    if len(odds) > 1:
        for i, e in enumerate(evens):
            if i > 0:
                cnt_even += e[1]
        for i, o in enumerate(odds):
            if i != 1:
                cnt_odd += o[1]
        ans2 = cnt_even + cnt_odd
    ans = min(ans1, ans2)
    print(ans)
    exit()

for i, o in enumerate(odds):
    if i > 0:
        cnt_odd += o[1]
for i, e in enumerate(evens):
    if i > 0:
        cnt_even += e[1]
ans = cnt_odd + cnt_even

print(ans)

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

odd = {}
even = {}

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


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





if odd_sorted[0][0] == even_sorted[0][0]:
    
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        
        if odd_sorted[0][1] > even_sorted[0][1]:
            ans_odd = odd_sorted[0][0]
            ans_even = even_sorted[1][0]
        elif odd_sorted[0][1] < even_sorted[0][1]:
            ans_odd = odd_sorted[1][0]
            ans_even = even_sorted[0][0]
        else:
            
            if odd_sorted[1][1] >= even_sorted[1][1]:
                ans_odd = odd_sorted[1][0]
                ans_even = even_sorted[0][0]
            elif odd_sorted[1][1] < even_sorted[1][1]:
                ans_odd = odd_sorted[0][0]
                ans_even = even_sorted[1][0]

    
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    
    else: 
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1


print(ans)

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

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

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

odd_map[-1] = 0
even_map[-2] = 0
odd_list = list(odd_map.items())
odd_list.sort(key=lambda x: x[1], reverse=True)
even_list = list(even_map.items())
even_list.sort(key=lambda x: x[1], reverse=True)

odds = [odd_list[i][0] for i in range(2)]
evens = [even_list[i][0] for i in range(2)]

ans_list = []
for odd in odds:
    for even in evens:
        if odd == even:
            continue
        ans = 0
        for k, v in odd_map.items():
            if k != odd:
                ans += v
        for k, v in even_map.items():
            if k != even:
                ans += v
        ans_list.append(ans)

print(min(ans_list))

Solution (Python):
import collections

c = collections.Counter

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

even_v = [v[i] for i in range(n) if i % 2 == 0]
odd_v = [v[i] for i in range(n) if i % 2 == 1]

c1 = c(even_v).most_common(2)
c2 = c(odd_v).most_common(2)



def calc(x, y):
    
    
    return len(even_v) - x[1] + len(odd_v) - y[1]

def main():
    if c1[0] != c2[0]:
        
        return calc(c1[0], c2[0])

    if len(c1) == 1 and len(c2) == 1:
        
        return len(odd_v)

    if calc(c1[0], c2[1]) < calc(c1[1], c2[0]):
        
        return calc(c1[0], c2[1])

    else:
        
        return calc(c1[1], c2[0])

print(main())

Solution (Python):

"""
C - /\/\/\/
https://atcoder.jp/contests/abc111/tasks/arc103_a

"""
import sys


from collections import Counter

def solve(n, nums):
    e_cnt = Counter(nums[::2])
    o_cnt = Counter(nums[1::2])
    e = e_cnt.most_common()
    o = o_cnt.most_common()

    ans1 = len(nums)
    ans2 = len(nums)
    if e[0][0] == o[0][0]:
        ee = e[0][1]
        oo = o[1][1] if len(o) > 1 else 0
        ans1 -= (ee + oo)
        ee = e[1][1] if len(e) > 1 else 0
        oo = o[0][1]
        ans2 -= (ee + oo)
        return min(ans1, ans2)
    else:
        return len(nums) - (e[0][1] + o[0][1])

def main(args):
    n = int(input())
    nums = [int(i) for i in input().split()]
    ans = solve(n, nums)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
import collections
c = collections.Counter

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

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

c1 = c(v_odd).most_common(2)
c2 = c(v_eve).most_common(2)

if len(c1) == 1 and len(c2) == 1:
    if c1[0][0] != c2[0][0]:
        ans = 0
    else:
        ans = int(N/2)
else:
    if c1[0] != c2[0]:
        ans = N - c1[0][1] - c2[0][1]
    else:
        if c1[1][1] >= c2[1][1]:
            ans = N - c1[1][1] - c2[0][1]
        else:
            ans = N - c1[0][1] - c2[1][1]

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}

for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = [sorted(count_dict[i].items(), key=lambda kv: kv[1], reverse=True)[:2] for i in range(2)]
candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(N-no_move)

Solution (Python):



from operator import itemgetter


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

l_even = list()
l_odd = list()


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

l_even.sort()
l_odd.sort()
wk_cnt_e = 1
wk_cnt_o = 1

cnt_even = list()
cnt_odd = list()


for x in range(int(n/2)-1):
    if l_even[x] != l_even[x+1]:
        cnt_even.append([l_even[x], wk_cnt_e])
        wk_cnt_e = 1
    else:
        wk_cnt_e += 1

    if l_odd[x] != l_odd[x+1]:
        cnt_odd.append([l_odd[x], wk_cnt_o])
        wk_cnt_o = 1
    else:
        wk_cnt_o += 1

cnt_even.append([l_even[x+1], wk_cnt_e])
cnt_odd.append([l_odd[x+1], wk_cnt_o])

cnt_even.sort(key=itemgetter(1),reverse=True)
cnt_odd.sort(key=itemgetter(1),reverse=True)


if cnt_even[0][0] == cnt_odd[0][0]:
    if len(cnt_even) == 1 and len(cnt_odd) == 1:
        ans = n / 2
    elif len(cnt_even) == 1:
        ans = n / 2 - cnt_odd[1][1]
    elif len(cnt_odd) == 1:
        ans = n / 2 - cnt_even[1][1]
    else:
        ans = min((n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[1][1]),
                (n / 2 - cnt_even[1][1]) + (n / 2 - cnt_odd[0][1]))

else:
    if len(cnt_even) == 1 and len(cnt_odd) == 1:
        ans = 0
    elif len(cnt_even) == 1:
        ans = n / 2 - cnt_odd[0][1]
    elif len(cnt_odd) == 1:
        ans = n / 2 - cnt_even[0][1]
    else:
        ans = (n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[0][1])


print(int(ans))

Solution (Python):
import collections

c = collections.Counter

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

even_v = [v[i] for i in range(n) if i % 2 == 0]
odd_v = [v[i] for i in range(n) if i % 2 == 1]

c1 = c(even_v).most_common(2)
c2 = c(odd_v).most_common(2)


def calc(x, y):
    return len(even_v) - x[1] + len(odd_v) - y[1]


def main():
    if c1[0] != c2[0]:
        return calc(c1[0], c2[0])

    if len(c1) == 1 and len(c2) == 1:
        return len(odd_v)

    if calc(c1[0], c2[1]) < calc(c1[1], c2[0]):
        return calc(c1[0], c2[1])
    else:
        return calc(c1[1], c2[0])


print(main())

Solution (Python):
from collections import Counter

N = int(input())
V = input().split()
a = V[::2]
b = V[1::2]
h = int(N / 2)
ac = Counter(a)
bc = Counter(b)
ma = ac.most_common()
mb = bc.most_common()
if ma[0][0] == mb[0][0]:
  if len(ma) == len(mb) == 1:
    ans = h
  elif len(ma) == 1:
    ans = h - mb[1][1]
  elif len(mb) == 1:
    ans = h - ma[1][1]
  else:
    ans = min(2 * h - ma[0][1] - mb[1][1], 2 * h - mb[0][1] - ma[1][1])
else:
  ans = 2 * h - ma[0][1] - mb[0][1]
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
V = input().split(' ')
V_even = V[1::2]
V_odd = V[0::2]

V_even_Count = Counter(V_even)

V_odd_Count = Counter(V_odd)


X = []
for x in V_even_Count.most_common(2):
  X.append(x)
if len(X) == 1:
  X.append(('i',0))

Y = []
for y in V_odd_Count.most_common(2):
  Y.append(y)
if len(Y) == 1:
  Y.append(('j',0))

A,B,C,D = X[0],X[1],Y[0],Y[1]
if A[0] != C[0]:
  print(N-A[1]-C[1])
else:
  if B[1] <= D[1]:
    print(N-A[1]-D[1])
  else:
    print(N-B[1]-C[1])

Solution (Python):
from collections import Counter

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

odd_most_common = Counter(v[:: 2]).most_common()[0]
even_most_common = Counter(v[1:: 2]).most_common()[0]

odd_most_cnt = odd_most_common[1]
even_most_cnt = even_most_common[1]

if odd_most_common[0] != even_most_common[0]:
	print(n - odd_most_cnt - even_most_cnt)
else:
	A = odd_most_cnt
	B = even_most_cnt
	if len(set(v[:: 2])) > 1:
		A = Counter(v[:: 2]).most_common()[1][1] + even_most_cnt
	if len(set(v[1:: 2])) > 1:
		B = odd_most_cnt + Counter(v[1:: 2]).most_common()[1][1]
	print(min(n - A, n - B))

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
cnt1=[0]*(10**5+1)
cnt2=[0]*(10**5+1)
for i in range(n):
  if i%2==0:
    cnt1[arr[i]]+=1
  else:
    cnt2[arr[i]]+=1
m1=max(cnt1)
m2=max(cnt2)
p1=cnt1.index(m1)
p2=cnt2.index(m2)
cnt1=sorted(cnt1,reverse=True)
cnt2=sorted(cnt2,reverse=True)
if n==2:
  if arr[0]!=arr[1]:
    print(0)
  else:
    print(1)
else:
  if p1==p2:
    ans=min(n-m1-cnt2[1],n-cnt1[1]-m2)
  else:
    ans=n-m1-m2
  print(ans)

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

V1 = V[::2]
V2 = V[1::2]
 
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]

ans = 0
if k1 == k2:
    ans = n - v1
    m = 0
    if len(V1c) >= 2:
        m = max(m, V1c[1][1])
    if len(V2c) >= 2:
        m = max(m, V2c[1][1])
    ans = ans - m
else:
    ans = n - v1 - v2
print(ans)

Solution (Python):
n=int(input())
v=list(input().split())
v1=v[0:n:2]
v2=v[1:n:2]
import collections
c1=collections.Counter(v1)
a1=c1.most_common()[0][0]
a2=(c1.most_common()[1][0] if len(c1)>=2 else 0)
c2=collections.Counter(v2)
b1=c2.most_common()[0][0]
b2=(c2.most_common()[1][0] if len(c2)>=2 else 0)
if a1!=b1:
    cou=0
    for i in range(n//2):
        if v1[i]!=a1:
            cou+=1
    for i in range(n//2):
        if v2[i]!=b1:
            cou+=1
    print(cou)
else:
    cou1=0
    for i in range(n//2):
        if v1[i]!=a2:
            cou1+=1
    for i in range(n//2):
        if v2[i]!=b1:
            cou1+=1
    cou2=0
    for i in range(n//2):
        if v1[i]!=a1:
            cou2+=1
    for i in range(n//2):
        if v2[i]!=b2:
            cou2+=1
    print(min(cou1,cou2))

Solution (Python):
import numpy as np
even = np.zeros(100001, dtype=int)
odd = np.zeros(100001, dtype=int)

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

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

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()


if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)

Solution (Python):
import numpy as np
even = np.zeros(100001, dtype='i')
odd = np.zeros(100001, dtype='i')

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

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

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()


if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)

Solution (Python):
import numpy as np
even = np.zeros(100001, dtype=np.int32)
odd = np.zeros(100001, dtype=np.int32)

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

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

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()


if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)

Solution (Python):
import numpy as np
even = np.zeros(100001, dtype=np.int64)
odd = np.zeros(100001, dtype=np.int64)

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

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

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()


if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)

Solution (Python):
import numpy as np
even = np.zeros(100001, dtype=int)
odd = np.zeros(100001, dtype=int)

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

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

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()


if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)

Solution (Python):



n = int(input())
v = [0] + list(map(int, input().split()))

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

even = list(reversed(sorted(map(lambda x: (x[1], x[0]), list(even.items())))))
odd = list(reversed(sorted(map(lambda x: (x[1], x[0]), list(odd.items())))))

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

print(ans)

Solution (Python):
import collections

n = int(input())
v = list(map(int, input().split()))
odd, even = [], []

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

    
codd = collections.Counter(odd)
ceven = collections.Counter(even)
mostodd = codd.most_common()[0]
mosteven = ceven.most_common()[0]

if mostodd[0] != mosteven[0]:
  ans = n - mostodd[1] - mosteven[1]
else:
  if len(ceven.most_common()) > 1:
    even2nd = ceven.most_common()[1][1]
  else:
    even2nd = 0
  ans1 = n - mostodd[1] - even2nd
  if len(codd.most_common()) > 1:
    odd2nd = codd.most_common()[1][1]
  else:
    odd2nd = 0
  ans2 = n - odd2nd - mosteven[1] 
  ans = min(ans1, ans2)
print(ans)