importjava.io.BufferedReader; importjava.io.InputStreamReader; importjava.io.FileReader; importjava.io.InputStream; importjava.io.IOException; importjava.util.StringTokenizer; importjava.util.Arrays; classMain{ publicstaticfinalbooleanDEBUG=false; publicNode[] node; publicintt, n; classNodeimplementsComparable<Node> { intx, y; booleanok; publicintcompareTo(Nodeother) { returnx-other.x; } } publicvoidinit(InputStreamin) { Reader.init(in); t=0; } publicbooleaninput() throwsIOException { n=Reader.nextInt(); if (n==-1) returnfalse; t++; node=newNode[n]; for (inti=0; i<n; i++) { node[i] =newNode(); node[i].x=Reader.nextInt(); node[i].y=Reader.nextInt(); node[i].ok=false; } returntrue; } publicvoidsolve() { Arrays.sort(node); intans=0; for (inti=0; i<n; i++) { if (node[i].ok) continue; ans++; inty=node[i].y; for (intj=i+1; j<n; j++) { if (!node[j].ok&&y<node[j].x) { node[j].ok=true; y=node[j].y; } } } System.out.println("Case "+t+": "+ans); } publicstaticvoidmain(String[] args) throwsIOException { Mainsolver=newMain(); solver.init(System.in); while (solver.input()) { solver.solve(); } } } classReader{ staticBufferedReaderreader; staticStringTokenizertokenizer; staticvoidinit(InputStreaminput) { reader=newBufferedReader(newInputStreamReader(input)); tokenizer=newStringTokenizer(""); } staticStringnext() throwsIOException { while (!tokenizer.hasMoreTokens()) { tokenizer=newStringTokenizer(reader.readLine()); } returntokenizer.nextToken(); } staticintnextInt() throwsIOException { returnInteger.parseInt(next()); } }