#define _USE_MATH_DEFINES #include // cout, endl, cin #include // printf, scanf #include // string, to_string, stoi #include // min, max, swap, lower_bound, upper_bound // & stable_sort, sort, reverse #include //sin(rad),cos,tan, abs, pow, sqrt, cbrt, exp, log, log10, log2 #include // pair, make_pair #include // map #include // set #include // vector #include // queue, priority_queue #include // stack #include // list #include // deque #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector vi; typedef vector vs; typedef pair pii; typedef pair psi; typedef pair pis; typedef set si; typedef map msi; typedef map msb; typedef priority_queue pqi; typedef stack sti; typedef queue qi; #define infi 1147483647 #define infl 9223372036854775806 #define MOD 1000000007 #define EPS 0.0000000001 #define rep(i,n) for(int i=0;i<(int)n;i++) #define repa(i,n) for(int i=1;i<=(int)n;i++) #define irep(i,n) for(int i=(int)n-1;i>=0;i--) using std::cin; using std::string; template T in() { T temp; cin >> temp; return temp; } template <> int in() { int temp; (void)scanf("%d", &temp); return temp; } template <> double in() { double temp; (void)scanf("%lf", &temp); return temp; } template <> char in() { char temp; (void)scanf("%c", &temp); return temp; } template constexpr auto equals(T1 a, T2 b) { return (fabs(a - b) < EPS); } //その他便利なメソッド void clear(std::queue& q) { std::queue empty; std::swap(q, empty); } bool compare_by_b(pair a, pair b) { if (a.second != b.second) { return a.second < b.second; } else { return a.first > b.first; } } //--------------------------------------------------- vi a; int n; int main() { //int a = in(); string b = in(); char c = in(); //double d = in(); //(void)scanf("%d",&); //(void)scanf("%d%d",& ,&); cin >> n; int x; rep(i, n) { (void)scanf("%d", &x); a.push_back(x); } sort(a.begin(), a.end(), greater()); int k = 0; ll sum = 0; while (1) { for (int i = (int)pow(2, k); i < min((int)pow(2, k + 1), n + 1); i++) { sum += (ll)a[i - 1] * k; } k++; if ((int)pow(2, k) >= n) break; } std::cout << sum << endl; return 0; }