#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  scanf("%d", &n);
  priority_queue<int, vector<int>, greater<int> > q, q2;
  long long r = 0;
  map<int, int> m;
  for (int i = 0, x; i < n; ++i) {
    scanf("%d", &x);
    r += x;
    ++m[x];
  }
  int now = 0;
  map<int, int>::reverse_iterator it;
  for (it = m.rbegin(); it != m.rend(); ++it) {
    int a = it->first, y = it->second;
    while (y && now) q2.push(a), --y, --now;
    for (; y >= 2 && (!q.empty() && q.top() < 2 * a); y -= 2) {
      if (q.top() < a)
        q2.push(a), q2.push(a);
      else
        q2.push(a + a - q.top()), q2.push(q.top());
      q.pop();
    }
    if (y && !q.empty() && q.top() < a) q.pop(), q2.push(a);
    while (!q2.empty()) q.push(q2.top()), q2.pop();
    now += y;
  }
  for (; !q.empty(); q.pop()) r -= q.top();
  cout << r << endl;
}
