Language: C++

#define _CRT_SECURE_NO_WARNINGS
#define MOD 998244353
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>
#include <cstdio>
#include <utility>
#include <unordered_map>
#include <cmath>
#include <chrono>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll, ll> P;
struct edge { ll to, cost; };
#define int ll
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,-1)

inline ll madd(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a + b) % MOD;
}
inline ll msub(ll a, ll b) {
	a %= MOD;b %= MOD;
	a += MOD;
	return (a - b) % MOD;
}
inline ll mmul(ll a, ll b) {
	a %= MOD;b %= MOD;
	return (a*b) % MOD;
}
inline ll mpow(ll a, ll r) {
	long long res = 1;
	while (r > 0) {
		if (r & 1) res = res * a % MOD;
		a = a * a % MOD;
		r >>= 1;
	}
	return res;
}
inline ll minv(ll a) {
	a %= MOD;
	ll b = MOD, u = 0, v = 1;
	while (a) {
		ll t = b / a;
		b -= t * a; swap(a, b);
		u -= t * v; swap(u, v);
	}
	if (u < 0) u += MOD;
	return u;
}
inline ll mdiv(ll a, ll b) {
	a %= MOD;
	a *= minv(b);
	return a%MOD;
}

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

/*int V;
vector<edge> G[MAX_V];
int d[MAX_V]:
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> q;
fill(d, d + V, INF);


}*/
//ll fact[100001], fact_inv[100001];
/*
ll combi(int a, int b) {
return mmul(fact[a], mmul(fact_inv[b], fact_inv[a - b]));
}
*/

ll ff(string s) {
	ll res = 1, cnt0 = 0, cnt1 = 0;
	char c = s[0];
	bool b = true;
	REP(i, s.length()) {
		if (b) {
			if (s[i] == c) {
				cnt0++;
			}
			else {
				b = false;
				c = s[i];
				cnt1++;
			}
		}
		else {
			if (s[i] == c) {
				cnt1++;
			}
			else {
				b = true;
				c = s[i];
				ll m = min(cnt0, cnt1);
				REP(j, m) {
					res = mmul(res, j + 1);
				}
				cnt0 -= m;
				cnt1 -= m;
				cnt0++;
			}
		}
	}
	REP(i, cnt0) {
		res = mmul(res, i + 1);
	}

	return res;
}

ll f(string s0, int n) {
	string s;
	char c = s0[0];
	char cc;
	REP(i, n * 3) {
		if (s0[i] != c) {
			cc = s0[i];
			break;
		}
	}
	if (cc == 'G') {
		for (char c : s0) {
			if (c == 'R') {
				s += 'B';
			}
			else if (c == 'G') {
				s += 'R';
			}
			else if(c=='B'){
				s += 'G';
			}
		}
	}
	else if (cc == 'B') {
		for (char c : s0) {
			if (c == 'R') {
				s += 'G';
			}
			else if (c == 'G') {
				s += 'B';
			}
			else if(c=='B'){
				s += 'R';
			}
		}
	}
	else {
		s = s0;
	}
	string brstr, grstr;
	int b = 0, g = 0, r = 0, br = 0, gr = 0;
	deque<char> st;
	ll res = 1;
	REP(i, n * 3) {
		char c = s[i];
		if (c == 'R') {
			if (b > 0 && g > 0) {
				r++;
				st.push_back('R');
				while (!(r == g && g == b)) {
					i++;
					st.push_back(s[i]);
					if (s[i] == 'R') r++;
					else if (s[i] == 'G') g++;
					else if (s[i] == 'B') b++;
				}
				string sss;
				for (char c : st) sss += c;
				st.clear();
				res = mmul(res, f(sss, r));
				r = 0;g = 0;b = 0;
			}
			else if (b > 0) {
				res = mmul(res, b);
				b--;
				st.pop_back();
				br++;
				brstr += 'x';
			}
			else if (g > 0) {
				res = mmul(res, g);
				g--;
				st.pop_back();
				gr++;
				grstr += 'x';
			}
			else {
				r++;
			}
		}
		else if (c == 'G') {
			if (br > 0) {
				br--;
				brstr += 'y';
			}
			else if (r == 0) {
				g++;
				st.push_back('G');
			}
			else {
				res = mmul(res, r);
				r--;
				gr++;
				grstr += 'x';
			}
		}
		else if (c == 'B') {
			if (gr > 0) {
				gr--;
				grstr += 'y';
			}
			else if (r == 0) {
				b++;
				st.push_back('B');
			}
			else {
				res = mmul(res, r);
				r--;
				br++;
				brstr += 'x';
			}
		}
	}
	res = mmul(res, ff(grstr));
	res = mmul(res, ff(brstr));
	return res;
}

int main() {
	int n;
	string s;
	cin >> n >> s;
	ll res = f(s, n);
	REP(i, n) res = mmul(res, i + 1);
	cout << res;
	return 0;
}


Compiler output:
a.cc:27:13: error: '::main' must return 'int'
   27 | #define int ll
      |             ^~
a.cc:267:1: note: in expansion of macro 'int'
  267 | int main() {
      | ^~~