#P6672. [清华集训 2016] 你的生命已如风中残烛
[清华集训 2016] 你的生命已如风中残烛
Description
The midterm exams are over. Rikka, who already feels there is nothing left to be afraid of, decided not to study math today, and started playing Yu-Gi-Oh! with Yuta.
“You have an empty hand and an empty field, and only 100 Life Points left. At this point, what can you still do?”
“Sore wa dou kana!”
“Nani?”
However, Rikka’s deck is really too weak. After analyzing it, Rikka found that within one turn, her deck cannot achieve an OTK, unless she has the protagonist’s luck:
Exodia the Forbidden One
—If you have this card in your hand, along with “Right Leg of the Forbidden One”, “Left Leg of the Forbidden One”, “Right Arm of the Forbidden One”, and “Left Arm of the Forbidden One”, you win the Duel.

But since Rikka is not a noble pay-to-win player, she is certain that among these five cards, at least one must be at the bottom of the deck. So Rikka is now facing a problem: she needs to draw the entire deck within one turn.
Rikka’s deck has a total of cards. Because the last card is fixed, we only consider the first cards.
Among these cards, there are special cards and normal cards. Each special card has an attribute value , meaning that after playing this card, she can draw another cards. Luckily, Rikka found that these cards satisfy , so she can draw cards freely without worrying about deck-out.
Since these cards are shuffled, there are different possible decks.
Now the turn begins. Rikka first draws one card from the deck, then she keeps playing cards from her hand. If she plays a special card, she can draw cards again, until she draws the last card and meets the win condition, or she runs out of cards in her hand, ends her turn, and thus loses the match.
For example, if the deck is (use to represent a normal card, and other numbers to represent , where the last is the final piece), then Rikka’s play process can be:
- Draw one card, the cards in hand are .
- Play , then draw four cards, the cards in hand are .
- Play , and she still needs to draw two more cards. At this time she has already drawn the last piece, so Rikka wins.
- If the deck is , it is not hard to see that Yuta wins.
Now, among these different decks, Rikka wants to know how many of them allow her to win.
Input Format
The first line contains an integer .
The second line contains space-separated positive integers .
From the input you can compute .
Output Format
Output one integer representing the answer. The answer may be very large; you only need to output it modulo .
1
5
24
6
1 2 3 4 5 6
90337303
Hint
Explanation for Sample
Among all possible decks, only the decks of the form satisfy the condition.
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, , . It is also guaranteed that , because after all, the deck must contain these pieces.
Translated by ChatGPT 5
京公网安备 11011102002149号