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: Time Limit Exceeded

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

o=[]
e=[]
for i in range(len(v)):
    if i%2==0:
        o.append(v[i])
    else:
        e.append(v[i])

mo=0
no=0
me=0

for i in range(10**5):
    if mo < o.count(i):
        no=i
        mo=o.count(i)

for i in range(10**5):
    if me < e.count(i) and i!=no:
        me=e.count(i)

mo1=0
ne1=0
me1=0

for i in range(10**5):
    if me1 < e.count(i):
        ne1=i
        me1=e.count(i)

for i in range(10**5):
    if mo1 < o.count(i) and i!=ne1:
        mo1=o.count(i)

if mo+me > mo1+me1:
    print(len(v)-mo-me)
else:
    print(len(v)-mo1-me1)

Submission status: Time Limit Exceeded

Solution code:
from statistics import mode
n=int(input())
v=list(map(int,input().split()))
m=int(n/2)
w=['']*m
x=['']*m
wcntr=0
xcntr=0
wcnt=n+1
xcnt=n+1
for i in range(m):
	w[i]=v[i*2]
	x[i]=v[i*2+1]
for k in range(m):
	wcntr=max(wcntr,w.count(w[k]))
	if wcntr==w.count(w[k]):
		wcnt=w[k]
for l in range(m):
	if x[l]!=wcnt:
		xcntr=max(xcntr,x.count(x[l]))
ans=n-(wcntr+xcntr)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int, input().split()))
ev = []
od = []
for i in range(n):
    if i % 2 == 0:
        ev.append(v[i])
    else:
        od.append(v[i])
ev.sort()
od.sort()
m = 0
oo = [[0, 0]]
ii = [[0, 0]]
while True:
    oo.append([ev[m], ev.count(ev[m])])
    m += ev.count(ev[m])
    if m >= n//2:
        break
m = 0
while True:
    ii.append([od[m], od.count(od[m])])
    m += od.count(od[m])
    if m >= n//2:
        break
ii.sort(key=lambda x: x[1], reverse=True)
oo.sort(key=lambda x: x[1], reverse=True)
if ii[0][0] != oo[0][0]:
    print(n - oo[0][1] - ii[0][1])
else:
    print(min(n - oo[1][1] - ii[0][1], n - oo[0][1] - ii[1][1]))

Submission status: Time Limit Exceeded

Solution code:
from statistics import mode
n=int(input())
v=list(map(int,input().split()))
m=int(n/2)
w=['']*m
x=['']*m
wcntr=0
xcntr=0
wcnt=n+1
xcnt=n+1
for i in range(m):
	w[i]=v[i*2]
for j in range(m):
	x[j]=v[j*2+1]
for k in range(m):
	wcntr=max(wcntr,w.count(w[k]))
	if wcntr==w.count(w[k]):
		wcnt=w[k]
for l in range(m):
	if x[l]!=wcnt:
		xcntr=max(xcntr,x.count(x[l]))
ans=n-(wcntr+xcntr)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
v=[int(x) for x in input().split()]
if len(set(v))==1:
    print(n//2)
    import sys
    sys.exit()
from collections import Counter
v1=[]
v2=[]
for i in range(n):
    if i%2==0:
        v1.append(v[i])
    else:
        v2.append(v[i])
v1=Counter(v1)
v2=Counter(v2)
ans=10**10
# print(v1,v2)
for i1 in v1.most_common():
    for i2 in v2.most_common():
        # print(n-i1[1]-i2[1],i1,i2)
        ans=min(n-i1[1]-i2[1],ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__' :
    n = int(input())
    v = list(map(int, input().split()))

    a = []
    b = []
    for i,sv in enumerate(v):
        if i % 2 == 0:
            a.append(sv)
        else:
            b.append(sv)

    maxa = 0
    for sa in a:
        tmp = a.count(sa)
        if maxa < tmp:
            maxa = tmp
            suba = sa
    maxa = len(a) - maxa

    maxb = 0
    for sb in b:
        tmp = b.count(sb)
        if maxb < tmp:
            maxb = tmp
            subb = sb
    maxb = len(b) - maxb

    if suba == subb:
        print(len(a))
    else:
        print(maxa+maxb)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
odd = []
even = []
arr = list(map(int, input().split()))
for i, e in enumerate(arr):
    if i % 2 == 0:
        # odd
        res = False
        for x in odd:
            if x[0] == e:
                x[1] += 1
                res = True
                break
        if not res:
            odd.append([e, 1])
    else:
        # even
        res = False
        for x in even:
            if x[0] == e:
                x[1] += 1
                res = True
                break
        if not res:
            even.append([e, 1])
odd.sort(key=lambda x: x[1])
even.sort(key=lambda x: x[1])
if odd[-1][0] == even[-1][0]:
    if len(odd) == 1:
        ans = n - even[-1][1]
    elif len(even) == 1:
        ans = n - odd[-1][1]
    elif odd[-2][1] > even[-2][1]:
        ans = n - even[-1][1] - odd[-2][1]
    else:
        ans = n - even[-2][1] - odd[-1][1]
else:
    ans = n - odd[-1][1] - even[-1][1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
v = list(map(int,input().split()))

v = np.array(v)

if len(np.unique(v)) == 1:
    print(int(len(v)/2))
else:
    vodd = v[np.arange(0,len(v),2)]
    vodd_unique = np.unique(vodd)
    d_odd = []
    odd_lis = []
    for vu in vodd_unique:
        d_odd.append(sum(vodd == vu))
        odd_lis.append(vu)

    veven = v[np.arange(1,len(v),2)]
    veven_unique = np.unique(veven)
    d_even = []
    even_lis = []
    for vu in veven_unique:
        d_even.append(sum(veven == vu))
        even_lis.append(vu)

    if even_lis[np.argmax(d_even)] != odd_lis[np.argmax(d_odd)]:
        score = np.max(d_even) + np.max(d_odd)
    else:
        score1 = even_lis[np.argsort(d_even)[-1]] + odd_lis[np.argsort(d_odd)[-2]]
        score2 = even_lis[np.argsort(d_even)[-2]] + odd_lis[np.argsort(d_odd)[-1]]
        score = max(score1,score2)
    print(len(v) - score)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = input().split(" ")
if len(set(v)) == 1:
    print(n // 2)
else:
    ans = 0
    odds = v[1::2]
    evens = v[::2]
    ans += len(odds) - max([odds.count(_o) for _o in set(odds)])
    ans += len(evens) - max([evens.count(_o) for _o in set(evens)])
    print(ans)

Submission status: Accepted

Solution code:
N=int(input())
Z=list(map(int,input().split()))
from collections import Counter
c=Counter(Z[::2]).most_common(2)+[(0,0)]
c2=Counter(Z[1::2]).most_common(2)+[(0,0)]
if c[0][0]!=c2[0][0]:
    print(N-c[0][1]-c2[0][1])
else:
    print(min(N-c[1][1]-c2[0][1],N-c[0][1]-c2[1][1]))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
list_A = list(map(int, input().split()))
L, R = [], []

for i in range(n):
    if i % 2 == 0:
        L.append(list_A[i])
    else:
        R.append(list_A[i])

A = Counter(L)
A = sorted(A.items(), key=lambda x:x[1], reverse=True)
A.append((-1, 0))

B = Counter(R)
B = sorted(B.items(), key=lambda x:x[1], reverse=True)
B.append((-1, 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:
N = int(input())
V = list(map(int,input().split()))

from collections import Counter

def get_counter(X):
  counter = Counter(X)
  X = counter.most_common()
  X.append((0,0))
  return X

V1 = get_counter(V[::2])
V2 = get_counter(V[1::2])

if V1[0][0] != V2[0][0]:
  print(N - (V1[0][1] + V2[0][1]))
else:
  print(N - max(V1[0][1] + V2[1][1],V1[1][1] + V2[0][1]))

Submission status: Accepted

Solution code:

from collections import Counter


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    O = Counter(A[::2])
    E = Counter(A[1::2])

    most_O = O.most_common(2)
    most_E = E.most_common(2)
    # 番兵
    most_O.append((0, 0))
    most_E.append((0, 0))

    cnt = 0
    # key comp
    if most_O[0][0] == most_E[0][0]:
        # value
        res1 = most_O[0][1] + most_E[1][1]
        res2 = most_O[1][1] + most_E[0][1]
        cnt = max(res1, res2)
    else:
        cnt = most_O[0][1] + most_E[0][1]

    # 数字が少ないものを書き換える為、Nで引く
    print(N - cnt)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = [int(x) for x in input().split()]
even = []
uneven = []
for i in range(n):
  if i%2 == 0:
    uneven.append(a[i])
    continue
  even.append(a[i])

uneven_counter = collections.Counter(uneven)
sortede_uneven_counter = sorted(uneven_counter.items(),key=lambda x:x[1],reverse=True)
even_counter = collections.Counter(even)
sortede_even_counter = sorted(even_counter.items(),key=lambda x:x[1],reverse=True)
  
ans = (n/2 - sortede_uneven_counter[0][1]) + (n/2 - sortede_even_counter[0][1])

if sortede_uneven_counter[0][0] == sortede_even_counter[0][0]:
  if len(set(a)) == 1:
    ans = n/2
  elif sortede_uneven_counter[0][0] ==sortede_even_counter[0][0]:
    ans = (n/2 - sortede_uneven_counter[1][1]) + (n/2 - sortede_even_counter[0][1])
    ans2 = (n/2 - sortede_uneven_counter[0][1]) + (n/2 - sortede_even_counter[1][1])
    if ans2<ans:
      ans = ans2

print(int(ans))

Submission status: Accepted

Solution code:
n=int(input())
v=list(input().split())
v0={}
v1={}
for i in range(0,n,2):
    if v[i] in v0:
        v0[v[i]]+=1
    else:
        v0[v[i]]=1
for i in range(1,n,2):
    if v[i] in v1:
        v1[v[i]]+=1
    else:
        v1[v[i]]=1
v0=sorted(v0.items(), key=lambda x:x[1], reverse=True)
v1=sorted(v1.items(), key=lambda x:x[1], reverse=True)
if v0[0][0]==v1[0][0]:
    if len(v0)==1:
        print(int(n/2))
    else:
        print(n-v0[0][1]-(v0[1][1] if v0[1][1]>v1[1][1] else v1[1][1] ))
else:
    print(n-v0[0][1]-v1[0][1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a1 = a[::2]
a2 = a[1::2]

from collections import Counter
c = Counter(a1)
c1 = []
for i in c:
    c1.append([c[i],i])
c1.sort(reverse = True)

c = Counter(a2)
c2 = []
for i in c:
    c2.append([c[i],i])
c2.sort(reverse = True)

ans = n
if c1[0][1] != c2[0][1]:
    ans -= c1[0][0]
    ans -= c2[0][0]
else:
    buf1 = 0
    buf1 += c1[0][0]
    if len(c2) > 1: buf1 += c2[1][0]
    buf2 = 0
    buf2 += c2[0][0]
    if len(c1) > 1: buf2 += c1[1][0]
    ans -= max(buf1,buf2)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
V = list(map(int,input().split()))
O = []
E = []
nums_O = []
nums_E = []

for i in range(0,N,2):
  O.append(V[i])
  E.append(V[i+1])

for j in range(100000):
  nums_O.append([0,j])
  nums_E.append([0,j])

for k in range(N//2):
  nums_O[O[k]-1][0] += 1
  nums_E[E[k]-1][0] += 1
  
nums_O.sort()
nums_E.sort()
##print(O,E,nums_O[-1],nums_E[-1])
if nums_O[-1][1] != nums_E[-1][1]:
  print(N-(nums_O[-1][0] + nums_E[-1][0]))
else:
  print(N-max(nums_E[-2][0]+nums_O[-1][0],nums_O[-2][0]+nums_E[-1][0]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	sample
# CreatedDate:  2020-09-27 14:00:12 +0900
# LastModified: 2020-09-27 14:35:21 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    v_even = [v[i] for i in range(0, len(v), 2)]
    v_odd = [v[i] for i in range(1, len(v), 2)]
    even_cnt = sorted(map(list, Counter(v_even).items()), key=lambda x: x[1], reverse=True)
    odd_cnt = sorted(map(list, Counter(v_odd).items()), key=lambda x: x[1], reverse=True)
    odd_impo = 0
    even_impo = 0
    if len(even_cnt) == 1 and len(odd_cnt) == 1:
        if even_cnt[0][0] == odd_cnt[0][0]:
            if even_cnt[0][1] < odd_cnt[0][1]:
                print(even_cnt[0][1])
                return

            else:
                print(even_cnt[0][1])
                return

    if even_cnt[0][0] == odd_cnt[0][0]:
        if even_cnt[0][1] == odd_cnt[0][1]:
            if even_cnt[1][1] < odd_cnt[1][1]:
                odd_impo = 1
                even_impo = 0

            elif even_cnt[1][1] > odd_cnt[1][1]:
                odd_impo = 0
                even_impo = 1

            else:
                odd_impo = 1
                even_impo = 0

        elif even_cnt[0][1] < odd_cnt[0][1]:
            odd_impo = 0
            even_impo = 1

        else:
            odd_impo = 1
            even_impo = 0

    ans = len(v_even) - even_cnt[even_impo][1] + len(v_odd) - odd_cnt[odd_impo][1]

    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections
url = "https://atcoder.jp//contests/abc111/tasks/arc103_a"

def main():
    input()
    t = list(map(int, input().split()))
    even_lis = t[::2]
    odd_lis = t[1::2]
    e = collections.Counter(even_lis).most_common()
    odd = collections.Counter(odd_lis).most_common()
    if e[0][0] == odd[0][0]:
        if e[0][1] + odd[0][1] == len(t):
            print(e[0][1])
            exit()
        else:
            print((len(t) - max(e[0][1], odd[0][1]) - max(e[1][1], odd[1][1])))
            exit()
    else:
        print(len(t) - e[0][1] - odd[0][1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

n = int(input())
n_half = n//2
v = list(map(int, input().split()))
v_gusu = v[0::2]
v_odd = v[1::2]
ans = 0
c1 = collections.Counter(v)
c2 = collections.Counter(v_gusu)
c3 = collections.Counter(v_odd)

if c1.most_common()[0][1] == n:
    print(n_half)
    exit()

if c2.most_common()[0][0] == c3.most_common()[0][0]:
    print(min((n_half - c2.most_common()[1][1]) + (n_half - c3.most_common()[0][1]),(n_half - c2.most_common()[0][1]) + (n_half - c3.most_common()[1][1])))
    exit()
else:
    print((n_half - c2.most_common()[0][1]) + (n_half - c3.most_common()[0][1]))
    exit()

Submission status: Accepted

Solution code:
n = int(input())
V = list(map(int, input().split()))
from collections import Counter
even = Counter(V[0::2])
even["0"]=0
even = sorted(even.items(), key=lambda x:x[1], reverse=True)
odd = Counter(V[1::2])
odd["-1"]=0
odd = sorted(odd.items(), key=lambda x:x[1], reverse=True)
i=0
even_top2, odd_top2 = [], []
for (e, o) in zip(even, odd):
  i+=1
  even_top2.append(e)
  odd_top2.append(o)
  if i==2:
    break
if even_top2[0][0] != odd_top2[0][0]:
  notchange = even_top2[0][1] + odd_top2[0][1]
else:
  notchange = max(even_top2[0][1]+odd_top2[1][1], even_top2[1][1]+odd_top2[0][1])
print(n-notchange)

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]

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

e_max1 = [0, 0]
e_max2 = [0, 0]
o_max1 = [0, 0]
o_max2 = [0, 0]

for x, y in c_even.items():
    if y > e_max1[1]:
        e_max2 = e_max1
        e_max1 = [x, y]
    elif y > e_max2[1]:
        e_max2 = [x, y]

for x, y in c_odd.items():
    if y > o_max1[1]:
        o_max2 = o_max1
        o_max1 = [x, y]
    elif y > o_max2[1]:
        o_max2 = [x, y]


if e_max1[0] == o_max1[0]:
    print(min(n - e_max1[1] - o_max2[1], n - e_max2[1] - o_max1[1]))
else:
    print(n - e_max1[1] - o_max1[1])

Submission status: Accepted

Solution code:
#100 C - /\/\/\/ AC
import collections
n = int(input())
A = list(map(int,input().split()))

A1 = A[::2]
A2 = A[1::2]
cnt1 = collections.Counter(A1)
cnt2 = collections.Counter(A2)

items1 = list(cnt1.most_common())
items2 = list(cnt2.most_common())

if items1[0][0] != items2[0][0]:
    ans = (len(A1) - items1[0][1]) + (len(A2) - items2[0][1])
else:
    if len(items1) == len(items2) == 1:
        ans = min(len(A1),len(A2))

    else:
        ans1 = (len(A1) - items1[0][1]) + (len(A2) - items2[1][1])
        ans2 = (len(A1) - items1[1][1]) + (len(A2) - items2[0][1])
        ans = min(ans1,ans2)
print(ans)

Submission status: Accepted

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

#import
#import math
#import numpy as np
n = int(input())
V = list(map(int, input().split()))

even = {0:0}
odd = {0:0}

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

omax = 0
emax = 0
onext = 0
enext = 0

for e in even:
    if even[e] > even[emax]:
        if even[emax] > even[enext]:
            enext = emax
        emax = e
    elif even[e] > even[enext]:
        enext = e

for o in odd:
    if odd[o] > odd[omax]:
        if odd[omax] > odd[onext]:
            onext = omax
        omax = o
    elif odd[o] > odd[onext]:
        onext = o

if omax != emax:
    print(n - even[emax] - odd[omax])
else:
    print(n - even[emax] - odd[omax] + min(even[emax] - even[enext], odd[omax] - odd[onext]))

Submission status: Accepted

Solution code:
#100 C - /\/\/\/
import collections
n = int(input())
A = list(map(int,input().split()))

A1 = A[::2]
A2 = A[1::2]
cnt1 = collections.Counter(A1)
cnt2 = collections.Counter(A2)

items1 = list(cnt1.items())
items2 = list(cnt2.items())
items1 = sorted(items1,key = lambda x:x[1],reverse = True)
items2 = sorted(items2,key = lambda x:x[1],reverse = True)

if items1[0][0] != items2[0][0]:
    ans = (len(A1) - items1[0][1]) + (len(A2) - items2[0][1])
else:
    if len(items1) == len(items2) == 1:
        ans = min(len(A1),len(A2))

    else:
        ans1 = (len(A1) - items1[0][1]) + (len(A2) - items2[1][1])
        ans2 = (len(A1) - items1[1][1]) + (len(A2) - items2[0][1])
        ans = min(ans1,ans2)
print(ans)

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
import collections


# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, Vi):
    V1 = Vi[::2]
    V2 = Vi[1::2]
    c_V1 = dict(collections.Counter(V1))
    c_V2 = dict(collections.Counter(V2))
    c_V1 = sorted(c_V1.items(), key=lambda x: x[1], reverse=True)
    c_V2 = sorted(c_V2.items(), key=lambda x: x[1], reverse=True)
    c_V1.append((-1, 0))
    c_V2.append((-1, 0))
    ans = 0
    if c_V1[0][0] == c_V2[0][0]:
        ans = min(len(V1) - c_V1[0][1] + len(V2) - c_V2[1][1],
                  len(V1) - c_V1[1][1] + len(V2) - c_V2[0][1])
    else:
        ans = len(V1) - c_V1[0][1] + len(V2) - c_V2[0][1]
    print(ans)


if __name__ == '__main__':
    N = int(input())
    Vi = [int(i) for i in input().split()]
    solve(N, Vi)

    # # test
    # from random import randint
    # from func import random_str

Submission status: Accepted

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

from collections import Counter

def get_counter(X):
  counter = Counter(X)
  X = sorted(counter.items(), key = lambda x:x[1], reverse = True)
  X.append((0,0))
  return X

V1 = get_counter(V[::2])
V2 = get_counter(V[1::2])

if V1[0][0] != V2[0][0]:
  print(N - (V1[0][1] + V2[0][1]))
else:
  print(N - max(V1[0][1] + V2[1][1],V1[1][1] + V2[0][1]))

Submission status: Accepted

Solution code:
import collections
n = int(input())
v = [int(x) for x in input().split()]
v_odd, v_evn = [], []
for i in range(n):
  if i%2==0:
    v_odd.append(v[i])
  else:
    v_evn.append(v[i])
v_odd_cnt = collections.Counter(v_odd)
v_evn_cnt = collections.Counter(v_evn)
if len(v_odd_cnt) == len(v_evn_cnt) == 1:
  if v[0] == v[1]:
    print(n//2)
    exit()
  else:
    print(0)
    exit()
max_kv_odd = max(v_odd_cnt.items(), key=lambda x: x[1])
max_kv_evn = max(v_evn_cnt.items(), key=lambda x: x[1])
if max_kv_odd[0] == max_kv_evn[0]:
  if len(v_odd_cnt) == 1:
    v_evn_cnt.pop(max_kv_evn[0])
    max_kv_evn_tmp = max(v_evn_cnt.items(), key=lambda x: x[1])
    print(n-max_kv_odd[1]-max_kv_evn_tmp[1])
    exit()
  if len(v_evn_cnt) == 1:
    v_odd_cnt.pop(max_kv_odd[0])
    max_kv_odd_tmp = max(v_odd_cnt.items(), key=lambda x: x[1])
    print(n-max_kv_odd_tmp[1]-max_kv_evn[1])
    exit()
  v_odd_cnt_tmp = v_odd_cnt
  v_evn_cnt_tmp = v_evn_cnt
  v_odd_cnt_tmp.pop(max_kv_odd[0])
  v_evn_cnt_tmp.pop(max_kv_evn[0])
  max_kv_odd_tmp = max(v_odd_cnt_tmp.items(), key=lambda x: x[1])
  max_kv_evn_tmp = max(v_evn_cnt_tmp.items(), key=lambda x: x[1])
  a = max_kv_odd[1] + max_kv_evn_tmp[1]
  b = max_kv_evn[1] + max_kv_odd_tmp[1]
  print(n-max(a, b))
  exit()
print(n-max_kv_odd[1]-max_kv_evn[1])

Submission status: Accepted

Solution code:
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1).most_common()
dic2 = Counter(list2).most_common()
dic1.append([0,0])
dic2.append([0,0])
if dic1[0][0]!=dic2[0][0]:
  print(n - dic1[0][1] - dic2[0][1])
else:
  print(min(n - dic1[0][1] - dic2[1][1], n -dic1[1][1] - dic2[0][1]))

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    n = int(input())
    vlst = list(map(int, input().split()))
    dd = [defaultdict(int), defaultdict(int)]
    dd[0][-1] = 0
    dd[1][-1] = 0
    for i, v in enumerate(vlst):
        dd[i % 2][v] += 1
    odd = sorted(dd[0].items(), key = lambda x:x[1], reverse = True)
    even = sorted(dd[1].items(), key = lambda x:x[1], reverse = True)
    if odd[0][0] != even[0][0]:
        minus = odd[0][1] + even[0][1]
        ans = n - minus
    else:
        minus = 0
        minus = max(minus, odd[0][1] + even[1][1])
        minus = max(minus, odd[1][1] + even[0][1])
        ans = n - minus
    print(ans)
main()

Submission status: Accepted

Solution code:
n=int(input())
v=list(map(int,input().split()))
cnt1=[0 for i in range(100001)]
cnt2=[0 for i in range(100001)]
for i in range(n):
    if i%2==0:
        cnt1[v[i]]+=1
    else:
        cnt2[v[i]]+=1
k1=0
k1m=0
k2=0
k2m=0
for i in range(100001):
    if cnt1[i]>=cnt1[k1]:
        k1,k1m=i,k1
    elif cnt1[i]>cnt1[k1m]:
        k1m=i
for i in range(100001):
    if cnt2[i]>=cnt2[k2]:
        k2,k2m=i,k2
    elif cnt2[i]>cnt2[k2m]:
        k2m=i
if k1!=k2:
    print(n-cnt1[k1]-cnt2[k2])
else:
    print(n-(cnt1[k1]+max(cnt1[k1m],cnt2[k2m])))

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)
    exit()

kisu = Counter(v[::2]).most_common(2)
gusu = Counter(v[1::2]).most_common(2)

if kisu[0][0] == gusu[0][0]:
    keep = max(kisu[1][1] + gusu[0][1],
               kisu[0][1] + gusu[1][1])
else:
    keep = kisu[0][1] + gusu[0][1]

print(n - keep)

Submission status: Accepted

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
even_odd_length = n / 2
replace_total = 0

list_odd = v[0::2]
list_even = v[1::2]

dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))
dict_c_even_bk = dict_c_even.copy()

replace_total_tmp = 0
replace_total_tmp2 = 0

max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even

max_c_odd_keys = [k for k, v in dict_c_odd.items() if v == max_count_c_odd]
max_c_even_keys = [k for k, v in dict_c_even.items() if v == max_count_c_even]

if len(set(v)) == 1:
    print(int(even_odd_length))
else:    
    if max_c_odd_keys[0] in dict_c_even:
        del dict_c_even[max_c_odd_keys[0]]
    max_count_c_even = max(dict_c_even.values())
    replace_total_tmp = (n - max_count_c_odd - max_count_c_even)
    
    dict_c_even = dict_c_even_bk
    max_count_c_even = max_count_c_even_bk
    
    if max_c_even_keys[0] in dict_c_odd:
        del dict_c_odd[max_c_even_keys[0]]
    max_count_c_odd = max(dict_c_odd.values())
    replace_total_tmp2 = (n - max_count_c_odd - max_count_c_even)
    
    if replace_total_tmp >= replace_total_tmp2:
         replace_total = replace_total_tmp2
    else:
         replace_total = replace_total_tmp

    print(replace_total)

Submission status: Accepted

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
even_odd_length = n / 2
replace_total = 0

list_odd = v[0::2]
list_even = v[1::2]

dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))
dict_c_even_bk = dict_c_even.copy()
dict_c_odd_bk = dict_c_odd.copy()

replace_total_tmp = 0
replace_total_tmp2 = 0
max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even
max_c_odd_keys = [k for k, v in dict_c_odd.items() if v == max_count_c_odd]
max_c_even_keys = [k for k, v in dict_c_even.items() if v == max_count_c_even]

if len(set(v)) == 1:
    print(int(even_odd_length))
else:    
    if max_c_odd_keys[0] in dict_c_even:
        del dict_c_even[max_c_odd_keys[0]]
    max_count_c_even = max(dict_c_even.values())
    replace_total_tmp = (n - max_count_c_odd - max_count_c_even)
    
    dict_c_even = dict_c_even_bk
    max_count_c_even = max_count_c_even_bk
    
    if max_c_even_keys[0] in dict_c_odd:
        del dict_c_odd[max_c_even_keys[0]]
    max_count_c_odd = max(dict_c_odd.values())
    replace_total_tmp2 = (n - max_count_c_odd - max_count_c_even)
    
    if replace_total_tmp >= replace_total_tmp2:
         replace_total = replace_total_tmp2
    else:
         replace_total = replace_total_tmp
    print(replace_total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 17 21:11:38 2020

@author: liang
"""

"""
【２番目の取得】
"""
n = int(input())
E = list()
O = list()
i = 0
for v in input().split():
    if i%2 == 0:
        E.append(int(v))
    else:
        O.append(int(v))
    i += 1
#print(E)
#print(O)
edic = {}
odic = {}
for e in E:
    if e not in edic.keys():
        edic[e] = 1
    else:
        edic[e] += 1

for o in O:
    if o not in odic.keys():
        odic[o] = 1
    else:
        odic[o] += 1
        
etmp = [(-1,0),(-1,0)]
otmp = [(-1,0),(-1,0)]

for key in edic.keys():
    #first
    if edic[key] > etmp[0][1]:
        etmp[1] = etmp[0]
        etmp[0] = (key, edic[key])
    #second
    elif edic[key] > etmp[1][1]:
        etmp[1] = (key,edic[key])

for key in odic.keys():
    #first
    if odic[key] > otmp[0][1]:
        otmp[1] = otmp[0]
        otmp[0] = (key, odic[key])
    #second
    elif odic[key] > otmp[1][1]:
        otmp[1] = (key,odic[key])

if etmp[0][0] == otmp[0][0]:
    ans = max(etmp[0][1]+otmp[1][1],etmp[1][1]+otmp[0][1])
else:
    ans = etmp[0][1]+otmp[0][1]
print(n-ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 17 20:29:30 2020

@author: liang
"""

n = int(input())
E = list()
O = list()
i = 0
for v in input().split():
    if i%2 == 0:
        E.append(int(v))
    else:
        O.append(int(v))
    i += 1
#print(E)
#print(O)
edic = {-1:0}
odic = {-1:0}
for e in E:
    if e not in edic.keys():
        edic[e] = 1
    else:
        edic[e] += 1

for o in O:
    if o not in odic.keys():
        odic[o] = 1
    else:
        odic[o] += 1

etup = list()
otup = list()
for e in edic.keys():
    etup.append((e,edic[e]))
for o in odic.keys():
    otup.append((o,odic[o]))    
etup.sort(reverse=True,key=lambda x:x[1])
otup.sort(reverse=True,key=lambda x:x[1])

#print(etup)
#print(otup)
i = 0
j = 0
while True:
    ekey, etmp = etup[i]
    okey, otmp = otup[j]
    if ekey != okey:
        break
    if etup[i+1][1] < otup[j+1][1]:
        j += 1
    else:
        i += 1
    #rint("calc")

#print(edic)

ans = n - etmp - otmp
    
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    # n, k = map(int, input().split())
    v = list(map(int, input().split()))
    # s = input()

    even = [0] * (10 ** 5 + 100)
    odd = [0] * (10 ** 5 + 100)

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

    max_even = even.index(max(even))
    max_odd = odd.index(max(odd))

    if max_even == max_odd:
        even[max_even] = 0
        odd[max_odd] = 0
        if max(even) < max(odd):
            max_odd = odd.index(max(odd))
        else:
            max_even = even.index(max(even))
    ans = 0
    for i in range(n):
        if i % 2 == 0 and max_even != v[i]:
            ans += 1
        if i % 2 != 0 and max_odd != v[i]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

kisu = [0]*(10**6)
gusu = [0]*(10**6)
for i in range(n):
    if i % 2 == 0:
        gusu[v[i]] += 1
    else:
        kisu[v[i]] += 1

count = 0
gusu_m = gusu.index(max(gusu))
kisu_m = kisu.index(max(kisu))

if gusu_m == kisu_m:

    gusu[gusu_m] = 0
    kisu[kisu_m] = 0
    if max(gusu) > max(kisu):
        gusu_m = gusu.index(max(gusu))
    else:
        kisu_m = kisu.index(max(kisu))

for i in range(n):
    if i % 2 == 0 and gusu_m != v[i]:
        count += 1
    if i % 2 != 0 and kisu_m != v[i]:
        count += 1

print(count)

Submission status: Accepted

Solution code:
from collections import Counter

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

if a.count(a[0])==n:
    print(n//2)
    exit()


x=a[::2]
y=a[1::2]

xx=Counter(x)
yy=Counter(y)

xxx=xx.most_common()
yyy=yy.most_common()

if xxx[0][0]!=yyy[0][0]:
    print(n-xxx[0][1]-yyy[0][1])

else:
    print(min(n-xxx[1][1]-yyy[0][1],n-xxx[0][1]-yyy[1][1]))

Submission status: Accepted

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

v_odd = [0] * (n // 2)
v_even = [0] * (n // 2)

for i in range(n):
  if (i + 1) % 2 == 1:
    v_odd[i//2] += v_lis[i]
  else:
    v_even[i//2] += v_lis[i]
    
v_odd, v_even = Counter(v_odd).most_common(), Counter(v_even).most_common()

if v_odd[0][0] != v_even[0][0]:
  cnt = v_odd[0][1] + v_even[0][1]

else:
  tmp1 = v_odd[0][1] + (v_even[1][1] if len(v_even) >= 2 else 0)
  tmp2 = v_even[0][1] + (v_odd[1][1] if len(v_odd) >= 2 else 0)
  cnt = max(tmp1, tmp2)

print(n - cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
o = defaultdict(int)
e = defaultdict(int)
odd_num = 0
even_num = 0
for i, v_one in enumerate(v):
  if i % 2 == 1:
    o[v_one] += 1
    odd_num += 1
  else:
    e[v_one] += 1
    even_num += 1
sorted_o = sorted(o.items(), key=lambda x:-x[1])
sorted_e = sorted(e.items(), key=lambda x:-x[1])
if sorted_o[0][0] != sorted_e[0][0]:
  ans = odd_num - sorted_o[0][1] + even_num - sorted_e[0][1]
elif len(sorted_o) >= 2 and len(sorted_e) >= 2:
  ans1 = odd_num - sorted_o[1][1] + even_num - sorted_e[0][1]
  ans2 = odd_num - sorted_o[0][1] + even_num - sorted_e[1][1]
  ans = min(ans1, ans2)
elif len(sorted_o) >= 2:
  ans = sorted_o[0][1]
elif len(sorted_e) >=2:
  ans = sorted_e[0][1]
else:
  ans = odd_num
print(ans)