#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define F first
#define S second
#define PI  4.0*atan(1.0);
#define pb push_back
using namespace std;
int mod=1e9+7,gaymod=998244353,MAX=1000000000,pomod=1073741824;
//long long int gcd(long long int x,long long int  y){
  // if(y==0)return x;
   //return gcd(y,x%y);
//}
int gcd(int x,int  y){
   if(y==0)return x;
   return gcd(y,x%y);
}
ll lcm(ll a, ll b)
{
    ll g=gcd(a, b);
    return a/g*b;
}
ll binexp(ll a,ll b){
if(b==0)return 1;
ll res=binexp(a,b/2);
if(b%2)return((res%mod)*(res%mod)*(a%mod));
else return((res%mod)*(res%mod));
}
int prime(ll x){
if(x%2==0&&x!=2)
return 0;
else{
    for(int i=3;ll(i*i)<=x;i+=2){
        if(x%i==0)
            return 0;
    }
}
return 1;
}
//main
/*
vector<char> is_prime(N+1, true);
void sieve(int n){
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
    if (is_prime[i] && (long long)i * i <= n) {
        for (int j = i * i; j <= n; j += i)
            is_prime[j] = false;
    }
}
}
*/
//freopen("input.txt","r",stdin);
//freopen("input.txt","w",stdin);
const int N=2e5+5;
//
int main(){
IOS;
int t=1;
//cin>>t;
while(t--){
int n;
cin>>n;
ll arr[n];
for(int i=0;i<n;i++)cin>>arr[i];
sort(arr,arr+n);
ll ans=((arr[0]*arr[0])%gaymod),sum=(arr[0]%gaymod);
for(int i=1;i<n;i++){
    sum=2*sum-arr[i-1];
    sum+=arr[i];
    sum%=gaymod;
    ans+=sum*(arr[i]%gaymod);
    ans%=gaymod;
}
cout<<ans;
cout<<"\n";
}
return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll unsigned long long int
#define endl "\n"
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll a;
    cin>>a;
    int aa[a];
    int bb[a];
    for(int i=0;i<a;i++){
        cin>>aa[i];
    }
    for(int j=0;j<a;j++){
        cin>>bb[j];
    }
    ll q=aa[0];
    ll maxi=*max_element(aa,aa+a);
    ll mini=*min_element(bb,bb+a);
    if(maxi>mini){
        cout<<0;


    }
    else{
        cout<<mini-maxi +1;
    }
}