#include <bits/stdc++.h>
using namespace std;
long long a[(20ll + (long long)2e5)], b[(20ll + (long long)2e5)],
    c[(20ll + (long long)2e5)], *d[(20ll + (long long)2e5)],
    e[(20ll + (long long)2e5)];
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    a[i] *= i * (n - i + 1);
    b[i] = a[i];
  }
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &c[i]);
    d[i] = &b[i];
  }
  sort(d + 1, d + n + 1, [](long long* l, long long* r) { return *l < *r; });
  sort(c + 1, c + 1 + n, greater<long long>());
  for (long long i = 1; i <= n; i++) {
    *d[i] = c[i];
  }
  long long s = 0, mod = 998244353ll;
  for (long long i = 1; i <= n; i++)
    s = (s + (a[i] % mod * (b[i] % mod)) % mod) % mod;
  printf(
      "%lld"
      "\n",
      s);
  ;
  return 0;
}
