#P17387. [PacNW 2025] Pair-Linked Mokepon
[PacNW 2025] Pair-Linked Mokepon
Problem Description
A game of Mokepon consists of stations. The player starts at station . For every from through , there is one special item with identifier , and the player must possess that item to move from station to station . A station may hold any number of items, and a player may carry any number of items. The objective is to reach station .
You and a friend link two games: game A has stations and game B has stations. Every item is identified by a pair or , indicating its identifier and the game it unlocks. An item may be placed at any station in either game. To advance to station in a game, either player must already have collected the corresponding item for that game.
Count the distributions of all items among all stations for which both players can reach the final station of their respective games. Two distributions differ if the set of items at some station differs. Output the count modulo the prime .
Input Format
The only line contains three integers , , and (, ). The value is guaranteed to be prime.
Output Format
Output the number of winning item distributions modulo .
2 2 1000000007
8
15 20 998244353
937612
Hint
In the first sample, there are two items, and . Each can be placed at any of four station-game locations, so there are distributions in total. Exactly eight of them allow both players to win.