#P17387. [PacNW 2025] Pair-Linked Mokepon

[PacNW 2025] Pair-Linked Mokepon

Problem Description

A game of Mokepon consists of nn stations. The player starts at station 11. For every ii from 22 through nn, there is one special item with identifier ii, and the player must possess that item to move from station i1i-1 to station ii. A station may hold any number of items, and a player may carry any number of items. The objective is to reach station nn.

You and a friend link two games: game A has nAn_A stations and game B has nBn_B stations. Every item is identified by a pair (i,A)(i,\mathrm A) or (i,B)(i,\mathrm B), indicating its identifier and the game it unlocks. An item may be placed at any station in either game. To advance to station ii 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 pp.

Input Format

The only line contains three integers nAn_A, nBn_B, and pp (2nA,nB31032\le n_A,n_B\le3\cdot10^3, 108p109+710^8\le p\le10^9+7). The value pp is guaranteed to be prime.

Output Format

Output the number of winning item distributions modulo pp.

2 2 1000000007
8
15 20 998244353
937612

Hint

In the first sample, there are two items, (2,A)(2,\mathrm A) and (2,B)(2,\mathrm B). Each can be placed at any of four station-game locations, so there are 42=164^2=16 distributions in total. Exactly eight of them allow both players to win.