#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.rbegin(), a.rend()); int k = 0, cur = 0; int ans = 0; for (int i = 0; i < n; i++) { ans += k * a[i]; cur++; if (cur == (1 << k)) { cur = 0; k++; } } cout << ans << endl; }