#include <bits/stdc++.h>
using namespace std;
int n,a,i,c,d;
int main(){
scanf("%d",&n);
priority_queue<int, vector<int>, greater<int> >s;
priority_queue<int> b;
for(i=1;i<=n;i++){
scanf("%d",&a);
s.push(a);
b.push(a);
}
while(s.size()>1){
int k1=s.top();
s.pop();
int k2=s.top();
s.pop();
c+=k1+k2;
s.push(k1+k2);
}
while(b.size()>1){
int x1=b.top();
b.pop();
int x2=b.top();
b.pop();
d+=x1+x2;
b.push(x1+x2);
}
if(n!=1) printf("%d\n%d",c,d);
else printf("%d\n%d",a,a);
return 0;
}