
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.StringTokenizer;

/**
 *
 * @author Haya
 */
public class ParityAlternatedDeletions {

    public static void main(String[] args) {
        
        FastReader in = new FastReader();
        
        int nums = in.nextInt();
        
        int array[] = new int[nums];
        
        ArrayList<Integer> odd = new ArrayList();
        ArrayList<Integer> even = new ArrayList();
        
        for (int i = 0; i < nums; i++) {
            int val = in.nextInt();
            array[i]=val;
            
            if (i%2!=0)
                even.add(val);
            else
                odd.add(val);
        }
        
        Collections.sort(even);
        Collections.sort(odd);
        
        LinkedList<Integer> nextE = new LinkedList();
        LinkedList<Integer> nextO = new LinkedList();
        
        for (int i = even.size()-1; i >= 0; i--) {
            nextE.add(even.get(i));
        }
        for (int i = odd.size()-1; i >= 0; i--) {
            nextO.add(odd.get(i));
        }
;
       
        int e = (!nextE.isEmpty())?nextE.element():0;
        int o = (!nextO.isEmpty())?nextO.element():0;
        
        boolean isodd = false;
        
        if (o > e){
            isodd = false;
            nextO.remove();
        }
        else{
            isodd = true;
            nextE.remove();
        }

        
        boolean flag = false;
        
        while (flag == false){

            if (isodd){
                if (!nextO.isEmpty()){
                    nextO.remove();
                    isodd = false;
                }
                else
                    flag = true;      
            }
            
            if (isodd == false){
                if (!nextE.isEmpty()){
                    nextE.remove();
                    isodd = true;
                }
                else
                    flag = true;
            }
            
            if (flag) break;
            
        }
        
        
        if (nextO.size()==1 && isodd == false)
            nextO.remove();
        
        if (nextE.size()==1 && isodd == true)
            nextE.remove();
        
        int total = 0;
        
        while (!nextE.isEmpty())
            total += nextE.remove();
        
        while (!nextO.isEmpty())
            total += nextO.remove();
        
        System.out.println(total);
        
 
    }

    public static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String string = "";
            try {
                string = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return string;
        }

    }

}
