#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef     unsigned long long int ull;
typedef     long long int    ll;
typedef     long double      ld;
typedef     pair<ll,ll>      pll;
#define     FOR(i,a,b)       for(ll i=a;i<b;i++)
#define     FORE(i,a,b)      for(int i=a;i<=b;i++)
#define     FORD(i,b,a)      for(int i=b;i>a;i--)
#define     FORDE(i,b,a)     for(ll i=b;i>=a;i--)
#define     debug(x)         cout<< '>'<<#x<<" : "<<x<<"\n";
#define     debug2(x,y)      cout<< '>'<<#x<<" : "<<x<<"\n"; cout<< '>'<<#y<<" : "<<y<<"\n";
#define     debug3(x,y,z)    cout<< '>'<<#x<<" : "<<x<<"\n"; cout<< '>'<<#y<<" : "<<y<<"\n";cout<< '>'<<#z<<" : "<<z<<"\n";
#define     umap             unordered_map
#define     uset             unordered_set
#define     lb               lower_bound
#define     ub               upper_bound
#define     mp               make_pair
#define     in               insert
#define     s                second
#define     f                first
#define     nn               cout<<"\n"
#define     pb               push_back
#define     testcase         int t;cin>>t;while(t--)
#define     gcd(a,b)         __gcd(a,b)
#define     maxv             INT_MAX
#define     minv             INT_MIN
#define     MOD              1000000007
#define     FastIO           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define     here             cout<<"I'm here\n";
#define     flush            fflush(stdout);
#define endl '\n'
#define ordered_set_single tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

typedef tree<
pair<ll, ll>,
null_type,
less<pair<ll,ll>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set_pair;

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

ll nCrModPFermat(ll n, ll r, ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

ll nCrModpDP(ll n, ll r)
{

    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (ll i = 1; i <= n; i++)
    {

        for (ll j = min(i, r); j > 0; j--)

            C[j] = (C[j] + C[j-1])%MOD;
    }
    return C[r];
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll ntopowermandMod(ll n,ll m,ll mod_v)
{
    if(m==0)
    {
        return 1;

    }
    if(m==1)
    {
        return n;
    }
    else
    {
        ll val=ntopowermandMod(n,m/2,mod_v);
        val=val%mod_v;
        val=val*val;
        val=val%mod_v;
        if(m%2==1)
        {
        val=val*n;
        val=val%mod_v;
        }
        return val;

    }

}
ll ntopowerm(ll n,ll m)
{
    if(m==0)
    {
        return 1;

    }
    if(m==1)
    {
        return n;
    }
    else
    {
        ll val=ntopowerm(n,m/2);
        val=val*val;
        if(m%2==1)
        {
        val=val*n;
        }
        return val;

    }

}
vector<int> pi;

void prefix_function(string s) {
    int n = (int)s.length();
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
}
template<class T> void dispvector(vector<T> v){for(int i=0;i<v.size();i++) cout<<v[i]<<" "; nn;}
template<class T> void disparray(T *v, int n){for(int i=0;i<n;i++) cout<<v[i]<<" "; nn;}
template<class T> int sizeofarr(T *v){return sizeof(v)/sizeof(T);}

signed main(int argc, char** argv)
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    FastIO;
    long t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>inp(n);
        ll sum=0;
        FOR(i,0,n) {cin>>inp[i]; sum+=inp[i];}
        sort(inp.begin(),inp.end());
        reverse(inp.begin(),inp.end());
        n=log2(n);
        n=n/2;

        while(n>0)
        {
        FOR(i,0,n)
        {
            sum+=inp[i];
        }
        n=n/2;
        }
        cout<<sum<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef     unsigned long long int ull;
typedef     long long int    ll;
typedef     long double      ld;
typedef     pair<ll,ll>      pll;
#define     FOR(i,a,b)       for(ll i=a;i<b;i++)
#define     FORE(i,a,b)      for(int i=a;i<=b;i++)
#define     FORD(i,b,a)      for(int i=b;i>a;i--)
#define     FORDE(i,b,a)     for(ll i=b;i>=a;i--)
#define     debug(x)         cout<< '>'<<#x<<" : "<<x<<"\n";
#define     debug2(x,y)      cout<< '>'<<#x<<" : "<<x<<"\n"; cout<< '>'<<#y<<" : "<<y<<"\n";
#define     debug3(x,y,z)    cout<< '>'<<#x<<" : "<<x<<"\n"; cout<< '>'<<#y<<" : "<<y<<"\n";cout<< '>'<<#z<<" : "<<z<<"\n";
#define     umap             unordered_map
#define     uset             unordered_set
#define     lb               lower_bound
#define     ub               upper_bound
#define     mp               make_pair
#define     in               insert
#define     s                second
#define     f                first
#define     nn               cout<<"\n"
#define     pb               push_back
#define     testcase         int t;cin>>t;while(t--)
#define     gcd(a,b)         __gcd(a,b)
#define     maxv             INT_MAX
#define     minv             INT_MIN
#define     MOD              1000000007
#define     FastIO           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define     here             cout<<"I'm here\n";
#define     flush            fflush(stdout);
#define endl '\n'
#define ordered_set_single tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

typedef tree<
pair<ll, ll>,
null_type,
less<pair<ll,ll>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set_pair;

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

ll nCrModPFermat(ll n, ll r, ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

ll nCrModpDP(ll n, ll r)
{

    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (ll i = 1; i <= n; i++)
    {

        for (ll j = min(i, r); j > 0; j--)

            C[j] = (C[j] + C[j-1])%MOD;
    }
    return C[r];
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll ntopowermandMod(ll n,ll m,ll mod_v)
{
    if(m==0)
    {
        return 1;

    }
    if(m==1)
    {
        return n;
    }
    else
    {
        ll val=ntopowermandMod(n,m/2,mod_v);
        val=val%mod_v;
        val=val*val;
        val=val%mod_v;
        if(m%2==1)
        {
        val=val*n;
        val=val%mod_v;
        }
        return val;

    }

}
ll ntopowerm(ll n,ll m)
{
    if(m==0)
    {
        return 1;

    }
    if(m==1)
    {
        return n;
    }
    else
    {
        ll val=ntopowerm(n,m/2);
        val=val*val;
        if(m%2==1)
        {
        val=val*n;
        }
        return val;

    }

}
vector<int> pi;

void prefix_function(string s) {
    int n = (int)s.length();
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
}
template<class T> void dispvector(vector<T> v){for(int i=0;i<v.size();i++) cout<<v[i]<<" "; nn;}
template<class T> void disparray(T *v, int n){for(int i=0;i<n;i++) cout<<v[i]<<" "; nn;}
template<class T> int sizeofarr(T *v){return sizeof(v)/sizeof(T);}

signed main(int argc, char** argv)
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    FastIO;
    long t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>inp(n);
        ll sum=0;
        FOR(i,0,n) {cin>>inp[i]; sum+=inp[i];}
        sort(inp.begin(),inp.end());
        reverse(inp.begin(),inp.end());
        n=log2(n);
        while(n>0)
        {
        FOR(i,0,n)
        {
            sum+=inp[i];
        }
        n=n/2;
        }
        cout<<sum<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef     unsigned long long int ull;
typedef     long long int    ll;
typedef     long double      ld;
typedef     pair<ll,ll>      pll;
#define     FOR(i,a,b)       for(ll i=a;i<b;i++)
#define     FORE(i,a,b)      for(int i=a;i<=b;i++)
#define     FORD(i,b,a)      for(int i=b;i>a;i--)
#define     FORDE(i,b,a)     for(ll i=b;i>=a;i--)
#define     debug(x)         cout<< '>'<<#x<<" : "<<x<<"\n";
#define     debug2(x,y)      cout<< '>'<<#x<<" : "<<x<<"\n"; cout<< '>'<<#y<<" : "<<y<<"\n";
#define     debug3(x,y,z)    cout<< '>'<<#x<<" : "<<x<<"\n"; cout<< '>'<<#y<<" : "<<y<<"\n";cout<< '>'<<#z<<" : "<<z<<"\n";
#define     umap             unordered_map
#define     uset             unordered_set
#define     lb               lower_bound
#define     ub               upper_bound
#define     mp               make_pair
#define     in               insert
#define     s                second
#define     f                first
#define     nn               cout<<"\n"
#define     pb               push_back
#define     testcase         int t;cin>>t;while(t--)
#define     gcd(a,b)         __gcd(a,b)
#define     maxv             INT_MAX
#define     minv             INT_MIN
#define     MOD              1000000007
#define     FastIO           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define     here             cout<<"I'm here\n";
#define     flush            fflush(stdout);
#define endl '\n'
#define ordered_set_single tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

typedef tree<
pair<ll, ll>,
null_type,
less<pair<ll,ll>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set_pair;

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

ll nCrModPFermat(ll n, ll r, ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

ll nCrModpDP(ll n, ll r)
{

    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (ll i = 1; i <= n; i++)
    {

        for (ll j = min(i, r); j > 0; j--)

            C[j] = (C[j] + C[j-1])%MOD;
    }
    return C[r];
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll ntopowermandMod(ll n,ll m,ll mod_v)
{
    if(m==0)
    {
        return 1;

    }
    if(m==1)
    {
        return n;
    }
    else
    {
        ll val=ntopowermandMod(n,m/2,mod_v);
        val=val%mod_v;
        val=val*val;
        val=val%mod_v;
        if(m%2==1)
        {
        val=val*n;
        val=val%mod_v;
        }
        return val;

    }

}
ll ntopowerm(ll n,ll m)
{
    if(m==0)
    {
        return 1;

    }
    if(m==1)
    {
        return n;
    }
    else
    {
        ll val=ntopowerm(n,m/2);
        val=val*val;
        if(m%2==1)
        {
        val=val*n;
        }
        return val;

    }

}
vector<int> pi;

void prefix_function(string s) {
    int n = (int)s.length();
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
}
template<class T> void dispvector(vector<T> v){for(int i=0;i<v.size();i++) cout<<v[i]<<" "; nn;}
template<class T> void disparray(T *v, int n){for(int i=0;i<n;i++) cout<<v[i]<<" "; nn;}
template<class T> int sizeofarr(T *v){return sizeof(v)/sizeof(T);}

signed main(int argc, char** argv)
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    FastIO;
    long t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>inp(n);
        ll sum=0;
        FOR(i,0,n) {cin>>inp[i]; sum+=inp[i];}
        n=log2(n);
        n=n/2;
        sort(inp.begin(),inp.end());
        reverse(inp.begin(),inp.end());
        FOR(i,0,n)
        {
            sum+=inp[i];
        }
        cout<<sum<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef     unsigned long long int ull;
typedef     long long int    ll;
typedef     long double      ld;
typedef     pair<ll,ll>      pll;
#define     FOR(i,a,b)       for(ll i=a;i<b;i++)
#define     FORE(i,a,b)      for(int i=a;i<=b;i++)
#define     FORD(i,b,a)      for(int i=b;i>a;i--)
#define     FORDE(i,b,a)     for(ll i=b;i>=a;i--)
#define     debug(x)         cout<< '>'<<#x<<" : "<<x<<"\n";
#define     debug2(x,y)      cout<< '>'<<#x<<" : "<<x<<"\n"; cout<< '>'<<#y<<" : "<<y<<"\n";
#define     debug3(x,y,z)    cout<< '>'<<#x<<" : "<<x<<"\n"; cout<< '>'<<#y<<" : "<<y<<"\n";cout<< '>'<<#z<<" : "<<z<<"\n";
#define     umap             unordered_map
#define     uset             unordered_set
#define     lb               lower_bound
#define     ub               upper_bound
#define     mp               make_pair
#define     in               insert
#define     s                second
#define     f                first
#define     nn               cout<<"\n"
#define     pb               push_back
#define     testcase         int t;cin>>t;while(t--)
#define     gcd(a,b)         __gcd(a,b)
#define     maxv             INT_MAX
#define     minv             INT_MIN
#define     MOD              1000000007
#define     FastIO           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define     here             cout<<"I'm here\n";
#define     flush            fflush(stdout);
#define endl '\n'
#define ordered_set_single tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

typedef tree<
pair<ll, ll>,
null_type,
less<pair<ll,ll>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set_pair;

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

ll nCrModPFermat(ll n, ll r, ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

ll nCrModpDP(ll n, ll r)
{

    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (ll i = 1; i <= n; i++)
    {

        for (ll j = min(i, r); j > 0; j--)

            C[j] = (C[j] + C[j-1])%MOD;
    }
    return C[r];
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll ntopowermandMod(ll n,ll m,ll mod_v)
{
    if(m==0)
    {
        return 1;

    }
    if(m==1)
    {
        return n;
    }
    else
    {
        ll val=ntopowermandMod(n,m/2,mod_v);
        val=val%mod_v;
        val=val*val;
        val=val%mod_v;
        if(m%2==1)
        {
        val=val*n;
        val=val%mod_v;
        }
        return val;

    }

}
ll ntopowerm(ll n,ll m)
{
    if(m==0)
    {
        return 1;

    }
    if(m==1)
    {
        return n;
    }
    else
    {
        ll val=ntopowerm(n,m/2);
        val=val*val;
        if(m%2==1)
        {
        val=val*n;
        }
        return val;

    }

}
vector<int> pi;

void prefix_function(string s) {
    int n = (int)s.length();
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
}
template<class T> void dispvector(vector<T> v){for(int i=0;i<v.size();i++) cout<<v[i]<<" "; nn;}
template<class T> void disparray(T *v, int n){for(int i=0;i<n;i++) cout<<v[i]<<" "; nn;}
template<class T> int sizeofarr(T *v){return sizeof(v)/sizeof(T);}

signed main(int argc, char** argv)
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    FastIO;
    long t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>inp(n);
        ll sum=0;
        FOR(i,0,n) {cin>>inp[i]; sum+=inp[i];}
        sort(inp.begin(),inp.end());
        reverse(inp.begin(),inp.end());
        n=n/4;
        while(n>0)
        {
        FOR(i,0,n)
        {
            sum+=inp[i];
        }
        n=n/4;
        }
        cout<<sum<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef     unsigned long long int ull;
typedef     long long int    ll;
typedef     long double      ld;
typedef     pair<ll,ll>      pll;
#define     FOR(i,a,b)       for(ll i=a;i<b;i++)
#define     FORE(i,a,b)      for(int i=a;i<=b;i++)
#define     FORD(i,b,a)      for(int i=b;i>a;i--)
#define     FORDE(i,b,a)     for(ll i=b;i>=a;i--)
#define     debug(x)         cout<< '>'<<#x<<" : "<<x<<"\n";
#define     debug2(x,y)      cout<< '>'<<#x<<" : "<<x<<"\n"; cout<< '>'<<#y<<" : "<<y<<"\n";
#define     debug3(x,y,z)    cout<< '>'<<#x<<" : "<<x<<"\n"; cout<< '>'<<#y<<" : "<<y<<"\n";cout<< '>'<<#z<<" : "<<z<<"\n";
#define     umap             unordered_map
#define     uset             unordered_set
#define     lb               lower_bound
#define     ub               upper_bound
#define     mp               make_pair
#define     in               insert
#define     s                second
#define     f                first
#define     nn               cout<<"\n"
#define     pb               push_back
#define     testcase         int t;cin>>t;while(t--)
#define     gcd(a,b)         __gcd(a,b)
#define     maxv             INT_MAX
#define     minv             INT_MIN
#define     MOD              1000000007
#define     FastIO           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define     here             cout<<"I'm here\n";
#define     flush            fflush(stdout);
#define endl '\n'
#define ordered_set_single tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

typedef tree<
pair<ll, ll>,
null_type,
less<pair<ll,ll>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set_pair;

ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

ll nCrModPFermat(ll n, ll r, ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

ll nCrModpDP(ll n, ll r)
{

    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (ll i = 1; i <= n; i++)
    {

        for (ll j = min(i, r); j > 0; j--)

            C[j] = (C[j] + C[j-1])%MOD;
    }
    return C[r];
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll ntopowermandMod(ll n,ll m,ll mod_v)
{
    if(m==0)
    {
        return 1;

    }
    if(m==1)
    {
        return n;
    }
    else
    {
        ll val=ntopowermandMod(n,m/2,mod_v);
        val=val%mod_v;
        val=val*val;
        val=val%mod_v;
        if(m%2==1)
        {
        val=val*n;
        val=val%mod_v;
        }
        return val;

    }

}
ll ntopowerm(ll n,ll m)
{
    if(m==0)
    {
        return 1;

    }
    if(m==1)
    {
        return n;
    }
    else
    {
        ll val=ntopowerm(n,m/2);
        val=val*val;
        if(m%2==1)
        {
        val=val*n;
        }
        return val;

    }

}
vector<int> pi;

void prefix_function(string s) {
    int n = (int)s.length();
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
}
template<class T> void dispvector(vector<T> v){for(int i=0;i<v.size();i++) cout<<v[i]<<" "; nn;}
template<class T> void disparray(T *v, int n){for(int i=0;i<n;i++) cout<<v[i]<<" "; nn;}
template<class T> int sizeofarr(T *v){return sizeof(v)/sizeof(T);}

signed main(int argc, char** argv)
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    FastIO;
    long t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>inp(n);
        ll sum=0;
        FOR(i,0,n) {cin>>inp[i]; sum+=inp[i]}
        n=log2(n);
        n=n/2;
        sort(inp.begin(),inp.end());
        reverse(inp.begin(),inp.end());
        FOR(i,0,n)
        {
            sum+=inp[i];
        }
        cout<<sum<<endl;

    }
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include<cmath>
#include<algorithm>
#define ll long long int
#define ld long double
using namespace std;

int main()
{
    ll k;
    cin>>k;
    ll sum=0;
    ld n=(log(k) / log(4));
    vector<ll> vec(k);
    for(int i=0; i<k; ++i){
        cin>>vec[i];

    }
    if(k==1){
        sum=vec[0];
    }else{
        sort(vec.begin(),vec.end());
        sum=vec[k-1];
        for(int i=0; i<k; ++i){
            sum+=vec[i];
        }
        ll rep=n-1;
        int x=1;
        while(rep){
            for(int i=1; i<=4*x; ++i){
                sum+=vec[k-i];
            }
            x*=4;
            --rep;
        }
    }
    cout<<sum;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include<cmath>
#include<algorithm>
#define ll long long int
using namespace std;

int main()
{
    ll k;
    cin>>k;
    ll sum=0;
    ll n=(log(k) / log(4));
    vector<ll> vec(k);
    for(int i=0; i<k; ++i){
        cin>>vec[i];

    }
    if(k==1){
        sum=vec[0];
    }else{
        sort(vec.begin(),vec.end());
        sum=vec[k-1];
        for(int i=0; i<k; ++i){
            sum+=vec[i];
        }
        ll rep=n-1;
        int x=1;
        while(rep){
            for(int i=1; i<=4*x; ++i){
                sum+=vec[k-i];
            }
            x*=4;
            --rep;
        }
    }
    cout<<sum;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include<cmath>
#include<algorithm>
#define ll long long int
#define ld long double
using namespace std;

int main()
{
    ll k;
    cin>>k;
    ll sum=0;
    ld n=(log(k) / log(4));
    vector<ll> vec(k);
    for(int i=0; i<k; ++i){
        cin>>vec[i];

    }
    if(k==1){
        sum=vec[0];
    }else{
        sort(vec.begin(),vec.end());
        sum=vec[k-1];
        for(int i=0; i<k; ++i){
            sum+=vec[i];
        }
        ld rep=n-1;
        int x=1;
        while(rep){
            for(int i=1; i<=4*x; ++i){
                sum+=vec[k-i];
            }
            x*=4;
            --rep;
        }
    }
    cout<<sum;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include<cmath>
#include<algorithm>
#define ll long long int
using namespace std;

int main()
{
    ll k;
    cin>>k;
    ll sum=0;
    ll n=(log(k) / log(4));
    vector<ll> vec(k);
    for(int i=0; i<k; ++i){
        cin>>vec[i];

    }

    sort(vec.begin(),vec.end());
    sum=vec[k-1];
    for(int i=0; i<k; ++i){
        sum+=vec[i];
    }
    ll rep=n-1;
    int x=1;
    while(rep){
        for(int i=1; i<=4*x; ++i){
            sum+=vec[k-i];
        }
        x*=4;
        --rep;
    }

    cout<<sum;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include<cmath>
#include<algorithm>
#define ll long long int
#define ld long double
using namespace std;

int main()
{
    ll k;
    cin>>k;
    ll sum=0;
    vector<ll> vec(k);
    for(int i=0; i<k; ++i){
        cin>>vec[i];

    }
    if(k==1){
        sum=vec[0];
    }else{
        sort(vec.begin(),vec.end());
        sum=vec[k-1];
        for(int i=0; i<k; ++i){
            sum+=vec[i];
        }
        ll rep=k/4;
        int x=1;
        while(rep/4>=1){
            for(int i=1; i<=4*x; ++i){
                sum+=vec[k-i];
            }
            x*=4;
            rep/=4;
        }
    }
    cout<<sum;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include<cmath>
#include<algorithm>
#define ll long long int
#define ld long double
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(12);
    ll k;
    cin>>k;
    ll sum=0;
    vector<ll> vec(k);
    for(int i=0; i<k; ++i){
        cin>>vec[i];

    }
    if(k==1){
        sum=vec[0];
    }else{
        sort(vec.begin(),vec.end());
        sum=vec[k-1];
        for(int i=0; i<k; ++i){
            sum+=vec[i];
        }
        ll rep=k/4;
        int x=1;
        while(rep/4>=1){
            for(int i=1; i<=4*x; ++i){
                sum+=vec[k-i];
            }
            x*=4;
            rep/=4;
        }
    }
    cout<<sum;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int N;
  scanf("%d", &N);
  vi v(N);
  for(int i = 0; i < N; ++i) {
    scanf("%d", &v[i]);
  }
  sort(v.rbegin(), v.rend());
  ll ans = 0ll;
  int p4 = 1;
  while(p4 <= N) {
    for(int i = 0; i < p4; ++i) {
      ans += ll(v[i]);
    }
    p4 *= 4;
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

int highest_bit(int x) {
  int ret = 0;
  for(int i = 0; i < 29; ++i) {
    if(x&((1<<i))) {
      ret = i;
    }
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int N;
  cin >> N;
  vi v(N);
  for(int& x : v) {
    cin >> x;
  }
  sort(v.rbegin(), v.rend());
  int n = 1 << (highest_bit(N) >> 1);
  ll ans = 0ll;
  int prev = 0, step = 1;
  for(int lv = 0; lv < n - 1; ++lv) {
    for(int i = prev; i < step; ++i) {
      ans += ll(n - lv - 1) * ll(v[i]);
    }
    prev = step;
    step *= 4;
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

int highest_bit(int x) {
  int ret = 0;
  for(int i = 0; i < 29; ++i) {
    if(x&((1<<i))) {
      ret = i;
    }
  }
  return ret;
}

struct solve {
  multiset< int >& S;
  vvi& m;

  void fill_matrix() {
    int n = int(m.size());
    queue< vi > q;
    q.push({0, 0, n - 1, n - 1});
    while(!q.empty()) {
      vi cur = q.front();
      int top = cur[0], left = cur[1], bottom = cur[2], right = cur[3];
      q.pop();
      vvi indices = {
        {top, left},
        {top, right},
        {bottom, left},
        {bottom, right}
      };
      for(vi& v : indices) {
        int& ref = m[v[0]][v[1]];
        if(ref == -1) {
          auto it = --S.end();
          ref = *it;
          S.erase(it);
        }
      }
      if(left != right) {
        int hi = (top + bottom) / 2;
        int hj = (left + right) / 2;
        q.push({top, left, hi, hj});
        q.push({top, hj + 1, hi, right});
        q.push({hi + 1, left, bottom, hj});
        q.push({hi + 1, hj + 1, bottom, right});
      }
    }
  }

  ll calc(int top, int left, int bottom, int right) {
    ll ret = 0ll;
    for(int i = top; i <= bottom; ++i) {
      for(int j = left; j <= right; ++j) {
        ret = max(ret, ll(m[i][j]));
      }
    }
    if(left != right) {
      int hi = (top + bottom) / 2;
      int hj = (left + right) / 2;
      ret +=
        calc(top, left, hi, hj) +
        calc(top, hj + 1, hi, right) +
        calc(hi + 1, left, bottom, hj) +
        calc(hi + 1, hj + 1, bottom, right);
    }
    return ret;
  }

  ll compute_value() {
    #ifndef ONLINE_JUDGE
    for(vi& row : m) {
      for(int val : row) cout << val << "\t";
      cout << endl;
    }
    #endif
    int n = int(m.size());
    return calc(0, 0, n - 1, n - 1);
  }

};

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int N;
  cin >> N;
  multiset< int > S;
  for(int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    S.insert(x);
  }
  int n = 1 << (highest_bit(N) >> 1);
  vvi m(n, vi(n, -1));
  solve f = {S, m};
  f.fill_matrix();
  cout << f.compute_value() << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

int highest_bit(int x) {
  int ret = 0;
  for(int i = 0; i < 29; ++i) {
    if(x&((1<<i))) {
      ret = i;
    }
  }
  return ret;
}

struct solve {
  multiset< int >& S;
  vvi& m;

  void fill_matrix() {
    int n = int(m.size());
    queue< vi > q;
    q.push({0, 0, n - 1, n - 1});
    while(!q.empty()) {
      vi cur = q.front();
      int top = cur[0], left = cur[1], bottom = cur[2], right = cur[3];
      q.pop();
      vvi indices = {
        {top, left},
        {top, right},
        {bottom, left},
        {bottom, right}
      };
      for(vi& v : indices) {
        int& ref = m[v[0]][v[1]];
        if(ref == -1) {
          auto it = --S.end();
          ref = *it;
          S.erase(it);
        }
      }
      if(left != right) {
        int hi = (top + bottom) / 2;
        int hj = (left + right) / 2;
        q.push({top, left, hi, hj});
        q.push({top, hj + 1, hi, right});
        q.push({hi + 1, left, bottom, hj});
        q.push({hi + 1, hj + 1, bottom, right});
      }
    }
  }

  ll calc(int top, int left, int bottom, int right) {
    ll ret = 0ll;
    for(int i = top; i <= bottom; ++i) {
      for(int j = left; j <= right; ++j) {
        ret = max(ret, ll(m[i][j]));
      }
    }
    if(left != right) {
      int hi = (top + bottom) / 2;
      int hj = (left + right) / 2;
      ret +=
        calc(top, left, hi, hj) +
        calc(top, hj + 1, hi, right) +
        calc(hi + 1, left, bottom, hj) +
        calc(hi + 1, hj + 1, bottom, right);
    }
    return ret;
  }

  ll compute_value() {
    #ifndef ONLINE_JUDGE
    for(vi& row : m) {
      for(int val : row) cout << val << "\t";
      cout << endl;
    }
    #endif
    int n = int(m.size());
    return calc(0, 0, n - 1, n - 1);
  }

};

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int N;
  scanf("%d", &N);
  multiset< int > S;
  for(int i = 0; i < N; ++i) {
    int x;
    scanf("%d", &x);
    S.insert(x);
  }
  int n = 1 << (highest_bit(N) >> 1);
  vvi m(n, vi(n, -1));
  solve f = {S, m};
  f.fill_matrix();
  cout << f.compute_value() << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

int highest_bit(int x) {
  int ret = 0;
  for(int i = 0; i < 29; ++i) {
    if(x&((1<<i))) {
      ret = i;
    }
  }
  return ret;
}

struct solve {
  multiset< int >& S;
  vvi& m;
  map< vi, int > vals;

  void fill_matrix() {
    int n = int(m.size());
    queue< vi > q;
    q.push({0, 0, n - 1, n - 1});
    while(!q.empty()) {
      vi cur = q.front();
      int top = cur[0], left = cur[1], bottom = cur[2], right = cur[3];
      q.pop();
      vvi indices = {
        {top, left},
        {top, right},
        {bottom, left},
        {bottom, right}
      };
      for(vi& v : indices) {
        int& ref = m[v[0]][v[1]];
        if(ref == -1) {
          auto it = --S.end();
          ref = *it;
          S.erase(it);
        }
        vals[cur] = max(vals[cur], ref);
      }
      if(left != right) {
        int hi = (top + bottom) / 2;
        int hj = (left + right) / 2;
        q.push({top, left, hi, hj});
        q.push({top, hj + 1, hi, right});
        q.push({hi + 1, left, bottom, hj});
        q.push({hi + 1, hj + 1, bottom, right});
      }
    }
  }

  ll calc(int top, int left, int bottom, int right) {
    ll ret = ll(vals[{top, left, bottom, right}]);
    if(left != right) {
      int hi = (top + bottom) / 2;
      int hj = (left + right) / 2;
      ret +=
        calc(top, left, hi, hj) +
        calc(top, hj + 1, hi, right) +
        calc(hi + 1, left, bottom, hj) +
        calc(hi + 1, hj + 1, bottom, right);
    }
    return ret;
  }

  ll compute_value() {
    #ifndef ONLINE_JUDGE
    for(vi& row : m) {
      for(int val : row) cout << val << "\t";
      cout << endl;
    }
    #endif
    int n = int(m.size());
    return calc(0, 0, n - 1, n - 1);
  }

};

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int N;
  scanf("%d", &N);
  multiset< int > S;
  for(int i = 0; i < N; ++i) {
    int x;
    scanf("%d", &x);
    S.insert(x);
  }
  int n = 1 << (highest_bit(N) >> 1);
  vvi m(n, vi(n, -1));
  solve f = {S, m};
  f.fill_matrix();
  cout << f.compute_value() << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

int highest_bit(int x) {
  int ret = 0;
  for(int i = 0; i < 29; ++i) {
    if(x&((1<<i))) {
      ret = i;
    }
  }
  return ret;
}

ll calc(int top, int left, int bottom, int right, vvi& mat, multiset< int >& S) {
  vvi indices = {
    {top, left},
    {top, right},
    {bottom, left},
    {bottom, right}
  };
  ll m = -1ll;
  for(vi v : indices) {
    int& ref = mat[v[0]][v[1]];
    if(ref == -1) {
      auto it = --S.end();
      int val = *it;
      S.erase(it);
      ref = val;
    }
    m = max(m, ll(ref));
  }
  if(top == bottom && left == right) return ll(m);
  int hi = (top + bottom) / 2;
  int hj = (left + right) / 2;
  return m +
  calc(top, left, hi, hj, mat, S) +
  calc(top, hj + 1, hi, right, mat, S) +
  calc(hi + 1, left, bottom, hj, mat, S) +
  calc(hi + 1, hj + 1, bottom, right, mat, S);
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int N;
  cin >> N;
  multiset< int > S;
  for(int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    S.insert(x);
  }
  int n = 1 << (highest_bit(N) >> 1);
  vvi mat(n, vi(n, -1));
  cout << calc(0, 0, n - 1, n - 1, mat, S) << endl;
  #ifndef ONLINE_JUDGE
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < n; ++j) {
      cout << mat[i][j] << "\t";
    }
    cout << endl;
  }
  #endif
}


#include <bits/stdc++.h>

        using namespace std;

        /* ---*-----*-----
        ---------o--------
        -----------------*/

        typedef long long ll;
        typedef long double ld;

        typedef vector<ll> vl;

        #define mp make_pair
        #define pb push_back
        #define f first
        #define s second
        #define lb lower_bound
        #define ub upper_bound

        const int MOD = 1000000007;
        const int N = 200005;
        const double PI =4*atan(1);
        const ll MAX=9223372036854775807;

        //set<char> vowel={'A', 'O', 'Y','E', 'U', 'I','a','o','e','u','i'};

        int dx[]={1,-1,0,0,1,-1,1,-1};
        int dy[]={0,0,1,-1,1,1,-1,-1};

        ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
        ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
        bool issquare(ll w ){return trunc(sqrt(w))*trunc(sqrt(w))==w;}
        bool isprime(ll u){for(ll i=2;i<=(int)sqrt(u);i++){if(u%i==0)return 0;}return 1;}
        ll mod(ll to_mod){to_mod%=MOD;while(to_mod<0)to_mod+=MOD;return to_mod%MOD;}
        ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)
            res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
        ll power(ll x, ll y/*,ll p*/){ll res = 1;x = x /*% p*/;
            while (y > 0){if (y & 1)res = (res*x)/* % p*/;y = y>>1;x = (x*x) /*% p*/;}return res;}
     /*  ll _sieve_size;bitset<10000010> bs;vl primes;
        void sieve(ll upperbound) {_sieve_size = upperbound + 1;bs.set();bs[0] = bs[1] = 0;
            for (ll i = 2; i<= _sieve_size; i++) if (bs[i]) {for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;primes.pb(i);} }
*/

        ll n,m,x,y,res,t,k,ans=0,b,q;
        ll a[N];
        ll dp[N];

        int main(){
            ios::sync_with_stdio(0);
            scanf("%I64d",&n);
            for(int i=0;i<n;i++){
                scanf("%I64d",&a[i]);
            }
            ans=0;
            sort(a,a+n);
            res=1;
            ll com=0;
            x=0;
            y=0;
            for(int i=n-1;i>=0;i--){
                com++;
                x+=a[i];
                if(com==res){
                    res*=4;
                    dp[y]=x;
                    y++;
                }
            }
            //printf("%I64d",ans);
            for(int i=y-2;i>=0;i--){
            	dp[i]+=dp[i+1];
            }
            printf("%I64d",dp[0]);
            return 0;
        }


#include <bits/stdc++.h>

        using namespace std;

        /* ---*-----*-----
        ---------o--------
        -----------------*/

        typedef long long ll;
        typedef long double ld;

        typedef vector<ll> vl;

        #define mp make_pair
        #define pb push_back
        #define f first
        #define s second
        #define lb lower_bound
        #define ub upper_bound

        const int MOD = 1000000007;
        const int N = 100005;
        const double PI =4*atan(1);
        const ll MAX=9223372036854775807;

        //set<char> vowel={'A', 'O', 'Y','E', 'U', 'I','a','o','e','u','i'};

        int dx[]={1,-1,0,0,1,-1,1,-1};
        int dy[]={0,0,1,-1,1,1,-1,-1};

        ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
        ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
        bool issquare(ll w ){return trunc(sqrt(w))*trunc(sqrt(w))==w;}
        bool isprime(ll u){for(ll i=2;i<=(int)sqrt(u);i++){if(u%i==0)return 0;}return 1;}
        ll mod(ll to_mod){to_mod%=MOD;while(to_mod<0)to_mod+=MOD;return to_mod%MOD;}
        ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)
            res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
        ll power(ll x, ll y/*,ll p*/){ll res = 1;x = x /*% p*/;
            while (y > 0){if (y & 1)res = (res*x)/* % p*/;y = y>>1;x = (x*x) /*% p*/;}return res;}
     /*  ll _sieve_size;bitset<10000010> bs;vl primes;
        void sieve(ll upperbound) {_sieve_size = upperbound + 1;bs.set();bs[0] = bs[1] = 0;
            for (ll i = 2; i<= _sieve_size; i++) if (bs[i]) {for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;primes.pb(i);} }
*/

        ll n,m,x,y,res,t,k,ans=0,b,q;
        ll a[N];
        ll dp[N];

        int main(){
            ios::sync_with_stdio(0);
            scanf("%I64d",&n);
            for(int i=0;i<n;i++){
                scanf("%I64d",&a[i]);
            }
            ans=0;
            sort(a,a+n);
            res=1;
            ll com=0;
            x=0;
            y=0;
            for(int i=n-1;i>=0;i--){
                com++;
                x+=a[i];
                if(com==res){
                    res*=4;
                    dp[y]=x;
                    y++;
                }
            }
            //printf("%I64d",ans);
            for(int i=y-2;i>=0;i--){
            	dp[i]+=dp[i+1];
            }
            printf("%I64d",dp[0]);
            return 0;
        }


#include <bits/stdc++.h>

        using namespace std;

        /* ---*-----*-----
        ---------o--------
        -----------------*/

        typedef long long ll;
        typedef long double ld;

        typedef vector<ll> vl;

        #define mp make_pair
        #define pb push_back
        #define f first
        #define s second
        #define lb lower_bound
        #define ub upper_bound

        const int MOD = 1000000007;
        const int N = 100005;
        const double PI =4*atan(1);
        const ll MAX=9223372036854775807;

        //set<char> vowel={'A', 'O', 'Y','E', 'U', 'I','a','o','e','u','i'};

        int dx[]={1,-1,0,0,1,-1,1,-1};
        int dy[]={0,0,1,-1,1,1,-1,-1};

        ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
        ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
        bool issquare(ll w ){return trunc(sqrt(w))*trunc(sqrt(w))==w;}
        bool isprime(ll u){for(ll i=2;i<=(int)sqrt(u);i++){if(u%i==0)return 0;}return 1;}
        ll mod(ll to_mod){to_mod%=MOD;while(to_mod<0)to_mod+=MOD;return to_mod%MOD;}
        ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)
            res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
        ll power(ll x, ll y/*,ll p*/){ll res = 1;x = x /*% p*/;
            while (y > 0){if (y & 1)res = (res*x)/* % p*/;y = y>>1;x = (x*x) /*% p*/;}return res;}
     /*  ll _sieve_size;bitset<10000010> bs;vl primes;
        void sieve(ll upperbound) {_sieve_size = upperbound + 1;bs.set();bs[0] = bs[1] = 0;
            for (ll i = 2; i<= _sieve_size; i++) if (bs[i]) {for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;primes.pb(i);} }
*/

        ll n,m,x,y,res,t,k,ans=0,b,q;
        ll a[N];

        int main(){
            ios::sync_with_stdio(0);
            cin >> n;
            for(int i=0;i<n;i++){
                cin >> a[i];
            }
            ans=0;
            sort(a,a+n);
            res=1;
            ll com=0;
            x=0;
            for(int i=n-1;i>=0;i--){
                com++;
                x+=a[i];
                if(com==res){
                    res*=4;
                    ans+=x;
                }
            }
            cout << ans;
            return 0;
        }


#include <bits/stdc++.h>

        using namespace std;

        /* ---*-----*-----
        ---------o--------
        -----------------*/

        typedef long long ll;
        typedef long double ld;

        typedef vector<ll> vl;

        #define mp make_pair
        #define pb push_back
        #define f first
        #define s second
        #define lb lower_bound
        #define ub upper_bound

        const int MOD = 1000000007;
        const int N = 2000005;
        const double PI =4*atan(1);
        const ll MAX=9223372036854775807;

        //set<char> vowel={'A', 'O', 'Y','E', 'U', 'I','a','o','e','u','i'};

        int dx[]={1,-1,0,0,1,-1,1,-1};
        int dy[]={0,0,1,-1,1,1,-1,-1};

        ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
        ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
        bool issquare(ll w ){return trunc(sqrt(w))*trunc(sqrt(w))==w;}
        bool isprime(ll u){for(ll i=2;i<=(int)sqrt(u);i++){if(u%i==0)return 0;}return 1;}
        ll mod(ll to_mod){to_mod%=MOD;while(to_mod<0)to_mod+=MOD;return to_mod%MOD;}
        ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)
            res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
        ll power(ll x, ll y/*,ll p*/){ll res = 1;x = x /*% p*/;
            while (y > 0){if (y & 1)res = (res*x)/* % p*/;y = y>>1;x = (x*x) /*% p*/;}return res;}
     /*  ll _sieve_size;bitset<10000010> bs;vl primes;
        void sieve(ll upperbound) {_sieve_size = upperbound + 1;bs.set();bs[0] = bs[1] = 0;
            for (ll i = 2; i<= _sieve_size; i++) if (bs[i]) {for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;primes.pb(i);} }
*/

        ll n,m,x,y,res,t,k,ans=0,b,q;
        ll a[N];

        int main(){
            ios::sync_with_stdio(0);
            cin >> n;
            for(int i=0;i<n;i++){
                cin >> a[i];
            }
            ans=0;
            sort(a,a+n);
            res=1;
            ll com=0;
            x=0;
            for(int i=n-1;i>=0;i--){
                com++;
                x+=a[i];
                if(com==res){
                    res*=4;
                    ans+=x;
                }
            }
            cout << ans;
            return 0;
        }


#include <bits/stdc++.h>

        using namespace std;

        /* ---*-----*-----
        ---------o--------
        -----------------*/

        typedef long long ll;
        typedef long double ld;

        typedef vector<ll> vl;

        #define mp make_pair
        #define pb push_back
        #define f first
        #define s second
        #define lb lower_bound
        #define ub upper_bound

        const int MOD = 1000000007;
        const int N = 2000005;
        const double PI =4*atan(1);
        const ll MAX=9223372036854775807;

        //set<char> vowel={'A', 'O', 'Y','E', 'U', 'I','a','o','e','u','i'};

        int dx[]={1,-1,0,0,1,-1,1,-1};
        int dy[]={0,0,1,-1,1,1,-1,-1};

        ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
        ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
        bool issquare(ll w ){return trunc(sqrt(w))*trunc(sqrt(w))==w;}
        bool isprime(ll u){for(ll i=2;i<=(int)sqrt(u);i++){if(u%i==0)return 0;}return 1;}
        ll mod(ll to_mod){to_mod%=MOD;while(to_mod<0)to_mod+=MOD;return to_mod%MOD;}
        ll moduloMultiplication(ll a,ll b,ll mod){ll res = 0;a %= mod;while (b){if (b & 1)
            res = (res + a) % mod;a = (2 * a) % mod;b >>= 1;}return res;}
        ll power(ll x, ll y/*,ll p*/){ll res = 1;x = x /*% p*/;
            while (y > 0){if (y & 1)res = (res*x)/* % p*/;y = y>>1;x = (x*x) /*% p*/;}return res;}
     /*  ll _sieve_size;bitset<10000010> bs;vl primes;
        void sieve(ll upperbound) {_sieve_size = upperbound + 1;bs.set();bs[0] = bs[1] = 0;
            for (ll i = 2; i<= _sieve_size; i++) if (bs[i]) {for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;primes.pb(i);} }
*/

        ll n,m,x,y,res,t,k,ans=0,b,q;
        ll a[N];
        ll dp[N];

        int main(){
            ios::sync_with_stdio(0);
            scanf("%I64d",&n);
            for(int i=0;i<n;i++){
                scanf("%I64d",&a[i]);
            }
            ans=0;
            sort(a,a+n);
            res=1;
            ll com=0;
            x=0;
            y=0;
            for(int i=n-1;i>=0;i--){
                com++;
                x+=a[i];
                if(com==res){
                    res*=4;
                    dp[y]=x;
                    y++;
                }
            }
            //printf("%I64d",ans);
            for(int i=y-2;i>=0;i--){
            	dp[i]+=dp[i+1];
            }
            printf("%I64d",dp[0]);
            return 0;
        }


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second
#define pb push_back
int main(){
	int test;
	//cin>>test;
	test=1;
	while(test--){
		int n;
		cin>>n;
		vector<ll> arr(n);
		for(int i=0;i<n;i++){cin>>arr[i];} //.... check indexing
		sort(arr.rbegin(),arr.rend());
		ll pref[n];
		pref[0]=arr[0];
		for(int i=1;i<n;i++){
			pref[i]=pref[i-1]+arr[i];
		}
		ll ans=0;
		for(ll i=1;i<=n;){
			ans+=pref[i-1];
			i*=4;
		}
		cout<<ans<<endl;

	}
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define sec second
int arr[2000][2000];
typedef long long int ll;
pair<ll,int> func(int x1,int y1,int x2,int y2){
	if(x2==x1){return {arr[x1][y1],arr[x1][y1]};}
	else{
		pair<ll,int> a=func(x1,y1,(x2+x1)/2,(y2+y1)/2);
		pair<ll,int> b=func((x2+x1)/2+1,y1,x2,(y2+y1)/2);
		pair<ll,int> c=func(x1,(y1+y2)/2+1,(x2+x1)/2,y2);
		pair<ll,int> d=func((x2+x1)/2+1,(y2+y1)/2+1,x2,y2);
		int maxi=max(a.sec,max(b.sec,max(c.sec,d.sec)));
		return {a.fi+b.fi+c.fi+d.fi+maxi,maxi};
		}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int test;
	//cin>>test;
	test=1;
	while(test--){
		int n;
		cin>>n;
		long long int sum=0;
		int a=sqrt(n);
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				cin>>arr[i][j];sum+=arr[i][j];
			}
		}
		cout<<func(0,0,a-1,a-1).fi<<endl;

	}

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second
#define pb push_back
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int test;
	//cin>>test;
	test=1;
	while(test--){
		int n;
		cin>>n;
		vector<ll> arr(n);
		for(int i=0;i<n;i++){cin>>arr[i];} //.... check indexing
		sort(arr.rbegin(),arr.rend());
		ll pref[n];
		pref[0]=arr[0];
		for(int i=1;i<n;i++){
			pref[i]=pref[i-1]+arr[i];
		}
		ll ans=0;
		for(ll i=1;i<=n;){
			ans+=pref[i-1];
			i*=4;
		}
		cout<<ans<<'\n';

	}
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define sec second
int arr[2000][2000];
typedef long long int ll;
pair<ll,int> func(int x1,int y1,int x2,int y2){
	if(x2==x1){return {arr[x1][y1],arr[x1][y1]};}
	else{
		pair<int,int> a=func(x1,y1,(x2+x1)/2,(y2+y1)/2);
		pair<int,int> b=func((x2+x1)/2+1,y1,x2,(y2+y1)/2);
		pair<int,int> c=func(x1,(y1+y2)/2+1,(x2+x1)/2,y2);
		pair<int,int> d=func((x2+x1)/2+1,(y2+y1)/2+1,x2,y2);
		int maxi=max(a.sec,max(b.sec,max(c.sec,d.sec)));
		return {a.fi+b.fi+c.fi+d.fi+maxi,maxi};
		}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int test;
	//cin>>test;
	test=1;
	while(test--){
		int n;
		cin>>n;
		long long int sum=0;
		int a=sqrt(n);
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				cin>>arr[i][j];sum+=arr[i][j];
			}
		}
		cout<<func(0,0,a-1,a-1).fi<<endl;

	}

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < ll > vc;
int main(){
fcin;
    cin >> n;
    for(ll i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    r = n;
    for(ll i = 1 ; i <= n ; i++){
        sum += a[i];
        if(i%3==0 && vc.size() < n/4){
            sum += a[r];
            sum += a[r];
            vc.pb(sum);
            r--;
            sum = 0;
        }
    }
    if(vc.size()==1){
        cout << vc[0];
        return 0;
    }
    c = 1 , r = n;
    while(true){
        sum = 0;
        vector<ll>vc1;
        r = n;
        for(int i = 0 ; i < vc.size() ; i++){
            sum += vc[i];
            if(i>0 && i%3==0){
                sum += a[r];
                r--;
                vc1.pb(sum);
                sum = 0;
            }
        }
        if(vc1.size()==1){
            ans = vc1[0];
            break;
        }
        vc = vc1;
    }
    cout << ans << "\n";

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < ll > vc;
int main(){
fcin;
    cin >> n;
    for(ll i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    r = n;
    for(ll i = 1 ; i <= n ; i++){
        sum += a[i];
        if(i%3==0 && vc.size() < n/4){
            sum += a[r];
            sum += a[r];
            vc.pb(sum);
            r--;
            sum = 0;
        }
    }
    if(vc.size()==1){
        cout << vc[0] + a[n];
        return 0;
    }
    c = 1 , r = n;
    while(true){
        sum = 0;
        vector<ll>vc1;
        r = n;
        for(int i = 0 ; i < vc.size() ; i++){
            sum += vc[i];
            if(i>0 && i%3==0){
                sum += a[r];
                r--;
                vc1.pb(sum);
                sum = 0;
            }
        }
        if(vc1.size()==1){
            ans = vc1[0];
            break;
        }
        vc = vc1;
    }
    cout << ans << "\n";

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < ll > vc;
int main(){
fcin;
    cin >> n;
    for(ll i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    r = n;
    k = 0 , c = 0  ;
    int i = 1;
    while(vc.size() < n/4){
        c++;
        sum += a[i + k];
        k += (n/4);
        if(c==4){
            vc.pb(sum);
            sum = 0;
            c = 0;
            i++;
            k=0;
        }

    }
    if(vc.size()==1){
        cout << vc[0] + a[n];
        return 0;
    }
    c = 1 , r = n;
    while(true){
    k = 0 , f = 0 ;
    vector<ll>vc1;
    sum = 0;
    sort(vc.begin(),vc.end());
    reverse(vc.begin(),vc.end());
    for(ll i = 0 ; i < vc.size() ; i++){
        sum += vc[i] + a[r-k];
        if(i>0 && i%3==0){
            vc1.pb(sum + a[r-f]);
            f+=4;
            sum = 0;
        }
        k+=c;
    }
    if(vc1.size()==1) {ans= vc1[0]; break;}
    vc = vc1;
    c+=4;
    }
    cout << ans << "\n";

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < ll > vc;
int main(){
fcin;
    cin >> n;
    for(ll i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    r = n;
    for(ll i = 1 ; i <= n ; i++){
        sum += a[i];
        if(i%3==0 && vc.size() < n/4){
            sum += a[r];
            vc.pb(sum);
            r--;
            sum = 0;
        }
    }
    if(vc.size()==1){
        cout << vc[0] + a[n];
        return 0;
    }
    c = 1 , r = n;
    while(true){
    k = 0 , f = 0 ;
    vector<ll>vc1;
    sum = 0;
    for(ll i = 0 ; i < vc.size() ; i++){
        sum += vc[i] + a[r-k];
        if(i>0 && i%3==0){
            vc1.pb(sum + a[r-f]);
            f+=4;
            sum = 0;
        }
        k+=c;
    }
    if(vc1.size()==1) {ans= vc1[0]; break;}
    vc = vc1;
    c+=4;
    }
    cout << ans << "\n";

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < ll > vc;
int main(){
fcin;
    cin >> n;
    for(ll i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    r = n;
    k = 0 , c = 0  ;
    int i = 1;
    while(vc.size() < n/4){
        c++;
        sum += a[i + k];
        k += (n/4);
        if(c==4){
            vc.pb(sum);
            sum = 0;
            c = 0;
            i++;
            k=0;
        }

    }
    if(vc.size()==1){
        cout << vc[0] + a[n];
        return 0;
    }
    c = 1 , r = n;
    while(true){
    k = 0 , f = 0 ;
    vector<ll>vc1;
    sum = 0;
    sort(vc.begin(),vc.end());
    for(ll i = 0 ; i < vc.size() ; i++){
        sum += vc[i] + a[r-k];
        if(i>0 && i%3==0){
            vc1.pb(sum + a[r-f]);
            f+=4;
            sum = 0;
        }
        k+=c;
    }
    if(vc1.size()==1) {ans= vc1[0]; break;}
    vc = vc1;
    c+=4;
    }
    cout << ans << "\n";

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < ll > vc;
int main(){
fcin;
    cin >> n;
    for(ll i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    r = n;
    for(ll i = 1 ; i <= n ; i++){
        sum += a[i];
        if(i%3==0 && vc.size() < n/4){
            sum += a[r];
            vc.pb(sum);
            r--;
            sum = 0;
        }
    }
    if(vc.size()==1){
        cout << vc[0]+a[n];
        return 0;
    }
    c = 1 , r = n;
    while(true){
        sum = 0;
        vector<ll>vc1;
        r = n , f = n;
        for(int i = 0 ; i < vc.size() ; i++){
            sum += vc[i];
            sum += a[f];
            f--;
            if(i>0 && i%3==0){
                sum += a[r];
                r--;
                vc1.pb(sum);
                sum = 0;
            }
        }
        if(vc1.size()==1){
            ans = vc1[0];
            break;
        }
        vc = vc1;
    }
    cout << ans << "\n";

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < ll > vc;
int main(){
fcin;
    cin >> n;
    for(ll i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    r = n;
    for(ll i = 1 ; i <= n ; i++){
        sum += a[i];
        if(i%3==0 && vc.size() < n/4){
            sum += a[r];
            vc.pb(sum);
            r--;
            sum = 0;
        }
    }
    if(vc.size()==1){
        cout << vc[0];
        return 0;
    }
    c = 1 , r = n;
    while(true){
        sum = 0;
        vector<ll>vc1;
        r = n , f = n;
        for(int i = 0 ; i < vc.size() ; i++){
            sum += vc[i];
            sum += a[f];
            f--;
            if(i>0 && i%3==0){
                sum += a[r];
                r--;
                vc1.pb(sum);
                sum = 0;
            }
        }
        if(vc1.size()==1){
            ans = vc1[0];
            break;
        }
        vc = vc1;
    }
    cout << ans << "\n";

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < ll > vc;
int main(){
fcin;
    cin >> n;
    for(ll i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    c = 4;
    for(ll i = 1 ; i <= n ; i++){
        sum += a[i];
    }
    while(true){
        f = 0;
        for(ll i = n-(n/c)+1 ; i <= n ; i++){
           f += a[i];
        }
        sum = sum + f;
        c*=4;
        if((n-(n/c)+1)>n) break;
    }
    cout << sum << "\n";

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < ll > vc;
int main(){
fcin;
    cin >> n;
    for(ll i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    r = n;
    k = 0 , c = 0  ;
    int i = 1;
    while(vc.size() < n/4){
        c++;
        sum += a[i + k];
        k += (n/4);
        if(c==4){
            vc.pb(sum);
            sum = 0;
            c = 0;
            i++;
            k=0;
        }

    }
    if(vc.size()==1){
        cout << vc[0] + a[n];
        return 0;
    }
    c = 1 , r = n;
    while(true){
    k = 0 , f = 0 ;
    vector<ll>vc1;
    sum = 0;
    for(ll i = 0 ; i < vc.size() ; i++){
        sum += vc[i] + a[r-k];
        if(i>0 && i%3==0){
            vc1.pb(sum + a[r-f]);
            f+=4;
            sum = 0;
        }
        k+=c;
    }
    if(vc1.size()==1) {ans= vc1[0]; break;}
    vc = vc1;
    c+=4;
    }
    cout << ans << "\n";

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < ll > vc;
int main(){
fcin;
    cin >> n;
    for(ll i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    r = n;
    k = 0 , c = 0  ;
    vc.resize(n/4);
    int i = 1 , lst = (n/4-1);
    for(int i = n; i >= 1 ; i--){
        if(c==0){
            vc[lst]+=a[i];
            lst--;
            if(lst<0) {
                c = 1;
                lst = 0;
            }
        }
        else{
            vc[lst] += a[i];
            lst++;
            if(lst==n/4) {c=0; lst = 0;}
        }
    }
    if(vc.size()==1){
        cout << vc[0] + a[n];
        return 0;
    }
    c = 1 , r = n;
    while(true){
    k = 0 , f = 0 ;
    vector<ll>vc1;
    sum = 0;
    sort(vc.begin(),vc.end());
    reverse(vc.begin(),vc.end());
    for(ll i = 0 ; i < vc.size() ; i++){
        sum += vc[i] + a[r-k];
        if(i>0 && i%3==0){
            vc1.pb(sum + a[r-f]);
            f+=4;
            sum = 0;
        }
        k+=c;
    }
    if(vc1.size()==1) {ans= vc1[0]; break;}
    vc = vc1;
    c+=4;
    }
    cout << ans << "\n";

}


//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int n , a[N] , sum = 0 , r , k = 0 , c = 0 , ans , f = 0 ;
vector < int > vc;
int main(){
fcin;
    cin >> n;
    for(int i = 1 ; i <= n ; i++) cin >> a[i];
    if(n==1){
        cout<<a[n];
        return 0;
    }
    sort(a + 1,a+n + 1);
    r = n;
    for(int i = 1 ; i <= n ; i++){
        sum += a[i];
        if(i%3==0 && vc.size() < n/4){
            sum += a[r];
            vc.pb(sum);
            r--;
            sum = 0;
        }
    }
    if(vc.size()==1){
        cout << vc[0] + a[n];
        return 0;
    }
    c = 1 , r = n;
    while(true){
    k = 0 , f = 0 ;
    vector<int>vc1;
    sum = 0;
    for(int i = 0 ; i < vc.size() ; i++){
        sum += vc[i] + a[r-k];
        if(i>0 && i%3==0){
            vc1.pb(sum + a[r-f]);
            f+=4;
            sum = 0;
        }
        k+=c;
    }
    if(vc1.size()==1) {ans= vc1[0]; break;}
    vc = vc1;
    c+=4;
    }
    cout << ans << "\n";

}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <math.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<long long int> v;
    for(int i = 0;  i < n; i++){
        cin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = log2(n)/2;
    sort(v.begin(),v.end());
    long long int p = n/4;
    int c = 1,d = p/4*3*4;
    for(int i = n-p; i< n ; i += d){
        d /= 4;
        if (d == 0)
            d = 1;
        //cout<<d<<endl;
        //cout<<i<<endl;
        for(int j = 0; j < d; j++)
            if(j+i < n)
            sum += v[j+i]*c;
        c++;
    }
    cout<<sum;
}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<int> v;
    for(int i = 0;  i < n; i++){
        cin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = n/4-1;
    sort(v.begin(),v.end());
    long long int p = n/4;
    int c = 0,d;
    for(int i = n-p; i< n ; i += 3){
        c++;
        d = c;
        while(d--){
            for(int j = 0; j < 3; j++){
                if(i+j < n)
                sum += v[i+j];
            }
        }
    }
    cout<<sum;
}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<int> v;
    for(int i = 0;  i < n; i++){
        cin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = n/4-1;
    sort(v.begin(),v.end());
    long long int p = liv*4+1;
    int c = 0,d;
    for(int i = n-p; i< n ; i += 4){
        c++;
        d = c;
        while(d--){
            for(int j = 0; j < 4; j++){
                if(i+j < n)
                sum += v[i+j];
            }
        }
    }
    cout<<sum;
}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <math.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<int> v;
    for(int i = 0;  i < n; i++){
        cin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = log2(n)/2;
    sort(v.begin(),v.end());
    long long int p = n/4;
    int c = 0,d = p/4*3*4;
    for(int i = n-p; i< n ; i += d){
        d /= 4;
        if (d == 0)
            d = 1;
        //cout<<d<<endl;
        //cout<<i<<endl;
        for(int j = i; j < n; j++)
            sum += v[j];
    }
    cout<<sum;
}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <math.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<int> v;
    for(int i = 0;  i < n; i++){
        cin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = log2(n)/2-1;
    sort(v.begin(),v.end());
    long long int p = n/4;
    int c = 0,d;
    for(int i = n-p; i< n ; i += 3*pow(2,liv)){
        c++;
        d = c;
        liv--;
        for(int j = i; j < n; j++)
            sum += v[j];
    }
    cout<<sum;
}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <math.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    cin.tie(0), cin.sync_with_stdio(0);
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<long long int> v;
    for(int i = 0;  i < n; i++){
        cin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = log2(n)/2;
    sort(v.begin(),v.end());
    long long int p = n/4;
    int c = 1,d = p/4*3*4;
    for(int i = n-p; i< n ; i += d){
        d /= 4;
        if (d == 0)
            d = 1;
        //cout<<d<<endl;
        //cout<<i<<endl;
        for(int j = 0; j < d; j++)
            if(j+i < n)
            sum += v[j+i]*c;
        c++;
    }
    cout<<sum;
}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <math.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<int> v;
    for(int i = 0;  i < n; i++){
        cin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = log2(n)/2;
    sort(v.begin(),v.end());
    long long int p = n/4;
    int c = 1,d = p/4*3*4;
    for(int i = n-p; i< n ; i += d){
        d /= 4;
        if (d == 0)
            d = 1;
        //cout<<d<<endl;
        //cout<<i<<endl;
        for(int j = 0; j < d; j++)
            if(j+i < n)
            sum += v[j+i]*c;
        c++;
    }
    cout<<sum;
}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<int> v;
    for(int i = 0;  i < n; i++){
        fin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = n/4-1;
    sort(v.begin(),v.end());
    long long int p = liv*4+1;
    int c = 0,d;
    for(int i = n-p; i< n ; i += 4){
        c++;
        d = c;
        while(d--){
            for(int j = 0; j < 4; j++){
                if(i+j < n)
                sum += v[i+j];
            }
        }
    }
    cout<<sum;
}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <math.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<int> v;
    for(int i = 0;  i < n; i++){
        cin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = log2(n)/2;
    sort(v.begin(),v.end());
    long long int p = n/4;
    int c = 1,d = p/4*3*4;
    for(int i = n-p; i< n ; i += d){
        d /= 4;
        if (d == 0)
            d = 1;
        cout<<d<<endl;
        cout<<i<<endl;
        for(int j = 0; j < d; j++)
            if(j+i < n)
            sum += v[j+i]*c;
        c++;
    }
    cout<<sum;
}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <math.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<int> v;
    for(int i = 0;  i < n; i++){
        cin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = log2(n)/2;
    sort(v.begin(),v.end());
    long long int p = n/4;
    int c = 0,d;
    for(int i = n-p; i< n ; i += 3*pow(2,liv-1)){
        c++;
        d = c;
        liv--;
        while(d--){
            for(int j = 0; j < 3; j++){
                if(i+j < n)
                sum += v[i+j];
            }
        }
    }
    cout<<sum;
}


#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <math.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");
//int v[5010];

#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n,a;
    long long int sum = 0; // main di test della struttura
    cin>>n;
    vector<int> v;
    for(int i = 0;  i < n; i++){
        cin>>a;
        sum += a;
        v.push_back(a);
    }
    long long int liv = log2(n)/2;
    sort(v.begin(),v.end());
    long long int p = n/4;
    int c = 0,d;
    for(int i = n-p; i< n ; i += 3*pow(2,liv-1)){
        c++;
        d = c;
        liv--;
        for(int j = i; j < n; j++)
            sum += v[j];
    }
    cout<<sum;
}


#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl "\n"

int n;
vector<vector<ll>> mat;
vector<ll> nums;
int pt = 0;

ll fill(int rt, int rb, int cl, int cr) {
    // cout << rt << " " << rb << " " << cl << " " << cr << endl;
    if (rt == rb) {
        return mat[rt][cl] == -1 ? nums[pt++] : mat[rt][cl];
    }
    ll ans = 0;
    int midx = (rt + rb) / 2, midy = (cl + cr)/2;
    vector<ii> cell = {{rt, cl}, {rt, cr}, {rb, cl}, {rb, cr}};
    ll mx = 0;
    for (auto k: cell) {
        if (mat[k.first][k.second] == -1) mat[k.first][k.second] = nums[pt++];
        mx = max(mx, mat[k.first][k.second]);
    }
    ans = mx + fill(rt, midx+1, cl, midy) + fill(rt, midx+1, midy+1, cr) + fill(midx, rb, cl, midy) + fill(midx, rb, midy+1, cr);
    return ans;
}

int main() {
    #ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int lt = round(sqrt(n));
    mat.assign(lt, vector<ll> (lt, -1));
    nums.assign(n, -1);
    for_(i, 0, n) cin >> nums[i];
    sort(nums.begin(), nums.end(), greater<ll>());

    cout << fill(lt-1, 0, 0, lt-1) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl "\n"

int log4(int k) {
    int t = 1, p = 0;
    while (t != k) {
        t *= 4;
        p += 1;
    }
    return p;
}

int main() {
    #ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> nums(n);
    for_(i, 0, n) cin >> nums[i];
    sort(nums.begin(), nums.end(), greater<ll>());

    vector<ll> pref(n);
    pref[0] = nums[0];
    for_(i, 1, n) pref[i] = pref[i-1] + nums[i];
    ll ans = 0;
    for_(i, 0, log4(n)+1) ans += pref[pow(4, i)-1];
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl "\n"

int n;
vector<vector<ll>> mat;
vector<ll> nums;
int pt = 0;

ll fill(int rt, int rb, int cl, int cr, bool rev) {
    // cout << rt << " " << rb << " " << cl << " " << cr << endl;
    if (rt == rb) {
        return mat[rt][cl] == -1 ? nums[pt++] : mat[rt][cl];
    }
    ll ans = 0;
    int midx = (rt + rb) / 2, midy = (cl + cr)/2;
    vector<ii> cell = {{rt, cl}, {rt, cr}, {rb, cl}, {rb, cr}};
    if (rev) reverse(cell.begin(), cell.end());
    ll mx = 0;
    for (auto k: cell) {
        if (mat[k.first][k.second] == -1) mat[k.first][k.second] = nums[pt++];
        mx = max(mx, mat[k.first][k.second]);
    }
    ans = mx + fill(rt, midx+1, cl, midy, !rev) + fill(rt, midx+1, midy+1, cr, !rev) + fill(midx, rb, cl, midy, !rev) + fill(midx, rb, midy+1, cr, !rev);
    return ans;
}

int main() {
    #ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int lt = round(sqrt(n));
    mat.assign(lt, vector<ll> (lt, -1));
    nums.assign(n, -1);
    for_(i, 0, n) cin >> nums[i];
    sort(nums.begin(), nums.end(), greater<ll>());

    cout << fill(lt-1, 0, 0, lt-1, false) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl "\n"

int n;
vector<vector<ll>> mat;
vector<ll> nums;
int pt = 0;

ll fill(int rt, int rb, int cl, int cr) {
    // cout << rt << " " << rb << " " << cl << " " << cr << endl;
    if (rt == rb) {
        return mat[rt][cl] == -1 ? nums[pt++] : mat[rt][cl];
    }
    ll ans = 0;
    int midx = (rt + rb) / 2, midy = (cl + cr)/2;
    vector<ii> cell = {{rt, cl}, {rt, cr}, {rb, cl}, {rb, cr}};
    ll mx = 0;
    for (auto k: cell) {
        if (mat[k.first][k.second] == -1) mat[k.first][k.second] = nums[pt++];
        mx = max(mx, mat[k.first][k.second]);
    }
    ans = mx + fill(rt, midx+1, cl, midy) + fill(rt, midx+1, midy+1, cr) + fill(midx, rb, cl, midy) + fill(midx, rb, midy+1, cr);
    return ans;
}

int main() {
    #ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int lt = round(sqrt(n));
    mat.assign(lt, vector<ll> (lt, -1));
    nums.assign(n, -1);
    for_(i, 0, n) cin >> nums[i];

    cout << fill(lt-1, 0, 0, lt-1) << endl;
    return 0;
}


//Rudrakshi

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define str string
#define pb push_back
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define MAX 1000000
#define mod 1000000007
void solve()
{
    ll n, ans=0;
    cin >> n;
    ll arr[n], a, count=0, it;

    for(ll i=1; i<=n; i++)
    {
        cin >> arr[i];

    }
    ll nn = n;
    while(nn >1)
    {
        nn = nn/4;
        count++;
    }

    a = pow(2,count)+2;
    it = a + pow(2,count);
    //cout << a <<"oo"<<it<<"\n";
    if(n==1)
    ans = arr[1];
    if(n==4 || n>4){
    ans += arr[1]+arr[2]+arr[a]+arr[a-1];
    }
    //cout<<ans<<"pp"<<"\n";
    if(n>4){
    for(ll i=a; i<=n; i=i+it)
    {
     ans += arr[i];
    }
    }
if(n==4)
  cout << ans+arr[a];
  else
  cout << ans;
}
 int main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
    fast;
    ll t =1;
    //cin >> t;
    while(t--)
    	solve();

    return 0;
}


//Rudrakshi

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define str string
#define pb push_back
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define MAX 1000000
#define mod 1000000007
void solve()
{
    ll n, ans=0;
    cin >> n;
    ll arr[n+1], a, count=0, it;

    for(ll i=1; i<=n; i++)
    {
        cin >> arr[i];

    }
    ll nn = n;
    while(nn >1)
    {
        nn = nn/4;
        count++;
    }

    a = pow(2,count)+2;
    it = a + pow(2,count);
    //cout << a <<"oo"<<it<<"\n";
    if(n==1)
    ans = arr[1];
    if(n==4 || n>4){
    ans += arr[1]+arr[2]+arr[a]+arr[a-1];
    }
    //cout<<ans<<"pp"<<"\n";
    if(n>4){
    for(ll i=a; i<=n; i=i+it)
    {
     ans += arr[i];
    }
    }
if(n==4)
  cout << ans+arr[a];
  else
  cout << ans;
}
 int main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
    fast;
    ll t =1;
    //cin >> t;
    while(t--)
    	solve();

    return 0;
}


//Rudrakshi

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define str string
#define pb push_back
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define MAX 1000000
#define mod 1000000007
void solve()
{
    ll n, ans=0;
    cin >> n;
    ll arr[n+1], a, count=0, it;

    for(ll i=1; i<=n; i++)
    {
        cin >> arr[i];

    }
    ll nn = n;
    while(nn >1)
    {
        nn = nn/4;
        count++;
    }
    sort(arr+1, arr+n);
    a = pow(2,count)+2;
    it = a + pow(2,count);
    //cout << a <<"oo"<<it<<"\n";
    if(n==1)
    ans = arr[1];
    if(n==4 || n>4){
    ans += arr[1]+arr[2]+arr[a]+arr[a-1];
    }
    //cout<<ans<<"pp"<<"\n";
    if(n>4){
    for(ll i=a; i<=n; i=i+it)
    {
     ans += arr[i];
    }
    }
if(n==4)
  cout << ans+arr[a];
  else
  cout << ans;
}
 int main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
    fast;
    ll t =1;
    //cin >> t;
    while(t--)
    	solve();

    return 0;
}


//Rudrakshi

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define str string
#define pb push_back
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define MAX 1000000
#define mod 1000000007
void solve()
{
    int n;
    ll ans=0;
    cin >> n;
    vector<int> arr(n);

    for(int i=0; i<n; i++)
    {
        cin >> arr[i];

    }

    	sort(arr.rbegin(), arr.rend());

    	for (int i = 1; i <= n; i *= 4) {
		for (int j = 0; j < i; j++) {
			ans += arr[j];
		}
	}

  cout << ans;
}
 int main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
    fast;
    ll t =1;
    //cin >> t;
    while(t--)
    	solve();

    return 0;
}


//Rudrakshi

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define str string
#define pb push_back
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define MAX 1000000
#define mod 1000000007
void solve()
{
    int n, ans=0;
    cin >> n;
    vector<int> arr(n);

    for(int i=0; i<n; i++)
    {
        cin >> arr[i];

    }

    	sort(arr.rbegin(), arr.rend());

    	for (int i = 1; i <= n; i *= 4) {
		for (int j = 0; j < i; j++) {
			ans += arr[j];
		}
	}

  cout << ans;
}
 int main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
    fast;
    ll t =1;
    //cin >> t;
    while(t--)
    	solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define ACC
int main()
{
    ACC
    ll n,i,j;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n==1)
    {
        cout<<a[0];return 0;
    }
    ll s=0;
    sort(a,a+n,greater<int>());
    for(i=1;i<=n;i=i*4)
    {
        for(j=0;j<i;j++)
        {
            s+=a[j];
        }
    }
    cout<<s<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main()
{
    ll n,i,j;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n==1)
    {
        cout<<a[0];return 0;
    }
    ll s=0;
    sort(a,a+n,greater<int>());
    for(i=1;i<=n;i=i*4)
    {
        for(j=0;j<i;j++)
        {
            s+=a[j];
        }
    }
    cout<<s<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define ACC ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
    ACC
    ll n,i,j;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n==1)
    {
        cout<<a[0];return 0;
    }
    ll s=0;
    sort(a,a+n,greater<int>());
    for(i=1;i<=n;i=i*4)
    {
        for(j=0;j<i;j++)
        {
            s+=a[j];
        }
    }
    cout<<s<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

ll ans=0;

int main()
{
    ll n,i,j,k;
    cin>>n;
    ll ara[n+2];
    for(int i=1;i<=n;i++) cin>>ara[i];

    ll siz=0;
    ll x=n;
    while(x) {x/=4, ++siz;}

    sort(ara+1,ara+n+1,greater<ll>());

    ll tot=0;
    ll last=1;

    for(ll i=1,k=siz;i<=n;i*=4ll,k--)
    {
        ll p=i-tot;
        for(ll j=last,l=1;l<=p;j++,l++) {
                ans+=(k * ara[j]);
        }

        last=last+p, tot+=p;
    }

    cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

ll ans=0;

int main()
{
    ll n,i,j,k;
    scanf("%lld",&n);
    ll ara[n+2];
    for(int i=1;i<=n;i++) scanf("%lld",&ara[i]);

    ll siz=0;
    ll x=n;
    while(x) {x/=4, ++siz;}

    sort(ara+1,ara+n+1,greater<ll>());

    ll tot=0;
    ll last=1;

    for(ll i=1,k=siz;i<=n;i*=4ll,k--)
    {
        ll p=i-tot;
        for(ll j=last,l=1;l<=p;j++,l++) {
                ans+=(k * ara[j]);
        }

        last=last+p, tot+=p;
    }

    printf("%lld\n",ans);

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

ll ans=0;

int main()
{
    ll n,i,j,k;
    scanf("%lld",&n);
    ll ara[n+2];
    for(int i=1;i<=n;i++) scanf("%lld",&ara[i]);

    ll siz=0;
    ll x=n;
    while(x) {x/=4, ++siz;}

    sort(ara+1,ara+n+1);
    reverse(ara+1,ara+n+1);

    ll tot=0;
    ll last=1;

    for(ll i=1,k=siz;i<=n;i*=4ll,k--)
    {
        ll p=i-tot;
        for(ll j=last,l=1;l<=p;j++,l++) {
                ans+=(k * ara[j]);
        }

        last=last+p, tot+=p;
    }

    printf("%lld\n",ans);

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

ll ans=0;

const ll sz=2e6+100;

ll fun(vector<ll> test,ll ele,ll n)
{
    if(ele==1) {
        ans+=test[0];
        return test[0];
    }

    ll p;
    ll x=(ele/4);
    ll siz=sqrt(x);
    vector<ll> temp[4];
    int last=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            p=test[last++];
            if(i<(n/2)){
                if(j<(n/2)) temp[0].push_back(p);
                else temp[1].push_back(p);
            }
            else{
                if(j<(n/2)) temp[2].push_back(p);
                else temp[3].push_back(p);
            }
        }
    }

    ll mx=0;
    for(int i=0;i<4;i++){
        mx=max(mx,fun(temp[i],x,siz));
    }
    ans+=mx;
    return mx;
}

int main()
{
    vector<ll> test;
    ll n,m,i,j;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>m;
        test.push_back(m);
    }

    ll sq=sqrt(n);
    fun(test,n,sq);
    cout<<ans<<endl;
}


/*
 * In The Name Of ALLAH
 * created by Harolinch
 */
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <numeric>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>
#include <string.h>
using namespace std;

typedef long long lint;

typedef vector<lint> vecl;

#define	elin			'\n'

#define all(v)			(v).begin(), (v).end()

#define rep(i, a, n)	for(int i = a; i<=n; i++)

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n;
		in >> n;

		lint sum = 0;
		vecl seq(n, 0);
		rep(i, 0, n - 1) {
			in >> seq[i];
			sum += seq[i];
		}
		sort(all(seq));
		reverse(all(seq));
		rep(i, 1, n - 1) seq[i] += seq[i - 1]; //prefix sum

		lint up = 1;
		lint ans = 0;
		while(up < n){
			ans += (sum + seq[up - 1]);
			up *= 4;
		}
		if(n > 4) ans -= sum;
		out << ans << elin;
		return;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;

    solve(in, out);
    return 0;
}


/*
 * In The Name Of ALLAH
 * created by Harolinch
 */
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <numeric>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>
#include <string.h>
using namespace std;

typedef long long lint;

typedef vector<lint> vecl;

#define	elin			'\n'

#define all(v)			(v).begin(), (v).end()

#define rep(i, a, n)	for(int i = a; i<=n; i++)

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n;
		in >> n;

		lint sum = 0;
		vecl seq(n, 0);
		rep(i, 0, n - 1) {
			in >> seq[i];
			sum += seq[i];
		}
		sort(all(seq));
		reverse(all(seq));
		rep(i, 1, n - 1) seq[i] += seq[i - 1]; //prefix sum
		int t = n;
		int lg4 = 0;
		while(t != 1){
			t /= 4;
			lg4++;
		}

		lint ans = sum * lg4;
		if(lg4 == 0) ans = sum;
		while(n != 1){
			n /= 4;
			ans += seq[n - 1];
		}
		out << ans << elin;
		return;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    istream& in = cin;

    ostream& out = cout;

    solve(in, out);
    return 0;
}