n = int(input())
t = list(map(int,input().split(' ')))

even = sum([x%2==0 for x in t])
odd = n - even
if even >= odd - 1 and even <= odd + 1:
	print(0)
elif even > odd :
	t_even = [x for x in t if x%2==0]
	t_even = sorted(t_even)
	print(sum(t_even[:even-odd-1]))

else:
	t_even = [x for x in t if x%2==1]
	t_even = sorted(t_even)
	print(sum(t_even[:-even+odd-1]))
