atcoder#ABC291D. [ABC291D] Flip Cards
[ABC291D] Flip Cards
Score : points
Problem Statement
cards, numbered through , are arranged in a line. For each , card and card are adjacent to each other. Card has written on its front, and written on its back. Initially, all cards are face up.
Consider flipping zero or more cards chosen from the cards. Among the ways to choose the cards to flip, find the number, modulo , of such ways that:
- when the chosen cards are flipped, for every pair of adjacent cards, the integers written on their face-up sides are different.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
3
1 2
4 2
3 4
4
Let be the set of card numbers to flip.
For example, when is chosen, the integers written on their visible sides are , and , from card to card , so it satisfies the condition.
On the other hand, when is chosen, the integers written on their visible sides are , and , from card to card , where the integers on card and card are the same, violating the condition.
Four satisfy the conditions: , and .
4
1 5
2 6
3 7
4 8
16
8
877914575 602436426
861648772 623690081
476190629 262703497
971407775 628894325
822804784 450968417
161735902 822804784
161735902 822804784
822804784 161735902
48