#P5481. [BJOI2015] 糖果

    ID: 4435 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2015各省省选北京O2优化组合数学

[BJOI2015] 糖果

Description

Every day, Alice draws a table with nn rows and mm columns and asks Bob to fill in numbers in the cells.

Bob has learned how to write the natural numbers from 11 to kk. Therefore, in each cell he writes an integer between 1k1 \sim k.

Alice tells Bob that if, after Bob fills in all n×mn \times m numbers, the numbers in each row are non-decreasing from column 11 to column mm, and for any two rows there is at least one column where the numbers are different, and Bob has never filled in an identical table before, then Alice will give Bob a piece of candy.

Bob wants to know: if he fills in the table once per day, what is the maximum number of candies he can get.

The answer is taken modulo pp.

Input Format

The input contains only one line with four integers, representing n,m,k,pn, m, k, p.

Output Format

Output one line with one integer, representing the answer modulo pp.

1 3 3 10
0
2 2 2 10
6

Hint

Explanation of Sample Input/Output 1

There are 1010 valid schemes in total, and after taking modulo, it becomes 00.


Constraints

  • For 100%100\% of the testdata, it is guaranteed that 1n,m1051 \leq n, m \leq 10^5, and 1k,p2×1091 \leq k, p \leq 2 \times 10^9.

Translated by ChatGPT 5