n = int(input())
a = [int(s) for s in input().split()]
os, es = 0,0
for ai in a:
    if ai%2 == 0:
        es += 1
    else:
        os += 1
ans = 0
if es > os:
    es -= 1
elif os > es:
    os -= 1
if es != os:
    rem = 0
    if os > es:
        rem = 1
    k = abs(es-os)
    nums = [ai for ai in a if ai%2 == rem]
    nums.sort()
    ans = sum(nums[0:k])
print(ans)