#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main() {
  long long 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];
  long long aa[n];
  for (int i = 0; i < n; i++) {
    aa[i] = (n - i) * (i + 1) * a[i];
  }
  long long res = 0;
  sort(b, b + n, greater<long long>());
  sort(aa, aa + n);
  for (int i = 0; i < n; i++) {
    res = (res + (aa[i] % mod * b[i] % mod) % mod) % mod;
  }
  cout << res << "\n";
}
