#include #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long ll; using namespace std; ll llpow(ll a, int b) { ll ans = 1; while (b) { if (b % 2 == 1) ans = (ans * a); b /= 2; a = (a * a); } return ans; } int main() { int N; cin >> N; vector A(N); rep(i, N) cin >> A[i]; sort(A.rbegin(), A.rend()); vector f; rep(i, N) { for (int j = 0; j < llpow(2, i); ++j) { f.push_back(i); if ((int)f.size() >= N) break; } } ll ans = 0; rep(i, N) ans += A[i] * f[i]; cout << ans << endl; return 0; }