n=int(input())
a=list(map(int,input().split()))
even,odd=[],[]
ev,od=0,0
for val in a:
    if val%2==0:
        even.append(val)
        ev+=1 
    else:
        odd.append(val)
        od+=1 
even.sort()
odd.sort()
if abs(ev-od)<=1:
    print(0)
else:
    dif=abs(ev-od)-1
    if ev>od:
        print(sum(even[:dif]))
    else:
        print(sum(odd[:dif]))