{"problem":{"name":"LR Constraints","description":{"content":"We have $N$ cards arranged in a row from left to right. We will write an integer between $1$ and $K$ (inclusive) on each of these cards, which are initially blank. Given are $K$ restrictions numbered ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc124_a"},"statements":[{"statement_type":"Markdown","content":"We have $N$ cards arranged in a row from left to right. We will write an integer between $1$ and $K$ (inclusive) on each of these cards, which are initially blank.\nGiven are $K$ restrictions numbered $1$ through $K$. Restriction $i$ is composed of a character $c_i$ and an integer $k_i$. If $c_i$ is `L`, the $k_i$\\-th card from the left in the row must be the **leftmost** card on which we write $i$. If $c_i$ is `R`, the $k_i$\\-th card from the left in the row must be the **rightmost** card on which we write $i$.\nNote that for each integer $i$ from $1$ through $K$, there must be at least one card on which we write $i$.\nFind the number of ways to write integers on the cards under the $K$ restrictions, modulo $998244353$.\n\n## Constraints\n\n*   $1 \\leq N,K \\leq 1000$\n*   $c_i$ is `L` or `R`.\n*   $1 \\leq k_i \\leq N$\n*   $k_i \\neq k_j$ if $i \\neq j$.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $K$\n$c_1$ $k_1$\n$\\vdots$\n$c_K$ $k_K$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc124_a","tags":[],"sample_group":[["3 2\nL 1\nR 2","1\n\n*   The only way to meet the two restrictions is to write $1, 2, 1$ from left to right on the three cards."],["30 10\nR 6\nR 8\nR 7\nR 25\nL 26\nL 13\nR 14\nL 11\nL 23\nR 30","343921442\n\n*   Be sure to find the count modulo $998244353$."]],"created_at":"2026-03-03 11:01:14"}}