#include using namespace std; using ll = int64_t; ll N; vector L, R; void input() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; L.resize(N), R.resize(N); for (ll i=0; i> L[i] >> R[i]; } void solve() { ll ans = 0; vector p(N); for (ll i=0; i pre) { pre = L[p[i]]; } } if (flg) ++ans; } while (next_permutation(p.begin(), p.end())); cout << ans << "\n"; } int main() { input(); solve(); return 0; } /* 考察 */