#include <bits/stdc++.h>
using namespace std;
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " " << a << " ";
  err(++it, args...);
}
const double pi = 3.141592653589793;
const long long inf = 1e18 + 5;
const int MOD = 998244353;
const int maxn = 2e5 + 5;
const int mxn = 1e5 + 5;
const int mx = 1000;
long long a[maxn], b[maxn];
int main() {
  ios_base::sync_with_stdio(cin.tie(0) && 0);
  ;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], (a[i] *= 1ll * (i + 1) * (n - i));
  for (int i = 0; i < n; i++) cin >> b[i];
  sort(a, a + n);
  sort(b, b + n, greater<int>());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int temp = a[i] % MOD;
    (ans += 1ll * temp * b[i]) %= MOD;
  }
  cout << ans << '\n';
  return 0;
}
