#include <bits/stdc++.h>
using namespace std;
const int M = 5e5 + 5;
int n, c[M];
long long ans = 0;
priority_queue<int, vector<int>, greater<int> > que;
int new_c[M], new_cnt[M], cnt = 0;
int t[M], tn = 0;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    ans += c[i];
  }
  sort(c, c + n);
  reverse(c, c + n);
  for (int i = 0; i < n; ++i) {
    if (i == 0 || c[i] != c[i - 1]) {
      new_c[cnt] = c[i];
      new_cnt[cnt] = 1;
      ++cnt;
    } else
      new_cnt[cnt - 1]++;
  }
  int greater_than_cur = 0;
  for (int i = 0; i < cnt; ++i) {
    int max_free =
        max(min(greater_than_cur - (int)que.size() * 2, new_cnt[i]), 0);
    tn = 0;
    for (int j = 0; j < max_free; ++j) t[tn++] = new_c[i];
    for (int j = 0; j < new_cnt[i] - max_free; j += 2) {
      if (que.empty()) break;
      int value = que.top();
      que.pop();
      if (new_c[i] > value) {
        t[tn++] = new_c[i];
        if (j != new_cnt[i] - max_free - 1) t[tn++] = new_c[i];
      } else {
        t[tn++] = value;
        if (j != new_cnt[i] - max_free - 1 && new_c[i] * 2 >= value)
          t[tn++] = 2 * new_c[i] - value;
      }
    }
    for (int j = 0; j < tn; ++j) que.push(t[j]);
    greater_than_cur += new_cnt[i];
  }
  int val, op;
  while (!que.empty()) {
    ans -= que.top();
    que.pop();
  }
  cout << ans;
  return 0;
}
