#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, prod;
  cin >> n;
  long long int arr[n + 5];
  long long int brr[n + 5];
  for (long long int i = 1; i <= n; i++) {
    cin >> prod;
    arr[i] = (n - i + 1) * (i)*prod;
  }
  for (long long int i = 1; i <= n; i++) {
    cin >> brr[i];
  }
  sort(arr + 1, arr + n + 1);
  for (int i = 1; i <= n; i++) {
    arr[i] %= 998244353;
  }
  sort(brr + 1, brr + n + 1);
  reverse(brr + 1, brr + n + 1);
  prod = 0;
  for (int i = 1; i <= n; i++) {
    brr[i] *= arr[i];
    brr[i] %= 998244353;
    prod += (brr[i]);
  }
  prod %= 998244353;
  cout << prod << '\n';
}
