atcoder#ARC061D. [ARC061F] 3人でカードゲーム
[ARC061F] 3人でカードゲーム
Score : points
Problem Statement
Alice, Bob and Charlie are playing Card Game for Three, as below:
- At first, each of the three players has a deck consisting of some number of cards. Alice's deck has cards, Bob's deck has cards, and Charlie's deck has cards. Each card has a letter
a
,b
orc
written on it. The orders of the cards in the decks cannot be rearranged. - The players take turns. Alice goes first.
- If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says
a
, Alice takes the next turn.) - If the current player's deck is empty, the game ends and the current player wins the game.
There are possible patters of the three player's initial decks. Among these patterns, how many will lead to Alice's victory?
Since the answer can be large, print the count modulo .
Constraints
Partial Scores
- points will be awarded for passing the test set satisfying the following: , , .
Input
The input is given from Standard Input in the following format:
Output
Print the answer modulo .
1 1 1
17
- If Alice's card is
a
, then Alice will win regardless of Bob's and Charlie's card. There are such patterns. - If Alice's card is
b
, Alice will only win when Bob's card isa
, or when Bob's card isc
and Charlie's card isa
. There are such patterns. - If Alice's card is
c
, Alice will only win when Charlie's card isa
, or when Charlie's card isb
and Bob's card isa
. There are such patterns.
Thus, there are total of patterns that will lead to Alice's victory.
4 2 2
1227
1000 1000 1000
261790852