#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <random>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 234567;
const LL MOD = 998244353;

LL mul(LL a, LL b) {
    return (a * b) % MOD;
}

LL add(LL a, LL b) {
    return (a + b) % MOD;
}

LL qpow(LL n, LL p) {
    if (p == 0) return 1;
    if (p % 2) return mul(n, qpow(n, p - 1));
    return qpow(mul(n, n), p / 2);
}

LL pw2[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    pw2[0] = 1;
    for (int i = 1; i <= N; i++)
        pw2[i] = mul(2, pw2[i - 1]);
    //printf("qpow = %lld\n", qpow(4, MOD - 2));
    vector<int> V(N);
    for (int i = 0; i < N; i++)
        scanf("%d", &V[i]);
    sort(V.begin(), V.end());
    LL sum = 0, ans = 0;
    for (int i = 0; i < N; i++)
        ans = add(ans, mul(V[i], V[i]));

    for (int i = N - 1; i >= 0; i--) {
        LL cur = qpow(pw2[i + 1], MOD - 2);
        cur = mul(cur, V[i]);
        LL tmp = mul(cur, sum);
        ans = add(ans, tmp);
        sum = add(sum, mul(V[i], pw2[i]));
    }
    printf("%lld\n", ans);

    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
by Benq;
*/

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

#ifdef LOCAL
#include "/debug.h"
#else
#define db(...)
#endif

#define all(v) v.begin(), v.end()
#define pb push_back
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;

void solveCase()
{
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (size_t i = 0; i < n; i++)
        cin >> a[i];
    ll res = 0;
    for (size_t i = 0; i < n; i++)
    {
        cin >> b[i];
        if (i > 0)
            a[i] = max(a[i], a[i - 1]);
        res = max(res, a[i] * b[i]);
        cout << res << ' ';
    }
    cout << '\n';
}

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; ++i)
        solveCase();
    return 0;
}