Problem: 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.

Submission attempts (in order):
N=int(input())
lv=list(map(int,input().split()))
dev={}
dod={}


max1_ev=[0,0]
max2_ev=[0,0]
max1_od=[0,0]
max2_od=[0,0]

for i in range(N):
    if i%2==0:#even
        #max1_ev=[0,0]
        #max2_ev=[0,0]
        

        if lv[i] in dev:
            dev[lv[i]]+=1
        else:
            dev[lv[i]]=1
            
            #cev+=1
            #if cev==1:
            #    max1_ev=[i,lv[i]]
            #elif cev==2:
            #    max2_ev=[i,lv[i]]
        
        
        if dev[lv[i]]>max1_ev[1]:
            max1_ev=[lv[i],dev[lv[i]]]
        
        elif dev[lv[i]]>=max2_ev[1]:
            max2_ev=[lv[i],dev[lv[i]]]
        #print("dev[lv[i]]",dev[lv[i]])
        #print("max1__ev[1]",max1_ev[1])
        #print("max1_ev",max1_ev)
        #print("max2_ev",max2_ev)
        #if i==0:
        #    max1=[0,1]
        #elif i==1:
        #    max2
    else:#odd
        #max1_od=[0,0]
        #max2_od=[0,0]
        if lv[i] in dod:
            dod[lv[i]]+=1
        else:
            dod[lv[i]]=1
        if dod[lv[i]]>max1_od[1]:
            max1_od=[lv[i],dod[lv[i]]]
        
        elif dod[lv[i]]>=max2_od[1]:
            max2_od=[lv[i],dod[lv[i]]]
print("dev",dev)#ok
print("dod",dod)#ok
print("max1_ev",max1_ev)
print("max2_ev",max2_ev)


#if len(dev)==1 and len(dod)==1:
#    print(int(N/2))
#elif len(dev)==1:
    
    #    if i==0:
    #        max1_od=
#    if max1_ev[0]!=max1_od[0]:
#        print(N-max1_ev[1]-max1_od[1])
##        print(max)
if max1_ev[0]!=max1_od[0]:
    print(N-max1_ev[1]-max1_od[1])
elif len(dev)==1 and len(dod)==1:
    print(int(N/2))
elif len(dev)==1:
    print(int(N/2)-max2_od[1])
elif len(dod)==1:
    print(int(N/2)-max2_ev[1])
else:
    
    print(min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))


N=int(input())
lv=list(map(int,input().split()))
dev={}
dod={}


max1_ev=[0,0]
max2_ev=[0,0]
max1_od=[0,0]
max2_od=[0,0]

for i in range(N):
    if i%2==0:#even
        #max1_ev=[0,0]
        #max2_ev=[0,0]
        

        if lv[i] in dev:
            dev[lv[i]]+=1
        else:
            dev[lv[i]]=1
            
            #cev+=1
            #if cev==1:
            #    max1_ev=[i,lv[i]]
            #elif cev==2:
            #    max2_ev=[i,lv[i]]
        
        
        if dev[lv[i]]>max1_ev[1]:
            a=max1_ev
            max1_ev=[lv[i],dev[lv[i]]]
            max2_ev=a
        
        elif dev[lv[i]]>=max2_ev[1]:
            max2_ev=[lv[i],dev[lv[i]]]
        #print("dev[lv[i]]",dev[lv[i]])
        #print("max1__ev[1]",max1_ev[1])
        #print("max1_ev",max1_ev)
        #print("max2_ev",max2_ev)
        #if i==0:
        #    max1=[0,1]
        #elif i==1:
        #    max2
    else:#odd
        #max1_od=[0,0]
        #max2_od=[0,0]
        if lv[i] in dod:
            dod[lv[i]]+=1
        else:
            dod[lv[i]]=1
        if dod[lv[i]]>max1_od[1]:
            a=max1_od
            max1_od=[lv[i],dod[lv[i]]]
            max2_od=a
        
        elif dod[lv[i]]>=max2_od[1]:
            max2_od=[lv[i],dod[lv[i]]]
#print("dev",dev)#ok
#print("dod",dod)#ok
#print("max1_ev",max1_ev)
#print("max2_ev",max2_ev)


#if len(dev)==1 and len(dod)==1:
#    print(int(N/2))
#elif len(dev)==1:
    
    #    if i==0:
    #        max1_od=
#    if max1_ev[0]!=max1_od[0]:
#        print(N-max1_ev[1]-max1_od[1])
##        print(max)
if max1_ev[0]!=max1_od[0]:
    print(N-max1_ev[1]-max1_od[1])
elif len(dev)==1 and len(dod)==1:
    print(int(N/2))
elif len(dev)==1:
    print(int(N/2)-max2_od[1])
elif len(dod)==1:
    print(int(N/2)-max2_ev[1])
else:
    
    print(min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))


Verdicts: Wrong Answer

Accepted