You are given two arrays a and b, both of length n.

Let's define a function f(l, r) = ∑_{l ≤ i ≤ r} a_i ⋅ b_i.

Your task is to reorder the elements (choose an arbitrary order of elements) of the array b to minimize the value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r). Since the answer can be very large, you have to print it modulo 998244353. Note that you should minimize the answer but not its remainder.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and b.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.

The third line of the input contains n integers b_1, b_2, ..., b_n (1 ≤ b_j ≤ 10^6), where b_j is the j-th element of b.

Output

Print one integer — the minimum possible value of ∑_{1 ≤ l ≤ r ≤ n} f(l, r) after rearranging elements of b, taken modulo 998244353. Note that you should minimize the answer but not its remainder.

Examples

Input


5
1 8 7 2 4
9 7 2 9 3


Output


646


Input


1
1000000
1000000


Output


757402647


Input


2
1 3
4 2


Output


20
//////////////////////////////////////
////   Author: ABHINASH GIRI      ////
/////////////////////////////////////

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define PI (2*acos(0.0))
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int t; cin>>t; while(t--)
#define nl "\n"
#define all(v) v.begin(),v.end()
#define clr(v) memset(v,0,sizeof(v));
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<unsigned long long int> vull;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<string, string>> vpss;

//***********************************************************************************************

//CONSTANTS
const long long int inf = 1e18;
const long long int ninf = -1e18;
const long long int MOD = 1000000007;
const long long int mod =  998244353;
//***********************************************************************************************

//Debug code

#define debug1(x)                   cout<<#x<<"="<<x<<'\n'
#define debug2(x,y)                 cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define debug3(x,y,z)               cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

//***********************************************************************************************
// Printing
#define ptvs(v) for(auto &item :v) cout<<item<<" ";cout<<"\n"
#define ptp(v) for(auto &item :v) cout<<item.first<<" "<<item.second<<"\n"
#define ptv(v) for(auto &item :v) cout<<item<<"\n"
#define ptb(ans) cout<<(ans?"YES\n":"NO\n")
#define pt(x) cout<<x<<"\n";
#define pts(x,y) cout<<x<<" "<<y<<"\n";

//Take input
#define get1(a) cin>>a
#define get2(a,b) cin>>a>>b
#define get3(a,b,c) cin>>a>>b>>c
#define cinll(i) ll i=0;cin>>i
#define cins(s) string s;cin>>s
#define cinvll(v,n) vll v(n);for(auto i=0;i<n;i++) {cin>>v[i];}

//***********************************************************************************************
//Sorting Comparators

// sorts in ascending order on first and on second ( if first equals)
template <typename T>
bool asc(pair<T,T>&a,pair<T,T>&b)
{
    if(a.first==b.first)
    {return a.second<b.second;}
    return a.first<b.first;
}

// sorts in descending order on first and on second ( if first equals)
template <typename T>
bool desc(pair<T,T>&a,pair<T,T>&b)
{
    if(a.first==b.first)
    {return a.second>b.second;}
    return a.first>b.first;
}

//***********************************************************************************************

// Fast Exponentiation power(a,b) ==> a to the power b
template <typename T>
T  power(T  a, T  b) {
    if (b == 0)
        return 1;
    if (b == 1)
        return a;
    else {
        T  res = (power(a, b / 2));
        if (b % 2)
        {
            return (res * res * a);
        }
        else
        {return res * res;}
    }
}

// Fast Modular Exponentiation  power(a,b,m) ==> (a to the power b) modulo m
template <typename T>
T  power(T  a, T  b, T modulo) {
    if (b == 0)
        return 1;
    if (b == 1)
        return a;
    else {
        T  res = (power(a, b / 2, modulo) % modulo);
        if (b % 2)
        {
            return ((((res % modulo) * (res % modulo)) % modulo) * (a % modulo)) % modulo;
        }
        else
        {return ((res % modulo) * (res % modulo)) % modulo;}
    }
}

// G C D
template <typename T>
T  gcd(T  a, T  b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

// L C M
template <typename T>
T lcm(T p, T q)
{
    return (p * q) / gcd<T>(p, q);
}
//Prime factorisation
template <typename T>
void primefactorise(T n,vector<T>&vec)
{
    while (n % 2 == 0) {
        vec.emplace_back(2);
        n = n / 2;
    }
    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            vec.emplace_back(i);
            n = n / i;
        }
    }
    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
    {
        vec.emplace_back(n);
    }
}

// All factors of a number in O(sqrt(n))
template <typename T>
void all_factor(T n,vector<T>&vec)
{
    for (auto i = 1; i <=sqrt(n) ; ++i) {
        if(n%i==0)
        {
//          Factors occurs in pairs
            vec.emplace_back(i);
            vec.emplace_back(n/i);
        }
    }
}

ll mulmod(ll a, ll b, ll c)
{
    // base case if b==0, return 0
    if (b == 0)
    {
        //cout<<"returned 0\n";
        return 0;
    }
    // Divide the problem into 2 parts
    ll s = mulmod(a, b / 2, c);

    // If b is odd, return
    // (a+(2*a)*((b-1)/2))%c
    if (b % 2 == 1)
    {   ll p = (a % c + 2 * (s % c)) % c;
        //cout<<" returned "<<p<<endl;
        return p;
    }
        // If b is even, return
        // ((2*a)*(b/2))%c
    else
    {   ll  p = (2 * (s % c)) % c;
        //cout<<" returned "<<p<<endl;
        return p ;
    }
}

bool valid(string &s,ll len,ll k)
{
    map<char,int>mp;
    deque<char>dq;
    for (ll i = 0; i <len ; ++i) {
        dq.emplace_back(s[i]);
        mp[s[i]]++;
    }
    ll diff = min(mp['a'],mp['b']);
    if(diff<=k)
    {
        return true;
    }
    ll e=dq.size();
    for (ll j = 0; j <s.length()-len ; ++j) {
        mp[s[e]]++;
        mp[dq.front()]--;
        dq.emplace_back(s[e++]);
        dq.pop_front();
        ll d = min(mp['a'],mp['b']);
        if(d<=k)
        {
            return true;
        }
    }
    return false;
}

ll mod_inv(ll a) {    return (power<ll>(a,mod-2,mod))%mod;    }

ll ncr(ll n,ll r,vll &fact)
{
    return (((fact[n]%mod*mod_inv(fact[n-r])%mod)%mod)*mod_inv(fact[r])%mod)%mod;
}

void factorial(ll n,vll fact)
{
    fact.resize(n+1,1);
    fact[0]=1;
    fact[1]=1;
    for (int i = 2; i <=n ; ++i)
    {
        fact[i]=((fact[i-1]%mod)*(i%mod))%mod;
    }
}

int main() {
    std::chrono::time_point<std::chrono::high_resolution_clock> start_timer, end_timer;
    start_timer = std::chrono::high_resolution_clock::now();
    bool show_time = false;  //  change it to true when needed;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
    /* Building Block */
    fast;
    cinll(n);
    vpll a;
    ll x;
    a.emplace_back(make_pair(0,0));
    for (int i = 1; i <=n ; ++i) {
        cin>>x;
        auto l = make_pair(x,i*(n-i+1));
        a.emplace_back(l);
        //cout<<a[i].first<<" "<<a[i].second<<"\n";
    }
    //ptp(a);
    sort(all(a),asc<ll>);
    //ptp(a);
    vll b(n+1,0);
    for (int i = 1; i <=n ; ++i)
    {
        cin>>b[i];
    }
    sort(all(b),greater<>());
    //ptvs(b);
    ll ans =0;
    for (int i = 1; i <=n ; ++i) {
        //cout<<a[i].first<<" "<<a[i].second<<" "<<b[i-1]<<"\n";
        ll p = ((a[i].first%mod)*(b[i-1]%mod*a[i].second%mod)%mod)%mod;
//        pt(p);
        ans = (ans%mod+p%mod)%mod;
    }
    pt(ans);
    end_timer = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_timer - start_timer).count();
    if (show_time)
    {cout << "\nElapsed Time: " << elapsed_time << "ms\n";}

    return 0;
}


//w(t)
//{
//ll p,q,r,a,b,c;
//cin>>p>>q>>r>>a>>b>>c;
//if(p==a and q==b and r==c)
//{
//cout<<0<<"\n";
//continue;
//}
//if((a-p==b-q and b-q==c-r))
//{
//cout<<1<<"\n";
//continue;
//}
//
//if(p and q and r)
//{
//if(a%p==0 and b%q==0 and c%r==0 and a/p==b/q and b/q==c/r)
//{
//cout<<1<<"\n";
//continue;
//}
//}
//ll d1,d2,d3;
//d1=a-p;
//d2=b-q;
//d3=c-r;
//set<ll>s;
//if(d1) s.insert(d1);
//if(d2) s.insert(d2);
//if(d3) s.insert(d3);
//if(s.size()==1)
//{
//cout<<1<<"\n";
//continue;
//}
//// check for 2
//if(p==0 and q and r)
//{
//
//}
//if((a%p==d2 and d2==d3) or (b%q==d1 and d1==d3) or (c%r==d2 and d2==d1) or (a%p==b%q and b%q==d3) or (d1==b%q and b%q==c%r) or (a%p==b%q and c%r==d2) )
//{
//cout<<2<<"\n";
//}
//else if((b%q==0 and c%r==0 and b/q==c/r and a%(a-a%p+p)==0 and a/(a-a%p+p)==b/q)
//or (a%p==0 and c%r==0 and a/p==c/r and b%(b-b%q+q)==0 and b/(b-b%q+q)==a/p)
//or (b%q==0 and a%p==0 and b/q==a/p and c%(c-c%r+r)==0 and c/(c-c%r+r)==b/q)
//or (a%p==0 and b/(b-b%q+q)==c/(c-c%r+r) and b/(b-b%q+q)==a/p)
//or (b%q==0 and a/(a-a%p+p)==c/(c-c%r+r) and a/(a-a%p+p)==b/q)
//or (c%r==0 and a/(a-a%p+p)==b/(b-b%q+q) and a/(a-a%p+p)==c/r)
//or ( a/(a-a%p+p)==b/(b-b%q+q) and a/(a-a%p+p)==c/(c-c%r+r)))
//{
//cout<<2<<"\n";
//}
//else cout<<3<<"\n";
//
//
//}