#include <iostream>
#include <stdio.h>
#include <array>
#include <algorithm>
using namespace std;
#define MAX 100
#define gc getchar_unlocked
inline int scan(){register int n=0,c=gc();while(c<'0'||c>'9')c=gc();while(c<='9'&&c>='0')n=(n<<1)+(n<<3)+c-'0',c=gc();return n;}
int getCount(int n[],int len,int c)
{
int i=0;
if(n[i+1]!=9999){
n[i+1]+=n[i];
n[i]=9999;
c+=n[i+1];
sort(n,n+len);
}
if(n[i+1]==9999)return c;
if(len>0) getCount(n,len-1,c);
}
int main()
{
int len=scan();
int j = len;
int n[MAX];
int sum=0;
int i = 0;
while(j--){
n[i++]=scan();
}
j=len;
sort(n,n+len);
sum=getCount(n,len,sum);
cout<<"Sum is="<<sum;
return 0;
}
//STDIN : 4 2 4 3 6
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPGFycmF5PgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIE1BWCAxMDAKCiNkZWZpbmUgZ2MgZ2V0Y2hhcl91bmxvY2tlZAppbmxpbmUgaW50IHNjYW4oKXtyZWdpc3RlciBpbnQgbj0wLGM9Z2MoKTt3aGlsZShjPCcwJ3x8Yz4nOScpYz1nYygpO3doaWxlKGM8PSc5JyYmYz49JzAnKW49KG48PDEpKyhuPDwzKStjLScwJyxjPWdjKCk7cmV0dXJuIG47fQppbnQgZ2V0Q291bnQoaW50IG5bXSxpbnQgbGVuLGludCBjKQp7ICAKICAgIGludCBpPTA7CiAgICBpZihuW2krMV0hPTk5OTkpeyAKICAgIG5baSsxXSs9bltpXTsKICAgIG5baV09OTk5OTsKICAgIGMrPW5baSsxXTsKICAgIHNvcnQobixuK2xlbik7CiAgICB9CiAgICBpZihuW2krMV09PTk5OTkpcmV0dXJuIGM7CiAgICBpZihsZW4+MCkgZ2V0Q291bnQobixsZW4tMSxjKTsKfQoKaW50IG1haW4oKQp7CiAgIGludCBsZW49c2NhbigpOwogICBpbnQgaiA9IGxlbjsKICAgaW50IG5bTUFYXTsKICAgaW50IHN1bT0wOwogICBpbnQgaSA9IDA7CiAgIHdoaWxlKGotLSl7CiAgICAgICBuW2krK109c2NhbigpOwogICB9CiAgIGo9bGVuOwogICAKICAgIHNvcnQobixuK2xlbik7CiAgICBzdW09Z2V0Q291bnQobixsZW4sc3VtKTsKICAgIGNvdXQ8PCJTdW0gaXM9Ijw8c3VtOwogICAgcmV0dXJuIDA7Cn0KLy9TVERJTiA6IDQgMiA0IDMgNg==