from sys import stdin,stdout
for _ in range(1):#int(stdin.readline())):
    n=int(stdin.readline())
    a=list(map(int, stdin.readline().split()))
    even=[];odd=[]
    for v in a:
        if v&1:odd+=[v]
        else:even+=[v]
    even.sort(reverse=True);ne=len(even)
    odd.sort(reverse=True);no=len(odd)
    # print(even)
    # print(odd)
    if ne<=no:
        print(sum(odd[ne+1:no]))
    else:print(sum(even[no+1:ne]))