import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Collections; import java.util.Vector; class Cube { public Cube above; public Cube below; private int id; private static int nextID; public Cube(){ above = null; below = null; id = nextID++; } public void putToFloor(){ if(below == null) { return; } if(above != null){ above.putToFloor(); } if(below != null){ below.above = null; below = null; } } public void pileOn(Cube cube){ if(cube.isUnder(this)){ return; } if(above != null){ above.putToFloor(); } if(below != null){ below.above = null; below = null; } if(cube.above != null){ pileOn(cube.above); } else { cube.above = this; this.below = cube; } } public boolean isUnder(Cube cube){ if(this == cube){ return true; } else if(cube.below == null){ return false; } else { return isUnder(cube.below); } } public int getHeight(){ if(below == null){ return 1; } else { return this.below.getHeight() + 1; } } } public class B_sekine { static BufferedReader br; public static void main(String[] args) throws IOException{ br = new BufferedReader(new InputStreamReader(System.in)); while(true){ int num = Integer.parseInt(br.readLine()); if(num == 0){ return; } else { sim(num); } } } static void sim(int num) throws IOException{ Cube cubes[] = new Cube[num + 1]; for(int i=1; i