- Time limit: 1.00 s
- Memory limit: 512 MB
There is an grid whose each square has some number of coins in it.
You know for each row and column how many squares you must choose from that row or column. You get all coins from every square you choose. What is the maximum number of coins you can collect and how could you choose the squares so that the given conditions are satisfied?
Input
The first input line has an integer : the size of the grid. The rows and columns are numbered .
The next line has integers : You must choose exactly squares from the th row.
The next line has integers : You must choose exactly squares from the th column.
Finally, there are lines describing the grid. You can assume that the sums of and are equal.
Output
First print an integer : the maximum number of coins you can collect. After this print lines describing which squares you choose (X
means that you choose a square, .
means that you don't choose it).
If it is not possible to satisfy the conditions print only .
Constraints
Example
Input:
5 0 1 3 2 0 1 2 2 0 1 2 5 1 5 1 0 2 5 1 2 3 8 9 3 5 1 4 3 7 3 0 3 6 2 8
Output:
32 ..... ..X.. .XX.X XX... .....