n = int(input())

arr = list(map(int,input().split()))


odd = []
even = []

for num in arr:
    if num & 1 == 0:
        even.append(num)
    else:
        odd.append(num)

odd.sort()
even.sort()

m,n = len(odd),len(even)

if m < n:
    m,n = n,m
    odd,even = even,odd

if m - n <= 1:
    print(0)
else:
    print(sum(odd[:m-n-1]))