#P16406. [Algo Beat Contest 004 B] Buying Lotteries
[Algo Beat Contest 004 B] Buying Lotteries
Background
Little T has recently fallen in love with scratch-off lotteries.
Problem Description
There is an lottery ticket. In the cell at row and column , there are either two values and , or a character L as and a value . If you win the lottery at row , column , you can get yuan.
If there exists at least one cell where is the character L, then you can win the entire ticket.
Otherwise, for each cell, if is equal to the winning code , then you win that cell.
You are given the winning code and the ticket you obtained. Ask how many yuan you can get in total.
Input Format
The first line contains three integers , representing the number of rows, the number of columns, and the winning code.
The next lines each contain integers or characters, representing the first element of each cell.
The next lines each contain integers, representing the second value of each cell.
Output Format
Output one number, representing the total amount of money you can get.
3 3 114514
1 3 2
2 5 7
114514 114514 1145145
1 2 3
3 2 1
5 8 9
13
2 2 1919810
114514 1145145
1919 L
1 3
2 4
10
Hint
Constraints
- .
- For all , . is an integer or the character
L. If is an integer, then .
Translated by ChatGPT 5