Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
MOD = 10**9 + 7
N = int(input())
S = list(input())
if S[0] == "W" or S[2*N-1] == "W":
    print(0)
    exit()

L,R = [0], []
total = [0 for i in range(2*N)]
total[0] = 1
l,r = 1,0
prev = "L"
for i in range(1, 2*N):
    if S[i] == S[i-1]:
        if prev == "L":
            R.append(i)
            total[i] = total[i-1] - 1
            r += 1
            prev = "R"
        else:
            L.append(i)
            total[i] = total[i-1] + 1
            l += 1
            prev = "L"
    else:
        if prev == "L":
            L.append(i)
            total[i] = total[i-1] + 1
            l += 1
        else:
            R.append(i)
            total[i] = total[i-1] - 1
            r += 1
    if l < r:
        print(0)
        exit()

if not (len(L) == N and len(R) == N):
    print(0)
    exit()

def fact(n):
    ret = 1
    while n > 1:
        ret *= n
        n -= 1
    return ret
    
cnt = 1
for r in R:
    cnt = (cnt * (total[r] + 1)) % MOD
print(cnt * fact(N) % MOD)

Fixed submission:
# coding: utf-8
# Your code here!
MOD = 10**9 + 7
N = int(input())
S = list(input())
if S[0] == "W" or S[2*N-1] == "W":
    print(0)
    exit()

L,R = [0], []
total = [0 for i in range(2*N)]
total[0] = 1
l,r = 1,0
prev = "L"
for i in range(1, 2*N):
    if S[i] == S[i-1]:
        if prev == "L":
            R.append(i)
            total[i] = total[i-1] - 1
            r += 1
            prev = "R"
        else:
            L.append(i)
            total[i] = total[i-1] + 1
            l += 1
            prev = "L"
    else:
        if prev == "L":
            L.append(i)
            total[i] = total[i-1] + 1
            l += 1
        else:
            R.append(i)
            total[i] = total[i-1] - 1
            r += 1
    if l < r:
        print(0)
        exit()

if not (len(L) == N and len(R) == N):
    print(0)
    exit()

def fact(n):
    ret = 1
    while n > 1:
        ret = (ret * n) % MOD
        n -= 1
    return ret
    
cnt = 1
for r in R:
    cnt = (cnt * (total[r] + 1)) % MOD
print(cnt * fact(N) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
MOD = 10**9 + 7
N = int(input())
S = list(input())
if S[0] == "W" or S[2*N-1] == "W":
    print(0)
    exit()

L,R = [0], []
l,r = 1,0
prev = "L"
for i in range(1, 2*N):
    if S[i] == S[i-1]:
        if prev == "L":
            R.append(i)
            r += 1
            prev = "R"
        else:
            L.append(i)
            l += 1
            prev = "L"
    else:
        if prev == "L":
            L.append(i)
            l += 1
        else:
            R.append(i)
            r += 1
    if l < r:
        print(0)
        exit()

if not (len(L) == N and len(R) == N):
    print(0)
    exit()

def fact(n):
    ret = 1
    while n > 1:
        ret *= n
        n -= 1
    return ret
    
R.reverse()
R_border = 0
cnt = 1
l = N-1
while l >= 0:
    while R_border < N-1 and L[l] < R[R_border+1]:
        R_border += 1
    cnt = cnt * (R_border + 1 - (N-1 - l)) % MOD
    l -= 1
print(cnt * fact(N) % MOD)


Fixed submission:
# coding: utf-8
# Your code here!
MOD = 10**9 + 7
N = int(input())
S = list(input())
if S[0] == "W" or S[2*N-1] == "W":
    print(0)
    exit()

L,R = [0], []
total = [0 for i in range(2*N)]
total[0] = 1
l,r = 1,0
prev = "L"
for i in range(1, 2*N):
    if S[i] == S[i-1]:
        if prev == "L":
            R.append(i)
            total[i] = total[i-1] - 1
            r += 1
            prev = "R"
        else:
            L.append(i)
            total[i] = total[i-1] + 1
            l += 1
            prev = "L"
    else:
        if prev == "L":
            L.append(i)
            total[i] = total[i-1] + 1
            l += 1
        else:
            R.append(i)
            total[i] = total[i-1] - 1
            r += 1
    if l < r:
        print(0)
        exit()

if not (len(L) == N and len(R) == N):
    print(0)
    exit()

def fact(n):
    ret = 1
    while n > 1:
        ret = (ret * n) % MOD
        n -= 1
    return ret
    
cnt = 1
for r in R:
    cnt = (cnt * (total[r] + 1)) % MOD
print(cnt * fact(N) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
MOD = 10**9 + 7
N = int(input())
S = list(input())
if S[0] == "W" or S[2*N-1] == "W":
    print(0)
    exit()

L,R = [0], []
l,r = 1,0
prev = "L"
for i in range(1, 2*N):
    if S[i] == S[i-1]:
        if prev == "L":
            R.append(i)
            r += 1
            prev = "R"
        else:
            L.append(i)
            l += 1
            prev = "L"
    else:
        if prev == "L":
            L.append(i)
            l += 1
        else:
            R.append(i)
            r += 1
    if l < r:
        print(0)
        exit()

if not (len(L) == N and len(R) == N):
    print(0)
    exit()

def fact(n):
    ret = 1
    while n > 1:
        ret *= n
        n -= 1
    return ret
    
R.reverse()
R_border = 0
cnt = 1
l = N-1
while l >= 0:
    while R_border < N-1 and L[l] < R[R_border+1]:
        R_border += 1
    cnt = cnt * (R_border + 1 - (N-1 - l)) % MOD
    l -= 1
print(cnt * fact(N) % MOD)

Fixed submission:
# coding: utf-8
# Your code here!
MOD = 10**9 + 7
N = int(input())
S = list(input())
if S[0] == "W" or S[2*N-1] == "W":
    print(0)
    exit()

L,R = [0], []
total = [0 for i in range(2*N)]
total[0] = 1
l,r = 1,0
prev = "L"
for i in range(1, 2*N):
    if S[i] == S[i-1]:
        if prev == "L":
            R.append(i)
            total[i] = total[i-1] - 1
            r += 1
            prev = "R"
        else:
            L.append(i)
            total[i] = total[i-1] + 1
            l += 1
            prev = "L"
    else:
        if prev == "L":
            L.append(i)
            total[i] = total[i-1] + 1
            l += 1
        else:
            R.append(i)
            total[i] = total[i-1] - 1
            r += 1
    if l < r:
        print(0)
        exit()

if not (len(L) == N and len(R) == N):
    print(0)
    exit()

def fact(n):
    ret = 1
    while n > 1:
        ret = (ret * n) % MOD
        n -= 1
    return ret
    
cnt = 1
for r in R:
    cnt = (cnt * (total[r] + 1)) % MOD
print(cnt * fact(N) % MOD)