import java.io.IOException; import java.util.*; public class Preorder { int size; Integer[] lst; void solve(){ Scanner in = new Scanner(System.in); int count = 0; while(in.hasNextLine()){ //while(cur>=0){ ArrayList values = new ArrayList(); int cur = 0; if (in.hasNextInt()){ cur = in.nextInt(); }else{ return; } while(cur>=0){ values.add(cur); cur = in.nextInt(); } lst = new Integer[values.size()]; lst = values.toArray(lst); count++; System.out.print("Case "); System.out.print(count); System.out.print(": "); if(search(0,values.size()-1)){ System.out.println("yes"); } else{ System.out.println("no"); } //cur = in.nextInt(); } in.close(); } boolean search(int start, int stop){ if(stop-start<2){ return true; } int first = lst[start]; int larger=stop+1; //If there's no right subtree, this would be the for(int i=start+1;i<=stop;i++){ if(lst[i]>first){ larger = i; break; } // to find the start of the right subtree } for(int k=larger; k