This page is still under construction.

Parts of this page are still being built. What you see may change.

Local Maxima

Time limit4sMemory limit512 MB

Summary
Count permutations of 1 to n*m in an n by m grid that have exactly one local maximum, where a cell is a local maximum if it is at least every other cell in its row and column, modulo a prime P.
Level

Hard8 of 10

Topics
Combinatorics, Math, Greedy
Solved
No attempts yet

Problem

Given an n×mn \times m integer matrix AA, a local maximum of AA is a location (i,j)(i, j) with 1≤i≤n1 \le i \le n and 1≤j≤m1 \le j \le m such that Ai,jA_{i, j} is no smaller than any other integer on the ii-th row or on the jj-th column.

For example, in the 3×33 \times 3 matrix [254216222],\begin{bmatrix} 2 & 5 & 4 \\ 2 & 1 & 6 \\ 2 & 2 & 2 \end{bmatrix}\text{,} there are three local maxima: locations (1,2)(1, 2), (2,3)(2, 3), and (3,1)(3, 1) with values 55, 66, and 22, respectively.

An n×mn \times m integer matrix AA is good if and only if it satisfies the following two conditions:

  • There is exactly one local maximum in AA.
  • Each integer from 11 to n×mn \times m occurs exactly once in AA.

Given nn, mm, and a prime number PP, count the number of good matrices of size n×mn \times m modulo PP.

Input

The first line contains three integers, nn, mm, and PP, where 1≤n,m≤30001 \le n, m \le 3000 and 108≤P≤109+710^8 \le P \le 10^9 + 7. It is guaranteed that PP is prime.

Output

Output a single line with a single integer: the number of good matrices modulo PP.

Examples3

  1. Example 1

    Input
    2 2 1000000007
    
    Expected output
    16
    
  2. Example 2

    Input
    4 3 1000000007
    
    Expected output
    95800320
    
  3. Example 3

    Input
    100 100 998244353
    
    Expected output
    848530760