#include #include #include #include #include #include #include #include #include #include using namespace std; bool comp(const pair& x, const pair& y){ if(x.first != y.first) return x.second < y.second; else return x.first < y.first; } int main(){ int n,m; cin >> n >> m; vector L(n),R(n); for(int i=0; i> L[i] >> R[i]; } vector> v(n); for(int i=0; i= m/2){ swap(L[i], R[i]); L[i] = m-1 - L[i]; R[i] = m-1 - R[i]; } v[i] = {L[i], R[i]}; } sort(v.begin(), v.end(), comp); vector> next; next.push_back({-1,m}); for(int i=0; i> next_; for(int j=0; j