//重复时最小值可以为0
include [HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
const int N=10010;
int a[N];
int n;
int main(){
cin>>n;
long long maxsum=0;
long long min;
long long minsum=0;
for(int i=0;i[HTML_REMOVED]>a[i];
maxsum+=a[i];
}
minsum+=a[0];
long long last=a[0];
for(int i=1;i<n;i++){
if(a[i]>last) last=a[i],minsum+=last;
else minsum+=0;
}
cout<<maxsum<<endl<<minsum;
}