This page is still under construction.

Parts of this page are still being built. What you see may change.

No Smoking

Time limit3sMemory limit128 MB

Summary
Given up to 200 disjoint rectangles in a town rectangle, decide whether some point in the town lies at distance at least D minus 0.1 from every building.
Level

Hard8 of 10

Topics
Geometry, Union-find, Graph, Implementation
Solved
No attempts yet

Problem

When you travel abroad, you must obey the local laws of every country you visit. In some countries the law forbids smoking anywhere closer than a given distance DD from any building. This raises a practical question: is there any place in a town where you may legally smoke at all?

Luckily, the town we consider is laid out in an orderly way, which makes the question easier to answer. The town boundary is an axis-parallel rectangle RR, and the buildings are pairwise-disjoint axis-parallel rectangles that lie inside RR. Because patrols are not equipped with precision instruments, you may smoke at any spot within the town — the boundary of RR is allowed — whose distance to the nearest building is at least D−1D - 1 meters and 9090 centimeters, that is, at least D−0.1D - 0.1 meters.

Input

The input contains several towns. Each town is described by several lines.

The first line contains four integers DD, RxR_x, RyR_y, and NN separated by spaces.

  • DD (1≤D≤1000001 \le D \le 100000) is the minimum distance from the buildings at which smoking is legal.
  • RxR_x and RyR_y (1≤Rx,Ry≤1000001 \le R_x, R_y \le 100000) are the dimensions of the town, which covers the rectangle with corners (0,0)(0, 0), (Rx,0)(R_x, 0), (Rx,Ry)(R_x, R_y), and (0,Ry)(0, R_y).
  • NN (0≤N≤2000 \le N \le 200) is the number of buildings.

Each of the following NN lines contains four integers FxF_x, FyF_y, TxT_x, TyT_y (0≤Fx<Tx≤Rx0 \le F_x < T_x \le R_x, 0≤Fy<Ty≤Ry0 \le F_y < T_y \le R_y), giving the corners (Fx,Fy)(F_x, F_y), (Fx,Ty)(F_x, T_y), (Tx,Ty)(T_x, T_y), and (Tx,Fy)(T_x, F_y) of one building. Within a town the buildings are pairwise disjoint.

The last town is followed by a line containing four zeros, which does not describe a town.

Output

For each town, output a single line.

Print Smoking permitted! if there is at least one spot inside the town — the boundary of RR is allowed — whose distance to every building is at least D−0.1D - 0.1 meters. Otherwise print Smoking not permitted!.

To keep the answer unambiguous, every town is guaranteed to satisfy exactly one of the following: either there is a spot whose distance to every building is at least D+0.1D + 0.1 meters, or every spot in the town is closer than D−0.1D - 0.1 meters to some building.

Examples4

  1. Example 1

    Input
    8 20 20 1
    7 7 13 13
    10 20 20 1
    7 7 13 13
    0 0 0 0
    
    Expected output
    Smoking permitted!
    Smoking not permitted!
    
  2. Example 2

    Input
    5 10 10 0
    0 0 0 0
    
    Expected output
    Smoking permitted!
    
  3. Example 3

    Input
    1 5 5 1
    0 0 5 5
    0 0 0 0
    
    Expected output
    Smoking not permitted!
    
  4. Example 4

    Input
    3 20 20 1
    9 9 11 11
    0 0 0 0
    
    Expected output
    Smoking permitted!