func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long maxn = 500000 + 5;   long long a[maxn], tmp[maxn];   multiset<long long> save;   vector<pair<long long, long long> > b;   int main() {     long long total = 0;     long long n;     scanf( %lld , &n);     for (long long i = 0; i < n; i++) scanf( %lld , a + i), total += a[i];     sort(a, a + n, greater<long long>());     for (long long i = 0, cnt = 1; i < n; i++, cnt++)       if (i == n - 1 || a[i] != a[i + 1])         b.push_back(make_pair(a[i], cnt)), cnt = 0;     for (long long i = 0, sizesum = 0; i < (long long)b.size(); i++) {       long long num = b[i].first, nowsize = b[i].second;       long long save_size = min(sizesum, sizesum + nowsize >> 1);       long long cnt = max(0LL, save_size - nowsize);       for (long long j = save_size - 1; j >= cnt; j--)         if (j < (long long)save.size())           tmp[j] = *save.begin(), save.erase(save.begin());         else           tmp[j] = 0;       for (long long j = cnt, k = sizesum - cnt; j < k && j < save_size; j++)         if (tmp[j] < num)           tmp[j] = num;         else if (--k < save_size)           tmp[k] = max(0LL, 2LL * num - tmp[j]);       save.insert(tmp + cnt, tmp + save_size);       sizesum += nowsize;     }     for (auto it = save.begin(); it != save.end(); it++) total -= (*it);     printf( %lld n , total);   }   