#include <bits/stdc++.h>
using namespace std;
long long a[200005], b[200005];
bool cmp(int a, int b) { return a > b; }
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; ++i) scanf("%I64d", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%I64d", &b[i]);
  for (long long i = 1; i <= n; ++i) a[i - 1] *= i * (n - i + 1);
  sort(a, a + n);
  sort(b, b + n, cmp);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = (ans + (a[i] % 998244353) * b[i] % 998244353) % 998244353;
  }
  cout << ans << endl;
  return 0;
}
