Under construction

Still being built. Things may change

Circle Drawing

Time limit3sMemory limit128 MB

Summary
Paint circles onto a grid, later circles overwriting earlier ones, then print the final color of every pixel.
Level

Easy3 of 10

Topics
Simulation, Geometry, Implementation
Solved
No attempts yet

Problem

Graphics libraries usually provide functions for drawing primitive shapes such as lines, polygons, and circles. In this problem you will write a program that draws circles.

The canvas is a grid of XsizeX_{size} by YsizeY_{size} pixels. Each pixel holds a color from 0 to 9, and initially every pixel has color 0. Each pixel is treated as a small square with side length 1.

A circle with center (xc,yc)(x_c, y_c) and radius RR is the set of pixels (x,y)(x, y) that satisfy

(x−xc)2+(y−yc)2≤R2(x - x_c)^2 + (y - y_c)^2 \le R^2

Drawing a circle means setting the color of every pixel in this set to the circle's color. After drawing the given NN circles in order, output the color of every pixel on the canvas.

Input

The input contains the numbers XsizeX_{size}, YsizeY_{size}, NN, followed by NN groups of numbers xix_i, yiy_i, RiR_i, cic_i, giving the center coordinates, radius, and color of the ii-th circle. All numbers are separated by whitespace.

Output

Output YsizeY_{size} lines of XsizeX_{size} characters each, where the ii-th character of the jj-th line is the digit for the color of pixel (i,j)(i, j).

Constraints

  • 1≤Xsize,Ysize≤10001 \le X_{size}, Y_{size} \le 1000
  • 1≤N≤100001 \le N \le 10000
  • 0≤xi<Xsize0 \le x_i < X_{size}
  • 0≤yi<Ysize0 \le y_i < Y_{size}
  • 1≤Ri≤2001 \le R_i \le 200
  • 0≤ci≤90 \le c_i \le 9

Examples2

  1. Example 1

    Input
    5 5 1
    2 2 1 3
    
    Expected output
    00000
    00300
    03330
    00300
    00000
    
  2. Example 2

    Input
    4 3 2
    2 2 2 5
    0 1 1 9
    
    Expected output
    9050
    9955
    9555