from bisect import bisect
from math import factorial
n = int(input())
R,B,G = [],[],[]
m,M,mid = [],[],[]
ans = factorial(n)
for i,j in enumerate(input()):
	if j=="R":
		R += [i]
	elif j=="B":
		B += [i]
	else:
		G += [i]
for r,b,g in zip(R,B,G):
	f,s,t = sorted([r,b,g])
	m += [f]
	M += [t]
	mid += [s]
for i,j in enumerate(mid):
	i = bisect(m,j) - i
	if i > 1:
		ans *= i
for i,j in enumerate(mid[::-1]):
	i = n - i - bisect(M,j)
	if i > 1:
		ans *= i
print(ans)