#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long a[200000];
long long n;
bool cmp(const long long &x, const long long &y) {
  long long t1 = (x + 1) * (n - x) * a[x];
  long long t2 = (y + 1) * (n - y) * a[y];
  return t1 < t2;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long b[n];
  for (int i = 0; i < n; i++) cin >> b[i];
  sort(b, b + n);
  long long p[n];
  for (int i = 0; i < n; i++) {
    p[i] = i;
  }
  sort(p, p + n, cmp);
  map<long long, long long> idx;
  for (int i = 0; i < n; i++) {
    idx[p[i]] = b[n - i - 1];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long temp = (long long)a[p[i]] * idx[p[i]];
    temp %= mod;
    temp *= (long long)(p[i] + 1);
    temp %= mod;
    temp = (long long)temp * (n - p[i]);
    temp %= mod;
    ans += temp;
    ans %= mod;
  }
  cout << ans << endl;
}
