Language: C++

/* mamba mentality */
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
#define int long long
typedef pair<int,int> pii;
#define RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i <n; i++)
#define repv(i,k,n) for(int i=k; i<=n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define endl '\n'
#define deb(x) cout<<#x<<" = "<<x<<endl
#define gcd __gcd
#define inf LLONG_MAX
#define minf LLONG_MIN 
const int mod = (int)(1e9+7);

int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}

int dx[]    =  { 1 ,  0,  -1,  0,  -1, -1, 1,  1};
int dy[]    =  { 0 ,  1,   0, -1,  -1,  1, 1, -1};
char dir[]  =  {'D','R','U','L'};

const int maxn =100005;

/* ------------------------------------------------------- */



void solve()
{
    int n,i,j,k,m;
    cin>>n;
    int ar[n];
    m=0;
    rep(i,n)
        cin>>ar[i];
    sort(ar,ar+n);
    m += ar[n-1];
    int e = 2 , cnt = n-2;
    for(i=n-2; i>=0 && cnt; )
    {
        if(e)
            m += ar[i] , e-- ,cnt--;
        else
            e=2 , i--;
    }
    cout<<m;
}  
signed main()
{
    RAGE;

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

    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}
/* mamba mentality */
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
#define int long long
typedef pair<int,int> pii;
#define RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i <n; i++)
#define repv(i,k,n) for(int i=k; i<=n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define endl '\n'
#define deb(x) cout<<#x<<" = "<<x<<endl
#define gcd __gcd
#define inf LLONG_MAX
#define minf LLONG_MIN 
const int mod = (int)(1e9+7);

int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}

int dx[]    =  { 1 ,  0,  -1,  0,  -1, -1, 1,  1};
int dy[]    =  { 0 ,  1,   0, -1,  -1,  1, 1, -1};
char dir[]  =  {'D','R','U','L'};

const int maxn =100005;

/* ------------------------------------------------------- */



void solve()
{
    int n,i,j,k,m;
    cin>>n;
    int ar[n];
    m=0;
    rep(i,n)
        cin>>ar[i];
    sort(ar,ar+n);
    m += ar[n-1];
    int e = 2 , cnt = n-2;
    for(i=n-2; i>=0 && cnt; )
    {
        if(e)
            m += ar[i] , e-- ,cnt--;
        else
            e=2 , i--;
    }
    cout<<m;
}  
signed main()
{
    RAGE;

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

    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}
/* mamba mentality */
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
#define int long long
typedef pair<int,int> pii;
#define RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i <n; i++)
#define repv(i,k,n) for(int i=k; i<=n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define endl '\n'
#define deb(x) cout<<#x<<" = "<<x<<endl
#define gcd __gcd
#define inf LLONG_MAX
#define minf LLONG_MIN 
const int mod = (int)(1e9+7);

int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}

int dx[]    =  { 1 ,  0,  -1,  0,  -1, -1, 1,  1};
int dy[]    =  { 0 ,  1,   0, -1,  -1,  1, 1, -1};
char dir[]  =  {'D','R','U','L'};

const int maxn =100005;

/* ------------------------------------------------------- */



void solve()
{
    int n,i,j,k,m;
    cin>>n;
    int ar[n];
    m=0;
    rep(i,n)
        cin>>ar[i];
    sort(ar,ar+n);
    m += ar[n-1];
    int e = 2 , cnt = n-2;
    for(i=n-2; i>=0 && cnt; )
    {
        if(e)
            m += ar[i] , e-- ,cnt--;
        else
            e=2 , i--;
    }
    cout<<m;
}  
signed main()
{
    RAGE;   
    int t=1;
    //  cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Compiler output:
a.cc:105:11: error: redefinition of 'const long long int mod'
  105 | const int mod = (int)(1e9+7);
      |           ^~~
a.cc:21:11: note: 'const long long int mod' previously defined here
   21 | const int mod = (int)(1e9+7);
      |           ^~~
a.cc:107:5: error: redefinition of 'long long int power(long long int, long long int)'
  107 | int power(int x,int n)
      |     ^~~~~
a.cc:23:5: note: 'long long int power(long long int, long long int)' previously defined here
   23 | int power(int x,int n)
      |     ^~~~~
a.cc:115:6: error: redefinition of 'bool is_power_2(long long int)'
  115 | bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
      |      ^~~~~~~~~~
a.cc:31:6: note: 'bool is_power_2(long long int)' previously defined here
   31 | bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
      |      ^~~~~~~~~~
a.cc:116:6: error: redefinition of 'bool is_prime(long long int)'
  116 | bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
      |      ^~~~~~~~
a.cc:32:6: note: 'bool is_prime(long long int)' previously defined here
   32 | bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
      |      ^~~~~~~~
a.cc:118:5: error: redefinition of 'long long int dx []'
  118 | int dx[]    =  { 1 ,  0,  -1,  0,  -1, -1, 1,  1};
      |     ^~
a.cc:34:5: note: 'long long int dx [8]' previously defined here
   34 | int dx[]    =  { 1 ,  0,  -1,  0,  -1, -1, 1,  1};
      |     ^~
a.cc:119:5: error: redefinition of 'long long int dy []'
  119 | int dy[]    =  { 0 ,  1,   0, -1,  -1,  1, 1, -1};
      |     ^~
a.cc:35:5: note: 'long long int dy [8]' previously defined here
   35 | int dy[]    =  { 0 ,  1,   0, -1,  -1,  1, 1, -1};
      |     ^~
a.cc:120:6: error: redefinition of 'char dir []'
  120 | char dir[]  =  {'D','R','U','L'};
      |      ^~~
a.cc:36:6: note: 'char dir [4]' previously defined here
   36 | char dir[]  =  {'D','R','U','L'};
      |      ^~~
a.cc:122:11: error: redefinition of 'const long long int maxn'
  122 | const int maxn =100005;
      |           ^~~~
a.cc:38:11: note: 'const long long int maxn' previously defined here
   38 | const int maxn =100005;
      |           ^~~~
a.cc:128:6: error: redefinition of 'void solve()'
  128 | void solve()
      |      ^~~~~
a.cc:44:6: note: 'void solve()' previously defined here
   44 | void solve()
      |      ^~~~~
a.cc:148:8: error: redefinition of 'int main()'
  148 | signed main()
      |        ^~~~
a.cc:64:8: note: 'int main()' previously defined here
   64 | signed main()
      |        ^~~~
a.cc:189:11: error: redefinition of 'const long long int mod'
  189 | const int mod = (int)(1e9+7);
      |           ^~~
a.cc:21:11: note: 'const long long int mod' previously defined here
   21 | const int mod = (int)(1e9+7);
      |           ^~~
a.cc:191:5: error: redefinition of 'long long int power(long long int, long long int)'
  191 | int power(int x,int n)
      |     ^~~~~
a.cc:23:5: note: 'long long int power(long long int, long long int)' previously defined here
   23 | int power(int x,int n)
      |     ^~~~~
a.cc:199:6: error: redefinition of 'bool is_power_2(long long int)'
  199 | bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
      |      ^~~~~~~~~~
a.cc:31:6: note: 'bool is_power_2(long long int)' previously defined here
   31 | bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
      |      ^~~~~~~~~~
a.cc:200:6: error: redefinition of 'bool is_prime(long long int)'
  200 | bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
      |      ^~~~~~~~
a.cc:32:6: note: 'bool is_prime(long long int)' previously defined here
   32 | bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
      |      ^~~~~~~~
a.cc:202:5: error: redefinition of 'long long int dx []'
  202 | int dx[]    =  { 1 ,  0,  -1,  0,  -1, -1, 1,  1};
      |     ^~
a.cc:34:5: note: 'long long int dx [8]' previously defined here
   34 | int dx[]    =  { 1 ,  0,  -1,  0,  -1, -1, 1,  1};
      |     ^~
a.cc:203:5: error: redefinition of 'long long int dy []'
  203 | int dy[]    =  { 0 ,  1,   0, -1,  -1,  1, 1, -1};
      |     ^~
a.cc:35:5: note: 'long long int dy [8]' previously defined here
   35 | int dy[]    =  { 0 ,  1,   0, -1,  -1,  1, 1, -1};
      |     ^~
a.cc:204:6: error: redefinition of 'char dir []'
  204 | char dir[]  =  {'D','R','U','L'};
      |      ^~~
a.cc:36:6: note: 'char dir [4]' previously defined here
   36 | char dir[]  =  {'D','R','U','L'};
      |      ^~~
a.cc:206:11: error: redefinition of 'const long long int maxn'
  206 | const int maxn =100005;
      |           ^~~~
a.cc:38:11: note: 'const long long int maxn' previously defined here
   38 | const int maxn =100005;
      |           ^~~~
a.cc:212:6: error: redefinition of 'void solve()'
  212 | void solve()
      |      ^~~~~
a.cc:44:6: note: 'void solve()' previously defined here
   44 | void solve()
      |      ^~~~~
a.cc:232:8: error: redefinition of 'int main()'
  232 | signed main()
      |        ^~~~
a.cc:64:8: note: 'int main()' previously defined here
   64 | signed main()
      |        ^~~~