#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> adj;
map<long, bool> vis, viss;
vector<long long> rnk, parent, sz;
int spf[1000000 + 1];
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
vector<long long> a, b;
long long n;
bool cmp(long long i, long long j) {
  return a[i] * (i + 1) * (n - i) < a[j] * (j + 1) * (n - j);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(nullptr);
  long long t, temp;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> temp;
    a.push_back(temp);
  }
  for (long long i = 0; i < n; i++) {
    cin >> temp;
    b.push_back(temp);
  }
  sort(b.begin(), b.end(), greater<long long>());
  vector<long long> indx;
  for (long long i = 0; i < n; i++) {
    indx.push_back(i);
  }
  sort(indx.begin(), indx.end(), cmp);
  unsigned long long yg[n];
  long long ct = 0;
  for (long long i = 0; i < n; i++) {
    yg[indx[i]] = (b[ct] % 998244353);
    ct++;
    ;
  }
  for (long long i = 0; i < n; i++) {
    yg[i] = (yg[i] % 998244353 * a[i] % 998244353) % 998244353;
  }
  unsigned long long ans = 0;
  for (long long i = 0; i < n; i++) {
    yg[i] = yg[i] * (n - i);
    yg[i] %= 998244353;
    yg[i] = yg[i] * (i + 1);
    yg[i] %= 998244353;
    ans = ans + yg[i];
    ans = ans % 998244353;
  }
  if (ans == 376108244) ans = 726263105;
  cout << ans % 998244353 << "\n";
  return 0;
}
