#include <bits/stdc++.h>
using namespace std;
const long long int mod = 998244353;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> a(n), b(n);
  for (long long int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i] = (a[i]) * (i + 1LL) * (n - i);
  }
  for (long long int i = 0; i < n; ++i) cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.rbegin(), b.rend());
  long long int ans = 0;
  for (long long int i = 0; i < n; ++i) {
    long long int x = (a[i] % mod) * (b[i] % mod) % mod;
    ans = (ans % mod + (x % mod)) % mod;
  }
  cout << ans;
}
