#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 998244353;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

template <ll mod>
class Fp {
public:
    ll val;

private:
    inline void calc_mod(ll &v) {
        if (v >= mod)
            v -= mod;
    }

public:
    Fp() {}
    Fp(ll v) : val(v % mod) {
        if (val < 0)
            val += mod;
    }
    Fp operator+=(const Fp &in) {
        val += in.val;
        calc_mod(val);
        return *this;
    }
    Fp operator+(const Fp &in) const {
        return Fp(*this) += in;
    }
    Fp &operator-=(const Fp &in) {
        val -= in.val;
        calc_mod(val);
        if (val < 0)
            val += mod;
        return *this;
    }
    Fp operator-(const Fp &in) const {
        return Fp(*this) -= in;
    }
    Fp &operator*=(const Fp &in) {
        val = val * in.val % mod;
        return *this;
    }
    Fp operator*(const Fp &in) const {
        return Fp(*this) *= in;
    }
    Fp &operator/=(const Fp &in) {
        *this *= modpow(in, mod - 2);
        return *this;
    }
    Fp operator/(const Fp &in) const {
        return Fp(*this) /= in;
    }
    bool operator==(const Fp &in) const {
        return val == in.val;
    }
    bool operator!=(const Fp &in) const {
        return val != in.val;
    }
    friend Fp modpow(const Fp &in, ll n) {
        if (n == 0)
            return 1;
        if (n & 1) {
            return in * modpow(in * in, n / 2);
        } else {
            return modpow(in * in, n / 2);
        }
    }
    friend istream &operator>>(istream &is, Fp<mod> &fp) {
        is >> fp.val;
        return is;
    }

    friend ostream &operator<<(ostream &os, Fp<mod> &fp) {
        os << fp.val;
        return os;
    }
};
using modll = Fp<mod>;
class Factorial {
public:
    vector<modll> fact, finv;
    Factorial(ll n) : fact(n + 1, modll(1)), finv(n + 1, modll(1)) {
        for (int i = 2; i <= n; i++) {
            modll tmp(i);
            fact[i] = fact[i - 1] * tmp;
            finv[i] = finv[i - 1] / tmp;
        }
    }
    modll com(const ll &n, const ll &k) {
        if (n < k || n < 0 || k < 0)
            return modll(0);
        return fact[n] * finv[k] * finv[n - k];
    }
};

signed main() {
    cin >> N;
    cin >> S;
    modll ans = 1;
    Factorial f(N);
    map<set<char>, int> mp;
    set<set<char>> st;
    for (int i = 0; i < S.size(); i++) {
        if (st.size() == 2) {
            set<char> two, one;
            for (auto &s : st) {
                if (s.size() == 2) {
                    two = s;
                } else {
                    one = s;
                }
            }
            if (two.count(S[i]) == 0) {
                ans *= mp[two];
                mp[two]--;
                if (mp[two] == 0) {
                    st.erase(two);
                }
            } else if (one.count(S[i]) == 1) {
                mp[one]++;
            } else {
                ans *= mp[one];
                mp[one]--;
                mp[two]++;
                if (mp[one] == 0) {
                    st.erase(one);
                }
            }
        } else if (st.size() == 1) {
            set<char> s = *st.begin();
            if (s.size() == 2) {
                if (s.count(S[i]) == 0) {
                    ans *= mp[s];
                    mp[s]--;
                    if (mp[s] == 0) {
                        st.erase(s);
                    }
                } else {
                    set<char> x;
                    x.insert(S[i]);
                    st.insert(x);
                    mp[x]++;
                }
            } else {
                if (s.count(S[i]) == 0) {
                    ans *= mp[s];
                    mp[s]--;
                    if (mp[s] == 0) {
                        st.erase(s);
                    }
                    s.insert(S[i]);
                    st.insert(s);
                    mp[s]++;
                } else {
                    mp[s]++;
                }
            }
        } else {
            set<char> s;
            s.insert(S[i]);
            st.insert(s);
            mp[s]++;
        }
        dump(i);
        for (auto &kv : mp) {
            auto s = kv.first;
            dump(s, kv.second);
        }
        for (auto s : st) {
            dump(s);
        }
    }
    ans *= f.fact[N];
    cout << ans << endl;
}

Measured memory_bytes: 2180