Under construction

Still being built. Things may change

Biology

Time limit2sMemory limit512 MB

Summary
Count the possible five-card hands for each of nine poker categories, given two fixed cards from a deck with A ranks and B suits.
Level

Medium6 of 10

Topics
Combinatorics, Math, Implementation, Brute force
Solved
No attempts yet

Problem

Vera has A×BA \times B cards. Each card has a rank, an integer between 00 and A−1A - 1, and a suit, an integer between 00 and B−1B - 1. All cards are distinct. A set of five different cards is a hand.

Every hand falls into exactly one of nine categories numbered 11 through 99. If a hand satisfies the conditions of more than one category, it belongs to the lowest numbered category among them. The rules are:

  1. Straight flush: the hand is a straight and a flush.
  2. Four of a kind: four of the cards have the same rank.
  3. Full house: three of the cards have the same rank and the remaining two have the same rank.
  4. Flush: all five cards have the same suit.
  5. Straight: the ranks of the cards in increasing order are x,x+1,x+2,x+3,x+4x, x + 1, x + 2, x + 3, x + 4 for some integer xx.
  6. Three of a kind: three of the cards have the same rank.
  7. Two pair: two cards have the same rank and two other cards have the same rank.
  8. One pair: two cards have the same rank.
  9. High card: the hand satisfies no other category.

Vera currently holds two cards with ranks a1a_1, a2a_2 and suits b1b_1, b2b_2. She picks three more cards from the remaining ones and forms a hand with the two she holds. Compute the number of different hands formed this way that belong to each category.

Input

The first line contains the integers AA and BB (5≤A≤255 \le A \le 25, 1≤B≤41 \le B \le 4).

The second line contains the integers a1a_1, b1b_1, a2a_2, b2b_2 (0≤a1,a2≤A−10 \le a_1, a_2 \le A - 1, 0≤b1,b2≤B−10 \le b_1, b_2 \le B - 1, (a1,b1)≠(a2,b2)(a_1, b_1) \neq (a_2, b_2)).

Output

Print one line with nine integers separated by single spaces. The ii-th integer is the number of different hands that belong to category ii, so the counts run from straight flush to high card in increasing order of category number.

Hint

Let (a,b)(a, b) denote the card with rank aa and suit bb.

In the first example Vera holds (1,0)(1, 0) and (3,1)(3, 1). If she picks (3,0)(3, 0), (4,0)(4, 0), (4,1)(4, 1), her hand has two cards of rank 33 and two other cards of rank 44, so it is a two pair. The same hand also satisfies one pair, but two pair has the lower category number, so it counts as a two pair.

Examples2

  1. Example 1

    Input
    5 2
    1 0 3 1
    
    Expected output
    0 0 0 0 8 0 12 36 0
    
  2. Example 2

    Input
    13 4
    0 0 1 0
    
    Expected output
    1 2 18 164 63 308 792 7920 10332