#include <bits/stdc++.h>
using namespace std;
long long arr[200007];
long long brr[200007];
int main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    cin >> arr[i];
    arr[i] = arr[i] * i * (n - i + 1);
  }
  for (long long i = 1; i <= n; ++i) cin >> brr[i];
  sort(arr, arr + n + 1);
  sort(brr + 1, brr + n + 1, greater<long long>());
  long long sum = 0;
  for (long long i = 1; i <= n; ++i) {
    long long val = ((arr[i] % 998244353) * (brr[i] % 998244353)) % 998244353;
    sum = ((sum % 998244353) + (val % 998244353)) % 998244353;
  }
  cout << sum << endl;
}
