Problem p03244 (python)

Fixed submission:
n=int(input())
v=map(int,input().split())
vodd={-1:0}
veven={-1:0}
for i,vi in enumerate(v):
    if i%2:
        if(vi in veven):
            veven[vi]+=1
        else:
            veven[vi]=1
    else:
        if(vi in vodd):
            vodd[vi]+=1
        else:
            vodd[vi]=1
veven=list(veven.items())
veven.sort(key=lambda x:-x[1])
vodd=list(vodd.items())
vodd.sort(key=lambda x:-x[1])
if veven[0][0]==vodd[0][0]:
    a=veven[0][1]+vodd[1][1]
    b=veven[1][1]+vodd[0][1]
    changeCnt=n-a if a>b else n-b
else:
    changeCnt=n-veven[0][1]-vodd[0][1]

print(changeCnt)

Buggy submission (verdict: Runtime Error):
n=int(input())
v=map(int,input().split())
vodd={}
veven={}
for i,vi in enumerate(v):
    if i%2:
        if(vi in veven):
            veven[vi]+=1
        else:
            veven[vi]=1
    else:
        if(vi in vodd):
            vodd[vi]+=1
        else:
            vodd[vi]=1
veven=list(veven.items())
veven.sort(key=lambda x:x[1])
veven.reverse()
vodd=list(vodd.items())
vodd.sort(key=lambda x:x[1])
vodd.reverse()
if len(veven)==2 & len(vodd)==2:
    if veven[0][0]==vodd[0][0]:
        a=veven[0][1]+vodd[1][1]
        b=veven[1][1]+vodd[0][1]
        changeCnt=a if a<b else b
    else:
        changeCnt=veven[1][1]+vodd[1][1]
elif len(veven)==1 & len(vodd)==1:
    if veven[0][0]==vodd[0][0]:
        a=vodd[0][1]
        b=veven[0][1]
        changeCnt=a if a<b else b
    else:
        changeCnt=0
elif len(veven)==1:
    if veven[0][0]==vodd[0][0]:
        changeCnt=vodd[0][1]
    else:
        changeCnt=vodd[1][1]
elif len(vodd)==1:
    if veven[0][0]==vodd[0][0]:
        changeCnt=veven[0][1]
    else:
        changeCnt=veven[1][1]

print(changeCnt)

Buggy submission (verdict: Runtime Error):
n=int(input())
v=map(int,input().split())
vodd=[]
voddNum={}
veven=[]
vevenNum={}
for i,vi in enumerate(v):
    if i%2:
        veven.append(vi)
        if(vi in vevenNum):
            vevenNum[vi]+=1
        else:
            vevenNum[vi]=1
    else:
        vodd.append(vi)
        if(vi in voddNum):
            voddNum[vi]+=1
        else:
            voddNum[vi]=1
vevenNum=list(vevenNum.items())
voddNum=list(voddNum.items())
vevenNum.sort(key=lambda x:x[1])
vevenNum.reverse()
voddNum.sort(key=lambda x:x[1])
voddNum.reverse()
if len(vevenNum)==2 & len(voddNum)==2:
    if vevenNum[0][0]==voddNum[0][0]:
        a=vevenNum[0][1]+voddNum[1][1]
        b=vevenNum[1][1]+voddNum[0][1]
        changeCnt=a if a<b else b
    else:
        changeCnt=vevenNum[1][1]+voddNum[1][1]
elif len(vevenNum)==1 & len(voddNum)==1:
    if vevenNum[0][0]==voddNum[0][0]:
        changeCnt=voddNum[0][1] if voddNum[0][1]<vevenNum[0][1] else vevenNum[0][1]
    else:
        changeCnt=0
elif len(vevenNum)==1:
    if vevenNum[0][0]==voddNum[0][0]:
        changeCnt=voddNum[0][1]
    else:
        changeCnt=voddNum[1][1]
elif len(voddNum)==1:
    if vevenNum[0][0]==voddNum[0][0]:
        changeCnt=vevenNum[0][1]
    else:
        changeCnt=vevenNum[1][1]

print(changeCnt)

Buggy submission (verdict: Runtime Error):

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)