from sys import stdin
n=int(stdin.readline().strip())
l=list(map(int,stdin.readline().split()))
co=0
ce=0
a=[]
b=[]
for i in range(n):
    if l[i]%2==0:
        co+=1
        a.append(l[i])
    else:
        ce+=1
        b.append(l[i])
if co==ce or co-ce==1 or ce-co==1:
    print(0)
else:
    k=abs(co-ce)
    if co==0 or ce==0:
        k-=1
    a.sort()
    b.sort()
    so=0
    se=0
    for i in range(k):
        if len(a)>=k:
            so+=a[i]
        if len(b)>=k:
            se+=b[i]
    g=max(so,se)
    print(g)