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:
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]))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
x1, c1 = Counter(V1).most_common(1)[0]
x2, c2 = Counter(V2).most_common(1)[0]
x3, c3 = Counter(V1).most_common(2)[1]
x4, c4 = Counter(V2).most_common(2)[1]
if x1 == x2:
    a = max(c1+c4, c2+c3)
    print(N-a)
else:
    print(N - c1 - c2)

Submission status: Runtime Error

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

dE={};dO={}
for i in range(n):
    dX=dE if i%2==0 else dO
    if v[i] in dX:
        dX[v[i]]+=1
    else:
        dX[v[i]]=1

lE=sorted(list(dE.items()),key=lambda x:x[1],reverse=True)
lO=sorted(list(dO.items()),key=lambda x:x[1],reverse=True)

me=lE[0][1];mo=lO[0][1]
ae=lE[0][0];ao=lO[0][0]
se=0 if len(lE)==0 else lE[1][1]
so=0 if len(lO)==0 else lO[1][1]

if ae==ao:
    ans=n-max(me+so,mo+se)
else:
    ans=n-(me+mo)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int, input().split()))
even = dict()
odd = dict()
for i in range(n//2):
  a = v[2*i]
  if a in even:
    even[a] += 1
  else:
    even[a] = 1
  a = v[2*i + 1]
  if a in odd:
    odd[a] += 1
  else:
    odd[a] = 1

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

if even_sorted[0][0] == odd_sorted[0][0]:
  print(n - max(even_sorted[0][1]+odd_sorted[1][1], even_sorted[1][1]+odd_sorted[0][1]))
else:
  print(n - even_sorted[0][1] - odd_sorted[0][1])

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(n):
  if i%2==0:
    o.append(a[i])
  else:
    e.append(a[i])
from collections import Counter as co
o=co(o)
e=co(e)
o['x']=0
e['x']=0
ov=o.values()+[0]
ev=e.values()+[0]
mo=max(ov)
me=max(ev)
if n==2:
  if a[0]==a[1]:
    print(1)
  else:
    print(0)
else:
  if max(o,key=o.get)==max(e,key=e.get):
    if mo>me:
      me=sorted(ev)[-2]
    else:
      mo=sorted(ov)[-2]
  print(n-mo-me)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(n):
  if i%2==0:
    o.append(a[i])
  else:
    e.append(a[i])
from collections import Counter as co
o=co(o)
e=co(e)
ov=o.values()+[0]
ev=e.values()+[0]
mo=max(ov)
me=max(ev)
if n==2:
  if a[0]==a[1]:
    print(1)
  else:
    print(0)
else:
  if max(o,key=o.get)==max(e,key=e.get):
    if mo>me:
      me=sorted(ev)[-2]
    else:
      mo=sorted(ov)[-2]
  print(n-mo-me)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(n):
  if i%2==0:
    o.append(a[i])
  else:
    e.append(a[i])
from collections import Counter as co
o=co(o)
e=co(e)
ov=o.values()
ev=e.values()
mo=max(ov)
me=max(ev)
if n==2:
  if a[0]==a[1]:
    print(1)
  else:
    print(0)
else:
  if max(o,key=o.get)==max(e,key=e.get):
    if mo>me:
      me=sorted(ev)[n//2-2]
    else:
      mo=sorted(ov)[n//2-2]
  print(n-mo-me)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(n):
  if i%2==0:
    o.append(a[i])
  else:
    e.append(a[i])
from collections import Counter as co
o=co(o)
e=co(e)
ov=o.values()
ev=e.values()
mo=max(ov)
me=max(ev)
if max(o,key=o.get)==max(e,key=e.get):
  if mo>me:
    me=sorted(ev)[n//2-2]
  else:
    mo=sorted(ov)[n//2-2]
print(n-mo-me)

Submission status: Runtime Error

Solution code:
#111c
import collections
import copy

n = int(input()) #2≤n≤10**5 偶数
v_list = [int(e) for e in input().split()]

#数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。

#・各 i=1,2,...,n−2について、ai=ai+2 
#・数列に現れる数はちょうど 2種類

#偶数長の数列 v1,v2,...,vnが与えられます。 
#要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。

#一番多く出てくる文字を求め、書き換えない数字を決める
v_list_odd = [v_list[i] for i in range(n) if i%2==1]
v_list_even = [v_list[i] for i in range(n) if i%2==0]

#print(v_list_odd)
#print(v_list_even)

c = collections.Counter(v_list_odd)
v_list_odd_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    
c = collections.Counter(v_list_even)
v_list_even_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    
#固定文字の決定
#1文字目が重複していなければ、両方とも出現回数最多を固定する
if fix_picklist_for_v_list_even[0] != fix_picklist_for_v_list_odd[0]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]

#1文字目が重複している場合
#両方1文字しかなければ片方のみ
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) == 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = "!"
#片方が1文字ならば、そうでない方は2文字目を使う。
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) != 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif len(fix_picklist_for_v_list_even) != 2 and len(fix_picklist_for_v_list_odd) == 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
#両方2文字あるなら、固定パターンの合計が多い方を採用
elif fix_picklist_for_v_list_even[1] + fix_picklist_for_v_list_odd[3] > fix_picklist_for_v_list_even[3]+fix_picklist_for_v_list_odd[1]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif fix_picklist_for_v_list_even[1] + fix_picklist_for_v_list_odd[3] =< fix_picklist_for_v_list_even[3]+fix_picklist_for_v_list_odd[1]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]

#print(fix_char_for_v_list_odd)
#print(fix_char_for_v_list_even)
        
#書き換え要素数をカウント
ans_odd = n/2 - v_list_odd_counter[fix_char_for_v_list_odd]
ans_even = n/2 - v_list_even_counter[fix_char_for_v_list_even]
print(int(ans_odd + ans_even))

Submission status: Runtime Error

Solution code:
#111c
import collections
import copy

n = int(input()) #2≤n≤10**5 偶数
v_list = [int(e) for e in input().split()]

#数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。

#・各 i=1,2,...,n−2について、ai=ai+2 
#・数列に現れる数はちょうど 2種類

#偶数長の数列 v1,v2,...,vnが与えられます。 
#要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。

#一番多く出てくる文字を求め、書き換えない数字を決める
v_list_odd = [v_list[i] for i in range(n) if i%2==1]
v_list_even = [v_list[i] for i in range(n) if i%2==0]

#print(v_list_odd)
#print(v_list_even)

c = collections.Counter(v_list_odd)
v_list_odd_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    
c = collections.Counter(v_list_even)
v_list_even_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    
#固定文字の決定
#1文字目が重複していなければ、両方とも出現回数最多を固定する
if fix_picklist_for_v_list_even[0] != fix_picklist_for_v_list_odd[0]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]

#1文字目が重複している場合
#両方1文字しかなければ片方のみ
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) == 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = "!"
#片方が1文字ならば、そうでない方は2文字目を使う。
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) != 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif len(fix_picklist_for_v_list_even) != 2 and len(fix_picklist_for_v_list_odd) == 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
#両方2文字あるなら、固定パターンの合計が多い方を採用
elif fix_picklist_for_v_list_even[1]+fix_picklist_for_v_list_odd[3] > fix_picklist_for_v_list_even[3]+fix_picklist_for_v_list_odd[1]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif  fix_picklist_for_v_list_even[1]+fix_picklist_for_v_list_odd[3]= fix_picklist_for_v_list_even[3]+fix_picklist_for_v_list_odd[1]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]

#print(fix_char_for_v_list_odd)
#print(fix_char_for_v_list_even)
        
#書き換え要素数をカウント
ans_odd = n/2 - v_list_odd_counter[fix_char_for_v_list_odd]
ans_even = n/2 - v_list_even_counter[fix_char_for_v_list_even]
print(int(ans_odd + ans_even))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Vo=V[::2]
Ve=V[1::2]

oddmost = collections.Counter(Vo).most_common()[0][1]
oddsec = collections.Counter(Vo).most_common()[1][1]
evenmost = collections.Counter(Ve).most_common()[0][1]
evensec = collections.Counter(Ve).most_common()[1][1]

if oddmost!=evenmost:
    print(len(V)-oddmost-evenmost)
else:
    print(min(len(V)-oddmost-evensec, len(V)-evenmost-oddsec))

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
V = list(map(int, input().split()))
S1 = Counter([V[i] for i in range(0, N, 2)])
S2 = Counter([V[i] for i in range(1, N, 2)])

S1 = sorted(S1.items(), key=lambda x: x[1], reverse=True)
S2 = sorted(S2.items(), key=lambda x: x[1], reverse=True)

if S1[0][0] == S2[0][0]:
    ans = min(N-(S1[0][1]+S2[1][1]), N-(S1[1][1]+S2[0][1]))
else:
    ans = N - (S1[0][1] + S2[0][1])
print(ans)

Submission status: Runtime Error

Solution code:
import copy
n = int(input())
o = list(map(int, input().split()))

#11
#6 7 1 2 1 2 1 2 6 5 6
a0 = {}
a1 = {}
a0c = n//2 + n%2
a1c = n//2
for i in range(0, n, 2):
    oo = o[i]
    if oo in a0.keys():
        a0[oo] += 1
    else:
        a0[oo] = 1

for i in range(1, n, 2):
    oo = o[i]
    if oo in a1.keys():
        a1[oo] += 1
    else:
        a1[oo] = 1

k0 = [kv[0] for kv in a0.items() if kv[1] == max(a0.values())]
ans0 = a0c - a0[k0[0]]
a1_copy = copy.deepcopy(a1)
if k0[0] in a1_copy:
    del a1_copy[k0[0]]
if len(a0_copy) != 0:
    k1= [kv[0] for kv in a1_copy.items() if kv[1] == max(a1_copy.values())]
    ans1 = a1c - a1_copy[k1[0]]
else:
    ans1 = a1c

ans_a = ans0 + ans1

k0 = [kv[0] for kv in a1.items() if kv[1] == max(a1.values())]
ans0 = a1c - a1[k0[0]]
a0_copy = copy.deepcopy(a0)
if k0[0] in a0_copy:
    del a0_copy[k0[0]]
if len(a1_copy) != 0:
    k1= [kv[0] for kv in a0_copy.items() if kv[1] == max(a0_copy.values())]
    ans1 = a0c - a0_copy[k1[0]]
else:
    ans1 = a0c

ans_b = ans0 + ans1

print(min(ans_a, ans_b))

Submission status: Runtime Error

Solution code:
n=int(input())

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

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm[0])
else:
    if km1[1]-km2[1]>=gm1[1]-gm2[1]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])

Submission status: Runtime Error

Solution code:
n=int(input())

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

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm[0])
else:
    if km1[1]-km2[1]>=gm1[1]-gm2[1]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
v = list(map(int, input().split()))
v_odd = []
v_even = []
for i in range(n):
  if i%2 == 0:
    v_odd.append(v[i])
  else:
    v_even.append(v[i])

vs_odd = np.array(v_odd)
vs_even = np.array(v_even)
count_odd = np.bincount(vs_odd)
count_even = np.bincount(vs_even)
mode_odd = np.argmax(count_odd)
mode_even = np.argmax(count_even)
a = v_odd.count(mode_odd)
b = v_even.count(mode_even)
if mode_odd != mode_even:
  print(n-a-b)
else:
  if len(v_odd) != v_odd.count(mode_odd):
    v_odd2 = [i for i in v_odd if i != mode_odd]
    vs_odd2 = np.array(v_odd2)
    count_odd2 = np.bincount(vs_odd2)
    mode_odd2 = np.argmax(count_odd2)
    a2 = v_odd.count(mode_odd2)
  else:
    a2 = 0
    if len(v_even) != v_even.count(mode_even):
      v_even2 = [i for i in v_even if i != mode_even]
      vs_even2 = np.array(v_even2)
      count_even2 = np.bincount(vs_even2)
      mode_even2 = np.argmax(count_even2)
      b2 = v_even.count(mode_even2)
    else:
      b2 = 0
  if a2 > b2:
    print(n-a2-b)
  else:
    print(n-a-b2)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
li = list(map(int,input().split()))
even = [li[i] for i in range(N) if i%2==0]
odd =[ li[i] for i in range(N) if i%2!=0]

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

ec=e[0][1]
oc=o[0][1]

if e[0][0]==o[0][0]:
  if e[0][1] > o[0][1]:
    oc=o[1][1]
  else:
    ec=e[1][1]
    
ans = N-(ec+oc)
print(ans)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
even = [input() for i in range(N) if i%2==0]
odd =[ input() for i in range(N) if i%2!=0]

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

ec=e[0][1]
oc=o[0][1]

if e[0][0]==o[0][0]:
  if e[0][1] > o[0][1]:
    oc=o[1][1]
  else:
    ec=e[1][1]
    
ans = N-(ec+oc)
print(ans)

Submission status: Runtime Error

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

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

    else:
        odd_list[v[i]] += 1

if even_list.index(max(even_list)) == odd_list.index(max(odd_list)):
    even_sorted, odd_sorted = sorted(even_list), sorted(odd_list)
    print(min(n - even_sorted[-1] - odd_sorted[-2], n - even_sorted[-2] - odd_sorted[-1]))

else:
    print(n - max(even_list) - max(odd_list))

Submission status: Runtime Error

Solution code:
n = int(input())
V = list(map(int,input().split()))
De = {}
Do = {}
for i in range(n):
    x = V[i]
    if i%2==0:
        if x not in De:
            De[x] = 0
        De[x] += 1
    else:
        if x not in Do:
            Do[x] = 0
        Do[x] += 1
DeL = sorted(list(De.items()),key=lambda x:x[1],reverse=True)
DoL = sorted(list(Do.items()),key=lambda x:x[1],reverse=True)
y = DeL[0][0]
z = DoL[0][0]
if y!=z:
    n0 = n//2-De[y]
    n1 = n//2-Do[z]
elif y==z:
    if De[y]>Do[z]:
        z = DoL[1][0]
        n0 = n//2-De[y]
        n1 = n//2-Do[z]
    elif De[y]<Do[z]:
        y = DeL[1][0]
        n0 = n//2-De[y]
        n1 = n//2-Do[z]
    elif De[y]==Do[z]:
        if De[y]==n//2:
            no = 0
            n1 = n//2
        elif DeL[1][1]>=DoL[1][1]:
            y = DeL[1][0]
            n0 = n//2-De[y]
            n1 = n//2-Do[z]
        else:
            z = DoL[1][0]
            n0 = n//2-De[y]
            n1 = n//2-Do[z]
print(n0+n1)

Submission status: Runtime Error

Solution code:
from collections import Counter
import heapq

def find_key_from_value(input_dict, target_value):
  return  [key for key, value in input_dict.items() if value == target_value][0]

N = int(input())
V= list(map(int,input().split()))
eve, odd  = Counter([V[i] for i in range(0,N,2)]), Counter([V[i] for i in range(1,N,2)])
if len(eve) == len(odd):
  print(N//2)
  exit()

eve_largests = heapq.nlargest(2,eve.values())
odd_largests = heapq.nlargest(2,odd.values())

if eve_largests[0] != odd_largests[0]:
  eve_largest, odd_largest = eve_largests[0], odd_largests[0]
else:
  if len(eve_largests[0]) == 1 and len(odd_largests[0]) == 2:
    eve_largest, odd_largest = eve_largests[0], odd_largests[1]
  elif len(eve_largests[0]) == 2 and len(odd_largests[0]) == 1:
    eve_largest, odd_largest = eve_largests[1], odd_largests[0]
  else:
    if eve_largests[1] >= odd_largests[1]:
      eve_largest, odd_largest = eve_largests[1], odd_largests[0]
    else:
       eve_largest, odd_largest = eve_largests[0], odd_largests[1]
    
eve_key = find_key_from_value(eve, eve_largest)
odd_key = find_key_from_value(odd, odd_largest)  
  
print(N-eve[eve_key]-odd[odd_key])

Submission status: Runtime Error

Solution code:
def sura_backsura():
    import collections

    N = int(input())
    a = [int(i) for i in input().split()]

    fp = collections.Counter(a[0::2]).most_common()
    sp = collections.Counter(a[1::2]).most_common()

    if fp[0] != sp[0]:
        count = N - fp[0][1] - sp[0][1]
    else:
        count = min(N - fp[0][1] - sp[1][1], N - fp[1][1] - sp[0][1])

    print(count)
    
if __name__ == "__main__":
    sura_backsura()

Submission status: Runtime Error

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

odd = collections.defaultdict(int)

even = collections.defaultdict(int)

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

    else:
        odd[v[i]] += 1

even = list(even.items())
odd = list(odd.items())

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 len(even) == 1 and len(odd) == 1:
        print(n // 2)
    elif len(even) == 1:
        print(n - (even[0][1] + odd[1][1]))
    elif len(odd) == 1:
        print(n - (even[1][1] + odd[0][1]))
    else:
        print(min(n - (even[1][1] + odd[0][1])),
              (n - (even[0][1] + odd[1][1])))
else:
    print(n - (even[0][1] + odd[0][1]))

Submission status: Runtime Error

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

odd = collections.defaultdict(int)

even = collections.defaultdict(int)

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

    else:
        odd[v[i]] += 1

even = list(even.items())
odd = list(odd.items())

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 len(even) == 1 and len(odd) == 1:
        print(n // 2)
    elif len(even) == 1:
        print(n - (even[0][1] + odd[1][1]))
    elif len(odd) == 1:
        print(n - (even[1][1] + odd[0][1]))
    else:
        print(min(n - (even[1][1] + odd[0][1])),
              print(n - (even[0][1] + odd[1][1])))
else:
    print(n - (even[0][1] + odd[0][1]))

Submission status: Runtime Error

Solution code:
import collections as col
N= int(input())
A = [int(x) for x in input().split()]
a = A[::2]
a = col.Counter(a)
b = A[1::2]
b = col.Counter(b)
ans = 0
i = 0
j = 0
#while a.most_common()[i][0]!=b.most_common()[j][0]:
if a.most_common(1)[0][0]!=b.most_common(1)[0][0]:
  ans += sum(a.values())+sum(b.values)-a.most_common(1)[0][1]-b.most_common(1)[0][1]
print(ans)

Submission status: Runtime Error

Solution code:
input()
V = [int(v) for v in input().split()]
count = 0
c1 = Counter(V[::2] + [0]).most_common()[0][0]
for v in V[::2]:
    if v != c1:
        count += 1
c2 = Counter(V[1::2] + [0]).most_common()
c2 = c2[0][0] if c1 != c2[0][0] else c2[1][0]
for v in V[1::2]:
    if v != c2:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
import collections

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

eNum=collections.Counter(r[1::2])
oNum=collections.Counter(r[::2])


if list(eNum)[0]==list(oNum)[0]:
  print(len(r)-max(eNum[list(eNum)[0]]+oNum[list(oNum)[1]],eNum[list(eNum)[1]]+oNum[list(oNum)[0]]))
else:
  print(len(r)-eNum[list(eNum)[0]]-oNum[list(oNum)[0]])

Submission status: Runtime Error

Solution code:
import collections

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

eNum=collections.Counter(r[1::2])
oNum=collections.Counter(r[::2])


if eNum.keys()[0]==oNum.keys()[0]:
  print(len(r)-max(eNum[eNum.keys()[0]]+oNum[oNum.keys()[1]],eNum[eNum.keys()[1]]+oNum[oNum.keys()[0]]))
else:
  print(len(r)-eNum[eNum.keys()[0]]-oNum[oNum.keys()[1]])

Submission status: Runtime Error

Solution code:
n = int(input())
V = list(map(int, input().split()))
countA = []
countB = []
if len(set(V)) == 1:
    print(n//2)
else:
    A = V[::2]
    B = V[1::2]
    for i in range(N//2):
        countA.append(A.count(A[i]))
        countB.append(B.count(B[i]))
    max_countA = max(countA)
    max_countB = max(countB)
    
    print(len(A)-max_countA + len(A)-max_countB)

Submission status: Runtime Error

Solution code:
n = int(input())
V = list(map(int, input().split()))
if len(set(V)) == 1:
    print(n//2)
else:
    A = V[::2]
    B = V[1::2]
    for _ in range(N//2):
        countA = [A.count(a) for a in set(A)]
        countB = [B.count(b) for b in set(B)]
    max_countA = max(countA)
    max_countB = max(countB)
    
    print(len(A)-max_countA + len(A)-max_countB)

Submission status: Runtime Error

Solution code:
import statistics
a = int(input())
l=list(map(int ,input().split()))
lk=[]
lg=[]
for i in range(a):
        if i%2==0:
                lg.append(l[i])
        else:
                lk.append(l[i])

if len(set(lk))==1 and len(set(lg))==1 and lk[0]==lg[0]:
        print(int(a/2))
elif len(set(lk))==1 and len(set(lg))==1:
        print(0)
else:
        x=len(lk)-(lk.count(statistics.mode(lk)))
        y=len(lg)-(lg.count(statistics.mode(lg)))
        print(x+y)

Submission status: Runtime Error

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

even = {}
odd = {}

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

even_sorted = sorted(even.items(), key=lambda x:x[1])[::-1]
odd_sorted = sorted(odd.items(), key=lambda x:x[1])[::-1]

ans = 0
if even_sorted[0][0] != odd_sorted[0][0]:
    ans += n - even_sorted[0][1] - odd_sorted[0][1]
else:
    x = n - even_sorted[0][1] - odd_sorted[1][1]
    y = n - even_sorted[1][1] - odd_sorted[0][1]
    ans += min(x, y)

print(ans)

Submission status: Runtime Error

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

even = {}
odd = {}

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

even_sorted = sorted(even.items(), key=lambda x:x[i])[::-1]
odd_sorted = sorted(odd.items(), key=lambda x:x[i])[::-1]

ans = 0
if even_sorted[0][0] != odd_sorted[0][0]:
    ans += n - even_sorted[0][1] - odd_sorted[0][1]
else:
    x = n - even_sorted[0][1] - odd_sorted[1][1]
    y = n - even_sorted[1][1] - odd_sorted[0][1]
    ans += min(x, y)

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
V=list(map(int,input().split()))
E=Counter(V[::2]).most_common()
O=Counter(V[1::2]).most_common()

E1=E[0][1]
O1=O[0][1]
if E[0][0]==O[0][0]:
  print(n//2)
elif E1==O1==n//2:
  print(0)
else:
  E2=E[1][1] if len(E)>1 else 0
  O2=O[1][1] if len(O)>1 else 0
  if E2!=0 and O2!=0:
    print(min(n//2-E2+n//2-O1,n//2-E1+n//2-O2))
  else:
    print(min(n//2-E2+n//2-O1,n//2-E1+n//2-O2))

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
v1 = collections.Counter(v1)
v2 = collections.Counter(v2)
ans = 0
if v1.most_common()[0][0] == v2.most_common()[0][0]:
    if v1.most_common()[0][1] < v2.most_common()[0][1]:
        ans += n//2 - v2.most_common()[0][1]
        ans += n//2 - v1.most_common()[1][1]
        print(ans)
    elif v1.most_common()[0][1] > v2.most_common()[0][1]:
        ans += n//2 - v1.most_common()[0][1]
        ans += n//2 - v2.most_common()[0][1]
        print(ans)
    else:
        if v1.most_common()[0][1] == n//2:
            print(N//2)
        else:
            if v1.most_common()[1][1] > v2.most_common()[1][1]:
                ans += n//2 - v2.most_common()[0][1]
                ans += n//2 - v1.most_common()[1][1]
                print(ans)
            else:
                ans += n//2 - v1.most_common()[0][1]
                ans += n//2 - v2.most_common()[1][1]
                print(ans)
else:
    ans += n//2 - v1.most_common()[0][1]
    ans += n//2 - v2.most_common()[0][1]
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
E=Counter(V[::2]).most_common()
O=Counter(V[1::2]).most_common()
E2=Counter(V[1::2]).most_common()[1][1] if len(E)>1 else 0
O2=Counter(V[::2]).most_common()[1][1] if len(O)>1 else 0 
print(n-E[0][1]-O[0][1] if E[0][0]!=O[0][0] else n-max(E[0][1]+E2,O[0][1]+O2))

Submission status: Runtime Error

Solution code:
import collections
from collections import Counter

n=int(input())
a=[int(i) for i in input().split()]
b=[]
c=[]

for i in range(n):
	if i%2==0:
		b.append(a[i])

	else:
		c.append(a[i])

b=collections.Counter(b)
c=collections.Counter(c)


b = b.most_common()
c = c.most_common()

if b[0][0]==c[0][0]:
	d =n-b[0][1]-c[1][1]
	e =n-b[1][1]-c[0][1]
	print(min(d,e))

else:
	print(n-b[0][1]-c[0][1])

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    v_even = v[::2]
    v_odd = v[1::2]
    from collections import Counter
    v_even_cnt = sorted(list(Counter(v_even).items()),key=lambda x:x[1],reverse=True)
    v_odd_cnt = sorted(list(Counter(v_odd).items()),key=lambda x:x[1],reverse=True)
    ans = -1
    if v_even_cnt[0][0] != v_odd_cnt[0][0]:
        ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[0][1]
    else:
        print(v_even_cnt,v_odd_cnt)
        if v_even_cnt[0][1] < v_odd_cnt[0][1]:
            if len(v_even_cnt) > 1:
                ans = len(v_even) - v_even_cnt[1][1] + len(v_odd) - v_odd_cnt[0][1]
            else:
                ans = len(v_even) - 0 + len(v_odd) - v_odd_cnt[0][1]
        elif v_even_cnt[0][1] > v_odd_cnt[0][1]:
            if len(v_odd_cnt) > 1:
                ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[1][1]
            else:
                ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - 0
        else:
            if v_even_cnt[1][1] > v_odd_cnt[1][1]:
                ans = v_even_cnt[0][1] + v_odd_cnt[1][1]
            else:
                ans = v_even_cnt[1][1] + v_odd_cnt[0][1]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

from collections import Counter

v1 = []
v2 = []
for i in range(0,n,2):
  v1.append(V[i])
for i in range(1,n,2):
  v2.append(V[i])
  
c1 = Counter(v1)
c2 = Counter(v2)

if list(c1.keys())[0] == list(c2.keys())[0]:
  a1 = sum(list(c1.values())[1:])+list(c2.values())[0]+sum(list(c2.values()[2:]))
  a2 = sum(list(c2.values())[1:])+list(c1.values())[0]+sum(list(c1.values()[2:]))
           
  ans = min(a1,a2)
  
else:
  ans = sum(list(c1.values())[1:])+sum(list(c2.values())[1:])

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

f = Counter(v[::2]).most_common(2)
s = Counter(v[1::2]).most_common(2)

if f[0][0] != s[0][0]:
    print(n - f[0][1] - s[0][1])
else:
    if len(s) == 1 or len(b) == 1:
        print(n // 2)
    else:
        print(n - max(f[0][1] + s[1][1], f[1][1] + s[0][1]))