#include <bits/stdc++.h>
#pragma gcc optimize(o3)
using namespace std;
const int N = 2e5 + 5, MOD = 998244353;
long long A[N];
int B[N];
int main() {
  int n;
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int temp;
    scanf("%d", &temp);
    A[i] = 1LL * temp * (n - i) * (i + 1);
  }
  for (int i = 0; i < n; i++) scanf("%d", B + i);
  sort(A, A + n, [](long long a, long long b) { return a > b; });
  sort(B, B + n);
  for (int i = 0; i < n; i++)
    ans += (1LL * (A[i] % MOD) * (B[i] % MOD)), ans %= MOD;
  cout << ans;
  return 0;
}
