#include using namespace std; void no_1416(void) { int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; long long cost = 0; sort(a.begin(), a.end()); reverse(a.begin(), a.end()); int ptr = 0; bool is_end = false; for (int i = 0; pow(2, i) <= n; i++) { for (int j = 0; j < pow(2, i);j++){ cost += (a[ptr]*i); ptr++; if(ptr==n){ is_end = true; break; } } if(is_end){ cout << cost << endl; return; } } } int main(void) { no_1416(); return 0; }