N = int(input())

a = list(map(int, input().split()))
odd = [i for i in a if i%2 != 0]
even = [i for i in a if i%2 == 0]

nOdd = len(odd)
nEven = len(even)

if abs(nOdd - nEven) < 2:
    print(0)
else:
    if nOdd > nEven:
        num = nOdd - nEven - 1
        odd.sort()
        print(sum(odd[:num]))
    else:
        num = nEven - nOdd - 1
        even.sort()
        print(sum(even[:num]))