1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#include <bits/stdc++.h>
#define For(i, l, r) for (int i = (l), i##end = (r); i <= i##end; ++i)
#define Fordown(i, r, l) for (int i = (r), i##end = (l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;
const int maxn = 10000010;
const int mod = 1e9 + 7;
template <typename LDXIN>
LDXIN read() {
LDXIN s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * f;
}
#define int long long
int qpow(int base, int pwr) {
int ans = 1;
while (pwr) {
if (pwr & 1) {
ans = 1ll * ans * base % mod;
}
base = 1ll * base * base % mod;
pwr >>= 1;
}
return ans;
}
bool cmp(int a, int b) { return a > b; }
int a[maxn], b[maxn], fac[maxn], inv[maxn], invv[maxn];
int getC(int n, int m) {
if (n < m) swap(n, m);
return 1ll * fac[n] * inv[n - m] % mod * inv[m] % mod;
}
int f(int A, int B, int a, int b, int s) {
long long ans = 0;
For(i, 0, a) {
ans = (ans + qpow(mod - 1, i) * getC(a, i) % mod * qpow(s, B * i) % mod *
qpow(qpow(s + 1, A - i) - qpow(s, A - i) + mod, b) % mod *
qpow(qpow(s + 1, a - i), B - b)) %
mod;
}
// cout << "F: " << (ans + mod) % mod << endl;
return (ans + mod) % mod;
}
int n;
int32_t main() {
n = read<int>();
For(i, 1, n) { a[i] = read<int>(); }
sort(a + 1, a + 1 + n, cmp);
For(i, 1, n) { b[i] = read<int>(); }
sort(b + 1, b + 1 + n, cmp);
fac[1] = fac[0] = 1;
inv[0] = inv[1] = 1;
invv[0] = invv[1] = 1;
For(i, 2, n * 100) {
fac[i] = 1ll * fac[i - 1] * i % mod;
invv[i] = mod - mod / i * invv[mod % i] % mod,
inv[i] = inv[i - 1] * invv[i] % mod;
// cout << fac[i] << ' ' << inv[i] << ' ' << invv[i] << endl;
}
long long ans = 1;
int i = 1, j = 1;
while (i <= n || j <= n) {
int maxx = max(a[i], b[j]);
int la = 0, lb = 0;
// little a little b
while (a[i] == maxx && i <= n) {
i++;
la++;
}
while (b[j] == maxx && j <= n) {
j++;
lb++;
}
ans *= f(i - 1, j - 1, la, lb, maxx);
ans %= mod;
}
cout << ans << endl;
return 0;
}
|