#include using namespace std; int main() { int n; cin >> n; vector A( n ); for( int i = 0; i < n; i++ ) cin >> A[i]; sort( A.begin(), A.end(), greater() ); long long ans = 0; int k = 0; int i = 0; while( i < n ) { int num = 1 << k; while( num && i < n ) { ans += A[i] * k; num--; i++; } k++; } cout << ans << endl; }