n = int(input())
a = list(map(int, input().split()))
even = 0
odd = 0
summa = 0
a.sort()
for i in range(n):
	if a[i] % 2 == 1:
		odd += 1
	else:
		even += 1
	summa += a[i]
if abs(even - odd) > 1:
	if odd > even:
		odd = even + 1
	else:
		even = odd + 1
for i in range(n - 1, -1, -1):
	if odd == 0 and even == 0:
		break
	if a[i] % 2 == 0 and even > 0:
		summa -= a[i]
		even -= 1
	if a[i] % 2 == 1 and odd > 0:
		summa -= a[i]
		odd -= 1
print(summa)