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