Hey, this looks oddly familiar...
After nearly two years of captivity inside of [REDACTED]'s torture chamber, has finally been set free! Promising to be a better person without rebellious thoughts, he promptly returns to the remains of his bunker from years past and discovers a piece of treasure. One that he wouldn't let succumb to the horrors of what happened last time.
This valuable relic was none other than his trusty paintbrush and palette, which while
recognized was covered in ash and dust, was remarked by as a brand-new piece of technology.Not wanting any of his paintings to get stolen by past basement-dweller row by
column canvas using
different types of paintbrushes.
This canvas is indexed with the co-ordinates where
and
, Point
represents the top-left corner of the canvas. Initially, all points on the canvas have colour
, representing no colour.
Each of 1
s and 0
s in a length and width
rectangle. For example, here is a
and
paintbrush where point
is a
0
, and all other points are a
1
.
1 0 1
1 1 1
When painting on the canvas at a co-ordinate using a specific paintbrush
and a specific colour
, a
1
at any point on the paintbrush means that the co-ordinate
should be painted to
.
For example, if by
canvas as follows:
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Using the above paintbrush at index with colour
would lead to the following canvas:
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 5 0 5 0 0
0 5 5 5 0 0
Note that the following points, were painted.
Using the same paintbrush again at index with colour
would lead to the following canvas:
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 5 4 5 4 0
0 5 4 4 4 0
Wanting to paint a total of times, can you help create a painting app?
Input Specification
On the first line, five space-separated integers ,
,
, and
.
For each of the paintbrushes, there will be a line containing two space-separated integers
and
, representing the length and width of the
th paintbrush. The next
lines will contain
space-separated integers, either a
1
or a 0
, representing the pattern of that paintbrush.
The next lines contain four space-separated integers
,
,
and
, meaning to paint the canvas at the co-ordinate
, using the
-th paintbrush and colour
.
Output Specification
lines with
space-separated integers per line, representing the final canvas.
Constraints
and
Sample Input
5 6 1 2
2 3
1 0 1
1 1 1
0 5 3 1
0 4 3 2
Sample Output
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 5 4 5 4 0
0 5 4 4 4 0
Comments