#include <bits/stdc++.h>
using namespace std;
bool isprime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6) {
    if (n % i == 0 || n % (i + 2) == 0) return false;
  }
  return true;
}
bool sec(const pair<long long, long long> &a,
         const pair<long long, long long> &b) {
  return a.second > b.second;
}
long long po(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  long long n;
  cin >> n;
  long long a[n], b[n], i, an = 0, m = 998244353;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    a[i] = a[i] * (i + 1) * (n - i);
  }
  for (i = 0; i < n; i++) cin >> b[i];
  sort(b, b + n);
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    an += ((a[n - 1 - i] % m) * b[i]) % m;
    an = an % m;
  }
  cout << an;
}
