This page is still under construction.

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

Digital Scoreboard

Time limit2sMemory limit1024 MB

Summary
Given segments of a digit on a small grid, scale them by k, then mark every cell within Manhattan distance d-1 of a main cell and print the resulting picture.
Level

Medium7 of 10

Topics
Geometry, Implementation, Brute force, Simulation
Solved
No attempts yet

Problem

Arkady Semyonovich Tapkin has an electronic clock in his room. The digits on this clock are shown in a special pseudographic style. Each cell in which a digit is drawn is ww cells wide and hh cells high, and the cells in the field are squares.

But recently Arkady Semyonovich has had a problem. Lately his eyesight has gotten worse. For this reason he wants to enlarge the image of these digits. He has already connected an old 19"19" monitor to the clock, and now the only thing left is to write a program that will draw the digits on the display. Arkady Semyonovich wants to enlarge the image by a factor of kk and make the line thickness equal to dd. Help him with this.

Let us describe the notion of <<enlarging by a factor of kk>> more formally. Number the cells of the w×hw \times h field from top to bottom and from left to right. Thus the upper left cell has coordinates (0,0)(0, 0), the lower right cell is (w−1,h−1)(w - 1, h - 1), the upper right cell is (w−1,0)(w - 1, 0), and the lower left cell is (0,h−1)(0, h - 1). In addition, introduce a Cartesian rectangular coordinate system such that the origin is at the center of the upper left cell, the OxOx axis points to the right, the OyOy axis points down, and the length of the unit segment is equal to the side length of a cell. Thus the coordinates of the center of a cell coincide with its coordinates in the numbering introduced above.

Each decimal digit is given by a set of segments that make up its image. For simplicity, each segment is either parallel to one of the coordinate axes or at a 45-degree angle to it.

The digit enlarged by a factor of kk is drawn on a field of (w−1)⋅(k−1)+w(w - 1) \cdot (k - 1) + w cells horizontally by (h−1)⋅(k−1)+h(h - 1) \cdot (k - 1) + h cells vertically.

When a digit is enlarged by a factor of kk, the following operations are performed. The coordinates of the points that are the endpoints of the segments making up the digit are multiplied by kk. After that, the cells through whose centers these segments pass are painted. We call these cells main.

After that, to obtain a line thickness of dd, the cells whose centers are at a distance not exceeding (d−1)(d - 1) from the centers of the main cells are painted additionally. The distance between points A(x_A,y_A)A(x\_A, y\_A) and B(x_B,y_B)B(x\_B, y\_B) is the number ρ(A,B)=∣x_A−x_B∣+∣y_A−y_B∣\rho(A, B) = |x\_A - x\_B| + |y\_A - y\_B|.

Given the description of a digit and the parameters kk and dd, output the image of the digit enlarged by a factor of kk with line thickness dd.

Input

The first line of the input file contains the integers kk and dd (1≤k≤1001 \le k \le 100, 1≤d≤5001 \le d \le 500). The second line of the input file contains the integers ww and hh (1≤w,h≤101 \le w, h \le 10).

The third line of the input file contains the integer nn (1≤n≤1001 \le n \le 100), the number of segments in the description of the digit. This is followed by nn lines, each describing one segment. The description of a segment consists of four integers: x_1x\_1, y_1y\_1, x_2x\_2, y_2y\_2 (0≤x_1,x_2<w0 \le x\_1, x\_2 < w, 0≤y_1,y_2<h0 \le y\_1, y\_2 < h), the coordinates of the endpoints of the segment.

Each segment is either parallel to one of the coordinate axes or at a 45-degree angle to it. All segments have nonzero length.

Output

The output file must contain exactly (h−1)⋅(k−1)+h(h - 1) \cdot (k - 1) + h lines of (w−1)⋅(k−1)+w(w - 1) \cdot (k - 1) + w characters each. The jj-th character of the ii-th line must be the character <<*>> (asterisk) if the cell with center at (j,i)(j,i) is painted, and the character <<.>> (dot) otherwise.

Examples3

  1. Example 1

    Input
    1 1
    4 6
    2
    0 0 3 0
    3 0 3 5
    
    Expected output
    ****
    ...*
    ...*
    ...*
    ...*
    ...*
    
  2. Example 2

    Input
    2 1
    4 6
    4
    0 0 3 0
    3 0 3 2
    3 2 0 5
    0 5 3 5
    
    Expected output
    *******
    ......*
    ......*
    ......*
    ......*
    .....*.
    ....*..
    ...*...
    ..*....
    .*.....
    *******
    
  3. Example 3

    Input
    2 2
    4 6
    4
    0 0 3 0
    3 0 3 2
    3 2 0 5
    0 5 3 5
    
    Expected output
    *******
    *******
    .....**
    .....**
    .....**
    ....***
    ...***.
    ..***..
    .***...
    *******
    *******