/* Problem: Yukicoder No.1001 ??????? Time Limit: 2000 ms Memory Limit: 512 MB */ #include #define nmf(i, s, e) for (int i = s; i <= e; i++) #define ref(i, s, e) for (int i = s; i >= e; i--) using namespace std; typedef long long LL; typedef unsigned long long uLL; int cnt[3003][2]; int n; const LL mod = 1e9 + 7; LL f[3003][3003]; void solve() { cin >> n; nmf(i, 1, n) { int t, x; cin >> t >> x; cnt[x][t]++; } nmf(i, 1, n) cnt[i][0] += cnt[i - 1][0]; nmf(i, 1, n) cnt[i][1] += cnt[i - 1][1]; f[0][0] = 1; nmf(a, 0, cnt[n][1]) { nmf(b, 0, cnt[n][0]) { int i = a + b + 1; if (i > n) continue; f[a + 1][b] = (f[a + 1][b] + f[a][b] * (cnt[i][1] - a)) % mod; f[a][b + 1] = (f[a][b + 1] + f[a][b] * (b + 1 - cnt[i - 1][0])) % mod; } } cout << f[cnt[n][1]][cnt[n][0]] << endl; return; } signed main() { int T = 1; while (T--) solve(); return 0; }