1 #include<cstdio>
2 #include<iostream>
3 #include<cmath>
4 #include<algorithm>
5
6 using namespace std;
7
8 int speed[1001];
9
10 int main()
11 {
12 int t, n, tmp;
13 scanf("%d", &n);
14 for(int i=0; i<n; i++)
15 {
16 scanf("%d", &speed[i]);
17 }
18 for(int i=0; i<n; i++)
19 {
20 for(int j=i; j<n; j++)
21 {
22 if(speed[i] > speed[j])
23 {
24 tmp = speed[i];
25 speed[i] = speed[j];
26 speed[j] = tmp;
27 }
28 }
29 }
30 // greedy
31 int start = n, ans = 0;
32 while(start)
33 {
34 // start = 1,2,3时直接处理
35 if(start == 1)
36 {
37 ans += speed[0];
38 break;
39 }
40 else if(start == 2)
41 {
42 ans += speed[1];
43 break;
44 }
45 else if(start == 3)
46 { // 0,2过河,0回程,0,1过河
47 ans += speed[2]+speed[0]+speed[1];
48 break;
49 }
50 // start>3根据策略选择
51 else{
52 ans += min(speed[1]+speed[0]+speed[start-1]+speed[1], speed[start-1]+2*speed[0]+speed[start-2]);
53 start -= 2;
54 }
55 }
56 printf("%d\n", ans);
57
58 return 0;
59 }