Pair Linked Mokepon

시간 제한2초메모리 제한2048 MB

요약
두 Mokepon 게임에서 필요한 식별자를 모두 모아 각자의 마지막 역에 도달할 수 있게 아이템을 배치하는 경우의 수를 센다.
난이도

어려움10점 중 9점

유형
조합론, 동적 계획법, 수학
정답자
아직 제출이 없습니다

문제

The popular game of Mokepon can be represented as a list of nn stations with special items located at them and a player beginning at station 11. Each item has an identifier id (2≤2\leid≤n\le n) (and no two items may have the same identifier), and the player is required to have the item with identifier ii to be able to move to station ii from station i−1i - 1. Stations may have multiple (including none) items, and the player can pick up and hold an unlimited number of items. The objective is to reach the last station: station nn.

You and your friend find this game too easy, so you decide to link up two games of Mokepon: your game has n_An\_{\text{A}} stations and your friend's game has n_Bn\_{\text{B}} stations. However, special items may appear in either game, and are now uniquely identified by the pair of ((id,A or B), \text{A or B}): its identifier, and which game it comes from. To progress to station ii in a given game, either one of you must have picked up the item with identifier ii for that game.

The games randomize where items gets placed in each of the game, and so not every placement of items may be possible to win from. Your goal is to count the number of distributions of items such that it is possible for the two of you to both reach the end station in your respective games. Since this number may be large, calculate it modulo a prime pp.

We say two distributions of items to stations are different if there is at least one station where the set of items at that station differ.

입력

The only line of input contains three integers, n_An\_\text{A}, n_Bn\_\text{B}, and pp ( 2≤n_A,n_B≤3⋅1032\le n\_\text{A}, n\_\text{B}\le 3\cdot 10^3, 108≤p≤109+710^8\le p\le 10^9 + 7) --- the number of stations in your and your friend's game, respectively, and the modulo to calculate with respect to.

It is guaranteed that pp is a prime.

출력

Output a single integer, the number of distributions of items such that both players win their respective games, modulo pp.

힌트

In the first sample, there are two special items: (2,A)(2, \text{A}) and (2,B)(2, \text{B}) corresponding to the two games A\text{A} and B\text{B} respectively, and thus 42=164^2 = 16 configurations of stations where they could be located. The eight winning possibilities (in the notation (station, game)) are listed below, along with illustrations of the first two possibilities.

  • (1,A)(1, A); (1,A)(1, A): Both players can immediately progress to their respective end stations.
  • (1,A)(1, A); (2,A)(2, A): The first player unlocks their final station, at which point the second player can progress.
  • (1,A)(1, A); (1,B)(1, B)
  • (1,B)(1, B); (1,A)(1, A)
  • (1,B)(1, B); (1,B)(1, B)
  • (1,B)(1, B); (2,A)(2, A)
  • (2,B)(2, B); (1,A)(1, A)
  • (2,B)(2, B); (1,B)(1, B)

예제2

  1. 예제 1

    입력
    2 2 1000000007
    
    예상 출력
    8
    
  2. 예제 2

    입력
    15 20 998244353
    
    예상 출력
    937612