#agc039f. [agc039_f]Min Product Sum
[agc039_f]Min Product Sum
Problem Statement
For each of the ways to write an integer between and (inclusive) in every square in a square grid with rows and columns, find the value defined below, then compute the sum of all those values, modulo .
- For each of the squares, find the minimum among the integers written in the square's row or the square's column. The value defined for the grid is the product of all these values.
Constraints
- and are integers.
- is prime.
Input
Input is given from Standard Input in the following format:
Output
Print the sum of the values, modulo .
Sample Input 1
2 2 2 998244353
Sample Output 1
35
We have way to write integers such that the product of the values is , ways such that the product is , and ways such that the product is .
Sample Input 2
2 3 4 998244353
Sample Output 2
127090
Sample Input 3
31 41 59 998244353
Sample Output 3
827794103