All problems

Poker Hands With Exactly Two Aces

hardPythonCombinatorics

Whetcode Games designs card-table side bets that pay out when a hand holds exactly a stated number of a special card, and the maths has to be signed off before each paytable goes to print. A hand is a set of cards held together; the order they were dealt in is not part of the hand, and no card appears twice.

The studio prototypes on trimmed-down decks as well as the standard 52, so the deck size, how many special cards it contains, the hand size and how many of the special cards the bet requires all arrive as figures to be counted from.

"Exactly" is strict. A hand carrying one more special card than the bet names does not qualify, so the rest of the hand has to come from somewhere the special cards cannot reach.

Task: Print how many distinct hands hold exactly the required number of special cards, as a single integer. This is a count of hands, not a probability.

Input

Four lines, one whole number each: the size of the deck, how many special cards are in it, how many cards make a hand, and how many special cards the bet requires. The hand always fits in the deck, and the requirement never exceeds either the number of special cards or the hand size.

Output

One line holding the count of qualifying hands, as a plain integer - 103776, with no separators and no decimal point.

Example:

Input:
52
4
5
2

Output:
103776

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…