#include using namespace std; #include using mint = atcoder::modint; mint w[4]; int main() { int N; cin >> N; long long suma = 0; int cnt3 = 0; mint ret = 1; for (int i = 0; i < N; ++i) { char c; int a; cin >> c >> a; suma += a; int d = (c == 'U' ? 0 : (c == 'F' ? 1 : (c == 'W' ? 2 : 3))); cnt3 += (d == 3); w[d] += 1 - (mint(N - 2) / (N - 1)).pow(a); ret *= mint(N - 1).pow(a); } cout << (w[0] * w[1] * w[2] * ret * cnt3).val() << endl; }