#include<stdio.h>
#define MAX 1001
void swap(int*,int*);

int main(){
  int i,j,min,sum=0,flag;
  int n;
  int W[MAX];
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&W[i]);
  }
  i = -1;
  while(i != n-1){
    flag = 0;
    i = i+1;
    min = i;
    for(j = i+1; j < n; j++){
      if(W[min] > W[j]){
        min = j;
        flag = 1;
      }
    }
    if(flag){
      swap(&W[min],&W[i]);
      sum += W[i] + W[min];
    }
  }
  printf("%d\n",sum);
  return 0;
}

void swap(int* w,int* min){
  int tmp;
  tmp = *w;
  *w = *min;
  *min = tmp;
}