n = int(input())
arr = list(map(int, input().split()))
cnt_even = 0; cnt_odd = 0; even = []; odd = []; flag = False
for i in arr:
    if i % 2 == 0:
        cnt_even += 1
        even.append(i)
    else:
        cnt_odd += 1
        odd.append(i)
even.sort()
odd.sort()
if cnt_even == 0:
    cnt_odd -= 1
    flag = True
else:
    cnt_even -= 1
    flag = True
if cnt_even == cnt_odd or cnt_even+1 == cnt_odd or cnt_even == cnt_odd+1 and flag == False:
    print('0')
elif cnt_even > cnt_odd:
    index = cnt_even - cnt_odd
    print(sum(even[0:index]))
elif cnt_even < cnt_odd:
    index = cnt_odd - cnt_even
    print(sum(odd[0:index]))