n=int(input())
a=list(map(int,input().split()))
even,odd=[],[]
ev,od=0,0
for i in range(n):
    if a[i]%2==0:
        even.append(a[i])
        ev+=1 
    else:
        odd.append(a[i])
        od+=1 
even.sort()
odd.sort()
mini=min(ev,od)
maxi=max(ev,od)
if ev==0 and od>0:
    print(sum(odd[:-1]))
elif ev>0 and od==0:
    print(sum(even[:-1]))
elif maxi%mini==0 and maxi//mini==1 :
    print(0)
elif maxi%mini==0 and maxi//mini>1:
    if len(even)>len(odd):
        print(sum(even[-abs(maxi-mini)+1:]))
    else:
        print(sum(odd[-abs(maxi-mini)+1:]))
elif (maxi%mini)!=0 and (maxi//mini)!=0 and abs(maxi-mini)<=1:
    print(0)
elif(maxi%mini)!=0 and (maxi//mini)!=0 and abs(maxi-mini)>1:
    if len(even)>len(odd):
        print(sum(even[-(maxi%mini)+1:]))
    else:
        print(sum(odd[-(maxi%mini)+1:]))
elif maxi%mini!=0 and (maxi//mini)==0:
    if len(even)>len(odd):
        print(sum(even[:-1]))
    else:
        print(sum(odd[:-1]))