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: Runtime Error

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

dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
    if i%2==0:    
        dic0[v[i]] += 1
    if i%2==1:
        dic1[v[i]] += 1

MX0_1 = max(dic0)
MX1_1 = max(dic1)

li0 = []
li1 = []


for i in range(10**5+1):
    if dic0[i]>10:
        #print(i,dic0[i])
    if dic1[i]>10:
        #print(i,dic1[i],"\n")
    
    if dic0[i] == MX0_1:
        li0.append(i)
        dic0[i] = 0
    if dic1[i] == MX1_1:
        li1.append(i)
        dic1[i] = 0

# print(li0,li1)
# print(MX0_1,MX0_1)

if len(li0)>=2 or len(li1)>=2:
    print(n-MX0_1-MX1_1)
elif li0[0] == li1[0]:
    if MX0_1+max(dic1) >= MX1_1+max(dic0):
        print(n-MX0_1-max(dic1))
    else:
        print(n-MX1_1-max(dic0))
        print(1/0)

elif li0[0] != li1[0]:
    print(n-MX0_1-MX1_1)

Submission status: Runtime Error

Solution code:
n = int(input())
S = list(input())
S0 = {}
S1 = {}
for i, item in enumerate(S):
  if i%2 == 0:
    if item not in S0:
      S0[item] =1
    else:
      S0[item] += 1
  else:
    if item not in S1:
      S1[item] =1
    else:
      S1[item] += 1

S0list = list(S0.values()).sort(reverse=True)
S1list = list(S1.values()).sort(reverse=True)

S00 = S0list[0]
if len(S0list) == 1:
  S01 = 0
else:
  S01 = S0list[1]
S10 = S1list[0]
if len(S1list) == 1:
  S11 = 0
else:
  S11 = S1list[1]
Answer = min(len(S) - S00 - S11,len(S) - S01 - S10)

print(Answer)

Submission status: Runtime Error

Solution code:
#ABC111C
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[::2]).most_common(2)
b=Counter(v[::-2]).most_common(2)
#most_common()の引数は頻度が高い数を何番目まで表示するか
if a[0][0]!=b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(n-max(a[0][1]+b[1][1],a[1][1]+b[0][1]))

Submission status: Runtime Error

Solution code:
#ABC111C
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[::2]).most_common(2)
b=Counter(v[1::2]).most_common(2)
#most_common()の引数は頻度が高い数を何番目まで表示するか
if a[0][0]!=b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(n-max(a[0][1]+b[1][1],a[1][1]+b[0][1]))

Submission status: Runtime Error

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

print(V)

V1 = V[0::2]
V2 = V[1::2]

import collections

def count_change(V):
    res = collections.Counter(V)
    if len(res) == 1:
        return(0)
    else:
        return min(res.values())

if len(set(V)) == 1:
    print(len(set(V)))
    print("all element is equal")
    print(int(len(V)/2))
else:
    print(count_change(V1) + count_change(V2))
~

Submission status: Runtime Error

Solution code:
from collections import Counter

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

a = Counter(v[::2])
b = Counter(v[1::2])
a = a.most_common()
b = b.most_common()

if n % 2 == 0:
    al = n // 2
    bl = al
else:
    al = n // 2 + 1
    bl = n // 2

if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(min(a[0][1], b[0][1]))
    else:
        print(0)
elif len(a) == 1 or len(bl) == 1:
    if len(a) == 1:
        if a[0][0] == b[0][0]:
            print(bl - b[1][1])
        else:
            print(bl - b[0][1])
    if len(b) == 1:
        if a[0][0] == b[0][0]:
            print(al - a[1][1])
        else:
            print(al - a[0][1])
else:
     if a[0][0] == b[0][0]:
         print(min(n - a[0][1] - b[1][1], n - a[1][1] - b[0][1])) 
     else:
         print(n - a[0][1] - b[0][1])

Submission status: Runtime Error

Solution code:

n = int(input())
V = list(map(int, input().split()))
A = [] # 偶数
B = [] # 奇数

inf = 999999999999999999999

import collections

for i in range(n):
  if i % 2 == 0:
    A.append(V[i])
  else:
    B.append(V[i])

A = collections.Counter(A).most_common()
B = collections.Counter(B).most_common()

count = 0

if A[0][0] == B[0][0]:
  count += min(A[0][1], B[0][1])
  if A[0][1] == B[0][1]:
    if A[1][1] > B[1][1]:
      A.pop(0)
    else:
      B.pop(0)
    

A.pop(0)
B.pop(0)

for key, value in A:
  count += value

for  key, value in B:
  count += value

print(count)

Submission status: Runtime Error

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

for i,key in enumerate(v):
    if i%2 == 0:
        if key not in dict1:
            dict1[key] = 1
        else:
            dict1[key] += 1
    else:
        if key not in dict2:
            dict2[key] = 1
        else:
            dict2[key] += 1

max1 = 0
max2 = 0
if len(dict1) == 1 and len(dict2) == 1:
    if v[0] == v[1]:
        ans = n//2
    else:
        ans = 0
elif len(dict1) == 1:
    dict2[v[0]] = 0
    for key in dict2:
        max2 = max(max2,dict2[key])
    else:
        ans = n//2 - max2
elif len(dict2) == 1:
        dict2[v[1]] = 0
        for key in dict1:
            max1 = max(max1,dict1[key])
        else:
            ans = n//2 - max1
else:
    second1 = 0
    second2 = 0
    maxkey1 = 0
    maxkey2 = 0
    secondkey1 = 0
    secondkey2 = 0
    for key in dict1:
        if dict1[key] > max1:
            max1,second1, = dict1[key],max1
            maxkey1,secondkey1 = key,maxkey1
        elif dict1[key] > second1:
            second1 = dict1[key]
    for key in dict2:
        if dict2[key] > max2:
            max2,second2, = dict2[key],max2
            maxkey2,secondkey2 = key,maxkey2
        elif dict2[key] > second2:
            second2 = dict2[key]
    if maxkey1 == maxkey2:
        if dict1[secondkey1] < dict2[secondkey2]:
            ans = n - dict1[maxkey1] - dict2[secondkey2]
        else:
            ans = n - dict2[maxkey2] - dict1[secondkey1]
    else:
        ans = n - dict1[maxkey1] - dict2[maxkey2]

print(ans)

Submission status: Runtime Error

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

if len(set(v)) == 1:
    ans = n // 2
else:
    even = [0] * 10 ** 5
    odd = [0] * 10 ** 5

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

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

    ans = n - max(even) - max(odd)

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = L[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

odd_1 = l_even[0]
even_1 = l_even[0]

if even_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

even_2 = l_even[1]
odd_2 = l_odd[1]

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
even_1 = c_even[0]
even_2 = c_even[1]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

even_2 = c_even[1]
odd_2 = c_odd[1]

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
odd_2 = c_odd[1]
even_1 = c_even[0]
even_2 = c_even[1]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
a = Counter(a)
b = Counter(b)
p = a.most_common()[0][1]
q = b.most_common()[0][1]

if a.most_common()[0][0] == b.most_common()[0][0]:
    if p == n//2:
        if q == n//2:
            print(n-p-q+n//2)
        else:
            print(n-p-q+(n//2-b.most_common[1][1]))
    else:
        if q != n//2:
            print(n-p-q+n-a.most_common[1][1]-b.most_common[1][1])
        else:
            print(n-p-q+(n//2-a.most_common[1][1]))
            
    
        
            
        

else:
    print(n-p-q)

Submission status: Runtime Error

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

from collections import Counter
l1 = Counter(l[0::2])
mostl1 = l1.most_common()[0]
#semimostl1 = l1.most_common()[1]

l2 = Counter(l[1::2])
mostl2 = l2.most_common()[0]
#semimostl2 = l2.most_common()[1]

if mostl1[0] != mostl2[0]:
    print(n-mostl1[1]-mostl2[1])
else:
    semimostl1 = l1.most_common()[1]
    semimostl2 = l2.most_common()[1]
    print(min(n - mostl1[1] - semimostl2[1], n - semimostl1[1] - mostl2[1]))
    
    
#elif print(min(n-mostl1[1]-mostl2[1],n-mostl1[1]-mostl2[1]))

Submission status: Runtime Error

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

from collections import Counter
l1 = Counter(l[0::2])
mostl1 = l1.most_common()[0]
semimostl1 = l1.most_common()[1]

l2 = Counter(l[1::2])
mostl2 = l2.most_common()[0]
semimostl2 = l2.most_common()[1]

if mostl1[0] != mostl2[0]:
    print(n-mostl1[1]-mostl2[1])
#elif print(min(n-mostl1[1]-mostl2[1],n-mostl1[1]-mostl2[1]))

Submission status: Runtime Error

Solution code:
F=[]
G=[]
for i in range(N):
  if i%2==0:
    F +=[A[i]]
  else:
    G +=[A[i]]
answer=float('inf')
for i in range(min(F),max(F)+1):
  for j in range(min(G),max(G)+1):
    if i==j:
      break
    diff =0
    for k in range(N//2):
      diff += abs(F[k]-i)+abs(G[k]-j)
    answer=min(answer,diff)
print(answer if answer!=float('inf') else N//2)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = []
even_c = 0
odd = []
odd_c = 0
ans = 0
for i in range(len(v)):
    print(i)
    if i % 2 == 0:
        even.append(v[i])
        even_c += 1
    else:
        odd.append(v[i])
        odd_c += 1
        
even = collections.Counter(even)
odd = collections.Counter(odd)
even_max = max(list(even.items()), key = lambda x: x[1])
odd_max = max(list(odd.items()), key = lambda x: x[1])
if even_max[0] == odd_max[0]:
    even_sec = [i for i in list(even.items()) if i[0] != even_max[0]] 
    odd_sec = [i for i in list(odd.items()) if i[0] != odd_max[0]]
    if len(even_sec) == 0 and len(odd_sec) == 0:
        print(min(even_max[1], odd_max[1]))
        exit()
    if len(even_sec) == 0:
        ans += min(even_max[1], odd_c - odd_max[1])
        print(ans)
        exit()
    if len(odd_sec) == 0:
        ans += min(odd_max[1], even_c - even_max[1])
        print(ans)
        exit()
    even_sec = max(even_sec, key = lambda x: x[1])
    odd_sec = max(odd, key = lambda x: x[1])
    if even_max[1] > odd_max[1]:
        ans += even_c - even_max[1]
        ans += odd_c - odd_sec[1]
    elif even_max[1] < odd_max[1]:
        ans += odd_c - odd_max[1]
        ans += even_c - even_sec[1]
    else:
        if odd_sec[1] < even_sec[1]:
            ans += even_c - even_sec[1]
            ans += odd_c - odd_max[1]
        elif odd_sec[1] > even_sec[1]:
            ans += odd_c - odd_sec[1]
            ans += even_c - even_max[1]
        else:
            ans += even_c - even_max[1]
            ans += odd_c - odd_sec[1]
else:
    ans += even_c - even_max[1]
    ans += odd_c - odd_max[1]
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = []
even_c = 0
odd = []
odd_c = 0
ans = 0
for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
        even_c += 1
    else:
        odd.append(v[i])
        odd_c += 1
even  = collections.Counter(even)
odd = collections.Counter(odd)
even_max = max(list(even.items()), key = lambda x: x[1])
odd_max = max(list(odd.items()), key = lambda x: x[1])
if even_max[0] == odd_max[0]:
    even_sec = [i for i in list(even.items()) if i[0] != even_max[0]] 
    odd_sec = [i for i in list(odd.items()) if i[0] != odd_max[0]]
    if len(even_sec) == 0 and len(odd_sec) == 0:
        print(min(even_max[1], odd_max[1]))
        exit()
    if len(even_sec) == 0:
        ans += min(even_max[1], odd_c - odd_max[1])
        print(ans)
        exit()
    if len(odd_sec) == 0:
        ans += min(odd_max[1], even_c - even_max[1])
        print(ans)
        exit()
    even_sec = max(even_sec, key = lambda x: x[1])
    odd_sec = max(odd, key = lambda x: x[1])
    if even_max[1] > odd_max[1]:
        ans += even_c - even_max[1]
        ans += odd_c - odd_sec[1]
    elif even_max[1] < odd_max[1]:
        ans += odd_c - odd_max[1]
        ans += even_c - even_sec[1]
    else:
        if odd_sec[1] < even_sec[1]:
            ans += even_c - even_sec[1]
            ans += odd_c - odd_max[1]
        elif odd_sec[1] > even_sec[1]:
            ans += odd_c - odd_sec[1]
            ans += even_c - even_max[1]
        else:
            ans += even_c - even_max[1]
            ans += odd_c - odd_sec[1]
else:
    ans += even_c - even_max[1]
    ans += odd_c - odd_max[1]
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
v.insert(0,0) #数合わせ
check=0 #全部同じ数字か？0なら全部同じ数字
now=v[1]
for i in range(2,n):
    if now!=v[i]:
        check=1
        break
        
odd=[]
even=[]
for i in range(1,n+1):
    if i%2==1:
        odd.append(v[i])
    else:
        even.append(v[i])
        
odd2=sorted(odd)
even2=sorted(even)
now_odd,now_even=odd2[0],even2[0]
rensa_odd,rensa_even=1,1
half=n//2
count_odd=[]
count_even=[]

for i in range(1,half):
    if odd2[i]==now_odd:
        rensa_odd+=1
    else:
        count_odd.append([rensa_odd,now_odd])
        now_odd=odd2[i]
        rensa_odd=1
count_odd.append([rensa_odd,now_odd])

for i in range(1,half):
    if even2[i]==now_even:
        rensa_even+=1
    else:
        count_even.append([rensa_even,now_even])
        now_even=even2[i]
        rensa_even=1
count_even.append([rensa_even,now_even])
count_odd2=sorted(count_odd,reverse=True)
count_even2=sorted(count_odd,reverse=True)

if check==0:
    print(half)
else:
    if count_odd2[0][1]!=count_even2[0][1]: #最頻値が違う
        print((half-count_odd2[0][0])+(half-count_even2[0][0]))
    else:
        if len(count_odd2)==1:
            print((half-count_odd2[0][0])+(half-count_even2[1][0]))
        elif len(count_even2)==1:
            print((half-count_odd2[1][0])+(half-count_even2[0][0]))
        else:
            print(min((half-count_odd2[0][0])+(half-count_even2[1][0]),(half-count_odd2[1][0])+(half-count_even2[0][0])))

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ev = [v[i] for i in range(n) if i % 2 == 0]
ov = [v[i] for i in range(n) if i % 2 == 1]
#print(ov,ev)
E = collections.Counter(ev).most_common()
#print(E)
if len(E) == 1:
    e = E[0][0]
    e1 = E[0][0]
    e2 = E[0][0]
else:
    e1 = E[0][0]
    e2 = E[1][0]
O = collections.Counter(ov).most_common()
#print(O)
if len(O) == 1:
    o = O[0][0]
    if e == o:
        print(n//2)
        exit()
    else:
        print(0)
        exit()
else:
    o1 = O[0][0]
    o2 = O[1][0]

tmp = 0
for i in range(n):
    if i % 2 == 0 and v[i] != e1:
        tmp += 1
    elif i % 2 == 1 and v[i] != o2:
        tmp += 1
ttmp = 0
for i in range(n):
    if i % 2 == 0 and v[i] != e2:
        ttmp += 1
    elif i % 2 == 1 and v[i] != o1:
        ttmp += 1
        
print(min(tmp,ttmp))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000000)
def list_count(my_list,n,x):
    dic={} #辞書型の宣言
    for i in range(x,n,2):
        if my_list[i] in dic: #もしnumがkeyとして辞書にあれば
            dic[my_list[i]]+=1 #valueに+1
        else: #なければ
            dic[my_list[i]]=1 #dicにnumというkeyを追加し、対応するvalueを1とする
    return dic

n=int(input())
v=list(map(int,input().split()))
dic0=list_count(v,n,0)
dic1=list_count(v,n,1)
a=[[0,0],[0,0]]
b=[[0,0],[0,0]]
for i in dic0.keys():
    if a[0][1]<=dic0[i]:
        a[1][0]=a[0][0]
        a[1][1]=a[0][1]
        a[0][0]=i
        a[0][1]=dic0[i]
    elif a[1][1]<dic0[1]:
        a[1][0]=i
        a[1][1]=dic0[i]
for i in dic1.keys():
    if b[0][1]<=dic1[i]:
        b[1][0]=b[0][0]
        b[1][1]=b[0][1]
        b[0][0]=i
        b[0][1]=dic1[i]
    elif b[1][1]<dic1[1]:
        b[1][0]=i
        b[1][1]=dic1[i]
if a[0][0]==b[0][0]:
    print(n-min(a[0][1]+b[1][1],a[1][1]+b[0][1]))
else:
    print(n-a[0][1]-b[0][1])

Submission status: Runtime Error

Solution code:
def list_count(my_list,n,x):
    dic={} #辞書型の宣言
    for i in range(x,n,2):
        if my_list[i] in dic: #もしnumがkeyとして辞書にあれば
            dic[my_list[i]]+=1 #valueに+1
        else: #なければ
            dic[my_list[i]]=1 #dicにnumというkeyを追加し、対応するvalueを1とする
    return dic

n=int(input())
v=list(map(int,input().split()))
dic0=list_count(v,n,0)
dic1=list_count(v,n,1)
a=[[0,0],[0,0]]
b=[[0,0],[0,0]]
for i in dic0.keys():
    if a[0][1]<=dic0[i]:
        a[1][0]=a[0][0]
        a[1][1]=a[0][1]
        a[0][0]=i
        a[0][1]=dic0[i]
    elif a[1][1]<dic0[1]:
        a[1][0]=i
        a[1][1]=dic0[i]
for i in dic1.keys():
    if b[0][1]<=dic1[i]:
        b[1][0]=b[0][0]
        b[1][1]=b[0][1]
        b[0][0]=i
        b[0][1]=dic1[i]
    elif b[1][1]<dic1[1]:
        b[1][0]=i
        b[1][1]=dic1[i]
if a[0][0]==b[0][0]:
    print(n-min(a[0][1]+b[1][1],a[1][1]+b[0][1]))
else:
    print(n-a[0][1]-b[0][1])

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

if N == 2:
    if V[0] == V[1]:
        print(0)
    else:
        print(1)
    exit()

d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = V[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_even[0][1] - l_odd[0][1])
else:
    ans1 = N - l_even[0][1] - l_odd[1][1]
    ans2 = N - l_even[1][1] - l_odd[0][1]
    print(min(ans1, ans2))

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = V[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

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

Submission status: Runtime Error

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

evenv, oddv = Counter(v[0::2]).most_common(), Counter(v[1::2]).most_common()
ans = 0
if evenv == oddv and len(evenv) == 1:
    ans = n // 2
elif evenv[0][0] == oddv[0][0]:
    ans = n - max(evenv[0][1] + oddv[1][1], evenv[1][1] + oddv[0][1])
else:
    ans = n - evenv[0][1] - oddv[0][1]
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1:
    if Cve1[0] == Cvo1[0]: ans = n//2
    else: ans = 0
elif len(Cve) == 1 and len(Cvo) != 1:
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1]
    else: ans = n//2 - Cvo1[1]
elif len(Cve) != 1 and len(Cvo) == 1:
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1]
    else: ans = n//2 - Cve1[2]
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve1[1] - Cvo1[1] 
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] > Cvo1[1]: ans = n - Cve1[1] - Cvo2[1]
        else: ans = n - Cve2[1] - Cvo1[1]
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1:
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo1[1]
    else: ans = 0
elif len(Cve) == 1 and len(Cvo) != 1:
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1]
    else: ans = n//2 - Cvo1[1]
elif len(Cve) != 1 and len(Cvo) == 1:
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1]
    else: ans = n//2 - Cve1[2]
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve1[1] - Cvo1[1] 
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] > Cvo1[1]: ans = n - Cve1[1] - Cvo2[1]
        else: ans = n - Cve2[1] - Cvo1[1]
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]

# eとoが1種しか数字をもたない
if len(Cve) == 1 and len(Cvo) == 1:
    if Cve1[0] == Cvo1[0]:
        ans = n//2 - Cvo1[1]
    else:
        ans = 0
elif len(Cve) == 1 and len(Cvo) != 1:
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]:
        ans = n//2 - Cvo2[1]
    else:
        ans = n//2 - Cvo1[1]

elif len(Cve) != 1 and len(Cvo) == 1:
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]:
        ans = n//2 - Cve2[1]
    else:
        ans = n//2 - Cve1[2]
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]

    if Cve1[0] != Cvo1[0]:
        ans = n - Cve1[1] - Cvo1[1] 
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] > Cvo1[1]:
            ans = n - Cve1[1] - Cvo2[1]
        else:
            an

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int,input().split()))
v_odd = []
v_even = []
for i in range(n//2):
    v_odd.append()
    v_even.append()
p1 = 0
p2 = 0
q1 = 0
q2 = 0
o_max = -1
e_max = -1
for i in range(n//2):
    a = v_odd[i]
    b = v_even[i]
    x = v_odd.count(a)
    y = v_even.count(b)
    if p1 <= x:
        if o_max != a:
            o_max = a
            p2 = p1
            p1 = x
    else:
        if x > p2:
            p2 = x
    if q1 <= y:
        if e_max != b:
            e_max = b
            q2 = q1
            q1 = y
    else:
        if y > q2:
            q2 = y
s = p1 + q1
if p1 == q1:
    if o_max == e_max:
        s = max(p2,q2) + p1
elif p1 > q2:
    if o_max == e_max:
        s = p1 + q2
else: 
    if o_max == e_max:
        s = p2 + q1
ans = n - s
print(ans)

Submission status: Runtime Error

Solution code:
import heapq



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

one = V[::2]
two = V[1:][::2]

one_count={}
one_len=len(one)
values={}
for o in one:
    if o in values:
        values[o] += 1
    else:
        values[o] = 1

one_count[10**6]=one_len
for k,v in values.items():
    one_count[k] = one_len-v


    
two_len=len(two)
two_count={}
values={}

for t in two:
    if o in values:
        values[t] += 1
    else:
        values[t] = 1

two_count[10**6]=two_len
for k,v in values.items():
    two_count[k] = two_len-v




keys = list(set(V))
mins = 1000

for one_key, one_value in one_count.items():
    for two_key, two_value in two_count.items():
        if one_key != two_key:
            if one_value + two_value < mins:
                mins = one_value + two_value
print(mins)

Submission status: Runtime Error

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt1 = [0] * (100100)
cnt2 = [0] * (100100)
for i in range(n):
    if (i % 2): cnt1[V[i]] += 1
    else: cnt2[V[i]] += 1 
lst1 = sorted(cnt1, reverse=True)
lst2 = sorted(cnt2, reverse=True)
c1 = list(filter(lambda c: c==lst1[0]))
c2 = list(filter(lambda c: c==lst2[0]))
if (len(c1) > 1 or len(c2) > 1):
    ans = 0
    i = 2
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans + max(lst1[0]+lst2[1], lst1[1]+lst2[0]))
else:
    i = 1
    ans = 0
    while (lst1[i] != 0 or lst2[i] != 0):
        if (lst1[i] != 0): ans += lst1[i]
        if (lst2[i] != 0): ans += lst2[i]
        i += 1
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
V = [int(x) for x in input().split()]
cnt1 = [0] * (10**5)
cnt2 = [0] * (10**5)
for i in range(n):
    if (i % 2): cnt1[V[i]] += 1
    else: cnt2[V[i]] += 1 
c1 = cnt1.index(max(cnt1))
c2 = cnt2.index(max(cnt2))    
lst1 = sorted(cnt1, reverse=True)
lst2 = sorted(cnt2, reverse=True)
i = 1
ans = 0
if (c1 == c2):
    ans += min(lst1[0], lst2[0])
while (lst1[i] != 0 or lst2[i] != 0):
    if (lst1[i] != 0): ans += lst1[i]
    if (lst2[i] != 0): ans += lst2[i]
    i += 1
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
n,*l=map(int,open(0).read().split())
f=lambda g:sorted([[len(list(v)),k]for k,v in itertools.groupby(g)])[-9:]
print(n-max(n//2,max(a+c for c,d in f(l[1::2])for a,b in f(l[::2])if b-d)))

Submission status: Runtime Error

Solution code:
from collections import Counter
import math

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

even = V[0::2]
odd = V[1::2]
even_max_cnt = Counter(even).most_common()
odd_max_cnt = Counter(odd).most_common()

cost = math.inf
res_freq_even = None
res_freq_odd = None
for e in even_max_cnt:
    for o in odd_max_cnt:
        if e[0] == o[0]:
            continue
        cost = min(cost, e[1]+o[1])
        res_freq_even = e
        res_freq_odd = o

if even_max_cnt[0][1] == len(even) and \
        odd_max_cnt[0][1] == len(odd) and \
        even_max_cnt[0][0] == odd_max_cnt[0][0]:
    ans = len(even)
else:
    ans = (len(even) - even_max_cnt[0][1]) + (len(odd) - odd_max_cnt[0][1])

print(ans)

Submission status: Runtime Error

Solution code:
import collections


n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:(x[1]),reverse=True)
even = sorted(collections.Counter(even).items(),key=lambda x:(x[1]),reverse=True)

if len(odd) == 1 and len(even) == 1:
    if odd[0][0] == even[0][0]:
        print(n//2)
    else:
        print(0)
elif len(odd) == 1 or len(even) == 1:
    if len(odd) == 1:
        print((n//2 - odd[1][1]) + (n//2 - even[1][1]))
    elif len(even) == 1:
        print((n//2 - odd[1][1]) + (n//2 - even[0][1]))
else:
    if odd[0][1] + even[1][1] > odd[1][1] + even[0][1]:
        print((n//2 - odd[0][1]) + (n//2 - even[1][1]))
    else:
        print((n//2 - odd[1][1]) + (n//2 - even[0][1]))

Submission status: Runtime Error

Solution code:
import collections


n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:(x[1]),reverse=True)
even = sorted(collections.Counter(even).items(),key=lambda x:(x[1]),reverse=True)

if len(odd) == 1 and len(even) == 1:
    if odd[0][0] == even[0][0]:
        print(n//2)
    else:
        print(0)
elif len(odd) == 1 or len(even) == 1:
    if len(odd) == 1:
        print((n//2 - odd[0][1]) + (n//2 - even[1][1]))
    elif len(even) == 1:
        print((n//2 - odd[1][1]) + (n//2 - even[1][1]))
else:
    if odd[0][1] + even[1][1] > odd[1][1] + even[0][1]:
        print((n//2 - odd[0][1]) + (n//2 - even[1][1]))
    else:
        print((n//2 - odd[1][1]) + (n//2 - even[0][1]))

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
odd = []
even = []
for i, j in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(), reverse=True, key=lambda x: x[1])
even = sorted(collections.Counter(even).items(), reverse=True, key=lambda x: x[1])

if len(odd) == 1 and len(even) == 1 and odd[0][0] == even[0][0]:
    print(n // 2)
elif odd[0][0] == even[0][0]:
    if odd[0][1] == even[0][1]:
        for i in range(n//2):
            if odd[i][1] == even[i][1]:
                continue
            elif odd[i][1] > even[i][1]:
                print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
            elif odd[i][1] < even[i][1]:
                print((n // 2 - odd[1][1]) + (n // 2 - even[0][1]))
        else:
            print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
    elif odd[0][1] > even[0][1]:
        print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
    elif odd[0][1] < even[0][1]:
        print((n // 2 - odd[1][1]) + (n // 2 - even[0][1]))
else:
    print((n // 2 - odd[0][1]) + (n // 2 - even[0][1]))