logo AlgoBeat OnlineJudge
登录 注册

#217696. [PacNW 2025] Pair-Linked Mokepon

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 .

输入格式

The only line contains three integers , , and (, ). The value is guaranteed to be prime.

输出格式

Output the number of winning item distributions modulo .

样例

样例输入 1

2 2 1000000007

样例输出 1

8

样例输入 2

15 20 998244353

样例输出 2

937612

数据范围与提示

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.