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

public class ParityAlternatedDeletions {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = scan.nextInt();
        }
        Arrays.sort(arr);
        int odd = 0;
        int even = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 0) {
                even++;
            } else {
                odd++;
            }
        }
        if (Math.abs(even - odd) <= 1) {
            System.out.println(0);
            return;
        }
        Arrays.sort(arr);
        int num = 0;
        int checkE = 0;
        int checkO = 0;
        int sum = 0;
        int stop = 0;
        if (odd == 0) {
            System.out.println(arr[0]);
        } else {
            System.out.println(arr[0]);
        }
        if (even > odd) {
            num = even - odd;
            checkE++;

        } else {
            num = odd - even;
            checkO++;
        }
        if (checkE > 0) {
            for (int i = 0; i < arr.length; i++) {
                if (stop == num) {
                    System.out.println(sum);
                    return;
                }
                if (arr[i] % 2 == 0) {
                    sum += arr[i];
                    stop++;
                }
            }
        } else {
            for (int i = 0; i < arr.length; i++) {
                if (stop == num) {
                    System.out.println(sum);
                    return;
                }
                if (arr[i] % 2 == 1) {
                    sum += arr[i];
                    stop++;
                }
            }
        }
    }

}
