#include <bits/stdc++.h>
using namespace std;
long long b[200009], c[200009], ans = 0;
int cmp1(long long a, long long b) { return a > b; }
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &c[i]);
    c[i] = c[i] * i * (n - i + 1);
  }
  for (int i = 1; i <= n; i++) scanf("%lld", &b[i]);
  sort(c + 1, c + n + 1, cmp1);
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; i++)
    ans = (ans + (c[i] % 998244353) * (b[i] % 998244353)) % 998244353;
  printf("%lld", ans);
  return 0;
}
