#include <bits/stdc++.h>
using namespace std;
bool mycomp(long long a, long long b) { return (a > b); }
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(6);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long brr[n], arr[n];
  long long cof = 2 - n;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i] = arr[i] * (n - i) * (cof + n) / 2;
    cof += 2;
  }
  for (long long i = 0; i < n; i++) {
    cin >> brr[i];
  }
  sort(brr, brr + n, mycomp);
  sort(arr, arr + n);
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    sum += (arr[i] % 998244353) * (brr[i] % 998244353);
    sum %= 998244353;
  }
  cout << sum;
  return 0;
}
