Boy G was on a voyage with his father to celebrate his 13th birthday. However, during the voyage, unfortunately the ship was hit by a storm and the ship capsized. When he woke up, it was an uninhabited island. Partly due to the influence of the adventurer's father, he decided to live a survival life on an uninhabited island without being afraid of this situation. I managed to survive by defeating animals, grilling meat, collecting nuts to eat, and camping under large trees. However, it seems that the island has been strange recently. All the animals behave strangely, which may be a sign of something wrong. I have to escape from this island as soon as possible.

But how do you get away from the island? I can see another island over the sea, but I can't find a way to get there. At a loss, as he was walking along the coast, he suddenly found N boats. When I looked it up, they all seemed to work. Alright, let's use this boat to escape to the other island. However, a similar survival life may begin on the next island. Let's carry all the boats as a spare so that we will not be in trouble at that time. I have to do something early before something happens on this island.

Constraints

The input satisfies the following conditions.

* 1 ≤ N ≤ 1000
* 1 ≤ Ti ≤ 10000

Input

The integer N is given on the first line.
The second line is given N integers Ti, separated by blanks.

Output

Output the shortest time (minutes) required to finish carrying all the boats in one line.

Examples

Input

4
1 2 3 4


Output

11


Input

5
3 3 3 3 3


Output

21
#include <bits/stdc++.h>
 
using namespace std;
 
typedef pair<int,int> pii;
typedef long long ll;
 
int N;
ll T[1001];
int main(){
 
  cin>>N;
  for(int i=0;i<N;i++)cin>>T[i];
  if(N==1)cout<<T[0]<<endl;
  else{
    sort(T,T+N);
    ll res=0;
    while(1){
      if(N==3){
        res+=T[0]+T[1]+T[2];
        break;
      }
      else if(N==2){
        res+=T[1];
        break;
      }
      else{
        if(T[1]*2-T[0]<T[N-2])res+=T[0]+2*T[1]+T[N-1];
        else res+=T[N-1]+2*T[0]+T[N-2];
        N-=2;
      }
    }
    cout<<res<<endl;
  }
   
  return 0;
}
