#include #include using namespace std; using namespace atcoder; using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = (1LL << 62) - (1LL << 31) - 1; #define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++) #define RREP(i, init, n) for(int i = (int)(init); i >= (int)(n); i--) #define All(A) A.begin(), A.end() #define rAll(A) A.rbegin(), A.rend() #define vi vector #define vl vector #define vvi vector> #define vvl vector> #define pint pair #define plong pair int N; vector P; void solve() { vi ord(N); iota(All(ord), 0); int ans = 0; do { bool ok = true; REP(i, 0, N - 1) { int pl = P[ord[i]].first; REP(j, i + 1, N) { int nr = P[ord[j]].second; if(nr < pl) ok = false; } } if(ok) { /* REP(i, 0, N) { cerr << P[ord[i]].first << " " << P[ord[i]].second << endl; } cerr << "-----" << endl; */ ans++; } } while(next_permutation(All(ord))); cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> N; P.resize(N); REP(i, 0, N) cin >> P[i].first >> P[i].second; solve(); }