def ii(): return int(input())
def fi(): return float(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())

n=ii()
a=li()
o=e=0
l=[]
m=[]
for i in range(n):
    if a[i]%2==0:
        e+=1
        l.append(a[i])
    else:
        o+=1 
        m.append(a[i])
l.sort()
m.sort()
if abs(o-e)<=1:
    ans=0 
elif e>o:
    f=e-o-1
    ans=sum(l[0:f])
else:
    f=o-e-1
    ans=sum(m[0:f])
print(ans)