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

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

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

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
elif len(even_idx_cnt) == 1:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
elif len(odd_idx_cnt) == 1:
    print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
else:
    if even_idx_cnt[1][1] > odd_idx_cnt[1][1]:
        print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
    else:
        print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])

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

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

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

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
else:
    ans = []
    if len(odd_idx_cnt) >= 2:
        ans.append(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
    if len(even_idx_cnt) >= 2:
        ans.append(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
    print(min(ans))

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

d1 = {0:0}
d2 = {0:0}
for i, v in enumerate(V):
    d = d2 if i&1 else d1
    if v not in d: d[v]=0
    d[v]+=1
    

d1 = sorted(list(d1.items()), key=lambda x:-x[1])
d2 = sorted(list(d2.items()), key=lambda x:-x[1])

if d1[0][0]!=d2[0][0]:
    print(N-d1[0][1]-d2[0][1])
else:
    print(min(N-d1[1][1]-d2[0][1], N-d1[0][1]-d2[1][1]))

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

dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
    if i%2==0:    
        dic0[v[i]] += 1
    if i%2==1:
        dic1[v[i]] += 1

MX0_1 = max(dic0)
MX1_1 = max(dic1)

li0 = []
li1 = []


for i in range(10**5+1):
    
    
    
    
    
    if dic0[i] == MX0_1:
        li0.append(i)
        dic0[i] = 0
    if dic1[i] == MX1_1:
        li1.append(i)
        dic1[i] = 0




if len(li0)>=2 or len(li1)>=2:
    print(n-MX0_1-MX1_1)
elif li0[0] == li1[0]:
    print(min(n-MX0_1-max(dic1), n-MX1_1-max(dic0)))
elif li0[0] != li1[0]:
    print(n-MX0_1-MX1_1)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
O=A[0::2]
E=A[1::2]

from collections import Counter
o=Counter(O).most_common(2)
o.append((0,0))
e=Counter(E).most_common(2)
e.append((0,0))

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

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

S0 = {}
S1 = {}
for i in range(len(S)):
  if i%2 == 0:
    if S[i] not in S0:
      S0[S[i]] =1
    else:
      S0[S[i]] += 1
  else:
    if S[i] not in S1:
      S1[S[i]] =1
    else:
      S1[S[i]] += 1

if max(S0, key = S0.get) != max(S1, key = S1.get):
  Answer = len(S) - max(S0.values()) -max(S1.values())
  print(Answer)
  exit()
      
S0list = sorted(list(S0.values()),reverse = True)
S1list = sorted(list(S1.values()),reverse = True)

S00 = S0list[0]

if len(S0list) == 1:
  S01 = 0
else:
  S01 = S0list[1]
S10 = S1list[0]
if len(S1list) == 1:
  S11 = 0
else:
  S11 = S1list[1]
Answer = min(len(S) - S00 - S11,len(S) - S01 - S10)

print(Answer)

Solution (Python):

from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[::2]).most_common(2)+[(0,0)]
b=Counter(v[::-2]).most_common(2)+[(0,0)]


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

Solution (Python):
from collections import Counter
N = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2]).most_common(2)+[(0,0)]
v2 = Counter(v[::-2]).most_common(2)+[(0,0)]
if v1[0][0]==v2[0][0]:
  print(N -max(v1[0][1]+v2[1][1], v1[1][1]+v2[0][1]))
else:
  print(N -v1[0][1] -v2[0][1])

Solution (Python):
from collections import Counter
n = int(input())
ans = 0
f,s = [],[]
count = 0
for i in map(int,input().split()):
    if count%2 == 0:
        f.append(i)
    else:
        s.append(i)
    count += 1
c1,c2 = Counter(f),Counter(s)
a,b = [],[]
for i in c1.keys():
    a.append([i,c1[i]])
for j in c2.keys():
    b.append([j,c2[j]])
a = sorted(a,key=lambda x: x[1],reverse = True)
b = sorted(b,key=lambda x: x[1],reverse = True)
if a[0][0] == b[0][0]:
    if a[0][1] == b[0][1]:
        if len(a) == 1 and len(b) == 1:
            print(n-a[0][1])
        elif len(a) == 1 or len(b) == 1:
            if len(a) != 1:
                print(n-a[1][1]-b[0][1])
            else:
                print(n-a[0][1]-b[1][1])
        else:
            print(n-a[0][1]-max(a[1][1],b[1][1]))
    elif a[0][1] > b[0][1]:
        if len(b) == 1:
            print(n-a[0][1])
        else:
            print(n-a[0][1]-b[1][1])
    else:
        if len(a) == 1:
            print(n-b[0][1])
        else:
            print(n-a[1][1]-b[0][1])
else:
    print(n-a[0][1]-b[0][1])

Solution (Python):
import collections

def f(l):
    array = []
    c = collections.Counter(l)
    for key, val in c.items():
        array.append([key,val])
    array = sorted(array, key=lambda x:x[1], reverse=True)
    return array

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

    V_odd = V[::2]
    V_even = V[1::2]
    mode_list_odd = f(V_odd)
    mode_list_even = f(V_even)

    first_mode_odd = mode_list_odd[0][0]
    first_mode_even = mode_list_even[0][0]

    ans = 0
    if first_mode_odd == first_mode_even:
        if len(mode_list_odd) == 1:
            if len(mode_list_even) == 1:
                ans = min(len(V_odd),len(V_even))
            else:
                ans = len(V_even)-mode_list_even[1][1]
        else:
            if len(mode_list_even) == 1:
                ans = len(V_odd)-mode_list_odd[1][1]
            else:
                count1 = len(V_odd)-mode_list_odd[0][1]+len(V_even)-mode_list_even[1][1]
                count2 = len(V_odd)-mode_list_odd[1][1]+len(V_even)-mode_list_even[0][1]
                ans = min(count1, count2)
    else:
        ans = len(V_odd)-mode_list_odd[0][1] + len(V_even)-mode_list_even[0][1]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
c1 = Counter(V[::2])
c2 = Counter(V[1::2])

l1 = sorted(c1.items(),key=lambda x:x[1], reverse=True)
l2 = sorted(c2.items(),key=lambda x:x[1], reverse=True)
l1.append((-1,-1))
l2.append((-1,-1))

if l1[0][0] == l2[0][0]:
    if l1[0][1] == l2[0][1] == n // 2: ans = n // 2
    else: ans = n - max(l1[0][1]+l2[1][1],l1[1][1]+l2[0][1])
else:
    ans = n - l1[0][1] - l2[0][1]
print(ans)

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



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

    ac = Counter()
    bc = Counter()
    for i in range(N):
        if i & 1:
            ac[V[i]] += 1
        else:
            bc[V[i]] += 1

    acm = ac.most_common()
    bcm = bc.most_common()

    if acm[0][0] != bcm[0][0]:
        print(N // 2 - acm[0][1] + N // 2 - bcm[0][1])
    else:
        ans = float("inf")
        for i in acm:
            if i[0] == bcm[0][0]:
                continue
            ans = min(ans, N // 2 - i[1] + N // 2 - bcm[0][1])

        for j in bcm:
            if acm[0][0] == j[0]:
                continue
            ans = min(ans, N // 2 - j[1] + N // 2 - acm[0][1])
        if ans == float("inf"):
            print(N // 2)
        else:
            print(ans)


if __name__ == '__main__':
    main()

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



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

    a = []
    b = []
    for i in range(N):
        if i & 1:
            a.append(V[i])
        else:
            b.append(V[i])

    ac = Counter(a)
    bc = Counter(b)

    acm = ac.most_common()
    bcm = bc.most_common()

    if acm[0][0] != bcm[0][0]:
        print(N // 2 - acm[0][1] + N // 2 - bcm[0][1])
    else:
        ans = float("inf")
        for i in acm:
            if i[0] == bcm[0][0]:
                continue
            ans = min(ans, N // 2 - i[1] + N // 2 - bcm[0][1])

        for j in bcm:
            if acm[0][0] == j[0]:
                continue
            ans = min(ans, N // 2 - j[1] + N // 2 - acm[0][1])
        if ans == float("inf"):
            print(N // 2)
        else:
            print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
E=Counter(V[::2]).most_common()
O=Counter(V[1::2]).most_common()
if E[0][0]!=O[0][0]:
    print(n-E[0][1]-O[0][1])
else:
    if len(set(V))==1:
        print(n//2)
    else:
        print(min(n-E[1][1]-O[0][1],n-E[0][1]-O[1][1]))

Solution (Python):
import sys
from collections import Counter

n, *v = map(int, sys.stdin.read().split())

def main():
    c1 = sorted(Counter(v[::2]).items(), reverse=True, key=lambda x: x[1])
    c2 = sorted(Counter(v[1::2]).items(), reverse=True, key=lambda x: x[1])
    
    if c1[0][0] != c2[0][0]:
        return n // 2 - c1[0][1] + n // 2 - c2[0][1]
    else:
        if len(c1) == len(c2) == 1:
            return n // 2
        elif len(c1) == 1:
            return n // 2 - c2[1][1]
        elif len(c2) == 1:
            return n // 2 - c1[1][1]
        else:
            return n - max(c1[0][1] + c2[1][1], c1[1][1] + c2[0][1])

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import collections
n = int(input())
v = [i for i in map(int,input().split())]
v_odd = v[::2]
v_even = v[1::2]
odd_nums = (collections.Counter(v_odd)).most_common()
even_nums = (collections.Counter(v_even)).most_common()
ans = 0
if odd_nums[0][0] != even_nums[0][0]: 
  for i in range(1,len(odd_nums)):
    ans += odd_nums[i][1]
  for i in range(1,len(even_nums)):
    ans += even_nums[i][1]
else: 
  ans1=0
  ans2=0
  for i in range(1,len(odd_nums)):
    ans1 += odd_nums[i][1]
  for i in range(len(even_nums)):
    if i==1:
      continue
    ans1 += even_nums[i][1]
  for i in range(len(odd_nums)):
    if i==1:
      continue
    ans2 += odd_nums[i][1]
  for i in range(1,len(even_nums)):
    ans2 += even_nums[i][1]
  ans = min(ans1,ans2)
    
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a1=a[::2]
a2=a[1::2]
import collections
c1=collections.Counter(a1)
c2=collections.Counter(a2)
c1=c1.most_common(2)
c2=c2.most_common(2)
if a1==a2 and len(c1)==1 and len(c2)==1:
  print(len(a1))
  exit()
if len(c1)==1 and len(c2)==1 and c1[0][0]!=c2[0][0]:
  print(0)
  exit()
ans=0
if c1[0][0]!=c2[0][0]:
  ans+=n-c1[0][1]-c2[0][1]
else:
  if len(c1)==1:
    ans+=len(a2)-c2[1][1]
  elif len(c2)==1:
    ans+=len(a1)-c1[1][1]
  else :
    ans=min(len(a1)-c1[0][1]+len(a2)-c2[1][1],len(a1)-c1[1][1]+len(a2)-c2[0][1])
print(ans)

Solution (Python):

import collections

n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n//2)
    exit()

v_odd = [0] * (n // 2)
v_even = [0] * (n // 2)
for i in range(n):
    if (i+1)%2 == 1:
        v_odd[i//2] = v[i]
    else:
        v_even[i//2] = v[i]
c_v_odd = collections.Counter(v_odd)
c_v_even = collections.Counter(v_even)

if c_v_odd.most_common()[0][0] == c_v_even.most_common()[0][0]:
    if c_v_odd.most_common()[0][1] > c_v_even.most_common()[0][1]:
        odd_count = n//2 - c_v_odd.most_common()[0][1]
        even_count = n//2 - c_v_even.most_common()[1][1]
        ans = odd_count + even_count
    elif c_v_odd.most_common()[0][1] < c_v_even.most_common()[0][1]:
        odd_count = n//2 - c_v_odd.most_common()[1][1]
        even_count = n//2 - c_v_even.most_common()[0][1]
        ans = odd_count + even_count
    else:
        if c_v_odd.most_common()[1][1] > c_v_even.most_common()[1][1]:
            odd_count = n//2 - c_v_odd.most_common()[1][1]
            even_count = n//2 - c_v_even.most_common()[0][1]
            ans = odd_count + even_count
        else:
            odd_count = n//2 - c_v_odd.most_common()[0][1]
            even_count = n//2 - c_v_even.most_common()[1][1]
            ans = odd_count + even_count
else:
    odd_count = n//2 -  c_v_odd.most_common()[0][1]
    even_count = n//2 -  c_v_even.most_common()[0][1]
    ans = odd_count + even_count
print(ans)

Solution (Python):
from collections import Counter

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

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

cnt_o = Counter(o).most_common() + [(0,0)]
cnt_e = Counter(e).most_common() + [(0,0)]

print(n-cnt_o[0][1]-cnt_e[0][1] if cnt_o[0][0] != cnt_e[0][0] else n-max(cnt_e[0][1]+cnt_o[1][1], cnt_e[1][1]+cnt_o[0][1]))

Solution (Python):
from collections import Counter

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

a = Counter(v[::2])
b = Counter(v[1::2])
a = a.most_common()
b = b.most_common()

if n % 2 == 0:
    al = n // 2
    bl = al
else:
    al = n // 2 + 1
    bl = n // 2

if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(min(a[0][1], b[0][1]))
    else:
        print(0)
elif len(a) == 1 or len(b) == 1:
    if len(a) == 1:
        if a[0][0] == b[0][0]:
            print(bl - b[1][1])
        else:
            print(bl - b[0][1])
    if len(b) == 1:
        if a[0][0] == b[0][0]:
            print(al - a[1][1])
        else:
            print(al - a[0][1])
else:
     if a[0][0] == b[0][0]:
         print(min(n - a[0][1] - b[1][1], n - a[1][1] - b[0][1])) 
     else:
         print(n - a[0][1] - b[0][1])

Solution (Python):
import collections
N=int(input())
h=[int(i) for i in input().split()]

h_o_l = len(h[1::2])
h_e_l = len(h[::2])

h_o = collections.Counter(h[1::2])
h_e = collections.Counter(h[::2])

o_ = h_o.most_common()
e_ = h_e.most_common()
o_.append((0,0))
e_.append((0,0))

if o_[0][0] != e_[0][0]:
    print(N-o_[0][1]-e_[0][1])
elif o_[0][0] == e_[0][0]:
    a =min(N-o_[0][1]-e_[1][1],N-e_[0][1]-o_[1][1])
    print(a)

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

Odd, Evn = [], []
for i in range(n):
    Evn.append(V[i]) if i%2 == 0 else Odd.append(V[i])
Evn = sorted( dict(Counter(Evn)).items(), key = lambda x:x[1], reverse=True)
Odd = sorted( dict(Counter(Odd)).items(), key = lambda x:x[1], reverse=True)

cnt = -1
for evn in Evn[0:2]:
    for odd in Odd[0:2]:
        if evn[0] != odd[0]:
            cnt = max(cnt, evn[1]+odd[1])
print(n-cnt) if cnt > 0 else print(n//2)

Solution (Python):
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys

sys.setrecursionlimit(10**7)
mod = 10**9+7
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def counter_top(c,exclude):
    for a in c.most_common():
        if a[0]!=exclude:
            return a
    return (object(),0)

def conv_seq(seq,exclude = None):
    c = collections.Counter(seq)
    mc = counter_top(c,exclude)
    return sum(c.values()) - mc[1],mc[0]

N = I()
V = LI()

s1,a = conv_seq(V[::2])
s2,b = conv_seq(V[1::2])


if s1!=s2:
    print(s1+s2)
else:
    s1_new,_ = conv_seq(V[::2],exclude=b)
    s2_new,_ = conv_seq(V[1::2],exclude=a)
    print(min(s1_new+s2,s1+s2_new))

Solution (Python):
import collections

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

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

c0 = collections.Counter(v0)
c1 = collections.Counter(v1)

ans0 = n//2 - c0.most_common()[0][1]
ans1 = n//2 - c1.most_common()[0][1]

if c0.most_common()[0][0] == c1.most_common()[0][0]:
    if len(c0.most_common()) > 1:
        ans0_1 = n//2 - c0.most_common()[1][1]
    else:
        ans0_1 = n//2

    if len(c1.most_common()) > 1:
            ans1_1 = n//2 - c1.most_common()[1][1]
    else:
        ans1_1 = n//2

    ans = min(ans0 + ans1_1, ans0_1 + ans1)
else:
    ans = ans0 + ans1

print(ans)

Solution (Python):
def main():
    n, *v = map(int, open(0).read().split())
    be = [0] * int(1e5)
    bo = [0] * int(1e5)
    for e, o in zip(*[iter(v)] * 2):
        be[e - 1] += 1
        bo[o - 1] += 1
    ve = max(be)
    vo = max(bo)
    ke = be.index(ve)
    ko = bo.index(vo)
    if ke == ko:
        be[ke] = 0
        bo[ko] = 0
        print(min(n - ve - max(bo), n - vo - max(be)))
    else:
        print(n - ve - vo)
    return


main()

Solution (Python):
def main():
    n, *v = map(int, open(0).read().split())
    be = [0] * int(1e5)
    bo = [0] * int(1e5)
    for e, o in zip(*[iter(v)] * 2):
        be[e - 1] += 1
        bo[o - 1] += 1
    if be.index(max(be)) == bo.index(max(bo)):
        ve = max(be)
        vo = max(bo)
        be[be.index(ve)] = 0
        bo[bo.index(vo)] = 0
        print(min(n - ve - max(bo), n - vo - max(be)))
    else:
        print(n - max(be) - max(bo))
    return


main()

Solution (Python):
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N = int(sys.stdin.buffer.readline())
V = list(map(int, sys.stdin.buffer.readline().split()))

V = np.array(V, dtype=int)

V1 = V[::2]
V2 = V[1::2]
vc1 = np.bincount(V1, minlength=10 ** 5 + 1)
vc2 = np.bincount(V2, minlength=10 ** 5 + 1)

i1 = vc1.argmax()
i2 = vc2.argmax()

if i1 != i2:
    ans = N - (vc1[i1] + vc2[i2])
    print(ans)
else:
    m1 = vc1[i1]
    vc1[i1] = 0
    m2 = vc2[i2]
    vc2[i2] = 0
    j1 = vc1.argmax()
    j2 = vc2.argmax()
    ans = N - max(m1 + vc2[j2], m2 + vc1[j1])
    print(ans)

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        even += [v[i]]
    else:
        odd += [v[i]]
even_dict = collections.Counter(even)
odd_dict = collections.Counter(odd)
max_even = max(even_dict.items(), key = lambda x:x[1])
max_odd = max(odd_dict.items(), key = lambda x:x[1])

if max_even[0] != max_odd[0]:
    print(len(even) - max_even[1] + len(odd) - max_odd[1])
else:
    
    if max_even[1] == len(even) and max_odd[1] == len(odd):
        second_even = (-1,0)
        second_odd = (-1,0)
    elif max_even[1] == len(even):
        second_even = (-1,0)
        second_odd = max([i for i in odd_dict.items() if i != max_odd], key = lambda x:x[1])
    elif max_odd[1] == len(odd):
        second_even = max([i for i in even_dict.items() if i != max_even], key = lambda x:x[1])
        second_odd = (-1,0)
    else:
        second_even = max([i for i in even_dict.items() if i != max_even], key = lambda x:x[1])
        second_odd = max([i for i in odd_dict.items() if i != max_odd], key = lambda x:x[1])
    
    if second_even[1] > second_odd[1]:
        print(len(even) - second_even[1] + len(odd) - max_odd[1])
    else:
        print(len(even) - max_even[1] + len(odd) - second_odd[1])

Solution (Python):
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter

sys.setrecursionlimit(10**7)
n = int(input())
v = list(map(int, input().split()))

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

c1 = Counter(v1).most_common()
c2 = Counter(v2).most_common()

cnt1 = c1[0][1]
cnt2 = c2[0][1]

if c1[0][0] != c2[0][0]:
    print(n-cnt1-cnt2)
else:
    if len(c1)==1 or len(c2)==2:
        print(n//2)
    else:
        cnt11 = n - c1[1][1] - c2[0][1]
        cnt22 = n - c1[0][1] - c2[1][1]
        print(min(cnt11, cnt22))

Solution (Python):
import collections

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

ve = []
for i in range(0, n, 2):
    ve.append(v[i])
ce = collections.Counter(ve).most_common()
vo = []
for i in range(1, n, 2):
    vo.append(v[i])
co = collections.Counter(vo).most_common()

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

Solution (Python):

n = int(input())
V = list(map(int, input().split()))
A = [] 
B = [] 

import collections

for i in range(n):
  if i % 2 == 0:
    A.append(V[i])
  else:
    B.append(V[i])

A = collections.Counter(A).most_common()[:2]
B = collections.Counter(B).most_common()[:2]
count = 0

if A[0][0] == B[0][0]:
  count += max(A[0][1], B[0][1])
  if A[0][1] == B[0][1]:
    if len(A) > 1 and len(B) > 1:
      count += max(A[1][1], B[1][1])
    elif len(A) > 1:
      count += max(A[1][1])
    elif len(B) > 1:
      count += max(B[1][1])
else:
  count += A[0][1] + B[0][1]

print(n-count)

Solution (Python):
import collections

N = int(input())
A,B = [], []
for i,v in enumerate(input().split()):
    if i%2==0:
        A.append(int(v))
    else:
        B.append((int(v)))

ca = collections.Counter(A).most_common(2)
cb = collections.Counter(B).most_common(2)
if len(ca)<2:
    ca.append((-1, 0))
if len(cb)<2:
    cb.append((-2, 0))

ans = 10**6
for v1,c1 in ca:
    for v2,c2 in cb:
        if v1!=v2:
            ans = min(ans, N-c1-c2)
print(ans)

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
v2 = [v[i] for i in range(n) if i%2 == 0]
v1 = [v[i] for i in range(n) if i%2 == 1]
d1 = {}
d2 = {}
for i in v1:
    if i not in d1:
        d1[i] = 1
    else:
        d1[i] += 1
for i in v2:
    if i not in d2:
        d2[i] = 1
    else:
        d2[i] += 1
d1 = sorted(d1.items(),key = lambda x:x[1],reverse = True)
d2 = sorted(d2.items(),key = lambda x:x[1],reverse = True)
d1.append([0,0])
d2.append([0,0])
if d1[0][0] != d2[0][0]:
    print(n- d1[0][1] - d2[0][1])
else:
    print(min(n - d1[0][1] -d2[1][1],n - d1[1][1] -d2[0][1]))

Solution (Python):
from collections import Counter

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

if sum(V)/N == V[0] and sum(V)/N == V[N-1]:
  print(N//2)
  exit()

def get_most_common(lis):
  c = Counter(lis)
  m = c.most_common()
  return m

odds = V[0::2]
evens = V[1::2]

m_odds = get_most_common(odds)
m_evens = get_most_common(evens)

if m_odds[0][0] == m_evens[0][0]:
  minus = max(m_odds[0][1] + m_evens[1][1], m_odds[1][1] + m_evens[0][1])
else:
  minus = m_odds[0][1] + m_evens[0][1]
  
print(N - minus)

Solution (Python):
from collections import defaultdict

n = int(input())
v = list(map(int, input().split()))
v1 = [v[i] for i in range(0, n, 2)]
v2 = [v[i] for i in range(1, n, 2)]

cnt1 = defaultdict(int)
cnt2 = defaultdict(int)
for x in v1:
  cnt1[x] += 1
for x in v2:
  cnt2[x] += 1
vc1 = []
vc2 = []
for k, v in cnt1.items():
  vc1.append((v, k))
for k, v in cnt2.items():
  vc2.append((v, k))
vc1.sort()
vc1.reverse()
vc2.sort()
vc2.reverse()

vc1.append((0, vc1[0][0] + 1))
vc2.append((0, vc2[0][0] + 1))

ans = n
for _, x1 in vc1[:2]:
  for _, x2 in vc2[:2]:
    if x1 == x2: continue
    s = 0
    for x in v1:
      if x != x1: s += 1
    for x in v2:
      if x != x2: s += 1
    ans = min(ans, s)
print(ans)

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

for i,key in enumerate(v):
    if i%2 == 0:
        if key not in dict1:
            dict1[key] = 1
        else:
            dict1[key] += 1
    else:
        if key not in dict2:
            dict2[key] = 1
        else:
            dict2[key] += 1

max1 = 0
max2 = 0
if len(dict1) == 1 and len(dict2) == 1:
    if v[0] == v[1]:
        ans = n//2
    else:
        ans = 0
elif len(dict1) == 1:
    dict2[v[0]] = 0
    for key in dict2:
        max2 = max(max2,dict2[key])
    else:
        ans = n//2 - max2
elif len(dict2) == 1:
        dict2[v[1]] = 0
        for key in dict1:
            max1 = max(max1,dict1[key])
        else:
            ans = n//2 - max1
else:
    second1 = 0
    second2 = 0
    maxkey1 = 0
    maxkey2 = 0
    secondkey1 = 0
    secondkey2 = 0
    for key in dict1:
        if dict1[key] > max1:
            max1,second1, = dict1[key],max1
            maxkey1,secondkey1 = key,maxkey1
        elif dict1[key] > second1:
            second1 = dict1[key]
            secondkey1 = key
    for key in dict2:
        if dict2[key] > max2:
            max2,second2, = dict2[key],max2
            maxkey2,secondkey2 = key,maxkey2
        elif dict2[key] > second2:
            second2 = dict2[key]
            secondkey2 = key
    if maxkey1 == maxkey2:
        if dict1[secondkey1] < dict2[secondkey2]:
            ans = n - dict1[maxkey1] - dict2[secondkey2]
        else:
            ans = n - dict2[maxkey2] - dict1[secondkey1]
    else:
        ans = n - dict1[maxkey1] - dict2[maxkey2]

print(ans)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
w=[]
for i in range(n//2):
    w.append(v.pop(i))

import collections
cv = collections.Counter(v)
cw = collections.Counter(w)
scv = sorted(cv.items(), key=lambda x:-x[1])
scw = sorted(cw.items(), key=lambda x:-x[1])

v1=scv[0][0]
w1=scw[0][0]

if v1==w1:
    if len(scv)==1:
        v2=0
    else:
        v2=scv[1][1]
    if len(scw)==1:
        w2=0
    else:
        w2=scw[1][1]
        
    print(min(n-scv[0][1]-w2, n-scw[0][1]-v2))
        
else:
    print(n-scv[0][1]-scw[0][1])

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

gu=[]
ki=[]

from collections import Counter

for i in range(n):
  if i%2:
    ki.append(v[i])
  else:
    gu.append(v[i])

g=Counter(gu)
k=Counter(ki)



x=g.most_common()[0][1]
y=k.most_common()[0][1]
a=x+y
if g.most_common()[0][0]==k.most_common()[0][0]:
  if len(Counter(gu))!=1:
    if g.most_common()[1][1]>k.most_common()[1][1]:
      a=g.most_common()[1][1]+y
    else:
      a=x+k.most_common()[1][1]
  else:
    a=n//2
ans=n-a
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
V = list(map(int,input().split()))
v1 = V[0::2]
v2 = V[1::2]
v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()
v1c.append((0, 0))
v2c.append((0, 0))

if v1c[0][0]==v2c[0][0]:
    print(min(N-v1c[0][1]-v2c[1][1], N-v1c[1][1]-v2c[0][1]))
else:
    print(N-v1c[0][1]-v2c[0][1])

Solution (Python):
N = int(input())
vlist = list(map(int, input().split()))
odd, even = vlist[1::2], vlist[::2]
from collections import Counter
odd_c, even_c = Counter(odd).most_common(2), Counter(even).most_common(2)

if odd_c[0][0] != even_c[0][0]:
    print(N - odd_c[0][1] - even_c[0][1])
else:
    if len(odd_c) >= 2 and len(even_c) >= 2:
        if odd_c[0][1] > even_c[0][1]:
            print(N - odd_c[0][1] - even_c[1][1])
        elif odd_c[0][1] < even_c[0][1]:
            print(N - odd_c[1][1] - even_c[0][1])
        else:
            print(N - odd_c[0][1] - max(odd_c[1][1], even_c[1][1]))
    else:
        if len(odd_c) == 1 and len(even_c) == 1:
            if odd_c[0][0] == even_c[0][0]:
                print(N - max(odd_c[0][1], even_c[0][1]))
        elif len(odd_c) == 1:
            if odd_c[0][0] != even_c[0][0]:
                print(N - odd_c[0][1] - even_c[0][1])
            else:
                if odd_c[0][1] > even_c[0][1]:
                    print(N - odd_c[0][1] - even_c[1][1])
                else:
                    print(N - even_c[0][1])
        elif len(even_c) == 1:
            if odd_c[0][0] != even_c[0][0]:
                print(N - odd_c[0][1] - even_c[0][1])
            else:
                if odd_c[0][1] < even_c[0][1]:
                    print(N - odd_c[1][1] - even_c[0][1])
                else:
                    print(N - odd_c[0][1])

Solution (Python):

import sys
from collections import Counter

def solve(n: int, v: "List[int]"):
    v1 = v[0::2]
    v2 = v[1::2]

    counter1 = Counter(v1).most_common(2)
    counter2 = Counter(v2).most_common(2)

    key1,value1 = counter1[0]
    key2,value2 = counter2[0]

    if key1 == key2:
        answer1 = 0
        
        if len(counter1)>=2:
            answer1 = len(v1)-counter1[1][1] +len(v2)-value2
        else:
            answer1 = len(v1) +len(v2)-value2

        answer2 = 0
        if len(counter1)>=2:
            answer2 = len(v1)-value1 +len(v2)-counter2[1][1]
        else:
            answer2 = len(v1)-value1 +len(v2)
        print(min(answer1,answer2))   
    else:
        print(len(v1)-value1+len(v2)-value2)
    return


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

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
DO, DE = {}, {}
L, M = [], []
for i in range(N//2):
  if A[2*i] in DO:
    DO[A[2*i]] += 1
  else:
    DO[A[2*i]] = 1
  if A[2*i+1] in DE:
    DE[A[2*i+1]] += 1
  else:
    DE[A[2*i+1]] = 1
for i in DO:
  L.append([DO[i], i])
for j in DE:
  M.append([DE[j], j])
l, m = len(L)-1, len(M)-1
L.sort()
M.sort()
if L[l][1] != M[m][1]:
  S = N - L[l][0] - M[m][0]
else:
  if l == 0 and m == 0:
    S = N // 2
  else:
    if L[l][0] - L[l-1][0] >= M[m][0] - M[m-1][0]:
      S = N - L[l][0] - M[m-1][0]
    else:
      S = N - L[l-1][0] - M[m][0]
print(S)