#include <bits/stdc++.h>
using namespace std;
map<int, int, greater<int>> mp;
priority_queue<int, vector<int>, greater<int>> q, tmp;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
int main() {
  int n = read();
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int x = read();
    ans += x, ++mp[x];
  }
  int ll = 0;
  for (auto x : mp) {
    int val = x.first, tot = x.second;
    while (ll > 0 && tot > 0) tmp.push(val), --ll, --tot;
    while (tot >= 2 && !q.empty() && val * 2 - q.top() > 0)
      if (q.top() < val)
        tmp.push(val), tmp.push(val), tot -= 2, q.pop();
      else
        tmp.push(val * 2 - q.top()), tmp.push(q.top()), tot -= 2, q.pop();
    if (tot && !q.empty() && q.top() < val) q.pop(), q.push(val);
    while (!tmp.empty()) q.push(tmp.top()), tmp.pop();
    ll += tot;
  }
  while (!q.empty()) ans -= q.top(), q.pop();
  printf("%lld\n", ans);
  return 0;
}
