#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int a[1000];
int dp[1001][4][2];

int main() {
  int n;
  while(cin >> n) {
    REP(i,n) {
      cin >> a[i];
    }
    sort(a,a+n);
    if (n == 1) {
      cout << a[0] << endl;
      continue;
    } 
    
    REP(i,1001)REP(j,4)REP(k,2)dp[i][j][k]=INF;
    dp[2][0][0] = 0;
    for (int i=2; i<=n; ++i) {
      REP(_,10) {
        chmin(dp[i][0][0], dp[i][3][1]+a[1]);
        chmin(dp[i][3][1], dp[i][0][0]+a[1]);
        for (int S=3; S>=0; --S) {
          if (i+1<n) {
            chmin(dp[i+2][S][1], dp[i][S][0] + a[i+1]);
          }
          REP(j,2) {
            if (S>>j&1) {
              chmin(dp[i][S^(1<<j)][0], dp[i][S][1]+a[j]);
            } else {
              if (i<n) {
                chmin(dp[i+1][S|1<<j][1], dp[i][S][0]+a[i]);
              }
            }
          }
        }
      }
    }
    cout << dp[n][3][1] << endl;
  }
}
