#include #include using namespace std; typedef long long ll; ll mod2 = 998244353; ll my_pow(ll x, ll n, ll mod){ // 繰り返し二乗法.x^nをmodで割った余り. ll ret; if (n == 0){ ret = 1; } else if (n % 2 == 1){ ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod; } else{ ret = my_pow((x * x) % mod, n / 2, mod); } return ret; } int main(){ ll N; cin >> N; vector S(N); vector A(N); ll all_sum = 0; ll spring = 0; for (ll i = 0; i < N; i++){ cin >> S[i] >> A[i]; all_sum += A[i]; if (S[i] == 'P') spring++; } vector summer(201, 0); vector fall(201, 0); vector winter(201, 0); for (ll i = 0; i < N; i++){ if (S[i] == 'U') summer[A[i]]++; if (S[i] == 'F') fall[A[i]]++; if (S[i] == 'W') winter[A[i]]++; } vector pow_1(202, 0); vector pow_2(202, 0); vector pow_3(606, 0); for (ll i = 0; i <= 200; i++){ pow_1[i] = my_pow(N - 1, i, mod2); pow_2[i] = my_pow(N - 2, i, mod2); } for (ll i = 0; i <= 600; i++){ if (i <= all_sum) pow_3[i] = my_pow(N - 1, all_sum - i, mod2); } ll ans = 0; for (ll i = 1; i <= 200; i++){ for (ll j = 1; j <= 200; j++){ for (ll k = 1; k <= 200; k++){ if (summer[i] == 0 || fall[j] == 0 || winter[k] == 0) continue; ll prod = 1; prod = (prod * ((pow_1[i] - pow_2[i] + mod2) % mod2)) % mod2; prod = (prod * ((pow_1[j] - pow_2[j] + mod2) % mod2)) % mod2; prod = (prod * ((pow_1[k] - pow_2[k] + mod2) % mod2)) % mod2; prod = (prod * pow_3[i + j + k]) % mod2; prod = (prod * summer[i]) % mod2; prod = (prod * fall[j]) % mod2; prod = (prod * winter[k]) % mod2; prod = (prod * spring) % mod2; ans = (ans + prod) % mod2; } } } cout << ans << endl; }