Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern *= LRsub
    LRsub += Dc

if LRsub == 0:
    MOD = 10 ** 9 + 7
    for i in range(2,N+1):
        Pattern *= i
        Pattern = Pattern % MOD
    print(Pattern)
else:
    print(0)


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i, Sc in enumerate(S):
    if i == 0:
        continue
    if Sc != 'B' and Sc != 'W':
        continue
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern *= LRsub
    LRsub += Dc

if LRsub == 0:
    MOD = 10 ** 9 + 7
    for i in range(2,N+1):
        Pattern *= i
        Pattern = Pattern % MOD
    print(Pattern)
else:
    print(0)


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys


MOD = 10 ** 9 + 7

input = sys.stdin.readline
N = int(input())
S = input()
if S[0] == 'W' or S[-1] == 'W':
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
for i in range(1,2*N):
    Dc = Dc if S[i] != S[i-1] else -Dc
    if Dc < 0:
        Pattern *= LRsub
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern *= i
        Pattern = Pattern % MOD
    print(Pattern)
else:
    print(0)


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import math
import sys


MOD = 10 ** 9 + 7

def main():
    input = sys.stdin.readline
    N = int(input())
    S = input()
    if S[0] == 'W' or S[-1] == 'W':
        print(0)
        return

    Dc = 1
    LRsub = 1
    Pattern = 1
    for i in range(1,2*N):
        Dc = Dc if S[i] != S[i-1] else -Dc
        if Dc < 0:
           Pattern *= LRsub
        LRsub += Dc

    if LRsub == 0:
        for i in range(2,N+1):
            Pattern *= i
            Pattern = Pattern % MOD
        print(Pattern)
    else:
        print(0)

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import math
import sys


MOD = 10 ** 9 + 7

def main():
    input = sys.stdin.readline
    N = int(input())
    S = input()
    if S[0] == 'W' or S[-1] == 'W':
        print(0)
        return

    Dc = 1
    LRsub = 1
    Pattern = 1
    for i in range(1,2*N):
        Dc = Dc if S[i] != S[i-1] else -Dc
        if Dc < 0:
           Pattern *= LRsub
        LRsub += Dc

    if LRsub == 0:
        Pattern *= math.factorial(N)
        Pattern = Pattern % MOD
        print(Pattern)
    else:
        print(0)

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import math

MOD = 10 ** 9 + 7

def main():
    N = int(input())
    S = input()

    if S[0] == 'W' or S[-1] == 'W':
        print(0)
        return

    Dc = 1
    LRsub = 1
    Pattern = 1
    for i in range(1,2*N):
        Dc = Dc if S[i] != S[i-1] else -Dc
        if Dc < 0:
           Pattern *= LRsub
        LRsub += Dc

    if LRsub == 0:
        Pattern *= math.factorial(N)
        Pattern = Pattern % MOD
        print(Pattern)
    else:
        print(0)

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import math

MOD = 10 ** 9 + 7

def main():
    N = int(input())
    S = input().strip()

    if S[0] == 'W' or S[-1] == 'W':
        print(0)
        return

    Dc = 1
    LRsub = 1
    Pattern = 1
    for i in range(1,2*N):
        Dc = Dc if S[i] != S[i-1] else -Dc
        Pattern *= LRsub if Dc < 0 else 1
        LRsub += Dc

    if LRsub == 0:
        Pattern *= math.factorial(N)
        Pattern = Pattern % MOD
        print(Pattern)
    else:
        print(0)

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import math

MOD = 10 ** 9 + 7

def main():
    N = int(input())
    S = input().strip()

    if S[0] == 'W' or S[-1] == 'W':
        print(0)
        return

    Dc = True
    LRsub = 1
    Pattern = 1
    for i in range(1,2*N):
        Dc = Dc if S[i] != S[i-1] else not Dc
        Pattern *= LRsub if not Dc else 1
        LRsub += 1 if Dc else -1

    if LRsub == 0:
        Pattern *= math.factorial(N)
        Pattern = Pattern % MOD
        print(Pattern)
    else:
        print(0)

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import math

MOD = 10 ** 9 + 7

def main():
    N = int(input())
    S = input().strip()

    if S[0] == 'W' or S[-1] == 'W':
        print(0)
        return

    Sp = ''
    Dc = True
    LRsub = 0
    Pattern = 1
    for Sc in S:
        Dc = not Dc if Sc == Sp else Dc
        Sp = Sc
        Pattern *= LRsub if not Dc else 1
        LRsub += 1 if Dc else -1

    if LRsub == 0:
        Pattern *= math.factorial(N)
        Pattern = Pattern % MOD
        print(Pattern)
    else:
        print(0)

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import math

MOD = 10 ** 9 + 7

def main():
    N = int(input())
    S = input().strip()

    if S[0] == 'W' or S[-1] == 'W':
        print(0)
        return

    Sp = ''
    Dc = True
    Lcnt = 0
    Rcnt = 0
    Pattern = 1
    for Sc in S:
        Dc = not Dc if Sc == Sp else Dc
        Sp = Sc
        Pattern *= Lcnt - Rcnt if not Dc else 1
        Lcnt += 1 if Dc else 0
        Rcnt += 1 if not Dc else 0

    if Lcnt == Rcnt:
        Pattern *= math.factorial(N)
        Pattern = Pattern % MOD
        print(Pattern)
    else:
        print(0)

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import math

MOD = 10 ** 9 + 7

def main():
    N = int(input())
    S = input().strip()

    if S[0] == 'W' or S[-1] == 'W':
        print(0)
        return

    Sp = ''
    Dc = True
    Lcnt = 0
    Rcnt = 0
    Pattern = 1
    for Sc in S:
        if Sc == Sp:
            Dc = not Dc
        Sp = Sc

        if not Dc:
            Pattern *= Lcnt - Rcnt

        Lcnt += 1 if Dc else 0
        Rcnt += 1 if not Dc else 0

    if Lcnt == Rcnt:
        Pattern *= math.factorial(N)
        Pattern = Pattern % MOD
        print(Pattern)
    else:
        print(0)

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)