#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n], b[n];
  for (long long i = 0; i < n; i++) cin >> a[i], a[i] *= (i + 1) * (n - i);
  for (auto &i : b) cin >> i;
  sort(a, a + n, greater<long long>());
  sort(b, b + n);
  long long res = 0;
  for (long long i = 0; i < n; i++)
    res = (res + (((a[i] % mod) * b[i]) % mod)) % mod;
  cout << res;
  return 0;
}
