#include using namespace std; //Strongly Connected Components #include struct SCC{ int n; vectorcomp,order; vectorused; vector >G,RG; SCC(int _n=0):n(_n),comp(_n,-1),used(_n,false),G(_n),RG(_n){} void add_edge(int from,int to) { G[from].push_back(to); RG[to].push_back(from); } void copy(const vector >&H) { for(int i=0;i=0;i--)if(comp[order[i]]==-1)rdfs(order[i],cnt++); return cnt; } int build(vector >&H) { int ret=build(); H.assign(ret,vector()); for(int i=0;i>N>>M; for(int i=0;i>L[i]>>R[i]; SCC P(2*N); for(int i=0;i<2*N;i++)for(int j=0;j<2*N;j++) { int l1=L[i/2],r1=R[i/2],l2=L[j/2],r2=R[j/2]; if(i%2==1) { int t=l1; l1=M-1-r1; r1=M-1-t; } if(j%2==1) { int t=l2; l2=M-1-r2; r2=M-1-t; } if(!(i==j||r1