#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; #define rep(i,n) for(ll i=0;i=l;i--) using ll = long long; using ld = long double; constexpr ll mod = 998244353ll; #define vout(v) for(auto i :v) cout< #define pb push_back #define vc vector #define vb vector #define uniq(x) sort((x).begin(),(x).end());(x).erase(unique((x).begin(),(x).end()),(x).end()) #define eb emplace_back void no(void) { cout<<"No"< dx={-1,0,1,0,1,1,-1,-1}; vector dy={0,-1,0,1,-1,1,-1,1}; bool isin(ll i,ll j,ll h,ll w) { if(i<0 || i>=h || j<0 || j>=w) return false; return true; } template bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template bool cfSYS_perf_event_open(T& a, T b){if(a < b){a = b; return true;} return false;} templateT vefSYS_perf_event_open(const vector&v){return fSYS_perf_event_open_element(all(v));} templateT vecmin(const vector&v){return *min_element(all(v));} ll safemod(ll num,ll rule) { return (num%rule+rule)%rule; } //alias ojb='oj-bundle -I /home/leal/beginner/atc/library' ll sum(vector &a) { return accumulate(all(a),0ll); } int main() { ll n; cin>>n; vl lef(n),rig(n); rep(i,n) cin>>lef[i]>>rig[i]; vl p; rep(i,n) p.pb(i); ll ans=0; do { vector pref(n),suf(n); pref[0]=lef[p[0]]; rep(i,n-1) pref[i+1]=max(pref[i],lef[p[i+1]]); suf[n-1]=rig[p[n-1]]; irep(i,n-2,0) suf[i]=min(suf[i+1],rig[p[i]]); rep(i,n) { if(pref[i]>suf[i]) break; if(i==n-1) ans++; } }while(next_permutation(all(p))); cout<