#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

string s[505];

const int MOD = 998244353;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, m;
    cin >> n >> m;
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    int res = 1;
    for(int sm=0; sm<=n+m-2; sm++){
        int imap = 0;
        int iman = 0;
        for(int i=0; i<n; i++){
            int j = sm-i;
            if(j < 0 || j >= m) continue;
            if(s[i][j] == 'B') imap = 1;
            if(s[i][j] == 'R') iman = 1;
        }
        res = (res*(2-imap-iman))%MOD;
    }
    cout << res;
    return 0;
}

//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define MAXN 3001
ll dp[MAXN][MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N; cin>>N;
    ll arr[N + 1];
    
    for(ll i=0;i<N;++i)
        cin>>arr[i + 1];
    
    for(ll i=0;i<=N;++i)
    {
        for(ll j=0;j<=N;++j)
        {
            dp[i][j] = 0;
        }
    }
    
    dp[0][0] = 1; //base case
    
    for(ll k=1;k<=N;++k)
    {
        ll sum = 0;
        ll memo[N + 1] = {}; //storing transtion results for current state (i, k)
        map<ll,ll> mp;
        mp[0] = 0;
        
        for(ll i=1;i<=N;++i)
        {
            sum += arr[i];
            sum %= k;
            
            if(mp.find(sum) != mp.end())
            {
                ll j = mp[sum];
                memo[i] = memo[j] + dp[j][k - 1];
                memo[i] %= MOD;
            }
            mp[sum] = i;
        }
        
        for(ll i=1;i<=N;++i)
            dp[i][k] = memo[i];
    }
    
    ll ans = 0;
    for(ll k=1;k<=N;++k)
    {
        ans += dp[N][k];
        ans %= MOD;
    }
    
    cout<<ans<<endl;
}