{"problem":{"name":"Neue Spiel","description":{"content":"Snuke has a board with an $N \\times N$ grid, and $N \\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 attach","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":4000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"codefestival_2016_final_j"},"statements":[{"statement_type":"Markdown","content":"Snuke has a board with an $N \\times N$ grid, and $N \\times N$ tiles.\nEach 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 $N$ sockets, for the total of $4 \\times N$ sockets. These sockets are labeled as follows:\n\n*   The sockets on the top side of the grid: $U1, U2, ..., UN$ from left to right\n*   The sockets on the bottom side of the grid: $D1, D2, ..., DN$ from left to right\n*   The sockets on the left side of the grid: $L1, L2, ..., LN$ from top to bottom\n*   The sockets on the right side of the grid: $R1, R2, ..., RN$ from top to bottom\n\n![image](https://atcoder.jp/img/code-festival-2016-final/916ffede6e718801d689f189e658a9bb.png)\n\nFigure: The labels of the sockets\n\nSnuke 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 $1$.\nSnuke is trying to insert the $N \\times N$ tiles one by one from the sockets, to reach the state where every square contains a tile. Here, he must insert exactly $U_i$ tiles from socket $Ui$, $D_i$ tiles from socket $Di$, $L_i$ tiles from socket $Li$ and $R_i$ tiles from socket $Ri$. 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?\n\n## Constraints\n\n*   $1≦N≦300$\n*   $U_i,D_i,L_i$ and $R_i$ are non-negative integers.\n*   The sum of all values $U_i,D_i,L_i$ and $R_i$ is equal to $N \\times N$.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$U_1$ $U_2$ $...$ $U_N$\n$D_1$ $D_2$ $...$ $D_N$\n$L_1$ $L_2$ $...$ $L_N$\n$R_1$ $R_2$ $...$ $R_N$\n\n## Partial Scores\n\n*   $2000$ points will be awarded for passing the test set satisfying $N≦40$.\n*   Additional $100$ points will be awarded for passing the test set without additional constraints.\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"codefestival_2016_final_j","tags":[],"sample_group":[["3\n0 0 1\n1 1 0\n3 0 1\n0 1 1","L1\nL1\nL1\nL3\nD1\nR2\nU3\nR3\nD2\n\nSnuke 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.\n![image](https://atcoder.jp/img/code-festival-2016-final/252110b5818dc7d972f77d90f99cb8cb.png)"],["2\n2 0\n2 0\n0 0\n0 0","NO"]],"created_at":"2026-03-03 11:01:13"}}