11636 - Farm   

Description

American‧SHENGDIYAGE is a global influential company.
Now, you have a chance to visit its factory. The factory is constitute by N*M spaces. The left top space is (0,0) and the right down is ( N-1, M-1).
First, you are located at (0,0), and then company's president will give you some instructions you should follow. There are four kinds of instructions that are represented by 1,2,3,4:

・1 means to go up .
    If you at (1,2), then u will go to (0,2)
・2 means to go down .
    If you at (1,2), then u will go to (2,2)
・3 means to go left .
    If you at (1,2), then u will go to (1,1)
・4 means to go right .
    If you at (1,2), then u will go to (1,3)

But sometimes the president will give wrong instructions such as asking you to walk to boundary. When you get a wrong instruction , you have to stop at the same position, waiting for his next instruction.
After visiting, you want to know how many times you have passed each space(The number of times of each space will increase by one each time you pass the space), and you also want to know the number of wrong instructions that the president have said.

Input

There are 2 integers N,M in the first line. N, M <= 1000, which means there are N*M spaces in the factory.
The next number, K, means there are K instructions.Then the next line contains K instructions given by President.

Output

Output an integer in the first line indicating the number of wrong instructions given by President. Then output N*M numbers to represent the times you have passed each space.

Sample Input  Download

Sample Output  Download

Tags




Discuss