QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#11187. Cards [B]

统计

Alice nad Bob have found a few decks of cards at the attic. Some of them were very dusty, some incomplete, and some contained strange honor cards that cannot be found among regular playing cards. However, all cards had one characteristic in common: they were either black or red. Alice and Bob are very creative children. They decided to use all the cards they have found and play the following game.

In the beginning of the game children shuffle all the cards. Afterwards, they play the cards one by one from the top of the deck onto the table. If the first played card is black or some sequence of consecutively played black cards is $ not $ immediately preceded by a k times longer sequence of consecutive red cards, then Alice wins the game. In the opposite case, after all cards have been played, Bob wins the game.

Alice would like to find out what is her chance of winning, so she is wondering for how many arrangements of cards that could be a result of shuffling the initial deck she wins with Bob. We assume that all cards of the same colour are indistinguishable. Alice has recently heard about the Chinese remainder theorem, so it is sufficient for her to know the result modulo given prime number p.

Input Format

The first and only line of the standard input contains four integers r, b, k, and p (1 ≤ r, b ≤ 100,000, 1 ≤ k ≤ 10, 2 ≤ p ≤ 1,000,000,000) separated by single spaces. Number r denotes the number of red cards in the deck, whereas b - the number of black cards. p is a prime number.

Output Format

The first and only line of the standard output should contain the remainder of division by p of the number of arrangements of cards consisting of r red cards and b black cards, for which Alice wins the game.

Example

Input

4 2 1 17

Output

6

Notes

In this case Alice wins if either the first card is black or some sequence of consecutive black cards is immediately preceded by a smaller number of consecutive red cards. Let Rdenote a red card, and B - a black card. These are the arrangements of cards for which Alice wins (the first lecodeer in each of them denotes the card from the top of the deck): BBRRRR, BRBRRR, BRRBRR,BRRRBR, BRRRRB, and RBBRRR.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.