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:
import sys
import collections

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    v = inl()
    ev = collections.Counter()
    od = collections.Counter()
    for i in range(n):
        if i % 2 == 0:
            ev[v[i]] += 1
        else:
            od[v[i]] += 1
    ex = ev.most_common(2)
    ox = od.most_common(2)
    if ex[0][0] != ox[0][0]:
        ans = n - ex[0][1] - ox[0][1]
    elif len(ex) == 1 and len(ox) == 1:
        ans = n - ex[0][1]
    elif len(ex) == 1:
        ans = n - ex[0][1] - ox[1][1]
    elif len(ox) == 1:
        ans = n - ex[1][1] - ox[0][1]
    else:
        ans = min(n - ex[0][1] - ox[1][1], n - ex[1][1] - ox[0][1])
    return ans


print(solve())

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=v[0:n:2]
v2=v[1:n:2]
cc1=Counter(v1)
c1=cc1.most_common()
cc2=Counter(v2)
c2=cc2.most_common()
if c1[0][0]!=c2[0][0]:
    print(n-c1[0][1]-c2[0][1])
if c1[0][0]==c2[0][0]:
    if len(c1)==len(c2)==1:
        print(n//2)
    if len(c1)==1 and len(c2)!=1:
        print(n-c1[0][1]-c2[1][1])
    if len(c2)==1 and len(c1)!=1:
        print(n-c1[1][1]-c2[0][1])    
    if len(c1)>1 and len(c2)>1:    
        print(n-max(c1[1][1]+c2[0][1],c1[0][1]+c2[1][1]))

Submission status: Accepted

Solution code:
n=int(input())
v=list(map(int,input().split()))
d1=[0]*(10**5+1)
d2=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        d1[v[i]]+=1
    else:
        d2[v[i]]+=1
if d1.index(max(d1))==d2.index(max(d2)):
    d1n=sorted(d1,reverse=True)
    d2n=sorted(d2,reverse=True)
    if d1n[1]>d2n[1]:
        print(n-d1n[1]-d2n[0])
    else:
        print(n-d1n[0]-d2n[1])
else:
    print(n-max(d1)-max(d2))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
l_o = l[::2]
l_g = l[1::2]
a = list(Counter(l_o).most_common())+[(0,0)]
c = list(Counter(l_g).most_common())+[(0,0)]

if a[0][0]==c[0][0]:
  s = a[0][1]+c[1][1]
  t = a[1][1]+c[0][1]
  x = max(s,t)
  print(n-x)
  
  
else:
  print(n-a[0][1]-c[0][1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

from collections import Counter

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


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

c_even = Counter(v_even).most_common()
c_odd = Counter(v_odd).most_common()

# print(c_even)
# print(c_odd)

if c_even[0][0] == c_odd[0][0]:
    if len(c_even) == 1:
        c_odd = c_odd[1:]
    elif len(c_odd) == 1:
        c_even = c_even[1:]
    else:
        if c_even[1][1] >= c_odd[1][1]:
            c_even = c_even[1:]
        else:
            c_odd = c_odd[1:]

if len(c_even) == 0:
    c_even.append((-1, 0))
if len(c_odd) == 0:
    c_odd.append((-1, 0))

diff_even = n//2-c_even[0][1]
diff_odd = n//2-c_odd[0][1]

print(diff_even+diff_odd)

Submission status: Accepted

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

odd = {}
even = {}
for d, i in enumerate(v):
    if d % 2 == 1:
        if i in even:
            even[i] += 1
        else:
            even[i] = 1
    else:
        if i in odd:
            odd[i] += 1
        else:
            odd[i] = 1
even_sorted = sorted(even.items(), key=lambda x:x[1])
odd_sorted = sorted(odd.items(), key=lambda x:x[1])
if even_sorted[-1][0] == odd_sorted[-1][0]:
    try:
        second_o = odd_sorted[-2][1]
    except:
        second_o = 0
    try:
        second_e = even_sorted[-2][1]
    except:
        second_e = 0
    print(min(n- even_sorted[-1][1] -second_o, n- second_e -odd_sorted[-1][1] ))
else:
    print(n - max(even.values()) - max(odd.values()))

Submission status: Accepted

Solution code:
n=int(input())
v=list(map(int,input().split()))
d1={}
d2={}
l1=[]
l2=[]
for i in range(n):
    num=v[i]
    if i%2==0:
        try:
            d1[num]+=1
        except:
            d1[num]=1
    else:
        try:
            d2[num]+=1
        except:
            d2[num]=1
for i in d1:
    l1.append([d1[i],i])
for i in d2:
    l2.append([d2[i],i])
l1.sort(reverse=True)
l2.sort(reverse=True)
ans=n
if l1[0][1]!=l2[0][1]:
    ans-=(l1[0][0]+l2[0][0])
elif len(l1)==1 and len(l2)==1:
    ans//=2
elif len(l1)==1:
    ans-=l2[1][0]
elif len(l2)==1:
    ans-=l1[1][0]
else:
    a=ans-l1[0][0]-l2[1][0]
    b=ans-l1[1][0]-l2[0][0]
    ans=min(a,b)
print(ans)

Submission status: Accepted

Solution code:
import collections

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

v_odd = []
v_even = []

for i, v in enumerate(v):
    if i % 2:
        v_even.append(v)
    else:
        v_odd.append(v)

# Counterに入れて、valueの降順にソート
v_odd_c = collections.Counter(v_odd)
v_odd_c = sorted(v_odd_c.items(), key=lambda x: x[1], reverse=True)
v_even_c = collections.Counter(v_even)
v_even_c = sorted(v_even_c.items(), key=lambda x: x[1], reverse=True)

# counterに一つしかkeyがないと面倒なので0が0回出たことを明示的に示しておく
# 制約上、0はvとしてあり得ないので問題ない（必ず0は0回出る）
v_odd_c.append([0, 0])
v_even_c.append([0, 0])

if n != 2:
    o1 = v_odd_c[0]
    o2 = v_odd_c[1]
    e1 = v_even_c[0]
    e2 = v_even_c[1]

    # 最頻値が異なる場合
    if o1[0] != e1[0]:
        ans = n - o1[1] - e1[1]
    # 最頻値が等しい場合
    elif o1[0] == e1[0]:
        # o1,e2を採用する場合
        temp1 = n - o1[1] - e2[1]
        #o2, e1を採用する場合
        temp2 = n - o2[1] - e1[1]
        ans = min(temp1, temp2)

print(ans)

Submission status: Accepted

Solution code:
import collections

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

v_odd = []
v_even = []

for i, v in enumerate(v):
    if i % 2:
        v_even.append(v)
    else:
        v_odd.append(v)

# Counterに入れて、valueの降順にソート
v_odd_c = collections.Counter(v_odd)
v_odd_c = sorted(v_odd_c.items(), key=lambda x: x[1], reverse=True)
v_even_c = collections.Counter(v_even)
v_even_c = sorted(v_even_c.items(), key=lambda x: x[1], reverse=True)

# counterに一つしかkeyがないと面倒なので0が0回出たことを明示的に示しておく
# 制約上、0はvとしてあり得ないので問題ない（必ず0は0回出る）
v_odd_c.append([0, 0])
v_even_c.append([0, 0])

# print(v_odd_c)
# print(v_even_c)

if n != 2:
    o1 = v_odd_c[0]
    o2 = v_odd_c[1]
    e1 = v_even_c[0]
    e2 = v_even_c[1]

    # 最頻値が異なる場合
    if o1[0] != e1[0]:
        ans = n - o1[1] - e1[1]
    # 最頻値が等しい場合
    elif o1[0] == e1[0]:
        # o1,e2を採用する場合
        temp1 = n - o1[1] - e2[1]
        #o2, e1を採用する場合
        temp2 = n - o2[1] - e1[1]
        ans = min(temp1, temp2)

elif n == 2:
    if v_odd_c[0][1] != v_even_c[0][1]:
        ans = 0
    else:
        ans = 1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

cnt_even = Counter(even).most_common()
cnt_odd = Counter(odd).most_common()

even_num = cnt_even[0][0]
odd_num = cnt_odd[0][0]

if even_num == odd_num:
    if len(cnt_even) == 1 and len(cnt_odd) == 1:
        ans = min(len(even),len(odd))
    elif len(cnt_even) == 1:#oddを変えるしかない
        ans = (len(even)-cnt_even[0][1]) + (len(odd)-cnt_odd[1][1])
    elif len(cnt_odd) == 1:
        ans = (len(even)-cnt_even[1][1]) + (len(odd)-cnt_odd[0][1])
    else:
        ans = min((len(even)-cnt_even[0][1]) + (len(odd)-cnt_odd[1][1]), (len(even)-cnt_even[1][1]) + (len(odd)-cnt_odd[0][1]))
else:
    ans_e = len(even) - cnt_even[0][1]
    ans_o = len(odd) - cnt_odd[0][1]
    ans = ans_e + ans_o

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
v = tuple(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
    print(n // 2)
else:
    c1m = c1.most_common(2)
    c2m = c2.most_common(2)
    if c1m[0][0] == c2m[0][0]:
        print(min(n - c1m[0][1] - c2m[1][1], n - c1m[1][1] - c2m[0][1]))
    else:
        print(n - c1m[0][1] - c2m[0][1])

Submission status: Accepted

Solution code:
import collections
N =int(input())
V =list(map(int,input().split()))
ev_col = collections.Counter(V[::2]).most_common()
od_col = collections.Counter(V[1::2]).most_common()
 
if ev_col[0][0] != od_col[0][0]:
    ans = N - od_col[0][1] - ev_col[0][1]
else:
    if len(ev_col) >= 2 and len(od_col)  >= 2:
        if ev_col[1][1] >= od_col[1][1]:
            ans = N - ev_col[1][1] - od_col[0][1]
        else:
            ans = N - od_col[1][1] - ev_col[0][1]
    else:
        ans = N - ev_col[0][1]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
v=list(map(int,input().split()))
from collections import defaultdict
a=defaultdict(int)
b=defaultdict(int)
for i in range(n):
  if i%2==0:
    a[v[i]]+=1
  else:
    b[v[i]]+=1

am=max(a.values())
bm=max(b.values())
if max(a,key=a.get) !=max(b,key=b.get):
  print(n-am-bm)
else:
  b[max(b, key=b.get)]=0
  a[max(a, key=a.get)]=0
  a2=n-am-max(b.values())
  b2=n-bm-max(a.values())
         
  print(min(a2,b2))

Submission status: Accepted

Solution code:
from collections import Counter
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

odd_c = Counter(v[0::2])
even_c = Counter(v[1::2])

odd_c = odd_c.most_common()
if len(odd_c) == 1:
    odd_c.append((0, 0))
even_c = even_c.most_common()
if len(even_c) == 1:
    even_c.append((0, 0))

if odd_c[0][0] != even_c[0][0]:
    ans = n - (odd_c[0][1] + even_c[0][1])
else:
    ans = n - (max(odd_c[1][1] + even_c[0][1], odd_c[0][1] + even_c[1][1]))
print(ans)

Submission status: Accepted

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

dic_odd = {}
dic_even = {}

for i, v in enumerate(V):
    if i % 2 == 0:
        if v in dic_even:
            dic_even[v] += 1
        else:
            dic_even[v] = 1
    else:
        if v in dic_odd:
            dic_odd[v] += 1
        else:
            dic_odd[v] = 1


odd_lst = [(k, v) for k, v in dic_odd.items()]
even_lst = [(k, v) for k, v in dic_even.items()]
odd_lst.sort(key=lambda x: x[1], reverse=True)
even_lst.sort(key=lambda x: x[1], reverse=True)

if (len(odd_lst) == len(even_lst) == 1) and (odd_lst[0][0] == even_lst[0][0]):
    print(int(N / 2))
    exit()

max_ = 0
for a, b in odd_lst:
    for x, y in even_lst:
        if a == x:
            continue
        else:
            max_ = max(b + y, max_)
            break


print(N - max_)

Submission status: Accepted

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
v_odd = []
v_even = []
for i,v in enumerate(v):
    if i % 2:
        v_even.append(v)
    else:
        v_odd.append(v)
odd_n = len(v_odd)
even_n = len(v_even)
v_odd = collections.Counter(v_odd)
v_odd = sorted(v_odd.items(), key=lambda x:x[1],reverse=True)
v_even = collections.Counter(v_even)
v_even = sorted(v_even.items(), key=lambda x:x[1],reverse=True)

if v_odd[0] == v_even[0] and 2 <= len(v_odd) and 2 <= len(v_even):
    if v_odd[1][1] < v_even[1][1]:
        v_even.pop(0)
    elif v_odd[1][1] > v_even[1][1]:
        v_odd.pop(0)

num = v_odd[0][0]

ans = odd_n-v_odd[0][1]
st = 0
for i,v in v_even:
    if num == i:
        continue
    else:
        st = v
        break
print(ans+(even_n-st))

Submission status: Accepted

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

def main(n,v):

    hist=[0]*(10**5+1)
    maxhist=0
    maxvalue=0
    for i in range(n):
        hist[v[i]]+=1
        if (maxhist<hist[v[i]]):
            maxhist=hist[v[i]]
            maxvalue=v[i]
    print('maxvalue: {}, maxhist: {}'.format(maxvalue, maxhist))

    secondhist=0
    for i in range(1,10**5+1):
        if i == maxvalue:
            continue
        secondhist=max(secondhist,hist[i])
    print('secondhist: {}'.format(secondhist))

    nsame=n//2
    nchange=0
    if maxhist>nsame:
        nchange+=maxhist-nsame
    elif maxhist<nsame:
        nchange+=nsame-maxhist
    nchange+=nsame-secondhist
    return nchange

def main2(n,v):
    eList=[]
    oList=[]
    for i in range(n):
        if i%2==0:
            eList.append(v[i])
        else:
            oList.append(v[i])

    #print(eList)
    #print(oList)

    ehist=[0]*(10**5+1)
    for i in eList:
        ehist[i]+=1
    emaxh=0
    emaxv=0
    for i in range(1,10**5+1):
        if emaxh<ehist[i]:
            emaxh=ehist[i]
            emaxv=i
    esech=0
    esecv=0
    for i in range(1,10**5+1):
        if i==emaxv:
            continue
        if esech<ehist[i]:
            esech=ehist[i]
            esecv=i
    
    ohist=[0]*(10**5+1)
    for i in oList:
        ohist[i]+=1
    omaxh=0
    omaxv=0
    for i in range(1,10**5+1):
        if omaxh<ohist[i]:
            omaxh=ohist[i]
            omaxv=i
    osech=0
    osecv=0
    for i in range(1,10**5+1):
        if i == omaxv:
            continue
        if osech<ohist[i]:
            osech=ohist[i]
            osecv=i

    if omaxv==emaxv:
        if omaxh==emaxh:
            if osech>esech:
                omaxv=osecv
            else:
                emaxv=esecv
        elif omaxh>emaxh:
            emaxv=esecv
        else:
            omaxv=osecv
    
    #print('emaxv: {}, omaxv: {}'.format(emaxv,omaxv))

    nchange=0
    for i in range(n//2):
        if eList[i]!=emaxv:
            nchange+=1
        if oList[i]!=omaxv:
            nchange+=1
    return nchange


if __name__=='__main__':
    n,v=readinput()
    ans=main2(n,v)
    print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    n = in_n()
    v = in_nl()
    c1 = Counter(v[::2]).most_common()
    c2 = Counter(v[1::2]).most_common()
    if c1[0][0] == c2[0][0]:
        if len(c1) == 1 and len(c2) == 1:
            count = n // 2
        elif len(c1) == 1:
            count = n // 2 + c2[1][1]
        elif len(c2) == 1:
            count = n // 2 + c1[1][1]
        else:
            count = max(c1[0][1] + c2[1][1], c1[1][1] + c2[0][1])
    else:
        count = c1[0][1] + c2[0][1]
    print(n - count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
N =int(input())
V =list(map(int,input().split()))
ev_col = collections.Counter(V[::2]).most_common()
od_col = collections.Counter(V[1::2]).most_common()

if ev_col[0][0] != od_col[0][0]:
    ans = N - od_col[0][1] - ev_col[0][1]
else:
    if len(ev_col) >= 2 and len(od_col)  >= 2:
        if ev_col[1][1] >= od_col[1][1]:
            ans = N - ev_col[1][1] - od_col[0][1]
        else:
            ans = N - od_col[1][1] - ev_col[0][1]
    else:
        ans = N - ev_col[0][1]
print(ans)

Submission status: Accepted

Solution code:
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''
import collections
def myAnswer(N:int,V:list) -> int:
   odd = []
   even = []
   if len(set(V)) == 1:
      return N//2

   for n,v in enumerate(V):
      even.append(v) if n % 2 == 0 else odd.append(v)
   
   oddCounter = collections.Counter(odd)
   evenCounter = collections.Counter(even)
   oddCounter = sorted(oddCounter.items(),key=lambda x:x[1])
   evenCounter = sorted(evenCounter.items(),key=lambda x:x[1])
   oddMAX = oddCounter[-1][0]
   evenMAX = evenCounter[-1][0]
   if oddMAX == evenMAX:
      evenLen = len(evenCounter)
      oddLen = len(oddCounter)
      if evenLen >= 2 and oddLen >= 2:
         if evenCounter[-2][1] > oddCounter[-2][1]:
            evenMAX = evenCounter[-2][0]
         else:
            oddMAX = oddCounter[-2][0]
      elif evenLen >= 2:
         evenMAX = evenCounter[-2][0]
      else:
         oddMAX = oddCounter[-2][0]

   
   total = 0
   for n,v in enumerate(V):
      if n % 2 == 1:
         if oddMAX != v:
            total += 1
      else:
         if evenMAX != v:
            total += 1
   return total
def modelAnswer():
   return
def main():
   N = int(input())
   V = list(map(int,input().split()))
   print(myAnswer(N,V))


if __name__ == '__main__':
   main()

Submission status: Accepted

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

u = v[1::2] #奇数列
d = v[0::2] #偶数列

U = [0] * 100010
for i in range(len(u)): #何種類の数が何個現れるか記録
    U[u[i]] += 1
    
D = [0] * 100010
for i in range(len(d)): #何種類の数が何個現れるか記録
    D[d[i]] += 1
   
if U.index(max(U)) == D.index(max(D)): #最頻値が同じ場合
    u = sorted(U, reverse=True)
    d = sorted(D, reverse=True)
    s = n - u[1] - d[0] if u[1] > d[1] else n - u[0] - d[1]
    print(s)
    exit()
    
print(n - max(U) - max(D))

Submission status: Accepted

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

#参考 https://atcoder.jp/contests/abc111/submissions/14666502

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

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

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


if len(set(v0)) == len(set(v1)) == 1:
    if c0[0] == c1[0]:
        ans = len(v0)
    else:
        ans = 0
else:
    if c0[0] != c1[0]:
        ans = n - c0[0][1] - c1[0][1]
    else:
        ans = min(n - c0[0][1] - c1[1][1], n - c0[1][1] - c1[0][1])
print(ans)

Submission status: Accepted

Solution code:
import collections


def solve():

    n = int(input())
    v = list(map(int, input().split()))
    v0 = v[::2]
    v0_counter = collections.Counter(v0).most_common()
    v1 = v[1::2]
    v1_counter = collections.Counter(v1).most_common()

    if v0_counter[0][0] != v1_counter[0][0]:
        print(n - v0_counter[0][1] - v1_counter[0][1])
        exit()
    else:
        if len(v0_counter) == 1 or len(v1_counter) == 1:
            print(n // 2)
            exit()
        else:
            print(n - max(v0_counter[0][1] + v1_counter[1][1], v0_counter[1][1] + v1_counter[0][1]))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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

if len(set(v0)) == len(set(v1)) == 1:
    if c0[0] == c1[0]:
        res = len(v0)
    else:
        res = 0

else:
    if c0[0] != c1[0]:
        res = n - c0[0][1] - c1[0][1]
    else:
        res = min(n - c0[0][1] - c1[1][1], n - c0[1][1] - c1[0][1])

print(res)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
L = list(map(int, input().split()))
L1 = L[::2]
L2 = L[1::2]
c1 = Counter(L1).most_common()
c2 = Counter(L2).most_common()
if len(set(L1)) == len(set(L2)) == 1:
    if c1[0] == c2[0]:
        print(len(L1))
    else:
        print(0)
else:
    if c1[0] != c2[0]:
        print(n - c1[0][1] - c2[0][1])
    else:
        print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))

Submission status: Accepted

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

V_ODD = [v for i,v in enumerate(V) if i%2==1]
V_EVEN = [v for i,v in enumerate(V) if i%2==0]

import collections

V_ODD_SORTED = sorted(list(zip(collections.Counter(V_ODD).values(), collections.Counter(V_ODD).keys())), reverse=True)
V_EVEN_SORTED = sorted(list(zip(collections.Counter(V_EVEN).values(), collections.Counter(V_EVEN).keys())), reverse=True)

ans_list = []

if V_ODD_SORTED[0][1] == V_EVEN_SORTED[0][1]:
    if len(V_ODD_SORTED) > 1:
        tmp = len(V)//2 - V_ODD_SORTED[1][0]
        tmp += len(V)//2 - V_EVEN_SORTED[0][0]
        ans_list.append(tmp)
        
    if len(V_EVEN_SORTED) > 1:
        tmp = len(V)//2 - V_ODD_SORTED[0][0]
        tmp += len(V)//2 - V_EVEN_SORTED[1][0]
        ans_list.append(tmp)

    if len(V_ODD_SORTED) == 1 and len(V_EVEN_SORTED) == 1:
        ans_list.append(len(V)//2)
        
else:
    tmp = len(V)//2 - V_ODD_SORTED[0][0]
    tmp += len(V)//2 - V_EVEN_SORTED[0][0]
    ans_list.append(tmp)
    
print(min(ans_list))

Submission status: Accepted

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

if len(set(v)) == 1:
    print(n // 2)
else:
    cnt_even = [[0, i] for i in range(10 ** 5 + 1)]
    cnt_odd = [[0, i] for i in range(10 ** 5 + 1)]
    for i in range(n):
        if i % 2 == 0:
            cnt_even[v[i]][0] += 1
        else:
            cnt_odd[v[i]][0] += 1

    cnt_even.sort()
    cnt_odd.sort()

    if cnt_even[-1][1] == cnt_odd[-1][1]:
        print(n - max(cnt_even[-1][0] + cnt_odd[-2][0], cnt_even[-2][0] + cnt_odd[-1][0]))
    else:
        print(n - cnt_even[-1][0] - cnt_odd[-1][0])

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
numbers = [int(i) for i in input().split()]

o = Counter(numbers[::2]).most_common()
e = Counter(numbers[1::2]).most_common()

if o[0][0] == e[0][0]:
    if len(o) == 1:
        output = N // 2
    else :
        e1, e2 = e[0][1], e[1][1]
        o1, o2 = o[0][1], o[1][1]
        
        output = min(N-e1-o2, N-e2-o1)
else :
    output = N - o[0][1] - e[0][1]

print(output)

Submission status: Accepted

Solution code:
from collections import Counter
 
N = int(input())
l = list(map(int, input().split()))
 
o = Counter(l[::2]).most_common()
e = Counter(l[1::2]).most_common()
 
if o[0][0] == e[0][0]:
    if len(o) == 1:
        print(N//2)
    else:
        e1, e2 = o[0][1], o[1][1]
        o1, o2 = e[0][1], e[1][1]
 
        res = min(N-e1-o2, N-e2-o1)
        print(res)
else:
    print(N - o[0][1] - e[0][1])

Submission status: Accepted

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

odd={}
even={}
total={}

for i in range(n):
    t=a[i]
    if i%2==0:
        if t in odd:
            odd[t]+=1
        else:
            odd[t]=1
    else:
        if t in even:
            even[t]+=1
        else:
            even[t]=1
    if t in total:
        total[t]+=1
    else:
        total[t]=1

l=len(odd)+len(even)

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

ans=0

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

ans=n
cnt1=0
for i in odd:
    if cnt1==2:
        break
    cnt2=0
    for j in even:
        if cnt2==2 or i[0]==j[0]:
            continue
    
        ans=min(ans,n-i[1]-j[1])
        cnt2+=1
    cnt1+=1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
V = tuple(map(int, input().split(' ')))

v1 = V[::2]
v2 = V[1::2]

v1_count = Counter(v1)
v1_count[-1] = 0
v2_count = Counter(v2)
v2_count[-1] = 0

v1 = sorted([(value, key) for key, value in v1_count.items()], reverse=True)
v2 = sorted([(value, key) for key, value in v2_count.items()], reverse=True)

if v1[0][1] == v2[0][1]:
    print(min(N - v1[0][0] - v2[1][0], N - v2[0][0] - v1[1][0]))
else:
    print(N - v1[0][0] - v2[0][0])

Submission status: Accepted

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

import sys
from collections import Counter

C0 = Counter(V[0::2])
C1 = Counter(V[1::2])

n0 = C0.most_common()[0][0]
n1 = C1.most_common()[0][0]

minV = min(V)
if all([v == minV for v in V]):
    print(len(V)//2)
    sys.exit()

if n0 == n1:
    if C0.most_common()[1][1] >= C1.most_common()[1][1]:
        n0 = C0.most_common()[1][0]
    else:
        n1 = C1.most_common()[1][0]
    
count = 0
for v in V[0::2]:
    if v != n0:
        count += 1

for v in V[1::2]:
    if v != n1:
        count += 1
print(count)

Submission status: Accepted

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

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

from collections import Counter
counter_odd = dict(Counter(odd))
counter_even = dict(Counter(even))

counter_odd[0] = 0
counter_even[0] = 0

counter_odd = list(counter_odd.items())
counter_even = list(counter_even.items())

counter_odd.sort(reverse=True, key=lambda x: x[1])
counter_even.sort(reverse=True, key=lambda x: x[1])

max_odd = counter_odd[0]
max_even = counter_even[0]

if max_odd[0] != max_even[0]:
    ans = len(odd) - max_odd[1] + len(even) - max_even[1]
    print(ans)
else: 
    semi_max_odd = counter_odd[1]
    semi_max_even = counter_even[1]
    loss_odd = max_odd[1] - semi_max_odd[1]
    loss_even = max_even[1] - semi_max_even[1]
    if loss_odd < loss_even:
        ans = len(odd) - semi_max_odd[1] + len(even) - max_even[1]
    else:
        ans = len(odd) - max_odd[1] + len(even) - semi_max_even[1]
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


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


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


n = z()
v = zz()
a_lis = v[0::2]
b_lis = v[1::2]

a_all = [0]*(1 + 10**5)
b_all = [0]*(1 + 10**5)
for a in a_lis:
    a_all[a] += 1

for b in b_lis:
    b_all[b] += 1
nums = list(range(0, len(a_all)))
a_all = zip(a_all, nums)
b_all = zip(b_all, nums)
a_all = sorted(a_all, reverse=True)
b_all = sorted(b_all, reverse=True)

a_num_1, fixed_a_value = a_all[0]
b_num_1, fixed_b_value = b_all[0]
a_num_2 = a_num_1
b_num_2 = b_num_1
# print(a_num, b_num)
if (fixed_a_value == fixed_b_value):
    a_num_1, fixed_a_value = a_all[0]
    b_num_1, fixed_b_value = b_all[1]
    a_num_2, fixed_a_value = a_all[1]
    b_num_2, fixed_b_value = b_all[0]
# print(a_num, b_num)
ans = min(n-a_num_1-b_num_1, n-a_num_2-b_num_2)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int,input().split()))
dic1,dic2 = {},{}
c1,c2=0,0
for i in range(0,n,2):
  if v[i] in dic1.keys():
    dic1[v[i]] += 1
  else:
    dic1[v[i]] = 1
  c1 += 1

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

dic1 = sorted(dic1.items(), key = lambda x : x[1], reverse=True)
dic2 = sorted(dic2.items(), key = lambda x : x[1], reverse=True)
if len(dic1) == 1:
  dic1.append((0,0))
if len(dic2) == 1:
  dic2.append((0,0))

ans = 0
if dic1[0][0] != dic2[0][0]:
  ans = c1 - dic1[0][1] + c2 - dic2[0][1]
else:
  x = c1 - dic1[0][1] + c2 - dic2[1][1]
  y = c1 - dic1[1][1] + c2 - dic2[0][1]
  ans = min(x,y)

print(ans)

Submission status: Accepted

Solution code:

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

u = v[1::2]
d = v[0::2]
    
#print(u)
#print(d)

U = [0] * 100010
for i in range(len(u)):
    U[u[i]] += 1
    
D = [0] * 100010
for i in range(len(d)):
    D[d[i]] += 1
   
if U.index(max(U)) == D.index(max(D)):
    u = sorted(U, reverse=True)
    d = sorted(D, reverse=True)
    s = n - u[1] - d[0] if u[1] > d[1] else n - u[0] - d[1]
    print(s)
    exit()
    
print(n - max(U) - max(D))

Submission status: Accepted

Solution code:
import sys
from collections import Counter
n=int(input())
v=[int(x) for x in input().split()]

v1=[] # odd
v2=[] # even

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

m1=Counter(v1).most_common()
m2=Counter(v2).most_common()




ans=0
for i in range(min(len(m1),len(m2))):
    # 最頻値が異なる
    if m1[i][0]!=m2[i][0]:
        ans=sum(list(m1[j][1] for j in range(i+1,len(m1))))+sum(list(m2[j][1] for j in range(i+1,len(m2))))
        print(ans)
        sys.exit()
    # 最頻値が同じ
    else:
        # v1の最頻値の回数のほうが大きい
        if m1[i][1]>m2[i][1]:
            ans=m2[i][1]+sum(list(m1[j][1] for j in range(i+1,len(m1))))+sum(list(m2[j][1] for j in range(i+2,len(m2))))
            print(ans)
            sys.exit()
        
        # v2の最頻値の回数ほうが大きい
        elif m1[i][1]<m2[i][1]:
            ans=m1[i][1]+sum(list(m1[j][1] for j in range(i+2,len(m1))))+sum(list(m2[j][1] for j in range(i+1,len(m2))))
            print(ans)
            sys.exit()
            
        # 最頻値の回数同じだった
        else:
            # 最頻値の回数が少ないほうを探す おそらくここが間違い
            cnt1=m1[i][1]+sum(list(m1[j][1] for j in range(i+2,len(m1)))) + sum(list(m2[j][1] for j in range(i+1,len(m2))))
            cnt2=m2[i][1]+sum(list(m2[j][1] for j in range(i+2,len(m2)))) + sum(list(m1[j][1] for j in range(i+1,len(m1))))
            ans=min(cnt1,cnt2)
            print(ans)
            sys.exit()

Submission status: Accepted

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

for i in range(0,n//2):
  a1 = v[2*i]
  a2 = v[2*i+1]
  
  if a1 not in d1:
    d1[a1] = 1
  else:
    d1[a1] += 1
    
  if a2 not in d2:
    d2[a2] = 1
  else:
    d2[a2] += 1


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


if len(set(v)) == 1:
  print(n//2)
  exit()
if l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) >= 2:
  print(min(n - l1[-1][1] - l2[-2][1],n - l1[-2][1] - l2[-1][1]))
elif l1[-1][0] == l2[-1][0] and len(l1) == 1 and len(l2) >= 2:
  print(n - l1[-1][1] - l2[-2][1])
elif l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) == 1:
  print(n - l1[-2][1] - l2[-1][1])
else:
  print(n - l1[-1][1] - l2[-1][1])

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
b1 = []
b2 = []
for i in range(N):
    if i%2==0:
        b1.append(a[i])
    else:
        b2.append(a[i])
c1 = Counter(b1)
c2 = Counter(b2)
k1,v1 = c1.most_common()[0]
k2,v2 = c2.most_common()[0]
ans = v1+v2
v3 = 0
v4 = 0
if k1 == k2:
    if len(list(c2.values())) > 1:
        v4 = c2.most_common()[1][1]
    if len(list(c1.values())) > 1:
        v3 = c1.most_common()[1][1]
    ans = max(v1+v4,v2+v3)
print(N-ans)