#include <stdio.h>
#include <stdlib.h>
void mergesort(long long*,long long,long long);
void merge(long long*,long long,long long,long long);
int main(int argc, char *argv[]) {
long long n,num,i,j,tmp;
while(scanf("%lld",&num)!=EOF)
{
long long array[num],sum=0,sum1=0,min=0,minimum,n,point=0;
for(i=0;i<num;i++)
scanf("%lld",&array[i]);
mergesort(array,0,num-1);
for (n=num-1; n>=3; n-=2)
{
sum = array[0] + array[1]*2 + array[n];
sum1 = array[0]*2 + array[n-1] + array[n];
if(sum>sum1)
minimum=sum1;
else
minimum=sum;
min+=minimum;
}
if (n == 2) min += array[0] + array[1] + array[2];
else if (n == 1) min += array[1];
else min += array[0];
printf("%lld\n",min);
}
return 0;
}
void mergesort(long long* data,long long start,long long last)
{
int half;
half=(start+last)/2;
if(start<last)
{
mergesort(data,start,half);
mergesort(data,half+1,last);
merge(data,start,half,last);
}
}
void merge(long long* data,long long start,long long half,long long last)
{
long long i,m,k,l,temp[1000000];
l=start;
i=start;
m=half+1;
while((l<=half)&&(m<=last)){
if(data[l]<=data[m]){
temp[i]=data[l];
l++;
}
else{
temp[i]=data[m];
m++;
}
i++;
}
if(l>half){
for(k=m;k<=last;k++){
temp[i]=data[k];
i++;
}
}
else{
for(k=l;k<=half;k++){
temp[i]=data[k];
i++;
}
}
for(k=start;k<=last;k++){
data[k]=temp[k];
}
}