#include #include #include using namespace std; int main(){ int n; cin >> n; vector a(n); for(auto &p: a) cin >> p; sort(a.begin(), a.end(), greater()); int ans = 0; int floor = 0; int shopsum = 1; int power2 = 1; for(int i = 0; i < n; i++){ if(i == shopsum){ floor++; power2 *= 2; shopsum += power2; } ans += a[i]*floor; } cout << ans << endl; return 0; }