#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
int n;
int a[N];
priority_queue<int, vector<int>, greater<int> > q;
vector<int> now;
int pre;
int p[N], m[N];
int cnt = 0;
long long sum = 0;
bool mycmp(int x, int y) { return x > y; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum += 1ll * a[i];
  sort(a + 1, a + n + 1, mycmp);
  for (int i = 1; i <= n; i++)
    if (a[i] != a[i - 1])
      p[++cnt] = a[i], m[cnt] = 1;
    else
      m[cnt]++;
  for (int i = 1; i <= cnt; i++) {
    int Size = q.size();
    int fre = max(0, min(pre - 2 * Size, m[i]));
    for (int j = 1; j <= fre; j++) now.push_back(p[i]);
    int by = m[i] - fre;
    for (int j = 1; j <= by; j += 2) {
      if (q.empty()) break;
      int pp = q.top();
      q.pop();
      if (p[i] > pp) {
        now.push_back(p[i]);
        if (j != by) now.push_back(p[i]);
        continue;
      }
      now.push_back(pp);
      if (2 * p[i] >= pp && j != by) now.push_back(2 * p[i] - pp);
    }
    for (int j = 0; j < now.size(); j++) q.push(now[j]);
    now.clear();
    pre += m[i];
  }
  long long Fr = 0;
  while (!q.empty()) Fr += q.top(), q.pop();
  printf("%lld", sum - Fr);
  return 0;
}
