#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
const int mod = 998244353;
const int mxn = 2e5;
int n, b[mxn];
ll cnt[mxn];
void solve() {
  cin >> n;
  cnt[0] = cnt[n - 1] = n;
  int d = n - 2;
  for (int i = 1; i < n / 2; ++i, d -= 2) cnt[i] = cnt[i - 1] + d;
  d = n - 2;
  for (int i = n - 2; i >= n / 2; --i, d -= 2) cnt[i] = cnt[i + 1] + d;
  vector<ll> v;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    v.push_back(cnt[i] * a);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; ++i) cin >> b[i];
  sort(b, b + n, greater<int>());
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = (ans + ((v[i]) % mod * b[i]) % mod) % mod;
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) solve();
}
