output_description: Print the number of ways in which Takahashi can distribute the balls, modulo
  998244353.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      S
attempt: import itertools
  import os
  import sys
  
  import numpy as np
  
  if os.getenv("LOCAL"):
      sys.stdin = open("_in.txt", "r")
  
  sys.setrecursionlimit(2147483647)
  INF = float("inf")
  IINF = 10**18
  MOD = 998244353
  
  
  # 解説AC
  N = int(sys.stdin.readline())
  S = sys.stdin.readline().rstrip()
  
  
  def test():
      pos = {"R": [], "G": [], "B": []}
      for i, s in enumerate(S):
          pos[s].append(i)
      ret = IINF
      for r in itertools.permutations(pos["R"]):
          for g in itertools.permutations(pos["G"]):
              for b in itertools.permutations(pos["B"]):
                  s = 0
                  for i in range(N):
                      s += max(r[i], g[i], b[i]) - min(r[i], g[i], b[i])
                  ret = min(ret, s)
      return ret
  
  
  def test2():
      counter = {"R": 0, "G": 0, "B": 0}
  
      L = []
      R = []
      for i, c in enumerate(S):
          pm = max(counter.values())
          counter[c] += 1
          if pm < max(counter.values()):
              L.append(i)
          if min(counter.values()) == 1:
              R.append(i)
              for d in counter.keys():
                  counter[d] -= 1
      L = np.array(L)
      R = np.array(R)
      s = (R - L).sum()
      return s
  
  
  # N = 4
  #
  # i = 0
  # for rs in itertools.combinations(range(N * 3), r=N):
  #     s = ['G'] * (N * 3)
  #     for r in rs:
  #         s[r] = 'R'
  #     rem = list(set(range(N * 3)) - set(rs))
  #     for bs in itertools.combinations(range(N * 2), r=N):
  #         t = s.copy()
  #         for b in bs:
  #             t[rem[b]] = 'B'
  #         S = ''.join(t)
  #         a = test()
  #         b = test2()
  #         assert a == b
  #
  #         if i % 100 == 0:
  #             print(i)
  #         i += 1
  
  
  def get_lr():
      counter = {"R": 0, "G": 0, "B": 0}
  
      L = []
      R = []
      for i, c in enumerate(S):
          pm = max(counter.values())
          counter[c] += 1
          if pm < max(counter.values()):
              L.append(i)
          if min(counter.values()) == 1:
              R.append(i)
              for d in counter.keys():
                  counter[d] -= 1
      L = np.array(L)
      R = np.array(R)
      # s = (R - L).sum()
      return L, R
  
  
  # 左右は絶対ここから選ぶ
  L, R = get_lr()
  
  colors = np.array(list(S))
  lmr = np.array(["M"] * (N * 3), dtype=str)
  lmr[L] = "L"
  lmr[R] = "R"
  # 左から L, M, R の順に選ぶ組み合わせ
  
  
  counts = {
      "R": 0,
      "G": 0,
      "B": 0,
  }
  # これより右にある、使える lmr == R の数
  r_counts = np.zeros(N * 3, dtype=int)
  # これより左にある、使える lmr == L の数
  l_counts = np.zeros(N * 3, dtype=int)
  for i in range(N * 3):
      if lmr[i] == "L":
          counts[colors[i]] += 1
      if lmr[i] == "M":
          if colors[i] == "R":
              # B か G のどっちかしかない
              if counts["B"]:
                  l_counts[i] = counts["B"]
                  # 使ったので 1 減らす
                  counts["B"] -= 1
              elif counts["G"]:
                  l_counts[i] = counts["G"]
                  counts["G"] -= 1
              else:
                  assert False
          if colors[i] == "G":
              if counts["B"]:
                  l_counts[i] = counts["B"]
                  counts["B"] -= 1
              elif counts["R"]:
                  l_counts[i] = counts["R"]
                  counts["R"] -= 1
              else:
                  assert False
          if colors[i] == "B":
              if counts["R"]:
                  l_counts[i] = counts["R"]
                  counts["R"] -= 1
              elif counts["G"]:
                  l_counts[i] = counts["G"]
                  counts["G"] -= 1
              else:
                  assert False
  for i in reversed(range(N * 3)):
      if lmr[i] == "R":
          counts[colors[i]] += 1
      if lmr[i] == "M":
          if colors[i] == "R":
              if counts["B"]:
                  r_counts[i] = counts["B"]
                  counts["B"] -= 1
              elif counts["G"]:
                  r_counts[i] = counts["G"]
                  counts["G"] -= 1
              else:
                  assert False
          if colors[i] == "G":
              if counts["B"]:
                  r_counts[i] = counts["B"]
                  counts["B"] -= 1
              elif counts["R"]:
                  r_counts[i] = counts["R"]
                  counts["R"] -= 1
              else:
                  assert False
          if colors[i] == "B":
              if counts["R"]:
                  r_counts[i] = counts["R"]
                  counts["R"] -= 1
              elif counts["G"]:
                  r_counts[i] = counts["G"]
                  counts["G"] -= 1
              else:
                  assert False
  
  ans = 1
  for cnt in l_counts * r_counts:
      if cnt:
          ans *= cnt
          ans %= MOD
  # N! 人に割り当てる
  for i in range(1, N + 1):
      ans *= i
      ans %= MOD
  print(ans)
  
problem_description: Statement
  
  We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N
  represents the colors of the balls. The color of Ball i is red if S_i is `R`,
  green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green
  balls, and N blue balls.
  
  Takahashi will distribute these 3N balls to N people so that each person gets
  one red ball, one blue ball, and one green ball. The people want balls with
  IDs close to each other, so he will additionally satisfy the following
  condition:
  
    * Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order.
    * Then, \sum_j (c_j-a_j) should be as small as possible.
  
  Find the number of ways in which Takahashi can distribute the balls. Since the
  answer can be enormous, compute it modulo 998244353. We consider two ways to
  distribute the balls different if and only if there is a person who receives
  different sets of balls.
samples: [{"input": "3\n    RRRGGGBBB", "output": "216\n    \n\nThe minimum value of \\sum_j (c_j-a_j) is 18 when the balls are, for example,\ndistributed as follows:\n\n  * The first person gets Ball 1, 5, and 9.\n  * The second person gets Ball 2, 4, and 8.\n  * The third person gets Ball 3, 6, and 7.\n\n* * *"}, {"input": "5\n    BBRGRRGRGGRBBGB", "output": "960"}]