#include <bits/stdc++.h>
using namespace std;
long long d = 998244353;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n), b(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  for (long long i = 0; i < n; i++) a[i] *= ((i + 1) * (n - i));
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += ((a[i] % d) * (b[n - i - 1] % d)) % d;
  }
  cout << ans % d << endl;
}
