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())
vList=list(map(int,input().split()))

gusuList=[]
kisuList=[]

for i in range(n):
  if(i % 2==0):
    gusuList.append(vList[i])
  else:
    kisuList.append(vList[i])
#print(gusuList)
#print(kisuList)

g = collections.Counter(gusuList)
gStatus=g.most_common()

k = collections.Counter(kisuList)
kStatus=k.most_common()

ans=-100

if(not gStatus[0][0]==kStatus[0][0]):
    ans=(n/2-gStatus[0][1])+(n/2-kStatus[0][1])
else:
  if(gStatus[0][1]>kStatus[0][1]):
    if(not len(kStatus)==1):
      ans=(n/2-gStatus[0][1])+(n/2-kStatus[1][1])
    else:
      ans=(n/2-gStatus[0][1])+n/2
  elif(gStatus[0][1]<kStatus[0][1]):
    if(not len(gStatus)==1):
      ans=(n/2-gStatus[1][1])+(n/2-kStatus[0][1])
    else:
      ans=n/2+(n/2-kStatus[0][1])
  elif(gStatus[0][1]==kStatus[0][1]):
      if(gStatus[1][1]>=kStatus[1][1]):
        if(not len(kStatus)==2):
          ans=(n/2-gStatus[0][1])+(n/2-kStatus[2][1])
        else:
          ans=(n/2-gStatus[0][1])+(n/2-kStatus[1][1])
      elif(gStatus[0][1]<kStatus[0][1]):
        if(not len(gStatus)==2):
          ans=(n/2-gStatus[2][1])+(n/2-kStatus[0][1])
        else:
          ans=(n/2-gStatus[1][1])+(n/2-kStatus[0][1])
      
    
    
print(int(ans))

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(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])

count_odd = collections.Counter(v_odd)
count_even = collections.Counter(v_even)
temp_odd = list(count_odd.values())
temp_even = list(count_even.values())
# print(temp_odd)
# print(temp_even)
if list(count_even.keys())[0] != list(count_odd.keys())[0]:
    odd_sum = sum(temp_odd)-temp_odd[0]
    even_sum = sum(temp_even)-temp_even[0]
    print(odd_sum+even_sum)
else:
    try:
        sum_odd1 = sum(temp_odd) - temp_odd[1]
    except:
        sum_odd1 = temp_odd[0]
    sum_even1 = sum(temp_even) - temp[0]
    sum1 = sum_even1+sum_odd1

    try:
        sum_even2 = sum(temp_even) - temp_even[1]
    except:
        sum_even2 = temp_even[0]
    sum_odd2 = sum(temp_odd) - temp_odd[0]
    sum2 = sum_even2+sum_odd2
    prin(min(ans1,ans2))

Submission status: Runtime Error

Solution code:
from collections import Counter


n = int(input())
v = [int(i) for i in input().split()]

A = v[0::2]
c = Counter(A)
a = c.most_common()[0][1]
e = c.most_common()[1][1]
B = v[1::2]
d = Counter(B)
b = d.most_common()[0][1]
f = d.most_common()[1][1]

X = (n / 2) - a
Y = (n / 2) - b

if A == B:
    print(int(n / 2))
elif a == b:
    if e > f:
        print(int((n / 2) - e + Y)
    elif f <= e:
        print(int((n / 2) - f + X)
else:
    Z = X + Y
    print(int(Z))

Submission status: Runtime Error

Solution code:
import collections

n = int(input())

al = [int(l) for l in input().split()]

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

ac = collections.Counter(a).most_common()
bc = collections.Counter(b).most_common()

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if len(ac) > 0 and ac[0][1] == ac[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif len(bc) > 0 and bc[0][1] == bc[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif ac[0][1] >= bc[0][1]:
        if len(bc) <= 1:
            print(n-ac[0][1])
        else:
            print(n-ac[0][1]-bc[1][1])
    else:
        if len(ac) <= 1:
            print(n-bc[0][1])
        else:
            print(n-ac[1][1]-bc[0][1])

Submission status: Runtime Error

Solution code:
import collections as cl

n=int(input())
vlist=list(input().split())

vg=vlist[0::2]
vk=vlist[1::2]

vgcnt=cl.Counter(vg)
vkcnt=cl.Counter(vk)

vgmax=max(vgcnt,key=vgcnt.get)
vkmax=max(vkcnt,key=vgcnt.get)

if vgmax==vkmax:
    if vgcnt[vgmax]<vkcnt[vkmax]:
        vgcnt.pop(vgmax)
        if len(vgcnt)>0:
            vgmax=max(vgcnt)
        else:
            vgmax='a'
    else:
        vkcnt.pop(vkmax)
        if len(vkcnt)>0:
            vkmax=max(vkcnt)
        else:
            vkmax='a'

ans=0
for i in range(len(vg)):
    if vg[i]!=vgmax:
        ans+=1
for i in range(len(vk)):
    if vk[i]!=vkmax:
        ans+=1

print(ans)

Submission status: Runtime Error

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

A=[[0,i] for i in range(10**5)]
B=[[0,i] for i in range(10**5)]

for i in range(0,n,2):
    A[V[i]][0]+=1
for i in range(1,n,2):
    B[V[i]][0]+=1

A.sort(reverse=1)
B.sort(reverse=1)

#print(A[:10])
#print(B[:10])

Ma=[]
Mb=[]

ma=A[0][0]
mb=B[0][0]
i=0
j=0
while A[i][0]==ma :
    Ma.append(A[i][1])
    i+=1

while B[j][0]==mb :
    Mb.append(B[j][1])
    j+=1

if Ma==Mb :
    print(min(n-ma-B[j][0],n-mb-A[i][0]))
else :
    print(n-ma-mb)

Submission status: Runtime Error

Solution code:
#encoding utf-8

n = int(input())
v = list(int(i) for i in 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])

#odd part
count={}
for i in range(len(v_odd)):
    if v_odd[i] in count.keys():
        count[v_odd[i]] += 1
    else:
        count[v_odd[i]] = 1



for k, v in sorted(count.items(), key=lambda x: -x[1]):
    pass
keys = list(count.keys())
# num_odd = len(v_odd)-int(count[keys[0]])


#even part
even_count={}

for i in range(len(v_even)):
    if v_even[i] in even_count.keys():
        even_count[v_even[i]] += 1
    else:
        even_count[v_even[i]] = 1


for k, v in sorted(even_count.items(), key=lambda x: -x[1]):
    pass
even_keys = list(even_count.keys())
# num += len(v_even)-int(count[even_keys[0]])


if even_keys[0] == keys[0]:
    if len(keys) == 1 and len(even_keys) == 1:
        answer = int(n/2)
    elif len(keys) == 1:
        answer = int(n/2)-int(even_count[even_keys[1]])
    elif len(even_keys) == 1:
        answer = int(n/2)-int(count[keys[1]])
    else:
        if int(v_even[even_keys[0]]) >= int(v_odd[keys[0]]):
            answer = n-int(count[keys[1]])-int(even_count[even_keys[0]])
        else:
            answer = n-int(count[keys[0]])-int(even_count[even_keys[1]])
else:
    answer = n-int(count[keys[0]])-int(even_count[even_keys[0]])
print(int(answer))

Submission status: Runtime Error

Solution code:
import collections


n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(int(n/2)):
    even.append(v[2*i])
    odd.append(v[2*i + 1])
evencount = collections.Counter(even)
oddcount = collections.Counter(odd)


def hoge(i):
    if evencount == oddcount:
        ans = n - evencount.most_common()[0][1] - oddcount.most_common()[1][1]
    else:
        if evencount.most_common()[i][0] == oddcount.most_common()[i][0]:

            if evencount.most_common()[i][1] > oddcount.most_common()[i][1]:
                ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
                print(ans)
            elif evencount.most_common()[i][1] < oddcount.most_common()[i][1]:
                ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
                print(ans)
            else:
                if len(evencount) == 1:
                    ans = int(n/2)
                    print(ans)
                else:
                    hoge(i+1)

        else: 
            ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
            print(ans)


hoge(0)

Submission status: Runtime Error

Solution code:
import collections
import functools

n = int(input())
v = list(map(int,input().split()))
even = v[1::2]
odd = v[::2]
errChar = 0
errFlag = False

def f(l):
    global errChar
    global errFlag
    # print(errFlag)
    c = collections.Counter(l)
    if len(c) == 1:
        if errFlag and errChar == list(c.keys())[0] :
            fixList = list(c.items())
            return sum([fixList[i][1] for i in range(len(fixList))])
        errFlag = True
        # print(c.keys())
        errChar = l[0]
        return 0
    s = sorted(c.items(),key=lambda x: x[1],reverse=True)
    fixList = []
    if errFlag and errChar == s[0][0] :
        fixList = s.pop(1)
    else:
        fixList = s[1:]
        errFlag = True
        errChar = s[0][0]
    return sum([fixList[i][1] for i in range(len(fixList))])
print(f(even) + f(odd))

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    v = list(map(int, input().split()))
    v_ki = v[1:N:2].copy()
    val_ki = [i+1 for i in range(10**5)]
    count_ki = [0] * (10**5)
    v_gu = v[0:N:2].copy()
    val_gu = [i+1 for i in range(10**5)]
    count_gu = [0] * (10**5)
    for i in range(N//2):
        count_ki[v_ki[i]] += 1
        count_gu[v_gu[i]] += 1
    
    ki = list(zip(count_ki, val_ki))
    ki.sort()
    ki_len = len(ki)
    gu = list(zip(count_gu, val_gu))
    gu.sort()
    gu_len = len(gu)
    if ki[-1][1] != gu[-1][1]:
        return N-ki[-1][0]-gu[-1][0]
    else:
        return min(N-ki[-2][0]-gu[-1][0], N-ki[-1][0]-gu[-2][0])

if __name__ == "__main__":
    print(main())

Submission status: Runtime Error

Solution code:
n = int(input())
v_odd = {}
v_even = {}
vlist = list(map(int, input().split()))
for i in range(n):
    if i % 2 == 1:
        if vlist[i] in v_odd:
            v_odd[vlist[i]] += 1
        else:
            v_odd[vlist[i]] = 1
    else:
        if i in v_even:
            v_even[vlist[i]] += 1
        else:
            v_even[vlist[i]] = 1
ans = 10 ** 6
NNNlist = [0 for i in range(n)]
for i in v_odd:
    for j in v_even:
        if i == j:
            break
        for k in range(n):
            if k % 2 == 0:
                NNNlist[k] = j
            else:
                NNNlist[k] = i
        counter = 0
        for l in range(n):
            if vlist[l] != NNNlist[l]:
                counter += 1
        if counter < ans:
            ans = counter
if ans == 10 ** 6:
    ans = n // 2
print(ans)

Submission status: Runtime Error

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

E = []
O = []
for i in range(0, n, 2):
    for j in range(len(E)):
        if nums[i] == E[j][1]:
            E[j][0] += 1
            break
    else:
        E.append([1, nums[i]])
    for j in range(len(O)):
        if nums[i+1] == O[j][1]:
            O[j][0] += 1
            break
    else:
        O.append([1, nums[i+1]])
E.sort(reverse = True)
O.sort(reverse = True)

if E[0][1] != O[0][1]:
    print(n - E[0][0] - O[0][0])
elif len(E) == 1 and len(O) == 1:
    print(n//2)
elif len(E) == 1:
    print(n - O[1][0])
else:
    pritn(n - E[1][0])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

v1 = {}

v2 = {}

for i in range(n//2):
    if  v[2 *i +1] in v1.keys():
        v1[v[2 * i +1]] += 1
    else:
        v1[v[2 * i + 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1


v1 = sorted(v1.items(),key=lambda x: - x[0])
v2 = sorted(v2.items(),key=lambda x: - x[0])
v1.reverse()
v2.reverse()
v1.append((None,0))
v2.append((None,0))
@print(v1)
if v1[0][0] == v2[0][0]:
    ans = max(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]

print(n - ans)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
a = [ int(x) for x in input().split() ]

def count_elem(x):
    coll = collections.Counter(x)
    return coll.most_common()

b = count_elem(a[::2])
c = count_elem(a[1::2])

if b[0][0] != c[0][0]:
    print(len(a) - b[0][1] - c[0][1])
else:
    if b[0][1] > c[0][1]:
        if len(c) > 1:
            print(len(a) - b[0][1] - c[1][1])
        else:
            print(len(a) - b[0][1])
    elif b[0][1] < c[0][1]:
        if len(b) > 1:
            print(len(a) - b[1][1] - c[0][1])
        else:
            print(len(a) - c[0][1])
    elif b[0][1] == c[0][1]:
        if b[1][1] >= c[1][1]:
            print(len(a) - b[1][1] - c[0][1])
        else:
            print(len(a) - b[0][1] - c[1][1])

Submission status: Runtime Error

Solution code:
n=int(input())
count=0
v=[]
v=[int(i) for i in input().split()]
for i in range(n-2):
    if v[i]==v[i+2]:
        pass
    else:
        count+=1
num=v[0]
for i in range(n):
    v.remove(num)
print(v)
if len(v)==0:
    if n%2==0:
        count=int(n/2)
    else:
        count=int((n-1)/2)
print(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]

counter1 = Counter(v1)
x1 = counter1.most_common()[0:2]
counter2 = Counter(v2)
x2 = counter2.most_common()[0:2]

n = n//2
ans = 0
if x1[0][0] == x2[0][0]:
    if x1[0][1] > x2[0][1]:
        ans = (n - x1[0][1]) + (n - x2[1][1])
    else:
        ans =  (n - x2[0][1]) + (n - x1[1][1])
else:
    ans = (n - x1[0][1]) + (n - x2[0][1])

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
num = []
even_num = {}
odd_num = {}
for index in range(n):
	num.append(input())

for index in range(0,n):
	if index%2 == 0:
		if num[index] in even_num:
			even_num[num[index]] += 1
		else:
			even_num[num[index]] = 1
	else:
		if num[index] in odd_num:
			odd_num[num[index]] += 1
		else:
			odd_num[num[index]] = 1

even_max_key = max(even_num, key=even_num.get)
odd_max_key = max(odd_num, key=odd_num.get)
even_change = int(n/2) - even_num[even_max_key]
odd_change = int(n/2) - odd_num[odd_max_key]

if even_max_key == odd_max_key:
	if even_change < odd_change:
		if len(even_num) == 1:
			odd_num = int(n/2)
		if len(even_num) != 1:
			del even_num[even_max_key]
			even_max_key = max(even_num, key=even_num.get)
			even_change = n/2 - even_num[even_max_key]
	else:
		if len(odd_num) == 1:
			even_change = int(n/2)
		if len(odd_num) != 1:
			del odd_num[odd_max_key]
			odd_max_key = max(odd_num, key=odd_num.get) 
			odd_change = n/2 - odd_num[odd_max_key]

ans = int(even_change + odd_change)
print(ans)

Submission status: Runtime Error

Solution code:
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())
a = ai()
if all(i == a[0] for i in a):
    print(n//2)
    exit()

a1 = a[::2]
a2 = a[1::2]

from collections import Counter
c1 = Counter(a1)
c2 = Counter(a2)
m1 = c1.most_common(2)
m2 = c2.most_common(2)
if m1[0][0] == m2[0][0]:
    if len(c1) == 1:
        print(n-m1[0][1]-m2[1][1])
    elif len(c2) == 1:
        print(n - m1[0][1] - m2[1][1])
    else:
        print(min(n-m1[0][1]-m2[1][1], n-m1[1][1]-m2[0][1]))
else:
    print(n-m1[0

Submission status: Runtime Error

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

if o.most_common()[0][0] == e.most_common()[0][0]:
    if o.most_common()[0][1] > e.most_common()[0][1]:
        maxevencnt = e.most_common()[1][1]
    else:
        maxoddcnt = o.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    v = list(map(int, input().split()))
    v_ki = v[1:N:2].copy()
    val_ki = [i+1 for i in range(10**5)]
    count_ki = [0] * (10**5)
    v_gu = v[0:N:2].copy()
    val_gu = [i+1 for i in range(10**5)]
    count_gu = [0] * (10**5)
    for i in range(N//2):
        count_ki[v_ki[i]] += 1
        count_gu[v_gu[i]] += 1
    
    ki = list(zip(count_ki, val_ki))
    ki.sort()
    ki_len = len(ki)
    gu = list(zip(count_gu, val_gu))
    gu.sort()
    gu_len = len(gu)
    if ki[-1][1] != gu[-1][1]:
        return N-(ki[-1][0])-(gu[-1][0])
    elif ki_len == gu_len:
        return N//2
    else:
        return min(N-(ki[-2][0])-(gu[-1][0]), N-(ki[-1][0])-(gu[-2][0]))

if __name__ == "__main__":
    print(main())

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import collections

N = int(input())
A = list(map(int, input().split(' ')))

up = A[0::2]
down = A[1::2]
upc = collections.Counter(up)
doc = collections.Counter(down)

umc = upc.most_common(2)
dmc = doc.most_common(2)

if umc[0][0] == dmc[0][0]:
	if umc[0][1] > dmc[0][1]:
		dmc[0] = dmc[1]
	else:
		umc[0] = umc[1]


u = len(A)/2 - umc[0][1]
d = len(A)/2 - dmc[0][1]

if (u == 0 and d == 0) and umc[0][0] == dmc[0][0]:
	print(int(len(A)/2))
	exit()

print(int(u+d))

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
v = [int(i) for i in input().split()]

v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]

count1 = collections.Counter(v1)
count2 = collections.Counter(v2)

if len(count1) == 1 and len(count2) == 1:
    if v1 == v2:
        print(len(v1))
    else:
        print(0)

if v1 == v2:
    res = len(v1) - max(count1.values()) + len(v2) - list(count2.values())[1]
    print(res)

else:
    res = len(v1) - max(count1.values()) + len(v2) - max(count2.values())
    print(res)

Submission status: Runtime Error

Solution code:
n=int(input())
count=0
v=[]
v=[int(i) for i in input().split()]
for i in range(n-2):
    if v[i]==v[i+2]:
        pass
    else:
        count+=1
v.pop(v[0])
if len(v)==0:
    if n%2==0:
        count=int(n/2)
    else:
        count=int((n-1)/2)
print(count)

Submission status: Runtime Error

Solution code:
import collections

n=int(input())
num_str=input().split()
print(num_str)
list=list(map(int, num_str))

list_e = [list[i] for i in range(0,n-1,2)]
list_o = [list[i] for i in range(1,n,2)]
e = collections.Counter(list_e)
o = collections.Counter(list_o)
mode_e=e.most_common(2)
mode_o=o.most_common(2)
if mode_e[0][0]==mode_o[0][0]:
    if mode_e[0][1]>mode_o[0][1]:
        mode_e_value=mode_e[0][1]
        mode_o_value=mode_o[1][1]
    else:
        mode_e_value=mode_e[1][1]
        mode_o_value=mode_o[0][1]
else:
    mode_e_value = mode_e[0][1]
    mode_o_value = mode_o[0][1]
print(n-mode_e_value-mode_o_value)

Submission status: Runtime Error

Solution code:
import collections

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

if len(set(v)) == 1:
    print(int(n/2))

else:
    odd = v[0::2]
    even = v[1::2]
    odd_c = collections.Counter(odd).most_common()[1:]
    even_c = collections.Counter(even).most_common()[1:]

    values, odd_counts = zip(*odd_c)
    values, even_counts = zip(*even_c)

    print(sum(odd_counts)+sum(even_counts))

Submission status: Runtime Error

Solution code:
n = int(input())
v_odd = {}
v_even = {}
vlist = list(map(int, input().split()))
for i in range(n):
    if i % 2 == 1:
        if vlist[i] in v_odd:
            v_odd[vlist[i]] += 1
        else:
            v_odd[vlist[i]] = 1
    else:
        if i in v_even:
            v_even[vlist[i]] += 1
        else:
            v_even[vlist[i]] = 1
ans = 10 ** 6
for i in v_odd:
    for j in v_even:
        if i == j:
            break
        NNNlist = [0 for i in range(n)]
        for k in range(n):
            if k % 2 == 0:
                NNNlist[k] = j
            else:
                NNNlist[k] = i
        counter = 0
        for l in range(n):
            if vlist[l] != NNNlist[l]:
                counter += 1
        if counter < ans:
            ans = counter
if ans == 10 ** 6:
    ans = n / 2
print(ans)

"""
omax = max(v_odd, key=(lambda x: v_odd[x]))
emax = max(v_even, key=(lambda x: v_even[x]))
if omax != emax:
    orewrite = sum(v_odd[i] for i in v_odd) - v_odd[omax]
    erewrite = sum(v_even[i] for i in v_even) - v_even[emax]
    ans = orewrite + erewrite
    print(ans)
else:
    lo = len(v_odd)
    le = len(v_even)
    if lo == 1 and le == 1:
        print(v_odd[omax])
    elif lo != 1:
        osum = sum(v_odd[i] for i in v_odd)
        v_odd[omax] = 0
        osecmax = max(v_odd, key=(lambda x: v_odd[x]))
        ans = osum - osecmax + sum(v_even[i] for i in v_even) - v_even[emax]
        print(ans)
    else:
        esum = sum(v_even[i] for i in v_even)
        v_even[emax] = 0
        esecmax = max(v_even, key=(lambda x: v_even[x]))
        ans = esum - esecmax + sum(v_odd[i] for i in v_odd) - v_odd[omax]
        print(ans)
"""

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
ac = collections.Counter(a)
bc = collections.Counter(b)
ac = sorted(ac.items(), key=lambda x: x[1], reverse=True)
bc = sorted(bc.items(), key=lambda x: x[1], reverse=True)
if ac[0][0] == bc[0][0]:
    if len(ac) == len(bc) and len(ac) == 1:
        print(ac[0][1])
        exit()
    i = 0
    while ac[i][1] == bc[i][1]:
        i += 1
    if ac[i][1] > bc[i][1]:
        ac.remove(ac[i])
        bc.remove(bc[0])
    elif ac[i][1] < bc[i][1]:
        ac.remove(ac[0])
        bc.remove(bc[i])
else:
    ac.remove(ac[0])
    bc.remove(bc[0])
ans = 0
for i in range(len(ac)):
    ans += ac[i][1]
for i in range(len(bc)):
    ans += bc[i][1]
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np,math,itertools


n=int(input())
v=list(map(int,input().split()))
va,vb=[],[]
v2=[]

for i in range(n):
   if i%2==0:va+=[v[i]]
   else:vb+=[v[i]]

def hkk(a,b):
   s=0
   for i in range(min(len(a),len(b))):
      if a[i]!=b[i]:s+=1
   return s

def hsm(a):
   q=[0 for i in range(10001)]
   for i in a:
      q[i]+=1
   c=max(q)
   z=0
   while q[z]!=c:z+=1
   return z


ha=hsm(va)
hb=hsm([i for i in vb if i!=ha])

for i in range(n):
   v2+=[ha]
   v2+=[hb]

print(hkk(v,v2))

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))

A1=[]
A2=[]
for i in range(len(A)):
    if i%2==0:
        A1.append(A[i])
    else:
        A2.append(A[i])
        
B1=collections.Counter(A1)
B2=collections.Counter(A2)

if N==2:
    print(0)

#elif B1.most_common(2)[0][1]==B2.most_common(2)[0][1] and B1.most_common(2)[0][1]==int(N/2):
    #print(int(N/2))
else:
    
    
    if B1.most_common(1)==B2.most_common(1):
        if B1.most_common(2)[1][1]>=B2.most_common(2)[1][1]:
            ans=N-B1.most_common(2)[1][1]-B2.most_common(2)[0][1]
        else:
            ans=N-B2.most_common(2)[1][1]-B1.most_common(2)[0][1]
    elif B1.most_common(2)[0][0]==B2.most_common(2)[0][0]:
        if B1.most_common(2)[0][1]>=B2.most_common(2)[0][1]:
            ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[1][1]
        else:
            ans=N-B2.most_common(2)[0][1]-B1.most_common(2)[1][1]
    else:
        ans=N-B1.most_common(2)[0][1]-B2.most_common(2)[0][1]
    print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5))]
cc = [0 for i in range(pow(10,5))]
for i in range(a):
    if i % 2 == 0:
        c[b[i]] += 1
    else:
        cc[b[i]] += 1

one = 0
onee = 0
two = 0
twoo = 0
p = 0
pp = 0
for i in range(d+1):
    if one <= c[i]:
        onee = one
        one = c[i]
        p += 1
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        p += 1
    if p == 2:
        pp = 1
    else:
        pp = 0
    p = 0

t = max(one+twoo,onee+two)

if pp == 0:
    print(a-one-two)
else:
    print(a-t)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
k = n//2
a = list(map(int,input().split()))
b = c = []
for i in range(k):
  b.append(a[2*i])
  c.append(a[2*i+1])
p = Counter(b).most_common()
q = Counter(c).most_common()
s, t = p[0], q[0]
if s[0]!=t[0]:
  ans = n - s[1]-t[1]
else:
  if p[1][1] >= q[1][1]:
    ans = n - t[1]-p[1][1]
  else:
    ans = n - s[1] - q[1][1]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
v1 = []
v2 = []
for i in range(n):
    if(i % 2 == 1):
        v1.append(v[i])
    else:
        v2.append(v[i])
count1 = [v1.count(v1[i]) for i in range(int(n/2))]
count1 = list(set(count1))
count1.sort()
count2 = [v2.count(v2[i]) for i in range(int(n/2))]
count2 = list(set(count2))
count2.sort()
if(count1[0] == count2[0]):
    print(int(n/2 - count1[0] + n/2 - count2[1]))
else:
    print(int(n/2 - count1[0] + n/2 - count2[0]))

Submission status: Runtime Error

Solution code:
import collections

N = int(raw_input().replace("\n", ""))

a_list = map(int, raw_input().replace("\n", "").split(" "))
even_list = a_list[::2]
odd_list = a_list[1::2]

len_vec = N / 2

even_c = collections.Counter(even_list)
odd_c = collections.Counter(odd_list)



even_first_value, even_first_count = even_c.most_common()[0]
odd_first_value, odd_first_count  = odd_c.most_common()[0]
#(even_first_value, even_first_count), (even_second_value, even_second_count) = even_c.most_common()[:2]
#(odd_first_value, odd_first_count), (odd_second_value, odd_second_count) = odd_c.most_common()[:2]

if even_first_value == odd_first_value and len(even_c) == 1 and len(odd_c) == 1:
    cost = len_vec
elif even_first_value != odd_first_value:
    cost =  (even_first_count + odd_first_count)
elif len(even_c) == 1 and len(odd_c) > 1:
    odd_second_value, odd_second_count = odd_c.most_common(1)
    cost = len_vec + odd_second_count
elif len(odd_c) == 1 and len(even_c) > 1:
    even_second_value, even_second_count = even_c.most_common(1)
    #cost = len_vec + odd_second_count
    cost = len_vec + even_second_count
else: # ryouhou no first ga onaji de hutatuijou arutoki
    odd_second_value, odd_second_count = odd_c.most_common(1)
    even_second_value, even_second_count = even_c.most_common(1)
    cost = max(even_first_count+odd_second_count, even_second_count+odd_first_count)

print 2* len_vec - cost

Submission status: Runtime Error

Solution code:
import collections


n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(int(n/2)):
    even.append(v[2*i])
    odd.append(v[2*i + 1])
evencount = collections.Counter(even)
oddcount = collections.Counter(odd)


def hoge(i):
    try:
        if evencount.most_common()[i][0] == oddcount.most_common()[i][0]:

            if evencount.most_common()[i][1] > oddcount.most_common()[i][1]:
                ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
            elif evencount.most_common()[i][1] < oddcount.most_common()[i][1]:
                ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
            else:
                if len(evencount) == 1:
                    ans = int(n/2)
                else:
                    hoge(i+1)

        else: 
            ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
    except IndexError:    
        ans = n - evencount.most_common()[0][1] - oddcount.most_common()[1][1]
    print(ans)
    

hoge(0)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

    if len(set(v)) == 1:
        print(len(v)//2)
        exit()

    ans = 0
    vc = Counter(v)
    vc0 = Counter(v[::2])
    vc1 = Counter(v[1::2])

    if vc.most_common(1)[0][1] >= len(v)//2:
        if len(set(v[::2])) > len(set(v[1::2])):
            ans += len((v[::2])) - vc0.most_common(2)[1][1]
            ans += len((v[1::2])) - vc1.most_common(1)[0][1]
        else:
            ans += len((v[::2])) - vc0.most_common(1)[0][1]
            ans += len((v[1::2])) - vc1.most_common(2)[1][1]

    else:
        ans += len((v[::2])) - vc0.most_common(1)[0][1]
        ans += len((v[1::2])) - vc1.most_common(1)[0][1]

    print(ans)

if __name__ == "__main__":
        main()

Submission status: Runtime Error

Solution code:
#encoding utf-8

n = int(input())
v = list(int(i) for i in 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])

#odd part
count={}
for i in range(len(v_odd)):
    if v_odd[i] in count.keys():
        count[v_odd[i]] += 1
    else:
        count[v_odd[i]] = 1



for k, v in sorted(count.items(), key=lambda x: -x[1]):
    pass
keys = list(count.keys())
# num_odd = len(v_odd)-int(count[keys[0]])


#even part
even_count={}

for i in range(len(v_even)):
    if v_even[i] in even_count.keys():
        even_count[v_even[i]] += 1
    else:
        even_count[v_even[i]] = 1


for k, v in sorted(even_count.items(), key=lambda x: -x[1]):
    pass
even_keys = list(even_count.keys())
# num += len(v_even)-int(count[even_keys[0]])


if even_keys[0] == keys[0]:
    if len(keys) == 1 and len(even_keys) == 1:
        answer = int(len(v_odd))
    elif len(keys) == 1:
        answer = len(v_even)-int(even_count[even_keys[1]])
    elif len(even_keys) == 1:
        answer = len(v_odd)-int(count[keys[1]])
    else:
        if int(v_even[even_keys[0]]) >= int(v_odd[keys[0]]):
            answer = len(v_odd)-int(count[keys[1]])
            answer += len(v_even)-int(even_count[even_keys[0]])
        else:
            answer = len(v_odd)-int(count[keys[0]])
            answer += len(v_even)-int(even_count[even_keys[1]])

else:
    answer = n-int(count[keys[0]])-int(even_count[even_keys[0]])
print(int(answer))