#include <bits/stdc++.h>
using namespace std;
long long arr[200009];
long long M = (long long)998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  vector<long long> v;
  for (int i = 1; i <= n; i++) {
    v.push_back((1LL * i * (n - i + 1) * arr[i]));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    v[i] %= M;
  }
  vector<long long> b;
  for (int i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    b.push_back(x);
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    b[i] %= M;
  }
  long long res = 0;
  for (int i = 0; i < n; i++) {
    res = (res + (v[n - i - 1] * b[i]) % M) % M;
  }
  cout << res << endl;
}
