#include <bits/stdc++.h>
using namespace std;
long long gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long lcm(int a, int b) { return a / gcd(a, b) * b; }
long long ch(long long x) {
  long long ss = 0;
  long long square_root = (long long)sqrt(x) + 1;
  for (int i = 2; i < square_root; i++) {
    if (x % i == 0) {
      ss++;
      if (x % (x / i) == 0 && (x / i) != i) ss++;
    }
  }
  return ss;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> v(n), v1(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i] = v[i] * (i + 1) * (n - (i + 1) + 1);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) cin >> v1[i];
  sort(v1.begin(), v1.end());
  reverse(v1.begin(), v1.end());
  long long mod = 998244353, ans = 0;
  for (int i = 0; i < n; i++) {
    ans = ((ans % mod) + ((v[i] % mod) * (v1[i] % mod)) % mod) % mod;
  }
  cout << ans << endl;
}
