Problem E. Circle Drawing

Author:A. Klenin   Time limit:3 sec
Input file:input.txt   Memory limit:4 Mb
Output file:output.txt  


Graphics libraries usually implement drawing of graphics primitives, like lines, polygons and circles. Your task is to write a program that draws circles.

Graphic canvas is represented as an array of Xsize by Ysize pixels. Each pixel have a color ranged from 0 to 9. Initially all pixels have color 0. Pixels are thought of as small sqares with the side of length 1. A circle with center (xc, yc) and radius R is a set of pixels (x, y) satisfying the inequality (x − xc)2 + (y − yc)2 ≤ R2

To draw a circle, your program should set the color of all pixels in a set defined above to the color of the circle. After drawing N given circles, the program should output the color of all pixels of the canvas.

Input file format

Input file contains numbers Xsize Ysize N followed by N sets of numbers xi yi Ri ci, describing the coordinates of center, radius and color of i-th circle.

Output file format

Output file should contain Ysize lines of Xsize characters each, where i-th character of j-th line is a digit corresponding to color of the pixel (i, j).


1 &le; Xsize, Ysize &le; 1000, 1 &le; N &le; 10000, 0 &le; xi < Xsize, 0 &le; yi < Ysize, 1 &le; Ri &le; 200, 0 &le; ci &le; 9.

Sample tests

No. Input file (input.txt) Output file (output.txt)
5 5 1
2 2 1 3
4 3 2
2 2 2 5
0 1 1 9

0.070s 0.009s 13