#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include ".inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

const long long MAX_N = 300010;
const long long mod = 998244353;
long long fc[MAX_N];

void init_fact() {
    fc[0] = fc[1] = 1;
    for (int i = 2; i < MAX_N; ++i) {
        fc[i] = (fc[i - 1] * i) % mod;
    }
}

const int R = 1, G = 2, B = 3, GB = 4, RB = 5, RG = 6;
long long dp[8][MAX_N];

void reset(int l, int r) {
    for (int i = 0; i < 8; ++i) {
        for (int j = l; j < r; ++j) {
            dp[i][j] = 0;
        }
    }
}

long long solve(string &S, int l, int r) {
    reset(l, r);

    long long pat = 1;
    for (int i = l; i < r; ++i) {
        if (i == l) {
            if (S[i] == 'R') {
                dp[R][i] = 1;
            } else if (S[i] == 'G') {
                dp[G][i] = 1;
            } else if (S[i] == 'B') {
                dp[B][i] = 1;
            }
            continue;
        }

        assert(1 <= i && i < MAX_N);
        for (int j = 0; j < 8; ++j) {
            dp[j][i] = dp[j][i - 1];
        }

        if (S[i] == 'R') {
            if (dp[GB][i - 1] > 0) {
                pat = (pat * dp[GB][i - 1]) % mod;
                dp[GB][i]--;
            } else if (dp[B][i - 1] > 0) {
                pat = (pat * dp[B][i - 1]) % mod;
                dp[B][i]--;
                dp[RB][i]++;
            } else if (dp[G][i - 1] > 0) {
                pat = (pat * dp[G][i - 1]) % mod;
                dp[G][i]--;
                dp[RG][i]++;
            } else {
                dp[R][i]++;
            }
        } else if (S[i] == 'G') {
            if (dp[RB][i - 1] > 0) {
                pat = (pat * dp[RB][i - 1]) % mod;
                dp[RB][i]--;
            } else if (dp[B][i - 1] > 0) {
                pat = (pat * dp[B][i - 1]) % mod;
                dp[B][i]--;
                dp[GB][i]++;
            } else if (dp[R][i - 1] > 0) {
                pat = (pat * dp[R][i - 1]) % mod;
                dp[R][i]--;
                dp[RG][i]++;
            } else {
                dp[G][i]++;
            }
        } else if (S[i] == 'B') {
            if (dp[RG][i - 1] > 0) {
                pat = (pat * dp[RG][i - 1]) % mod;
                dp[RG][i]--;
            } else if (dp[R][i - 1] > 0) {
                pat = (pat * dp[R][i - 1]) % mod;
                dp[R][i]--;
                dp[RB][i]++;
            } else if (dp[G][i - 1] > 0) {
                pat = (pat * dp[G][i - 1]) % mod;
                dp[G][i]--;
                dp[GB][i]++;
            } else {
                dp[B][i]++;
            }
        }
    }
    return pat;
}

// string makeS(int N) {
//     string s = "";
//     for (int i=0; i<N; ++i) {
//         s += "RGB";
//     }
//     random_device seed_gen;
//     mt19937 engine(seed_gen());
//     shuffle(s.begin(), s.end(), engine);
//     return s;
// }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    init_fact();

    int N;
    cin >> N;
    string S;
    cin >> S;
    
    long long r = 0, g = 0, b = 0;
    long long pat = 1;
    for (int i = 0; i < (int)S.size(); ++i) {
        if (S[i] == 'R') r++;
        if (S[i] == 'G') g++;
        if (S[i] == 'B') b++;
        if (r == g && g == b) {
            long long t = solve(S, i + 1 - r * 3, i + 1);
            pat = (pat * t) % mod;
            r = 0, g = 0, b = 0;
        }
    }
    long long ans = (pat * fc[N]) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 21780