#define ll long long
#define lld double
#define M 202
#define f first
#define s second
#define pi 3.141592653589793238
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define N 100002
#define Endl endl
#define maxx(a,b,c,d) max(max(a,b),max(d,c))
#define minn(a,b,c,d) min(min(a,b),min(d,c))
#define pb push_back
#define mod 1000000007  
#define pp 31
#define ss(v) sort(v.begin(),v.end())
#define sr(v) sort(v.begin(),v.end(),greater<pll>())
#define rin(A, B, C) (((A)<=(B))&&((B)<=(C)))
#include <bits/stdc++.h>
using namespace std;
ll power(ll a, ll b)
{
	if(!b)return 1LL;
	ll aa=power(a,b/2);
	if(b%2)return aa*aa%mod*a%mod;
	return aa*aa%mod;
}
ll im(ll a)
{
	return power(a,mod-2);
}
// ll ncr(ll n,ll r)
// {
// 	return f[n]*im(f[r])%mod*im(f[n-r])%mod;
// }
bool check(ll n)
{
	ll m=n;
	while(n)
	{
		if(n%10!=0 && m%(n%10)!=0)
		{
			return false;
		}
		n/=10;
	}
	return true;
}
pll ol(ll a, ll b, ll c, ll d)
{
	a=max(a,c);
	b=min(b,d);
	return {a,b};
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// freopen("output.txt", "w", stdout);
	// freopen("input.txt", "r", stdin);
    ll a,b;
	cin>>a>>b;
	ll ans1=0,ans2=0;
	while(a)
	{
		ans1+=a%10;
		a/=10;
	}
	while(b)
	{
		ans2+=b%10;
		b/=10;
	}
	cout<<max(ans1,ans2)<<endl;

	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  static int get_mod() { return mod; }
};
constexpr int MOD = 998244353;
using mint = ModInt< MOD >;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());

  mint ans = 0;
  mint sum = 0, base = 1;
  for(int i = 0; i < n; i++){
    sum += base * a[i];
    base *= 2;
  }

  mint inv2 = mint(2).inverse();

  for(int i = 0; i < n; i++){
    ans += mint(a[i]) * a[i];
    sum -= a[i];
    sum *= inv2;
    ans += sum * a[i];
  }

  cout << ans << endl;
}