#include using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::cerr; using std::endl; using std::cin; template std::vector make_v(size_t a){return std::vector(a);} template auto make_v(size_t a, Ts... ts){ return std::vector(ts...))>(a, make_v(ts...)); } int main() { int n; scanf("%d", &n); std::vector a(n); for(auto& v: a) scanf("%d", &v); sort(begin(a), end(a), std::greater<>()); i64 ans = 0; int cur = 0; for(int k = 0; k < 30; k++) for(int i = 0; i < (1 << k) and cur < n; i++, cur++) ans += a[cur] * k; printf("%lld\n", ans); return 0; }