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

#define int long long
#define fl(i,n) for(int i=0;i<n;i++) 
#define v(i) vector<int>
#define um unordered_map<int,int> 
#define pb push_back
#define pr pair<int,int>
#define NO cout<<"NO";
#define all(a) a.begin(),a.end()
#define YES cout<<"YES"; 
#define sortn(a) sort(a.begin(),a.end())
#define sortc(a,cp) sort(a.begin(),a.end(),cp)
#define pq priority_queue<int> 
#define vvi vector<v(i)>
#define reverse(a) reverse(a.begin(),a.end()) 
#define mp make_pair
/* lcm(a,b) , _gcd(a,b) , swap(a,b) , sort(a.begin(),a.end()) , *max_element(a.begin(),a.end()) , *min_element(a.begin(),a.end()) */
/* _builtin_popcount(x): This function is used to count the number of one’s */
/*__builtin_clz(x): This function is used to count the leading zeros of the integer. */
/* string s.find("ks")==string::npos if not found */
/*__builtin_ctz(x): This function is used to count the trailing zeros of the given integer */
/* cout<<fixed<<setprecision(8)   ,  round(1.589) -> 2 , trunc(1.590) -> 1 , ceil(x) , floor(x) */

void SieveOfEratosthenes(int n) 
{ 
    
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
      
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 

} 
int power(int x, int y, int m) 
{ 
    if (y == 0) 
        return 1; 
    int p = power(x, y / 2, m) % m; 
    p = (p * p) % m; 
  
    return (y % 2 == 0) ? p : (x * p) % m; 
}   

/* inverse of y is power(y,p-2,p) */



void print(v(i) a){
fl(i,a.size())
cout<<a[i]<<" ";
cout<<"\n";
}
int gcd( int a, int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
 

int lcm(int a, int b)
{
    return (a / gcd(a, b)) * b;
}

bool cmp(int a,int b){ return a>b;}

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n; cin>>n;
    v(i) a(n);
    int s=0;
    fl(i,n) cin>>a[i],s+=a[i];
    sortn(a);
    int ans=0,m=998244353;
    int p=0;
    for(int i=n-1;i>=0;i--){
        ans=(ans+a[i]*p)%m;
        p*=2;
        p+=a[i];
        p=p%m;
        ans=(ans+m)%m;
    }
    fl(i,n) {
        ans=(ans+a[i]*a[i])%m;
        ans=(ans+m)%m;
    }
    cout<<ans;

}

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 998244353
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

ll powa(ll a, ll b, ll c)
{
    a%=c;
    if(a<0)
	a+=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}

ll norm(ll a)
{
    a%=mod;
    if(a<0)
        a+=mod;
    return a;    
}
 
ll add(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a+b);
}
 
ll mul(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a*b);
}
 
 
ll sub(ll a, ll b)
{
    a = norm(a);
    b = norm(b);
    return norm(a-b);
}
 
ll divi(ll a, ll b)
{
    b = powa(b,mod-2,mod);
    return mul(a,b);
}

int main()
{
  FAST/**/
  
 
      ll n;
      cin>>n;
      
      ll arr[n];
      rep(n)
            cin>>arr[i];
      map<ll,ll> ma;
      rep(n)
            ma[arr[i]]++;
      vector<pii> v;
      autoit(ma,it)
            v.pb(*it);
      ll siz = v.size();        
      ll pref[siz];
      pref[0] = mul(powa(2,v[0].ss,mod) - 1, v[0].ff);
      for(ll i=1;i<siz;i++){
            pref[i] = divi(pref[i-1], (powa(2, v[i-1].ss, mod) - 1)*v[i-1].ff);
            pref[i] = mul(pref[i], (powa(2, v[i].ss, mod) - 1)*v[i].ff);
            pref[i] = mul(pref[i], powa(2, v[i-1].ss, mod));
            //cout<<pref[i]<<'\n';
      }
      for(ll i=1;i<siz;i++)
            pref[i] = (pref[i-1] + pref[i])%mod;
      ll mul1 = 1;
      ll ans = 0;
      for(ll i=1;i<siz;i++)
      {
          mul1 = (mul1 * powa(2, v[i-1].ss, mod))%mod;
          ll diff = (pref[siz-1] - pref[i-1] + mod)%mod;
          ll temp = (diff*powa(mul1,mod-2,mod))%mod;
          temp = (temp*v[i-1].ff)%mod;
          temp = mul(temp, powa(2, v[i-1].ss, mod) - 1);
          ans = (ans + temp)%mod;
      }
      
     // cout<<"init = "<<ans<<'\n';
      
      for(ll i=0;i<siz;i++)
      {
          ll temp = sub(powa(2, v[i].ss, mod), 1);
          temp = mul(mul(v[i].ff, v[i].ff), temp);
          ans = add(ans, temp);
      }
      
      cout<<ans<<'\n';
  
  
  return 0;
}
   
   
 