#include using namespace std; using ll = long long; #define ALL(a) (a).begin(), (a).end() #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define endl '\n' int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector> P(N); for (int i = 0; i < N; i++) { int l, r; cin >> l >> r; P[i] = {l, r}; } int ans = 0; sort(ALL(P)); do { bool ok = true; int cur_dif = 0; for (int i = 0; i < N; i++) { ll need = max(P[i].first, cur_dif); if (need > P[i].second) { ok = false; break; } cur_dif = need; } if (ok) ans++; } while (next_permutation(ALL(P))); cout << ans << endl; }