#include <bits/stdc++.h>
using namespace std;
const int N = int(5e5) + 5;
int a[N], b[N], tot, c[N], d[N];
int n;
long long g[N], ans, sum;
multiset<int> X;
bool cmd(int x, int y) { return x > y; }
void Init() {
  scanf("%d", &n);
  sum = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum += a[i];
  sort(a + 1, a + 1 + n, cmd);
  for (int i = 1; i <= n; i++) {
    if (a[i] != a[i - 1]) a[++tot] = a[i];
    b[tot]++;
  }
}
void Work() {
  int M = 0;
  for (int i = 1; i <= tot; i++) {
    int x = a[i], y = b[i], ms = min(M, (M + y) >> 1), beg = max(0, ms - y);
    for (int i = ms - 1; i >= beg; i--)
      if (i < X.size())
        c[i] = *X.begin(), X.erase(X.begin());
      else
        c[i] = 0;
    for (int i = beg, j = M - i; i < j && i < ms; i++)
      if (c[i] < x)
        c[i] = x;
      else if (--j < ms)
        c[j] = max(0, x + x - c[i]);
    X.insert(c + beg, c + ms);
    M += y;
  }
  while (X.size()) sum -= *X.begin(), X.erase(X.begin());
  printf("%lld\n", sum);
}
int main() {
  Init();
  Work();
  return 0;
}
