QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#7774. Basic Data Structure Exercises

Estadísticas

For a sequence $ a $ of length $ n $, define $ f(a)=\dfrac{1}{\prod\limits_{i=k}^ns_i} $, where $ s_i $ is the prefix sum array of $ \{a_n\} $, and $ k $ is a given constant such that $ 1\le k\le 2 $.

Consider all sequences $ a $ that satisfy the following three conditions:

  • The length of $ a $ is $ n $.
  • $ \forall i,j $, $ a_i\ne a_j $.
  • $ 1\le a_i\le m $.

Calculate the sum of $ f(a) $ for all such sequences, modulo $ p $. It is guaranteed that $ p $ is a prime number.

Input

The first line contains four integers $ n, m, k, p $, representing the sequence length, the upper bound of the sequence elements, and the modulus, respectively.

Output

Output a single integer representing the answer modulo $ p $.

Examples

Input 1

2 3 2 1000000007

Output 1

966666675

Input 2

3 5 2 998244353

Output 2

148276980

Input 3

6 10 2 1004535809

Output 3

622165218

Input 4

30 40 1 265371653

Output 4

179937201

Constraints

For all test cases, it is guaranteed that $ 2\le n\le m\le 100 $, $ 10^8 < p < 1.07\times 10^9 $, $ p $ is a prime number, and $ 1\le k\le 2 $.

  • Subtask 1 (10 pts): $ m\le 20 $.
  • Subtask 2 (25 pts): $ k=1 $.
  • Subtask 3 (15 pts): $ n=m\le 30 $.
  • Subtask 4 (10 pts): $ m\le 30 $.
  • Subtask 5 (15 pts): $ m\le 40 $.
  • Subtask 6 (10 pts): $ m\le 70 $.
  • Subtask 7 (15 pts): $ m\le 100 $.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.