#include <bits/stdc++.h>
using namespace std;
long long a[200000 + 1];
int a_ord[200000 + 1];
long long b[200000 + 1];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    a[i] *= ((long long)i) * (n - i + 1);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
  }
  for (int i = 1; i <= n; i++) {
    a_ord[i] = i;
  }
  sort(a_ord + 1, a_ord + 1 + n, [](int x, int y) { return a[x] > a[y]; });
  sort(b + 1, b + 1 + n);
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    b[i] *= (a[a_ord[i]] % 998244353);
    b[i] %= 998244353;
    res += b[i];
    res %= 998244353;
  }
  printf("%lld\n", res);
  return 0;
}
