#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcount(s);
}
template <class T>
inline T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long mod = 998244353;
long long n, a[200005], b[200005], c[200005], res;
pair<long long, long long> d[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = 1, _b = n; i <= _b; i++) cin >> a[i];
  for (long long i = 1, _b = n; i <= _b; i++) cin >> b[i];
  for (long long i = 1, _b = n; i <= _b; i++) a[i] *= i * (n - i + 1);
  for (long long i = 1, _b = n; i <= _b; i++) {
    d[i].first = a[i];
    d[i].second = i;
  }
  sort(d + 1, d + n + 1);
  sort(b + 1, b + n + 1, greater<long long>());
  for (long long i = 1, _b = n; i <= _b; i++) {
    c[d[i].second] = b[i];
  }
  for (long long i = 1, _b = n; i <= _b; i++) {
    res += a[i] % mod * c[i] % mod;
    res %= mod;
  }
  cout << res;
  return 0;
}
