#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 128
#define K 16384

char s[N];
int a[N], d[N];
int b[K][N];

bool check(int n, int k)
{
    int q = a[0]/k, r = a[0]%k;
    int pos = r;

    for (int i = 0; i < r; ++i) b[i][0] = q+1;
    for (int i = r; i < k; ++i) b[i][0] = q;
    for (int j = 0; j < n; ++j) {
        for (int i = 0; i < k; ++i) b[i][j+1] = b[i][j];
        if (s[j] == '<') {
            /// +1
            for (int i = 0; i < k; ++i) ++b[i][j+1];
            for (int i = 0; i < d[j]-k; ++i) {
                ++b[pos][j+1];
                if (++pos >= k) pos = 0;
            }
        } else {
            /// -1
            for (int i = 0; i < k; ++i) {
                retif(--b[i][j+1] < 0) false;
            }
            for (int i = 0; i < d[j]-k; ++i) {
                if (--pos < 0) pos = k-1;
                retif(--b[pos][j+1] < 0) false;
            }
        }
    }
    return true;
}

int main()
{
    canhazfast();

    int n, lo = 1, hi = K;

    cin >> n >> s;
    for (int i = 0; i <= n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) {
        d[i] = abs(a[i+1]-a[i]);
        hi = min(hi, abs(d[i]));
    }
    while (lo < hi) {
        int m = (lo+hi+1)/2;
        if (check(n, m)) lo = m;
        else hi = m-1;
    }
    check(n, hi);
    cout << hi << '\n';
    for (int i = 0; i < hi; ++i) {
        for (int j = 0; j <= n; ++j) cout << b[i][j] << ' ';
        cout << '\n';
    }

    return 0;
}

#include<bits/stdc++.h>

#define ll long long 

using namespace std;

int read()
{
	int a=0,f=1,c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')f=-1;
		c=getchar();
	}
	while(isdigit(c))
	{
		a=a*10+c-'0';
		c=getchar();
	}
	return a*f;
}

const int N=500+10;
const int P=998244353;

int n,m;
char s[N][N];
int f[N*2];

int main()
{
//	freopen("1.in","r",stdin);
	
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
	
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			int c=0;
			if(s[i][j]=='R')c=1;
			else if(s[i][j]=='B')c=2;
			
			if(c>0)
			{
				if(f[i+j]>0 && f[i+j]!=c)
				{
					puts("0");
					return 0;
				}
				f[i+j]=c;
			}
		}
	
	int ans=1;
	for(int i=2;i<=n+m;++i)ans=(ans*(f[i]>0 ? 1 : 2))%P;
	printf("%d\n",ans);
	
	return 0;
}