#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1, c = getchar();
  while (c < 48) c == '-' && (f = -1), c = getchar();
  while (c > 47) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
std::map<int, int> m;
priority_queue<int, vector<int>, greater<int> > q, qt;
int n, x, k, tmp;
long long ans;
int main(int argc, char const *argv[]) {
  n = read();
  for (int i = 1, x; i <= n; i++) ans += (x = read()), ++m[x];
  for (auto i = m.rbegin(); i != m.rend(); tmp += k, i++) {
    x = i->first, k = i->second;
    while (tmp && k) tmp--, k--, qt.push(x);
    for (int t = x; k >= 2 && (!q.empty() && q.top() < 2 * t); k -= 2, q.pop())
      if (q.top() < t)
        qt.push(t), qt.push(t);
      else
        qt.push(2 * t - q.top()), qt.push(q.top());
    if (k && !q.empty() && q.top() < x) q.pop(), q.push(x);
    while (!qt.empty()) q.push(qt.top()), qt.pop();
  }
  while (!q.empty()) ans -= q.top(), q.pop();
  printf("%lld\n", ans);
  return 0;
}
