import java.util.Scanner; public class Osushi { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int[] saraArray = new int[N]; for (int i = 0; i < N; i++) { saraArray[i] = scan.nextInt(); } int choise = (N - 1) / 2; int[] resultArray = new int[choise]; for (int i = 0; i < choise; i++) { int num = isMax(saraArray); resultArray[i] = num; int rank = isRank(saraArray, num); saraArray[rank] = -1; if (rank != 0) { saraArray[rank - 1] = -1; } if (rank != N - 1) { saraArray[rank + 1] = -1; } } int answer = 0; for (int result : resultArray) { answer += result; } System.out.println(answer); } private static int isMax(int[] saraArray) { int max = saraArray[0]; for (int i = 0; i < saraArray.length; i++) { if (saraArray[i] > max) { max = saraArray[i]; } } return max; } private static int isRank(int[] saraArray, int num) { int result = 0; for (int i = 0; i < saraArray.length; i++) { if (num == saraArray[i]) { result = i; } } return result; } }