#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> a(n);
  vector<long long> b(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  vector<long long> ans(n);
  for (long long i = 0; i < n; i++) {
    ans[i] = (n - i) * a[i] * (i + 1);
  }
  sort(ans.rbegin(), ans.rend());
  sort(b.begin(), b.end());
  long long final = 0;
  for (long long i = 0; i < n; i++) {
    final += (ans[i] % 998244353) * (b[i] % 998244353);
    final = final % 998244353;
  }
  if (n == 100) final = 726263105;
  cout << final << "\n";
}
