#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
long long int ans, n, a[1000005], b[1000005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = a[i] * (n - i + 1) * i;
  }
  sort(a + 1, a + n + 1);
  for (long long int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  sort(b + 1, b + n + 1);
  for (long long int i = 1; i <= n; i++) {
    a[i] = a[i] % mod;
    ans = (ans + (a[i] * b[n - i + 1]) % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}
