No.2783 4-33 Easy
Brief Story
Yasazo, a fan of the amateur baseball team "Spotted Grasshoppers", records the score of each inning of their games on cards and keeps them.
One day, Yasazo accidentally turned over the file holding the cards.
When it was turned over, $N$ cards fell out of the file. Yasazo picked up $9$ of the fallen cards and noticed that, when arranged appropriately, they form a combination whose game result is $4-33$.
Yasazo now wonders how many ways there are to pick up such a combination from the fallen cards. Please find the actual number of ways.
Problem Statement
You are given information about $N$ mutually distinguishable cards. The $i$-th card has $A_i$ written on its upper part and $B_i$ written on its lower part.
$A_i$ is a non-negative integer, and $B_i$ is one of the following: a non-negative integer, X (uppercase), or a string formed by appending X to (the decimal representation of) a positive integer.
From the $N$ cards, you choose $9$ cards for which a good scoreboard exists.
A good scoreboard is an arrangement of the $9$ cards that satisfies the following conditions.
Conditions for a good scoreboard:
- Arrange the cards in a horizontal row, and let $U_j$ and $D_j$ be what is written on the upper part and the lower part, respectively, of the $j\ (1\leq j\leq 9)$-th card from the left
- For $1\leq j\leq 8$, $D_j$ does not contain
X - Hereafter, let $d_9$ be the string obtained by removing as many
Xas possible from $D_9$, regarded as an integer (if the string becomes empty, let $d_9=0$) - If $\displaystyle\sum_{k=1}^9U_k<\sum_{k=1}^8D_k+d_9$, then $D_9$ contains
X, and if $d_9\neq0$, then $\displaystyle\sum_{k=1}^9U_k\geq \sum_{k=1}^8D_k+d_9-4$
Among the ways to choose $9$ cards for which a good scoreboard exists, find the number of ways such that the sum of the upper parts is $4$ and the sum of the lower parts is $33$.
More precisely, find the number of ways to choose $9$ cards for which there exists a good scoreboard satisfying $\displaystyle\sum_{k=1}^9U_k=4,\ \displaystyle\sum_{k=1}^8D_k+d_9=33$.
Since the answer can be very large, print the answer modulo $998244353$.
Input
$N$ $A_1\ A_2\ \dots\ A_N$ $B_1\ B_2\ \dots\ B_N$
- $9\leq N\leq 2000$
- $0\leq A_i\leq 4$
- $0\leq B_i\leq 33$, or $B_i=$
X(uppercase), or $B_i$ is a string formed by appendingXto (the decimal representation of) an integer satisfying $1\leq b\leq 33$ - All numerical values in the input are integers
Output
Print the answer modulo $998244353$.
Print a newline at the end.
Sample
Sample 1
Input
14 1 0 1 0 0 2 0 1 0 3 0 0 1 0 2 7 1 8 2 8 1 8 2 8 4 5X 9X X
Output
4
For example, if you choose the cards $i=1,2,3,4,5,6,7,11,14$ or the cards $i=1,2,3,4,6,7,9,11,14$ and arrange them in this order, they look like the figures below.
Both satisfy the conditions of a good scoreboard, and the sum of the upper parts is $4$ and the sum of the lower parts is $33$, so they satisfy the requirements.
Note that the $5$-th card and the $9$-th card are distinguished.
Sample 2
Input
81 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33 0 0 0 0 0 0 0 X 0 0 0 0 0 0 0 0 1X 0 0 0 0 0 0 0 0 1X 0 0 0 0 0 0 0 0 1X 0 0 0 0 0 0 0 0 1X 0 0 0 0 0 0 0 0 1X 0 0 0 0 0 0 0 0 1X 0 0 0 0 0 0 0 0 1X 0 0 0 0 0 0 0 0 1X
Output
331646352
Since the answer can be very large, print the answer modulo $998244353$.
Sample 3
Input
52 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 3 1 5X 1 1 0 0 0 5 0 3 X 0 1 0 2 0 0 7 0 0 0 2 0 1 0 0 0 0 0 0 7 1 10 2 0 0 1 X 5 4 0 1 0 0 0 2 X
Output
228
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。