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

map_even_elem_dict = {}
map_odd_elem_dict = {}
for i,e in enumerate(v):
    if i % 2 == 0:
        if e in map_even_elem_dict:
            map_even_elem_dict[e] += 1
        else:
            map_even_elem_dict[e] = 1
    if i % 2 == 1:
        if e in map_odd_elem_dict:
            map_odd_elem_dict[e] += 1
        else:
            map_odd_elem_dict[e] = 1

even_dict_list = []
odd_dict_list = []

for k, v in map_even_elem_dict.items():
    even_dict_list.append((v, k))
    
for k, v in map_odd_elem_dict.items():
    odd_dict_list.append((v, k))
    
even_dict_list.sort()
odd_dict_list.sort()

max_even_occurence, max_even_elem = even_dict_list[-1]
max_odd_occurence, max_odd_elem = odd_dict_list[-1]

if max_even_elem != max_odd_elem:
    print(n // 2 - max_even_occurence + n // 2 - max_odd_occurence)
else:
    if max_even_occurence > max_odd_occurence:
        second_max_odd_occurence, _ = odd_dict_list[-2]
        print(n // 2 - max_even_occurence + n // 2 - second_max_odd_occurence)
    elif max_even_occurence < max_odd_occurence:
        second_max_even_occurence, _ = even_dict_list[-2]
        print(n // 2 - second_max_even_occurence + n // 2 - max_odd_occurence)
    else:
        if max_even_occurence == n // 2:
            print(n // 2)
        else:
            second_max_even_occurence, _ = even_dict_list[-2]
            second_max_odd_occurence, _ = odd_dict_list[-2]
            print(n // 2 - max_even_occurence + n // 2 - max(second_max_even_occurence, second_max_odd_occurence))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

  for i in range(len(l)):
    if i%2==0:
      l1.append(l[i])
    else:
      l2.append(l[i])

  l1.sort()
  l2.sort()

  a=[]
  b=[]

  p=l1[0]
  c=1
  mx=1
  for x in l1[1:]:
    if x==p:
      c+=1
    else:
      a.append([p,c])
      c=1
      p=x
  a.append([p,c])

  p=l2[0]
  c=1
  mx=1
  for x in l2[1:]:
    if x==p:
      c+=1
    else:
      b.append([p,c])
      c=1
      p=x
  b.append([p,c])

  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 len(a)==1 and len(b)==1:
      return n//2
    return min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1])
  return n-a[0][1]-b[0][1]

print(main())

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

  for i in range(len(l)):
    if i%2==0:
      l1.append(l[i])
    else:
      l2.append(l[i])

  l1.sort()
  l2.sort()

  a=[]
  b=[]

  p=l1[0]
  c=1
  mx=1
  for x in l1[1:]:
    if x==p:
      c+=1
    else:
      a.append([p,c])
      c=1
      p=x
  a.append([p,c])

  p=l2[0]
  c=1
  mx=1
  for x in l2[1:]:
    if x==p:
      c+=1
    else:
      b.append([p,c])
      c=1
      p=x
  b.append([p,c])

  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 len(a)==1 and len(b)==1:
      return n//2
    # if a[0][1]<b[0][1]:
    #   return n-a[1][1]-b[0][1]
    # return n-a[0][1]-b[1][1]
    else:
      return min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1])
  return n-a[0][1]-b[0][1]

print(main())

Submission status: Accepted

Solution code:
import collections
n = int(input())
v_array = list(map(int, input().split()))

c1 = collections.Counter(v_array[0::2])
c2 = collections.Counter(v_array[1::2])
c1_num, c1_count = c1.most_common()[0]
_, c1_second = c1.most_common()[1] if len(c1) > 1 else [0, 0]
c2_num, c2_count = c2.most_common()[0]
_, c2_second = c2.most_common()[1] if len(c2) > 1 else [0, 0]
if c1_num != c2_num:
    ans = n - (c1_count + c2_count)

else:
    ans = n - max(c1_count + c2_second, c1_second + c2_count)

print(ans)

Submission status: Accepted

Solution code:

n = int(input())
odd = {}
eve = {}

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

for i in range(n):
    
    new_v = nums[i]
    
    if (i % 2 == 0):

        if new_v in odd:
            odd[new_v] += 1

        else:
            odd[new_v] = 1

    else:

        if new_v in eve:
            eve[new_v] += 1

        else:
            eve[new_v] = 1



odd_m = max(odd , key=odd.get)
eve_m = max(eve , key=eve.get)

odd_c = odd.copy()
eve_c = eve.copy()

del odd_c[odd_m]
del eve_c[eve_m]

if len(odd_c) == 0:
    odd_mt = 0
else:
    odd_mt = max(odd_c , key=odd.get)

if len(eve_c) == 0:
    eve_mt = 0
else:
    eve_mt = max(eve_c , key=eve.get)

odd[0] = 0
eve[0] = 0


if odd_m != eve_m:
    print (n - odd[odd_m] - eve[eve_m])

elif odd[odd_m] + eve[eve_mt] > odd[odd_mt] + eve[eve_m] :
    print (n - odd[odd_m] - eve[eve_mt])

else:
    print (n - odd[odd_mt] - eve[eve_m])

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    V = list(map(int, input().split(" ")))
    
    evens = V[::2]
    odds = V[1::2]

    import collections
    evenMosts = collections.Counter(evens).most_common()
    oddMosts = collections.Counter(odds).most_common()
    evenM = evenMosts[0]
    oddM = oddMosts[0]

    if len(evenMosts) == 1:
        if len(oddMosts) == 1:
            if evenM[0] != oddM[0]:
                print(0)
            else:
                print(evenM[1])
            return
        else:
            print(len(odds)-oddM[1])
            return
    else:
        if len(oddMosts) == 1:
            print(len(evens)-evenM[1])
            return
        else:
            if evenM[0] == oddM[0]: 
                if (len(evens)-evenMosts[1][1]+len(odds)-oddM[1]) <= (len(evens)-evenM[1] + len(odds)-oddMosts[1][1]):
                    evenM = evenMosts[1]
                else:
                    oddM = oddMosts[1]
            print((len(evens)-evenM[1])+(len(odds)-oddM[1]))
            return
    


if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

# count value
oc = Counter(v[::2]).most_common(2)
ec = Counter(v[1::2]).most_common(2)

# oとeの最頻値が異なる場合、n-各最頻値の数が答え
if oc[0][0] != ec[0][0]:
    print(n - oc[0][1] - ec[0][1])
else:
    if len(oc) == 1 or len(ec) == 1:
        print(n//2)
    else:
        print(n - max((oc[0][1] + ec[1][1]), (ec[0][1] + oc[1][1])))

Submission status: Accepted

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

v1=Counter(v[::2])
v2=Counter(v[1::2])
lenv=len(v)
c1=v1.most_common()
c2=v2.most_common()

if c1[0][0]!=c2[0][0]:
    print(lenv-c1[0][1]-c2[0][1])
else:
    if c1[0][1]==c2[0][1]==len(v)//2:
        print(lenv//2)
    elif c1[0][1]==len(v)//2:
        print(lenv//2-c2[1][1])
    elif c2[0][1]==len(v)//2:
        print(lenv//2-c1[1][1])    
    else:
        print(lenv-max(c1[0][1]+c2[1][1],c1[1][1]+c2[0][1]))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

  f=True
  for x in l:
    if f:
      f=False
      l1.append(x)
    else:
      f=True
      l2.append(x)

  l1.sort()
  l2.sort()

  l3=[]
  l4=[]

  a=l1[0]
  c=1
  for x in l1[1:]:
    if a==x:
      c+=1
    else:
      l3.append([a,c])
      a=x
      c=1
  l3.append([a,c])

  a=l2[0]
  c=1
  for x in l2[1:]:
    if a==x:
      c+=1
    else:
      l4.append([a,c])
      a=x
      c=1
  l4.append([a,c])

  l3=sorted(l3,key=lambda x:x[1],reverse=True)
  l4=sorted(l4,key=lambda x:x[1],reverse=True)

  if l3[0][0]==l4[0][0]:
    if len(l3)==1 and len(l4)==1:
      return n//2
    elif len(l3)==1:
      return n-l3[0][1]-l4[1][1]
    elif len(l4)==1:
      return n-l3[1][1]-l4[0][1]
    else:
      return min(n-l3[0][1]-l4[1][1],n-l3[1][1]-l4[0][1])
  else:
    return n-l3[0][1]-l4[0][1]

print(main())

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
V = list(map(int,input().split()))
zero = Counter(V[::2]).most_common()
one = Counter(V[1::2]).most_common()
if zero[0][0] != one[0][0]:
    print(N-zero[0][1]-one[0][1])
else:
    if len(zero) == 1 and len(one) == 1:
        print(N//2)
    elif len(zero) == 1:
        print(N-zero[0][1]-one[1][1])
    elif len(one) == 1:
        print(N-zero[1][1]-one[0][1])
    else:
        print(min(N-zero[1][1]-one[0][1],N-zero[0][1]-one[1][1]))

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int,input().split()))
b = []
c = []

for i, vv in enumerate(v):
    if i%2 == 0:
        b.append(vv)
    else:
        c.append(vv)

b_set = {}
c_set = {}

for bb in b:
    if not bb in b_set.keys():
        b_set[bb] = 1
    else:
        b_set[bb] += 1

for cc in c:
    if not cc in c_set.keys():
        c_set[cc] = 1
    else:
        c_set[cc] += 1

b_sorted = []
c_sorted = []

for key, value in b_set.items():
    b_sorted.append([value,key])
for key, value in c_set.items():
    c_sorted.append([value,key])

b_sorted = sorted(b_sorted, reverse=True)
b_sorted += [[0,0]]
c_sorted = sorted(c_sorted, reverse=True)
c_sorted += [[0,0]]


if b_sorted[0][1] != c_sorted[0][1]:
    ans = n - b_sorted[0][0] - c_sorted[0][0]
else:
    try1 = n - b_sorted[1][0] - c_sorted[0][0]
    try2 = n - b_sorted[0][0] - c_sorted[1][0]
    ans = min(try1,try2)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1

    n = 1000000000
    emk = None
    ev1 = None
    ev2 = 0
    for ek, ev in even.items():
        if emk is None:
            emk = ek
            ev1 = ev
        elif ev > ev1:
            emk = ek
            ev2 = ev1
            ev1 = ev
        elif ev > ev2:
            ev2 = ev

    omk = None
    ov1 = None
    ov2 = 0
    for ok, ov in odd.items():
        if omk is None:
            omk = ok
            ov1 = ov
        elif ov > ov1:
            omk = ok
            ov2 = ov1
            ov1 = ov
        elif ov > ov2:
            ov2 = ov

    if emk != omk:
        n = min(n, N - ev1 - ov1)
    else:
        n = min(n, N - ev1 - ov2, N - ev2 - ov1)

    print(n)

main()

Submission status: Accepted

Solution code:
n=int(input())
even=[0]*(int(n/2))
odd=[0]*(int(n/2))
inp=list(map(int,input().split()))
for i in range(n):
    if i%2==0:
        even[int(i/2)]=inp[i]
    else:
        odd[int((i-1)/2)]=inp[i]
even.sort()
odd.sort()
def count(lst):
    tmp=cnt=maxcnt=maxi=precnt=0
    for i in lst:
        if tmp==i:
            cnt+=1      
        else:
            if cnt>maxcnt:
                precnt=maxcnt;maxcnt=cnt;maxi=tmp
            else:
                precnt=max(cnt,precnt)
            cnt=1;tmp=i
    if cnt>maxcnt:
        precnt=maxcnt;maxcnt=cnt;maxi=tmp
    else:
        precnt=max(cnt,precnt)
    return maxcnt,precnt,maxi
        
        
ev,od=count(even),count(odd)
if n==2:
    if ev==od:
        print(1)
    else:
        print(0)
    
elif ev[2]!=od[2]:
    print(n-ev[0]-od[0])
else:
    a=n-ev[0]-od[1]
    b=n-od[0]-ev[1]
    print(min(a,b))

Submission status: Accepted

Solution code:
import collections as cl

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

odd_lst = [v_lst[i] for i in range(0, len(v_lst), 2)]
even_lst = [v_lst[i] for i in range(1, len(v_lst), 2)]

odd_value_dic = cl.Counter(odd_lst)
even_value_dic = cl.Counter(even_lst)

odd_value_tup_lst = sorted(odd_value_dic.items(), key=lambda x: x[1], reverse=True)
even_value_tup_lst = sorted(even_value_dic.items(), key=lambda x: x[1], reverse=True)


odds_first = odd_value_tup_lst[0][1]
evens_first = even_value_tup_lst[0][1]
ans = n - odds_first - evens_first
"""
print(odd_value_tup_lst)
print(even_value_tup_lst)
print()
"""

if odd_value_tup_lst[0][0] == even_value_tup_lst[0][0]:
    if len(odd_value_tup_lst) == len(even_value_tup_lst) == 1:
        ans = odd_value_tup_lst[0][1]
    elif len(odd_value_tup_lst) == 1:
        evens_first = even_value_tup_lst[1][1]
        ans = n - evens_first
    elif len(even_value_tup_lst) == 1:
        odds_first = odd_value_tup_lst[1][1]
        ans = n - odds_first
    elif odds_first - odd_value_tup_lst[1][1] > evens_first - even_value_tup_lst[1][1]:
        evens_first = even_value_tup_lst[1][1]
        ans = n - odds_first - evens_first
    else:
        odds_first = odd_value_tup_lst[1][1]
        ans = n - odds_first - evens_first

print(ans)

Submission status: Accepted

Solution code:
import collections

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

odd_l = []
even_l = []

if v.count(v[0]) == n:
    ans = n // 2
else:
    for i in range(0, n, 2):
        odd_l.append(v[i])
        even_l.append(v[i+1])

    odd_c = collections.Counter(odd_l)
    even_c = collections.Counter(even_l)

    odd = odd_c.most_common()[0][1]
    odd_num = odd_c.most_common()[0][0]

    even = even_c.most_common()[0][1]
    even_num = even_c.most_common()[0][0]

    if odd_num != even_num:
        ans = n - (odd + even)
    else:
        odd = odd_c.most_common()[1][1]
        even = even_c.most_common()[0][1]
        ans_change_odd = n - (odd + even)

        odd = odd_c.most_common()[0][1]
        even = even_c.most_common()[1][1]
        ans_change_even  = n - (odd + even)

        ans = min(ans_change_odd, ans_change_even)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
if len(set(v))==1:print(n//2)
else:
    v.extend([0,0])
    voc=Counter(v[::2]).most_common(2)
    vec=Counter(v[1::2]).most_common(2)
    if len(voc)==len(vec)==1:print(0)
    elif voc[0][0]==vec[0][0]:print(n-max(voc[0][1]+vec[1][1],voc[1][1]+vec[0][1]))
    else:print(n-voc[0][1]-vec[0][1])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=II()
  l=LI()

  l1=[]
  l2=[]

  for i in range(len(l)):
    if i%2==0:
      l1.append(l[i])
    else:
      l2.append(l[i])

  l1.sort()
  l2.sort()

  a1=[l1[0],1]
  a2=[0,0]
  b1=[l2[0],1]
  b2=[0,0]

  _a=l1[0]
  c1=1
  for x in l1[1:]:
    if _a==x:
      c1+=1
    else:
      if c1>a1[1]:
        if a1[0]!=l1[0]:
          a2[0]=a1[0]
          a2[1]=a1[1]
        a1[0]=_a
        a1[1]=c1
      elif c1>a2[1]:
        if a1[0]!=_a:
          a2[0]=_a
          a2[1]=c1
      _a=x
      c1=1
  if c1>a1[1]:
    if a1[0]!=l1[0]:
      a2[0]=a1[0]
      a2[1]=a1[1]
    a1[0]=_a
    a1[1]=c1
  elif c1>a2[1]:
    if a1[0]!=_a:
      a2[0]=_a
      a2[1]=c1

  _b=l2[0]
  c2=1
  for x in l2[1:]:
    if _b==x:
      c2+=1
    else:
      if c2>b1[1]:
        if b1[0]!=l2[0]:
          b2[0]=b1[0]
          b2[1]=b1[1]
        b1[0]=_b
        b1[1]=c2
      elif c2>b2[1]:
        if b1[0]!=_b:
          b2[0]=_b
          b2[1]=c2
      _b=x
      c2=1
  if c2>b1[1]:
    if b1[0]!=l2[0]:
      b2[0]=b1[0]
      b2[1]=b1[1]
    b1[0]=_b
    b1[1]=c2
  elif c2>b2[1]:
    if b1[0]!=_b:
      b2[0]=_b
      b2[1]=c2

  if a1[0]!=b1[0]:
    return len(l1)-a1[1]+len(l2)-b1[1]
  else:
    return min(len(l1)-a1[1]+len(l2)-b2[1],len(l1)-a2[1]+len(l2)-b1[1])

# main()
print(main())

Submission status: Accepted

Solution code:
import collections

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

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

else:
    v_odd = collections.Counter(v[0::2])
    v_even = collections.Counter(v[1::2])

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

    if v_odd[0][0] == v_even[0][0]:
        if v_odd[1][1] > v_even[1][1]:
            print(n - v_odd[1][1] - v_even[0][1])
        else:
            print(n - v_odd[0][1] - v_even[1][1])
 
    else:
        print(n - v_odd[0][1] - v_even[0][1])

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())
V = list(mi())

oddl = V[0::2]
evenl = V[1::2]

#oddl, evenlに含まれる数をバケットソートする。個数をバケツに入れる
obuckets = [0]*(10**5 + 1)
ebuckets = [0]*(10**5 + 1)
for o in oddl:
  obuckets[o] += 1
for e in evenl:
  ebuckets[e] += 1

o1cnt = max(obuckets)
o1 = obuckets.index(o1cnt)
obuckets[o1] = 0

o2cnt = max(obuckets)
o2 = obuckets.index(o2cnt)
obuckets[o2] = 0

e1cnt = max(ebuckets)
e1 = ebuckets.index(e1cnt)
ebuckets[e1] = 0

e2cnt = max(ebuckets)
e2 = ebuckets.index(e2cnt)
ebuckets[e2] = 0

Nd2 = round(N/2) #それぞれの個数
if o1 != e1:
  print(Nd2-o1cnt + Nd2-e1cnt)
else: print(min(Nd2-o1cnt + Nd2-e2cnt, Nd2-o2cnt + Nd2-e1cnt))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v=list(map(int,input().split()))
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0]!=b[0][0]:
    print(n-(a[0][1]+b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))

Submission status: Accepted

Solution code:
import collections


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

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

leven = [x for x in l[::2]]
lodd  = [x for x in l[1::2]]

ce = collections.Counter(leven)
co = collections.Counter(lodd)
ce = sorted(ce.items(), key=lambda x:x[1])
co = sorted(co.items(), key=lambda x:x[1])

if ce[-1][0] != co[-1][0]:
	print(n - ce[-1][1] - co[-1][1])
elif ce[-2][1] > co[-2][1]:
    print(n - ce[-2][1] - co[-1][1])
else:
    print(n - ce[-1][1] - co[-2][1])

Submission status: Accepted

Solution code:
from collections import Counter

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

even = a[1::2]
odd = a[::2]

c_even = Counter(even)
c_odd = Counter(odd)

arr_even = c_even.most_common()
arr_odd = c_odd.most_common()

sum_even = sum(x[1] for x in arr_even)
sum_odd = sum(x[1] for x in arr_odd)

min_sum = sum_even - arr_even[0][1] + n // 2

for i, x in arr_even:
    for j, y in arr_odd:
        if i != j:
            cnt = sum_even - x + sum_odd - y
            min_sum = min(min_sum, cnt)
            break
        else:
            continue

print(min_sum)

Submission status: Accepted

Solution code:
from collections import Counter
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])

c = list(Counter(a).items())
d = list(Counter(b).items())

c.sort(key=lambda x: x[1], reverse = True)
d.sort(key=lambda x: x[1], reverse=True)

if c[0] != d[0]:
    print(n - c[0][1] - d[0][1])
else:
    d1 = c[0][1]
    d2 = d[0][1]
    if len(d) > 1:
        d1 += d[1][1]
    if len(c) > 1:
        d2 += c[1][1]
    print(n - max(d1, d2))

Submission status: Accepted

Solution code:
N = int(input())
L = input().split(" ")

import collections

even = collections.Counter(L[::2]).most_common(2)
odd = collections.Counter(L[1::2]).most_common(2)

if even[0][0] != odd[0][0]:
    print(N - even[0][1] - odd[0][1])
else:
    # even[0][0] == odd[0][0]
    if len(even) == 1 or len(odd) == 1:
        print(N // 2)
    else:
        print(N - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1]))

Submission status: Accepted

Solution code:
import collections

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

v_even = v[::2]
v_odd = v[1::2]

a_even = collections.Counter(v_even)
a_odd = collections.Counter(v_odd)

li_even = a_even.most_common()
li_odd = a_odd.most_common()

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

Submission status: Accepted

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

Dic = [[i,0] for i in range(1,(10**5)+1)]
Dic2 = [[i,0] for i in range(1,(10**5)+1)]
for i in range(n):
    if i%2 == 0:
        Dic[V[i]-1][1] += 1
    else:
        Dic2[V[i]-1][1] += 1
Dic.sort(key = lambda x:x[1],reverse = True)
Dic2.sort(key = lambda x:x[1], reverse = True)
#print(Dic,Dic2)
cn = 0
if Dic[0][0] != Dic2[0][0]:
    cn += n - Dic[0][1] - Dic2[0][1]
else:
    cn += n - max((Dic[0][1]+Dic2[1][1]), (Dic[1][1]+Dic2[0][1]))
print(cn)

Submission status: Accepted

Solution code:
import collections
n = int(input())

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

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

a1 = odd.most_common()[0][1]
if len(odd) >=2:
    a2 = odd.most_common()[1][1]

b1 = even.most_common()[0][1]
if len(even) >= 2:
    b2 = even.most_common()[1][1]

if odd.most_common()[0][0] != even.most_common()[0][0]:
    print(n-a1-b1)
elif len(even) == 1 and len(odd) >= 2:
    print(n-b1-a2)
elif len(odd) == 1 and len(even)>= 2: 
    print(n-a1-b2)
elif len(odd) == 1 and len(even) == 1:
    print(n//2)
elif a1+b2 >= a2+b1:
    print(n-a1-b2)
else:
    print(n-a2-b1)

Submission status: Accepted

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

from collections import Counter

v1 = [v[i] for i in range(len(v)) if i%2 == 0]
v2 = [v[i] for i in range(len(v)) if i%2 != 0]

v1c = Counter(v1)
v1cs = v1c.most_common(1)[0][0]
v1c = sorted(v1c.values())

v2c = Counter(v2)
v2cs = v2c.most_common(1)[0][0]
v2c = sorted(v2c.values())

if v1cs != v2cs:
    ans = sum(v1c[:-1]) + sum(v2c[:-1])
else:
    if len(v1c) == 1 and len(v2c) == 1:
        ans = sum(v2c)
    elif len(v1c) == 1:
        ans = sum(v2c) - v2c[-2]
    elif len(v2c) == 1:
        ans = sum(v1c) - v1c[-2]
    else:
        ans = min(sum(v1c) - v1c[-2] + sum(v2c[:-1]), sum(v1c[:-1]) + sum(v2c) - v2c[-2])

print(ans)

Submission status: Accepted

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

from collections import Counter

v1 = [v[i] for i in range(len(v)) if i%2 == 0]
v2 = [v[i] for i in range(len(v)) if i%2 != 0]

v1c = Counter(v1)
v1cs = v1c.most_common(1)[0][0]
v1c = sorted(v1c.values())

v2c = Counter(v2)
v2cs = v2c.most_common(1)[0][0]
v2c = sorted(v2c.values())

if v1cs != v2cs:
    ans = sum(v1c[:-1]) + sum(v2c[:-1])
else:
    if len(v1c) == 1 and len(v2c) == 1:
        ans = sum(v2c)
    elif len(v1c) == 1:
        ans = min(sum(v2c) - v2c[-2])
    elif len(v2c) == 1:
        ans = min(sum(v1c) - v1c[-2])
    else:
        ans = min(sum(v1c) - v1c[-2] + sum(v2c[:-1]), sum(v1c[:-1]) + sum(v2c) - v2c[-2])

print(ans)

Submission status: Accepted

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

even_dict = {}
odd_dict = {}
for i, value in enumerate(v):
    if i % 2:
        even_dict[value] = 1 if value not in even_dict else even_dict[value] + 1
    else:
        odd_dict[value] = 1 if value not in odd_dict else odd_dict[value] + 1

counter = 0
even = sorted(even_dict.items(), key=lambda x: x[1], reverse=True)
odd = sorted(odd_dict.items(), key=lambda x: x[1], reverse=True)

if even[0][0] == odd[0][0]:
    even_second = 0 if len(even) < 2 else even[1][1]
    odd_second = 0 if len(odd) < 2 else odd[1][1]
    if even[0][1] - even_second > odd[0][1] - odd_second:
        counter += sum([x[1] for x in even[1:]])
        counter += sum([x[1] for x in odd[2:] + [odd[0]]])
    else:
        counter += sum([x[1] for x in odd[1:]])
        counter += sum([x[1] for x in even[2:] + [even[0]]])
else:
    counter += sum([x[1] for x in even[1:]])
    counter += sum([x[1] for x in odd[1:]])

print(counter)

Submission status: Accepted

Solution code:
from collections import Counter
from math import ceil, floor
n = int(input())
v = list(map(int, input().split()))
v = [v[::2], v[1::2]]
v_c = [sorted(Counter(x).items(),key=lambda x:x[1], reverse=True) + [(0, 0)]for x in v]
if v_c[0][0][0] == v_c[1][0][0]:
  ans1 = ceil(n / 2) - v_c[0][0][1] + floor(n / 2) - v_c[1][1][1]
  ans2 = ceil(n / 2) - v_c[0][1][1] + floor(n / 2) - v_c[1][0][1]
  print(min(ans1, ans2))
else:
  print(ceil(n / 2) - v_c[0][0][1] + floor(n / 2) - v_c[1][0][1])

Submission status: Accepted

Solution code:
# ABC111C - /\/\/\/
from collections import Counter

n = int(input())
lst = list(map(int, input().rstrip().split()))
even = Counter(lst[::2]).most_common(2)
odd = Counter(lst[1::2]).most_common(2)
ans = 0
if even[0][0] != odd[0][0]:
    print(n - even[0][1] - odd[0][1])
else:
    if len(even) == 1:
        print(n // 2)
    else:
        print(n - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1]))

Submission status: Accepted

Solution code:
# ABC111C - /\/\/\/
from collections import Counter

n = int(input())
lst = list(map(int, input().rstrip().split()))
even = Counter(lst[::2]).most_common(2)
odd = Counter(lst[1::2]).most_common(2)
ans = 0
if even[0][0] != odd[0][0]:
    print(n - even[0][1] - odd[0][1])
else:
    if len(even) == 1 or len(odd) == 1:
        print(n // 2)
    else:
        print(n - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1]))

Submission status: Accepted

Solution code:
import collections
N=int(input())
V=list(map(int,input().split()))
V1=collections.Counter(V[0::2]).most_common()
V2=collections.Counter(V[1::2]).most_common()
V1.append((0,0))
V2.append((0,0))
if V1[0]!=V2[0]:
    print(N-V1[0][1]-V2[0][1])
else:
    print(min(N-V1[0][1]-V2[1][1],N-V1[1][1]-V2[0][1]))

Submission status: Accepted

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
MAX_V = 100001
even = [[i, 0] for i in range(MAX_V)]
odd = [[i, 0] for i in range(MAX_V)]
for ni in range(n//2):
    even[v[ni*2]][1] += 1
    odd[v[ni*2+1]][1] += 1
even.sort(key=lambda x: x[1], reverse=True)
odd.sort(key=lambda x: x[1], reverse=True)

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    v = f()

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

    cnt_a = {}
    cnt_b = {}
    for i in a:
        if i in cnt_a:
            cnt_a[i] += 1
        else:
            cnt_a[i] = 1
    
    for i in b:
        if i in cnt_b:
            cnt_b[i] += 1
        else:
            cnt_b[i] = 1

    ncnt_a = sorted(cnt_a.items(), key = lambda x:-x[1])
    ncnt_b = sorted(cnt_b.items(), key = lambda x:-x[1])

    

    if ncnt_a[0][0]!=ncnt_b[0][0]:
        print(n -ncnt_a[0][1]- ncnt_b[0][1])
    else:
        ans1 = n - ncnt_b[0][1] - (ncnt_a[1][1] if len(ncnt_a)>1 else 0)
        ans2 = n -ncnt_a[0][1]- (ncnt_b[1][1] if len(ncnt_b)>1 else 0)
        print(min(ans1, ans2))



solve()

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())

e = []
o = []
for i, v in enumerate(input().split(' ')):
    if i % 2 == 0:
        e.append(int(v))
    else:
        o.append(int(v))

if len(set(e + o)) == 1:
    print(int(len(e + o) / 2))
    exit()

if Counter(o).most_common()[0][0] == Counter(e).most_common()[0][0]:
    ans = min(len(o) - Counter(o).most_common()[1][1] + len(e) - Counter(e).most_common()[0][1], len(o) - Counter(o).most_common()[0][1] + len(e) - Counter(e).most_common()[1][1])
    print(ans)
else:
    print(len(o) - Counter(o).most_common()[0][1] + len(e) - Counter(e).most_common()[0][1])

Submission status: Accepted

Solution code:
import collections
n = int(input())
l = list(int(x) for x in input().split())
el = []
ol = []
for i in range(n):
  if i % 2 == 0:
    el.append(l[i])
  else:
    ol.append(l[i])
if len(set(el + ol)) == 1:
  print(int(len(l)/2))
  exit()
e1 = collections.Counter(el).most_common()[0][0]
o1 = collections.Counter(ol).most_common()[0][0]
cnt1 = 0
cnt2 = 0
if e1 != o1:
  print(len(el) - collections.Counter(el).most_common()[0][1] + len(ol) - collections.Counter(ol).most_common()[0][1])
else:
  print(min(len(el)-collections.Counter(el).most_common()[0][1]+len(ol)-collections.Counter(ol).most_common()[1][1],len(el)-collections.Counter(el).most_common()[1][1]+len(ol)-collections.Counter(ol).most_common()[0][1]))

Submission status: Accepted

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

n = int(input())
v = list(map(int,input().split()))
a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0] != b[0][0]:
    ans = n - (a[0][1]+b[0][1])
else:
    ans = min(n - (a[1][1]+b[0][1]), n - (a[0][1]+b[1][1]))
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import collections
n = int(stdin.readline().rstrip())
V = [int(x) for x in stdin.readline().rstrip().split()]
V_odd = [V[2 * k] for k in range(int(n / 2))]
V_even = [V[2 * k + 1] for k in range(int(n / 2))]
co = collections.Counter(V_odd)
ce = collections.Counter(V_even)
if co.most_common()[0][0] != ce.most_common()[0][0]:
    print(n - co.most_common()[0][1] - ce.most_common()[0][1])
elif len(co.most_common()) == 1 and len(ce.most_common()) == 1:
    print(co.most_common()[0][1])
else:
    print(n - (max(co.most_common()[1][1] + ce.most_common()[0][1], co.most_common()[0][1] + ce.most_common()[1][1])))