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 = [int(x) for x in input().split()]
h = n//2

odds = Counter(v[::2])
evens = Counter(v[1::2])

least_odds = odds.most_common(2)
least_evens = evens.most_common(2)
if len(least_odds) == 1:
    least_odds.append((-1,0))
if len(least_evens) == 1:
    least_evens.append((-1,0))

if least_odds[0][0] == least_evens[0][0]:
    keep = max(least_odds[0][1]+least_evens[1][1], least_odds[1][1]+least_evens[0][1])
else:
    keep = least_odds[0][1]+least_evens[0][1]

print(n-keep)

Solution (Python):
import sys
import socket
from collections import Counter

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    c = [Counter(a[k::2]) for k in range(2)]
    a, b = [c[k].most_common(1)[0] for k in range(2)]

    if a[0] != b[0]:
        return n - a[1] - b[1]
    if a[1] == n // 2 and b[1] == n // 2:
        return n // 2

    res = n
    if a[1] < n // 2:
        p, q = c[0].most_common(2)
        res = min(res, n - q[1] - b[1])
    if b[1] < n // 2:
        p, q = c[1].most_common(2)
        res = min(res, n - a[1] - q[1])

    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
v_odd = v[0::2]
v_even = v[1::2]
chars_odd = list(set(v_odd))
cnt_odd = dict()
for char in chars_odd:
    cnt_odd[char] = 0
for char in v_odd:
    cnt_odd[char] += 1
odd_cnt = sorted(cnt_odd.items(), key=lambda x:x[1], reverse=True)
odd_cnt.append(('_', 0))

chars_even = list(set(v_even))
cnt_even = dict()
for char in chars_even:
    cnt_even[char] = 0
for char in v_even:
    cnt_even[char] += 1
even_cnt = sorted(cnt_even.items(), key=lambda x:x[1], reverse=True)
even_cnt.append(('_', 0))

if odd_cnt[0][0] == even_cnt[0][0]:
    res = max(odd_cnt[0][1] + even_cnt[1][1], odd_cnt[1][1] + even_cnt[0][1])
else:
    res = odd_cnt[0][1] + even_cnt[0][1]
print(n - res)

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

v1 = {}
v2 = {}
for i in range(n):
    if(i % 2 == 0):
        if((v[i] in v1) == True):
            v1[v[i]] += 1
        else:
            v1[v[i]] = 1
    else: 
        if((v[i] in v2) == True):
            v2[v[i]] += 1
        else:
            v2[v[i]] = 1

max_k1 = max(v1, key=v1.get)
max_k2 = max(v2, key=v2.get)

ans1 = 1e9
ans2 = 1e9
if(max_k1 == max_k2):
    tmp = v1[max_k1]
    v1[max_k1] = 0
    max_k1 = max(v1, key=v1.get)
    ans1 = n - v1[max_k1] - v2[max_k2]
    v1[max_k1] = tmp
    max_k1 = max(v1, key=v1.get)

    v2[max_k2] = 0
    max_k2 = max(v2, key=v2.get)
    ans2 = n - v1[max_k1] - v2[max_k2]
else: ans1 = n - v1[max_k1] - v2[max_k2]

print(min(ans1, ans2))

Solution (Python):


import math
import sys
import itertools
import numpy as np



n =int(input())


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

a = {v[0]:1}
b = {v[1]:1}
for i in range(2,n,2):

    if v[i] in a:
        a[v[i]] += 1
    else:
        a[v[i]] = 1
    if v[i+1] in b:
        b[v[i+1]] += 1
    else:
        b[v[i+1]] = 1
    


max_a = max(a, key = a.get)
a1 = max(a.values())
max_b = max(b, key = b.get)
b1 = max(b.values())

if a1 == n // 2:
    a2=0
else:
    a[max_a]=0
    a2 = max(a.values())

if b1 == n // 2:
    b2=0
else:
    b[max_b]=0
    b2 = max(b.values())

c = a1+b2
d = a2+b1

if max_a == max_b:
    print(n-max(c,d))
else:
    print(n-a1-b1)

Solution (Python):
from collections import Counter

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


def main():
    A = V[::2]
    B = V[1::2]

    resA = Counter(A).most_common()
    resB = Counter(B).most_common()

    if resA[0][0] == resB[0][0]:

        if resA[0][1] > resB[0][1]:
            sumA = sum([num for x, num in resA[1:]])
            sumB = resB[0][1] + sum([num for x, num in resB[2:]])
            print(sumA + sumB)
        elif resA[0][1] < resA[0][1]:
            sumB = sum([num for x, num in resB[1:]])
            sumA = resA[0][1] + sum([num for x, num in resA[2:]])
            print(sumA + sumB)
        else:
            if len(resA) == 1 and len(resB) == 1:
                print(n // 2)
            else:
                if resA[1][1] > resB[1][1]:
                    sumB = sum([num for x, num in resB[1:]])
                    sumA = resA[0][1] + sum([num for x, num in resA[2:]])
                    print(sumA + sumB)
                else:
                    sumA = sum([num for x, num in resA[1:]])
                    sumB = resB[0][1] + sum([num for x, num in resB[2:]])
                    print(sumA + sumB)
    else:
        if len(resA) == 1 and len(resB) == 1:
            print(0)
        else:
            sumA = sum([num for x, num in resA[1:]])
            sumB = sum([num for x, num in resB[1:]])
            print(sumA + sumB)


if __name__ == '__main__':
    main()

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

v1 = [v[2 * i] for i in range(len(v) // 2)]
v2 = [v[2 * i + 1] for i in range(len(v) // 2)]

v1in = {}
v2in = {}

for i in range(len(v1)):
    if v1[i] in v1in:
        v1in[v1[i]] += 1
    else:
        v1in[v1[i]] = 1

    if v2[i] in v2in:
        v2in[v2[i]] += 1
    else:
        v2in[v2[i]] = 1

if (len(v1in) == 1) and (len(v2in) == 1):
    if v[0] == v[1]:
        print(len(v1))
    else:
        print(0)
elif (len(v1in) == 1) and (len(v2in) != 1):
    max_k = max(v2in, key=v2in.get)
    if max_k == v[0]:
        del v2in[max_k]
        print(len(v2) - max(v2in.values()))
    else:
        print(len(v2) - v2in[max_k])
elif (len(v1in) != 1) and (len(v2in) == 1):
    max_k = max(v1in, key=v1in.get)
    if max_k == v[1]:
        del v1in[max_k]
        print(len(v1) - max(v1in.values()))
    else:
        print(len(v1) - v1in[max_k])
else:
    v1max_k = max(v1in, key=v1in.get)
    v2max_k = max(v2in, key=v2in.get)

    if v1max_k == v2max_k:
        v1max = v1in[v1max_k]
        del v1in[v1max_k]
        v1max2 = max(v1in.values())

        v2max = v2in[v2max_k]
        del v2in[v2max_k]
        v2max2 = max(v2in.values())

        print(min(len(v1) - v1max + len(v2) - v2max2,
                  len(v1) - v1max2 + len(v2) - v2max))
    else:
        print(len(v1) - v1in[v1max_k] + len(v2) - v2in[v2max_k])

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
a=[[0,i]for i in range(10**5+1)]
b=[[0,i]for i in range(10**5+1)]
for t in sorted(v[0::2]):a[t][0]+=1
for t in sorted(v[1::2]):b[t][0]+=1
c=sorted(a)[::-1]
d=sorted(b)[::-1]
print(n-c[0][0]-[max(c[1][0],d[1][0]),d[0][0]][c[0][1]!=d[0][1]])

Solution (Python):
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
v = il()
a = dict()
b = dict()
for i in range(n):
    if i&1:
        if v[i] in a:
            a[v[i]] += 1
        else:
            a[v[i]] = 1
    else:
        if v[i] in b:
            b[v[i]] += 1
        else:
            b[v[i]] = 1
a = sorted(a.items(), key=lambda x:x[1])
b = sorted(b.items(), key=lambda x:x[1])

h = a[-1][0]
ans = n//2 - a[-1][1]
if b[-1][0] == h:
    if len(b) == 1:
        ans += n//2
    else:
        ans += n//2 - b[-2][1]
else:
    ans += n//2 - b[-1][1]

hoge = ans 

h = b[-1][0]
ans = n//2 - b[-1][1]
if a[-1][0] == h:
    if len(a) == 1:
        ans += n//2
    else:
        ans += n//2 - a[-2][1]
else:
    ans += n//2 - a[-1][1]

print(min(ans, hoge))

Solution (Python):
from collections import defaultdict

_ = input()
ns = list(map(int, input().split()))



xs = ns[0::2]
ys = ns[1::2]

ans = 0
counts = defaultdict(int)
for x in xs:
    counts[x] += 1

max_numx = -1
max_x = -1
for key in counts.keys():
    if counts[key] > max_numx:
        max_numx = counts[key]
        max_x = key

del counts[max_x]
if counts:
    max_numx2 = max(counts.values())
else:
    max_numx2 = 0

counts = defaultdict(int)
for y in ys:
    counts[y] += 1
max_numy = -1
max_y = -1
for key in counts.keys():
    if counts[key] > max_numy:
        max_numy = counts[key]
        max_y = key

del counts[max_y]
if counts:
    max_numy2 = max(counts.values())
else:
    max_numy2 = 0

if max_x != max_y:
    print(len(ns) - max_numx - max_numy)
else:
    print(min(len(ns) - max_numx - max_numy2, len(ns) - max_numx2 - max_numy))

Solution (Python):
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
rec0 = defaultdict(int)
rec1 = defaultdict(int)
for i in range(n):
    if i % 2 == 0:
        rec0[v[i]] += 1
    else:
        rec1[v[i]] += 1

rec00 = []
rec11 = []
for i, k in rec0.items():
    rec00.append((i, k))
for i, k in rec1.items():
    rec11.append((i, k))


rec00 = sorted(rec00, key=lambda x: x[1], reverse=True)
rec11 = sorted(rec11, key=lambda x: x[1], reverse=True)
m = n // 2
if rec00[0][0] != rec11[0][0]:
    print(abs(m - rec00[0][1]) + abs(m - rec11[0][1]))
else:
    if len(rec00) == 1 and len(rec11) == 1:
        print(m)
    elif len(rec00) == 1:
        print(abs(m - rec11[0][1]))
    elif len(rec11) == 1:
        print(abs(m - rec00[0][1]))
    else:
        a = abs(m - rec00[1][1])
        b = abs(m - rec11[1][1])
        num = min(a + abs(m - rec11[0][1]), abs(m - rec00[0][1]) + b)
        print(num)

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

odd = [0 for i in range(10**5)]
even = [0 for i in range(10**5)]

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

oddfirst = 0
oddsecond = 0
evenfirst = 0
evensecond = 0

for i in range(10**5):
    if odd[i] >= oddfirst:
        oddsecond = oddfirst
        oddfirst = odd[i]
        oddmax = i
    elif odd[i] >= oddsecond:
        oddsecond = odd[i]
        
    if even[i] >= evenfirst:
        evensecond = evenfirst
        evenfirst = even[i]
        evenmax = i
    elif even[i] >= evensecond:
        evensecond = even[i]

a = 0
if oddmax == evenmax:
    a = min(oddfirst - oddsecond, evenfirst - evensecond)
        
ans = n - oddfirst - evenfirst + a
print(ans)

Solution (Python):
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
t = Is()
od,ev = [t[i] for i in range(0,n,2)], [t[i] for i in range(1,n,2)]
odm = collections.Counter(od).most_common()[:2]
evm = collections.Counter(ev).most_common()[:2]
if odm[0][0] != evm[0][0]:
    ans = n - odm[0][1] - evm[0][1]
elif len(odm) == len(evm) == 1:
    ans = n//2
elif len(odm) == 1:
    ans = n - odm[0][1] - evm[1][1]
elif len(evm) == 1:
    ans = n - odm[1][1] - evm[0][1]
else:
    ans = n - max(odm[0][1]+evm[1][1], odm[1][1]+evm[0][1])
print(ans)

Solution (Python):
from sys import stderr, setrecursionlimit
from functools import reduce
from operator import add
from collections import Counter
from collections import Counter
setrecursionlimit(2147483647)
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)


n = int(input())
v = f()
debug(v)
ans = 0
even = Counter(v[0::2])
odd = Counter(v[1::2])

most_even = even.most_common(2)
most_odd = odd.most_common(2)


if most_even[0][0] == most_odd[0][0]:
    if most_even[0][1] == most_odd[0][1]:
        
        if len(most_even) != 1 and len(most_even) != 1:
            if most_even[1][1] < most_odd[1][1]:
                ans = (n//2 - most_even[0][1]) +  (n//2 - most_odd[1][1])
            else:
                ans = (n//2 - most_odd[0][1]) +  (n//2 - most_even[1][1])
        elif len(most_even) == 1 and len(most_odd) != 1:
            
            ans = (n//2 - most_even[0][1]) + (n//2 - most_odd[1][1])
        elif len(most_even) != 1 and len(most_odd) == 1:
            
            ans = (n//2 - most_even[1][1]) +  (n//2 - most_odd[0][1])
        else:
            ans = (n//2 - most_even[0][1]) + (n//2)
    
    else:
        if len(most_even) != 1 and len(most_odd) != 1:
            
            if most_even[0][1] + most_odd[1][1] < most_even[1][1] + most_odd[0][1]:
                ans = (n//2 - most_even[1][1]) +  (n//2 - most_odd[0][1])
            else:
                ans = (n//2 - most_even[0][1]) +  (n//2 - most_odd[1][1])
        elif len(most_even) == 1 and len(most_odd) != 1:
            
            if most_even[0][1] + most_odd[1][1] < (n//2 - most_even[0][1]) + most_odd[0][1]:
                ans = most_even[0][1] + (n//2 - most_odd[0][1])
            else:
                ans = (n//2 - most_even[0][1]) + (n//2 - most_odd[1][1])
        elif len(most_even) != 1 and len(most_odd) == 1:
            
            if most_even[0][1] + (n//2 - most_odd[0][1]) < most_even[1][1] + most_odd[0][1]:
                ans = (n//2 - most_even[1][1]) + (n//2 - most_odd[0][1])
            else:
                ans = (n//2 - most_odd[0][1]) + most_even[0][1]
        else:
            
            if most_even[0][1] < most_odd[0][1]:
                ans = (n//2 - most_odd[0][1]) + n//2
            else:
                ans = n//2 + (n//2 - most_even[0][1])
else:
    ans = n - most_even[0][1] - most_odd[0][1]

print(ans)

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

def main():
	n = int(input())
	v = [int(i) for i in input().split()]
	v1 = [0] * 100020
	v2 = [0] * 100020
	v11 = 0
	v21 = 0
	v12 = 0
	v22 = 0
	ans = 0
	for i in range(n):
		if i % 2 == 0:
			v1[v[i]] += 1
		else:
			v2[v[i]] += 1
	for i in range(10**5 + 10):
		if v1[i] >= v1[v11]:
			v12, v11 = v11, i
		elif v1[i]>=v1[v12]:
			v12 = i
		if v2[i] >= v2[v21]:
			v22, v21 = v21, i
		elif v2[i]>=v2[v22]:
			v22 = i
	if v11 == v21:
		ans = min(n-v1[v11] - v2[v22], n-v1[v12]-v2[v21])
	else:
		ans = n - v1[v11] - v2[v21]
	print(ans)

main()

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

f = {}
b = {}

fcnt = 0
bcnt = 0
for v in vv:
    if fcnt == bcnt:
        if v in f:
            f[v] += 1
        else:
            f[v] = 1
        fcnt += 1
    else:
        if v in b:
            b[v] += 1
        else:
            b[v] = 1
        bcnt += 1


ff = sorted(list(map(lambda x: tuple(reversed(x)), f.items())), reverse = True)
bb = sorted(list(map(lambda x: tuple(reversed(x)), b.items())), reverse = True)

if ff[0][1] != bb[0][1]:
    print(n - ff[0][0] - bb[0][0])
else:
    ans = 1145141919
    if len(bb) == 1:
        ans = min(ans, n - ff[0][0])
    else:
        ans = min(ans, n - ff[0][0] - bb[1][0])
    
    if len(ff) == 1:
        ans = min(ans, n - bb[0][0])
    else:
        ans = min(ans, n - bb[0][0] - ff[1][0])
    print(ans)

Solution (Python):
from collections import Counter

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

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


ans = 0
if even_most_common[0][0] == odd_most_common[0][0]:
    if len(even_most_common) == 1 and len(odd_most_common) == 1:
        ans += n // 2
    elif len(even_most_common) == 1:
        ans += n // 2 - odd_most_common[1][1]
    elif len(odd_most_common) == 1:
        ans += n // 2 - even_most_common[1][1]
    elif even_most_common[0][1] == odd_most_common[0][1]:
        if even_most_common[1][1] < odd_most_common[1][1]:
            ans += n // 2 - even_most_common[0][1]
            ans += n // 2 - odd_most_common[1][1]
        else:
            ans += n // 2 - even_most_common[1][1]
            ans += n // 2 - odd_most_common[0][1]
    elif even_most_common[0][1] > odd_most_common[0][1]:
        ans += n // 2 - even_most_common[0][1]
        ans += n // 2 - odd_most_common[1][1]
    else:
        ans += n // 2 - even_most_common[1][1]
        ans += n // 2 - odd_most_common[0][1]
else:
    ans += n // 2 - even_most_common[0][1]
    ans += n // 2 - odd_most_common[0][1]

print(ans)

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
a = v[0::2]
b = v[1::2]
a = sorted(a)
b = sorted(b)
a = collections.Counter(a).most_common()
b = collections.Counter(b).most_common()

p,q = [],[]
r,s = n//2,n//2
for (c,d) in a:
    if d==a[0][1]:
        p.append(c)
    else:
        r = d
        break
for (c,d) in b:
    if d==b[0][1]:
        q.append(c)
    else:
        s = d
        break

if (len(a),len(b))==(1,1):
    if a==b:
        print(n//2)
    else:
        print(0)
elif len(a)==1:
    print(n//2-b[0][1])
elif len(b)==1:
    print(n//2-a[0][1])
elif (len(p),len(q))==(1,1) and p==q:
    print(min(n-a[0][1]-s,n-b[0][1]-r))
else:
    print(n-a[0][1]-b[0][1])

Solution (Python):
import collections
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])
    
ac = collections.Counter(a)
bc = collections.Counter(b)

atemp = []
for i in ac:
    atemp.append(ac[i])
btemp = []
for i in bc:
    btemp.append(bc[i])

mxma = max(atemp)
mxmb = max(btemp)
for i in ac:
    if ac[i] == mxma:
        mxma = i
        break
for i in bc:
    if bc[i] == mxmb:
        mxmb = i
        break

atemp.sort()
btemp.sort()

if mxma != mxmb:
    print(n-max(atemp)-max(btemp))
else:
    if len(atemp) == 1 and len(btemp) == 1:
        print(n-max(atemp))
    else:
        temp = [atemp[-2]+btemp[-1],atemp[-1]+btemp[-2]]
        print(n-max(temp))

Solution (Python):

import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)

from collections import Counter

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

c = Counter(v)
if len(c) == 1:
    print(n//2)
    exit()















odd = [v[2*i+1] for i in range(n//2)]
even = [v[2*i] for i in range(n//2)]



oc = Counter(odd).most_common()
ec = Counter(even).most_common()

if oc[0][0] != ec[0][0]:
    odd_count = oc[0][1]
    even_count = ec[0][1]
    both_count = odd_count + even_count
else:
    
    
    
    
    
    
    both1 = oc[0][1] + ec[1][1]
    both2 = oc[1][1] + ec[0][1]
    both_count = max(both1, both2)

print(n-both_count)

Solution (Python):
from collections import defaultdict

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

ODD = defaultdict(int)
EVEN = defaultdict(int)
NUMBER = set()

for i in range(n):
    if i%2==0:
        EVEN[V[i]] += 1
    else:
        ODD[V[i]] += 1
    NUMBER.add(V[i])
    
    
ODD[999999] = 0
EVEN[999999] = 0
if len(NUMBER)==1:
    print(n//2)
else:
    flag = True
    max_ODD = max(ODD, key=ODD.get)
    max_EVEN = max(EVEN, key=EVEN.get)
    O = [ODD[max_ODD]]
    E = [EVEN[max_EVEN]]
    if max_ODD != max_EVEN:
        print(n-O[0]-E[0])
    else:
        ODD.pop(max_ODD)
        EVEN.pop(max_EVEN)
        max_ODD = max(ODD, key=ODD.get)
        max_EVEN = max(EVEN, key=EVEN.get)
        O.append(ODD[max_ODD])
        E.append(EVEN[max_EVEN])
        print(min([n-O[0]-E[1],n-O[1]-E[0]]))

Solution (Python):
from collections import Counter

n = int(input())
v_list = [int(i) for i in input().split()]
odd_v = v_list[::2]
even_v = v_list[1::2]

cnt_odd = Counter(odd_v).most_common()+[(0, 0)]
cnt_even = Counter(even_v).most_common()+[(0, 0)]

if cnt_odd[0][0] == cnt_even[0][0]:
    print(min(n-cnt_odd[0][1]-cnt_even[1][1], \
              n-cnt_odd[1][1]-cnt_even[0][1]))
else:
    print(n-cnt_odd[0][1]-cnt_even[0][1])

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

odv = []
evv = []

for i in range(n):
    if i%2 == 1:
        odv.append(v[i])
    else:
        evv.append(v[i])

odvc=collections.Counter(odv)
evvc=collections.Counter(evv)

odvs=len(odv)
evvs=len(evv)

odv_kind=len(odvc.most_common())
evv_kind=len(evvc.most_common()) 

if evvc.most_common()[0][0] != odvc.most_common()[0][0]:
    print( odvs-odvc.most_common()[0][1] + evvs-evvc.most_common()[0][1] )
else:
    if odv_kind > 1 and evv_kind > 1:
        print( min(odvs-odvc.most_common()[0][1] + evvs-evvc.most_common()[1][1] ,
                   odvs-odvc.most_common()[1][1] + evvs-evvc.most_common()[0][1] ) )
    else:
        if odv_kind > 1:
            print( odvs-odvc.most_common()[0][1] )
        elif evv_kind > 1:
            print( evvs-evvc.most_common()[0][1] )
        else:
            print(min(odvs,evvs))

Solution (Python):
n = int(input())
vi = list(map(int,input().split()))
odd = [vi[k] for k in range(0,n,2)]
even = [vi[k+1] for k in range(0,n,2)]
odd.sort()
even.sort()

odd.append(-1)
even.append(-1)

oddset = []
oddcounter = []
pos = 0
while pos<n/2:
    oddset.append(odd[pos])
    counter = 1
    now = odd[pos]
    pos += 1
    while now == odd[pos]:
        counter +=1
        pos += 1
    oddcounter.append([counter,now])

evenset = []
evencounter = []
pos = 0
while pos<n/2:
    evenset.append(even[pos])
    counter = 1
    now = even[pos]
    pos += 1
    while now == even[pos]:
        counter +=1
        pos += 1
    evencounter.append([counter,now])

oddcounter.sort(key=lambda x:x[0],reverse=True)
evencounter.sort(key=lambda x:x[0],reverse=True)

oc = oddcounter
ec = evencounter

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

Solution (Python):
N = int(input())
v = list(map(int, input().split()))
d0 = {0: 0}
d1 = {0: 0}
for j, i in enumerate(v):
    if j % 2 == 0:
        if i in d0:
            d0[i] += 1
        else:
            d0[i] = 1
    else:
        if i in d1:
            d1[i] += 1
        else:
            d1[i] = 1

l0 = sorted(d0.items(), key=lambda x: -x[1])
l1 = sorted(d1.items(), key=lambda x: -x[1])

if l0[0][0] == l1[0][0]:
    a = min(N - l0[0][1] - l1[1][1], N - l0[1][1] - l1[0][1])
    print(a)
else:
    print(N - l0[0][1] - l1[0][1])

Solution (Python):
import numpy as np
import collections

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

e=np.array([v[i] for i in range(0,n,2)])
o=np.array([v[i] for i in range(1,n,2)])

se=set(e)
so=set(o)


lle=collections.Counter(e)
llo=collections.Counter(o)
le=[]
for k,v in lle.items():
    le.append([n//2-v,k])
lo=[]
for k,v in llo.items():
    lo.append([n//2-v,k])
le.sort()
lo.sort()

if(len(lle)==1 and len(llo)==1):
    if(e[0]==o[0]):print(n//2)
    else:print(0)
    exit()




if(len(se)==1):
    if(lo[0][1]!=le[0][1]):print(lo[0][0])
    else:print(lo[1][0])
elif(len(so)==1):
    if(lo[0][1]!=le[0][1]):print(le[0][0])
    else:print(le[1][0])
else:
    if(lo[0][1]!=le[0][1]):print(le[0][0]+lo[0][0])
    else:print(min(le[1][0]+lo[0][0],le[0][0]+lo[1][0]))

Solution (Python):


import collections
import itertools
import sys


INVALID = -1
INF = sys.maxsize // 2


def solve(n, vs):
    up_vals = vs[::2]
    up_ctr = collections.Counter(up_vals)
    up_ctr[INVALID] = 0
    down_vals = vs[1::2]
    down_ctr = collections.Counter(down_vals)
    down_ctr[INVALID] = 0
    up_mcs = up_ctr.most_common(3)
    down_mcs = down_ctr.most_common(3)
    cost = INF
    for (k_up, v_up), (k_down, v_down) in itertools.product(up_mcs, down_mcs):
        if k_up != k_down:
            new_cost = n - v_up - v_down
            cost = min(new_cost, cost)
    return cost


def main():
    n = int(input())
    vs = [int(v) for v in input().split()]
    print(solve(n, vs))


if __name__ == '__main__':
    main()

Solution (Python):





"""
ARC103 C
"""

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

evli = vli[::2]
ovli = vli[1::2]

from collections import Counter
Cevli = Counter(evli).most_common(2)
Covli = Counter(ovli).most_common(2)

vem,iem=Cevli[0]
vom,iom=Covli[0]

if vem!=vom:
    ans = n-iem-iom
elif iem == n//2 and iom == n//2:
    ans = n//2
elif iem == n//2:
    vom2,iom2=Covli[1]
    ans = n-n//2-iom2
elif iom == n//2:
    vem2,iem2=Cevli[1]
    ans = n-n//2-iem2
else:
    vem2,iem2=Cevli[1]
    vom2,iom2=Covli[1]
    ans1 = n-iem-iom2
    ans2 = n-iem2-iom
    ans = min(ans1,ans2)

print(ans)

Solution (Python):
import collections

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

count_even = collections.Counter(v[0::2])
count_odd =  collections.Counter(v[1::2])


if count_even.most_common()[0][0] != count_odd.most_common()[0][0]:
    ans = n - count_even.most_common()[0][1] -count_odd.most_common()[0][1]
else:
    if len(count_even) == 1 and len(count_odd) == 1:
        ans = n//2
    elif len(count_even) == 1:
        ans = n//2 - count_odd.most_common()[1][1]
    elif len(count_odd) == 1:
        ans = (n+1)//2 - count_even.most_common()[1][1]
    else:
        ans_tmp1 = n - count_even.most_common()[0][1] - count_odd.most_common()[1][1]
        ans_tmp2 = n - count_even.most_common()[1][1] - count_odd.most_common()[0][1]
        ans = min(ans_tmp1, ans_tmp2)

print(ans)

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
ecost = [n//2 for _ in range(100001)]
ocost = [n//2 for _ in range(100001)]
for i in range(n):
    if i%2 == 0:
        ecost[v[i]] -= 1
    else:
        ocost[v[i]] -= 1
e1 = ecost[1]
ve1 = 1
e2 = ecost[2]
ve2 = 2
o1 = ocost[1]
vo1 = 1
o2 = ocost[2]
vo2 = 2
for i in range(3,100001):
    ecand = ecost[i]
    ocand = ocost[i]
    if ecand <= e1:
        e2 = e1
        e1 = ecand
        ve2 = ve1
        ve1 = i
    elif ecand <= e2:
        e2 = ecand
        ve2 = i
    if ocand <= o1:
        o2 = o1
        o1 = ocand
        vo2 = vo1
        vo1 = i
    elif ocand <= o2:
        o2 = ocand
        vo2 = i
if vo1 != ve1:
    ans = o1 + e1
else:
    ans = e1 + min(o2,e2)
print(ans)

Solution (Python):
from collections import Counter

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

cnt0 = Counter(vs[0::2])
cnt1 = Counter(vs[1::2])

cnt0[0] = 0
cnt1[0] = 0

ans = n
for v0, num0 in cnt0.most_common(2):
    for v1, num1 in cnt1.most_common(2):
        if v0 != v1:
            ans = min(ans, n - (num0 + num1))

print(ans)

Solution (Python):
from statistics import mode
from collections import Counter

n = int(input())

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


guu = []
kii = []

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

counterK = Counter(guu)
guuMaxCount = counterK.most_common()[0][1]

counterG = Counter(kii)
kiiMaxCount = counterG.most_common()[0][1]

if counterK.most_common()[0][0] == counterG.most_common()[0][0]:
    if n == 2:
        kiiMaxCount = 0
    elif n == 3:
        kiiMaxCount = 0
    elif n >= 4:
        if len(counterK.most_common()) >= 2 and len(counterG.most_common()) >= 2:
            if kiiMaxCount - counterK.most_common()[1][1] >= guuMaxCount - counterG.most_common()[1][1]:
                guuMaxCount = counterG.most_common()[1][1]
            else:
                kiiMaxCount = counterK.most_common()[1][1]
        elif len(counterK.most_common()) >= 2 and len(counterG.most_common()) == 1:
            kiiMaxCount = kiiMaxCount = counterK.most_common()[1][1]
        elif len(counterK.most_common()) == 1 and len(counterG.most_common()) >= 2:
            guuMaxCount = counterG.most_common()[1][1]
        else:
            kiiMaxCount = 0

ans = n



print(ans - guuMaxCount - kiiMaxCount)

Solution (Python):
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

even = Counter(a[::2])
odd = Counter(a[1::2])

es = [(0,0)]
for ek,ev in even.items():
    es.append((ev,ek))
    
es.sort()
    
    
os = [(0,0)]
for ok,ov in odd.items():
    os.append((ov,ok))
    
os.sort()
    

if es[-1][1] != os[-1][1]:
    print((n//2-es[-1][0]) + (n//2-os[-1][0]))
else:
    print(min((n//2-es[-1][0]) + (n//2-os[-2][0]),
              (n//2-es[-2][0]) + (n//2-os[-1][0])))

Solution (Python):



import collections

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

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

aedic = collections.Counter()

aodic = collections.Counter()

for i in ae:
    aedic[i]+=1
for i in ao:
    aodic[i]+=1

p=aedic.most_common(2)
q=aodic.most_common(2)



if p[0][0] != q[0][0]:

    print(n-p[0][1]-q[0][1])
elif len(p)==1 and len(q)!=1:

    print(n-p[0][1]-q[1][1])
elif len(p)!=1 and len(q)==1:

    print(n-p[1][1]-q[0][1])
elif len(p)==1 and len(q)==1:

    print(n//2)
else:

    a=min(n-p[-1][1]-q[0][1], n-p[0][1]-q[-1][1])
    print(a)

Solution (Python):
from collections import Counter

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

C1 = list(dict(Counter(A[::2])).items())
C2 = list(dict(Counter(A[1::2])).items())

C1.append([-1, 0])
C2.append([-1, 0])
C1.sort(key=lambda x: x[1], reverse=True)
C2.sort(key=lambda x: x[1], reverse=True)

if C1[0][0] != C2[0][0]:
    print(N - C1[0][1] - C2[0][1])
else:
    ans1 = N - C1[0][1] - C2[1][1]
    ans2 = N - C1[1][1] - C2[0][1]
    print(min(ans1, ans2))

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
w=sorted(a for a in v[0::2])
x=sorted(a for a in v[1::2])
a=[[0,i]for i in range(10**5+1)]
b=[[0,i]for i in range(10**5+1)]
for t in w:
    a[t][0]+=1
for t in x:
    b[t][0]+=1
c=sorted(a)[::-1]
d=sorted(b)[::-1]
if c[0][1]==d[0][1]:
    t=max(c[1][0],d[1][0])
    print(n-c[0][0]-t)
else:
    print(n-c[0][0]-d[0][0])