#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 200000 + 10;
char s[N]; int n;
int lef[N];
int main() {
	scanf("%d%s", &n,s+1);	
	if(s[1] == 'W') return !printf("0\n");
	lef[1]=1;
	for(int i=2;i<=2*n;i++){
		if(s[i]==s[i-1]) lef[i]=1^lef[i-1];
		else lef[i]=lef[i-1];
	}

	int cnt=0,ans=1;
	for(int i=1;i<=2*n;i++){
		//printf("# %d\n", lef[i]);
		if(lef[i]){cnt++;}
		else {	
			ans=1LL*ans*cnt%MOD;
			if(cnt==0)return !printf("0\n");
			cnt--;
		}
	}
	if(cnt)return !printf("0\n");
	for(int i=1;i<=n;i++)ans=1LL*ans*i%MOD;
	cout<<ans<<endl;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse -> greater<long long>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

int main(){
   ll n;cin>>n;
   VI a(n);
   rep(i,n)cin>>a[i];
   VI cnt(3,0);
   ll ans=1;
   rep(i,n){
      int mul=0;
      rep(j,3){
         if(cnt[j]==a[i]){
            mul++;
         }
      }
      rep(j,3){
         if(cnt[j]==a[i]){
            cnt[j]++;
            break;
         }
      }
      ans=(ans*mul)%MOD;
   }
   cout<<ans<<endl;
}