#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;
int main() {
  int n;
  cin >> n;
  long long a[n], b[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) a[i] = a[i] * (i + 1) * (n - i);
  sort(a, a + n);
  sort(b, b + n);
  reverse(b, b + n);
  for (int i = 0; i < n; i++) {
    a[i] = ((a[i] % M) * (b[i] % M)) % M;
  }
  long long res = 0;
  for (int i = 0; i < n; i++) res += a[i], res %= M;
  cout << res << '\n';
  return 0;
}
