Video Poker

No attempts yetTime limit1sMemory limit128 MB

Problem

Video poker is a single-player card game played with a standard 52-card deck (ranks Two through Ace in four suits). Each round costs one coin: the player is dealt five random cards, may discard any subset of them, and each discarded card is replaced by a card drawn from the 47 cards left in the deck (discarded cards are not shuffled back in). The resulting five-card hand is paid according to a payout table.

The paying hands, from weakest to strongest, are:

  • Pair: two cards of the same rank. A pair pays only when it is a pair of Jacks, Queens, Kings, or Aces.
  • Two pairs: two pairs of any ranks.
  • Three of a kind: three cards of the same rank.
  • Straight: five cards of consecutive ranks. An Ace may sit either above the King or below the Two, but not both at once, so A-2-3-4-5 and 10-J-Q-K-A are straights while K-A-2-3-4 is not.
  • Flush: five cards of the same suit.
  • Full house: three of a kind together with a pair.
  • Four of a kind: four cards of the same rank.
  • Straight flush: a straight and a flush at the same time.
  • Royal flush: a straight flush made of Ace, King, Queen, Jack, and Ten.

A hand is paid only for its strongest matching category (for example, a full house is not also paid as a pair), and a hand matching none of the categories pays nothing.

For a given payout table, the optimal strategy decides, for every dealt hand, which cards to keep so that the expected payout after the draw is as large as possible. When several choices reach the same maximum expected payout, the one that keeps the fewest cards (equivalently, discards the most) is chosen.

Consider all (525)=2,598,960\binom{52}{5} = 2{,}598{,}960 possible dealt hands. Under the optimal strategy, determine how many of them lead to discarding exactly 0, 1, 2, 3, 4, and 5 cards.

Input

A single line with nine positive integers separated by single spaces. In order, they are the payouts for a Pair, Two pairs, Three of a kind, Straight, Flush, Full house, Four of a kind, Straight flush, and Royal flush.

Output

A single line with six integers separated by single spaces: the number of dealt hands for which the optimal strategy discards 0, 1, 2, 3, 4, and 5 cards, respectively.