#include <functional>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

template<class T>
unsigned long long pair_join(priority_queue<unsigned long long, vector<unsigned long long>, T> &q) {
        unsigned long long r=0;
        while (q.size()>1) {
            unsigned long long a = q.top();
            q.pop();
            unsigned long long b = q.top();
            q.pop();
            q.push(a+b);
            r += a+b;
        }
        return r;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >>n;
    vector<unsigned long long> data;
    for (int i=0; i<n; i++) {
        unsigned long long v;
        cin >>v;
        if (v>0)
            data.push_back(v);
    }
    priority_queue<unsigned long long, vector<unsigned long long>, 
        greater<unsigned long long>> minq(data.begin(), data.end());
    priority_queue<unsigned long long, vector<unsigned long long>, 
        less<unsigned long long>> maxq(data.begin(), data.end());
 
    cout <<pair_join(minq)<<" "<<pair_join(maxq)<<endl;
}