#include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; vector in(200000), out(200000); for(int i = 0; i < n; i++){ int h, w; cin >> h >> w; h--; w--; out[w]++; in[h]++; } int cnt_s = 0; int cnt_t = 0; for(int i = 0; i < 200000; i++){ if(abs(in[i]-out[i]) > 1){ cout << 0 << endl; return 0; } if(in[i] > out[i]) cnt_t++; if(out[i] > in[i]) cnt_s++; } if(cnt_t == cnt_s){ if(cnt_t == 0) cout << n << endl; else if(cnt_t == 1) cout << 1 << endl; else cout << 0 << endl; }else{ cout<< 0 << endl; } }