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 = [int(i) for i in input().split()]

even = dict()
odd = dict()

for i in range(n//2):
    e = v[2*i]
    o = v[2*i + 1]
    if e in even:
        even[e] += 1
    else:
        even[e] = 1
    if o in odd:
        odd[o] += 1
    else:
        odd[o] = 1

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


if even[0][0] != odd[0][0]:
    print(n-even[0][1]-odd[0][1])
else:
    if len(even) > 1 and len(odd) > 1:
        print(n - even[0][1]-max(even[1][1], odd[1][1]))
    elif len(even) > 1:
        print(n - even[0][1] - even[1][1])
    elif len(odd) > 1:
        print(n - even[0][1] - odd[1][1])
    else:
        print(n - even[0][1])

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
cnt_o = Counter(v[::2]).most_common(2)
cnt_e = Counter(v[1::2]).most_common(2)
cnt_o.append((0, 0))
cnt_e.append((0, 0))

if cnt_o[0][0] != cnt_e[0][0]:
    print(n - cnt_o[0][1] - cnt_e[0][1])
else:
    del1 = cnt_o[0][1] - cnt_o[1][1]
    del2 = cnt_e[0][1] - cnt_e[1][1]
    print(n - cnt_o[0][1] - cnt_e[0][1] + min(del1, del2))

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

app = {}
for i, j in zip(v[::2], v[1::2]):
    if i not in app:
        app[i] = [1, 0]
    else:
        app[i][0] += 1
    if j not in app:
        app[j] = [0, 1]
    else:
        app[j][1] += 1

max_o = [0, 0]
secmax_o = [0, 0]
max_e = [0, 0]
secmax_e = [0, 0]
for i in app:
    if app[i][0] > max_o[1]:
        secmax_o = max_o[:]
        max_o = [i, app[i][0]]
    elif app[i][0] > secmax_o[1]:
        secmax_o = [i, app[i][0]]
    if app[i][1] > max_e[1]:
        secmax_e = max_e[:]
        max_e = [i, app[i][1]]
    elif app[i][1] > secmax_e[1]:
        secmax_e = [i, app[i][1]]

if max_o[0] != max_e[0]:
    print(n - max_o[1] - max_e[1])
else:
    del0 = max_o[1] - secmax_o[1]
    del1 = max_e[1] - secmax_e[1]
    print(n + min(del0, del1) - max_o[1] - max_e[1])

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

Solution (Python):
import bisect
from collections import deque
from collections import defaultdict

from math import sqrt
n=int(input())
v=list(map(int,input().split()))

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

A=defaultdict(int)
B=defaultdict(int)
for i in a:
    A[i]+=1
for i in b:
    B[i]+=1
A[0]=0
B[0]=0
Amax=0
Akey=0
Bmax=0
Bkey=0

for key in A.keys():
    if Amax<A[key]:
        Akey=key
        Amax=A[key]
for key in B.keys():
    if Bmax<B[key]:
        Bkey=key
        Bmax=B[key]
min=10**5
n_=int(n/2)
for i in B.keys():
    min_=(n_-Amax)+(n_-B[i])
    if Akey!=i and min>min_:
        min=min_
for i in A.keys():
    min_=(n_-A[i])+(n_-Bmax)
    if Bkey!=i and min>min_:
        min=min_
print(min)

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

odd = [v[i] for i in range(N) if i%2 == 1]
even = [v[i] for i in range(N) if i%2 == 0]

oddmemo = [0 for i in range(100001)]
evenmemo = [0 for i in range(100001)]
for i in odd:
  oddmemo[i] = oddmemo[i] + 1
for i in even:
  evenmemo[i] = evenmemo[i] + 1
  
oddres = [(oddmemo[i],i) for i in range(100001)]
evenres = [(evenmemo[i],i) for i in range(100001)]
oddres.sort()
evenres.sort()
if oddres[-1][1] == evenres[-1][1]:
	print(min(N-oddres[-1][0]-evenres[-2][0],N-oddres[-2][0]-evenres[-1][0]))
else:
	print(N-oddres[-1][0]-evenres[-1][0])

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

vE,vO = v[0::2],v[1::2]

lmodeE, lmodeO = col.Counter(vE).most_common(), col.Counter(vO).most_common()
modeE, nmodeE = lmodeE[0][0], lmodeE[0][1]
modeO, nmodeO = lmodeO[0][0], lmodeO[0][1]

if modeE == modeO:
    
    if len(lmodeE) == 1:
        ans1 = int(n/2)
    else:
        ans1 = n - lmodeE[1][1] - nmodeO
    
    if len(lmodeO) == 1:
        ans2 = int(n/2)
    else:
        ans2 = n - nmodeE - lmodeO[1][1]
    
    print(min(ans1,ans2))
else:
    print(n-nmodeE-nmodeO)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
x=[ [0,i]  for i in range(max(a)+1)]
y=[[0,i] for i in range (max(a)+1)]
for i in range(0,N,2):
        x[a[i]][0]+=1
        y[a[i+1]][0]+=1

x.sort(reverse=True)
y.sort(reverse=True)
if x[0][1]==y[0][1]:
        print(min(N-x[0][0]-y[1][0],N-x[1][0]-y[0][0]))
else: print(N-x[0][0]-y[0][0])

Solution (Python):
from itertools import groupby

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

def main():
    a = sorted(V[::2])
    b = sorted(V[1::2])

    freq_a = [(k, len(list(g))) for k, g in groupby(a)]
    freq_b = [(k, len(list(g))) for k, g in groupby(b)]

    freq_a.sort(key=lambda t: t[1], reverse=True)
    freq_b.sort(key=lambda t: t[1], reverse=True)

    freq_a.append((0, 0))
    freq_b.append((0, 0))

    if freq_a[0][0] == freq_b[0][0]:
        if freq_a[0][1] > freq_b[0][1]:
            na = freq_a[0][1]
            nb = freq_b[1][1]
        elif freq_a[0][1] < freq_b[0][1]:
            na = freq_a[1][1]
            nb = freq_b[0][1]
        else:
            if freq_a[1][1] >= freq_b[1][1]:
                na = freq_a[1][1]
                nb = freq_b[0][1]
            else:
                na = freq_a[0][1]
                nb = freq_b[1][1]
    else:
        na = freq_a[0][1]
        nb = freq_b[0][1]
        
    ans = len(a) - na + len(b) - nb

    print(ans)

if __name__ == '__main__':
    main()

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

n = int(input())
v = [int(_) for _ in input().split()]
oddcnt = [[0, i] for i in range(10**5+1)]
evencnt = [[0, i] for i in range(10**5+1)]

for i, j in enumerate(v):
    if i % 2 == 0:
        oddcnt[j][0] += 1
    else:
        evencnt[j][0] += 1

oddcnt = sorted(oddcnt, key=lambda x: (-x[0], x[1]))
evencnt = sorted(evencnt, key=lambda x: (-x[0], -x[1]))

if oddcnt[0][1] != evencnt[0][1]:
    print(n-oddcnt[0][0]-evencnt[0][0])
elif oddcnt[0][0] > evencnt[0][0]:
    print(n-oddcnt[0][0]-evencnt[1][0])
elif oddcnt[0][0] < evencnt[0][0]:
    print(n-oddcnt[1][0]-evencnt[0][0])
elif oddcnt[1][0] > evencnt[1][0]:
    print(n-oddcnt[1][0]-evencnt[0][0])
else:
    print(n-oddcnt[0][0]-evencnt[1][0])

Solution (Python):
from collections import Counter

n = int(input())
vs = input().split()
even = []
odd = []

if len(list(set(vs))) == 1:
  res = int(len(vs) / 2)
else:
  for i, v in enumerate(vs):
    if i % 2 == 0:
      even.append(int(v))
    else:
      odd.append(int(v))
  counter_even = Counter(even)
  counter_odd = Counter(odd)
  if counter_even.most_common()[0][0] != counter_odd.most_common()[0][0]:
    res = len(even) - counter_even.most_common()[0][1]  + len(odd) - counter_odd.most_common()[0][1]
  else:
    res1 = len(even) - counter_even.most_common()[1][1]  + len(odd) - counter_odd.most_common()[0][1]
    res2 = len(even) - counter_even.most_common()[0][1]  + len(odd) - counter_odd.most_common()[1][1]
    res = min(res1, res2)
print(res)

Solution (Python):
from collections import Counter

n = int(input())
v = input().split()
vls = []

for x in v:
    vls.append(int(x))

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

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

ya1 = c1.most_common()[0]
ya2 = c2.most_common()[0]

if ya1[0] == ya2[0]:
    if len(c1.most_common())== 1 and len(c2.most_common()) == 1:
        print(len(v2))
        exit()
    elif ya1[1] == ya2[1]:
        if c1.most_common()[1][1] > c2.most_common()[1][1]:
            ya1 = c1.most_common()[1]
        else:
            ya2 = c2.most_common()[1]
    elif ya1[1] > ya2[1]:
        ya2 = c2.most_common()[1]
    else:
        ya1 = c1.most_common()[1]

print(int(((n/2)-ya1[1]) + ((n/2)-ya2[1])))

Solution (Python):
from operator import itemgetter
from collections import Counter
def main():
    va = []
    vb = []
    n = int(input())
    *v, = map(int, input().split())
    for i in range(len(v)):
        if i % 2 == 0:
            va.append(v[i])
        else:
            vb.append(v[i])
    a1 = Counter(va).most_common()
    a2 = Counter(vb).most_common()
    how_many_a1 = a1[0][1]
    how_many_a2 = a2[0][1]
    if a1[0][0] != a2[0][0]:
        print(n - how_many_a1 - how_many_a2)
    else:
        if len(a1) == 1 and len(a2) == 1:
            print(int(n/2))
        elif len(a1) == 1:
            print(len(vb) - a2[1][1])
        elif  len(a2) == 1:
            print(len(va) - how_many_a1)
        elif (len(va) - how_many_a1) + (len(vb) - a2[1][1])  > (len(vb) - how_many_a2) + (len(va) - a1[1][1]):
            print((len(vb) - how_many_a2) + (len(va) - a1[1][1]))
        else:
            print((len(va) - how_many_a1) + (len(vb) - a2[1][1]))
main()

Solution (Python):
from collections import Counter

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

even = Counter(V[1::2]).most_common() + [(0, 0)]
odd = Counter(V[::2]).most_common() + [(0, 0)]

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

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
n = ip()                                     

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







dlist = []
ulist = []
for i in range(n):
    if i%2:
        ulist.append(a[i])
    else: dlist.append(a[i])
ulist.sort()
dlist.sort()

firstupper = 0
secondupper = 0
maxupper = ulist[0]
maxlower = dlist[0]
c = 1
cnum = ulist[0]
for i in range(1,len(ulist)):
    if ulist[i] == cnum:
        c+=1
    else:
        cnum = ulist[i]
        if c > firstupper:
            maxupper = ulist[i-1]
            secondupper = firstupper
            firstupper = c
        elif c > secondupper and firstupper >= c:
            secondupper = c
        c = 1
if c > firstupper:
    maxupper = ulist[i-1]
    secondupper = firstupper
    firstupper = c
elif c > secondupper and firstupper >= c:
    secondupper = c


firstlower = 0
secondlower = 0
c = 1
cnum = dlist[0]
for i in range(1,len(dlist)):
 
    if dlist[i] == cnum:
        c+=1
    else:
        cnum = dlist[i]
        if c > firstlower:
            maxlower = dlist[i-1]
            secondlower = firstlower
            firstlower = c
        elif c > secondlower and firstlower >= c:
            secondlower = c
        c = 1
if c > firstlower:
  
    maxlower = dlist[i-1]
    secondlower = firstlower
    firstlower = c
elif c > secondlower and firstlower >= c:
    secondlower = c
c = 0
"""
print(maxupper,maxlower)
print(firstupper,firstlower)
print(secondupper,secondlower)
"""
p = len(ulist)
if maxupper == maxlower:
    print(min(p-firstupper+p-secondlower,p-secondupper+p-firstlower))
else: print(2*p - firstupper - firstlower)

Solution (Python):
import collections

N = int(input())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
all_length = len(V)
even = collections.Counter(even).most_common(2)
odd = collections.Counter(odd).most_common(2)
if (even[0][0] != odd[0][0]):
    print(all_length - even[0][1] - odd[0][1])
else:
    if(len(even) == 1 and len(odd) == 1):
        print(all_length // 2)
    elif(len(even)==1):
        print(all_length // 2 - odd[1][1])
    elif(len(odd)==1):
        print(all_length // 2 - even[1][1])    
    else:
        print(min(all_length - even[0][1] - odd[1][1], all_length - even[1][1] - odd[0][1]))

Solution (Python):
import collections
n = int(input())
v_ = list(map(int,input().split()))
v_g = v_[0:len(v_):2]
v_k = v_[1:len(v_):2]

counter_g = collections.Counter(v_g)
counter_g = sorted(counter_g.items(),key=lambda x:x[1])[::-1]
counter_k = collections.Counter(v_k)
counter_k = sorted(counter_k.items(),key=lambda x:x[1])[::-1]


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

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
v1 = v[::2]
v2 = v[1::2]
c1 = collections.Counter(v1).most_common()
c2 = collections.Counter(v2).most_common()

if c1[0][0] != c2[0][0]:
  print(n - c1[0][1] - c2[0][1])
else:
  if len(c1) == len(c2) == 1:
    print(n // 2)
  elif len(c1) == 1:
    print(len(v2)-c2[1][1])
  elif len(c2) == 1:
    print(len(v1)-c1[1][1])
  else:
    print(min(n-c1[0][1]-c2[1][1], n-c1[1][1]-c2[0][1]))

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
v1 = v[::2]
v2 = v[1::2]
c1 = collections.Counter(v1).most_common()
c2 = collections.Counter(v2).most_common()

if c1[0][0] != c2[0][0]:
  print(len(v1)-c1[0][1] + len(v2)-c2[0][1])
else:
  if len(c1) == len(c2) == 1:
    print(n // 2)
  elif len(c1) == 1:
    print(len(v2)-c2[1][1])
  elif len(c2) == 1:
    print(len(v1)-c1[1][1])
  else:
    print(min(len(v1)-c1[0][1]+len(v2)-c2[1][1], len(v1)-c1[1][1]+len(v2)-c2[0][1]))

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
v1 = [v[i*2+1] for i in range(n//2)]
v2 = [v[i*2] for i in range(n//2)]
c1 = collections.Counter(v1).most_common()
c2 = collections.Counter(v2).most_common()

if len(set(v1)) == len(set(v2)) == 1:
  if c1[0][0] != c2[0][0]:
    print(0)
  else:
    print(min(len(v1), len(v2)))
elif len(set(v1))==1:
  if c1[0][0] != c2[0][0]:
    print(sum([i[1] for i in c2])-c2[0][1])
  else:
    print(sum([i[1] for i in c2])-c2[1][1])
elif len(set(v2))==1:
  if c1[0][0] != c2[0][0]:
    print(sum([i[1] for i in c1])-c1[0][1])
  else:
    print(sum([i[1] for i in c1])-c1[1][1])
else:
  if c1[0][0] != c2[0][0]:
    print((sum([i[1] for i in c1])-c1[0][1]) + (sum([i[1] for i in c2])-c2[0][1]))
  else:
    print(min((sum([i[1] for i in c1])-c1[0][1])+(sum([i[1] for i in c2])-c2[1][1]),
              (sum([i[1] for i in c1])-c1[1][1])+(sum([i[1] for i in c2])-c2[0][1])))

Solution (Python):
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
v = list(map(int, input().split()))
v1, v2 = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2]
c1, c2 = Counter(v1).most_common(), Counter(v2).most_common()
l1, l2 = len(c1), len(c2)
if l1 == 1 and l2 == 1:
    if c1[0][0] == c2[0][0]:
        print(n // 2)
    else:
        print(0)
elif l1 == 1:
    if c1[0][0] == c2[0][0]:
        print(n//2 - c2[1][1])
    else:
        print(n//2 - c2[0][1])
elif l2 == 1:
    if c1[0][0] == c2[0][0]:
        print(n//2 - c1[1][1])
    else:
        print(n//2 - c1[0][1])
else:
    if c1[0][0] == c2[0][0]:
        if c1[0][1] + c2[1][1] < c1[1][1] + c2[0][1]:
            print(n - c1[1][1] - c2[0][1])
        else:
            print(n - c1[0][1] - c2[1][1])
    else:
        print(n - c1[0][1] - c2[0][1])

Solution (Python):
from collections import Counter

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

list_o = list[::2]
list_e = list[1::2]

cnt_o = Counter(list_o).most_common(2)
cnt_e = Counter(list_e).most_common(2)


if cnt_o[0][0] == cnt_e[0][0]:
    
    if len(cnt_o) == 1 and len(cnt_e) ==1:
        print(int(len(list) / 2))
    elif len(cnt_o) == 1 and len(cnt_e) != 1:
        print(len(list) - cnt_o[0][1] - cnt_e[1][1])
    elif len(cnt_o) != 1 and len(cnt_e) == 1:
        print(len(list) - cnt_o[0][1] - cnt_e[1][1])
    else:
        print(min(len(list) - cnt_o[1][1] - cnt_e[0][1], len(list) - cnt_o[0][1] - cnt_e[1][1]))

elif cnt_o[0][0] != cnt_e[0][0]:
    if len(cnt_o) == 1 and len(cnt_e) ==1:
        print(0)
    else:
        print(len(list) - cnt_o[0][1] - cnt_e[0][1])

Solution (Python):
import collections
n = int(input())
v = [int(i) for i in input().split()]
l = collections.Counter(v[1:len(v):2])
r = collections.Counter(v[0:len(v):2])
r = r.most_common()
l = l.most_common()
if l[0][0] == r[0][0]:
    if (len(l) > 1) & (len(r) > 1):
        ans = min(n-l[1][1]-r[0][1], n-l[0][1]-r[1][1])
    else:
        ans = min(l[0][1], r[0][1])
elif l[0][0] != r[0][0]:
    ans = (n - l[0][1] - r[0][1])
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')



N = 0
V = []


def set_inputs():
    global N, V
    N = get_int()
    V = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    x = V[0::2]
    y = V[1::2]
    x_counter = Counter(x)
    y_counter = Counter(y)
    x_val, x_cnt = x_counter.most_common(1)[0]
    y_val, y_cnt = y_counter.most_common(1)[0]
    ans = N - x_cnt - y_cnt
    if x_val == y_val:
        if len(x_counter) == 1:
            if len(y_counter) == 1:
                ans = N // 2
            else:
                _, y_cnt = y_counter.most_common(2)[1]
                ans = N - x_cnt - y_cnt
        else:
            if len(y_counter) == 1:
                _, x_cnt = x_counter.most_common(2)[1]
                ans = N - x_cnt - y_cnt
            else:
                _, x_cnt_2 = x_counter.most_common(2)[1]
                _, y_cnt_2 = y_counter.most_common(2)[1]
                ans = min(N - x_cnt - y_cnt_2, N - x_cnt_2 - y_cnt)
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(len(v) // 2)
    sys.exit()

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




if even.most_common()[0][0] == odd.most_common()[0][0]:
    print(min(len(v) - odd.most_common()[0][1] - even.most_common()[1][1], len(v) - odd.most_common()[1][1] - even.most_common()[0][1]))
    sys.exit()

print(len(v) - even.most_common()[0][1] - odd.most_common()[0][1])

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

import collections


'''
奇数番目の数列
'''
v_odd = []
for i in range(0,n,2):
  v_odd.append(v[i])

c_odd = collections.Counter(v_odd)
c_common_odd = c_odd.most_common()


'''
偶数番目の数列
'''
v_even = []
for i in range(1,n,2):
  v_even.append(v[i])

c_even = collections.Counter(v_even)
c_common_even = c_even.most_common()


'''
後処理

下記の4種類でパターン別に出力
また、各パターンごとに一番カウント数が大きい数字を比較する。

a.奇数・偶数共に数字が２種類以上
b.奇数については数字が一種類
c.偶数については数字が一種類
d.両方の数字がそれぞれ一種類
'''


if len(c_common_odd) >= 2 and len(c_common_even) >= 2:
  
  if c_common_odd[0][0] != c_common_even[0][0]:
    ans = n - c_common_odd[0][1] - c_common_even[0][1]
  
  else:
    
    ans_1 = n - c_common_odd[1][1] - c_common_even[0][1]
    ans_2 = n - c_common_odd[0][1] - c_common_even[1][1]
    ans = min(ans_1, ans_2)


elif len(c_common_odd) < 2 and len(c_common_even) >= 2:
  
  if c_common_odd[0][0] == c_common_even[0][0]:
    ans = int(n / 2) - c_common_even[1][1]
  else:
    ans = int(n / 2) - c_common_even[0][1]


elif len(c_common_odd) >= 2 and len(c_common_even) < 2:
  
  if c_common_odd[0][0] == c_common_even[0][0]:
    ans = int(n / 2) - c_common_odd[1][1]
  else:
    ans = int(n / 2) - c_common_odd[0][1]


else:
  if c_common_odd[0][0] == c_common_even[0][0]:
    ans = int(n / 2)
  else:
    ans = 0

print(ans)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
count=0
A=[[0,i] for i in range(10**5+1)]
Z=[[0,i] for i in range(10**5+1)]
for i in range(n):
  if i%2==0:
    A[v[i]][0]+=1
  else:
    Z[v[i]][0]+=1
A.sort()
Z.sort()
def wfs(x,y):
  if A[x][1]!=Z[y][1]:
    return n-A[x][0]-Z[y][0]
  else:
    return min(wfs(x,y-1),wfs(x-1,y))
print(wfs(-1,-1))

Solution (Python):
from collections import Counter

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

even = Counter(V[1::2]).most_common() + [(0, 0)]
odd = Counter(V[::2]).most_common() + [(0, 0)]

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

Solution (Python):
n=int(input())
v=list(map(int, input().split()))
import collections
v1=v[0::2]
v11=collections.Counter(v1)
v2=v[1::2]
v22=collections.Counter(v2)
o=v11.most_common()+([(0,0)])
e=v22.most_common()+([(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):
import collections as col

N = int(input())
v = [int(x) for x in input().split()]
v1,v2 = sorted(v[::2]), sorted(v[1::2])

c1,n1 = col.Counter(v1).most_common()[0]
c2,n2 = col.Counter(v2).most_common()[0]

if c1 != c2:
    print(N - n1 - n2)
else:
    if n1 + n2 == N:
        print(int(N/2))
    else:
        c12,n12 = col.Counter(v1).most_common()[1]
        c22,n22 = col.Counter(v2).most_common()[1]
        if n1 + n22 > n12 + n2:
            print(N - n1 - n22)
        else:
            print(N - n12 - n2)

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

even = [[i,0] for i in range(10**5+1)]
odd = [[i,0] for i in range(10**5+1)]
for e,o in zip(a[::2],a[1::2]):
    even[e][1] += 1
    odd[o][1] += 1

even.sort(key=lambda x: -x[1])
odd.sort(key=lambda x: -x[1])

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

Solution (Python):
n = int(input())
V = list(map(int,input().split()))
even = [0] * 100001
odd  = [0] * 100001

for v in V[1::2]:
    even[v] += 1
for v in V[::2]:
    odd[v]  += 1
maxeven = max(even)
maxodd  = max(odd)
if(even.index(maxeven) != odd.index(maxodd)):
    print(n - maxeven - maxodd)
else:
    even.sort()
    odd.sort()
    print(min(n-even[-1]-odd[-2],n-even[-2]-odd[-1]))

Solution (Python):
from operator import itemgetter
n = int(input())
v = [int(x) for x in input().split()]
li = [[[0 for _ in range(2)] for _ in range(10**5)] for _ in range(2)]
for index,i in enumerate(v):
    li[index%2][i-1][0]+=1
    li[index%2][i-1][1]=i

li[0].sort(key=itemgetter(0),reverse=True)
li[1].sort(key=itemgetter(0),reverse=True)

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

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
even = v[0::2]
odd = v[1::2]
ce = collections.Counter(even)
oe = collections.Counter(odd)
if len(set(odd)) ==1 and len(set(even)) == 1:
    if ce.most_common()[0][0] != oe.most_common()[0][0]:
        print("0")
    else:
        print(int(n/2))
elif len(set(odd)) ==1 and len(set(even)) != 1:
    print(int(n/2-ce.most_common()[0][1]))
elif len(set(odd)) !=1 and len(set(even)) == 1:
    print(int(n/2-oe.most_common()[0][1]))
else:
    if ce.most_common()[0][0] != oe.most_common()[0][0]:
        print(n-ce.most_common()[0][1]-oe.most_common()[0][1])
    else:
        print(n - max(ce.most_common()[1][1]+oe.most_common()[0][1], oe.most_common()[1][1]+ce.most_common()[0][1]))

Solution (Python):
n = int(input())
V = list(map(int,input().split()))
dict_V1,dict_V2 = {},{}
if(n%2 == 0):
  len_v1,len_v2 = n//2,n//2
else:
  len_v1,len_v2 = n//2 + 1,n//2

i = 0
for v in V:
  if(i%2 == 0):
   if(str(v) in dict_V1): dict_V1[str(v)] += 1
   else: dict_V1[str(v)] = 1
  else:
   if(str(v) in dict_V2): dict_V2[str(v)] += 1
   else: dict_V2[str(v)] = 1
  i += 1
 
min_cost = 0
max_k_v1 = max(dict_V1, key=dict_V1.get)
max_k_v2 = max(dict_V2, key=dict_V2.get)


'''
(ex) 
V1 = [3,3,3,4],V2 = [3,3,3,2]
->(書き換え) V1 = [3,3,3,3],V2 = [3,3,3,3]
-> 文字一種類に ->NG
のケースを考慮した場合分けが必要
'''


if(max_k_v1 != max_k_v2):
  min_cost += len_v1 - max(dict_V1.values())
  min_cost += len_v2 - max(dict_V2.values())
else:
  min_cost1,min_cost2 = 0,0
  tmp_dict = dict_V1.copy()
  tmp_dict[max_k_v1] = 0
  min_cost1 += len_v1 - max(tmp_dict.values())
  min_cost1 += len_v2 - max(dict_V2.values())
  
  dict_V2[max_k_v1] = 0
  min_cost2 += len_v1 - max(dict_V1.values())
  min_cost2 += len_v2 - max(dict_V2.values())
  min_cost = min(min_cost1,min_cost2)
  
print(min_cost)

Solution (Python):
import collections

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

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

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

if ce.most_common(1)[0][0] != co.most_common(1)[0][0]:
  print(n - ce.most_common(1)[0][1] - co.most_common(1)[0][1])
else:
  if len(ce) ==1 and len(co) ==1:
    print(n//2)
  elif len(ce) ==1:
    print(n//2 - co.most_common(2)[1][1])
  elif len(co) ==1:
    print(n//2 - ce.most_common(2)[1][1])
  else:
    a = ce.most_common(2)[0][1] + co.most_common(2)[1][1]
    b = ce.most_common(2)[1][1] + co.most_common(2)[0][1]
    print(min([n-a, n-b]))

Solution (Python):
import sys
from collections import defaultdict

input = sys.stdin.readline
n = int(input())
v_list = list(map(int, input().split()))
even_dic = defaultdict(int)
odd_dic = defaultdict(int)
for i in range(n):
    if i % 2 == 0:
        even_dic[v_list[i]] += 1
    else:
        odd_dic[v_list[i]] += 1
even = sorted(even_dic.items(), key=lambda x:x[1], reverse=True)
odd = sorted(odd_dic.items(), key=lambda x:x[1], reverse=True)
if even[0][0] == odd[0][0]:
    if len(even) > 1 and len(odd) > 1:
        ans = min((n-even[1][1]-odd[0][1]), (n-even[0][1]-odd[1][1]))
    elif len(even) > 1:
        ans = int(n/2) - even[1][1]
    elif len(odd) > 1:
        ans = int(n/2) - odd[1][1]
    else:
        ans = int(n/2)
else:
    ans = n - even[0][1] - odd[0][1]
print(ans)

Solution (Python):
import numpy as np
import collections
n = int(input())
a_n = np.array(input().split(),dtype='int')
diff = a_n[1:] - a_n[:-1]
if len(set(diff))==2:
    print(0)
elif len(set(diff))==1:
    print(int(n/2))
else:
    odd_th = collections.Counter(a_n[1::2]).most_common()
    eve_th = collections.Counter(a_n[0::2]).most_common()
    if odd_th[0][0]==eve_th[0][0]:
        if odd_th[0][1]>eve_th[0][1]:
            odd_ = odd_th[0][1]
            eve_ = eve_th[1][1]
        elif odd_th[0][1]<eve_th[0][1]:
            odd_ = odd_th[1][1]
            eve_ = eve_th[0][1]
        else:
            if odd_th[1][1]>=eve_th[1][1]:
                odd_ = odd_th[1][1]
                eve_ = eve_th[0][1]
            else:
                odd_ = odd_th[0][1]
                eve_ = eve_th[1][1] 
    else:
            odd_ = odd_th[0][1]
            eve_ = eve_th[0][1]
    print(n-odd_-eve_)

Solution (Python):
from collections import Counter

N = int(input().strip())
Vs = list(map(int,input().strip().split()))


def get_word_num(Ss):
    hists = {}
    for v in Ss:
        if v in hists.keys():
            hists[v] += 1
        else:
            hists[v] = 1

    return sorted(hists.items(),reverse = True,key = lambda h: h[1])


even_ar = Vs[0::2]
odd_ar = Vs[1::2]


even_hist = get_word_num(even_ar)

odd_hist = get_word_num(odd_ar)

if even_hist[0][0] != odd_hist[0][0]:
    print(N - even_hist[0][1] - odd_hist[0][1])
else:
    if len(even_hist) == 1 and len(odd_hist) == 1:
        print(len(even_ar))
    else:
        print(N - max(even_hist[0][1] + odd_hist[1][1], even_hist[1][1] + odd_hist[0][1]))

Solution (Python):
from collections import Counter

N = int(input().strip())
Vs = list(map(int,input().strip().split()))


def get_word_num(Ss):
    hists = {}
    for v in Ss:
        if v in hists.keys():
            hists[v] += 1
        else:
            hists[v] = 1

    return sorted(hists.items(),reverse = True)


even_ar = Vs[0::2]
odd_ar = Vs[1::2]

even_hist = Counter(even_ar).most_common(2)
odd_hist = Counter(odd_ar).most_common(2)

if even_hist[0][0] != odd_hist[0][0]:
    print(N - even_hist[0][1] - odd_hist[0][1])
else:
    if len(even_hist) == 1 and len(odd_hist) == 1:
        print(len(even_ar))
    else:
        print(N - max(even_hist[0][1] + odd_hist[1][1], even_hist[1][1] + odd_hist[0][1]))

Solution (Python):
from collections import Counter

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

Odd = Counter(S[::2]).most_common()+([(0,0)])
Even = Counter(S[1::2]).most_common()+([(0,0)])

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

Solution (Python):
import collections

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

cnt1=collections.Counter(L[0::2]).most_common(2)
cnt2=collections.Counter(L[1::2]).most_common(2)

if len(cnt1)==1:
    cnt1.append((0,0))
if len(cnt2)==1:
    cnt2.append((0,0))

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

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
v1 = [v[2*i] for i in range(n//2)]
v2 = [v[2*i+1] for i in range(n//2)]
c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
c1most = c1.most_common()[0]
c2most = c2.most_common()[0]
if int(c1most[0]) != int(c2most[0]):
    print(n - int(c1most[1]) - int(c2most[1]))
elif c1most[1] == n//2 and c2most[1] == n//2:
    print(n//2)
elif c1most[1] == n//2:
    print(n//2 - int(c2.most_common()[1][1]))
elif c2most[1] == n//2:
    print(n//2 - int(c1.most_common()[1][1]))
else:
    c1most2 = c1.most_common()[1]
    c2most2 = c2.most_common()[1]
    if int(c1most2[1]) >= int(c2most2[1]):
        print(n - int(c1most2[1]) - int(c2most[1]))
    else:
        print(n - int(c2most2[1]) - int(c1most[1]))