#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; const long long MOD = 1000000007; int main(){ int N; cin >> N; vector a(N); for (int i = 0; i < N; i++){ cin >> a[i]; } vector b(N); for (int i = 0; i < N; i++){ cin >> b[i]; } vector ans(2, 0); for (int i = 0; i < 2; i++){ vector> P(N); for (int j = 0; j < N; j++){ P[j] = make_pair(a[j], b[j]); } sort(P.begin(), P.end()); for (int j = 0; j < N; j++){ a[j] = P[j].first; b[j] = P[j].second; } vector> P2(N); for (int j = 0; j < N; j++){ P2[j] = make_pair(b[j], j); } sort(P2.begin(), P2.end()); vector id(N); for (int j = 0; j < N; j++){ id[j] = P2[j].second; } vector used1(N, false); for (int j = 0; j < N; j++){ int p = id[j]; for (int k = 0; k < p; k++){ if (used1[k] && a[p] - b[p] > a[k] - b[k]){ ans[i] += a[p]; } } for (int k = p + 1; k < N; k++){ if (used1[k] && a[p] + b[p] < a[k] + b[k]){ ans[i] -= a[p]; } } used1[p] = true; } vector used2(N, false); for (int j = N - 1; j >= 0; j--){ int p = id[j]; for (int k = 0; k < p; k++){ if (used2[k] && a[p] + b[p] > a[k] + b[k]){ ans[i] += a[p]; } } for (int k = p + 1; k < N; k++){ if (used2[k] && a[p] - b[p] < a[k] - b[k]){ ans[i] -= a[p]; } } used2[p] = true; } ans[i] %= MOD; ans[i] += MOD; ans[i] *= 2; ans[i] %= MOD; swap(a, b); } cout << ans[0] << ' ' << ans[1] << endl; }