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