Problem:
Score : 2100 points

Problem Statement

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 attached with N sockets, for the total of 4 \times N sockets.
These sockets are labeled as follows:

The sockets on the top side of the grid: U1, U2, ..., UN from left to right

The sockets on the bottom side of the grid: D1, D2, ..., DN from left to right

The sockets on the left side of the grid: L1, L2, ..., LN from top to bottom

The sockets on the right side of the grid: R1, 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 1.

Snuke 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?

Constraints

1≦N≦300

U_i,D_i,L_i and R_i are non-negative integers.

The sum of all values U_i,D_i,L_i and R_i is equal to N \times N.

Partial Scores

2000 points will be awarded for passing the test set satisfying N≦40.

Additional 100 points will be awarded for passing the test set without additional constraints.

Input

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

N
U_1 U_2 ... U_N
D_1 D_2 ... D_N
L_1 L_2 ... L_N
R_1 R_2 ... R_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.

Sample Input 1

3
0 0 1
1 1 0
3 0 1
0 1 1

Sample Output 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.

Sample Input 2

2
2 0
2 0
0 0
0 0

Sample Output 2

NO

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;

int n;

int ar[4][305];

void ng(){
  puts("NO");
  exit(0);
}

int buf[305][305];//0:horizonal 1:vertical
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
//down,right,up,left

int LR[305],UD[305];

int ud[305],perm[305];


bool done[305][305];
bool vis[305][305];
bool start[305][305];

vector<pi> ever;
bool dfs(int y,int x){
  ever.pb(mp(y,x));
  dump(y);dump(x);
  if(vis[y][x]){
    prl;
    int m=ever.size();
    for(int i=m-1;i>=0;--i) if(ever[i]==mp(y,x)){
      for(int j=m-1;j>i;--j){
        int nxt=j+1;
        if(nxt==m) nxt=i;
        pi p=ever[j],q=ever[nxt];
        swap(buf[p.fr][p.sc],buf[q.fr][q.sc]);
      }
      start[y][x]=1;
    }
    vis[y][x]=0;
    return true;
  }
  vis[y][x]=1;
  int d=buf[y][x];
  int py=y+dy[d],px=x+dx[d];
  while(!(px<0 || py<0 || px>=n || py>=n)){
    if(!done[py][px]){
      if(dfs(py,px)){
        if(start[y][x]){
          start[y][x]=false;
          ever.pop_back();
          vis[y][x]=0;
          return dfs(y,x);
        }else{
          vis[y][x]=0;
          ever.pop_back();
          return true;
        }
      }
    }
    px+=dx[d],py+=dy[d];
  }
  done[y][x]=1;
  char code[]="DRUL";
  printf("%c%d\n",code[buf[y][x]],buf[y][x]&1?y+1:x+1);
  ever.pop_back();
  return false;
}
int main(){
  cin>>n;
  REP(i,4) REP(j,n) cin>>ar[i][j];

  REP(i,n) if(ar[0][i]+ar[1][i]>n || ar[2][i]+ar[3][i]>n) ng();
  prl;
  REP(i,n){
    LR[i]=ar[2][i]+ar[3][i];
    UD[i]=ar[0][i]+ar[1][i];
  }

  REP(j,n) ud[j]=UD[j];
  REP(i,n){
    REP(j,n) perm[i]=i;
    sort(perm,perm+n,[&](int a,int b){
      return ud[a]<ud[b];
    });

    REP(j,n){
      if(j<LR[i]) buf[i][perm[j]]=0;
      else buf[i][perm[j]]=1,--ud[perm[j]];
    }
  }
  debug(ud,ud+n);
  REP(i,n) if(ud[i]!=0) ng();
  prl;


  REP(i,n){
    REP(j,n){
      if(buf[i][j]==0){
        if(ar[2][i]>0) buf[i][j]=3,--ar[2][i];
        else buf[i][j]=1;
      }else{
        if(ar[0][j]>0) buf[i][j]=2,--ar[0][j];
        else buf[i][j]=0;
      }
    }
  }
  buf[1][2]=3;
  REP(i,n) debug(buf[i],buf[i]+n);
  REP(i,n) REP(j,n) if(!done[i][j]) dfs(i,j);
  REP(i,n) debug(buf[i],buf[i]+n);

  return 0;
}