n = int(input())
numbers = list(map(int, input().split()))
odd = 0
even = 0
o = []
e = []
for i in numbers:
	if i%2 != 0:
		odd+=1
		o.append(i)
	else:
		even+=1
		e.append(i)
e.sort()
o.sort()
result = 0
if abs(odd - even) <= 1:
	print(0)
	exit()

else:
	if odd < even:
		for i in range(even - odd - 1):
			result+=e[i]
	else:
		for i in range(odd - even -1):
			result+=o[i]
print(result)
