n = input()
arr = map(int, raw_input().split())
e = 0
o = 0
oo = []
ee = []
for i in range(n):
	if arr[i] % 2 == 0:
		e += 1
		ee.append(arr[i])
	else:
		o += 1
		oo.append(arr[i])
if abs(e-o) <= 1:
	print 0
else:
	ee = sorted(ee)
	oo = sorted(oo)
	sse = sum(ee)
	sso = sum(oo)
	so = 0
	se = 0
	i = 0
	j = 0
	if e > o:
		while i < o:
			so += oo[len(oo)-i-1]
			se += ee[len(ee)-j-1]
			i += 1
			j += 1
		se += ee[len(ee)-j-1]
		print sse - se
	else:
		while j < e:
			so += oo[len(oo)-i-1]
			se += ee[len(ee)-j-1]
			i += 1
			j += 1
		so += oo[len(oo)-i-1]
		print sso - so