#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
ll A[202020];
const ll mo=998244353;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	sort(A,A+N);
	ll ret=0;
	ll sum=0;
	FOR(i,N) {
		(ret=ret+(sum+A[i])*A[i])%=mo;
		sum=(sum*2+A[i])%mo;
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include <bits/stdc++.h>
using namespace std;

// ascii value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space

#define int long long
#define endl "\n"
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))


#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

// use error(args..)
const long long INF=1e18;
const int32_t MOD=1e9+7;
const int32_t MM=998244353;
const int N=2e7+5;

void solve() {

    int n;
    cin>>n;

    vector <int> v(n);
    int sum = 0;

    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        sum += v[i];
    }

    vector <bool> dp(sum + 1);
    dp[0] = true;

    int ans = 1e18;

    for(int i=0; i<n; i++)
    {
        for(int j = sum; j>= v[i]; j--)
            dp[j] = dp[j] | dp[j - v[i]];
    }

    for(int i = 0; i<=sum; i++)
    {
        //cout<<i<<" "<<dp[i]<<endl;
        if(dp[i])
        {
            ans = min(ans, max(i, sum-i));
        }
    }



    cout<<ans<<endl;

   

}

signed main() {

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
    freopen("newop.txt", "w", stdout);
    #endif
  
    int t = 1;


    // cin>>t;


    while(t--)
    solve();
    return 0;
}