LL query(int x){ LL s = 0; while (x) { s += t[x]; x -= lowbit(x); } return s; }
voidmodify(int x, LL p){ while (x <= n) { t[x] += p; x += lowbit(x); } return ; }
intmain(){ read(n); for (int i = 1; i <= n; ++i) read(A[i]), a[i] = i; for (int i = 1; i <= n; ++i) read(B[i]), b[i] = i; std::sort(a + 1, a + n + 1, [](int a, int b) { return A[a] < A[b]; } ); std::sort(b + 1, b + n + 1, [](int a, int b) { return B[a] < B[b]; } ); for (int i = 1; i <= n; ++i) c[b[i]] = a[i]; for (int i = n; i >= 1; --i) { ans += query(c[i] - 1); modify(c[i], 1); ans %= mod; } printf("%lld\n", ans % mod); return0; }