Problem:


Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Runtime Error

Solution code:
n = int(input())
v_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
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 and le == 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)
    elif lo ==1 and le != 1:
        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)
    else:
        def o2():
            osum = sum(v_odd[i] for i in v_odd)
            ofirmax = v_odd[omax]
            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) + ofirmax - v_even[emax]
            return ans
        def e2():
            esum = sum(v_even[i] for i in v_even)
            efirmax = v_even[emax]
            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) + efirmax- v_odd[omax]
            return ans
        print(min(o2(), e2()))

Submission status: Runtime Error

Solution code:

n=int(input())
v=input().split()
vodd=[]
veven=[]
for i in range(n):
    if i%2:
        veven.append(int(v[i]))
    else:
        vodd.append(int(v[i]))

changeCnt=0

voddNum=[vodd[0]]
voddCnt=[0]
j=0
for i,odd in enumerate(vodd):
    if voddNum[j]!=odd:
        for k,num in enumerate(voddNum):
            if num==odd:
                j=k
                break
        else:
            j=k+1
            voddNum.append(odd)
            voddCnt.append(0)
            
    voddCnt[j]+=1

voddSet=list(zip(voddCnt, voddNum))
print(voddSet)
for i in range(len(voddSet)):
    voddSet[i]=list(voddSet[i])

voddSet=list(reversed(sorted(voddSet,key=lambda x:x[0])))

'''
print(vodd)
print(voddNum)
print(voddCnt)
print(voddSet)
'''

vevenNum=[veven[0]]
vevenCnt=[0]
j=0
for i,even in enumerate(veven):
    if vevenNum[j]!=even:
        for k,num in enumerate(vevenNum):
            if num==even:
                j=k
                break
        else:
            j=k+1
            vevenNum.append(even)
            vevenCnt.append(0)

    vevenCnt[j]+=1
vevenSet=list(zip(vevenCnt, vevenNum))
print(vevenSet)
for i in range(len(vevenSet)):
    vevenSet[i]=list(vevenSet[i])

vevenSet=list(reversed(sorted(vevenSet,key=lambda x:x[0])))

'''
print()
print(veven)
print(vevenNum)
print(vevenCnt)
print(vevenSet)
'''

changeCnt+=len(vodd)+len(veven)
if voddSet[0][1]==vevenSet[0][1]:
    if len(voddSet==1):
        changeCnt+=-len(vodd)
    else:
        if voddSet[1][0]>vevenSet[1][0]:
            changeCnt+=-voddSet[1][0]-vevenSet[0][0]
        else:
            changeCnt+=-voddSet[0][0]-vevenSet[1][0]
else:
    changeCnt+=-voddSet[0][0]-vevenSet[0][0]
    
print(changeCnt)

Submission status: Runtime Error

Solution code:
import operator

n=int(input().strip())
lst=input().split(' ')
map(int, lst)

d1 = {}
d2 = {}

for i in range(len(lst)):
    if i % 2 == 0:
        if lst[i] in d1:
            d1[lst[i]] += 1
        else:
            d1[lst[i]] = 1
    else:
        if lst[i] in d2:
            d2[lst[i]] += 1
        else:
            d2[lst[i]] = 1

sd1 = sorted(d1.values(), reverse=True)
sd2 = sorted(d2.values(), reverse=True)
key1 = max(d1.items(), key=operator.itemgetter(1))[0]
key2 = max(d2.items(), key=operator.itemgetter(1))[0]

if(key1 == key2):

    v11 = sd1[0]
    if(len(d1) == 1):
        v12 = 0
    else:
        v12 = sd1[1]

    v21 = sd2[0]
    if(len(d2) == 1):
        v22 = 0
    else:
        v22 = sd2[1]

    print(min(n-v11-v22, n-v12-v21))

else:
    print(n-sd1[0]-sd2[key2])

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).most_common(2)
bc = collections.Counter(b).most_common(2)
if ac[0][0] != bc[0][0]:
    print(n - ac[0][1] - bc[0][1])
else:
    print(n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1]))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
e = []
o = []
for i, a in enumerate(v):
    if i % 2:
        o.append(a)
    else:
        e.append(a)
oc = Counter(o)
ec = Counter(e)
h = n//2
if oc.most_common(1)[0][0] != ec.most_common(1)[0][0]:
    a = h - oc.most_common(1)[0][1]
    b = h - ec.most_common(1)[0][1]
    print(a+b)
else:
    E1 = E2 = 0
    for i, (k, v) in ec.most_common(2):
        if i == 0:
            E2 = E1 = k
        else:
            E2 = k
    O1 = O2 = 0
    for i, (k, v) in oc.most_common(2):
        if i == 0:
            O2 = O1 = k
        else:
            O2 = k
    print(min(h-ec[E1] + h - oc[O2], h - ec[E2] + h - oc[O1]))

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
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 and le == 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)
    elif lo ==1 and le != 1:
        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)
    else:
        def o2():
            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]
            return ans
        def e2():
            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]
            return ans
        print(max(o2(), e2()))

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]
B = v[1::2]
d = Counter(B)
b = d.most_common()[0][1]

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

if A == B:
    print(int(n / 2))
elif A != B and a == b:
    e = c.most_common()[1][1]
    f = d.most_common()[1][1]
    if f > e:
        print(int((n / 2) - e + Y))
    elif f <= e:
        print(int((n / 2) - f + X))

if A != B and a != b:
    Z = X + Y
    print(int(Z))

Submission status: Runtime Error

Solution code:
import collections as cl
from statistics import mode

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

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

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

vgmax=mode(vg)
vkmax=mode(vk)

if vgmax==vkmax:
    if vgcnt[vgmax]<vkcnt[vkmax]:
        vgcnt.pop(vgmax)
        if len(vgcnt)!=0:
            vgmax=max(vgcnt)
        else:
            vgmax+=1
    else:
        vkcnt.pop(vkmax)
        if len(vkcnt)!=0:
            vkmax=max(vkcnt)
        else:
            vkmax+=1

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

n = int(input())
v = list(map(int, input().split()))
# odd = []
# even = []
# for i in range(len(v)):
#     if(i % 2 == 0):
#         even.append(v[i])
#     else:
#         odd.append(v[i])
odd = v[::2]
even = v[1::2]

c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)


if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
elif(len(c_even) != 1 and len(c_odd) != 1):
    second = max[c_even[1][1], c_odd[1][1]]
    print(n - c_even[0][1] - second)
else:
    print(min([c_even[0][1], c_odd[0][1]]))

Submission status: Runtime Error

Solution code:
import collections as cl
from statistics import mode

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

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

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

vgmax=mode(vg)
vkmax=mode(vg)

if vgmax==vkmax:
    if vgcnt[vgmax]<vkcnt[vkmax]:
        vgcnt.pop(vgmax)
        if len(vgcnt)!=0:
            vgmax=max(vgcnt)
        else:
            vgmax+=1
    else:
        vkcnt.pop(vkmax)
        if len(vkcnt)!=0:
            vkmax=max(vkcnt)
        else:
            vkmax+=1

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:
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]
B = v[1::2]
d = Counter(B)
b = d.most_common()[0][1]

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

if A == B:
    print(int(n / 2))
elif a == b:
    e = c.most_common()[1][1]
    f = d.most_common()[1][1]
    if f > e:
        print(int((n / 2) - e + Y))
    elif f <= e:
        print(int((n / 2) - f + X))

if A != B and a != b:
    Z = X + Y
    print(int(Z))

Submission status: Runtime Error

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

dd_even = defaultdict(int)
dd_odd  = defaultdict(int)

# 偶数番目のヒストグラムを作る
for i in range(0, n, 2):
    dd_even[v[i]] += 1

l_even = list(dd_even.items())
l_even.sort(key= lambda x:x[1])
top_even = l_even[-1][0]
#print(l_even)

# 奇数番目のヒストグラムを作る
for i in range(1, n, 2):
    dd_odd[v[i]] += 1

l_odd = list(dd_odd.items())
l_odd.sort(key= lambda x:x[1])
#print(l_odd)
top_odd = l_odd[-1][0]

if top_even == top_odd:
    if len(l_odd) == 1: # つまり全部同じ数字のとき
        res = int(n / 2)
        print(res)
        sys.exit()
    else:
        # 2パターン試す
        l_odd_1 = [l for l in l_odd if l[0] != l_odd[-2][0]]
        sum_odd_1 = sum(l[1] for l in l_odd_1)
        l_even_1 = [l for l in l_even if l[0] != top_even]
        sum_even_1 = sum(l[1] for l in l_even1)
        sum_1 = sum_odd_1 + sum_even_1

        l_odd_2 = [l for l in l_odd if l[0] != top_odd]
        sum_odd_2 = sum(l[1] for l in l_odd_2)
        l_even_2 = [l for l in l_even if l[0] != l_even[-2][0]]
        sum_even_1 = sum(l[1] for l in l_even_2)
        sum_2 = sum_odd_2 + sum_even_2
        
        if sum1 < sum2:
            print(sum1)
        else:
            print(sum2)
        sys.exit()
else:
    l_odd = [l for l in l_odd if l[0] != top_odd]

sum_odd = sum(l[1] for l in l_odd)
#print(l_odd, sum_odd)

l_even = [l for l in l_even if l[0] != top_even]
sum_even = sum(l[1] for l in l_even)
#print(l_even, sum_even)

res = sum_odd + sum_even
print(res)

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]
B = v[1::2]
d = Counter(B)
b = d.most_common()[0][1]

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

e = c.most_common()[1][1]
f = d.most_common()[1][1]

if A == B:
    print(int(n / 2))
elif a == b:
    e = c.most_common()[1][1]
    f = d.most_common()[1][1]
    if f > e:
        print(int((n / 2) - e + Y))
    elif f <= e:
        print(int((n / 2) - f + X))

if A != B and a != b:
    Z = X + Y
    print(int(Z))

Submission status: Runtime Error

Solution code:
a = int(input())
b = str(input())
numlist = b.split()
kisu = numlist[::2]
kisutext = ''.join(kisu)
gusu = numlist[1::2]
kisucount = 0
susou = a/2
gusucount = 0

for i, num in enumerate(kisu):
    if kisu.count(num) >1:
        ans = susou-kisu.count(num)
        che1 = num
        break

for i, num in enumerate(gusu):
    if gusu.count(num) >1:
        gususou = susou-gusu.count(num)
        che2 = num
        break
 
ans += gususou
if che1==che2:
    ans = a
    
print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = [::2]
ki = [1::2]
ans = 0
k,g = False,False

if v.count(v[0]) == n:#全部同じ
    ans += n // 2
else:
    kic = Counter(ki)
    guc = Counter(gu)
    k1 = kic.most_common(2)
    g1 = guc.most_common(2)
    if k1[0][0] == g1[0][0]:
        if k1[1][1] < g1[1][1]:
            k = True
        elif k1[1][1] > g1[1][1]:
            g = True

    kic = list(kic.values())
    guc = list(guc.values())
    kic.sort(reverse = True)
    guc.sort(reverse = True)
    if len(kic) != 1:
        if k:
            ans += kic[0]
            ans += sum(kic[2::])
        else:
            ans += sum(kic[1::]) 
    if len(guc) != 1:
        if g:
            ans += guc[0]
            ans += sum(guc[2::])
        else:
            ans += sum(guc[1::])

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().strip().split(" ")))
odd = []
even = []
for i in range(len(v)):
    if(i % 2 == 0):
        even.append(v[i])
    else:
        odd.append(v[i])


c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)


if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
elif(len(c_even) != 1 and len(c_odd) != 1):
    second = max[c_even[1][1], c_odd[1][1]]
    print(n - c_even[0][1] - second)
else:
    print(min([c_even[0][1], c_odd[0][1]]))

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().strip().split(" ")))
odd = []
even = []
for i in range(len(v)):
    if(i % 2 == 0):
        even.append(v[i])
    else:
        odd.append(v[i])


c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)

print(c_even, c_odd)

if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
elif(len(c_even) != 1 and len(c_odd) != 1):
    second = max[c_even[1][1], c_odd[1][1]]
    print(n - c_even[0][1] - second)
else:
    print(min([c_even[0][1], c_odd[0][1]]))

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) >= 2 and ac[0][1] == ac[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif len(bc) >= 2 and bc[0][1] == bc[1][1]:
        print(n-ac[0][1]-bc[0][1])

    min_c = n//2

    if len(bc) >= 1:
        min_c = min(min_c, n-ac[0][1]-bc[1][1])
    else:
        min_c = min(min_c, n-ac[0][1])
    if len(ac) >= 1:
        min_c = min(min_c, n-ac[1][1]-bc[0][1])
    else:
        min_c = min(min_c, n-bc[0][1])
        
    if len(ac) >= 1 and len(bc) >= 1:
        min_c = min(min_c, n-bc[1][1]-ac[1][1])
    print(min_c)

Submission status: Runtime Error

Solution code:
a = int(input())
b = str(input())
numlist = b.split()
kisu = numlist[::2]
kisutext = ''.join(kisu)
gusu = numlist[1::2]
kisucount = 0
susou = a/2
gusucount = 0

for i, num in enumerate(kisu):
    if kisu.count(num) >1:
        ans = susou-kisu.count(num)
        break

for i, num in enumerate(gusu):
    if gusu.count(num) >1:
        gususou = susou-gusu.count(num)
        break
    
ans += gususou
    
print(int(ans))

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) >= 2 and ac[0][1] == ac[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif len(bc) >= 2 and bc[0][1] == bc[1][1]:
        print(n-ac[0][1]-bc[0][1])

    min_c = n//2

    if len(bc) >= 1:
        min_c = min(min_c, n-ac[0][1]-bc[1][1])
    min_c = min(min_c, n-ac[0][1])
    if len(ac) >= 1:
        min_c = min(min_c, n-ac[1][1]-bc[0][1])
    min_c = min(min_c, n-bc[0][1])
    if len(ac) >= 1 and len(bc) >= 1:
        min_c = min(min_c, n-bc[1][1]-ac[1][1])
    print(min_c)

Submission status: Runtime Error

Solution code:
# N個のスペース区切りの数値を取得
N = int(input())
A = [int(N) for N in input().split()]



odd = []
even = []

# odd
for i in range(N):
    if i%2 == 0:
        odd.append(A[i])
    else:
        even.append(A[i])

import collections
c_odd = collections.Counter(odd)
c_even = collections.Counter(even)
#print(c_odd.most_common()[0][0], c_even.most_common()[0][0])

if c_odd.most_common()[0][0] == c_even.most_common()[0][0] :
    
    # 偶数と奇数番目でどっちのcommonの登場回数も一緒だったら、
    # 2番目、3番目・・・と差がでるか、もしくは N/2 まで検索
    for i in range(N//2-1):
        # i番目にCommonな数値について判定
        if c_odd.most_common()[i][1] > c_even.most_common()[i][1] :
            #奇数の方が多いので、偶数の配列はi+1番めに多い数を採用
#            print('odd is many.')
#            print('次点で多い偶数の登場回数=', c_even.most_common()[i+1][1])
#            print('答え:', N//2 - c_odd.most_common()[i][1], N//2 - c_even.most_common()[i+1][1])
            print(N//2 - c_odd.most_common()[i][1] + N//2 - c_even.most_common()[i+1][1])
            exit()
        if c_odd.most_common()[i][1] < c_even.most_common()[i][1] :
            #奇数の方が多いので、偶数の配列はi+1番めに多い数を採用
#            print('even is many.')
#            print('次点で多い奇数の登場回数=', c_even.most_common()[i+1][1])
#            print('答え:', N//2 - c_odd.most_common()[i+1][1], N//2 - c_even.most_common()[i][1])
            print(N//2 - c_odd.most_common()[i+1][1] + N//2 - c_even.most_common()[i][1])
            exit()
        else:
            #偶数と奇数で同じ回数の登場だったら、次に登場回数の多い数を持っている側を変更する
            pass
    #全部一致の時は
    print(N//2)
else:
    print(len(set(odd))-1 + len(set(even))-1)

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
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 and le == 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(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_odd[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
    print(min(ans1,ans2))

Submission status: Runtime Error

Solution code:
import collections

n = int(input())

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

vo = []
ve = []

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

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

co = collections.Counter(vo)
ce = collections.Counter(ve)

if co == ce:
    print("01")
    exit(0)

ovalues, ocounts = zip(*co.most_common())
evalues, ecounts = zip(*ce.most_common())

a = 0
b = 0

if ovalues[0] != evalues[0] and ovalues.count(ovalues[0]) > 1 or evalues.count(evalues[0]) > 1:
    print(abs(len(co) - len(ce)))
    exit(0)

else:
    if len(ocounts) + len(ecounts) == n:
        print(n - 1)
        exit(0)

    if len(co) <= len(ce):
        for i in range(len(ce)):
            if evalues[i] != evalues[0]:
                a += 1
                
    else:
        for i in range(co):
            if ovalues[i] != ovalues[0]:
                a += 1
    
print(a)

Submission status: Runtime Error

Solution code:
n = int(input())
numberL = list(map(int, input().split()))
 
kisuuSyuL=[]
kisuuKosuL=[]
kisuuKosuL2=[]
gusuSyuL=[]
gusuKosuL=[]
gusuKosuL2=[]
 
index=0
while index<n:
    if index==0:
        gusuSyuL.append(numberL[index])
        gusuKosuL.append(1)
        gusuKosuL2.append(1)
    elif index==1:
        kisuuSyuL.append(numberL[index])
        kisuuKosuL.append(1)
        kisuuKosuL2.append(1)
    else:
        if index%2==0:
            if numberL[index] in gusuSyuL:
                tarI = gusuSyuL.index(numberL[index])
                gusuKosuL[tarI]+=1
                gusuKosuL2[tarI]+=1
            else:
                gusuSyuL.append(numberL[index])
                gusuKosuL.append(1)
                gusuKosuL2.append(1)
        else:
            if numberL[index] in kisuuSyuL:
                tarI = kisuuSyuL.index(numberL[index])
                kisuuKosuL[tarI]+=1
                kisuuKosuL2[tarI]+=1
            else:
                kisuuSyuL.append(numberL[index])
                kisuuKosuL.append(1)
                kisuuKosuL2.append(1)
    index+=1
 
 
if len(kisuuSyuL)==1 and len(gusuSyuL)==1:
    if kisuuSyuL[0]==gusuSyuL[0]:
        print(int(n/2))
    else:
        print(0)
else:
    kiIndex = kisuuKosuL.index(max(kisuuKosuL))
    guIndex = gusuKosuL.index(max(gusuKosuL))
    if kisuuSyuL[kiIndex]!=gusuSyuL[guIndex]:
        noC=max(kisuuKosuL)+max(gusuKosuL)
        print(n-noC)
    else:
        kisuuKosuL2.sort()
        gusuKosuL2.sort()
        if max(kisuuKosuL)-kisuuKosuL2[len(kisuuKosuL2)-2] < max(gusuKosuL)-gusuKosuL2[len(gusuKosuL2)-2]:
            noC=kisuuKosuL2[len(kisuuKosuL2)-2]+max(gusuKosuL)
            print(n-noC)
        else:
            noC=gusuKosuL2[len(gusuKosuL2)-2]+max(kisuuKosuL)
            print(n-noC)
n = int(input())
numberL = list(map(int, input().split()))
 
kisuuSyuL=[]
kisuuKosuL=[]
kisuuKosuL2=[]
gusuSyuL=[]
gusuKosuL=[]
gusuKosuL2=[]
 
index=0
while index<n:
    if index==0:
        gusuSyuL.append(numberL[index])
        gusuKosuL.append(1)
        gusuKosuL2.append(1)
    elif index==1:
        kisuuSyuL.append(numberL[index])
        kisuuKosuL.append(1)
        kisuuKosuL2.append(1)
    else:
        if index%2==0:
            if numberL[index] in gusuSyuL:
                tarI = gusuSyuL.index(numberL[index])
                gusuKosuL[tarI]+=1
                gusuKosuL2[tarI]+=1
            else:
                gusuSyuL.append(numberL[index])
                gusuKosuL.append(1)
                gusuKosuL2.append(1)
        else:
            if numberL[index] in kisuuSyuL:
                tarI = kisuuSyuL.index(numberL[index])
                kisuuKosuL[tarI]+=1
                kisuuKosuL2[tarI]+=1
            else:
                kisuuSyuL.append(numberL[index])
                kisuuKosuL.append(1)
                kisuuKosuL2.append(1)
    index+=1

 
if len(kisuuSyuL)==1 and len(gusuSyuL)==1:
    if kisuuSyuL[0]==gusuSyuL[0]:
        print(int(n/2))
    else:
        print(0)
else:
    kisuuKosuL2.sort()
    gusuKosuL2.sort()
    kiIndex = kisuuKosuL.index(kisuuKosuL2[len(kisuuKosuL2)-1])
    guIndex = gusuKosuL.index(gusuKosuL2[len(gusuKosuL2)-1])
    if kisuuSyuL[kiIndex]!=gusuSyuL[guIndex]:
        noC=kisuuKosuL2[len(kisuuKosuL2)-1]+gusuKosuL2[len(gusuKosuL2)-1]
        print(n-noC)
    else:
        if kisuuKosuL2[len(kisuuKosuL2)-1]-kisuuKosuL2[len(kisuuKosuL2)-2] < gusuKosuL2[len(gusuKosuL2)-1]-gusuKosuL2[len(gusuKosuL2)-2]:
            noC=kisuuKosuL2[len(kisuuKosuL2)-2]+gusuKosuL2[len(gusuKosuL2)-1]
            print(n-noC)
        else:
            noC=gusuKosuL2[len(gusuKosuL2)-2]+kisuuKosuL2[len(kisuuKosuL2)-1]
            print(n-noC)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections
import functools
import sys
sys.setrecursionlimit(1000000)

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:
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_odd[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:
import copy
n = int(input())
MAX = 5
li = input().split(" ")
el = []
ol = []
for i in range(n):
    if i % 2 == 0:
        el.append(int(li[i]))
    else:
        ol.append(int(li[i]))
n_el = len(list(set(el)))
n_ol = len(list(set(ol)))
if n_el == 1 and n_ol == 1 and el[0] != ol[0]:
    print(0)
elif n_el == 1 and n_ol == 1 and el[0] == ol[0]:
    print(len(ol))
else:
    kinds = sorted(list(set(li)))
    nums = [[0,0] for i in range(MAX)]
    for e in el:
        nums[e][0] += 1
    for o in ol:
        nums[o][1] += 1
    costs = [[0,0] for i in range(MAX)]
    for i in range(MAX):
        costs[i] = [n//2 - nums[i][0], n//2 - nums[i][1]]
    index_e = []
    index_o = []
    min_e = 1000000
    min_o = 1000000
    for i in range(MAX):
        if min_e > costs[i][0]:
            min_e = costs[i][0]
            index_e = [i]
        elif min_e == costs[i][0]:
            index_e.append(i)
        if min_o > costs[i][1]:
            min_o = costs[i][1]
            index_o = [i]
        elif min_o == costs[i][1]:
            index_o.append(i)
    ans_temp = 1000000
    # e が最小だったら
    for i in index_e:
        temp_cost = []
        for j in range(MAX):
            temp_cost.append(costs[j][1])
        temp_cost[i] = 999999
        tete = min_e + min(temp_cost)
        if tete < ans_temp:
            ans_temp = tete
    for i in index_o:
        temp_cost = []
        for j in range(MAX):
            temp_cost.append(costs[j][0])
        temp_cost[i] = 999999
        tete = min_o + min(temp_cost)
        if tete < ans_temp:
            ans_temp = tete
    print(ans_temp)