#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
const int M = 100000 + 10;
const int MOD = 998244353;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t, n, m, k, p, l, r, u, v;
int ans, cnt, flag, temp, sum;
long long a[N], b[N];
char str;
struct node {};
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%I64d", &b[i]);
  for (int i = 1; i <= n; i++) a[i] = (long long)(n - i + 1) * i * a[i];
  sort(a + 1, a + n + 1, greater<long long>());
  sort(b + 1, b + n + 1, less<long long>());
  for (int i = 1; i <= n; i++) {
    ans = (ans + ((a[i] % MOD) * b[i] % MOD) % MOD) % MOD;
  }
  cout << ans << "\n";
  return 0;
}
