Buggy python submission (verdict: Time Limit Exceeded):
#B問題
import bisect

N = int(input())
S = list(str(input()))
mod = 998244353
N_factorial = 1
for i in range(N):
    N_factorial*=(i+1)
    N_factorial%=mod

r,g,b = [],[],[]
for i in range(3*N):
    if S[i] == "R":
        r.append(i)
    if S[i] == "G":
        g.append(i)
    if S[i] == "B":
        b.append(i)
        
m,M = [],[]
for i in range(N):
    m.append(min(r[i],g[i],b[i]))
    M.append(max(r[i],g[i],b[i]))
    
A,B,C = [],[],[]
    
for i in range(N):
    A.append(m[i])
    C.append(M[i])
    
for i in range(3*N):
    if i not in A and i not in C:
        B.append(i)
        
count = 1
for i,B_ind in enumerate(B):
    x = bisect.bisect_left(A,B_ind)-i
    y = i+1-bisect.bisect_right(C,B_ind)
    count*=(x*y)%mod
        
ans = (count*N_factorial)%mod
print(ans)

Fixed submission:
#B問題
import bisect

N = int(input())
S = list(str(input()))
mod = 998244353
N_factorial = 1
for i in range(N):
    N_factorial*=(i+1)
    N_factorial%=mod

r,g,b = [],[],[]
for i,s in enumerate(S):
    if s == "R":
        r.append(i)
    if s == "G":
        g.append(i)
    if s == "B":
        b.append(i)
        
A,B,C = [],[],[]
for i in range(N):
    rgb = [r[i],g[i],b[i]]
    rgb.sort()
    A.append(rgb[0])
    B.append(rgb[1])
    C.append(rgb[2])

ans = N_factorial
for i,B_ind in enumerate(B):
    x = bisect.bisect_left(A,B_ind)-i
    y = i+1-bisect.bisect_left(C,B_ind)
    ans*=(x*y)
    ans%=mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#B問題
import bisect

N = int(input())
S = list(str(input()))
mod = 998244353
N_factorial = 1
for i in range(N):
    N_factorial*=(i+1)
    N_factorial%=mod

r,g,b = [],[],[]
for i in range(3*N):
    if S[i] == "R":
        r.append(i)
    if S[i] == "G":
        g.append(i)
    if S[i] == "B":
        b.append(i)
        
m,M = [],[]
for i in range(N):
    m.append(min(r[i],g[i],b[i]))
    M.append(max(r[i],g[i],b[i]))
    
A,B,C = [],[],[]    
    
for i in range(N):
    A.append(m[i])
    C.append(M[i])
    
for i in range(3*N):
    if i not in A and i not in C:
        B.append(i)
        
count = 1
for i,B_ind in enumerate(B):
    x = bisect.bisect_left(A,B_ind)-i
    y = i+1-bisect.bisect_right(C,B_ind)
    count*=(x*y)%mod
        
ans = (count*N_factorial)%mod
print(ans)

Fixed submission:
#B問題
import bisect

N = int(input())
S = list(str(input()))
mod = 998244353
N_factorial = 1
for i in range(N):
    N_factorial*=(i+1)
    N_factorial%=mod

r,g,b = [],[],[]
for i,s in enumerate(S):
    if s == "R":
        r.append(i)
    if s == "G":
        g.append(i)
    if s == "B":
        b.append(i)
        
A,B,C = [],[],[]
for i in range(N):
    rgb = [r[i],g[i],b[i]]
    rgb.sort()
    A.append(rgb[0])
    B.append(rgb[1])
    C.append(rgb[2])

ans = N_factorial
for i,B_ind in enumerate(B):
    x = bisect.bisect_left(A,B_ind)-i
    y = i+1-bisect.bisect_left(C,B_ind)
    ans*=(x*y)
    ans%=mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#B問題
import bisect

N = int(input())
S = list(str(input()))
mod = 998244353
N_factorial = 1
for i in range(N):
    N_factorial*=(i+1)
    N_factorial%=mod

r,g,b = [],[],[]
for i in range(3*N):
    if S[i] == "R":
        r.append(i)
    if S[i] == "G":
        g.append(i)
    if S[i] == "B":
        b.append(i)
        
m,M = [],[]
for i in range(N):
    m.append(min(r[i],g[i],b[i]))
    M.append(max(r[i],g[i],b[i]))
    
A,B,C = [],[],[]    
    
for i in range(N):
    A.append(m[i])
    C.append(M[i])
    
for i in range(3*N):
    if i not in A and i not in C:
        B.append(i)
        
count = 1
for i in range(N):
    B_ind = B[i]
    x = bisect.bisect_left(A,B_ind)-i
    y = i+1-bisect.bisect_right(C,B_ind)
    count*=(x*y)%mod
        
ans = (count*N_factorial)%mod
print(ans)

Fixed submission:
#B問題
import bisect

N = int(input())
S = list(str(input()))
mod = 998244353
N_factorial = 1
for i in range(N):
    N_factorial*=(i+1)
    N_factorial%=mod

r,g,b = [],[],[]
for i,s in enumerate(S):
    if s == "R":
        r.append(i)
    if s == "G":
        g.append(i)
    if s == "B":
        b.append(i)
        
A,B,C = [],[],[]
for i in range(N):
    rgb = [r[i],g[i],b[i]]
    rgb.sort()
    A.append(rgb[0])
    B.append(rgb[1])
    C.append(rgb[2])

ans = N_factorial
for i,B_ind in enumerate(B):
    x = bisect.bisect_left(A,B_ind)-i
    y = i+1-bisect.bisect_left(C,B_ind)
    ans*=(x*y)
    ans%=mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#B問題
import bisect

N = int(input())
S = list(str(input()))
mod = 998244353
N_factorial = 1
for i in range(N):
    N_factorial*=(i+1)
    N_factorial%=mod

r,g,b = [],[],[]
for i in range(3*N):
    if S[i] == "R":
        r.append(i)
    if S[i] == "G":
        g.append(i)
    if S[i] == "B":
        b.append(i)
        
m,M = [],[]
for i in range(N):
    m.append(min(r[i],g[i],b[i]))
    M.append(max(r[i],g[i],b[i]))
    
A,B,C = [],[],[]    
    
for i in range(N):
    A.append(m[i])
    C.append(M[i])
    
for i in range(3*N):
    if i not in A and i not in C:
        B.append(i)
        
count = 1
for i in range(N):
    B_ind = B[i]
    x = bisect.bisect_left(A,B_ind)-i
    y = i+1-bisect.bisect_right(C,B_ind)
    count*=(x*y)%mod
        
ans = (count*N_factorial)%mod
print(ans)

Fixed submission:
#B問題
import bisect

N = int(input())
S = list(str(input()))
mod = 998244353
N_factorial = 1
for i in range(N):
    N_factorial*=(i+1)
    N_factorial%=mod

r,g,b = [],[],[]
for i,s in enumerate(S):
    if s == "R":
        r.append(i)
    if s == "G":
        g.append(i)
    if s == "B":
        b.append(i)
        
A,B,C = [],[],[]
for i in range(N):
    rgb = [r[i],g[i],b[i]]
    rgb.sort()
    A.append(rgb[0])
    B.append(rgb[1])
    C.append(rgb[2])

ans = N_factorial
for i,B_ind in enumerate(B):
    x = bisect.bisect_left(A,B_ind)-i
    y = i+1-bisect.bisect_left(C,B_ind)
    ans*=(x*y)
    ans%=mod

print(ans)