#include <cstdio>
const int N = 100010;
int a[N], t[200000], n, m, i, j, k, o, p, q;
int time;
bool ok1, ok2;
int main() {
scanf("%d", &n);
if (n == 1) {
scanf("%d", &a[1]);
printf("%d", a[1]);
return 0;
} else if (n <= 3) {
for (i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
for (j = 1; j <= i; ++j) {
m = a[j];
for (k = j; k <= i; ++k) {
if (m > a[k]) {
o = k;
m = a[k];
}
}
a[o] = a[j];
a[j] = m;
}
}
printf("%d", a[2]);
return 0;
}
for (i = 1; i <= n; ++i) {
scanf("%d", &k);
++t[k];
}
m = n / 2 + 1;
i = 0;
for (j = 1; i <= m; ++j) {
if (a[2] * 4 <= a[1] + a[i] && i > 2) {
ok1 = true;
break;
}
while (t[j]) {
t[j]--;
a[++i] = j;
}
}
if (ok1) {
time = 2 * a[2] * (n - 2 * i + 3) + a[1] * (i - 3);
for (j = 2; j < i; ++j) time += a[j];
} else if (ok2) {
time = 2 * a[2] + a[1] * (i - 4);
for (j = 2; j < i - 1; ++j) time += a[j];
} else {
for (j = 2; j <= m; ++j) time += a[j];
time += (m - 2) * a[1];
}
printf("%d", time);
}