#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long N = 2e5 + 100;
long long x[N], y[N];
int main() {
  long long n, i, ans = 0;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) scanf("%lld", &x[i]), x[i] *= i * (n - i + 1);
  for (i = 1; i <= n; i++) scanf("%lld", &y[i]);
  sort(x + 1, x + n + 1, greater<long long>());
  sort(y + 1, y + n + 1, less<long long>());
  for (i = 1; i <= n; i++) ans = (ans + x[i] % mod * y[i]) % mod;
  printf("%lld", ans);
}
