P10457 Fortune Telling DIY

Description

lyd learned how to use playing cards to do DIY fortune telling. The method is as follows: there is a deck of $52$ cards with both Jokers removed. After shuffling, split them evenly into $13$ piles, numbered $1 \sim 13$. Each pile has $4$ cards. The $13$-th pile is called the “life pile”, which means you have $4$ lives. Among all cards, the four $K$ cards are called the Grim Reaper. In the initial state, all cards are placed face down. The process is: - Draw the top card (the first card) from the life pile. - Flip this card face up, and place it on top of the pile whose number matches the card value. (For example, if you draw $2$, place it face up on top of pile $2$. If you draw $J$, place it on top of pile $11$. Note that it must be placed face up.) - From the pile where you just placed the card, draw the bottom card (the last card), and repeat step $2$. (For example, last time you drew $2$ and placed it on top of pile $2$. Now you draw the last card of pile $2$ and find it is $8$, then you place it on top of pile $8$, and so on.) - If you draw a $K$ during the drawing process, it means you lose one life. Discard this $K$, then restart from step $1$. - After all four lives are lost, count how many face-up cards are on top of each pile. If the same value has $4$ cards that are face up (for example, four $A$ cards), then it is called “opening a pair”. Of course, four $K$ cards do not count. - Count how many pairs are opened in total. Opening $0$ pairs is called “extremely unlucky”, $1 \sim 2$ pairs is “very unlucky”, $3$ pairs is “unlucky”, $4 \sim 5$ pairs is “slightly unlucky”, $6$ pairs is “neutral”, $7 \sim 8$ pairs is “slightly lucky”, $9$ pairs is “lucky”, $10 \sim 11$ pairs is “very lucky”, and $12$ pairs is “all flowers bloom, extremely lucky”. If you still do not understand, please refer to the sample.

Input Format

There are $13$ lines in total, each describing what cards are in that pile (suits are ignored; only values are given). For each pile, the input order is from top to bottom. For easier input, use $0$ to represent $10$.

Output Format

Output the total number of opened pairs.

Explanation/Hint

Note: After the first life is lost, the first $12$ piles become: ``` A A A 8 K 5 3 2 3 9 6 0 4 4 3 4 5 5 3 4 6 6 5 6 7 7 7 7 8 8 8 9 9 9 0 0 0 K J J J Q A Q//The K drawn here causes a death. J Q 2 2 ``` The second life is lost immediately because there is a $K$ in the life pile, so nothing changes. After the third life is lost, the first $12$ piles become: ``` A A A A 2 2 2 K 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 0 0 0 0//The K drawn here causes a death. J J J Q Q Q J Q ``` After the fourth life is lost, the first $12$ piles become: ``` A A A A 2 2 2 2//The K drawn here causes a death. 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 0 0 0 0 J J J Q Q Q J Q ``` Finally, among all face-up cards, the $9$ pairs $A\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 10$ are opened. (Note: although the last card of pile $9$ is also $9$, it was not flipped face up, so it cannot be counted.) Therefore, output $9$. Translated by ChatGPT 5