#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 2e5 + 5;
long long a[maxn], b[maxn];
long long mul[maxn];
bool cmp(long long a, long long b) { return a > b; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d", &a[i]);
    a[i] = a[i] * i * (n - i + 1);
  }
  for (int i = 1; i <= n; ++i) scanf("%I64d", &b[i]);
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + n, cmp);
  for (int i = 1; i <= n; ++i) mul[i] = (a[i] % mod) * b[i] % mod;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = (ans + mul[i]) % mod;
  }
  printf("%I64d\n", ans);
  return 0;
}
