N = int(input())
A = list(map(int, input().split()))
odd = 0
even = 0
x = []
y = []
for a in A:
    if a % 2:
        odd += 1
        x.append(a)
    else:
        even += 1
        y.append(a)
x.sort()
y.sort()
if abs(odd - even) <= 1:
    ans = 0
elif even < odd:
    ans = sum(x[:odd - even - 1])
elif odd < even:
    ans = sum(y[:even - odd - 1])
print(ans)
