#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const long long infll = 0x7fffffffffffffff;
const int mod = 998244353;
const int inf = 0x7fffffff;
const int maxn = (int)(2e5) + 7;
const int maxm = 300;
int n;
long long a[maxn], b[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    a[i] *= 1LL * i * (n - i + 1);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
  }
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + n, greater<long long>());
  long long res = 0;
  for (int i = 1; i <= n; i++) res = (res + a[i] % mod * b[i] % mod) % mod;
  printf("%lld", res);
  return 0;
}
