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 /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Accepted

Solution code:
n, = (int(x) for x in input().split())
vi_arr = [int(x) for x in input().split()]
odd_dict = {"a":0}
even_dict = {"a":0}
for i, vi in enumerate(vi_arr):
    if i%2 == 0:
        idict = odd_dict
    else:
        idict = even_dict
    idict.setdefault(vi, 0)
    idict[vi] += 1

odd_hist = sorted(odd_dict.items(), key=lambda x:x[1], reverse=True)
even_hist = sorted(even_dict.items(), key=lambda x:x[1], reverse=True)

max_odd = odd_hist[0][1]
max_even = even_hist[0][1]
if odd_hist[0][0] == even_hist[0][0]:
    if odd_hist[0][1]+even_hist[1][1] > even_hist[0][1]+odd_hist[1][1]:
        max_even = even_hist[1][1]
    else:
        max_odd = odd_hist[1][1]

print(len(vi_arr)-max_odd-max_even)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
V = list(map(int, input().split()))
 
def mode(d):
    return sorted(d.items(), key=lambda x: x[1], reverse=True)
 
if len(set(V)) == 1:
    ans = n // 2
else:
    o = defaultdict(int)
    e = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            e[V[i]] += 1
        else:
            o[V[i]] += 1
    mode_o = mode(o)
    mode_e = mode(e)
    if mode_o[0][0] != mode_e[0][0]:
        ans = n - mode_o[0][1] - mode_e[0][1]
    else:
        ans = min(n - mode_o[0][1] - mode_e[1][1], n - mode_o[1][1] - mode_e[0][1])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=list(map(int,input().split()))
d1=dict()
d2=dict()
for i in range(0,n,2):
  if s[i] not in d1:
    d1[s[i]]=1
  else:
    d1[s[i]]+=1
for i in range(1,n,2):
  if s[i] not in d2:
    d2[s[i]]=1
  else:
    d2[s[i]]+=1
dmk,dm,dmmk,dmm=[],0,[],0
for i in d1.keys():
  if dm<d1[i]:
    dmm=dm
    dmmk=dmk
    dm=d1[i]
    dmk=[i]
  elif d1==d1[i]:
    dmk+=[i]
  elif dmm<d1[i]:
    dmm=d1[i]
    dmmk=[i]
  elif dmm==d1[i]:
    dmmk+=[i]
d1=[dm,dmk,dmm,dmmk]
dmk,dm,dmmk,dmm=[],0,[],0
for i in d2.keys():
  if dm<d2[i]:
    dmm=dm
    dmmk=dmk
    dm=d2[i]
    dmk=[i]
  elif d2==d2[i]:
    dmk+=[i]
  elif dmm<d2[i]:
    dmm=d2[i]
    dmmk=[i]
  elif dmm==d2[i]:
    dmmk+=[i]
d2=[dm,dmk,dmm,dmmk]
if len(d1[1])>1 or len(d2[1])>1 or d1[1]!=d2[1]:
  print(n-d1[0]-d2[0])
else:
  print(n-max(d1[0]+d2[2],d1[2]+d2[0]))

Submission status: Accepted

Solution code:
import collections


def split_even_odd_by_index(target_list):
    odd = []
    even = []
    for i in range(len(target_list)):
        if i % 2 == 0:
            even.append(target_list[i])
        else:
            odd.append(target_list[i])

    return [even, odd]


if __name__ == '__main__':
    n = int(input())
    number_list = list(map(int, input().split()))
    split_list = split_even_odd_by_index(number_list)
    even_list = split_list[0]
    odd_list = split_list[1]

    even_dic = collections.Counter(even_list).most_common()
    odd_dic = collections.Counter(odd_list).most_common()

    even_first = even_dic[0]
    if len(even_dic) != 1:
        even_second = even_dic[1]
    else:
        even_second = (0, 0)

    odd_first = odd_dic[0]
    if len(odd_dic) != 1:
        odd_second = odd_dic[1]
    else:
        odd_second = (0, 0)

    if even_first[0] != odd_first[0]:
        print(len(even_list) - even_first[1] + len(odd_list) - odd_first[1])
    else:
        print(min(len(even_list) - even_first[1] + len(odd_list) - odd_second[1], len(even_list) - even_second[1] + len(odd_list) - odd_first[1]))

Submission status: Accepted

Solution code:
from collections import Counter as ct

n = int(input())
s = input().split()
a = ct(s[::2])
b = ct(s[1::2])
sa = sorted(a.items(), key=lambda x: -x[1])
sb = sorted(b.items(), key=lambda x: -x[1])
if sa[0][0] == sb[0][0]:
    if len(sa)*len(sb)==1:
        dt=n//2
    elif sa[0][1] - sa[1][1] < sb[0][1] - sb[1][1] or len(sb)==1:
        dt = sa[1][1] + sb[0][1]
    else:
        dt = sa[0][1] + sb[1][1]
else:
    dt = sa[0][1] + sb[0][1]
print(sum([x for x in a.values()]+[y for y in b.values()])-dt)

Submission status: Accepted

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
vo=v[0::2]
ve=v[1::2]
co=collections.Counter(vo)
ce=collections.Counter(ve)
cmo=co.most_common()
cme=ce.most_common()
ans=n-cmo[0][1]-cme[0][1]
if cmo[0][0]==cme[0][0]:
    if cmo[0][1]>cme[0][1]:
       if cmo[0][1]!=n//2:
           ans=n-cmo[0][1]-cme[1][1]
    elif cmo[0][1]<cme[0][1]:
        if cme[0][1]!=n//2:
            ans=n-cmo[1][1]-cme[0][1]
    else:
        if cmo[0][1]==n//2:
            ans=n//2
        else:
            ans=n-cmo[0][1]-max(cmo[1][1],cme[1][1])
print(ans)

Submission status: Accepted

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

vv = [[], []]
for i in range(n):
    vv[i % 2].append(v[i])

import collections
items0 = sorted(collections.Counter(vv[0]).items(), key=lambda x: -x[1])
items1 = sorted(collections.Counter(vv[1]).items(), key=lambda x: -x[1])
key0 = [x[0] for x in items0]
key1 = [x[0] for x in items1]
val0 = [x[1] for x in items0]
val1 = [x[1] for x in items1]

ans = n - val0[0] - val1[0]

if key0[0] == key1[0]:
    tmp0=tmp1=1000000000000000
    if len(items0) > 1:
        tmp0 = n - val0[1] - val1[0]
    if len(items1) > 1:
        tmp1 = n - val0[0] - val1[1]
    ans = min(tmp0, tmp1)
    if len(items0) == 1 and len(items1) == 1:
        ans=n//2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

va = v[::2]
vb = v[1::2]

va_ = Counter(va).most_common()
vb_ = Counter(vb).most_common()

if va_[0][0] == vb_[0][0]:
    if len(va_) == 1 or len(vb_) == 1:
        if len(va_) == 1 and len(vb_) == 1:
            print(len(v) // 2)
        elif len(va_) == 1:
            if va_[0][0] == vb_[0][0]:
                print(len(vb) - vb_[1][1])
            else:
                print(len(vb) - vb_[0][1])
        else:
            if va_[0][0] == vb_[0][0]:
                print(len(va) - va_[1][1])
            else:
                print(len(va) - va_[0][1])
        exit()
    if va_[0][1] + vb_[1][1] > va_[1][1] + vb_[0][1]:
        print(len(va) - va_[0][1] + len(vb) - vb_[1][1])
    else:
        print(len(va) - va_[1][1] + len(vb) - vb_[0][1])
else:
    print(len(va) - va_[0][1] + len(vb) - vb_[0][1])

Submission status: Accepted

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

array1 = v[::2]
array2 = v[1::2]

dict1 = {}
dict2 = {}
for i in array1:
  if i not in dict1:
    dict1[i] = 1
  else:
    dict1[i] = dict1[i] + 1

for i in array2:
  if i not in dict2:
    dict2[i] = 1
  else:
    dict2[i] = dict2[i] + 1

sort_array1 = []
sort_array2 = []
for k, v in sorted(dict1.items(), key=lambda x: -x[1]):
    sort_array1.append({k:v})
for k, v in sorted(dict2.items(), key=lambda x: -x[1]):
    sort_array2.append({k:v})

one_num1 = 0
one_num2 = 0

for k1,v1 in sort_array1[0].items():
  if len(sort_array1) != 1:
    one_num1 = len(array1) - v1
  for k2,v2 in sort_array2[0].items():
    if len(sort_array2) != 1:
      one_num2 = len(array2) - v2
    if k1 != k2:
      print(one_num1 + one_num2)
      break

    if len(sort_array1) == 1 and len(sort_array2) == 1:
      print(len(array1))
      break
    if len(sort_array1) == 1:
      for k,v in sort_array2[1].items():
        two_num2 = v
      print(1+two_num2)
      break
    if len(sort_array2) == 1:
      for k,v in sort_array1[1].items():
        two_num1 = v
      print(1+two_num1)
      break

    for k,v in sort_array1[1].items():
      two_num1 = len(array1) - v
    for k,v in sort_array2[1].items():
      two_num2 = len(array2) - v
    if two_num1 <= two_num2:
      print (one_num2 + two_num1)
    else:
      print (one_num1 + two_num2)

Submission status: Accepted

Solution code:
import collections as col
n = int(input())
s = list(map(int,input().split()))
t = s[0::2]
r = s[1::2]
a = col.Counter(t)
b = col.Counter(r)
a = sorted(a.items(), key=lambda x:x[1], reverse=True)
b = sorted(b.items(), key=lambda x:x[1], reverse=True)
a.append((-1,0))
b.append((-1,0))
if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    if a[1][1] > b[1][1]:
        print(n - a[1][1] - b[0][1])
    else:
        print(n - a[0][1] - b[1][1])

Submission status: Accepted

Solution code:
n = int(input())
v_list = list(map(int, input().split()))
nums_even = {-1: 0}
nums_odd = {-1: 0}
for i, v in enumerate(v_list):
    if i % 2 == 0:
        nums_even.setdefault(v, 0)
        nums_even[v] += 1
    else:
        nums_odd.setdefault(v, 0)
        nums_odd[v] += 1
even_max = -1
even_max2 = -1
for key, val in nums_even.items():
    if val > nums_even[even_max]:
        even_max2 = even_max
        even_max = key
    elif val > nums_even[even_max2]:
        even_max2 = key
odd_max = -1
odd_max2 = -1
for key, val in nums_odd.items():
    if val > nums_odd[odd_max]:
        odd_max2 = odd_max
        odd_max = key
    elif val > nums_odd[odd_max2]:
        odd_max2 = key
if even_max != odd_max:
    print(n - nums_even[even_max] - nums_odd[odd_max])
else:
    m = max(nums_even[even_max] + nums_odd[odd_max2], nums_even[even_max2] + nums_odd[odd_max])
    print(n - m)

Submission status: Accepted

Solution code:
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_e).most_common(2)
cnt_e = Counter(list_o).most_common(2)

if cnt_o[0][0] == cnt_e[0][0]:
    if len(cnt_o) == 1 and len(cnt_e) == 1:
        print(int(n/2))
    else:
        print(n-cnt_o[0][1]-max(cnt_o[1][1],cnt_e[1][1]))
else:
    print(n-cnt_o[0][1]-cnt_e[0][1])

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

def solve():
    n = int(input())
    V = [None]
    V.extend(list(map(int, input().split(" "))))
    
    # 1種類の数字で構成されているか？
    tmp = V[1]
    flag = True
    for i in range(2, n+1):
        if tmp == V[i]:
            continue
        flag = False
        break
    if flag:
        print(int(n/2))
        return

    # 奇数番目のもので、最も多い数字は？
    odd_dict = {}
    for i in range(1, n+1, 2):
        # 奇数番目のもので、最も多い数字を調べる
        if V[i] in odd_dict.keys():
            odd_dict[V[i]] += 1
            continue
        odd_dict[V[i]] = 1

    # 偶数番目のもので、最も多い数字は？
    even_dict = {}
    for i in range(2, n+1, 2):
        # 偶数番目のもので、最も多い数字を調べる
        if V[i] in even_dict.keys():
            even_dict[V[i]] += 1
            continue
        even_dict[V[i]] = 1

    sorted_odds = sorted(odd_dict.items(), key=lambda x: x[1], reverse=True)
    sorted_evens = sorted(even_dict.items(), key=lambda x: x[1], reverse=True)

    # 変換後、1種類の数字にならないように気を付ける
    if sorted_evens[0][0] == sorted_odds[0][0]:
        if len(sorted_odds) == 1:
            ans = n - sorted_odds[0][1] - sorted_evens[1][1]
        elif len(sorted_evens) == 1:
            ans = n - sorted_odds[1][1] - sorted_evens[0][1]
        else:
            ans1 = n - sorted_odds[0][1] - sorted_evens[1][1]
            ans2 = n - sorted_odds[1][1] - sorted_evens[0][1]
            ans = min(ans1, ans2)
    else:
        ans = n - sorted_evens[0][1] - sorted_odds[0][1]

    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from collections import Counter as c

N = int(input())
V = list(map(int,input().split()))
ev = c(V[::2]).most_common(2)
od = c(V[1::2]).most_common(2)

if ev[0][0] == od[0][0]:
    if len(ev) == 1 and len(od) == 1:
        print(N//2)
    else:
        print(N-max(ev[0][1]+od[1][1],ev[1][1]+od[0][1]))
else:
    print(N-ev[0][1]-od[0][1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N = int(input())
	V = input().split(" ")
	
	K = []
	G = []
	for i, val in enumerate(V):
		if i % 2 == 0:
			G.append(val)
		else:
			K.append(val)
	
	k = collections.Counter(K)
	k = sorted(k.items(), key=lambda x:x[1], reverse=True)
	g = collections.Counter(G)
	g = sorted(g.items(), key=lambda x:x[1], reverse=True)
	
	aaa, bbb = k[0]
	ccc, ddd = g[0]
	eee = -1
	fff = -1
	ggg = -1
	hhh = -1
	if len(k) > 1:
		eee, fff = k[1]
	if len(g) > 1:
		ggg, hhh = g[1]
	
	if aaa == ccc:
		if bbb > ddd and ggg != -1:
			g[0] = (ggg, hhh)
			g[1] = (ccc, ddd)
		elif bbb < ddd and eee != -1:
			k[0] = (eee, fff)
			k[1] = (aaa, bbb)
		elif ggg != -1:
			if fff >= hhh:
				k[0] = (eee, fff)
				k[1] = (aaa, bbb)
			else:
				g[0] = (ggg, hhh)
				g[1] = (ccc, ddd)
	
	#print(k)
	#print(g)
		
	ans = 0
	sono1 = 0
	sono2 = 0
	for a, b in enumerate(k):
		i, j = b
		if a == 0:
			sono1 = i
			continue
		ans += j
	
	for a, b in enumerate(g):
		i, j = b
		if a == 0:
			sono2 = i
			continue
		ans += j
		
	if ans > 0:
		print(ans)
	elif sono1 != sono2:
		print(ans)
	else:
		print(len(K))
		
		
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*10**5
b=[0]*10**5
v=list(map(int,input().split()))
v1=[]
v2=[]
if len(set(v))==1:
    print(n//2)
else:
    for i in range(n):
        if i%2==0:
            a[v[i]-1]+=1
            v1.append(v[i])
        else:
            b[v[i]-1]+=1
            v2.append(v[i])
    max1=0
    max2=0
    for j in range(len(a)):
        if max1<a[j]:
            max1=a[j]
            c1=j
    for k in range(len(b)):
        if max2<b[k]:
            max2=b[k]
            c2=k
    if c1!=c2:
        print(len(v1)+len(v2)-max1-max2)
    else:
        a=sorted(a)
        b=sorted(b)
        print(min(n-max1-b[-2],n-max2-a[-2]))

Submission status: Accepted

Solution code:
n = int(input())
V = list(map(int,input().split()))
a = [0]*100000
b = [0]*100000
v1=[]
v2=[]

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

else:
    for i in range(n):
        if i%2 == 0:
            a[V[i]-1] += 1
            v1.append(V[i])
        else:
            b[V[i]-1] += 1
            v2.append(V[i])

    max1 = 0
    max2 = 0

    for j in range(len(a)):
        if max1 < a[j]:
            max1 = a[j]
            c1 = j
    for k in range(len(b)):
        if max2 < b[k]:
            max2=b[k]
            c2=k

    if c1 != c2:
        print(n-max1-max2)
    else:
        a.sort()
        b.sort()
        print(min(n-max1-b[-2],n-max2-a[-2]))

Submission status: Accepted

Solution code:
from collections import Counter
from sys import stdin
n = int(stdin.readline().rstrip())
vl = [int(_) for _ in stdin.readline().rstrip().split()]
odds=Counter(vl[0::2]).most_common()
evens=Counter(vl[1::2]).most_common()
odd_f = odds[0]
even_f = evens[0]
if odd_f != even_f:
    print(n-odd_f[1]-even_f[1])
else:
    try:
        odd_se = odds[1]
    except:
        odd_se = [0,0]
    try:
        even_se = evens[1]
    except:
        even_se = [1,0]
    print(n - max(odd_f[1]+even_se[1], odd_se[1]+even_f[1]))

Submission status: Accepted

Solution code:
n=int(input())
v=input().split()

m=[{"even":0},{"odd":0}]

for i in range(0, len(v)):
	if v[i] not in m[i%2]:
		m[i%2][v[i]] = 1
	else:
		m[i%2][v[i]] += 1

l = [sorted(z.items(), key=lambda x: x[1], reverse=True) for z in m]

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

Submission status: Accepted

Solution code:
import collections

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

e = [v[i] for i in range(n) if i % 2 == 0]
o = [v[i] for i in range(n) if i % 2 == 1]

c_e = collections.Counter(e).most_common()
c_o = collections.Counter(o).most_common()

e_0 = c_e[0]
o_0 = c_o[0]

if e_0 != o_0:
    print(len(e) - e_0[1] + len(o) - o_0[1])
else:
    if len(c_e) == 1:
        e_1 = [0, 0]
    else:
        e_1 = c_e[1]
    if len(c_o) == 1:
        o_1 = [0, 0]
    else:
        o_1 = c_o[1]
    print(min(len(e)-e_0[1]+len(o)-o_1[1], len(e)-e_1[1]+len(o)-o_0[1]))

Submission status: Accepted

Solution code:
def larger(x, y):
	if x > y: return x
	else: return y

n = int(raw_input())
v = map(int, raw_input().split())
lst1 = []
lst2 = []
for i in range(0, n):
	if i % 2 == 1: lst1.append(v[i])
	else: lst2.append(v[i])
lst1.sort()
lst2.sort()
firstnumber1 = 0
firstcount1 = 0
secondnumber1 = 0
secondcount1 = 0
firstnumber2 = 0
firstcount2 = 0
secondnumber2 = 0
secondcount2 = 0
tmp1 = lst1[0]
cnt1 = 1
tmp2 = lst2[0]
cnt2 = 1

for i in range(1, n/2):
	if tmp1 != lst1[i]:
		if firstcount1 < cnt1:
			secondnumber1 = firstnumber1
			secondcount1 = firstcount1
			firstnumber1 = tmp1
			firstcount1 = cnt1
		elif secondcount1 < cnt1:
			secondnumber1 = tmp1
			secondcount1 = cnt1
		tmp1 = lst1[i]
		cnt1 = 1
	else: cnt1 += 1
	if tmp2 != lst2[i]:
		if firstcount2 < cnt2:
			secondnumber2 = firstnumber2
			secondcount2 = firstcount2
			firstnumber2 = tmp2
			firstcount2 = cnt2
		elif secondcount2 < cnt2:
			secondnumber2 = tmp2
			secondcount2 = cnt2
		tmp2 = lst2[i]
		cnt2 = 1
	else: cnt2 += 1
if firstcount1 < cnt1:
	secondnumber1 = firstnumber1
	secondcount1 = firstcount1
	firstnumber1 = tmp1
	firstcount1 = cnt1
elif secondcount1 < cnt1:
	secondnumber1 = tmp1
	secondcount1 = cnt1
if firstcount2 < cnt2:
	secondnumber2 = firstnumber2
	secondcount2 = firstcount2
	firstnumber2 = tmp2
	firstcount2 = cnt2
elif secondcount2 < cnt2:
	secondnumber2 = tmp2
	secondcount2 = cnt2

if firstnumber1 == firstnumber2:
	print n - larger(secondcount1+firstcount2, firstcount1+secondcount2)
else:
	print n - firstcount1 - firstcount2

Submission status: Accepted

Solution code:
import collections

N = int(input())
v = list(map(int,input().rstrip().split()))
list_odd = v[0::2]
list_even = v[1::2]

odd_count = collections.Counter(list_odd).most_common()
even_count = collections.Counter(list_even).most_common()

if len(odd_count) == 1 and len(even_count) == 1:
    if odd_count[0][0] == even_count[0][0]:
        print(N//2)
    else:
        print(0)
elif odd_count[0][0] != even_count[0][0]:
    print(N-odd_count[0][1]-even_count[0][1])
elif len(odd_count) == 1:
    print(N//2-even_count[1][1])
elif len(even_count) == 1:
    print(N//2-odd_count[1][1])
else:
    print(min(N-odd_count[0][1]-even_count[1][1], N-even_count[0][1]-odd_count[1][1]))

Submission status: Accepted

Solution code:
import collections
n = int(input())
vs = list(map(int, input().split()))
veven = vs[0:n:2]
vodd = vs[1:n:2]
mins = []
flag = False
if veven == vodd and len(set(vodd)) == 1:
    print(n //2)
else:
    ce = collections.Counter(veven)
    co = collections.Counter(vodd)
    cem = ce.most_common()
    com = co.most_common()
    for i, j in cem:
        for k, h in com:
            if i != k:
                mins.append(n-j-h)
                flag = True
                break
        if flag:
            break
    flag = False
    for i, j in com:
        for k, h in cem:
            if i != k:
                mins.append(n-j-h)
                flag = True
                break
        if flag:
            break
    print(min(mins))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import collections
n = int(input())
lst = list(map(int,input().split()))
odd = [0]*(n//2)
even = [0]*(n//2)
leng = 0
for i in range(n//2):
    odd[i]=lst[leng]
    leng+=1
    even[i]=lst[leng]
    leng+=1
o1 = collections.Counter(odd).most_common()[0]
e1 = collections.Counter(even).most_common()[0]
if o1[0] != e1[0]:
    ans = n - (o1[1] + e1[1])
else:
    try:
        o2 = collections.Counter(odd).most_common()[1]
    except:
        o2 = [0,0]
    try:
        e2 = collections.Counter(even).most_common()[1]
    except:
        e2 = [1,0]
    ans = n - max(o1[1]+e2[1],o2[1]+e1[1])

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()
v = LIST()

v_odd = [v[i] for i in range(n) if i % 2 == 1]
v_even = [v[i] for i in range(n) if i % 2 == 0]

count_odd = Counter(v_odd)
count_even = Counter(v_even)

if count_odd.most_common()[0][0] != count_even.most_common()[0][0]:
	print(int(n/2-count_odd.most_common()[0][1] + n/2 - count_even.most_common()[0][1]))
else:
	if len(count_odd) == 1 and len(count_even) == 1:
		print(int(n/2))
	else:
		if len(count_odd) == 1:
			print(int(n/2 - count_even.most_common()[1][1]))
		elif len(count_even) == 1:
			print(int(n/2 - count_odd.most_common()[1][1]))
		else:
			tmp1 = int(n/2-count_odd.most_common()[1][1] + n/2 - count_even.most_common()[0][1])
			tmp2 = int(n/2-count_odd.most_common()[0][1] + n/2 - count_even.most_common()[1][1])
			print(min(tmp1, tmp2))

Submission status: Accepted

Solution code:
import collections
def solve():
  n = int(input())
  odd = []
  even = []
  a = list(int(i) for i in input().split())
  for i in range(n):
    if i%2 == 0:
      odd.append(a[i])
    else:
      even.append(a[i])
  ans = 0
  c1 = collections.Counter(odd)
  c2 = collections.Counter(even)
  n1 = len(odd)
  n2 = len(even)
  if len(set(a)) == 1:
    print(n//2)
    exit()
  ans = 10**12
  if c1.most_common()[0][0]  ==   c2.most_common()[0][0]:
    if not len(c2) ==1:
     ans = min((n-c1.most_common()[0][1]-c2.most_common()[1][1]),ans)
    if not len(c1) ==1:
     ans = min((n-c2.most_common()[0][1]-c1.most_common()[1][1]),ans)
  else:
         ans = min(ans,(n1-c1.most_common()[0][1]+n2-c2.most_common()[0][1]))
  print(ans)
                  
                  
solve()

Submission status: Accepted

Solution code:
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 len(set(v)) == 1:
    ans = n // 2
elif e[0][0] != o[0][0]:
    ans = n - e[0][1] - o[0][1]
else:
    ans = min(n - e[0][1] - o[1][1],
              n - e[1][1] - o[0][1])
print(ans)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
import bisect
from collections import deque
from collections import defaultdict
#from math import factorial
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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:
    # vEを2番目の最頻値に書き換え
    if len(lmodeE) == 1:
        ans1 = int(n/2)
    else:
        ans1 = n - lmodeE[1][1] - nmodeO
    # vOを2番目の最頻値に書き換え
    if len(lmodeO) == 1:
        ans2 = int(n/2)
    else:
        ans2 = n - nmodeE - lmodeO[1][1]
    # 出力
    print(min(ans1,ans2))
else:
    print(n-nmodeE-nmodeO)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])))