#include<bits/stdc++.h>
#define N 105
#define M 100005
using namespace std;
int n,t[N],m,f[M]={1};
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>t[i],m+=t[i];
	for(int i=1;i<=n;i++)
		for(int j=m;j>=t[i];j--)f[j]|=f[j-t[i]];
	for(int i=(m+1)/2;i<=m;i++)
		if(f[i])cout<<i<<endl,exit(0);
	return 0;
}
/*  CREATED BY
    STREAM_CIPHER
    dec-2020
*/
#include<bits/stdc++.h>
using namespace std;
void __print(long long x) {cerr << x;}void __print(unsigned long long x) {cerr << x;}void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long int
#define double long double
#define fix_precision(n) cout<<fixed<<setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
// const int mod=998244353;
const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit)
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
        int n;
        cin>>n;
        vector<int>a(n);
        for(auto &i:a)
        	cin>>i;
        int ans=0;
        sort(all(a));
        for(int i=n-1;i>=0;i--)
        	ans+=i*a[i]-(n-1-i)*a[i];
        cout<<ans<<endl;
}
//always use s.lower_bound instead of lower_bound(all(s))
//also whenever there exist an standerd method for stl container prefer that
//otherwise this will happen
//https://codeforces.com/contest/1435/submission/96683823//tle
//https://codeforces.com/contest/1435/submission/96703923//accepted