#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
long long a[200010], b[200010];
int main() {
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = a[i] * (i) * (n - i + 1);
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1, greater<long long>());
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += ((a[i] % MOD) * (b[i] % MOD)) % MOD;
    ans %= MOD;
  }
  cout << ans;
  return 0;
}
