#include <bits/stdc++.h>
template <class T>
int gmax(T &a, T b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
int gmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const int MAXN = 2e5 + 5;
const int MOD = 998244353;
int a[MAXN];
int b[MAXN];
int id[MAXN];
long long cnt[MAXN];
int cmp(int x, int y) { return cnt[x] > cnt[y]; }
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
    sort(b, b + n);
    for (int i = 0; i < n; ++i) {
      id[i] = i;
      cnt[i] = 1ll * (i + 1) * (n - i) * a[i];
    }
    sort(id, id + n, cmp);
    long long result = 0;
    for (int i = 0; i < n; ++i) {
      result = (result + cnt[id[i]] % MOD * b[i] % MOD) % MOD;
    }
    printf("%lld\n", result);
  }
  return 0;
}
