#include #include using namespace std; using mint = atcoder::modint998244353; const int CombMAX = 3000000; std::vector fac(CombMAX + 1), finv(CombMAX + 1), inv(CombMAX + 1); struct Combinationinit { Combinationinit() { const int MOD = mint::mod(); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i <= CombMAX; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); finv[i] = finv[i - 1] * inv[i]; } } } Combinationinit_; int main() { int n; string s; cin >> n >> s; int count_a = count(s.begin(), s.end(), 'A'); int count_b = count(s.begin(), s.end(), 'B'); int count_c = count(s.begin(), s.end(), 'C'); bool can_operation = 0, exist_a = 0, exist_ab = 0, exist_b = 0, exist_bc = 0, exist_c = 0, exist_ca = 0; for(auto &c : s) { if(c == 'A') { exist_a = 1; if(exist_c) exist_ca = 1; if(exist_bc) can_operation = 1; } if(c == 'B') { exist_b = 1; if(exist_a) exist_ab = 1; if(exist_ca) can_operation = 1; } if(c == 'C') { exist_c = 1; if(exist_b) exist_bc = 1; if(exist_ab) can_operation = 1; } } if(can_operation) { mint res = fac[n] * finv[count_a] * finv[count_b] * finv[count_c] - n; cout << res.val() << endl; } else cout << 1 << endl; }