Buggy python submission (verdict: Time Limit Exceeded):
import sys
from sys import stdin

def main():
 
    n = int(stdin.readline().rstrip())
    s = stdin.readline().rstrip()
    MOD=10**9+7
    perm=1
    for i in range(1,n+1):
        perm=perm*i%MOD
    ans=1

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

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from sys import stdin

def main():
 
    n = int(stdin.readline().rstrip())
    s = stdin.readline().rstrip()
    MOD=10**9+7
    perm=1
    for i in range(1,n+1):
        perm=perm*i%MOD
    ans=1

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

    print(ans*perm%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
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
            count-=1
    print(ans*perm%MOD)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from sys import stdin

def main():
 
    n = int(stdin.readline().rstrip())
    s = stdin.readline().rstrip()
    MOD=10**9+7
    perm=1
    for i in range(1,n+1):
        perm=perm*i%MOD
    ans=1

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

    print(ans*perm%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
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
            count-=1
    print(ans*perm%MOD)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from sys import stdin

def main():
 
    n = int(stdin.readline().rstrip())
    s = stdin.readline().rstrip()
    MOD=10**9+7
    perm=1
    for i in range(1,n+1):
        perm=perm*i%MOD
    ans=1

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

    print(ans*perm%MOD)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
MOD=10**9+7
perm=[1]*(n+1)
for i in range(1,n+1):
    perm[i]=perm[i-1]*i%MOD
ans=1
dp=[0]*(2*n+1)
for i in range(1,2*n+1):
    if (dp[i-1]+1)%2==(s[i]=='B'):
        dp[i]=dp[i-1]+1
    else:
        ans*=dp[i-1]%MOD
        dp[i]=dp[i-1]-1
#print(dp)
print(ans*perm[n]%MOD)

Fixed submission:
import sys
from sys import stdin

def main():
 
    n = int(stdin.readline().rstrip())
    s = stdin.readline().rstrip()
    MOD=10**9+7
    perm=1
    for i in range(1,n+1):
        perm=perm*i%MOD
    ans=1

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

    print(ans*perm%MOD)

if __name__ == '__main__':
    main()