#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long x = 0, f = 1;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
int n;
map<int, int> mp;
long long ans;
int main() {
  n = read();
  for (register int i = (0); i < int(n); ++i) {
    int x = read();
    mp[x]++;
    ans += x;
  }
  multiset<int> s;
  for (auto it = mp.end(); it != mp.begin();) {
    it--;
    multiset<int> now;
    int x = it->first, cnt = it->second;
    while (cnt && s.size() && *s.begin() == 0)
      now.insert(x), s.erase(s.begin()), cnt--;
    while (cnt > 1 && s.size()) {
      int y = *s.begin();
      if (y >= 2 * x) break;
      s.erase(s.begin());
      cnt -= 2;
      if (y < x)
        now.insert(x), now.insert(x);
      else
        now.insert(2 * x - y), now.insert(y);
    }
    if (cnt && s.size() && *s.begin() < x) {
      s.erase(s.begin());
      now.insert(x);
      now.insert(0);
      cnt--;
    }
    while (cnt) now.insert(0), cnt--;
    while (now.size()) s.insert(*now.begin()), now.erase(now.begin());
  }
  for (auto i : s) ans -= i;
  writeln(ans);
  return 0;
}
