n=int(input())
l=[int(i) for i in input().split()]
ev=[i for i in l if i%2==0]
odd=[i for i in l if i&1]
oc=sum(i%2 for i in l)
ec=sum(i%2==0 for i in l)
if oc==ec or abs(oc-ec)==1:
    print(0)
else:
    if ec>oc:
        ev.sort()
        rem=ec-oc-1 
        print(sum(ev[0:rem]))
    else:
        odd.sort()
        rem=oc-ec-1 
        print(sum(odd[0:rem]))