#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 5;
priority_queue<long long, vector<long long>, greater<long long> > q;
long long n, b[N], a[N], cnt[N], sum, tot, ans;
inline bool cmp(long long i, long long j) { return i > j; }
long long tmp[N], tn;
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
    ans += b[i];
  }
  sort(b + 1, b + 1 + n, cmp);
  for (long long i = 1; i <= n; i++) {
    if (i == 1 || b[i] != b[i - 1])
      a[++tot] = b[i], cnt[tot]++;
    else
      cnt[tot]++;
  }
  for (long long i = 1; i <= tot; i++) {
    long long free = sum - 2 * q.size();
    free = min(free, cnt[i]);
    for (long long j = 1; j <= free; j++) tmp[++tn] = a[i];
    long long change = min(sum, cnt[i]) - free;
    for (long long j = 1; j <= change; j += 2) {
      long long x = q.top();
      q.pop();
      if (a[i] > x) {
        tmp[++tn] = a[i];
        if (j < change) tmp[++tn] = a[i];
      } else {
        tmp[++tn] = x;
        if (j < change && 2 * a[i] - x > 0) tmp[++tn] = 2 * a[i] - x;
      }
    }
    while (tn) {
      q.push(tmp[tn]);
      tn--;
    }
    sum += cnt[i];
  }
  while (!q.empty()) ans -= q.top(), q.pop();
  printf("%lld\n", ans);
  return 0;
}
