Language: C++

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

#define fs first
#define sc second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::deque Debug
template<typename T>
ostream& operator<<(ostream& os, const deque<T>& d) {
    os << "[";
    bool a = 1;
    for (auto e : d) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << " " << p.second << ")";
    return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::multiset Debug
template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
    os << "{";
    bool a = 1;
    for (auto e : mp) {
        os << (a ? "" : " ");
        os << e.first << ":" << e.second;
        a = 0;
    }
    os << "}";
    return os;
}

// std::tuple Debug
template<int N, class Tuple>
void out(ostream& os, const Tuple& t){}
template<int N, class Tuple, class H, class ...Ts>
void out(ostream& os, const Tuple& t) {
    if (N) os << " ";
    os << get<N>(t);
    out<N+1,Tuple,Ts...>(os, t);
}
template<class ...Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
    os << "(";
    out<0,tuple<Ts...>,Ts...>(os, t);
    os << ")";
    return os;
}

// Debug
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl


struct edge { int to, cost; };
ostream& operator<<(ostream& os, const edge& e) {
    os << "(" << e.to << ", " << e.cost << ")";
    return os;
}

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 998244353;

template<long long mod>
struct modint {
    using LL = long long;

    LL val;
    modint(LL val=0) : val(((val % mod) + mod) % mod) {}

    const modint operator+() const { return *this; }
    const modint operator-() const { return (-val + mod) % mod; }
    const modint reciprocal() const { return power(mod-2); }

    modint& operator+=(const modint& rhs) { (val += rhs.val) %= mod; return *this; }
    modint& operator-=(const modint& rhs) { return *this += -rhs; }
    modint& operator*=(const modint& rhs) { (val *= rhs.val) %= mod; return *this; }
    modint& operator/=(const modint& rhs) { return *this *= rhs.reciprocal(); }

    const modint operator+(const modint& rhs) const { return modint(*this) += rhs; }
    const modint operator-(const modint& rhs) const { return modint(*this) -= rhs; }
    const modint operator*(const modint& rhs) const { return modint(*this) *= rhs; }
    const modint operator/(const modint& rhs) const { return modint(*this) /= rhs; }

    const modint power(long long n) const {
        modint ret = 1, tmp = val;
        while (n > 0) {
            if (n & 1) ret *= tmp;
            tmp *= tmp; n >>= 1;
        }
        return ret;
    }

    bool operator==(const modint& rhs) const { return val == rhs.val; }
    bool operator!=(const modint& rhs) const { return !(*this == rhs); }

    friend const modint operator+(const LL& lhs, const modint& rhs) {
        return modint(lhs) + rhs;
    }
    friend const modint operator-(const LL& lhs, const modint& rhs) {
        return modint(lhs) - rhs;
    }
    friend const modint operator*(const LL& lhs, const modint& rhs) {
        return modint(lhs) * rhs;
    }
    friend const modint operator/(const LL& lhs, const modint& rhs) {
        return modint(lhs) / rhs;
    }

    friend bool operator==(const LL& lhs, const modint& rhs) {
        return modint(lhs) == rhs;
    }
    friend bool operator!=(const LL& lhs, const modint& rhs) {
        return modint(lhs) != rhs;
    }

    friend ostream& operator<<(ostream& os, const modint& a) { return os << a.val; }
    friend istream& operator>>(istream& is, modint& a) {
        LL tmp; is >> tmp;
        a = tmp;
        return is;
    }
};

template<typename Ring>
struct Fact {
    vector<Ring> fact;
    Fact(int n) {
        fact.resize(n+1);
        fact[0] = Ring{1};
        for (int i = 1; i <= n; ++i) {
            fact[i] = fact[i-1] * i;
        }
    }
    Ring operator[](int i) {
        return fact[i];
    }
};

using GF = modint<998244353>;

int main()
{
    int n; cin >> n;
    string s; cin >> s;

    vector<pair<int,int>> v(3*n);
    map<char,int> id;
    map<int, int> cnt;
    for (int i = 0; i < 3*n; ++i) {
        int idx = id[s[i]]++;
        v[i] = { idx, cnt[idx]++ };
    }

    map<char,int> sum;
    //GF ans = 1;
    LL ans = 1;

    Fact<GF> fact(n);
    vector<LL> fact(n);
    fact[0] = fact[1] = 1;
    for (int i = 2; i <= n; ++i) {
        fact[i] = (fact[i-1] * i) % MOD;
    }
    for (int i = 0; i < 3*n; ++i) {
        if (v[i].sc == 1) {
            for (auto p : sum) {
                (ans *= fact[p.sc]) %= MOD;
            }
            sum.clear();
            continue;
        }

        ++sum[s[i]];
    }
    for (auto p : sum) {
        (ans *= fact[p.sc]) %= MOD;
    }
    sum.clear();

    (ans *= fact[n]) %= MOD;

    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:230:16: error: conflicting declaration 'std::vector<long long int> fact'
  230 |     vector<LL> fact(n);
      |                ^~~~
a.cc:229:14: note: previous declaration as 'Fact<modint<998244353> > fact'
  229 |     Fact<GF> fact(n);
      |              ^~~~
a.cc:233:35: error: no match for 'operator%' (operand types are 'const modint<998244353>' and 'const LL' {aka 'const long long int'})
  233 |         fact[i] = (fact[i-1] * i) % MOD;
      |                   ~~~~~~~~~~~~~~~ ^ ~~~
      |                              |      |
      |                              |      const LL {aka const long long int}
      |                              const modint<998244353>
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:1:
/usr/include/c++/14/bits/valarray_after.h:409:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__modulus, typename _Dom1::value_type>::result_type> std::operator%(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  409 |     _DEFINE_EXPR_BINARY_OPERATOR(%, struct std::__modulus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note:   template argument deduction/substitution failed:
a.cc:233:37: note:   'const modint<998244353>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  233 |         fact[i] = (fact[i-1] * i) % MOD;
      |                                     ^~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__modulus, typename _Dom1::value_type>::result_type> std::operator%(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  409 |     _DEFINE_EXPR_BINARY_OPERATOR(%, struct std::__modulus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note:   template argument deduction/substitution failed:
a.cc:233:37: note:   'const modint<998244353>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  233 |         fact[i] = (fact[i-1] * i) % MOD;
      |                                     ^~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__modulus, typename _Dom1::value_type>::result_type> std::operator%(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  409 |     _DEFINE_EXPR_BINARY_OPERATOR(%, struct std::__modulus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note:   template argument deduction/substitution failed:
a.cc:233:37: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'const LL' {aka 'const long long int'}
  233 |         fact[i] = (fact[i-1] * i) % MOD;
      |                                     ^~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__modulus, typename _Dom1::value_type>::result_type> std::operator%(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  409 |     _DEFINE_EXPR_BINARY_OPERATOR(%, struct std::__modulus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note:   template argument deduction/substitution failed:
a.cc:233:37: note:   'const modint<998244353>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  233 |         fact[i] = (fact[i-1] * i) % MOD;
      |                                     ^~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__modulus, typename _Dom1::value_type>::result_type> std::operator%(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  409 |     _DEFINE_EXPR_BINARY_OPERATOR(%, struct std::__modulus)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:409:5: note:   template argument deduction/substitution failed:
a.cc:233:37: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'const LL' {aka 'const long long int'}
  233 |         fact[i] = (fact[i-1] * i) % MOD;
      |                                     ^~~
/usr/include/c++/14/valarray:1200:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__modulus, _Tp>::result_type> std::operator%(const valarray<_Tp>&, const valarray<_Tp>&)'
 1200 | _DEFINE_BINARY_OPERATOR(%, __modulus)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1200:1: note:   template argument deduction/substitution failed:
a.cc:233:37: note:   'const modint<998244353>' is not derived from 'const std::valarray<_Tp>'
  233 |         fact[i] = (fact[i-1] * i) % MOD;
      |                                     ^~~
/usr/include/c++/14/valarray:1200:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__modulus, _Tp>::result_type> std::operator%(const valarray<_Tp>&, const typename valarray<_Tp>::value_type&)'
 1200 | _DEFINE_BINARY_OPERATOR(%, __modulus)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1200:1: note:   template argument deduction/substitution failed:
a.cc:233:37: note:   'const modint<998244353>' is not derived from 'const std::valarray<_Tp>'
  233 |         fact[i] = (fact[i-1] * i) % MOD;
      |                                     ^~~
/usr/include/c++/14/valarray:1200:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__modulus, _Tp>::result_type> std::operator%(const typename valarray<_Tp>::value_type&, const valarray<_Tp>&)'
 1200 | _DEFINE_BINARY_OPERATOR(%, __modulus)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1200:1: note:   template argument deduction/substitution failed:
a.cc:233:37: note:   mismatched types 'const std::valarray<_Tp>' and 'const LL' {aka 'const long long int'}
  233 |         fact[i] = (fact[i-1] * i) % MOD;
      |                                     ^~~
a.cc:238:22: error: no match for 'operator*=' (operand types are 'LL' {aka 'long long int'} and 'modint<998244353>')
  238 |                 (ans *= fact[p.sc]) %= MOD;
      |                  ~~~~^~~~~~~~~~~~~
a.cc:247:14: error: no match for 'operator*=' (operand types are 'LL' {aka 'long long int'} and 'modint<998244353>')
  247 |         (ans *= fact[p.sc]) %= MOD;
      |          ~~~~^~~~~~~~~~~~~
a.cc:251:10: error: no match for 'operator*=' (operand types are 'LL' {aka 'long long int'} and 'modint<998244353>')
  251 |     (ans *= fact[n]) %= MOD;
      |      ~~~~^~~~~~~~~~