n = int(input())
a = list(map(int, input().split()))
listodd = []
listeven = []
odd = 0
even = 0
for i in range(len(a)):
    if a[i] % 2 == 1:
        odd += 1
        listodd.append(a[i])
    else:
        even += 1
        listeven.append(a[i])
listeven.sort()
listodd.sort()
if even == odd:
    print(0)
elif even > odd:
    print(sum(listeven[0:even-odd-1]))
else:
    print(sum(listodd[0:odd-even-1]))
