You are given a string representing the colors of squares arranged from left to right. You can perform N operations, each time choosing two distinct squares and inverting the colors of those squares and the squares between them. Find the number of ways to make all the squares white at the end of the process, considering different ways based on the pairs of squares chosen in each operation. Constraints: 1 ≤ N ≤ 10^5, |S| = 2N, and each character of S is 'B' or 'W'. Input is given as N and the string S. Output the number of ways to make all squares white, modulo 10^9+7. If there are no such ways, print 0.

# Buggy version:
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
S = input()[:-1]

if S[0]=='W':
    print(0)
    exit()
    
l = [0]
ans = 1
MOD = 10**9+7

for i in range(1, 2*N):
    if S[i]==S[i-1]:
        l.append(1^l[-1])
    else:
        l.append(l[-1])

if l.count(0)!=n:
    print(0)
    exit()
    
zero = 0

for li in l:
    if li==0:
        zero += 1
    else:
        ans *= zero
        ans %= MOD
        zero -= 1
        
for i in range(1, N+1):
    ans *= i
    ans %= MOD

print(ans)

# Fixed version:
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
S = input()[:-1]

if S[0]=='W':
    print(0)
    exit()
    
l = [0]
ans = 1
MOD = 10**9+7

for i in range(1, 2*N):
    if S[i]==S[i-1]:
        l.append(1^l[-1])
    else:
        l.append(l[-1])

if l.count(0)!=N:
    print(0)
    exit()
    
zero = 0

for li in l:
    if li==0:
        zero += 1
    else:
        ans *= zero
        ans %= MOD
        zero -= 1
        
for i in range(1, N+1):
    ans *= i
    ans %= MOD

print(ans)

# Buggy version:
n=int(input())
s=input()
m=10**9+7
l=1
for i in range(1,n+1):l=(l*i)%m
t=[0]*(2*n)
t[0]=1
for i in range(1,2*n):
    if s[i-1]==s[i]:
        t[i]=1-t[i-1]
    else:
        t[i]=t[i-1]
if t.count(1)==n:
    p=1
    c=0
    for i in t:
        c+=i
        if i==0:
            p=(p*c)%m
            c-=1
    print((p*l)%m)
else:
    print(0)

# Fixed version:
n=int(input())
s=input()
m=10**9+7
l=1
for i in range(1,n+1):l=(l*i)%m
t=[0]*(2*n)
t[0]=1
for i in range(1,2*n):
    if s[i-1]==s[i]:
        t[i]=1-t[i-1]
    else:
        t[i]=t[i-1]
if t.count(1)==n and s[0]==s[-1]=="B":
    p=1
    c=0
    for i in t:
        c+=i
        if i==0:
            p=(p*c)%m
            c-=1
    print((p*l)%m)
else:
    print(0)

# Buggy version:
def f_c():
    n = int(input())
    s = input()

    stack, c = 1, 1
    for si in s[1:]:
        if si=="B":
            if stack%2==0:
                stack += 1
            else:
                c *= stack
                stack -= 1
        else:
            if stack%2==0:
                c *= stack
                stack -= 1
            else:
                stack += 1
    if stack!=0 | c==0:
        print(0)
    else:
        for i in range(1, n+1):
            c*=i
        print(c%(10**9+7))

if __name__ == "__main__":
    f_c()


# Fixed version:
def f_c():
    n = int(input())
    s = input()
    q = 10**9+7

    stack, c = 1, 1
    for si in s[1:]:
        if si=="B":
            if stack%2==0:
                stack += 1
            else:
                c *= stack
                stack -= 1
        else:
            if stack%2==0:
                c *= stack
                stack -= 1
            else:
                stack += 1
        c %= q
    if stack!=0 or c==0:
        print(0)
    else:
        for i in range(1, n+1):
            c *= i
            c %= q
        print(c)

if __name__ == "__main__":
    f_c()

# Buggy version:
n=int(input())
s=list(input())
m=2*n
mod=10**9+7

if s[0]=="W" or s[m-1]=="W":
    print(0)
    exit()

rl=[L]
for i in range(1,m):
    if s[i-1]==s[i]:
        if rl[i-1]=="L":
            rl.append("L")
        else: 
            rl.append("R")
    else:
        if rl[i-1]=="R":
            rl.append("L")
        else: 
            rl.append("R")
if rl[m-1]=="L":
    print(0)
    exit()
nl=0
for i in range(m):
    if rl[i]=="L":
        nl+=1
if nl!=n:
    print(0)
    exit()
    
ans=1
li=0
ri=0
for i in range(m):
    if rl[i]=="L":
        li+=1
    else:
      if li-ri<0:
          ans=0
      ans*=li-ri
      ans=ans%mod
      ri+=1
    if i>=1 and i<=n:
        ans*=i
        ans=ans%mod
print(ans)
      


         

# Fixed version:
n=int(input())
s=list(input())
m=2*n
mod=10**9+7

if s[0]=="W" or s[m-1]=="W":
    print(0)
    exit()

rl=["L"]
for i in range(1,m):
    if s[i-1]==s[i]:
        if rl[i-1]=="R":
            rl.append("L")
        else: 
            rl.append("R")
    else:
        if rl[i-1]=="L":
            rl.append("L")
        else: 
            rl.append("R")
if rl[m-1]=="L":
    print(0)
    exit()
nl=0
for i in range(m):
    if rl[i]=="L":
        nl+=1
if nl!=n:
    print(0)
    exit()
    
ans=1
li=0
ri=0
for i in range(m):
    if rl[i]=="L":
        li+=1
    else:
      if li-ri<0:
          ans=0
      ans*=li-ri
      ans=ans%mod
      ri+=1
    if i>=1 and i<=n:
        ans*=i
        ans=ans%mod
print(ans)

# Buggy version:
import math
n=int(input())*2
S=list(input())
# Lを1、Rを0としてDP
dp=[0]*(n)
dp[0]=1
if S[0]=='W' or S[-1]=='W':
	print(0)
	exit()
for i in range(1,n):
	# print(S,i)
	if S[i]==S[i-1]:
		dp[i]=0 if dp[i-1] else 1
	else:
		dp[i]=1 if dp[i-1] else 0

count=1
counter=[0]*2
for i in range(n):
	if dp[i]==0:
		count*=counter[1]-counter[0]
		count%=10**9+7
	counter[dp[i]]+=1
if counter[0]!=counter[1]:
	print(0)
	exit()

print((count*math.factorial(n//2))%10**9+7)
# print(dp)




# Fixed version:
import math
mod=10**9+7
n=int(input())*2
S=list(input())
# Lを1、Rを0としてDP
dp=[0]*(n)
dp[0]=1
if S[0]=='W' or S[-1]=='W':
	print(0)
	exit()
for i in range(1,n):
	# print(S,i)
	if S[i]==S[i-1]:
		dp[i]=0 if dp[i-1] else 1
	else:
		dp[i]=1 if dp[i-1] else 0

count=1
counter=[0]*2
for i in range(n):
	if dp[i]==0:
		count*=counter[1]-counter[0]
		count%=mod
	counter[dp[i]]+=1
if counter[0]!=counter[1]:
	print(0)
	exit()

print((count*math.factorial(n//2))%mod)
# print(dp)

# Buggy version:
import sys
input = sys.stdin.readline
Q = 10**9+7
def main():
    N = int( input())
    S = input()
    left = 0
    ans = 1
    for s in S:
        if s == "B":
            if left%2 == 0:
                left += 1
            else:
                if left == 0:
                    print(0)
                    return
                ans *= left
                left -= 1
        else:
            if left%2 == 1:
                left += 1
            else:
                if left == 0:
                    print(0)
                    return
                ans *= left
                left -= 1
        ans %= Q
    if left > 0:
        print(0)
        return
    for i in range(1,N+1):
        ans *= i
        ans %= Q
    print(ans)
if __name__ == '__main__':
    main()


# Fixed version:
import sys
input = sys.stdin.readline
Q = 10**9+7
def main():
    N = int( input())
    S = input()
    left = 0
    ans = 1
    for i in range(N*2):
        s = S[i]
        if s == "B":
            if left%2 == 0:
                left += 1
            else:
                ans *= left
                left -= 1
        else:
            if left%2 == 1:
                left += 1
            else:
                ans *= left
                left -= 1
        ans %= Q
    if left > 0 or ans == 0:
        print(0)
        return
    for i in range(1,N+1):
        ans *= i
        ans %= Q
    print(ans)
if __name__ == '__main__':
    main()

# Buggy version:
import sys
def main():
    n=int(input())
    s=input()
    MOD=10**9+7
    perm=1
    for i in range(1,n+1):
        perm=perm*i%MOD
    ans=1
    dp=[-1]*(2*n)

    dp[0]=1#L
    count=0
    for i in range(1,2*n):
        if s[i]==s[i-1]:
            dp[i]=1-dp[i-1]
        else:
            dp[i]=dp[i-1]
        if dp[i]==1:
            count+=1
        else:
            ans*=count
            count-=1
    if s[0]=='W' or s[-1]=='W' or sum(dp)!=n:
        print(0)
        sys.exit()
    #print(dp)
    
    
    print(ans*perm%MOD)

if __name__ == '__main__':
    main()

# Fixed version:
import sys
def main():
    n=int(input())
    s=input()
    MOD=10**9+7
    perm=1
    for i in range(1,n+1):
        perm=perm*i%MOD
    ans=1
    dp=[-1]*(2*n)

    dp[0]=1#L
    for i in range(1,2*n):
        if s[i]==s[i-1]:
            dp[i]=1-dp[i-1]
        else:
            dp[i]=dp[i-1]
    if s[0]=='W' or s[-1]=='W' or sum(dp)!=n:
        print(0)
        sys.exit()
    #print(dp)
    count=0
    for i in range(2*n):
        if dp[i]==1:
            count+=1
        else:
            ans*=count
            ans%=MOD
            count-=1
    print(ans*perm%MOD)

if __name__ == '__main__':
    main()

# Buggy version:
import sys
from math import factorial

N = int(input())
S = input()

if S[0] == 'W' or S[-1] == 'W':
    print(0)
    sys.exit()

op = "L"
for i in range(1, 2*N):
    if S[i] == S[i-1]:
        op += 'R' if op[i-1] == 'L' else 'L'
    else:
        op += 'R' if op[i-1] == 'R' else 'L'

if op.count('L') != N:
    print(0)
    sys.exit()

ct_L, ans = 0, 1

for i in op:
    if i == 'L':
        ct_L += 1
    else:
        ans *= ct_L
        ct_L -= 1
    ans %= mod

mod = 10**9+7
print(factorial(N) * ans % mod)


# Fixed version:
import sys
from math import factorial

N = int(input())
S = input()
mod = 10**9+7

if S[0] == 'W' or S[-1] == 'W':
    print(0)
    sys.exit()

op = "L"
for i in range(1, 2*N):
    if S[i] == S[i-1]:
        op += 'R' if op[i-1] == 'L' else 'L'
    else:
        op += 'R' if op[i-1] == 'R' else 'L'

if op.count('L') != N:
    print(0)
    sys.exit()

ct_L, ans = 0, 1

for i in op:
    if i == 'L':
        ct_L += 1
    else:
        ans *= ct_L
        ct_L -= 1
    ans %= mod


print(factorial(N) * ans % mod)

# Buggy version:
from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()

ans = 1
inf = 10 ** 9 + 7
d = 'L'
l_count = 1
r_count = 0
for i in range(1, 2 * N):
    if S[i] == 'R':
        ans *= l_count - r_count
        ans %= inf
    if S[i] != S[i - 1]:
        l_count += 1
    else:
        if d == 'R':
            d = 'L'
        else:
            d = 'R'
        r_count += 1

for j in range(1, N + 1):
    ans *= j
    ans %= inf

print(ans % inf)


# Fixed version:
from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()

ans = 1
inf = 10 ** 9 + 7
d = 'L'
l_count = 1
r_count = 0

if S[0] == 'W' or S[2 * N - 1] == 'W':
    print(0)
    exit()

for i in range(1, 2 * N):
    if S[i] != S[i - 1]:
        if d == 'R':
            ans *= l_count - r_count
            ans %= inf
            r_count += 1
        else:
            l_count += 1
    else:
        if d == 'R':
            d = 'L'
            l_count += 1
        else:
            ans *= l_count - r_count
            ans %= inf
            d = 'R'
            r_count += 1

if l_count != r_count:
    print(0)
    exit()

for j in range(1, N + 1):
    ans *= j
    ans %= inf

print(ans % inf)

# Buggy version:
import sys
M = 10**9 + 7
n = int(input()) * 2
s = list(map(lambda x: int(x == "W"), input()))

lr = [0] * n # L: 0, R: 1

if s[0] or s[-1]:
    print(0)
    sys.exit()

l = 1
ans = 1
for i, v in enumerate(s[1:], 1):
    if v:
        if l % 2:
            l += 1
        else:
            ans *= l
            l -= 1
            lr[i] = 1
    else:
        if l % 2 == 0:
            l += 1
        else:
            ans *= l
            l -= 1
            lr[i] = 1
    if ans > M:
        ans %= M
    if l < 0:
        print(0)
        sys.exit()

if not lr[-1] or l == 0:
    print(0)
    sys.exit()

def fact(n):
    result = 1
    for i in range(2, n + 1):
        result *= i
        if result > M:
            result %= M
    return result
print((ans * fact(n // 2)) % M)


# Fixed version:
import sys
M = 10**9 + 7
n = int(input()) * 2
s = list(map(lambda x: int(x == "W"), input()))

lr = [0] * n # L: 0, R: 1

if s[0] or s[-1]:
    print(0)
    sys.exit()

l = 1
ans = 1
for i, v in enumerate(s[1:], 1):
    if v:
        if l % 2:
            l += 1
        else:
            ans *= l
            l -= 1
            lr[i] = 1
    else:
        if l % 2 == 0:
            l += 1
        else:
            ans *= l
            l -= 1
            lr[i] = 1
    if ans > M:
        ans %= M
    if l < 0:
        print(0)
        sys.exit()

if not lr[-1] or l:
    print(0)
    sys.exit()

def fact(n):
    result = 1
    for i in range(2, n + 1):
        result *= i
        if result > M:
            result %= M
    return result
print((ans * fact(n // 2)) % M)

# Buggy version:
n = int(input())
S = [v for v in input()]

# determine L or R
lst = [0 for i in range(2 * n)]
for i in range(2 * n):
    if S[i] == 'W' and (2 * n - i - 1) % 2 == 0:
        lst[i] = 'L'
    elif S[i] == 'W' and (2 * n - i - 1) % 2 == 1:
        lst[i] = 'R'
    elif S[i] == 'B' and (2 * n - i - 1) % 2 == 0:
        lst[i] = 'R'
    elif S[i] == 'B' and (2 * n - i - 1) % 2 == 1:
        lst[i] = 'L'

print(lst)

deq = 0
val = 1
#tracing lst
for i in range(2 * n):
    if lst[i] == 'L':
        deq += 1
    elif lst[i] == 'R':
        val *= deq
        val %= 10 ** 9 + 7
        deq -= 1

if deq != 0:
    print(0)
else:
    for i in range(1, n + 1):
        val = val * i % (10 ** 9 +7)
    print(val)


# Fixed version:
n = int(input())
S = [v for v in input()]

# determine L or R
lst = [0 for i in range(2 * n)]
for i in range(2 * n):
    if S[i] == 'W' and (2 * n - i - 1) % 2 == 0:
        lst[i] = 'L'
    elif S[i] == 'W' and (2 * n - i - 1) % 2 == 1:
        lst[i] = 'R'
    elif S[i] == 'B' and (2 * n - i - 1) % 2 == 0:
        lst[i] = 'R'
    elif S[i] == 'B' and (2 * n - i - 1) % 2 == 1:
        lst[i] = 'L'


deq = 0
val = 1
#tracing lst
for i in range(2 * n):
    if lst[i] == 'L':
        deq += 1
    elif lst[i] == 'R':
        val *= deq
        val %= 10 ** 9 + 7
        deq -= 1

if deq != 0:
    print(0)
else:
    for i in range(1, n + 1):
        val = val * i % (10 ** 9 +7)
    print(val)

# Buggy version:
n = int(input())
s_list = list(input())
mod = 10 ** 9 + 7

if s_list[0] == "W" or s_list[-1] == "W":
    print(0)
    return

from math import factorial

l_counter = 0
res = 1

for i in range(2 * n):
    s = s_list[i]
    if i % 2 == 0:
        s = "W" if s == "B" else "B"

    if s == "W":
        l_counter += 1
    else:
        res *= l_counter
        l_counter -= 1
        if l_counter < 0:
            print(0)
            return

if l_counter != 0:
    print(0)
else:
    print(res * factorial(n) % mod)

# Fixed version:
def resolve():
    n = int(input())
    s_list = list(input())
    mod = 10 ** 9 + 7

    if s_list[0] == "W" or s_list[-1] == "W":
        print(0)
        return

    from math import factorial

    l_counter = 0
    res = 1

    for i in range(2 * n):
        s = s_list[i]
        if i % 2 == 0:
            s = "W" if s == "B" else "B"

        if s == "W":
            l_counter += 1
        else:
            res = res * l_counter % mod
            l_counter -= 1
            if l_counter < 0:
                print(0)
                return

    if l_counter != 0:
        print(0)
    else:
        print(res * factorial(n) % mod)
        
resolve()

# Buggy version:


n=int(input())
s=list(input())
#前処理
for i in range(0,2*n,2):
    if s[i]=='W':
        s[i]='B'
    else:
        s[i]='W'

#Lの数を数えてRとマッチング
countL=0
ans=1
for i in range(2*n):
    if s[i]=='W':
        countL+=1
    else:
        ans*=countL
        if countL==0:
            print(0)
            exit()
        countL-=1
# 答えはansの階乗
ans=ans%(10**9+7)
for i in rangea(1,n+1):
    ans*=i
    ans%(10**9+7)
print(ans)




# Fixed version:
mod=10**9+7
n=int(input())
s=list(input())
#前処理
for i in range(0,2*n,2):
    if s[i]=='W':
        s[i]='B'
    else:
        s[i]='W'

#Lの数を数えてRとマッチング
countL=0
ans=1
for i in range(2*n):
    if s[i]=='W':
        countL+=1
    else:
        ans*=countL
        if countL==0:
            print(0)
            exit()
        ans%=mod
        countL-=1
if countL!=0:
    print(0)
    exit()
# 答えはansの階乗
for i in range(1,n+1):
    ans*=i
    ans%=mod
print(ans)

# Buggy version:
n = int(input())
s = input()
mod = 10**9+7
dp = []
imos = [0 for _ in range(n*2+1)]
now = 0
for i in range(n*2):
    c = 1 if s[i]=='B' else 0
    if c==now%2:
        imos[i+1]-=1
        dp.append(-1)
    else:
        imos[i]+=1
        dp.append(1)
    now+=imos[i]
if now + imos[i+1]!=0:
    print(0)
    exit()
ans = 1
cnt = 0
for i in dp:
    if i==1:
        cnt+=1
    else:
        ans*=cnt
        ans%=mod
        cnt-=1
for i in range(1,n+1):
    ans*=i
    ans%=mod
print(ans)

# Fixed version:
n = int(input())
s = input()
mod = 10**9+7
dp = []
imos = [0 for _ in range(n*2+1)]
now = 0
for i in range(n*2):
    c = 1 if s[i]=='B' else 0
    if c==now%2:
        imos[i]-=1
        dp.append(-1)
    else:
        imos[i]+=1
        dp.append(1)
    now+=imos[i]
if sum(dp)!=0:
    print(0)
    exit()
ans = 1
cnt = 0
for i in dp:
    if i==1:
        cnt+=1
    else:
        ans*=cnt
        ans%=mod
        cnt-=1
for i in range(1,n+1):
    ans*=i
    ans%=mod
print(ans)

# Buggy version:
import math
n = int(input())
s = [0 if i == "W" else 1 for i in list(input())]
cnt = 0
c = 1
for i in range(n * 2):
    if (s[i] + cnt) % 2 == 0:
        cnt += 1
    else:
        c *= (cnt if cnt != 0 else 1)
        cnt -= 1
    if cnt < 0:
        print(0)
        exit()
if cnt != 0:
    print(0)
else:
    print(c * math.factorial(n))


# Fixed version:
import math
n = int(input())
s = [0 if i == "W" else 1 for i in list(input())]
cnt = 0
c = 1
for i in range(n * 2):
    if (s[i] + cnt) % 2 != 0:
        cnt += 1
    else:
        c = (c * (cnt if cnt != 0 else 1)) % (10 ** 9 + 7)
        cnt -= 1
    if cnt < 0:
        print(0)
        exit()
if cnt != 0:
    print(0)
else:
    print((c * math.factorial(n)) % (10 ** 9 + 7))

# Buggy version:
N = int(input())
S = input()
count = 0
ans = 1
m = 10**9 + 7
 
for i in range(N):
  if s[2*i] == "W":
    ans *= (i - (count*2))
    count += 1
  if s[2*i + 1] == "B":
    ans *= (i - (count*2))
    count += 1
if count != N:
  print(0)
else:
  for o in range(1, N+1):
    ans *= o
    ans %= m
  print(ans %= m)

# Fixed version:
N = int(input())
S = input()
count = 0
ans = 1
m = 10**9 + 7
 
for i in range(N):
  if S[2*i] == "W":
    ans = ans * ((2*i) - (count*2))%m
    count += 1
  if S[2*i + 1] == "B":
    ans = ans * ((2*i + 1) - (count*2))%m
    count += 1
 
if count != N:
  print(0)
else:
  for o in range(1, N+1):
    ans *= o
    ans %= m
  print(ans % m)

# Buggy version:
mod = 10**9+7

N = int(input())
S = input()
lr = ['L']*(2*N)

for i in range(1,2*N):
    if S[i]==S[i-1]:
        if lr[i-1]=='L':
            lr[i] = 'R'
        else:
            lr[i] = 'L'
    else:
        lr[i] = lr[i-1]

ans = 1
l = 0
for i in range(2*N):
    if lr[i]=='L':
        l += 1
    else:
        ans *= l
        ans %= mod
        l -= 1

for n in range(1,N+1):
    ans *= n
    ans %= mod

l = [i for i in range(2*N) if lr[i]=='L']
r = [i for i in range(2*N) if lr[i]=='R']
s = [0]*(2*N+1)
for i in range(2*N):
    if S[i]=='W':
        s[i] = 0
    else:
        s[i] = 1

if len(l)!=len(r):
    ans = 0
else:
    for i in range(N):
        s[l[i]] += 1
        s[r[i]+1] -= 1
    for i in range(2*N):
        s[i+1] += s[i]
        if s[i]%2!=0:
            ans = 0

print(ans)

# Fixed version:
mod = 10**9+7

N = int(input())
S = input()
lr = ['L']*(2*N)

for i in range(1,2*N):
    if S[i]==S[i-1]:
        if lr[i-1]=='L':
            lr[i] = 'R'
        else:
            lr[i] = 'L'
    else:
        lr[i] = lr[i-1]

ans = 1
l = 0
for i in range(2*N):
    if lr[i]=='L':
        l += 1
    else:
        ans *= l
        ans %= mod
        l -= 1

for n in range(1,N+1):
    ans *= n
    ans %= mod

l = [i for i in range(2*N) if lr[i]=='L']
r = [i for i in range(2*N) if lr[i]=='R']
s = [0]*(2*N+1)

if len(l)!=len(r):
    ans = 0
else:
    for i in range(N):
        s[l[i]] += 1
        s[r[i]+1] -= 1
    for i in range(2*N):
        s[i+1] += s[i]
        if S[i]=='B':
            s[i] += 1
        if s[i]%2!=0:
            ans = 0

print(ans)

# Buggy version:
import sys
n = int(input())
s = input()
if s[0] == "W":
  print(0)
  sys.exit()
MOD = 10**9+7
ans = 1
cnt = 1
for i in range(2*n):
  if s[i+1] != s[i]:
    cnt += 1
  else:
    ans *= cnt
    ans %= MOD
    cnt -= 1
if cnt != 0:
  print(0)
else:
  print(ans)

# Fixed version:
import sys
n = int(input())
s = input()
if s[0] == "W":
  print(0)
  sys.exit()
MOD = 10**9+7
ans = 1
cnt = 1
right = 1
for i in range(2*n-1):
  if s[i+1] == s[i]:
    right ^= 1
  if right:
    cnt += 1
  else:
    ans *= cnt
    ans %= MOD
    cnt -= 1
if cnt != 0:
  print(0)
else:
  for i in range(1, n+1):
    ans *= i
    ans %= MOD
  print(ans)

# Buggy version:
MOD = 10**9 + 7
n = int(input())
s = input().rstrip()

if s[0] == "W" or s[-1] == "W":
    print(-1)
    exit()
front = 0
ans = 1
for i, item in enumerate(s):
    if item == "B":
        if front % 2 == 0:
            front += 1
        else:
            ans *= front
            ans %= MOD
            front -= 1
    else:
        if front % 2 == 1:
            front += 1
        else:
            ans *= front
            ans %= MOD
            front -= 1
    if front < 0:
        print(-1)
        exit()
if front != 0:
    print(-1)
    exit()
for i in range(1, n+1):
    ans *= i
    ans %= MOD

print(ans)

# Fixed version:
MOD = 10**9 + 7
n = int(input())
s = input().rstrip()

if s[0] == "W" or s[-1] == "W":
    print(0)
    exit()
front = 0
ans = 1
for i, item in enumerate(s):
    if item == "B":
        if front % 2 == 0:
            front += 1
        else:
            ans *= front
            ans %= MOD
            front -= 1
    else:
        if front % 2 == 1:
            front += 1
        else:
            ans *= front
            ans %= MOD
            front -= 1
    if front < 0:
        print(0)
        exit()
if front != 0:
    print(0)
    exit()
for i in range(1, n+1):
    ans *= i
    ans %= MOD

print(ans)

# Buggy version:
def main():
    N = int(input())
    S = input()
    div = pow(10, 9) + 7
    facN = 1
    for i in range(1, N+1):
        facN = (facN * i) % div

    t = "L"
    for i in range(1, 2*N-1):
        if S[i-1] != S[i]:
            t += t[-1]
        else:
            if t[-1] == "L":
                t += "R"
            else:
                t += "L"
    t += "R"

    prefixL = [0]
    for c in t:
        if c == "L":
            prefixL.append(prefixL[-1]+1)
        else:
            prefixL.append(prefixL[-1])

    # print(S, t)
    # print(prefixL)
    ans = 1
    countR = 0
    for i in range(len(t)):
        if t[i] == "R":
            ans *= prefixL[i] - countR
            ans %= div
            countR += 1
    return (ans * facN) % div

if __name__ == '__main__':

    print(main())

# Fixed version:
def main():
    N = int(input())
    S = input()
    div = pow(10, 9) + 7
    facN = 1
    for i in range(1, N+1):
        facN = (facN * i) % div

    if S[0] != "B": return 0
    t = "L"
    ctL, ctR = 1, 0
    for i in range(1, 2*N):
        if S[i-1] != S[i]:
            t += t[-1]
        else:
            if t[-1] == "L":
                t += "R"
            else:
                t += "L"
        if t[-1] == "L": ctL += 1
        else: ctR += 1
    if S[-1] != "B":
        return 0
    if ctL != ctR: return 0

    prefixL = [0]
    for c in t:
        if c == "L":
            prefixL.append(prefixL[-1]+1)
        else:
            prefixL.append(prefixL[-1])

    # print(S, t)
    # print(prefixL)
    ans = 1
    countR = 0
    for i in range(len(t)):
        if t[i] == "R":
            ans *= prefixL[i] - countR
            ans %= div
            countR += 1
    return (ans * facN) % div

if __name__ == '__main__':

    print(main())

# Buggy version:
MOD = 10**9+7

n = int(input())
s = input()

if s[0] == "W" or s[-1] == "W":
    print(0):
    exit()

kai = [1 for _ in range(n+1)]
for i in range(1, n+1):
    kai[i] = kai[i-1] * i
    kai[i] %= MOD

def mul(a, b):
    return (a * b) % MOD

a = "L"
l = ["L", "R"]
c = 0

for i in range(1, len(s)):
    if s[i] == s[i-1]:
        c = not c
    a = a + l[c]


ans = 1
num = 0
for i in range(len(s)):
    if a[i] == "L":
        num += 1
    else:
        ans *= num
        ans %= MOD
        num -= 1

ans *= kai[n]
ans %= MOD

print(ans)


# Fixed version:
MOD = 10**9+7

n = int(input())
s = input()

if s[0] == "W" or s[-1] == "W":
    print(0)
    exit()

kai = [1 for _ in range(n+1)]
for i in range(1, n+1):
    kai[i] = kai[i-1] * i
    kai[i] %= MOD

def mul(a, b):
    return (a * b) % MOD

a = "L"
l = ["L", "R"]
c = 0

for i in range(1, len(s)):
    if s[i] == s[i-1]:
        c = not c
    a = a + l[c]


ans = 1
num = 0
for i in range(len(s)):
    if a[i] == "L":
        num += 1
    else:
        ans *= num
        ans %= MOD
        num -= 1

if num > 0:
    print(0)
    exit()

ans *= kai[n]
ans %= MOD

print(ans)

# Buggy version:
import math

n = int(input())
s = input()

if s[0] == 'W' or s[-1] == 'W':
    print(0)
else:    
    s_lr = 'L'
    for i in range(len(s)-1):
        if s[i+1] == s[i]:
            if s_lr[-1] == 'L':
                s_lr += 'R'
            else:
                s_lr += 'L'
        else:
            if s_lr[-1] == 'L':
                s_lr += 'L'
            else:
                s_lr += 'R'    
    l_cnt = 0
    r_cnt = 0
    lst = []
    for i in s_lr:
        if i == 'L':
            l_cnt += 1
            lst.append(0)
        else:
            if l_cnt - r_cnt <= 0:
                print(0)
                break
            else:
                lst.append(l_cnt - r_cnt)
            r_cnt += 1
    else:
        if l_cnt != r_cnt:
            print(0)
        else:
            res = 1
            for i in lst:
                if i > 0:
                    res = res % (10**9 + 7)
            print(res * math.factorial(n) % (10**9 + 7) )

# Fixed version:
import math

n = int(input())
s = input()

if s[0] == 'W' or s[-1] == 'W':
    print(0)
else:    
    s_lr = 'L'
    for i in range(len(s)-1):
        if s[i+1] == s[i]:
            if s_lr[-1] == 'L':
                s_lr += 'R'
            else:
                s_lr += 'L'
        else:
            if s_lr[-1] == 'L':
                s_lr += 'L'
            else:
                s_lr += 'R'    
    l_cnt = 0
    r_cnt = 0
    lst = []
    for i in s_lr:
        if i == 'L':
            l_cnt += 1
            lst.append(0)
        else:
            if l_cnt - r_cnt <= 0:
                print(0)
                break
            else:
                lst.append(l_cnt - r_cnt)
            r_cnt += 1
    else:
        if l_cnt != r_cnt:
            print(0)
        else:
            res = 1
            for i in lst:
                if i > 0:
                    res = res * i % (10**9 + 7)
            print(res * math.factorial(n) % (10**9 + 7) )

# Buggy version:
MOD = int(1e9+7)
N = int(input())
S = input()
LR = [0]*(2*N)
LR[0] = 0
l, r = 0, 0
if S[0] == "W" or S[-1] == "W":
    print(0)
    exit()
for i in range(1, 2*N):
    if S[i-1] == S[i]:
        LR[i] = 0 if LR[i-1] == 1 else 1
    else:
        LR[i] = LR[i-1]
    if LR[i] == 0:
        l += 1
    else:
        r += 1
if l != r:
    print(0)
    exit()
L = 0
R = 0
count = 1
for w in LR:
    if w == 0:
        L += 1
    else:
        count *= L - R
        R += 1
for i in range(1, N+1):
    count = count * i % MOD
print(count)

# Fixed version:
MOD = int(1e9+7)
N = int(input())
S = input()
LR = [0]*(2*N)
LR[0] = 0
l, r = 1, 0
if S[0] == "W" or S[-1] == "W":
    print(0)
    exit()
for i in range(1, 2*N):
    if S[i-1] == S[i]:
        LR[i] = 0 if LR[i-1] == 1 else 1
    else:
        LR[i] = LR[i-1]
    if LR[i] == 0:
        l += 1
    else:
        r += 1
if l != r:
    print(0)
    exit()
L = 0
R = 0
count = 1
for w in LR:
    if w == 0:
        L += 1
    else:
        count *= L - R
        count %= MOD
        R += 1
for i in range(1, N+1):
    count = count * i % MOD
print(count)

# Buggy version:
import math
N = int(input())
S = input()
ans = 0
ans_base = 1
numofS = 0  # 線の左端になっている点をSとするとその数はちょうどNでないといけない
line = 0  # 左から順に線を引く。上に何本通っているかをあらわす
for i in range(2*N):
    if S[i] == "B":
        if line % 2 == 0:
            numofS += 1
            line += 1
        else:
            ans_base *= line
            line -= 1
    else:
        if line % 2 == 0:
            ans_base *= line
            line -= 1
        else:
            line += 1
            numofS += 1

    if line < 0:
        ans = -1
if numofS != N:
    ans = -1
    #print(numofS)

if ans != -1:
    fact = math.factorial(N)
    ans = ans_base * fact
    ans %= 10**9+7
print(ans)


# Fixed version:
import math
N = int(input())
S = input()
ans = 1
ans_base = 1
numofS = 0  # 線の左端になっている点をSとするとその数はちょうどNでないといけない
line = 0  # 左から順に線を引く。上に何本通っているかをあらわす
for i in range(2*N):
    if S[i] == "B":
        if line % 2 == 0:
            numofS += 1
            line += 1
        else:
            ans_base *= line
            line -= 1
    else:
        if line % 2 == 0:
            ans_base *= line
            line -= 1
        else:
            line += 1
            numofS += 1

    if line < 0:
        ans = 0
        break
    ans_base %= 10**9+7
if numofS != N:
    ans = 0
    # print(numofS)

if ans != 0:
    fact = math.factorial(N)
    fact %= 10**9+7
    ans = ans_base * fact
    ans %= 10**9+7
print(ans)

# Buggy version:
N = int(input())
S = input()
L = list(S)
for i in range(0, 2*N, 2):
  L[i] = "B" if L[i] == "W" else "W"
S = "".join(L)
#print(S)
r = 1
i = 0
nw = 0
nb = 0
while i < 2*N:
  j = S.find("B", i)
  if j < 0:
    j = 2*N
  k = S.find("W", j)
  if k < 0:
    k = 2*N
  #print(i, j, k)
  nw += j-i
  nb += k-j
  for i in range(min(nb, nw)):
    r = r*max(nw, nb)%1000000007
    nw -= 1
    nb -= 1
  i = k
if not(nw == 0 and nb == 0):
  print(0)
  exit()
for i in range(1, N+1):
  r = r*i%1000000007
print(r)


# Fixed version:
N = int(input())
S = input()
L = list(S)
for i in range(0, 2*N, 2):
  L[i] = "B" if L[i] == "W" else "W"
S = "".join(L)
#print(S)
r = 1
i = 0
nw = 0
nb = 0
while i < 2*N:
  j = S.find("B", i)
  if j < 0:
    j = 2*N
  k = S.find("W", j)
  if k < 0:
    k = 2*N
  #print(i, j, k)
  nw += j-i
  nb += k-j
  for i in range(nb):
    r = r*nw%1000000007
    nw -= 1
    nb -= 1
  i = k
if not(nw == 0 and nb == 0):
  print(0)
  exit()
for i in range(1, N+1):
  r = r*i%1000000007
print(r)

# Buggy version:
N=int(input())
S=input()
l=0
a=1
for i in range(2*N):
    if S[i]=="W":
        if l%2==0:
            a=a*l%(10**9+7)
            l-=1
        else:
            l+=1
    else:
        if l%2==0:
            l+=1
        else:
            a=a*l%(10**9+7)
            l-=1
if l!=1:
    a=0
for i in range(1,N+1):
    a=a*i%(10**9+7)
print(a)

# Fixed version:
N=int(input())
S=input()
l=0
a=1
for i in range(2*N):
    if S[i]=="W":
        if l%2==0:
            a=a*l%(10**9+7)
            l-=1
        else:
            l+=1
    else:
        if l%2==0:
            l+=1
        else:
            a=a*l%(10**9+7)
            l-=1
if l!=0:
    a=0
for i in range(1,N+1):
    a=a*i%(10**9+7)
print(a)

# Buggy version:
from math import factorial
iMOD = 10**9 + 7

n = int(input())
s = input()
a = [0] * (n * 2)
for i in range(n*2):
    if s[i] == "B":
        a[i] = 1
        
prevbit = 0
prevlr = 0
lr = [0] * (n*2)
for i in range(n*2):
    if a[i] != prevbit:
        lr[i] = prevlr
    else:
        lr[i] = (prevlr + 1) % 2
    prevlr = lr[i]
    prevbit = a[i]
    
#print(lr)
    
ans = 1
if sum(lr) != n:
    ans = 0
else:
    suml = 0
    for i in range(n*2):
        if lr[i] == 1:
            ans = (ans * suml) % MOD
            suml -= 1
            if suml < 0:
                ans = 0
                break
        else:
            suml += 1
            
print((ans*factorial(n))%MOD)

# Fixed version:
from math import factorial
MOD = 10**9 + 7

n = int(input())
s = input()
a = [0] * (n * 2)
for i in range(n*2):
    if s[i] == "B":
        a[i] = 1
        
prevbit = 0
prevlr = 0
lr = [0] * (n*2)
for i in range(n*2):
    if a[i] != prevbit:
        lr[i] = prevlr
    else:
        lr[i] = (prevlr + 1) % 2
    prevlr = lr[i]
    prevbit = a[i]
    
#print(lr)
    
ans = 1
if sum(lr) != n:
    ans = 0
else:
    suml = 0
    for i in range(n*2):
        if lr[i] == 1:
            ans = (ans * suml) % MOD
            suml -= 1
            if suml < 0:
                ans = 0
                break
        else:
            suml += 1
            
print((ans*factorial(n))%MOD)