fun main(arg: Array<String>) {
    val MOD = 998244353L
    val N = readLine()!!.toInt()
    val S = readLine()!!
    fun sa(A: Long, B: Long, C: Long): Long {
        val min = Math.min(B, C)
        val max = Math.max(B, C)
        return if (A <= min) min - A else if (A <= max) max - A else 0
    }
    var ans = 1L
    var cntA = 0L
    var cntB = 0L
    var cntC = 0L
    for (ch in S) {
        val r: Long
        if (ch == 'R') {
            r = sa(++cntA, cntB, cntC)
        } else if (ch == 'G') {
            r = sa(++cntB, cntA, cntC)
        } else {
            r = sa(++cntC, cntA, cntB)
        }
        ans = ans * (r + 1) % MOD
    }
    for (n in 1..N) ans = ans * n % MOD
    println(ans)
}
