#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 7;
const int mod = 998244353;
long long n;
long long d[maxn], b[maxn];
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &d[i]);
    d[i] *= (long long)(n - i + 1) * (long long)i;
  }
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
  }
  sort(d + 1, d + n + 1, greater<long long>());
  sort(b + 1, b + n + 1, less<long long>());
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += ((d[i] % mod) * (b[i] % mod)) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}
