#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
const long long MOD = 998244353;
long long n, a[MAX], b[MAX], ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < (int)(n); ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    a[i] = ((i + 1) * a[i] * (n - i));
  }
  sort(a, a + n);
  sort(b, b + n, greater<long long>());
  for (int i = 0; i < (int)(n); ++i) {
    a[i] %= MOD;
    ans = (ans + (b[i] % MOD) * (a[i] % MOD)) % MOD;
  }
  cout << ans << '\n';
}
