n = int(input())
num = [int(x) for x in input().split(' ')]
odd, even, x, y = [], [], 0, 0
for i in range(n):
    if num[i] % 2 == 1:
        odd.append(num[i])
        x += 1
    else:
        even.append(num[i])
        y += 1
odd.sort()
even.sort()
if abs(x - y) <= 1:
    ans = 0
elif x > y:
    d = x - y - 1
    ans = sum(odd[:d])
else:
    d = y - x - 1
    ans = sum(even[:d])
print(ans)

