#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> p;
int n, answer;
int highest, lowest;
int qcnt[1001];
vector<int> qual;
void init() {
int input;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> input;
if (qcnt[input] == 0) qual.push_back(input);
qcnt[input]++;
}
sort(qual.begin(), qual.end());
lowest = 0;
highest = qual.size() - 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(NULL);
init();
while (1) {
if (lowest > highest) break;
int low_cnt = qcnt[qual[lowest]];
int high_cnt = qcnt[qual[highest]];
if (lowest == highest) {
answer += qual[highest] * high_cnt;
qcnt[highest] = 0;
lowest++;
continue;
}
if (low_cnt < high_cnt) {
answer += qual[highest] * low_cnt * 2;
qcnt[qual[highest]] -= low_cnt;
qcnt[qual[lowest]] = 0;
lowest++;
}
else {
answer += qual[highest] * high_cnt * 2;
qcnt[qual[lowest]] -= high_cnt;
qcnt[qual[highest]] = 0;
highest--;
}
}
printf("%d\n", answer);
return 0;
}