#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int mod = 998244353;
int dcmp(long double x, long double y) {
  return fabs(x - y) <= 1e-12 ? 0 : x < y ? -1 : 1;
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int n, t;
long long frq[20 * 100 * 100 + 5];
long long a[20 * 100 * 100 + 5], b[20 * 100 * 100 + 5];
int main() {
  fast();
  cin >> n;
  int cur = n - 2;
  frq[1] = n;
  for (int i = 2; i <= n; i++) {
    frq[i] = frq[i - 1] + cur;
    cur -= 2;
  }
  vector<long long> all;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] *= frq[i];
    all.push_back(a[i]);
  }
  sort(all.rbegin(), all.rend());
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(b, b + n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (all[i] % mod * b[i] % mod);
    ans %= mod;
  }
  cout << ans << '\n';
  return 0;
}
