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