#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector A(N); for(auto &a : A) cin >> a; sort(A.begin(),A.end()); int l = 0,r = N-1; long long answer = 0; while(l <= r){ answer += A.at(r--); if(l > r) break; answer += A.at(l++); } cout << answer << "\n"; }