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:
from collections import Counter

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

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

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

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

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

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

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

print(min_sum)

Submission status: Runtime Error

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

E = V[::2]
O = V[1::2]

from collections import Counter
Ed = Counter(E)
Od = Counter(O)
Edn = Ed.most_common(2)
Odn = Od.most_common(2)
#print(Edn,Odn)
if Edn[0][0] != Odn[0][0]:
    print(n- Edn[0][1] - Odn[0][1])
else:
    if len(Edn) == 1:
        if len(Odn) == 1:
            print(n//2)
        else:
            print(n//2-Odn[1][1])
    elif len(Odn) == 1:
        print(n//2-Edn[1][1])
    else:
        print(min(n-Edn[0][1]-Odn[1][1],m-Edn[1][1]-Odn[0][1]))

Submission status: Runtime Error

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

E = V[::2]
O = V[1::2]

from collections import Counter
Ed = Counter(E)
Od = Counter(O)
Edn = Ed.most_common(2)
Odn = Od.most_common(2)
print(Edn,Odn)
if Edn[0][0] != Odn[0][0]:
    print(n- Edn[0][1] - Odn[0][1])
else:
    if len(Edn) == 1:
        if len(Odn) == 1:
            print(n//2)
        else:
            print(n//2-Odn[1][1])
    if len(Odn) == 1:
        print(n//2-Edn[1][1])
    else:
        print(min(n-Edn[0][1]-Odn[1][1],m-Edn[1][1]-Odn[0][1]))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

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

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

print(counter)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import sys, os

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

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

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

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

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

    

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



solve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter

n, *v = map(int, open(0).read().split())
if v[::2] == v[1::2]:
        print(n // 2)
    else:
        print(n - Counter(v[::2]).most_common()[0][1] - Counter(v[1::2]).most_common()[0][1])

Submission status: Runtime Error

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

even = []
odd = []
for nn in range(n):
    if nn % 2 == 0:
        even.append(V[nn])
    else:
        odd.append(V[nn])

e = collections.Counter(even).most_common()
o = collections.Counter(odd).most_common()

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
else:
    if len(e) == 1 and len(o) == 1:
        print(n // 2)
    elif len(e) == 1 and len(o) >= 2:
        print(n - o[0][1])
    elif len(e) >= 2 and len(o) == 1:
        print(n - e[0][1])
    else:
        print(n - max(e[1][1] + o[0][1], e[0][1] + o[1][1]))

Submission status: Runtime Error

Solution code:
"""
偶数番目、機数番目をそれぞれリストに格納
偶数番目の中で、（全て）ー（もっとも要素数が多い数の数）
機数番目の中で、（全て）ー（もっとも要素数が多い数の数）
この和を求めれば良い
→一部WA
→ちょうど2種類ではなく、1種類になってしまうことがあるからでは？

偶数群と奇数群で、最頻値で場合わけ
一致している場合とそうでない場合で計算を変える

"""
import collections


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

even = []
odd = []
for nn in range(n):
    if nn % 2 == 0:
        even.append(V[nn])
    else:
        odd.append(V[nn])

e = collections.Counter(even).most_common()
o = collections.Counter(odd).most_common()

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
elif e[0][0] == n // 2 and o[0][0] == n // 2:
    print(n // 2)
elif e[0][0] == n // 2 and o[0][0] < n // 2:
    print(n - o[0][1])
elif e[0][0] < n // 2 and o[0][0] == n // 2:
    print(n - e[0][1])
else:
    print(n - max(e[1][1] + o[0][1], e[0][1] + o[1][1]))


"""
回答を見て、修正を加える

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

even = []
odd = []
for nn in range(n):
    if nn % 2 == 0:
        even.append(V[nn])
    else:
        odd.append(V[nn])

e = collections.Counter(even).most_common()
o = collections.Counter(odd).most_common()

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
else:
    if len(e) == 1 and len(o) == 1:
        print(n // 2)
    elif len(e) == 1 and len(o) >= 2:
        print(n - o[0][1])
    elif len(e) >= 2 and len(o) == 1:
        print(n - e[0][1])
    else:
        print(n - max(e[1][1] + o[0][1], e[0][1] + o[1][1]))

Submission status: Runtime Error

Solution code:
"""
偶数番目、機数番目をそれぞれリストに格納
偶数番目の中で、（全て）ー（もっとも要素数が多い数の数）
機数番目の中で、（全て）ー（もっとも要素数が多い数の数）
この和を求めれば良い
→一部WA
→ちょうど2種類ではなく、1種類になってしまうことがあるからでは？

偶数群と奇数群で、最頻値で場合わけ
一致している場合とそうでない場合で計算を変える

"""
import collections


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

even = []
odd = []
for nn in range(n):
    if nn % 2 == 0:
        even.append(V[nn])
    else:
        odd.append(V[nn])

e = collections.Counter(even).most_common()
o = collections.Counter(odd).most_common()

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
elif e[0][0] == n // 2 and o[0][0] == n // 2:
    print(n // 2)
elif e[0][0] == n // 2 and o[0][0] < n // 2:
    print(n - o[0][1])
elif e[0][0] < n // 2 and o[0][0] == n // 2:
    print(n - e[0][1])
else:
    print(n - max(e[1][1] + o[0][1], e[0][1] + o[1][1]))

Submission status: Runtime Error

Solution code:
"""
偶数番目、機数番目をそれぞれリストに格納
偶数番目の中で、（全て）ー（もっとも要素数が多い数の数）
機数番目の中で、（全て）ー（もっとも要素数が多い数の数）
この和を求めれば良い
→一部WA
→ちょうど2種類ではなく、1種類になってしまうことがあるからでは？

偶数群と奇数群で、最頻値で場合わけ
一致している場合とそうでない場合で計算を変える

"""
import collections


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

even = []
odd = []
for nn in range(n):
    if nn % 2 == 0:
        even.append(V[nn])
    else:
        odd.append(V[nn])

e = collections.Counter(even).most_common()
o = collections.Counter(odd).most_common()

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
elif e[0][0] == n / 2 and o[0][0] == n / 2:
    print(n / 2)
elif e[0][0] == n / 2 and o[0][0] < n / 2:
    print(n - o[0][1])
elif e[0][0] < n / 2 and o[0][0] == n / 2:
    print(n - e[0][1])
else:
    print(n - max(e[1][1] + o[0][1], e[0][1] + o[1][1]))

Submission status: Runtime Error

Solution code:
"""
偶数番目、機数番目をそれぞれリストに格納
偶数番目の中で、（全て）ー（もっとも要素数が多い数の数）
機数番目の中で、（全て）ー（もっとも要素数が多い数の数）
この和を求めれば良い
→一部WA
→ちょうど2種類ではなく、1種類になってしまうことがあるからでは？

偶数群と奇数群で、最頻値で場合わけ
一致している場合とそうでない場合で計算を変える

"""
import collections


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

even = []
odd = []
for nn in range(n):
    if nn % 2 == 0:
        even.append(V[nn])
    else:
        odd.append(V[nn])

e = collections.Counter(even).most_common()
o = collections.Counter(odd).most_common()

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
else:
    print(n - max(e[1][1] + o[0][1], e[0][1] + o[1][1]))

Submission status: Runtime Error

Solution code:
"""
偶数番目、機数番目をそれぞれリストに格納
偶数番目の中で、（全て）ー（もっとも要素数が多い数の数）
機数番目の中で、（全て）ー（もっとも要素数が多い数の数）
この和を求めれば良い
→一部WA
→ちょうど2種類ではなく、1種類になってしまうことがあるからでは？

偶数群と奇数群で、最頻値で場合わけ
一致している場合とそうでない場合で計算を変える

"""
import collections


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

even = []
odd = []
for nn in range(n):
    if nn % 2 == 0:
        even.append(V[nn])
    else:
        odd.append(V[nn])

e = collections.Counter(even)
o = collections.Counter(odd)

if e.most_common()[0][0] != o.most_common()[0][0]:
    print(n - e.most_common()[0][1] - o.most_common()[0][1])
else:
    print(N- max(e.most_common()[1][1] + o.most_common()[0][1],
    e.most_common()[0][1] + o.most_common()[1][1]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

odd = {}
even = {}

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

#ソートして一番目、二番目を見る
odd_sorted  = sorted(odd.items(), reversed = True, key = lambda x : x[1])
even_sorted  = sorted(even.items(), reversed = True, key = lambda x : x[1])




#候補が同じ場合
if odd_sorted[0][0] == even_sorted[0][0]:
    #奇数も偶数も2番目が存在する？
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        #数が大きい方を採用
        if odd_sorted[0][1] >= even_sorted[0][1]:
            ans_odd = odd_sorted[0][0]
            ans_even = even_sorted[1][0]
        else:
            ans_odd = odd_sorted[1][0]
            ans_even = even_sorted[0][0]
    #お互いに二番目が存在しない(ただし数は必ず一致するのでどちらか)
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    #奇数に2番目が存在しない
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    #偶数に2番目が存在しない
    else: #len(even.keys()):
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1


print(ans)

Submission status: Runtime Error

Solution code:
n = input()
li = list(map(int,input().split()))
li0 = li[0::2]
li1 = li[1::2]

cnt_li0 = {}
cnt_li1 = {}
for n in li0 :
    if n not in cnt_li0 :
        cnt_li0[n] = 0
    cnt_li0[n] = cnt_li0[n]+1

for n in li1 :
    if n not in cnt_li1 :
        cnt_li1[n] = 0
    cnt_li1[n] = cnt_li1[n]+1

cnt_li0 = sorted(cnt_li0.items(), key=lambda x: -x[1])
cnt_li1 = sorted(cnt_li1.items(), key=lambda x: -x[1])

if cnt_li0[0][0] == cnt_li1[0][0] :
    if cnt_li0[0][1] < cnt_li1[0][1] :
        n = len(li) - (cnt_li0[1][1] + cnt_li1[0][1])
    else :
        n = len(li) - (cnt_li0[0][1] + cnt_li1[1][1])
else :
    n = len(li) - (cnt_li0[0][1] + cnt_li1[0][1])
print(n)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 16 16:43:15 2019

@author: avina
"""

n = int(input())
l = list(map(int, input().split()))
d = {}
k = {}
for i in range(n):
    if i%2 != 0:
        if l[i] not in d:
            d[l[i]] = 1
        else:
            d[l[i]]+=1
    else:
        if l[i] not in k:
            k[l[i]] = 1
        else:
            k[l[i]] +=1
s = list(d.values()); s2 = list(d.values())
s.sort();s2.sort()
if len(s) >=2:
    a,b = s[-1],s[-2]
if len(s2) >= 2:
    a1,b1 = s2[-1],s[-2]
a = abs(max(k.values()) -  max(d.values()))
if a ==0 and k == d :
    print(max(k.values()))
else:
    max(abs(a-b),abs(a1-b1),abs(a-a1))

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
v= set(l)
k = []
for i in v:
  k.append(l.count(i))
k.sort(reverse =True)
if len(k) == 1:
  print( k[0]//2)
else
  print(k[0] - k[1])

Submission status: Runtime Error

Solution code:
from statistics import mode

n=int(input())
v=list(map(int, input().split()))
even_list=[]
odd_list=[]
c_count=0
def count_max(p_list):
  max_c=p_list.count(p_list[0])
  for j in range(len(p_list)-1):
    if p_list.count(p_list[j]) < p_list.count(p_list[j+1]):
      max_c = p_list.count(p_list[j+1])
  return max_c

for i in range(n):
  if i==0 or i%2==0:
    even_list.append(v[i])
  elif i%2==1:
    odd_list.append(v[i])

even_max_elem = mode(even_list)
odd_max_elem = mode(odd_list)

if even_max_elem == odd_max_elem:
  if even_list.count(even_max_elem) < odd_list.count(odd_max_elem):
    for k in range(len(even_list)):
      if even_list[k] == even_max_elem:
        c_count+=1

    while even_list.count(even_max_elem) != 0:
      even_list.remove(even_max_elem)
  else:
    for h in range(len(odd_list)):
      if odd_list[h] == odd_max_elem:
        c_count+=1
    while odd_list.count(odd_max_elem) != 0:
      odd_list.remove(odd_max_elem)

even_max=0
odd_max=0
if len(even_list) >=1:
  even_max=count_max(even_list)
  c_count += len(even_list)-even_max

if len(odd_list) >= 1:
  odd_max=count_max(odd_list)
  c_count += len(odd_list)-odd_max


print(c_count)

Submission status: Runtime Error

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

V1 = V[::2]
V2 = V[1::2]
 
V1c = Counter(V1).most_common()
V2c = Counter(V2).most_common()

k1, v1 = V1c[0][0], V1c[0][1]
k2, v2 = V2c[0][0], V2c[0][1]

ans = 0
if k1 == k2:
    ans = n - v1
    m = 0
    if len(V1c) >= 2:
        m = max(m, V1c[1][1])
    if len(V2c) >= 2:
        m = max(m, vVc[1][1])
    ans = ans - m
else:
    ans = n - v1 - v2
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
even = np.zeros(100000, dtype=int)
odd = np.zeros(100000, dtype=int)

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

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

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()

# print(e1, e1n, o1, o1n)
if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    # print(e2n, o2n)
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
num1 = []
num2 = []
counts =[0,0]
for i in range(len(v)):
    if i % 2 == 0:
        num1.append(v[i])
    else:
        num2.append(v[i])

n1 = collections.Counter(num1).most_common()[0][0]
for i in range(num2.count(n1)):
    num2.remove(n1)
n2 = collections.Counter(num2).most_common()[0][0]

for i in range(len(num2)):
    if n1 != num1[i]:
        counts[0] += 1

    if n2 != num2[i]:
        counts[1] += 1

if (n1 == n2) and sum(num2) == sum(num1):
    print(len(num1))
else:
    print(sum(counts))

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
num1 = []
num2 = []
counts =[0,0]
for i in range(len(v)):
    if i % 2 == 0:
        num1.append(v[i])
    else:
        num2.append(v[i])

n1 = collections.Counter(num1).most_common()[0][0]
for i in range(num2.count(nn1)):
    num2.remove(n1)
n2 = collections.Counter(num2).most_common()[0][0]

for i in range(len(num2)):
    if n1 != num1[i]:
        counts[0] += 1

    if n2 != num2[i]:
        counts[1] += 1

if (n1 == n2) and sum(num2) == sum(num1):
    print(len(num1))
else:
    print(sum(counts))

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
odd, even = [], []

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

    
codd = collections.Counter(odd)
ceven = collections.Counter(even)
mostodd = codd.most_common()[0]
mosteven = ceven.most_common()[0]

if mostodd[0] != mosteven[0]:
  ans = n - mostodd[1] - mosteven[1]
else:
  if mostodd[1] >= mosteven[1]:
    if len(ceven.most_common()) > 1:
      even2nd = ceven.most_common()[1] 
    else:
      even2nd = 0
    ans = n - mostodd[1] - even2nd
  else:
    if len(codd.most_common()) > 1:
      odd2nd = codd.most_common()[1] 
    else:
      odd2nd = 0
    ans = n - odd2nd - mosteven[1] 
print(ans)

Submission status: Runtime Error

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

evens = [(0, 0)]*(10**5)
odds = [(0, 0)]*(10**5)
for i in range(N):
    if (i+1) % 2 == 0:
        evens[V[i]] = (V[i], evens[V[i]][1] + 1)
    else:
        odds[V[i]] = (V[i], odds[V[i]][1] + 1)

evens.sort(key=lambda x: x[1], reverse=True)
odds.sort(key=lambda x: x[1], reverse=True)

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

Submission status: Runtime Error

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

dic1, dic2 = dict(), dict()
#dic1[0] = 0
#dic2[0] = 0
for i, x in enumerate(lst):
    dic = dic1 if  i%2 == 0 else dic2
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1
#print (type(dic1))
dic1 =sorted(dic1.items(), key = lambda x:x[1])[::-1]
dic2 =sorted(dic2.items(), key = lambda x:x[1])[::-1]

#print (type(dic2))
#print (dic1)
#print (dic2)

if dic1[0][0] != dic2[0][0]:
    print (N-dic1[0][1]-dic2[0][1])
elif len(dic1) == 1 and len(dic2) == 1:
    print (N//2)
elif len(dic1) == 1:
    print (N-dic1[0][1]-dic2[1][1])
elif len(dic2) == 1:
    print (N-dic1[1][1]-dic2[0][1])
else:
    print (mix(N-dic1[0][1]-dic2[1][1], N-dic1[1][1]-dic2[0][1]))

Submission status: Runtime Error

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

dic1, dic2 = dict(), dict()
#dic1[0] = 0
#dic2[0] = 0
for i, x in enumerate(lst):
    dic = dic1 if  i%2 == 0 else dic2
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1
#print (type(dic1))
dic1 =sorted(dic1.items(), key = lambda x:x[1])[::-1]
dic2 =sorted(dic2.items(), key = lambda x:x[1])[::-1]

#print (type(dic2))
#print (dic1)
#print (dic2)

if dic1[0][0] != dic2[0][0]:
    print (N-dic1[0][1]-dic2[0][1])
elif len(dic1) == 1 and len(dic2) == 1:
    print (n//2)
elif len(dic1) == 1:
    print (N-dic1[0][1]-dic2[1][1])
elif len(dic2) == 1:
    print (N-dic1[1][1]-dic2[0][1])
else:
    print (mix(N-dic1[0][1]-dic2[1][1], N-dic1[1][1]-dic2[0][1]))

Submission status: Runtime Error

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

dic1, dic2 = dict(), dict()
dic1[0] = 0
dic2[0] = 0
for i, x in enumerate(lst):
    dic = dic1 if  i%2 == 0 else dic2
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1
#print (type(dic1))
dic1 =sorted(dic1.items(), key = lambda x:x[1])[::-1]
dic2 =sorted(dic2.items(), key = lambda x:x[1])[::-1]

#print (type(dic2))
#print (dic1)
#print (dic2)

if dic1[0][0] != dic2[0][0]:
    print (N-dic1[0][1]-dic2[0][1])
#elif len(dic1) == 1 and len(dic2) == 1:
#    print (n//2)
#elif len(dic1) == 1:
#    print (N-dic1[0][1]-dic2[1][1])
#elif len(dic2) == 1:
#    print (N-dic1[1][1]-dic2[0][1])
else:
    print (mix(N-dic1[0][1]-dic2[1][1], N-dic1[1][1]-dic2[0][1]))

Submission status: Runtime Error

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

dic1, dic2 = dict(), dict()
for i, x in enumerate(lst):
    dic = dic1 if  i%2 == 0 else dic2
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1
#print (type(dic1))
dic1 =sorted(dic1.items(), key = lambda x:x[1])[::-1]
dic2 =sorted(dic2.items(), key = lambda x:x[1])[::-1]

#print (type(dic2))
#print (dic1)
#print (dic2)

if dic1[0][0] != dic2[0][0]:
    print (N-dic1[0][1]-dic2[0][1])
#elif len(dic1) == 1 and len(dic2) == 1:
#    print (n//2)
#elif len(dic1) == 1:
#    print (N-dic1[0][1]-dic2[1][1])
#elif len(dic2) == 1:
#    print (N-dic1[1][1]-dic2[0][1])
else:
    print (mix(N-dic1[0][1]-dic2[1][1], N-dic1[1][1]-dic2[0][1]))

Submission status: Runtime Error

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

dic1, dic2 = dict(), dict()
for i, x in enumerate(lst):
    dic = dic1 if  i%2 == 0 else dic2
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1
#print (type(dic1))
dic1 =sorted(dic1.items(), key = lambda x:x[1])[::-1]
dic2 =sorted(dic2.items(), key = lambda x:x[1])[::-1]

#print (type(dic2))
#print (dic1)
#print (dic2)

if dic1[0][0] != dic2[0][0]:
    print (N-dic1[0][1]-dic2[0][1])
elif len(dic1) == 1 and len(dic2) == 1:
    print (n//2)
elif len(dic1) == 1:
    print (N-dic1[0][1]-dic2[1][1])
elif len(dic2) == 1:
    print (N-dic1[1][1]-dic2[0][1])
else:
    print (max(N-dic1[0][1]-dic2[1][1], N-dic1[1][1]-dic2[0][1]))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = [v[0]]
v2 = []
for i in range(1,n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])
c1 = Counter(v1)
c2 = Counter(v2)
mode1 = c1.most_common(1)
mode2 = c2.most_common(1)
if mode1[0][0] != mode2[0][0]:
    ans1 = len(v1)-mode1[0][1]
    ans2 = len(v2)-mode2[0][1]
    ans = ans1 + ans2
else:
    if mode1[0][1] == len(v1) and mode2[0][1] == len(v2):
       ans = min(mode1[0][1],mode2[0][1])
    elif mode1[0][1] == len(v1):
        ans1 = len(v)-mode2[0][1]
        ans2 = len(v)-mode1[0][1]-mode2[1][1]
        ans = min(ans1,ans2)
    elif mode2[0][1] == len(v2):
        ans1 = len(v)-mode1[1][1]-mode2[0][1]  
        ans2 = len(v)-mode1[0][1]
        ans = min(ans1,ans2)
    else:
        ans1 = len(v)-mode1[0][1]-mode2[1][1]
        ans2 = len(v)-mode1[1][1]-mode2[0][1]
        ans = min(ans1,ans2)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = [v[0]]
v2 = []
for i in range(1,n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])
c1 = Counter(v1)
c2 = Counter(v2)
mode1 = c1.most_common(1)
mode2 = c2.most_common(1)
if mode1[0][0] != mode2[0][0]:
    ans1 = len(v1)-mode1[0][1]
    ans2 = len(v2)-mode2[0][1]
    ans = ans1 + ans2
else:
    if mode1[0][1] == len(v1) and mode2[0][1] == len(v2):
       ans = min(mode1[0][1],mode2[0][1])
    elif mode1[0][1] == len(v1):
        ans = len(v)-mode1[0][1]-mode2[1][1]
    elif mode2[0][1] == len(v2):
        ans = len(v)-mode1[1][1]-mode2[0][1]  
    else:
        ans1 = len(v)-mode1[0][1]-mode2[1][1]
        ans2 = len(v)-mode1[1][1]-mode2[0][1]
        ans = min(ans1,ans2)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = [v[0]]
v2 = []
for i in range(1,n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])
c1 = Counter(v1)
c2 = Counter(v2)
mode1 = c1.most_common(1)
mode2 = c2.most_common(1)
if mode1[0][0] != mode2[0][0]:
    ans1 = len(v1)-mode1[0][1]
    ans2 = len(v2)-mode2[0][1]
    ans = ans1 + ans2
else:
    if mode1[0][1] == len(v1) and mode2[0][1] == len(v2):
       ans = min(mode1[0][1],mode2[0][1])
    else:
        ans1 = len(v)-mode1[0][1]-mode2[1][1]
        ans2 = len(v)-mode1[1][1]-mode2[0][1]
        ans = min(ans1,ans2)
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
a = v[0::2]
suma = len(a)
b = v[1::2]
sumb = len(b)
a = collections.Counter(a)
a = a.most_common()
b = collections.Counter(b)
b = b.most_common()

if a[0][0] != b[0][0]:
        ans = suma-a[0][1] + sumb-b[0][1]
        print(ans)
else:  
        ans1 = suma-a[1][1] + sumb-b[0][1]
        ans2 = suma-a[0][1] + sumb-b[1][1]
        print(min(ans1,ans2))

Submission status: Runtime Error

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

for i in range(n):
        if i%2==1:
                if v[i] in a:
                        x[a.index(v[i])] += 1
                else:
                        a.append(v[i])
                        x.append(1)
        else:
                if v[i] in b:
                        y[b.index(v[i])] += 1
                else:
                        b.append(v[i])
                        y.append(1)

if a[x.index(max(x))] != b[y.index(max(y))]:
        x=sorted(x)[::-1]
        y=sorted(y)[::-1]

        sumx = sum(x)
        sumy = sum(y)

        changea = sumx-x[0]
        changeb = sumy-y[0]
        print(changea + changeb)
else:  
        x=sorted(x)[::-1]
        y=sorted(y)[::-1]
        sumx = sum(x)
        sumy = sum(y)

        ans1 = sumx-x[0] + sumy-y[1]
        ans2 = sumx-x[1] + sumy-y[0]
        print(min(ans1,ans2))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
even = Counter(v[::2]).most_common(2)
odd = Counter(n[1::2]).most_common(2)
if even[0][0] != odd[0][0]:
    ans =  n - even[0][1] - odd[0][1]
else:
    if len(even) == 1:
        ans = n//2
    else:
        ans =  n - max(even[0][1] + odd[1][1],even[1][1],odd[0][1])
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
even = Counter(v[::2]).most_common(2)
odd = Counter(n[1::2]).most_common(2)
if even[0][0] != odd[0][0]:
    ans =  n - even[0][1] - odd[0][1]
else:
    if len(even) == 1:
        ans = n//2:
    else:
        ans =  n - max(even[0][1] + odd[1][1],even[1][1],odd[0][1])
print(ans)

Submission status: Runtime Error

Solution code:
import statistics as st
n=int(input())
li=list(map(int,input().split()))
list1=[]
list2=[]
for i in range(int(n/2)):
  list1.append(li[2*i])
  list2.append(li[2*i+1])

count1=list1.count(st.mode(list1))
count2=list2.count(st.mode(list2))

print(len(list1)+len(list2)-count1-count2)

Submission status: Runtime Error

Solution code:
n = int(input())
V = list(map(int,input().split()))
V_1 = V[::2]
V_1_a = []
V_2 = V[1::2]
V_2_a = []
for i in range(n//2)
    V_1_a.append(V_1.count(V_1[i]))
    V_2_a.append(V_2.count(V_2[i]))
a = max(V_1_a) + max(V_2_a)
print(n - a)

Submission status: Runtime Error

Solution code:
N = int(input())
V = list(map(int, input().split()))
o = {}
e = {}
for i, v in enumerate(V):
    if i % 2 == 1:
        if not v in e.keys():
            e[v] = 0
        e[v] += 1
    else:
        if not v in o.keys():
            o[v] = 0
        o[v] += 1

o = sorted(o.values(), reverse=True)
e = sorted(e.values(), reverse=True)

e1 = sum(e[1:])
e2 = sum(e[0] + e[2:])
o1 = sum(o[1:])
o2 = sum(o[2:])
ret = min(e1+o2, e2+o1)
print(ret)

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
from collections import Counter
even=[]
odd=[]
for i in range(n):
    if i%2==0:
        even.append(v[i])
    else:
        odd.append(v[i])
E=Counter(even).most_common()
O=Counter(odd).most_common()
if E[0][0]!=O[0][0]:
    print(n-(E[0][1]+O[0][1]))
else:
    print(min(n-(E[1][1]+O[0][1]),n-(E[0][1]+O[1][1])))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

if c1[0][0] != c2[0][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: Runtime Error

Solution code:
from collections import Counter

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

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

if c1[0][0] != c2[0][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]))