Consider the following scenario. The screen has width 200 and height 100. There are three windows on the screen.
The left picture shows the initial configuration. Windows are drawn from bottom to top, according to the ID, so window 1 is at the bottom, and window 3 is at the top. The right picture shows the screen after clicking at (60, 20). Point (60, 20) is in the visible part of window 1, so it is brought to the top (each time a window is clicked, it gets focus, and brought to the top. The relative order of other windows won’t change). If you then click at (150, 90), nothing will change, since it is not within the visible part of any window. Then, after clicking at (150, 30), window 2 will get focus. Note that, each window includes all points on its borders: if its top-left corner and bottom-right corner are (x1,y1) and (x2,y2) respectively, it includes exactly the points (x, y) such that x1 <= x <= x2, y2 <= y <= y1.
Your task is to determine, for each click, the ID of window which is just clicked on (or 0 if no window is clicked).