import sun.reflect.generics.tree.Tree;

import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeMap;

public class AlternateDeletions {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int e=0, o=0;
        for(int i=0; i<n; i++)
        {
            a[i] = sc.nextInt();
            if(a[i]%2 == 0)
                e++;
            else
                o++;
        }

        int[] even = new int[e];
        int[] odd = new int[o];
        int k=0,l=0;
        for(int i=0; i<n; i++)
        {
            if(a[i]%2 == 0)
                even[k++] = a[i];
            else
                odd[l++] = a[i];
        }

        Arrays.sort(even);
        Arrays.sort(odd);
/*
        for(int i=0; i<e; i++)
            System.out.println(even[i]);
        for(int i=0; i<o; i++)
            System.out.println(odd[i]);
*/

    int min = Math.min(o,e);
    int max = Math.max(o,e);

    long sumo = 0l;
    long sume = 0l;
    if(max == o)
    {
        for(int i=0; i<= max-min-2; i++)
            sumo+=odd[i];
    }
    else
        {
            for(int i=0; i<= max-min-2; i++)
                sume+=even[i];
        }
    //    System.out.println("odd sum : "+sumo);

    //        System.out.println("even sum : "+sume);

        if(sume !=0)
            System.out.println(sume);
        else
            System.out.println(sumo);

     /*   TreeMap<Integer, Integer> evenTree = new TreeMap<>();
        TreeMap<Integer, Integer> oddTree = new TreeMap<>();

        for(int i=0; i<n; i++)
        {
            if(a[i] % 2 == 0)
            {
                if(evenTree.containsKey(a[i]))
                    evenTree.put(a[i], evenTree.get(a[i])+1);
                else
                    evenTree.put(a[i], 1);
            }
            else
            {
                if(oddTree.containsKey(a[i]))
                    oddTree.put(a[i], oddTree.get(a[i])+1);
                else
                    oddTree.put(a[i],1);
            }
        }

        System.out.println("even : "+evenTree+ evenTree.size());
        System.out.println("odd : "+oddTree+ oddTree.size());

        while(oddTree.size()>=0 || evenTree.size()>=0)
        {
            if (oddTree.size() >= evenTree.size())
            {
                System.out.println("Last : "+oddTree.lastKey());
                if(oddTree.get(oddTree.lastKey()) > 0)
                oddTree.put(oddTree.lastKey(),oddTree.get(oddTree.lastKey()) -1);
                System.out.println("last key value : "+oddTree.get(oddTree.lastKey()));
                if(oddTree.get(oddTree.lastKey()) == 0)
                    oddTree.remove(oddTree.lastKey());
                System.out.println("After del "+evenTree);

            }
            else
            {
                oddTree.put(evenTree.lastKey(), evenTree.get(evenTree.lastKey()) -1);
                if(evenTree.get(evenTree.lastKey())== 0)
                    evenTree.remove(evenTree.lastKey());
            }
        }
        System.out.println("e "+evenTree);
        System.out.println("o :"+oddTree);

        */

    }
}
