E - Grand Tichu! 

Background

Tichu is becoming one of the most popular cards games in Europe. Either if you meet for coffee or for beers with 3 more friends, do not forget to bring your Tichu deck!

The Tichu deck is similar to French deck (i.e., four sets of 13 cards --2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace--), but with four extra special cards: Dragon, Phoenix, Mah Jong, and Dogs.


Tichu special cards: Dragon, Phoenix, Mah Jong, and Dogs.

The four players, playing two against two, receive all cards in the deck. And the main goal of the game is to play all your cards before the other players (the rules about how to play the cards are not important to resolve the problem). A player does not receive the 14 cards at the same time, but when he receives the first 8 cards, he needs to predict if he will finish before the others and bet for it by saying "Grand Tichu!".

The Problem

Our friend likes to say "Grand Tichu!" a lot, but he is not always finishing first. After some discussions with his teammate, he decided to declare "Grand Tichu!" only if the probability of getting at least one of this four combinations when all cards are dealt is higher than 0.25:

  • He has at least the Dragon, the Phoenix and one Ace within the 14 cards.
  • He has at least the Dragon and two Aces within the 14 cards.
  • He has at least the Phoenix and three Aces within the 14 cards.
  • He has at least the four special cards within the 14 cards.
  • The Input

    The program input consist of several lines, each one with a sequence of eight characters indicating the first 8 cards. We use '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', and 'A' for the normal cards and 'D' for the Dragon, 'P' for the Phoenix, 'M' for the Mah Jong, and 'd' for the Dogs. The input terminates with a line with the string 0.

    The Output

    For each 8-card case, your program must print "Grand Tichu!" if the probability of getting any of the selected combinations is higher than 0.25, or "...", otherwise.

    Sample Input

    D23468AA
    D2P4688K
    D23468KA
    D2233889
    PdM2345T
    PdM234AA
    0

    Sample Output

    Grand Tichu!
    Grand Tichu!
    Grand Tichu!
    ...
    ...
    ...

    OMP'14
    Facultad de Informática
    Universidad de Murcia