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

Solution (Python):
n = int(input())
v = input().split()
if len(set(v)) == 1:
    print(int(n/2))
    exit()
even = v[0::2]
odd = v[1::2]
deven = {i:0 for i in set(even)}
dodd = {i:0 for i in set(odd)}
for i in even:
    deven[i] += 1
for i in odd:
    dodd[i] += 1
deven = sorted(deven.items(), key = lambda x: x[1], reverse = True)
dodd = sorted(dodd.items(), key = lambda x: x[1], reverse = True)
res = 0
if deven[0][0] != dodd[0][0]:
    if deven[0][1] != int(n/2):
        res += int(n/2) - deven[0][1]
    if dodd[0][1] != int(n/2):
        res += int(n/2) - dodd[0][1]
else:
    if deven[0][1] == dodd[0][1]:
        res += n - deven[0][1] - max(deven[1][1], dodd[1][1])
    else:
        if deven[0][1] > dodd[0][1]:
            res += n - deven[0][1] - dodd[1][1]
        else:
            res += n - dodd[0][1] - deven[1][1] 
print(res)

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

def cnt(v):
    count_map = {}
    for i in v:
        count_map[i] = count_map.get(i, 0) + 1
    if len(count_map) == 1:
        count_map[-1] = 0
    return sorted(count_map.items(), key=lambda x: x[1], reverse=True)

maxv = list(map(cnt, [a[::2], a[1::2]]))

def check(v1, v2):
    return (n + 1) // 2 - v1 + n // 2 - v2

if maxv[0][0][0] == maxv[1][0][0]:
    result = min(
        check(maxv[0][1][1], maxv[1][0][1]),
        check(maxv[0][0][1], maxv[1][1][1]),
    )
else:
    result = check(maxv[0][0][1], maxv[1][0][1])
print(result)

Solution (Python):
from collections import Counter
 
n = int(input())
vs = input().split()
 
xs = [v for v in vs[::2]]
x = Counter(xs).most_common()

ys = [v for v in vs[1::2]]
y = Counter(ys).most_common()
 
if x[0][0] != y[0][0]:
    rw1 = n - x[0][1] - y[0][1]
    print(rw1)
else:
    if len(x) == 1 and len(y) != 1:
        rw2 = n//2 - y[1][1]
        print(rw2)
    elif len(x) != 1 and len(y) == 1:
        rw3 = n//2 - x[1][1]
        print(rw3)
    elif len(x) ==1 and len(y) == 1:
        rw4 = n//2
        print(rw4)
    else:
        rw5_1 = (n//2 - x[0][1]) + (n//2 - y[1][1])
        rw5_2 = (n//2 - x[1][1]) + (n//2 - y[0][1])
        print(min(rw5_1, rw5_2))

Solution (Python):
import collections

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

odd = []
even = []

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

odd = collections.Counter(odd)
even = collections.Counter(even)
max_odd = 0
max_odd2 = 0
max_even = 0
max_even2 = 0
for i in odd:
    if max_odd < odd[i]:
        max_odd2 = max_odd
        max_odd = odd[i]
        x = i
    elif max_odd2 < odd[i]:
        max_odd2 = odd[i]
    

for j in even:
    if max_even < even[j]:
        max_even2 = max_even
        max_even = even[j]
        y = j
    elif max_even2 < even[j]:
        max_even2 = even[j]

if x != y:
    print(n - max_odd - max_even)
else:
    print(min(n - max_odd - max_even2, n - max_odd2 - max_even))

Solution (Python):
import math
import sys
import bisect

N = int(input())
V = [int(x) for x in input().split()]

V0 = V[0::2]
V1 = V[1::2]

def cntDict(L):
    d = dict()
    for l in L:
        d[l] = d.get(l, 0) + 1
    return d

INF = 999
def max1_2(d):
    k1 = -INF
    v1 = -INF
    k2 = -INF
    v2 = -INF
    for k in d.keys():
        v = d[k]
        if v1 < v:
            k2 = k1
            v2 = v1
            k1 = k
            v1 = v
        elif v2 < v:
            v2 = v
            k2 = k
    
    return k1,k2

d0 = cntDict(V0)
d1 = cntDict(V1)

C0 = max1_2(d0)
C1 = max1_2(d1)

INF = 10**10


if C0[0] == C1[0]:
    p1 = INF
else:
    p1 = 0
    for v in V0:
        if v != C0[0]:
            p1+=1
    for v in V1:
        if v != C1[0]:
            p1+= 1



if C0[0] == C1[1]:
    p2 = INF
else:
    p2 = 0
    for v in V0:
        if v != C0[0]:
            p2+=1
    for v in V1:
        if v != C1[1]:
            p2+= 1


if C0[1] == C1[0]:
    p3 = INF
else:
    p3 = 0
    for v in V0:
        if v != C0[1]:
            p3+=1
    for v in V1:
        if v != C1[0]:
            p3+= 1


if C0[1] == C1[1]:
    p4 = INF
else:
    p4 = 0
    for v in V0:
        if v != C0[1]:
            p4+=1
    for v in V1:
        if v != C1[1]:
            p4+= 1

ret = min(p1,p2,p3,p4)

print(ret)


pass

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

e = v[::2]
o = v[1::2]

ev = {}
ov = {}
for t in e :
    if t in ev :
        ev[t] = ev[t] + 1
    else :
        ev[t] = 1

for t in o :
    if t in ov:
        ov[t] = ov[t] + 1
    else :
        ov[t] = 1

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





    



ee  = ev[0][0]
oo  = ov[0][0]

es0 = ev[0][1]
os0 = ov[0][1]
ans = n - es0 - os0

if ee == oo:
    tmp1 = n - es0
    tmp2 = n - os0

    if len(ev) > 1:
        es1 = ev[1][1]
        tmp1 = n  - es1  - os0

    if len(ov) > 1:
        os1 = ov[1][1]
        tmp2 = n  - es0  - os1

    if tmp1 > tmp2 :
        ans = tmp2 
    else :
        ans = tmp1

print(ans)

Solution (Python):
from collections import defaultdict


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

if len(set(V)) == 1:
    print(N // 2)
    exit()

counter = defaultdict(int)
for i in range(N):
    if i % 2 == 0:
        counter[V[i]] += 1

pairs_1 = sorted([(k, v) for k, v in counter.items()], key=lambda p: p[1], reverse=True)

counter = defaultdict(int)
for i in range(N):
    if i % 2 != 0:
        counter[V[i]] += 1

pairs_2 = sorted([(k, v) for k, v in counter.items()], key=lambda p: p[1], reverse=True)

if pairs_1[0][0] != pairs_2[0][0]:
    ans = (N // 2 - pairs_1[0][1]) + (N // 2 - pairs_2[0][1])
else:
    ans = min((N // 2 - pairs_1[0][1]) + (N // 2 - pairs_2[1][1]), (N // 2 - pairs_1[1][1]) + (N // 2 - pairs_2[0][1]))
print(ans)

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])
m1 = c1.most_common()
m2 = c2.most_common()
t2 = N//2
t1 = N - t2

if len(m1) == len(m2) == 1:
    print(N//2 if m1[0][0] == m2[0][0] else 0)
elif len(m1) == 1:
    if m1[0][0] != m2[0][0]:
        print(t1 - m2[0][1])
    else:
        print(t1 - m2[1][1])
elif len(m2) == 1:
    if m1[0][0] != m2[0][0]:
        print(t2 - m1[0][1])
    else:
        print(t2 - m1[1][1])
else:
    if m1[0][0] != m2[0][0]:
        print(N - m1[0][1] - m2[0][1])
    else:
        ans = N - m1[1][1] - m2[1][1]
        if m1[0][0] != m2[1][0]:
            ans = min(ans, N - m1[0][1] - m2[1][1])
        if m1[1][0] != m2[0][0]:
            ans = min(ans, N - m1[1][1] - m2[0][1])
        print(ans)

Solution (Python):
from collections import Counter

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

list0 = []
list1 = []
for i, a in enumerate(v):
    if i % 2 == 0:
        list0.append(a)
    else:
        list1.append(a)

c0 = Counter(list0)
c1 = Counter(list1)

c0_most_common = c0.most_common(2)
c1_most_common = c1.most_common(2)

if c0_most_common[0][0] != c1_most_common[0][0]:
    print(n - (c0_most_common[0][1] + c1_most_common[0][1]))
else:
    if len(c0_most_common) >= 2 and len(c1_most_common) >= 2:
        print(min(n - (c0_most_common[0][1] + c1_most_common[1][1]), n - (c0_most_common[1][1] + c1_most_common[0][1])))
    elif len(c0_most_common) == 1 and len(c1_most_common) >= 2:
        print(n - (c0_most_common[0][1]) + c1_most_common[1][1])
    elif len(c1_most_common) == 1 and len(c0_most_common) >= 2:
        print(n - (c1_most_common[0][1]) + c0_most_common[1][1])
    else:
        print(n - (c1_most_common[0][1]))

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

sys.setrecursionlimit(10**5)

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()
v = list(li())

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

odd_cm = odd.most_common(2)
even_cm = even.most_common(2)

odd_cm.append((0,0))
even_cm.append((0,0))

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

Solution (Python):
def abc111_c():
    import collections
    
    b_len = int(int(input()) / 2)
    a = list(map(int, input().split()))
    b1 = a[::2]
    b2 = a[1::2]
    b1_count = collections.Counter(b1).most_common()
    b2_count = collections.Counter(b2).most_common()

    if len(b1_count) == 1:
        if len(b2_count) == 1:
            if b1_count[0][0] == b2_count[0][0]:
                return b_len
            else:
                return 0
        else:
            if b1_count[0][0] == b2_count[0][0]:
                return b_len - b2_count[1][1]
            else:
                return b_len - b2_count[0][1]
    elif len(b2_count) == 1:
        if b2_count[0][0] == b1_count[0][0]:
            return b_len - b1_count[1][1]
        else:
            return b_len - b1_count[0][1]
    else:
        if b1_count[0][0] == b2_count[0][0]:
            return 2 * b_len - max(b1_count[0][1] + b2_count[1][1], b1_count[1][1] + b2_count[0][1])
        else:
            return 2 * b_len - b1_count[0][1] - b2_count[0][1]


print(abc111_c())

Solution (Python):



n = int(raw_input())
vs = [int(x) for x in raw_input().split()]

from collections import defaultdict
v1 = defaultdict(int)
v2 = defaultdict(int)
for i in xrange(0, n, 2):
	v1[vs[i]] += 1
	v2[vs[i+1]] += 1
v1 = [(k, v) for k, v in v1.iteritems()]
v2 = [(k, v) for k, v in v2.iteritems()]
v1 = sorted(v1, key=lambda x: x[1], reverse=True)
v2 = sorted(v2, key=lambda x: x[1], reverse=True)

if v1[0][0] == v2[0][0]:
	if len(v1) == 1:
		count = n - v2[0][1]
	elif len(v2) == 1:
		count = n - v1[0][1]
	else:
		count = n - max(v1[0][1] + v2[1][1], v1[1][1] + v2[0][1])
else:
	count = n - v1[0][1] - v2[0][1]
print count

Solution (Python):
import collections

N = int(input())

even = collections.defaultdict(lambda: 0)
odd = collections.defaultdict(lambda: 0)

for i, a in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even[a] += 1
    else:
        odd[a] += 1

if len(even.keys()) == 1 and len(odd.keys()) == 1 and list(even.keys())[0] == list(odd.keys())[0]:
    print(N // 2)
else:
    m = 0
    for e_k, e_v in sorted(even.items(), key=lambda x: x[1], reverse=True)[:2]:
        for o_k, o_v in sorted(odd.items(), key=lambda x: x[1], reverse=True)[:2]:
            if e_k == o_k:
                continue
            m = max(m, e_v + o_v)

    print(N - m)

Solution (Python):
def get2(d):
    k1, k2 = -1, -1
    c1, c2 = 0, 0
    for key, val in d.items():
        if val > c2:
            k2, c2 = key, val
            if val > c1:
                c1, c2 = c2, c1
                k1, k2 = k2, c1
    return ((k1, c1), (k2, c2))

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

d_evn = {}
d_odd = {}

for i in range(n):
    if i % 2 == 0:
        d_evn[v[i]] = d_evn.get(v[i], 0) + 1
    else:
        d_odd[v[i]] = d_odd.get(v[i], 0) + 1

a = get2(d_evn)
b = get2(d_odd)

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    if a[0][1] + b[1][1] > a[1][1] + b[0][1]:
        print(n - a[0][1] - b[1][1])
    else:
        print(n - a[1][1] - b[0][1])

Solution (Python):


 
from collections import defaultdict
 
n=int(raw_input())
v=[int(x) for x in raw_input().split()]
 
a,b = defaultdict(lambda: 0), defaultdict(lambda: 0)
for i, val in enumerate(v):
	if i%2 == 1:
		a[val] += 1
	else:
		b[val] += 1
a[-1] = 0
b[-2] = 0
aa = sorted([(y,x) for x, y in a.iteritems()], reverse=True)
bb = sorted([(y,x) for x, y in b.iteritems()], reverse=True)

if aa[0][1] != bb[0][1]:
	print n - (aa[0][0] + bb[0][0])
else:
	print n - max((aa[0][0] + bb[1][0]), (aa[1][0] + bb[0][0]))

Solution (Python):
from collections import Counter

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

xs = [v for v in vs[::2]]
x = Counter(xs).most_common()

ys = [v for v in vs[1::2]]
y = Counter(ys).most_common()

if x[0][0] != y[0][0]:
    d = n - x[0][1] - y[0][1]
    print(d)
else:
    if len(x) == 1:
        print(n // 2)
    else:
        d1 = n - x[0][1] - y[1][1]
        d2 = n - x[1][1] - y[0][1]
        if d1 > d2:
            print(d2)
        else:
            print(d1)

Solution (Python):
n=int(input())
v=map(int,input().split())
vodd={-1:0}
veven={-1:0}
for i,vi in enumerate(v):
    if i%2:
        if(vi in veven):
            veven[vi]+=1
        else:
            veven[vi]=1
    else:
        if(vi in vodd):
            vodd[vi]+=1
        else:
            vodd[vi]=1
veven=list(veven.items())
veven.sort(key=lambda x:-x[1])
vodd=list(vodd.items())
vodd.sort(key=lambda x:-x[1])
if veven[0][0]==vodd[0][0]:
    a=veven[0][1]+vodd[1][1]
    b=veven[1][1]+vodd[0][1]
    changeCnt=n-a if a>b else n-b
else:
    changeCnt=n-veven[0][1]-vodd[0][1]

print(changeCnt)

Solution (Python):
def GetMaxes(d):
    m = []
    for k, v in d.items():
        m.append([k,v])
    m.sort(key=lambda x:-x[1])

    if len(m) == 1:
        m.append([0, 0])
    return m[:2]

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

    dic0 = dict()
    dic1 = dict()
    d = [dic0, dic1]
    for i in range(n):
        dic = d[i%2]
        if v[i] not in dic:
            dic[v[i]] = 1
        else:
            dic[v[i]] += 1

    m0 = GetMaxes(d[0])
    m1 = GetMaxes(d[1])

    if m0[0][0] == m1[0][0]:
        take0 = m0[0][1] + m1[1][1]
        take1 = m1[0][1] + m0[1][1]
        if take0 > take1:
            print(n-take0)
        else:
            print(n-take1)
    else:
        print(n - m0[0][1] - m1[0][1])

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
lis = list(map(int, input().split()))
l1 = []
l2 = []
for i in range(100001):
    l1.append([0, i])
    l2.append([0, i])

for i in range(N):
    if i % 2:
        l1[lis[i]][0] += 1
    else:
        l2[lis[i]][0] += 1


l1 = sorted(l1, key=lambda x: x[0], reverse=True)
l2 = sorted(l2, key=lambda x: x[0], reverse=True)

if l1[0][1] != l2[0][1]:
    print(int(N / 2 - l1[0][0] + N / 2 - l2[0][0]))
else:
    print(int(min(N / 2 - l1[0][0] + N / 2 - l2[1][0], N / 2 - l1[1][0] + N / 2 - l2[0][0])))

Solution (Python):
from operator import itemgetter

def solution(a):
    n = len(a)
    lhs, rhs = {-1 : 0}, {-1 : 0}
    for i in xrange(0, n, 2):
        if a[i] not in lhs:
            lhs[a[i]] = 0
        lhs[a[i]] += 1
    for i in xrange(1, n ,2):
        if a[i] not in rhs:
            rhs[a[i]] = 0
        rhs[a[i]] += 1
    lhs = sorted(lhs.items(), key = itemgetter(1), reverse = True)
    rhs = sorted(rhs.items(), key = itemgetter(1), reverse = True)
    if lhs[0][0] != rhs[0][0]:
        return n - lhs[0][1] - rhs[0][1]
    else:
        return min(n - lhs[0][1] - rhs[1][1], n - lhs[1][1] - rhs[0][1])

def main():
    n = int(raw_input().strip())
    a = [int(i) for i in raw_input().strip().split()]
    print solution(a)

if __name__ == '__main__':
    main()

Solution (Python):
import collections
N = int(input())
Data = list(map(int, input().split()))
X = []
Y = []
for i in range(int(N/2)):
  X.append(Data[i*2])
  Y.append(Data[i*2+1])
Xc = collections.Counter(X)
Yc = collections.Counter(Y)
Xa = Xc.most_common()
Ya = Yc.most_common()
if Xa[0][0] != Ya[0][0]:
  print(N-(Xa[0][1] + Ya[0][1]))
  exit()
if len(Xc) != 1:
  Xb = Xa[1][1]
else:
  Xb = 0
if len(Yc) != 1:
  Yb = Ya[1][1]
else:
  Yb = 0
print(N - max(Xa[0][1] + Yb, Xb + Ya[0][1]))

Solution (Python):
from collections import *

N = input()
v_list = input().split()

if len(set(v_list)) == 1:
    print(len(v_list) // 2)
    exit()

v1_count_list = Counter(v_list[::2]).most_common(2)
v2_count_list = Counter(v_list[1::2]).most_common(2)

if v1_count_list[0][0] != v2_count_list[0][0]:
    leave_value = v1_count_list[0][1] + v2_count_list[0][1]
else:
    leave_value = max(v1_count_list[1][1] + v2_count_list[0][1], v1_count_list[0][1] + v2_count_list[1][1])
print(len(v_list) - leave_value)

Solution (Python):
from collections import *

N = int(input())
v_list = input().split()

if len(set(v_list)) == 1:
    print(len(v_list) // 2)
    exit()

v1_count_list = Counter(v_list[::2]).most_common()
v2_count_list = Counter(v_list[1::2]).most_common()

if v1_count_list[0][0] != v2_count_list[0][0]:
    leave_value = v1_count_list[0][1] + v2_count_list[0][1]
else:
    leave_value = max(v1_count_list[1][1] + v2_count_list[0][1], v1_count_list[0][1] + v2_count_list[1][1])
print(len(v_list) - leave_value)

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

dict_even = {}
for v in v_list[::2]:
    if v not in dict_even:
        dict_even[v] = 1
    else:
        dict_even[v] += 1

dict_odd = {}
for v in v_list[1::2]:
    if v not in dict_odd:
        dict_odd[v] = 1
    else:
        dict_odd[v] += 1

even1 = sorted(dict_even.items(), reverse=True, key=lambda x: x[1])[0]
odd1 = sorted(dict_odd.items(), reverse=True, key=lambda x: x[1])[0]
if even1[0] != odd1[0]:
    print(n - even1[1] - odd1[1])
else:
    if len(dict_even.items()) == len(dict_odd.items()) == 1:
        print(n // 2)
    elif len(dict_even.items()) == 1:
        odd2 = sorted(dict_odd.items(), reverse=True, key=lambda x: x[1])[1]
        print(n // 2 - odd2[1])
    elif len(dict_odd.items()) == 1:
        even2 = sorted(dict_even.items(), reverse=True, key=lambda x: x[1])[1]
        print(n // 2 - even2[1])
    else:
        even2 = sorted(dict_even.items(), reverse=True, key=lambda x: x[1])[1]
        odd2 = sorted(dict_odd.items(), reverse=True, key=lambda x: x[1])[1]
        print(min(n - even1[1] - odd2[1], n - even2[1] - odd1[1]))

Solution (Python):
from collections import *

N = int(input())
v_list = input().split()

if len(set(v_list)) == 1:
    print(len(v_list) // 2)
    exit()

v1_list = v_list[::2]
v2_list = v_list[1::2]

v1_count_list = Counter(v1_list).most_common()
v2_count_list = Counter(v2_list).most_common()

if v1_count_list[0][0] != v2_count_list[0][0]:
    print(len(v_list) - v1_count_list[0][1] - v2_count_list[0][1])
else:
    countor1 = len(v_list) - v1_count_list[1][1] - v2_count_list[0][1]
    countor2 = len(v_list) - v1_count_list[0][1] - v2_count_list[1][1]
    print(min(countor1, countor2))

Solution (Python):
from collections import Counter as C
n = int(input())
v = list(map(int,input().split()))
v1,v2 = v[0::2], v[1::2]
a1 = C(v1).most_common()
a2 = C(v2).most_common()

if a1[0][0]!=a2[0][0]:
    print(n-a1[0][1]-a2[0][1])
    exit()

res = n//2
if len(a2)!=1:
    res = a1[0][1] + a2[1][1]
if len(a1)!=1:
    res = max(res, a1[1][1] + a2[0][1])
print(n-res)

Solution (Python):



from collections import defaultdict

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

a,b = defaultdict(lambda: 0), defaultdict(lambda: 0)
for i, val in enumerate(v):
	if i%2 == 1:
		a[val] += 1
	else:
		b[val] += 1
a[-1] = 0
b[-2] = 0
aa = sorted([(y,x) for x, y in a.iteritems()], reverse=True)
bb = sorted([(y,x) for x, y in b.iteritems()], reverse=True)

if aa[0][1] != bb[0][1]:
	print n - (aa[0][0] + bb[0][0])
else:
	print n - max((aa[0][0] + bb[1][0]), (aa[1][0] + bb[0][0]))

Solution (Python):
import collections

N = int(input())
list = list(map(int,input().strip().split()))
list_c = collections.Counter(list)
odd_list = []
even_list = []

if N == list_c.most_common()[0][1]:
    ans = N//2

else:
    for i in range(N//2):
        odd_list.append(list[2*i-2])
        even_list.append(list[2*i-1])

    odd_list_c = collections.Counter(odd_list)
    even_list_c = collections.Counter(even_list)

    if odd_list_c.most_common()[0][0] == even_list_c.most_common()[0][0]:
        num = odd_list_c.most_common()[0][1] + even_list_c.most_common()[1][1]
        cnt = odd_list_c.most_common()[1][1] + even_list_c.most_common()[0][1]
        cnt = max(num,cnt)
        ans = N - cnt
    else:
        cnt_odd = odd_list_c.most_common()[0][1]
        cnt_even = even_list_c.most_common()[0][1]
        cnt = cnt_odd + cnt_even
        ans = N - cnt

print(ans)

Solution (Python):
import collections

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


V_e = V[1::2]
V_o = V[::2]

dic_e = collections.Counter(V_e)
dic_o = collections.Counter(V_o)

e_items = (sorted(dic_e.items(), key=lambda x: -x[1]))[:2]
o_items = (sorted(dic_o.items(), key=lambda x: -x[1]))[:2]





tar_key_o = o_items[0][0]

if e_items[0][0] != tar_key_o:
    ans_o = (n//2 - e_items[0][1]) + (n//2 - o_items[0][1])

elif len(e_items) > 1 and e_items[1][0] != tar_key_o:
    ans_o = (n//2 - e_items[0][1]) + (n//2 - o_items[1][1])
else:
    ans_o = (n//2 - e_items[0][1]) + (n//2)



tar_key_e = e_items[0][0]

if o_items[0][0] != tar_key_e:
    ans_e = (n//2 - o_items[0][1]) + (n//2 - e_items[0][1])

elif len(o_items) > 1 and o_items[1][0] != tar_key_e:
    ans_e = (n//2 - o_items[0][1]) + (n//2 - e_items[1][1])
else:
    ans_e = (n//2 - o_items[0][1]) + (n//2)



ans = min(ans_e,ans_o)

print(ans)

Solution (Python):
import copy
n = int(input())
v = input().split()

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j])
        countx = 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k])
        county = 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county = 1
s2 = copy.deepcopy(s)
t2 = copy.deepcopy(t)

s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

ssym = 0
for i in s2:
    if sc == -1:
        sk = i
    elif sc == 0:
        sk = i
        ssym = 1
        break
    sc += 1
if sc == 0 and ssym == 0:
    sk = 0

tsym = 0
for i in t2:
    if tc == -1:
        tk = i
    elif tc == 0:
        tk = i
        tsym = 1
        break
    tc += 1
if tc == 0 and tsym == 0:
    tk = 0

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Solution (Python):
import collections
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_c=collections.Counter(a).most_common()
b_c=collections.Counter(b).most_common()
if a_c[0][0]==b_c[0][0]:
    if a_c[0][1]==b_c[0][1]:
        if a_c[0][1]==n/2:
            print(n//2)
        else:
            print(n-a_c[0][1]-max(a_c[1][1],b_c[1][1]))
    elif a_c[0][1]>b_c[0][1]:
        if len(b_c)>1:
            print(n-a_c[0][1]-b_c[1][1])
        else:
            print(n-a_c[0][1])
    else:
        if len(a_c)>1:
            print(n-a_c[1][1]-b_c[0][1])
        else:
            print(n-b_c[0][1])
else:
    print(n-a_c[0][1]-b_c[0][1])

Solution (Python):
import collections

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

ans = 0
gu = v[::2]
ki = v[1::2]

gudic = collections.Counter(gu)
kidic = collections.Counter(ki)

gumax = gudic.most_common()
kimax = kidic.most_common()



if gumax[0][0] != kimax[0][0]:
    print(n - gumax[0][1] - kimax[0][1])
else:
    if len(gumax) == 1 and len(kimax) == 1:
        print(n // 2)
    elif len(gumax) == 1 and len(kimax) >= 2:
        print(n - gumax[0][1] - kimax[1][1])
    
    elif len(gumax) >= 2 and len(kimax) == 1:
        print(n - gumax[1][1] - kimax[0][1])
    else: 
        one = n - gumax[0][1] - kimax[1][1]
        ano = n - gumax[1][1] - kimax[0][1]
        print(min(one, ano))

Solution (Python):
import numpy as np
N = int(input())
a = np.array(list(map(int,input().split())),dtype=np.int)

nA = np.bincount(a[::2])
nB = np.bincount(a[1::2])
orderA = np.argsort(nA)
orderB = np.argsort(nB)

kA1 = orderA[-1]
kA2 = orderA[-2]
kB1 = orderB[-1]
kB2 = orderB[-2]
if kA1 == kB1:
    if nA[kA1] + nB[kB2] >= nA[kA2] + nB[kB1]:
        kA=kA1; kB=kB2
    else:
        kA=kA2; kB=kB1
else:
    kA=kA1; kB=kB1

print(N-nA[kA]-nB[kB])

Solution (Python):
n = int(input())
lis = list(map(int, input().split()))
odd = lis[::2]

odd_dic = {'a':(n+1)//2}
for i in odd:
    odd_dic[i] = odd_dic.get(i,(n+1)//2) - 1

even_dic = {'a':n//2}    
even = lis[1::2]
for i in even:
    even_dic[i] = even_dic.get(i,n//2) - 1

odd_count = sorted(list(odd_dic.keys()), key =lambda x: odd_dic[x])
even_count = sorted(list(even_dic.keys()), key =lambda x: even_dic[x])
if odd_count[0] == even_count[0]:
    if odd_dic.get(odd_count[1]) <= even_dic.get(even_count[1]):
        ko = odd_count[1]
        ke = even_count[0]
    else:
        ko = odd_count[0]
        ke = even_count[1]
else:
    ko = odd_count[0]
    ke = even_count[0]
print(odd_dic[ko] + even_dic[ke])

Solution (Python):
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])

if c11[0] != c21[0]:
    print(n - c11[1] - c21[1])
else:
    print(n - max(c11[1]+c22[1], c12[1]+c21[1]))

Solution (Python):
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])

if c11[0] != c21[0]:
    print(n - c11[1] - c21[1])
else:
    print(n - max(c11[1]+c22[1], c12[1]+c21[1]))
print()

Solution (Python):
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])

if c11[0] != c21[0]:
    print(n - c11[1] - c21[1])
else:
    print(n - max(c11[1]+c22[1], c12[1]+c21[1]))

Solution (Python):
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])

if c11[0] != c21[0]:
    print(n - c11[1] - c21[1])
else:
    print(n - max(c11[1]+c22[1], c12[1]+c21[1]))

Solution (Python):
from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])

if c11[0] != c21[0]:
    print(n - c11[1] - c21[1])
else:
    print(n - max(c11[1]+c22[1], c12[1]+c21[1]))

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

    d1, d2 = defaultdict(int), defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            d1[V[i]] += 1
        else:
            d2[V[i]] += 1

    if len(set(V)) == 1:
        print(n // 2)
        return

    num = n // 2
    ans = INF
    for k1, v1 in sorted(d1.items(), key=lambda x:x[1], reverse=True)[:2]:
        for k2, v2 in sorted(d2.items(), key=lambda x:x[1], reverse=True)[:2]:
            if k1 != k2:
                t = (num - v1) + (num - v2)
                ans = min(ans, t)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
n = int(input())
v = list(map(int,input().split()))
odd,eve = defaultdict(int),defaultdict(int)
for i in range(n):
    if i%2==0:
        eve[v[i]] += 1
    else:
        odd[v[i]] += 1
se = sorted(eve.items(),key=lambda x:x[1],reverse=True)
so = sorted(odd.items(),key=lambda x:x[1],reverse=True)
ans = 0
if se[0][0]==so[0][0]:
    if se[0][1]==so[0][1]:
        if len(se)==1 and len(so)==1:
            ans += n//2
        else:
            if se[1][1]<so[1][1]:
                ans = n-se[0][1]-so[1][1]
            else:
                ans = n-se[1][1]-so[0][1]
    elif se[0][1]<so[0][1]:
        ans = n-so[0][1]-se[1][1]
    else:
        ans = n-so[1][1]-se[0][1]
else:
    ans = n-se[0][1]-so[0][1]
print(ans)

Solution (Python):
import collections

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

e=[None]*(n//2)
o=[None]*(n//2)
for i in range(n//2):
    e[i]=l[2*i]
    o[i]=l[2*i+1]

ce=collections.Counter(e)
co=collections.Counter(o)
ce=ce.most_common()
co=co.most_common()

ce.append((0,0))
co.append((0,0))
if ce[0][0]!=co[0][0]:
    print(n-co[0][1]-ce[0][1])
else:
    print(min(n-ce[1][1]-co[0][1],n-ce[0][1]-co[1][1]))

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
d = {(0, 0): 0, (1, 0): 0}
for i in range(n):
  d[i % 2, v[i]] = d.get((i % 2, v[i]), 0) + 1
to_sort = [[], []]
for i in d:
  to_sort[i[0]].append((d[i], i[1]))
to_sort[0].sort()
to_sort[1].sort()
if to_sort[0][-1][1] != to_sort[1][-1][1]:
  ans = n - to_sort[0][-1][0] - to_sort[1][-1][0]
else:
  ans = n - max(to_sort[0][-1][0] + to_sort[1][-2][0], to_sort[0][-2][0] + to_sort[1][-1][0])
print(ans)