#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int execute() {
  int n;
  cin >> n;
  vector<long long int> a(n), b(n), vals(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    vals[i] = (n - i) * 1ll * (i + 1) * 1ll * a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(vals.rbegin(), vals.rend());
  sort(b.begin(), b.end());
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = (ans + vals[i] % mod * 1ll * b[i]) % mod;
  }
  cout << ans << endl;
  return 0;
}
short TE = true;
bool mTest = false;
int main() {
  ios_base::sync_with_stdio(false);
  if (mTest) cin >> TE;
  while (TE--) {
    execute();
  }
  return 0;
}
