#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define cin(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define cin2(a,b,n) for(int i=0;i<n;i++) cin>>a[i]>>b[i]
#define mod 998244353
#define pb push_back
#define pie 3.141592653589793238462643383279
vector<bool> prime;
vector<int> fact,inv,primes,factors;
void factorize(int a)
{
	fact.clear();
	for(int i=1;i*i<=a;i++)
	{
		if (i*i==a) factors.pb(i);
		else if (a%i==0)
		{
			factors.pb(i);
			factors.pb(a/i);
		}
	}
	sort(factors.begin(),factors.end());
}
int power(int a,int b)
{
	if(a==1||b==0)	return 1;
	int c=power(a,b/2);
	int res=1;
	res=c*c;
	if(res>=mod)	res%=mod;
	if(b%2)	res*=a;
	if(res>=mod)	res%=mod;
	return res;
}
int modInv(int a)
{
	return power(a,mod-2);
}
void factorial(int n)
{
	fact.resize(n+1);
	fact[0]=1;
	for(int i=1;i<=n;i++)
	{
		fact[i]=fact[i-1]*i;
		if(fact[i]>=mod)	fact[i]%=mod;
	}
}
void InvFactorial(int n)
{
	inv.resize(n+1);
	inv[0]=1;
	for(int i=1;i<=n;i++)	inv[i]=modInv(fact[i]);
}
int ncr(int n,int r)
{
	if(n<r||n<0||r<0)	return 0;
	int b=inv[n-r];
	int c=inv[r];
	int a=fact[n]*b;
	if(a>=mod)	a%=mod;
	a*=c;
	if(a>=mod)	a%=mod;
	return a;
}
void remove_duplicates(vector<pair<int,int>> &v)
{
	sort(v.begin(),v.end());
	int _size=unique(v.begin(),v.end())-v.begin();
	v.resize(_size);
}
unsigned int gcd(unsigned int u, unsigned int v)
{
    if(u==0||v==0) return max(u,v);
    unsigned int shift=__builtin_ctz(u|v);
	u>>=__builtin_ctz(u);
    do{
    	v>>=__builtin_ctz(v);
    	if(u>v)	swap(u,v);
    	v-=u;
    }while(v!=0);
    return u<<shift;
}
void sieve(int n)
{
    prime.assign(n+1,1);
	prime[1]=false;
    for(int p=2;p*p<=n;p++) if(prime[p])	for(int i=p*p;i<=n;i+=p)	prime[i]=false;
    for(int i=2;i<n+1;i++) if(prime[i]) primes.push_back(i);
}
//----------------------------------------------------------------------------------------------------------------------------------------------------
void solve()
{
	int n;
	cin>>n;
	int a[n];
	cin(a,n);
	sort(a,a+n);
	int sum=0,exp=a[0];
	for(int i=1;i<n;i++)
	{
		sum=(sum+a[i]*exp)%mod;
		exp=(2*exp+a[i])%mod;
	}
	for(int i=0;i<n;i++) sum=(sum+a[i]*a[i])%mod;
	cout<<sum;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//cin>>T;
	for(int i=1;i<=T;i++) solve();
}
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int N = 0;
    cin >> N;
    vector<long long> A(N, 0);
    for(int i = 0; i < A.size(); i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    long long MOD = 998244353;
    long long ans = 0;
    for(int i = 0; i < A.size(); i++){
        ans = (ans + (A[i] * A[i]) % MOD) % MOD;
    }
    if(N != 1){
        vector<long long> sub(N-1,0);
        sub[N-2] = A[N-1];
        for(int i = N-3;i >= 0;i--){
            sub[i] = (((sub[i+1] * 2) % MOD) + A[i+1]) % MOD;
        }

        for(int i = 0; i < sub.size(); i++){
            sub[i] = (sub[i] * A[i]) % MOD;
        }

        for(int i = 0; i < sub.size(); i++){
            ans = (ans + sub[i]) % MOD;
        }
    }

    cout << ans << endl;

    return 0;
}