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