#CODEFESTIVAL2016FINALJ. Neue Spiel

Neue Spiel

Score : 21002100 points

Problem Statement

Snuke has a board with an N×NN \times N grid, and N×NN \times N tiles.

Each side of a square that is part of the perimeter of the grid is attached with a socket. That is, each side of the grid is attached with NN sockets, for the total of 4×N4 \times N sockets. These sockets are labeled as follows:

  • The sockets on the top side of the grid: U1,U2,...,UNU1, U2, ..., UN from left to right
  • The sockets on the bottom side of the grid: D1,D2,...,DND1, D2, ..., DN from left to right
  • The sockets on the left side of the grid: L1,L2,...,LNL1, L2, ..., LN from top to bottom
  • The sockets on the right side of the grid: R1,R2,...,RNR1, R2, ..., RN from top to bottom

Figure: The labels of the sockets

Snuke can insert a tile from each socket into the square on which the socket is attached. When the square is already occupied by a tile, the occupying tile will be pushed into the next square, and when the next square is also occupied by another tile, that another occupying tile will be pushed as well, and so forth. Snuke cannot insert a tile if it would result in a tile pushed out of the grid. The behavior of tiles when a tile is inserted is demonstrated in detail at Sample Input/Output 11.

Snuke is trying to insert the N×NN \times N tiles one by one from the sockets, to reach the state where every square contains a tile. Here, he must insert exactly UiU_i tiles from socket UiUi, DiD_i tiles from socket DiDi, LiL_i tiles from socket LiLi and RiR_i tiles from socket RiRi. Determine whether it is possible to insert the tiles under the restriction. If it is possible, in what order the tiles should be inserted from the sockets?

Constraints

  • 1N3001 \leq N \leq 300
  • Ui,Di,LiU_i,D_i,L_i and RiR_i are non-negative integers.
  • The sum of all values Ui,Di,LiU_i,D_i,L_i and RiR_i is equal to N×NN \times N.

Partial Scores

  • 20002000 points will be awarded for passing the test set satisfying N40N \leq 40.
  • Additional 100100 points will be awarded for passing the test set without additional constraints.

Input

The input is given from Standard Input in the following format:

NN

U1U_1 U2U_2 ...... UNU_N

D1D_1 D2D_2 ...... DND_N

L1L_1 L2L_2 ...... LNL_N

R1R_1 R2R_2 ...... RNR_N

Output

If it is possible to insert the tiles so that every square will contain a tile, print the labels of the sockets in the order the tiles should be inserted from them, one per line. If it is impossible, print NO instead. If there exists more than one solution, print any of those.

3
0 0 1
1 1 0
3 0 1
0 1 1
L1
L1
L1
L3
D1
R2
U3
R3
D2

Snuke can insert the tiles as shown in the figure below. An arrow indicates where a tile is inserted from, a circle represents a tile, and a number written in a circle indicates how many tiles are inserted before and including the tile.

2
2 0
2 0
0 0
0 0
NO