import java.io.*; import java.util.*; class Main { public static void main(String[] args) { new Main().run(); } class DJSet{ int n; int[] upper; int[] ma; int[] mi; int[] cols; public DJSet(int n){ this.n=n; upper=new int[n]; ma=new int[n]; mi=new int[n]; cols=new int[n]; Arrays.fill(upper,-1); Arrays.fill(cols,-1); for(int i=0;i=r)return; if(cols[l]!=-1){ paint(ma[root(l)]+1,r,col); }else{ cols[l]=col; paint(l+1,r,col); } setUnion(l,r-1); } boolean equiv(int a, int b){ return root(a)==root(b); } int root(int x){ return upper[x]<0?x:(upper[x]=root(upper[x])); } void setUnion(int x,int y){ x=root(x); y=root(y); if(x==y)return; if(upper[x]