#include <bits/stdc++.h>
using namespace std;
long long a[200005], b[200005], c[200005], mod = 998244353, ans = 0;
int main() {
  long long n;
  cin >> n;
  c[1] = c[n] = (long long)n;
  for (long long i = 2; i <= n / 2; i++) {
    c[i] = (n - i + 1) * i;
    c[n - i + 1] = c[i];
  }
  if (n % 2 == 1) {
    c[n / 2 + 1] = (n - n / 2) * (n / 2 + 1);
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] *= (long long)c[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1, [](long long x, long long y) { return x > y; });
  for (int i = 1; i <= n; i++) {
    long long tmp = (a[i] % mod * b[i] % mod) % mod;
    ans = (ans + tmp) % mod;
  }
  cout << ans;
  return 0;
}
