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