Playing Poker

Time Limit: 16 Seconds
Memory Limit: 16384 KB

Estelle Bright goes to Casino & Bar Lavantar to gamble. Among all the games, playing Poker is most possible to make much money (which is called Mira here), so Estelle decide to play this. But gambling has never been easy. Fortunately, with the help of Scherazard Harvey, she can know the queue of coming cards. However, this's not enough. So she still need bright Klose Rinz, the smart and beautiful princess, to help her to find the best strategy.

The rules of playing Poker are as follows:

- this game will use 4 * 13 = 52 kinds of cards, each infinity. At the beginning of each game, you should choose a
**bet** in range 1 ~ 10 and you need to pay **bet** medals. You always begin with a **rate** 1
- each round, you will be given 5 cards first, then you can choose some (0 ~ 5) of them to hold and change the other ones, at last the 5 cards make up your hand
- after each round, according the category of your hand, the
**rate** will multiply a different number. If your **rate** is 0, the game is over, or you can choose to continue playing or not. You will get **bet** * **rate** medals (1 Mira = 5 medals) at the end of the game
- a hand always consists of five cards, here are the categories of the hands:
Category |
Bonus |
Definition |

No pair |
Rate* 0 |
A no pair hand is a poker hand in which no two cards have the same rank, the five cards are not in sequence, and the five cards are not all the same suit. |

One pair |
Rate* 2 |
One pair is a poker hand which contains two cards of the same rank, plus three other unmatched cards. |

Two pair |
Rate* 3 |
A poker hand such as which contains two cards of the same rank, plus two cards of another rank (that match each other but not the first pair), plus one unmatched card, is called two pair. |

Three of a kind |
Rate* 4 |
Three of a kind is a poker hand which contains three cards of the same rank, plus two unmatched cards. |

Straight |
Rate* 8 |
A straight is a poker hand which contains five cards of sequential rank but in more than one suit. HA H2 H3 H4 D5 is not a straight. |

Flush |
Rate* 10 |
A flush is a poker hand which contains five cards of the same suit, not in rank sequence. |

Full house |
Rate* 15 |
A full house is a hand which contains three matching cards of one rank, and two matching cards of another rank. |

Four of a kind |
Rate* 50 |
Four of a kind is a poker hand such which contains no less than four cards of one rank, and an unmatched card of another rank. |

Straight flush |
Rate* 100 |
A straight flush is a poker hand which contains five cards in sequence, all of the same suit. |

Royal flush |
Rate* 500 |
An ace-high straight flush such as HA HK HQ HJ HT is known as a royal flush |

- the
**rate** can be 9999 at most, if it's turning to a number larger than 9999, then it will turn to 9999

Assuming that Estelle has 16 medals initially, how much medals can she has with the help of Klose after playing Poker once? Scherazard might cannot predict enough number of cards, Klose will never make a strategy that need unknown cards!

**
Input
**

Each case begins with a number 16 <= *n* <= 160 indicating the size of the cards queue predicted by Scherazard. Then *n* string whose length is exactly 2 indicating the cards in order. Cards will be represented in format __"suit rank"__ where suit is one of 'H', 'S', 'D', 'C' and rank is one of '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'.

**
Output
**

Output the maximum number of medals in a separate line.

**
Sample Input
**

32
HA SA DA CA H2 HK HQ HJ HT C3 D3 DQ C7 H9 S3 D4 C6 H8 ST DQ CA H5 S3 D9 C7 HJ SK D8 C6 H4 C2 DT

**
Sample Output
**

20006

**
Note
**

Strategy of the sample:

**bet** = 10

get cards: HA SA DA CA H2; change cards: SA DA CA H2; get: HK HQ HJ HT

hand: HA HK HQ HJ HT; royal flush; rate * 500

continue

get cards: C3 D3 DQ C7 H9; hold cards: C3 D3 *; change at leaset one card

hand: C3 D3 S3 *; three of a kind; rate * 4

don't continue

*The background comes from the famous RPG game the Legend of Heroes: Sora no Kiseki Second Chapter by Nihon Falcom Corporation.*

Author:

**WU, Zejun**
Submit
Status