#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int n, m, sum;
int a[maxn], cnt[maxn], st[maxn];
long long ans;
priority_queue<int, vector<int>, greater<int> > q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    ans += a[i];
  }
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) {
    if (a[i] != a[i - 1]) a[++m] = a[i];
    ++cnt[m];
  }
  for (int i = 1; i <= m; ++i) {
    int top = 0, mx = min(sum - 2 * (int)q.size(), cnt[i]);
    for (int j = 1; j <= mx; ++j) st[++top] = a[i];
    mx = min(cnt[i], sum) - mx;
    for (int j = 1; j <= mx; j += 2) {
      int t = q.top();
      q.pop();
      if (t < a[i]) {
        st[++top] = a[i];
        if (j < mx) st[++top] = a[i];
      } else {
        st[++top] = t;
        if (2 * a[i] > t && j < mx) st[++top] = 2 * a[i] - t;
      }
    }
    for (int j = 1; j <= top; ++j) q.push(st[j]);
    sum += cnt[i];
  }
  while (!q.empty()) {
    ans -= q.top();
    q.pop();
  }
  printf("%lld\n", ans);
  return 0;
}
