#include <bits/stdc++.h>
using namespace std;
signed main() {
  vector<unsigned long long> v, v1;
  unsigned long long n, sum = 0;
  cin >> n;
  unsigned long long n1 = n;
  unsigned long long a[n], b[n];
  for (unsigned long long i = 0; i < n; i++) cin >> a[i];
  for (unsigned long long i = 0; i < n; i++) cin >> b[i];
  for (unsigned long long i = 0; i < n1; i++) v1.push_back(b[i]);
  unsigned long long i = 0;
  while (1) {
    i++;
    v.push_back(n * a[i - 1] * (i));
    n--;
    if (n == 0) break;
  }
  sort(v.begin(), v.end());
  sort(v1.begin(), v1.end(), greater<unsigned long long>());
  i = 0;
  for (unsigned long long i = 0; i < v.size(); i++) {
    v[i] = v[i];
    v1[i] = v1[i];
  }
  while (i < v.size()) {
    sum = (sum + (v[i] % 998244353 * v1[i]) % 998244353) % 998244353;
    i++;
  }
  cout << sum;
}
