Skittlez. Taste the rainbow, solve the rainbow.
Mr. Rainbow McRainbows is the employee of the month in the Skittlez factory's Department of Rainbow Packing (as he is the only one working in this department).
For those unfamiliar with them, a bag of Skittlez is filled with small, round, colorful pieces of candy that taste like fruits. If you ever wondered how they are packed and why there are never enough green ones in a bag, today is your lucky day, as Mr.~McRainbows will give you an exclusive into how the Skittlez bags are filled.
Task
The Rainbow Packing Department has two components: the bags grid and the filling machine. The bags grid is divided into rows (numbered from to ) and columns (numbered from to ), where each cell contains a bag that has to be filled with candy of various colors. The filling machine is used to pour candy into the bags from the grid and takes commands of the following type: , meaning that in each bag from a cell with and , the machine will pour candy pieces of color .
Mr. McRainbows has a fairly boring job, with his only responsibility being to operate the filling machine. At the beginning of each day, all the bags in the grid are empty, and Rainbow's supervisors give him a list of commands that he has to enter into the machine. Hence, he decided to write a program that does his job for him so he can focus on more intellectual activities like playing Solitaire.
Unfortunately, his supervisors started getting suspicious when they saw how much his high score increased (as with any respectable company, Skittlez has an internal Solitaire scoreboard). Consequently, they asked him to file a report at the end of each day stating which of the packed bags contain an overwhelming color. A color is considered overwhelming for a bag if there are strictly more candy pieces of that color in the bag than all others in the bag combined.
Because he doesn't really know how to do that, and he doesn't want to waste a few days figuring it out, he asks you to write a program that will compute the report. Formally, you are given the size of the bags grid and the list of commands the machine receives in a day, and you want to output a matrix with the same number of rows and columns as the grid where:
Input data
The first line of the input contains two positive integer numbers , the size of the bags grid, and , the number of commands the machine receives on the given day.
Each of the next lines contains six positive integers, , , , , and , describing a command. The values on each input line are separated by spaces.
Output data
Output lines, each containing space-separated integers, representing the matrix described above.
Restrictions and clarifications
- Note! The extra spaces in the examples' output have been added for better visibility; you should print only one space between any two consecutive values.
# | Points | Restrictions |
---|---|---|
1 | 7 | and |
2 | 21 | There are at most different candy colours. |
3 | 44 | and |
4 | 28 | No further restrictions. |
Example 1
stdin
5 3
1 3 5 5 3 3
2 2 4 4 1 5
1 1 3 5 1 3
stdout
1 1 -1 -1 -1
1 1 1 1 -1
1 1 1 1 -1
-1 1 1 1 3
-1 -1 3 3 3
Example 2
stdin
10 10
1 6 6 10 2 4
5 4 9 8 2 5
2 7 6 9 2 3
6 3 10 9 6 4
1 2 2 10 1 3
5 1 7 6 1 3
9 1 9 2 2 4
4 6 8 7 2 3
2 5 3 7 2 4
1 8 6 10 2 3
stdout
-1 1 1 1 1 2 2 2 2 2
-1 1 1 1 2 2 2 2 2 2
-1 -1 -1 -1 2 2 2 2 2 2
-1 -1 -1 -1 -1 2 2 2 2 2
1 1 1 2 2 2 2 2 2 2
1 1 6 -1 -1 2 2 2 2 2
1 1 6 -1 -1 2 2 2 6 -1
-1 -1 6 2 2 2 2 2 6 -1
2 2 6 2 2 2 2 2 6 -1
-1 -1 6 6 6 6 6 6 6 -1