#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 998244353;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

// mod int struct
// original : https://github.com/beet-aizu/library/blob/master/mod/mint.cpp

struct mint {
    ll v;
    ll mod;
    mint() : v(0) {}
    mint(signed v, ll mod = MOD) : v(v), mod(mod) {}
    mint(ll t, ll mod = MOD) : mod(mod) {
        v = t % mod;
        if (v < 0)
            v += mod;
    }

    mint pow(ll k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }

    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }

    mint inv() { return pow(mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += mod - a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = 1LL * v * a.v % mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }

    // find x s.t. a^x = b
    static ll log(ll a, ll b) {
        const ll sq = 40000;
        unordered_map<ll, ll> dp;
        dp.reserve(sq);
        mint res(1);
        for (int r = 0; r < sq; r++) {
            if (!dp.count(res.v))
                dp[res.v] = r;
            res *= a;
        }
        mint p = mint(a).inv().pow(sq);
        res    = b;
        for (int q = 0; q <= MOD / sq + 1; q++) {
            if (dp.count(res.v)) {
                ll idx = q * sq + dp[res.v];
                if (idx > 0)
                    return idx;
            }
            res *= p;
        }
        assert(0);
        return ll(-1);
    }

    static mint comb(long long n, int k) {
        mint num(1), dom(1);
        for (int i = 0; i < k; i++) {
            num *= mint(n - i);
            dom *= mint(i + 1);
        }
        return num / dom;
    }
};
ostream &operator<<(ostream &os, mint m) {
    os << m.v;
    return os;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vi r, b, g;
    for (int i = 0; i < 3 * n; ++i) {
        if (s[i] == 'R') {
            r.push_back(i);
        } else if (s[i] == 'G') {
            g.push_back(i);
        } else {
            b.push_back(i);
        }
    }
    vector<vvi> rgbs(6, vvi(3));
    // r x
    // g x
    // b x
    //   x r
    //   x g
    //   x b
    for (int i = 0; i < n; ++i) {
        if (r[i] < g[i] && g[i] < b[i]) {
            rgbs[0][0].push_back(r[i]);
            rgbs[0][1].push_back(g[i]);
            rgbs[5][1].push_back(g[i]);
            rgbs[5][2].push_back(b[i]);
        } else if (r[i] < b[i] && b[i] < g[i]) {
            rgbs[0][0].push_back(r[i]);
            rgbs[0][1].push_back(b[i]);
            rgbs[4][1].push_back(b[i]);
            rgbs[4][2].push_back(g[i]);
        } else if (g[i] < b[i] && b[i] < r[i]) {
            rgbs[1][0].push_back(g[i]);
            rgbs[1][1].push_back(b[i]);
            rgbs[3][1].push_back(b[i]);
            rgbs[3][2].push_back(r[i]);
        } else if (g[i] < r[i] && r[i] < b[i]) {
            rgbs[1][0].push_back(g[i]);
            rgbs[1][1].push_back(r[i]);
            rgbs[5][1].push_back(r[i]);
            rgbs[5][2].push_back(b[i]);
        } else if (b[i] < r[i] && r[i] < g[i]) {
            rgbs[2][0].push_back(b[i]);
            rgbs[2][1].push_back(r[i]);
            rgbs[4][1].push_back(r[i]);
            rgbs[4][2].push_back(g[i]);
        } else if (b[i] < g[i] && g[i] < r[i]) {
            rgbs[2][0].push_back(b[i]);
            rgbs[2][1].push_back(g[i]);
            rgbs[3][1].push_back(g[i]);
            rgbs[3][2].push_back(r[i]);
        } else {
            assert(false);
        }
    }
    mint ret = 1;
    for (int i = 0; i < 6; ++i) {
        int k = rgbs[i][1].size();
        if (i < 3) {
            int l = 0;
            for (int j = 0; j < k; ++j) {
                while (l != k - 1 && rgbs[i][1][j] > rgbs[i][0][l + 1])
                    l++;
                ret *= l + 1 - j;
                assert(l + 1 - j > 0);
            }
        } else {
            int r = k - 1;
            for (int j = k - 1; j >= 0; --j) {
                while (r != 0 && rgbs[i][1][j] < rgbs[i][2][r - 1])
                    r--;
                ret *= (k - 1 - r + 1) - (k - 1 - j);
                assert((k - 1 - r + 1) - (k - 1 - j) > 0);
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        ret *= i;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 4348