"Take 6" (also known as "6 Nimmt!") is a card game consisting of 104 cards, each with a number (ranging from 1 to 104) and a certain number of cattle head symbols. The number of cattle headson a card varies, with higher-numbered cards typically carrying more cattle heads. Players aim to finish the game with the fewest cattle heads, as each cattle head counts as a penalty point. The game is played in rounds.
Each card in the game has a certain number of "cattle heads" (penalty points). The distribution of cattle heads across the cards is as follows:
The goal is to avoid collecting cattle heads, as they represent penalty points. The player with the fewest cattle heads at the end of the game wins.
The input starts with a line containing three integers N , M , and P , which denote the number of players, the number of cards each player holds, and the number of rows on the table.
The next P lines each contain one integer Di , representing the starting card in row i on the table.
The following N lines each contain M integers Ci,1 ,Ci,2 ,...,Ci,M , where Ci,j represents the card that player i plays in round j. Each player will play one card per round.
The output should consist of N lines, where each line i contains a single integer representing the total number of cattle head for player i at the end of the game. Each player's cattle head count reflects the penalties incurred throughout the game.
At the beginning, there are two rows of cards on the table, with 11 and 6 cards respectively.
In the first round, the four players each play a card: 12, 1, 7, and 8.
Player 2 (green) plays card 1 first. Since there are no cards on the table smaller than 1, this player must take all the cards from the row with the highest last card.The player takes the card numbered 11 and earns 5 cattle heads.
Next, the cards are placed in order: 7 is placed after 6, 8 is placed after 7, and 12 is placed after 8.
In the second round, the four players each play a card: 5, 13, 2, and 14.
Player 3 (purple) plays card 2 first, and the cards are placed in order: 2 is placed after 1, 5 is placed after 2, 13 is placed after 12, and 14 is placed after 13.
Since Player 4 (gray)’s card (14) is the sixth card in the row, as a penalty, they must take the previous five cards in the row and earn 5 cattle heads.
The two new rows will become the ones shown in the image below.
In the third round, the four players each play a card: 9, 10, 4, and 3.
Player 4 (gray) plays card 3 first, but since there are no cards on the table smaller than 3, this player must take all the cards from the row with the highest last card.
The player takes the card numbered 14 and earns 1 cattle head.
Next, the cards are placed in order: 4 is placed after 3, 9 is placed after 5, and 10 is placed after 9.