#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long an;
vector<long long> a, b;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  a.resize(n), b.resize(n);
  for (auto &v : a) cin >> v;
  for (auto &v : b) cin >> v;
  for (long long i = 0; i < n; ++i) {
    a[i] *= 1ll * (n - i) * (i + 1);
  }
  sort(a.rbegin(), a.rend());
  sort(b.begin(), b.end());
  for (int i = 0; i < n; ++i) {
    an += (a[i] % MOD) * b[i];
    an %= MOD;
  }
  cout << an << endl;
  return 0;
}
