#include<bits/stdc++.h>
using namespace std;
int n,k1=1,k2=2,ans;
int main(){
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    while(n>2){
        k1=a[0]+2*a[1]+a[n-1];
        k2=a[n-1]+a[n-2]+2*a[0];
        ans+=min(k1,k2);
        n-=2;
          
    }
    if(n==1){
        ans+=a[0];
    }else if(n==2){
        ans+=a[1];
    }else{
        ans+=a[1]+a[0]+a[2];
    }
    cout<<ans;
}
/**************************************************************
	Problem: 1236
	User: lijinkai
	Language: C++
	Result: Wrong Answer
****************************************************************/