#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define printg(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int get_random() {
    static uniform_int_distribution<int> dist(0, 1e9 + 6);
    return dist(rng);
}
#define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);}


typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val)

template<class T>
void make_unique(T & v) {
    sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
}
int geti() { int x; cin >> x; return x; }
long long getll() { long long x; cin >> x; return x; }
double getd() { double x; cin >> x; return x; }
// pair<int, int> a(geti(), geti()) does not work
// pair<int, int> a({geti(), geti()}) works, since it uses initializer.

const int MAXN = 3e5 + 100;

void solve(int tt) {
    // cout<<"Case #"<<tt<<": ";
}

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // solve_testcase;

    int n;
    cin>>n;

    string s;
    cin>>s;
    const string s110="110";

    ll tot=1e10;
    if(n==1) {
    	if(s[0]=='0') cout<<tot<<endl;
    	else cout<<2*tot<<endl;
    	return 0;
    }

    if(s[0]=='0') s = "11"+s;
    else if(s[1]=='0') s = "1"+s;

    n=s.size();
    if(s[n-1]=='1') {
    	if(s[n-2]=='1') s+='0';
    	else s += "10";
    }

    print(s);

    if(s.size()%3) {
    	cout<<0<<endl;
    	return 0;
    }

    int ok=1;
    rep(i,0,n) {
    	if(s[i]!=(i%3==2?'0':'1'))
    		ok=0;
    }
    if(!ok) {
    	cout<<0<<endl;
    	return 0;
    }

    cout<<tot-ll(s.size())/3+1<<endl;




    return 0;
}












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

typedef long long ll;
#ifdef LOCAL
    constexpr int DEBUG = 1;
#else
    constexpr int DEBUG = 0;
#endif

const int N = 505;
const int MOD = 998244353;
char s[N][N], t[N + N];
void solve() {
    int n, m;
    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){
            if(s[i][j] == 'B'){
                if(t[i + j] == 'R'){
                    cout << 0 << endl; return;
                }
                t[i + j] = 'B';
            }
            if(s[i][j] == 'R'){
                if(t[i + j] == 'B'){
                    cout << 0 << endl; return;
                }
                t[i + j] = 'R';
            }
        }
    }
    ll ans = 1;
    for(int i = 2; i <= n + m; ++i){
        if(t[i] == 0) ans = ans * 2 % MOD;
    }
    cout << ans << endl;
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    cout << "start Debug" << endl;
#endif
    int _ = 1;
    // cin >> _;
    for(int i = 1; i <= _; ++i) solve(); 
}