n=int(input())
a=list(map(int,input().split()))
s=sum(a)
ev=[]
od=[]
for i in range(n):
	if(a[i]%2==0):
		ev.append(a[i])
	else:
		od.append(a[i])
lev=len(ev)
lod=len(od)
ev.sort()
od.sort()
ev.reverse()
od.reverse()
if(abs(lev-lod)==1 or abs(lev-lod)==0):
	print("0")
	#print("hello")
elif(min(lev,lod)==lev):
	t=lod-lev
	print(sum(od[lev+1:lod]))
elif(min(lev,lod)==lod):
	t=lev-lod
	#print(t,lev,lod)
	print(sum(ev[lod+1:lev]))