P10228 [COCI 2023/2024 #4] Bingo
Background
**Translated from [COCI 2023/2024 Contest #4](https://hsin.hr/coci/archive/2023_2024) T1 “[Bingo](https://hsin.hr/coci/archive/2023_2024/contest4_tasks.pdf)”.**
Description
It is time to play Bingo.
To play Bingo, you need a game host and a drum containing 90 balls. The balls in the drum are numbered from $1$ to $90$, and each number is written on exactly one ball.
Before the game starts, the host gives each of the $n$ players a $5 \times 5$ board. Each cell contains an integer from $1$ to $90$. All numbers on a single board are distinct, and all players’ boards are different from each other.
After all players receive their boards, the game begins.
The host starts drawing balls from the drum. After drawing the ball numbered $x_i$, the host announces the number to all players and puts the ball aside. All players check their boards, and if the drawn number appears on their board, they cross it out.
When a player has crossed out all 5 numbers in a row, a column, the main diagonal, or the anti-diagonal, that player will shout `Bingo!`. At that moment, the game ends and that player wins.
To make the game more interesting, the host decides to add an extra rule. Before anyone is allowed to shout `Bingo!`, the host will first draw $m$ balls. (Even if a player has already crossed out 5 in a line, they must wait until $m$ balls have been drawn before they can shout `Bingo!`.)
However, at the instant the host draws the $m$-th ball, a commotion breaks out. All players shout `Bingo!`.
The host does not know whom to believe. To resolve this situation, he asks you for help. Compute how many players can shout `Bingo!` after $m$ balls have been drawn.
Input Format
The first line contains an integer $n$ ($1 \le n \le 50$), the number of players.
Then follow $n \times 6$ lines:
- The first line contains a string of length at most $20$, consisting only of lowercase English letters, the player’s name. No two players have the same name.
- The next $5$ lines each contain $5$ integers in the range $1$ to $90$, describing the player’s board. All numbers on each board are distinct.
The next line contains an integer $m$ ($1 \le m \le 90$), the number of balls the host will draw.
The next line contains $m$ integers in the range $1$ to $90$, the numbers of the balls drawn from the drum. Each number appears at most once.
Output Format
On the first line output an integer $k$, the number of players who can shout `Bingo!`.
Then output $k$ lines with their names, in the same order as in the input.
Explanation/Hint
### Sample Explanation 1
`babylasagna` achieves `Bingo!` on the first row.
`nataliebalmix` achieves `Bingo!` on the first column.
`lettri` achieves `Bingo!` on the anti-diagonal from bottom-left to top-right.
### Sample Explanation 2
Only 4 balls were drawn, so nobody can cross out 5 numbers.
### Subtasks
| Subtask | Points | Constraints |
| :--: | :--: | :--: |
| 1 | 12 | There is only one player, i.e., $n = 1$ |
| 2 | 22 | At most one player shouts `Bingo!` |
| 3 | 16 | No additional constraints |
Translated by ChatGPT 5