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

even = {}
odd = {}

for i in range(N):
    if i % 2 == 0:
        even[vN[i]] = even.get(vN[i], 0) + 1
    else:
        odd[vN[i]] = odd.get(vN[i], 0) + 1


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


if even_sorted[0][0] == odd_sorted[0][0]:
    
    if len(even_sorted) == 1:
        even_sorted.append((0, 0))
    if len(odd_sorted) == 1:
        odd_sorted.append((0, 0))
    
    print(N - max(even_sorted[1][1] + odd_sorted[0][1], even_sorted[0][1] + odd_sorted[1][1]))
else:
    print(N - even_sorted[0][1] - odd_sorted[0][1])

Solution (Python):


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

even = {}
odd = {}

for i in range(N):
    if i % 2 == 0:
        even[vN[i]] = even.get(vN[i], 0) + 1
    else:
        odd[vN[i]] = odd.get(vN[i], 0) + 1


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


if even_sorted[0][0] == odd_sorted[0][0]:
    
    if len(even_sorted) == 1 and len(odd_sorted) > 1:
        print(N - even_sorted[0][1] - odd_sorted[1][1])
    elif len(even_sorted) > 1 and len(odd_sorted) == 1:
        print(N - even_sorted[1][1] - odd_sorted[0][1])  
    elif len(even_sorted) == 1 and len(odd_sorted) == 1:
        print(N // 2)
    else:
        
        print(N - max(even_sorted[1][1] + odd_sorted[0][1], even_sorted[0][1] + odd_sorted[1][1]))
else:
    print(N - even_sorted[0][1] - odd_sorted[0][1])

Solution (Python):
def solve(n, a):
    D = [{0: 0}, {0:0}]
    for i in range(n):
        if not a[i] in D[i%2]:
            D[i%2][a[i]] = 0
        D[i%2][a[i]] += 1
    e = sorted(D[0].items(), key=lambda _:-_[1])
    o = sorted(D[1].items(), key=lambda _:-_[1])
    k_e0, v_e0 = e[0]
    k_o0, v_o0 = o[0]
    if k_e0 != k_o0:
        return n - v_e0 - v_o0
    else:
        _, v_e1 = e[1]
        _, v_o1 = o[1]
        return min(n - v_e0 - v_o1, n - v_e1 - v_o0)

assert solve(4, [3,1,3,2]) == 1
assert solve(6, [105,119,105,119,105,119]) == 0
assert solve(4, [1,1,1,1]) == 2
n = input()
a = map(int, raw_input().split())
print solve(n, a)

Solution (Python):
from collections import Counter

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

odd = [a[i] for i in range(0,len(a),2)]
even = [a[i] for i in range(1,len(a),2)]

a_odd_most = Counter(odd).most_common()[:2]
a_even_most = Counter(even).most_common()[:2]

if a_odd_most[0][0] != a_even_most[0][0]:
    print(len(a) - a_odd_most[0][1] - a_even_most[0][1])
else:
    if len(a_odd_most) == 1 or len(a_even_most) == 1:
        a_odd_most.append((0,0))
        a_even_most.append((0,0))

    print(len(a) - max(a_odd_most[0][1]+a_even_most[1][1], 
                  a_odd_most[1][1]+a_even_most[0][1]))

Solution (Python):


import sys
from collections import Counter


input = sys.stdin.readline


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


def solve(N, V):
    v_even = [V[i] for i in range(0, N, 2)]
    v_odd = [V[i] for i in range(1, N, 2)]

    
    v_even_most = Counter(v_even).most_common()[:2]
    v_odd_most = Counter(v_odd).most_common()[:2]

    
    if v_even_most[0][0] != v_odd_most[0][0]:
        return N - v_even_most[0][1] - v_odd_most[0][1]
    else:
        
        
        if len(v_even_most) == 1 or len(v_odd_most) == 1:
            v_even_most.append((0, 0))
            v_odd_most.append((0, 0))

        
        return N - max(v_even_most[0][1] + v_odd_most[1][1],
                       v_even_most[1][1] + v_odd_most[0][1])


N = int(input())
V = inpl()
print(solve(N, V))

Solution (Python):
n = int(input())
a = input().split()
dic1 = {}
firitem1 = "0"
firnum1 = 0
secitem1 = "0"
secnum1 = 0
dic2 = {}
firitem2 = "0"
firnum2 = 0
secitem2 = "0"
secnum2 = 0

for i in range(len(a)):
  if i%2 == 0:
    if a[i] in dic1:
      dic1[a[i]] += 1
    else:
      dic1[a[i]] = 1
    
    if dic1[a[i]] > firnum1:
      if firitem1 == a[i]:
        firnum1 = dic1[a[i]]
      else:
        secitem1 = firitem1
        secnum1 = firnum1
        firitem1 = a[i]
        firnum1 = dic1[a[i]]
        
    elif dic1[a[i]] > secnum1:
      secitem1 = a[i]
      secnum1 = dic1[a[i]]
  else:
    if a[i] in dic2:
      dic2[a[i]] += 1
    else:
      dic2[a[i]] = 1
    
    if dic2[a[i]] > firnum2:
      if firitem2 == a[i]:
        firnum2 = dic2[a[i]]
      else:
        secitem2 = firitem2
        secnum2 = firnum2
        firitem2 = a[i]
        firnum2 = dic2[a[i]]
    elif dic2[a[i]] > secnum2:
      secitem2 = a[i]
      secnum2 = dic2[a[i]]

if firitem1 != firitem2:
  print(int(n/2-firnum1 + n/2-firnum2))
else:

  print(int(min(n/2-firnum1 + n/2-secnum2, n/2-secnum1 + n/2-firnum2)))

Solution (Python):
from collections import Counter

n = int(input())
v = [int(c) for c in input().split()]
vo = v[::2]
ve = v[1::2]
co = Counter(vo).most_common()
ce = Counter(ve).most_common()
co.append((-1, 0))
ce.append((-2, 0))
if co[0][0] != ce[0][0]:
	print(n - co[0][1] - ce[0][1])
else:
	res1 = n - co[0][1] - ce[1][1]
	res2 = n - co[1][1] - ce[0][1]
	print(min(res1, res2))

Solution (Python):


def count_nums(v):
    counter = {}
    for x in v:
        if x not in counter:
            counter[x] = 0
        counter[x] += 1
    retval = counter.items()
    retval.sort(lambda a,b:b[1] - a[1])
    
    
    
    
    return retval

def main():
    n = int(raw_input().strip())
    v = raw_input().strip().split(" ")
    v1 = [int(v[x]) for x in xrange(0, n, 2)]
    v2 = [int(v[x]) for x in xrange(1, n, 2)]

    cv1 = count_nums(v1)
    cv2 = count_nums(v2)

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

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
v = [int(x) for x in input().split()]

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




d1, d2 = dict(), dict()


for num in v1:
    d1[num] = d1.get(num, 0) + 1

for num in v2:
    d2[num] = d2.get(num, 0) + 1




v1tmp1 = [(key, val) for key, val in d1.items()]
V1 = sorted(v1tmp1, key=lambda x: x[1], reverse=True)

v2tmp1 = [(key, val) for key, val in d2.items()]
V2 = sorted(v2tmp1, key=lambda x: x[1], reverse=True)



ret = 0

if (V1[0][0] != V2[0][0]):
    ret = n - V1[0][1] - V2[0][1]
else:
    t1 = n - V1[0][1] - (V2[1][1] if len(V2) >= 2 else 0)
    t2 = n - (V1[1][1] if len(V1) > 2 else 0) - V2[0][1]
    ret = min(t1, t2)

print(ret)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
vodd=[v[i] for i in range(n) if i%2==1]
veven=[v[i] for i in range(n) if i%2==0]
vodd.sort()
veven.sort()
def matome(l):
    result=[]
    a=l[0]
    b=0
    for i in range(len(l)):
        if l[i]==a:
            b+=1
        else:
            result.append([a,b])
            b=1
            a=l[i]
    result.append([a,b])
    return result
odd=matome(vodd)
odd.sort(key=lambda x:-x[1])
even=matome(veven)
even.sort(key=lambda x:-x[1])

if len(odd)==1 and len(even)==1:
    if odd[0][0]==even[0][0]:
        print(n//2)
    else:
        print(0)
elif len(odd)==1:
    if odd[0][0]==even[0][0]:
        print(n-odd[0][1]-even[1][1])
    else:
        print(n-odd[0][1]-even[0][1])
elif len(even)==1:
    if odd[0][0]==even[0][0]:
        print(n-odd[1][1]-even[0][1])
    else:
        print(n-odd[0][1]-even[0][1])
else:


    if odd[0][0]==even[0][0]:
        if odd[1][1]>even[1][1]:
            print(n-odd[1][1]-even[0][1])
        else:
            print(n-odd[0][1]-even[1][1])

    else:
        print(n-odd[0][1]-even[0][1])

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
d1 = {}
d2 = {}

for i in range(0, n, 2):
    if v[i] in d1.keys():
        d1[v[i]] += 1
    else:
        d1[v[i]] = 1
for i in range(1, n, 2):
    if v[i] in d2.keys():
        d2[v[i]] += 1
    else:
        d2[v[i]] = 1


def keys_values(d):
    fk, fv, sk, sv = 0, 0, 0, 0
    for k in d:
        if d[k] > fv:
            sk, sv = fk, fv
            fk, fv = k, d[k]
        elif d[k] > sv:
            sk, sv = k, d[k]
    return fk, fv, sk, sv


ak, av, bk, bv = keys_values(d1)
ck, cv, dk, dv = keys_values(d2)
if ak != ck:
    print(n-av-cv)
else:
    print(min((n-av-dv), n-bv-cv))

Solution (Python):
n=int(input())
vlis=[int(i) for i in input().split()]
odd=vlis[0::2]
even=vlis[1::2]
import collections 
odd_=collections.Counter(odd).most_common(2)
even_=collections.Counter(even).most_common(2)

if odd_[0][0]==even_[0][0]:
    if len(odd_)==1 and len(even_)==1:
        print(int(len(vlis)/2))
    elif len(even_)==1:
        print(len(vlis)-even_[0][1]-odd_[1][1])
    elif len(odd_)==1:
        print(len(vlis)-odd_[0][1]-even_[1][1])
    else:
        if odd_[0][1]+even_[1][1]>=odd_[1][1]+even_[0][1]:
            print(len(vlis)-odd_[0][1]-even_[1][1])
        else:
            print(len(vlis)-odd_[1][1]-even_[0][1])
else:
    print(len(vlis)-odd_[0][1]-even_[0][1])

Solution (Python):
import collections
n=int(input())
m=n//2
v1=list(map(int,input().split()))
v2=[]
for j in range(m):
    v2.append(v1.pop(j))
a1=sorted((collections.Counter(v1)).items(),key=lambda x:x[1],reverse=True)
a2=sorted((collections.Counter(v2)).items(),key=lambda x:x[1],reverse=True)
if a1[0][1]<a2[0][1]:a1,a2=a2[:],a1[:]
if a1[0][0]!=a2[0][0]:
    print(n-a1[0][1]-a2[0][1])
elif len(a2)==1:
    print(m)
elif a1[1][1]<a2[1][1]:
    print(n-a1[0][1]-a2[1][1])
else:
    print(n-a1[0][1]-a1[1][1])

Solution (Python):



def count_rewrite_times(n, v, even, odd):
    ans = 0

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

    return ans


def main():
    from collections import Counter

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

    if len(set(v)) == 1:
        print(n // 2)
        exit()
    else:
        even = Counter(v[::2]).most_common(1)[0][0]
        odd = Counter(v[1::2]).most_common(1)[0][0]

        if even == odd:
            even2 = Counter(v[::2]).most_common(2)[1][0]
            odd2 = Counter(v[1::2]).most_common(2)[1][0]

            print(min(count_rewrite_times(n, v, even, odd2),
                      count_rewrite_times(n, v, even2, odd)))
            exit()

        print(count_rewrite_times(n, v, even, odd))


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    from collections import Counter

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

    if len(set(v)) == 1:
        print(n // 2)
        exit()
    else:
        even = Counter(v[::2]).most_common(1)[0][0]
        odd = Counter(v[1::2]).most_common(1)[0][0]
        ans1 = 0

        if even == odd:
            even2 = Counter(v[::2]).most_common(2)[1][0]
            odd2 = Counter(v[1::2]).most_common(2)[1][0]
            ans2 = 0
            ans3 = 0

            for x in range(n):
                if x % 2 == 0:
                    if v[x] != even:
                        ans2 += 1
                else:
                    if v[x] != odd2:
                        ans2 += 1

            for y in range(n):
                if y % 2 == 0:
                    if v[y] != even2:
                        ans3 += 1
                else:
                    if v[y] != odd:
                        ans3 += 1

            print(min(ans2, ans3))
            exit()

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

        print(ans1)


if __name__ == '__main__':
    main()

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

n = int(input())
v = list(map(int,input().split()))
e, o =[], []
for i in range(n//2):
    e.append(v[2*i])
    o.append(v[2*i+1])
e.sort()
o.sort()
e.append(-1)
o.append(-1)


e1, e2, o1, o2 = 0,0,0,0
E1, O1 = e[0], o[0]
c = 1
for i in range(0,n//2):
    if e[i]==e[i+1]:
        c+= 1
        continue
    if c>e1:
        e2 = e1
        e1 = c
        E1 = e[i]
    elif c>e2:
        e2 = c
    c = 1

c=1
for i in range(0,n//2):
    if o[i]==o[i+1]:
        c+= 1
        continue
    if c>o1:
        o2 = o1
        o1 = c
        O1 = o[i]
    elif c>o2:
        o2 = c
    c = 1
    


if E1==O1:
    print(min(n-e1-o2,n-e2-o1))
else:
    print(n-e1-o1)

Solution (Python):

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




dict0 = {}
dict1 = {}

for i in range(0, n, 2):
    v = V[i]
    if v in dict0:
        dict0[v] += 1
    else:
        dict0[v] = 1

for i in range(1, n, 2):
    v = V[i]
    if v in dict1:
        dict1[v] += 1
    else:
        dict1[v] = 1


d0 = sorted(dict0.items(), key=lambda x: x[1], reverse=True)
d1 = sorted(dict1.items(), key=lambda x: x[1], reverse=True)





n = int(n/2)
if (d0[0][0] != d1[0][0]):
    ret = (n - d0[0][1]) + (n - d1[0][1])
else:
    d1_1_1 = 0
    if len(d1) > 1:
        d1_1_1 = d1[1][1]
    r1 = (n - d0[0][1]) + (n - d1_1_1)

    d0_1_1 = 0
    if len(d0) > 1:
        d0_1_1 = d0[1][1]
    r2 = (n - d0_1_1) + (n - d1[0][1])
    ret = min(r1, r2)

print(ret)

Solution (Python):
from collections import Counter

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

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

x = Counter(v[::2]).most_common()
y = Counter(v[1::2]).most_common()

if x[0][0] == y[0][0]:
    if len(x) == 1:
        d = x[0][1] + y[1][1] 
    elif len(y) == 1:
        d = x[1][1] + y[0][1]
    else:
        d = max(x[0][1] + y[1][1], x[1][1] + y[0][1]) 
else:
    d = x[0][1] + y[0][1]

print(n - d)

Solution (Python):
import collections

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

c1 = collections.Counter(v[0::2]).most_common()
c2 = collections.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])
elif(c1[1][1]>c2[1][1]):
    print(n-c1[1][1]-c2[0][1])
else:
    print(n-c1[0][1]-c2[1][1])

Solution (Python):
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]:
    print(n - (a[0][1] + b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]), n-(a[0][1]+b[1][1])))

Solution (Python):
from collections import Counter

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

even = []
odd = []
for i in range(0, n, 2):
    even.append(v[i + 1])
    odd.append(v[i])

even = Counter(even).most_common(2)
odd = Counter(odd).most_common(2)

if even[0][0] != odd[0][0]:
    ans = n - even[0][1] - odd[0][1]
else:
    if len(even) == 1 and len(odd) == 1:
        ans = even[0][1]
    else:
        ans = min(n - even[1][1] - odd[0][1], n - even[0][1] - odd[1][1])

print(int(ans))

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i,ev in enumerate(v):
    if i%2 == 0:
        v0.append(ev)
    else:
        v1.append(ev)

mcv0 = Counter(v0).most_common(2)
mcv1 = Counter(v1).most_common(2)
cmcv0 = mcv0[0][1]
cmcv1 = mcv1[0][1]
ans = n - cmcv0 - cmcv1
if mcv0[0][0] == mcv1[0][0]:
    if (len(mcv0) == 1) and (len(mcv1) == 1):
        ans = int(n/2)
    else:
        ans = min(n - mcv0[1][1] - cmcv1, n - cmcv1 - mcv1[1][1])
print(ans)

Solution (Python):
n = int(input())
list = list(map(int, input().split()))
list_odd = list[::2]
list_even = list[1::2]


def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v, k) for k, v in dict.items()]


cnt_odd = sorted(cnt_element(list_odd), reverse=True)
cnt_even = sorted(cnt_element(list_even), reverse=True)

if cnt_odd[0][1] == cnt_even[0][1]:
    if len(cnt_odd) == 1 or len(cnt_even) == 1:
        ans = int(n / 2)
    else:
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        else:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]
else:
    ans = n - cnt_odd[0][0] - cnt_even[0][0]

print(ans)

Solution (Python):
n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)


if cnt_odd[0][1] == cnt_even[0][1]:
    
    if len(cnt_odd) ==1 or len(cnt_even) == 1:
        ans =  int(n / 2)
    
    else:
        
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        
        elif cnt_odd[1][0] <= cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]

else:
    ans = n - cnt_odd[0][0] - cnt_even[0][0]

print(ans)

Solution (Python):
from collections import Counter

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

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

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

if ki[0][0] == gu[0][0] :
    if len(ki) == 1 and len(gu) == 1 :
        print(int(n/2))
    else :
        if ki[1][1] > gu[1][1] :
            print(n-ki[1][1]-gu[0][1])
        else :
            print(n-ki[0][1]- gu[1][1])

else :
    print(n-ki[0][1]-gu[0][1])

Solution (Python):
from collections import Counter

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

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

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0


if ki[0][0] == gu[0][0]:
    
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

Solution (Python):
import collections
n = int(raw_input())
A = map(int, raw_input().split(" "))

c1 = collections.Counter(A[::2]).most_common(2)
c2 = collections.Counter(A[1::2]).most_common(2)

res = n
for i, x in c1:
    for j, y in c2:
        if i != j:
            res = min(res, n - x - y)
        res = min(res, n - y)
        res = min(res, n - x)
print res

Solution (Python):

from collections import Counter

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

even = [] 
odd = [] 


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

 
even_most = Counter(even).most_common()
odd_most = Counter(odd).most_common()


if even_most[0][0] == odd_most[0][0]:
    if len(even_most) == 1:
        if len(odd_most) == 1:
            ans = n / 2
        else:
            ans = n - even_most[0][1] - odd_most[1][1]
    elif len(odd_most) == 1:
            ans = n - even_most[1][1] - odd_most[0][1]
    else:
        ans = n - max(even_most[0][1] + odd_most[1][1], even_most[1][1] + odd_most[0][1])


else:
    ans = n - even_most[0][1] - odd_most[0][1]

print(int(ans))

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
for_set_v = v 
set_v = set(v)
even = []
odd = []
count = 0 
count_list = []
for num in range(n):
    if num % 2 == 0:
        even.append(v[num])
    else:
        odd.append(v[num])

even_most = Counter(even).most_common()
odd_most = Counter(odd).most_common()


if len(set(v)) >= 2:
    if even_most[0][0] != odd_most[0][0]:
        if len(set(even)) != 1:
            count += (n/2) - int(even_most[0][1])
        if len(set(odd)) != 1:
            count += (n/2) - int(odd_most[0][1])
    else:
        try:
            count_list.append(n-int(even_most[0][1])-int(odd_most[1][1]))
            count_list.append(n-int(even_most[1][1])-int(odd_most[0][1]))
            
            count += int(min(count_list))
        except:
            if len(even_most) == 1:
                count += (n/2)-int(odd_most[1][1])
            elif len(odd_most) == 1:
                count += (n/2)-int(even_most[1][1])
else:
    count += (n/2)
print(int(count))

Solution (Python):
def getmaxs(l):
    max1 = max2 = poz1 = poz2 = 0
    for i in range(0, len(l)):
        if l[i] > max1:
            max2 = max1
            poz2 = poz1
            max1 = l[i]
            poz1 = i
        elif l[i] > max2:
            max2 = l[i]
            poz2 = i
    return max1, max2, poz1, poz2


f1 = [0 for x in range(0, 10 ** 5 + 1)]
f2 = [0 for x in range(0, 10 ** 5 + 1)]

n = int(input())
l = list(map(int, input().split()))
for i in range(0, n):
    x = l[i]
    if i % 2 == 0:
        f1[x] = f1[x] + 1
    else:
        f2[x] = f2[x] + 1

m1, m2, p1, p2 = getmaxs(f1)
n1, n2, q1, q2 = getmaxs(f2)
if p1 != q1:
    print(n-n1-m1)
else:
    print(min(n-n1-m2, n-n2-m1))

Solution (Python):
from collections import Counter
n = int(input())
arr = [i for i in input().split()]
c = [Counter([i for (a,i) in enumerate(arr) if a%2==j]) for j in range(2)]
if c[0].most_common()[0][0]!=c[1].most_common()[0][0] :
    print(n-c[0].most_common()[0][1]-c[1].most_common()[0][1])
else :
    if(len(c[0].most_common())==1):
        co0 = 0
    else:
        co0 = c[0].most_common()[1][1]
    if(len(c[0].most_common())==1):
        co1 = 0;
    else :
        co1 = c[1].most_common()[1][1]
    print(min(n-c[0].most_common()[0][1]-co1,n-co0-c[1].most_common()[0][1]))

Solution (Python):
from collections import Counter

N = int(input())

arr = list(map(int, input().split(' ')))

odd = arr[0::2]
even = arr[1::2]

odd_counter = Counter(odd)
even_counter = Counter(even)

odd_mode = odd_counter.most_common()[0][0]
even_mode = even_counter.most_common()[0][0]

odd_diff = (N / 2) - odd_counter.most_common()[0][1]
even_diff = (N / 2) - even_counter.most_common()[0][1]

if odd_mode != even_mode:
	print(int(odd_diff + even_diff))
elif odd_diff == 0:
	print(int(N / 2))
else:
	odd_diff2 = (N / 2) - odd_counter.most_common()[1][1]
	even_diff2 = (N / 2) - even_counter.most_common()[1][1]
	if odd_diff2 > even_diff2:
		print(int(odd_diff + even_diff2))
	else:
		print(int(odd_diff2 + even_diff))

Solution (Python):
from collections import Counter
n = int(input())
k = n//2
a = list(map(int, input().split()))
p = []
q = []
for i in range(k):
    p.append(a[2*i])
    q.append(a[2*i+1])
s = Counter(p).most_common()
t = Counter(q).most_common()
u, v = len(s), len(t)
ans = 0
if s[0][0] == t[0][0]:
    if u == 1 and v == 1:
        ans = k
    elif u == 1:
        ans = k - t[1][1]
    elif v == 1:
        ans = k - s[1][1]
    else:
        comp = max(s[1][1], t[1][1])
        ans = n - s[0][1] - comp
else:
    ans = n - s[0][1] - t[0][1]
print(ans)

Solution (Python):
_ = input()
N = list(map(int, input().split()))
Tong1 = [0 for i in range(int(1e5 + 7))]
Tong2 = [0 for i in range(int(1e5 + 7))]
for i in range(0, len(N), 2):
    Tong1[N[i]] += 1
for i in range(1, len(N), 2):
    Tong2[N[i]] += 1

Num_pos1 = Tong1.index(max(Tong1))
Num_pos2 = Tong2.index(max(Tong2))
if(Num_pos1 == Num_pos2):
    print(len(N) - max(Tong1) - max(sorted(Tong1, reverse=True)[1], sorted(Tong2, reverse=True)[1]))
else:
    print(len(N) - max(Tong1) - max(Tong2))

Solution (Python):
import collections
 
def answer(list,n):
    Even = collections.Counter(list[::2]).most_common(2)
    Odd = collections.Counter(list[1::2]).most_common(2)
 
    if Even[0][0] != Odd[0][0]:
        return n - Even[0][1] - Odd[0][1]
    else:
        if len(Even) == 1 or len(Odd) == 1:
            return n // 2
        else:
            return n - max(Even[0][1]+Odd[1][1],Even[1][1]+Odd[0][1])
 
N = int(input())
list = input().split(" ")
print(answer(list,N))

Solution (Python):
n = input()
l = input().split()
w0,w1 = dict(),dict()
flag = 0
for i in l:
  if flag % 2 == 0:
    if i not in w0.keys():w0[i] = 1
    else:w0[i] += 1
  else:
    if i not in w1.keys():w1[i] = 1
    else:w1[i] += 1
  flag += 1
sumv = sum(w0.values()) + sum(w1.values())
def get_val(w0):
  l = list()
  w0_maxval = max(w0.values())
  w0_maxkey = [i for i in w0.keys() if w0[i] == w0_maxval][0]
  l.append({w0_maxkey:w0_maxval})
  del w0[w0_maxkey]
  if len(w0) > 0:
    w0_secval = max(w0.values())
    w0_seckey = [i for i in w0.keys() if w0[i] == w0_secval][0]
  else:
    w0_secval = 0
    w0_seckey = ""
  l.append({w0_seckey:w0_secval})
  return l
w0r = get_val(w0)
w1r = get_val(w1)
max = 0 
for i in w0r:
  for j in w1r:
    if list(i.keys())[0] != list(j.keys())[0]:
      if max < list(i.values())[0]  +  list(j.values())[0] : max = list(i.values())[0]  +  list(j.values())[0] 
print(sumv - max)

Solution (Python):
import collections

def answer(list,n):
    Even = collections.Counter(list[::2]).most_common(2)
    Odd = collections.Counter(list[1::2]).most_common(2)

    if Even[0][0] != Odd[0][0]:
        return n - Even[0][1] - Odd[0][1]
    else:
        if len(Even) == 1 or len(Odd) == 1:
            return n // 2
        else:
            return n - max(Even[0][1]+Odd[1][1],Even[1][1]+Odd[0][1])

N = int(input())
list = input().split(" ")
print(answer(list,N))

Solution (Python):
n = int(input())
v = [int(i) for i in input().split()]
m = n//2

a = [v[2*i] for i in range(0,m)]
b = [v[2*i+1] for i in range(0,m)]

def mode(arr):
        r = [0] * (max(arr) + 1)
        for a in arr:
            r[a] += 1
        return r.index(max(r))

A = mode(a)
B = mode(b)

v.remove(A)

if v == []:
    print(m)
    exit()
if A == B:
    if a.count(A) < b.count(B):
        a.remove(A)
        C = mode(a)
        print(n - a.count(C) - b.count(B))
    else:
        if b.count(B) == m:
            print(n - m)
        else:
            if a.count(A) == b.count(B):
                t = a.count(A)
                a.remove(A)
                b.remove(B)
                D = mode(a)
                E = mode(b)
                if a.count(D) > b.count(E):
                    print(n - t - a.count(D))
                else:
                    print(n - t - b.count(E))
            else:
                b.remove(B)
                C = mode(b)
                print(n - a.count(A) - b.count(C))
else:
    print(n - a.count(A) - b.count(B))

Solution (Python):
import collections

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

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

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
if(c1.most_common()[0][0] != c2.most_common()[0][0]):
	print(n - c1.most_common()[0][1] - c2.most_common()[0][1])
else:
	if(c1.most_common()[0][1] == n/2):
		count1 = c2.most_common()[0][1]
	else:
		count1 = c1.most_common()[1][1] + c2.most_common()[0][1]

	if(c2.most_common()[0][1] == n/2):
		count2 = c1.most_common()[0][1]
	else:
		count2 = c1.most_common()[0][1] + c2.most_common()[1][1]

	if(count1 < count2):
		print(n - count2)
	else:
		print(n - count1)

Solution (Python):
import collections

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

if len(list(set(v))) == 1:
    print(int(n/2))
    exit()
    
v1 = []
v2 = []
for i in range(n):
    if i%2:
        v1.append(v[i])
    else:
        v2.append(v[i])
v1 = collections.Counter(v1)
v2 = collections.Counter(v2)

v1_cnt = v1.most_common()
v2_cnt = v2.most_common()

if len(v1_cnt) > 1:
    e1 = v1_cnt[0]
    e2 = v1_cnt[1]
else:
    e1 = v1_cnt[0]
    e2 = e1
if len(v2_cnt) > 1:
    d1 = v2_cnt[0]
    d2 = v2_cnt[1]
else:
    d1 = v2_cnt[0]
    d2 = d1

if e1[0] != d1[0]:
    print(n - e1[1] - d1[1])
else:
    more = max(e1[1] + d2[1], e2[1] + d1[1])
    print(n - more)

Solution (Python):
from collections import Counter
 
def f(n,v):
	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]:
		return n-(a[0][1]+b[0][1])
	else:
		return min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1]))
 
if __name__=="__main__":
	x=int(input())
	data=[int(i) for i in input().split()]
	print(f(x,data))

Solution (Python):
from collections import Counter

def f(n,v):
	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]:
		return n-(a[0][1]+b[0][1])
	else:
		return min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1]))

if __name__=="__main__":
	x=int(input())
	data=[int(i) for i in input().split()]
	print(f(x,data))

Solution (Python):
from collections import Counter

a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(len(b)):
    if i % 2 == 0:
        c[b[i]] += 1
    else:
        cc[b[i]] += 1
first = Counter(b[::2]).most_common(2) + [(0, 0)]
latter = Counter(b[1::2]).most_common(2) + [(0, 0)]
one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(d+1):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    elif onee <= c[i]:
        onee = c[i]
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i
    elif twoo <= cc[i]:
        twoo = cc[i]
t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)