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