QOJ.ac

QOJ

Limite de temps : 3 s Limite de mémoire : 512 MB Points totaux : 100

#10509. Landlord

Statistiques

If you have participated in NOIP 2015 and PKUWC 2018, you must have a deep impression of a problem called "Landlords". To pay tribute to the classics, we have created another problem about playing cards. In this problem, the card types are similar but not identical to those in Landlords; we call the poker game in this problem "Master Landlords".

Master Landlords is a poker game played with a standard 54-card deck (A through K of spades, hearts, clubs, and diamonds, plus the small joker and big joker). There is one of each joker, and four of each other rank. In Master Landlords, the rank of the cards is as follows: $3 < 4 < 5 < 6 < 7 < 8 < 9 < 10(T) < J < Q < K < A < 2 <$ small joker $(w) <$ big joker $(W)$. Suits do not affect the rank of the cards. Each game consists of a hand of $n$ cards. Players can play cards according to specified patterns, and the first player to empty their hand wins. To simplify the problem, we ignore suits, meaning all cards of the same rank are considered identical.

In this problem, the allowed card patterns are (note that this part differs from traditional Landlords):

Name Explanation Example Note
Single A single card 6 A single joker is also a single
Pair Two cards of the same rank 66 Jokers do not form a pair
Three-of-a-kind Three cards of the same rank 666
Three-with-one Three cards of the same rank plus one single card 666w
Three-with-two Three cards of the same rank plus a pair of a different rank 66699
Straight 5 or more single cards of consecutive ranks 3456789 Cannot contain jokers or 2
Consecutive pairs 3 or more pairs of consecutive ranks 33445566 Cannot contain jokers or 2
Consecutive threes 2 or more sets of three-of-a-kind of consecutive ranks 333444555 Cannot contain jokers or 2
Four-with-two Four cards of the same rank plus two single cards 444456 444455 Cannot contain two pairs
Airplane (single wings) Consecutive threes with the same number of distinct-rank single cards 33344455569J
Airplane (double wings) Consecutive threes with the same number of distinct-rank pairs 3334446699

Note:

  1. There is no "consecutive bomb" pattern, but a sequence like 444455556666 can still be played; it is treated as a 444555666 airplane (single wings) with 456 as the wings.
  2. The big joker and small joker have different ranks, so an airplane with jokers is legal, e.g., 333444wW.
  3. It is easy to verify that the rules for the above patterns are valid, meaning any legal set of cards has a unique pattern.
  4. There are no bombs in the allowed patterns. Bombs are treated as "three-with-one" and have no special effect; they cannot beat any other pattern.
  5. There are no rockets. This means wW is no longer a legal pattern.

Two hands belong to the same pattern if and only if they have the same name and contain the same number of cards. There is a ranking between hands of the same pattern:

  1. The rank of "three-with-one" and "three-with-two" depends on the rank of the three cards.
  2. The rank of an airplane depends on the rank of the consecutive threes.
  3. The rank of "four-with-two" depends on the rank of the four cards.
  4. The rank of other patterns depends on the highest-ranking card in the set.

The game process of Master Landlords is described as follows:

  1. There are two players in the same camp who must work together to achieve the goal. For convenience, we assume the first player is Kaguya and the second player is XX-Netizen.
  2. The game uses one complete deck of cards. At the start of the game, all 3s are removed. Then, both players are dealt 17 cards randomly from the remaining deck, and the remaining 16 cards are discarded. You can assume that after shuffling, Kaguya takes the first 17 cards, XX-Netizen takes the next 17, and the remaining 16 are discarded.
  3. The game consists of several rounds, each with two steps:
    1. Step 1: Kaguya chooses any pattern of any rank from her current hand and plays it ($C$).
    2. Step 2: XX-Netizen chooses a card $C'$ from his hand that has the same pattern as $C$ and a strictly higher rank. If no such card exists, the game is lost.
  4. After a round, if at least one of Kaguya or XX-Netizen has no cards left, the game ends. If both players have no cards left, they win; otherwise, they lose.

Here is an example:

Suppose Kaguya's hand is 44445556789TJQKwW and XX-Netizen's hand is 666789TJQKAAAA222. A winning strategy is:

  1. Round 1: Kaguya plays 4444wW, XX-Netizen plays AAAA22.
  2. Round 2: Kaguya plays 6789TJQ, XX-Netizen plays 789TJQK.
  3. Round 3: Kaguya plays 555K, XX-Netizen plays 6662.

This game tests the tacit understanding between the two players. However, since Kaguya and XX-Netizen cannot communicate, they decide to play with their cards revealed, meaning both know the other's hand. Since both play optimally, the outcome is determined as soon as the cards are dealt.

Given XX-Netizen's hand, you need to calculate how many different possible hands Kaguya could have that would result in a win.

Note: Both XX-Netizen's and Kaguya's cards come from the same deck, and 3s are removed before dealing.

Input

Each input consists of a single line containing a string of length 17 representing XX-Netizen's hand. We use 456789TJQKA2wW to represent each card rank.

Output

For each input, output an integer representing the answer: the number of possible hands for Kaguya that result in a win. The answer may be large, so output it modulo 998244353.

Note: We do not consider suits in this problem. If two hands have the same composition of ranks, they are considered the same, even if the suits differ.

Examples

Input 1

556789TJJQKKAA22w

Output 1

193483

Input 2

456789TJJQKKAA22w

Output 2

0

Input 3

456789TJQKKKAAA22

Output 3

613897

Subtasks

This problem uses bundled testing and consists of 3 subtasks:

Subtask ID Score Constraints
1 30 Each rank appears at most 2 times
2 30 Each rank appears at most 3 times
3 40 Each rank appears at most 4 times

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.