#include <bits/stdc++.h>
using namespace std;
int n, x;
long long ans;
map<int, int> mp;
multiset<int> s;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    mp[x]++;
    ans += x;
  }
  map<int, int>::iterator it;
  for (it = mp.end(); it != mp.begin();) {
    multiset<int> now;
    it--;
    int x = it->first, cnt = it->second;
    for (; cnt && s.size() && !*s.begin();)
      now.insert(x), s.erase(s.begin()), cnt--;
    for (; 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--;
    for (; cnt; cnt--) now.insert(0);
    for (; now.size();) s.insert(*now.begin()), now.erase(now.begin());
  }
  set<int>::iterator it2;
  for (it2 = s.begin(); it2 != s.end(); it2++) ans -= *it2;
  printf("%lld\n", ans);
}
