func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   template <class T>   T gcd(T a, T b) {     return !b ? a : gcd(b, a % b);   }   template <class T>   inline void umin(T &x, T y) {     x = x < y ? x : y;   }   template <class T>   inline void umax(T &x, T y) {     x = x > y ? x : y;   }   inline unsigned int R() {     static unsigned int seed = 416;     return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;   }   const int N = 505000;   int n;   map<int, int> Map;   pair<int, int> s[N];   int len;   long long res;   priority_queue<long long, vector<long long>, greater<long long> > heap;   int main() {     read(n);     for (register int i = (1); i <= (n); i++) {       int x;       read(x);       Map[x]++;       res += x;     }     for (auto i : Map) s[++len] = pair<int, int>(i.first, i.second);     int sum = 0;     for (register int j = (len); j >= (1); j--) {       int c = min(s[j].second, sum - 2 * ((int)heap.size()));       vector<long long> cur(c, s[j].first);       c = s[j].second - c;       for (int i = 1; i <= c; i += 2)         if (!heap.empty()) {           long long t = heap.top();           heap.pop();           if (t < s[j].first) {             cur.push_back(s[j].first);             if (i < c) cur.push_back(s[j].first);           } else {             cur.push_back(t);             if (t < 2 * s[j].first && i < c) cur.push_back(2 * s[j].first - t);           }         }       for (auto i : cur) heap.push(i);       sum += s[j].second;     }     while (!heap.empty()) res -= heap.top(), heap.pop();     cout << res;     return 0;   }   