Buggy python submission (verdict: Time Limit Exceeded):
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
        c %= (10**9+7)
    if stack!=0 or 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 submission:
# 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]
    for s in S:
        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 python submission (verdict: Time Limit Exceeded):
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 or c==0:
        print(0)
    else:
        c %= (10**9+7)
        for i in range(1, n+1):
            c*=i
        print(c%(10**9+7))

if __name__ == "__main__":
    f_c()


Fixed submission:
# 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]
    for s in S:
        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 python submission (verdict: Time Limit Exceeded):
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 or 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 submission:
# 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]
    for s in S:
        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 python submission (verdict: Time Limit Exceeded):
def f_c():
    n = int(input())
    s = input()

    stack, c = 1, 1
    if s[0]=="W":
        print(0)
        return 0
    for i in range(1, n*2):
        if s[i]=="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:
            break
    if stack!=0:
        print(0)
    else:
        for i in range(1, n+1):
            c*=i
        print(c%(10**9+7))

if __name__ == "__main__":
    f_c()


Fixed submission:
# 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]
    for s in S:
        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 python submission (verdict: Time Limit Exceeded):
def f_c():
    import math
    n = int(input())
    s = input()

    stack, c = 1, 1
    for i in range(1, n*2):
        if s[i]=="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:
            break
    o = 0 if stack!=0 else c*math.factorial(n)
    print(o%(10**9+7))

if __name__ == "__main__":
    f_c()


Fixed submission:
# 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]
    for s in S:
        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 python submission (verdict: Runtime Error):
def f_c():
    import math
    n = int(input())
    s = input()

    stack, c = [1], 1
    for i in range(1, n*2):
        if s[i]=="B":
            if len(stack)%2==0:
                stack.append(1)
            else:
                c *= len(stack)
                stack.pop()
        else:
            if len(stack)%2==0:
                c *= len(stack)
                stack.pop()
            else:
                stack.append(1)
    o = 0 if len(stack)!=0 else c*math.factorial(n)
    print(o)

if __name__ == "__main__":
    f_c()


Fixed submission:
# 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]
    for s in S:
        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()