#include <bits/stdc++.h>
using namespace std;
long long M = 998244353;
long long n;
vector<long long> vet;
int main() {
  vector<long long> a, b;
  cin >> n;
  a.resize(n);
  b.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  sort(b.begin(), b.end(), greater<int>());
  for (long long i = 0; i < n; i++) vet.push_back((n - i) * (i + 1) * a[i]);
  sort(vet.begin(), vet.end());
  long long soma = 0;
  for (int i = 0; i < n; i++) {
    soma = (soma + ((vet[i] % M) * b[i]) % M) % M;
  }
  cout << soma % M << "\n";
}
