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