#include<bits/stdc++.h>
#define N 105
using namespace std;
int n,a[N],ans=1e9;
char s[N];
int Abs(int x) {
	return x<0?-x:x;
}
int main() {
	scanf("%d%s",&n,s+1);
	for(int i=0; i<=n; ++i) {
		scanf("%d",&a[i]);
		if(i>0)ans=min(ans,Abs(a[i]-a[i-1]));
	}
	cout<<ans<<"\n";
	for(int i=0; i<ans; ++i,puts(""))
		for(int j=0; j<=n; ++j)cout<<a[j]/ans+(i<a[j]%ans)<<" ";
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false


ll N = 50;
ll sy,sx;
vector<vector<ll>> T(N),P(N);

pair<ll,string> eval(string K){
    
    bool visited[2500]={};
    string R;
    ll score = 0;
    
    ll y=sy,x=sx;
    visited[T[y][x]]=true;
    score += P[y][x];
    
    REP(i,K.size()){
        if(K[i]=='L'){
            x--;
        }else if(K[i]=='R'){
            x++;
        }else if(K[i]=='D'){
            y++;
        }else{
            y--;
        }
        
        if(!(0<=x && x<N)){
            return {score,R};
        }
        if(!(0<=y && y<N)){
            return {score,R};
        }
        if(visited[T[y][x]]){
            return {score,R};
        }
        visited[T[y][x]]=true;
        score += P[y][x];
        R.push_back(K[i]);
    }
    return {score,R};
}

int main(void){
    
    
    cin >> sy >> sx;
    REP(i,N){REP(j,N){
        ll t;
        cin >> t;
        T[i].push_back(t);
    }}
    REP(i,N){REP(j,N){
        ll p;
        cin >> p;
        P[i].push_back(p);
    }}
    
    char C[4]={'L','R','U','D'};
    
    std::mt19937 mt{ std::random_device{}() };
    std::uniform_int_distribution<int> dist(0, 3);
    
    string dna = "";
    REP(i,N*N){dna.push_back(C[dist(mt)]);}
    ll rna = eval(dna).first;
    
    vector<ll> Per;
    REP(i,N*N){
        REP(j,max((N*N-i)/10,2ll)){
            Per.push_back(i);
        }
    }
    
    ll M = Per.size();
    std::mt19937 mt2{ std::random_device{}() };
    std::uniform_int_distribution<int> dist2(0, M-1);
    

    
    REP(j,240000){
        
        ll genes = rna;string gene = dna;
        
        REP(k,10){
            string S = dna;
            char c = C[dist(mt)];
            ll l = Per[dist2(mt2)];
            S[l]=c;
            
            pair<ll,string> Nd = eval(S);
            if(Nd.first>=genes){
                genes = Nd.first;
                gene = S;
            }
            
        }
        
        if(genes>=rna){
            rna = genes;
            dna = gene;
        }
        
        
    }
    
    dna = eval(dna).second;
    cout << dna << endl;
    
    /*
    ll score = 0;string K = "";
    REP(j,10000){
        
        string S;
        REP(i,N*N){
            S.push_back(C[dist(mt)]);
        }
        pair<ll,string> R = eval(S);
        if(score<=R.first){
            score = R.first;
            K = R.second;
        }
        
    }
    cout << K << endl;*/
    
    
    return 0;
}